@amplitude/analytics-core 0.9.6 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { CoreClient, Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types';
1
+ import { CoreClient, Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue, Result } from '@amplitude/analytics-types';
2
2
  import { Timeline } from './timeline';
3
3
  export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
4
4
  initializing: boolean;
@@ -6,22 +6,21 @@ export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
6
6
  config: T;
7
7
  timeline: Timeline;
8
8
  protected q: CallableFunction[];
9
- protected pluginQueue: CallableFunction[];
9
+ protected dispatchQ: CallableFunction[];
10
10
  constructor(name?: string);
11
11
  _init(config: T): Promise<void>;
12
- protected getAndResetQueuedFunctions(): CallableFunction[];
13
- protected runQueuedFunctions(): Promise<void>;
14
- protected getAndResetQueuedPluginFunctions(): CallableFunction[];
15
- protected runQueuedPluginFunctions(): Promise<void>;
16
- track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
17
- logEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>;
18
- identify(identify: Identify, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
19
- groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
20
- setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
21
- revenue(revenue: Revenue, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
12
+ runQueuedFunctions(queueName: 'q' | 'dispatchQ'): Promise<void>;
13
+ track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): Promise<Result>;
14
+ logEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<Result>;
15
+ identify(identify: Identify, eventOptions?: EventOptions): Promise<Result>;
16
+ groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions): Promise<Result>;
17
+ setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions): Promise<Result>;
18
+ revenue(revenue: Revenue, eventOptions?: EventOptions): Promise<Result>;
22
19
  add(plugin: Plugin): Promise<void>;
23
20
  remove(pluginName: string): Promise<void>;
24
- dispatch(event: Event): Promise<import("@amplitude/analytics-types").Result>;
21
+ dispatchWithCallback(event: Event, callback: (result: Result) => void): void;
22
+ dispatch(event: Event): Promise<Result>;
23
+ process(event: Event): Promise<Result>;
25
24
  setOptOut(optOut: boolean): void;
26
25
  flush(): Promise<void>;
27
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,MAAM,EACN,KAAK,EACL,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,OAAO,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,YAAY,UAAS;IACrB,IAAI,EAAE,MAAM,CAAC;IAGb,MAAM,EAAE,CAAC,CAAC;IAGV,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAM;IACrC,SAAS,CAAC,WAAW,EAAE,gBAAgB,EAAE,CAAM;gBAEnC,IAAI,SAAa;IAKvB,KAAK,CAAC,MAAM,EAAE,CAAC;IAOrB,SAAS,CAAC,0BAA0B;cAMpB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= '$default'; }
11
11
  this.initializing = false;
12
12
  this.q = [];
13
- this.pluginQueue = [];
13
+ this.dispatchQ = [];
14
14
  this.logEvent = this.track.bind(this);
15
15
  this.timeline = new timeline_1.Timeline();
16
16
  this.name = name;
@@ -22,30 +22,23 @@ var AmplitudeCore = /** @class */ (function () {
22
22
  case 0:
23
23
  this.config = config;
24
24
  this.timeline.reset();
25
- return [4 /*yield*/, this.runQueuedPluginFunctions()];
25
+ return [4 /*yield*/, this.runQueuedFunctions('q')];
26
26
  case 1:
27
- _a.sent();
28
- return [4 /*yield*/, this.runQueuedFunctions()];
29
- case 2:
30
27
  _a.sent();
31
28
  return [2 /*return*/];
32
29
  }
33
30
  });
34
31
  });
35
32
  };
36
- AmplitudeCore.prototype.getAndResetQueuedFunctions = function () {
37
- var queuedFunctions = this.q;
38
- this.q = [];
39
- return queuedFunctions;
40
- };
41
- AmplitudeCore.prototype.runQueuedFunctions = function () {
33
+ AmplitudeCore.prototype.runQueuedFunctions = function (queueName) {
42
34
  return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
43
35
  var queuedFunctions, queuedFunctions_1, queuedFunctions_1_1, queuedFunction, e_1_1;
44
36
  var e_1, _a;
45
37
  return (0, tslib_1.__generator)(this, function (_b) {
46
38
  switch (_b.label) {
47
39
  case 0:
48
- queuedFunctions = this.getAndResetQueuedFunctions();
40
+ queuedFunctions = this[queueName];
41
+ this[queueName] = [];
49
42
  _b.label = 1;
50
43
  case 1:
51
44
  _b.trys.push([1, 6, 7, 8]);
@@ -77,50 +70,6 @@ var AmplitudeCore = /** @class */ (function () {
77
70
  });
78
71
  });
79
72
  };
80
- AmplitudeCore.prototype.getAndResetQueuedPluginFunctions = function () {
81
- var queuedFunctions = this.pluginQueue;
82
- this.pluginQueue = [];
83
- return queuedFunctions;
84
- };
85
- AmplitudeCore.prototype.runQueuedPluginFunctions = function () {
86
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
87
- var queuedFunctions, queuedFunctions_2, queuedFunctions_2_1, queuedFunction, e_2_1;
88
- var e_2, _a;
89
- return (0, tslib_1.__generator)(this, function (_b) {
90
- switch (_b.label) {
91
- case 0:
92
- queuedFunctions = this.getAndResetQueuedPluginFunctions();
93
- _b.label = 1;
94
- case 1:
95
- _b.trys.push([1, 6, 7, 8]);
96
- queuedFunctions_2 = (0, tslib_1.__values)(queuedFunctions), queuedFunctions_2_1 = queuedFunctions_2.next();
97
- _b.label = 2;
98
- case 2:
99
- if (!!queuedFunctions_2_1.done) return [3 /*break*/, 5];
100
- queuedFunction = queuedFunctions_2_1.value;
101
- return [4 /*yield*/, queuedFunction()];
102
- case 3:
103
- _b.sent();
104
- _b.label = 4;
105
- case 4:
106
- queuedFunctions_2_1 = queuedFunctions_2.next();
107
- return [3 /*break*/, 2];
108
- case 5: return [3 /*break*/, 8];
109
- case 6:
110
- e_2_1 = _b.sent();
111
- e_2 = { error: e_2_1 };
112
- return [3 /*break*/, 8];
113
- case 7:
114
- try {
115
- if (queuedFunctions_2_1 && !queuedFunctions_2_1.done && (_a = queuedFunctions_2.return)) _a.call(queuedFunctions_2);
116
- }
117
- finally { if (e_2) throw e_2.error; }
118
- return [7 /*endfinally*/];
119
- case 8: return [2 /*return*/];
120
- }
121
- });
122
- });
123
- };
124
73
  AmplitudeCore.prototype.track = function (eventInput, eventProperties, eventOptions) {
125
74
  var event = (0, event_builder_1.createTrackEvent)(eventInput, eventProperties, eventOptions);
126
75
  return this.dispatch(event);
@@ -145,7 +94,7 @@ var AmplitudeCore = /** @class */ (function () {
145
94
  return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
146
95
  return (0, tslib_1.__generator)(this, function (_a) {
147
96
  if (!this.config) {
148
- this.pluginQueue.push(this.add.bind(this, plugin));
97
+ this.q.push(this.add.bind(this, plugin));
149
98
  return [2 /*return*/];
150
99
  }
151
100
  return [2 /*return*/, this.timeline.register(plugin, this.config)];
@@ -156,40 +105,56 @@ var AmplitudeCore = /** @class */ (function () {
156
105
  return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
157
106
  return (0, tslib_1.__generator)(this, function (_a) {
158
107
  if (!this.config) {
159
- this.pluginQueue.push(this.remove.bind(this, pluginName));
108
+ this.q.push(this.remove.bind(this, pluginName));
160
109
  return [2 /*return*/];
161
110
  }
162
111
  return [2 /*return*/, this.timeline.deregister(pluginName)];
163
112
  });
164
113
  });
165
114
  };
115
+ AmplitudeCore.prototype.dispatchWithCallback = function (event, callback) {
116
+ if (!this.config) {
117
+ return callback((0, result_builder_1.buildResult)(event, 0, messages_1.CLIENT_NOT_INITIALIZED));
118
+ }
119
+ void this.process(event).then(callback);
120
+ };
166
121
  AmplitudeCore.prototype.dispatch = function (event) {
167
- var _a;
168
122
  return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
169
- var result, e_3, message;
170
- return (0, tslib_1.__generator)(this, function (_b) {
171
- switch (_b.label) {
123
+ var _this = this;
124
+ return (0, tslib_1.__generator)(this, function (_a) {
125
+ if (!this.config) {
126
+ return [2 /*return*/, new Promise(function (resolve) {
127
+ _this.dispatchQ.push(_this.dispatchWithCallback.bind(_this, event, resolve));
128
+ })];
129
+ }
130
+ return [2 /*return*/, this.process(event)];
131
+ });
132
+ });
133
+ };
134
+ AmplitudeCore.prototype.process = function (event) {
135
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
136
+ var result, e_2, message, result;
137
+ return (0, tslib_1.__generator)(this, function (_a) {
138
+ switch (_a.label) {
172
139
  case 0:
173
- _b.trys.push([0, 2, , 3]);
140
+ _a.trys.push([0, 2, , 3]);
174
141
  // skip event processing if opt out
175
- if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.optOut) {
142
+ if (this.config.optOut) {
176
143
  return [2 /*return*/, (0, result_builder_1.buildResult)(event, 0, messages_1.OPT_OUT_MESSAGE)];
177
144
  }
178
145
  return [4 /*yield*/, this.timeline.push(event)];
179
146
  case 1:
180
- result = _b.sent();
181
- if (result.code === 200) {
182
- this.config.loggerProvider.log(result.message);
183
- }
184
- else {
185
- this.config.loggerProvider.error(result.message);
186
- }
147
+ result = _a.sent();
148
+ result.code === 200
149
+ ? this.config.loggerProvider.log(result.message)
150
+ : this.config.loggerProvider.error(result.message);
187
151
  return [2 /*return*/, result];
188
152
  case 2:
189
- e_3 = _b.sent();
190
- message = String(e_3);
153
+ e_2 = _a.sent();
154
+ message = String(e_2);
191
155
  this.config.loggerProvider.error(message);
192
- return [2 /*return*/, (0, result_builder_1.buildResult)(event, 0, message)];
156
+ result = (0, result_builder_1.buildResult)(event, 0, message);
157
+ return [2 /*return*/, result];
193
158
  case 3: return [2 /*return*/];
194
159
  }
195
160
  });
@@ -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;IAYE,uBAAY,IAAiB;QAAjB,qBAAA,EAAA,iBAAiB;QAX7B,iBAAY,GAAG,KAAK,CAAC;QAQX,MAAC,GAAuB,EAAE,CAAC;QAC3B,gBAAW,GAAuB,EAAE,CAAC;QA6C/C,aAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QA1C/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;wBACtB,qBAAM,IAAI,CAAC,wBAAwB,EAAE,EAAA;;wBAArC,SAAqC,CAAC;wBACtC,qBAAM,IAAI,CAAC,kBAAkB,EAAE,EAAA;;wBAA/B,SAA+B,CAAC;;;;;KACjC;IAES,kDAA0B,GAApC;QACE,IAAM,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC;QA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AAW,EAAC,KAAK,EAAE,CAAC,EAAE,0BAAe,CAAC,EAAC;yBAC/C;wBACc,qBAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAA;;wBAAxC,MAAM,GAAG,SAA+B;wBAC9C,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,IAAA,4BAAW,EAAC,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,EAAC;;;;;KAEzC;IAED,iCAAS,GAAT,UAAU,MAAe;QACvB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACxD,OAAO;SACR;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,6BAAK,GAAL;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IACH,oBAAC;AAAD,CAAC,AA5HD,IA4HC;AA5HY,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 initializing = false;\n name: string;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: T;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n timeline: Timeline;\n protected q: CallableFunction[] = [];\n protected pluginQueue: CallableFunction[] = [];\n\n constructor(name = '$default') {\n this.timeline = new Timeline();\n this.name = name;\n }\n\n async _init(config: T) {\n this.config = config;\n this.timeline.reset();\n await this.runQueuedPluginFunctions();\n await this.runQueuedFunctions();\n }\n\n protected getAndResetQueuedFunctions() {\n const queuedFunctions = this.q;\n this.q = [];\n return queuedFunctions;\n }\n\n protected async runQueuedFunctions() {\n const queuedFunctions = this.getAndResetQueuedFunctions();\n for (const queuedFunction of queuedFunctions) {\n await queuedFunction();\n }\n }\n\n protected getAndResetQueuedPluginFunctions() {\n const queuedFunctions = this.pluginQueue;\n this.pluginQueue = [];\n return queuedFunctions;\n }\n\n protected async runQueuedPluginFunctions() {\n const queuedFunctions = this.getAndResetQueuedPluginFunctions();\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.pluginQueue.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.pluginQueue.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
+ {"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";;;AAWA,uDAM+B;AAC/B,uCAAsC;AACtC,yDAAqD;AACrD,uCAAqE;AAErE;IAYE,uBAAY,IAAiB;QAAjB,qBAAA,EAAA,iBAAiB;QAX7B,iBAAY,GAAG,KAAK,CAAC;QAQX,MAAC,GAAuB,EAAE,CAAC;QAC3B,cAAS,GAAuB,EAAE,CAAC;QA0B7C,aAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAvB/B,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEK,6BAAK,GAAX,UAAY,MAAS;;;;;wBACnB,IAAI,CAAC,M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E,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACxD,OAAO;SACR;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,6BAAK,GAAL;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IACH,oBAAC;AAAD,CAAC,AA7HD,IA6HC;AA7HY,sCAAa","sourcesContent":["import {\n CoreClient,\n Config,\n Event,\n BaseEvent,\n EventOptions,\n Identify,\n Plugin,\n Revenue,\n Result,\n} from '@amplitude/analytics-types';\nimport {\n createGroupIdentifyEvent,\n createIdentifyEvent,\n createTrackEvent,\n createRevenueEvent,\n createGroupEvent,\n} from './utils/event-builder';\nimport { Timeline } from './timeline';\nimport { buildResult } from './utils/result-builder';\nimport { CLIENT_NOT_INITIALIZED, OPT_OUT_MESSAGE } from './messages';\n\nexport class AmplitudeCore<T extends Config> implements CoreClient<T> {\n initializing = false;\n name: string;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: T;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n timeline: Timeline;\n protected q: CallableFunction[] = [];\n protected dispatchQ: CallableFunction[] = [];\n\n constructor(name = '$default') {\n this.timeline = new Timeline();\n this.name = name;\n }\n\n async _init(config: T) {\n this.config = config;\n this.timeline.reset();\n await this.runQueuedFunctions('q');\n }\n\n async runQueuedFunctions(queueName: 'q' | 'dispatchQ') {\n const queuedFunctions = this[queueName];\n this[queueName] = [];\n for (const queuedFunction of queuedFunctions) {\n await queuedFunction();\n }\n }\n\n track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions) {\n const event = createTrackEvent(eventInput, eventProperties, eventOptions);\n return this.dispatch(event);\n }\n\n logEvent = this.track.bind(this);\n\n identify(identify: Identify, eventOptions?: EventOptions) {\n const event = createIdentifyEvent(identify, eventOptions);\n return this.dispatch(event);\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions) {\n const event = createGroupIdentifyEvent(groupType, groupName, identify, eventOptions);\n return this.dispatch(event);\n }\n\n setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions) {\n const event = createGroupEvent(groupType, groupName, eventOptions);\n return this.dispatch(event);\n }\n\n revenue(revenue: Revenue, eventOptions?: EventOptions) {\n const event = createRevenueEvent(revenue, eventOptions);\n return this.dispatch(event);\n }\n\n async add(plugin: Plugin) {\n if (!this.config) {\n this.q.push(this.add.bind(this, plugin));\n return;\n }\n return this.timeline.register(plugin, this.config);\n }\n\n async remove(pluginName: string) {\n if (!this.config) {\n this.q.push(this.remove.bind(this, pluginName));\n return;\n }\n return this.timeline.deregister(pluginName);\n }\n\n dispatchWithCallback(event: Event, callback: (result: Result) => void): void {\n if (!this.config) {\n return callback(buildResult(event, 0, CLIENT_NOT_INITIALIZED));\n }\n void this.process(event).then(callback);\n }\n\n async dispatch(event: Event): Promise<Result> {\n if (!this.config) {\n return new Promise<Result>((resolve) => {\n this.dispatchQ.push(this.dispatchWithCallback.bind(this, event, resolve));\n });\n }\n\n return this.process(event);\n }\n\n async process(event: Event): Promise<Result> {\n try {\n // skip event processing if opt out\n if (this.config.optOut) {\n return buildResult(event, 0, OPT_OUT_MESSAGE);\n }\n\n const result = await this.timeline.push(event);\n\n result.code === 200\n ? this.config.loggerProvider.log(result.message)\n : this.config.loggerProvider.error(result.message);\n\n return result;\n } catch (e) {\n const message = String(e);\n this.config.loggerProvider.error(message);\n const result = buildResult(event, 0, message);\n\n return result;\n }\n }\n\n setOptOut(optOut: boolean) {\n if (!this.config) {\n this.q.push(this.setOptOut.bind(this, Boolean(optOut)));\n return;\n }\n this.config.optOut = Boolean(optOut);\n }\n\n flush() {\n return this.timeline.flush();\n }\n}\n"]}
@@ -4,4 +4,5 @@ export declare const MAX_RETRIES_EXCEEDED_MESSAGE = "Event rejected due to excee
4
4
  export declare const OPT_OUT_MESSAGE = "Event skipped due to optOut config";
5
5
  export declare const MISSING_API_KEY_MESSAGE = "Event rejected due to missing API key";
6
6
  export declare const INVALID_API_KEY = "Invalid API key";
7
+ export declare const CLIENT_NOT_INITIALIZED = "Client not initialized";
7
8
  //# sourceMappingURL=messages.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAC5D,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AACpE,eAAO,MAAM,4BAA4B,+CAA+C,CAAC;AACzF,eAAO,MAAM,eAAe,uCAAuC,CAAC;AACpE,eAAO,MAAM,uBAAuB,0CAA0C,CAAC;AAC/E,eAAO,MAAM,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAC5D,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AACpE,eAAO,MAAM,4BAA4B,+CAA+C,CAAC;AACzF,eAAO,MAAM,eAAe,uCAAuC,CAAC;AACpE,eAAO,MAAM,uBAAuB,0CAA0C,CAAC;AAC/E,eAAO,MAAM,eAAe,oBAAoB,CAAC;AACjD,eAAO,MAAM,sBAAsB,2BAA2B,CAAC"}
@@ -1,9 +1,10 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.INVALID_API_KEY = exports.MISSING_API_KEY_MESSAGE = exports.OPT_OUT_MESSAGE = exports.MAX_RETRIES_EXCEEDED_MESSAGE = exports.UNEXPECTED_ERROR_MESSAGE = exports.SUCCESS_MESSAGE = void 0;
2
+ exports.CLIENT_NOT_INITIALIZED = exports.INVALID_API_KEY = exports.MISSING_API_KEY_MESSAGE = exports.OPT_OUT_MESSAGE = exports.MAX_RETRIES_EXCEEDED_MESSAGE = exports.UNEXPECTED_ERROR_MESSAGE = exports.SUCCESS_MESSAGE = void 0;
3
3
  exports.SUCCESS_MESSAGE = 'Event tracked successfully';
4
4
  exports.UNEXPECTED_ERROR_MESSAGE = 'Unexpected error occurred';
5
5
  exports.MAX_RETRIES_EXCEEDED_MESSAGE = 'Event rejected due to exceeded retry count';
6
6
  exports.OPT_OUT_MESSAGE = 'Event skipped due to optOut config';
7
7
  exports.MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key';
8
8
  exports.INVALID_API_KEY = 'Invalid API key';
9
+ exports.CLIENT_NOT_INITIALIZED = 'Client not initialized';
9
10
  //# sourceMappingURL=messages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":";;AAAa,QAAA,eAAe,GAAG,4BAA4B,CAAC;AAC/C,QAAA,wBAAwB,GAAG,2BAA2B,CAAC;AACvD,QAAA,4BAA4B,GAAG,4CAA4C,CAAC;AAC5E,QAAA,eAAe,GAAG,oCAAoC,CAAC;AACvD,QAAA,uBAAuB,GAAG,uCAAuC,CAAC;AAClE,QAAA,eAAe,GAAG,iBAAiB,CAAC","sourcesContent":["export const SUCCESS_MESSAGE = 'Event tracked successfully';\nexport const UNEXPECTED_ERROR_MESSAGE = 'Unexpected error occurred';\nexport const MAX_RETRIES_EXCEEDED_MESSAGE = 'Event rejected due to exceeded retry count';\nexport const OPT_OUT_MESSAGE = 'Event skipped due to optOut config';\nexport const MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key';\nexport const INVALID_API_KEY = 'Invalid API key';\n"]}
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":";;AAAa,QAAA,eAAe,GAAG,4BAA4B,CAAC;AAC/C,QAAA,wBAAwB,GAAG,2BAA2B,CAAC;AACvD,QAAA,4BAA4B,GAAG,4CAA4C,CAAC;AAC5E,QAAA,eAAe,GAAG,oCAAoC,CAAC;AACvD,QAAA,uBAAuB,GAAG,uCAAuC,CAAC;AAClE,QAAA,eAAe,GAAG,iBAAiB,CAAC;AACpC,QAAA,sBAAsB,GAAG,wBAAwB,CAAC","sourcesContent":["export const SUCCESS_MESSAGE = 'Event tracked successfully';\nexport const UNEXPECTED_ERROR_MESSAGE = 'Unexpected error occurred';\nexport const MAX_RETRIES_EXCEEDED_MESSAGE = 'Event rejected due to exceeded retry count';\nexport const OPT_OUT_MESSAGE = 'Event skipped due to optOut config';\nexport const MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key';\nexport const INVALID_API_KEY = 'Invalid API key';\nexport const CLIENT_NOT_INITIALIZED = 'Client not initialized';\n"]}
@@ -2,7 +2,6 @@ import { Config, Event, EventCallback, Plugin, Result } from '@amplitude/analyti
2
2
  export declare class Timeline {
3
3
  queue: [Event, EventCallback][];
4
4
  applying: boolean;
5
- isReady: boolean;
6
5
  plugins: Plugin[];
7
6
  register(plugin: Plugin, config: Config): Promise<void>;
8
7
  deregister(pluginName: string): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EAGN,KAAK,EACL,aAAa,EACb,MAAM,EAEN,MAAM,EACP,MAAM,4BAA4B,CAAC;AAGpC,qBAAa,QAAQ;IACnB,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,EAAE,CAAM;IAErC,QAAQ,UAAS;IAGjB,OAAO,UAAS;IAChB,OAAO,EAAE,MAAM,EAAE,CAAM;IAEjB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK7C,UAAU,CAAC,UAAU,EAAE,MAAM;IAQ7B,KAAK;IAML,IAAI,CAAC,KAAK,EAAE,KAAK;IAOjB,aAAa,CAAC,OAAO,EAAE,MAAM;IAavB,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,SAAS;IAwC9C,KAAK;CAgBZ"}
1
+ {"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EAGN,KAAK,EACL,aAAa,EACb,MAAM,EAEN,MAAM,EACP,MAAM,4BAA4B,CAAC;AAGpC,qBAAa,QAAQ;IACnB,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,EAAE,CAAM;IAErC,QAAQ,UAAS;IAGjB,OAAO,EAAE,MAAM,EAAE,CAAM;IAEjB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK7C,UAAU,CAAC,UAAU,EAAE,MAAM;IAQ7B,KAAK;IAKL,IAAI,CAAC,KAAK,EAAE,KAAK;IAOjB,aAAa,CAAC,OAAO,EAAE,MAAM;IAavB,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,SAAS;IAwC9C,KAAK;CAgBZ"}
@@ -10,7 +10,6 @@ var Timeline = /** @class */ (function () {
10
10
  this.applying = false;
11
11
  // Flag indicates whether timeline is ready to process event
12
12
  // Events collected before timeline is ready will stay in the queue to be processed later
13
- this.isReady = false;
14
13
  this.plugins = [];
15
14
  }
16
15
  Timeline.prototype.register = function (plugin, config) {
@@ -32,7 +31,6 @@ var Timeline = /** @class */ (function () {
32
31
  };
33
32
  Timeline.prototype.reset = function () {
34
33
  this.applying = false;
35
- this.isReady = false;
36
34
  this.plugins = [];
37
35
  };
38
36
  Timeline.prototype.push = function (event) {
@@ -44,7 +42,7 @@ var Timeline = /** @class */ (function () {
44
42
  };
45
43
  Timeline.prototype.scheduleApply = function (timeout) {
46
44
  var _this = this;
47
- if (!this.isReady || this.applying)
45
+ if (this.applying)
48
46
  return;
49
47
  this.applying = true;
50
48
  setTimeout(function () {
@@ -1 +1 @@
1
- {"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":";;;AAAA,8DAUoC;AACpC,yDAAqD;AAErD;IAAA;QACE,UA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AAG,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"]}
1
+ {"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":";;;AAAA,8DAUoC;AACpC,yDAAqD;AAErD;IAAA;QACE,UAAK,GAA6B,EAAE,CAAC;QACrC,kDAAkD;QAClD,aAAQ,GAAG,KAAK,CAAC;QACjB,4DAA4D;QAC5D,yFAAyF;QACzF,YAAO,GAAa,EAAE,CAAC;IAgGzB,CAAC;IA9FO,2BAAQ,GAAd,UAAe,MAAc,EAAE,MAAc;;;;4BAC3C,qBAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAA;;wBAA1B,SAA0B,CAAC;wBAC3B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;;;;;KAC3B;IAED,6BAAU,GAAV,UAAW,UAAkB;QAC3B,IAAI,CAAC,OAAO,CAAC,MAAM,CACjB,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,IAAI,KAAK,UAAU,EAA1B,CAA0B,CAAC,EAC9D,CAAC,CACF,CAAC;QACF,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,wBAAK,GAAL;QACE,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;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,GAAG,CAAC,UAAC,IAAI,IAAK,OAAA,KAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAhB,CAAgB,CAAC,CAAC,EAAA;;wBAAxD,SAAwD,CAAC;wBAEnD,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CACrC,UAAC,MAAc,IAAkC,OAAA,MAAM,CAAC,IAAI,KAAK,4BAAU,CAAC,WAAW,EAAtC,CAAsC,CACxF,CAAC;wBAEI,mBAAmB,GAAG,WAAW,CAAC,GAAG,CAAC,UAAC,MAAM;4BACjD,OAAO,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;wBACxC,CAAC,CAAC,CAAC;wBAEH,qBAAM,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAA;;wBAAtC,SAAsC,CAAC;;;;;KACxC;IACH,eAAC;AAAD,CAAC,AAtGD,IAsGC;AAtGY,4BAAQ","sourcesContent":["import {\n BeforePlugin,\n Config,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n EventCallback,\n Plugin,\n PluginType,\n Result,\n} from '@amplitude/analytics-types';\nimport { buildResult } from './utils/result-builder';\n\nexport class Timeline {\n queue: [Event, EventCallback][] = [];\n // Flag to guarantee one schedule apply is running\n applying = false;\n // Flag indicates whether timeline is ready to process event\n // Events collected before timeline is ready will stay in the queue to be processed later\n plugins: Plugin[] = [];\n\n async register(plugin: Plugin, config: Config) {\n await plugin.setup(config);\n this.plugins.push(plugin);\n }\n\n deregister(pluginName: string) {\n this.plugins.splice(\n this.plugins.findIndex((plugin) => plugin.name === pluginName),\n 1,\n );\n return Promise.resolve();\n }\n\n reset() {\n this.applying = false;\n this.plugins = [];\n }\n\n push(event: Event) {\n return new Promise<Result>((resolve) => {\n this.queue.push([event, resolve]);\n this.scheduleApply(0);\n });\n }\n\n scheduleApply(timeout: number) {\n if (this.applying) return;\n this.applying = true;\n setTimeout(() => {\n void this.apply(this.queue.shift()).then(() => {\n this.applying = false;\n if (this.queue.length > 0) {\n this.scheduleApply(0);\n }\n });\n }, timeout);\n }\n\n async apply(item: [Event, EventCallback] | undefined) {\n if (!item) {\n return;\n }\n\n let [event] = item;\n const [, resolve] = item;\n\n const before = this.plugins.filter<BeforePlugin>(\n (plugin: Plugin): plugin is BeforePlugin => plugin.type === PluginType.BEFORE,\n );\n\n for (const plugin of before) {\n event = await plugin.execute({ ...event });\n }\n\n const enrichment = this.plugins.filter<EnrichmentPlugin>(\n (plugin: Plugin): plugin is EnrichmentPlugin => plugin.type === PluginType.ENRICHMENT,\n );\n\n for (const plugin of enrichment) {\n event = await plugin.execute({ ...event });\n }\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === PluginType.DESTINATION,\n );\n\n const executeDestinations = destination.map((plugin) => {\n const eventClone = { ...event };\n return plugin.execute(eventClone).catch((e) => buildResult(eventClone, 0, String(e)));\n });\n\n void Promise.all(executeDestinations).then(([result]) => {\n resolve(result);\n });\n\n return;\n }\n\n async flush() {\n const queue = this.queue;\n this.queue = [];\n\n await Promise.all(queue.map((item) => this.apply(item)));\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === PluginType.DESTINATION,\n );\n\n const executeDestinations = destination.map((plugin) => {\n return plugin.flush && plugin.flush();\n });\n\n await Promise.all(executeDestinations);\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { CoreClient, Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types';
1
+ import { CoreClient, Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue, Result } from '@amplitude/analytics-types';
2
2
  import { Timeline } from './timeline';
3
3
  export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
4
4
  initializing: boolean;
@@ -6,22 +6,21 @@ export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
6
6
  config: T;
7
7
  timeline: Timeline;
8
8
  protected q: CallableFunction[];
9
- protected pluginQueue: CallableFunction[];
9
+ protected dispatchQ: CallableFunction[];
10
10
  constructor(name?: string);
11
11
  _init(config: T): Promise<void>;
12
- protected getAndResetQueuedFunctions(): CallableFunction[];
13
- protected runQueuedFunctions(): Promise<void>;
14
- protected getAndResetQueuedPluginFunctions(): CallableFunction[];
15
- protected runQueuedPluginFunctions(): Promise<void>;
16
- track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
17
- logEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>;
18
- identify(identify: Identify, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
19
- groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
20
- setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
21
- revenue(revenue: Revenue, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
12
+ runQueuedFunctions(queueName: 'q' | 'dispatchQ'): Promise<void>;
13
+ track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): Promise<Result>;
14
+ logEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<Result>;
15
+ identify(identify: Identify, eventOptions?: EventOptions): Promise<Result>;
16
+ groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions): Promise<Result>;
17
+ setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions): Promise<Result>;
18
+ revenue(revenue: Revenue, eventOptions?: EventOptions): Promise<Result>;
22
19
  add(plugin: Plugin): Promise<void>;
23
20
  remove(pluginName: string): Promise<void>;
24
- dispatch(event: Event): Promise<import("@amplitude/analytics-types").Result>;
21
+ dispatchWithCallback(event: Event, callback: (result: Result) => void): void;
22
+ dispatch(event: Event): Promise<Result>;
23
+ process(event: Event): Promise<Result>;
25
24
  setOptOut(optOut: boolean): void;
26
25
  flush(): Promise<void>;
27
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,MAAM,EACN,KAAK,EACL,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,OAAO,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,YAAY,UAAS;IACrB,IAAI,EAAE,MAAM,CAAC;IAGb,MAAM,EAAE,CAAC,CAAC;IAGV,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAM;IACrC,SAAS,CAAC,WAAW,EAAE,gBAAgB,EAAE,CAAM;gBAEnC,IAAI,SAAa;IAKvB,KAAK,CAAC,MAAM,EAAE,CAAC;IAOrB,SAAS,CAAC,0BAA0B;cAMpB,kBAAkB;IAOlC,SAAS,CAAC,gCAAgC;cAM1B,wBAAwB;IAOxC,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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;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;IAQ/B,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAOtE,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAUvC,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAuB5C,SAAS,CAAC,MAAM,EAAE,OAAO;IAQzB,KAAK;CAGN"}
@@ -2,13 +2,13 @@ import { __awaiter, __generator, __values } from "tslib";
2
2
  import { createGroupIdentifyEvent, createIdentifyEvent, createTrackEvent, createRevenueEvent, createGroupEvent, } from './utils/event-builder';
3
3
  import { Timeline } from './timeline';
4
4
  import { buildResult } from './utils/result-builder';
5
- import { OPT_OUT_MESSAGE } from './messages';
5
+ import { CLIENT_NOT_INITIALIZED, OPT_OUT_MESSAGE } from './messages';
6
6
  var AmplitudeCore = /** @class */ (function () {
7
7
  function AmplitudeCore(name) {
8
8
  if (name === void 0) { name = '$default'; }
9
9
  this.initializing = false;
10
10
  this.q = [];
11
- this.pluginQueue = [];
11
+ this.dispatchQ = [];
12
12
  this.logEvent = this.track.bind(this);
13
13
  this.timeline = new Timeline();
14
14
  this.name = name;
@@ -20,30 +20,23 @@ var AmplitudeCore = /** @class */ (function () {
20
20
  case 0:
21
21
  this.config = config;
22
22
  this.timeline.reset();
23
- return [4 /*yield*/, this.runQueuedPluginFunctions()];
23
+ return [4 /*yield*/, this.runQueuedFunctions('q')];
24
24
  case 1:
25
- _a.sent();
26
- return [4 /*yield*/, this.runQueuedFunctions()];
27
- case 2:
28
25
  _a.sent();
29
26
  return [2 /*return*/];
30
27
  }
31
28
  });
32
29
  });
33
30
  };
34
- AmplitudeCore.prototype.getAndResetQueuedFunctions = function () {
35
- var queuedFunctions = this.q;
36
- this.q = [];
37
- return queuedFunctions;
38
- };
39
- AmplitudeCore.prototype.runQueuedFunctions = function () {
31
+ AmplitudeCore.prototype.runQueuedFunctions = function (queueName) {
40
32
  return __awaiter(this, void 0, void 0, function () {
41
33
  var queuedFunctions, queuedFunctions_1, queuedFunctions_1_1, queuedFunction, e_1_1;
42
34
  var e_1, _a;
43
35
  return __generator(this, function (_b) {
44
36
  switch (_b.label) {
45
37
  case 0:
46
- queuedFunctions = this.getAndResetQueuedFunctions();
38
+ queuedFunctions = this[queueName];
39
+ this[queueName] = [];
47
40
  _b.label = 1;
48
41
  case 1:
49
42
  _b.trys.push([1, 6, 7, 8]);
@@ -75,50 +68,6 @@ var AmplitudeCore = /** @class */ (function () {
75
68
  });
76
69
  });
77
70
  };
78
- AmplitudeCore.prototype.getAndResetQueuedPluginFunctions = function () {
79
- var queuedFunctions = this.pluginQueue;
80
- this.pluginQueue = [];
81
- return queuedFunctions;
82
- };
83
- AmplitudeCore.prototype.runQueuedPluginFunctions = function () {
84
- return __awaiter(this, void 0, void 0, function () {
85
- var queuedFunctions, queuedFunctions_2, queuedFunctions_2_1, queuedFunction, e_2_1;
86
- var e_2, _a;
87
- return __generator(this, function (_b) {
88
- switch (_b.label) {
89
- case 0:
90
- queuedFunctions = this.getAndResetQueuedPluginFunctions();
91
- _b.label = 1;
92
- case 1:
93
- _b.trys.push([1, 6, 7, 8]);
94
- queuedFunctions_2 = __values(queuedFunctions), queuedFunctions_2_1 = queuedFunctions_2.next();
95
- _b.label = 2;
96
- case 2:
97
- if (!!queuedFunctions_2_1.done) return [3 /*break*/, 5];
98
- queuedFunction = queuedFunctions_2_1.value;
99
- return [4 /*yield*/, queuedFunction()];
100
- case 3:
101
- _b.sent();
102
- _b.label = 4;
103
- case 4:
104
- queuedFunctions_2_1 = queuedFunctions_2.next();
105
- return [3 /*break*/, 2];
106
- case 5: return [3 /*break*/, 8];
107
- case 6:
108
- e_2_1 = _b.sent();
109
- e_2 = { error: e_2_1 };
110
- return [3 /*break*/, 8];
111
- case 7:
112
- try {
113
- if (queuedFunctions_2_1 && !queuedFunctions_2_1.done && (_a = queuedFunctions_2.return)) _a.call(queuedFunctions_2);
114
- }
115
- finally { if (e_2) throw e_2.error; }
116
- return [7 /*endfinally*/];
117
- case 8: return [2 /*return*/];
118
- }
119
- });
120
- });
121
- };
122
71
  AmplitudeCore.prototype.track = function (eventInput, eventProperties, eventOptions) {
123
72
  var event = createTrackEvent(eventInput, eventProperties, eventOptions);
124
73
  return this.dispatch(event);
@@ -143,7 +92,7 @@ var AmplitudeCore = /** @class */ (function () {
143
92
  return __awaiter(this, void 0, void 0, function () {
144
93
  return __generator(this, function (_a) {
145
94
  if (!this.config) {
146
- this.pluginQueue.push(this.add.bind(this, plugin));
95
+ this.q.push(this.add.bind(this, plugin));
147
96
  return [2 /*return*/];
148
97
  }
149
98
  return [2 /*return*/, this.timeline.register(plugin, this.config)];
@@ -154,40 +103,56 @@ var AmplitudeCore = /** @class */ (function () {
154
103
  return __awaiter(this, void 0, void 0, function () {
155
104
  return __generator(this, function (_a) {
156
105
  if (!this.config) {
157
- this.pluginQueue.push(this.remove.bind(this, pluginName));
106
+ this.q.push(this.remove.bind(this, pluginName));
158
107
  return [2 /*return*/];
159
108
  }
160
109
  return [2 /*return*/, this.timeline.deregister(pluginName)];
161
110
  });
162
111
  });
163
112
  };
113
+ AmplitudeCore.prototype.dispatchWithCallback = function (event, callback) {
114
+ if (!this.config) {
115
+ return callback(buildResult(event, 0, CLIENT_NOT_INITIALIZED));
116
+ }
117
+ void this.process(event).then(callback);
118
+ };
164
119
  AmplitudeCore.prototype.dispatch = function (event) {
165
- var _a;
166
120
  return __awaiter(this, void 0, void 0, function () {
167
- var result, e_3, message;
168
- return __generator(this, function (_b) {
169
- switch (_b.label) {
121
+ var _this = this;
122
+ return __generator(this, function (_a) {
123
+ if (!this.config) {
124
+ return [2 /*return*/, new Promise(function (resolve) {
125
+ _this.dispatchQ.push(_this.dispatchWithCallback.bind(_this, event, resolve));
126
+ })];
127
+ }
128
+ return [2 /*return*/, this.process(event)];
129
+ });
130
+ });
131
+ };
132
+ AmplitudeCore.prototype.process = function (event) {
133
+ return __awaiter(this, void 0, void 0, function () {
134
+ var result, e_2, message, result;
135
+ return __generator(this, function (_a) {
136
+ switch (_a.label) {
170
137
  case 0:
171
- _b.trys.push([0, 2, , 3]);
138
+ _a.trys.push([0, 2, , 3]);
172
139
  // skip event processing if opt out
173
- if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.optOut) {
140
+ if (this.config.optOut) {
174
141
  return [2 /*return*/, buildResult(event, 0, OPT_OUT_MESSAGE)];
175
142
  }
176
143
  return [4 /*yield*/, this.timeline.push(event)];
177
144
  case 1:
178
- result = _b.sent();
179
- if (result.code === 200) {
180
- this.config.loggerProvider.log(result.message);
181
- }
182
- else {
183
- this.config.loggerProvider.error(result.message);
184
- }
145
+ result = _a.sent();
146
+ result.code === 200
147
+ ? this.config.loggerProvider.log(result.message)
148
+ : this.config.loggerProvider.error(result.message);
185
149
  return [2 /*return*/, result];
186
150
  case 2:
187
- e_3 = _b.sent();
188
- message = String(e_3);
151
+ e_2 = _a.sent();
152
+ message = String(e_2);
189
153
  this.config.loggerProvider.error(message);
190
- return [2 /*return*/, buildResult(event, 0, message)];
154
+ result = buildResult(event, 0, message);
155
+ return [2 /*return*/, result];
191
156
  case 3: return [2 /*return*/];
192
157
  }
193
158
  });
@@ -1 +1 @@
1
- {"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core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D;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,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACxD,OAAO;SACR;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,6BAAK,GAAL;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IACH,oBAAC;AAAD,CAAC,AA5HD,IA4HC","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 initializing = false;\n name: string;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: T;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n timeline: Timeline;\n protected q: CallableFunction[] = [];\n protected pluginQueue: CallableFunction[] = [];\n\n constructor(name = '$default') {\n this.timeline = new Timeline();\n this.name = name;\n }\n\n async _init(config: T) {\n this.config = config;\n this.timeline.reset();\n await this.runQueuedPluginFunctions();\n await this.runQueuedFunctions();\n }\n\n protected getAndResetQueuedFunctions() {\n const queuedFunctions = this.q;\n this.q = [];\n return queuedFunctions;\n }\n\n protected async runQueuedFunctions() {\n const queuedFunctions = this.getAndResetQueuedFunctions();\n for (const queuedFunction of queuedFunctions) {\n await queuedFunction();\n }\n }\n\n protected getAndResetQueuedPluginFunctions() {\n const queuedFunctions = this.pluginQueue;\n this.pluginQueue = [];\n return queuedFunctions;\n }\n\n protected async runQueuedPluginFunctions() {\n const queuedFunctions = this.getAndResetQueuedPluginFunctions();\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.pluginQueue.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.pluginQueue.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
+ {"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";AAWA,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAErE;IAYE,uBAAY,IAAiB;QAAjB,qBAAA,EAAA,iBAAiB;QAX7B,iBAAY,GAAG,KAAK,CAAC;QAQX,MAAC,GAAuB,EAAE,CAAC;QAC3B,cAAS,GAAuB,EAAE,CAAC;QA0B7C,aAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAvB/B,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,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;wBACtB,qBAAM,IAAI,CAAC,kBAAkB,CAA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,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IACH,oBAAC;AAAD,CAAC,AA7HD,IA6HC","sourcesContent":["import {\n CoreClient,\n Config,\n Event,\n BaseEvent,\n EventOptions,\n Identify,\n Plugin,\n Revenue,\n Result,\n} from '@amplitude/analytics-types';\nimport {\n createGroupIdentifyEvent,\n createIdentifyEvent,\n createTrackEvent,\n createRevenueEvent,\n createGroupEvent,\n} from './utils/event-builder';\nimport { Timeline } from './timeline';\nimport { buildResult } from './utils/result-builder';\nimport { CLIENT_NOT_INITIALIZED, OPT_OUT_MESSAGE } from './messages';\n\nexport class AmplitudeCore<T extends Config> implements CoreClient<T> {\n initializing = false;\n name: string;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: T;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n timeline: Timeline;\n protected q: CallableFunction[] = [];\n protected dispatchQ: CallableFunction[] = [];\n\n constructor(name = '$default') {\n this.timeline = new Timeline();\n this.name = name;\n }\n\n async _init(config: T) {\n this.config = config;\n this.timeline.reset();\n await this.runQueuedFunctions('q');\n }\n\n async runQueuedFunctions(queueName: 'q' | 'dispatchQ') {\n const queuedFunctions = this[queueName];\n this[queueName] = [];\n for (const queuedFunction of queuedFunctions) {\n await queuedFunction();\n }\n }\n\n track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions) {\n const event = createTrackEvent(eventInput, eventProperties, eventOptions);\n return this.dispatch(event);\n }\n\n logEvent = this.track.bind(this);\n\n identify(identify: Identify, eventOptions?: EventOptions) {\n const event = createIdentifyEvent(identify, eventOptions);\n return this.dispatch(event);\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions) {\n const event = createGroupIdentifyEvent(groupType, groupName, identify, eventOptions);\n return this.dispatch(event);\n }\n\n setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions) {\n const event = createGroupEvent(groupType, groupName, eventOptions);\n return this.dispatch(event);\n }\n\n revenue(revenue: Revenue, eventOptions?: EventOptions) {\n const event = createRevenueEvent(revenue, eventOptions);\n return this.dispatch(event);\n }\n\n async add(plugin: Plugin) {\n if (!this.config) {\n this.q.push(this.add.bind(this, plugin));\n return;\n }\n return this.timeline.register(plugin, this.config);\n }\n\n async remove(pluginName: string) {\n if (!this.config) {\n this.q.push(this.remove.bind(this, pluginName));\n return;\n }\n return this.timeline.deregister(pluginName);\n }\n\n dispatchWithCallback(event: Event, callback: (result: Result) => void): void {\n if (!this.config) {\n return callback(buildResult(event, 0, CLIENT_NOT_INITIALIZED));\n }\n void this.process(event).then(callback);\n }\n\n async dispatch(event: Event): Promise<Result> {\n if (!this.config) {\n return new Promise<Result>((resolve) => {\n this.dispatchQ.push(this.dispatchWithCallback.bind(this, event, resolve));\n });\n }\n\n return this.process(event);\n }\n\n async process(event: Event): Promise<Result> {\n try {\n // skip event processing if opt out\n if (this.config.optOut) {\n return buildResult(event, 0, OPT_OUT_MESSAGE);\n }\n\n const result = await this.timeline.push(event);\n\n result.code === 200\n ? this.config.loggerProvider.log(result.message)\n : this.config.loggerProvider.error(result.message);\n\n return result;\n } catch (e) {\n const message = String(e);\n this.config.loggerProvider.error(message);\n const result = buildResult(event, 0, message);\n\n return result;\n }\n }\n\n setOptOut(optOut: boolean) {\n if (!this.config) {\n this.q.push(this.setOptOut.bind(this, Boolean(optOut)));\n return;\n }\n this.config.optOut = Boolean(optOut);\n }\n\n flush() {\n return this.timeline.flush();\n }\n}\n"]}
@@ -4,4 +4,5 @@ export declare const MAX_RETRIES_EXCEEDED_MESSAGE = "Event rejected due to excee
4
4
  export declare const OPT_OUT_MESSAGE = "Event skipped due to optOut config";
5
5
  export declare const MISSING_API_KEY_MESSAGE = "Event rejected due to missing API key";
6
6
  export declare const INVALID_API_KEY = "Invalid API key";
7
+ export declare const CLIENT_NOT_INITIALIZED = "Client not initialized";
7
8
  //# sourceMappingURL=messages.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAC5D,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AACpE,eAAO,MAAM,4BAA4B,+CAA+C,CAAC;AACzF,eAAO,MAAM,eAAe,uCAAuC,CAAC;AACpE,eAAO,MAAM,uBAAuB,0CAA0C,CAAC;AAC/E,eAAO,MAAM,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAC5D,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AACpE,eAAO,MAAM,4BAA4B,+CAA+C,CAAC;AACzF,eAAO,MAAM,eAAe,uCAAuC,CAAC;AACpE,eAAO,MAAM,uBAAuB,0CAA0C,CAAC;AAC/E,eAAO,MAAM,eAAe,oBAAoB,CAAC;AACjD,eAAO,MAAM,sBAAsB,2BAA2B,CAAC"}
@@ -4,4 +4,5 @@ export var MAX_RETRIES_EXCEEDED_MESSAGE = 'Event rejected due to exceeded retry
4
4
  export var OPT_OUT_MESSAGE = 'Event skipped due to optOut config';
5
5
  export var MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key';
6
6
  export var INVALID_API_KEY = 'Invalid API key';
7
+ export var CLIENT_NOT_INITIALIZED = 'Client not initialized';
7
8
  //# sourceMappingURL=messages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,eAAe,GAAG,4BAA4B,CAAC;AAC5D,MAAM,CAAC,IAAM,wBAAwB,GAAG,2BAA2B,CAAC;AACpE,MAAM,CAAC,IAAM,4BAA4B,GAAG,4CAA4C,CAAC;AACzF,MAAM,CAAC,IAAM,eAAe,GAAG,oCAAoC,CAAC;AACpE,MAAM,CAAC,IAAM,uBAAuB,GAAG,uCAAuC,CAAC;AAC/E,MAAM,CAAC,IAAM,eAAe,GAAG,iBAAiB,CAAC","sourcesContent":["export const SUCCESS_MESSAGE = 'Event tracked successfully';\nexport const UNEXPECTED_ERROR_MESSAGE = 'Unexpected error occurred';\nexport const MAX_RETRIES_EXCEEDED_MESSAGE = 'Event rejected due to exceeded retry count';\nexport const OPT_OUT_MESSAGE = 'Event skipped due to optOut config';\nexport const MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key';\nexport const INVALID_API_KEY = 'Invalid API key';\n"]}
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,eAAe,GAAG,4BAA4B,CAAC;AAC5D,MAAM,CAAC,IAAM,wBAAwB,GAAG,2BAA2B,CAAC;AACpE,MAAM,CAAC,IAAM,4BAA4B,GAAG,4CAA4C,CAAC;AACzF,MAAM,CAAC,IAAM,eAAe,GAAG,oCAAoC,CAAC;AACpE,MAAM,CAAC,IAAM,uBAAuB,GAAG,uCAAuC,CAAC;AAC/E,MAAM,CAAC,IAAM,eAAe,GAAG,iBAAiB,CAAC;AACjD,MAAM,CAAC,IAAM,sBAAsB,GAAG,wBAAwB,CAAC","sourcesContent":["export const SUCCESS_MESSAGE = 'Event tracked successfully';\nexport const UNEXPECTED_ERROR_MESSAGE = 'Unexpected error occurred';\nexport const MAX_RETRIES_EXCEEDED_MESSAGE = 'Event rejected due to exceeded retry count';\nexport const OPT_OUT_MESSAGE = 'Event skipped due to optOut config';\nexport const MISSING_API_KEY_MESSAGE = 'Event rejected due to missing API key';\nexport const INVALID_API_KEY = 'Invalid API key';\nexport const CLIENT_NOT_INITIALIZED = 'Client not initialized';\n"]}
@@ -2,7 +2,6 @@ import { Config, Event, EventCallback, Plugin, Result } from '@amplitude/analyti
2
2
  export declare class Timeline {
3
3
  queue: [Event, EventCallback][];
4
4
  applying: boolean;
5
- isReady: boolean;
6
5
  plugins: Plugin[];
7
6
  register(plugin: Plugin, config: Config): Promise<void>;
8
7
  deregister(pluginName: string): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EAGN,KAAK,EACL,aAAa,EACb,MAAM,EAEN,MAAM,EACP,MAAM,4BAA4B,CAAC;AAGpC,qBAAa,QAAQ;IACnB,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,EAAE,CAAM;IAErC,QAAQ,UAAS;IAGjB,OAAO,UAAS;IAChB,OAAO,EAAE,MAAM,EAAE,CAAM;IAEjB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK7C,UAAU,CAAC,UAAU,EAAE,MAAM;IAQ7B,KAAK;IAML,IAAI,CAAC,KAAK,EAAE,KAAK;IAOjB,aAAa,CAAC,OAAO,EAAE,MAAM;IAavB,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,SAAS;IAwC9C,KAAK;CAgBZ"}
1
+ {"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EAGN,KAAK,EACL,aAAa,EACb,MAAM,EAEN,MAAM,EACP,MAAM,4BAA4B,CAAC;AAGpC,qBAAa,QAAQ;IACnB,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,EAAE,CAAM;IAErC,QAAQ,UAAS;IAGjB,OAAO,EAAE,MAAM,EAAE,CAAM;IAEjB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK7C,UAAU,CAAC,UAAU,EAAE,MAAM;IAQ7B,KAAK;IAKL,IAAI,CAAC,KAAK,EAAE,KAAK;IAOjB,aAAa,CAAC,OAAO,EAAE,MAAM;IAavB,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,SAAS;IAwC9C,KAAK;CAgBZ"}
@@ -8,7 +8,6 @@ var Timeline = /** @class */ (function () {
8
8
  this.applying = false;
9
9
  // Flag indicates whether timeline is ready to process event
10
10
  // Events collected before timeline is ready will stay in the queue to be processed later
11
- this.isReady = false;
12
11
  this.plugins = [];
13
12
  }
14
13
  Timeline.prototype.register = function (plugin, config) {
@@ -30,7 +29,6 @@ var Timeline = /** @class */ (function () {
30
29
  };
31
30
  Timeline.prototype.reset = function () {
32
31
  this.applying = false;
33
- this.isReady = false;
34
32
  this.plugins = [];
35
33
  };
36
34
  Timeline.prototype.push = function (event) {
@@ -42,7 +40,7 @@ var Timeline = /** @class */ (function () {
42
40
  };
43
41
  Timeline.prototype.scheduleApply = function (timeout) {
44
42
  var _this = this;
45
- if (!this.isReady || this.applying)
43
+ if (this.applying)
46
44
  return;
47
45
  this.applying = true;
48
46
  setTimeout(function () {
@@ -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;;;;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,CA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AAC,IAAI,CAAC,UAAC,EAAQ;gCAAR,KAAA,aAAQ,EAAP,MAAM,QAAA;4BACjD,OAAO,CAAC,MAAM,CAAC,CAAC;wBAClB,CAAC,CAAC,CAAC;wBAEH,sBAAO;;;;KACR;IAEK,wBAAK,GAAX;;;;;;;wBACQ,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;wBACzB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;wBAEhB,qBAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,UAAC,IAAI,IAAK,OAAA,KAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAhB,CAAgB,CAAC,CAAC,EAAA;;wBAAxD,SAAwD,CAAC;wBAEnD,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CACrC,UAAC,MAAc,IAAkC,OAAA,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC,WAAW,EAAtC,CAAsC,CACxF,CAAC;wBAEI,mBAAmB,GAAG,WAAW,CAAC,GAAG,CAAC,UAAC,MAAM;4BACjD,OAAO,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;wBACxC,CAAC,CAAC,CAAC;wBAEH,qBAAM,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAA;;wBAAtC,SAAsC,CAAC;;;;;KACxC;IACH,eAAC;AAAD,CAAC,AAxGD,IAwGC","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"]}
1
+ {"version":3,"file":"timeline.js","sourceRo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,CAAC;wBAEH,qBAAM,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAA;;wBAAtC,SAAsC,CAAC;;;;;KACxC;IACH,eAAC;AAAD,CAAC,AAtGD,IAsGC","sourcesContent":["import {\n BeforePlugin,\n Config,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n EventCallback,\n Plugin,\n PluginType,\n Result,\n} from '@amplitude/analytics-types';\nimport { buildResult } from './utils/result-builder';\n\nexport class Timeline {\n queue: [Event, EventCallback][] = [];\n // Flag to guarantee one schedule apply is running\n applying = false;\n // Flag indicates whether timeline is ready to process event\n // Events collected before timeline is ready will stay in the queue to be processed later\n plugins: Plugin[] = [];\n\n async register(plugin: Plugin, config: Config) {\n await plugin.setup(config);\n this.plugins.push(plugin);\n }\n\n deregister(pluginName: string) {\n this.plugins.splice(\n this.plugins.findIndex((plugin) => plugin.name === pluginName),\n 1,\n );\n return Promise.resolve();\n }\n\n reset() {\n this.applying = false;\n this.plugins = [];\n }\n\n push(event: Event) {\n return new Promise<Result>((resolve) => {\n this.queue.push([event, resolve]);\n this.scheduleApply(0);\n });\n }\n\n scheduleApply(timeout: number) {\n if (this.applying) return;\n this.applying = true;\n setTimeout(() => {\n void this.apply(this.queue.shift()).then(() => {\n this.applying = false;\n if (this.queue.length > 0) {\n this.scheduleApply(0);\n }\n });\n }, timeout);\n }\n\n async apply(item: [Event, EventCallback] | undefined) {\n if (!item) {\n return;\n }\n\n let [event] = item;\n const [, resolve] = item;\n\n const before = this.plugins.filter<BeforePlugin>(\n (plugin: Plugin): plugin is BeforePlugin => plugin.type === PluginType.BEFORE,\n );\n\n for (const plugin of before) {\n event = await plugin.execute({ ...event });\n }\n\n const enrichment = this.plugins.filter<EnrichmentPlugin>(\n (plugin: Plugin): plugin is EnrichmentPlugin => plugin.type === PluginType.ENRICHMENT,\n );\n\n for (const plugin of enrichment) {\n event = await plugin.execute({ ...event });\n }\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === PluginType.DESTINATION,\n );\n\n const executeDestinations = destination.map((plugin) => {\n const eventClone = { ...event };\n return plugin.execute(eventClone).catch((e) => buildResult(eventClone, 0, String(e)));\n });\n\n void Promise.all(executeDestinations).then(([result]) => {\n resolve(result);\n });\n\n return;\n }\n\n async flush() {\n const queue = this.queue;\n this.queue = [];\n\n await Promise.all(queue.map((item) => this.apply(item)));\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === PluginType.DESTINATION,\n );\n\n const executeDestinations = destination.map((plugin) => {\n return plugin.flush && plugin.flush();\n });\n\n await Promise.all(executeDestinations);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amplitude/analytics-core",
3
- "version": "0.9.6",
3
+ "version": "0.9.7",
4
4
  "description": "",
5
5
  "author": "Amplitude Inc",
6
6
  "homepage": "https://github.com/amplitude/Amplitude-TypeScript",
@@ -40,5 +40,5 @@
40
40
  "files": [
41
41
  "lib"
42
42
  ],
43
- "gitHead": "e0e8c340cf94fd182cc313a177d4148ed89f4bd5"
43
+ "gitHead": "7e75f22a1d9a972f627d18ae2e09add8dac2c63f"
44
44
  }