@amplitude/analytics-core 0.9.6 → 0.10.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.
Files changed (49) hide show
  1. package/lib/cjs/core-client.d.ts +12 -13
  2. package/lib/cjs/core-client.d.ts.map +1 -1
  3. package/lib/cjs/core-client.js +39 -74
  4. package/lib/cjs/core-client.js.map +1 -1
  5. package/lib/cjs/index.d.ts +1 -0
  6. package/lib/cjs/index.d.ts.map +1 -1
  7. package/lib/cjs/index.js +5 -1
  8. package/lib/cjs/index.js.map +1 -1
  9. package/lib/cjs/logger.d.ts +1 -0
  10. package/lib/cjs/logger.d.ts.map +1 -1
  11. package/lib/cjs/logger.js +11 -0
  12. package/lib/cjs/logger.js.map +1 -1
  13. package/lib/cjs/messages.d.ts +1 -0
  14. package/lib/cjs/messages.d.ts.map +1 -1
  15. package/lib/cjs/messages.js +2 -1
  16. package/lib/cjs/messages.js.map +1 -1
  17. package/lib/cjs/timeline.d.ts +0 -1
  18. package/lib/cjs/timeline.d.ts.map +1 -1
  19. package/lib/cjs/timeline.js +1 -3
  20. package/lib/cjs/timeline.js.map +1 -1
  21. package/lib/cjs/utils/debug.d.ts +12 -0
  22. package/lib/cjs/utils/debug.d.ts.map +1 -0
  23. package/lib/cjs/utils/debug.js +123 -0
  24. package/lib/cjs/utils/debug.js.map +1 -0
  25. package/lib/esm/core-client.d.ts +12 -13
  26. package/lib/esm/core-client.d.ts.map +1 -1
  27. package/lib/esm/core-client.js +40 -75
  28. package/lib/esm/core-client.js.map +1 -1
  29. package/lib/esm/index.d.ts +1 -0
  30. package/lib/esm/index.d.ts.map +1 -1
  31. package/lib/esm/index.js +1 -0
  32. package/lib/esm/index.js.map +1 -1
  33. package/lib/esm/logger.d.ts +1 -0
  34. package/lib/esm/logger.d.ts.map +1 -1
  35. package/lib/esm/logger.js +11 -0
  36. package/lib/esm/logger.js.map +1 -1
  37. package/lib/esm/messages.d.ts +1 -0
  38. package/lib/esm/messages.d.ts.map +1 -1
  39. package/lib/esm/messages.js +1 -0
  40. package/lib/esm/messages.js.map +1 -1
  41. package/lib/esm/timeline.d.ts +0 -1
  42. package/lib/esm/timeline.d.ts.map +1 -1
  43. package/lib/esm/timeline.js +1 -3
  44. package/lib/esm/timeline.js.map +1 -1
  45. package/lib/esm/utils/debug.d.ts +12 -0
  46. package/lib/esm/utils/debug.d.ts.map +1 -0
  47. package/lib/esm/utils/debug.js +116 -0
  48. package/lib/esm/utils/debug.js.map +1 -0
  49. package/package.json +3 -3
@@ -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;IA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K,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"}
@@ -10,7 +10,7 @@ var AmplitudeCore = /** @class */ (function () {
10
10
  if (name === void 0) { name = '$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,C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E,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,IAA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AAE,OAAO,CAAC,CAAC;wBAE9C,sBAAO,MAAM,EAAC;;;;;KAEjB;IAED,iCAAS,GAAT,UAAU,MAAe;QACvB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACxD,OAAO;SACR;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,6BAAK,GAAL;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IACH,oBAAC;AAAD,CAAC,AA7HD,IA6HC;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"]}
@@ -6,6 +6,7 @@ export { Config } from './config';
6
6
  export { Logger } from './logger';
7
7
  export { AMPLITUDE_PREFIX } from './constants';
8
8
  export { returnWrapper } from './utils/return-wrapper';
9
+ export { debugWrapper, getClientLogConfig, getClientStates } from './utils/debug';
9
10
  export { UUID } from './utils/uuid';
10
11
  export { MemoryStorage } from './storage/memory';
11
12
  export { BaseTransport } from './transports/base';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
package/lib/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.createIdentifyEvent = exports.BaseTransport = exports.MemoryStorage = exports.UUID = exports.returnWrapper = exports.AMPLITUDE_PREFIX = exports.Logger = exports.Config = exports.Destination = exports.Revenue = exports.Identify = exports.AmplitudeCore = void 0;
2
+ exports.createIdentifyEvent = exports.BaseTransport = exports.MemoryStorage = exports.UUID = exports.getClientStates = exports.getClientLogConfig = exports.debugWrapper = exports.returnWrapper = exports.AMPLITUDE_PREFIX = exports.Logger = exports.Config = exports.Destination = exports.Revenue = exports.Identify = exports.AmplitudeCore = void 0;
3
3
  var core_client_1 = require("./core-client");
4
4
  Object.defineProperty(exports, "AmplitudeCore", { enumerable: true, get: function () { return core_client_1.AmplitudeCore; } });
5
5
  var identify_1 = require("./identify");
@@ -16,6 +16,10 @@ var constants_1 = require("./constants");
16
16
  Object.defineProperty(exports, "AMPLITUDE_PREFIX", { enumerable: true, get: function () { return constants_1.AMPLITUDE_PREFIX; } });
17
17
  var return_wrapper_1 = require("./utils/return-wrapper");
18
18
  Object.defineProperty(exports, "returnWrapper", { enumerable: true, get: function () { return return_wrapper_1.returnWrapper; } });
19
+ var debug_1 = require("./utils/debug");
20
+ Object.defineProperty(exports, "debugWrapper", { enumerable: true, get: function () { return debug_1.debugWrapper; } });
21
+ Object.defineProperty(exports, "getClientLogConfig", { enumerable: true, get: function () { return debug_1.getClientLogConfig; } });
22
+ Object.defineProperty(exports, "getClientStates", { enumerable: true, get: function () { return debug_1.getClientStates; } });
19
23
  var uuid_1 = require("./utils/uuid");
20
24
  Object.defineProperty(exports, "UUID", { enumerable: true, get: function () { return uuid_1.UUID; } });
21
25
  var memory_1 = require("./storage/memory");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAAA,6CAA8C;AAArC,4GAAA,aAAa,OAAA;AACtB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,qDAAoD;AAA3C,0GAAA,WAAW,OAAA;AACpB,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,yCAA+C;AAAtC,6GAAA,gBAAgB,OAAA;AACzB,yDAAuD;AAA9C,+GAAA,aAAa,OAAA;AACtB,qCAAoC;AAA3B,4FAAA,IAAI,OAAA;AACb,2CAAiD;AAAxC,uGAAA,aAAa,OAAA;AACtB,0CAAkD;AAAzC,qGAAA,aAAa,OAAA;AACtB,uDAA4D;AAAnD,oHAAA,mBAAmB,OAAA","sourcesContent":["export { AmplitudeCore } from './core-client';\nexport { Identify } from './identify';\nexport { Revenue } from './revenue';\nexport { Destination } from './plugins/destination';\nexport { Config } from './config';\nexport { Logger } from './logger';\nexport { AMPLITUDE_PREFIX } from './constants';\nexport { returnWrapper } from './utils/return-wrapper';\nexport { UUID } from './utils/uuid';\nexport { MemoryStorage } from './storage/memory';\nexport { BaseTransport } from './transports/base';\nexport { createIdentifyEvent } from './utils/event-builder';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAAA,6CAA8C;AAArC,4GAAA,aAAa,OAAA;AACtB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,qDAAoD;AAA3C,0GAAA,WAAW,OAAA;AACpB,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,yCAA+C;AAAtC,6GAAA,gBAAgB,OAAA;AACzB,yDAAuD;AAA9C,+GAAA,aAAa,OAAA;AACtB,uCAAkF;AAAzE,qGAAA,YAAY,OAAA;AAAE,2GAAA,kBAAkB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAC1D,qCAAoC;AAA3B,4FAAA,IAAI,OAAA;AACb,2CAAiD;AAAxC,uGAAA,aAAa,OAAA;AACtB,0CAAkD;AAAzC,qGAAA,aAAa,OAAA;AACtB,uDAA4D;AAAnD,oHAAA,mBAAmB,OAAA","sourcesContent":["export { AmplitudeCore } from './core-client';\nexport { Identify } from './identify';\nexport { Revenue } from './revenue';\nexport { Destination } from './plugins/destination';\nexport { Config } from './config';\nexport { Logger } from './logger';\nexport { AMPLITUDE_PREFIX } from './constants';\nexport { returnWrapper } from './utils/return-wrapper';\nexport { debugWrapper, getClientLogConfig, getClientStates } from './utils/debug';\nexport { UUID } from './utils/uuid';\nexport { MemoryStorage } from './storage/memory';\nexport { BaseTransport } from './transports/base';\nexport { createIdentifyEvent } from './utils/event-builder';\n"]}
@@ -7,5 +7,6 @@ export declare class Logger implements ILogger {
7
7
  log(...args: any[]): void;
8
8
  warn(...args: any[]): void;
9
9
  error(...args: any[]): void;
10
+ debug(...args: any[]): void;
10
11
  }
11
12
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAIzE,qBAAa,MAAO,YAAW,OAAO;IACpC,QAAQ,EAAE,QAAQ,CAAC;;IAMnB,OAAO,IAAI,IAAI;IAIf,MAAM,CAAC,QAAQ,GAAE,QAAwB,GAAG,IAAI;IAIhD,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAOzB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAO1B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;CAM5B"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAIzE,qBAAa,MAAO,YAAW,OAAO;IACpC,QAAQ,EAAE,QAAQ,CAAC;;IAMnB,OAAO,IAAI,IAAI;IAIf,MAAM,CAAC,QAAQ,GAAE,QAAwB,GAAG,IAAI;IAIhD,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAOzB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAO1B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAO3B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;CAO5B"}
package/lib/cjs/logger.js CHANGED
@@ -43,6 +43,17 @@ var Logger = /** @class */ (function () {
43
43
  }
44
44
  console.error("".concat(PREFIX, "[Error]: ").concat(args.join(' ')));
45
45
  };
46
+ Logger.prototype.debug = function () {
47
+ var args = [];
48
+ for (var _i = 0; _i < arguments.length; _i++) {
49
+ args[_i] = arguments[_i];
50
+ }
51
+ if (this.logLevel < analytics_types_1.LogLevel.Debug) {
52
+ return;
53
+ }
54
+ // console.debug output is hidden by default in chrome
55
+ console.log("".concat(PREFIX, "[Debug]: ").concat(args.join(' ')));
56
+ };
46
57
  return Logger;
47
58
  }());
48
59
  exports.Logger = Logger;
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":";;AAAA,8DAAyE;AAEzE,IAAM,MAAM,GAAG,mBAAmB,CAAC;AAEnC;IAGE;QACE,IAAI,CAAC,QAAQ,GAAG,0BAAQ,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,wBAAO,GAAP;QACE,IAAI,CAAC,QAAQ,GAAG,0BAAQ,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,uBAAM,GAAN,UAAO,QAAkC;QAAlC,yBAAA,EAAA,WAAqB,0BAAQ,CAAC,IAAI;QACvC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,oBAAG,GAAH;QAAI,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,yBAAc;;QAChB,IAAI,IAAI,CAAC,QAAQ,GAAG,0BAAQ,CAAC,OAAO,EAAE;YACpC,OAAO;SACR;QACD,OAAO,CAAC,GAAG,CAAC,UAAG,MAAM,oBAAU,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAE,CAAC,CAAC;IACnD,CAAC;IAED,qBAAI,GAAJ;QAAK,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,yBAAc;;QACjB,IAAI,IAAI,CAAC,QAAQ,GAAG,0BAAQ,CAAC,IAAI,EAAE;YACjC,OAAO;SACR;QACD,OAAO,CAAC,IAAI,CAAC,UAAG,MAAM,qBAAW,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAE,CAAC,CAAC;IACrD,CAAC;IAED,sBAAK,GAAL;QAAM,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,yBAAc;;QAClB,IAAI,IAAI,CAAC,QAAQ,GAAG,0BAAQ,CAAC,KAAK,EAAE;YAClC,OAAO;SACR;QACD,OAAO,CAAC,KAAK,CAAC,UAAG,MAAM,sBAAY,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAE,CAAC,CAAC;IACvD,CAAC;IACH,aAAC;AAAD,CAAC,AAnCD,IAmCC;AAnCY,wBAAM","sourcesContent":["import { LogLevel, Logger as ILogger } from '@amplitude/analytics-types';\n\nconst PREFIX = 'Amplitude Logger ';\n\nexport class Logger implements ILogger {\n logLevel: LogLevel;\n\n constructor() {\n this.logLevel = LogLevel.None;\n }\n\n disable(): void {\n this.logLevel = LogLevel.None;\n }\n\n enable(logLevel: LogLevel = LogLevel.Warn): void {\n this.logLevel = logLevel;\n }\n\n log(...args: any[]): void {\n if (this.logLevel < LogLevel.Verbose) {\n return;\n }\n console.log(`${PREFIX}[Log]: ${args.join(' ')}`);\n }\n\n warn(...args: any[]): void {\n if (this.logLevel < LogLevel.Warn) {\n return;\n }\n console.warn(`${PREFIX}[Warn]: ${args.join(' ')}`);\n }\n\n error(...args: any[]): void {\n if (this.logLevel < LogLevel.Error) {\n return;\n }\n console.error(`${PREFIX}[Error]: ${args.join(' ')}`);\n }\n}\n"]}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":";;AAAA,8DAAyE;AAEzE,IAAM,MAAM,GAAG,mBAAmB,CAAC;AAEnC;IAGE;QACE,IAAI,CAAC,QAAQ,GAAG,0BAAQ,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,wBAAO,GAAP;QACE,IAAI,CAAC,QAAQ,GAAG,0BAAQ,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,uBAAM,GAAN,UAAO,QAAkC;QAAlC,yBAAA,EAAA,WAAqB,0BAAQ,CAAC,IAAI;QACvC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,oBAAG,GAAH;QA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\nexport class Logger implements ILogger {\n logLevel: LogLevel;\n\n constructor() {\n this.logLevel = LogLevel.None;\n }\n\n disable(): void {\n this.logLevel = LogLevel.None;\n }\n\n enable(logLevel: LogLevel = LogLevel.Warn): void {\n this.logLevel = logLevel;\n }\n\n log(...args: any[]): void {\n if (this.logLevel < LogLevel.Verbose) {\n return;\n }\n console.log(`${PREFIX}[Log]: ${args.join(' ')}`);\n }\n\n warn(...args: any[]): void {\n if (this.logLevel < LogLevel.Warn) {\n return;\n }\n console.warn(`${PREFIX}[Warn]: ${args.join(' ')}`);\n }\n\n error(...args: any[]): void {\n if (this.logLevel < LogLevel.Error) {\n return;\n }\n console.error(`${PREFIX}[Error]: ${args.join(' ')}`);\n }\n\n debug(...args: any[]): void {\n if (this.logLevel < LogLevel.Debug) {\n return;\n }\n // console.debug output is hidden by default in chrome\n console.log(`${PREFIX}[Debug]: ${args.join(' ')}`);\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,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,CAAC,MAAM,CACjB,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,IAAI,KAAK,UAAU,EAA1B,CAA0B,CAAC,EAC9D,C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AC,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,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,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,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AQ","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"]}
@@ -0,0 +1,12 @@
1
+ import { Config, LogConfig } from '@amplitude/analytics-types';
2
+ import { AmplitudeCore } from '../core-client';
3
+ export declare const getStacktrace: (ignoreDepth?: number) => string[];
4
+ export declare const getClientLogConfig: (client: AmplitudeCore<Config>) => () => LogConfig;
5
+ export declare const getValueByStringPath: (obj: any, path: string) => any;
6
+ export declare const getClientStates: (client: AmplitudeCore<Config>, paths: Array<string>) => () => {
7
+ [key: string]: any;
8
+ };
9
+ export declare const debugWrapper: <T extends any[], R>(fn: (...args: T) => R, fnName: string, getLogConfig: () => LogConfig, getStates?: (() => {
10
+ [key: string]: any;
11
+ }) | undefined, fnContext?: any) => (...args: T) => R;
12
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../../src/utils/debug.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAY,SAAS,EAAgB,MAAM,4BAA4B,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,eAAO,MAAM,aAAa,4BAAsB,MAAM,EAMrD,CAAC;AAGF,eAAO,MAAM,kBAAkB,WAAY,cAAc,MAAM,CAAC,WAAS,SAMxE,CAAC;AAGF,eAAO,MAAM,oBAAoB,QAAS,GAAG,QAAQ,MAAM,KAAG,GAW7D,CAAC;AAEF,eAAO,MAAM,eAAe,WAAY,cAAc,MAAM,CAAC,SAAS,MAAM,MAAM,CAAC;;CAMlF,CAAC;AAEF,eAAO,MAAM,YAAY,sDAGb,MAAM,gBACA,MAAM,SAAS;;4BAElB,GAAG,sBA2Cf,CAAC"}
@@ -0,0 +1,123 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.debugWrapper = exports.getClientStates = exports.getValueByStringPath = exports.getClientLogConfig = exports.getStacktrace = void 0;
3
+ var tslib_1 = require("tslib");
4
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
5
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
6
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
7
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
8
+ var analytics_types_1 = require("@amplitude/analytics-types");
9
+ var getStacktrace = function (ignoreDepth) {
10
+ if (ignoreDepth === void 0) { ignoreDepth = 0; }
11
+ var trace = new Error().stack || '';
12
+ return trace
13
+ .split('\n')
14
+ .slice(2 + ignoreDepth)
15
+ .map(function (text) { return text.trim(); });
16
+ };
17
+ exports.getStacktrace = getStacktrace;
18
+ // This hook makes sure we always get the latest logger and logLevel.
19
+ var getClientLogConfig = function (client) { return function () {
20
+ var _a = (0, tslib_1.__assign)({}, client.config), logger = _a.loggerProvider, logLevel = _a.logLevel;
21
+ return {
22
+ logger: logger,
23
+ logLevel: logLevel,
24
+ };
25
+ }; };
26
+ exports.getClientLogConfig = getClientLogConfig;
27
+ // This is a convenient function to get the attribute from object with string path, similar to lodash '#get'.
28
+ var getValueByStringPath = function (obj, path) {
29
+ var e_1, _a;
30
+ path = path.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
31
+ path = path.replace(/^\./, ''); // strip a leading dot
32
+ try {
33
+ for (var _b = (0, tslib_1.__values)(path.split('.')), _c = _b.next(); !_c.done; _c = _b.next()) {
34
+ var attr = _c.value;
35
+ if (attr in obj) {
36
+ obj = obj[attr];
37
+ }
38
+ else {
39
+ return;
40
+ }
41
+ }
42
+ }
43
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
44
+ finally {
45
+ try {
46
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
47
+ }
48
+ finally { if (e_1) throw e_1.error; }
49
+ }
50
+ return obj;
51
+ };
52
+ exports.getValueByStringPath = getValueByStringPath;
53
+ var getClientStates = function (client, paths) { return function () {
54
+ var e_2, _a;
55
+ var res = {};
56
+ try {
57
+ for (var paths_1 = (0, tslib_1.__values)(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
58
+ var path = paths_1_1.value;
59
+ res[path] = (0, exports.getValueByStringPath)(client, path);
60
+ }
61
+ }
62
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
63
+ finally {
64
+ try {
65
+ if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
66
+ }
67
+ finally { if (e_2) throw e_2.error; }
68
+ }
69
+ return res;
70
+ }; };
71
+ exports.getClientStates = getClientStates;
72
+ var debugWrapper = function (fn, fnName, getLogConfig, getStates, fnContext) {
73
+ if (fnContext === void 0) { fnContext = null; }
74
+ return function () {
75
+ var args = [];
76
+ for (var _i = 0; _i < arguments.length; _i++) {
77
+ args[_i] = arguments[_i];
78
+ }
79
+ var _a = getLogConfig(), logger = _a.logger, logLevel = _a.logLevel;
80
+ // return early if possible to reduce overhead
81
+ if ((logLevel && logLevel < analytics_types_1.LogLevel.Debug) || !logLevel || !logger) {
82
+ return fn.apply(fnContext, args);
83
+ }
84
+ var debugContext = {
85
+ type: 'invoke public method',
86
+ name: fnName,
87
+ args: args,
88
+ stacktrace: (0, exports.getStacktrace)(1),
89
+ time: {
90
+ start: new Date().toISOString(),
91
+ },
92
+ states: {},
93
+ };
94
+ if (getStates && debugContext.states) {
95
+ debugContext.states.before = getStates();
96
+ }
97
+ var result = fn.apply(fnContext, args);
98
+ if (result && result.promise) {
99
+ // if result is a promise, add the callback
100
+ result.promise.then(function () {
101
+ if (getStates && debugContext.states) {
102
+ debugContext.states.after = getStates();
103
+ }
104
+ if (debugContext.time) {
105
+ debugContext.time.end = new Date().toISOString();
106
+ }
107
+ logger.debug(JSON.stringify(debugContext, null, 2));
108
+ });
109
+ }
110
+ else {
111
+ if (getStates && debugContext.states) {
112
+ debugContext.states.after = getStates();
113
+ }
114
+ if (debugContext.time) {
115
+ debugContext.time.end = new Date().toISOString();
116
+ }
117
+ logger.debug(JSON.stringify(debugContext, null, 2));
118
+ }
119
+ return result;
120
+ };
121
+ };
122
+ exports.debugWrapper = debugWrapper;
123
+ //# sourceMappingURL=debug.js.map