summaryrefslogtreecommitdiff
path: root/node_modules/@jet/environment/metrics/helpers
diff options
context:
space:
mode:
authorrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
committerrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
commitbce557cc2dc767628bed6aac87301a1be7c5431b (patch)
treeb51a051228d01fe3306cd7626d4a96768aadb944 /node_modules/@jet/environment/metrics/helpers
init commit
Diffstat (limited to 'node_modules/@jet/environment/metrics/helpers')
-rw-r--r--node_modules/@jet/environment/metrics/helpers/index.js21
-rw-r--r--node_modules/@jet/environment/metrics/helpers/location.js213
-rw-r--r--node_modules/@jet/environment/metrics/helpers/models.js3
-rw-r--r--node_modules/@jet/environment/metrics/helpers/numerics.js23
-rw-r--r--node_modules/@jet/environment/metrics/helpers/util.js76
5 files changed, 336 insertions, 0 deletions
diff --git a/node_modules/@jet/environment/metrics/helpers/index.js b/node_modules/@jet/environment/metrics/helpers/index.js
new file mode 100644
index 0000000..ee6bdeb
--- /dev/null
+++ b/node_modules/@jet/environment/metrics/helpers/index.js
@@ -0,0 +1,21 @@
+"use strict";
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ var desc = Object.getOwnPropertyDescriptor(m, k);
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
+ desc = { enumerable: true, get: function() { return m[k]; } };
+ }
+ Object.defineProperty(o, k2, desc);
+}) : (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ o[k2] = m[k];
+}));
+var __exportStar = (this && this.__exportStar) || function(m, exports) {
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+__exportStar(require("./location"), exports);
+__exportStar(require("./models"), exports);
+__exportStar(require("./numerics"), exports);
+__exportStar(require("./util"), exports);
+//# sourceMappingURL=index.js.map \ No newline at end of file
diff --git a/node_modules/@jet/environment/metrics/helpers/location.js b/node_modules/@jet/environment/metrics/helpers/location.js
new file mode 100644
index 0000000..7bccd40
--- /dev/null
+++ b/node_modules/@jet/environment/metrics/helpers/location.js
@@ -0,0 +1,213 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.MetricsLocationTracker = void 0;
+const validation = require("../../json/validation");
+const optional_1 = require("../../types/optional");
+const metricsUtil = require("./util");
+/**
+ * A type describing metrics location tracker.
+ *
+ * The tracker manages stack of metrics location items.
+ */
+class MetricsLocationTracker {
+ // endregion
+ // region Initialization
+ /**
+ * Create new metrics location tracker with all required attributes.
+ * @param rootPosition - Current root position of the tracker.
+ * @param locations - Array of metrics location to track.
+ */
+ constructor(rootPosition = 0, locations = []) {
+ this.rootPosition = rootPosition;
+ this.locationStack = locations.map((location) => new MetricsLocationStackItem(location));
+ }
+ // endregion
+ // region Location Stack Management
+ /**
+ * Check whether location stack is empty or not.
+ */
+ get isEmpty() {
+ return this.locationStack.length === 0;
+ }
+ /**
+ * Push new location to location tracker's stack.
+ * @param location - Location to push to stack.
+ */
+ pushLocation(location) {
+ this.locationStack.push(new MetricsLocationStackItem(location));
+ }
+ /**
+ * Pop location from location tracker's stack.
+ */
+ popLocation() {
+ var _a;
+ if (this.locationStack.length === 0) {
+ validation.unexpectedType("ignoredValue", "non-empty location stack", "empty location stack");
+ return null;
+ }
+ return (_a = this.locationStack.pop()) === null || _a === void 0 ? void 0 : _a.location;
+ }
+ /**
+ * Returns tracker's current position.
+ */
+ get currentPosition() {
+ const stackItem = this.lastStackItem;
+ if ((0, optional_1.isSome)(stackItem)) {
+ return stackItem.position;
+ }
+ else {
+ return this.rootPosition;
+ }
+ }
+ /**
+ * Set current position of tracker.
+ * This is necessary when large today modules are broken apart into multipart shelves.
+ * We need to preserve the position of content within server-response, not our logical shelves.
+ * @param position - Position to set to.
+ */
+ setCurrentPosition(position) {
+ const stackItem = this.lastStackItem;
+ if ((0, optional_1.isSome)(stackItem)) {
+ stackItem.position = position;
+ }
+ else {
+ this.rootPosition = position;
+ }
+ }
+ /**
+ * Advance tracker's position.
+ */
+ nextPosition() {
+ const stackItem = this.lastStackItem;
+ if ((0, optional_1.isSome)(stackItem)) {
+ stackItem.position += 1;
+ }
+ else {
+ this.rootPosition += 1;
+ }
+ }
+ /**
+ * Convert location tracker's stack items to array of metric location objects.
+ */
+ get stackItemsToLocations() {
+ return this.locationStack.map((stackItem) => stackItem.location);
+ }
+ /**
+ * Returns last stack item in location stack or `null` if stack is empty.
+ */
+ get lastStackItem() {
+ const length = this.locationStack.length;
+ if (length === 0) {
+ return null;
+ }
+ return this.locationStack[length - 1];
+ }
+ // endregion
+ // region Adding Location
+ /**
+ * Create new basic location and add it to existing locations of the location tracker
+ * and return resulting array of locations.
+ * @param options - Base metrics options which include location tracker to get current locations from.
+ * @param title - New location title.
+ */
+ static locationsByAddingBasicLocation(options, title) {
+ const locations = options.locationTracker.stackItemsToLocations;
+ locations.push(MetricsLocationTracker.buildBasicLocation(options, title));
+ return locations;
+ }
+ /**
+ * Create new content location and add it to existing locations of the location tracker
+ * and return resulting array of locations.
+ * @param options - Content metrics options which include location tracker to get current locations from.
+ * @param title - New location title.
+ */
+ static locationsByAddingContentLocation(options, title) {
+ const locations = options.locationTracker.stackItemsToLocations;
+ locations.push(MetricsLocationTracker.buildContentLocation(options, title));
+ return locations;
+ }
+ // endregion
+ // region Metrics Options
+ /**
+ * Create new basic location from base metrics options
+ * and push it to the stack of location tracker included into options.
+ * @param options - Base metrics options which include location tracker to push new location to.
+ * @param title - Location title.
+ */
+ static pushBasicLocation(options, title) {
+ options.locationTracker.pushLocation(MetricsLocationTracker.buildBasicLocation(options, title));
+ }
+ /**
+ * Create new content location from content metrics options
+ * and push it to the stack of location tracker included into options.
+ * @param options - Content metrics options which include location tracker to push new location to.
+ * @param title - Location title.
+ */
+ static pushContentLocation(options, title) {
+ options.locationTracker.pushLocation(MetricsLocationTracker.buildContentLocation(options, title));
+ }
+ /**
+ * Pop last location from location tracker contained in metrics options.
+ * @param options - Metrics options containing the location tracker.
+ */
+ static popLocation(options) {
+ return options.locationTracker.popLocation();
+ }
+ // endregion
+ // region Location Builders
+ static buildBasicLocation(options, title) {
+ let name = title;
+ if ((0, optional_1.isSome)(options.anonymizationOptions)) {
+ name = options.anonymizationOptions.anonymizationString;
+ }
+ const location = {
+ locationPosition: options.locationTracker.currentPosition,
+ locationType: metricsUtil.targetTypeForMetricsOptions(options),
+ name: name,
+ };
+ if ((0, optional_1.isSome)(options.recoMetricsData)) {
+ Object.assign(location, options.recoMetricsData);
+ }
+ return location;
+ }
+ static buildContentLocation(options, title) {
+ const base = MetricsLocationTracker.buildBasicLocation(options, title);
+ // Use the location tracker if there is no id override.
+ if ((0, optional_1.isNothing)(options.id)) {
+ base.idType = "sequential" /* MetricsIDType.sequential */;
+ base.id = options.locationTracker.currentPosition.toString();
+ }
+ else {
+ // If there is a id specified, use that.
+ base.idType = metricsUtil.idTypeForMetricsOptions(options);
+ let id = options.id;
+ if ((0, optional_1.isSome)(options.anonymizationOptions)) {
+ id = options.anonymizationOptions.anonymizationString;
+ }
+ base.id = id;
+ }
+ if ((0, optional_1.isSome)(options.fcKind)) {
+ base.fcKind = options.fcKind;
+ }
+ if ((0, optional_1.isSome)(options.displayStyle)) {
+ base.displayStyle = options.displayStyle;
+ }
+ return base;
+ }
+}
+exports.MetricsLocationTracker = MetricsLocationTracker;
+/**
+ * A type describing a metrics location item in location tracking stack.
+ */
+class MetricsLocationStackItem {
+ /**
+ * Create new metrics location stack item with all required attributes.
+ * @param location - The metrics location associated with this item.
+ * @param position - The position of the item.
+ */
+ constructor(location, position = 0) {
+ this.location = location;
+ this.position = position;
+ }
+}
+//# sourceMappingURL=location.js.map \ No newline at end of file
diff --git a/node_modules/@jet/environment/metrics/helpers/models.js b/node_modules/@jet/environment/metrics/helpers/models.js
new file mode 100644
index 0000000..b2dccd6
--- /dev/null
+++ b/node_modules/@jet/environment/metrics/helpers/models.js
@@ -0,0 +1,3 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+//# sourceMappingURL=models.js.map \ No newline at end of file
diff --git a/node_modules/@jet/environment/metrics/helpers/numerics.js b/node_modules/@jet/environment/metrics/helpers/numerics.js
new file mode 100644
index 0000000..822f51f
--- /dev/null
+++ b/node_modules/@jet/environment/metrics/helpers/numerics.js
@@ -0,0 +1,23 @@
+"use strict";
+/**
+ * Number related helper functions for metrics.
+ */
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.reduceSignificantDigits = void 0;
+/**
+ * Reduce significant figures of `value` by `significantDigits`.
+ * @param value - Value to reduce precision of.
+ * @param significantDigits - Number of significant digits to reduce precision by.
+ *
+ * Examples:
+ * value = 123.5, significantDigits = 0, result = 120 (no significant digit reduced)
+ * value = 123.5, significantDigits = 1, result = 120 (1 significant digit reduced)
+ * value = 123.5, significantDigits = 2, result = 100 (2 significant digit reduced)
+ */
+function reduceSignificantDigits(value, significantDigits) {
+ const roundFactor = Math.pow(10.0, significantDigits);
+ const roundingFunction = value > 0.0 ? Math.floor : Math.ceil;
+ return roundingFunction(value / roundFactor) * roundFactor;
+}
+exports.reduceSignificantDigits = reduceSignificantDigits;
+//# sourceMappingURL=numerics.js.map \ No newline at end of file
diff --git a/node_modules/@jet/environment/metrics/helpers/util.js b/node_modules/@jet/environment/metrics/helpers/util.js
new file mode 100644
index 0000000..00c739a
--- /dev/null
+++ b/node_modules/@jet/environment/metrics/helpers/util.js
@@ -0,0 +1,76 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.searchTermFromRefURL = exports.extractSiriRefAppFromRefURL = exports.idTypeForMetricsOptions = exports.targetTypeForMetricsOptions = void 0;
+const optional_1 = require("../../types/optional");
+const urls = require("../../util/urls");
+/**
+ * Returns click target type for given base metrics options.
+ * @param options - Base metrics options to derive click target type for.
+ */
+function targetTypeForMetricsOptions(options) {
+ let type = options.targetType;
+ if ((0, optional_1.isNothing)(type)) {
+ type = "lockup" /* MetricsClickTargetType.lockup */;
+ }
+ return type;
+}
+exports.targetTypeForMetricsOptions = targetTypeForMetricsOptions;
+/**
+ * Returns metrics ID type for given content metrics options.
+ * @param options - Content metrics options to derive metrics ID type for.
+ */
+function idTypeForMetricsOptions(options) {
+ let type = options.idType;
+ if ((0, optional_1.isNothing)(type)) {
+ type = "its_id" /* MetricsIDType.itsID */;
+ }
+ return type;
+}
+exports.idTypeForMetricsOptions = idTypeForMetricsOptions;
+/**
+ * Extract and return Siri reference app from URL string.
+ * @param refUrlString - URL string.
+ * @returns An optional Siri reference app string.
+ */
+function extractSiriRefAppFromRefURL(urlString) {
+ const refUrl = new urls.URL(urlString);
+ if ((0, optional_1.isNothing)(refUrl.query)) {
+ return null;
+ }
+ let extractedRefApp = null;
+ for (const key of Object.keys(refUrl.query)) {
+ if (key === "referrer") {
+ if (refUrl.query[key] === "siri") {
+ extractedRefApp = "com.apple.siri";
+ }
+ break;
+ }
+ }
+ return extractedRefApp;
+}
+exports.extractSiriRefAppFromRefURL = extractSiriRefAppFromRefURL;
+/**
+ * Extract and return search term from reference URL string.
+ * @param refUrlString - Reference URL string.
+ * @returns An optional search term string.
+ */
+function searchTermFromRefURL(refUrlString) {
+ const refUrl = new urls.URL(refUrlString);
+ const queryItems = refUrl.query;
+ if ((0, optional_1.isNothing)(queryItems)) {
+ return null;
+ }
+ const searchTerm = queryItems["term"];
+ const path = refUrl.pathname;
+ if ((0, optional_1.isNothing)(searchTerm) || (0, optional_1.isNothing)(path)) {
+ return null;
+ }
+ if (!path.endsWith("/search")) {
+ return null;
+ }
+ // the url object has already url-decoded this query parameter
+ const plainTerm = searchTerm;
+ return plainTerm;
+}
+exports.searchTermFromRefURL = searchTermFromRefURL;
+//# sourceMappingURL=util.js.map \ No newline at end of file