@amplitude/analytics-core 2.6.1 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/lib/cjs/index.d.ts +1 -1
  2. package/lib/cjs/index.d.ts.map +1 -1
  3. package/lib/cjs/index.js.map +1 -1
  4. package/lib/cjs/remote-config/remote-config-localstorage.d.ts +10 -0
  5. package/lib/cjs/remote-config/remote-config-localstorage.d.ts.map +1 -0
  6. package/lib/cjs/remote-config/remote-config-localstorage.js +54 -0
  7. package/lib/cjs/remote-config/remote-config-localstorage.js.map +1 -0
  8. package/lib/cjs/remote-config/remote-config.d.ts +115 -0
  9. package/lib/cjs/remote-config/remote-config.d.ts.map +1 -0
  10. package/lib/cjs/remote-config/remote-config.js +264 -0
  11. package/lib/cjs/remote-config/remote-config.js.map +1 -0
  12. package/lib/cjs/types/browser-config.d.ts +3 -2
  13. package/lib/cjs/types/browser-config.d.ts.map +1 -1
  14. package/lib/cjs/types/browser-config.js.map +1 -1
  15. package/lib/esm/index.d.ts +1 -1
  16. package/lib/esm/index.d.ts.map +1 -1
  17. package/lib/esm/index.js.map +1 -1
  18. package/lib/esm/remote-config/remote-config-localstorage.d.ts +10 -0
  19. package/lib/esm/remote-config/remote-config-localstorage.d.ts.map +1 -0
  20. package/lib/esm/remote-config/remote-config-localstorage.js +51 -0
  21. package/lib/esm/remote-config/remote-config-localstorage.js.map +1 -0
  22. package/lib/esm/remote-config/remote-config.d.ts +115 -0
  23. package/lib/esm/remote-config/remote-config.d.ts.map +1 -0
  24. package/lib/esm/remote-config/remote-config.js +261 -0
  25. package/lib/esm/remote-config/remote-config.js.map +1 -0
  26. package/lib/esm/types/browser-config.d.ts +3 -2
  27. package/lib/esm/types/browser-config.d.ts.map +1 -1
  28. package/lib/esm/types/browser-config.js.map +1 -1
  29. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.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AAa,EAAmB,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAS,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGjF,OAAO,EAAkB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAQlD,OAAO,EAIL,8BAA8B,EAC9B,6BAA6B,EAC7B,8BAA8B,GAC/B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export { AmplitudeCore, CoreClient } from './core-client';\nexport { Identify, IIdentify } from './identify';\nexport { Revenue, IRevenue, RevenueProperty } from './revenue';\nexport { Destination } from './plugins/destination';\nexport { IdentityEventSender } from './plugins/identity';\nexport { IConfig, Config, RequestMetadata } from './config';\nexport { Logger, ILogger } from './logger';\nexport { getGlobalScope } from './global-scope';\nexport { getAnalyticsConnector, setConnectorDeviceId, setConnectorUserId } from './analytics-connector';\nexport { isNewSession } from './session';\nexport { getCookieName, getOldCookieName } from './cookie-name';\nexport { getLanguage } from './language';\nexport { getQueryParams } from './query-params';\n\nexport { returnWrapper, AmplitudeReturn } from './utils/return-wrapper';\nexport { debugWrapper, getClientLogConfig, getClientStates } from './utils/debug';\nexport { UUID } from './utils/uuid';\nexport { createIdentifyEvent } from './utils/event-builder';\n\nexport { MemoryStorage } from './storage/memory';\nexport { CookieStorage } from './storage/cookie';\nexport { getStorageKey } from './storage/helpers';\n\nexport { BaseTransport } from './transports/base';\nexport { FetchTransport } from './transports/fetch';\n\nexport { LogLevel } from './types/loglevel';\nexport { AMPLITUDE_PREFIX, STORAGE_PREFIX } from './types/constants';\nexport { Storage, IdentityStorageType } from './types/storage';\nexport { Event, IdentifyOperation, SpecialEventType } from './types/event/event';\nexport { EventOptions, BaseEvent } from './types/event/base-event';\nexport { IngestionMetadata } from './types/event/ingestion-metadata';\nexport { ServerZoneType, ServerZone } from './types/server-zone';\nexport { OfflineDisabled } from './types/offline';\nexport { Plan } from './types/event/plan';\nexport { TransportType, Transport } from './types/transport';\nexport { Payload } from './types/payload';\nexport { Response } from './types/response';\nexport { UserSession } from './types/user-session';\nexport { Plugin, BeforePlugin, DestinationPlugin, EnrichmentPlugin, PluginType } from './types/plugin';\nexport { Result } from './types/result';\nexport {\n ElementInteractionsOptions,\n Messenger,\n ActionType,\n DEFAULT_CSS_SELECTOR_ALLOWLIST,\n DEFAULT_DATA_ATTRIBUTE_PREFIX,\n DEFAULT_ACTION_CLICK_ALLOWLIST,\n} from './types/element-interactions';\nexport { PageTrackingOptions, PageTrackingTrackOn, PageTrackingHistoryChanges } from './types/page-view-tracking';\nexport { Status } from './types/status';\nexport {\n BrowserConfig,\n BrowserOptions,\n DefaultTrackingOptions,\n TrackingOptions,\n AutocaptureOptions,\n CookieOptions,\n AttributionOptions,\n} from './types/browser-config';\nexport { BrowserClient } from './types/browser-client';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAc,MAAM,eAAe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AAgB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAS,iBAAiB,EAAE,gBAAgB,EAAqC,MAAM,qBAAqB,CAAC;AAGpH,OAAO,EAAkB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAQlD,OAAO,EAIL,8BAA8B,EAC9B,6BAA6B,EAC7B,8BAA8B,GAC/B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export { AmplitudeCore, CoreClient } from './core-client';\nexport { Identify, IIdentify } from './identify';\nexport { Revenue, IRevenue, RevenueProperty } from './revenue';\nexport { Destination } from './plugins/destination';\nexport { IdentityEventSender } from './plugins/identity';\nexport { IConfig, Config, RequestMetadata } from './config';\nexport { Logger, ILogger } from './logger';\nexport { getGlobalScope } from './global-scope';\nexport { getAnalyticsConnector, setConnectorDeviceId, setConnectorUserId } from './analytics-connector';\nexport { isNewSession } from './session';\nexport { getCookieName, getOldCookieName } from './cookie-name';\nexport { getLanguage } from './language';\nexport { getQueryParams } from './query-params';\n\nexport { returnWrapper, AmplitudeReturn } from './utils/return-wrapper';\nexport { debugWrapper, getClientLogConfig, getClientStates } from './utils/debug';\nexport { UUID } from './utils/uuid';\nexport { createIdentifyEvent } from './utils/event-builder';\n\nexport { MemoryStorage } from './storage/memory';\nexport { CookieStorage } from './storage/cookie';\nexport { getStorageKey } from './storage/helpers';\n\nexport { BaseTransport } from './transports/base';\nexport { FetchTransport } from './transports/fetch';\n\nexport { LogLevel } from './types/loglevel';\nexport { AMPLITUDE_PREFIX, STORAGE_PREFIX } from './types/constants';\nexport { Storage, IdentityStorageType } from './types/storage';\nexport { Event, IdentifyOperation, SpecialEventType, IdentifyEvent, GroupIdentifyEvent } from './types/event/event';\nexport { EventOptions, BaseEvent } from './types/event/base-event';\nexport { IngestionMetadata } from './types/event/ingestion-metadata';\nexport { ServerZoneType, ServerZone } from './types/server-zone';\nexport { OfflineDisabled } from './types/offline';\nexport { Plan } from './types/event/plan';\nexport { TransportType, Transport } from './types/transport';\nexport { Payload } from './types/payload';\nexport { Response } from './types/response';\nexport { UserSession } from './types/user-session';\nexport { Plugin, BeforePlugin, DestinationPlugin, EnrichmentPlugin, PluginType } from './types/plugin';\nexport { Result } from './types/result';\nexport {\n ElementInteractionsOptions,\n Messenger,\n ActionType,\n DEFAULT_CSS_SELECTOR_ALLOWLIST,\n DEFAULT_DATA_ATTRIBUTE_PREFIX,\n DEFAULT_ACTION_CLICK_ALLOWLIST,\n} from './types/element-interactions';\nexport { PageTrackingOptions, PageTrackingTrackOn, PageTrackingHistoryChanges } from './types/page-view-tracking';\nexport { Status } from './types/status';\nexport {\n BrowserConfig,\n BrowserOptions,\n DefaultTrackingOptions,\n TrackingOptions,\n AutocaptureOptions,\n CookieOptions,\n AttributionOptions,\n} from './types/browser-config';\nexport { BrowserClient } from './types/browser-client';\n"]}
@@ -0,0 +1,10 @@
1
+ import { RemoteConfigStorage, RemoteConfigInfo } from './remote-config';
2
+ import { ILogger } from '../logger';
3
+ export declare class RemoteConfigLocalStorage implements RemoteConfigStorage {
4
+ private readonly key;
5
+ private readonly logger;
6
+ constructor(apiKey: string, logger: ILogger);
7
+ fetchConfig(): Promise<RemoteConfigInfo>;
8
+ setConfig(config: RemoteConfigInfo): Promise<boolean>;
9
+ }
10
+ //# sourceMappingURL=remote-config-localstorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-config-localstorage.d.ts","sourceRoot":"","sources":["../../../src/remote-config/remote-config-localstorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,qBAAa,wBAAyB,YAAW,mBAAmB;IAClE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;gBAErB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;IAK3C,WAAW,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAiCxC,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAUtD"}
@@ -0,0 +1,51 @@
1
+ var RemoteConfigLocalStorage = /** @class */ (function () {
2
+ function RemoteConfigLocalStorage(apiKey, logger) {
3
+ this.key = "AMP_remote_config_".concat(apiKey.substring(0, 10));
4
+ this.logger = logger;
5
+ }
6
+ RemoteConfigLocalStorage.prototype.fetchConfig = function () {
7
+ var result = null;
8
+ var failedRemoteConfigInfo = {
9
+ remoteConfig: null,
10
+ lastFetch: new Date(),
11
+ };
12
+ try {
13
+ result = localStorage.getItem(this.key);
14
+ }
15
+ catch (error) {
16
+ this.logger.debug('Remote config localstorage failed to access: ', error);
17
+ return Promise.resolve(failedRemoteConfigInfo);
18
+ }
19
+ if (result === null) {
20
+ this.logger.debug('Remote config localstorage gets null because the key does not exist');
21
+ return Promise.resolve(failedRemoteConfigInfo);
22
+ }
23
+ try {
24
+ var remoteConfigInfo = JSON.parse(result);
25
+ this.logger.debug('Remote config localstorage parsed successfully.');
26
+ return Promise.resolve({
27
+ remoteConfig: remoteConfigInfo.remoteConfig,
28
+ lastFetch: new Date(remoteConfigInfo.lastFetch),
29
+ });
30
+ }
31
+ catch (error) {
32
+ this.logger.debug('Remote config localstorage failed to parse: ', error);
33
+ localStorage.removeItem(this.key);
34
+ return Promise.resolve(failedRemoteConfigInfo);
35
+ }
36
+ };
37
+ RemoteConfigLocalStorage.prototype.setConfig = function (config) {
38
+ try {
39
+ localStorage.setItem(this.key, JSON.stringify(config));
40
+ this.logger.debug('Remote config localstorage set successfully.');
41
+ return Promise.resolve(true);
42
+ }
43
+ catch (error) {
44
+ this.logger.debug('Remote config localstorage failed to set: ', error);
45
+ }
46
+ return Promise.resolve(false);
47
+ };
48
+ return RemoteConfigLocalStorage;
49
+ }());
50
+ export { RemoteConfigLocalStorage };
51
+ //# sourceMappingURL=remote-config-localstorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-config-localstorage.js","sourceRoot":"","sources":["../../../src/remote-config/remote-config-localstorage.ts"],"names":[],"mappings":"AAGA;IAIE,kCAAY,MAAc,EAAE,MAAe;QACzC,IAAI,CAAC,GAAG,GAAG,4BAAqB,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC;QAC1D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,8CAAW,GAAX;QACE,IAAI,MAAM,GAAkB,IAAI,CAAC;QACjC,IAAM,sBAAsB,GAAG;YAC7B,YAAY,EAAE,IAAI;YAClB,SAAS,EAAE,IAAI,IAAI,EAAE;SACtB,CAAC;QAEF,IAAI;YACF,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACzC;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+CAA+C,EAAE,KAAK,CAAC,CAAC;YAC1E,OAAO,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;SAChD;QAED,IAAI,MAAM,KAAK,IAAI,EAAE;YACnB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qEAAqE,CAAC,CAAC;YACzF,OAAO,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;SAChD;QAED,IAAI;YACF,IAAM,gBAAgB,GAAqB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAqB,CAAC;YAClF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAC;YACrE,OAAO,OAAO,CAAC,OAAO,CAAC;gBACrB,YAAY,EAAE,gBAAgB,CAAC,YAAY;gBAC3C,SAAS,EAAE,IAAI,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC;aAChD,CAAC,CAAC;SACJ;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8CAA8C,EAAE,KAAK,CAAC,CAAC;YACzE,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClC,OAAO,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;SAChD;IACH,CAAC;IAED,4CAAS,GAAT,UAAU,MAAwB;QAChC,IAAI;YACF,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;YACvD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;YAClE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SAC9B;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4CAA4C,EAAE,KAAK,CAAC,CAAC;SACxE;QACD,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IACH,+BAAC;AAAD,CAAC,AApDD,IAoDC","sourcesContent":["import { RemoteConfigStorage, RemoteConfigInfo } from './remote-config';\nimport { ILogger } from '../logger';\n\nexport class RemoteConfigLocalStorage implements RemoteConfigStorage {\n private readonly key: string;\n private readonly logger: ILogger;\n\n constructor(apiKey: string, logger: ILogger) {\n this.key = `AMP_remote_config_${apiKey.substring(0, 10)}`;\n this.logger = logger;\n }\n\n fetchConfig(): Promise<RemoteConfigInfo> {\n let result: string | null = null;\n const failedRemoteConfigInfo = {\n remoteConfig: null,\n lastFetch: new Date(),\n };\n\n try {\n result = localStorage.getItem(this.key);\n } catch (error) {\n this.logger.debug('Remote config localstorage failed to access: ', error);\n return Promise.resolve(failedRemoteConfigInfo);\n }\n\n if (result === null) {\n this.logger.debug('Remote config localstorage gets null because the key does not exist');\n return Promise.resolve(failedRemoteConfigInfo);\n }\n\n try {\n const remoteConfigInfo: RemoteConfigInfo = JSON.parse(result) as RemoteConfigInfo;\n this.logger.debug('Remote config localstorage parsed successfully.');\n return Promise.resolve({\n remoteConfig: remoteConfigInfo.remoteConfig,\n lastFetch: new Date(remoteConfigInfo.lastFetch),\n });\n } catch (error) {\n this.logger.debug('Remote config localstorage failed to parse: ', error);\n localStorage.removeItem(this.key);\n return Promise.resolve(failedRemoteConfigInfo);\n }\n }\n\n setConfig(config: RemoteConfigInfo): Promise<boolean> {\n try {\n localStorage.setItem(this.key, JSON.stringify(config));\n this.logger.debug('Remote config localstorage set successfully.');\n return Promise.resolve(true);\n } catch (error) {\n this.logger.debug('Remote config localstorage failed to set: ', error);\n }\n return Promise.resolve(false);\n }\n}\n"]}
@@ -0,0 +1,115 @@
1
+ import { ServerZoneType } from '../types/server-zone';
2
+ import { ILogger } from '../logger';
3
+ /**
4
+ * Modes for receiving remote config updates:
5
+ * - `'all'` – Receive all config updates as they occur.
6
+ * - `{ timeout: number }` – Wait for a remote response until the specified timeout (in milliseconds),
7
+ * then return a cached copy if available.
8
+ */
9
+ export type DeliveryMode = 'all' | {
10
+ timeout: number;
11
+ };
12
+ /**
13
+ * Sources of returned remote config:
14
+ * - `cache` - Fetched from local storage.
15
+ * - `remote` - Fetched from remote.
16
+ */
17
+ export type Source = 'cache' | 'remote';
18
+ export declare const US_SERVER_URL = "https://sr-client-cfg.amplitude.com/config";
19
+ export declare const EU_SERVER_URL = "https://sr-client-cfg.eu.amplitude.com/config";
20
+ export declare const DEFAULT_MAX_RETRIES = 3;
21
+ export declare const FETCHED_KEYS: string[];
22
+ export interface RemoteConfig {
23
+ [key: string]: any;
24
+ }
25
+ export interface RemoteConfigInfo {
26
+ remoteConfig: RemoteConfig | null;
27
+ lastFetch: Date;
28
+ }
29
+ export interface RemoteConfigStorage {
30
+ /**
31
+ * Fetch remote config from storage asynchronously.
32
+ */
33
+ fetchConfig(): Promise<RemoteConfigInfo>;
34
+ /**
35
+ * Set remote config to storage asynchronously.
36
+ */
37
+ setConfig(config: RemoteConfigInfo): Promise<boolean>;
38
+ }
39
+ /**
40
+ * Information about each callback registered by `RemoteConfigClient.subscribe()`,
41
+ * managed internally by `RemoteConfigClient`.
42
+ */
43
+ export interface CallbackInfo {
44
+ id: string;
45
+ key?: string;
46
+ deliveryMode: DeliveryMode;
47
+ callback: RemoteConfigCallback;
48
+ lastCallback?: Date;
49
+ }
50
+ /**
51
+ * Callback used in `RemoteConfigClient.subscribe()`.
52
+ * This function is called when the remote config is fetched.
53
+ */
54
+ type RemoteConfigCallback = (remoteConfig: RemoteConfig | null, source: Source, lastFetch: Date) => void;
55
+ export interface IRemoteConfigClient {
56
+ /**
57
+ * Subscribe for updates to remote config.
58
+ * Callback is guaranteed to be called at least once,
59
+ * Whether we are able to fetch a config or not.
60
+ *
61
+ * @param key - a string containing a series of period delimited keys to filter the returned config.
62
+ * Ie, {a: {b: {c: ...}}} would return {b: {c: ...}} for "a" or {c: ...} for "a.b".
63
+ * Set to `undefined` to subscribe all keys.
64
+ * @param deliveryMode - how the initial callback is sent.
65
+ * @param callback - a block that will be called when remote config is fetched.
66
+ * @return id - identification of the subscribe and can be used to unsubscribe from updates.
67
+ */
68
+ subscribe(key: string | undefined, deliveryMode: DeliveryMode, callback: RemoteConfigCallback): string;
69
+ /**
70
+ * Unsubscribe a callback from receiving future updates.
71
+ *
72
+ * @param id - identification of the callback that you want to unsubscribe.
73
+ * It's the return value of subscribe().
74
+ * @return boolean - whether the callback is removed.
75
+ */
76
+ unsubscribe(id: string): boolean;
77
+ /**
78
+ * Request the remote config client to fetch from remote, update cache, and callback.
79
+ */
80
+ updateConfigs(): void;
81
+ }
82
+ export declare class RemoteConfigClient implements IRemoteConfigClient {
83
+ readonly apiKey: string;
84
+ readonly serverUrl: string;
85
+ readonly logger: ILogger;
86
+ readonly storage: RemoteConfigStorage;
87
+ callbackInfos: CallbackInfo[];
88
+ constructor(apiKey: string, logger: ILogger, serverZone?: ServerZoneType);
89
+ subscribe(key: string | undefined, deliveryMode: DeliveryMode, callback: RemoteConfigCallback): string;
90
+ unsubscribe(id: string): boolean;
91
+ updateConfigs(): Promise<void>;
92
+ /**
93
+ * Send remote first. If it's already complete, we can skip the cached response.
94
+ * - if remote is fetched first, no cache fetch.
95
+ * - if cache is fetched first, still fetching remote.
96
+ */
97
+ subscribeAll(callbackInfo: CallbackInfo): Promise<void>;
98
+ /**
99
+ * Waits for a remote response until the given timeout, then return a cached copy, if available.
100
+ */
101
+ subscribeWaitForRemote(callbackInfo: CallbackInfo, timeout: number): Promise<void>;
102
+ /**
103
+ * Call the callback with filtered remote config based on key.
104
+ * @param remoteConfigInfo - the whole remote config object without filtering by key.
105
+ */
106
+ sendCallback(callbackInfo: CallbackInfo, remoteConfigInfo: RemoteConfigInfo, source: Source): void;
107
+ fetch(retries?: number, timeout?: number): Promise<RemoteConfigInfo>;
108
+ /**
109
+ * Return jitter in the bound of [0,baseDelay) and then floor round.
110
+ */
111
+ getJitterDelay(baseDelay: number): number;
112
+ getUrlParams(): string;
113
+ }
114
+ export {};
115
+ //# sourceMappingURL=remote-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-config.d.ts","sourceRoot":"","sources":["../../../src/remote-config/remote-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD;;;;GAIG;AACH,MAAM,MAAM,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAExC,eAAO,MAAM,aAAa,+CAA+C,CAAC;AAC1E,eAAO,MAAM,aAAa,kDAAkD,CAAC;AAC7E,eAAO,MAAM,mBAAmB,IAAI,CAAC;AASrC,eAAO,MAAM,YAAY,UAOxB,CAAC;AAEF,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YAAY,EAAE,CAAM;gBAEvB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAE,cAAqB;IAO9E,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,oBAAoB,GAAG,MAAM;IAmBtG,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAY1B,aAAa;IAQnB;;;;OAIG;IACG,YAAY,CAAC,YAAY,EAAE,YAAY;IAsB7C;;OAEG;IACG,sBAAsB,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM;IA4BxE;;;OAGG;IACH,YAAY,CAAC,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM;IAuBrF,KAAK,CAAC,OAAO,GAAE,MAA4B,EAAE,OAAO,GAAE,MAAwB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA4ChH;;OAEG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAIzC,YAAY,IAAI,MAAM;CAUvB"}
@@ -0,0 +1,261 @@
1
+ import { __awaiter, __generator } from "tslib";
2
+ import { RemoteConfigLocalStorage } from './remote-config-localstorage';
3
+ import { UUID } from '../utils/uuid';
4
+ export var US_SERVER_URL = 'https://sr-client-cfg.amplitude.com/config';
5
+ export var EU_SERVER_URL = 'https://sr-client-cfg.eu.amplitude.com/config';
6
+ export var DEFAULT_MAX_RETRIES = 3;
7
+ /**
8
+ * The default timeout for fetch in milliseconds.
9
+ * Linear backoff policy: timeout / retry times is the interval between fetch retry.
10
+ */
11
+ var DEFAULT_TIMEOUT = 1000;
12
+ // TODO(xinyi)
13
+ // const DEFAULT_MIN_TIME_BETWEEN_FETCHES = 5 * 60 * 1000; // 5 minutes
14
+ export var FETCHED_KEYS = [
15
+ 'analyticsSDK.browserSDK',
16
+ 'sessionReplay.sr_interaction_config',
17
+ 'sessionReplay.sr_logging_config',
18
+ 'sessionReplay.sr_privacy_config',
19
+ 'sessionReplay.sr_sampling_config',
20
+ 'sessionReplay.sr_targeting_config',
21
+ ];
22
+ var RemoteConfigClient = /** @class */ (function () {
23
+ function RemoteConfigClient(apiKey, logger, serverZone) {
24
+ if (serverZone === void 0) { serverZone = 'US'; }
25
+ // Registered callbackInfos by subscribe().
26
+ this.callbackInfos = [];
27
+ this.apiKey = apiKey;
28
+ this.serverUrl = serverZone === 'US' ? US_SERVER_URL : EU_SERVER_URL;
29
+ this.logger = logger;
30
+ this.storage = new RemoteConfigLocalStorage(apiKey, logger);
31
+ }
32
+ RemoteConfigClient.prototype.subscribe = function (key, deliveryMode, callback) {
33
+ var id = UUID();
34
+ var callbackInfo = {
35
+ id: id,
36
+ key: key,
37
+ deliveryMode: deliveryMode,
38
+ callback: callback,
39
+ };
40
+ this.callbackInfos.push(callbackInfo);
41
+ if (deliveryMode === 'all') {
42
+ void this.subscribeAll(callbackInfo);
43
+ }
44
+ else {
45
+ void this.subscribeWaitForRemote(callbackInfo, deliveryMode.timeout);
46
+ }
47
+ return id;
48
+ };
49
+ RemoteConfigClient.prototype.unsubscribe = function (id) {
50
+ var index = this.callbackInfos.findIndex(function (callbackInfo) { return callbackInfo.id === id; });
51
+ if (index === -1) {
52
+ this.logger.debug("Remote config client unsubscribe failed because callback with id ".concat(id, " doesn't exist."));
53
+ return false;
54
+ }
55
+ this.callbackInfos.splice(index, 1);
56
+ this.logger.debug("Remote config client unsubscribe succeeded removing callback with id ".concat(id, "."));
57
+ return true;
58
+ };
59
+ RemoteConfigClient.prototype.updateConfigs = function () {
60
+ return __awaiter(this, void 0, void 0, function () {
61
+ var result;
62
+ var _this = this;
63
+ return __generator(this, function (_a) {
64
+ switch (_a.label) {
65
+ case 0: return [4 /*yield*/, this.fetch()];
66
+ case 1:
67
+ result = _a.sent();
68
+ void this.storage.setConfig(result);
69
+ this.callbackInfos.forEach(function (callbackInfo) {
70
+ _this.sendCallback(callbackInfo, result, 'remote');
71
+ });
72
+ return [2 /*return*/];
73
+ }
74
+ });
75
+ });
76
+ };
77
+ /**
78
+ * Send remote first. If it's already complete, we can skip the cached response.
79
+ * - if remote is fetched first, no cache fetch.
80
+ * - if cache is fetched first, still fetching remote.
81
+ */
82
+ RemoteConfigClient.prototype.subscribeAll = function (callbackInfo) {
83
+ return __awaiter(this, void 0, void 0, function () {
84
+ var remotePromise, cachePromise, result;
85
+ var _this = this;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0:
89
+ remotePromise = this.fetch().then(function (result) {
90
+ _this.logger.debug('Remote config client subscription all mode fetched from remote.');
91
+ _this.sendCallback(callbackInfo, result, 'remote');
92
+ void _this.storage.setConfig(result);
93
+ });
94
+ cachePromise = this.storage.fetchConfig().then(function (result) {
95
+ return result;
96
+ });
97
+ return [4 /*yield*/, Promise.race([remotePromise, cachePromise])];
98
+ case 1:
99
+ result = _a.sent();
100
+ // If cache is fetched first, wait for remote.
101
+ if (result !== undefined) {
102
+ this.logger.debug('Remote config client subscription all mode fetched from cache.');
103
+ this.sendCallback(callbackInfo, result, 'cache');
104
+ }
105
+ return [4 /*yield*/, remotePromise];
106
+ case 2:
107
+ _a.sent();
108
+ return [2 /*return*/];
109
+ }
110
+ });
111
+ });
112
+ };
113
+ /**
114
+ * Waits for a remote response until the given timeout, then return a cached copy, if available.
115
+ */
116
+ RemoteConfigClient.prototype.subscribeWaitForRemote = function (callbackInfo, timeout) {
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ var timeoutPromise, result, error_1, result;
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0:
122
+ timeoutPromise = new Promise(function (_, reject) {
123
+ setTimeout(function () {
124
+ reject('Timeout exceeded');
125
+ }, timeout);
126
+ });
127
+ _a.label = 1;
128
+ case 1:
129
+ _a.trys.push([1, 3, , 5]);
130
+ return [4 /*yield*/, Promise.race([this.fetch(), timeoutPromise])];
131
+ case 2:
132
+ result = (_a.sent());
133
+ this.logger.debug('Remote config client subscription wait for remote mode returns from remote.');
134
+ this.sendCallback(callbackInfo, result, 'remote');
135
+ void this.storage.setConfig(result);
136
+ return [3 /*break*/, 5];
137
+ case 3:
138
+ error_1 = _a.sent();
139
+ this.logger.debug('Remote config client subscription wait for remote mode exceeded timeout. Try to fetch from cache.');
140
+ return [4 /*yield*/, this.storage.fetchConfig()];
141
+ case 4:
142
+ result = _a.sent();
143
+ if (result.remoteConfig !== null) {
144
+ this.logger.debug('Remote config client subscription wait for remote mode returns a cached copy.');
145
+ this.sendCallback(callbackInfo, result, 'cache');
146
+ }
147
+ else {
148
+ this.logger.debug('Remote config client subscription wait for remote mode failed to fetch cache.');
149
+ this.sendCallback(callbackInfo, result, 'remote');
150
+ }
151
+ return [3 /*break*/, 5];
152
+ case 5: return [2 /*return*/];
153
+ }
154
+ });
155
+ });
156
+ };
157
+ /**
158
+ * Call the callback with filtered remote config based on key.
159
+ * @param remoteConfigInfo - the whole remote config object without filtering by key.
160
+ */
161
+ RemoteConfigClient.prototype.sendCallback = function (callbackInfo, remoteConfigInfo, source) {
162
+ callbackInfo.lastCallback = new Date();
163
+ var filteredConfig;
164
+ if (callbackInfo.key) {
165
+ // Filter remote config by key.
166
+ // For example, if remote config is {a: {b: {c: 1}}},
167
+ // if key = 'a', filter result is {b: {c: 1}};
168
+ // if key = 'a.b', filter result is {c: 1}
169
+ filteredConfig = callbackInfo.key.split('.').reduce(function (config, key) {
170
+ if (config === null) {
171
+ return config;
172
+ }
173
+ return key in config ? config[key] : null;
174
+ }, remoteConfigInfo.remoteConfig);
175
+ }
176
+ else {
177
+ filteredConfig = remoteConfigInfo.remoteConfig;
178
+ }
179
+ callbackInfo.callback(filteredConfig, source, remoteConfigInfo.lastFetch);
180
+ };
181
+ RemoteConfigClient.prototype.fetch = function (retries, timeout) {
182
+ if (retries === void 0) { retries = DEFAULT_MAX_RETRIES; }
183
+ if (timeout === void 0) { timeout = DEFAULT_TIMEOUT; }
184
+ return __awaiter(this, void 0, void 0, function () {
185
+ var interval, failedRemoteConfigInfo, attempt, res, body, remoteConfig, error_2;
186
+ var _this = this;
187
+ return __generator(this, function (_a) {
188
+ switch (_a.label) {
189
+ case 0:
190
+ interval = timeout / retries;
191
+ failedRemoteConfigInfo = {
192
+ remoteConfig: null,
193
+ lastFetch: new Date(),
194
+ };
195
+ attempt = 0;
196
+ _a.label = 1;
197
+ case 1:
198
+ if (!(attempt < retries)) return [3 /*break*/, 12];
199
+ _a.label = 2;
200
+ case 2:
201
+ _a.trys.push([2, 8, , 9]);
202
+ return [4 /*yield*/, fetch(this.getUrlParams(), {
203
+ method: 'GET',
204
+ headers: {
205
+ Accept: '*/*',
206
+ },
207
+ })];
208
+ case 3:
209
+ res = _a.sent();
210
+ if (!!res.ok) return [3 /*break*/, 5];
211
+ return [4 /*yield*/, res.text()];
212
+ case 4:
213
+ body = _a.sent();
214
+ this.logger.debug("Remote config client fetch with retry time ".concat(retries, " failed with ").concat(res.status, ": ").concat(body));
215
+ return [3 /*break*/, 7];
216
+ case 5: return [4 /*yield*/, res.json()];
217
+ case 6:
218
+ remoteConfig = (_a.sent());
219
+ return [2 /*return*/, {
220
+ remoteConfig: remoteConfig,
221
+ lastFetch: new Date(),
222
+ }];
223
+ case 7: return [3 /*break*/, 9];
224
+ case 8:
225
+ error_2 = _a.sent();
226
+ // Handle rejects when the request fails, for example, a network error
227
+ this.logger.debug("Remote config client fetch with retry time ".concat(retries, " is rejected because: "), error_2);
228
+ return [3 /*break*/, 9];
229
+ case 9:
230
+ if (!(attempt < retries - 1)) return [3 /*break*/, 11];
231
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, _this.getJitterDelay(interval)); })];
232
+ case 10:
233
+ _a.sent();
234
+ _a.label = 11;
235
+ case 11:
236
+ attempt++;
237
+ return [3 /*break*/, 1];
238
+ case 12: return [2 /*return*/, failedRemoteConfigInfo];
239
+ }
240
+ });
241
+ });
242
+ };
243
+ /**
244
+ * Return jitter in the bound of [0,baseDelay) and then floor round.
245
+ */
246
+ RemoteConfigClient.prototype.getJitterDelay = function (baseDelay) {
247
+ return Math.floor(Math.random() * baseDelay);
248
+ };
249
+ RemoteConfigClient.prototype.getUrlParams = function () {
250
+ var urlParams = new URLSearchParams({
251
+ api_key: this.apiKey,
252
+ });
253
+ FETCHED_KEYS.forEach(function (key) {
254
+ urlParams.append('config_keys', key);
255
+ });
256
+ return "".concat(this.serverUrl, "?").concat(urlParams.toString());
257
+ };
258
+ return RemoteConfigClient;
259
+ }());
260
+ export { RemoteConfigClient };
261
+ //# sourceMappingURL=remote-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-config.js","sourceRoot":"","sources":["../../../src/remote-config/remote-config.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAiBrC,MAAM,CAAC,IAAM,aAAa,GAAG,4CAA4C,CAAC;AAC1E,MAAM,CAAC,IAAM,aAAa,GAAG,+CAA+C,CAAC;AAC7E,MAAM,CAAC,IAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;GAGG;AACH,IAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,cAAc;AACd,uEAAuE;AACvE,MAAM,CAAC,IAAM,YAAY,GAAG;IAC1B,yBAAyB;IACzB,qCAAqC;IACrC,iCAAiC;IACjC,iCAAiC;IACjC,kCAAkC;IAClC,mCAAmC;CACpC,CAAC;AAwEF;IAQE,4BAAY,MAAc,EAAE,MAAe,EAAE,UAAiC;QAAjC,2BAAA,EAAA,iBAAiC;QAH9E,2CAA2C;QAC3C,kBAAa,GAAmB,EAAE,CAAC;QAGjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC;QACrE,IAAI,CAAC,MAAM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1E,qBAAM,GAAG,CAAC,IAAI,EAAE,EAAA;;wBAA9C,YAAY,GAAiB,CAAC,SAAgB,CAAiB;wBACrE,sBAAO;gCACL,YAAY,EAAE,YAAY;gCAC1B,SAAS,EAAE,IAAI,IAAI,EAAE;6BACtB,EAAC;;;;wBAGJ,sEAAsE;wBACtE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qDAA8C,OAAO,2BAAwB,EAAE,OAAK,CAAC,CAAC;;;6BAMtG,CAAA,OAAO,GAAG,OAAO,GAAG,CAAC,CAAA,EAArB,yBAAqB;wBACvB,qBAAM,IAAI,OAAO,CAAC,UAAC,OAAO,IAAK,OAAA,UAAU,CAAC,OAAO,EAAE,KAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,EAAlD,CAAkD,CAAC,EAAA;;wBAAlF,SAAkF,CAAC;;;wBA9B9C,OAAO,EAAE,CAAA;;6BAkClD,sBAAO,sBAAsB,EAAC;;;;KAC/B;IAED;;OAEG;IACH,2CAAc,GAAd,UAAe,SAAiB;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IAC/C,CAAC;IAED,yCAAY,GAAZ;QACE,IAAM,SAAS,GAAG,IAAI,eAAe,CAAC;YACpC,OAAO,EAAE,IAAI,CAAC,MAAM;SACrB,CAAC,CAAC;QACH,YAAY,CAAC,OAAO,CAAC,UAAC,GAAG;YACvB,SAAS,CAAC,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;QAEH,OAAO,UAAG,IAAI,CAAC,SAAS,cAAI,SAAS,CAAC,QAAQ,EAAE,CAAE,CAAC;IACrD,CAAC;IACH,yBAAC;AAAD,CAAC,AAxMD,IAwMC","sourcesContent":["import { ServerZoneType } from '../types/server-zone';\nimport { ILogger } from '../logger';\nimport { RemoteConfigLocalStorage } from './remote-config-localstorage';\nimport { UUID } from '../utils/uuid';\n\n/**\n * Modes for receiving remote config updates:\n * - `'all'` – Receive all config updates as they occur.\n * - `{ timeout: number }` – Wait for a remote response until the specified timeout (in milliseconds),\n * then return a cached copy if available.\n */\nexport type DeliveryMode = 'all' | { timeout: number };\n\n/**\n * Sources of returned remote config:\n * - `cache` - Fetched from local storage.\n * - `remote` - Fetched from remote.\n */\nexport type Source = 'cache' | 'remote';\n\nexport const US_SERVER_URL = 'https://sr-client-cfg.amplitude.com/config';\nexport const EU_SERVER_URL = 'https://sr-client-cfg.eu.amplitude.com/config';\nexport const DEFAULT_MAX_RETRIES = 3;\n\n/**\n * The default timeout for fetch in milliseconds.\n * Linear backoff policy: timeout / retry times is the interval between fetch retry.\n */\nconst DEFAULT_TIMEOUT = 1000;\n// TODO(xinyi)\n// const DEFAULT_MIN_TIME_BETWEEN_FETCHES = 5 * 60 * 1000; // 5 minutes\nexport const FETCHED_KEYS = [\n 'analyticsSDK.browserSDK',\n 'sessionReplay.sr_interaction_config',\n 'sessionReplay.sr_logging_config',\n 'sessionReplay.sr_privacy_config',\n 'sessionReplay.sr_sampling_config',\n 'sessionReplay.sr_targeting_config',\n];\n\nexport interface RemoteConfig {\n [key: string]: any;\n}\n\nexport interface RemoteConfigInfo {\n remoteConfig: RemoteConfig | null;\n // Timestamp of when the remote config was fetched.\n lastFetch: Date;\n}\n\nexport interface RemoteConfigStorage {\n /**\n * Fetch remote config from storage asynchronously.\n */\n fetchConfig(): Promise<RemoteConfigInfo>;\n\n /**\n * Set remote config to storage asynchronously.\n */\n setConfig(config: RemoteConfigInfo): Promise<boolean>;\n}\n\n/**\n * Information about each callback registered by `RemoteConfigClient.subscribe()`,\n * managed internally by `RemoteConfigClient`.\n */\nexport interface CallbackInfo {\n id: string;\n key?: string;\n deliveryMode: DeliveryMode;\n callback: RemoteConfigCallback;\n lastCallback?: Date;\n}\n\n/**\n * Callback used in `RemoteConfigClient.subscribe()`.\n * This function is called when the remote config is fetched.\n */\ntype RemoteConfigCallback = (remoteConfig: RemoteConfig | null, source: Source, lastFetch: Date) => void;\n\nexport interface IRemoteConfigClient {\n /**\n * Subscribe for updates to remote config.\n * Callback is guaranteed to be called at least once,\n * Whether we are able to fetch a config or not.\n *\n * @param key - a string containing a series of period delimited keys to filter the returned config.\n * Ie, {a: {b: {c: ...}}} would return {b: {c: ...}} for \"a\" or {c: ...} for \"a.b\".\n * Set to `undefined` to subscribe all keys.\n * @param deliveryMode - how the initial callback is sent.\n * @param callback - a block that will be called when remote config is fetched.\n * @return id - identification of the subscribe and can be used to unsubscribe from updates.\n */\n subscribe(key: string | undefined, deliveryMode: DeliveryMode, callback: RemoteConfigCallback): string;\n\n /**\n * Unsubscribe a callback from receiving future updates.\n *\n * @param id - identification of the callback that you want to unsubscribe.\n * It's the return value of subscribe().\n * @return boolean - whether the callback is removed.\n */\n unsubscribe(id: string): boolean;\n\n /**\n * Request the remote config client to fetch from remote, update cache, and callback.\n */\n updateConfigs(): void;\n}\n\nexport class RemoteConfigClient implements IRemoteConfigClient {\n readonly apiKey: string;\n readonly serverUrl: string;\n readonly logger: ILogger;\n readonly storage: RemoteConfigStorage;\n // Registered callbackInfos by subscribe().\n callbackInfos: CallbackInfo[] = [];\n\n constructor(apiKey: string, logger: ILogger, serverZone: ServerZoneType = 'US') {\n this.apiKey = apiKey;\n this.serverUrl = serverZone === 'US' ? US_SERVER_URL : EU_SERVER_URL;\n this.logger = logger;\n this.storage = new RemoteConfigLocalStorage(apiKey, logger);\n }\n\n subscribe(key: string | undefined, deliveryMode: DeliveryMode, callback: RemoteConfigCallback): string {\n const id = UUID();\n const callbackInfo = {\n id: id,\n key: key,\n deliveryMode: deliveryMode,\n callback: callback,\n };\n this.callbackInfos.push(callbackInfo);\n\n if (deliveryMode === 'all') {\n void this.subscribeAll(callbackInfo);\n } else {\n void this.subscribeWaitForRemote(callbackInfo, deliveryMode.timeout);\n }\n\n return id;\n }\n\n unsubscribe(id: string): boolean {\n const index = this.callbackInfos.findIndex((callbackInfo) => callbackInfo.id === id);\n if (index === -1) {\n this.logger.debug(`Remote config client unsubscribe failed because callback with id ${id} doesn't exist.`);\n return false;\n }\n\n this.callbackInfos.splice(index, 1);\n this.logger.debug(`Remote config client unsubscribe succeeded removing callback with id ${id}.`);\n return true;\n }\n\n async updateConfigs() {\n const result = await this.fetch();\n void this.storage.setConfig(result);\n this.callbackInfos.forEach((callbackInfo) => {\n this.sendCallback(callbackInfo, result, 'remote');\n });\n }\n\n /**\n * Send remote first. If it's already complete, we can skip the cached response.\n * - if remote is fetched first, no cache fetch.\n * - if cache is fetched first, still fetching remote.\n */\n async subscribeAll(callbackInfo: CallbackInfo) {\n const remotePromise = this.fetch().then((result) => {\n this.logger.debug('Remote config client subscription all mode fetched from remote.');\n this.sendCallback(callbackInfo, result, 'remote');\n void this.storage.setConfig(result);\n });\n\n const cachePromise = this.storage.fetchConfig().then((result) => {\n return result;\n });\n\n // Wait for the first result to resolve\n const result = await Promise.race([remotePromise, cachePromise]);\n\n // If cache is fetched first, wait for remote.\n if (result !== undefined) {\n this.logger.debug('Remote config client subscription all mode fetched from cache.');\n this.sendCallback(callbackInfo, result, 'cache');\n }\n await remotePromise;\n }\n\n /**\n * Waits for a remote response until the given timeout, then return a cached copy, if available.\n */\n async subscribeWaitForRemote(callbackInfo: CallbackInfo, timeout: number) {\n const timeoutPromise = new Promise((_, reject) => {\n setTimeout(() => {\n reject('Timeout exceeded');\n }, timeout);\n });\n\n try {\n const result: RemoteConfigInfo = (await Promise.race([this.fetch(), timeoutPromise])) as RemoteConfigInfo;\n\n this.logger.debug('Remote config client subscription wait for remote mode returns from remote.');\n this.sendCallback(callbackInfo, result, 'remote');\n void this.storage.setConfig(result);\n } catch (error) {\n this.logger.debug(\n 'Remote config client subscription wait for remote mode exceeded timeout. Try to fetch from cache.',\n );\n const result = await this.storage.fetchConfig();\n if (result.remoteConfig !== null) {\n this.logger.debug('Remote config client subscription wait for remote mode returns a cached copy.');\n this.sendCallback(callbackInfo, result, 'cache');\n } else {\n this.logger.debug('Remote config client subscription wait for remote mode failed to fetch cache.');\n this.sendCallback(callbackInfo, result, 'remote');\n }\n }\n }\n\n /**\n * Call the callback with filtered remote config based on key.\n * @param remoteConfigInfo - the whole remote config object without filtering by key.\n */\n sendCallback(callbackInfo: CallbackInfo, remoteConfigInfo: RemoteConfigInfo, source: Source) {\n callbackInfo.lastCallback = new Date();\n\n let filteredConfig: RemoteConfig | null;\n if (callbackInfo.key) {\n // Filter remote config by key.\n // For example, if remote config is {a: {b: {c: 1}}},\n // if key = 'a', filter result is {b: {c: 1}};\n // if key = 'a.b', filter result is {c: 1}\n filteredConfig = callbackInfo.key.split('.').reduce((config, key) => {\n if (config === null) {\n return config;\n }\n\n return key in config ? (config[key] as RemoteConfig) : null;\n }, remoteConfigInfo.remoteConfig);\n } else {\n filteredConfig = remoteConfigInfo.remoteConfig;\n }\n\n callbackInfo.callback(filteredConfig, source, remoteConfigInfo.lastFetch);\n }\n\n async fetch(retries: number = DEFAULT_MAX_RETRIES, timeout: number = DEFAULT_TIMEOUT): Promise<RemoteConfigInfo> {\n const interval = timeout / retries;\n const failedRemoteConfigInfo: RemoteConfigInfo = {\n remoteConfig: null,\n lastFetch: new Date(),\n };\n\n for (let attempt = 0; attempt < retries; attempt++) {\n try {\n const res = await fetch(this.getUrlParams(), {\n method: 'GET',\n headers: {\n Accept: '*/*',\n },\n });\n\n // Handle unsuccessful fetch\n if (!res.ok) {\n const body = await res.text();\n this.logger.debug(`Remote config client fetch with retry time ${retries} failed with ${res.status}: ${body}`);\n } else {\n // Handle successful fetch\n const remoteConfig: RemoteConfig = (await res.json()) as RemoteConfig;\n return {\n remoteConfig: remoteConfig,\n lastFetch: new Date(),\n };\n }\n } catch (error) {\n // Handle rejects when the request fails, for example, a network error\n this.logger.debug(`Remote config client fetch with retry time ${retries} is rejected because: `, error);\n }\n\n // Linear backoff:\n // wait for the specified interval before the next attempt\n // except after the last attempt.\n if (attempt < retries - 1) {\n await new Promise((resolve) => setTimeout(resolve, this.getJitterDelay(interval)));\n }\n }\n\n return failedRemoteConfigInfo;\n }\n\n /**\n * Return jitter in the bound of [0,baseDelay) and then floor round.\n */\n getJitterDelay(baseDelay: number): number {\n return Math.floor(Math.random() * baseDelay);\n }\n\n getUrlParams(): string {\n const urlParams = new URLSearchParams({\n api_key: this.apiKey,\n });\n FETCHED_KEYS.forEach((key) => {\n urlParams.append('config_keys', key);\n });\n\n return `${this.serverUrl}?${urlParams.toString()}`;\n }\n}\n"]}
@@ -75,8 +75,9 @@ export interface ExternalBrowserConfig extends IConfig {
75
75
  */
76
76
  pageCounter?: number;
77
77
  /**
78
- * Whether to fetch remote configuration.
79
- * @defaultValue `false`
78
+ * Whether to fetch remote configuration. The remote configuration can be updated in the Amplitude platform here:
79
+ * https://app.amplitude.com/data/amplitude/{your_org_name}/settings/autocapture
80
+ * @defaultValue `true`
80
81
  */
81
82
  fetchRemoteConfig?: boolean;
82
83
  }
@@ -1 +1 @@
1
- {"version":3,"file":"browser-config.d.ts","sourceRoot":"","sources":["../../../src/types/browser-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,WAAW,aAAc,SAAQ,qBAAqB,EAAE,qBAAqB;CAAG;AAEtF,MAAM,WAAW,qBAAsB,SAAQ,OAAO;IACpD;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,GAAG,sBAAsB,CAAC;IACnD;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,GAA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OAAO,CAAC;CACrC;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;IACrC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,KAAK,aAAa,GAAG,QAAQ,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;AAGxE,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE,aAAa,CAAC;CAAG"}
@@ -1 +1 @@
1
- {"version":3,"file":"browser-config.js","sourceRoot":"","sources":["../../../src/types/browser-config.ts"],"names":[],"mappings":"","sourcesContent":["import { UserSession } from './user-session';\nimport { IdentityStorageType, Storage } from './storage';\nimport { Transport } from './transport';\nimport { IConfig } from '../config';\nimport { ElementInteractionsOptions } from './element-interactions';\nimport { PageTrackingOptions } from './page-view-tracking';\n\nexport interface BrowserConfig extends ExternalBrowserConfig, InternalBrowserConfig {}\n\nexport interface ExternalBrowserConfig extends IConfig {\n /**\n * An app version for events tracked. This can be the version of your application.\n * @defaultValue `undefined`\n */\n appVersion?: string;\n /**\n * @deprecated This property is deprecated and will be removed in future versions. Please migrate to using `autocapture` instead.\n * The default event tracking configuration.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/#tracking-default-events}.\n * @defaultValue `true`\n */\n defaultTracking?: boolean | DefaultTrackingOptions;\n /**\n * The configurations for auto-captured events.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/autocapture/}.\n */\n autocapture?: boolean | AutocaptureOptions;\n /**\n * The identifier for the device running your application.\n * @defaultValue `UUID()`\n */\n deviceId?: string;\n /**\n * Configuration for cookie.\n */\n cookieOptions?: CookieOptions;\n /**\n * The storage for user identify.\n * @defaultValue `\"cookie\"`\n */\n identityStorage?: IdentityStorageType;\n /**\n * The partner identifier.\n * Amplitude requires the customer who built an event ingestion integration to add the partner identifier to partner_id.\n * @defaultValue `undefined`\n */\n partnerId?: string;\n /**\n * The custom Session ID for the current session.\n * @defaultValue `timestamp`\n */\n sessionId?: number;\n /**\n * The period of inactivity from the last tracked event before a session expires in milliseconds.\n * @defaultValue `1,800,000` (30 minutes)\n */\n sessionTimeout: number;\n /**\n * The configurations for tracking additional properties.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/#optional-tracking}.\n */\n trackingOptions: TrackingOptions;\n /**\n * Network transport mechanism used to send events.\n * @defaultValue `\"fetch\"`\n */\n transport?: 'fetch' | 'xhr' | 'beacon';\n /**\n * The identifier for the user being tracked.\n * @defaultValue `undefined`\n */\n userId?: string;\n /**\n * User's Nth instance of performing a default Page Viewed event within a session.\n * Used for landing page analysis.\n */\n pageCounter?: number;\n /**\n * Whether to fetch remote configuration.\n * @defaultValue `false`\n */\n fetchRemoteConfig?: boolean;\n}\n\ninterface InternalBrowserConfig {\n cookieStorage: Storage<UserSession>;\n lastEventTime?: number;\n lastEventId?: number;\n transportProvider: Transport;\n version?: string;\n}\n\n/**\n * @deprecated This interface is deprecated and will be removed in future versions. Please migrate to using `AutocaptureOptions` instead.\n */\nexport interface DefaultTrackingOptions {\n /**\n * Enables/disables marketing attribution tracking or config with detailed attribution options.\n * @defaultValue `true`\n */\n attribution?: boolean | AttributionOptions;\n /**\n * Enables/disables form downloads tracking.\n * @defaultValue `true`\n */\n fileDownloads?: boolean;\n /**\n * Enables/disables form interaction tracking.\n * @defaultValue `true`\n */\n formInteractions?: boolean;\n /**\n * Enables/disables default page view tracking.\n * @defaultValue `true`\n */\n pageViews?: boolean | PageTrackingOptions;\n /**\n * Enables/disables session tracking.\n * @defaultValue `true`\n */\n sessions?: boolean;\n}\n\nexport interface AutocaptureOptions {\n /**\n * Enables/disables marketing attribution tracking or config with detailed attribution options.\n * @defaultValue `true`\n */\n attribution?: boolean | AttributionOptions;\n /**\n * Enables/disables form downloads tracking.\n * @defaultValue `true`\n */\n fileDownloads?: boolean;\n /**\n * Enables/disables form interaction tracking.\n * @defaultValue `true`\n */\n formInteractions?: boolean;\n /**\n * Enables/disables default page view tracking.\n * @defaultValue `true`\n */\n pageViews?: boolean | PageTrackingOptions;\n /**\n * Enables/disables session tracking.\n * @defaultValue `true`\n */\n sessions?: boolean;\n /**\n * Enables/disables user interactions tracking.\n * @defaultValue `false`\n */\n elementInteractions?: boolean | ElementInteractionsOptions;\n}\n\nexport interface TrackingOptions {\n /**\n * Enables/disables ip address tracking.\n * @defaultValue `true`\n */\n ipAddress?: boolean;\n /**\n * Enables/disables language tracking.\n * @defaultValue `true`\n */\n language?: boolean;\n /**\n * Enables/disables plantform tracking.\n * @defaultValue `true`\n */\n platform?: boolean;\n}\n\nexport interface AttributionOptions {\n /**\n * The rules to determine which referrers are excluded from being tracked as traffic source.\n * @defaultValue `[/your-domain\\.com$/]`\n */\n excludeReferrers?: (string | RegExp)[];\n /**\n * The value to represent undefined/no initial campaign parameter for first-touch attribution.\n * @defaultValue `\"EMPTY\"`\n */\n initialEmptyValue?: string;\n /**\n * The flag of if Amplitude to start a new session if any campaign parameter changes.\n * @defaultValue `false`\n */\n resetSessionOnNewCampaign?: boolean;\n}\n\nexport interface CookieOptions {\n /**\n * The domain property of cookies created.\n * @defaultValue `Your top level domain`\n */\n domain?: string;\n /**\n * The expiration of cookies created in days.\n * @defaultValue `365`\n */\n expiration?: number;\n /**\n * How cookies are sent with cross-site requests.\n * @defaultValue `\"Lax\"`\n */\n sameSite?: 'Strict' | 'Lax' | 'None';\n /**\n * The flag of if send cookies over secure protocols.\n * @defaultValue `false`\n */\n secure?: boolean;\n /**\n * The flag of if upgrade the cookies created by maintenance Browser SDK.\n * @defaultValue `true`\n */\n upgrade?: boolean;\n}\n\ntype HiddenOptions = 'apiKey' | 'transportProvider' | 'requestMetadata';\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface BrowserOptions extends Omit<Partial<ExternalBrowserConfig>, HiddenOptions> {}\n"]}
1
+ {"version":3,"file":"browser-config.js","sourceRoot":"","sources":["../../../src/types/browser-config.ts"],"names":[],"mappings":"","sourcesContent":["import { UserSession } from './user-session';\nimport { IdentityStorageType, Storage } from './storage';\nimport { Transport } from './transport';\nimport { IConfig } from '../config';\nimport { ElementInteractionsOptions } from './element-interactions';\nimport { PageTrackingOptions } from './page-view-tracking';\n\nexport interface BrowserConfig extends ExternalBrowserConfig, InternalBrowserConfig {}\n\nexport interface ExternalBrowserConfig extends IConfig {\n /**\n * An app version for events tracked. This can be the version of your application.\n * @defaultValue `undefined`\n */\n appVersion?: string;\n /**\n * @deprecated This property is deprecated and will be removed in future versions. Please migrate to using `autocapture` instead.\n * The default event tracking configuration.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/#tracking-default-events}.\n * @defaultValue `true`\n */\n defaultTracking?: boolean | DefaultTrackingOptions;\n /**\n * The configurations for auto-captured events.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/autocapture/}.\n */\n autocapture?: boolean | AutocaptureOptions;\n /**\n * The identifier for the device running your application.\n * @defaultValue `UUID()`\n */\n deviceId?: string;\n /**\n * Configuration for cookie.\n */\n cookieOptions?: CookieOptions;\n /**\n * The storage for user identify.\n * @defaultValue `\"cookie\"`\n */\n identityStorage?: IdentityStorageType;\n /**\n * The partner identifier.\n * Amplitude requires the customer who built an event ingestion integration to add the partner identifier to partner_id.\n * @defaultValue `undefined`\n */\n partnerId?: string;\n /**\n * The custom Session ID for the current session.\n * @defaultValue `timestamp`\n */\n sessionId?: number;\n /**\n * The period of inactivity from the last tracked event before a session expires in milliseconds.\n * @defaultValue `1,800,000` (30 minutes)\n */\n sessionTimeout: number;\n /**\n * The configurations for tracking additional properties.\n * See {@link https://www.docs.developers.amplitude.com/data/sdks/browser-2/#optional-tracking}.\n */\n trackingOptions: TrackingOptions;\n /**\n * Network transport mechanism used to send events.\n * @defaultValue `\"fetch\"`\n */\n transport?: 'fetch' | 'xhr' | 'beacon';\n /**\n * The identifier for the user being tracked.\n * @defaultValue `undefined`\n */\n userId?: string;\n /**\n * User's Nth instance of performing a default Page Viewed event within a session.\n * Used for landing page analysis.\n */\n pageCounter?: number;\n /**\n * Whether to fetch remote configuration. The remote configuration can be updated in the Amplitude platform here:\n * https://app.amplitude.com/data/amplitude/{your_org_name}/settings/autocapture\n * @defaultValue `true`\n */\n fetchRemoteConfig?: boolean;\n}\n\ninterface InternalBrowserConfig {\n cookieStorage: Storage<UserSession>;\n lastEventTime?: number;\n lastEventId?: number;\n transportProvider: Transport;\n version?: string;\n}\n\n/**\n * @deprecated This interface is deprecated and will be removed in future versions. Please migrate to using `AutocaptureOptions` instead.\n */\nexport interface DefaultTrackingOptions {\n /**\n * Enables/disables marketing attribution tracking or config with detailed attribution options.\n * @defaultValue `true`\n */\n attribution?: boolean | AttributionOptions;\n /**\n * Enables/disables form downloads tracking.\n * @defaultValue `true`\n */\n fileDownloads?: boolean;\n /**\n * Enables/disables form interaction tracking.\n * @defaultValue `true`\n */\n formInteractions?: boolean;\n /**\n * Enables/disables default page view tracking.\n * @defaultValue `true`\n */\n pageViews?: boolean | PageTrackingOptions;\n /**\n * Enables/disables session tracking.\n * @defaultValue `true`\n */\n sessions?: boolean;\n}\n\nexport interface AutocaptureOptions {\n /**\n * Enables/disables marketing attribution tracking or config with detailed attribution options.\n * @defaultValue `true`\n */\n attribution?: boolean | AttributionOptions;\n /**\n * Enables/disables form downloads tracking.\n * @defaultValue `true`\n */\n fileDownloads?: boolean;\n /**\n * Enables/disables form interaction tracking.\n * @defaultValue `true`\n */\n formInteractions?: boolean;\n /**\n * Enables/disables default page view tracking.\n * @defaultValue `true`\n */\n pageViews?: boolean | PageTrackingOptions;\n /**\n * Enables/disables session tracking.\n * @defaultValue `true`\n */\n sessions?: boolean;\n /**\n * Enables/disables user interactions tracking.\n * @defaultValue `false`\n */\n elementInteractions?: boolean | ElementInteractionsOptions;\n}\n\nexport interface TrackingOptions {\n /**\n * Enables/disables ip address tracking.\n * @defaultValue `true`\n */\n ipAddress?: boolean;\n /**\n * Enables/disables language tracking.\n * @defaultValue `true`\n */\n language?: boolean;\n /**\n * Enables/disables plantform tracking.\n * @defaultValue `true`\n */\n platform?: boolean;\n}\n\nexport interface AttributionOptions {\n /**\n * The rules to determine which referrers are excluded from being tracked as traffic source.\n * @defaultValue `[/your-domain\\.com$/]`\n */\n excludeReferrers?: (string | RegExp)[];\n /**\n * The value to represent undefined/no initial campaign parameter for first-touch attribution.\n * @defaultValue `\"EMPTY\"`\n */\n initialEmptyValue?: string;\n /**\n * The flag of if Amplitude to start a new session if any campaign parameter changes.\n * @defaultValue `false`\n */\n resetSessionOnNewCampaign?: boolean;\n}\n\nexport interface CookieOptions {\n /**\n * The domain property of cookies created.\n * @defaultValue `Your top level domain`\n */\n domain?: string;\n /**\n * The expiration of cookies created in days.\n * @defaultValue `365`\n */\n expiration?: number;\n /**\n * How cookies are sent with cross-site requests.\n * @defaultValue `\"Lax\"`\n */\n sameSite?: 'Strict' | 'Lax' | 'None';\n /**\n * The flag of if send cookies over secure protocols.\n * @defaultValue `false`\n */\n secure?: boolean;\n /**\n * The flag of if upgrade the cookies created by maintenance Browser SDK.\n * @defaultValue `true`\n */\n upgrade?: boolean;\n}\n\ntype HiddenOptions = 'apiKey' | 'transportProvider' | 'requestMetadata';\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface BrowserOptions extends Omit<Partial<ExternalBrowserConfig>, HiddenOptions> {}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amplitude/analytics-core",
3
- "version": "2.6.1",
3
+ "version": "2.8.0",
4
4
  "description": "",
5
5
  "author": "Amplitude Inc",
6
6
  "homepage": "https://github.com/amplitude/Amplitude-TypeScript",
@@ -40,5 +40,5 @@
40
40
  "files": [
41
41
  "lib"
42
42
  ],
43
- "gitHead": "51e4657f79ed61e84da7e57fbab0a05db6904fe8"
43
+ "gitHead": "0f7347c36a91764514bea8508f5792d1a27fde52"
44
44
  }