mirror of
https://github.com/rxliuli/apps.apple.com.git
synced 2025-11-09 22:00:32 +00:00
init commit
This commit is contained in:
901
shared/metrics-8/node_modules/@amp-metrics/ae-client-kit-core/dist/ae-client-kit-core.esm.js
generated
vendored
Normal file
901
shared/metrics-8/node_modules/@amp-metrics/ae-client-kit-core/dist/ae-client-kit-core.esm.js
generated
vendored
Normal file
@@ -0,0 +1,901 @@
|
||||
import { reflect, string, storage } from '@amp-metrics/mt-metricskit-utils-private';
|
||||
|
||||
/*
|
||||
* src/helpers/constants.js
|
||||
* ae-client-kit-core
|
||||
*
|
||||
* Copyright © 2019 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
var _allBaseFieldNames;
|
||||
var _environmentBaseFieldNames;
|
||||
|
||||
function requiredEnvironmentBaseFieldNames() {
|
||||
return [
|
||||
'app',
|
||||
'appVersion',
|
||||
'hardwareFamily',
|
||||
'hardwareModel',
|
||||
'os',
|
||||
'osBuildNumber',
|
||||
'osLanguages',
|
||||
'osVersion',
|
||||
'resourceRevNum',
|
||||
'screenHeight',
|
||||
'screenWidth',
|
||||
'userAgent'
|
||||
];
|
||||
}
|
||||
|
||||
function optionalEnvironmentBaseFieldNames() {
|
||||
return ['delegateApp', 'hardwareBrand', 'storeFrontCountryCode', 'storeFrontHeader', 'storeFrontLanguage'];
|
||||
}
|
||||
|
||||
function otherBaseFieldNames() {
|
||||
return [
|
||||
'baseVersion',
|
||||
'clientEventId',
|
||||
'connection',
|
||||
'eventTime',
|
||||
'eventType',
|
||||
'eventVersion',
|
||||
'timezoneOffset',
|
||||
'xpPostFrequency',
|
||||
'xpSendMethod'
|
||||
];
|
||||
}
|
||||
|
||||
function environmentBaseFieldNames() {
|
||||
if (!_environmentBaseFieldNames) {
|
||||
_environmentBaseFieldNames = requiredEnvironmentBaseFieldNames().concat(optionalEnvironmentBaseFieldNames());
|
||||
}
|
||||
|
||||
return _environmentBaseFieldNames;
|
||||
}
|
||||
|
||||
function allBaseFieldNames() {
|
||||
if (!_allBaseFieldNames) {
|
||||
_allBaseFieldNames = environmentBaseFieldNames().concat(otherBaseFieldNames());
|
||||
}
|
||||
|
||||
return _allBaseFieldNames;
|
||||
}
|
||||
|
||||
/*
|
||||
* src/event_handlers/Base.js
|
||||
* ae-client-kit-core
|
||||
*
|
||||
* Copyright © 2018 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
var attachDelegate = reflect.attachDelegate;
|
||||
var cryptoRandomBase62String = string.cryptoRandomBase62String;
|
||||
var exceptionString = string.exceptionString;
|
||||
|
||||
var _prototypeInitialized;
|
||||
|
||||
/**
|
||||
* Creates and returns an object (key/value data map (dictionary)) containing all of the "base" fields common to all metrics events.
|
||||
* To override any functionality in this class, use the "setDelegate() method in order to override the specific functions that need customization.
|
||||
* Kits can also extend this class and additional methods specific to their event model.
|
||||
* @example
|
||||
* // extend kit-core Base class
|
||||
* var MetricsKitBase = function MetricsKitBase() {
|
||||
* kitCore.eventHandlers.Base.apply(this, arguments); // invoke Base constructor
|
||||
* };
|
||||
* MetricsKitBase.prototype = new kitCore.eventHandlers.Base();
|
||||
* MetricsKitBase.prototype.constructor = MetricsKitBase;
|
||||
*
|
||||
* // set Kit-specific methods
|
||||
* MetricsKitBase.prototype.environment = function() { return metricsKit.system.environment; }
|
||||
* MetricsKitBase.prototype.eventRecorder = function() { return metricsKit.system.eventRecorder; }
|
||||
* MetricsKitBase.prototype.metricsData = function(pageId, pageType, pageContext, callerSuppliedFieldsMapsN) { ... }
|
||||
* MetricsKitBase.prototype.processMetricsData = function( ... ) { ... }
|
||||
*
|
||||
* // extend kit-core known fields
|
||||
* MetricsKitBase.prototype.knownFields = function knownFields() {
|
||||
* var parentKnownFields = Object.getPrototypeOf(MetricsKitBase.prototype).knownFields();
|
||||
* return parentKnownFields.concat(['dsId', 'anotherUserExperienceOnlyField']);
|
||||
* };
|
||||
*
|
||||
* // add Kit-specific accessor functions
|
||||
* MetricsKitBase.prototype.dsId = function dsId() { return this.environment().dsId(); };
|
||||
* MetricsKitBase.prototype.anotherUserExperienceOnlyField = function() { ... };
|
||||
*
|
||||
* // create a Kit-specific class instance
|
||||
* metricsKit.eventHandlers.base = new MetricsKitBase(metricsKit);
|
||||
* @param {MetricsKit/PerfKit/VPAFKit} kit
|
||||
* @delegatable
|
||||
* @constructor
|
||||
*/
|
||||
function Base(processor) {
|
||||
if (!reflect.isDefinedNonNull(processor)) {
|
||||
throw new Error('A processor instance is required for creating BaseEventHandler.');
|
||||
}
|
||||
// @private
|
||||
this._processor = processor;
|
||||
|
||||
if (!_prototypeInitialized) {
|
||||
_prototypeInitialized = true;
|
||||
environmentBaseFieldNames().forEach(function (fieldName) {
|
||||
Base.prototype[fieldName] = function (callerSuppliedEventFields) {
|
||||
var returnValue;
|
||||
|
||||
if (callerSuppliedEventFields && callerSuppliedEventFields.hasOwnProperty(fieldName)) {
|
||||
returnValue = callerSuppliedEventFields[fieldName];
|
||||
} else {
|
||||
returnValue = this.environment()[fieldName]();
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Base._className = 'eventHandlers.base';
|
||||
|
||||
/**
|
||||
* Allows replacement of one or more of this class instance's functions
|
||||
* Any method on the passed-in object which matches a method that this class has will be called instead of the built-in class method.
|
||||
* To replace *all* methods of his class, simply have your delegate implement all the methods of this class
|
||||
* Your delegate can be a true object instance, an anonymous object, or a class object.
|
||||
* Your delegate is free to have as many additional non-matching methods as it likes (these methods will not be copied to the target object).
|
||||
* It can even act as a delegate for multiple MetricsKit objects, though that is not recommended.
|
||||
*
|
||||
* "setDelegate()" may be called repeatedly, with the functions in the most-recently set delegates replacing any functions matching those in the earlier delegates, as well as any as-yet unreplaced functions.
|
||||
* This allows callers to replace some number of methods that need custom implementations.
|
||||
* If, for example, a client wants to use the standard logger implementation with the exception of, say, the "debug" method, they can
|
||||
* call "setDelegate()" with their own delegate containing only a single method of "debug" as the delegate, which would leave all the other methods intact.
|
||||
*
|
||||
* NOTE: The delegate function will have a property called origFunction representing the original function that it replaced.
|
||||
* This allows the delegate to, essentially, call "super" before or after it does some work.
|
||||
* If a replaced method is overridden again with a subsequent "setDelegate()" call, the "origFunction" property will be the previous delegate's function.
|
||||
* @example:
|
||||
* To override one or more methods, in place:
|
||||
* base.setDelegate({ app: function() { return 'myApp'; });
|
||||
* To override one or more methods with a separate object:
|
||||
* base.setDelegate(customBaseDelegate);
|
||||
* (where "customBaseDelegate" might be defined elsewhere as, e.g.:
|
||||
* var customBaseDelegate = { app: function() { return Device.appIdentifier; };
|
||||
* appVersion: function() { return Device.appVersion; } };
|
||||
* To override one or more methods with an instantiated object from a class definition:
|
||||
* base.setDelegate(new CustomBaseDelegate());
|
||||
* (where "CustomBaseDelegate" might be defined elsewhere as, e.g.:
|
||||
* function CustomBaseDelegate() {}
|
||||
* CustomBaseDelegate.prototype.app = function app() { return Device.appIdentifier; };
|
||||
* CustomBaseDelegate.prototype.appVersion = function appVersion() { return Device.appVersion; };
|
||||
* To override one or more methods with a class object (with "static" methods):
|
||||
* base.setDelegate(CustomBaseDelegate);
|
||||
* (where "CustomBaseDelegate" might be defined elsewhere as, e.g.:
|
||||
* function CustomBaseDelegate() {}
|
||||
* CustomBaseDelegate.app = function app() { return Device.appIdentifier; };
|
||||
* CustomBaseDelegate.appVersion = function appVersion() { return Device.appVersion; };
|
||||
* @param {Object} delegate Object or Class with delegate method(s) to be called instead of default (built-in) methods.
|
||||
* @returns {Boolean} true if one or more methods on the delegate object match one or more methods on the default object,
|
||||
* otherwise returns false.
|
||||
*/
|
||||
Base.prototype.setDelegate = function setDelegate(delegate) {
|
||||
return attachDelegate(this, delegate);
|
||||
};
|
||||
|
||||
/**
|
||||
* The active environment class
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @see src/system/Environment
|
||||
* @return {Environment}
|
||||
* @overridable
|
||||
*/
|
||||
Base.prototype.environment = function environment() {
|
||||
// Don't wrap the throw in a helper function or the backtrace won't be as nice.
|
||||
throw exceptionString(Base._className, 'environment');
|
||||
};
|
||||
|
||||
/**
|
||||
* The active eventRecorder
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @return {Object} an event recorder that implements a sendMethod() function
|
||||
* @overridable
|
||||
*/
|
||||
Base.prototype.eventRecorder = function eventRecorder() {
|
||||
// Don't wrap the throw in a helper function or the backtrace won't be as nice.
|
||||
throw exceptionString(Base._className, 'eventRecorder');
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a simple map object (dictionary) with all the "base" fields required by AMP Analytics
|
||||
* Some fields can be derived by this class itself.
|
||||
* Some fields need to be provided by callers.
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @returns key/value pairs of all "base" fields required by AMP Analytics.
|
||||
* WARNING: May return "null" if metrics are disabled via the metrics.disabled config source value, or on error.
|
||||
* @overridable
|
||||
*
|
||||
* TODO: consider adding default implementation for shared Kit use
|
||||
*/
|
||||
Base.prototype.metricsData = function metricsData() {
|
||||
// Don't wrap the throw in a helper function or the backtrace won't be as nice.
|
||||
throw exceptionString(Base._className, 'metricsData');
|
||||
};
|
||||
|
||||
/**
|
||||
* All of the various eventHandlers invoke this method to generate their metrics data
|
||||
* The data is a simple map object (dictionary) with all the fields required by AMP Analytics for that event
|
||||
* Some fields can be derived by this class itself.
|
||||
* This function typically expects to be called with the correct context
|
||||
* (e.g. base.processMetricsData.apply(this, arguments))
|
||||
* @returns {Object} key/value pairs of all fields required by AMP Analytics.
|
||||
* WARNING: May return "null" if metrics and/or the specific eventType for this handler is disabled, or on error.
|
||||
*
|
||||
* TODO: consider adding default implementation for shared Kit use
|
||||
*/
|
||||
Base.prototype.processMetricsData = function processMetricsData() {
|
||||
// Don't wrap the throw in a helper function or the backtrace won't be as nice.
|
||||
throw exceptionString(Base._className, 'processMetricsData');
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {Array} all the fields that base eventHandlers know about
|
||||
*/
|
||||
Base.prototype.knownFields = function knownFields() {
|
||||
return allBaseFieldNames();
|
||||
};
|
||||
|
||||
/**
|
||||
* ********************* ACCESSOR FUNCTIONS *********************
|
||||
* We create accessor functions for every data field because:
|
||||
* 1. Cleans/simplifies all methods that use it.
|
||||
* 2. Facilitates writing test case shims
|
||||
* 3. Allows specific feature suppliers to be overridden (via setDelegate()))
|
||||
*/
|
||||
|
||||
/**
|
||||
* The app identifier of the binary app
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String} The app identifier of the binary app
|
||||
* @example "com.apple.appstore" or "com.apple.gamecenter"
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.app = function app(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The version number of this application
|
||||
* @example "1.0", "5.43", etc.
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String} the version number of this application
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.appVersion = function appVersion(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The version of the set of base data to be sent up
|
||||
* @returns {number} the version of the set of base data to be sent up
|
||||
* @overridable
|
||||
*/
|
||||
Base.prototype.baseVersion = function baseVersion() {
|
||||
return 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* A unique identifier for each event
|
||||
* @return {String}
|
||||
* @overridable
|
||||
*/
|
||||
Base.prototype.clientEventId = function clientEventId(callerSuppliedEventFields) {
|
||||
return (callerSuppliedEventFields && callerSuppliedEventFields.clientEventId) || cryptoRandomBase62String(true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Type of internet connection.
|
||||
* Only applicable to devices
|
||||
* Beware that users on WiFi may actually be receiving 3G speeds (i.e. if device is tethered to a portable hotspot.)
|
||||
* @example "WiFi, "3G, etc.
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String} type of internet connection
|
||||
* @overridable
|
||||
*/
|
||||
Base.prototype.connection = function connection(callerSuppliedEventFields) {
|
||||
return (callerSuppliedEventFields && callerSuppliedEventFields.connection) || this.environment().connectionType();
|
||||
};
|
||||
|
||||
/**
|
||||
* The identifier of the process generating the event, if different from “app”, or blank otherwise.
|
||||
* @example 'web-experience-app'
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.delegateApp = function delegateApp(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The id of this user ("directory service id").
|
||||
* This id will get mapped to a consumerId on the server.
|
||||
* @example 659261189
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Base.prototype.dsId = function dsId(callerSuppliedEventFields) {
|
||||
return (callerSuppliedEventFields && callerSuppliedEventFields.dsId) || this.environment().dsId();
|
||||
};
|
||||
|
||||
/**
|
||||
* The time (UTC) in milliseconds at which this event happened.
|
||||
* This field is central to determining the sequence of user events
|
||||
* Use online epoch converter to test your values.
|
||||
* @example 1437356433388 (http://www.epochconverter.com converts that to: July 19, 2015 at 6:40:33 PM PDT GMT-7:00 DST)
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {number} the time (UTC) in milliseconds at which this event happened
|
||||
* @overridable
|
||||
*/
|
||||
Base.prototype.eventTime = function eventTime(callerSuppliedEventFields) {
|
||||
return (callerSuppliedEventFields && callerSuppliedEventFields.eventTime) || Date.now();
|
||||
};
|
||||
|
||||
/**
|
||||
* The version of the set of data to be sent up
|
||||
* @return {Number}
|
||||
* @overridable
|
||||
*/
|
||||
Base.prototype.eventVersion = function eventVersion(callerSuppliedEventFields) {
|
||||
return (callerSuppliedEventFields && callerSuppliedEventFields.eventVersion) || null;
|
||||
};
|
||||
|
||||
/**
|
||||
* The hardware brand of the device. Not required for Apple devices.
|
||||
* @example "Samsung", "LG", "Google"
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.hardwareBrand = function hardwareBrand(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The hardware family of the device
|
||||
* @example "iPhone", "Macbook Pro"
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.hardwareFamily = function hardwareFamily(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The model of the device
|
||||
* @example "iPhone10,2", "MacbookPro11,5"
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.hardwareModel = function hardwareModel(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The name of the OS
|
||||
* @example "ios", "macos", "windows"
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.os = function os(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The build number of the OS
|
||||
* @example "15D60", "17E192"
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.osBuildNumber = function osBuildNumber(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* A string array of language IDs, ordered in descending preference
|
||||
* @example ["en-US", "fr-CA"]
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {Array}
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.osLanguages = function osLanguages(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The full OS version number
|
||||
* In ITML, the value can be retrieved via Device.systemVersion
|
||||
* @example "8.2.1" (iOS) "10.10.3" (Desktop)
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String} the full OS version number
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.osVersion = function osVersion(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The HTML resources revision number
|
||||
* @example 2C97 or 8.4.0.0.103
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String} the HTML resources revision number
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.resourceRevNum = function resourceRevNum(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The client screen height in pixels
|
||||
* @example 568
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {number} the client screen height in pixels
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.screenHeight = function screenHeight(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The client screen width in pixels
|
||||
* @example 320
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {number} the client screen width in pixels
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.screenWidth = function screenWidth(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* ISO 3166 Country Code. Apps that cannot provide a storeFrontHeader should provide a storeFrontCountryCode instead
|
||||
* @example US
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String} the store front country code
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.storeFrontCountryCode = function storeFrontCountryCode(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The value contained in the X-Apple-Store-Front header value at the time the event is being created.
|
||||
* @example K143441-1,29 ab:rSwnYxS0
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String} the value contained in the X-Apple-Store-Front header value at the time the event is being created
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.storeFrontHeader = function storeFrontHeader(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The difference, in minutes, between GMT (UTC) and timezone of event origin ("local time).
|
||||
* This means that the offset is positive if the local timezone is behind UTC and negative if it is ahead.
|
||||
* Daylight saving time prevents this value from being a constant, even for a given locale
|
||||
* @example 420 (PST, not -420) or -600 (Australian Eastern Standard Time, UTC+10)
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {number} the difference, in minutes, between GMT (UTC) and timezone of event origin ("local time).
|
||||
* @overridable
|
||||
*/
|
||||
Base.prototype.timezoneOffset = function timezoneOffset(callerSuppliedEventFields) {
|
||||
return (callerSuppliedEventFields && callerSuppliedEventFields.timezoneOffset) || new Date().getTimezoneOffset();
|
||||
};
|
||||
|
||||
/**
|
||||
* The client’s user agent string. If the "app field is not provided, "userAgent may be used to derive the value of the "app field
|
||||
* @example AppStore/2.0 iOS/8.3 model/iPhone7,2 build/12F70 (6; dt:106)
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String} the client’s user agent string. If the "app field is not provided, "userAgent may be used to derive the value of the "app field
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Base.prototype.userAgent = function userAgent(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* How often, in milliseconds, batches of events should get sent to the server.
|
||||
* This field should be based on the client's most recent config value of "postFrequency".
|
||||
* This is valuable for problem analysis because it indicates if and how clients are honoring the "postFrequency" value
|
||||
* they were supplied with.
|
||||
* This cannot be a "passthrough" field, because it can change (via new config) during program execution, so the value
|
||||
* in effect at event creation time is what is needed.
|
||||
* @example 60000
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {number} how often, in milliseconds, batches of events should get sent to the server
|
||||
* @overridable
|
||||
*/
|
||||
Base.prototype.xpPostFrequency = function xpPostFrequency(callerSuppliedEventFields) {
|
||||
return (
|
||||
(callerSuppliedEventFields && callerSuppliedEventFields.xpPostFrequency) ||
|
||||
this._processor.config.value('postFrequency')
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* The methodology being used by the eventRecorder to send batches of events to the server
|
||||
* This field should be hardcoded in the client based on what method it is using to encode and send its events to Figaro.
|
||||
* The three typical values are:
|
||||
* "itms" - use this value when/if JavaScript code enqueues events for sending via the "itms.recordEvent()" method in ITML.
|
||||
* "itunes" - use this value when/if JavaScript code enqueues events by calling the "iTunes.recordEvent()" method in Desktop Store apps.
|
||||
* "javascript" - use this value when/if JavaScript code enqueues events for sending via the JavaScript eventQueue management. This is typically only used by older clients which don't have the built-in functionality of itms or iTunes available to them.
|
||||
* @example "itms", "itunes", "javascript"
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String} the methodology being used by the eventRecorder to send batches of events to the server
|
||||
* @overridable
|
||||
*/
|
||||
Base.prototype.xpSendMethod = function (callerSuppliedEventFields) {
|
||||
return (callerSuppliedEventFields && callerSuppliedEventFields.xpSendMethod) || this.eventRecorder().sendMethod();
|
||||
};
|
||||
|
||||
/*
|
||||
* src/event_handlers/index.js
|
||||
* ae-client-kit-core
|
||||
*
|
||||
* Copyright © 2018 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
var eventHandlers = {
|
||||
Base: Base
|
||||
};
|
||||
|
||||
/*
|
||||
* src/system/Environment.js
|
||||
* ae-client-kit-core
|
||||
*
|
||||
* Copyright © 2018 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
var attachDelegate$1 = reflect.attachDelegate;
|
||||
var exceptionString$1 = string.exceptionString;
|
||||
var localStorageObject = storage.localStorageObject;
|
||||
var sessionStorageObject = storage.sessionStorageObject;
|
||||
|
||||
var _prototypeInitialized$1;
|
||||
|
||||
/**
|
||||
* Provides a set of environment-specific (platform-specific) functions which can be individually overridden for the needs
|
||||
* of the particular environment, or replaced en masse by providing a single replacement environment delegate object.
|
||||
* Kits can extend this class and additional methods specific to their event model.
|
||||
* @example
|
||||
* // MetricsKit code
|
||||
*
|
||||
* // extend kit-core Environment class
|
||||
* var MetricsKitEnvironment = function MetricsKitEnvironment() {
|
||||
* kitCore.system.Environment.apply(this, arguments); // invoke Environment constructor
|
||||
* };
|
||||
* MetricsKitEnvironment.prototype = new kitCore.system.Environment();
|
||||
* MetricsKitEnvironment.prototype.constructor = MetricsKitEnvironment;
|
||||
*
|
||||
* // add Kit-specific functions
|
||||
* MetricsKitEnvironment.prototype.dsId = function dsId() {
|
||||
* throw this._exceptionString(_utils.reflect.functionName());
|
||||
* };
|
||||
* MetricsKitEnvironment.prototype.anotherUserExperienceOnlyField = function() { ... };
|
||||
*
|
||||
* // create a Kit-specific class instance
|
||||
* metricsKit.system.environment = new MetricsKitEnvironment();
|
||||
*
|
||||
* // client app code remains unchanged:
|
||||
* var customEnvironmentDelegate = {
|
||||
* app: function() { return 'myAppName'; },
|
||||
* appVersion: function() { ... } // etc.
|
||||
* };
|
||||
*
|
||||
* metricsKit.system.environment.setDelegate(customEnvironmentDelegate);
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function Environment() {
|
||||
// consider moving this code into a separate init method
|
||||
if (!_prototypeInitialized$1) {
|
||||
_prototypeInitialized$1 = true;
|
||||
requiredEnvironmentBaseFieldNames().forEach(function (fieldName) {
|
||||
Environment.prototype[fieldName] = function () {
|
||||
throw exceptionString$1(Environment._className, fieldName);
|
||||
};
|
||||
});
|
||||
|
||||
optionalEnvironmentBaseFieldNames().forEach(function (fieldName) {
|
||||
Environment.prototype[fieldName] = function () {};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Environment._className = 'system.environment';
|
||||
|
||||
/**
|
||||
* Allows replacement of one or more of this class instance's functions
|
||||
* Any method on the passed-in object which matches a method that this class has will be called instead of the built-in class method.
|
||||
* To replace *all* methods of his class, simply have your delegate implement all the methods of this class
|
||||
* Your delegate can be a true object instance, an anonymous object, or a class object.
|
||||
* Your delegate is free to have as many additional non-matching methods as it likes (these methods will not be copied to the target object).
|
||||
* It can even act as a delegate for multiple MetricsKit objects, though that is not recommended.
|
||||
*
|
||||
* "setDelegate()" may be called repeatedly, with the functions in the most-recently set delegates replacing any functions matching those in the earlier delegates, as well as any as-yet unreplaced functions.
|
||||
* This allows callers to replace some number of methods that need custom implementations.
|
||||
* If, for example, a client wants to use the standard logger implementation with the exception of, say, the "debug" method, they can
|
||||
* call "setDelegate()" with their own delegate containing only a single method of "debug" as the delegate, which would leave all the other methods intact.
|
||||
*
|
||||
* NOTE: The delegate function will have a property called origFunction representing the original function that it replaced.
|
||||
* This allows the delegate to, essentially, call "super" before or after it does some work.
|
||||
* If a replaced method is overridden again with a subsequent "setDelegate()" call, the "origFunction" property will be the previous delegate's function.
|
||||
* @example:
|
||||
* To override one or more methods, in place:
|
||||
* environment.setDelegate({ app: function() { return 'myApp'; });
|
||||
* To override one or more methods with a separate object:
|
||||
* environment.setDelegate(customEnvironmentDelegate);
|
||||
* (where "customEnvironmentDelegate" might be defined elsewhere as, e.g.:
|
||||
* var customEnvironmentDelegate = { app: function() { return Device.appIdentifier; },
|
||||
* appVersion: function() { return Device.appVersion; } };
|
||||
* To override one or more methods with an instantiated object from a class definition:
|
||||
* environment.setDelegate(new CustomEnvironmentDelegate());
|
||||
* (where "CustomEnvironmentDelegate" might be defined elsewhere as, e.g.:
|
||||
* function CustomEnvironmentDelegate() {}
|
||||
* CustomEnvironmentDelegate.prototype.app = function app() { return Device.appIdentifier; };
|
||||
* CustomEnvironmentDelegate.prototype.appVersion = function appVersion() { return Device.appVersion; };
|
||||
* To override one or more methods with a class object (with "static" methods):
|
||||
* environment.setDelegate(CustomEnvironmentDelegate);
|
||||
* (where "CustomEnvironmentDelegate" might be defined elsewhere as, e.g.:
|
||||
* function CustomEnvironmentDelegate() {}
|
||||
* CustomEnvironmentDelegate.app = function app() { return Device.appIdentifier; };
|
||||
* CustomEnvironmentDelegate.appVersion = function appVersion() { return Device.appVersion; };
|
||||
* @param {Object} delegate Object or Class with delegate method(s) to be called instead of default (built-in) methods.
|
||||
* @returns {Boolean} true if one or more methods on the delegate object match one or more methods on the default object,
|
||||
* otherwise returns false.
|
||||
*/
|
||||
Environment.prototype.setDelegate = function setDelegate(delegate) {
|
||||
return attachDelegate$1(this, delegate);
|
||||
};
|
||||
|
||||
/**
|
||||
* The app identifier of the binary app
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example "com.apple.appstore" or "com.apple.gamecenter"
|
||||
* @returns {String}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.app = function app() { };
|
||||
|
||||
/**
|
||||
* The version number of this application
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example "1.0", "5.43", etc.
|
||||
* @returns {String}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.appVersion = function appVersion() { };
|
||||
|
||||
/**
|
||||
* Type of internet connection.
|
||||
* Only applicable to devices
|
||||
* Beware that users on WiFi may actually be receiving 3G speeds (i.e. if device is tethered to a portable hotspot.)
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example "WiFi, "3G, etc.
|
||||
* @returns {String}
|
||||
*/
|
||||
Environment.prototype.connectionType = function connectionType() {
|
||||
// Don't wrap the throw in a helper function or the backtrace won't be as nice.
|
||||
// TODO: use a constant instead of a hardcoded string
|
||||
throw exceptionString$1(Environment._className, 'connectionType');
|
||||
};
|
||||
|
||||
/**
|
||||
* The identifier of the process generating the event, if different from “app”, or blank otherwise.
|
||||
* NO DEFAULT IMPLEMENTATION... HOWEVER: these fields are not required, so an exception will not be thrown if they
|
||||
* are omitted.
|
||||
* @example 'web-experience-app'
|
||||
* @returns {String}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.delegateApp = function delegateApp(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The id of this user ("directory service id").
|
||||
* This id will get mapped to a consumerId on the server.
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example 659261189
|
||||
* @returns {String}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
Environment.prototype.dsId = function dsId() {
|
||||
// Don't throw an exception to avoid breaking minor version backwards compatibility.
|
||||
// Consider adding an exception in the next major version.
|
||||
};
|
||||
|
||||
/**
|
||||
* The hardware brand of the device. Not required for Apple devices.
|
||||
* NO DEFAULT IMPLEMENTATION... HOWEVER: these fields are not required, so an exception will not be thrown if they
|
||||
* are omitted.
|
||||
* @example "Samsung", "LG", "Google"
|
||||
* @returns {String}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.hardwareBrand = function hardwareBrand() { };
|
||||
|
||||
/**
|
||||
* The hardware family of the device
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example "iPhone", "Macbook Pro"
|
||||
* @returns {String}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.hardwareFamily = function hardwareFamily() { };
|
||||
|
||||
/**
|
||||
* The model of the device
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example "iPhone10,2", "MacbookPro11,5"
|
||||
* @returns {String}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.hardwareModel = function hardwareModel() { };
|
||||
|
||||
/**
|
||||
* The name of the OS
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example "ios", "macos", "windows"
|
||||
* @returns {String}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.os = function os() { };
|
||||
|
||||
/**
|
||||
* The build number of the OS
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example "15D60", "17E192"
|
||||
* @returns {String}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.osBuildNumber = function osBuildNumber() { };
|
||||
|
||||
/**
|
||||
* A string array of language IDs, ordered in descending preference
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example ["en-US", "fr-CA"]
|
||||
* @returns {Array}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.osLanguages = function osLanguages() { };
|
||||
|
||||
/**
|
||||
* The full OS version number
|
||||
* In ITML, the value can be retrieved via Device.systemVersion
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example "8.2.1" (iOS) "10.10.3" (Desktop)
|
||||
* @returns {String}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.osVersion = function osVersion() { };
|
||||
|
||||
/**
|
||||
* HTML resources revision number
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example 2C97 or 8.4.0.0.103
|
||||
* @returns {String}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.resourceRevNum = function resourceRevNum() { };
|
||||
|
||||
/**
|
||||
* Client screen height in pixels
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example 568
|
||||
* @returns {number}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.screenHeight = function screenHeight() { };
|
||||
|
||||
/**
|
||||
* Client screen width in pixels
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example 320
|
||||
* @returns {number}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.screenWidth = function screenWidth() { };
|
||||
|
||||
/**
|
||||
* ISO 3166 Country Code. Apps that cannot provide a storeFrontHeader should provide a storeFrontCountryCode instead
|
||||
* NO DEFAULT IMPLEMENTATION... Either this method or storeFrontHeader must be replaced.
|
||||
* are omitted.
|
||||
* @example US
|
||||
* @param {Map} callerSuppliedEventFields
|
||||
* @returns {String} the store front country code
|
||||
* @overridable
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.storeFrontCountryCode = function storeFrontCountryCode(callerSuppliedEventFields) { };
|
||||
|
||||
/**
|
||||
* The value contained in the X-Apple-Store-Front header value at the time the event is being created.
|
||||
* NO DEFAULT IMPLEMENTATION... Either this method or storeFrontHeader must be replaced.
|
||||
* @example K143441-1,29 ab:rSwnYxS0
|
||||
* @returns {String}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.storeFrontHeader = function storeFrontHeader() { };
|
||||
|
||||
/**
|
||||
* Client’s user agent string. If the "app field is not provided, "userAgent may be used to derive the value of the "app field
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example AppStore/2.0 iOS/8.3 model/iPhone7,2 build/12F70 (6; dt:106)
|
||||
* @returns {String}
|
||||
*/
|
||||
// This prototype method is created dynamically upon instance initialization
|
||||
// Environment.prototype.userAgent = function userAgent() { };
|
||||
|
||||
/**
|
||||
* Some clients have platform-specific implementations of these objects (e.g. iTunes.sessionStorage),
|
||||
* so we cover them in case they need to be overridden.
|
||||
*/
|
||||
Environment.prototype.localStorageObject = localStorageObject;
|
||||
Environment.prototype.sessionStorageObject = sessionStorageObject;
|
||||
|
||||
/**
|
||||
* Fetching identifier entity from AMS Metrics Identifier API
|
||||
* @param {String} idNamespace - The id namespace that is defined under 'metricsIdentifier' in the bag
|
||||
* @param {'userid' | 'clientid'} idType - The identifier type (userid or clientid)
|
||||
* @param {Boolean} crossDeviceSync - The boolean flag to indicate whether the identifier is synced across devices
|
||||
* @returns {Promise}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.platformIdentifier = function platformIdentifier() {};
|
||||
|
||||
/*
|
||||
* src/system/index.js
|
||||
* ae-client-kit-core
|
||||
*
|
||||
* Copyright © 2018 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
var system = {
|
||||
Environment: Environment
|
||||
};
|
||||
|
||||
/*
|
||||
* src/helpers/MetricsData.js
|
||||
* ae-client-kit-core
|
||||
*
|
||||
* Copyright © 2018 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates and returns a MetricsData instance with APIs to store event data and create and send events to AMP Analytics
|
||||
* @delegatable
|
||||
* @constructor
|
||||
* @return {MetricsData}
|
||||
*/
|
||||
function MetricsData() {
|
||||
// @private
|
||||
this._eventData = {}; // this data may be unclean; it should be cleaned before being enqueued as an event
|
||||
}
|
||||
|
||||
/**
|
||||
************************************ PUBLIC METHODS/IVARS ************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add event data to this metricsData object
|
||||
* This data may be unclean; it should be cleaned before being enqueued as an event
|
||||
* @param {Object<varargs>} callerSuppliedEventFieldsMapN a variable number of Object arguments from 0-N,
|
||||
* each containing key/value pairs representing event fields to include when sending the event.
|
||||
* Later objects take precedence over earlier ones, overriding any field value that may have already been there.
|
||||
* @overridable
|
||||
*/
|
||||
MetricsData.prototype.updateData = function updateData(/* callerSuppliedEventFieldsMapN(varargs) */) {
|
||||
reflect.extend.apply(null, [this._eventData].concat(Array.prototype.slice.call(arguments)));
|
||||
};
|
||||
|
||||
/*
|
||||
* src/helpers/index.js
|
||||
* ae-client-kit-core
|
||||
*
|
||||
* Copyright © 2018 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
var helpers = {
|
||||
MetricsData: MetricsData
|
||||
};
|
||||
|
||||
export { eventHandlers, helpers, system };
|
||||
987
shared/metrics-8/node_modules/@amp-metrics/mt-client-config/dist/mt-client-config.esm.js
generated
vendored
Normal file
987
shared/metrics-8/node_modules/@amp-metrics/mt-client-config/dist/mt-client-config.esm.js
generated
vendored
Normal file
@@ -0,0 +1,987 @@
|
||||
import { storage, reflect, network, keyValue, number } from '@amp-metrics/mt-metricskit-utils-private';
|
||||
import Logger from '@amp-metrics/mt-client-logger-core';
|
||||
|
||||
/*
|
||||
* src/environment.js
|
||||
* mt-client-config
|
||||
*
|
||||
* Copyright © 2016-2017 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides a set of environment-specific (platform-specific) functions which can be individually overridden for the needs
|
||||
* of the particular environment, or replaced en masse by providing a single replacement environment delegate object
|
||||
* The functionality in this class is typically replaced via a delegate.
|
||||
* @see setDelegate
|
||||
* @delegatable
|
||||
* @constructor
|
||||
*/
|
||||
var Environment = function () {};
|
||||
|
||||
/**
|
||||
************************************ PUBLIC METHODS/IVARS ************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows replacement of one or more of this class' functions
|
||||
* Any method on the passed-in object which matches a method that this class has will be called instead of the built-in class method.
|
||||
* To replace *all* methods of his class, simply have your delegate implement all the methods of this class
|
||||
* Your delegate can be a true object instance, an anonymous object, or a class object.
|
||||
* Your delegate is free to have as many additional non-matching methods as it likes.
|
||||
* It can even act as a delegate for multiple MetricsKit objects, though that is not recommended.
|
||||
*
|
||||
* "setDelegate()" may be called repeatedly, with the functions in the most-recently set delegates replacing any functions matching those in the earlier delegates, as well as any as-yet unreplaced functions.
|
||||
* This allows callers to use "canned" delegates to get most of their functionality, but still replace some number of methods that need custom implementations.
|
||||
* If, for example, a client wants to use the "canned" itml/environment delegate with the exception of, say, the "appVersion" method, they can set itml/environment as the delegate, and
|
||||
* then call "setDelegate()" again with their own delegate containing only a single method of "appVersion" as the delegate, which would leave all the other "replaced" methods intact,
|
||||
* but override the "appVersion" method again, this time with their own supplied delegate.
|
||||
*
|
||||
* NOTE: The delegate function will have a property called origFunction representing the original function that it replaced.
|
||||
* This allows the delegate to, essentially, call "super" before or after it does some work.
|
||||
* If a replaced method is overridden again with a subsequent "setDelegate()" call, the "origFunction" property will be the previous delegate's function.
|
||||
* @example:
|
||||
* To override one or more methods, in place:
|
||||
* eventRecorder.setDelegate({recordEvent: itms.recordEvent});
|
||||
* To override one or more methods with a separate object:
|
||||
* eventRecorder.setDelegate(eventRecorderDelegate);
|
||||
* (where "eventRecorderDelegate" might be defined elsewhere as, e.g.:
|
||||
* var eventRecorderDelegate = {recordEvent: itms.recordEvent,
|
||||
* sendMethod: 'itms'};
|
||||
* To override one or more methods with an instantiated object from a class definition:
|
||||
* eventRecorder.setDelegate(new EventRecorderDelegate());
|
||||
* (where "EventRecorderDelegate" might be defined elsewhere as, e.g.:
|
||||
* function EventRecorderDelegate() {
|
||||
* }
|
||||
* EventRecorderDelegate.prototype.recordEvent = itms.recordEvent;
|
||||
* EventRecorderDelegate.prototype.sendMethod = function sendMethod() {
|
||||
* return 'itms';
|
||||
* };
|
||||
* To override one or more methods with a class object (with "static" methods):
|
||||
* eventRecorder.setDelegate(EventRecorderDelegate);
|
||||
* (where "EventRecorderDelegate" might be defined elsewhere as, e.g.:
|
||||
* function EventRecorderDelegate() {
|
||||
* }
|
||||
* EventRecorderDelegate.recordEvent = itms.recordEvent;
|
||||
* EventRecorderDelegate.sendMethod = function sendMethod() {
|
||||
* return 'itms';
|
||||
* };
|
||||
* @param {Object} Object or Class with delegate method(s) to be called instead of default (built-in) methods.
|
||||
* @returns {Boolean} true if one or more methods on the delegate object match one or more methods on the default object,
|
||||
* otherwise returns false.
|
||||
*/
|
||||
Environment.prototype.setDelegate = function setDelegate(delegate) {
|
||||
return reflect.attachDelegate(this, delegate);
|
||||
};
|
||||
|
||||
Environment.prototype.localStorageObject = storage.localStorageObject;
|
||||
Environment.prototype.sessionStorageObject = storage.sessionStorageObject;
|
||||
|
||||
/*
|
||||
* src/network.js
|
||||
* mt-client-config
|
||||
*
|
||||
* Copyright © 2018 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Network request methods exposed so delegate callers can override
|
||||
* @constructor
|
||||
*/
|
||||
var Network = function () {};
|
||||
|
||||
/**
|
||||
* Allows replacement of one or more of this class' functions
|
||||
* Any method on the passed-in object which matches a method that this class has will be called instead of the built-in class method.
|
||||
* To replace *all* methods of his class, simply have your delegate implement all the methods of this class
|
||||
* Your delegate can be a true object instance, an anonymous object, or a class object.
|
||||
* Your delegate is free to have as many additional non-matching methods as it likes.
|
||||
* It can even act as a delegate for multiple MetricsKit objects, though that is not recommended.
|
||||
*
|
||||
* "setDelegate()" may be called repeatedly, with the functions in the most-recently set delegates replacing any functions matching those in the earlier delegates, as well as any as-yet unreplaced functions.
|
||||
* This allows callers to use "canned" delegates to get most of their functionality, but still replace some number of methods that need custom implementations.
|
||||
* If, for example, a client wants to use the "canned" itml/environment delegate with the exception of, say, the "appVersion" method, they can set itml/environment as the delegate, and
|
||||
* then call "setDelegate()" again with their own delegate containing only a single method of "appVersion" as the delegate, which would leave all the other "replaced" methods intact,
|
||||
* but override the "appVersion" method again, this time with their own supplied delegate.
|
||||
*
|
||||
* NOTE: The delegate function will have a property called origFunction representing the original function that it replaced.
|
||||
* This allows the delegate to, essentially, call "super" before or after it does some work.
|
||||
* If a replaced method is overridden again with a subsequent "setDelegate()" call, the "origFunction" property will be the previous delegate's function.
|
||||
* @example:
|
||||
* To override one or more methods, in place:
|
||||
* eventRecorder.setDelegate({recordEvent: itms.recordEvent});
|
||||
* To override one or more methods with a separate object:
|
||||
* eventRecorder.setDelegate(eventRecorderDelegate);
|
||||
* (where "eventRecorderDelegate" might be defined elsewhere as, e.g.:
|
||||
* var eventRecorderDelegate = {recordEvent: itms.recordEvent,
|
||||
* sendMethod: 'itms'};
|
||||
* To override one or more methods with an instantiated object from a class definition:
|
||||
* eventRecorder.setDelegate(new EventRecorderDelegate());
|
||||
* (where "EventRecorderDelegate" might be defined elsewhere as, e.g.:
|
||||
* function EventRecorderDelegate() {
|
||||
* }
|
||||
* EventRecorderDelegate.prototype.recordEvent = itms.recordEvent;
|
||||
* EventRecorderDelegate.prototype.sendMethod = function sendMethod() {
|
||||
* return 'itms';
|
||||
* };
|
||||
* To override one or more methods with a class object (with "static" methods):
|
||||
* eventRecorder.setDelegate(EventRecorderDelegate);
|
||||
* (where "EventRecorderDelegate" might be defined elsewhere as, e.g.:
|
||||
* function EventRecorderDelegate() {
|
||||
* }
|
||||
* EventRecorderDelegate.recordEvent = itms.recordEvent;
|
||||
* EventRecorderDelegate.sendMethod = function sendMethod() {
|
||||
* return 'itms';
|
||||
* };
|
||||
* @param {Object} Object or Class with delegate method(s) to be called instead of default (built-in) methods.
|
||||
* @returns {Boolean} true if one or more methods on the delegate object match one or more methods on the default object,
|
||||
* otherwise returns false.
|
||||
*/
|
||||
Network.prototype.setDelegate = function setDelegate(delegate) {
|
||||
return reflect.attachDelegate(this, delegate);
|
||||
};
|
||||
|
||||
/**
|
||||
* Covers private utils implementation of makeAjaxRequest for delegation
|
||||
*/
|
||||
Network.prototype.makeAjaxRequest = network.makeAjaxRequest;
|
||||
|
||||
/*
|
||||
* src/config.js
|
||||
* mt-client-config
|
||||
*
|
||||
* Copyright © 2016-2017 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
var NO_TOPIC_KEY = 'noTopicConfig';
|
||||
var COMPOUND_SEPARATOR = '_';
|
||||
|
||||
/**
|
||||
* The default config should not include keys which have meaning if they are omitted.
|
||||
* For example, a configSource without impressions means no impressions should be recorded, and in this case we should
|
||||
* not have impressions in defaults so we don't inadvertently disobey the client's configSource.
|
||||
*/
|
||||
var DEFAULTS = {
|
||||
configBaseUrl: 'https://xp.apple.com/config/1/report',
|
||||
disabled: true // Prevent sending event if no config is available
|
||||
};
|
||||
|
||||
// @private
|
||||
var _defaultConfig;
|
||||
|
||||
/**
|
||||
* Appends the provided source and its subsection if the subsection key matches the provided topic to the provided configSources array.
|
||||
* @param {Array} configSources
|
||||
* @param {String} topic
|
||||
* @param {Object} source
|
||||
*/
|
||||
var _appendSectionAndSubsectionToConfigSources = function _appendSectionAndSubsectionToConfigSources(
|
||||
configSources,
|
||||
topic,
|
||||
source
|
||||
) {
|
||||
if (source) {
|
||||
configSources.push(source);
|
||||
var subsection = source[topic];
|
||||
if (subsection && reflect.hasAnyKeys(subsection)) {
|
||||
configSources.push(subsection);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides config-related functionality including managing config sources and values.
|
||||
* The functionality in this class is typically replaced via a delegate.
|
||||
* @see setDelegate
|
||||
* @delegatable
|
||||
* @constructor
|
||||
* @param {String} topic
|
||||
*/
|
||||
var Config = function Config(topic) {
|
||||
// @public
|
||||
this.environment = new Environment();
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated
|
||||
*/
|
||||
this.network = new Network();
|
||||
|
||||
// @public
|
||||
this.logger = /*#__PURE__*/ new Logger('mt-client-config');
|
||||
|
||||
// @private
|
||||
this._topic = topic || NO_TOPIC_KEY;
|
||||
|
||||
// @private
|
||||
this._debugSource = null;
|
||||
// @private
|
||||
this._cachedSource = null;
|
||||
// @private
|
||||
this._serviceSource = null;
|
||||
// @private
|
||||
this._initCalled = false;
|
||||
// @private
|
||||
this._initialized = false;
|
||||
// @private
|
||||
this._showedDebugWarning = false;
|
||||
// @private
|
||||
this._showedNoProvidedSourceWarning = false;
|
||||
// @private
|
||||
this._keyPathsThatSuppressWarning = {
|
||||
configBaseUrl: true // used to fetch a config source, so we do not expect sources to be set when retrieving this value
|
||||
};
|
||||
// @private
|
||||
this._configFetchPromise = null;
|
||||
|
||||
// @const
|
||||
this.DEBUG_SOURCE_KEY = 'mtClientConfig_debugSource' + COMPOUND_SEPARATOR + this._topic;
|
||||
// @const
|
||||
this.CACHED_SOURCE_KEY = 'mtClientConfig_cachedSource' + COMPOUND_SEPARATOR + this._topic;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {Config} the default config instance, which is not associated with any topic
|
||||
*/
|
||||
Config.defaultConfig = function defaultConfig() {
|
||||
if (!_defaultConfig) {
|
||||
_defaultConfig = new Config(NO_TOPIC_KEY);
|
||||
}
|
||||
return _defaultConfig;
|
||||
};
|
||||
|
||||
/**
|
||||
************************************ PSEUDO-PRIVATE METHODS/IVARS ************************************
|
||||
* These functions need to be accessible for ease of testing, but should not be used by clients
|
||||
*/
|
||||
Config.prototype._defaults = function _defaults() {
|
||||
return DEFAULTS;
|
||||
};
|
||||
|
||||
Config.prototype._setInitialized = function _setInitialized(initialized) {
|
||||
this._initialized = initialized;
|
||||
};
|
||||
|
||||
Config.prototype._setInitCalled = function _setInitCalled(initCalled) {
|
||||
this._initCalled = initCalled;
|
||||
};
|
||||
|
||||
Config.prototype._setShowedDebugWarning = function _setShowedDebugWarning(value) {
|
||||
this._showedDebugWarning = value;
|
||||
};
|
||||
|
||||
Config.prototype._setShowedNoProvidedSourceWarning = function _setShowedNoProvidedSourceWarning(value) {
|
||||
this._showedNoProvidedSourceWarning = value;
|
||||
};
|
||||
|
||||
/**
|
||||
************************************ PUBLIC METHODS ************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows replacement of one or more of this class' functions
|
||||
* Any method on the passed-in object which matches a method that this class has will be called instead of the built-in class method.
|
||||
* To replace *all* methods of his class, simply have your delegate implement all the methods of this class
|
||||
* Your delegate can be a true object instance, an anonymous object, or a class object.
|
||||
* Your delegate is free to have as many additional non-matching methods as it likes.
|
||||
* It can even act as a delegate for multiple MetricsKit objects, though that is not recommended.
|
||||
*
|
||||
* "setDelegate()" may be called repeatedly, with the functions in the most-recently set delegates replacing any functions matching those in the earlier delegates, as well as any as-yet unreplaced functions.
|
||||
* This allows callers to use "canned" delegates to get most of their functionality, but still replace some number of methods that need custom implementations.
|
||||
* If, for example, a client wants to use the "canned" itml/environment delegate with the exception of, say, the "appVersion" method, they can set itml/environment as the delegate, and
|
||||
* then call "setDelegate()" again with their own delegate containing only a single method of "appVersion" as the delegate, which would leave all the other "replaced" methods intact,
|
||||
* but override the "appVersion" method again, this time with their own supplied delegate.
|
||||
*
|
||||
* NOTE: The delegate function will have a property called origFunction representing the original function that it replaced.
|
||||
* This allows the delegate to, essentially, call "super" before or after it does some work.
|
||||
* If a replaced method is overridden again with a subsequent "setDelegate()" call, the "origFunction" property will be the previous delegate's function.
|
||||
* @example:
|
||||
* To override one or more methods, in place:
|
||||
* eventRecorder.setDelegate({recordEvent: itms.recordEvent});
|
||||
* To override one or more methods with a separate object:
|
||||
* eventRecorder.setDelegate(eventRecorderDelegate);
|
||||
* (where "eventRecorderDelegate" might be defined elsewhere as, e.g.:
|
||||
* var eventRecorderDelegate = {recordEvent: itms.recordEvent,
|
||||
* sendMethod: 'itms'};
|
||||
* To override one or more methods with an instantiated object from a class definition:
|
||||
* eventRecorder.setDelegate(new EventRecorderDelegate());
|
||||
* (where "EventRecorderDelegate" might be defined elsewhere as, e.g.:
|
||||
* function EventRecorderDelegate() {
|
||||
* }
|
||||
* EventRecorderDelegate.prototype.recordEvent = itms.recordEvent;
|
||||
* EventRecorderDelegate.prototype.sendMethod = function sendMethod() {
|
||||
* return 'itms';
|
||||
* };
|
||||
* To override one or more methods with a class object (with "static" methods):
|
||||
* eventRecorder.setDelegate(EventRecorderDelegate);
|
||||
* (where "EventRecorderDelegate" might be defined elsewhere as, e.g.:
|
||||
* function EventRecorderDelegate() {
|
||||
* }
|
||||
* EventRecorderDelegate.recordEvent = itms.recordEvent;
|
||||
* EventRecorderDelegate.sendMethod = function sendMethod() {
|
||||
* return 'itms';
|
||||
* };
|
||||
* @param {Object} Object or Class with delegate method(s) to be called instead of default (built-in) methods.
|
||||
* @returns {Boolean} true if one or more methods on the delegate object match one or more methods on the default object,
|
||||
* otherwise returns false.
|
||||
*/
|
||||
Config.prototype.setDelegate = function setDelegate(delegate) {
|
||||
return reflect.attachDelegate(this, delegate);
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset the attached delegates from
|
||||
* @param delegate
|
||||
*/
|
||||
Config.prototype.resetDelegate = function resetDelegate() {
|
||||
// reset the delegates from environment, network and logger
|
||||
reflect.detachMethods(this);
|
||||
// Detach the attached methods from prototype(source, debugSource and attached utility methods from mt-metricskit-utils-private, etc.) of the config instance
|
||||
reflect.resetDelegates(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {String} the Figaro topic that this config corresponds with
|
||||
* Most clients do not need to override this method
|
||||
*/
|
||||
Config.prototype.topic = function topic() {
|
||||
return this._topic;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the metrics config endpoint hostname
|
||||
* Most clients do not need to override this method
|
||||
* @deprecated
|
||||
* @return {String} a hostname e.g.xp.apple.com
|
||||
*/
|
||||
Config.prototype.configHostname = function configHostname() {};
|
||||
|
||||
/**
|
||||
* Returns a constructed URL to the metrics config endpoint for use with getConfig()
|
||||
* Most clients do not need to override this method
|
||||
* @deprecated
|
||||
* @return {Promise} A Promise with a URL to the metrics config endpoint e.g. https://xp.apple.com/config/1/report/xp_its_main
|
||||
*/
|
||||
Config.prototype.configUrl = function configUrl() {
|
||||
var configHostname = this.configHostname();
|
||||
var returnUrlPromise;
|
||||
|
||||
if (configHostname) {
|
||||
returnUrlPromise = Promise.resolve('https://' + configHostname + '/config/1/report');
|
||||
} else {
|
||||
returnUrlPromise = this.value('configBaseUrl');
|
||||
}
|
||||
|
||||
return returnUrlPromise.then(
|
||||
function (returnUrl) {
|
||||
if (this._topic !== NO_TOPIC_KEY) {
|
||||
returnUrl += '/' + this.topic();
|
||||
} else {
|
||||
this.logger.error('config.configUrl(): Topic must be provided');
|
||||
}
|
||||
return returnUrl;
|
||||
}.bind(this)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* This function will be used to access all of the sources for configuration data (e.g. disabled, blacklistedEvents, fieldsMap, etc.)
|
||||
* THIS METHOD MUST BE PROVIDED BY A DELEGATE
|
||||
* Returns an array of key/value objects (dictionaries) for all of the config sources (e.g. the bag, the page, the control parent, etc.).
|
||||
* This method will be called frequently and repeatedly from the metrics.config.* functions.
|
||||
* MetricsKit will use this return value to traverse the list of config objects, looking for config values.
|
||||
* If later dictionaries of key/value pairs contain any keys already collected, the most late (farthest in the area) config value will overwrite earlier ones.
|
||||
* IMPORTANT: This function might be called frequently and repeatedly so should be optimized for performance.
|
||||
* It will be called frequently (rather than having this API provide a "setConfig" method for permanently setting the config values) since
|
||||
* these config values can always be changing from one call to the next, so this ensures that they are current.
|
||||
* THEREFORE: This function should NOT try to "simplify" by, e.g., merging all config sources into a single object to return when called.
|
||||
* Doing so is an enormous amount of work to do each time MetricsKit needs to look up a single value.
|
||||
* It is far more efficient for MetricsKit to simply interogate each configSource for the required key, rather than
|
||||
* the delegate function merging *all* keys of *all* sources (looping through all values of all sources) in order to look up a single value.
|
||||
* @example var sources = function() { return [itms.getBag().metrics, pageData.metrics.config]; }; // return an array of sources of app config
|
||||
* @example var sources = function() { return metrics.utils.keyValue.sourcesArray(itms.getBag().metrics, pageData.metrics.config, swooshData.metrics.config); }; // Let MetricsKit help build the array from a varargs list of sources
|
||||
* @example var sources = function() { return metrics.utils.keyValue.sourcesArray(existingArrayOfConfigSources, pageData.metrics.config, swooshData.metrics.config); }; // Let MetricsKit help build the array from a varargs list of sources where some args are already arrays of other sources (only works one level deep)
|
||||
* @see metrics.system.configSources.sources for simple creation of the return value of config sources.
|
||||
*/
|
||||
Config.prototype.sources = function sources() {};
|
||||
|
||||
/**
|
||||
* Search through the configuration sources provided by "metrics.system.configSources()", looking for the highest precedence value for "key"
|
||||
* If no config sources provided, look for values in the DEFAULTS constant
|
||||
* "keypath" can be a simple top-level config key such as "postFrequency" or a compound "path", such as fieldsMap.cookies
|
||||
* @param {String} keyPath the dot-separated (".") path to the desired config value.
|
||||
* @param {String} (optional) topic an 'override' topic which will override the main topic.
|
||||
* @returns {Promise} A Promise of the value at the reached keypath. Returns "null" if the key or key's value is not found.
|
||||
* Values found in later (farthest in array) dictionaries of key/value pairs overwrite earlier dictionaries.
|
||||
* @see metrics.system.configSources.setDelegate()
|
||||
*/
|
||||
Config.prototype.value = function value(keyPath, topic) {
|
||||
var getConfigValueFn = function () {
|
||||
var cachedSource = this.cachedSource();
|
||||
var serviceSource = this.serviceSource();
|
||||
var configSourcesArray = this.sources();
|
||||
var savedDebugSource = this.debugSource(); // NOTE: Always go through the accessor method, since it may need to be retrieved from localStorage
|
||||
var sourceProvided = cachedSource || serviceSource || configSourcesArray || savedDebugSource;
|
||||
var sourcesToCheck;
|
||||
|
||||
// show relevant warnings
|
||||
if (!configSourcesArray && !serviceSource && !(keyPath in this._keyPathsThatSuppressWarning)) {
|
||||
if (!this._showedNoProvidedSourceWarning) {
|
||||
this._showedNoProvidedSourceWarning = true;
|
||||
this.logger.warn(
|
||||
'Metrics config: No config provided via delegate or fetched via init(), using cached config values.'
|
||||
);
|
||||
}
|
||||
}
|
||||
if (savedDebugSource) {
|
||||
if (!this._showedDebugWarning) {
|
||||
// We do this in case developers forget to clear this and wonder why the app isn't working correctly in normal running.
|
||||
this._showedDebugWarning = true;
|
||||
this.logger.warn(
|
||||
'"debugSource" found.\nThis will override any same-named client-supplied configSource fields.\nThis setting "sticks" across session, use "setDebugSource(null)" to clear'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!reflect.isArray(configSourcesArray)) {
|
||||
configSourcesArray = [configSourcesArray];
|
||||
}
|
||||
|
||||
// disable the event only if there are no provided sources
|
||||
// In case of fetch config failed and no cached config in local
|
||||
if (keyPath === 'disabled') {
|
||||
if (sourceProvided) {
|
||||
sourcesToCheck = [cachedSource, serviceSource, configSourcesArray, savedDebugSource];
|
||||
} else {
|
||||
sourcesToCheck = [DEFAULTS];
|
||||
}
|
||||
} else {
|
||||
// For non-disabling rules, check all sources
|
||||
// Let "DEFAULTS" be overwritten by cachedSource, then serviceSource, then client-supplied configSources,
|
||||
// and then let "savedDebugSource" overwrite everyone
|
||||
sourcesToCheck = [DEFAULTS, cachedSource, serviceSource, configSourcesArray, savedDebugSource];
|
||||
}
|
||||
|
||||
sourcesToCheck = this.configSourcesWithOverrides(sourcesToCheck, topic || this.topic());
|
||||
// Pass each source as an individual argument; valueForKeyPath won't expand configSourcesArray if it is nested in sourcesToCheck
|
||||
return keyValue.valueForKeyPath.apply(null, [keyPath].concat(sourcesToCheck));
|
||||
}.bind(this);
|
||||
|
||||
if (this._configFetchPromise) {
|
||||
return this._configFetchPromise.then(getConfigValueFn);
|
||||
} else {
|
||||
var value = getConfigValueFn();
|
||||
return Promise.resolve(value);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Pushes any subsections within a config source to the front of the provided config sources array if the subsection key matches with the specified topic.
|
||||
* This method is used by the default implementation of 'value(keyPath)' to determine precedence
|
||||
* of config sources for the given topic.
|
||||
* Subsections that are later in the array will take precedence over earlier subsections.
|
||||
* Note that if one of the config sources is an array, this method will traverse one level deep
|
||||
* to check for the presence of a dictionary that may contain a desired subsection.
|
||||
* We traverse one level deep to maintain parity with _utils.keyValue.valueForKeyPath() which will be used to traverse the config sources
|
||||
* @param {Array} configSources
|
||||
* @param {String} topic
|
||||
* @returns {Array} returnSources
|
||||
*/
|
||||
Config.prototype.configSourcesWithOverrides = function configSourcesWithOverrides(configSources, topic) {
|
||||
var returnSources = configSources;
|
||||
if (configSources && configSources.length && topic) {
|
||||
returnSources = [];
|
||||
for (var i = 0; i < configSources.length; i++) {
|
||||
var source = configSources[i];
|
||||
if (source) {
|
||||
if (reflect.isArray(source) && source.length) {
|
||||
var subarray = [];
|
||||
for (var j = 0; j < source.length; j++) {
|
||||
_appendSectionAndSubsectionToConfigSources(subarray, topic, source[j]);
|
||||
}
|
||||
returnSources.push(subarray);
|
||||
} else {
|
||||
_appendSectionAndSubsectionToConfigSources(returnSources, topic, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnSources;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set's a "priority" configSource that will override any same-named client-supplied configSource fields.
|
||||
* This can be done in code (e.g. in testcases) or, more typically, in Web Inspector when debugging or testing a running app (client) using MetricsKit.
|
||||
* This is useful when testing, both in testcases and at runtime. One example would be to set a temporary "bag" structure that could then be tweaked at will, e.g. blacklisting fields, etc.
|
||||
* This setting "sticks" across session so that it can be set, the app restarted, and the values will be present at the earliest runnings of the app.
|
||||
* Use "setDebugSource(null)" to clear this value
|
||||
* NOTE: If no "localStorage" is available (e.g. when testing), this value will only last for the session or until it is explicitly cleared.
|
||||
* Here is an example of how to use this to test an app at runtime (and/or launch time)
|
||||
* Run the app
|
||||
* Open Web Inspector
|
||||
* Set a variable to bag contents, e.g. var debugBag = itms.getBag();
|
||||
* Call: metrics.config.setDebugSource(debugBag.metrics);
|
||||
* enter: debugBag.metrics.disabled=true;
|
||||
* Then do some things to generate events and make sure that:
|
||||
* The app doesn’t crash
|
||||
* No JavaScript events are generated in the console
|
||||
* The events aren’t sent
|
||||
* Reset that by entering: delete debugBag.metrics.disabled
|
||||
* enter: debugBag.metrics.blacklistedEvents = [“page”, “click”];
|
||||
* Then do some things to generate events and make sure that:
|
||||
* The app doesn’t crash
|
||||
* No JavaScript events are generated in the console
|
||||
* Those events, and only those events, aren’t sent
|
||||
* I save the object you set via metrics.config.setDebugSource to localStorage to facilitate testing at app startup, so remember to clear it out when you’re done or you’ll be confused why things aren’t working right in the future:
|
||||
* metrics.config.setDebugSource();
|
||||
* If there are values you want to be in effect at app-launch, just do the tweaking to the bag before your call to metrics.config.setDebugSource(debugBag.metrics);, passing in the tweaked bag.
|
||||
* @param aDebugSource a plain old JavaScript object with keys and values which will be searched when config is requested.
|
||||
* @returns {*} debugSource
|
||||
*/
|
||||
Config.prototype.setDebugSource = function setDebugSource(aDebugSource) {
|
||||
this._debugSource = aDebugSource || null;
|
||||
return storage.saveObjectToStorage(this.environment.localStorageObject(), this.DEBUG_SOURCE_KEY, this._debugSource);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return any previously set debugSource which would be stored in localStorage.
|
||||
* If not present in localStorage, the class variable value of debugSource will be returned.
|
||||
* @returns {*} debugSource
|
||||
*/
|
||||
Config.prototype.debugSource = function debugSource() {
|
||||
if (this._debugSource) ; else {
|
||||
// Otherwise look in localStorage for one...
|
||||
this._debugSource = storage.objectFromStorage(this.environment.localStorageObject(), this.DEBUG_SOURCE_KEY);
|
||||
}
|
||||
return this._debugSource;
|
||||
};
|
||||
|
||||
/**
|
||||
* Save a source to localStorage which will have config values that can be used in the next visit until a fresh config is fetched
|
||||
* @param {Object} aSource
|
||||
* @return {Object}
|
||||
*/
|
||||
Config.prototype.setCachedSource = function setCachedSource(aSource) {
|
||||
this._cachedSource = aSource || null;
|
||||
return storage.saveObjectToStorage(
|
||||
this.environment.localStorageObject(),
|
||||
this.CACHED_SOURCE_KEY,
|
||||
this._cachedSource
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return any previously set savedSource which would be stored in localStorage.
|
||||
* The class variable value of savedSource will be returned if non-null to avoid expensive reads from disk.
|
||||
* @return {Object}
|
||||
*/
|
||||
Config.prototype.cachedSource = function cachedSource() {
|
||||
if (this._cachedSource) ; else {
|
||||
// Otherwise look in localStorage for one...
|
||||
this._cachedSource = storage.objectFromStorage(this.environment.localStorageObject(), this.CACHED_SOURCE_KEY);
|
||||
}
|
||||
return this._cachedSource;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set a source, typically one that was fetched from the config endpoint,
|
||||
* which will have config values that can be overwritten by clients via config.setDelegate
|
||||
* @param {Object} aServiceSource
|
||||
* @deprecated
|
||||
* @return {Object}
|
||||
*/
|
||||
Config.prototype.setServiceSource = function setServiceSource(aServiceSource) {
|
||||
this._serviceSource = aServiceSource;
|
||||
return this._serviceSource;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a config source that was retrieved from the metrics config service endpoint
|
||||
* @deprecated
|
||||
* @return {Object}
|
||||
*/
|
||||
Config.prototype.serviceSource = function serviceSource() {
|
||||
return this._serviceSource;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize config by setting config delegate or fetching it from the config endpoint as necessary
|
||||
* If we wanted config to persist across page turns, we could save it via setCachedSource and fetch it every time we wake up,
|
||||
* but we expect most clients to be single page apps
|
||||
*
|
||||
* @param {Function} (optional) configSourcesFn - a function that returns an array of key/value objects (dictionaries) for all of the config sources
|
||||
* (e.g. the bag, the page, the control parent, etc.).
|
||||
* @return {Promise} A Promise for the Config initialization. Returns an rejected Promise if failed to fetch config from server
|
||||
*/
|
||||
Config.prototype.init = function init(configSourcesFn) {
|
||||
var isDefaultConfig = this._topic === NO_TOPIC_KEY || !reflect.isFunction(configSourcesFn);
|
||||
|
||||
if (isDefaultConfig) {
|
||||
this.logger.warn(
|
||||
'config.init(): Falling back to default config because configSourcesFn or a valid topic was not provided'
|
||||
);
|
||||
}
|
||||
|
||||
// default config does not need to initialize
|
||||
if (this._initCalled || isDefaultConfig) {
|
||||
return Promise.resolve(this);
|
||||
}
|
||||
|
||||
this._initCalled = true;
|
||||
var self = this;
|
||||
|
||||
this._configFetchPromise = Promise.resolve(configSourcesFn())
|
||||
.then(function (configSources) {
|
||||
self.setDelegate({
|
||||
sources: function sources() {
|
||||
return configSources;
|
||||
}
|
||||
});
|
||||
self._initialized = true;
|
||||
return self;
|
||||
})
|
||||
.catch(function (error) {
|
||||
self._initCalled = false;
|
||||
self._initialized = false;
|
||||
throw error;
|
||||
});
|
||||
|
||||
return this._configFetchPromise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Release resources of the config
|
||||
*/
|
||||
Config.prototype.cleanup = function cleanup() {
|
||||
this._initCalled = this._initialized = false;
|
||||
this.setCachedSource();
|
||||
this.setDebugSource();
|
||||
this.resetDelegate();
|
||||
this.environment = null;
|
||||
this.network = null;
|
||||
this.logger = null;
|
||||
this._topic = null;
|
||||
this._debugSource = null;
|
||||
this._cachedSource = null;
|
||||
this._serviceSource = null;
|
||||
this._initCalled = false;
|
||||
this._initialized = false;
|
||||
this._showedDebugWarning = false;
|
||||
this._showedNoProvidedSourceWarning = false;
|
||||
this._configFetchPromise = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Indicates whether or not config has initialized.
|
||||
* Initialization is accomplished in one of the following ways:
|
||||
* 1) a service source is set via a call to config.setServiceSource() TODO: Deprecated
|
||||
* 2) a source function delegate is set via config.setDelegate()
|
||||
* @return {Boolean}
|
||||
*/
|
||||
Config.prototype.initialized = function initialized() {
|
||||
return this._initialized;
|
||||
};
|
||||
|
||||
/*
|
||||
* src/impls/metrics_config.js
|
||||
* mt-client-config
|
||||
*
|
||||
* Copyright © 2020 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Metrics config implementation for Config
|
||||
* This class is a subclass of Config to provide the business methods for metrics collection
|
||||
* @param topic
|
||||
* @constructor
|
||||
*/
|
||||
var MetricsConfig = function MetricsConfig(topic) {
|
||||
Config.call(this, topic);
|
||||
};
|
||||
|
||||
MetricsConfig.prototype = Object.create(Config.prototype);
|
||||
MetricsConfig.prototype.constructor = MetricsConfig;
|
||||
|
||||
/**
|
||||
************************************ PUBLIC METHODS/IVARS ************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Boolean config value which, when "true", tells clients to avoid all metrics code paths (different than simply not sending metrics).
|
||||
* Useful for avoiding discovered client bugs.
|
||||
* NOTE1: This will cause unrecoverable event loss, as the clients will not be recording events at all.
|
||||
* NOTE2: Typically all event_handlers will check for this in addition to "recordEvent()" checking because that way
|
||||
* if a client overrides "recordEvent", these checks will still take effect.
|
||||
* We also test it in recordEvent() in case someone creates their own event_handler, we'd still want to exclude what needs to be excluded.
|
||||
* @param {String} (optional) topic an 'override' topic which will override the main topic.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
MetricsConfig.prototype.disabled = function disabled(topic) {
|
||||
return this.value('disabled', topic).then(function (disabled) {
|
||||
return !!disabled;
|
||||
});
|
||||
};
|
||||
|
||||
/** @DEPERECATED per Inclusive Software Efforts; use denylistedEvents instead
|
||||
* Array config value which instructs clients to avoid sending particular event types.
|
||||
* Useful for reducing server processing in emergencies by abandoning less-critical events.
|
||||
* Useful for dealing with urgent privacy concerns, etc., around specific events.
|
||||
* NOTE1: This will cause unrecoverable event loss, as the clients will not be recording events at all.
|
||||
* NOTE2: Typically all event_handlers will check for this in addition to "recordEvent()" checking because that way
|
||||
* if a client overrides "recordEvent", these checks will still take effect.
|
||||
* We also test it in recordEvent() in case someone creates their own event_handler, we'd still want to exclude what needs to be excluded, in case they don't.
|
||||
* @param {String} (optional) topic an 'override' topic which will override the main topic.
|
||||
* @returns {Promise} Guaranteed to always return a Promise with the valid array, though the array may be empty if the value was unset in config
|
||||
*/
|
||||
MetricsConfig.prototype.blacklistedEvents = function blacklistedEvents(topic) {
|
||||
return this.denylistedEvents(topic);
|
||||
};
|
||||
|
||||
/**
|
||||
* Array config value which instructs clients to avoid sending particular event types.
|
||||
* Useful for reducing server processing in emergencies by abandoning less-critical events.
|
||||
* Useful for dealing with urgent privacy concerns, etc., around specific events.
|
||||
* NOTE1: This will cause unrecoverable event loss, as the clients will not be recording events at all.
|
||||
* NOTE2: Typically all event_handlers will check for this in addition to "recordEvent()" checking because that way
|
||||
* if a client overrides "recordEvent", these checks will still take effect.
|
||||
* We also test it in recordEvent() in case someone creates their own event_handler, we'd still want to exclude what needs to be excluded, in case they don't.
|
||||
* @param {String} (optional) topic an 'override' topic which will override the main topic.
|
||||
* @returns {Promise} Guaranteed to always return a Promise with the valid array, though it may be empty if the value was unset in config
|
||||
*/
|
||||
MetricsConfig.prototype.denylistedEvents = function denylistedEvents(topic) {
|
||||
var blacklistedEventsArray = this.value('blacklistedEvents', topic)
|
||||
.then(function (returnArray) {
|
||||
return returnArray || [];
|
||||
})
|
||||
.catch(function () {
|
||||
return [];
|
||||
});
|
||||
var denylistedEventsArray = this.value('denylistedEvents', topic)
|
||||
.then(function (returnArray) {
|
||||
return returnArray || [];
|
||||
})
|
||||
.catch(function () {
|
||||
return [];
|
||||
});
|
||||
return Promise.all([blacklistedEventsArray, denylistedEventsArray]).then(function (outputs) {
|
||||
var blacklistedEventsArray = outputs[0];
|
||||
var denylistedEventsArray = outputs[1];
|
||||
return dedupedArray(blacklistedEventsArray, denylistedEventsArray);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a deduped array (similar to a Set object) using the contents from both arrayA and arrayB
|
||||
* @param {Array} arrayA the first array to dedupe
|
||||
* @param {Array} arrayB the other array to dedupe
|
||||
* @return {Array} The deduped array
|
||||
*/
|
||||
function dedupedArray(arrayA, arrayB) {
|
||||
var tempDict = {}; // necessary for returning array of unique values and not having access to Set object in ES5
|
||||
var returnArray = [];
|
||||
if (arrayA) {
|
||||
for (var i = 0; i < arrayA.length; i++) {
|
||||
tempDict[arrayA[i]] = 0; // value for key doesn't matter; we want a list of unique values
|
||||
}
|
||||
}
|
||||
if (arrayB) {
|
||||
for (var j = 0; j < arrayB.length; j++) {
|
||||
tempDict[arrayB[j]] = 0; // value for key doesn't matter; we want a list of unique values
|
||||
}
|
||||
}
|
||||
returnArray = Object.keys(tempDict);
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array config value which instructs clients to avoid sending particular event fields.
|
||||
* Useful for dealing with urgent privacy concerns, etc., around specific event fields (e.g. dsid)
|
||||
* NOTE: Typically all event_handlers will check for this in addition to "recordEvent()" checking because that way
|
||||
* if a client overrides "recordEvent", these checks will still take effect.
|
||||
* We also test it in recordEvent() in case someone creates their own event_handler, we'd still want to exclude what needs to be excluded, in case they don't.
|
||||
* @param {String} (optional) topic an 'override' topic which will override the main topic.
|
||||
* @returns {Promise} Guaranteed to always return a Promise with the valid array, though it may be empty if the value was unset in config
|
||||
*/
|
||||
MetricsConfig.prototype.blacklistedFields = function blacklistedFields(topic) {
|
||||
return this.denylistedFields(topic);
|
||||
};
|
||||
|
||||
/**
|
||||
* Array config value which instructs clients to avoid sending particular event fields.
|
||||
* Useful for dealing with urgent privacy concerns, etc., around specific event fields (e.g. dsid)
|
||||
* NOTE: Typically all event_handlers will check for this in addition to "recordEvent()" checking because that way
|
||||
* if a client overrides "recordEvent", these checks will still take effect.
|
||||
* We also test it in recordEvent() in case someone creates their own event_handler, we'd still want to exclude what needs to be excluded, in case they don't.
|
||||
* @param {String} (optional) topic an 'override' topic which will override the main topic.
|
||||
* @returns {Promise} Guaranteed to always return a Promise valid array, though it may be empty if the value was unset in config
|
||||
*/
|
||||
MetricsConfig.prototype.denylistedFields = function denylistedFields(topic) {
|
||||
var blacklistedFieldsArray = this.value('blacklistedFields', topic)
|
||||
.then(function (returnArray) {
|
||||
return returnArray || [];
|
||||
})
|
||||
.catch(function () {
|
||||
return [];
|
||||
});
|
||||
var denylistedFieldsArray = this.value('denylistedFields', topic)
|
||||
.then(function (returnArray) {
|
||||
return returnArray || [];
|
||||
})
|
||||
.catch(function () {
|
||||
return [];
|
||||
});
|
||||
return Promise.all([blacklistedFieldsArray, denylistedFieldsArray]).then(function (outputs) {
|
||||
var blacklistedFieldsArray = outputs[0];
|
||||
var denylistedFieldsArray = outputs[1];
|
||||
return dedupedArray(blacklistedFieldsArray, denylistedFieldsArray);
|
||||
});
|
||||
};
|
||||
|
||||
/** @DEPRECATED per Inclusive Software Efforts; use removeDenylistedFields instead
|
||||
* Remove all blacklisted fields from the passed-in object.
|
||||
* IMPORTANT: This action is performed in-place for performance of not having to create new objects each time.
|
||||
* NOTE: Typically all event_handlers will call this in addition to "recordEvent()" calling it because that way
|
||||
* if a client overrides "recordEvent", these checks will still take effect.
|
||||
* We also test it in recordEvent() in case someone creates their own event_handler, we'd still want to exclude what needs to be excluded, in case they don't.
|
||||
* @param {Object} eventFields a dictionary of event data
|
||||
* @param {String} (optional) topic an 'override' topic which will override the main topic.
|
||||
* @returns {Promise} the passed-in object with any blacklisted fields removed
|
||||
*/
|
||||
MetricsConfig.prototype.removeBlacklistedFields = function removeBlacklistedFields(eventFields, topic) {
|
||||
return this.removeDenylistedFields(eventFields, topic);
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove all denylisted fields from the passed-in object.
|
||||
* IMPORTANT: This action is performed in-place for performance of not having to create new objects each time.
|
||||
* NOTE: Typically all event_handlers will call this in addition to "recordEvent()" calling it because that way
|
||||
* if a client overrides "recordEvent", these checks will still take effect.
|
||||
* We also test it in recordEvent() in case someone creates their own event_handler, we'd still want to exclude what needs to be excluded, in case they don't.
|
||||
* @param {Object} eventFields a dictionary of event data
|
||||
* @param {String} (optional) topic an 'override' topic which will override the main topic.
|
||||
* @returns {Promise} the passed-in object with any denylisted fields removed
|
||||
*/
|
||||
MetricsConfig.prototype.removeDenylistedFields = function removeDenylistedFields(eventFields, topic) {
|
||||
if (eventFields) {
|
||||
return this.denylistedFields(topic).then(function (denylistedFieldsArray) {
|
||||
for (var ii = 0; ii < denylistedFieldsArray.length; ii++) {
|
||||
var aDenylistedField = denylistedFieldsArray[ii];
|
||||
// Double check this is not null (or empty string), or "delete" will blow up...
|
||||
if (aDenylistedField) {
|
||||
if (aDenylistedField in eventFields) {
|
||||
delete eventFields[aDenylistedField];
|
||||
}
|
||||
}
|
||||
}
|
||||
return eventFields;
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve(eventFields);
|
||||
}
|
||||
};
|
||||
|
||||
/** @DEPRECATED per Inclusive Software Efforts; use metricsDisabledOrDenylistedEvent instead
|
||||
* Convenience function used by event handlers to determine if they should build and return metricsData.
|
||||
* NOTE: Typically all event_handlers will check for this in addition to "recordEvent()" checking because that way
|
||||
* if a client overrides "recordEvent", these checks will still take effect.
|
||||
* We also test it in recordEvent() in case someone creates their own event_handler, we'd still want to exclude what needs to be excluded, in case they don't.
|
||||
* @param {String} anEventType
|
||||
* @param {String} (optional) topic an 'override' topic which will override the main topic.
|
||||
* @returns {Promise} returns "true" if <b>either</b> "disabled()" is true or "blacklistedEvents()" contains this eventType
|
||||
*/
|
||||
MetricsConfig.prototype.metricsDisabledOrBlacklistedEvent = function metricsDisabledOrBlacklistedEvent(
|
||||
anEventType,
|
||||
topic
|
||||
) {
|
||||
return this.metricsDisabledOrDenylistedEvent(anEventType, topic);
|
||||
};
|
||||
|
||||
/**
|
||||
* Convenience function used by event handlers to determine if they should build and return metricsData.
|
||||
* NOTE: Typically all event_handlers will check for this in addition to "recordEvent()" checking because that way
|
||||
* if a client overrides "recordEvent", these checks will still take effect.
|
||||
* We also test it in recordEvent() in case someone creates their own event_handler, we'd still want to exclude what needs to be excluded, in case they don't.
|
||||
* @param {String} anEventType
|
||||
* @param {String} (optional) topic an 'override' topic which will override the main topic.
|
||||
* @returns {Boolean} returns "true" if <b>either</b> "disabled()" is true or "denylistedEvents()" contains this eventType
|
||||
*/
|
||||
MetricsConfig.prototype.metricsDisabledOrDenylistedEvent = function metricsDisabledOrDenylistedEvent(
|
||||
anEventType,
|
||||
topic
|
||||
) {
|
||||
return this.disabled(topic).then(
|
||||
function (disabled) {
|
||||
return (
|
||||
disabled ||
|
||||
(anEventType
|
||||
? this.denylistedEvents(topic).then(function (denylistedEvents) {
|
||||
return denylistedEvents.indexOf(anEventType) > -1;
|
||||
})
|
||||
: false)
|
||||
);
|
||||
}.bind(this)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Config map which instructs clients to de-res (lower the resolution of) particular event fields.
|
||||
* The Privacy team typically requires device capacity information to be de-resed.
|
||||
* @param {String} (optional) topic an 'override' topic which will override the main topic.
|
||||
* @returns {Promise} An array of config objects { fieldName, (optional) magnitude, (optional) significantDigits }
|
||||
* Guaranteed to always return a valid array, though it may be empty if the value was unset in config
|
||||
*/
|
||||
MetricsConfig.prototype.deResFields = function deResFields(topic) {
|
||||
return this.value('deResFields', topic).then(function (returnArray) {
|
||||
return returnArray || [];
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* De-res appropriate fields in the passed-in object by lowering the resolution of those field values.
|
||||
* For example, a raw number of bytes "de-res"'d to MB, but without the "floor" filter, would look like these examples:
|
||||
* 31708938240/1024/1024 ==> 30240
|
||||
* 15854469120/1024/1024 ==> 15120
|
||||
* 63417876480/1024/1024 ==> 60480
|
||||
*
|
||||
* With the "floor" formula we replace the two least significant digits with "00"
|
||||
* Doing so will convert values like so:
|
||||
*
|
||||
* 31708938240/1024/1024 ==> 30200
|
||||
* 15854469120/1024/1024 ==> 15100
|
||||
* 63417876480/1024/1024 ==> 60400
|
||||
*
|
||||
* IMPORTANT: This action is performed in-place for performance of not having to create new objects each time.
|
||||
* NOTE: Be careful not to call this method more than once for a given event, as de-resing a number more than
|
||||
* once can lead to inaccurate reporting (numbers will likely be smaller than their real values)
|
||||
* @param {Object} eventFields a dictionary of event data
|
||||
* @param {String} (optional) topic an 'override' topic which will override the main topic.
|
||||
* @returns {Promise} the passed-in object with any fields de-resed
|
||||
*/
|
||||
MetricsConfig.prototype.applyDeRes = function applyDeRes(eventFields, topic) {
|
||||
if (eventFields) {
|
||||
return this.deResFields(topic).then(function (deResFieldsConfigArray) {
|
||||
var fieldName;
|
||||
|
||||
deResFieldsConfigArray.forEach(function (deResFieldConfig) {
|
||||
fieldName = deResFieldConfig.fieldName;
|
||||
if (fieldName in eventFields) {
|
||||
eventFields[fieldName] = number.deResNumber(
|
||||
eventFields[fieldName],
|
||||
deResFieldConfig.magnitude,
|
||||
deResFieldConfig.significantDigits
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return eventFields;
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve(eventFields);
|
||||
}
|
||||
};
|
||||
|
||||
export default Config;
|
||||
export { MetricsConfig };
|
||||
3103
shared/metrics-8/node_modules/@amp-metrics/mt-client-constraints/dist/mt-client-constraints.esm.js
generated
vendored
Normal file
3103
shared/metrics-8/node_modules/@amp-metrics/mt-client-constraints/dist/mt-client-constraints.esm.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
533
shared/metrics-8/node_modules/@amp-metrics/mt-client-logger-core/dist/mt-client-logger-core.esm.js
generated
vendored
Normal file
533
shared/metrics-8/node_modules/@amp-metrics/mt-client-logger-core/dist/mt-client-logger-core.esm.js
generated
vendored
Normal file
@@ -0,0 +1,533 @@
|
||||
import { reflect, string } from '@amp-metrics/mt-metricskit-utils-private';
|
||||
|
||||
/*
|
||||
* src/utils.js
|
||||
* mt-client-logger-core
|
||||
*
|
||||
* Copyright © 2016-2017 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
function FlagSymbol(key) {
|
||||
this.key = key;
|
||||
}
|
||||
FlagSymbol.prototype.toString = function toString() {
|
||||
return this.key;
|
||||
};
|
||||
|
||||
var utils = {
|
||||
/**
|
||||
************************************ PUBLIC METHODS/IVARS ************************************
|
||||
*/
|
||||
|
||||
/** Special flag classes that can be passed as arguments to logger methods in order to dictate logging behavior
|
||||
* Use class instances to guarantee that flag arguments are unique, and use constructor names for O(1) lookup */
|
||||
flagArguments: {
|
||||
/**
|
||||
* When logging, if any of the arguments is an instance of this class, the log output will include a call stack trace.
|
||||
* @example usage: logger.warn('danger!', logger.INCLUDE_CALL_STACK);
|
||||
*/
|
||||
INCLUDE_CALL_STACK: new FlagSymbol('INCLUDE_CALL_STACK'),
|
||||
/**
|
||||
* When logging, if any of the arguments is an instance of this class, the remaining arguments will be mirrored to the logging server
|
||||
* @example usage: logger.info('some message', logger.MIRROR_TO_SERVER);
|
||||
*/
|
||||
MIRROR_TO_SERVER: new FlagSymbol('MIRROR_TO_SERVER'),
|
||||
/**
|
||||
* When logging, if any of the arguments is an instance of this class, the client (console) output will be suppressed
|
||||
* This would typically be used when callers want to log an event to the server without printing it
|
||||
* @example usage: logger.debug(someDiagnosticsInfoObject, logger.MIRROR_TO_SERVER, logger.SUPPRESS_CLIENT_OUTPUT);
|
||||
*/
|
||||
SUPPRESS_CLIENT_OUTPUT: new FlagSymbol('SUPPRESS_CLIENT_OUTPUT')
|
||||
},
|
||||
|
||||
/**
|
||||
* Allows replacement of one or more of this class' functions
|
||||
* Any method on the passed-in object which matches a method that this class has will be called instead of the built-in class method.
|
||||
* To replace *all* methods of his class, simply have your delegate implement all the methods of this class
|
||||
* Your delegate can be a true object instance, an anonymous object, or a class object.
|
||||
* Your delegate is free to have as many additional non-matching methods as it likes (these methods will not be copied to the target object).
|
||||
* It can even act as a delegate for multiple MetricsKit objects, though that is not recommended.
|
||||
*
|
||||
* "setDelegate()" may be called repeatedly, with the functions in the most-recently set delegates replacing any functions matching those in the earlier delegates, as well as any as-yet unreplaced functions.
|
||||
* This allows callers to replace some number of methods that need custom implementations.
|
||||
* If, for example, a client wants to use the standard logger implementation with the exception of, say, the "debug" method, they can
|
||||
* call "setDelegate()" with their own delegate containing only a single method of "debug" as the delegate, which would leave all the other methods intact.
|
||||
*
|
||||
* NOTE: The delegate function will have a property called origFunction representing the original function that it replaced.
|
||||
* This allows the delegate to, essentially, call "super" before or after it does some work.
|
||||
* If a replaced method is overridden again with a subsequent "setDelegate()" call, the "origFunction" property will be the previous delegate's function.
|
||||
* @example:
|
||||
* To override one or more methods, in place:
|
||||
* logger.setDelegate({ debug: console.debug });
|
||||
* To override one or more methods with a separate object:
|
||||
* logger.setDelegate(customLoggerDelegate);
|
||||
* (where "customLoggerDelegate" might be defined elsewhere as, e.g.:
|
||||
* var customLoggerDelegate = { debug: function(msg) { document.getElementById('debugMsg').innerHTML = msg; },
|
||||
* serverUrl: function() { return 'https://custom-log-server.apple.com'; } };
|
||||
* To override one or more methods with an instantiated object from a class definition:
|
||||
* eventRecorder.setDelegate(new CustomLoggerDelegate());
|
||||
* (where "CustomLoggerDelegate" might be defined elsewhere as, e.g.:
|
||||
* function CustomLoggerDelegate() {
|
||||
* }
|
||||
* CustomLoggerDelegate.prototype.debug = function debug(msg) {
|
||||
* document.getElementById('debugMsg').innerHTML = msg;
|
||||
* };
|
||||
* CustomLoggerDelegate.prototype.serverUrl = function serverUrl() {
|
||||
* return 'https://custom-log-server.apple.com';
|
||||
* };
|
||||
* To override one or more methods with a class object (with "static" methods):
|
||||
* eventRecorder.setDelegate(CustomLoggerDelegate);
|
||||
* (where "CustomLoggerDelegate" might be defined elsewhere as, e.g.:
|
||||
* function CustomLoggerDelegate() {
|
||||
* }
|
||||
* CustomLoggerDelegate.debug = function debug(msg) {
|
||||
* document.getElementById('debugMsg').innerHTML = msg;
|
||||
* };
|
||||
* CustomLoggerDelegate.serverUrl = function serverUrl() {
|
||||
* return 'https://custom-log-server.apple.com';
|
||||
* };
|
||||
* @param {Object} delegate Object or Class with delegate method(s) to be called instead of default (built-in) methods.
|
||||
* @returns {Boolean} true if one or more methods on the delegate object match one or more methods on the default object,
|
||||
* otherwise returns false.
|
||||
*/
|
||||
setDelegate: function setDelegate(delegate) {
|
||||
return reflect.attachDelegate(this, delegate);
|
||||
},
|
||||
|
||||
/**
|
||||
* If the log level allows, logs/throws an error to the console and mirrors the log event to the server
|
||||
* @param {Logger} logger
|
||||
* @param {String} methodName
|
||||
* @param {Array-like Object} origArguments
|
||||
*/
|
||||
execute: function execute(logger, methodName, origArguments) {
|
||||
var methodLevel = logger.levelStringToIntMap[methodName];
|
||||
|
||||
if (logger.level() !== logger.NONE && logger.level() <= methodLevel) {
|
||||
var argumentsArray = Array.prototype.slice.call(origArguments);
|
||||
var logArguments = utils.nonFlagLogArguments(argumentsArray);
|
||||
var logOptions = utils.logOptions(logger, methodLevel, argumentsArray);
|
||||
var callstack = logOptions.includeCallStack ? new Error().stack : null;
|
||||
var enrichedLogArguments = callstack ? logArguments.concat('\n' + callstack) : logArguments; // add newline for nicer output
|
||||
|
||||
// so testing harness can verify logging done within tested functions:
|
||||
logger[methodName]._lastLog = enrichedLogArguments;
|
||||
|
||||
if (logOptions.mirrorToServer) {
|
||||
utils.sendToServer(logger, methodName, logArguments, callstack);
|
||||
}
|
||||
|
||||
if (logOptions.throwInsteadOfPrint) {
|
||||
throw new Error(logArguments.toString());
|
||||
} else if (!logOptions.suppressClientOutput) {
|
||||
if (console[methodName]) {
|
||||
console[methodName].apply(console, enrichedLogArguments);
|
||||
} else {
|
||||
// fallback to console.log - node does not have console.debug
|
||||
console.log.apply(console, enrichedLogArguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Indicates whether an item is a specific flag object that dictates logging behavior
|
||||
* @param {*} argument
|
||||
* @return {Boolean}
|
||||
*/
|
||||
isFlagObject: function isFlagObject(argument) {
|
||||
return argument && argument === utils.flagArguments[argument.toString()];
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new array without specific arguments that dictate logging behavior (and are not intended to be logged)
|
||||
* @param {Array} argumentsArray
|
||||
* @return {Array}
|
||||
*/
|
||||
nonFlagLogArguments: function nonFlagLogArguments(argumentsArray) {
|
||||
return argumentsArray.filter(function (argument) {
|
||||
return !utils.isFlagObject(argument);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Inspects an array of arguments for specific flag objects that dictate log behavior and returns an object representing the intended behavior
|
||||
* By checking for all of the various flags in one pass, we avoid looping over the arguments array more than necessary
|
||||
* @param {Logger} logger
|
||||
* @param {Int} methodLevel
|
||||
* @param {Array} argumentsArray
|
||||
* @return {Object}
|
||||
*/
|
||||
logOptions: function logOptions(logger, methodLevel, argumentsArray) {
|
||||
var logOptions = {};
|
||||
var optionName;
|
||||
|
||||
argumentsArray.forEach(function (argument) {
|
||||
if (utils.isFlagObject(argument)) {
|
||||
optionName = string.snakeCaseToCamelCase(argument.toString());
|
||||
logOptions[optionName] = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (
|
||||
reflect.isFunction(logger.mirrorToServerLevel) &&
|
||||
logger.mirrorToServerLevel() !== logger.NONE &&
|
||||
logger.mirrorToServerLevel() <= methodLevel
|
||||
) {
|
||||
logOptions.mirrorToServer = true;
|
||||
}
|
||||
if (logger.throwLevel() !== logger.NONE && logger.throwLevel() <= methodLevel) {
|
||||
logOptions.throwInsteadOfPrint = true;
|
||||
}
|
||||
|
||||
return logOptions;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sends a log event to the server immediately without checking resolution
|
||||
* TODO: refactor to use eventRecorder once it is a standalone package
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @param {Logger} logger
|
||||
* @param {String} level
|
||||
* @param {Array} logArguments
|
||||
* @param {String} (optional) callstack
|
||||
* @return {String} the JSON-stringified event that was sent to the server
|
||||
* @overridable
|
||||
*/
|
||||
sendToServer: function sendToServer(logger, level, logArguments, callstack) {}
|
||||
};
|
||||
|
||||
/*
|
||||
* src/logger.js
|
||||
* mt-client-logger-core
|
||||
*
|
||||
* Copyright © 2016-2017 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
************************************ PRIVATE METHODS/IVARS ************************************
|
||||
*/
|
||||
|
||||
// Define log levels separately to expose this constant.
|
||||
// TODO clean constants up when consolidate.
|
||||
var LOG_LEVELS = {
|
||||
NONE: 0,
|
||||
DEBUG: 1,
|
||||
INFO: 2,
|
||||
WARN: 3,
|
||||
ERROR: 4
|
||||
};
|
||||
var LOGGER_LEVELS = {
|
||||
MIN_LEVEL: LOG_LEVELS.NONE,
|
||||
MAX_LEVEL: LOG_LEVELS.ERROR,
|
||||
levelIntToStringMap: {
|
||||
0: 'none',
|
||||
1: 'debug',
|
||||
2: 'info',
|
||||
3: 'warn',
|
||||
4: 'error'
|
||||
},
|
||||
levelStringToIntMap: {
|
||||
none: 0,
|
||||
debug: 1,
|
||||
info: 2,
|
||||
warn: 3,
|
||||
error: 4
|
||||
}
|
||||
};
|
||||
|
||||
reflect.extend(LOGGER_LEVELS, LOG_LEVELS);
|
||||
|
||||
/** Global properties */
|
||||
var LOGGER_PROPERTIES = {
|
||||
loggerName: 'defaultLogger',
|
||||
level: LOGGER_LEVELS.INFO,
|
||||
throwLevel: LOGGER_LEVELS.NONE
|
||||
};
|
||||
|
||||
var _initialized = false;
|
||||
|
||||
/** A map of logger names to Logger instances */
|
||||
var _loggers = {};
|
||||
|
||||
/**
|
||||
* Provides basic "log4j" type functionality.
|
||||
* The functionality in this class is typically replaced via a delegate.
|
||||
* NOTE: This class has a "secret" field extending each logger function called "_lastLog" which allows us to inspect logged errors from within our test cases of various functionality
|
||||
* to ensure that the correct errors are thrown.
|
||||
* DEFAULT implementation: console logging
|
||||
* DEFAULT logger level: INFO
|
||||
* @see setDelegate
|
||||
* @delegatable
|
||||
* @constructor
|
||||
* @param {String} loggerName
|
||||
*/
|
||||
function Logger(loggerName) {
|
||||
// @private
|
||||
this._loggerName = loggerName;
|
||||
|
||||
/* These variables are enumerated here for clarity */
|
||||
// @private
|
||||
this._level;
|
||||
// @private
|
||||
this._throwLevel;
|
||||
|
||||
// lazily add prototype properties
|
||||
if (!_initialized) {
|
||||
_initialized = true;
|
||||
reflect.extend(Logger.prototype, LOGGER_LEVELS);
|
||||
reflect.extend(Logger.prototype, utils.flagArguments);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the logger instance that has the name <loggerName>, creating a new one if it doesn't exist
|
||||
* @param {String} loggerName
|
||||
* @return {Logger}
|
||||
*/
|
||||
function loggerNamed(loggerName) {
|
||||
loggerName = loggerName || LOGGER_PROPERTIES.loggerName;
|
||||
var returnLogger = _loggers[loggerName];
|
||||
|
||||
if (!returnLogger) {
|
||||
returnLogger = new Logger(loggerName);
|
||||
_loggers[loggerName] = returnLogger;
|
||||
}
|
||||
|
||||
return returnLogger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a logger from the cache
|
||||
* @param loggerName
|
||||
*/
|
||||
function removeLogger(loggerName) {
|
||||
if (_loggers) {
|
||||
delete _loggers[loggerName];
|
||||
}
|
||||
}
|
||||
|
||||
function resetLoggerCache() {
|
||||
_loggers = {};
|
||||
}
|
||||
|
||||
/** Default class property setters and getters */
|
||||
Logger.level = function level() {
|
||||
return LOGGER_PROPERTIES.level;
|
||||
};
|
||||
Logger.throwLevel = function throwLevel() {
|
||||
return LOGGER_PROPERTIES.throwLevel;
|
||||
};
|
||||
|
||||
// TODO: new PR with this, flesh out and make app-wide with docs
|
||||
// Logger.setDelegate = function setDelegate() { };
|
||||
// Logger.logCallback = function logCallback() { };
|
||||
|
||||
/**
|
||||
************************************ PUBLIC METHODS/IVARS ************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows replacement of one or more of this class instance's functions
|
||||
* Any method on the passed-in object which matches a method that this class has will be called instead of the built-in class method.
|
||||
* To replace *all* methods of his class, simply have your delegate implement all the methods of this class
|
||||
* Your delegate can be a true object instance, an anonymous object, or a class object.
|
||||
* Your delegate is free to have as many additional non-matching methods as it likes (these methods will not be copied to the target object).
|
||||
* It can even act as a delegate for multiple MetricsKit objects, though that is not recommended.
|
||||
*
|
||||
* "setDelegate()" may be called repeatedly, with the functions in the most-recently set delegates replacing any functions matching those in the earlier delegates, as well as any as-yet unreplaced functions.
|
||||
* This allows callers to replace some number of methods that need custom implementations.
|
||||
* If, for example, a client wants to use the standard logger implementation with the exception of, say, the "debug" method, they can
|
||||
* call "setDelegate()" with their own delegate containing only a single method of "debug" as the delegate, which would leave all the other methods intact.
|
||||
*
|
||||
* NOTE: The delegate function will have a property called origFunction representing the original function that it replaced.
|
||||
* This allows the delegate to, essentially, call "super" before or after it does some work.
|
||||
* If a replaced method is overridden again with a subsequent "setDelegate()" call, the "origFunction" property will be the previous delegate's function.
|
||||
* @example:
|
||||
* To override one or more methods, in place:
|
||||
* logger.setDelegate({ debug: console.debug });
|
||||
* To override one or more methods with a separate object:
|
||||
* logger.setDelegate(customLoggerDelegate);
|
||||
* (where "customLoggerDelegate" might be defined elsewhere as, e.g.:
|
||||
* var customLoggerDelegate = { debug: function(msg) { document.getElementById('debugMsg').innerHTML = msg; },
|
||||
* serverUrl: function() { return 'https://custom-log-server.apple.com'; } };
|
||||
* To override one or more methods with an instantiated object from a class definition:
|
||||
* eventRecorder.setDelegate(new CustomLoggerDelegate());
|
||||
* (where "CustomLoggerDelegate" might be defined elsewhere as, e.g.:
|
||||
* function CustomLoggerDelegate() {
|
||||
* }
|
||||
* CustomLoggerDelegate.prototype.debug = function debug(msg) {
|
||||
* document.getElementById('debugMsg').innerHTML = msg;
|
||||
* };
|
||||
* CustomLoggerDelegate.prototype.serverUrl = function serverUrl() {
|
||||
* return 'https://custom-log-server.apple.com';
|
||||
* };
|
||||
* To override one or more methods with a class object (with "static" methods):
|
||||
* eventRecorder.setDelegate(CustomLoggerDelegate);
|
||||
* (where "CustomLoggerDelegate" might be defined elsewhere as, e.g.:
|
||||
* function CustomLoggerDelegate() {
|
||||
* }
|
||||
* CustomLoggerDelegate.debug = function debug(msg) {
|
||||
* document.getElementById('debugMsg').innerHTML = msg;
|
||||
* };
|
||||
* CustomLoggerDelegate.serverUrl = function serverUrl() {
|
||||
* return 'https://custom-log-server.apple.com';
|
||||
* };
|
||||
* @param {Object} delegate Object or Class with delegate method(s) to be called instead of default (built-in) methods.
|
||||
* @returns {Boolean} true if one or more methods on the delegate object match one or more methods on the default object,
|
||||
* otherwise returns false.
|
||||
*/
|
||||
Logger.prototype.setDelegate = function setDelegate(delegate) {
|
||||
return reflect.attachDelegate(this, delegate);
|
||||
};
|
||||
|
||||
/**
|
||||
* The name of this logger
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Logger.prototype.loggerName = function loggerName() {
|
||||
return this._loggerName;
|
||||
};
|
||||
|
||||
/**
|
||||
* Deduces the integer level from either a string or integer
|
||||
* @param {*} level loglevel which may be either a string (e.g. 'debug', 'DEBUG', 'Debug', etc.) or an integer (e.g. 1, 2, 3 or logger.DEBUG, logger.INFO, logger.WARN, etc.
|
||||
* @return {Int} the level as an integer or null if an invalid level argument was passed
|
||||
* @overrideable
|
||||
*/
|
||||
Logger.prototype.levelParameterAsInt = function levelParameterAsInt(level) {
|
||||
var returnLevel = null;
|
||||
var integerLevel;
|
||||
|
||||
if (reflect.isString(level)) {
|
||||
integerLevel = this.levelStringToIntMap[level.toLowerCase()];
|
||||
} else if (reflect.isNumber(level)) {
|
||||
integerLevel = level;
|
||||
}
|
||||
|
||||
if (integerLevel >= this.MIN_LEVEL && integerLevel <= this.MAX_LEVEL) {
|
||||
returnLevel = integerLevel;
|
||||
}
|
||||
|
||||
return returnLevel;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the level at which we will log at or above
|
||||
* @param {*} level loglevel which may be either a string (e.g. 'debug', 'DEBUG', 'Debug', etc.) or an integer (e.g. 1, 2, 3 or logger.DEBUG, logger.INFO, logger.WARN, etc.
|
||||
* @overridable
|
||||
*/
|
||||
Logger.prototype.setLevel = function setLevel(level) {
|
||||
var integerLevel = this.levelParameterAsInt(level);
|
||||
if (integerLevel !== null) {
|
||||
this._level = integerLevel;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* NOTE: This setting should be honored by all delegates.
|
||||
* This setting will cause any emitted log message at or above the specified level to throw an exception with the log message instead of logging to the console.
|
||||
* This is useful during testcase execution when we would expect to have no log output, or perhaps only "info" log output, etc.
|
||||
* @param {*} throwLevel loglevel which may be either a string (e.g. 'debug', 'DEBUG', 'Debug', etc.) or an integer (e.g. 1, 2, 3 or logger.DEBUG, logger.INFO, logger.WARN, etc.
|
||||
*/
|
||||
Logger.prototype.setThrowLevel = function setThrowLevel(throwLevel) {
|
||||
var integerLevel = this.levelParameterAsInt(throwLevel);
|
||||
if (integerLevel !== null) {
|
||||
this._throwLevel = integerLevel;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the current logger level as an integer
|
||||
* @overridable
|
||||
*/
|
||||
Logger.prototype.level = function level() {
|
||||
var level = this._level;
|
||||
return reflect.isNumber(level) ? level : Logger.level();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the current logger level as a string
|
||||
* @overridable
|
||||
*/
|
||||
Logger.prototype.levelString = function levelString() {
|
||||
return this.levelIntToStringMap[this.level()];
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the current logger throw level as an integer
|
||||
* @overridable
|
||||
*/
|
||||
Logger.prototype.throwLevel = function throwLevel() {
|
||||
var throwLevel = this._throwLevel;
|
||||
return reflect.isNumber(throwLevel) ? throwLevel : Logger.throwLevel();
|
||||
};
|
||||
|
||||
/**
|
||||
* Emits the log message if log level is set to "debug".
|
||||
* DEFAULT implementation: console.debug()
|
||||
* @param {Object} a list of objects (perhaps a single string) to be stringified and emitted as the log message
|
||||
* @api public
|
||||
* @overridable
|
||||
*/
|
||||
Logger.prototype.debug = function debug() {
|
||||
utils.execute(this, 'debug', arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* Emits the log message if log level is set to "info".
|
||||
* DEFAULT implementation: console.info()
|
||||
* @param {Object} a list of objects (perhaps a single string) to be stringified and emitted as the log message
|
||||
* @api public
|
||||
* @overridable
|
||||
*/
|
||||
Logger.prototype.info = function info() {
|
||||
utils.execute(this, 'info', arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* Emits the log message if log level is set to "warn".
|
||||
* DEFAULT implementation: console.warn()
|
||||
* @param {Object} a list of objects (perhaps a single string) to be stringified and emitted as the log message
|
||||
* @api public
|
||||
* @overridable
|
||||
*/
|
||||
Logger.prototype.warn = function warn() {
|
||||
utils.execute(this, 'warn', arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* Emits the log message if log level is set to "error".
|
||||
* DEFAULT implementation: console.error()
|
||||
* @param {Object} a list of objects (perhaps a single string) to be stringified and emitted as the log message
|
||||
* @api public
|
||||
* @overridable
|
||||
*/
|
||||
Logger.prototype.error = function error() {
|
||||
utils.execute(this, 'error', arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {String} levelString
|
||||
* @return {String} the most recent log event for this level
|
||||
*/
|
||||
Logger.prototype.lastLog = function lastLog(levelString) {
|
||||
return this[levelString] ? this[levelString]._lastLog : null;
|
||||
};
|
||||
|
||||
var level = Logger.level;
|
||||
var throwLevel = Logger.throwLevel;
|
||||
|
||||
/*
|
||||
* mt-client-logger-core/index.js
|
||||
* mt-client-logger-core
|
||||
*
|
||||
* Copyright © 2016-2017 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
export default Logger;
|
||||
export { LOG_LEVELS, level, loggerNamed, removeLogger, resetLoggerCache, throwLevel, utils };
|
||||
1364
shared/metrics-8/node_modules/@amp-metrics/mt-event-queue/dist/mt-event-queue.esm.js
generated
vendored
Normal file
1364
shared/metrics-8/node_modules/@amp-metrics/mt-event-queue/dist/mt-event-queue.esm.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
289
shared/metrics-8/node_modules/@amp-metrics/mt-metricskit-delegates-core/dist/mt-metricskit-delegates-core.esm.js
generated
vendored
Normal file
289
shared/metrics-8/node_modules/@amp-metrics/mt-metricskit-delegates-core/dist/mt-metricskit-delegates-core.esm.js
generated
vendored
Normal file
@@ -0,0 +1,289 @@
|
||||
import { MetricsConfig } from '@amp-metrics/mt-client-config';
|
||||
import { reflect } from '@amp-metrics/mt-metricskit-utils-private';
|
||||
|
||||
/*
|
||||
* src/delegate.js
|
||||
* mt-metricskit-delegates-core
|
||||
*
|
||||
* Copyright © 2022 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract class for delegates.
|
||||
* All delegate implementations should extend from this class.
|
||||
* @param {String} topic - Defines the AMP Analytics "topic" for events to be stored under
|
||||
* @param {Object} platformImpls - A map that include the platform-based components.
|
||||
* @param {Environment} platformImpls.environment - An Environment that provide the event field accessor for the platform
|
||||
* @param {EventRecorder} platformImpls.eventRecorder - An EventRecorder that provide the EventRecorder implementation for the platform
|
||||
* @constructor
|
||||
*/
|
||||
var Delegates = function Delegates(topic, platformImpls) {
|
||||
if (!reflect.isDefinedNonNullNonEmpty(topic) || !reflect.isString(topic)) {
|
||||
throw new Error('No valid topic was provided to Delegates.');
|
||||
}
|
||||
|
||||
this.config = this.getOrCreateConfig(topic);
|
||||
// TODO change platformImpls as an required argument in the next major version or supporting Typescript
|
||||
// since every platforms should provide their own impl for the Environment and EventHandler to the Delegates.
|
||||
if (reflect.isDefinedNonNull(platformImpls)) {
|
||||
this.environment = platformImpls.environment;
|
||||
this.eventRecorder = platformImpls.eventRecorder;
|
||||
}
|
||||
// A flag to indicate whether using the original execution context when calling the delegate methods. Default is false
|
||||
// TODO Consider to change this to true by default in the next major release
|
||||
// because using the execution context of the delegate methods may not necessary as accessing the the delegate methods' execution context is straightforward.
|
||||
this._useOrginalContextForDelegateFunc = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes the delegate by setting up the config.
|
||||
* @param delegates
|
||||
* @return {Promise}
|
||||
*/
|
||||
Delegates.prototype.init = function () {
|
||||
if (!reflect.isDefinedNonNull(this.environment)) {
|
||||
throw new Error('No environment was provided to Delegate options.');
|
||||
}
|
||||
|
||||
if (!reflect.isDefinedNonNull(this.eventRecorder)) {
|
||||
throw new Error('No eventRecorder was provided to Delegate options.');
|
||||
}
|
||||
|
||||
this.config.environment.setDelegate(this.environment);
|
||||
this.config.logger.setDelegate(this.logger);
|
||||
this.config.network.setDelegate(this.network);
|
||||
|
||||
var configSources = reflect.isFunction(this.configSources) ? this.configSources.bind(this) : null;
|
||||
|
||||
return this.config.init(configSources);
|
||||
};
|
||||
|
||||
/**
|
||||
* Merge the provided delegates into the current Delegate.
|
||||
* NOTE: Any delegates which already exist in the Delegate won't be merged.
|
||||
* @param {Object} delegates - A key/value map of the system delegates
|
||||
*/
|
||||
Delegates.prototype.mergeDelegates = function (delegates) {
|
||||
var self = this;
|
||||
for (var key in delegates) {
|
||||
if (!self[key]) {
|
||||
self[key] = delegates[key];
|
||||
}
|
||||
}
|
||||
|
||||
this.config.setDelegate(delegates.config);
|
||||
};
|
||||
|
||||
/**
|
||||
* Cleans up resources used by the delegate.
|
||||
*/
|
||||
Delegates.prototype.cleanup = function cleanup() {
|
||||
if (reflect.isFunction(this.eventRecorder.cleanup)) {
|
||||
this.eventRecorder.cleanup();
|
||||
}
|
||||
|
||||
this.config = null;
|
||||
this.eventRecorder = null;
|
||||
this.environment = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Overrides the platform-specific event recorder for the Delegate.
|
||||
* @param {object} eventRecorderDelegates
|
||||
* @returns {Delegates}
|
||||
*/
|
||||
Delegates.prototype.setEventRecorder = function setEventRecorder(eventRecorderDelegates) {
|
||||
if (reflect.isDefinedNonNull(eventRecorderDelegates)) {
|
||||
if (!reflect.isDefinedNonNull(this.eventRecorder)) {
|
||||
this.eventRecorder = eventRecorderDelegates;
|
||||
} else {
|
||||
reflect.setDelegates(this.eventRecorder, eventRecorderDelegates);
|
||||
this.eventRecorder.setDelegate(eventRecorderDelegates);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Overrides the existing environment implementations.
|
||||
* @param {object} environment
|
||||
* @return {Delegates}
|
||||
*/
|
||||
Delegates.prototype.setEnvironment = function setEnvironment(environment) {
|
||||
if (!reflect.isDefinedNonNull(this.environment)) {
|
||||
this.environment = environment;
|
||||
} else {
|
||||
var newEnvironment = Object.create(this.environment);
|
||||
reflect.extend(newEnvironment, environment);
|
||||
this.environment = newEnvironment;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Overrides the config methods
|
||||
* @param config
|
||||
* @return {Delegates}
|
||||
*/
|
||||
Delegates.prototype.setConfig = function setConfig(config) {
|
||||
this.config.setDelegate(config);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Access the config instance from the child delegates before/during calling Delegates.constructor,
|
||||
* this method will create new config instance and set it to the Delegates instance and return the config when the config doesn't exist
|
||||
* @param {String} topic - The topic to create the metrics config instance
|
||||
* @return {MetricsConfig}
|
||||
*/
|
||||
Delegates.prototype.getOrCreateConfig = function getOrCreateConfig(topic) {
|
||||
if (!reflect.isDefinedNonNull(this.config)) {
|
||||
this.config = new MetricsConfig(topic);
|
||||
}
|
||||
|
||||
return this.config;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the config sources. This method must be implemented by subdelegates.
|
||||
* @abstract
|
||||
* @return {Promise}
|
||||
*/
|
||||
Delegates.prototype.configSources = function configSources() {
|
||||
throw new Error('This method should be implemented by subdelegates.');
|
||||
};
|
||||
|
||||
/*
|
||||
* src/abstract_event_recorder.js
|
||||
* mt-metricskit-delegates-core
|
||||
*
|
||||
* Copyright © 2022 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract event recorder to provide common logic across platform event recorders
|
||||
* @constructor
|
||||
*/
|
||||
function AbstractEventRecorder() {
|
||||
this._operationPromiseChain = Promise.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows replacement of one or more of this class' functions
|
||||
* Any method on the passed-in object which matches a method that this class has will be called instead of the built-in class method.
|
||||
* To replace *all* methods of his class, simply have your delegate implement all the methods of this class
|
||||
* Your delegate can be a true object instance, an anonymous object, or a class object.
|
||||
* Your delegate is free to have as many additional non-matching methods as it likes.
|
||||
* It can even act as a delegate for multiple MetricsKit objects, though that is not recommended.
|
||||
*
|
||||
* "setDelegate()" may be called repeatedly, with the functions in the most-recently set delegates replacing any functions matching those in the earlier delegates, as well as any as-yet unreplaced functions.
|
||||
* This allows callers to use "canned" delegates to get most of their functionality, but still replace some number of methods that need custom implementations.
|
||||
* If, for example, a client wants to use the "canned" itml/environment delegate with the exception of, say, the "appVersion" method, they can set itml/environment as the delegate, and
|
||||
* then call "setDelegate()" again with their own delegate containing only a single method of "appVersion" as the delegate, which would leave all the other "replaced" methods intact,
|
||||
* but override the "appVersion" method again, this time with their own supplied delegate.
|
||||
*
|
||||
* NOTE: when the delegate function is called, it will include an additional final parameter representing the original function that it replaced (the callee would typically name this parameter "replacedFunction").
|
||||
* This allows the delegate to, essentially, call "super" before or after it does some work.
|
||||
* If a replaced method is overridden again with a subsequent "setDelegate()" call, the "replacedFunction" parameter will be the previous delegate.
|
||||
* @example:
|
||||
* To override one or more methods, in place:
|
||||
* eventRecorder.setDelegate({recordEvent: itms.recordEvent});
|
||||
* To override one or more methods with a separate object:
|
||||
* eventRecorder.setDelegate(eventRecorderDelegate);
|
||||
* (where "eventRecorderDelegate" might be defined elsewhere as, e.g.:
|
||||
* var eventRecorderDelegate = {recordEvent: itms.recordEvent,
|
||||
* sendMethod: 'itms'};
|
||||
* To override one or more methods with an instantiated object from a class definition:
|
||||
* eventRecorder.setDelegate(new EventRecorderDelegate());
|
||||
* (where "EventRecorderDelegate" might be defined elsewhere as, e.g.:
|
||||
* function EventRecorderDelegate() {
|
||||
* }
|
||||
* EventRecorderDelegate.prototype.recordEvent = itms.recordEvent;
|
||||
* EventRecorderDelegate.prototype.sendMethod = function sendMethod() {
|
||||
* return 'itms';
|
||||
* };
|
||||
* To override one or more methods with a class object (with "static" methods):
|
||||
* eventRecorder.setDelegate(EventRecorderDelegate);
|
||||
* (where "EventRecorderDelegate" might be defined elsewhere as, e.g.:
|
||||
* function EventRecorderDelegate() {
|
||||
* }
|
||||
* EventRecorderDelegate.recordEvent = itms.recordEvent;
|
||||
* EventRecorderDelegate.sendMethod = function sendMethod() {
|
||||
* return 'itms';
|
||||
* };
|
||||
* @param {Object} Object or Class with delegate method(s) to be called instead of default (built-in) methods.
|
||||
* @returns {Boolean} true if one or more methods on the delegate object match one or more methods on the default object,
|
||||
* otherwise returns false.
|
||||
*/
|
||||
AbstractEventRecorder.prototype.setDelegate = function setDelegate(delegate) {
|
||||
return reflect.attachDelegate(this, delegate);
|
||||
};
|
||||
|
||||
/**
|
||||
* Public method to interact with Processors to record an event
|
||||
* @param {String} topic - an 'override' topic which will override the main topic.
|
||||
* @param {Promise|Object} eventFields - a Promise/JavaScript object which will be converted to a JSON string and sent to AMP Analytics.
|
||||
* @return {Promise}
|
||||
*/
|
||||
AbstractEventRecorder.prototype.recordEvent = function recordEvent(topic, eventFields) {
|
||||
var vargs = Array.prototype.slice.call(arguments, 2);
|
||||
var self = this;
|
||||
this._operationPromiseChain = this._operationPromiseChain.then(function () {
|
||||
return Promise.resolve(eventFields).then(function (eventFields) {
|
||||
return self._recordEvent.apply(self, [topic, eventFields].concat(vargs));
|
||||
});
|
||||
});
|
||||
|
||||
return this._operationPromiseChain;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends any remaining events in the queue, then clears it
|
||||
* This is typically called on page / app close when the JS context is about to disappear and thus we will
|
||||
* not know if the events made it to the server
|
||||
* @param {Boolean} appIsExiting - Pass true if events are being flushed due to your app exiting or page going away
|
||||
* (the send method will be different in order to attempt to post events prior to actual termination)
|
||||
* @param {String} appExitSendMethod (optional) the send method for how events will be flushed when the app is exiting.
|
||||
* Possible options are enumerated in the `eventRecorder.SEND_METHOD` object.
|
||||
* Note: This argument will be ignored if appIsExiting is false.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
AbstractEventRecorder.prototype.flushUnreportedEvents = function flushUnreportedEvents() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var self = this;
|
||||
return this._operationPromiseChain.then(function () {
|
||||
// Reset the promise chain
|
||||
self._operationPromiseChain = Promise.resolve();
|
||||
return self._flushUnreportedEvents.apply(self, args);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Abstract recordEvent method
|
||||
* Subclasses implement this method to handle how to record an event
|
||||
* @abstract
|
||||
* @protected
|
||||
* @param {String} topic - an 'override' topic which will override the main topic.
|
||||
* @param {Object} eventFields - a JavaScript object which will be converted to a JSON string and sent to AMP Analytics.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
AbstractEventRecorder.prototype._recordEvent = function _recordEvent(topic, eventFields) {};
|
||||
|
||||
/**
|
||||
* Abstract flushUnreportedEvents method
|
||||
* Subclasses implement this method to handle how to flush the cache events
|
||||
* @abstract
|
||||
* @protected
|
||||
* @param {Boolean} appIsExiting - if events are being flushed due to your app exiting (or page going away for web-apps), pass "true".
|
||||
* This allows MetricsKit to modify its flush strategy to attempt to post events prior to actual termination.
|
||||
* In cases where appIsExiting==false, the parameter may be omitted.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
AbstractEventRecorder.prototype._flushUnreportedEvents = function _flushUnreportedEvents(appIsExiting) {};
|
||||
|
||||
export { AbstractEventRecorder, Delegates };
|
||||
728
shared/metrics-8/node_modules/@amp-metrics/mt-metricskit-delegates-web/dist/mt-metricskit-delegates-web.esm.js
generated
vendored
Normal file
728
shared/metrics-8/node_modules/@amp-metrics/mt-metricskit-delegates-web/dist/mt-metricskit-delegates-web.esm.js
generated
vendored
Normal file
@@ -0,0 +1,728 @@
|
||||
import { AbstractEventRecorder, Delegates } from '@amp-metrics/mt-metricskit-delegates-core';
|
||||
import { EventRecorder as EventRecorder$1, ImmediateEventRecorder, environment, network, logger } from '@amp-metrics/mt-event-queue';
|
||||
import { reflect, backoff } from '@amp-metrics/mt-metricskit-utils-private';
|
||||
|
||||
/*
|
||||
* src/environment.js
|
||||
* mt-metricskit-delegates-web
|
||||
*
|
||||
* Copyright © 2022 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides a pre-built HTML delegate to use against the metrics.system.environment delegate via metrics.system.environment.setDelegate()
|
||||
* If you want to use *most* of these methods, but not *all* of them, you can set this delegate and then create your own with whichever few methods you need to
|
||||
* customize additionally, and then setDelegate() *that* delegate, in order to override those methods.
|
||||
* @constructor
|
||||
* @param {Config} config (optional) - An instance of Config, which contains the topic and the relevant configurations for the topic.
|
||||
*/
|
||||
|
||||
function Environment(config) {
|
||||
this._config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
************************************ PSEUDO-PRIVATE METHODS/IVARS ************************************
|
||||
* These functions need to be accessible for ease of testing, but should not be used by clients
|
||||
*/
|
||||
Environment.prototype._document = function _document() {
|
||||
if (typeof document != 'undefined') {
|
||||
return document;
|
||||
} else {
|
||||
throw "metricskit-delegates-html.environment HTML delegate 'document' object not found";
|
||||
}
|
||||
};
|
||||
|
||||
Environment.prototype._window = function _window() {
|
||||
if (typeof window != 'undefined') {
|
||||
return window;
|
||||
} else {
|
||||
throw "metricskit-delegates-html.environment HTML delegate 'window' object not found";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
************************************ PUBLIC METHODS/IVARS ************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* The name of the browser that generated the event, it only return browser field if "browserMaps" config property exists in the topic config
|
||||
* Common userAgent format: "Mozilla/5.0 (<system-information>) <platform> (<platform-details>) <extensions>"
|
||||
* This implementation will read the browser identifer from the first item in the extensions part of the userAgent.
|
||||
* For those browsers which do not store their browser identifier in the first item (can be configured in "specifiedBrowsers" config, see the below example),
|
||||
* the function will search the defined string in the userAgent to verify if it is the case.
|
||||
* It will load the browser related configurations from "browserMaps" in the topic. The config looks like
|
||||
* {
|
||||
* specifiedBrowsers: string[], // listing the browsers identifiers which does not located in the first item in "extensions" in userAgent.
|
||||
* browserMap: Record<string, string> // map the browser identifiers to readable string. For example, Edg -> Edge, OPR -> Opera
|
||||
* }
|
||||
* @example Safari
|
||||
* @returns {Promise<string | null> | null}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.browser = function browser() {
|
||||
var userAgent = this._window().navigator.userAgent;
|
||||
|
||||
if (!reflect.isDefinedNonNull(this._config) || !reflect.isDefinedNonNullNonEmpty(userAgent)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this._config.value('browserMaps').then(function (browserConfig) {
|
||||
if (!reflect.isDefinedNonNull(browserConfig)) {
|
||||
return null;
|
||||
}
|
||||
var specifiedBrowsers = browserConfig.specifiedBrowsers || [];
|
||||
var browserMap = browserConfig.browserMap || {};
|
||||
var browserIdentifier = null;
|
||||
for (var i = 0; i < specifiedBrowsers.length; i++) {
|
||||
var specifiedBrowser = specifiedBrowsers[i];
|
||||
if (userAgent.indexOf(specifiedBrowser) > -1) {
|
||||
browserIdentifier = specifiedBrowser;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!reflect.isDefinedNonNull(browserIdentifier)) {
|
||||
// The Named capturing group: (?<name>...) requires "ECMAScript 2018"
|
||||
var matches = userAgent.match(/Mozilla\/5.0 \((.*?)\)(\s|$)((.*?)\/(.*?)(\s)\(.*\))?(.*?)\/(.*?)(\s|$)/);
|
||||
if (reflect.isDefinedNonNullNonEmpty(matches) && matches.length >= 8) {
|
||||
browserIdentifier = matches[7];
|
||||
}
|
||||
}
|
||||
|
||||
if (reflect.isDefinedNonNull(browserIdentifier)) {
|
||||
browserIdentifier = browserIdentifier.trim();
|
||||
} else {
|
||||
browserIdentifier = 'unknown';
|
||||
}
|
||||
|
||||
var browser = browserMap[browserIdentifier] || browserIdentifier;
|
||||
return browser;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* The cookie string, e.g. "iTunes.cookie" (iTunes desktop), "iTunes.cookieForDefaultURL" (HTML iOS), "itms.cookie" (itml app), "document.cookie" (browser)
|
||||
* NOTE: Callers should override this method if they want to supply a different cookie.
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.cookie = function cookie() {
|
||||
return this._window().document.cookie;
|
||||
};
|
||||
|
||||
/**
|
||||
* The URL that represents this page.
|
||||
* Typically this is a "deep link" type URL.
|
||||
* If no URL is available, this field may be omitted.
|
||||
* @example "https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewGrouping?cc=us&mt=8"
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.pageUrl = function pageUrl() {
|
||||
return this._window().location.href;
|
||||
};
|
||||
|
||||
/**
|
||||
* The URL of the parent page, if the app is embedded in a parent context.
|
||||
* Typically this is a "deep link" type URL.
|
||||
* If no URL is available, or if the app is not embedded, this field may be omitted.
|
||||
* @example "https://www.apple.com/blog/top-tracks.html"
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
* Note: due to iframe sandbox rules, the parent window's location may not be accessible.
|
||||
* In that case, we fall back to document.referrer, which should be reliable if the app
|
||||
* within the iframe is a single page app (document.referrer changes on every page turn).
|
||||
* If the app in the iframe is not a single page app, we will have to persist the
|
||||
* original referrer from the first page across page turns via e.g. localStorage.
|
||||
* However, this use case is not currently needed by any client.
|
||||
*/
|
||||
Environment.prototype.parentPageUrl = function parentPageUrl() {
|
||||
var windowObject = this._window();
|
||||
var parentWindow = windowObject.parent;
|
||||
var parentPageUrl;
|
||||
|
||||
if (parentWindow !== windowObject) {
|
||||
try {
|
||||
parentPageUrl = parentWindow.location.href;
|
||||
} catch (e) {
|
||||
parentPageUrl = this._document().referrer;
|
||||
}
|
||||
}
|
||||
|
||||
return parentPageUrl;
|
||||
};
|
||||
|
||||
/**
|
||||
* Pixel multiplier factor
|
||||
* @example 2
|
||||
* @returns {number}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.pixelRatio = function pixelRatio() {
|
||||
return this._window().devicePixelRatio;
|
||||
};
|
||||
|
||||
/**
|
||||
* Client screen height in pixels
|
||||
* @example 568
|
||||
* @returns {number}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.screenHeight = function screenHeight() {
|
||||
return this._window().screen.height;
|
||||
};
|
||||
|
||||
/**
|
||||
* Client screen width in pixels
|
||||
* @example 320
|
||||
* @returns {number}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.screenWidth = function screenWidth() {
|
||||
return this._window().screen.width;
|
||||
};
|
||||
|
||||
/**
|
||||
* Client’s user agent string. If the "app field is not provided, "userAgent may be used to derive the value of the "app field
|
||||
* @example AppStore/2.0 iOS/8.3 model/iPhone7,2 build/12F70 (6; dt:106)
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.userAgent = function userAgent() {
|
||||
return this._window().navigator.userAgent;
|
||||
};
|
||||
|
||||
/**
|
||||
* App viewport height in pixels. Does not include window “chrome”, status bars, etc.
|
||||
* Typically only available on desktop windowing systems.
|
||||
* @example 1920
|
||||
* @returns {number/undefined}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.windowInnerHeight = function windowInnerHeight() {
|
||||
return this._window().innerHeight;
|
||||
};
|
||||
|
||||
/**
|
||||
* App viewport width in pixels. Does not include window “chrome”, status bars, etc.
|
||||
* Typically only available on desktop windowing systems.
|
||||
* @example 1080
|
||||
* @returns {number/undefined}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.windowInnerWidth = function windowInnerWidth() {
|
||||
return this._window().innerWidth;
|
||||
};
|
||||
|
||||
/**
|
||||
* Height in pixels of containing window, encompassing app viewport as well as window chrome, status bars, etc.
|
||||
* Typically only available on desktop windowing systems.
|
||||
* @example 1080
|
||||
* @returns {number/undefined}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.windowOuterHeight = function windowOuterHeight() {
|
||||
return this._window().outerHeight;
|
||||
};
|
||||
|
||||
/**
|
||||
* Width in pixels of containing window, encompassing app viewport as well as window chrome, status bars, etc.
|
||||
* Typically only available on desktop windowing systems.
|
||||
* @example 1920
|
||||
* @returns {number/undefined}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.windowOuterWidth = function windowOuterWidth() {
|
||||
return this._window().outerWidth;
|
||||
};
|
||||
|
||||
/**
|
||||
* The offset between W3C timing entry timestamps (which are relative to the page lifecycle) and the epoch time
|
||||
* and the epoch time, in milliseconds
|
||||
* @return {Number}
|
||||
* @overridable
|
||||
* Note: this is only currently used by PerfKit
|
||||
* TODO: <rdar://problem/44976037> Refactor: Delegates: revisit HTML delegate packaging
|
||||
*/
|
||||
Environment.prototype.timeOriginOffset = function timeOriginOffset() {
|
||||
var returnValue = null;
|
||||
var performance = this._window().performance;
|
||||
|
||||
if (performance && performance.timing) {
|
||||
returnValue = performance.timing.navigationStart;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* THE FOLLOWING DATA ARE UNAVAILABLE IN A PURE WEB BROWSER CONTEXT,
|
||||
* BUT MAY BE IMPLEMENTED (VIA POTENTIALLY DIFFERENT APIS) IN VARIOUS HTML WEB VIEW CONTEXTS (iOS vs Desktop vs tvOS)
|
||||
* THEY ARE LEFT UNIMPLEMENTED FOR CONTEXT-SPECIFIC DELEGATES TO OVERWRITE IF APPLICABLE
|
||||
*/
|
||||
|
||||
/**
|
||||
* The app identifier of the binary app
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD SHOULD BE REPLACED
|
||||
* @example "com.apple.appstore" or "com.apple.gamecenter"
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.app = function app() {};
|
||||
|
||||
/**
|
||||
* The version number of this application
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD SHOULD BE REPLACED
|
||||
* @example "1.0", "5.43", etc.
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
* @defaultimpl navigator.appVersion
|
||||
*/
|
||||
Environment.prototype.appVersion = function appVersion() {};
|
||||
|
||||
/**
|
||||
* The total data capacity of the system, without regard for what's already been used or not.
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD SHOULD BE REPLACED
|
||||
* @returns {number}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.capacityData = function capacityData() {};
|
||||
|
||||
/**
|
||||
* The total available data capacity of the system.
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD SHOULD BE REPLACED
|
||||
* @returns {number}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.capacityDataAvailable = function capacityDataAvailable() {};
|
||||
|
||||
/**
|
||||
* The total disk capacity of the system, without regard for what's already been used or not.
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD SHOULD BE REPLACED
|
||||
* @returns {number}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.capacityDisk = function capacityDisk() {};
|
||||
|
||||
/**
|
||||
* The total system capacity, without regard for what's already been used or not.
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD SHOULD BE REPLACED
|
||||
* @returns {number}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.capacitySystem = function capacitySystem() {};
|
||||
|
||||
/**
|
||||
* The total available system capacity of the system.
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD SHOULD BE REPLACED
|
||||
* @api public
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.capacitySystemAvailable = function capacitySystemAvailable() {};
|
||||
|
||||
/**
|
||||
* Type of internet connection.
|
||||
* Only applicable to devices
|
||||
* Beware that users on WiFi may actually be receiving 3G speeds (i.e. if device is tethered to a portable hotspot.)
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD SHOULD BE REPLACED
|
||||
* @example "WiFi, "3G, etc.
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.connectionType = function connectionType() {};
|
||||
|
||||
/**
|
||||
* The id of this user ("directory service id").
|
||||
* This id will get anonymized on the server prior to being saved.
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD SHOULD BE REPLACED
|
||||
* @example 659261189
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.dsId = function dsId() {};
|
||||
|
||||
/**
|
||||
* The hardware brand of the device. Not required for Apple devices.
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example "Samsung", "LG", "Google"
|
||||
* @returns {String}
|
||||
*/
|
||||
Environment.prototype.hardwareBrand = function hardwareBrand() {};
|
||||
|
||||
/**
|
||||
* The hardware family of the device
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example "iPhone", "Macbook Pro"
|
||||
* @returns {String}
|
||||
*/
|
||||
Environment.prototype.hardwareFamily = function hardwareFamily() {};
|
||||
|
||||
/**
|
||||
* The model of the device
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example "iPhone10,2", "MacbookPro11,5"
|
||||
* @returns {String}
|
||||
*/
|
||||
Environment.prototype.hardwareModel = function hardwareModel() {};
|
||||
|
||||
/**
|
||||
* App that is hosting the storesheet or app
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD SHOULD BE REPLACED
|
||||
* @example com.rovio.AngryBirds
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.hostApp = function hostApp() {};
|
||||
|
||||
/**
|
||||
* Version of the app that is hosting the storesheet or app
|
||||
* NO DEFAULT IMPLEMENTATION... HOWEVER: this field is optional
|
||||
* @example "1.0.1"
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.hostAppVersion = function hostAppVersion() {
|
||||
// Optional field value
|
||||
};
|
||||
|
||||
/**
|
||||
* The name of the OS
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example "ios", "macos", "windows"
|
||||
* @returns {String}
|
||||
*/
|
||||
Environment.prototype.os = function os() {};
|
||||
|
||||
/**
|
||||
* The build number of the OS
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example "15D60", "17E192"
|
||||
* @returns {String}
|
||||
*/
|
||||
Environment.prototype.osBuildNumber = function osBuildNumber() {};
|
||||
|
||||
/**
|
||||
* A string array of language IDs, ordered in descending preference
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD MUST BE REPLACED
|
||||
* @example ["en-US", "fr-CA"]
|
||||
* @returns {Array}
|
||||
*/
|
||||
Environment.prototype.osLanguages = function osLanguages() {};
|
||||
|
||||
/**
|
||||
* The full OS version number
|
||||
* In ITML, the value can be retrieved via Device.systemVersion
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD SHOULD BE REPLACED
|
||||
* @example "8.2.1" (iOS) "10.10.3" (Desktop)
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.osVersion = function osVersion() {};
|
||||
|
||||
/**
|
||||
* HTML resources revision number
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD SHOULD BE REPLACED
|
||||
* @example 2C97 or 8.4.0.0.103
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.resourceRevNum = function resourceRevNum() {};
|
||||
|
||||
/**
|
||||
* ISO 3166 Country Code. Apps that cannot provide a storeFrontHeader should provide a storeFrontCountryCode instead
|
||||
* NO DEFAULT IMPLEMENTATION... Either this method or storeFrontHeader must be replaced.
|
||||
* @example US
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.storeFrontCountryCode = function storeFrontCountryCode() {};
|
||||
|
||||
/**
|
||||
* The value contained in the X-Apple-Store-Front header value at the time the event is being created.
|
||||
* NO DEFAULT IMPLEMENTATION... Either this method or storeFrontCountryCode must be replaced.
|
||||
* @example K143441-1,29 ab:rSwnYxS0
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.storeFrontHeader = function storeFrontHeader() {};
|
||||
|
||||
/**
|
||||
* The best supported language for a storefront
|
||||
* NO DEFAULT IMPLEMENTATION... HOWEVER: this field is optional
|
||||
* @example en-US
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.storeFrontLanguage = function storeFrontLanguage() {};
|
||||
|
||||
/**
|
||||
* The type of subscriber this user is.
|
||||
* NO DEFAULT IMPLEMENTATION... THIS METHOD SHOULD BE REPLACED
|
||||
* @example subscribed, notSubscribed, unknown, needsAuthentication
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
Environment.prototype.userType = function userType() {};
|
||||
|
||||
/*
|
||||
* src/event_recorder
|
||||
* mt-metricskit-delegates-web
|
||||
*
|
||||
* Copyright © 2022 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* A proxy EventRecorder to bridge the delegates layer to the mt-event-queue lib
|
||||
* @param eventRecorder - A eventRecorder implementation from the mt-event-queue lib
|
||||
* @constructor
|
||||
*/
|
||||
function EventRecorder(eventRecorder) {
|
||||
AbstractEventRecorder.call(this);
|
||||
this._proxyEventRecorder = eventRecorder;
|
||||
this.SEND_METHOD = eventRecorder.SEND_METHOD;
|
||||
}
|
||||
|
||||
EventRecorder.prototype = Object.create(AbstractEventRecorder.prototype);
|
||||
EventRecorder.prototype.constructor = EventRecorder;
|
||||
|
||||
/**
|
||||
* recordEvent implementation
|
||||
* This is an implementation for "AbstractEventRecorder._recordEvent"
|
||||
* @override
|
||||
* @param topic
|
||||
* @param eventFields
|
||||
* @private
|
||||
*/
|
||||
EventRecorder.prototype._recordEvent = function _recordEvent(topic, eventFields) {
|
||||
return this._proxyEventRecorder.recordEvent.apply(this._proxyEventRecorder, arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* This overrides the same method in AbstractEventRecorder to ignore the pending recorded event when the appExitSendMethod === 'SEND_METHOD.BEACON_SYNCHRONOUS'.
|
||||
* @param {Boolean} appIsExiting - Pass true if events are being flushed due to your app exiting or page going away
|
||||
* (the send method will be different in order to attempt to post events prior to actual termination)
|
||||
* @param {String} appExitSendMethod (optional) the send method for how events will be flushed when the app is exiting.
|
||||
* Possible options are enumerated in the `eventRecorder.SEND_METHOD` object.
|
||||
* Note: This argument will be ignored if appIsExiting is false.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
EventRecorder.prototype.flushUnreportedEvents = function flushUnreportedEvents(appIsExiting, appExitSendMethod) {
|
||||
var self = this;
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
// if this._proxyEventRecorder is an instance of QueuedEventRecorder and the callers wanted to flush events synchronously, ignore the pending events
|
||||
if (
|
||||
reflect.isDefinedNonNull(this._proxyEventRecorder.SEND_METHOD) &&
|
||||
appExitSendMethod === this._proxyEventRecorder.SEND_METHOD.BEACON_SYNCHRONOUS
|
||||
) {
|
||||
return this._proxyEventRecorder.flushUnreportedEvents.apply(this._proxyEventRecorder, arguments);
|
||||
} else {
|
||||
return this._operationPromiseChain.then(function () {
|
||||
// Reset the promise chain
|
||||
self._operationPromiseChain = Promise.resolve();
|
||||
return self._proxyEventRecorder.flushUnreportedEvents.apply(self._proxyEventRecorder, args);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends any remaining events in the queue
|
||||
* This is an implementation for "AbstractEventRecorder._flushUnreportedEvents"
|
||||
* @override
|
||||
*/
|
||||
EventRecorder.prototype._flushUnreportedEvents = function _flushUnreportedEvents() {
|
||||
return this._proxyEventRecorder.flushUnreportedEvents.apply(this._proxyEventRecorder, arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* The methodology being used to send batches of events to the server
|
||||
* This field should be hardcoded in the client based on what method it is using to encode and send its events to Figaro.
|
||||
* The three typical values are:
|
||||
* "itms" - use this value when/if JavaScript code enqueues events for sending via the "itms.recordEvent()" method in ITML.
|
||||
* "itunes" - use this value when/if JavaScript code enqueues events by calling the "iTunes.recordEvent()" method in Desktop Store apps.
|
||||
* "javascript" - use this value when/if JavaScript code enqueues events for sending via the JavaScript eventQueue management. This is typically only used by older clients which don't have the built-in functionality of itms or iTunes available to them.
|
||||
* DEFAULT implementation: console.debug()
|
||||
* @example "itms", "itunes", "javascript"
|
||||
* @returns {String}
|
||||
* @overridable
|
||||
*/
|
||||
EventRecorder.prototype.sendMethod = function sendMethod() {
|
||||
return this._proxyEventRecorder.sendMethod.apply(this._proxyEventRecorder, arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set event queue related properties for the giving topic
|
||||
* @param {String} topic defines the Figaro "topic" that this event should be stored under
|
||||
* @param {Object} properties the event queue properties for the topic
|
||||
* @param {Boolean} properties.anonymous true if sending all events for the topic with credentials omitted(no cookies, no PII fields)
|
||||
*/
|
||||
EventRecorder.prototype.setProperties = function setProperties(topic, properties) {
|
||||
return this._proxyEventRecorder.setProperties.apply(this._proxyEventRecorder, arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* clean resources of event recorder
|
||||
* Subclasses implement this method to handle how to clean resources
|
||||
* @returns {Promise} returns a Promise if the cleanup will asynchronously execute or undefined for synchronously executing
|
||||
*/
|
||||
EventRecorder.prototype.cleanup = function cleanup() {
|
||||
return this._proxyEventRecorder.cleanup.apply(this._proxyEventRecorder, arguments);
|
||||
};
|
||||
|
||||
/*
|
||||
* src/web_delegate.js
|
||||
* mt-metricskit-delegates-web
|
||||
*
|
||||
* Copyright © 2022 Apple Inc. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Delegate for providing access to the "canned" web MetricsKit delegates.
|
||||
* If further modification of these delegates is required, clients may pass in delegate options to override any of the fields within any delegate.
|
||||
* @constructor
|
||||
* @param {String} topic - Defines the AMP Analytics "topic" for events to be stored under
|
||||
* @param {Object} delegateOptions (optional) - Options that can be passed to either add additional delegates or to extend/override existing ones.
|
||||
*/
|
||||
var WebDelegates = function WebDelegates(topic, delegateOptions) {
|
||||
var config = this.getOrCreateConfig(topic);
|
||||
Delegates.call(this, topic, {
|
||||
environment: new Environment(config),
|
||||
eventRecorder: new EventRecorder(new EventRecorder$1(config))
|
||||
});
|
||||
|
||||
this.immediateEventRecorder = new EventRecorder(new ImmediateEventRecorder(config));
|
||||
this.network = null;
|
||||
this.logger = null;
|
||||
|
||||
if (delegateOptions) {
|
||||
this.mergeDelegates(delegateOptions);
|
||||
|
||||
if (delegateOptions.environment) {
|
||||
this.setEnvironment(delegateOptions.environment);
|
||||
}
|
||||
|
||||
if (delegateOptions.eventRecorder) {
|
||||
this.setEventRecorder(delegateOptions.eventRecorder);
|
||||
}
|
||||
|
||||
if (delegateOptions.network) {
|
||||
this.setNetwork(delegateOptions.network);
|
||||
}
|
||||
|
||||
if (delegateOptions.logger) {
|
||||
this.setLogger(delegateOptions.logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: We are temporarily setting this configUrl() delegate on the config to avoid breaking changes.
|
||||
* In the next major release, we will remove this and just fetch the config from
|
||||
* the delegateOptions.config.url directly instead of reading it from
|
||||
* this config method (defaulting to https://xp.apple.com/config/1/report/<topic>).
|
||||
*/
|
||||
if (delegateOptions.config) {
|
||||
if (delegateOptions.config.url) {
|
||||
this.config.setDelegate({
|
||||
configUrl: delegateOptions.config.url
|
||||
});
|
||||
}
|
||||
this.setConfig(delegateOptions.config);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Inherit from the base Delegate class
|
||||
*/
|
||||
WebDelegates.prototype = Object.create(Delegates.prototype);
|
||||
WebDelegates.prototype.constructor = WebDelegates;
|
||||
|
||||
/**
|
||||
* Sets the environment for the web-specific event queue as well as setting it on the delegate itself.
|
||||
* @param {Object} environment
|
||||
* @returns {WebDelegates}
|
||||
*/
|
||||
WebDelegates.prototype.setEnvironment = function (environment$1) {
|
||||
environment.setDelegate(environment$1);
|
||||
return Delegates.prototype.setEnvironment.call(this, environment$1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the network for the web-specific event queue as well as setting it on the delegate itself.
|
||||
* @param {Object} network
|
||||
* @returns {WebDelegates}
|
||||
*/
|
||||
WebDelegates.prototype.setNetwork = function (network$1) {
|
||||
if (network$1) {
|
||||
this.network = network$1;
|
||||
network.setDelegate(network$1);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the logger for the web-specific event queue as well as setting it on the delegate itself.
|
||||
* @param {Object} logger
|
||||
* @returns {WebDelegates}
|
||||
*/
|
||||
WebDelegates.prototype.setLogger = function (logger$1) {
|
||||
if (logger$1) {
|
||||
this.logger = logger$1;
|
||||
logger.setDelegate(logger$1);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the immediate event recorder for the delegate.
|
||||
* Note: Immediate event recorders are specific to web delegates.
|
||||
* @param {Object} immediateEventRecorder
|
||||
* @returns {WebDelegates}
|
||||
*/
|
||||
WebDelegates.prototype.setImmediateEventRecorder = function (immediateEventRecorder) {
|
||||
if (immediateEventRecorder) {
|
||||
var newImmediateEventRecorder = Object.create(this.immediateEventRecorder);
|
||||
Object.assign(newImmediateEventRecorder, immediateEventRecorder);
|
||||
this.immediateEventRecorder = newImmediateEventRecorder;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {Object} The config sources.
|
||||
*/
|
||||
WebDelegates.prototype.configSources = function configSources() {
|
||||
var self = this;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
var onFetchSuccess = function onFetchSuccess(response) {
|
||||
try {
|
||||
var configObject = JSON.parse(response);
|
||||
self.config.setCachedSource(configObject);
|
||||
self.config.setServiceSource(configObject); // TODO: Deprecated
|
||||
resolve(configObject);
|
||||
} catch (error) {
|
||||
onFetchFailure(error);
|
||||
}
|
||||
};
|
||||
|
||||
var onFetchFailure = function onFetchFailure(error) {
|
||||
self.config.setCachedSource(self.config.cachedSource());
|
||||
reject(error);
|
||||
};
|
||||
|
||||
var configUrlPromise = Promise.resolve(self.config.configUrl());
|
||||
|
||||
configUrlPromise
|
||||
.then(function (configUrl) {
|
||||
backoff.exponentialBackoff(
|
||||
self.config.network.makeAjaxRequest.bind(self.config.network, configUrl, 'GET', null),
|
||||
onFetchSuccess,
|
||||
onFetchFailure
|
||||
);
|
||||
})
|
||||
.catch(onFetchFailure);
|
||||
});
|
||||
};
|
||||
|
||||
export { Environment, WebDelegates };
|
||||
4045
shared/metrics-8/node_modules/@amp-metrics/mt-metricskit-processor-clickstream/dist/mt-metricskit-processor-clickstream.esm.js
generated
vendored
Normal file
4045
shared/metrics-8/node_modules/@amp-metrics/mt-metricskit-processor-clickstream/dist/mt-metricskit-processor-clickstream.esm.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2428
shared/metrics-8/node_modules/@amp-metrics/mt-metricskit-utils-private/dist/mt-metricskit-utils-private.esm.js
generated
vendored
Normal file
2428
shared/metrics-8/node_modules/@amp-metrics/mt-metricskit-utils-private/dist/mt-metricskit-utils-private.esm.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
64
shared/metrics-8/node_modules/@jet/engine/lib/actions/action-dispatcher.js
generated
vendored
Normal file
64
shared/metrics-8/node_modules/@jet/engine/lib/actions/action-dispatcher.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ActionDispatcher = void 0;
|
||||
const optional_1 = require("@jet/environment/types/optional");
|
||||
class ActionDispatcher {
|
||||
constructor(metricsPipeline) {
|
||||
this.implementations = {};
|
||||
this.metricsPipeline = metricsPipeline;
|
||||
}
|
||||
register(type, implementation) {
|
||||
if (type in this.implementations) {
|
||||
console.error(`An implementation is already registered for ${type}`);
|
||||
}
|
||||
this.implementations[type] = implementation;
|
||||
}
|
||||
async perform(action, metricsBehavior) {
|
||||
if (!(action.$kind in this.implementations)) {
|
||||
// 1. If there is no implementation registered for the type of action
|
||||
// we were passed, we check for a chained dispatcher to forward to.
|
||||
// If one is found, we forward this call without doing any work.
|
||||
// If none is found, we give up.
|
||||
if (optional_1.isSome(this.next)) {
|
||||
return await this.next.perform(action, metricsBehavior);
|
||||
}
|
||||
else {
|
||||
return "unsupported";
|
||||
}
|
||||
}
|
||||
// 2. We have an implementation for the action we were given.
|
||||
// We are responsible for processing metrics for that action.
|
||||
this.processMetrics(action, metricsBehavior);
|
||||
if (optional_1.isSome(this.next)) {
|
||||
// 3a. If we have another dispatcher we are chained to, we forward to it
|
||||
// if the implementation we have for the given action decides it cannot
|
||||
// support performing it.
|
||||
const outcome = await this.implementations[action.$kind](action);
|
||||
if (outcome === "unsupported") {
|
||||
return await this.next.perform(action, { behavior: "notProcessed" });
|
||||
}
|
||||
else {
|
||||
return outcome;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 3b. We hand off control to the implementation we have for the given action type.
|
||||
// If the implementation cannot perform the action, we give up.
|
||||
return await this.implementations[action.$kind](action);
|
||||
}
|
||||
}
|
||||
processMetrics(action, metricsBehavior) {
|
||||
if (metricsBehavior.behavior === "notProcessed") {
|
||||
return;
|
||||
}
|
||||
const actionMetrics = action.actionMetrics;
|
||||
const context = {
|
||||
customMetrics: actionMetrics.custom,
|
||||
pageFields: metricsBehavior.context.pageFields,
|
||||
};
|
||||
action.actionMetrics.data.forEach((data) => {
|
||||
this.metricsPipeline.process(data, context);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.ActionDispatcher = ActionDispatcher;
|
||||
13
shared/metrics-8/node_modules/@jet/engine/lib/actions/index.js
generated
vendored
Normal file
13
shared/metrics-8/node_modules/@jet/engine/lib/actions/index.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (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("./action-dispatcher"), exports);
|
||||
17
shared/metrics-8/node_modules/@jet/engine/lib/dependencies/index.js
generated
vendored
Normal file
17
shared/metrics-8/node_modules/@jet/engine/lib/dependencies/index.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (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("./jet-bag"), exports);
|
||||
__exportStar(require("./jet-host"), exports);
|
||||
__exportStar(require("./jet-network-fetch"), exports);
|
||||
__exportStar(require("./localized-strings-bundle"), exports);
|
||||
__exportStar(require("./localized-strings-json-object"), exports);
|
||||
40
shared/metrics-8/node_modules/@jet/engine/lib/dependencies/jet-bag.js
generated
vendored
Normal file
40
shared/metrics-8/node_modules/@jet/engine/lib/dependencies/jet-bag.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JetBag = void 0;
|
||||
class JetBag {
|
||||
constructor(backing) {
|
||||
this.backing = backing;
|
||||
}
|
||||
registerBagKeys() {
|
||||
// do nothing.
|
||||
}
|
||||
string(key) {
|
||||
const value = this.backing[key];
|
||||
return typeof value === "string" || value === null ? value : undefined;
|
||||
}
|
||||
double(key) {
|
||||
const value = this.backing[key];
|
||||
return typeof value === "number" || value === null ? value : undefined;
|
||||
}
|
||||
integer(key) {
|
||||
const value = this.backing[key];
|
||||
return typeof value === "number" || value === null ? value : undefined;
|
||||
}
|
||||
boolean(key) {
|
||||
const value = this.backing[key];
|
||||
return typeof value === "boolean" || value === null ? value : undefined;
|
||||
}
|
||||
array(key) {
|
||||
const value = this.backing[key];
|
||||
return Array.isArray(value) || value === null ? value : undefined;
|
||||
}
|
||||
dictionary(key) {
|
||||
const value = this.backing[key];
|
||||
return typeof value === "object" ? value : undefined;
|
||||
}
|
||||
url(key) {
|
||||
const value = this.backing[key];
|
||||
return typeof value === "string" ? value : undefined;
|
||||
}
|
||||
}
|
||||
exports.JetBag = JetBag;
|
||||
19
shared/metrics-8/node_modules/@jet/engine/lib/dependencies/jet-host.js
generated
vendored
Normal file
19
shared/metrics-8/node_modules/@jet/engine/lib/dependencies/jet-host.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JetHost = void 0;
|
||||
class JetHost {
|
||||
constructor(options) {
|
||||
this.osBuild = "unknown";
|
||||
this.deviceModel = "unknown";
|
||||
this.deviceModelFamily = "unknown";
|
||||
this.devicePhysicalModel = "unknown";
|
||||
this.deviceLocalizedModel = "unknown";
|
||||
this.clientIdentifier = "unknown";
|
||||
this.clientVersion = "unknown";
|
||||
this.platform = options.platform;
|
||||
}
|
||||
isOSAtLeast() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.JetHost = JetHost;
|
||||
39
shared/metrics-8/node_modules/@jet/engine/lib/dependencies/jet-network-fetch.js
generated
vendored
Normal file
39
shared/metrics-8/node_modules/@jet/engine/lib/dependencies/jet-network-fetch.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JetNetworkFetch = void 0;
|
||||
const optional_1 = require("@jet/environment/types/optional");
|
||||
class JetNetworkFetch {
|
||||
async fetch(request) {
|
||||
var _a, _b, _c;
|
||||
if (optional_1.isNothing(process === null || process === void 0 ? void 0 : process.env.MEDIA_API_TOKEN)) {
|
||||
return await Promise.reject(new Error("process.env.MEDIA_API_TOKEN must be specified"));
|
||||
}
|
||||
const headers = {
|
||||
...((_a = request.headers) !== null && _a !== void 0 ? _a : {}),
|
||||
authorization: `Bearer ${process === null || process === void 0 ? void 0 : process.env.MEDIA_API_TOKEN}`,
|
||||
};
|
||||
const response = await fetch(request.url, {
|
||||
body: request.body,
|
||||
method: (_b = request.method) !== null && _b !== void 0 ? _b : undefined,
|
||||
cache: (_c = request.cache) !== null && _c !== void 0 ? _c : undefined,
|
||||
headers: headers,
|
||||
});
|
||||
return {
|
||||
ok: response.ok,
|
||||
headers: Array.from(response.headers.keys()).reduce((previous, key) => {
|
||||
const value = response.headers.get(key);
|
||||
if (optional_1.isSome(value)) {
|
||||
previous[key] = value;
|
||||
}
|
||||
return previous;
|
||||
}, {}),
|
||||
redirected: response.redirected,
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
url: response.url,
|
||||
body: await response.text(),
|
||||
metrics: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.JetNetworkFetch = JetNetworkFetch;
|
||||
68
shared/metrics-8/node_modules/@jet/engine/lib/dependencies/localized-strings-bundle.js
generated
vendored
Normal file
68
shared/metrics-8/node_modules/@jet/engine/lib/dependencies/localized-strings-bundle.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LocalizedStringsBundle = void 0;
|
||||
const environment_1 = require("@jet/environment");
|
||||
const localized_strings_json_object_1 = require("./localized-strings-json-object");
|
||||
/**
|
||||
* A localized string data source which loads strings from the application bundle.
|
||||
*
|
||||
* The bundle used by this data source can be a web app webpack bundle
|
||||
* or a native app bundle bridged over to JS code.
|
||||
*/
|
||||
class LocalizedStringsBundle {
|
||||
// MARK: - Initialization
|
||||
/**
|
||||
* Create localized strings bundle with all required attributes.
|
||||
*
|
||||
* @param bundle - The app bundle object.
|
||||
*/
|
||||
constructor(bundle) {
|
||||
this.bundle = bundle;
|
||||
}
|
||||
// MARK: - LocalizedStringsDataSource
|
||||
async fetchStrings(language) {
|
||||
var _a;
|
||||
// Load the strings from bundle and cache them.
|
||||
const localizations = this.bundle.localizationsProperty;
|
||||
if (environment_1.isNothing(localizations)) {
|
||||
throw new Error("Localized strings bundle index file is missing 'localizations' property");
|
||||
}
|
||||
let strings;
|
||||
const format = (_a = localizations.format) !== null && _a !== void 0 ? _a : "json/inline" /* jsonInline */;
|
||||
if (format === "json/inline" /* jsonInline */) {
|
||||
const inlineLocalizations = localizations;
|
||||
strings = inlineLocalizations[language];
|
||||
}
|
||||
else {
|
||||
const externalLocalizations = localizations;
|
||||
switch (externalLocalizations.format) {
|
||||
case "json/multi-file" /* jsonMultiFile */:
|
||||
{
|
||||
// The path points to directory where JSON files are located.
|
||||
// We don't even have to list a directory, just construct a final path.
|
||||
// The path is also not an OS path but a bundle (e.g. JetPack) path.
|
||||
// Bundle APIs always use "/" in the path, same as the paths used in the
|
||||
// index.json (manifest) files.
|
||||
const jsonPath = `${externalLocalizations.path}/${language}.json`;
|
||||
strings = (await this.bundle.loadResource(jsonPath));
|
||||
}
|
||||
break;
|
||||
case "json/single-file" /* jsonSingleFile */:
|
||||
// The bundle contains single JSON file with all strings dictionary in it.
|
||||
strings = (await this.bundle.loadResource(externalLocalizations.path))[language];
|
||||
break;
|
||||
case "loctable" /* loctable */:
|
||||
throw new Error("Loctable format not supported in JS implementation");
|
||||
case "js" /* js */:
|
||||
throw new Error("Not yet implemented");
|
||||
default:
|
||||
throw new Error(`Unknown localization format: ${JSON.stringify(format)}`);
|
||||
}
|
||||
}
|
||||
if (environment_1.isNothing(strings)) {
|
||||
throw new Error(`Missing strings for ${language}`);
|
||||
}
|
||||
return new localized_strings_json_object_1.LocalizedStringsJSONObject(strings);
|
||||
}
|
||||
}
|
||||
exports.LocalizedStringsBundle = LocalizedStringsBundle;
|
||||
21
shared/metrics-8/node_modules/@jet/engine/lib/dependencies/localized-strings-json-object.js
generated
vendored
Normal file
21
shared/metrics-8/node_modules/@jet/engine/lib/dependencies/localized-strings-json-object.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LocalizedStringsJSONObject = void 0;
|
||||
/**
|
||||
* A type providing access to underlying localized strings JSON object.
|
||||
*/
|
||||
class LocalizedStringsJSONObject {
|
||||
/**
|
||||
* Create localized strings JSON object.
|
||||
*
|
||||
* @param strings - A dictionary containing localized strings.
|
||||
*/
|
||||
constructor(strings) {
|
||||
this.strings = strings;
|
||||
}
|
||||
// MARK: - Localized Strings
|
||||
string(key) {
|
||||
return this.strings[key];
|
||||
}
|
||||
}
|
||||
exports.LocalizedStringsJSONObject = LocalizedStringsJSONObject;
|
||||
15
shared/metrics-8/node_modules/@jet/engine/lib/index.js
generated
vendored
Normal file
15
shared/metrics-8/node_modules/@jet/engine/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (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("./actions"), exports);
|
||||
__exportStar(require("./dependencies"), exports);
|
||||
__exportStar(require("./metrics"), exports);
|
||||
16
shared/metrics-8/node_modules/@jet/engine/lib/metrics/aggregating/index.js
generated
vendored
Normal file
16
shared/metrics-8/node_modules/@jet/engine/lib/metrics/aggregating/index.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (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("./metrics-fields-aggregator"), exports);
|
||||
__exportStar(require("./metrics-fields-builder"), exports);
|
||||
__exportStar(require("./metrics-fields-context"), exports);
|
||||
__exportStar(require("./metrics-fields-provider"), exports);
|
||||
45
shared/metrics-8/node_modules/@jet/engine/lib/metrics/aggregating/metrics-fields-aggregator.js
generated
vendored
Normal file
45
shared/metrics-8/node_modules/@jet/engine/lib/metrics/aggregating/metrics-fields-aggregator.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MetricsFieldsAggregator = void 0;
|
||||
const optional_1 = require("@jet/environment/types/optional");
|
||||
const page_metrics_fields_provider_1 = require("../field-providers/page-metrics-fields-provider");
|
||||
class MetricsFieldsAggregator {
|
||||
constructor() {
|
||||
this.optInProviders = new Map();
|
||||
this.optOutProviders = new Map();
|
||||
}
|
||||
static makeDefaultAggregator() {
|
||||
const aggregator = new MetricsFieldsAggregator();
|
||||
aggregator.addOptInProvider(new page_metrics_fields_provider_1.PageMetricsFieldsProvider(), "pageFields");
|
||||
return aggregator;
|
||||
}
|
||||
addOptInProvider(provider, request) {
|
||||
this.optInProviders.set(request, provider);
|
||||
}
|
||||
addOptOutProvider(provider, request) {
|
||||
this.optOutProviders.set(request, provider);
|
||||
}
|
||||
removeOptInProvider(request) {
|
||||
this.optInProviders.delete(request);
|
||||
}
|
||||
removeOptOutProvider(request) {
|
||||
this.optOutProviders.delete(request);
|
||||
}
|
||||
addMetricsFields(options) {
|
||||
options.including.forEach((request) => {
|
||||
const provider = this.optInProviders.get(request);
|
||||
if (optional_1.isNothing(provider)) {
|
||||
// No provider registered
|
||||
return;
|
||||
}
|
||||
provider.addMetricsFields(options.builder, options.context);
|
||||
});
|
||||
this.optOutProviders.forEach((provider, request) => {
|
||||
if (optional_1.isNothing(provider) || options.excluding.includes(request)) {
|
||||
return;
|
||||
}
|
||||
provider.addMetricsFields(options.builder, options.context);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.MetricsFieldsAggregator = MetricsFieldsAggregator;
|
||||
15
shared/metrics-8/node_modules/@jet/engine/lib/metrics/aggregating/metrics-fields-builder.js
generated
vendored
Normal file
15
shared/metrics-8/node_modules/@jet/engine/lib/metrics/aggregating/metrics-fields-builder.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SimpleMetricsFieldsBuilder = void 0;
|
||||
class SimpleMetricsFieldsBuilder {
|
||||
constructor(baseFields) {
|
||||
this.fields = baseFields;
|
||||
}
|
||||
addValue(value, field) {
|
||||
this.fields[field] = value;
|
||||
}
|
||||
get allMetricsFields() {
|
||||
return this.fields;
|
||||
}
|
||||
}
|
||||
exports.SimpleMetricsFieldsBuilder = SimpleMetricsFieldsBuilder;
|
||||
2
shared/metrics-8/node_modules/@jet/engine/lib/metrics/aggregating/metrics-fields-context.js
generated
vendored
Normal file
2
shared/metrics-8/node_modules/@jet/engine/lib/metrics/aggregating/metrics-fields-context.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
2
shared/metrics-8/node_modules/@jet/engine/lib/metrics/aggregating/metrics-fields-provider.js
generated
vendored
Normal file
2
shared/metrics-8/node_modules/@jet/engine/lib/metrics/aggregating/metrics-fields-provider.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
13
shared/metrics-8/node_modules/@jet/engine/lib/metrics/field-providers/index.js
generated
vendored
Normal file
13
shared/metrics-8/node_modules/@jet/engine/lib/metrics/field-providers/index.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (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("./page-metrics-fields-provider"), exports);
|
||||
19
shared/metrics-8/node_modules/@jet/engine/lib/metrics/field-providers/page-metrics-fields-provider.js
generated
vendored
Normal file
19
shared/metrics-8/node_modules/@jet/engine/lib/metrics/field-providers/page-metrics-fields-provider.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PageMetricsFieldsProvider = void 0;
|
||||
const optional_1 = require("@jet/environment/types/optional");
|
||||
class PageMetricsFieldsProvider {
|
||||
addMetricsFields(builder, context) {
|
||||
const pageFields = context.pageFields;
|
||||
if (optional_1.isNothing(pageFields)) {
|
||||
// No page fields
|
||||
return;
|
||||
}
|
||||
for (const field in pageFields) {
|
||||
if (Object.prototype.hasOwnProperty.call(pageFields, field)) {
|
||||
builder.addValue(pageFields[field], field);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.PageMetricsFieldsProvider = PageMetricsFieldsProvider;
|
||||
18
shared/metrics-8/node_modules/@jet/engine/lib/metrics/index.js
generated
vendored
Normal file
18
shared/metrics-8/node_modules/@jet/engine/lib/metrics/index.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (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("./aggregating"), exports);
|
||||
__exportStar(require("./field-providers"), exports);
|
||||
__exportStar(require("./linting"), exports);
|
||||
__exportStar(require("./presenters"), exports);
|
||||
__exportStar(require("./metrics-pipeline"), exports);
|
||||
__exportStar(require("./recording"), exports);
|
||||
13
shared/metrics-8/node_modules/@jet/engine/lib/metrics/linting/index.js
generated
vendored
Normal file
13
shared/metrics-8/node_modules/@jet/engine/lib/metrics/linting/index.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (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("./metrics-event-linter"), exports);
|
||||
2
shared/metrics-8/node_modules/@jet/engine/lib/metrics/linting/metrics-event-linter.js
generated
vendored
Normal file
2
shared/metrics-8/node_modules/@jet/engine/lib/metrics/linting/metrics-event-linter.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
35
shared/metrics-8/node_modules/@jet/engine/lib/metrics/metrics-pipeline.js
generated
vendored
Normal file
35
shared/metrics-8/node_modules/@jet/engine/lib/metrics/metrics-pipeline.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MetricsPipeline = exports.FlushBehavior = void 0;
|
||||
const metrics_fields_builder_1 = require("./aggregating/metrics-fields-builder");
|
||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
||||
var FlushBehavior;
|
||||
(function (FlushBehavior) {
|
||||
FlushBehavior[FlushBehavior["automatic"] = 0] = "automatic";
|
||||
FlushBehavior[FlushBehavior["never"] = 1] = "never";
|
||||
})(FlushBehavior = exports.FlushBehavior || (exports.FlushBehavior = {}));
|
||||
class MetricsPipeline {
|
||||
constructor(options) {
|
||||
var _a;
|
||||
this.aggregator = options.aggregator;
|
||||
this.linter = options.linter;
|
||||
this.recorder = options.recorder;
|
||||
this.flushBehavior = (_a = options.flushBehavior) !== null && _a !== void 0 ? _a : FlushBehavior.automatic;
|
||||
}
|
||||
async process(data, context) {
|
||||
const builder = new metrics_fields_builder_1.SimpleMetricsFieldsBuilder(data.fields);
|
||||
this.aggregator.addMetricsFields({
|
||||
including: data.includingFields,
|
||||
excluding: data.excludingFields,
|
||||
builder: builder,
|
||||
context: context,
|
||||
});
|
||||
const lintedEvent = await this.linter.processEvent(builder.allMetricsFields);
|
||||
this.recorder.record(lintedEvent, data.topic);
|
||||
if (data.shouldFlush && this.flushBehavior === FlushBehavior.automatic) {
|
||||
this.recorder.flush();
|
||||
}
|
||||
return lintedEvent;
|
||||
}
|
||||
}
|
||||
exports.MetricsPipeline = MetricsPipeline;
|
||||
13
shared/metrics-8/node_modules/@jet/engine/lib/metrics/presenters/index.js
generated
vendored
Normal file
13
shared/metrics-8/node_modules/@jet/engine/lib/metrics/presenters/index.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (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("./page-metrics-presenter"), exports);
|
||||
51
shared/metrics-8/node_modules/@jet/engine/lib/metrics/presenters/page-metrics-presenter.js
generated
vendored
Normal file
51
shared/metrics-8/node_modules/@jet/engine/lib/metrics/presenters/page-metrics-presenter.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PageMetricsPresenter = void 0;
|
||||
const optional_1 = require("@jet/environment/types/optional");
|
||||
class PageMetricsPresenter {
|
||||
constructor(metricsPipeline) {
|
||||
this.metricsPipeline = metricsPipeline;
|
||||
this.isViewAppeared = false;
|
||||
}
|
||||
set pageMetrics(pageMetrics) {
|
||||
this.pageMetricsStore = pageMetrics;
|
||||
if (optional_1.isSome(pageMetrics) && this.isViewAppeared) {
|
||||
this.processInstructions("pageEnter");
|
||||
}
|
||||
}
|
||||
get pageMetrics() {
|
||||
return this.pageMetricsStore;
|
||||
}
|
||||
async processInstructions(invocationPoint) {
|
||||
var _a, _b, _c;
|
||||
if (optional_1.isNothing(this.pageMetrics)) {
|
||||
return;
|
||||
}
|
||||
// istanbul ignore next
|
||||
const invocationContext = {
|
||||
customMetrics: (_a = this.baseContext) === null || _a === void 0 ? void 0 : _a.customMetrics,
|
||||
pageFields: {
|
||||
...(_b = this.baseContext) === null || _b === void 0 ? void 0 : _b.pageFields,
|
||||
...(_c = this.pageMetrics) === null || _c === void 0 ? void 0 : _c.pageFields,
|
||||
},
|
||||
};
|
||||
await Promise.all(this.pageMetrics.instructions.map((instruction) => {
|
||||
const { invocationPoints } = instruction;
|
||||
if (invocationPoints.length === 0 || !invocationPoints.includes(invocationPoint)) {
|
||||
return;
|
||||
}
|
||||
return this.metricsPipeline.process(instruction.data, invocationContext);
|
||||
}));
|
||||
}
|
||||
async didEnterPage() {
|
||||
this.isViewAppeared = true;
|
||||
if (optional_1.isSome(this.pageMetrics)) {
|
||||
await this.processInstructions("pageEnter");
|
||||
}
|
||||
}
|
||||
async didLeavePage() {
|
||||
await this.processInstructions("pageExit");
|
||||
this.isViewAppeared = false;
|
||||
}
|
||||
}
|
||||
exports.PageMetricsPresenter = PageMetricsPresenter;
|
||||
14
shared/metrics-8/node_modules/@jet/engine/lib/metrics/recording/index.js
generated
vendored
Normal file
14
shared/metrics-8/node_modules/@jet/engine/lib/metrics/recording/index.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (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("./logging-event-recorder"), exports);
|
||||
__exportStar(require("./metrics-event-recorder"), exports);
|
||||
13
shared/metrics-8/node_modules/@jet/engine/lib/metrics/recording/logging-event-recorder.js
generated
vendored
Normal file
13
shared/metrics-8/node_modules/@jet/engine/lib/metrics/recording/logging-event-recorder.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LoggingEventRecorder = void 0;
|
||||
class LoggingEventRecorder {
|
||||
record(event) {
|
||||
console.log(`Record Event [${String(event.fields.eventType)}]`, event);
|
||||
}
|
||||
async flush() {
|
||||
console.log("Flushing");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
exports.LoggingEventRecorder = LoggingEventRecorder;
|
||||
2
shared/metrics-8/node_modules/@jet/engine/lib/metrics/recording/metrics-event-recorder.js
generated
vendored
Normal file
2
shared/metrics-8/node_modules/@jet/engine/lib/metrics/recording/metrics-event-recorder.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
19
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/index.js
generated
vendored
Normal file
19
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/index.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (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("./models"), exports);
|
||||
__exportStar(require("./types/globals"), exports);
|
||||
__exportStar(require("./types/javascriptcore"), exports);
|
||||
__exportStar(require("./types/metrics"), exports);
|
||||
__exportStar(require("./types/models"), exports);
|
||||
__exportStar(require("./types/optional"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
250
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/json/validation.js
generated
vendored
Normal file
250
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/json/validation.js
generated
vendored
Normal file
@@ -0,0 +1,250 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.unexpectedNull = exports.catchingContext = exports.context = exports.recordValidationIncidents = exports.endContext = exports.getContextNames = exports.beginContext = exports.messageForRecoveryAction = exports.isValidatable = exports.unexpectedType = exports.extendedTypeof = void 0;
|
||||
const optional_1 = require("../types/optional");
|
||||
/**
|
||||
* Returns a string containing the type of a given value.
|
||||
* This function augments the built in `typeof` operator
|
||||
* to return sensible values for arrays and null values.
|
||||
*
|
||||
* @privateRemarks
|
||||
* This function is exported for testing.
|
||||
*
|
||||
* @param value - The value to find the type of.
|
||||
* @returns A string containing the type of `value`.
|
||||
*/
|
||||
function extendedTypeof(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return "array";
|
||||
}
|
||||
else if (value === null) {
|
||||
return "null";
|
||||
}
|
||||
else {
|
||||
return typeof value;
|
||||
}
|
||||
}
|
||||
exports.extendedTypeof = extendedTypeof;
|
||||
/**
|
||||
* Reports a non-fatal validation failure, logging a message to the console.
|
||||
* @param recovery - The recovery action taken when the bad type was found.
|
||||
* @param expected - The expected type of the value.
|
||||
* @param actual - The actual value.
|
||||
* @param pathString - A string containing the path to the value on the object which failed type validation.
|
||||
*/
|
||||
function unexpectedType(recovery, expected, actual, pathString) {
|
||||
const actualType = extendedTypeof(actual);
|
||||
const prettyPath = optional_1.isSome(pathString) && pathString.length > 0 ? pathString : "<this>";
|
||||
trackIncident({
|
||||
type: "badType",
|
||||
expected: expected,
|
||||
// Our test assertions are matching the string interpolation of ${actual} value.
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
actual: `${actualType} (${actual})`,
|
||||
objectPath: prettyPath,
|
||||
contextNames: getContextNames(),
|
||||
recoveryAction: recovery,
|
||||
stack: new Error().stack,
|
||||
});
|
||||
}
|
||||
exports.unexpectedType = unexpectedType;
|
||||
// endregion
|
||||
/**
|
||||
* Determines if a given object conforms to the Validatable interface
|
||||
* @param possibleValidatable - An object that might be considered validatable
|
||||
*
|
||||
* @returns `true` if it is an instance of Validatable, `false` if not
|
||||
*/
|
||||
function isValidatable(possibleValidatable) {
|
||||
if (optional_1.isNothing(possibleValidatable)) {
|
||||
return false;
|
||||
}
|
||||
// MAINTAINER'S NOTE: We must check for either the existence of a pre-existing incidents
|
||||
// property *or* the ability to add one. Failure to do so will cause
|
||||
// problems for clients that either a) use interfaces to define their
|
||||
// view models; or b) return collections from their service routes.
|
||||
return (Object.prototype.hasOwnProperty.call(possibleValidatable, "$incidents") ||
|
||||
Object.isExtensible(possibleValidatable));
|
||||
}
|
||||
exports.isValidatable = isValidatable;
|
||||
/**
|
||||
* Returns a developer-readable diagnostic message for a given recovery action.
|
||||
* @param action - The recovery action to get the message for.
|
||||
* @returns The message for `action`.
|
||||
*/
|
||||
function messageForRecoveryAction(action) {
|
||||
switch (action) {
|
||||
case "coercedValue":
|
||||
return "Coerced format";
|
||||
case "defaultValue":
|
||||
return "Default value used";
|
||||
case "ignoredValue":
|
||||
return "Ignored value";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
exports.messageForRecoveryAction = messageForRecoveryAction;
|
||||
// region Contexts
|
||||
/**
|
||||
* Shared validation context "stack".
|
||||
*
|
||||
* Because validation incidents propagate up the context stack,
|
||||
* the representation used here is optimized for memory usage.
|
||||
* A more literal representation of this would be a singly linked
|
||||
* list describing a basic stack, but that will produce a large
|
||||
* amount of unnecessary garbage and require copying `incidents`
|
||||
* arrays backwards.
|
||||
*/
|
||||
const contextState = {
|
||||
/// The names of each validation context on the stack.
|
||||
nameStack: Array(),
|
||||
/// All incidents reported so far. Cleared when the
|
||||
/// context stack is emptied.
|
||||
incidents: Array(),
|
||||
// TODO: Removal of this is being tracked here:
|
||||
// <rdar://problem/35015460> Intro Pricing: Un-suppress missing parent 'offers' error when server address missing key
|
||||
/// The paths for incidents we wish to forgo tracking.
|
||||
suppressedIncidentPaths: Array(),
|
||||
};
|
||||
/**
|
||||
* Begin a new validation context with a given name,
|
||||
* pushing it onto the validation context stack.
|
||||
* @param name - The name for the validation context.
|
||||
*/
|
||||
function beginContext(name) {
|
||||
contextState.nameStack.push(name);
|
||||
}
|
||||
exports.beginContext = beginContext;
|
||||
/**
|
||||
* Traverses the validation context stack and collects all of the context names.
|
||||
* @returns The names of all validation contexts on the stack, from oldest to newest.
|
||||
*/
|
||||
function getContextNames() {
|
||||
if (contextState.nameStack.length === 0) {
|
||||
return ["<empty stack>"];
|
||||
}
|
||||
return contextState.nameStack.slice(0);
|
||||
}
|
||||
exports.getContextNames = getContextNames;
|
||||
/**
|
||||
* Ends the current validation context
|
||||
*/
|
||||
function endContext() {
|
||||
if (contextState.nameStack.length === 0) {
|
||||
console.warn("endContext() called without active validation context, ignoring");
|
||||
}
|
||||
contextState.nameStack.pop();
|
||||
}
|
||||
exports.endContext = endContext;
|
||||
/**
|
||||
* Records validation incidents back into an object that implements Validatable.
|
||||
*
|
||||
* Note: This method has a side-effect that the incident queue and name stack are cleared
|
||||
* to prepare for the next thread's invocation.
|
||||
*
|
||||
* @param possibleValidatable - An object that may conform to Validatable, onto which we
|
||||
* want to stash our validation incidents
|
||||
*/
|
||||
function recordValidationIncidents(possibleValidatable) {
|
||||
if (isValidatable(possibleValidatable)) {
|
||||
possibleValidatable.$incidents = contextState.incidents;
|
||||
}
|
||||
contextState.incidents = [];
|
||||
contextState.nameStack = [];
|
||||
contextState.suppressedIncidentPaths = [];
|
||||
}
|
||||
exports.recordValidationIncidents = recordValidationIncidents;
|
||||
/**
|
||||
* Create a transient validation context, and call a function that will return a value.
|
||||
*
|
||||
* Prefer this function over manually calling begin/endContext,
|
||||
* it is exception safe.
|
||||
*
|
||||
* @param name - The name of the context
|
||||
* @param producer - A function that produces a result
|
||||
* @returns <Result> The resulting type
|
||||
*/
|
||||
function context(name, producer, suppressingPath) {
|
||||
let suppressingName = null;
|
||||
if (optional_1.isSome(suppressingPath) && suppressingPath.length > 0) {
|
||||
suppressingName = name;
|
||||
contextState.suppressedIncidentPaths.push(suppressingPath);
|
||||
}
|
||||
let result = null;
|
||||
try {
|
||||
beginContext(name);
|
||||
result = producer();
|
||||
}
|
||||
catch (e) {
|
||||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
||||
if (!e.hasThrown) {
|
||||
unexpectedType("defaultValue", "no exception", e.message);
|
||||
e.hasThrown = true;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
if (name === suppressingName) {
|
||||
contextState.suppressedIncidentPaths.pop();
|
||||
}
|
||||
endContext();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.context = context;
|
||||
/**
|
||||
* Create a transient validation context, that catches errors and returns null
|
||||
*
|
||||
* @param name - The name of the context
|
||||
* @param producer - A function that produces a result
|
||||
* @param caught - An optional handler to provide a value when an error is caught
|
||||
* @returns <Result> The resulting type
|
||||
*/
|
||||
function catchingContext(name, producer, caught) {
|
||||
let result = null;
|
||||
try {
|
||||
result = context(name, producer);
|
||||
}
|
||||
catch (e) {
|
||||
result = null;
|
||||
if (optional_1.isSome(caught)) {
|
||||
result = caught(e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.catchingContext = catchingContext;
|
||||
/**
|
||||
* Track an incident within the current validation context.
|
||||
* @param incident - An incident object describing the problem.
|
||||
*/
|
||||
function trackIncident(incident) {
|
||||
if (contextState.suppressedIncidentPaths.includes(incident.objectPath)) {
|
||||
return;
|
||||
}
|
||||
contextState.incidents.push(incident);
|
||||
}
|
||||
// endregion
|
||||
// region Nullability
|
||||
/**
|
||||
* Reports a non-fatal error indicating a value was unexpectedly null.
|
||||
* @param recovery - The recovery action taken when the null value was found.
|
||||
* @param expected - The expected type of the value.
|
||||
* @param pathString - A string containing the path to the value on the object which was null.
|
||||
*/
|
||||
function unexpectedNull(recovery, expected, pathString) {
|
||||
const prettyPath = optional_1.isSome(pathString) && pathString.length > 0 ? pathString : "<this>";
|
||||
trackIncident({
|
||||
type: "nullValue",
|
||||
expected: expected,
|
||||
actual: "null",
|
||||
objectPath: prettyPath,
|
||||
contextNames: getContextNames(),
|
||||
recoveryAction: recovery,
|
||||
stack: new Error().stack,
|
||||
});
|
||||
}
|
||||
exports.unexpectedNull = unexpectedNull;
|
||||
// endregion
|
||||
//# sourceMappingURL=validation.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/alert-action.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/alert-action.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=alert-action.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/compound-action.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/compound-action.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=compound-action.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/empty-action.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/empty-action.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=empty-action.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/external-url-action.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/external-url-action.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=external-url-action.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/flow-action.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/flow-action.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=flow-action.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/flow-back-action.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/flow-back-action.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=flow-back-action.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/http-action.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/http-action.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=http-action.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/http-template-action.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/http-template-action.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=http-template-action.js.map
|
||||
22
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/index.js
generated
vendored
Normal file
22
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/index.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (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("./alert-action"), exports);
|
||||
__exportStar(require("./compound-action"), exports);
|
||||
__exportStar(require("./empty-action"), exports);
|
||||
__exportStar(require("./external-url-action"), exports);
|
||||
__exportStar(require("./flow-action"), exports);
|
||||
__exportStar(require("./flow-back-action"), exports);
|
||||
__exportStar(require("./http-action"), exports);
|
||||
__exportStar(require("./http-template-action"), exports);
|
||||
__exportStar(require("./toast-action"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/toast-action.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/actions/toast-action.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=toast-action.js.map
|
||||
39
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/artwork.js
generated
vendored
Normal file
39
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/artwork.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.makeArtworkURLTemplate = void 0;
|
||||
const validation = require("../json/validation");
|
||||
const optional_1 = require("../types/optional");
|
||||
const urls_1 = require("../util/urls");
|
||||
/**
|
||||
* Regex to parse artwork URL template string.
|
||||
*/
|
||||
const URL_TEMPLATE_PARSER = new RegExp("^({w}|[0-9]+(?:.[0-9]*)?)x({h}|[0-9]+(?:.[0-9]*)?)({c}|[a-z]{2}).({f}|[a-z]+)$");
|
||||
/**
|
||||
* Create an instance of artwork URL template from string.
|
||||
* @param fromString - String to create artwork URL template from.
|
||||
* @returns A new artwork URL template or `null` if string
|
||||
* does not represent a valid artwork URL template.
|
||||
*/
|
||||
function makeArtworkURLTemplate(fromString) {
|
||||
// A valid URL that ends with '{w}x{h}{c}.{f}'
|
||||
// with any of placeholders possibly resolved to an actual value.
|
||||
const url = new urls_1.URL(fromString);
|
||||
if (url.pathname === undefined) {
|
||||
validation.context("makeArtworkURLTemplate", () => {
|
||||
validation.unexpectedType("ignoredValue", "A valid URL string", fromString);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
// Expecting 5 matches: whole string + width, height, crop code and format.
|
||||
const lastPathComponent = fromString.substring(fromString.lastIndexOf("/") + 1);
|
||||
const matches = URL_TEMPLATE_PARSER.exec(lastPathComponent);
|
||||
if (optional_1.isNothing(matches) || matches.length !== 5) {
|
||||
validation.context("makeArtworkURLTemplate", () => {
|
||||
validation.unexpectedType("ignoredValue", "A valid artwork URL template ending with {w}x{h}{c}.{f} format", lastPathComponent);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
return fromString;
|
||||
}
|
||||
exports.makeArtworkURLTemplate = makeArtworkURLTemplate;
|
||||
//# sourceMappingURL=artwork.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/button.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/button.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=button.js.map
|
||||
131
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/color.js
generated
vendored
Normal file
131
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/color.js
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.areEqual = exports.luminanceFrom = exports.dynamicWith = exports.named = exports.rgbWith = exports.htmlWith = void 0;
|
||||
const optional_1 = require("../types/optional");
|
||||
// endregion
|
||||
// region Constructors
|
||||
/**
|
||||
* Create new `HTMLColor` from hexadecimal string representation.
|
||||
*
|
||||
* @param hexString - Hexadecimal string representation.
|
||||
*/
|
||||
function htmlWith(hexString) {
|
||||
if (optional_1.isNothing(hexString)) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
$kind: "html",
|
||||
value: hexString,
|
||||
};
|
||||
}
|
||||
exports.htmlWith = htmlWith;
|
||||
/**
|
||||
* Create new `RBGColor` with RGB components and opacity value.
|
||||
*
|
||||
* @param red - Red color value.
|
||||
* @param green - Green color value.
|
||||
* @param blue - Blue color value.
|
||||
* @param alpha - Opacity value.
|
||||
*/
|
||||
function rgbWith(red, green, blue, alpha = 1.0) {
|
||||
const newColor = {
|
||||
$kind: "rgb",
|
||||
red: red,
|
||||
green: green,
|
||||
blue: blue,
|
||||
alpha: alpha,
|
||||
};
|
||||
return newColor;
|
||||
}
|
||||
exports.rgbWith = rgbWith;
|
||||
/**
|
||||
* Create new named color using the color name.
|
||||
*
|
||||
* @param name - The name of the color.
|
||||
*/
|
||||
function named(name) {
|
||||
const newColor = {
|
||||
$kind: "named",
|
||||
name: name,
|
||||
};
|
||||
return newColor;
|
||||
}
|
||||
exports.named = named;
|
||||
/**
|
||||
* Create new dynamic color with light and dark color variants.
|
||||
*
|
||||
* @param lightColor - The light color variant.
|
||||
* @param lightHighContrastColor - The light hight-contrast color variant.
|
||||
* @param darkColor - The dark color variant.
|
||||
* @param darkHighContrastColor - The dark hight-contrast color variant.
|
||||
*/
|
||||
function dynamicWith(lightColor, lightHighContrastColor, darkColor, darkHighContrastColor) {
|
||||
const newColor = {
|
||||
$kind: "dynamic",
|
||||
lightColor: lightColor,
|
||||
lightHighContrastColor: lightHighContrastColor,
|
||||
darkColor: darkColor,
|
||||
darkHighContrastColor: darkHighContrastColor,
|
||||
};
|
||||
return newColor;
|
||||
}
|
||||
exports.dynamicWith = dynamicWith;
|
||||
// endregion
|
||||
// region Properties
|
||||
/**
|
||||
* Get the luminance of the color.
|
||||
*
|
||||
* @param rgbColor - The RGB color to get luminance for.
|
||||
*/
|
||||
function luminanceFrom(rgbColor) {
|
||||
// Note: This is lifted from UIColor_Private
|
||||
// Using RGB color components, calculates and returns (0.2126 * r) + (0.7152 * g) + (0.0722 * b).
|
||||
return rgbColor.red * 0.2126 + rgbColor.green * 0.7152 + rgbColor.blue * 0.0722;
|
||||
}
|
||||
exports.luminanceFrom = luminanceFrom;
|
||||
// endregion
|
||||
// region Identity
|
||||
/**
|
||||
* Compare two colors for equality.
|
||||
*
|
||||
* @param color1 - Left hand side color to compare.
|
||||
* @param color2 - Right hand side color to compare.
|
||||
* @returns A Boolean indicating whether the colors are equal.
|
||||
*/
|
||||
function areEqual(color1, color2) {
|
||||
if (optional_1.isNothing(color1)) {
|
||||
return optional_1.isNothing(color2);
|
||||
}
|
||||
else if (optional_1.isNothing(color2)) {
|
||||
return optional_1.isNothing(color1);
|
||||
}
|
||||
const kind1 = color1.$kind;
|
||||
const kind2 = color2.$kind;
|
||||
if (kind1 === "named" && kind2 === "named") {
|
||||
const namedColor1 = color1;
|
||||
const namedColor2 = color2;
|
||||
return namedColor1.name === namedColor2.name;
|
||||
}
|
||||
else if (kind1 === "rgb" && kind2 === "rgb") {
|
||||
const rgbColor1 = color1;
|
||||
const rgbColor2 = color2;
|
||||
return (rgbColor1.red === rgbColor2.red &&
|
||||
rgbColor1.green === rgbColor2.green &&
|
||||
rgbColor1.blue === rgbColor2.blue &&
|
||||
rgbColor1.alpha === rgbColor2.alpha);
|
||||
}
|
||||
else if (kind1 === "dynamic" && kind2 === "dynamic") {
|
||||
const dynamicColor1 = color1;
|
||||
const dynamicColor2 = color2;
|
||||
return (areEqual(dynamicColor1.lightColor, dynamicColor2.lightColor) &&
|
||||
areEqual(dynamicColor1.lightHighContrastColor, dynamicColor2.lightHighContrastColor) &&
|
||||
areEqual(dynamicColor1.darkColor, dynamicColor2.darkColor) &&
|
||||
areEqual(dynamicColor1.darkHighContrastColor, dynamicColor2.darkHighContrastColor));
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.areEqual = areEqual;
|
||||
// endregion
|
||||
//# sourceMappingURL=color.js.map
|
||||
21
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/index.js
generated
vendored
Normal file
21
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/index.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (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("./actions"), exports);
|
||||
__exportStar(require("./artwork"), exports);
|
||||
__exportStar(require("./button"), exports);
|
||||
__exportStar(require("./color"), exports);
|
||||
__exportStar(require("./menu"), exports);
|
||||
__exportStar(require("./paragraph"), exports);
|
||||
__exportStar(require("./programmed-text"), exports);
|
||||
__exportStar(require("./video"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
8
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/menu.js
generated
vendored
Normal file
8
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/menu.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.menuSeparatorID = void 0;
|
||||
/**
|
||||
* A standard identifier for including a separator in a menu.
|
||||
*/
|
||||
exports.menuSeparatorID = "com.apple.JetEngine.separator";
|
||||
//# sourceMappingURL=menu.js.map
|
||||
4
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/paragraph.js
generated
vendored
Normal file
4
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/paragraph.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// endregion
|
||||
//# sourceMappingURL=paragraph.js.map
|
||||
5
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/programmed-text.js
generated
vendored
Normal file
5
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/programmed-text.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
// region ProgrammedText
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// endregion
|
||||
//# sourceMappingURL=programmed-text.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/video.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/models/video.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=video.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/bag.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/bag.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=bag.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/bundle.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/bundle.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=bundle.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/cookie-provider.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/cookie-provider.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=cookie-provider.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/cryptography.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/cryptography.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=cryptography.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/host.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/host.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=host.js.map
|
||||
51
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/index.js
generated
vendored
Normal file
51
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/index.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (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 });
|
||||
/* `preprocessor` and `testContent` are normally replaced by inline literals while bundling an app's JS.
|
||||
*
|
||||
* If these values have not been set we want to provide defaults however
|
||||
* attempting to access them can trigger a ReferenceError as the
|
||||
* variables are undefined (distinct from a defined variable being set to
|
||||
* `undefined`).
|
||||
*
|
||||
* `typeof` checks can safely test undefined variables, note that these checks will become:
|
||||
* `typeof { DEBUG_BUILD: true, ... }` when webpack's DefinePlugin is used in @jet/build's webpack task.
|
||||
* When these variables have not been replaced we need to use `globalThis` to set them on the global scope
|
||||
* in order to avoid ReferenceErrors attempting to access them.
|
||||
*/
|
||||
if (typeof preprocessor === "undefined") {
|
||||
globalThis.preprocessor = {
|
||||
PRODUCTION_BUILD: false,
|
||||
CARRY_BUILD: false,
|
||||
DEBUG_BUILD: false,
|
||||
INTERNAL_BUILD: false,
|
||||
};
|
||||
}
|
||||
if (typeof testContent === "undefined") {
|
||||
globalThis.testContent = {
|
||||
INCLUDE_TEST_CONTENT: false,
|
||||
};
|
||||
}
|
||||
__exportStar(require("./bag"), exports);
|
||||
__exportStar(require("./bundle"), exports);
|
||||
__exportStar(require("./cookie-provider"), exports);
|
||||
__exportStar(require("./cryptography"), exports);
|
||||
__exportStar(require("./host"), exports);
|
||||
__exportStar(require("./jscookie"), exports);
|
||||
__exportStar(require("./net"), exports);
|
||||
__exportStar(require("./platform"), exports);
|
||||
__exportStar(require("./plist"), exports);
|
||||
__exportStar(require("./preprocessor"), exports);
|
||||
__exportStar(require("./random"), exports);
|
||||
__exportStar(require("./service"), exports);
|
||||
__exportStar(require("./types"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/jscookie.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/jscookie.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=jscookie.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/net.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/net.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=net.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/platform.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/platform.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=platform.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/plist.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/plist.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=plist.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/preprocessor.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/preprocessor.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=preprocessor.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/random.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/random.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=random.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/service.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/service.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=service.js.map
|
||||
16
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/types.js
generated
vendored
Normal file
16
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/globals/types.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.services = exports.random = exports.plist = exports.platform = exports.net = exports.localizer = exports.host = exports.cryptography = exports.cookieProvider = exports.bundle = exports.bag = void 0;
|
||||
const metatype_1 = require("../../util/metatype");
|
||||
exports.bag = metatype_1.makeMetatype("jet-engine:bag");
|
||||
exports.bundle = metatype_1.makeMetatype("jet-engine:bundle");
|
||||
exports.cookieProvider = metatype_1.makeMetatype("jet-engine:cookieProvider");
|
||||
exports.cryptography = metatype_1.makeMetatype("jet-engine:cryptography");
|
||||
exports.host = metatype_1.makeMetatype("jet-engine:host");
|
||||
exports.localizer = metatype_1.makeMetatype("jet-engine:localizer");
|
||||
exports.net = metatype_1.makeMetatype("jet-engine:net");
|
||||
exports.platform = metatype_1.makeMetatype("jet-engine:platform");
|
||||
exports.plist = metatype_1.makeMetatype("jet-engine:plist");
|
||||
exports.random = metatype_1.makeMetatype("jet-engine:random");
|
||||
exports.services = metatype_1.makeMetatype("jet-engine:services");
|
||||
//# sourceMappingURL=types.js.map
|
||||
14
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/javascriptcore/console.js
generated
vendored
Normal file
14
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/javascriptcore/console.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Describes standard functionality available in JSContexts
|
||||
*
|
||||
* Types are defined here to allow us to match the behavior available in JSContext in the target OS
|
||||
* which may not exactly match the definitions in standard TypeScript lib files, particularly on a
|
||||
* pre-release OS.
|
||||
*
|
||||
* The living standard for the Console API is available at https://console.spec.whatwg.org
|
||||
* The WebKit team has documented their interfaces at https://webkit.org/web-inspector/console-object-api/
|
||||
* The equivalent interface in Node is https://nodejs.org/api/console.html
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=console.js.map
|
||||
14
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/javascriptcore/index.js
generated
vendored
Normal file
14
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/javascriptcore/index.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (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("./console"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
57
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/metrics.js
generated
vendored
Normal file
57
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/metrics.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.notInstrumented = exports.PageInvocationPoint = exports.EMPTY_LINTED_METRICS_EVENT = void 0;
|
||||
/**
|
||||
* An empty linted metrics event.
|
||||
*
|
||||
* The empty events should be skipped from recording
|
||||
* by metrics event recorders.
|
||||
*/
|
||||
exports.EMPTY_LINTED_METRICS_EVENT = {
|
||||
fields: {},
|
||||
issues: [],
|
||||
};
|
||||
var PageInvocationPoint;
|
||||
(function (PageInvocationPoint) {
|
||||
PageInvocationPoint["pageEnter"] = "pageEnter";
|
||||
PageInvocationPoint["pageExit"] = "pageExit";
|
||||
PageInvocationPoint["appExit"] = "appExit";
|
||||
PageInvocationPoint["appEnter"] = "appEnter";
|
||||
PageInvocationPoint["backButton"] = "backButton";
|
||||
})(PageInvocationPoint = exports.PageInvocationPoint || (exports.PageInvocationPoint = {}));
|
||||
/**
|
||||
* Returns an empty metrics instance of the specified metrics type.
|
||||
* @param metricsType - Type of the metrics data to return.
|
||||
*
|
||||
* @deprecated Do not use, all metrics events should be instrumented.
|
||||
*/
|
||||
function notInstrumented(metricsType) {
|
||||
switch (metricsType) {
|
||||
case 0 /* ActionMetrics */:
|
||||
return {
|
||||
data: [],
|
||||
custom: {},
|
||||
};
|
||||
case 1 /* FetchTimingMetrics */:
|
||||
return {};
|
||||
case 2 /* PageMetrics */:
|
||||
return {
|
||||
instructions: [],
|
||||
custom: {},
|
||||
};
|
||||
case 3 /* ImpressionMetrics */:
|
||||
return {
|
||||
id: {
|
||||
id: "",
|
||||
impressionIndex: NaN,
|
||||
},
|
||||
fields: {},
|
||||
custom: {},
|
||||
};
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
exports.notInstrumented = notInstrumented;
|
||||
// endregion
|
||||
//# sourceMappingURL=metrics.js.map
|
||||
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/models.js
generated
vendored
Normal file
3
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/models.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=models.js.map
|
||||
71
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/optional.js
generated
vendored
Normal file
71
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/types/optional.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.flatMapOptional = exports.mapOptional = exports.unsafeUnwrapOptional = exports.unwrapOptional = exports.isSome = exports.isNothing = exports.unsafeUninitialized = void 0;
|
||||
/**
|
||||
* Bypass the protection provided by the `Optional` type
|
||||
* and pretend to produce a value of `Some<T>` while
|
||||
* actually returning `Nothing`.
|
||||
*/
|
||||
function unsafeUninitialized() {
|
||||
return undefined;
|
||||
}
|
||||
exports.unsafeUninitialized = unsafeUninitialized;
|
||||
/**
|
||||
* Test whether an optional does not contain a value.
|
||||
*
|
||||
* @param value - An optional value to test.
|
||||
*/
|
||||
function isNothing(value) {
|
||||
return value === undefined || value === null;
|
||||
}
|
||||
exports.isNothing = isNothing;
|
||||
/**
|
||||
* Test whether an optional contains a value.
|
||||
* @param value - An optional value to test.
|
||||
*/
|
||||
function isSome(value) {
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
exports.isSome = isSome;
|
||||
/**
|
||||
* Unwrap the value contained in a given optional,
|
||||
* throwing an error if there is no value.
|
||||
*
|
||||
* @param value - A value to unwrap.
|
||||
*/
|
||||
function unwrapOptional(value) {
|
||||
if (isNothing(value)) {
|
||||
throw new ReferenceError();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
exports.unwrapOptional = unwrapOptional;
|
||||
/**
|
||||
* Unwrap the value contained in a given optional
|
||||
* without checking if the value exists.
|
||||
*
|
||||
* @param value - A value to unwrap.
|
||||
*/
|
||||
function unsafeUnwrapOptional(value) {
|
||||
return value;
|
||||
}
|
||||
exports.unsafeUnwrapOptional = unsafeUnwrapOptional;
|
||||
function mapOptional(value, body) {
|
||||
if (isSome(value)) {
|
||||
return body(value);
|
||||
}
|
||||
else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
exports.mapOptional = mapOptional;
|
||||
function flatMapOptional(value, body) {
|
||||
if (isSome(value)) {
|
||||
return body(value);
|
||||
}
|
||||
else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
exports.flatMapOptional = flatMapOptional;
|
||||
//# sourceMappingURL=optional.js.map
|
||||
10
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/util/metatype.js
generated
vendored
Normal file
10
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/util/metatype.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.makeMetatype = void 0;
|
||||
function makeMetatype(name) {
|
||||
return {
|
||||
name: name,
|
||||
};
|
||||
}
|
||||
exports.makeMetatype = makeMetatype;
|
||||
//# sourceMappingURL=metatype.js.map
|
||||
370
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/util/urls.js
generated
vendored
Normal file
370
shared/metrics-8/node_modules/@jet/engine/node_modules/@jet/environment/util/urls.js
generated
vendored
Normal file
@@ -0,0 +1,370 @@
|
||||
"use strict";
|
||||
// MARK: - Parsing Regular Expressions
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.URL = void 0;
|
||||
const optional_1 = require("../types/optional");
|
||||
const protocolRegex = /^([a-z][a-z0-9.+-]*:)(\/\/)?([\S\s]*)/i;
|
||||
const queryParamRegex = /([^=?&]+)=?([^&]*)/g;
|
||||
const componentOrder = ["hash", "query", "pathname", "host"];
|
||||
class URL {
|
||||
constructor(url) {
|
||||
var _a;
|
||||
this.query = {};
|
||||
if (optional_1.isNothing(url)) {
|
||||
return;
|
||||
}
|
||||
// Split the protocol from the rest of the urls
|
||||
let remainder = url;
|
||||
const match = protocolRegex.exec(url);
|
||||
if (optional_1.isSome(match)) {
|
||||
// Pull out the protocol
|
||||
let protocol = match[1];
|
||||
if (protocol !== null && protocol !== undefined) {
|
||||
protocol = protocol.split(":")[0];
|
||||
}
|
||||
this.protocol = protocol !== null && protocol !== void 0 ? protocol : undefined;
|
||||
// Save the remainder
|
||||
remainder = (_a = match[3]) !== null && _a !== void 0 ? _a : undefined;
|
||||
}
|
||||
// Then match each component in a specific order
|
||||
let parse = { remainder: remainder, result: undefined };
|
||||
for (const component of componentOrder) {
|
||||
if (parse === undefined || parse.remainder === undefined) {
|
||||
break;
|
||||
}
|
||||
switch (component) {
|
||||
case "hash": {
|
||||
parse = splitUrlComponent(parse.remainder, "#", "suffix");
|
||||
this.hash = parse === null || parse === void 0 ? void 0 : parse.result;
|
||||
break;
|
||||
}
|
||||
case "query": {
|
||||
parse = splitUrlComponent(parse.remainder, "?", "suffix");
|
||||
if ((parse === null || parse === void 0 ? void 0 : parse.result) !== undefined) {
|
||||
this.query = URL.queryFromString(parse.result);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "pathname": {
|
||||
parse = splitUrlComponent(parse.remainder, "/", "suffix");
|
||||
if ((parse === null || parse === void 0 ? void 0 : parse.result) !== undefined) {
|
||||
// Replace the initial /, since paths require it
|
||||
this.pathname = "/" + parse.result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "host": {
|
||||
const authorityParse = splitUrlComponent(parse.remainder, "@", "prefix");
|
||||
const userInfo = authorityParse === null || authorityParse === void 0 ? void 0 : authorityParse.result;
|
||||
const hostPort = authorityParse === null || authorityParse === void 0 ? void 0 : authorityParse.remainder;
|
||||
if (userInfo !== undefined) {
|
||||
const userInfoSplit = userInfo.split(":");
|
||||
this.username = decodeURIComponent(userInfoSplit[0]);
|
||||
this.password = decodeURIComponent(userInfoSplit[1]);
|
||||
}
|
||||
if (hostPort !== undefined) {
|
||||
const hostPortSplit = hostPort.split(":");
|
||||
this.host = hostPortSplit[0];
|
||||
this.port = hostPortSplit[1];
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error("Unhandled case!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
get(component) {
|
||||
switch (component) {
|
||||
// Exhaustive match to make sure TS property minifiers and other
|
||||
// transformer plugins do not break this code.
|
||||
case "protocol":
|
||||
return this.protocol;
|
||||
case "username":
|
||||
return this.username;
|
||||
case "password":
|
||||
return this.password;
|
||||
case "port":
|
||||
return this.port;
|
||||
case "pathname":
|
||||
return this.pathname;
|
||||
case "query":
|
||||
return this.query;
|
||||
case "hash":
|
||||
return this.hash;
|
||||
default:
|
||||
// The fallback for component which is not a property of URL object.
|
||||
return this[component];
|
||||
}
|
||||
}
|
||||
set(component, value) {
|
||||
if (value === undefined) {
|
||||
return this;
|
||||
}
|
||||
if (component === "query") {
|
||||
if (typeof value === "string") {
|
||||
value = URL.queryFromString(value);
|
||||
}
|
||||
}
|
||||
switch (component) {
|
||||
// Exhaustive match to make sure TS property minifiers and other
|
||||
// transformer plugins do not break this code.
|
||||
case "protocol":
|
||||
this.protocol = value;
|
||||
break;
|
||||
case "username":
|
||||
this.username = value;
|
||||
break;
|
||||
case "password":
|
||||
this.password = value;
|
||||
break;
|
||||
case "port":
|
||||
this.port = value;
|
||||
break;
|
||||
case "pathname":
|
||||
this.pathname = value;
|
||||
break;
|
||||
case "query":
|
||||
this.query = value;
|
||||
break;
|
||||
case "hash":
|
||||
this.hash = value;
|
||||
break;
|
||||
default:
|
||||
// The fallback for component which is not a property of URL object.
|
||||
this[component] = value;
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
append(component, value) {
|
||||
let existingValue = this.get(component);
|
||||
let newValue;
|
||||
if (component === "query") {
|
||||
if (existingValue === undefined) {
|
||||
existingValue = {};
|
||||
}
|
||||
if (typeof value === "string") {
|
||||
value = URL.queryFromString(value);
|
||||
}
|
||||
if (typeof existingValue === "string") {
|
||||
newValue = { existingValue, ...value };
|
||||
}
|
||||
else {
|
||||
newValue = { ...existingValue, ...value };
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (existingValue === undefined) {
|
||||
existingValue = "";
|
||||
}
|
||||
let existingValueString = existingValue;
|
||||
if (existingValueString === undefined) {
|
||||
existingValueString = "";
|
||||
}
|
||||
let newValueString = existingValueString;
|
||||
if (component === "pathname") {
|
||||
const pathLength = existingValueString.length;
|
||||
if (pathLength === 0 || existingValue[pathLength - 1] !== "/") {
|
||||
newValueString += "/";
|
||||
}
|
||||
}
|
||||
// The component is not "query" so we treat value as string.
|
||||
// eslint-disable-next-line @typescript-eslint/no-base-to-string, @typescript-eslint/restrict-plus-operands
|
||||
newValueString += value;
|
||||
newValue = newValueString;
|
||||
}
|
||||
return this.set(component, newValue);
|
||||
}
|
||||
param(key, value) {
|
||||
if (key === null) {
|
||||
return this;
|
||||
}
|
||||
if (this.query === undefined) {
|
||||
this.query = {};
|
||||
}
|
||||
if (value === undefined) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||
delete this.query[key];
|
||||
}
|
||||
else {
|
||||
this.query[key] = value;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
removeParam(key) {
|
||||
if (key === undefined || this.query === undefined) {
|
||||
return this;
|
||||
}
|
||||
if (key in this.query) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||
delete this.query[key];
|
||||
}
|
||||
return this;
|
||||
}
|
||||
path(value) {
|
||||
return this.append("pathname", value);
|
||||
}
|
||||
pathExtension() {
|
||||
var _a, _b;
|
||||
// Extract path extension if one exists
|
||||
if (this.pathname === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
const lastFilenameComponents = (_b = (_a = this.pathname
|
||||
.split("/")
|
||||
.filter((item) => item.length > 0) // Remove any double or trailing slashes
|
||||
.pop()) === null || _a === void 0 ? void 0 : _a.split(".")) !== null && _b !== void 0 ? _b : [];
|
||||
if (lastFilenameComponents.filter(function (part) {
|
||||
return part !== "";
|
||||
}).length < 2 // Remove any empty parts (e.g. .ssh_config -> ["ssh_config"])
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
return lastFilenameComponents.pop();
|
||||
}
|
||||
/**
|
||||
* Returns the path components of the URL
|
||||
* @returns An array of non-empty path components from `urls`.
|
||||
*/
|
||||
pathComponents() {
|
||||
if (this.pathname === undefined) {
|
||||
return [];
|
||||
}
|
||||
return this.pathname.split("/").filter((component) => component.length > 0);
|
||||
}
|
||||
/**
|
||||
* Same as toString
|
||||
*
|
||||
* @returns A string representation of the URL
|
||||
*/
|
||||
build() {
|
||||
return this.toString();
|
||||
}
|
||||
/**
|
||||
* Converts the URL to a string
|
||||
*
|
||||
* @returns A string representation of the URL
|
||||
*/
|
||||
toString() {
|
||||
let url = "";
|
||||
if (this.protocol !== undefined) {
|
||||
url += this.protocol + "://";
|
||||
}
|
||||
if (this.username !== undefined) {
|
||||
url += encodeURIComponent(this.username);
|
||||
if (this.password !== undefined) {
|
||||
url += ":" + encodeURIComponent(this.password);
|
||||
}
|
||||
url += "@";
|
||||
}
|
||||
if (this.host !== undefined) {
|
||||
url += this.host;
|
||||
if (this.port !== undefined) {
|
||||
url += ":" + this.port;
|
||||
}
|
||||
}
|
||||
if (this.pathname !== undefined) {
|
||||
url += this.pathname;
|
||||
}
|
||||
if (this.query !== undefined && Object.keys(this.query).length !== 0) {
|
||||
url += "?" + URL.toQueryString(this.query);
|
||||
}
|
||||
if (this.hash !== undefined) {
|
||||
url += "#" + this.hash;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
// ----------------
|
||||
// Static API
|
||||
// ----------------
|
||||
/**
|
||||
* Converts a string into a query dictionary
|
||||
* @param query - The string to parse
|
||||
* @returns The query dictionary containing the key-value pairs in the query string
|
||||
*/
|
||||
static queryFromString(query) {
|
||||
const result = {};
|
||||
let parseResult = queryParamRegex.exec(query);
|
||||
while (parseResult !== null) {
|
||||
const key = decodeURIComponent(parseResult[1]);
|
||||
const value = decodeURIComponent(parseResult[2]);
|
||||
result[key] = value;
|
||||
parseResult = queryParamRegex.exec(query);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Converts a query dictionary into a query string
|
||||
*
|
||||
* @param query - The query dictionary
|
||||
* @returns The string representation of the query dictionary
|
||||
*/
|
||||
static toQueryString(query) {
|
||||
let queryString = "";
|
||||
let first = true;
|
||||
for (const key of Object.keys(query)) {
|
||||
if (!first) {
|
||||
queryString += "&";
|
||||
}
|
||||
first = false;
|
||||
queryString += encodeURIComponent(key);
|
||||
const value = query[key];
|
||||
if (value !== null && value.length > 0) {
|
||||
queryString += "=" + encodeURIComponent(value);
|
||||
}
|
||||
}
|
||||
return queryString;
|
||||
}
|
||||
/**
|
||||
* Convenience method to instantiate a URL from a string
|
||||
* @param url - The URL string to parse
|
||||
* @returns The new URL object representing the URL
|
||||
*/
|
||||
static from(url) {
|
||||
return new URL(url);
|
||||
}
|
||||
/**
|
||||
* Convenience method to instantiate a URL from numerous (optional) components
|
||||
* @param protocol - The protocol type
|
||||
* @param host - The host name
|
||||
* @param path - The path
|
||||
* @param query - The query
|
||||
* @param hash - The hash
|
||||
* @returns The new URL object representing the URL
|
||||
*/
|
||||
static fromComponents(protocol, host, path, query, hash) {
|
||||
const url = new URL();
|
||||
url.protocol = protocol;
|
||||
url.host = host;
|
||||
url.pathname = path;
|
||||
url.query = query !== null && query !== void 0 ? query : {};
|
||||
url.hash = hash;
|
||||
return url;
|
||||
}
|
||||
}
|
||||
exports.URL = URL;
|
||||
// MARK: - Helpers
|
||||
function splitUrlComponent(input, marker, style) {
|
||||
const index = input.indexOf(marker);
|
||||
let result;
|
||||
let remainder = input;
|
||||
if (index !== -1) {
|
||||
const prefix = input.slice(0, index);
|
||||
const suffix = input.slice(index + marker.length, input.length);
|
||||
if (style === "prefix") {
|
||||
result = prefix;
|
||||
remainder = suffix;
|
||||
}
|
||||
else {
|
||||
result = suffix;
|
||||
remainder = prefix;
|
||||
}
|
||||
}
|
||||
return {
|
||||
result: result,
|
||||
remainder: remainder,
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=urls.js.map
|
||||
Reference in New Issue
Block a user