@amplitude/analytics-core 2.38.0 → 2.40.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.
- package/lib/cjs/core-client.d.ts +9 -1
- package/lib/cjs/core-client.d.ts.map +1 -1
- package/lib/cjs/core-client.js +15 -5
- package/lib/cjs/core-client.js.map +1 -1
- package/lib/cjs/diagnostics/uncaught-sdk-errors.d.ts.map +1 -1
- package/lib/cjs/diagnostics/uncaught-sdk-errors.js +42 -12
- package/lib/cjs/diagnostics/uncaught-sdk-errors.js.map +1 -1
- package/lib/cjs/index.d.ts +5 -0
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +13 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/messenger/background-capture.d.ts +13 -0
- package/lib/cjs/messenger/background-capture.d.ts.map +1 -0
- package/lib/cjs/messenger/background-capture.js +64 -0
- package/lib/cjs/messenger/background-capture.js.map +1 -0
- package/lib/cjs/messenger/base-window-messenger.d.ts +100 -0
- package/lib/cjs/messenger/base-window-messenger.d.ts.map +1 -0
- package/lib/cjs/messenger/base-window-messenger.js +261 -0
- package/lib/cjs/messenger/base-window-messenger.js.map +1 -0
- package/lib/cjs/messenger/constants.d.ts +6 -0
- package/lib/cjs/messenger/constants.d.ts.map +1 -0
- package/lib/cjs/messenger/constants.js +15 -0
- package/lib/cjs/messenger/constants.js.map +1 -0
- package/lib/cjs/messenger/utils.d.ts +12 -0
- package/lib/cjs/messenger/utils.d.ts.map +1 -0
- package/lib/cjs/messenger/utils.js +48 -0
- package/lib/cjs/messenger/utils.js.map +1 -0
- package/lib/cjs/observers/network.d.ts.map +1 -1
- package/lib/cjs/observers/network.js +58 -39
- package/lib/cjs/observers/network.js.map +1 -1
- package/lib/cjs/storage/cookie.d.ts +0 -1
- package/lib/cjs/storage/cookie.d.ts.map +1 -1
- package/lib/cjs/storage/cookie.js +4 -4
- package/lib/cjs/storage/cookie.js.map +1 -1
- package/lib/cjs/types/client/browser-client.d.ts +33 -0
- package/lib/cjs/types/client/browser-client.d.ts.map +1 -1
- package/lib/cjs/types/client/browser-client.js.map +1 -1
- package/lib/cjs/types/element-interactions.d.ts +0 -1
- package/lib/cjs/types/element-interactions.d.ts.map +1 -1
- package/lib/cjs/types/element-interactions.js.map +1 -1
- package/lib/cjs/utils/safe-stringify.d.ts +4 -0
- package/lib/cjs/utils/safe-stringify.d.ts.map +1 -0
- package/lib/cjs/utils/safe-stringify.js +9 -0
- package/lib/cjs/utils/safe-stringify.js.map +1 -0
- package/lib/esm/core-client.d.ts +9 -1
- package/lib/esm/core-client.d.ts.map +1 -1
- package/lib/esm/core-client.js +16 -6
- package/lib/esm/core-client.js.map +1 -1
- package/lib/esm/diagnostics/uncaught-sdk-errors.d.ts.map +1 -1
- package/lib/esm/diagnostics/uncaught-sdk-errors.js +43 -13
- package/lib/esm/diagnostics/uncaught-sdk-errors.js.map +1 -1
- package/lib/esm/index.d.ts +5 -0
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +4 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/messenger/background-capture.d.ts +13 -0
- package/lib/esm/messenger/background-capture.d.ts.map +1 -0
- package/lib/esm/messenger/background-capture.js +60 -0
- package/lib/esm/messenger/background-capture.js.map +1 -0
- package/lib/esm/messenger/base-window-messenger.d.ts +100 -0
- package/lib/esm/messenger/base-window-messenger.d.ts.map +1 -0
- package/lib/esm/messenger/base-window-messenger.js +257 -0
- package/lib/esm/messenger/base-window-messenger.js.map +1 -0
- package/lib/esm/messenger/constants.d.ts +6 -0
- package/lib/esm/messenger/constants.d.ts.map +1 -0
- package/lib/esm/messenger/constants.js +12 -0
- package/lib/esm/messenger/constants.js.map +1 -0
- package/lib/esm/messenger/utils.d.ts +12 -0
- package/lib/esm/messenger/utils.d.ts.map +1 -0
- package/lib/esm/messenger/utils.js +43 -0
- package/lib/esm/messenger/utils.js.map +1 -0
- package/lib/esm/observers/network.d.ts.map +1 -1
- package/lib/esm/observers/network.js +58 -39
- package/lib/esm/observers/network.js.map +1 -1
- package/lib/esm/storage/cookie.d.ts +0 -1
- package/lib/esm/storage/cookie.d.ts.map +1 -1
- package/lib/esm/storage/cookie.js +4 -4
- package/lib/esm/storage/cookie.js.map +1 -1
- package/lib/esm/types/client/browser-client.d.ts +33 -0
- package/lib/esm/types/client/browser-client.d.ts.map +1 -1
- package/lib/esm/types/client/browser-client.js.map +1 -1
- package/lib/esm/types/element-interactions.d.ts +0 -1
- package/lib/esm/types/element-interactions.d.ts.map +1 -1
- package/lib/esm/types/element-interactions.js.map +1 -1
- package/lib/esm/utils/safe-stringify.d.ts +4 -0
- package/lib/esm/utils/safe-stringify.d.ts.map +1 -0
- package/lib/esm/utils/safe-stringify.js +6 -0
- package/lib/esm/utils/safe-stringify.js.map +1 -0
- package/package.json +5 -1
package/lib/esm/core-client.d.ts
CHANGED
|
@@ -16,6 +16,13 @@ export declare class AmplitudeCore implements CoreClient, PluginHost {
|
|
|
16
16
|
isReady: boolean;
|
|
17
17
|
protected q: Array<CallableFunction | typeof returnWrapper>;
|
|
18
18
|
protected dispatchQ: Array<CallableFunction>;
|
|
19
|
+
/**
|
|
20
|
+
* Current user properties (operation-applied, flat key-value).
|
|
21
|
+
* Only used by client-side SDKs; server SDKs may leave this undefined.
|
|
22
|
+
*/
|
|
23
|
+
userProperties: {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
} | undefined;
|
|
19
26
|
constructor(name?: string);
|
|
20
27
|
protected _init(config: IConfig): Promise<void>;
|
|
21
28
|
runQueuedFunctions(queueName: 'q' | 'dispatchQ'): Promise<void>;
|
|
@@ -39,8 +46,9 @@ export declare class AmplitudeCore implements CoreClient, PluginHost {
|
|
|
39
46
|
* This is a best-effort api that only supports $set, $clearAll, and $unset.
|
|
40
47
|
* Other operations are not supported and are ignored.
|
|
41
48
|
*
|
|
49
|
+
* Operations are applied on top of current client state (this.userProperties).
|
|
42
50
|
*
|
|
43
|
-
* @param userProperties The
|
|
51
|
+
* @param userProperties The new user properties object from identify() or setIdentity().
|
|
44
52
|
* @returns A key-value object user properties without operations.
|
|
45
53
|
*
|
|
46
54
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EACL,KAAK,EAIL,cAAc,EACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAA6B,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAStC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACpE,qBAAa,aAAc,YAAW,UAAU,EAAE,UAAU;IAC1D,SAAS,CAAC,YAAY,UAAS;IAC/B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IAGvB,MAAM,EAAE,OAAO,CAAC;IAGhB,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,UAAS;IAChB,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,gBAAgB,GAAG,OAAO,aAAa,CAAC,CAAM;IACjE,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAM;
|
|
1
|
+
{"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OA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CAAA;KAAE,GAAG,CAAC,EAAE;CAGzE"}
|
package/lib/esm/core-client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __awaiter, __generator, __values } from "tslib";
|
|
1
|
+
import { __assign, __awaiter, __generator, __values } from "tslib";
|
|
2
2
|
import { IdentifyOperation, SpecialEventType, } from './types/event/event';
|
|
3
3
|
import { OrderedIdentifyOperations } from './identify';
|
|
4
4
|
import { CLIENT_NOT_INITIALIZED, OPT_OUT_MESSAGE } from './types/messages';
|
|
@@ -88,10 +88,14 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
88
88
|
};
|
|
89
89
|
AmplitudeCore.prototype.track = function (eventInput, eventProperties, eventOptions) {
|
|
90
90
|
var event = createTrackEvent(eventInput, eventProperties, eventOptions);
|
|
91
|
+
// Update client user properties immediately and synchronously
|
|
92
|
+
this.userProperties = this.getOperationAppliedUserProperties(event.user_properties);
|
|
91
93
|
return returnWrapper(this.dispatch(event));
|
|
92
94
|
};
|
|
93
95
|
AmplitudeCore.prototype.identify = function (identify, eventOptions) {
|
|
94
96
|
var event = createIdentifyEvent(identify, eventOptions);
|
|
97
|
+
// Update client user properties immediately and synchronously
|
|
98
|
+
this.userProperties = this.getOperationAppliedUserProperties(event.user_properties);
|
|
95
99
|
return returnWrapper(this.dispatch(event));
|
|
96
100
|
};
|
|
97
101
|
AmplitudeCore.prototype.groupIdentify = function (groupType, groupName, identify, eventOptions) {
|
|
@@ -100,6 +104,8 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
100
104
|
};
|
|
101
105
|
AmplitudeCore.prototype.setGroup = function (groupType, groupName, eventOptions) {
|
|
102
106
|
var event = createGroupEvent(groupType, groupName, eventOptions);
|
|
107
|
+
// Update client user properties immediately and synchronously
|
|
108
|
+
this.userProperties = this.getOperationAppliedUserProperties(event.user_properties);
|
|
103
109
|
return returnWrapper(this.dispatch(event));
|
|
104
110
|
};
|
|
105
111
|
AmplitudeCore.prototype.revenue = function (revenue, eventOptions) {
|
|
@@ -153,8 +159,9 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
153
159
|
* This is a best-effort api that only supports $set, $clearAll, and $unset.
|
|
154
160
|
* Other operations are not supported and are ignored.
|
|
155
161
|
*
|
|
162
|
+
* Operations are applied on top of current client state (this.userProperties).
|
|
156
163
|
*
|
|
157
|
-
* @param userProperties The
|
|
164
|
+
* @param userProperties The new user properties object from identify() or setIdentity().
|
|
158
165
|
* @returns A key-value object user properties without operations.
|
|
159
166
|
*
|
|
160
167
|
* @example
|
|
@@ -171,7 +178,9 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
171
178
|
* }
|
|
172
179
|
*/
|
|
173
180
|
AmplitudeCore.prototype.getOperationAppliedUserProperties = function (userProperties) {
|
|
174
|
-
var
|
|
181
|
+
var _a;
|
|
182
|
+
var base = (_a = this.userProperties) !== null && _a !== void 0 ? _a : {};
|
|
183
|
+
var updatedProperties = __assign({}, base);
|
|
175
184
|
if (userProperties === undefined) {
|
|
176
185
|
return updatedProperties;
|
|
177
186
|
}
|
|
@@ -217,7 +226,7 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
217
226
|
};
|
|
218
227
|
AmplitudeCore.prototype.process = function (event) {
|
|
219
228
|
return __awaiter(this, void 0, void 0, function () {
|
|
220
|
-
var
|
|
229
|
+
var result, e_2, message, result;
|
|
221
230
|
return __generator(this, function (_a) {
|
|
222
231
|
switch (_a.label) {
|
|
223
232
|
case 0:
|
|
@@ -227,8 +236,9 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
227
236
|
return [2 /*return*/, buildResult(event, 0, OPT_OUT_MESSAGE)];
|
|
228
237
|
}
|
|
229
238
|
if (event.event_type === SpecialEventType.IDENTIFY) {
|
|
230
|
-
|
|
231
|
-
|
|
239
|
+
// Do not update this.userProperties here.
|
|
240
|
+
// It is only set synchronously in identify() or setIdentity()
|
|
241
|
+
this.timeline.onIdentityChanged({ userProperties: this.userProperties });
|
|
232
242
|
}
|
|
233
243
|
return [4 /*yield*/, this.timeline.push(event)];
|
|
234
244
|
case 1:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";AAIA,OAAO,EAEL,iBAAiB,EAEjB,gBAAgB,GAEjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAa,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAElE,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD;IAaE,uBAAY,IAAiB;QAAjB,qBAAA,EAAA,iBAAiB;QAZnB,iBAAY,GAAG,KAAK,CAAC;QAQ/B,YAAO,GAAG,KAAK,CAAC;QACN,MAAC,GAAmD,EAAE,CAAC;QACvD,cAAS,GAA4B,EAAE,CAAC;QAwClD,aAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QArC/B,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEe,6BAAK,GAArB,UAAsB,MAAe;;;;;wBACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;wBACrB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;wBAC1B,IAAI,CAAC,QAAQ,CAAC,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;wBAC1D,qBAAM,IAAI,CAAC,kBAAk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,CAAC,CAAC;YACzD,OAAO;SACR;QACD,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED,kCAAU,GAAV,UAAW,MAAe;QACxB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,MAAM,EAAE;YACjC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;YACrC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;SACvC;IACH,CAAC;IAED,6BAAK,GAAL;QACE,OAAO,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,8BAAM,GAAN,UAAO,IAAY;QACjB,IAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,IAAI,KAAK,IAAI,EAApB,CAAoB,CAAC,CAAC;QAC5E,IAAI,MAAM,KAAK,SAAS,EAAE;YACxB,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,uCAAgC,IAAI,CAAE,CAAC,CAAC;YACzE,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,+BAAO,GAAP,UAA0B,WAAwC;QAChE,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,YAAY,WAAW,EAA7B,CAA6B,CAAQ,CAAC;IACxF,CAAC;IACH,oBAAC;AAAD,CAAC,AA/PD,IA+PC","sourcesContent":["import { Plugin } from './types/plugin';\nimport { IConfig } from './types/config/core-config';\nimport { BaseEvent, EventOptions } from './types/event/base-event';\nimport { Result } from './types/result';\nimport {\n Event,\n IdentifyOperation,\n IdentifyUserProperties,\n SpecialEventType,\n UserProperties,\n} from './types/event/event';\nimport { IIdentify, OrderedIdentifyOperations } from './identify';\nimport { IRevenue } from './revenue';\nimport { CLIENT_NOT_INITIALIZED, OPT_OUT_MESSAGE } from './types/messages';\nimport { Timeline } from './timeline';\nimport {\n createGroupEvent,\n createGroupIdentifyEvent,\n createIdentifyEvent,\n createRevenueEvent,\n createTrackEvent,\n} from './utils/event-builder';\nimport { buildResult } from './utils/result-builder';\nimport { returnWrapper } from './utils/return-wrapper';\nimport { CoreClient, PluginHost } from './types/client/core-client';\nexport class AmplitudeCore implements CoreClient, PluginHost {\n protected initializing = false;\n protected name: string;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: IConfig;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n timeline: Timeline;\n isReady = false;\n protected q: Array<CallableFunction | typeof returnWrapper> = [];\n protected dispatchQ: Array<CallableFunction> = [];\n\n constructor(name = '$default') {\n this.timeline = new Timeline(this);\n this.name = name;\n }\n\n protected async _init(config: IConfig) {\n this.config = config;\n this.timeline.reset(this);\n this.timeline.loggerProvider = this.config.loggerProvider;\n await this.runQueuedFunctions('q');\n this.isReady = true;\n }\n\n async runQueuedFunctions(queueName: 'q' | 'dispatchQ') {\n const queuedFunctions = this[queueName];\n this[queueName] = [];\n for (const queuedFunction of queuedFunctions) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const val: ReturnType<typeof returnWrapper> | Promise<any> = queuedFunction();\n if (val && 'promise' in val) {\n await val.promise;\n } else {\n await val;\n }\n }\n // Rerun queued functions if the queue has accrued more while awaiting promises\n if (this[queueName].length) {\n await this.runQueuedFunctions(queueName);\n }\n }\n\n track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions) {\n const event = createTrackEvent(eventInput, eventProperties, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n logEvent = this.track.bind(this);\n\n identify(identify: IIdentify, eventOptions?: EventOptions) {\n const event = createIdentifyEvent(identify, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions) {\n const event = createGroupIdentifyEvent(groupType, groupName, identify, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions) {\n const event = createGroupEvent(groupType, groupName, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n revenue(revenue: IRevenue, eventOptions?: EventOptions) {\n const event = createRevenueEvent(revenue, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n add(plugin: Plugin) {\n if (!this.isReady) {\n this.q.push(this._addPlugin.bind(this, plugin));\n return returnWrapper();\n }\n return this._addPlugin(plugin);\n }\n\n _addPlugin(plugin: Plugin) {\n return returnWrapper(this.timeline.register(plugin, this.config));\n }\n\n remove(pluginName: string) {\n if (!this.isReady) {\n this.q.push(this._removePlugin.bind(this, pluginName));\n return returnWrapper();\n }\n return this._removePlugin(pluginName);\n }\n\n _removePlugin(pluginName: string) {\n return returnWrapper(this.timeline.deregister(pluginName, this.config));\n }\n\n dispatchWithCallback(event: Event, callback: (result: Result) => void): void {\n if (!this.isReady) {\n return callback(buildResult(event, 0, CLIENT_NOT_INITIALIZED));\n }\n void this.process(event).then(callback);\n }\n\n async dispatch(event: Event): Promise<Result> {\n if (!this.isReady) {\n return new Promise<Result>((resolve) => {\n this.dispatchQ.push(this.dispatchWithCallback.bind(this, event, resolve));\n });\n }\n\n return this.process(event);\n }\n\n /**\n *\n * This method applies identify operations to user properties and\n * returns a single object representing the final user property state.\n *\n * This is a best-effort api that only supports $set, $clearAll, and $unset.\n * Other operations are not supported and are ignored.\n *\n *\n * @param userProperties The `event.userProperties` object from an Identify event.\n * @returns A key-value object user properties without operations.\n *\n * @example\n * Input:\n * {\n * $set: { plan: 'premium' },\n * custom_flag: true\n * }\n *\n * Output:\n * {\n * plan: 'premium',\n * custom_flag: true\n * }\n */\n getOperationAppliedUserProperties(userProperties: UserProperties | undefined): { [key: string]: any } {\n const updatedProperties: { [key: string]: any } = {};\n\n if (userProperties === undefined) {\n return updatedProperties;\n }\n\n // Keep non-operation keys for later merge\n const nonOpProperties: {\n [key in Exclude<string, IdentifyOperation>]: any;\n } = {};\n Object.keys(userProperties).forEach((key) => {\n if (!Object.values(IdentifyOperation).includes(key as IdentifyOperation)) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n nonOpProperties[key] = userProperties[key];\n }\n });\n\n OrderedIdentifyOperations.forEach((operation) => {\n // Skip when key is an operation.\n if (!Object.keys(userProperties).includes(operation)) return;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const opProperties: IdentifyUserProperties = userProperties[operation];\n\n switch (operation) {\n case IdentifyOperation.CLEAR_ALL:\n // Due to operation order, the following line will never execute.\n /* istanbul ignore next */\n Object.keys(updatedProperties).forEach((prop) => {\n delete updatedProperties[prop];\n });\n break;\n case IdentifyOperation.UNSET:\n Object.keys(opProperties).forEach((prop) => {\n delete updatedProperties[prop];\n });\n break;\n case IdentifyOperation.SET:\n Object.assign(updatedProperties, opProperties);\n break;\n }\n });\n\n // Merge non-operation properties.\n // Custom properties should not be affected by operations.\n // https://github.com/amplitude/nova/blob/343f678ded83c032e83b189796b3c2be161b48f5/src/main/java/com/amplitude/userproperty/model/ModifyUserPropertiesIdent.java#L79-L83\n Object.assign(updatedProperties, nonOpProperties);\n\n return updatedProperties;\n }\n\n async process(event: Event): Promise<Result> {\n try {\n // skip event processing if opt out\n if (this.config.optOut) {\n return buildResult(event, 0, OPT_OUT_MESSAGE);\n }\n\n if (event.event_type === SpecialEventType.IDENTIFY) {\n const userProperties = this.getOperationAppliedUserProperties(event.user_properties);\n this.timeline.onIdentityChanged({ userProperties: userProperties });\n }\n\n const result = await this.timeline.push(event);\n\n result.code === 200\n ? this.config.loggerProvider.log(result.message)\n : result.code === 100\n ? this.config.loggerProvider.warn(result.message)\n : this.config.loggerProvider.error(result.message);\n\n return result;\n } catch (e) {\n const message = String(e);\n this.config.loggerProvider.error(message);\n const result = buildResult(event, 0, message);\n\n return result;\n }\n }\n\n setOptOut(optOut: boolean) {\n if (!this.isReady) {\n this.q.push(this._setOptOut.bind(this, Boolean(optOut)));\n return;\n }\n this._setOptOut(optOut);\n }\n\n _setOptOut(optOut: boolean) {\n if (this.config.optOut !== optOut) {\n this.config.optOut = Boolean(optOut);\n this.timeline.onOptOutChanged(optOut);\n }\n }\n\n flush() {\n return returnWrapper(this.timeline.flush());\n }\n\n plugin(name: string): Plugin | undefined {\n const plugin = this.timeline.plugins.find((plugin) => plugin.name === name);\n if (plugin === undefined) {\n this.config.loggerProvider.debug(`Cannot find plugin with name ${name}`);\n return undefined;\n }\n\n return plugin;\n }\n\n plugins<T extends Plugin>(pluginClass: { new (...args: any[]): T }): T[] {\n return this.timeline.plugins.filter((plugin) => plugin instanceof pluginClass) as T[];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";AAIA,OAAO,EAEL,iBAAiB,EAEjB,gBAAgB,GAEjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAa,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAElE,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD;IAmBE,uBAAY,IAAiB;QAAjB,qBAAA,EAAA,iBAAiB;QAlBnB,iBAAY,GAAG,KA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SACvC;IACH,CAAC;IAED,6BAAK,GAAL;QACE,OAAO,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,8BAAM,GAAN,UAAO,IAAY;QACjB,IAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,IAAI,KAAK,IAAI,EAApB,CAAoB,CAAC,CAAC;QAC5E,IAAI,MAAM,KAAK,SAAS,EAAE;YACxB,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,uCAAgC,IAAI,CAAE,CAAC,CAAC;YACzE,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,+BAAO,GAAP,UAA0B,WAAwC;QAChE,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,YAAY,WAAW,EAA7B,CAA6B,CAAQ,CAAC;IACxF,CAAC;IACH,oBAAC;AAAD,CAAC,AA9QD,IA8QC","sourcesContent":["import { Plugin } from './types/plugin';\nimport { IConfig } from './types/config/core-config';\nimport { BaseEvent, EventOptions } from './types/event/base-event';\nimport { Result } from './types/result';\nimport {\n Event,\n IdentifyOperation,\n IdentifyUserProperties,\n SpecialEventType,\n UserProperties,\n} from './types/event/event';\nimport { IIdentify, OrderedIdentifyOperations } from './identify';\nimport { IRevenue } from './revenue';\nimport { CLIENT_NOT_INITIALIZED, OPT_OUT_MESSAGE } from './types/messages';\nimport { Timeline } from './timeline';\nimport {\n createGroupEvent,\n createGroupIdentifyEvent,\n createIdentifyEvent,\n createRevenueEvent,\n createTrackEvent,\n} from './utils/event-builder';\nimport { buildResult } from './utils/result-builder';\nimport { returnWrapper } from './utils/return-wrapper';\nimport { CoreClient, PluginHost } from './types/client/core-client';\nexport class AmplitudeCore implements CoreClient, PluginHost {\n protected initializing = false;\n protected name: string;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: IConfig;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n timeline: Timeline;\n isReady = false;\n protected q: Array<CallableFunction | typeof returnWrapper> = [];\n protected dispatchQ: Array<CallableFunction> = [];\n\n /**\n * Current user properties (operation-applied, flat key-value).\n * Only used by client-side SDKs; server SDKs may leave this undefined.\n */\n userProperties: { [key: string]: any } | undefined;\n\n constructor(name = '$default') {\n this.timeline = new Timeline(this);\n this.name = name;\n }\n\n protected async _init(config: IConfig) {\n this.config = config;\n this.timeline.reset(this);\n this.timeline.loggerProvider = this.config.loggerProvider;\n await this.runQueuedFunctions('q');\n this.isReady = true;\n }\n\n async runQueuedFunctions(queueName: 'q' | 'dispatchQ') {\n const queuedFunctions = this[queueName];\n this[queueName] = [];\n for (const queuedFunction of queuedFunctions) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const val: ReturnType<typeof returnWrapper> | Promise<any> = queuedFunction();\n if (val && 'promise' in val) {\n await val.promise;\n } else {\n await val;\n }\n }\n // Rerun queued functions if the queue has accrued more while awaiting promises\n if (this[queueName].length) {\n await this.runQueuedFunctions(queueName);\n }\n }\n\n track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions) {\n const event = createTrackEvent(eventInput, eventProperties, eventOptions);\n // Update client user properties immediately and synchronously\n this.userProperties = this.getOperationAppliedUserProperties(event.user_properties);\n return returnWrapper(this.dispatch(event));\n }\n\n logEvent = this.track.bind(this);\n\n identify(identify: IIdentify, eventOptions?: EventOptions) {\n const event = createIdentifyEvent(identify, eventOptions);\n // Update client user properties immediately and synchronously\n this.userProperties = this.getOperationAppliedUserProperties(event.user_properties);\n return returnWrapper(this.dispatch(event));\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions) {\n const event = createGroupIdentifyEvent(groupType, groupName, identify, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions) {\n const event = createGroupEvent(groupType, groupName, eventOptions);\n // Update client user properties immediately and synchronously\n this.userProperties = this.getOperationAppliedUserProperties(event.user_properties);\n return returnWrapper(this.dispatch(event));\n }\n\n revenue(revenue: IRevenue, eventOptions?: EventOptions) {\n const event = createRevenueEvent(revenue, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n add(plugin: Plugin) {\n if (!this.isReady) {\n this.q.push(this._addPlugin.bind(this, plugin));\n return returnWrapper();\n }\n return this._addPlugin(plugin);\n }\n\n _addPlugin(plugin: Plugin) {\n return returnWrapper(this.timeline.register(plugin, this.config));\n }\n\n remove(pluginName: string) {\n if (!this.isReady) {\n this.q.push(this._removePlugin.bind(this, pluginName));\n return returnWrapper();\n }\n return this._removePlugin(pluginName);\n }\n\n _removePlugin(pluginName: string) {\n return returnWrapper(this.timeline.deregister(pluginName, this.config));\n }\n\n dispatchWithCallback(event: Event, callback: (result: Result) => void): void {\n if (!this.isReady) {\n return callback(buildResult(event, 0, CLIENT_NOT_INITIALIZED));\n }\n void this.process(event).then(callback);\n }\n\n async dispatch(event: Event): Promise<Result> {\n if (!this.isReady) {\n return new Promise<Result>((resolve) => {\n this.dispatchQ.push(this.dispatchWithCallback.bind(this, event, resolve));\n });\n }\n\n return this.process(event);\n }\n\n /**\n *\n * This method applies identify operations to user properties and\n * returns a single object representing the final user property state.\n *\n * This is a best-effort api that only supports $set, $clearAll, and $unset.\n * Other operations are not supported and are ignored.\n *\n * Operations are applied on top of current client state (this.userProperties).\n *\n * @param userProperties The new user properties object from identify() or setIdentity().\n * @returns A key-value object user properties without operations.\n *\n * @example\n * Input:\n * {\n * $set: { plan: 'premium' },\n * custom_flag: true\n * }\n *\n * Output:\n * {\n * plan: 'premium',\n * custom_flag: true\n * }\n */\n getOperationAppliedUserProperties(userProperties: UserProperties | undefined): { [key: string]: any } {\n const base = this.userProperties ?? {};\n const updatedProperties: { [key: string]: any } = { ...base };\n\n if (userProperties === undefined) {\n return updatedProperties;\n }\n\n // Keep non-operation keys for later merge\n const nonOpProperties: {\n [key in Exclude<string, IdentifyOperation>]: any;\n } = {};\n Object.keys(userProperties).forEach((key) => {\n if (!Object.values(IdentifyOperation).includes(key as IdentifyOperation)) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n nonOpProperties[key] = userProperties[key];\n }\n });\n\n OrderedIdentifyOperations.forEach((operation) => {\n // Skip when key is an operation.\n if (!Object.keys(userProperties).includes(operation)) return;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const opProperties: IdentifyUserProperties = userProperties[operation];\n\n switch (operation) {\n case IdentifyOperation.CLEAR_ALL:\n // Due to operation order, the following line will never execute.\n /* istanbul ignore next */\n Object.keys(updatedProperties).forEach((prop) => {\n delete updatedProperties[prop];\n });\n break;\n case IdentifyOperation.UNSET:\n Object.keys(opProperties).forEach((prop) => {\n delete updatedProperties[prop];\n });\n break;\n case IdentifyOperation.SET:\n Object.assign(updatedProperties, opProperties);\n break;\n }\n });\n\n // Merge non-operation properties.\n // Custom properties should not be affected by operations.\n // https://github.com/amplitude/nova/blob/343f678ded83c032e83b189796b3c2be161b48f5/src/main/java/com/amplitude/userproperty/model/ModifyUserPropertiesIdent.java#L79-L83\n Object.assign(updatedProperties, nonOpProperties);\n\n return updatedProperties;\n }\n\n async process(event: Event): Promise<Result> {\n try {\n // skip event processing if opt out\n if (this.config.optOut) {\n return buildResult(event, 0, OPT_OUT_MESSAGE);\n }\n\n if (event.event_type === SpecialEventType.IDENTIFY) {\n // Do not update this.userProperties here.\n // It is only set synchronously in identify() or setIdentity()\n this.timeline.onIdentityChanged({ userProperties: this.userProperties });\n }\n\n const result = await this.timeline.push(event);\n\n result.code === 200\n ? this.config.loggerProvider.log(result.message)\n : result.code === 100\n ? this.config.loggerProvider.warn(result.message)\n : this.config.loggerProvider.error(result.message);\n\n return result;\n } catch (e) {\n const message = String(e);\n this.config.loggerProvider.error(message);\n const result = buildResult(event, 0, message);\n\n return result;\n }\n }\n\n setOptOut(optOut: boolean) {\n if (!this.isReady) {\n this.q.push(this._setOptOut.bind(this, Boolean(optOut)));\n return;\n }\n this._setOptOut(optOut);\n }\n\n _setOptOut(optOut: boolean) {\n if (this.config.optOut !== optOut) {\n this.config.optOut = Boolean(optOut);\n this.timeline.onOptOutChanged(optOut);\n }\n }\n\n flush() {\n return returnWrapper(this.timeline.flush());\n }\n\n plugin(name: string): Plugin | undefined {\n const plugin = this.timeline.plugins.find((plugin) => plugin.name === name);\n if (plugin === undefined) {\n this.config.loggerProvider.debug(`Cannot find plugin with name ${name}`);\n return undefined;\n }\n\n return plugin;\n }\n\n plugins<T extends Plugin>(pluginClass: { new (...args: any[]): T }): T[] {\n return this.timeline.plugins.filter((plugin) => plugin instanceof pluginClass) as T[];\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uncaught-sdk-errors.d.ts","sourceRoot":"","sources":["../../../src/diagnostics/uncaught-sdk-errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAa1D,eAAO,MAAM,UAAU,6BAA6B,CAAC;AACrD,eAAO,MAAM,yBAAyB,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"uncaught-sdk-errors.d.ts","sourceRoot":"","sources":["../../../src/diagnostics/uncaught-sdk-errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAa1D,eAAO,MAAM,UAAU,6BAA6B,CAAC;AACrD,eAAO,MAAM,yBAAyB,uBAAuB,CAAC;AAgC9D,eAAO,MAAM,yBAAyB,aAAc;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,SAOzE,CAAC;AAEF,eAAO,MAAM,uBAAuB,WAAY,kBAAkB,SAmEjE,CAAC"}
|
|
@@ -1,23 +1,40 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
1
|
+
import { __assign, __values } from "tslib";
|
|
2
2
|
import { getGlobalScope } from '../global-scope';
|
|
3
3
|
export var GLOBAL_KEY = '__AMPLITUDE_SCRIPT_URL__';
|
|
4
4
|
export var EVENT_NAME_ERROR_UNCAUGHT = 'sdk.error.uncaught';
|
|
5
|
-
var
|
|
5
|
+
var getNormalizedScriptUrls = function () {
|
|
6
6
|
var scope = getGlobalScope();
|
|
7
7
|
/* istanbul ignore next */
|
|
8
|
-
|
|
8
|
+
if (!scope) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
var value = scope[GLOBAL_KEY];
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
/* istanbul ignore next - legacy single URL stored as string */
|
|
16
|
+
if (typeof value === 'string') {
|
|
17
|
+
return [value];
|
|
18
|
+
}
|
|
19
|
+
return [];
|
|
9
20
|
};
|
|
10
|
-
var
|
|
21
|
+
var addNormalizedScriptUrl = function (url) {
|
|
11
22
|
var scope = getGlobalScope();
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
/* istanbul ignore next */
|
|
24
|
+
if (!scope) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
var urls = getNormalizedScriptUrls();
|
|
28
|
+
if (!urls.includes(url)) {
|
|
29
|
+
urls.push(url);
|
|
30
|
+
scope[GLOBAL_KEY] = urls;
|
|
14
31
|
}
|
|
15
32
|
};
|
|
16
33
|
export var registerSdkLoaderMetadata = function (metadata) {
|
|
17
34
|
if (metadata.scriptUrl) {
|
|
18
35
|
var normalized = normalizeUrl(metadata.scriptUrl);
|
|
19
36
|
if (normalized) {
|
|
20
|
-
|
|
37
|
+
addNormalizedScriptUrl(normalized);
|
|
21
38
|
}
|
|
22
39
|
}
|
|
23
40
|
};
|
|
@@ -76,15 +93,28 @@ export var enableSdkErrorListeners = function (client) {
|
|
|
76
93
|
scope.addEventListener('unhandledrejection', handleRejection, true);
|
|
77
94
|
};
|
|
78
95
|
var detectSdkOrigin = function (payload) {
|
|
79
|
-
var
|
|
80
|
-
|
|
96
|
+
var e_1, _a;
|
|
97
|
+
var normalizedScriptUrls = getNormalizedScriptUrls();
|
|
98
|
+
if (normalizedScriptUrls.length === 0) {
|
|
81
99
|
return undefined;
|
|
82
100
|
}
|
|
83
|
-
|
|
84
|
-
|
|
101
|
+
try {
|
|
102
|
+
for (var normalizedScriptUrls_1 = __values(normalizedScriptUrls), normalizedScriptUrls_1_1 = normalizedScriptUrls_1.next(); !normalizedScriptUrls_1_1.done; normalizedScriptUrls_1_1 = normalizedScriptUrls_1.next()) {
|
|
103
|
+
var normalizedScriptUrl = normalizedScriptUrls_1_1.value;
|
|
104
|
+
if (payload.filename && payload.filename.includes(normalizedScriptUrl)) {
|
|
105
|
+
return 'filename';
|
|
106
|
+
}
|
|
107
|
+
if (payload.stack && payload.stack.includes(normalizedScriptUrl)) {
|
|
108
|
+
return 'stack';
|
|
109
|
+
}
|
|
110
|
+
}
|
|
85
111
|
}
|
|
86
|
-
|
|
87
|
-
|
|
112
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
113
|
+
finally {
|
|
114
|
+
try {
|
|
115
|
+
if (normalizedScriptUrls_1_1 && !normalizedScriptUrls_1_1.done && (_a = normalizedScriptUrls_1.return)) _a.call(normalizedScriptUrls_1);
|
|
116
|
+
}
|
|
117
|
+
finally { if (e_1) throw e_1.error; }
|
|
88
118
|
}
|
|
89
119
|
return undefined;
|
|
90
120
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uncaught-sdk-errors.js","sourceRoot":"","sources":["../../../src/diagnostics/uncaught-sdk-errors.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAcjD,M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AAE;QAC9B,OAAO,MAAM,CAAC;KACf;IAED,IAAI;QACF,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;KAC/B;IAAC,WAAM;QACN,OAAO,iBAAiB,CAAC;KAC1B;AACH,CAAC,CAAC","sourcesContent":["import { getGlobalScope } from '../global-scope';\nimport { IDiagnosticsClient } from './diagnostics-client';\n\ntype ErrorEventType = 'error' | 'unhandledrejection';\n\ninterface CapturedErrorContext {\n readonly type: ErrorEventType;\n readonly message: string;\n readonly stack?: string;\n readonly filename?: string;\n readonly errorName?: string;\n readonly metadata?: Record<string, unknown>;\n}\n\nexport const GLOBAL_KEY = '__AMPLITUDE_SCRIPT_URL__';\nexport const EVENT_NAME_ERROR_UNCAUGHT = 'sdk.error.uncaught';\n\nconst getNormalizedScriptUrls = (): string[] => {\n const scope = getGlobalScope() as Record<string, unknown> | null;\n /* istanbul ignore next */\n if (!scope) {\n return [];\n }\n const value = scope[GLOBAL_KEY];\n if (Array.isArray(value)) {\n return value as string[];\n }\n /* istanbul ignore next - legacy single URL stored as string */\n if (typeof value === 'string') {\n return [value];\n }\n return [];\n};\n\nconst addNormalizedScriptUrl = (url: string) => {\n const scope = getGlobalScope() as Record<string, unknown> | null;\n /* istanbul ignore next */\n if (!scope) {\n return;\n }\n const urls = getNormalizedScriptUrls();\n if (!urls.includes(url)) {\n urls.push(url);\n scope[GLOBAL_KEY] = urls;\n }\n};\n\nexport const registerSdkLoaderMetadata = (metadata: { scriptUrl?: string }) => {\n if (metadata.scriptUrl) {\n const normalized = normalizeUrl(metadata.scriptUrl);\n if (normalized) {\n addNormalizedScriptUrl(normalized);\n }\n }\n};\n\nexport const enableSdkErrorListeners = (client: IDiagnosticsClient) => {\n const scope = getGlobalScope();\n\n if (!scope || typeof scope.addEventListener !== 'function') {\n return;\n }\n\n const handleError = (event: ErrorEvent) => {\n const error = event.error instanceof Error ? event.error : undefined;\n const stack = error?.stack;\n const match = detectSdkOrigin({ filename: event.filename, stack });\n if (!match) {\n return;\n }\n\n capture({\n type: 'error',\n message: event.message,\n stack,\n filename: event.filename,\n errorName: error?.name,\n metadata: {\n colno: event.colno,\n lineno: event.lineno,\n isTrusted: event.isTrusted,\n matchReason: match,\n },\n });\n };\n\n const handleRejection = (event: PromiseRejectionEvent) => {\n const error = event.reason instanceof Error ? event.reason : undefined;\n const stack = error?.stack;\n const filename = extractFilenameFromStack(stack);\n const match = detectSdkOrigin({ filename, stack });\n\n if (!match) {\n return;\n }\n\n /* istanbul ignore next */\n capture({\n type: 'unhandledrejection',\n message: error?.message ?? stringifyReason(event.reason),\n stack,\n filename,\n errorName: error?.name,\n metadata: {\n isTrusted: event.isTrusted,\n matchReason: match,\n },\n });\n };\n\n const capture = (context: CapturedErrorContext) => {\n client.recordEvent(EVENT_NAME_ERROR_UNCAUGHT, {\n type: context.type,\n message: context.message,\n filename: context.filename,\n error_name: context.errorName,\n stack: context.stack,\n ...context.metadata,\n });\n };\n\n scope.addEventListener('error', handleError, true);\n scope.addEventListener('unhandledrejection', handleRejection, true);\n};\n\nconst detectSdkOrigin = (payload: { filename?: string; stack?: string }): 'filename' | 'stack' | undefined => {\n const normalizedScriptUrls = getNormalizedScriptUrls();\n if (normalizedScriptUrls.length === 0) {\n return undefined;\n }\n\n for (const normalizedScriptUrl of normalizedScriptUrls) {\n if (payload.filename && payload.filename.includes(normalizedScriptUrl)) {\n return 'filename';\n }\n if (payload.stack && payload.stack.includes(normalizedScriptUrl)) {\n return 'stack';\n }\n }\n\n return undefined;\n};\n\nconst normalizeUrl = (value: string) => {\n try {\n /* istanbul ignore next */\n const url = new URL(value, getGlobalScope()?.location?.origin);\n return url.origin + url.pathname;\n } catch {\n return undefined;\n }\n};\n\nconst extractFilenameFromStack = (stack?: string) => {\n if (!stack) {\n return undefined;\n }\n\n const match = stack.match(/(https?:\\/\\/\\S+?)(?=[)\\s]|$)/);\n /* istanbul ignore next */\n return match ? match[1] : undefined;\n};\n\n/* istanbul ignore next */\nconst stringifyReason = (reason: unknown) => {\n if (typeof reason === 'string') {\n return reason;\n }\n\n try {\n return JSON.stringify(reason);\n } catch {\n return '[object Object]';\n }\n};\n"]}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -68,4 +68,9 @@ export { ReactNativeConfig, ReactNativeTrackingOptions, ReactNativeOptions, Reac
|
|
|
68
68
|
export { ReactNativeClient } from './types/client/react-native-client';
|
|
69
69
|
export { Observable, asyncMap, merge, multicast, Unsubscribable } from './utils/observable';
|
|
70
70
|
export { InstanceProxy } from './types/proxy';
|
|
71
|
+
export { safeJsonStringify } from './utils/safe-stringify';
|
|
72
|
+
export type { BaseWindowMessenger, ActionHandler } from './messenger/base-window-messenger';
|
|
73
|
+
export { getOrCreateWindowMessenger } from './messenger/base-window-messenger';
|
|
74
|
+
export { enableBackgroundCapture } from './messenger/background-capture';
|
|
75
|
+
export { AMPLITUDE_ORIGIN, AMPLITUDE_ORIGIN_EU, AMPLITUDE_ORIGIN_STAGING, AMPLITUDE_ORIGINS_MAP, AMPLITUDE_BACKGROUND_CAPTURE_SCRIPT_URL, } from './messenger/constants';
|
|
71
76
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,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R,SAAS,EACT,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAG9D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAGrE,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,kBAAkB,EAClB,6BAA6B,GAC9B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE5F,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAC5F,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EACrB,uCAAuC,GACxC,MAAM,uBAAuB,CAAC"}
|
package/lib/esm/index.js
CHANGED
|
@@ -42,4 +42,8 @@ export { EMPTY_VALUE, BASE_CAMPAIGN, MKTG } from './types/constants';
|
|
|
42
42
|
export { CampaignParser } from './campaign/campaign-parser';
|
|
43
43
|
export { getPageTitle, TEXT_MASK_ATTRIBUTE, MASKED_TEXT_VALUE, replaceSensitiveString, CC_REGEX, SSN_REGEX, EMAIL_REGEX, } from './plugins/helpers';
|
|
44
44
|
export { Observable, asyncMap, merge, multicast } from './utils/observable';
|
|
45
|
+
export { safeJsonStringify } from './utils/safe-stringify';
|
|
46
|
+
export { getOrCreateWindowMessenger } from './messenger/base-window-messenger';
|
|
47
|
+
export { enableBackgroundCapture } from './messenger/background-capture';
|
|
48
|
+
export { AMPLITUDE_ORIGIN, AMPLITUDE_ORIGIN_EU, AMPLITUDE_ORIGIN_STAGING, AMPLITUDE_ORIGINS_MAP, AMPLITUDE_BACKGROUND_CAPTURE_SCRIPT_URL, } from './messenger/constants';
|
|
45
49
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI9C,OAAO,EAAE,QAAQ,EAAgC,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,OAAO,EAAY,eAAe,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAsB,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACxG,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,O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,EAC7B,8BAA8B,GAI/B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAEL,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,EAC7B,4BAA4B,EAC5B,4BAA4B,EAC5B,0CAA0C,EAC1C,4BAA4B,GAC7B,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAqD,MAAM,yBAAyB,CAAC;AAEjH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAMpE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,sBAAsB,EACtB,QAAQ,EACR,SAAS,EACT,WAAW,GACZ,MAAM,mBAAmB,CAAC;AA4B3B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAkB,MAAM,oBAAoB,CAAC","sourcesContent":["export { AmplitudeCore } from './core-client';\nexport { CoreClient, PluginHost } from './types/client/core-client';\nexport { AnalyticsClient } from './types/client/analytics-client';\nexport { AmplitudeContext } from './types/amplitude-context';\nexport { Identify, IIdentify, ValidPropertyType } from './identify';\nexport { Revenue, IRevenue, RevenueProperty } from './revenue';\nexport { Destination } from './plugins/destination';\nexport { IdentityEventSender } from './plugins/identity';\nexport { Config, RequestMetadata } from './config';\nexport { IConfig } from './types/config/core-config';\nexport { Logger, ILogger, LogConfig } 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';\nexport { isUrlMatchAllowlist, getDecodeURI } from './utils/url-utils';\nexport { generateHashCode, isTimestampInSample } from './utils/sampling';\n\nexport { MemoryStorage } from './storage/memory';\nexport { CookieStorage, isDomainEqual, decodeCookieValue } from './storage/cookie';\nexport { getStorageKey } from './storage/helpers';\n\nexport { BrowserStorage } from './storage/browser-storage';\n\nexport { DiagnosticsClient, IDiagnosticsClient } from './diagnostics/diagnostics-client';\nexport { registerSdkLoaderMetadata } from './diagnostics/uncaught-sdk-errors';\n\nexport { BaseTransport } from './transports/base';\nexport { FetchTransport } from './transports/fetch';\n\nexport { RemoteConfigClient, IRemoteConfigClient, RemoteConfig, Source } from './remote-config/remote-config';\n\nexport { LogLevel } from './types/loglevel';\nexport { AMPLITUDE_PREFIX, STORAGE_PREFIX } from './types/constants';\nexport { Storage, IdentityStorageType, CookieStorageConfig } from './types/storage';\nexport { consoleObserver } from './observers/console';\nexport {\n Event,\n IdentifyOperation,\n SpecialEventType,\n IdentifyEvent,\n GroupIdentifyEvent,\n IdentifyUserProperties,\n} 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, TransportOptions, TransportTypeOrOptions } from './types/transport';\nexport { Payload } from './types/payload';\nexport { Response } from './types/response';\nexport { UserSession } from './types/user-session';\nexport {\n Plugin,\n BeforePlugin,\n DestinationPlugin,\n EnrichmentPlugin,\n PluginType,\n AnalyticsIdentity,\n} 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 LabeledEvent,\n Trigger,\n DataSource,\n} from './types/element-interactions';\n\nexport {\n FrustrationInteractionsOptions,\n DEFAULT_DEAD_CLICK_ALLOWLIST,\n DEFAULT_RAGE_CLICK_ALLOWLIST,\n DEFAULT_ERROR_CLICK_ALLOWLIST,\n DEFAULT_RAGE_CLICK_THRESHOLD,\n DEFAULT_RAGE_CLICK_WINDOW_MS,\n DEFAULT_RAGE_CLICK_OUT_OF_BOUNDS_THRESHOLD,\n DEFAULT_DEAD_CLICK_WINDOW_MS,\n} from './types/frustration-interactions';\nexport { PageTrackingOptions, PageTrackingTrackOn, PageTrackingHistoryChanges } from './types/page-view-tracking';\nexport { FormInteractionsOptions } from './types/form-interactions';\nexport { Status } from './types/status';\n\nexport { NetworkEventCallback, networkObserver } from './observers/network';\nexport { NetworkRequestEvent, IRequestWrapper, JsonObject, JsonValue, JsonArray } from './network-request-event';\nexport { NetworkTrackingOptions, NetworkCaptureRule } from './types/network-tracking';\nexport { SAFE_HEADERS, FORBIDDEN_HEADERS } from './types/constants';\n\nexport { PageUrlEnrichmentOptions } from './types/page-url-enrichment';\n\n// Campaign\nexport { Campaign, UTMParameters, ReferrerParameters, ClickIdParameters, ICampaignParser } from './types/campaign';\nexport { EMPTY_VALUE, BASE_CAMPAIGN, MKTG } from './types/constants';\nexport { CampaignParser } from './campaign/campaign-parser';\nexport {\n getPageTitle,\n TEXT_MASK_ATTRIBUTE,\n MASKED_TEXT_VALUE,\n replaceSensitiveString,\n CC_REGEX,\n SSN_REGEX,\n EMAIL_REGEX,\n} from './plugins/helpers';\n\n// Browser\nexport {\n BrowserConfig,\n BrowserOptions,\n DefaultTrackingOptions,\n TrackingOptions,\n AutocaptureOptions,\n CookieOptions,\n AttributionOptions,\n RemoteConfigOptions,\n} from './types/config/browser-config';\nexport { BrowserClient } from './types/client/browser-client';\n\n// Node\nexport { NodeClient } from './types/client/node-client';\nexport { NodeConfig, NodeOptions } from './types/config/node-config';\n\n// React Native\nexport {\n ReactNativeConfig,\n ReactNativeTrackingOptions,\n ReactNativeOptions,\n ReactNativeAttributionOptions,\n} from './types/config/react-native-config';\nexport { ReactNativeClient } from './types/client/react-native-client';\n\nexport { Observable, asyncMap, merge, multicast, Unsubscribable } from './utils/observable';\n\nexport { InstanceProxy } from './types/proxy';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI9C,OAAO,EAAE,QAAQ,EAAgC,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,OAAO,EAAY,eAAe,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAsB,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACxG,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAmB,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,IAAI,E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AA0C,EAC1C,4BAA4B,GAC7B,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAqD,MAAM,yBAAyB,CAAC;AAEjH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAMpE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,sBAAsB,EACtB,QAAQ,EACR,SAAS,EACT,WAAW,GACZ,MAAM,mBAAmB,CAAC;AA4B3B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAkB,MAAM,oBAAoB,CAAC;AAG5F,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAI3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EACrB,uCAAuC,GACxC,MAAM,uBAAuB,CAAC","sourcesContent":["export { AmplitudeCore } from './core-client';\nexport { CoreClient, PluginHost } from './types/client/core-client';\nexport { AnalyticsClient } from './types/client/analytics-client';\nexport { AmplitudeContext } from './types/amplitude-context';\nexport { Identify, IIdentify, ValidPropertyType } from './identify';\nexport { Revenue, IRevenue, RevenueProperty } from './revenue';\nexport { Destination } from './plugins/destination';\nexport { IdentityEventSender } from './plugins/identity';\nexport { Config, RequestMetadata } from './config';\nexport { IConfig } from './types/config/core-config';\nexport { Logger, ILogger, LogConfig } 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';\nexport { isUrlMatchAllowlist, getDecodeURI } from './utils/url-utils';\nexport { generateHashCode, isTimestampInSample } from './utils/sampling';\n\nexport { MemoryStorage } from './storage/memory';\nexport { CookieStorage, isDomainEqual, decodeCookieValue } from './storage/cookie';\nexport { getStorageKey } from './storage/helpers';\n\nexport { BrowserStorage } from './storage/browser-storage';\n\nexport { DiagnosticsClient, IDiagnosticsClient } from './diagnostics/diagnostics-client';\nexport { registerSdkLoaderMetadata } from './diagnostics/uncaught-sdk-errors';\n\nexport { BaseTransport } from './transports/base';\nexport { FetchTransport } from './transports/fetch';\n\nexport { RemoteConfigClient, IRemoteConfigClient, RemoteConfig, Source } from './remote-config/remote-config';\n\nexport { LogLevel } from './types/loglevel';\nexport { AMPLITUDE_PREFIX, STORAGE_PREFIX } from './types/constants';\nexport { Storage, IdentityStorageType, CookieStorageConfig } from './types/storage';\nexport { consoleObserver } from './observers/console';\nexport {\n Event,\n IdentifyOperation,\n SpecialEventType,\n IdentifyEvent,\n GroupIdentifyEvent,\n IdentifyUserProperties,\n} 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, TransportOptions, TransportTypeOrOptions } from './types/transport';\nexport { Payload } from './types/payload';\nexport { Response } from './types/response';\nexport { UserSession } from './types/user-session';\nexport {\n Plugin,\n BeforePlugin,\n DestinationPlugin,\n EnrichmentPlugin,\n PluginType,\n AnalyticsIdentity,\n} 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 LabeledEvent,\n Trigger,\n DataSource,\n} from './types/element-interactions';\n\nexport {\n FrustrationInteractionsOptions,\n DEFAULT_DEAD_CLICK_ALLOWLIST,\n DEFAULT_RAGE_CLICK_ALLOWLIST,\n DEFAULT_ERROR_CLICK_ALLOWLIST,\n DEFAULT_RAGE_CLICK_THRESHOLD,\n DEFAULT_RAGE_CLICK_WINDOW_MS,\n DEFAULT_RAGE_CLICK_OUT_OF_BOUNDS_THRESHOLD,\n DEFAULT_DEAD_CLICK_WINDOW_MS,\n} from './types/frustration-interactions';\nexport { PageTrackingOptions, PageTrackingTrackOn, PageTrackingHistoryChanges } from './types/page-view-tracking';\nexport { FormInteractionsOptions } from './types/form-interactions';\nexport { Status } from './types/status';\n\nexport { NetworkEventCallback, networkObserver } from './observers/network';\nexport { NetworkRequestEvent, IRequestWrapper, JsonObject, JsonValue, JsonArray } from './network-request-event';\nexport { NetworkTrackingOptions, NetworkCaptureRule } from './types/network-tracking';\nexport { SAFE_HEADERS, FORBIDDEN_HEADERS } from './types/constants';\n\nexport { PageUrlEnrichmentOptions } from './types/page-url-enrichment';\n\n// Campaign\nexport { Campaign, UTMParameters, ReferrerParameters, ClickIdParameters, ICampaignParser } from './types/campaign';\nexport { EMPTY_VALUE, BASE_CAMPAIGN, MKTG } from './types/constants';\nexport { CampaignParser } from './campaign/campaign-parser';\nexport {\n getPageTitle,\n TEXT_MASK_ATTRIBUTE,\n MASKED_TEXT_VALUE,\n replaceSensitiveString,\n CC_REGEX,\n SSN_REGEX,\n EMAIL_REGEX,\n} from './plugins/helpers';\n\n// Browser\nexport {\n BrowserConfig,\n BrowserOptions,\n DefaultTrackingOptions,\n TrackingOptions,\n AutocaptureOptions,\n CookieOptions,\n AttributionOptions,\n RemoteConfigOptions,\n} from './types/config/browser-config';\nexport { BrowserClient } from './types/client/browser-client';\n\n// Node\nexport { NodeClient } from './types/client/node-client';\nexport { NodeConfig, NodeOptions } from './types/config/node-config';\n\n// React Native\nexport {\n ReactNativeConfig,\n ReactNativeTrackingOptions,\n ReactNativeOptions,\n ReactNativeAttributionOptions,\n} from './types/config/react-native-config';\nexport { ReactNativeClient } from './types/client/react-native-client';\n\nexport { Observable, asyncMap, merge, multicast, Unsubscribable } from './utils/observable';\n\nexport { InstanceProxy } from './types/proxy';\nexport { safeJsonStringify } from './utils/safe-stringify';\n\n// Messenger (cross-window communication)\nexport type { BaseWindowMessenger, ActionHandler } from './messenger/base-window-messenger';\nexport { getOrCreateWindowMessenger } from './messenger/base-window-messenger';\nexport { enableBackgroundCapture } from './messenger/background-capture';\nexport {\n AMPLITUDE_ORIGIN,\n AMPLITUDE_ORIGIN_EU,\n AMPLITUDE_ORIGIN_STAGING,\n AMPLITUDE_ORIGINS_MAP,\n AMPLITUDE_BACKGROUND_CAPTURE_SCRIPT_URL,\n} from './messenger/constants';\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BaseWindowMessenger } from './base-window-messenger';
|
|
2
|
+
/**
|
|
3
|
+
* Enable background capture on a messenger instance.
|
|
4
|
+
* Plugins can call this on a shared messenger instance.
|
|
5
|
+
* The first call registers the handlers; subsequent calls are no-ops.
|
|
6
|
+
*
|
|
7
|
+
* @param messenger - The messenger to enable background capture on
|
|
8
|
+
* @param options.scriptUrl - Override the background capture script URL (optional)
|
|
9
|
+
*/
|
|
10
|
+
export declare function enableBackgroundCapture(messenger: BaseWindowMessenger, options?: {
|
|
11
|
+
scriptUrl?: string;
|
|
12
|
+
}): void;
|
|
13
|
+
//# sourceMappingURL=background-capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background-capture.d.ts","sourceRoot":"","sources":["../../../src/messenger/background-capture.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AASnE;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CA6C9G"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { AMPLITUDE_BACKGROUND_CAPTURE_SCRIPT_URL } from './constants';
|
|
2
|
+
/**
|
|
3
|
+
* Brand key set on the messenger instance to track whether background capture
|
|
4
|
+
* has been enabled.
|
|
5
|
+
*/
|
|
6
|
+
var BG_CAPTURE_BRAND = '__AMPLITUDE_BACKGROUND_CAPTURE__';
|
|
7
|
+
/**
|
|
8
|
+
* Enable background capture on a messenger instance.
|
|
9
|
+
* Plugins can call this on a shared messenger instance.
|
|
10
|
+
* The first call registers the handlers; subsequent calls are no-ops.
|
|
11
|
+
*
|
|
12
|
+
* @param messenger - The messenger to enable background capture on
|
|
13
|
+
* @param options.scriptUrl - Override the background capture script URL (optional)
|
|
14
|
+
*/
|
|
15
|
+
export function enableBackgroundCapture(messenger, options) {
|
|
16
|
+
var _a;
|
|
17
|
+
// Check the brand on the messenger object itself — works across bundle boundaries
|
|
18
|
+
var branded = messenger;
|
|
19
|
+
if (branded[BG_CAPTURE_BRAND] === true) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
branded[BG_CAPTURE_BRAND] = true;
|
|
23
|
+
var scriptUrl = (_a = options === null || options === void 0 ? void 0 : options.scriptUrl) !== null && _a !== void 0 ? _a : AMPLITUDE_BACKGROUND_CAPTURE_SCRIPT_URL;
|
|
24
|
+
var backgroundCaptureInstance = null;
|
|
25
|
+
var onBackgroundCapture = function (type, backgroundCaptureData) {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
if (type === 'background-capture-complete') {
|
|
28
|
+
(_b = (_a = messenger.logger) === null || _a === void 0 ? void 0 : _a.debug) === null || _b === void 0 ? void 0 : _b.call(_a, 'Background capture complete');
|
|
29
|
+
messenger.notify({ action: 'background-capture-complete', data: backgroundCaptureData });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
messenger.registerActionHandler('initialize-background-capture', function () {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
(_b = (_a = messenger.logger) === null || _a === void 0 ? void 0 : _a.debug) === null || _b === void 0 ? void 0 : _b.call(_a, 'Initializing background capture (external script)');
|
|
35
|
+
var resolvedUrl = new URL(scriptUrl, messenger.endpoint).toString();
|
|
36
|
+
messenger
|
|
37
|
+
.loadScriptOnce(resolvedUrl)
|
|
38
|
+
.then(function () {
|
|
39
|
+
var _a, _b, _c;
|
|
40
|
+
(_b = (_a = messenger.logger) === null || _a === void 0 ? void 0 : _a.debug) === null || _b === void 0 ? void 0 : _b.call(_a, 'Background capture script loaded (external)');
|
|
41
|
+
// eslint-disable-next-line
|
|
42
|
+
backgroundCaptureInstance = /* istanbul ignore next -- window is always defined in browser */ (_c = window === null || window === void 0 ? void 0 : window.amplitudeBackgroundCapture) === null || _c === void 0 ? void 0 : _c.call(window, {
|
|
43
|
+
messenger: messenger,
|
|
44
|
+
onBackgroundCapture: onBackgroundCapture,
|
|
45
|
+
});
|
|
46
|
+
messenger.notify({ action: 'background-capture-loaded' });
|
|
47
|
+
})
|
|
48
|
+
.catch(function () {
|
|
49
|
+
var _a;
|
|
50
|
+
(_a = messenger.logger) === null || _a === void 0 ? void 0 : _a.warn('Failed to initialize background capture');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
messenger.registerActionHandler('close-background-capture', function () {
|
|
54
|
+
var _a;
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
56
|
+
(_a = backgroundCaptureInstance === null || backgroundCaptureInstance === void 0 ? void 0 : backgroundCaptureInstance.close) === null || _a === void 0 ? void 0 : _a.call(backgroundCaptureInstance);
|
|
57
|
+
backgroundCaptureInstance = null;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=background-capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background-capture.js","sourceRoot":"","sources":["../../../src/messenger/background-capture.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uCAAuC,EAAE,MAAM,aAAa,CAAC;AAEtE;;;GAGG;AACH,IAAM,gBAAgB,GAAG,kCAA2C,CAAC;AAErE;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,SAA8B,EAAE,OAAgC;;IACtG,kFAAkF;IAClF,IAAM,OAAO,GAAG,SAA+C,CAAC;IAChE,IAAI,OAAO,CAAC,gBAAgB,CAAC,KAAK,IAAI,EAAE;QACtC,OAAO;KACR;IACD,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAC;IAEjC,IAAM,SAAS,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,mCAAI,uCAAuC,CAAC;IAChF,IAAI,yBAAyB,GAAQ,IAAI,CAAC;IAE1C,IAAM,mBAAmB,GAAG,UAAC,IAAY,EAAE,qBAAgE;;QACzG,IAAI,IAAI,KAAK,6BAA6B,EAAE;YAC1C,MAAA,MAAA,SAAS,CAAC,MAAM,0CAAE,KAAK,mDAAG,6BAA6B,CAAC,CAAC;YACzD,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,6BAA6B,EAAE,IAAI,EAAE,qBAAqB,EAAE,CAAC,CAAC;SAC1F;IACH,CAAC,CAAC;IAEF,SAAS,CAAC,qBAAqB,CAAC,+BAA+B,EAAE;;QAC/D,MAAA,MAAA,SAAS,CAAC,MAAM,0CAAE,KAAK,mDAAG,mDAAmD,CAAC,CAAC;QAC/E,IAAM,WAAW,GAAG,IAAI,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;QAEtE,SAAS;aACN,cAAc,CAAC,WAAW,CAAC;aAC3B,IAAI,CAAC;;YACJ,MAAA,MAAA,SAAS,CAAC,MAAM,0CAAE,KAAK,mDAAG,6CAA6C,CAAC,CAAC;YACzE,2BAA2B;YAC3B,yBAAyB,GAAG,iEAAiE,CAAC,MAC5F,MACD,aADC,MAAM,uBAAN,MAAM,CACL,0BAA0B,uDAAG;gBAC9B,SAAS,WAAA;gBACT,mBAAmB,qBAAA;aACpB,CAAC,CAAC;YACH,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,2BAA2B,EAAE,CAAC,CAAC;QAC5D,CAAC,CAAC;aACD,KAAK,CAAC;;YACL,MAAA,SAAS,CAAC,MAAM,0CAAE,IAAI,CAAC,yCAAyC,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,qBAAqB,CAAC,0BAA0B,EAAE;;QAC1D,yGAAyG;QACzG,MAAA,yBAAyB,aAAzB,yBAAyB,uBAAzB,yBAAyB,CAAE,KAAK,yEAAI,CAAC;QACrC,yBAAyB,GAAG,IAAI,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/* eslint-disable no-restricted-globals */\nimport type { BaseWindowMessenger } from './base-window-messenger';\nimport { AMPLITUDE_BACKGROUND_CAPTURE_SCRIPT_URL } from './constants';\n\n/**\n * Brand key set on the messenger instance to track whether background capture\n * has been enabled.\n */\nconst BG_CAPTURE_BRAND = '__AMPLITUDE_BACKGROUND_CAPTURE__' as const;\n\n/**\n * Enable background capture on a messenger instance.\n * Plugins can call this on a shared messenger instance.\n * The first call registers the handlers; subsequent calls are no-ops.\n *\n * @param messenger - The messenger to enable background capture on\n * @param options.scriptUrl - Override the background capture script URL (optional)\n */\nexport function enableBackgroundCapture(messenger: BaseWindowMessenger, options?: { scriptUrl?: string }): void {\n // Check the brand on the messenger object itself — works across bundle boundaries\n const branded = messenger as unknown as Record<string, unknown>;\n if (branded[BG_CAPTURE_BRAND] === true) {\n return;\n }\n branded[BG_CAPTURE_BRAND] = true;\n\n const scriptUrl = options?.scriptUrl ?? AMPLITUDE_BACKGROUND_CAPTURE_SCRIPT_URL;\n let backgroundCaptureInstance: any = null;\n\n const onBackgroundCapture = (type: string, backgroundCaptureData: { [key: string]: string | number | null }) => {\n if (type === 'background-capture-complete') {\n messenger.logger?.debug?.('Background capture complete');\n messenger.notify({ action: 'background-capture-complete', data: backgroundCaptureData });\n }\n };\n\n messenger.registerActionHandler('initialize-background-capture', () => {\n messenger.logger?.debug?.('Initializing background capture (external script)');\n const resolvedUrl = new URL(scriptUrl, messenger.endpoint).toString();\n\n messenger\n .loadScriptOnce(resolvedUrl)\n .then(() => {\n messenger.logger?.debug?.('Background capture script loaded (external)');\n // eslint-disable-next-line\n backgroundCaptureInstance = /* istanbul ignore next -- window is always defined in browser */ (\n window as any\n )?.amplitudeBackgroundCapture?.({\n messenger,\n onBackgroundCapture,\n });\n messenger.notify({ action: 'background-capture-loaded' });\n })\n .catch(() => {\n messenger.logger?.warn('Failed to initialize background capture');\n });\n });\n\n messenger.registerActionHandler('close-background-capture', () => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n backgroundCaptureInstance?.close?.();\n backgroundCaptureInstance = null;\n });\n}\n"]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { ILogger } from '../logger';
|
|
2
|
+
import { Messenger } from '../types/element-interactions';
|
|
3
|
+
type MessageRequest = {
|
|
4
|
+
id: string;
|
|
5
|
+
action: string;
|
|
6
|
+
args: Record<string, any>;
|
|
7
|
+
};
|
|
8
|
+
export type ActionHandler = (data: any) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Brand key used to identify BaseWindowMessenger instances across bundle boundaries.
|
|
11
|
+
*/
|
|
12
|
+
declare const MESSENGER_BRAND: "__AMPLITUDE_MESSENGER_INSTANCE__";
|
|
13
|
+
/**
|
|
14
|
+
* BaseWindowMessenger provides generic cross-window communication via postMessage.
|
|
15
|
+
* Singleton access via getOrCreateWindowMessenger() to prevent duplicate instances
|
|
16
|
+
*/
|
|
17
|
+
declare class BaseWindowMessenger implements Messenger {
|
|
18
|
+
/** Brand property for cross-bundle instanceof checks. */
|
|
19
|
+
readonly [MESSENGER_BRAND] = true;
|
|
20
|
+
endpoint: string;
|
|
21
|
+
logger?: ILogger;
|
|
22
|
+
private isSetup;
|
|
23
|
+
private messageHandler;
|
|
24
|
+
requestCallbacks: {
|
|
25
|
+
[id: string]: {
|
|
26
|
+
resolve: (data: any) => void;
|
|
27
|
+
reject: (data: any) => void;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
private actionHandlers;
|
|
31
|
+
/**
|
|
32
|
+
* Messages received for actions that had no registered handler yet.
|
|
33
|
+
* Drained automatically when the corresponding handler is registered via
|
|
34
|
+
* registerActionHandler(), solving startup race conditions between
|
|
35
|
+
* independently-initialized plugins.
|
|
36
|
+
*/
|
|
37
|
+
private pendingMessages;
|
|
38
|
+
/**
|
|
39
|
+
* Tracks in-flight and completed script loads by URL.
|
|
40
|
+
* Using a map, this prevents duplicate loads before the first resolves.
|
|
41
|
+
*/
|
|
42
|
+
private scriptLoadPromises;
|
|
43
|
+
constructor({ origin }?: {
|
|
44
|
+
origin?: string;
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Send a message to the parent window (window.opener).
|
|
48
|
+
*/
|
|
49
|
+
notify(message: {
|
|
50
|
+
action: string;
|
|
51
|
+
data?: any;
|
|
52
|
+
} | MessageRequest): void;
|
|
53
|
+
/**
|
|
54
|
+
* Send an async request to the parent window with a unique ID.
|
|
55
|
+
* Returns a Promise that resolves when the parent responds.
|
|
56
|
+
*/
|
|
57
|
+
sendRequest(action: string, args: Record<string, any>, options?: {
|
|
58
|
+
timeout: number;
|
|
59
|
+
}): Promise<any>;
|
|
60
|
+
/**
|
|
61
|
+
* Handle a response to a previous request by resolving its Promise.
|
|
62
|
+
*/
|
|
63
|
+
private handleResponse;
|
|
64
|
+
/**
|
|
65
|
+
* Register a handler for a specific action type.
|
|
66
|
+
* Logs a warning if overwriting an existing handler.
|
|
67
|
+
*/
|
|
68
|
+
registerActionHandler(action: string, handler: ActionHandler): void;
|
|
69
|
+
/**
|
|
70
|
+
* Load a script once, deduplicating by URL.
|
|
71
|
+
* Safe against concurrent calls — the second call awaits the first's in-flight Promise
|
|
72
|
+
* rather than triggering a duplicate load.
|
|
73
|
+
*/
|
|
74
|
+
loadScriptOnce(url: string): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Set up the message listener. Idempotent — safe to call multiple times.
|
|
77
|
+
* Subclasses should call super.setup() and then register their own action handlers.
|
|
78
|
+
*/
|
|
79
|
+
setup({ logger, endpoint }?: {
|
|
80
|
+
logger?: ILogger;
|
|
81
|
+
endpoint?: string;
|
|
82
|
+
}): void;
|
|
83
|
+
/**
|
|
84
|
+
* Tear down the messenger: remove the message listener, clear all state.
|
|
85
|
+
*/
|
|
86
|
+
destroy(): void;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get or create a singleton BaseWindowMessenger instance.
|
|
90
|
+
* Ensures only one messenger (and one message listener) exists per page,
|
|
91
|
+
* preventing duplicate script loads and double notifications.
|
|
92
|
+
*
|
|
93
|
+
* The singleton is stored on globalScope under the same MESSENGER_KEY.
|
|
94
|
+
* The branded property check verifies the stored value is actually a messenger.
|
|
95
|
+
*/
|
|
96
|
+
export declare function getOrCreateWindowMessenger(options?: {
|
|
97
|
+
origin?: string;
|
|
98
|
+
}): BaseWindowMessenger;
|
|
99
|
+
export type { BaseWindowMessenger };
|
|
100
|
+
//# sourceMappingURL=base-window-messenger.d.ts.map
|