@amplitude/analytics-core 0.5.0 → 0.6.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/config.d.ts +1 -3
- package/lib/cjs/config.d.ts.map +1 -1
- package/lib/cjs/config.js +0 -2
- package/lib/cjs/config.js.map +1 -1
- package/lib/cjs/core-client.d.ts +2 -0
- package/lib/cjs/core-client.d.ts.map +1 -1
- package/lib/cjs/core-client.js +5 -7
- package/lib/cjs/core-client.js.map +1 -1
- package/lib/cjs/plugins/destination.d.ts +11 -9
- package/lib/cjs/plugins/destination.d.ts.map +1 -1
- package/lib/cjs/plugins/destination.js +63 -69
- package/lib/cjs/plugins/destination.js.map +1 -1
- package/lib/cjs/storage/memory.d.ts +6 -6
- package/lib/cjs/storage/memory.d.ts.map +1 -1
- package/lib/cjs/storage/memory.js +40 -7
- package/lib/cjs/storage/memory.js.map +1 -1
- package/lib/cjs/timeline.d.ts +12 -7
- package/lib/cjs/timeline.d.ts.map +1 -1
- package/lib/cjs/timeline.js +154 -138
- package/lib/cjs/timeline.js.map +1 -1
- package/lib/esm/config.d.ts +1 -3
- package/lib/esm/config.d.ts.map +1 -1
- package/lib/esm/config.js +0 -2
- package/lib/esm/config.js.map +1 -1
- package/lib/esm/core-client.d.ts +2 -0
- package/lib/esm/core-client.d.ts.map +1 -1
- package/lib/esm/core-client.js +6 -8
- package/lib/esm/core-client.js.map +1 -1
- package/lib/esm/plugins/destination.d.ts +11 -9
- package/lib/esm/plugins/destination.d.ts.map +1 -1
- package/lib/esm/plugins/destination.js +63 -69
- package/lib/esm/plugins/destination.js.map +1 -1
- package/lib/esm/storage/memory.d.ts +6 -6
- package/lib/esm/storage/memory.d.ts.map +1 -1
- package/lib/esm/storage/memory.js +40 -7
- package/lib/esm/storage/memory.js.map +1 -1
- package/lib/esm/timeline.d.ts +12 -7
- package/lib/esm/timeline.d.ts.map +1 -1
- package/lib/esm/timeline.js +153 -130
- package/lib/esm/timeline.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/storage/memory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/storage/memory.ts"],"names":[],"mappings":";;;AAEA;IAAA;QACE,kBAAa,GAAmB,IAAI,GAAG,EAAE,CAAC;IA0B5C,CAAC;IAxBO,iCAAS,GAAf;;;gBACE,sBAAO,IAAI,EAAC;;;KACb;IAEK,2BAAG,GAAT,UAAU,GAAW;;;gBACnB,sBAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,EAAC;;;KACpC;IAEK,8BAAM,GAAZ,UAAa,GAAW;;;;;4BACR,qBAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAA;;wBAA3B,KAAK,GAAG,SAAmB;wBACjC,sBAAO,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,EAAC;;;;KAClD;IAEK,2BAAG,GAAT,UAAU,GAAW,EAAE,KAAQ;;;gBAC7B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;;;;KACpC;IAEK,8BAAM,GAAZ,UAAa,GAAW;;;gBACtB,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;;;;KAChC;IAEK,6BAAK,GAAX;;;gBACE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;;;;KAC5B;IACH,oBAAC;AAAD,CAAC,AA3BD,IA2BC;AA3BY,sCAAa","sourcesContent":["import { Storage } from '@amplitude/analytics-types';\n\nexport class MemoryStorage<T> implements Storage<T> {\n memoryStorage: Map<string, T> = new Map();\n\n async isEnabled(): Promise<boolean> {\n return true;\n }\n\n async get(key: string): Promise<T | undefined> {\n return this.memoryStorage.get(key);\n }\n\n async getRaw(key: string): Promise<string | undefined> {\n const value = await this.get(key);\n return value ? JSON.stringify(value) : undefined;\n }\n\n async set(key: string, value: T): Promise<void> {\n this.memoryStorage.set(key, value);\n }\n\n async remove(key: string): Promise<void> {\n this.memoryStorage.delete(key);\n }\n\n async reset(): Promise<void> {\n this.memoryStorage.clear();\n }\n}\n"]}
|
package/lib/cjs/timeline.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { Config, Event, EventCallback, Plugin, Result } from '@amplitude/analytics-types';
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
export declare class Timeline {
|
|
3
|
+
queue: [Event, EventCallback][];
|
|
4
|
+
applying: boolean;
|
|
5
|
+
flushing: boolean;
|
|
6
|
+
plugins: Plugin[];
|
|
7
|
+
register(plugin: Plugin, config: Config): Promise<void>;
|
|
8
|
+
deregister(pluginName: string): Promise<void>;
|
|
9
|
+
push(event: Event, config: Config): Promise<Result>;
|
|
10
|
+
scheduleApply(timeout: number): void;
|
|
11
|
+
apply(item: [Event, EventCallback] | undefined): Promise<void>;
|
|
12
|
+
flush(): Promise<void>;
|
|
13
|
+
}
|
|
9
14
|
//# sourceMappingURL=timeline.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,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;AAIpC,qBAAa,QAAQ;IACnB,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,EAAE,CAAM;IACrC,QAAQ,UAAS;IACjB,QAAQ,UAAS;IACjB,OAAO,EAAE,MAAM,EAAE,CAAM;IAEjB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK7C,UAAU,CAAC,UAAU,EAAE,MAAM;IAQ7B,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM;IAWjC,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
|
@@ -1,149 +1,165 @@
|
|
|
1
|
-
var _this = this;
|
|
2
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
2
|
+
exports.Timeline = void 0;
|
|
4
3
|
var tslib_1 = require("tslib");
|
|
5
4
|
var analytics_types_1 = require("@amplitude/analytics-types");
|
|
6
5
|
var messages_1 = require("./messages");
|
|
7
6
|
var result_builder_1 = require("./utils/result-builder");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var scheduleApply = function (timeout) {
|
|
39
|
-
if (applying)
|
|
40
|
-
return;
|
|
41
|
-
applying = true;
|
|
42
|
-
setTimeout(function () {
|
|
43
|
-
void (0, exports.apply)().then(function () {
|
|
44
|
-
applying = false;
|
|
45
|
-
if (exports.queue.length > 0) {
|
|
46
|
-
(0, exports.scheduleApply)(0);
|
|
7
|
+
var Timeline = /** @class */ (function () {
|
|
8
|
+
function Timeline() {
|
|
9
|
+
this.queue = [];
|
|
10
|
+
this.applying = false;
|
|
11
|
+
this.flushing = false;
|
|
12
|
+
this.plugins = [];
|
|
13
|
+
}
|
|
14
|
+
Timeline.prototype.register = function (plugin, config) {
|
|
15
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
16
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
17
|
+
switch (_a.label) {
|
|
18
|
+
case 0: return [4 /*yield*/, plugin.setup(config)];
|
|
19
|
+
case 1:
|
|
20
|
+
_a.sent();
|
|
21
|
+
this.plugins.push(plugin);
|
|
22
|
+
return [2 /*return*/];
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
Timeline.prototype.deregister = function (pluginName) {
|
|
28
|
+
this.plugins.splice(this.plugins.findIndex(function (plugin) { return plugin.name === pluginName; }), 1);
|
|
29
|
+
return Promise.resolve();
|
|
30
|
+
};
|
|
31
|
+
Timeline.prototype.push = function (event, config) {
|
|
32
|
+
var _this = this;
|
|
33
|
+
return new Promise(function (resolve) {
|
|
34
|
+
if (config.optOut) {
|
|
35
|
+
resolve((0, result_builder_1.buildResult)(event, 0, messages_1.OPT_OUT_MESSAGE));
|
|
36
|
+
return;
|
|
47
37
|
}
|
|
38
|
+
_this.queue.push([event, resolve]);
|
|
39
|
+
_this.scheduleApply(0);
|
|
48
40
|
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return [2 /*return*/];
|
|
41
|
+
};
|
|
42
|
+
Timeline.prototype.scheduleApply = function (timeout) {
|
|
43
|
+
var _this = this;
|
|
44
|
+
if (this.applying)
|
|
45
|
+
return;
|
|
46
|
+
this.applying = true;
|
|
47
|
+
setTimeout(function () {
|
|
48
|
+
void _this.apply(_this.queue.shift()).then(function () {
|
|
49
|
+
_this.applying = false;
|
|
50
|
+
if (_this.queue.length > 0) {
|
|
51
|
+
_this.scheduleApply(0);
|
|
61
52
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
53
|
+
});
|
|
54
|
+
}, timeout);
|
|
55
|
+
};
|
|
56
|
+
Timeline.prototype.apply = function (item) {
|
|
57
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
58
|
+
var _a, event, _b, resolve, before, before_1, before_1_1, plugin, e_1_1, enrichment, enrichment_1, enrichment_1_1, plugin, e_2_1, destination, executeDestinations;
|
|
59
|
+
var e_1, _c, e_2, _d;
|
|
60
|
+
return (0, tslib_1.__generator)(this, function (_e) {
|
|
61
|
+
switch (_e.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
if (!item) {
|
|
64
|
+
return [2 /*return*/];
|
|
65
|
+
}
|
|
66
|
+
_a = (0, tslib_1.__read)(item, 1), event = _a[0];
|
|
67
|
+
_b = (0, tslib_1.__read)(item, 2), resolve = _b[1];
|
|
68
|
+
before = this.plugins.filter(function (plugin) { return plugin.type === analytics_types_1.PluginType.BEFORE; });
|
|
69
|
+
_e.label = 1;
|
|
70
|
+
case 1:
|
|
71
|
+
_e.trys.push([1, 6, 7, 8]);
|
|
72
|
+
before_1 = (0, tslib_1.__values)(before), before_1_1 = before_1.next();
|
|
73
|
+
_e.label = 2;
|
|
74
|
+
case 2:
|
|
75
|
+
if (!!before_1_1.done) return [3 /*break*/, 5];
|
|
76
|
+
plugin = before_1_1.value;
|
|
77
|
+
return [4 /*yield*/, plugin.execute((0, tslib_1.__assign)({}, event))];
|
|
78
|
+
case 3:
|
|
79
|
+
event = _e.sent();
|
|
80
|
+
_e.label = 4;
|
|
81
|
+
case 4:
|
|
82
|
+
before_1_1 = before_1.next();
|
|
83
|
+
return [3 /*break*/, 2];
|
|
84
|
+
case 5: return [3 /*break*/, 8];
|
|
85
|
+
case 6:
|
|
86
|
+
e_1_1 = _e.sent();
|
|
87
|
+
e_1 = { error: e_1_1 };
|
|
88
|
+
return [3 /*break*/, 8];
|
|
89
|
+
case 7:
|
|
90
|
+
try {
|
|
91
|
+
if (before_1_1 && !before_1_1.done && (_c = before_1.return)) _c.call(before_1);
|
|
92
|
+
}
|
|
93
|
+
finally { if (e_1) throw e_1.error; }
|
|
94
|
+
return [7 /*endfinally*/];
|
|
95
|
+
case 8:
|
|
96
|
+
enrichment = this.plugins.filter(function (plugin) { return plugin.type === analytics_types_1.PluginType.ENRICHMENT; });
|
|
97
|
+
_e.label = 9;
|
|
98
|
+
case 9:
|
|
99
|
+
_e.trys.push([9, 14, 15, 16]);
|
|
100
|
+
enrichment_1 = (0, tslib_1.__values)(enrichment), enrichment_1_1 = enrichment_1.next();
|
|
101
|
+
_e.label = 10;
|
|
102
|
+
case 10:
|
|
103
|
+
if (!!enrichment_1_1.done) return [3 /*break*/, 13];
|
|
104
|
+
plugin = enrichment_1_1.value;
|
|
105
|
+
return [4 /*yield*/, plugin.execute((0, tslib_1.__assign)({}, event))];
|
|
106
|
+
case 11:
|
|
107
|
+
event = _e.sent();
|
|
108
|
+
_e.label = 12;
|
|
109
|
+
case 12:
|
|
110
|
+
enrichment_1_1 = enrichment_1.next();
|
|
111
|
+
return [3 /*break*/, 10];
|
|
112
|
+
case 13: return [3 /*break*/, 16];
|
|
113
|
+
case 14:
|
|
114
|
+
e_2_1 = _e.sent();
|
|
115
|
+
e_2 = { error: e_2_1 };
|
|
116
|
+
return [3 /*break*/, 16];
|
|
117
|
+
case 15:
|
|
118
|
+
try {
|
|
119
|
+
if (enrichment_1_1 && !enrichment_1_1.done && (_d = enrichment_1.return)) _d.call(enrichment_1);
|
|
120
|
+
}
|
|
121
|
+
finally { if (e_2) throw e_2.error; }
|
|
122
|
+
return [7 /*endfinally*/];
|
|
123
|
+
case 16:
|
|
124
|
+
destination = this.plugins.filter(function (plugin) { return plugin.type === analytics_types_1.PluginType.DESTINATION; });
|
|
125
|
+
executeDestinations = destination.map(function (plugin) {
|
|
126
|
+
var eventClone = (0, tslib_1.__assign)({}, event);
|
|
127
|
+
return plugin.execute(eventClone).catch(function (e) { return (0, result_builder_1.buildResult)(eventClone, 0, String(e)); });
|
|
128
|
+
});
|
|
129
|
+
void Promise.all(executeDestinations).then(function (_a) {
|
|
130
|
+
var _b = (0, tslib_1.__read)(_a, 1), result = _b[0];
|
|
131
|
+
resolve(result);
|
|
132
|
+
});
|
|
133
|
+
return [2 /*return*/];
|
|
88
134
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return [3 /*break*/, 16];
|
|
113
|
-
case 15:
|
|
114
|
-
try {
|
|
115
|
-
if (enrichment_1_1 && !enrichment_1_1.done && (_d = enrichment_1.return)) _d.call(enrichment_1);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
Timeline.prototype.flush = function () {
|
|
139
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
140
|
+
var queue, destination, executeDestinations;
|
|
141
|
+
var _this = this;
|
|
142
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
143
|
+
switch (_a.label) {
|
|
144
|
+
case 0:
|
|
145
|
+
queue = this.queue;
|
|
146
|
+
this.queue = [];
|
|
147
|
+
return [4 /*yield*/, Promise.all(queue.map(function (item) { return _this.apply(item); }))];
|
|
148
|
+
case 1:
|
|
149
|
+
_a.sent();
|
|
150
|
+
destination = this.plugins.filter(function (plugin) { return plugin.type === analytics_types_1.PluginType.DESTINATION; });
|
|
151
|
+
executeDestinations = destination.map(function (plugin) {
|
|
152
|
+
return plugin.flush && plugin.flush();
|
|
153
|
+
});
|
|
154
|
+
return [4 /*yield*/, Promise.all(executeDestinations)];
|
|
155
|
+
case 2:
|
|
156
|
+
_a.sent();
|
|
157
|
+
return [2 /*return*/];
|
|
116
158
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return plugin.execute(eventClone).catch(function (e) { return (0, result_builder_1.buildResult)(eventClone, 0, String(e)); });
|
|
124
|
-
});
|
|
125
|
-
void Promise.all(executeDestinations).then(function (_a) {
|
|
126
|
-
var _b = (0, tslib_1.__read)(_a, 1), result = _b[0];
|
|
127
|
-
resolve(result);
|
|
128
|
-
});
|
|
129
|
-
return [2 /*return*/];
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}); };
|
|
133
|
-
exports.apply = apply;
|
|
134
|
-
var flush = function (config) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
|
|
135
|
-
var destination, flushDestinations;
|
|
136
|
-
return (0, tslib_1.__generator)(this, function (_a) {
|
|
137
|
-
switch (_a.label) {
|
|
138
|
-
case 0:
|
|
139
|
-
destination = config.plugins.filter(function (plugin) { return plugin.type === analytics_types_1.PluginType.DESTINATION; });
|
|
140
|
-
flushDestinations = destination.map(function (plugin) { return plugin.flush && plugin.flush(true); });
|
|
141
|
-
return [4 /*yield*/, Promise.all(flushDestinations)];
|
|
142
|
-
case 1:
|
|
143
|
-
_a.sent();
|
|
144
|
-
return [2 /*return*/];
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}); };
|
|
148
|
-
exports.flush = flush;
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
return Timeline;
|
|
163
|
+
}());
|
|
164
|
+
exports.Timeline = Timeline;
|
|
149
165
|
//# sourceMappingURL=timeline.js.map
|
package/lib/cjs/timeline.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":";;;AAAA,8DAUoC;AACpC,uCAA6C;AAC7C,yDAAqD;AAErD;IAAA;QACE,UAAK,GAA6B,EAAE,CAAC;QACrC,aAAQ,GAAG,KAAK,CAAC;QACjB,aAAQ,GAAG,KAAK,CAAC;QACjB,YAAO,GAAa,EAAE,CAAC;IA+FzB,CAAC;IA7FO,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,uBAAI,GAAJ,UAAK,KAAY,EAAE,MAAc;QAAjC,iBASC;QARC,OAAO,IAAI,OAAO,CAAS,UAAC,OAAO;YACjC,IAAI,MAAM,CAAC,MAAM,EAAE;gBACjB,OAA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,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,AAnGD,IAmGC;AAnGY,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 { OPT_OUT_MESSAGE } from './messages';\nimport { buildResult } from './utils/result-builder';\n\nexport class Timeline {\n queue: [Event, EventCallback][] = [];\n applying = false;\n flushing = 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 push(event: Event, config: Config) {\n return new Promise<Result>((resolve) => {\n if (config.optOut) {\n resolve(buildResult(event, 0, OPT_OUT_MESSAGE));\n return;\n }\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/config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Event, Config as IConfig, Logger as ILogger, InitOptions, LogLevel, Storage, Transport, Plan,
|
|
1
|
+
import { Event, Config as IConfig, Logger as ILogger, InitOptions, LogLevel, Storage, Transport, Plan, ServerZone } from '@amplitude/analytics-types';
|
|
2
2
|
import { Logger } from './logger';
|
|
3
3
|
export declare const getDefaultConfig: () => {
|
|
4
4
|
flushMaxRetries: number;
|
|
@@ -8,7 +8,6 @@ export declare const getDefaultConfig: () => {
|
|
|
8
8
|
loggerProvider: Logger;
|
|
9
9
|
saveEvents: boolean;
|
|
10
10
|
optOut: boolean;
|
|
11
|
-
plugins: never[];
|
|
12
11
|
serverUrl: string;
|
|
13
12
|
serverZone: ServerZone;
|
|
14
13
|
useBatch: boolean;
|
|
@@ -22,7 +21,6 @@ export declare class Config implements IConfig {
|
|
|
22
21
|
logLevel: LogLevel;
|
|
23
22
|
minIdLength?: number;
|
|
24
23
|
plan?: Plan;
|
|
25
|
-
plugins: Plugin[];
|
|
26
24
|
saveEvents: boolean;
|
|
27
25
|
serverUrl: string | undefined;
|
|
28
26
|
serverZone?: ServerZone;
|
package/lib/esm/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,IAAI,OAAO,EACjB,MAAM,IAAI,OAAO,EACjB,WAAW,EACX,QAAQ,EACR,OAAO,EACP,SAAS,EACT,IAAI,EACJ,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,IAAI,OAAO,EACjB,MAAM,IAAI,OAAO,EACjB,WAAW,EACX,QAAQ,EACR,OAAO,EACP,SAAS,EACT,IAAI,EACJ,UAAU,EACX,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,eAAO,MAAM,gBAAgB;;;;;;;;;;;CAW3B,CAAC;AAEH,qBAAa,MAAO,YAAW,OAAO;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,eAAe,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IAClC,QAAQ,EAAE,OAAO,CAAC;IAElB,OAAO,CAAC,OAAO,CAAS;IACxB,IAAI,MAAM,IAGS,OAAO,CADzB;IACD,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,EAEzB;gBAEW,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC;CAuB1C;AAED,eAAO,MAAM,YAAY,eAAgB,UAAU,YAAY,OAAO,kKAKrE,CAAC;AAEF,eAAO,MAAM,kBAAkB,oCAEjB,UAAU,aACZ,OAAO;;;;;;CAUlB,CAAC"}
|
package/lib/esm/config.js
CHANGED
|
@@ -9,7 +9,6 @@ export var getDefaultConfig = function () { return ({
|
|
|
9
9
|
loggerProvider: new Logger(),
|
|
10
10
|
saveEvents: true,
|
|
11
11
|
optOut: false,
|
|
12
|
-
plugins: [],
|
|
13
12
|
serverUrl: AMPLITUDE_SERVER_URL,
|
|
14
13
|
serverZone: ServerZone.US,
|
|
15
14
|
useBatch: false,
|
|
@@ -27,7 +26,6 @@ var Config = /** @class */ (function () {
|
|
|
27
26
|
this.logLevel = (_a = options.logLevel) !== null && _a !== void 0 ? _a : defaultConfig.logLevel;
|
|
28
27
|
this.minIdLength = options.minIdLength;
|
|
29
28
|
this.plan = options.plan;
|
|
30
|
-
this.plugins = defaultConfig.plugins;
|
|
31
29
|
this.optOut = (_b = options.optOut) !== null && _b !== void 0 ? _b : defaultConfig.optOut;
|
|
32
30
|
this.saveEvents = (_c = options.saveEvents) !== null && _c !== void 0 ? _c : defaultConfig.saveEvents;
|
|
33
31
|
this.serverUrl = options.serverUrl;
|
package/lib/esm/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.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I,UAAU,KAAK,UAAU,CAAC,EAAE,EAAE;QAChC,OAAO,QAAQ,CAAC,CAAC,CAAC,6BAA6B,CAAC,CAAC,CAAC,uBAAuB,CAAC;KAC3E;IACD,OAAO,QAAQ,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,oBAAoB,CAAC;AACtE,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,kBAAkB,GAAG,UAChC,SAAc,EACd,UAAsD,EACtD,QAA+C;IAF/C,0BAAA,EAAA,cAAc;IACd,2BAAA,EAAA,aAAyB,gBAAgB,EAAE,CAAC,UAAU;IACtD,yBAAA,EAAA,WAAoB,gBAAgB,EAAE,CAAC,QAAQ;IAE/C,IAAI,SAAS,EAAE;QACb,OAAO,EAAE,SAAS,WAAA,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;KAC7C;IACD,IAAM,WAAW,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC,UAAU,CAAC;IACrH,OAAO;QACL,UAAU,EAAE,WAAW;QACvB,SAAS,EAAE,YAAY,CAAC,WAAW,EAAE,QAAQ,CAAC;KAC/C,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n Event,\n Config as IConfig,\n Logger as ILogger,\n InitOptions,\n LogLevel,\n Storage,\n Transport,\n Plan,\n ServerZone,\n} from '@amplitude/analytics-types';\nimport {\n AMPLITUDE_SERVER_URL,\n AMPLITUDE_BATCH_SERVER_URL,\n EU_AMPLITUDE_SERVER_URL,\n EU_AMPLITUDE_BATCH_SERVER_URL,\n} from './constants';\n\nimport { Logger } from './logger';\n\nexport const getDefaultConfig = () => ({\n flushMaxRetries: 5,\n flushQueueSize: 10,\n flushIntervalMillis: 1000,\n logLevel: LogLevel.Warn,\n loggerProvider: new Logger(),\n saveEvents: true,\n optOut: false,\n serverUrl: AMPLITUDE_SERVER_URL,\n serverZone: ServerZone.US,\n useBatch: false,\n});\n\nexport class Config implements IConfig {\n apiKey: string;\n flushIntervalMillis: number;\n flushMaxRetries: number;\n flushQueueSize: number;\n loggerProvider: ILogger;\n logLevel: LogLevel;\n minIdLength?: number;\n plan?: Plan;\n saveEvents: boolean;\n serverUrl: string | undefined;\n serverZone?: ServerZone;\n transportProvider: Transport;\n storageProvider: Storage<Event[]>;\n useBatch: boolean;\n\n private _optOut = false;\n get optOut() {\n return this._optOut;\n }\n set optOut(optOut: boolean) {\n this._optOut = optOut;\n }\n\n constructor(options: InitOptions<IConfig>) {\n const defaultConfig = getDefaultConfig();\n this.apiKey = options.apiKey;\n this.flushIntervalMillis = options.flushIntervalMillis || defaultConfig.flushIntervalMillis;\n this.flushMaxRetries = options.flushMaxRetries || defaultConfig.flushMaxRetries;\n this.flushQueueSize = options.flushQueueSize || defaultConfig.flushQueueSize;\n this.loggerProvider = options.loggerProvider || defaultConfig.loggerProvider;\n this.logLevel = options.logLevel ?? defaultConfig.logLevel;\n this.minIdLength = options.minIdLength;\n this.plan = options.plan;\n this.optOut = options.optOut ?? defaultConfig.optOut;\n this.saveEvents = options.saveEvents ?? defaultConfig.saveEvents;\n this.serverUrl = options.serverUrl;\n this.serverZone = options.serverZone || defaultConfig.serverZone;\n this.storageProvider = options.storageProvider;\n this.transportProvider = options.transportProvider;\n this.useBatch = options.useBatch ?? defaultConfig.useBatch;\n this.loggerProvider.enable(this.logLevel);\n\n const serverConfig = createServerConfig(options.serverUrl, options.serverZone, options.useBatch);\n this.serverZone = serverConfig.serverZone;\n this.serverUrl = serverConfig.serverUrl;\n }\n}\n\nexport const getServerUrl = (serverZone: ServerZone, useBatch: boolean) => {\n if (serverZone === ServerZone.EU) {\n return useBatch ? EU_AMPLITUDE_BATCH_SERVER_URL : EU_AMPLITUDE_SERVER_URL;\n }\n return useBatch ? AMPLITUDE_BATCH_SERVER_URL : AMPLITUDE_SERVER_URL;\n};\n\nexport const createServerConfig = (\n serverUrl = '',\n serverZone: ServerZone = getDefaultConfig().serverZone,\n useBatch: boolean = getDefaultConfig().useBatch,\n) => {\n if (serverUrl) {\n return { serverUrl, serverZone: undefined };\n }\n const _serverZone = [ServerZone.US, ServerZone.EU].includes(serverZone) ? serverZone : getDefaultConfig().serverZone;\n return {\n serverZone: _serverZone,\n serverUrl: getServerUrl(_serverZone, useBatch),\n };\n};\n"]}
|
package/lib/esm/core-client.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { CoreClient, Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types';
|
|
2
|
+
import { Timeline } from './timeline';
|
|
2
3
|
export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
|
|
3
4
|
name: string;
|
|
4
5
|
config: T;
|
|
6
|
+
timeline: Timeline;
|
|
5
7
|
constructor(name?: string);
|
|
6
8
|
init(_apiKey: string | undefined, _userId: string | undefined, config: T): Promise<void>;
|
|
7
9
|
track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
@@ -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;
|
|
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;AAEtC,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;gBAEP,IAAI,SAAa;IAK7B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,CAAC;IAMxE,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;IAKxD,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,YAAY;IAK/C,GAAG,CAAC,MAAM,EAAE,MAAM;IAKlB,MAAM,CAAC,UAAU,EAAE,MAAM;IAIzB,QAAQ,CAAC,KAAK,EAAE,KAAK;IAgB3B,SAAS,CAAC,MAAM,EAAE,OAAO;IAKzB,KAAK;CAGN"}
|
package/lib/esm/core-client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter, __generator } from "tslib";
|
|
2
2
|
import { createGroupIdentifyEvent, createIdentifyEvent, createTrackEvent, createRevenueEvent, createGroupEvent, } from './utils/event-builder';
|
|
3
|
-
import {
|
|
3
|
+
import { Timeline } from './timeline';
|
|
4
4
|
import { buildResult } from './utils/result-builder';
|
|
5
5
|
var AmplitudeCore = /** @class */ (function () {
|
|
6
6
|
function AmplitudeCore(name) {
|
|
@@ -11,6 +11,7 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
11
11
|
// NOTE: Do not use `_apiKey` and `_userId` here
|
|
12
12
|
AmplitudeCore.prototype.init = function (_apiKey, _userId, config) {
|
|
13
13
|
this.config = config;
|
|
14
|
+
this.timeline = new Timeline();
|
|
14
15
|
return Promise.resolve();
|
|
15
16
|
};
|
|
16
17
|
AmplitudeCore.prototype.track = function (eventInput, eventProperties, eventOptions) {
|
|
@@ -38,16 +39,14 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
38
39
|
var config;
|
|
39
40
|
return __generator(this, function (_a) {
|
|
40
41
|
config = this.config;
|
|
41
|
-
return [2 /*return*/, register(plugin, config)];
|
|
42
|
+
return [2 /*return*/, this.timeline.register(plugin, config)];
|
|
42
43
|
});
|
|
43
44
|
});
|
|
44
45
|
};
|
|
45
46
|
AmplitudeCore.prototype.remove = function (pluginName) {
|
|
46
47
|
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var config;
|
|
48
48
|
return __generator(this, function (_a) {
|
|
49
|
-
|
|
50
|
-
return [2 /*return*/, deregister(pluginName, config)];
|
|
49
|
+
return [2 /*return*/, this.timeline.deregister(pluginName)];
|
|
51
50
|
});
|
|
52
51
|
});
|
|
53
52
|
};
|
|
@@ -58,7 +57,7 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
58
57
|
switch (_a.label) {
|
|
59
58
|
case 0:
|
|
60
59
|
_a.trys.push([0, 2, , 3]);
|
|
61
|
-
return [4 /*yield*/, push(event, this.config)];
|
|
60
|
+
return [4 /*yield*/, this.timeline.push(event, this.config)];
|
|
62
61
|
case 1:
|
|
63
62
|
result = _a.sent();
|
|
64
63
|
if (result.code === 200) {
|
|
@@ -83,8 +82,7 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
83
82
|
config.optOut = Boolean(optOut);
|
|
84
83
|
};
|
|
85
84
|
AmplitudeCore.prototype.flush = function () {
|
|
86
|
-
|
|
87
|
-
return flush(config);
|
|
85
|
+
return this.timeline.flush();
|
|
88
86
|
};
|
|
89
87
|
return AmplitudeCore;
|
|
90
88
|
}());
|
|
@@ -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;AAC/B,OAAO,EAAE,
|
|
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;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD;IASE,uBAAY,IAAiB;QAAjB,qBAAA,EAAA,iBAAiB;QAgB7B,aAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAf/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,gDAAgD;IAChD,4BAAI,GAAJ,UAAK,OAA2B,EAAE,OAA2B,EAAE,MAAS;QACtE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC/B,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,6BAAK,GAAL,UAAM,UAA8B,EAAE,eAAqC,EAAE,YAA2B;QACtG,IAAM,KAAK,GAAG,gBAAgB,CAAC,UAAU,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC,QAA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AM,CAAC,EAAA;;wBAArD,MAAM,GAAG,SAA4C;wBAC3D,IAAI,MAAM,CAAC,IAAI,KAAK,GAAG,EAAE;4BACvB,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;yBAChD;6BAAM;4BACL,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;yBAClD;wBACD,sBAAO,MAAM,EAAC;;;wBAER,OAAO,GAAG,MAAM,CAAC,GAAC,CAAC,CAAC;wBAC1B,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;wBAC1C,sBAAO,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,EAAC;;;;;KAEzC;IAED,iCAAS,GAAT,UAAU,MAAe;QACvB,IAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAED,6BAAK,GAAL;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IACH,oBAAC;AAAD,CAAC,AAhFD,IAgFC","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';\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\n constructor(name = '$default') {\n this.name = name;\n }\n\n // NOTE: Do not use `_apiKey` and `_userId` here\n init(_apiKey: string | undefined, _userId: string | undefined, config: T) {\n this.config = config;\n this.timeline = new Timeline();\n return Promise.resolve();\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[]) {\n const event = createGroupEvent(groupType, groupName);\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 const config = this.config;\n return this.timeline.register(plugin, config);\n }\n\n async remove(pluginName: string) {\n return this.timeline.deregister(pluginName);\n }\n\n async dispatch(event: Event) {\n try {\n const result = await this.timeline.push(event, this.config);\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 const config = this.config;\n config.optOut = Boolean(optOut);\n }\n\n flush() {\n return this.timeline.flush();\n }\n}\n"]}
|
|
@@ -2,20 +2,18 @@ import { Config, DestinationContext as Context, DestinationPlugin, Event, Invali
|
|
|
2
2
|
export declare class Destination implements DestinationPlugin {
|
|
3
3
|
name: string;
|
|
4
4
|
type: PluginType.DESTINATION;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
retryTimeout: number;
|
|
6
|
+
throttleTimeout: number;
|
|
7
7
|
storageKey: string;
|
|
8
|
-
backup: Set<Event>;
|
|
9
8
|
config: Config;
|
|
10
9
|
scheduled: boolean;
|
|
11
10
|
queue: Context[];
|
|
12
|
-
queueBuffer: Set<Context>;
|
|
13
11
|
setup(config: Config): Promise<undefined>;
|
|
14
12
|
execute(event: Event): Promise<Result>;
|
|
15
13
|
addToQueue(...list: Context[]): void;
|
|
16
14
|
schedule(timeout: number): void;
|
|
17
|
-
flush(
|
|
18
|
-
send(list: Context[]): Promise<void>;
|
|
15
|
+
flush(useRetry?: boolean): Promise<void>;
|
|
16
|
+
send(list: Context[], useRetry?: boolean): Promise<void>;
|
|
19
17
|
handleReponse(res: Response, list: Context[]): void;
|
|
20
18
|
handleSuccessResponse(res: SuccessResponse, list: Context[]): void;
|
|
21
19
|
handleInvalidResponse(res: InvalidResponse, list: Context[]): void;
|
|
@@ -23,8 +21,12 @@ export declare class Destination implements DestinationPlugin {
|
|
|
23
21
|
handleRateLimitResponse(res: RateLimitResponse, list: Context[]): void;
|
|
24
22
|
handleOtherReponse(list: Context[]): void;
|
|
25
23
|
fulfillRequest(list: Context[], code: number, message: string): void;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Saves events to storage
|
|
26
|
+
* This is called on
|
|
27
|
+
* 1) new events are added to queue; or
|
|
28
|
+
* 2) response comes back for a request
|
|
29
|
+
*/
|
|
30
|
+
saveEvents(): void;
|
|
29
31
|
}
|
|
30
32
|
//# sourceMappingURL=destination.d.ts.map
|