@amplitude/analytics-core 0.9.5 → 0.9.7
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 +12 -8
- package/lib/cjs/core-client.d.ts.map +1 -1
- package/lib/cjs/core-client.js +49 -19
- package/lib/cjs/core-client.js.map +1 -1
- package/lib/cjs/messages.d.ts +1 -0
- package/lib/cjs/messages.d.ts.map +1 -1
- package/lib/cjs/messages.js +2 -1
- package/lib/cjs/messages.js.map +1 -1
- package/lib/cjs/timeline.d.ts +0 -1
- package/lib/cjs/timeline.d.ts.map +1 -1
- package/lib/cjs/timeline.js +1 -3
- package/lib/cjs/timeline.js.map +1 -1
- package/lib/esm/core-client.d.ts +12 -8
- package/lib/esm/core-client.d.ts.map +1 -1
- package/lib/esm/core-client.js +50 -20
- package/lib/esm/core-client.js.map +1 -1
- package/lib/esm/messages.d.ts +1 -0
- package/lib/esm/messages.d.ts.map +1 -1
- package/lib/esm/messages.js +1 -0
- package/lib/esm/messages.js.map +1 -1
- package/lib/esm/timeline.d.ts +0 -1
- package/lib/esm/timeline.d.ts.map +1 -1
- package/lib/esm/timeline.js +1 -3
- package/lib/esm/timeline.js.map +1 -1
- package/package.json +2 -2
package/lib/cjs/core-client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoreClient, Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types';
|
|
1
|
+
import { CoreClient, Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue, Result } from '@amplitude/analytics-types';
|
|
2
2
|
import { Timeline } from './timeline';
|
|
3
3
|
export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
|
|
4
4
|
initializing: boolean;
|
|
@@ -6,17 +6,21 @@ export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
|
|
|
6
6
|
config: T;
|
|
7
7
|
timeline: Timeline;
|
|
8
8
|
protected q: CallableFunction[];
|
|
9
|
+
protected dispatchQ: CallableFunction[];
|
|
9
10
|
constructor(name?: string);
|
|
10
11
|
_init(config: T): Promise<void>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
runQueuedFunctions(queueName: 'q' | 'dispatchQ'): Promise<void>;
|
|
13
|
+
track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): Promise<Result>;
|
|
14
|
+
logEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<Result>;
|
|
15
|
+
identify(identify: Identify, eventOptions?: EventOptions): Promise<Result>;
|
|
16
|
+
groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions): Promise<Result>;
|
|
17
|
+
setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions): Promise<Result>;
|
|
18
|
+
revenue(revenue: Revenue, eventOptions?: EventOptions): Promise<Result>;
|
|
17
19
|
add(plugin: Plugin): Promise<void>;
|
|
18
20
|
remove(pluginName: string): Promise<void>;
|
|
19
|
-
|
|
21
|
+
dispatchWithCallback(event: Event, callback: (result: Result) => void): void;
|
|
22
|
+
dispatch(event: Event): Promise<Result>;
|
|
23
|
+
process(event: Event): Promise<Result>;
|
|
20
24
|
setOptOut(optOut: boolean): void;
|
|
21
25
|
flush(): Promise<void>;
|
|
22
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,MAAM,EACN,KAAK,EACL,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,OAAO,
|
|
1
|
+
{"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,MAAM,EACN,KAAK,EACL,SAAS,EAC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,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAOtE,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAUvC,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAuB5C,SAAS,CAAC,MAAM,EAAE,OAAO;IAQzB,KAAK;CAGN"}
|
package/lib/cjs/core-client.js
CHANGED
|
@@ -10,21 +10,35 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
10
10
|
if (name === void 0) { name = '$default'; }
|
|
11
11
|
this.initializing = false;
|
|
12
12
|
this.q = [];
|
|
13
|
+
this.dispatchQ = [];
|
|
13
14
|
this.logEvent = this.track.bind(this);
|
|
14
15
|
this.timeline = new timeline_1.Timeline();
|
|
15
16
|
this.name = name;
|
|
16
17
|
}
|
|
17
18
|
AmplitudeCore.prototype._init = function (config) {
|
|
19
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
20
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
21
|
+
switch (_a.label) {
|
|
22
|
+
case 0:
|
|
23
|
+
this.config = config;
|
|
24
|
+
this.timeline.reset();
|
|
25
|
+
return [4 /*yield*/, this.runQueuedFunctions('q')];
|
|
26
|
+
case 1:
|
|
27
|
+
_a.sent();
|
|
28
|
+
return [2 /*return*/];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
AmplitudeCore.prototype.runQueuedFunctions = function (queueName) {
|
|
18
34
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
19
35
|
var queuedFunctions, queuedFunctions_1, queuedFunctions_1_1, queuedFunction, e_1_1;
|
|
20
36
|
var e_1, _a;
|
|
21
37
|
return (0, tslib_1.__generator)(this, function (_b) {
|
|
22
38
|
switch (_b.label) {
|
|
23
39
|
case 0:
|
|
24
|
-
|
|
25
|
-
this
|
|
26
|
-
queuedFunctions = this.q;
|
|
27
|
-
this.q = [];
|
|
40
|
+
queuedFunctions = this[queueName];
|
|
41
|
+
this[queueName] = [];
|
|
28
42
|
_b.label = 1;
|
|
29
43
|
case 1:
|
|
30
44
|
_b.trys.push([1, 6, 7, 8]);
|
|
@@ -98,33 +112,49 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
98
112
|
});
|
|
99
113
|
});
|
|
100
114
|
};
|
|
115
|
+
AmplitudeCore.prototype.dispatchWithCallback = function (event, callback) {
|
|
116
|
+
if (!this.config) {
|
|
117
|
+
return callback((0, result_builder_1.buildResult)(event, 0, messages_1.CLIENT_NOT_INITIALIZED));
|
|
118
|
+
}
|
|
119
|
+
void this.process(event).then(callback);
|
|
120
|
+
};
|
|
101
121
|
AmplitudeCore.prototype.dispatch = function (event) {
|
|
102
|
-
var _a;
|
|
103
122
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
104
|
-
var
|
|
105
|
-
return (0, tslib_1.__generator)(this, function (
|
|
106
|
-
|
|
123
|
+
var _this = this;
|
|
124
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
125
|
+
if (!this.config) {
|
|
126
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
127
|
+
_this.dispatchQ.push(_this.dispatchWithCallback.bind(_this, event, resolve));
|
|
128
|
+
})];
|
|
129
|
+
}
|
|
130
|
+
return [2 /*return*/, this.process(event)];
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
AmplitudeCore.prototype.process = function (event) {
|
|
135
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
136
|
+
var result, e_2, message, result;
|
|
137
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
138
|
+
switch (_a.label) {
|
|
107
139
|
case 0:
|
|
108
|
-
|
|
140
|
+
_a.trys.push([0, 2, , 3]);
|
|
109
141
|
// skip event processing if opt out
|
|
110
|
-
if (
|
|
142
|
+
if (this.config.optOut) {
|
|
111
143
|
return [2 /*return*/, (0, result_builder_1.buildResult)(event, 0, messages_1.OPT_OUT_MESSAGE)];
|
|
112
144
|
}
|
|
113
145
|
return [4 /*yield*/, this.timeline.push(event)];
|
|
114
146
|
case 1:
|
|
115
|
-
result =
|
|
116
|
-
|
|
117
|
-
this.config.loggerProvider.log(result.message)
|
|
118
|
-
|
|
119
|
-
else {
|
|
120
|
-
this.config.loggerProvider.error(result.message);
|
|
121
|
-
}
|
|
147
|
+
result = _a.sent();
|
|
148
|
+
result.code === 200
|
|
149
|
+
? this.config.loggerProvider.log(result.message)
|
|
150
|
+
: this.config.loggerProvider.error(result.message);
|
|
122
151
|
return [2 /*return*/, result];
|
|
123
152
|
case 2:
|
|
124
|
-
e_2 =
|
|
153
|
+
e_2 = _a.sent();
|
|
125
154
|
message = String(e_2);
|
|
126
155
|
this.config.loggerProvider.error(message);
|
|
127
|
-
|
|
156
|
+
result = (0, result_builder_1.buildResult)(event, 0, message);
|
|
157
|
+
return [2 /*return*/, result];
|
|
128
158
|
case 3: return [2 /*return*/];
|
|
129
159
|
}
|
|
130
160
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";;;AAWA,uDAM+B;AAC/B,uCAAsC;AACtC,yDAAqD;AACrD,uCAAqE;AAErE;IAYE,uBAAY,IAAiB;QAAjB,qBAAA,EAAA,iBAAiB;QAX7B,iBAAY,GAAG,KAAK,CAAC;QAQX,MAAC,GAAuB,EAAE,CAAC;QAC3B,cAAS,GAAuB,EAAE,CAAC;QA0B7C,aAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAvB/B,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI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CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACxD,OAAO;SACR;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,6BAAK,GAAL;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IACH,oBAAC;AAAD,CAAC,AA7HD,IA6HC;AA7HY,sCAAa","sourcesContent":["import {\n CoreClient,\n Config,\n Event,\n BaseEvent,\n EventOptions,\n Identify,\n Plugin,\n Revenue,\n Result,\n} from '@amplitude/analytics-types';\nimport {\n createGroupIdentifyEvent,\n createIdentifyEvent,\n createTrackEvent,\n createRevenueEvent,\n createGroupEvent,\n} from './utils/event-builder';\nimport { Timeline } from './timeline';\nimport { buildResult } from './utils/result-builder';\nimport { CLIENT_NOT_INITIALIZED, OPT_OUT_MESSAGE } from './messages';\n\nexport class AmplitudeCore<T extends Config> implements CoreClient<T> {\n initializing = false;\n name: string;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: T;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n timeline: Timeline;\n protected q: CallableFunction[] = [];\n protected dispatchQ: CallableFunction[] = [];\n\n constructor(name = '$default') {\n this.timeline = new Timeline();\n this.name = name;\n }\n\n async _init(config: T) {\n this.config = config;\n this.timeline.reset();\n await this.runQueuedFunctions('q');\n }\n\n async runQueuedFunctions(queueName: 'q' | 'dispatchQ') {\n const queuedFunctions = this[queueName];\n this[queueName] = [];\n for (const queuedFunction of queuedFunctions) {\n await queuedFunction();\n }\n }\n\n track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions) {\n const event = createTrackEvent(eventInput, eventProperties, eventOptions);\n return this.dispatch(event);\n }\n\n logEvent = this.track.bind(this);\n\n identify(identify: Identify, eventOptions?: EventOptions) {\n const event = createIdentifyEvent(identify, eventOptions);\n return this.dispatch(event);\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions) {\n const event = createGroupIdentifyEvent(groupType, groupName, identify, eventOptions);\n return this.dispatch(event);\n }\n\n setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions) {\n const event = createGroupEvent(groupType, groupName, eventOptions);\n return this.dispatch(event);\n }\n\n revenue(revenue: Revenue, eventOptions?: EventOptions) {\n const event = createRevenueEvent(revenue, eventOptions);\n return this.dispatch(event);\n }\n\n async add(plugin: Plugin) {\n if (!this.config) {\n this.q.push(this.add.bind(this, plugin));\n return;\n }\n return this.timeline.register(plugin, this.config);\n }\n\n async remove(pluginName: string) {\n if (!this.config) {\n this.q.push(this.remove.bind(this, pluginName));\n return;\n }\n return this.timeline.deregister(pluginName);\n }\n\n dispatchWithCallback(event: Event, callback: (result: Result) => void): void {\n if (!this.config) {\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.config) {\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 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 const result = await this.timeline.push(event);\n\n result.code === 200\n ? this.config.loggerProvider.log(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.config) {\n this.q.push(this.setOptOut.bind(this, Boolean(optOut)));\n return;\n }\n this.config.optOut = Boolean(optOut);\n }\n\n flush() {\n return this.timeline.flush();\n }\n}\n"]}
|
package/lib/cjs/messages.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export declare const MAX_RETRIES_EXCEEDED_MESSAGE = "Event rejected due to excee
|
|
|
4
4
|
export declare const OPT_OUT_MESSAGE = "Event skipped due to optOut config";
|
|
5
5
|
export declare const MISSING_API_KEY_MESSAGE = "Event rejected due to missing API key";
|
|
6
6
|
export declare const INVALID_API_KEY = "Invalid API key";
|
|
7
|
+
export declare const CLIENT_NOT_INITIALIZED = "Client not initialized";
|
|
7
8
|
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAC5D,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AACpE,eAAO,MAAM,4BAA4B,+CAA+C,CAAC;AACzF,eAAO,MAAM,eAAe,uCAAuC,CAAC;AACpE,eAAO,MAAM,uBAAuB,0CAA0C,CAAC;AAC/E,eAAO,MAAM,eAAe,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAC5D,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AACpE,eAAO,MAAM,4BAA4B,+CAA+C,CAAC;AACzF,eAAO,MAAM,eAAe,uCAAuC,CAAC;AACpE,eAAO,MAAM,uBAAuB,0CAA0C,CAAC;AAC/E,eAAO,MAAM,eAAe,oBAAoB,CAAC;AACjD,eAAO,MAAM,sBAAsB,2BAA2B,CAAC"}
|
package/lib/cjs/messages.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.INVALID_API_KEY = exports.MISSING_API_KEY_MESSAGE = exports.OPT_OUT_MESSAGE = exports.MAX_RETRIES_EXCEEDED_MESSAGE = exports.UNEXPECTED_ERROR_MESSAGE = exports.SUCCESS_MESSAGE = void 0;
|
|
2
|
+
exports.CLIENT_NOT_INITIALIZED = exports.INVALID_API_KEY = exports.MISSING_API_KEY_MESSAGE = exports.OPT_OUT_MESSAGE = exports.MAX_RETRIES_EXCEEDED_MESSAGE = exports.UNEXPECTED_ERROR_MESSAGE = exports.SUCCESS_MESSAGE = void 0;
|
|
3
3
|
exports.SUCCESS_MESSAGE = 'Event tracked successfully';
|
|
4
4
|
exports.UNEXPECTED_ERROR_MESSAGE = 'Unexpected error occurred';
|
|
5
5
|
exports.MAX_RETRIES_EXCEEDED_MESSAGE = 'Event rejected due to exceeded retry count';
|
|
6
6
|
exports.OPT_OUT_MESSAGE = 'Event skipped due to optOut config';
|
|
7
7
|
exports.MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key';
|
|
8
8
|
exports.INVALID_API_KEY = 'Invalid API key';
|
|
9
|
+
exports.CLIENT_NOT_INITIALIZED = 'Client not initialized';
|
|
9
10
|
//# sourceMappingURL=messages.js.map
|
package/lib/cjs/messages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":";;AAAa,QAAA,eAAe,GAAG,4BAA4B,CAAC;AAC/C,QAAA,wBAAwB,GAAG,2BAA2B,CAAC;AACvD,QAAA,4BAA4B,GAAG,4CAA4C,CAAC;AAC5E,QAAA,eAAe,GAAG,oCAAoC,CAAC;AACvD,QAAA,uBAAuB,GAAG,uCAAuC,CAAC;AAClE,QAAA,eAAe,GAAG,iBAAiB,CAAC","sourcesContent":["export const SUCCESS_MESSAGE = 'Event tracked successfully';\nexport const UNEXPECTED_ERROR_MESSAGE = 'Unexpected error occurred';\nexport const MAX_RETRIES_EXCEEDED_MESSAGE = 'Event rejected due to exceeded retry count';\nexport const OPT_OUT_MESSAGE = 'Event skipped due to optOut config';\nexport const MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key';\nexport const INVALID_API_KEY = 'Invalid API key';\n"]}
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":";;AAAa,QAAA,eAAe,GAAG,4BAA4B,CAAC;AAC/C,QAAA,wBAAwB,GAAG,2BAA2B,CAAC;AACvD,QAAA,4BAA4B,GAAG,4CAA4C,CAAC;AAC5E,QAAA,eAAe,GAAG,oCAAoC,CAAC;AACvD,QAAA,uBAAuB,GAAG,uCAAuC,CAAC;AAClE,QAAA,eAAe,GAAG,iBAAiB,CAAC;AACpC,QAAA,sBAAsB,GAAG,wBAAwB,CAAC","sourcesContent":["export const SUCCESS_MESSAGE = 'Event tracked successfully';\nexport const UNEXPECTED_ERROR_MESSAGE = 'Unexpected error occurred';\nexport const MAX_RETRIES_EXCEEDED_MESSAGE = 'Event rejected due to exceeded retry count';\nexport const OPT_OUT_MESSAGE = 'Event skipped due to optOut config';\nexport const MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key';\nexport const INVALID_API_KEY = 'Invalid API key';\nexport const CLIENT_NOT_INITIALIZED = 'Client not initialized';\n"]}
|
package/lib/cjs/timeline.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { Config, Event, EventCallback, Plugin, Result } from '@amplitude/analyti
|
|
|
2
2
|
export declare class Timeline {
|
|
3
3
|
queue: [Event, EventCallback][];
|
|
4
4
|
applying: boolean;
|
|
5
|
-
isReady: boolean;
|
|
6
5
|
plugins: Plugin[];
|
|
7
6
|
register(plugin: Plugin, config: Config): Promise<void>;
|
|
8
7
|
deregister(pluginName: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EAGN,KAAK,EACL,aAAa,EACb,MAAM,EAEN,MAAM,EACP,MAAM,4BAA4B,CAAC;AAGpC,qBAAa,QAAQ;IACnB,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,EAAE,CAAM;IAErC,QAAQ,UAAS;IAGjB,OAAO,
|
|
1
|
+
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EAGN,KAAK,EACL,aAAa,EACb,MAAM,EAEN,MAAM,EACP,MAAM,4BAA4B,CAAC;AAGpC,qBAAa,QAAQ;IACnB,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,EAAE,CAAM;IAErC,QAAQ,UAAS;IAGjB,OAAO,EAAE,MAAM,EAAE,CAAM;IAEjB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK7C,UAAU,CAAC,UAAU,EAAE,MAAM;IAQ7B,KAAK;IAKL,IAAI,CAAC,KAAK,EAAE,KAAK;IAOjB,aAAa,CAAC,OAAO,EAAE,MAAM;IAavB,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,SAAS;IAwC9C,KAAK;CAgBZ"}
|
package/lib/cjs/timeline.js
CHANGED
|
@@ -10,7 +10,6 @@ var Timeline = /** @class */ (function () {
|
|
|
10
10
|
this.applying = false;
|
|
11
11
|
// Flag indicates whether timeline is ready to process event
|
|
12
12
|
// Events collected before timeline is ready will stay in the queue to be processed later
|
|
13
|
-
this.isReady = false;
|
|
14
13
|
this.plugins = [];
|
|
15
14
|
}
|
|
16
15
|
Timeline.prototype.register = function (plugin, config) {
|
|
@@ -32,7 +31,6 @@ var Timeline = /** @class */ (function () {
|
|
|
32
31
|
};
|
|
33
32
|
Timeline.prototype.reset = function () {
|
|
34
33
|
this.applying = false;
|
|
35
|
-
this.isReady = false;
|
|
36
34
|
this.plugins = [];
|
|
37
35
|
};
|
|
38
36
|
Timeline.prototype.push = function (event) {
|
|
@@ -44,7 +42,7 @@ var Timeline = /** @class */ (function () {
|
|
|
44
42
|
};
|
|
45
43
|
Timeline.prototype.scheduleApply = function (timeout) {
|
|
46
44
|
var _this = this;
|
|
47
|
-
if (
|
|
45
|
+
if (this.applying)
|
|
48
46
|
return;
|
|
49
47
|
this.applying = true;
|
|
50
48
|
setTimeout(function () {
|
package/lib/cjs/timeline.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":";;;AAAA,8DAUoC;AACpC,yDAAqD;AAErD;IAAA;QACE,UAAK,GAA6B,EAAE,CAAC;QACrC,kDAAkD;QAClD,aAAQ,GAAG,KAAK,CAAC;QACjB,4DAA4D;QAC5D,yFAAyF;QACzF,YAAO,
|
|
1
|
+
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":";;;AAAA,8DAUoC;AACpC,yDAAqD;AAErD;IAAA;QACE,UAAK,GAA6B,EAAE,CAAC;QACrC,kDAAkD;QAClD,aAAQ,GAAG,KAAK,CAAC;QACjB,4DAA4D;QAC5D,yFAAyF;QACzF,YAAO,GAAa,EAAE,CAAC;IAgGzB,CAAC;IA9FO,2BAAQ,GAAd,UAAe,MAAc,EAAE,MAAc;;;;4BAC3C,qBAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAA;;wBAA1B,SAA0B,CAAC;wBAC3B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;;;;;KAC3B;IAED,6BAAU,GAAV,UAAW,UAAkB;QAC3B,IAAI,CAAC,OAAO,CAAC,MAAM,CACjB,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,IAAI,KAAK,UAAU,EAA1B,CAA0B,CAAC,EAC9D,CAAC,CACF,CAAC;QACF,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,wBAAK,GAAL;QACE,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,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,UAAC,IAAI,IAAK,OAAA,KAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAhB,CAAgB,CAAC,CAAC,EAAA;;wBAAxD,SAAwD,CAAC;wBAEnD,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CACrC,UAAC,MAAc,IAAkC,OAAA,MAAM,CAAC,IAAI,KAAK,4BAAU,CAAC,WAAW,EAAtC,CAAsC,CACxF,CAAC;wBAEI,mBAAmB,GAAG,WAAW,CAAC,GAAG,CAAC,UAAC,MAAM;4BACjD,OAAO,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;wBACxC,CAAC,CAAC,CAAC;wBAEH,qBAAM,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAA;;wBAAtC,SAAsC,CAAC;;;;;KACxC;IACH,eAAC;AAAD,CAAC,AAtGD,IAsGC;AAtGY,4BAAQ","sourcesContent":["import {\n BeforePlugin,\n Config,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n EventCallback,\n Plugin,\n PluginType,\n Result,\n} from '@amplitude/analytics-types';\nimport { buildResult } from './utils/result-builder';\n\nexport class Timeline {\n queue: [Event, EventCallback][] = [];\n // Flag to guarantee one schedule apply is running\n applying = false;\n // Flag indicates whether timeline is ready to process event\n // Events collected before timeline is ready will stay in the queue to be processed later\n plugins: Plugin[] = [];\n\n async register(plugin: Plugin, config: Config) {\n await plugin.setup(config);\n this.plugins.push(plugin);\n }\n\n deregister(pluginName: string) {\n this.plugins.splice(\n this.plugins.findIndex((plugin) => plugin.name === pluginName),\n 1,\n );\n return Promise.resolve();\n }\n\n reset() {\n this.applying = false;\n this.plugins = [];\n }\n\n push(event: Event) {\n return new Promise<Result>((resolve) => {\n this.queue.push([event, resolve]);\n this.scheduleApply(0);\n });\n }\n\n scheduleApply(timeout: number) {\n if (this.applying) return;\n this.applying = true;\n setTimeout(() => {\n void this.apply(this.queue.shift()).then(() => {\n this.applying = false;\n if (this.queue.length > 0) {\n this.scheduleApply(0);\n }\n });\n }, timeout);\n }\n\n async apply(item: [Event, EventCallback] | undefined) {\n if (!item) {\n return;\n }\n\n let [event] = item;\n const [, resolve] = item;\n\n const before = this.plugins.filter<BeforePlugin>(\n (plugin: Plugin): plugin is BeforePlugin => plugin.type === PluginType.BEFORE,\n );\n\n for (const plugin of before) {\n event = await plugin.execute({ ...event });\n }\n\n const enrichment = this.plugins.filter<EnrichmentPlugin>(\n (plugin: Plugin): plugin is EnrichmentPlugin => plugin.type === PluginType.ENRICHMENT,\n );\n\n for (const plugin of enrichment) {\n event = await plugin.execute({ ...event });\n }\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === PluginType.DESTINATION,\n );\n\n const executeDestinations = destination.map((plugin) => {\n const eventClone = { ...event };\n return plugin.execute(eventClone).catch((e) => buildResult(eventClone, 0, String(e)));\n });\n\n void Promise.all(executeDestinations).then(([result]) => {\n resolve(result);\n });\n\n return;\n }\n\n async flush() {\n const queue = this.queue;\n this.queue = [];\n\n await Promise.all(queue.map((item) => this.apply(item)));\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === PluginType.DESTINATION,\n );\n\n const executeDestinations = destination.map((plugin) => {\n return plugin.flush && plugin.flush();\n });\n\n await Promise.all(executeDestinations);\n }\n}\n"]}
|
package/lib/esm/core-client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoreClient, Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types';
|
|
1
|
+
import { CoreClient, Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue, Result } from '@amplitude/analytics-types';
|
|
2
2
|
import { Timeline } from './timeline';
|
|
3
3
|
export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
|
|
4
4
|
initializing: boolean;
|
|
@@ -6,17 +6,21 @@ export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
|
|
|
6
6
|
config: T;
|
|
7
7
|
timeline: Timeline;
|
|
8
8
|
protected q: CallableFunction[];
|
|
9
|
+
protected dispatchQ: CallableFunction[];
|
|
9
10
|
constructor(name?: string);
|
|
10
11
|
_init(config: T): Promise<void>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
runQueuedFunctions(queueName: 'q' | 'dispatchQ'): Promise<void>;
|
|
13
|
+
track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): Promise<Result>;
|
|
14
|
+
logEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<Result>;
|
|
15
|
+
identify(identify: Identify, eventOptions?: EventOptions): Promise<Result>;
|
|
16
|
+
groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions): Promise<Result>;
|
|
17
|
+
setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions): Promise<Result>;
|
|
18
|
+
revenue(revenue: Revenue, eventOptions?: EventOptions): Promise<Result>;
|
|
17
19
|
add(plugin: Plugin): Promise<void>;
|
|
18
20
|
remove(pluginName: string): Promise<void>;
|
|
19
|
-
|
|
21
|
+
dispatchWithCallback(event: Event, callback: (result: Result) => void): void;
|
|
22
|
+
dispatch(event: Event): Promise<Result>;
|
|
23
|
+
process(event: Event): Promise<Result>;
|
|
20
24
|
setOptOut(optOut: boolean): void;
|
|
21
25
|
flush(): Promise<void>;
|
|
22
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,MAAM,EACN,KAAK,EACL,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,OAAO,
|
|
1
|
+
{"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client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UAAU,EAAE,MAAM;IAQ/B,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAOtE,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAUvC,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAuB5C,SAAS,CAAC,MAAM,EAAE,OAAO;IAQzB,KAAK;CAGN"}
|
package/lib/esm/core-client.js
CHANGED
|
@@ -2,27 +2,41 @@ import { __awaiter, __generator, __values } from "tslib";
|
|
|
2
2
|
import { createGroupIdentifyEvent, createIdentifyEvent, createTrackEvent, createRevenueEvent, createGroupEvent, } from './utils/event-builder';
|
|
3
3
|
import { Timeline } from './timeline';
|
|
4
4
|
import { buildResult } from './utils/result-builder';
|
|
5
|
-
import { OPT_OUT_MESSAGE } from './messages';
|
|
5
|
+
import { CLIENT_NOT_INITIALIZED, OPT_OUT_MESSAGE } from './messages';
|
|
6
6
|
var AmplitudeCore = /** @class */ (function () {
|
|
7
7
|
function AmplitudeCore(name) {
|
|
8
8
|
if (name === void 0) { name = '$default'; }
|
|
9
9
|
this.initializing = false;
|
|
10
10
|
this.q = [];
|
|
11
|
+
this.dispatchQ = [];
|
|
11
12
|
this.logEvent = this.track.bind(this);
|
|
12
13
|
this.timeline = new Timeline();
|
|
13
14
|
this.name = name;
|
|
14
15
|
}
|
|
15
16
|
AmplitudeCore.prototype._init = function (config) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
18
|
+
return __generator(this, function (_a) {
|
|
19
|
+
switch (_a.label) {
|
|
20
|
+
case 0:
|
|
21
|
+
this.config = config;
|
|
22
|
+
this.timeline.reset();
|
|
23
|
+
return [4 /*yield*/, this.runQueuedFunctions('q')];
|
|
24
|
+
case 1:
|
|
25
|
+
_a.sent();
|
|
26
|
+
return [2 /*return*/];
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
AmplitudeCore.prototype.runQueuedFunctions = function (queueName) {
|
|
16
32
|
return __awaiter(this, void 0, void 0, function () {
|
|
17
33
|
var queuedFunctions, queuedFunctions_1, queuedFunctions_1_1, queuedFunction, e_1_1;
|
|
18
34
|
var e_1, _a;
|
|
19
35
|
return __generator(this, function (_b) {
|
|
20
36
|
switch (_b.label) {
|
|
21
37
|
case 0:
|
|
22
|
-
|
|
23
|
-
this
|
|
24
|
-
queuedFunctions = this.q;
|
|
25
|
-
this.q = [];
|
|
38
|
+
queuedFunctions = this[queueName];
|
|
39
|
+
this[queueName] = [];
|
|
26
40
|
_b.label = 1;
|
|
27
41
|
case 1:
|
|
28
42
|
_b.trys.push([1, 6, 7, 8]);
|
|
@@ -96,33 +110,49 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
96
110
|
});
|
|
97
111
|
});
|
|
98
112
|
};
|
|
113
|
+
AmplitudeCore.prototype.dispatchWithCallback = function (event, callback) {
|
|
114
|
+
if (!this.config) {
|
|
115
|
+
return callback(buildResult(event, 0, CLIENT_NOT_INITIALIZED));
|
|
116
|
+
}
|
|
117
|
+
void this.process(event).then(callback);
|
|
118
|
+
};
|
|
99
119
|
AmplitudeCore.prototype.dispatch = function (event) {
|
|
100
|
-
var _a;
|
|
101
120
|
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
-
var
|
|
103
|
-
return __generator(this, function (
|
|
104
|
-
|
|
121
|
+
var _this = this;
|
|
122
|
+
return __generator(this, function (_a) {
|
|
123
|
+
if (!this.config) {
|
|
124
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
125
|
+
_this.dispatchQ.push(_this.dispatchWithCallback.bind(_this, event, resolve));
|
|
126
|
+
})];
|
|
127
|
+
}
|
|
128
|
+
return [2 /*return*/, this.process(event)];
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
AmplitudeCore.prototype.process = function (event) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
var result, e_2, message, result;
|
|
135
|
+
return __generator(this, function (_a) {
|
|
136
|
+
switch (_a.label) {
|
|
105
137
|
case 0:
|
|
106
|
-
|
|
138
|
+
_a.trys.push([0, 2, , 3]);
|
|
107
139
|
// skip event processing if opt out
|
|
108
|
-
if (
|
|
140
|
+
if (this.config.optOut) {
|
|
109
141
|
return [2 /*return*/, buildResult(event, 0, OPT_OUT_MESSAGE)];
|
|
110
142
|
}
|
|
111
143
|
return [4 /*yield*/, this.timeline.push(event)];
|
|
112
144
|
case 1:
|
|
113
|
-
result =
|
|
114
|
-
|
|
115
|
-
this.config.loggerProvider.log(result.message)
|
|
116
|
-
|
|
117
|
-
else {
|
|
118
|
-
this.config.loggerProvider.error(result.message);
|
|
119
|
-
}
|
|
145
|
+
result = _a.sent();
|
|
146
|
+
result.code === 200
|
|
147
|
+
? this.config.loggerProvider.log(result.message)
|
|
148
|
+
: this.config.loggerProvider.error(result.message);
|
|
120
149
|
return [2 /*return*/, result];
|
|
121
150
|
case 2:
|
|
122
|
-
e_2 =
|
|
151
|
+
e_2 = _a.sent();
|
|
123
152
|
message = String(e_2);
|
|
124
153
|
this.config.loggerProvider.error(message);
|
|
125
|
-
|
|
154
|
+
result = buildResult(event, 0, message);
|
|
155
|
+
return [2 /*return*/, result];
|
|
126
156
|
case 3: return [2 /*return*/];
|
|
127
157
|
}
|
|
128
158
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";AAWA,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;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C,MAAM,CAAC,OAAO,CAAC,CAAC;wBAErD,sBAAO,MAAM,EAAC;;;wBAER,OAAO,GAAG,MAAM,CAAC,GAAC,CAAC,CAAC;wBAC1B,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;wBACpC,MAAM,GAAG,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;wBAE9C,sBAAO,MAAM,EAAC;;;;;KAEjB;IAED,iCAAS,GAAT,UAAU,MAAe;QACvB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACxD,OAAO;SACR;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,6BAAK,GAAL;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IACH,oBAAC;AAAD,CAAC,AA7HD,IA6HC","sourcesContent":["import {\n CoreClient,\n Config,\n Event,\n BaseEvent,\n EventOptions,\n Identify,\n Plugin,\n Revenue,\n Result,\n} from '@amplitude/analytics-types';\nimport {\n createGroupIdentifyEvent,\n createIdentifyEvent,\n createTrackEvent,\n createRevenueEvent,\n createGroupEvent,\n} from './utils/event-builder';\nimport { Timeline } from './timeline';\nimport { buildResult } from './utils/result-builder';\nimport { CLIENT_NOT_INITIALIZED, OPT_OUT_MESSAGE } from './messages';\n\nexport class AmplitudeCore<T extends Config> implements CoreClient<T> {\n initializing = false;\n name: string;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: T;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n timeline: Timeline;\n protected q: CallableFunction[] = [];\n protected dispatchQ: CallableFunction[] = [];\n\n constructor(name = '$default') {\n this.timeline = new Timeline();\n this.name = name;\n }\n\n async _init(config: T) {\n this.config = config;\n this.timeline.reset();\n await this.runQueuedFunctions('q');\n }\n\n async runQueuedFunctions(queueName: 'q' | 'dispatchQ') {\n const queuedFunctions = this[queueName];\n this[queueName] = [];\n for (const queuedFunction of queuedFunctions) {\n await queuedFunction();\n }\n }\n\n track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions) {\n const event = createTrackEvent(eventInput, eventProperties, eventOptions);\n return this.dispatch(event);\n }\n\n logEvent = this.track.bind(this);\n\n identify(identify: Identify, eventOptions?: EventOptions) {\n const event = createIdentifyEvent(identify, eventOptions);\n return this.dispatch(event);\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions) {\n const event = createGroupIdentifyEvent(groupType, groupName, identify, eventOptions);\n return this.dispatch(event);\n }\n\n setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions) {\n const event = createGroupEvent(groupType, groupName, eventOptions);\n return this.dispatch(event);\n }\n\n revenue(revenue: Revenue, eventOptions?: EventOptions) {\n const event = createRevenueEvent(revenue, eventOptions);\n return this.dispatch(event);\n }\n\n async add(plugin: Plugin) {\n if (!this.config) {\n this.q.push(this.add.bind(this, plugin));\n return;\n }\n return this.timeline.register(plugin, this.config);\n }\n\n async remove(pluginName: string) {\n if (!this.config) {\n this.q.push(this.remove.bind(this, pluginName));\n return;\n }\n return this.timeline.deregister(pluginName);\n }\n\n dispatchWithCallback(event: Event, callback: (result: Result) => void): void {\n if (!this.config) {\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.config) {\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 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 const result = await this.timeline.push(event);\n\n result.code === 200\n ? this.config.loggerProvider.log(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.config) {\n this.q.push(this.setOptOut.bind(this, Boolean(optOut)));\n return;\n }\n this.config.optOut = Boolean(optOut);\n }\n\n flush() {\n return this.timeline.flush();\n }\n}\n"]}
|
package/lib/esm/messages.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export declare const MAX_RETRIES_EXCEEDED_MESSAGE = "Event rejected due to excee
|
|
|
4
4
|
export declare const OPT_OUT_MESSAGE = "Event skipped due to optOut config";
|
|
5
5
|
export declare const MISSING_API_KEY_MESSAGE = "Event rejected due to missing API key";
|
|
6
6
|
export declare const INVALID_API_KEY = "Invalid API key";
|
|
7
|
+
export declare const CLIENT_NOT_INITIALIZED = "Client not initialized";
|
|
7
8
|
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAC5D,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AACpE,eAAO,MAAM,4BAA4B,+CAA+C,CAAC;AACzF,eAAO,MAAM,eAAe,uCAAuC,CAAC;AACpE,eAAO,MAAM,uBAAuB,0CAA0C,CAAC;AAC/E,eAAO,MAAM,eAAe,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAC5D,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AACpE,eAAO,MAAM,4BAA4B,+CAA+C,CAAC;AACzF,eAAO,MAAM,eAAe,uCAAuC,CAAC;AACpE,eAAO,MAAM,uBAAuB,0CAA0C,CAAC;AAC/E,eAAO,MAAM,eAAe,oBAAoB,CAAC;AACjD,eAAO,MAAM,sBAAsB,2BAA2B,CAAC"}
|
package/lib/esm/messages.js
CHANGED
|
@@ -4,4 +4,5 @@ export var MAX_RETRIES_EXCEEDED_MESSAGE = 'Event rejected due to exceeded retry
|
|
|
4
4
|
export var OPT_OUT_MESSAGE = 'Event skipped due to optOut config';
|
|
5
5
|
export var MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key';
|
|
6
6
|
export var INVALID_API_KEY = 'Invalid API key';
|
|
7
|
+
export var CLIENT_NOT_INITIALIZED = 'Client not initialized';
|
|
7
8
|
//# sourceMappingURL=messages.js.map
|
package/lib/esm/messages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,eAAe,GAAG,4BAA4B,CAAC;AAC5D,MAAM,CAAC,IAAM,wBAAwB,GAAG,2BAA2B,CAAC;AACpE,MAAM,CAAC,IAAM,4BAA4B,GAAG,4CAA4C,CAAC;AACzF,MAAM,CAAC,IAAM,eAAe,GAAG,oCAAoC,CAAC;AACpE,MAAM,CAAC,IAAM,uBAAuB,GAAG,uCAAuC,CAAC;AAC/E,MAAM,CAAC,IAAM,eAAe,GAAG,iBAAiB,CAAC","sourcesContent":["export const SUCCESS_MESSAGE = 'Event tracked successfully';\nexport const UNEXPECTED_ERROR_MESSAGE = 'Unexpected error occurred';\nexport const MAX_RETRIES_EXCEEDED_MESSAGE = 'Event rejected due to exceeded retry count';\nexport const OPT_OUT_MESSAGE = 'Event skipped due to optOut config';\nexport const MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key';\nexport const INVALID_API_KEY = 'Invalid API key';\n"]}
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,eAAe,GAAG,4BAA4B,CAAC;AAC5D,MAAM,CAAC,IAAM,wBAAwB,GAAG,2BAA2B,CAAC;AACpE,MAAM,CAAC,IAAM,4BAA4B,GAAG,4CAA4C,CAAC;AACzF,MAAM,CAAC,IAAM,eAAe,GAAG,oCAAoC,CAAC;AACpE,MAAM,CAAC,IAAM,uBAAuB,GAAG,uCAAuC,CAAC;AAC/E,MAAM,CAAC,IAAM,eAAe,GAAG,iBAAiB,CAAC;AACjD,MAAM,CAAC,IAAM,sBAAsB,GAAG,wBAAwB,CAAC","sourcesContent":["export const SUCCESS_MESSAGE = 'Event tracked successfully';\nexport const UNEXPECTED_ERROR_MESSAGE = 'Unexpected error occurred';\nexport const MAX_RETRIES_EXCEEDED_MESSAGE = 'Event rejected due to exceeded retry count';\nexport const OPT_OUT_MESSAGE = 'Event skipped due to optOut config';\nexport const MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key';\nexport const INVALID_API_KEY = 'Invalid API key';\nexport const CLIENT_NOT_INITIALIZED = 'Client not initialized';\n"]}
|
package/lib/esm/timeline.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { Config, Event, EventCallback, Plugin, Result } from '@amplitude/analyti
|
|
|
2
2
|
export declare class Timeline {
|
|
3
3
|
queue: [Event, EventCallback][];
|
|
4
4
|
applying: boolean;
|
|
5
|
-
isReady: boolean;
|
|
6
5
|
plugins: Plugin[];
|
|
7
6
|
register(plugin: Plugin, config: Config): Promise<void>;
|
|
8
7
|
deregister(pluginName: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EAGN,KAAK,EACL,aAAa,EACb,MAAM,EAEN,MAAM,EACP,MAAM,4BAA4B,CAAC;AAGpC,qBAAa,QAAQ;IACnB,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,EAAE,CAAM;IAErC,QAAQ,UAAS;IAGjB,OAAO,
|
|
1
|
+
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EAGN,KAAK,EACL,aAAa,EACb,MAAM,EAEN,MAAM,EACP,MAAM,4BAA4B,CAAC;AAGpC,qBAAa,QAAQ;IACnB,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,EAAE,CAAM;IAErC,QAAQ,UAAS;IAGjB,OAAO,EAAE,MAAM,EAAE,CAAM;IAEjB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK7C,UAAU,CAAC,UAAU,EAAE,MAAM;IAQ7B,KAAK;IAKL,IAAI,CAAC,KAAK,EAAE,KAAK;IAOjB,aAAa,CAAC,OAAO,EAAE,MAAM;IAavB,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,SAAS;IAwC9C,KAAK;CAgBZ"}
|
package/lib/esm/timeline.js
CHANGED
|
@@ -8,7 +8,6 @@ var Timeline = /** @class */ (function () {
|
|
|
8
8
|
this.applying = false;
|
|
9
9
|
// Flag indicates whether timeline is ready to process event
|
|
10
10
|
// Events collected before timeline is ready will stay in the queue to be processed later
|
|
11
|
-
this.isReady = false;
|
|
12
11
|
this.plugins = [];
|
|
13
12
|
}
|
|
14
13
|
Timeline.prototype.register = function (plugin, config) {
|
|
@@ -30,7 +29,6 @@ var Timeline = /** @class */ (function () {
|
|
|
30
29
|
};
|
|
31
30
|
Timeline.prototype.reset = function () {
|
|
32
31
|
this.applying = false;
|
|
33
|
-
this.isReady = false;
|
|
34
32
|
this.plugins = [];
|
|
35
33
|
};
|
|
36
34
|
Timeline.prototype.push = function (event) {
|
|
@@ -42,7 +40,7 @@ var Timeline = /** @class */ (function () {
|
|
|
42
40
|
};
|
|
43
41
|
Timeline.prototype.scheduleApply = function (timeout) {
|
|
44
42
|
var _this = this;
|
|
45
|
-
if (
|
|
43
|
+
if (this.applying)
|
|
46
44
|
return;
|
|
47
45
|
this.applying = true;
|
|
48
46
|
setTimeout(function () {
|
package/lib/esm/timeline.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":";AAAA,OAAO,EAQL,UAAU,GAEX,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD;IAAA;QACE,UAAK,GAA6B,EAAE,CAAC;QACrC,kDAAkD;QAClD,aAAQ,GAAG,KAAK,CAAC;QACjB,4DAA4D;QAC5D,yFAAyF;QACzF,YAAO,
|
|
1
|
+
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":";AAAA,OAAO,EAQL,UAAU,GAEX,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD;IAAA;QACE,UAAK,GAA6B,EAAE,CAAC;QACrC,kDAAkD;QAClD,aAAQ,GAAG,KAAK,CAAC;QACjB,4DAA4D;QAC5D,yFAAyF;QACzF,YAAO,GAAa,EAAE,CAAC;IAgGzB,CAAC;IA9FO,2BAAQ,GAAd,UAAe,MAAc,EAAE,MAAc;;;;4BAC3C,qBAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAA;;wBAA1B,SAA0B,CAAC;wBAC3B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;;;;;KAC3B;IAED,6BAAU,GAAV,UAAW,UAAkB;QAC3B,IAAI,CAAC,OAAO,CAAC,MAAM,CACjB,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,IAAI,KAAK,UAAU,EAA1B,CAA0B,CAAC,EAC9D,CAAC,CACF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K,CAAC;wBACzB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;wBAEhB,qBAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,UAAC,IAAI,IAAK,OAAA,KAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAhB,CAAgB,CAAC,CAAC,EAAA;;wBAAxD,SAAwD,CAAC;wBAEnD,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CACrC,UAAC,MAAc,IAAkC,OAAA,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC,WAAW,EAAtC,CAAsC,CACxF,CAAC;wBAEI,mBAAmB,GAAG,WAAW,CAAC,GAAG,CAAC,UAAC,MAAM;4BACjD,OAAO,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;wBACxC,CAAC,CAAC,CAAC;wBAEH,qBAAM,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAA;;wBAAtC,SAAsC,CAAC;;;;;KACxC;IACH,eAAC;AAAD,CAAC,AAtGD,IAsGC","sourcesContent":["import {\n BeforePlugin,\n Config,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n EventCallback,\n Plugin,\n PluginType,\n Result,\n} from '@amplitude/analytics-types';\nimport { buildResult } from './utils/result-builder';\n\nexport class Timeline {\n queue: [Event, EventCallback][] = [];\n // Flag to guarantee one schedule apply is running\n applying = false;\n // Flag indicates whether timeline is ready to process event\n // Events collected before timeline is ready will stay in the queue to be processed later\n plugins: Plugin[] = [];\n\n async register(plugin: Plugin, config: Config) {\n await plugin.setup(config);\n this.plugins.push(plugin);\n }\n\n deregister(pluginName: string) {\n this.plugins.splice(\n this.plugins.findIndex((plugin) => plugin.name === pluginName),\n 1,\n );\n return Promise.resolve();\n }\n\n reset() {\n this.applying = false;\n this.plugins = [];\n }\n\n push(event: Event) {\n return new Promise<Result>((resolve) => {\n this.queue.push([event, resolve]);\n this.scheduleApply(0);\n });\n }\n\n scheduleApply(timeout: number) {\n if (this.applying) return;\n this.applying = true;\n setTimeout(() => {\n void this.apply(this.queue.shift()).then(() => {\n this.applying = false;\n if (this.queue.length > 0) {\n this.scheduleApply(0);\n }\n });\n }, timeout);\n }\n\n async apply(item: [Event, EventCallback] | undefined) {\n if (!item) {\n return;\n }\n\n let [event] = item;\n const [, resolve] = item;\n\n const before = this.plugins.filter<BeforePlugin>(\n (plugin: Plugin): plugin is BeforePlugin => plugin.type === PluginType.BEFORE,\n );\n\n for (const plugin of before) {\n event = await plugin.execute({ ...event });\n }\n\n const enrichment = this.plugins.filter<EnrichmentPlugin>(\n (plugin: Plugin): plugin is EnrichmentPlugin => plugin.type === PluginType.ENRICHMENT,\n );\n\n for (const plugin of enrichment) {\n event = await plugin.execute({ ...event });\n }\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === PluginType.DESTINATION,\n );\n\n const executeDestinations = destination.map((plugin) => {\n const eventClone = { ...event };\n return plugin.execute(eventClone).catch((e) => buildResult(eventClone, 0, String(e)));\n });\n\n void Promise.all(executeDestinations).then(([result]) => {\n resolve(result);\n });\n\n return;\n }\n\n async flush() {\n const queue = this.queue;\n this.queue = [];\n\n await Promise.all(queue.map((item) => this.apply(item)));\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === PluginType.DESTINATION,\n );\n\n const executeDestinations = destination.map((plugin) => {\n return plugin.flush && plugin.flush();\n });\n\n await Promise.all(executeDestinations);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/analytics-core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7",
|
|
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": "
|
|
43
|
+
"gitHead": "7e75f22a1d9a972f627d18ae2e09add8dac2c63f"
|
|
44
44
|
}
|