@amplitude/analytics-core 0.6.4 → 0.7.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 +2 -1
- package/lib/cjs/core-client.d.ts.map +1 -1
- package/lib/cjs/core-client.js +60 -13
- package/lib/cjs/core-client.js.map +1 -1
- package/lib/cjs/plugins/destination.d.ts.map +1 -1
- package/lib/cjs/plugins/destination.js +5 -1
- package/lib/cjs/plugins/destination.js.map +1 -1
- package/lib/cjs/timeline.js +1 -1
- package/lib/cjs/timeline.js.map +1 -1
- package/lib/cjs/utils/event-builder.d.ts +1 -1
- package/lib/cjs/utils/event-builder.d.ts.map +1 -1
- package/lib/cjs/utils/event-builder.js +3 -7
- package/lib/cjs/utils/event-builder.js.map +1 -1
- package/lib/esm/core-client.d.ts +2 -1
- package/lib/esm/core-client.d.ts.map +1 -1
- package/lib/esm/core-client.js +61 -14
- package/lib/esm/core-client.js.map +1 -1
- package/lib/esm/plugins/destination.d.ts.map +1 -1
- package/lib/esm/plugins/destination.js +6 -2
- package/lib/esm/plugins/destination.js.map +1 -1
- package/lib/esm/timeline.js +1 -1
- package/lib/esm/timeline.js.map +1 -1
- package/lib/esm/utils/event-builder.d.ts +1 -1
- package/lib/esm/utils/event-builder.d.ts.map +1 -1
- package/lib/esm/utils/event-builder.js +3 -7
- package/lib/esm/utils/event-builder.js.map +1 -1
- package/package.json +3 -3
package/lib/cjs/core-client.d.ts
CHANGED
|
@@ -4,13 +4,14 @@ export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
|
|
|
4
4
|
name: string;
|
|
5
5
|
config: T;
|
|
6
6
|
timeline: Timeline;
|
|
7
|
+
protected q: CallableFunction[];
|
|
7
8
|
constructor(name?: string);
|
|
8
9
|
_init(config: T): Promise<void>;
|
|
9
10
|
track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
10
11
|
logEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>;
|
|
11
12
|
identify(identify: Identify, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
12
13
|
groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
13
|
-
setGroup(groupType: string, groupName: string | string[]): Promise<import("@amplitude/analytics-types").Result>;
|
|
14
|
+
setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
14
15
|
revenue(revenue: Revenue, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
15
16
|
add(plugin: Plugin): Promise<void>;
|
|
16
17
|
remove(pluginName: string): Promise<void>;
|
|
@@ -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,EACR,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,qBAAa,aAAa,CAAC,CAAC,SAAS,MAAM,CAAE,YAAW,UAAU,CAAC,CAAC,CAAC;IACnE,IAAI,EAAE,MAAM,CAAC;IAGb,MAAM,EAAE,CAAC,CAAC;IAGV,QAAQ,EAAE,QAAQ,CAAC;
|
|
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,EACR,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,qBAAa,aAAa,CAAC,CAAC,SAAS,MAAM,CAAE,YAAW,UAAU,CAAC,CAAC,CAAC;IACnE,IAAI,EAAE,MAAM,CAAC;IAGb,MAAM,EAAE,CAAC,CAAC;IAGV,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAM;gBAEzB,IAAI,SAAa;IAKvB,KAAK,CAAC,MAAM,EAAE,CAAC;IAUrB,KAAK,CAAC,UAAU,EAAE,SAAS,GAAG,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,YAAY,CAAC,EAAE,YAAY;IAKxG,QAAQ,eALU,SAAS,GAAG,MAAM,sJAKH;IAEjC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,YAAY;IAKxD,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,YAAY;IAK9G,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,YAAY,CAAC,EAAE,YAAY;IAKrF,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,YAAY;IAK/C,GAAG,CAAC,MAAM,EAAE,MAAM;IAQlB,MAAM,CAAC,UAAU,EAAE,MAAM;IAQzB,QAAQ,CAAC,KAAK,EAAE,KAAK;IAoB3B,SAAS,CAAC,MAAM,EAAE,OAAO;IAQzB,KAAK;CAGN"}
|
package/lib/cjs/core-client.js
CHANGED
|
@@ -8,14 +8,52 @@ var messages_1 = require("./messages");
|
|
|
8
8
|
var AmplitudeCore = /** @class */ (function () {
|
|
9
9
|
function AmplitudeCore(name) {
|
|
10
10
|
if (name === void 0) { name = '$default'; }
|
|
11
|
+
this.q = [];
|
|
11
12
|
this.logEvent = this.track.bind(this);
|
|
12
13
|
this.timeline = new timeline_1.Timeline();
|
|
13
14
|
this.name = name;
|
|
14
15
|
}
|
|
15
16
|
AmplitudeCore.prototype._init = function (config) {
|
|
16
|
-
this
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
18
|
+
var queuedFunctions, queuedFunctions_1, queuedFunctions_1_1, queuedFunction, e_1_1;
|
|
19
|
+
var e_1, _a;
|
|
20
|
+
return (0, tslib_1.__generator)(this, function (_b) {
|
|
21
|
+
switch (_b.label) {
|
|
22
|
+
case 0:
|
|
23
|
+
this.config = config;
|
|
24
|
+
this.timeline.reset();
|
|
25
|
+
queuedFunctions = this.q;
|
|
26
|
+
this.q = [];
|
|
27
|
+
_b.label = 1;
|
|
28
|
+
case 1:
|
|
29
|
+
_b.trys.push([1, 6, 7, 8]);
|
|
30
|
+
queuedFunctions_1 = (0, tslib_1.__values)(queuedFunctions), queuedFunctions_1_1 = queuedFunctions_1.next();
|
|
31
|
+
_b.label = 2;
|
|
32
|
+
case 2:
|
|
33
|
+
if (!!queuedFunctions_1_1.done) return [3 /*break*/, 5];
|
|
34
|
+
queuedFunction = queuedFunctions_1_1.value;
|
|
35
|
+
return [4 /*yield*/, queuedFunction()];
|
|
36
|
+
case 3:
|
|
37
|
+
_b.sent();
|
|
38
|
+
_b.label = 4;
|
|
39
|
+
case 4:
|
|
40
|
+
queuedFunctions_1_1 = queuedFunctions_1.next();
|
|
41
|
+
return [3 /*break*/, 2];
|
|
42
|
+
case 5: return [3 /*break*/, 8];
|
|
43
|
+
case 6:
|
|
44
|
+
e_1_1 = _b.sent();
|
|
45
|
+
e_1 = { error: e_1_1 };
|
|
46
|
+
return [3 /*break*/, 8];
|
|
47
|
+
case 7:
|
|
48
|
+
try {
|
|
49
|
+
if (queuedFunctions_1_1 && !queuedFunctions_1_1.done && (_a = queuedFunctions_1.return)) _a.call(queuedFunctions_1);
|
|
50
|
+
}
|
|
51
|
+
finally { if (e_1) throw e_1.error; }
|
|
52
|
+
return [7 /*endfinally*/];
|
|
53
|
+
case 8: return [2 /*return*/];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
19
57
|
};
|
|
20
58
|
AmplitudeCore.prototype.track = function (eventInput, eventProperties, eventOptions) {
|
|
21
59
|
var event = (0, event_builder_1.createTrackEvent)(eventInput, eventProperties, eventOptions);
|
|
@@ -29,8 +67,8 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
29
67
|
var event = (0, event_builder_1.createGroupIdentifyEvent)(groupType, groupName, identify, eventOptions);
|
|
30
68
|
return this.dispatch(event);
|
|
31
69
|
};
|
|
32
|
-
AmplitudeCore.prototype.setGroup = function (groupType, groupName) {
|
|
33
|
-
var event = (0, event_builder_1.createGroupEvent)(groupType, groupName);
|
|
70
|
+
AmplitudeCore.prototype.setGroup = function (groupType, groupName, eventOptions) {
|
|
71
|
+
var event = (0, event_builder_1.createGroupEvent)(groupType, groupName, eventOptions);
|
|
34
72
|
return this.dispatch(event);
|
|
35
73
|
};
|
|
36
74
|
AmplitudeCore.prototype.revenue = function (revenue, eventOptions) {
|
|
@@ -39,16 +77,22 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
39
77
|
};
|
|
40
78
|
AmplitudeCore.prototype.add = function (plugin) {
|
|
41
79
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
42
|
-
var config;
|
|
43
80
|
return (0, tslib_1.__generator)(this, function (_a) {
|
|
44
|
-
|
|
45
|
-
|
|
81
|
+
if (!this.config) {
|
|
82
|
+
this.q.push(this.add.bind(this, plugin));
|
|
83
|
+
return [2 /*return*/];
|
|
84
|
+
}
|
|
85
|
+
return [2 /*return*/, this.timeline.register(plugin, this.config)];
|
|
46
86
|
});
|
|
47
87
|
});
|
|
48
88
|
};
|
|
49
89
|
AmplitudeCore.prototype.remove = function (pluginName) {
|
|
50
90
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
51
91
|
return (0, tslib_1.__generator)(this, function (_a) {
|
|
92
|
+
if (!this.config) {
|
|
93
|
+
this.q.push(this.remove.bind(this, pluginName));
|
|
94
|
+
return [2 /*return*/];
|
|
95
|
+
}
|
|
52
96
|
return [2 /*return*/, this.timeline.deregister(pluginName)];
|
|
53
97
|
});
|
|
54
98
|
});
|
|
@@ -56,7 +100,7 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
56
100
|
AmplitudeCore.prototype.dispatch = function (event) {
|
|
57
101
|
var _a;
|
|
58
102
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
59
|
-
var result,
|
|
103
|
+
var result, e_2, message;
|
|
60
104
|
return (0, tslib_1.__generator)(this, function (_b) {
|
|
61
105
|
switch (_b.label) {
|
|
62
106
|
case 0:
|
|
@@ -76,8 +120,8 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
76
120
|
}
|
|
77
121
|
return [2 /*return*/, result];
|
|
78
122
|
case 2:
|
|
79
|
-
|
|
80
|
-
message = String(
|
|
123
|
+
e_2 = _b.sent();
|
|
124
|
+
message = String(e_2);
|
|
81
125
|
this.config.loggerProvider.error(message);
|
|
82
126
|
return [2 /*return*/, (0, result_builder_1.buildResult)(event, 0, message)];
|
|
83
127
|
case 3: return [2 /*return*/];
|
|
@@ -86,8 +130,11 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
86
130
|
});
|
|
87
131
|
};
|
|
88
132
|
AmplitudeCore.prototype.setOptOut = function (optOut) {
|
|
89
|
-
|
|
90
|
-
|
|
133
|
+
if (!this.config) {
|
|
134
|
+
this.q.push(this.setOptOut.bind(this, Boolean(optOut)));
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
this.config.optOut = Boolean(optOut);
|
|
91
138
|
};
|
|
92
139
|
AmplitudeCore.prototype.flush = function () {
|
|
93
140
|
return this.timeline.flush();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";;;AAUA,uDAM+B;AAC/B,uCAAsC;AACtC,yDAAqD;AACrD,uCAA6C;AAE7C;
|
|
1
|
+
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";;;AAUA,uDAM+B;AAC/B,uCAAsC;AACtC,yDAAqD;AACrD,uCAA6C;AAE7C;IAUE,uBAAY,IAAiB;QAAjB,qBAAA,EAAA,iBAAiB;QAFnB,MAAC,GAAuB,EAAE,CAAC;QAsBrC,aAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAnB/B,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEK,6BAAK,GAAX,UAAY,MAAS;;;;;;;wBACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;wBACrB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;wBAChB,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC;wBAC/B,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC;;;;wBACiB,oBAAA,sBAAA,eAAe,CAAA;;;;wBAAjC,cAAc;wBACvB,qBAAM,cAAc,EAAE,EAAA;;wBAAtB,SAAsB,CAAC;;;;;;;;;;;;;;;;;;;;KAE1B;IAED,6BAAK,GAAL,UAAM,UAA8B,EAAE,eAAqC,EAAE,YAA2B;QACtG,IAAM,KAAK,GAAG,IAAA,gCAAgB,EAAC,UAAU,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAID,gCAAQ,GAAR,UAAS,QAAkB,EAAE,YAA2B;QACtD,IAAM,KAAK,GAAG,IAAA,mCAAmB,EAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QA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EAAE,CAAC;IAC/B,CAAC;IACH,oBAAC;AAAD,CAAC,AAnGD,IAmGC;AAnGY,sCAAa","sourcesContent":["import {\n CoreClient,\n Config,\n Event,\n BaseEvent,\n EventOptions,\n Identify,\n Plugin,\n Revenue,\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 { OPT_OUT_MESSAGE } from './messages';\n\nexport class AmplitudeCore<T extends Config> implements CoreClient<T> {\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\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 const queuedFunctions = this.q;\n this.q = [];\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 async dispatch(event: Event) {\n try {\n // skip event processing if opt out\n if (this.config?.optOut) {\n return buildResult(event, 0, OPT_OUT_MESSAGE);\n }\n const result = await this.timeline.push(event);\n if (result.code === 200) {\n this.config.loggerProvider.log(result.message);\n } else {\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 return buildResult(event, 0, message);\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destination.d.ts","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,IAAI,OAAO,EAC7B,iBAAiB,EACjB,KAAK,EACL,eAAe,EACf,uBAAuB,EACvB,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,MAAM,EAEN,eAAe,EAChB,MAAM,4BAA4B,CAAC;AAapC,qBAAa,WAAY,YAAW,iBAAiB;IACnD,IAAI,SAAe;IACnB,IAAI,yBAAmC;IAEvC,YAAY,SAAQ;IACpB,eAAe,SAAS;IACxB,UAAU,SAAM;IAIhB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,UAAS;IAClB,KAAK,EAAE,OAAO,EAAE,CAAM;IAEhB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAa/C,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAYtC,UAAU,CAAC,GAAG,IAAI,EAAE,OAAO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3E,uBAAuB,CAAC,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,OAAO,EAAE;IAyB/D,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE;IASlC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAK7D;;;;;OAKG;IACH,UAAU;CAOX"}
|
|
@@ -125,7 +125,11 @@ var Destination = /** @class */ (function () {
|
|
|
125
125
|
}
|
|
126
126
|
payload = {
|
|
127
127
|
api_key: this.config.apiKey,
|
|
128
|
-
events: list.map(function (context) {
|
|
128
|
+
events: list.map(function (context) {
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
130
|
+
var _a = context.event, extra = _a.extra, eventWithoutExtra = (0, tslib_1.__rest)(_a, ["extra"]);
|
|
131
|
+
return eventWithoutExtra;
|
|
132
|
+
}),
|
|
129
133
|
options: {
|
|
130
134
|
min_id_length: this.config.minIdLength,
|
|
131
135
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":";;;AAAA,8DAaoC;AACpC,wCAMqB;AACrB,0CAA8C;AAC9C,wCAAuC;AACvC,0DAAsD;AACtD,oCAA+C;AAE/C;IAAA;QACE,SAAI,GAAG,WAAW,CAAC;QACnB,SAAI,GAAG,4BAAU,CAAC,WAAoB,CAAC;QAEvC,iBAAY,GAAG,IAAI,CAAC;QACpB,oBAAe,GAAG,KAAK,CAAC;QACxB,eAAU,GAAG,EAAE,CAAC;QAKhB,cAAS,GAAG,KAAK,CAAC;QAClB,UAAK,GAAc,EAAE,CAAC;IA4NxB,CAAC;IA1NO,2BAAK,GAAX,UAAY,MAAc;;;;;;;;wBACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;wBAErB,IAAI,CAAC,UAAU,GAAG,UAAG,0BAAc,cAAI,IAAI,CAAC,MAAM,CAA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adTooLargeResponse,\n PluginType,\n RateLimitResponse,\n Response,\n Result,\n Status,\n SuccessResponse,\n} from '@amplitude/analytics-types';\nimport {\n INVALID_API_KEY,\n MAX_RETRIES_EXCEEDED_MESSAGE,\n MISSING_API_KEY_MESSAGE,\n SUCCESS_MESSAGE,\n UNEXPECTED_ERROR_MESSAGE,\n} from '../messages';\nimport { STORAGE_PREFIX } from '../constants';\nimport { chunk } from '../utils/chunk';\nimport { buildResult } from '../utils/result-builder';\nimport { createServerConfig } from '../config';\n\nexport class Destination implements DestinationPlugin {\n name = 'amplitude';\n type = PluginType.DESTINATION as const;\n\n retryTimeout = 1000;\n throttleTimeout = 30000;\n storageKey = '';\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: Config;\n scheduled = false;\n queue: Context[] = [];\n\n async setup(config: Config): Promise<undefined> {\n this.config = config;\n\n this.storageKey = `${STORAGE_PREFIX}_${this.config.apiKey.substring(0, 10)}`;\n const unsent = await this.config.storageProvider?.get(this.storageKey);\n this.saveEvents(); // sets storage to '[]'\n if (unsent && unsent.length > 0) {\n void Promise.all(unsent.map((event) => this.execute(event))).catch();\n }\n\n return Promise.resolve(undefined);\n }\n\n execute(event: Event): Promise<Result> {\n return new Promise((resolve) => {\n const context = {\n event,\n attempts: 0,\n callback: (result: Result) => resolve(result),\n timeout: 0,\n };\n void this.addToQueue(context);\n });\n }\n\n addToQueue(...list: Context[]) {\n const tryable = list.filter((context) => {\n if (context.attempts < this.config.flushMaxRetries) {\n context.attempts += 1;\n return true;\n }\n void this.fulfillRequest([context], 500, MAX_RETRIES_EXCEEDED_MESSAGE);\n return false;\n });\n\n tryable.forEach((context) => {\n this.queue = this.queue.concat(context);\n if (context.timeout === 0) {\n this.schedule(this.config.flushIntervalMillis);\n return;\n }\n\n setTimeout(() => {\n context.timeout = 0;\n this.schedule(0);\n }, context.timeout);\n });\n\n this.saveEvents();\n }\n\n schedule(timeout: number) {\n if (this.scheduled) return;\n this.scheduled = true;\n setTimeout(() => {\n void this.flush(true).then(() => {\n this.scheduled = false;\n if (this.queue.length > 0) {\n this.schedule(timeout);\n }\n });\n }, timeout);\n }\n\n async flush(useRetry = false) {\n const list: Context[] = [];\n const later: Context[] = [];\n this.queue.forEach((context) => (context.timeout === 0 ? list.push(context) : later.push(context)));\n this.queue = later;\n\n const batches = chunk(list, this.config.flushQueueSize);\n await Promise.all(batches.map((batch) => this.send(batch, useRetry)));\n }\n\n async send(list: Context[], useRetry = true) {\n if (!this.config.apiKey) {\n return this.fulfillRequest(list, 400, MISSING_API_KEY_MESSAGE);\n }\n\n const payload = {\n api_key: this.config.apiKey,\n events: list.map((context) => context.event),\n options: {\n min_id_length: this.config.minIdLength,\n },\n };\n\n try {\n const { serverUrl } = createServerConfig(this.config.serverUrl, this.config.serverZone, this.config.useBatch);\n const res = await this.config.transportProvider.send(serverUrl, payload);\n if (res === null) {\n this.fulfillRequest(list, 0, UNEXPECTED_ERROR_MESSAGE);\n return;\n }\n if (!useRetry) {\n this.fulfillRequest(list, res.statusCode, res.status);\n return;\n }\n this.handleReponse(res, list);\n } catch (e) {\n this.fulfillRequest(list, 0, String(e));\n }\n }\n\n handleReponse(res: Response, list: Context[]) {\n const { status } = res;\n switch (status) {\n case Status.Success:\n this.handleSuccessResponse(res, list);\n break;\n\n case Status.Invalid:\n this.handleInvalidResponse(res, list);\n break;\n\n case Status.PayloadTooLarge:\n this.handlePayloadTooLargeResponse(res, list);\n break;\n\n case Status.RateLimit:\n this.handleRateLimitResponse(res, list);\n break;\n\n default:\n this.handleOtherReponse(list);\n }\n }\n\n handleSuccessResponse(res: SuccessResponse, list: Context[]) {\n this.fulfillRequest(list, res.statusCode, SUCCESS_MESSAGE);\n }\n\n handleInvalidResponse(res: InvalidResponse, list: Context[]) {\n if (res.body.missingField || res.body.error.startsWith(INVALID_API_KEY)) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n\n const dropIndex = [\n ...Object.values(res.body.eventsWithInvalidFields),\n ...Object.values(res.body.eventsWithMissingFields),\n ...Object.values(res.body.eventsWithInvalidIdLengths),\n ...res.body.silencedEvents,\n ].flat();\n const dropIndexSet = new Set(dropIndex);\n\n const retry = list.filter((context, index) => {\n if (dropIndexSet.has(index)) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handlePayloadTooLargeResponse(res: PayloadTooLargeResponse, list: Context[]) {\n if (list.length === 1) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n this.config.flushQueueSize /= 2;\n this.addToQueue(...list);\n }\n\n handleRateLimitResponse(res: RateLimitResponse, list: Context[]) {\n const dropUserIds = Object.keys(res.body.exceededDailyQuotaUsers);\n const dropDeviceIds = Object.keys(res.body.exceededDailyQuotaDevices);\n const throttledIndex = res.body.throttledEvents;\n const dropUserIdsSet = new Set(dropUserIds);\n const dropDeviceIdsSet = new Set(dropDeviceIds);\n const throttledIndexSet = new Set(throttledIndex);\n\n const retry = list.filter((context, index) => {\n if (\n (context.event.user_id && dropUserIdsSet.has(context.event.user_id)) ||\n (context.event.device_id && dropDeviceIdsSet.has(context.event.device_id))\n ) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n if (throttledIndexSet.has(index)) {\n context.timeout = this.throttleTimeout;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handleOtherReponse(list: Context[]) {\n this.addToQueue(\n ...list.map((context) => {\n context.timeout = context.attempts * this.retryTimeout;\n return context;\n }),\n );\n }\n\n fulfillRequest(list: Context[], code: number, message: string) {\n this.saveEvents();\n list.forEach((context) => context.callback(buildResult(context.event, code, message)));\n }\n\n /**\n * Saves events to storage\n * This is called on\n * 1) new events are added to queue; or\n * 2) response comes back for a request\n */\n saveEvents() {\n if (!this.config.storageProvider) {\n return;\n }\n const events = Array.from(this.queue.map((context) => context.event));\n void this.config.storageProvider.set(this.storageKey, events);\n }\n}\n"]}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AAE,CAAC;QAClB,IAAI,CAAC,OAAO,CAAC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,QAAQ,CAAC,IAAA,4BAAW,EAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,EAA3D,CAA2D,CAAC,CAAC;IACzF,CAAC;IAED;;;;;OAKG;IACH,gCAAU,GAAV;QACE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE;YAChC,OAAO;SACR;QACD,IAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,KAAK,EAAb,CAAa,CAAC,CAAC,CAAC;QACtE,KAAK,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IACH,kBAAC;AAAD,CAAC,AA5OD,IA4OC;AA5OY,kCAAW","sourcesContent":["import {\n Config,\n DestinationContext as Context,\n DestinationPlugin,\n Event,\n InvalidResponse,\n PayloadTooLargeResponse,\n PluginType,\n RateLimitResponse,\n Response,\n Result,\n Status,\n SuccessResponse,\n} from '@amplitude/analytics-types';\nimport {\n INVALID_API_KEY,\n MAX_RETRIES_EXCEEDED_MESSAGE,\n MISSING_API_KEY_MESSAGE,\n SUCCESS_MESSAGE,\n UNEXPECTED_ERROR_MESSAGE,\n} from '../messages';\nimport { STORAGE_PREFIX } from '../constants';\nimport { chunk } from '../utils/chunk';\nimport { buildResult } from '../utils/result-builder';\nimport { createServerConfig } from '../config';\n\nexport class Destination implements DestinationPlugin {\n name = 'amplitude';\n type = PluginType.DESTINATION as const;\n\n retryTimeout = 1000;\n throttleTimeout = 30000;\n storageKey = '';\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: Config;\n scheduled = false;\n queue: Context[] = [];\n\n async setup(config: Config): Promise<undefined> {\n this.config = config;\n\n this.storageKey = `${STORAGE_PREFIX}_${this.config.apiKey.substring(0, 10)}`;\n const unsent = await this.config.storageProvider?.get(this.storageKey);\n this.saveEvents(); // sets storage to '[]'\n if (unsent && unsent.length > 0) {\n void Promise.all(unsent.map((event) => this.execute(event))).catch();\n }\n\n return Promise.resolve(undefined);\n }\n\n execute(event: Event): Promise<Result> {\n return new Promise((resolve) => {\n const context = {\n event,\n attempts: 0,\n callback: (result: Result) => resolve(result),\n timeout: 0,\n };\n void this.addToQueue(context);\n });\n }\n\n addToQueue(...list: Context[]) {\n const tryable = list.filter((context) => {\n if (context.attempts < this.config.flushMaxRetries) {\n context.attempts += 1;\n return true;\n }\n void this.fulfillRequest([context], 500, MAX_RETRIES_EXCEEDED_MESSAGE);\n return false;\n });\n\n tryable.forEach((context) => {\n this.queue = this.queue.concat(context);\n if (context.timeout === 0) {\n this.schedule(this.config.flushIntervalMillis);\n return;\n }\n\n setTimeout(() => {\n context.timeout = 0;\n this.schedule(0);\n }, context.timeout);\n });\n\n this.saveEvents();\n }\n\n schedule(timeout: number) {\n if (this.scheduled) return;\n this.scheduled = true;\n setTimeout(() => {\n void this.flush(true).then(() => {\n this.scheduled = false;\n if (this.queue.length > 0) {\n this.schedule(timeout);\n }\n });\n }, timeout);\n }\n\n async flush(useRetry = false) {\n const list: Context[] = [];\n const later: Context[] = [];\n this.queue.forEach((context) => (context.timeout === 0 ? list.push(context) : later.push(context)));\n this.queue = later;\n\n const batches = chunk(list, this.config.flushQueueSize);\n await Promise.all(batches.map((batch) => this.send(batch, useRetry)));\n }\n\n async send(list: Context[], useRetry = true) {\n if (!this.config.apiKey) {\n return this.fulfillRequest(list, 400, MISSING_API_KEY_MESSAGE);\n }\n\n const payload = {\n api_key: this.config.apiKey,\n events: list.map((context) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { extra, ...eventWithoutExtra } = context.event;\n return eventWithoutExtra;\n }),\n options: {\n min_id_length: this.config.minIdLength,\n },\n };\n\n try {\n const { serverUrl } = createServerConfig(this.config.serverUrl, this.config.serverZone, this.config.useBatch);\n const res = await this.config.transportProvider.send(serverUrl, payload);\n if (res === null) {\n this.fulfillRequest(list, 0, UNEXPECTED_ERROR_MESSAGE);\n return;\n }\n if (!useRetry) {\n this.fulfillRequest(list, res.statusCode, res.status);\n return;\n }\n this.handleReponse(res, list);\n } catch (e) {\n this.fulfillRequest(list, 0, String(e));\n }\n }\n\n handleReponse(res: Response, list: Context[]) {\n const { status } = res;\n switch (status) {\n case Status.Success:\n this.handleSuccessResponse(res, list);\n break;\n\n case Status.Invalid:\n this.handleInvalidResponse(res, list);\n break;\n\n case Status.PayloadTooLarge:\n this.handlePayloadTooLargeResponse(res, list);\n break;\n\n case Status.RateLimit:\n this.handleRateLimitResponse(res, list);\n break;\n\n default:\n this.handleOtherReponse(list);\n }\n }\n\n handleSuccessResponse(res: SuccessResponse, list: Context[]) {\n this.fulfillRequest(list, res.statusCode, SUCCESS_MESSAGE);\n }\n\n handleInvalidResponse(res: InvalidResponse, list: Context[]) {\n if (res.body.missingField || res.body.error.startsWith(INVALID_API_KEY)) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n\n const dropIndex = [\n ...Object.values(res.body.eventsWithInvalidFields),\n ...Object.values(res.body.eventsWithMissingFields),\n ...Object.values(res.body.eventsWithInvalidIdLengths),\n ...res.body.silencedEvents,\n ].flat();\n const dropIndexSet = new Set(dropIndex);\n\n const retry = list.filter((context, index) => {\n if (dropIndexSet.has(index)) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handlePayloadTooLargeResponse(res: PayloadTooLargeResponse, list: Context[]) {\n if (list.length === 1) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n this.config.flushQueueSize /= 2;\n this.addToQueue(...list);\n }\n\n handleRateLimitResponse(res: RateLimitResponse, list: Context[]) {\n const dropUserIds = Object.keys(res.body.exceededDailyQuotaUsers);\n const dropDeviceIds = Object.keys(res.body.exceededDailyQuotaDevices);\n const throttledIndex = res.body.throttledEvents;\n const dropUserIdsSet = new Set(dropUserIds);\n const dropDeviceIdsSet = new Set(dropDeviceIds);\n const throttledIndexSet = new Set(throttledIndex);\n\n const retry = list.filter((context, index) => {\n if (\n (context.event.user_id && dropUserIdsSet.has(context.event.user_id)) ||\n (context.event.device_id && dropDeviceIdsSet.has(context.event.device_id))\n ) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n if (throttledIndexSet.has(index)) {\n context.timeout = this.throttleTimeout;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handleOtherReponse(list: Context[]) {\n this.addToQueue(\n ...list.map((context) => {\n context.timeout = context.attempts * this.retryTimeout;\n return context;\n }),\n );\n }\n\n fulfillRequest(list: Context[], code: number, message: string) {\n this.saveEvents();\n list.forEach((context) => context.callback(buildResult(context.event, code, message)));\n }\n\n /**\n * Saves events to storage\n * This is called on\n * 1) new events are added to queue; or\n * 2) response comes back for a request\n */\n saveEvents() {\n if (!this.config.storageProvider) {\n return;\n }\n const events = Array.from(this.queue.map((context) => context.event));\n void this.config.storageProvider.set(this.storageKey, events);\n }\n}\n"]}
|
package/lib/cjs/timeline.js
CHANGED
|
@@ -44,7 +44,7 @@ var Timeline = /** @class */ (function () {
|
|
|
44
44
|
};
|
|
45
45
|
Timeline.prototype.scheduleApply = function (timeout) {
|
|
46
46
|
var _this = this;
|
|
47
|
-
if (this.
|
|
47
|
+
if (!this.isReady || this.applying)
|
|
48
48
|
return;
|
|
49
49
|
this.applying = true;
|
|
50
50
|
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,CAA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CAAC,mBAAmB,CAAC,EAAA;;wBAAtC,SAAsC,CAAC;;;;;KACxC;IACH,eAAC;AAAD,CAAC,AAxGD,IAwGC;AAxGY,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 isReady = false;\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.isReady = 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.isReady || 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"]}
|
|
@@ -2,6 +2,6 @@ import { BaseEvent, TrackEvent, IdentifyEvent, GroupIdentifyEvent, Identify as I
|
|
|
2
2
|
export declare const createTrackEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => TrackEvent;
|
|
3
3
|
export declare const createIdentifyEvent: (identify: IIdentify, eventOptions?: EventOptions | undefined) => IdentifyEvent;
|
|
4
4
|
export declare const createGroupIdentifyEvent: (groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions | undefined) => GroupIdentifyEvent;
|
|
5
|
-
export declare const createGroupEvent: (groupType: string, groupName: string | string[]) => IdentifyEvent;
|
|
5
|
+
export declare const createGroupEvent: (groupType: string, groupName: string | string[], eventOptions?: EventOptions | undefined) => IdentifyEvent;
|
|
6
6
|
export declare const createRevenueEvent: (revenue: Revenue, eventOptions?: EventOptions | undefined) => RevenueEvent;
|
|
7
7
|
//# sourceMappingURL=event-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,aAAa,EACb,kBAAkB,EAElB,QAAQ,IAAI,SAAS,EACrB,OAAO,EACP,YAAY,EACZ,YAAY,EACb,MAAM,4BAA4B,CAAC;AAGpC,eAAO,MAAM,gBAAgB,eACf,SAAS,GAAG,MAAM,iGAG7B,UAOF,CAAC;AAEF,eAAO,MAAM,mBAAmB,aAAc,SAAS,8CAAgC,aAQtF,CAAC;AAEF,eAAO,MAAM,wBAAwB,cACxB,MAAM,aACN,MAAM,GAAG,MAAM,EAAE,YAClB,SAAS,8CAElB,kBAWF,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAAe,MAAM,aAAa,MAAM,GAAG,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"event-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,aAAa,EACb,kBAAkB,EAElB,QAAQ,IAAI,SAAS,EACrB,OAAO,EACP,YAAY,EACZ,YAAY,EACb,MAAM,4BAA4B,CAAC;AAGpC,eAAO,MAAM,gBAAgB,eACf,SAAS,GAAG,MAAM,iGAG7B,UAOF,CAAC;AAEF,eAAO,MAAM,mBAAmB,aAAc,SAAS,8CAAgC,aAQtF,CAAC;AAEF,eAAO,MAAM,wBAAwB,cACxB,MAAM,aACN,MAAM,GAAG,MAAM,EAAE,YAClB,SAAS,8CAElB,kBAWF,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAAe,MAAM,aAAa,MAAM,GAAG,MAAM,EAAE,2DAa/E,CAAC;AAEF,eAAO,MAAM,kBAAkB,YAAa,OAAO,8CAAgC,YAMlF,CAAC"}
|
|
@@ -21,17 +21,13 @@ var createGroupIdentifyEvent = function (groupType, groupName, identify, eventOp
|
|
|
21
21
|
return groupIdentify;
|
|
22
22
|
};
|
|
23
23
|
exports.createGroupIdentifyEvent = createGroupIdentifyEvent;
|
|
24
|
-
var createGroupEvent = function (groupType, groupName) {
|
|
24
|
+
var createGroupEvent = function (groupType, groupName, eventOptions) {
|
|
25
25
|
var _a;
|
|
26
26
|
var identify = new identify_1.Identify();
|
|
27
27
|
identify.set(groupType, groupName);
|
|
28
|
-
var groupEvent = {
|
|
29
|
-
event_type: analytics_types_1.SpecialEventType.IDENTIFY,
|
|
30
|
-
user_properties: identify.getUserProperties(),
|
|
31
|
-
groups: (_a = {},
|
|
28
|
+
var groupEvent = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, eventOptions), { event_type: analytics_types_1.SpecialEventType.IDENTIFY, user_properties: identify.getUserProperties(), groups: (_a = {},
|
|
32
29
|
_a[groupType] = groupName,
|
|
33
|
-
_a)
|
|
34
|
-
};
|
|
30
|
+
_a) });
|
|
35
31
|
return groupEvent;
|
|
36
32
|
};
|
|
37
33
|
exports.createGroupEvent = createGroupEvent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-builder.js","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":";;;AAAA,8DAUoC;AACpC,wCAAuC;AAEhC,IAAM,gBAAgB,GAAG,UAC9B,UAA8B,EAC9B,eAAqC,EACrC,YAA2B;IAE3B,IAAM,SAAS,GAAc,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;IACtG,6EACK,SAAS,GACT,YAAY,GACZ,CAAC,eAAe,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC,EAC7D;AACJ,CAAC,CAAC;AAXW,QAAA,gBAAgB,oBAW3B;AAEK,IAAM,mBAAmB,GAAG,UAAC,QAAmB,EAAE,YAA2B;IAClF,IAAM,aAAa,mDACd,YAAY,KACf,UAAU,EAAE,kCAAgB,CAAC,QAAQ,EACrC,eAAe,EAAE,QAAQ,CAAC,iBAAiB,EAAE,GAC9C,CAAC;IAEF,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AARW,QAAA,mBAAmB,uBAQ9B;AAEK,IAAM,wBAAwB,GAAG,UACtC,SAAiB,EACjB,SAA4B,EA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,EAAE,EAC9C,MAAM;YACJ,GAAC,SAAS,IAAG,SAAS;kBAEzB,CAAC;IAEF,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AAhBW,QAAA,wBAAwB,4BAgBnC;AAEK,IAAM,gBAAgB,GAAG,UAAC,SAAiB,EAAE,SAA4B,EAAE,YAA2B;;IAC3G,IAAM,QAAQ,GAAG,IAAI,mBAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAEnC,IAAM,UAAU,mDACX,YAAY,KACf,UAAU,EAAE,kCAAgB,CAAC,QAAQ,EACrC,eAAe,EAAE,QAAQ,CAAC,iBAAiB,EAAE,EAC7C,MAAM;YACJ,GAAC,SAAS,IAAG,SAAS;kBAEzB,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAbW,QAAA,gBAAgB,oBAa3B;AAEK,IAAM,kBAAkB,GAAG,UAAC,OAAgB,EAAE,YAA2B;IAC9E,uDACK,YAAY,KACf,UAAU,EAAE,kCAAgB,CAAC,OAAO,EACpC,gBAAgB,EAAE,OAAO,CAAC,kBAAkB,EAAE,IAC9C;AACJ,CAAC,CAAC;AANW,QAAA,kBAAkB,sBAM7B","sourcesContent":["import {\n BaseEvent,\n TrackEvent,\n IdentifyEvent,\n GroupIdentifyEvent,\n SpecialEventType,\n Identify as IIdentify,\n Revenue,\n RevenueEvent,\n EventOptions,\n} from '@amplitude/analytics-types';\nimport { Identify } from '../identify';\n\nexport const createTrackEvent = (\n eventInput: BaseEvent | string,\n eventProperties?: Record<string, any>,\n eventOptions?: EventOptions,\n): TrackEvent => {\n const baseEvent: BaseEvent = typeof eventInput === 'string' ? { event_type: eventInput } : eventInput;\n return {\n ...baseEvent,\n ...eventOptions,\n ...(eventProperties && { event_properties: eventProperties }),\n };\n};\n\nexport const createIdentifyEvent = (identify: IIdentify, eventOptions?: EventOptions): IdentifyEvent => {\n const identifyEvent: IdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.IDENTIFY,\n user_properties: identify.getUserProperties(),\n };\n\n return identifyEvent;\n};\n\nexport const createGroupIdentifyEvent = (\n groupType: string,\n groupName: string | string[],\n identify: IIdentify,\n eventOptions?: EventOptions,\n): GroupIdentifyEvent => {\n const groupIdentify: GroupIdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.GROUP_IDENTIFY,\n group_properties: identify.getUserProperties(),\n groups: {\n [groupType]: groupName,\n },\n };\n\n return groupIdentify;\n};\n\nexport const createGroupEvent = (groupType: string, groupName: string | string[], eventOptions?: EventOptions) => {\n const identify = new Identify();\n identify.set(groupType, groupName);\n\n const groupEvent: IdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.IDENTIFY,\n user_properties: identify.getUserProperties(),\n groups: {\n [groupType]: groupName,\n },\n };\n return groupEvent;\n};\n\nexport const createRevenueEvent = (revenue: Revenue, eventOptions?: EventOptions): RevenueEvent => {\n return {\n ...eventOptions,\n event_type: SpecialEventType.REVENUE,\n event_properties: revenue.getEventProperties(),\n };\n};\n"]}
|
package/lib/esm/core-client.d.ts
CHANGED
|
@@ -4,13 +4,14 @@ export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
|
|
|
4
4
|
name: string;
|
|
5
5
|
config: T;
|
|
6
6
|
timeline: Timeline;
|
|
7
|
+
protected q: CallableFunction[];
|
|
7
8
|
constructor(name?: string);
|
|
8
9
|
_init(config: T): Promise<void>;
|
|
9
10
|
track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
10
11
|
logEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>;
|
|
11
12
|
identify(identify: Identify, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
12
13
|
groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
13
|
-
setGroup(groupType: string, groupName: string | string[]): Promise<import("@amplitude/analytics-types").Result>;
|
|
14
|
+
setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
14
15
|
revenue(revenue: Revenue, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
15
16
|
add(plugin: Plugin): Promise<void>;
|
|
16
17
|
remove(pluginName: string): Promise<void>;
|
|
@@ -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,EACR,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,qBAAa,aAAa,CAAC,CAAC,SAAS,MAAM,CAAE,YAAW,UAAU,CAAC,CAAC,CAAC;IACnE,IAAI,EAAE,MAAM,CAAC;IAGb,MAAM,EAAE,CAAC,CAAC;IAGV,QAAQ,EAAE,QAAQ,CAAC;
|
|
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,EACR,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,qBAAa,aAAa,CAAC,CAAC,SAAS,MAAM,CAAE,YAAW,UAAU,CAAC,CAAC,CAAC;IACnE,IAAI,EAAE,MAAM,CAAC;IAGb,MAAM,EAAE,CAAC,CAAC;IAGV,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAM;gBAEzB,IAAI,SAAa;IAKvB,KAAK,CAAC,MAAM,EAAE,CAAC;IAUrB,KAAK,CAAC,UAAU,EAAE,SAAS,GAAG,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,YAAY,CAAC,EAAE,YAAY;IAKxG,QAAQ,eALU,SAAS,GAAG,MAAM,sJAKH;IAEjC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,YAAY;IAKxD,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,YAAY;IAK9G,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,YAAY,CAAC,EAAE,YAAY;IAKrF,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,YAAY;IAK/C,GAAG,CAAC,MAAM,EAAE,MAAM;IAQlB,MAAM,CAAC,UAAU,EAAE,MAAM;IAQzB,QAAQ,CAAC,KAAK,EAAE,KAAK;IAoB3B,SAAS,CAAC,MAAM,EAAE,OAAO;IAQzB,KAAK;CAGN"}
|
package/lib/esm/core-client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __awaiter, __generator } from "tslib";
|
|
1
|
+
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';
|
|
@@ -6,14 +6,52 @@ import { 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
|
+
this.q = [];
|
|
9
10
|
this.logEvent = this.track.bind(this);
|
|
10
11
|
this.timeline = new Timeline();
|
|
11
12
|
this.name = name;
|
|
12
13
|
}
|
|
13
14
|
AmplitudeCore.prototype._init = function (config) {
|
|
14
|
-
this
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
16
|
+
var queuedFunctions, queuedFunctions_1, queuedFunctions_1_1, queuedFunction, e_1_1;
|
|
17
|
+
var e_1, _a;
|
|
18
|
+
return __generator(this, function (_b) {
|
|
19
|
+
switch (_b.label) {
|
|
20
|
+
case 0:
|
|
21
|
+
this.config = config;
|
|
22
|
+
this.timeline.reset();
|
|
23
|
+
queuedFunctions = this.q;
|
|
24
|
+
this.q = [];
|
|
25
|
+
_b.label = 1;
|
|
26
|
+
case 1:
|
|
27
|
+
_b.trys.push([1, 6, 7, 8]);
|
|
28
|
+
queuedFunctions_1 = __values(queuedFunctions), queuedFunctions_1_1 = queuedFunctions_1.next();
|
|
29
|
+
_b.label = 2;
|
|
30
|
+
case 2:
|
|
31
|
+
if (!!queuedFunctions_1_1.done) return [3 /*break*/, 5];
|
|
32
|
+
queuedFunction = queuedFunctions_1_1.value;
|
|
33
|
+
return [4 /*yield*/, queuedFunction()];
|
|
34
|
+
case 3:
|
|
35
|
+
_b.sent();
|
|
36
|
+
_b.label = 4;
|
|
37
|
+
case 4:
|
|
38
|
+
queuedFunctions_1_1 = queuedFunctions_1.next();
|
|
39
|
+
return [3 /*break*/, 2];
|
|
40
|
+
case 5: return [3 /*break*/, 8];
|
|
41
|
+
case 6:
|
|
42
|
+
e_1_1 = _b.sent();
|
|
43
|
+
e_1 = { error: e_1_1 };
|
|
44
|
+
return [3 /*break*/, 8];
|
|
45
|
+
case 7:
|
|
46
|
+
try {
|
|
47
|
+
if (queuedFunctions_1_1 && !queuedFunctions_1_1.done && (_a = queuedFunctions_1.return)) _a.call(queuedFunctions_1);
|
|
48
|
+
}
|
|
49
|
+
finally { if (e_1) throw e_1.error; }
|
|
50
|
+
return [7 /*endfinally*/];
|
|
51
|
+
case 8: return [2 /*return*/];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
17
55
|
};
|
|
18
56
|
AmplitudeCore.prototype.track = function (eventInput, eventProperties, eventOptions) {
|
|
19
57
|
var event = createTrackEvent(eventInput, eventProperties, eventOptions);
|
|
@@ -27,8 +65,8 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
27
65
|
var event = createGroupIdentifyEvent(groupType, groupName, identify, eventOptions);
|
|
28
66
|
return this.dispatch(event);
|
|
29
67
|
};
|
|
30
|
-
AmplitudeCore.prototype.setGroup = function (groupType, groupName) {
|
|
31
|
-
var event = createGroupEvent(groupType, groupName);
|
|
68
|
+
AmplitudeCore.prototype.setGroup = function (groupType, groupName, eventOptions) {
|
|
69
|
+
var event = createGroupEvent(groupType, groupName, eventOptions);
|
|
32
70
|
return this.dispatch(event);
|
|
33
71
|
};
|
|
34
72
|
AmplitudeCore.prototype.revenue = function (revenue, eventOptions) {
|
|
@@ -37,16 +75,22 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
37
75
|
};
|
|
38
76
|
AmplitudeCore.prototype.add = function (plugin) {
|
|
39
77
|
return __awaiter(this, void 0, void 0, function () {
|
|
40
|
-
var config;
|
|
41
78
|
return __generator(this, function (_a) {
|
|
42
|
-
|
|
43
|
-
|
|
79
|
+
if (!this.config) {
|
|
80
|
+
this.q.push(this.add.bind(this, plugin));
|
|
81
|
+
return [2 /*return*/];
|
|
82
|
+
}
|
|
83
|
+
return [2 /*return*/, this.timeline.register(plugin, this.config)];
|
|
44
84
|
});
|
|
45
85
|
});
|
|
46
86
|
};
|
|
47
87
|
AmplitudeCore.prototype.remove = function (pluginName) {
|
|
48
88
|
return __awaiter(this, void 0, void 0, function () {
|
|
49
89
|
return __generator(this, function (_a) {
|
|
90
|
+
if (!this.config) {
|
|
91
|
+
this.q.push(this.remove.bind(this, pluginName));
|
|
92
|
+
return [2 /*return*/];
|
|
93
|
+
}
|
|
50
94
|
return [2 /*return*/, this.timeline.deregister(pluginName)];
|
|
51
95
|
});
|
|
52
96
|
});
|
|
@@ -54,7 +98,7 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
54
98
|
AmplitudeCore.prototype.dispatch = function (event) {
|
|
55
99
|
var _a;
|
|
56
100
|
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
-
var result,
|
|
101
|
+
var result, e_2, message;
|
|
58
102
|
return __generator(this, function (_b) {
|
|
59
103
|
switch (_b.label) {
|
|
60
104
|
case 0:
|
|
@@ -74,8 +118,8 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
74
118
|
}
|
|
75
119
|
return [2 /*return*/, result];
|
|
76
120
|
case 2:
|
|
77
|
-
|
|
78
|
-
message = String(
|
|
121
|
+
e_2 = _b.sent();
|
|
122
|
+
message = String(e_2);
|
|
79
123
|
this.config.loggerProvider.error(message);
|
|
80
124
|
return [2 /*return*/, buildResult(event, 0, message)];
|
|
81
125
|
case 3: return [2 /*return*/];
|
|
@@ -84,8 +128,11 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
84
128
|
});
|
|
85
129
|
};
|
|
86
130
|
AmplitudeCore.prototype.setOptOut = function (optOut) {
|
|
87
|
-
|
|
88
|
-
|
|
131
|
+
if (!this.config) {
|
|
132
|
+
this.q.push(this.setOptOut.bind(this, Boolean(optOut)));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.config.optOut = Boolean(optOut);
|
|
89
136
|
};
|
|
90
137
|
AmplitudeCore.prototype.flush = function () {
|
|
91
138
|
return this.timeline.flush();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";AAUA,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC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,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,AAnGD,IAmGC","sourcesContent":["import {\n CoreClient,\n Config,\n Event,\n BaseEvent,\n EventOptions,\n Identify,\n Plugin,\n Revenue,\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 { OPT_OUT_MESSAGE } from './messages';\n\nexport class AmplitudeCore<T extends Config> implements CoreClient<T> {\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\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 const queuedFunctions = this.q;\n this.q = [];\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 async dispatch(event: Event) {\n try {\n // skip event processing if opt out\n if (this.config?.optOut) {\n return buildResult(event, 0, OPT_OUT_MESSAGE);\n }\n const result = await this.timeline.push(event);\n if (result.code === 200) {\n this.config.loggerProvider.log(result.message);\n } else {\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 return buildResult(event, 0, message);\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destination.d.ts","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,IAAI,OAAO,EAC7B,iBAAiB,EACjB,KAAK,EACL,eAAe,EACf,uBAAuB,EACvB,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,MAAM,EAEN,eAAe,EAChB,MAAM,4BAA4B,CAAC;AAapC,qBAAa,WAAY,YAAW,iBAAiB;IACnD,IAAI,SAAe;IACnB,IAAI,yBAAmC;IAEvC,YAAY,SAAQ;IACpB,eAAe,SAAS;IACxB,UAAU,SAAM;IAIhB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,UAAS;IAClB,KAAK,EAAE,OAAO,EAAE,CAAM;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EAAE,IAAI,EAAE,OAAO,EAAE;IAI3D,qBAAqB,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE;IAyB3D,6BAA6B,CAAC,GAAG,EAAE,uBAAuB,EAAE,IAAI,EAAE,OAAO,EAAE;IAS3E,uBAAuB,CAAC,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,OAAO,EAAE;IAyB/D,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE;IASlC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAK7D;;;;;OAKG;IACH,UAAU;CAOX"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __awaiter, __generator, __read, __spreadArray } from "tslib";
|
|
1
|
+
import { __awaiter, __generator, __read, __rest, __spreadArray } from "tslib";
|
|
2
2
|
import { PluginType, Status, } from '@amplitude/analytics-types';
|
|
3
3
|
import { INVALID_API_KEY, MAX_RETRIES_EXCEEDED_MESSAGE, MISSING_API_KEY_MESSAGE, SUCCESS_MESSAGE, UNEXPECTED_ERROR_MESSAGE, } from '../messages';
|
|
4
4
|
import { STORAGE_PREFIX } from '../constants';
|
|
@@ -123,7 +123,11 @@ var Destination = /** @class */ (function () {
|
|
|
123
123
|
}
|
|
124
124
|
payload = {
|
|
125
125
|
api_key: this.config.apiKey,
|
|
126
|
-
events: list.map(function (context) {
|
|
126
|
+
events: list.map(function (context) {
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
128
|
+
var _a = context.event, extra = _a.extra, eventWithoutExtra = __rest(_a, ["extra"]);
|
|
129
|
+
return eventWithoutExtra;
|
|
130
|
+
}),
|
|
127
131
|
options: {
|
|
128
132
|
min_id_length: this.config.minIdLength,
|
|
129
133
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":";A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IAAe,EAAE,IAAY,EAAE,OAAe;QAC3D,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,OAAO,CAAC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,EAA3D,CAA2D,CAAC,CAAC;IACzF,CAAC;IAED;;;;;OAKG;IACH,gCAAU,GAAV;QACE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE;YAChC,OAAO;SACR;QACD,IAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,KAAK,EAAb,CAAa,CAAC,CAAC,CAAC;QACtE,KAAK,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IACH,kBAAC;AAAD,CAAC,AAxOD,IAwOC","sourcesContent":["import {\n Config,\n DestinationContext as Context,\n DestinationPlugin,\n Event,\n InvalidResponse,\n PayloadTooLargeResponse,\n PluginType,\n RateLimitResponse,\n Response,\n Result,\n Status,\n SuccessResponse,\n} from '@amplitude/analytics-types';\nimport {\n INVALID_API_KEY,\n MAX_RETRIES_EXCEEDED_MESSAGE,\n MISSING_API_KEY_MESSAGE,\n SUCCESS_MESSAGE,\n UNEXPECTED_ERROR_MESSAGE,\n} from '../messages';\nimport { STORAGE_PREFIX } from '../constants';\nimport { chunk } from '../utils/chunk';\nimport { buildResult } from '../utils/result-builder';\nimport { createServerConfig } from '../config';\n\nexport class Destination implements DestinationPlugin {\n name = 'amplitude';\n type = PluginType.DESTINATION as const;\n\n retryTimeout = 1000;\n throttleTimeout = 30000;\n storageKey = '';\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: Config;\n scheduled = false;\n queue: Context[] = [];\n\n async setup(config: Config): Promise<undefined> {\n this.config = config;\n\n this.storageKey = `${STORAGE_PREFIX}_${this.config.apiKey.substring(0, 10)}`;\n const unsent = await this.config.storageProvider?.get(this.storageKey);\n this.saveEvents(); // sets storage to '[]'\n if (unsent && unsent.length > 0) {\n void Promise.all(unsent.map((event) => this.execute(event))).catch();\n }\n\n return Promise.resolve(undefined);\n }\n\n execute(event: Event): Promise<Result> {\n return new Promise((resolve) => {\n const context = {\n event,\n attempts: 0,\n callback: (result: Result) => resolve(result),\n timeout: 0,\n };\n void this.addToQueue(context);\n });\n }\n\n addToQueue(...list: Context[]) {\n const tryable = list.filter((context) => {\n if (context.attempts < this.config.flushMaxRetries) {\n context.attempts += 1;\n return true;\n }\n void this.fulfillRequest([context], 500, MAX_RETRIES_EXCEEDED_MESSAGE);\n return false;\n });\n\n tryable.forEach((context) => {\n this.queue = this.queue.concat(context);\n if (context.timeout === 0) {\n this.schedule(this.config.flushIntervalMillis);\n return;\n }\n\n setTimeout(() => {\n context.timeout = 0;\n this.schedule(0);\n }, context.timeout);\n });\n\n this.saveEvents();\n }\n\n schedule(timeout: number) {\n if (this.scheduled) return;\n this.scheduled = true;\n setTimeout(() => {\n void this.flush(true).then(() => {\n this.scheduled = false;\n if (this.queue.length > 0) {\n this.schedule(timeout);\n }\n });\n }, timeout);\n }\n\n async flush(useRetry = false) {\n const list: Context[] = [];\n const later: Context[] = [];\n this.queue.forEach((context) => (context.timeout === 0 ? list.push(context) : later.push(context)));\n this.queue = later;\n\n const batches = chunk(list, this.config.flushQueueSize);\n await Promise.all(batches.map((batch) => this.send(batch, useRetry)));\n }\n\n async send(list: Context[], useRetry = true) {\n if (!this.config.apiKey) {\n return this.fulfillRequest(list, 400, MISSING_API_KEY_MESSAGE);\n }\n\n const payload = {\n api_key: this.config.apiKey,\n events: list.map((context) => context.event),\n options: {\n min_id_length: this.config.minIdLength,\n },\n };\n\n try {\n const { serverUrl } = createServerConfig(this.config.serverUrl, this.config.serverZone, this.config.useBatch);\n const res = await this.config.transportProvider.send(serverUrl, payload);\n if (res === null) {\n this.fulfillRequest(list, 0, UNEXPECTED_ERROR_MESSAGE);\n return;\n }\n if (!useRetry) {\n this.fulfillRequest(list, res.statusCode, res.status);\n return;\n }\n this.handleReponse(res, list);\n } catch (e) {\n this.fulfillRequest(list, 0, String(e));\n }\n }\n\n handleReponse(res: Response, list: Context[]) {\n const { status } = res;\n switch (status) {\n case Status.Success:\n this.handleSuccessResponse(res, list);\n break;\n\n case Status.Invalid:\n this.handleInvalidResponse(res, list);\n break;\n\n case Status.PayloadTooLarge:\n this.handlePayloadTooLargeResponse(res, list);\n break;\n\n case Status.RateLimit:\n this.handleRateLimitResponse(res, list);\n break;\n\n default:\n this.handleOtherReponse(list);\n }\n }\n\n handleSuccessResponse(res: SuccessResponse, list: Context[]) {\n this.fulfillRequest(list, res.statusCode, SUCCESS_MESSAGE);\n }\n\n handleInvalidResponse(res: InvalidResponse, list: Context[]) {\n if (res.body.missingField || res.body.error.startsWith(INVALID_API_KEY)) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n\n const dropIndex = [\n ...Object.values(res.body.eventsWithInvalidFields),\n ...Object.values(res.body.eventsWithMissingFields),\n ...Object.values(res.body.eventsWithInvalidIdLengths),\n ...res.body.silencedEvents,\n ].flat();\n const dropIndexSet = new Set(dropIndex);\n\n const retry = list.filter((context, index) => {\n if (dropIndexSet.has(index)) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handlePayloadTooLargeResponse(res: PayloadTooLargeResponse, list: Context[]) {\n if (list.length === 1) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n this.config.flushQueueSize /= 2;\n this.addToQueue(...list);\n }\n\n handleRateLimitResponse(res: RateLimitResponse, list: Context[]) {\n const dropUserIds = Object.keys(res.body.exceededDailyQuotaUsers);\n const dropDeviceIds = Object.keys(res.body.exceededDailyQuotaDevices);\n const throttledIndex = res.body.throttledEvents;\n const dropUserIdsSet = new Set(dropUserIds);\n const dropDeviceIdsSet = new Set(dropDeviceIds);\n const throttledIndexSet = new Set(throttledIndex);\n\n const retry = list.filter((context, index) => {\n if (\n (context.event.user_id && dropUserIdsSet.has(context.event.user_id)) ||\n (context.event.device_id && dropDeviceIdsSet.has(context.event.device_id))\n ) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n if (throttledIndexSet.has(index)) {\n context.timeout = this.throttleTimeout;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handleOtherReponse(list: Context[]) {\n this.addToQueue(\n ...list.map((context) => {\n context.timeout = context.attempts * this.retryTimeout;\n return context;\n }),\n );\n }\n\n fulfillRequest(list: Context[], code: number, message: string) {\n this.saveEvents();\n list.forEach((context) => context.callback(buildResult(context.event, code, message)));\n }\n\n /**\n * Saves events to storage\n * This is called on\n * 1) new events are added to queue; or\n * 2) response comes back for a request\n */\n saveEvents() {\n if (!this.config.storageProvider) {\n return;\n }\n const events = Array.from(this.queue.map((context) => context.event));\n void this.config.storageProvider.set(this.storageKey, events);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":";AAAA,OAAO,EAOL,UAAU,EAIV,MAAM,GAEP,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,eAAe,EACf,4BAA4B,EAC5B,uBAAuB,EACvB,eAAe,EACf,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C;IAAA;QACE,SAAI,GAAG,WAAW,CAAC;QACnB,SAAI,G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AI,CAAC,MAAM,CAAC,eAAe,EAAE;YAChC,OAAO;SACR;QACD,IAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,KAAK,EAAb,CAAa,CAAC,CAAC,CAAC;QACtE,KAAK,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IACH,kBAAC;AAAD,CAAC,AA5OD,IA4OC","sourcesContent":["import {\n Config,\n DestinationContext as Context,\n DestinationPlugin,\n Event,\n InvalidResponse,\n PayloadTooLargeResponse,\n PluginType,\n RateLimitResponse,\n Response,\n Result,\n Status,\n SuccessResponse,\n} from '@amplitude/analytics-types';\nimport {\n INVALID_API_KEY,\n MAX_RETRIES_EXCEEDED_MESSAGE,\n MISSING_API_KEY_MESSAGE,\n SUCCESS_MESSAGE,\n UNEXPECTED_ERROR_MESSAGE,\n} from '../messages';\nimport { STORAGE_PREFIX } from '../constants';\nimport { chunk } from '../utils/chunk';\nimport { buildResult } from '../utils/result-builder';\nimport { createServerConfig } from '../config';\n\nexport class Destination implements DestinationPlugin {\n name = 'amplitude';\n type = PluginType.DESTINATION as const;\n\n retryTimeout = 1000;\n throttleTimeout = 30000;\n storageKey = '';\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: Config;\n scheduled = false;\n queue: Context[] = [];\n\n async setup(config: Config): Promise<undefined> {\n this.config = config;\n\n this.storageKey = `${STORAGE_PREFIX}_${this.config.apiKey.substring(0, 10)}`;\n const unsent = await this.config.storageProvider?.get(this.storageKey);\n this.saveEvents(); // sets storage to '[]'\n if (unsent && unsent.length > 0) {\n void Promise.all(unsent.map((event) => this.execute(event))).catch();\n }\n\n return Promise.resolve(undefined);\n }\n\n execute(event: Event): Promise<Result> {\n return new Promise((resolve) => {\n const context = {\n event,\n attempts: 0,\n callback: (result: Result) => resolve(result),\n timeout: 0,\n };\n void this.addToQueue(context);\n });\n }\n\n addToQueue(...list: Context[]) {\n const tryable = list.filter((context) => {\n if (context.attempts < this.config.flushMaxRetries) {\n context.attempts += 1;\n return true;\n }\n void this.fulfillRequest([context], 500, MAX_RETRIES_EXCEEDED_MESSAGE);\n return false;\n });\n\n tryable.forEach((context) => {\n this.queue = this.queue.concat(context);\n if (context.timeout === 0) {\n this.schedule(this.config.flushIntervalMillis);\n return;\n }\n\n setTimeout(() => {\n context.timeout = 0;\n this.schedule(0);\n }, context.timeout);\n });\n\n this.saveEvents();\n }\n\n schedule(timeout: number) {\n if (this.scheduled) return;\n this.scheduled = true;\n setTimeout(() => {\n void this.flush(true).then(() => {\n this.scheduled = false;\n if (this.queue.length > 0) {\n this.schedule(timeout);\n }\n });\n }, timeout);\n }\n\n async flush(useRetry = false) {\n const list: Context[] = [];\n const later: Context[] = [];\n this.queue.forEach((context) => (context.timeout === 0 ? list.push(context) : later.push(context)));\n this.queue = later;\n\n const batches = chunk(list, this.config.flushQueueSize);\n await Promise.all(batches.map((batch) => this.send(batch, useRetry)));\n }\n\n async send(list: Context[], useRetry = true) {\n if (!this.config.apiKey) {\n return this.fulfillRequest(list, 400, MISSING_API_KEY_MESSAGE);\n }\n\n const payload = {\n api_key: this.config.apiKey,\n events: list.map((context) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { extra, ...eventWithoutExtra } = context.event;\n return eventWithoutExtra;\n }),\n options: {\n min_id_length: this.config.minIdLength,\n },\n };\n\n try {\n const { serverUrl } = createServerConfig(this.config.serverUrl, this.config.serverZone, this.config.useBatch);\n const res = await this.config.transportProvider.send(serverUrl, payload);\n if (res === null) {\n this.fulfillRequest(list, 0, UNEXPECTED_ERROR_MESSAGE);\n return;\n }\n if (!useRetry) {\n this.fulfillRequest(list, res.statusCode, res.status);\n return;\n }\n this.handleReponse(res, list);\n } catch (e) {\n this.fulfillRequest(list, 0, String(e));\n }\n }\n\n handleReponse(res: Response, list: Context[]) {\n const { status } = res;\n switch (status) {\n case Status.Success:\n this.handleSuccessResponse(res, list);\n break;\n\n case Status.Invalid:\n this.handleInvalidResponse(res, list);\n break;\n\n case Status.PayloadTooLarge:\n this.handlePayloadTooLargeResponse(res, list);\n break;\n\n case Status.RateLimit:\n this.handleRateLimitResponse(res, list);\n break;\n\n default:\n this.handleOtherReponse(list);\n }\n }\n\n handleSuccessResponse(res: SuccessResponse, list: Context[]) {\n this.fulfillRequest(list, res.statusCode, SUCCESS_MESSAGE);\n }\n\n handleInvalidResponse(res: InvalidResponse, list: Context[]) {\n if (res.body.missingField || res.body.error.startsWith(INVALID_API_KEY)) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n\n const dropIndex = [\n ...Object.values(res.body.eventsWithInvalidFields),\n ...Object.values(res.body.eventsWithMissingFields),\n ...Object.values(res.body.eventsWithInvalidIdLengths),\n ...res.body.silencedEvents,\n ].flat();\n const dropIndexSet = new Set(dropIndex);\n\n const retry = list.filter((context, index) => {\n if (dropIndexSet.has(index)) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handlePayloadTooLargeResponse(res: PayloadTooLargeResponse, list: Context[]) {\n if (list.length === 1) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n this.config.flushQueueSize /= 2;\n this.addToQueue(...list);\n }\n\n handleRateLimitResponse(res: RateLimitResponse, list: Context[]) {\n const dropUserIds = Object.keys(res.body.exceededDailyQuotaUsers);\n const dropDeviceIds = Object.keys(res.body.exceededDailyQuotaDevices);\n const throttledIndex = res.body.throttledEvents;\n const dropUserIdsSet = new Set(dropUserIds);\n const dropDeviceIdsSet = new Set(dropDeviceIds);\n const throttledIndexSet = new Set(throttledIndex);\n\n const retry = list.filter((context, index) => {\n if (\n (context.event.user_id && dropUserIdsSet.has(context.event.user_id)) ||\n (context.event.device_id && dropDeviceIdsSet.has(context.event.device_id))\n ) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n if (throttledIndexSet.has(index)) {\n context.timeout = this.throttleTimeout;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handleOtherReponse(list: Context[]) {\n this.addToQueue(\n ...list.map((context) => {\n context.timeout = context.attempts * this.retryTimeout;\n return context;\n }),\n );\n }\n\n fulfillRequest(list: Context[], code: number, message: string) {\n this.saveEvents();\n list.forEach((context) => context.callback(buildResult(context.event, code, message)));\n }\n\n /**\n * Saves events to storage\n * This is called on\n * 1) new events are added to queue; or\n * 2) response comes back for a request\n */\n saveEvents() {\n if (!this.config.storageProvider) {\n return;\n }\n const events = Array.from(this.queue.map((context) => context.event));\n void this.config.storageProvider.set(this.storageKey, events);\n }\n}\n"]}
|
package/lib/esm/timeline.js
CHANGED
|
@@ -42,7 +42,7 @@ var Timeline = /** @class */ (function () {
|
|
|
42
42
|
};
|
|
43
43
|
Timeline.prototype.scheduleApply = function (timeout) {
|
|
44
44
|
var _this = this;
|
|
45
|
-
if (this.
|
|
45
|
+
if (!this.isReady || this.applying)
|
|
46
46
|
return;
|
|
47
47
|
this.applying = true;
|
|
48
48
|
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,GAAG,KAAK,CAAC;QAChB,YAAO,GAAa,EAAE,CAAC;IAiGzB,CAAC;IA/FO,2BAAQ,GAAd,UAAe,MAAc,EAAE,MAAc;;;;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ugin,\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 isReady = false;\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.isReady = 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.isReady || 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"]}
|
|
@@ -2,6 +2,6 @@ import { BaseEvent, TrackEvent, IdentifyEvent, GroupIdentifyEvent, Identify as I
|
|
|
2
2
|
export declare const createTrackEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => TrackEvent;
|
|
3
3
|
export declare const createIdentifyEvent: (identify: IIdentify, eventOptions?: EventOptions | undefined) => IdentifyEvent;
|
|
4
4
|
export declare const createGroupIdentifyEvent: (groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions | undefined) => GroupIdentifyEvent;
|
|
5
|
-
export declare const createGroupEvent: (groupType: string, groupName: string | string[]) => IdentifyEvent;
|
|
5
|
+
export declare const createGroupEvent: (groupType: string, groupName: string | string[], eventOptions?: EventOptions | undefined) => IdentifyEvent;
|
|
6
6
|
export declare const createRevenueEvent: (revenue: Revenue, eventOptions?: EventOptions | undefined) => RevenueEvent;
|
|
7
7
|
//# sourceMappingURL=event-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,aAAa,EACb,kBAAkB,EAElB,QAAQ,IAAI,SAAS,EACrB,OAAO,EACP,YAAY,EACZ,YAAY,EACb,MAAM,4BAA4B,CAAC;AAGpC,eAAO,MAAM,gBAAgB,eACf,SAAS,GAAG,MAAM,iGAG7B,UAOF,CAAC;AAEF,eAAO,MAAM,mBAAmB,aAAc,SAAS,8CAAgC,aAQtF,CAAC;AAEF,eAAO,MAAM,wBAAwB,cACxB,MAAM,aACN,MAAM,GAAG,MAAM,EAAE,YAClB,SAAS,8CAElB,kBAWF,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAAe,MAAM,aAAa,MAAM,GAAG,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"event-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,aAAa,EACb,kBAAkB,EAElB,QAAQ,IAAI,SAAS,EACrB,OAAO,EACP,YAAY,EACZ,YAAY,EACb,MAAM,4BAA4B,CAAC;AAGpC,eAAO,MAAM,gBAAgB,eACf,SAAS,GAAG,MAAM,iGAG7B,UAOF,CAAC;AAEF,eAAO,MAAM,mBAAmB,aAAc,SAAS,8CAAgC,aAQtF,CAAC;AAEF,eAAO,MAAM,wBAAwB,cACxB,MAAM,aACN,MAAM,GAAG,MAAM,EAAE,YAClB,SAAS,8CAElB,kBAWF,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAAe,MAAM,aAAa,MAAM,GAAG,MAAM,EAAE,2DAa/E,CAAC;AAEF,eAAO,MAAM,kBAAkB,YAAa,OAAO,8CAAgC,YAMlF,CAAC"}
|
|
@@ -16,17 +16,13 @@ export var createGroupIdentifyEvent = function (groupType, groupName, identify,
|
|
|
16
16
|
_a) });
|
|
17
17
|
return groupIdentify;
|
|
18
18
|
};
|
|
19
|
-
export var createGroupEvent = function (groupType, groupName) {
|
|
19
|
+
export var createGroupEvent = function (groupType, groupName, eventOptions) {
|
|
20
20
|
var _a;
|
|
21
21
|
var identify = new Identify();
|
|
22
22
|
identify.set(groupType, groupName);
|
|
23
|
-
var groupEvent = {
|
|
24
|
-
event_type: SpecialEventType.IDENTIFY,
|
|
25
|
-
user_properties: identify.getUserProperties(),
|
|
26
|
-
groups: (_a = {},
|
|
23
|
+
var groupEvent = __assign(__assign({}, eventOptions), { event_type: SpecialEventType.IDENTIFY, user_properties: identify.getUserProperties(), groups: (_a = {},
|
|
27
24
|
_a[groupType] = groupName,
|
|
28
|
-
_a)
|
|
29
|
-
};
|
|
25
|
+
_a) });
|
|
30
26
|
return groupEvent;
|
|
31
27
|
};
|
|
32
28
|
export var createRevenueEvent = function (revenue, eventOptions) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-builder.js","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":";AAAA,OAAO,EAKL,gBAAgB,GAKjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAC9B,UAA8B,EAC9B,eAAqC,EACrC,YAA2B;IAE3B,IAAM,SAAS,GAAc,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;IACtG,sCACK,SAAS,GACT,YAAY,GACZ,CAAC,eAAe,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC,EAC7D;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,mBAAmB,GAAG,UAAC,QAAmB,EAAE,YAA2B;IAClF,IAAM,aAAa,yBACd,YAAY,KACf,UAAU,EAAE,gBAAgB,CAAC,QAAQ,EACrC,eAAe,EAAE,QAAQ,CAAC,iBAAiB,EAAE,GAC9C,CAAC;IAEF,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,wBAAwB,GAAG,UACtC,SAAiB,EACjB,SAA4B,EAC5B,QAAmB,EACnB,YAA2B;;IAE3B,IAAM,aAAa,yBACd,YAAY,KACf,UAAU,EAAE,gBAAgB,CAAC,cAAc,EAC3C,gBAAgB,EAAE,QAAQ,CAAC,iBAAiB,EAAE,EAC9C,MAAM;YACJ,GAAC,SAAS,IAAG,SAAS;kBA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AAE,SAA4B,EAAE,YAA2B;;IAC3G,IAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAEnC,IAAM,UAAU,yBACX,YAAY,KACf,UAAU,EAAE,gBAAgB,CAAC,QAAQ,EACrC,eAAe,EAAE,QAAQ,CAAC,iBAAiB,EAAE,EAC7C,MAAM;YACJ,GAAC,SAAS,IAAG,SAAS;kBAEzB,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,kBAAkB,GAAG,UAAC,OAAgB,EAAE,YAA2B;IAC9E,6BACK,YAAY,KACf,UAAU,EAAE,gBAAgB,CAAC,OAAO,EACpC,gBAAgB,EAAE,OAAO,CAAC,kBAAkB,EAAE,IAC9C;AACJ,CAAC,CAAC","sourcesContent":["import {\n BaseEvent,\n TrackEvent,\n IdentifyEvent,\n GroupIdentifyEvent,\n SpecialEventType,\n Identify as IIdentify,\n Revenue,\n RevenueEvent,\n EventOptions,\n} from '@amplitude/analytics-types';\nimport { Identify } from '../identify';\n\nexport const createTrackEvent = (\n eventInput: BaseEvent | string,\n eventProperties?: Record<string, any>,\n eventOptions?: EventOptions,\n): TrackEvent => {\n const baseEvent: BaseEvent = typeof eventInput === 'string' ? { event_type: eventInput } : eventInput;\n return {\n ...baseEvent,\n ...eventOptions,\n ...(eventProperties && { event_properties: eventProperties }),\n };\n};\n\nexport const createIdentifyEvent = (identify: IIdentify, eventOptions?: EventOptions): IdentifyEvent => {\n const identifyEvent: IdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.IDENTIFY,\n user_properties: identify.getUserProperties(),\n };\n\n return identifyEvent;\n};\n\nexport const createGroupIdentifyEvent = (\n groupType: string,\n groupName: string | string[],\n identify: IIdentify,\n eventOptions?: EventOptions,\n): GroupIdentifyEvent => {\n const groupIdentify: GroupIdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.GROUP_IDENTIFY,\n group_properties: identify.getUserProperties(),\n groups: {\n [groupType]: groupName,\n },\n };\n\n return groupIdentify;\n};\n\nexport const createGroupEvent = (groupType: string, groupName: string | string[], eventOptions?: EventOptions) => {\n const identify = new Identify();\n identify.set(groupType, groupName);\n\n const groupEvent: IdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.IDENTIFY,\n user_properties: identify.getUserProperties(),\n groups: {\n [groupType]: groupName,\n },\n };\n return groupEvent;\n};\n\nexport const createRevenueEvent = (revenue: Revenue, eventOptions?: EventOptions): RevenueEvent => {\n return {\n ...eventOptions,\n event_type: SpecialEventType.REVENUE,\n event_properties: revenue.getEventProperties(),\n };\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/analytics-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Amplitude Inc",
|
|
6
6
|
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@amplitude/analytics-types": "^0.
|
|
36
|
+
"@amplitude/analytics-types": "^0.7.0",
|
|
37
37
|
"tslib": "^2.3.1"
|
|
38
38
|
},
|
|
39
39
|
"files": [
|
|
40
40
|
"lib"
|
|
41
41
|
],
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "d71a39cd63930ee604f0df293767692c09ab54f5"
|
|
43
43
|
}
|