@amplitude/analytics-core 0.6.5 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/core-client.d.ts +2 -1
- package/lib/cjs/core-client.d.ts.map +1 -1
- package/lib/cjs/core-client.js +3 -2
- package/lib/cjs/core-client.js.map +1 -1
- package/lib/cjs/plugins/destination.d.ts.map +1 -1
- package/lib/cjs/plugins/destination.js +5 -1
- package/lib/cjs/plugins/destination.js.map +1 -1
- package/lib/cjs/utils/event-builder.d.ts +1 -1
- package/lib/cjs/utils/event-builder.d.ts.map +1 -1
- package/lib/cjs/utils/event-builder.js +3 -7
- package/lib/cjs/utils/event-builder.js.map +1 -1
- package/lib/cjs/utils/return-wrapper.d.ts +3 -2
- package/lib/cjs/utils/return-wrapper.d.ts.map +1 -1
- package/lib/cjs/utils/return-wrapper.js.map +1 -1
- package/lib/esm/core-client.d.ts +2 -1
- package/lib/esm/core-client.d.ts.map +1 -1
- package/lib/esm/core-client.js +3 -2
- package/lib/esm/core-client.js.map +1 -1
- package/lib/esm/plugins/destination.d.ts.map +1 -1
- package/lib/esm/plugins/destination.js +6 -2
- package/lib/esm/plugins/destination.js.map +1 -1
- package/lib/esm/utils/event-builder.d.ts +1 -1
- package/lib/esm/utils/event-builder.d.ts.map +1 -1
- package/lib/esm/utils/event-builder.js +3 -7
- package/lib/esm/utils/event-builder.js.map +1 -1
- package/lib/esm/utils/return-wrapper.d.ts +3 -2
- package/lib/esm/utils/return-wrapper.d.ts.map +1 -1
- package/lib/esm/utils/return-wrapper.js.map +1 -1
- package/package.json +3 -3
package/lib/cjs/core-client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CoreClient, Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types';
|
|
2
2
|
import { Timeline } from './timeline';
|
|
3
3
|
export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
|
|
4
|
+
initializing: boolean;
|
|
4
5
|
name: string;
|
|
5
6
|
config: T;
|
|
6
7
|
timeline: Timeline;
|
|
@@ -11,7 +12,7 @@ export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
|
|
|
11
12
|
logEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>;
|
|
12
13
|
identify(identify: Identify, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
13
14
|
groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
14
|
-
setGroup(groupType: string, groupName: string | string[]): Promise<import("@amplitude/analytics-types").Result>;
|
|
15
|
+
setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
15
16
|
revenue(revenue: Revenue, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
16
17
|
add(plugin: Plugin): Promise<void>;
|
|
17
18
|
remove(pluginName: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,MAAM,EACN,KAAK,EACL,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,OAAO,EACR,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,qBAAa,aAAa,CAAC,CAAC,SAAS,MAAM,CAAE,YAAW,UAAU,CAAC,CAAC,CAAC;IACnE,IAAI,EAAE,MAAM,CAAC;IAGb,MAAM,EAAE,CAAC,CAAC;IAGV,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAM;gBAEzB,IAAI,SAAa;IAKvB,KAAK,CAAC,MAAM,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AQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,YAAY;IAKxD,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,YAAY;IAK9G,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,YAAY,CAAC,EAAE,YAAY;IAKrF,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,YAAY;IAK/C,GAAG,CAAC,MAAM,EAAE,MAAM;IAQlB,MAAM,CAAC,UAAU,EAAE,MAAM;IAQzB,QAAQ,CAAC,KAAK,EAAE,KAAK;IAoB3B,SAAS,CAAC,MAAM,EAAE,OAAO;IAQzB,KAAK;CAGN"}
|
package/lib/cjs/core-client.js
CHANGED
|
@@ -8,6 +8,7 @@ var messages_1 = require("./messages");
|
|
|
8
8
|
var AmplitudeCore = /** @class */ (function () {
|
|
9
9
|
function AmplitudeCore(name) {
|
|
10
10
|
if (name === void 0) { name = '$default'; }
|
|
11
|
+
this.initializing = false;
|
|
11
12
|
this.q = [];
|
|
12
13
|
this.logEvent = this.track.bind(this);
|
|
13
14
|
this.timeline = new timeline_1.Timeline();
|
|
@@ -67,8 +68,8 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
67
68
|
var event = (0, event_builder_1.createGroupIdentifyEvent)(groupType, groupName, identify, eventOptions);
|
|
68
69
|
return this.dispatch(event);
|
|
69
70
|
};
|
|
70
|
-
AmplitudeCore.prototype.setGroup = function (groupType, groupName) {
|
|
71
|
-
var event = (0, event_builder_1.createGroupEvent)(groupType, groupName);
|
|
71
|
+
AmplitudeCore.prototype.setGroup = function (groupType, groupName, eventOptions) {
|
|
72
|
+
var event = (0, event_builder_1.createGroupEvent)(groupType, groupName, eventOptions);
|
|
72
73
|
return this.dispatch(event);
|
|
73
74
|
};
|
|
74
75
|
AmplitudeCore.prototype.revenue = function (revenue, eventOptions) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";;;AAUA,uDAM+B;AAC/B,uCAAsC;AACtC,yDAAqD;AACrD,uCAA6C;AAE7C;
|
|
1
|
+
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";;;AAUA,uDAM+B;AAC/B,uCAAsC;AACtC,yDAAqD;AACrD,uCAA6C;AAE7C;IAWE,uBAAY,IAAiB;QAAjB,qBAAA,EAAA,iBAAiB;QAV7B,iBAAY,GAAG,KAAK,CAAC;QAQX,MAAC,GAAuB,EAAE,CAAC;QAsBrC,aAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAnB/B,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEK,6BAAK,GAAX,UAAY,MAAS;;;;;;;wBACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;wBACrB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;wBAChB,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC;wBAC/B,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC;;;;wBACiB,oBAAA,sBAAA,eAAe,CAAA;;;;wBAAjC,cAAc;wBACvB,qBAAM,cAAc,EAAE,EAAA;;wBAAtB,SAAsB,CAAC;;;;;;;;;;;;;;;;;;;;KAE1B;IAED,6BAAK,GAAL,UAAM,UAA8B,EAAE,eAAqC,EAAE,YAA2B;QACtG,IAAM,KAAK,GAAG,IAAA,gCAAgB,EAAC,UAAU,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9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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,AApGD,IAoGC;AApGY,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\n constructor(name = '$default') {\n this.timeline = new Timeline();\n this.name = name;\n }\n\n async _init(config: T) {\n this.config = config;\n this.timeline.reset();\n const queuedFunctions = this.q;\n this.q = [];\n for (const queuedFunction of queuedFunctions) {\n await queuedFunction();\n }\n }\n\n track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions) {\n const event = createTrackEvent(eventInput, eventProperties, eventOptions);\n return this.dispatch(event);\n }\n\n logEvent = this.track.bind(this);\n\n identify(identify: Identify, eventOptions?: EventOptions) {\n const event = createIdentifyEvent(identify, eventOptions);\n return this.dispatch(event);\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions) {\n const event = createGroupIdentifyEvent(groupType, groupName, identify, eventOptions);\n return this.dispatch(event);\n }\n\n setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions) {\n const event = createGroupEvent(groupType, groupName, eventOptions);\n return this.dispatch(event);\n }\n\n revenue(revenue: Revenue, eventOptions?: EventOptions) {\n const event = createRevenueEvent(revenue, eventOptions);\n return this.dispatch(event);\n }\n\n async add(plugin: Plugin) {\n if (!this.config) {\n this.q.push(this.add.bind(this, plugin));\n return;\n }\n return this.timeline.register(plugin, this.config);\n }\n\n async remove(pluginName: string) {\n if (!this.config) {\n this.q.push(this.remove.bind(this, pluginName));\n return;\n }\n return this.timeline.deregister(pluginName);\n }\n\n async dispatch(event: Event) {\n try {\n // skip event processing if opt out\n if (this.config?.optOut) {\n return buildResult(event, 0, OPT_OUT_MESSAGE);\n }\n const result = await this.timeline.push(event);\n if (result.code === 200) {\n this.config.loggerProvider.log(result.message);\n } else {\n this.config.loggerProvider.error(result.message);\n }\n return result;\n } catch (e) {\n const message = String(e);\n this.config.loggerProvider.error(message);\n return buildResult(event, 0, message);\n }\n }\n\n setOptOut(optOut: boolean) {\n if (!this.config) {\n this.q.push(this.setOptOut.bind(this, Boolean(optOut)));\n return;\n }\n this.config.optOut = Boolean(optOut);\n }\n\n flush() {\n return this.timeline.flush();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destination.d.ts","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,IAAI,OAAO,EAC7B,iBAAiB,EACjB,KAAK,EACL,eAAe,EACf,uBAAuB,EACvB,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,MAAM,EAEN,eAAe,EAChB,MAAM,4BAA4B,CAAC;AAapC,qBAAa,WAAY,YAAW,iBAAiB;IACnD,IAAI,SAAe;IACnB,IAAI,yBAAmC;IAEvC,YAAY,SAAQ;IACpB,eAAe,SAAS;IACxB,UAAU,SAAM;IAIhB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,UAAS;IAClB,KAAK,EAAE,OAAO,EAAE,CAAM;IAEhB,KAAK,CAAC,MAAM,EAAE,MAAM,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qBAAqB,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE;IAyB3D,6BAA6B,CAAC,GAAG,EAAE,uBAAuB,EAAE,IAAI,EAAE,OAAO,EAAE;IAS3E,uBAAuB,CAAC,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,OAAO,EAAE;IAyB/D,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE;IASlC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAK7D;;;;;OAKG;IACH,UAAU;CAOX"}
|
|
@@ -125,7 +125,11 @@ var Destination = /** @class */ (function () {
|
|
|
125
125
|
}
|
|
126
126
|
payload = {
|
|
127
127
|
api_key: this.config.apiKey,
|
|
128
|
-
events: list.map(function (context) {
|
|
128
|
+
events: list.map(function (context) {
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
130
|
+
var _a = context.event, extra = _a.extra, eventWithoutExtra = (0, tslib_1.__rest)(_a, ["extra"]);
|
|
131
|
+
return eventWithoutExtra;
|
|
132
|
+
}),
|
|
129
133
|
options: {
|
|
130
134
|
min_id_length: this.config.minIdLength,
|
|
131
135
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":";;;AAAA,8DAaoC;AACpC,wCAMqB;AACrB,0CAA8C;AAC9C,wCAAuC;AACvC,0DAAsD;AACtD,oCAA+C;AAE/C;IAAA;QACE,SAAI,GAAG,WAAW,CAAC;QACnB,SAAI,GAAG,4BAAU,CAAC,WAAoB,CAAC;QAEvC,iBAAY,GAAG,IAAI,CAAC;QACpB,oBAAe,GAAG,KAAK,CAAC;QACxB,eAAU,GAAG,EAAE,CAAC;QAKhB,cAAS,GAAG,KAAK,CAAC;QAClB,UAAK,GAAc,EAAE,CAAC;IA4NxB,CAAC;IA1NO,2BAAK,GA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AAC;IAChE,CAAC;IACH,kBAAC;AAAD,CAAC,AAxOD,IAwOC;AAxOY,kCAAW","sourcesContent":["import {\n Config,\n DestinationContext as Context,\n DestinationPlugin,\n Event,\n InvalidResponse,\n PayloadTooLargeResponse,\n PluginType,\n RateLimitResponse,\n Response,\n Result,\n Status,\n SuccessResponse,\n} from '@amplitude/analytics-types';\nimport {\n INVALID_API_KEY,\n MAX_RETRIES_EXCEEDED_MESSAGE,\n MISSING_API_KEY_MESSAGE,\n SUCCESS_MESSAGE,\n UNEXPECTED_ERROR_MESSAGE,\n} from '../messages';\nimport { STORAGE_PREFIX } from '../constants';\nimport { chunk } from '../utils/chunk';\nimport { buildResult } from '../utils/result-builder';\nimport { createServerConfig } from '../config';\n\nexport class Destination implements DestinationPlugin {\n name = 'amplitude';\n type = PluginType.DESTINATION as const;\n\n retryTimeout = 1000;\n throttleTimeout = 30000;\n storageKey = '';\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: Config;\n scheduled = false;\n queue: Context[] = [];\n\n async setup(config: Config): Promise<undefined> {\n this.config = config;\n\n this.storageKey = `${STORAGE_PREFIX}_${this.config.apiKey.substring(0, 10)}`;\n const unsent = await this.config.storageProvider?.get(this.storageKey);\n this.saveEvents(); // sets storage to '[]'\n if (unsent && unsent.length > 0) {\n void Promise.all(unsent.map((event) => this.execute(event))).catch();\n }\n\n return Promise.resolve(undefined);\n }\n\n execute(event: Event): Promise<Result> {\n return new Promise((resolve) => {\n const context = {\n event,\n attempts: 0,\n callback: (result: Result) => resolve(result),\n timeout: 0,\n };\n void this.addToQueue(context);\n });\n }\n\n addToQueue(...list: Context[]) {\n const tryable = list.filter((context) => {\n if (context.attempts < this.config.flushMaxRetries) {\n context.attempts += 1;\n return true;\n }\n void this.fulfillRequest([context], 500, MAX_RETRIES_EXCEEDED_MESSAGE);\n return false;\n });\n\n tryable.forEach((context) => {\n this.queue = this.queue.concat(context);\n if (context.timeout === 0) {\n this.schedule(this.config.flushIntervalMillis);\n return;\n }\n\n setTimeout(() => {\n context.timeout = 0;\n this.schedule(0);\n }, context.timeout);\n });\n\n this.saveEvents();\n }\n\n schedule(timeout: number) {\n if (this.scheduled) return;\n this.scheduled = true;\n setTimeout(() => {\n void this.flush(true).then(() => {\n this.scheduled = false;\n if (this.queue.length > 0) {\n this.schedule(timeout);\n }\n });\n }, timeout);\n }\n\n async flush(useRetry = false) {\n const list: Context[] = [];\n const later: Context[] = [];\n this.queue.forEach((context) => (context.timeout === 0 ? list.push(context) : later.push(context)));\n this.queue = later;\n\n const batches = chunk(list, this.config.flushQueueSize);\n await Promise.all(batches.map((batch) => this.send(batch, useRetry)));\n }\n\n async send(list: Context[], useRetry = true) {\n if (!this.config.apiKey) {\n return this.fulfillRequest(list, 400, MISSING_API_KEY_MESSAGE);\n }\n\n const payload = {\n api_key: this.config.apiKey,\n events: list.map((context) => context.event),\n options: {\n min_id_length: this.config.minIdLength,\n },\n };\n\n try {\n const { serverUrl } = createServerConfig(this.config.serverUrl, this.config.serverZone, this.config.useBatch);\n const res = await this.config.transportProvider.send(serverUrl, payload);\n if (res === null) {\n this.fulfillRequest(list, 0, UNEXPECTED_ERROR_MESSAGE);\n return;\n }\n if (!useRetry) {\n this.fulfillRequest(list, res.statusCode, res.status);\n return;\n }\n this.handleReponse(res, list);\n } catch (e) {\n this.fulfillRequest(list, 0, String(e));\n }\n }\n\n handleReponse(res: Response, list: Context[]) {\n const { status } = res;\n switch (status) {\n case Status.Success:\n this.handleSuccessResponse(res, list);\n break;\n\n case Status.Invalid:\n this.handleInvalidResponse(res, list);\n break;\n\n case Status.PayloadTooLarge:\n this.handlePayloadTooLargeResponse(res, list);\n break;\n\n case Status.RateLimit:\n this.handleRateLimitResponse(res, list);\n break;\n\n default:\n this.handleOtherReponse(list);\n }\n }\n\n handleSuccessResponse(res: SuccessResponse, list: Context[]) {\n this.fulfillRequest(list, res.statusCode, SUCCESS_MESSAGE);\n }\n\n handleInvalidResponse(res: InvalidResponse, list: Context[]) {\n if (res.body.missingField || res.body.error.startsWith(INVALID_API_KEY)) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n\n const dropIndex = [\n ...Object.values(res.body.eventsWithInvalidFields),\n ...Object.values(res.body.eventsWithMissingFields),\n ...Object.values(res.body.eventsWithInvalidIdLengths),\n ...res.body.silencedEvents,\n ].flat();\n const dropIndexSet = new Set(dropIndex);\n\n const retry = list.filter((context, index) => {\n if (dropIndexSet.has(index)) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handlePayloadTooLargeResponse(res: PayloadTooLargeResponse, list: Context[]) {\n if (list.length === 1) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n this.config.flushQueueSize /= 2;\n this.addToQueue(...list);\n }\n\n handleRateLimitResponse(res: RateLimitResponse, list: Context[]) {\n const dropUserIds = Object.keys(res.body.exceededDailyQuotaUsers);\n const dropDeviceIds = Object.keys(res.body.exceededDailyQuotaDevices);\n const throttledIndex = res.body.throttledEvents;\n const dropUserIdsSet = new Set(dropUserIds);\n const dropDeviceIdsSet = new Set(dropDeviceIds);\n const throttledIndexSet = new Set(throttledIndex);\n\n const retry = list.filter((context, index) => {\n if (\n (context.event.user_id && dropUserIdsSet.has(context.event.user_id)) ||\n (context.event.device_id && dropDeviceIdsSet.has(context.event.device_id))\n ) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n if (throttledIndexSet.has(index)) {\n context.timeout = this.throttleTimeout;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handleOtherReponse(list: Context[]) {\n this.addToQueue(\n ...list.map((context) => {\n context.timeout = context.attempts * this.retryTimeout;\n return context;\n }),\n );\n }\n\n fulfillRequest(list: Context[], code: number, message: string) {\n this.saveEvents();\n list.forEach((context) => context.callback(buildResult(context.event, code, message)));\n }\n\n /**\n * Saves events to storage\n * This is called on\n * 1) new events are added to queue; or\n * 2) response comes back for a request\n */\n saveEvents() {\n if (!this.config.storageProvider) {\n return;\n }\n const events = Array.from(this.queue.map((context) => context.event));\n void this.config.storageProvider.set(this.storageKey, events);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":";;;AAAA,8DAaoC;AACpC,wCAMqB;AACrB,0CAA8C;AAC9C,wCAAuC;AACvC,0DAAsD;AACtD,oCAA+C;AAE/C;IAAA;QACE,SAAI,GAAG,WAAW,CAAC;QACnB,SAAI,GAAG,4BAAU,CAAC,WAAoB,CAAC;QAEvC,iBAAY,GAAG,IAAI,CAAC;QACpB,oBAAe,GAAG,KAAK,CAAC;QACxB,eAAU,GAAG,EAAE,CAAC;QAKhB,cAAS,GAAG,KAAK,CAAC;QAClB,UAAK,GAAc,EAAE,CAAC;IAgOxB,CAAC;IA9NO,2BAAK,GAAX,UAAY,MAAc;;;;;;;;wBACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;wBAErB,IAAI,CAAC,UAAU,GAAG,UAAG,0BAAc,cAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC;wBAC9D,qBAAM,CAAA,MAAA,IAAI,CAAC,MAAM,CAAC,eAAe,0CAAE,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA,EAAA;;wBAAhE,MAAM,GAAG,SAAuD;wBACtE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,uBAAuB;wBAC1C,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;4BAC/B,KAAK,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,KAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAnB,CAAmB,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;yBACtE;wBAED,sBAA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YACvD,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC,WACF;IACJ,CAAC;IAED,oCAAc,GAAd,UAAe,IAAe,EAAE,IAAY,EAAE,OAAe;QAC3D,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,OAAO,CAAC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,QAAQ,CAAC,IAAA,4BAAW,EAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,EAA3D,CAA2D,CAAC,CAAC;IACzF,CAAC;IAED;;;;;OAKG;IACH,gCAAU,GAAV;QACE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE;YAChC,OAAO;SACR;QACD,IAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,KAAK,EAAb,CAAa,CAAC,CAAC,CAAC;QACtE,KAAK,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IACH,kBAAC;AAAD,CAAC,AA5OD,IA4OC;AA5OY,kCAAW","sourcesContent":["import {\n Config,\n DestinationContext as Context,\n DestinationPlugin,\n Event,\n InvalidResponse,\n PayloadTooLargeResponse,\n PluginType,\n RateLimitResponse,\n Response,\n Result,\n Status,\n SuccessResponse,\n} from '@amplitude/analytics-types';\nimport {\n INVALID_API_KEY,\n MAX_RETRIES_EXCEEDED_MESSAGE,\n MISSING_API_KEY_MESSAGE,\n SUCCESS_MESSAGE,\n UNEXPECTED_ERROR_MESSAGE,\n} from '../messages';\nimport { STORAGE_PREFIX } from '../constants';\nimport { chunk } from '../utils/chunk';\nimport { buildResult } from '../utils/result-builder';\nimport { createServerConfig } from '../config';\n\nexport class Destination implements DestinationPlugin {\n name = 'amplitude';\n type = PluginType.DESTINATION as const;\n\n retryTimeout = 1000;\n throttleTimeout = 30000;\n storageKey = '';\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: Config;\n scheduled = false;\n queue: Context[] = [];\n\n async setup(config: Config): Promise<undefined> {\n this.config = config;\n\n this.storageKey = `${STORAGE_PREFIX}_${this.config.apiKey.substring(0, 10)}`;\n const unsent = await this.config.storageProvider?.get(this.storageKey);\n this.saveEvents(); // sets storage to '[]'\n if (unsent && unsent.length > 0) {\n void Promise.all(unsent.map((event) => this.execute(event))).catch();\n }\n\n return Promise.resolve(undefined);\n }\n\n execute(event: Event): Promise<Result> {\n return new Promise((resolve) => {\n const context = {\n event,\n attempts: 0,\n callback: (result: Result) => resolve(result),\n timeout: 0,\n };\n void this.addToQueue(context);\n });\n }\n\n addToQueue(...list: Context[]) {\n const tryable = list.filter((context) => {\n if (context.attempts < this.config.flushMaxRetries) {\n context.attempts += 1;\n return true;\n }\n void this.fulfillRequest([context], 500, MAX_RETRIES_EXCEEDED_MESSAGE);\n return false;\n });\n\n tryable.forEach((context) => {\n this.queue = this.queue.concat(context);\n if (context.timeout === 0) {\n this.schedule(this.config.flushIntervalMillis);\n return;\n }\n\n setTimeout(() => {\n context.timeout = 0;\n this.schedule(0);\n }, context.timeout);\n });\n\n this.saveEvents();\n }\n\n schedule(timeout: number) {\n if (this.scheduled) return;\n this.scheduled = true;\n setTimeout(() => {\n void this.flush(true).then(() => {\n this.scheduled = false;\n if (this.queue.length > 0) {\n this.schedule(timeout);\n }\n });\n }, timeout);\n }\n\n async flush(useRetry = false) {\n const list: Context[] = [];\n const later: Context[] = [];\n this.queue.forEach((context) => (context.timeout === 0 ? list.push(context) : later.push(context)));\n this.queue = later;\n\n const batches = chunk(list, this.config.flushQueueSize);\n await Promise.all(batches.map((batch) => this.send(batch, useRetry)));\n }\n\n async send(list: Context[], useRetry = true) {\n if (!this.config.apiKey) {\n return this.fulfillRequest(list, 400, MISSING_API_KEY_MESSAGE);\n }\n\n const payload = {\n api_key: this.config.apiKey,\n events: list.map((context) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { extra, ...eventWithoutExtra } = context.event;\n return eventWithoutExtra;\n }),\n options: {\n min_id_length: this.config.minIdLength,\n },\n };\n\n try {\n const { serverUrl } = createServerConfig(this.config.serverUrl, this.config.serverZone, this.config.useBatch);\n const res = await this.config.transportProvider.send(serverUrl, payload);\n if (res === null) {\n this.fulfillRequest(list, 0, UNEXPECTED_ERROR_MESSAGE);\n return;\n }\n if (!useRetry) {\n this.fulfillRequest(list, res.statusCode, res.status);\n return;\n }\n this.handleReponse(res, list);\n } catch (e) {\n this.fulfillRequest(list, 0, String(e));\n }\n }\n\n handleReponse(res: Response, list: Context[]) {\n const { status } = res;\n switch (status) {\n case Status.Success:\n this.handleSuccessResponse(res, list);\n break;\n\n case Status.Invalid:\n this.handleInvalidResponse(res, list);\n break;\n\n case Status.PayloadTooLarge:\n this.handlePayloadTooLargeResponse(res, list);\n break;\n\n case Status.RateLimit:\n this.handleRateLimitResponse(res, list);\n break;\n\n default:\n this.handleOtherReponse(list);\n }\n }\n\n handleSuccessResponse(res: SuccessResponse, list: Context[]) {\n this.fulfillRequest(list, res.statusCode, SUCCESS_MESSAGE);\n }\n\n handleInvalidResponse(res: InvalidResponse, list: Context[]) {\n if (res.body.missingField || res.body.error.startsWith(INVALID_API_KEY)) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n\n const dropIndex = [\n ...Object.values(res.body.eventsWithInvalidFields),\n ...Object.values(res.body.eventsWithMissingFields),\n ...Object.values(res.body.eventsWithInvalidIdLengths),\n ...res.body.silencedEvents,\n ].flat();\n const dropIndexSet = new Set(dropIndex);\n\n const retry = list.filter((context, index) => {\n if (dropIndexSet.has(index)) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handlePayloadTooLargeResponse(res: PayloadTooLargeResponse, list: Context[]) {\n if (list.length === 1) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n this.config.flushQueueSize /= 2;\n this.addToQueue(...list);\n }\n\n handleRateLimitResponse(res: RateLimitResponse, list: Context[]) {\n const dropUserIds = Object.keys(res.body.exceededDailyQuotaUsers);\n const dropDeviceIds = Object.keys(res.body.exceededDailyQuotaDevices);\n const throttledIndex = res.body.throttledEvents;\n const dropUserIdsSet = new Set(dropUserIds);\n const dropDeviceIdsSet = new Set(dropDeviceIds);\n const throttledIndexSet = new Set(throttledIndex);\n\n const retry = list.filter((context, index) => {\n if (\n (context.event.user_id && dropUserIdsSet.has(context.event.user_id)) ||\n (context.event.device_id && dropDeviceIdsSet.has(context.event.device_id))\n ) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n if (throttledIndexSet.has(index)) {\n context.timeout = this.throttleTimeout;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handleOtherReponse(list: Context[]) {\n this.addToQueue(\n ...list.map((context) => {\n context.timeout = context.attempts * this.retryTimeout;\n return context;\n }),\n );\n }\n\n fulfillRequest(list: Context[], code: number, message: string) {\n this.saveEvents();\n list.forEach((context) => context.callback(buildResult(context.event, code, message)));\n }\n\n /**\n * Saves events to storage\n * This is called on\n * 1) new events are added to queue; or\n * 2) response comes back for a request\n */\n saveEvents() {\n if (!this.config.storageProvider) {\n return;\n }\n const events = Array.from(this.queue.map((context) => context.event));\n void this.config.storageProvider.set(this.storageKey, events);\n }\n}\n"]}
|
|
@@ -2,6 +2,6 @@ import { BaseEvent, TrackEvent, IdentifyEvent, GroupIdentifyEvent, Identify as I
|
|
|
2
2
|
export declare const createTrackEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => TrackEvent;
|
|
3
3
|
export declare const createIdentifyEvent: (identify: IIdentify, eventOptions?: EventOptions | undefined) => IdentifyEvent;
|
|
4
4
|
export declare const createGroupIdentifyEvent: (groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions | undefined) => GroupIdentifyEvent;
|
|
5
|
-
export declare const createGroupEvent: (groupType: string, groupName: string | string[]) => IdentifyEvent;
|
|
5
|
+
export declare const createGroupEvent: (groupType: string, groupName: string | string[], eventOptions?: EventOptions | undefined) => IdentifyEvent;
|
|
6
6
|
export declare const createRevenueEvent: (revenue: Revenue, eventOptions?: EventOptions | undefined) => RevenueEvent;
|
|
7
7
|
//# sourceMappingURL=event-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,aAAa,EACb,kBAAkB,EAElB,QAAQ,IAAI,SAAS,EACrB,OAAO,EACP,YAAY,EACZ,YAAY,EACb,MAAM,4BAA4B,CAAC;AAGpC,eAAO,MAAM,gBAAgB,eACf,SAAS,GAAG,MAAM,iGAG7B,UAOF,CAAC;AAEF,eAAO,MAAM,mBAAmB,aAAc,SAAS,8CAAgC,aAQtF,CAAC;AAEF,eAAO,MAAM,wBAAwB,cACxB,MAAM,aACN,MAAM,GAAG,MAAM,EAAE,YAClB,SAAS,8CAElB,kBAWF,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAAe,MAAM,aAAa,MAAM,GAAG,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"event-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,aAAa,EACb,kBAAkB,EAElB,QAAQ,IAAI,SAAS,EACrB,OAAO,EACP,YAAY,EACZ,YAAY,EACb,MAAM,4BAA4B,CAAC;AAGpC,eAAO,MAAM,gBAAgB,eACf,SAAS,GAAG,MAAM,iGAG7B,UAOF,CAAC;AAEF,eAAO,MAAM,mBAAmB,aAAc,SAAS,8CAAgC,aAQtF,CAAC;AAEF,eAAO,MAAM,wBAAwB,cACxB,MAAM,aACN,MAAM,GAAG,MAAM,EAAE,YAClB,SAAS,8CAElB,kBAWF,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAAe,MAAM,aAAa,MAAM,GAAG,MAAM,EAAE,2DAa/E,CAAC;AAEF,eAAO,MAAM,kBAAkB,YAAa,OAAO,8CAAgC,YAMlF,CAAC"}
|
|
@@ -21,17 +21,13 @@ var createGroupIdentifyEvent = function (groupType, groupName, identify, eventOp
|
|
|
21
21
|
return groupIdentify;
|
|
22
22
|
};
|
|
23
23
|
exports.createGroupIdentifyEvent = createGroupIdentifyEvent;
|
|
24
|
-
var createGroupEvent = function (groupType, groupName) {
|
|
24
|
+
var createGroupEvent = function (groupType, groupName, eventOptions) {
|
|
25
25
|
var _a;
|
|
26
26
|
var identify = new identify_1.Identify();
|
|
27
27
|
identify.set(groupType, groupName);
|
|
28
|
-
var groupEvent = {
|
|
29
|
-
event_type: analytics_types_1.SpecialEventType.IDENTIFY,
|
|
30
|
-
user_properties: identify.getUserProperties(),
|
|
31
|
-
groups: (_a = {},
|
|
28
|
+
var groupEvent = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, eventOptions), { event_type: analytics_types_1.SpecialEventType.IDENTIFY, user_properties: identify.getUserProperties(), groups: (_a = {},
|
|
32
29
|
_a[groupType] = groupName,
|
|
33
|
-
_a)
|
|
34
|
-
};
|
|
30
|
+
_a) });
|
|
35
31
|
return groupEvent;
|
|
36
32
|
};
|
|
37
33
|
exports.createGroupEvent = createGroupEvent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-builder.js","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":";;;AAAA,8DAUoC;AACpC,wCAAuC;AAEhC,IAAM,gBAAgB,GAAG,UAC9B,UAA8B,EAC9B,eAAqC,EACrC,YAA2B;IAE3B,IAAM,SAAS,GAAc,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,C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AAA,kBAAkB,sBAM7B","sourcesContent":["import {\n BaseEvent,\n TrackEvent,\n IdentifyEvent,\n GroupIdentifyEvent,\n SpecialEventType,\n Identify as IIdentify,\n Revenue,\n RevenueEvent,\n EventOptions,\n} from '@amplitude/analytics-types';\nimport { Identify } from '../identify';\n\nexport const createTrackEvent = (\n eventInput: BaseEvent | string,\n eventProperties?: Record<string, any>,\n eventOptions?: EventOptions,\n): TrackEvent => {\n const baseEvent: BaseEvent = typeof eventInput === 'string' ? { event_type: eventInput } : eventInput;\n return {\n ...baseEvent,\n ...eventOptions,\n ...(eventProperties && { event_properties: eventProperties }),\n };\n};\n\nexport const createIdentifyEvent = (identify: IIdentify, eventOptions?: EventOptions): IdentifyEvent => {\n const identifyEvent: IdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.IDENTIFY,\n user_properties: identify.getUserProperties(),\n };\n\n return identifyEvent;\n};\n\nexport const createGroupIdentifyEvent = (\n groupType: string,\n groupName: string | string[],\n identify: IIdentify,\n eventOptions?: EventOptions,\n): GroupIdentifyEvent => {\n const groupIdentify: GroupIdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.GROUP_IDENTIFY,\n group_properties: identify.getUserProperties(),\n groups: {\n [groupType]: groupName,\n },\n };\n\n return groupIdentify;\n};\n\nexport const createGroupEvent = (groupType: string, groupName: string | string[], eventOptions?: EventOptions) => {\n const identify = new Identify();\n identify.set(groupType, groupName);\n\n const groupEvent: IdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.IDENTIFY,\n user_properties: identify.getUserProperties(),\n groups: {\n [groupType]: groupName,\n },\n };\n return groupEvent;\n};\n\nexport const createRevenueEvent = (revenue: Revenue, eventOptions?: EventOptions): RevenueEvent => {\n return {\n ...eventOptions,\n event_type: SpecialEventType.REVENUE,\n event_properties: revenue.getEventProperties(),\n };\n};\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export declare const returnWrapper: <T extends (...args: any) => any>(fn: T) => (...args: Parameters<T>) => {
|
|
2
|
+
promise: ReturnType<T>;
|
|
3
|
+
};
|
|
3
4
|
//# sourceMappingURL=return-wrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"return-wrapper.d.ts","sourceRoot":"","sources":["../../../src/utils/return-wrapper.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"return-wrapper.d.ts","sourceRoot":"","sources":["../../../src/utils/return-wrapper.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,uBACH,GAAG,KAAK,GAAG;;CAG9B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"return-wrapper.js","sourceRoot":"","sources":["../../../src/utils/return-wrapper.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"return-wrapper.js","sourceRoot":"","sources":["../../../src/utils/return-wrapper.ts"],"names":[],"mappings":";;;AAAO,IAAM,aAAa,GACxB,UAAkC,EAAK;IACvC,OAAA;QAAC,cAAsB;aAAtB,UAAsB,EAAtB,qBAAsB,EAAtB,IAAsB;YAAtB,yBAAsB;;QAAK,OAAA,CAAC;YAC3B,OAAO,EAAE,EAAE,kEAAI,IAAI,UAAkB;SACtC,CAAC;IAF0B,CAE1B;AAFF,CAEE,CAAC;AAJQ,QAAA,aAAa,iBAIrB","sourcesContent":["export const returnWrapper =\n <T extends (...args: any) => any>(fn: T) =>\n (...args: Parameters<T>) => ({\n promise: fn(...args) as ReturnType<T>,\n });\n"]}
|
package/lib/esm/core-client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CoreClient, Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types';
|
|
2
2
|
import { Timeline } from './timeline';
|
|
3
3
|
export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
|
|
4
|
+
initializing: boolean;
|
|
4
5
|
name: string;
|
|
5
6
|
config: T;
|
|
6
7
|
timeline: Timeline;
|
|
@@ -11,7 +12,7 @@ export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
|
|
|
11
12
|
logEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>;
|
|
12
13
|
identify(identify: Identify, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
13
14
|
groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
14
|
-
setGroup(groupType: string, groupName: string | string[]): Promise<import("@amplitude/analytics-types").Result>;
|
|
15
|
+
setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
15
16
|
revenue(revenue: Revenue, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
16
17
|
add(plugin: Plugin): Promise<void>;
|
|
17
18
|
remove(pluginName: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,MAAM,EACN,KAAK,EACL,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,OAAO,EACR,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,qBAAa,aAAa,CAAC,CAAC,SAAS,MAAM,CAAE,YAAW,UAAU,CAAC,CAAC,CAAC;IACnE,IAAI,EAAE,MAAM,CAAC;IAGb,MAAM,EAAE,CAAC,CAAC;IAGV,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAM;gBAEzB,IAAI,SAAa;IAKvB,KAAK,CAAC,MAAM,EAAE,CAAC;IAUrB,KAAK,CAAC,UAAU,EAAE,SAAS,GAA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E,YAAY;IAKxD,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,YAAY;IAK9G,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,YAAY,CAAC,EAAE,YAAY;IAKrF,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,YAAY;IAK/C,GAAG,CAAC,MAAM,EAAE,MAAM;IAQlB,MAAM,CAAC,UAAU,EAAE,MAAM;IAQzB,QAAQ,CAAC,KAAK,EAAE,KAAK;IAoB3B,SAAS,CAAC,MAAM,EAAE,OAAO;IAQzB,KAAK;CAGN"}
|
package/lib/esm/core-client.js
CHANGED
|
@@ -6,6 +6,7 @@ import { OPT_OUT_MESSAGE } from './messages';
|
|
|
6
6
|
var AmplitudeCore = /** @class */ (function () {
|
|
7
7
|
function AmplitudeCore(name) {
|
|
8
8
|
if (name === void 0) { name = '$default'; }
|
|
9
|
+
this.initializing = false;
|
|
9
10
|
this.q = [];
|
|
10
11
|
this.logEvent = this.track.bind(this);
|
|
11
12
|
this.timeline = new Timeline();
|
|
@@ -65,8 +66,8 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
65
66
|
var event = createGroupIdentifyEvent(groupType, groupName, identify, eventOptions);
|
|
66
67
|
return this.dispatch(event);
|
|
67
68
|
};
|
|
68
|
-
AmplitudeCore.prototype.setGroup = function (groupType, groupName) {
|
|
69
|
-
var event = createGroupEvent(groupType, groupName);
|
|
69
|
+
AmplitudeCore.prototype.setGroup = function (groupType, groupName, eventOptions) {
|
|
70
|
+
var event = createGroupEvent(groupType, groupName, eventOptions);
|
|
70
71
|
return this.dispatch(event);
|
|
71
72
|
};
|
|
72
73
|
AmplitudeCore.prototype.revenue = function (revenue, eventOptions) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";AAUA,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;
|
|
1
|
+
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";AAUA,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;IAWE,uBAAY,IAAiB;QAAjB,qBAAA,EAAA,iBAAiB;QAV7B,iBAAY,GAAG,KAAK,CAAC;QAQX,MAAC,GAAuB,EAAE,CAAC;QAsBrC,aAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAnB/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;wBAChB,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC;wBAC/B,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC;;;;wBACiB,oBAAA,SAAA,eAAe,CAAA;;;;wBA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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,AApGD,IAoGC","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\n constructor(name = '$default') {\n this.timeline = new Timeline();\n this.name = name;\n }\n\n async _init(config: T) {\n this.config = config;\n this.timeline.reset();\n const queuedFunctions = this.q;\n this.q = [];\n for (const queuedFunction of queuedFunctions) {\n await queuedFunction();\n }\n }\n\n track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions) {\n const event = createTrackEvent(eventInput, eventProperties, eventOptions);\n return this.dispatch(event);\n }\n\n logEvent = this.track.bind(this);\n\n identify(identify: Identify, eventOptions?: EventOptions) {\n const event = createIdentifyEvent(identify, eventOptions);\n return this.dispatch(event);\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions) {\n const event = createGroupIdentifyEvent(groupType, groupName, identify, eventOptions);\n return this.dispatch(event);\n }\n\n setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions) {\n const event = createGroupEvent(groupType, groupName, eventOptions);\n return this.dispatch(event);\n }\n\n revenue(revenue: Revenue, eventOptions?: EventOptions) {\n const event = createRevenueEvent(revenue, eventOptions);\n return this.dispatch(event);\n }\n\n async add(plugin: Plugin) {\n if (!this.config) {\n this.q.push(this.add.bind(this, plugin));\n return;\n }\n return this.timeline.register(plugin, this.config);\n }\n\n async remove(pluginName: string) {\n if (!this.config) {\n this.q.push(this.remove.bind(this, pluginName));\n return;\n }\n return this.timeline.deregister(pluginName);\n }\n\n async dispatch(event: Event) {\n try {\n // skip event processing if opt out\n if (this.config?.optOut) {\n return buildResult(event, 0, OPT_OUT_MESSAGE);\n }\n const result = await this.timeline.push(event);\n if (result.code === 200) {\n this.config.loggerProvider.log(result.message);\n } else {\n this.config.loggerProvider.error(result.message);\n }\n return result;\n } catch (e) {\n const message = String(e);\n this.config.loggerProvider.error(message);\n return buildResult(event, 0, message);\n }\n }\n\n setOptOut(optOut: boolean) {\n if (!this.config) {\n this.q.push(this.setOptOut.bind(this, Boolean(optOut)));\n return;\n }\n this.config.optOut = Boolean(optOut);\n }\n\n flush() {\n return this.timeline.flush();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destination.d.ts","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,IAAI,OAAO,EAC7B,iBAAiB,EACjB,KAAK,EACL,eAAe,EACf,uBAAuB,EACvB,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,MAAM,EAEN,eAAe,EAChB,MAAM,4BAA4B,CAAC;AAapC,q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IAalB,KAAK,CAAC,QAAQ,UAAQ;IAUtB,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,QAAQ,UAAO;IAkC3C,aAAa,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE;IAwB5C,qBAAqB,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE;IAI3D,qBAAqB,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE;IAyB3D,6BAA6B,CAAC,GAAG,EAAE,uBAAuB,EAAE,IAAI,EAAE,OAAO,EAAE;IAS3E,uBAAuB,CAAC,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,OAAO,EAAE;IAyB/D,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE;IASlC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAK7D;;;;;OAKG;IACH,UAAU;CAOX"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __awaiter, __generator, __read, __spreadArray } from "tslib";
|
|
1
|
+
import { __awaiter, __generator, __read, __rest, __spreadArray } from "tslib";
|
|
2
2
|
import { PluginType, Status, } from '@amplitude/analytics-types';
|
|
3
3
|
import { INVALID_API_KEY, MAX_RETRIES_EXCEEDED_MESSAGE, MISSING_API_KEY_MESSAGE, SUCCESS_MESSAGE, UNEXPECTED_ERROR_MESSAGE, } from '../messages';
|
|
4
4
|
import { STORAGE_PREFIX } from '../constants';
|
|
@@ -123,7 +123,11 @@ var Destination = /** @class */ (function () {
|
|
|
123
123
|
}
|
|
124
124
|
payload = {
|
|
125
125
|
api_key: this.config.apiKey,
|
|
126
|
-
events: list.map(function (context) {
|
|
126
|
+
events: list.map(function (context) {
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
128
|
+
var _a = context.event, extra = _a.extra, eventWithoutExtra = __rest(_a, ["extra"]);
|
|
129
|
+
return eventWithoutExtra;
|
|
130
|
+
}),
|
|
127
131
|
options: {
|
|
128
132
|
min_id_length: this.config.minIdLength,
|
|
129
133
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":";AAAA,OAAO,EAOL,UAAU,EAIV,MAAM,GAEP,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,eAAe,EACf,4BAA4B,EAC5B,uBAAuB,EACvB,eAAe,EACf,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C;IAAA;QACE,SAAI,GAAG,WAAW,CAAC;QACnB,SAAI,GAAG,UAAU,CAAC,WAAoB,CAAC;QAEvC,iBAAY,GAAG,IAAI,CAAC;QACpB,oBAAe,GAAG,KAAK,CAAC;QACxB,eAAU,GAAG,EAAE,CAAC;QAKhB,cAAS,GAAG,KAAK,CAAC;QAClB,UAAK,GAAc,EAAE,CAAC;IA4NxB,CAAC;IA1NO,2BAAK,GAAX,UAAY,MAAc;;;;;;;;wBACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;wBAErB,IAAI,CAAC,UAAU,GAAG,UAAG,cAAc,cAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC;wBAC9D,qBAAM,CAAA,MAAA,IAAI,CAAC,MAAM,CAAC,eAAe,0CAAE,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA,EAAA;;wBAAhE,MAAM,GAAG,SAAuD;wBACtE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,uBAA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,2BACC,IAAI,CAAC,GAAG,CAAC,UAAC,OAAO;YAClB,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,KAAI,CAAC,YAAY,CAAC;YACvD,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC,WACF;IACJ,CAAC;IAED,oCAAc,GAAd,UAAe,IAAe,EAAE,IAAY,EAAE,OAAe;QAC3D,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,OAAO,CAAC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,EAA3D,CAA2D,CAAC,CAAC;IACzF,CAAC;IAED;;;;;OAKG;IACH,gCAAU,GAAV;QACE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE;YAChC,OAAO;SACR;QACD,IAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,KAAK,EAAb,CAAa,CAAC,CAAC,CAAC;QACtE,KAAK,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IACH,kBAAC;AAAD,CAAC,AAxOD,IAwOC","sourcesContent":["import {\n Config,\n DestinationContext as Context,\n DestinationPlugin,\n Event,\n InvalidResponse,\n PayloadTooLargeResponse,\n PluginType,\n RateLimitResponse,\n Response,\n Result,\n Status,\n SuccessResponse,\n} from '@amplitude/analytics-types';\nimport {\n INVALID_API_KEY,\n MAX_RETRIES_EXCEEDED_MESSAGE,\n MISSING_API_KEY_MESSAGE,\n SUCCESS_MESSAGE,\n UNEXPECTED_ERROR_MESSAGE,\n} from '../messages';\nimport { STORAGE_PREFIX } from '../constants';\nimport { chunk } from '../utils/chunk';\nimport { buildResult } from '../utils/result-builder';\nimport { createServerConfig } from '../config';\n\nexport class Destination implements DestinationPlugin {\n name = 'amplitude';\n type = PluginType.DESTINATION as const;\n\n retryTimeout = 1000;\n throttleTimeout = 30000;\n storageKey = '';\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: Config;\n scheduled = false;\n queue: Context[] = [];\n\n async setup(config: Config): Promise<undefined> {\n this.config = config;\n\n this.storageKey = `${STORAGE_PREFIX}_${this.config.apiKey.substring(0, 10)}`;\n const unsent = await this.config.storageProvider?.get(this.storageKey);\n this.saveEvents(); // sets storage to '[]'\n if (unsent && unsent.length > 0) {\n void Promise.all(unsent.map((event) => this.execute(event))).catch();\n }\n\n return Promise.resolve(undefined);\n }\n\n execute(event: Event): Promise<Result> {\n return new Promise((resolve) => {\n const context = {\n event,\n attempts: 0,\n callback: (result: Result) => resolve(result),\n timeout: 0,\n };\n void this.addToQueue(context);\n });\n }\n\n addToQueue(...list: Context[]) {\n const tryable = list.filter((context) => {\n if (context.attempts < this.config.flushMaxRetries) {\n context.attempts += 1;\n return true;\n }\n void this.fulfillRequest([context], 500, MAX_RETRIES_EXCEEDED_MESSAGE);\n return false;\n });\n\n tryable.forEach((context) => {\n this.queue = this.queue.concat(context);\n if (context.timeout === 0) {\n this.schedule(this.config.flushIntervalMillis);\n return;\n }\n\n setTimeout(() => {\n context.timeout = 0;\n this.schedule(0);\n }, context.timeout);\n });\n\n this.saveEvents();\n }\n\n schedule(timeout: number) {\n if (this.scheduled) return;\n this.scheduled = true;\n setTimeout(() => {\n void this.flush(true).then(() => {\n this.scheduled = false;\n if (this.queue.length > 0) {\n this.schedule(timeout);\n }\n });\n }, timeout);\n }\n\n async flush(useRetry = false) {\n const list: Context[] = [];\n const later: Context[] = [];\n this.queue.forEach((context) => (context.timeout === 0 ? list.push(context) : later.push(context)));\n this.queue = later;\n\n const batches = chunk(list, this.config.flushQueueSize);\n await Promise.all(batches.map((batch) => this.send(batch, useRetry)));\n }\n\n async send(list: Context[], useRetry = true) {\n if (!this.config.apiKey) {\n return this.fulfillRequest(list, 400, MISSING_API_KEY_MESSAGE);\n }\n\n const payload = {\n api_key: this.config.apiKey,\n events: list.map((context) => context.event),\n options: {\n min_id_length: this.config.minIdLength,\n },\n };\n\n try {\n const { serverUrl } = createServerConfig(this.config.serverUrl, this.config.serverZone, this.config.useBatch);\n const res = await this.config.transportProvider.send(serverUrl, payload);\n if (res === null) {\n this.fulfillRequest(list, 0, UNEXPECTED_ERROR_MESSAGE);\n return;\n }\n if (!useRetry) {\n this.fulfillRequest(list, res.statusCode, res.status);\n return;\n }\n this.handleReponse(res, list);\n } catch (e) {\n this.fulfillRequest(list, 0, String(e));\n }\n }\n\n handleReponse(res: Response, list: Context[]) {\n const { status } = res;\n switch (status) {\n case Status.Success:\n this.handleSuccessResponse(res, list);\n break;\n\n case Status.Invalid:\n this.handleInvalidResponse(res, list);\n break;\n\n case Status.PayloadTooLarge:\n this.handlePayloadTooLargeResponse(res, list);\n break;\n\n case Status.RateLimit:\n this.handleRateLimitResponse(res, list);\n break;\n\n default:\n this.handleOtherReponse(list);\n }\n }\n\n handleSuccessResponse(res: SuccessResponse, list: Context[]) {\n this.fulfillRequest(list, res.statusCode, SUCCESS_MESSAGE);\n }\n\n handleInvalidResponse(res: InvalidResponse, list: Context[]) {\n if (res.body.missingField || res.body.error.startsWith(INVALID_API_KEY)) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n\n const dropIndex = [\n ...Object.values(res.body.eventsWithInvalidFields),\n ...Object.values(res.body.eventsWithMissingFields),\n ...Object.values(res.body.eventsWithInvalidIdLengths),\n ...res.body.silencedEvents,\n ].flat();\n const dropIndexSet = new Set(dropIndex);\n\n const retry = list.filter((context, index) => {\n if (dropIndexSet.has(index)) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handlePayloadTooLargeResponse(res: PayloadTooLargeResponse, list: Context[]) {\n if (list.length === 1) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n this.config.flushQueueSize /= 2;\n this.addToQueue(...list);\n }\n\n handleRateLimitResponse(res: RateLimitResponse, list: Context[]) {\n const dropUserIds = Object.keys(res.body.exceededDailyQuotaUsers);\n const dropDeviceIds = Object.keys(res.body.exceededDailyQuotaDevices);\n const throttledIndex = res.body.throttledEvents;\n const dropUserIdsSet = new Set(dropUserIds);\n const dropDeviceIdsSet = new Set(dropDeviceIds);\n const throttledIndexSet = new Set(throttledIndex);\n\n const retry = list.filter((context, index) => {\n if (\n (context.event.user_id && dropUserIdsSet.has(context.event.user_id)) ||\n (context.event.device_id && dropDeviceIdsSet.has(context.event.device_id))\n ) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n if (throttledIndexSet.has(index)) {\n context.timeout = this.throttleTimeout;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handleOtherReponse(list: Context[]) {\n this.addToQueue(\n ...list.map((context) => {\n context.timeout = context.attempts * this.retryTimeout;\n return context;\n }),\n );\n }\n\n fulfillRequest(list: Context[], code: number, message: string) {\n this.saveEvents();\n list.forEach((context) => context.callback(buildResult(context.event, code, message)));\n }\n\n /**\n * Saves events to storage\n * This is called on\n * 1) new events are added to queue; or\n * 2) response comes back for a request\n */\n saveEvents() {\n if (!this.config.storageProvider) {\n return;\n }\n const events = Array.from(this.queue.map((context) => context.event));\n void this.config.storageProvider.set(this.storageKey, events);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":";AAAA,OAAO,EAOL,UAAU,EAIV,MAAM,GAEP,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,eAAe,EACf,4BAA4B,EAC5B,uBAAuB,EACvB,eAAe,EACf,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AA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AAC,OAAO,IAAK,OAAA,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,EAA3D,CAA2D,CAAC,CAAC;IACzF,CAAC;IAED;;;;;OAKG;IACH,gCAAU,GAAV;QACE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE;YAChC,OAAO;SACR;QACD,IAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,KAAK,EAAb,CAAa,CAAC,CAAC,CAAC;QACtE,KAAK,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IACH,kBAAC;AAAD,CAAC,AA5OD,IA4OC","sourcesContent":["import {\n Config,\n DestinationContext as Context,\n DestinationPlugin,\n Event,\n InvalidResponse,\n PayloadTooLargeResponse,\n PluginType,\n RateLimitResponse,\n Response,\n Result,\n Status,\n SuccessResponse,\n} from '@amplitude/analytics-types';\nimport {\n INVALID_API_KEY,\n MAX_RETRIES_EXCEEDED_MESSAGE,\n MISSING_API_KEY_MESSAGE,\n SUCCESS_MESSAGE,\n UNEXPECTED_ERROR_MESSAGE,\n} from '../messages';\nimport { STORAGE_PREFIX } from '../constants';\nimport { chunk } from '../utils/chunk';\nimport { buildResult } from '../utils/result-builder';\nimport { createServerConfig } from '../config';\n\nexport class Destination implements DestinationPlugin {\n name = 'amplitude';\n type = PluginType.DESTINATION as const;\n\n retryTimeout = 1000;\n throttleTimeout = 30000;\n storageKey = '';\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: Config;\n scheduled = false;\n queue: Context[] = [];\n\n async setup(config: Config): Promise<undefined> {\n this.config = config;\n\n this.storageKey = `${STORAGE_PREFIX}_${this.config.apiKey.substring(0, 10)}`;\n const unsent = await this.config.storageProvider?.get(this.storageKey);\n this.saveEvents(); // sets storage to '[]'\n if (unsent && unsent.length > 0) {\n void Promise.all(unsent.map((event) => this.execute(event))).catch();\n }\n\n return Promise.resolve(undefined);\n }\n\n execute(event: Event): Promise<Result> {\n return new Promise((resolve) => {\n const context = {\n event,\n attempts: 0,\n callback: (result: Result) => resolve(result),\n timeout: 0,\n };\n void this.addToQueue(context);\n });\n }\n\n addToQueue(...list: Context[]) {\n const tryable = list.filter((context) => {\n if (context.attempts < this.config.flushMaxRetries) {\n context.attempts += 1;\n return true;\n }\n void this.fulfillRequest([context], 500, MAX_RETRIES_EXCEEDED_MESSAGE);\n return false;\n });\n\n tryable.forEach((context) => {\n this.queue = this.queue.concat(context);\n if (context.timeout === 0) {\n this.schedule(this.config.flushIntervalMillis);\n return;\n }\n\n setTimeout(() => {\n context.timeout = 0;\n this.schedule(0);\n }, context.timeout);\n });\n\n this.saveEvents();\n }\n\n schedule(timeout: number) {\n if (this.scheduled) return;\n this.scheduled = true;\n setTimeout(() => {\n void this.flush(true).then(() => {\n this.scheduled = false;\n if (this.queue.length > 0) {\n this.schedule(timeout);\n }\n });\n }, timeout);\n }\n\n async flush(useRetry = false) {\n const list: Context[] = [];\n const later: Context[] = [];\n this.queue.forEach((context) => (context.timeout === 0 ? list.push(context) : later.push(context)));\n this.queue = later;\n\n const batches = chunk(list, this.config.flushQueueSize);\n await Promise.all(batches.map((batch) => this.send(batch, useRetry)));\n }\n\n async send(list: Context[], useRetry = true) {\n if (!this.config.apiKey) {\n return this.fulfillRequest(list, 400, MISSING_API_KEY_MESSAGE);\n }\n\n const payload = {\n api_key: this.config.apiKey,\n events: list.map((context) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { extra, ...eventWithoutExtra } = context.event;\n return eventWithoutExtra;\n }),\n options: {\n min_id_length: this.config.minIdLength,\n },\n };\n\n try {\n const { serverUrl } = createServerConfig(this.config.serverUrl, this.config.serverZone, this.config.useBatch);\n const res = await this.config.transportProvider.send(serverUrl, payload);\n if (res === null) {\n this.fulfillRequest(list, 0, UNEXPECTED_ERROR_MESSAGE);\n return;\n }\n if (!useRetry) {\n this.fulfillRequest(list, res.statusCode, res.status);\n return;\n }\n this.handleReponse(res, list);\n } catch (e) {\n this.fulfillRequest(list, 0, String(e));\n }\n }\n\n handleReponse(res: Response, list: Context[]) {\n const { status } = res;\n switch (status) {\n case Status.Success:\n this.handleSuccessResponse(res, list);\n break;\n\n case Status.Invalid:\n this.handleInvalidResponse(res, list);\n break;\n\n case Status.PayloadTooLarge:\n this.handlePayloadTooLargeResponse(res, list);\n break;\n\n case Status.RateLimit:\n this.handleRateLimitResponse(res, list);\n break;\n\n default:\n this.handleOtherReponse(list);\n }\n }\n\n handleSuccessResponse(res: SuccessResponse, list: Context[]) {\n this.fulfillRequest(list, res.statusCode, SUCCESS_MESSAGE);\n }\n\n handleInvalidResponse(res: InvalidResponse, list: Context[]) {\n if (res.body.missingField || res.body.error.startsWith(INVALID_API_KEY)) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n\n const dropIndex = [\n ...Object.values(res.body.eventsWithInvalidFields),\n ...Object.values(res.body.eventsWithMissingFields),\n ...Object.values(res.body.eventsWithInvalidIdLengths),\n ...res.body.silencedEvents,\n ].flat();\n const dropIndexSet = new Set(dropIndex);\n\n const retry = list.filter((context, index) => {\n if (dropIndexSet.has(index)) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handlePayloadTooLargeResponse(res: PayloadTooLargeResponse, list: Context[]) {\n if (list.length === 1) {\n this.fulfillRequest(list, res.statusCode, res.body.error);\n return;\n }\n this.config.flushQueueSize /= 2;\n this.addToQueue(...list);\n }\n\n handleRateLimitResponse(res: RateLimitResponse, list: Context[]) {\n const dropUserIds = Object.keys(res.body.exceededDailyQuotaUsers);\n const dropDeviceIds = Object.keys(res.body.exceededDailyQuotaDevices);\n const throttledIndex = res.body.throttledEvents;\n const dropUserIdsSet = new Set(dropUserIds);\n const dropDeviceIdsSet = new Set(dropDeviceIds);\n const throttledIndexSet = new Set(throttledIndex);\n\n const retry = list.filter((context, index) => {\n if (\n (context.event.user_id && dropUserIdsSet.has(context.event.user_id)) ||\n (context.event.device_id && dropDeviceIdsSet.has(context.event.device_id))\n ) {\n this.fulfillRequest([context], res.statusCode, res.body.error);\n return;\n }\n if (throttledIndexSet.has(index)) {\n context.timeout = this.throttleTimeout;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handleOtherReponse(list: Context[]) {\n this.addToQueue(\n ...list.map((context) => {\n context.timeout = context.attempts * this.retryTimeout;\n return context;\n }),\n );\n }\n\n fulfillRequest(list: Context[], code: number, message: string) {\n this.saveEvents();\n list.forEach((context) => context.callback(buildResult(context.event, code, message)));\n }\n\n /**\n * Saves events to storage\n * This is called on\n * 1) new events are added to queue; or\n * 2) response comes back for a request\n */\n saveEvents() {\n if (!this.config.storageProvider) {\n return;\n }\n const events = Array.from(this.queue.map((context) => context.event));\n void this.config.storageProvider.set(this.storageKey, events);\n }\n}\n"]}
|
|
@@ -2,6 +2,6 @@ import { BaseEvent, TrackEvent, IdentifyEvent, GroupIdentifyEvent, Identify as I
|
|
|
2
2
|
export declare const createTrackEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => TrackEvent;
|
|
3
3
|
export declare const createIdentifyEvent: (identify: IIdentify, eventOptions?: EventOptions | undefined) => IdentifyEvent;
|
|
4
4
|
export declare const createGroupIdentifyEvent: (groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions | undefined) => GroupIdentifyEvent;
|
|
5
|
-
export declare const createGroupEvent: (groupType: string, groupName: string | string[]) => IdentifyEvent;
|
|
5
|
+
export declare const createGroupEvent: (groupType: string, groupName: string | string[], eventOptions?: EventOptions | undefined) => IdentifyEvent;
|
|
6
6
|
export declare const createRevenueEvent: (revenue: Revenue, eventOptions?: EventOptions | undefined) => RevenueEvent;
|
|
7
7
|
//# sourceMappingURL=event-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,aAAa,EACb,kBAAkB,EAElB,QAAQ,IAAI,SAAS,EACrB,OAAO,EACP,YAAY,EACZ,YAAY,EACb,MAAM,4BAA4B,CAAC;AAGpC,eAAO,MAAM,gBAAgB,eACf,SAAS,GAAG,MAAM,iGAG7B,UAOF,CAAC;AAEF,eAAO,MAAM,mBAAmB,aAAc,SAAS,8CAAgC,aAQtF,CAAC;AAEF,eAAO,MAAM,wBAAwB,cACxB,MAAM,aACN,MAAM,GAAG,MAAM,EAAE,YAClB,SAAS,8CAElB,kBAWF,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAAe,MAAM,aAAa,MAAM,GAAG,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"event-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,aAAa,EACb,kBAAkB,EAElB,QAAQ,IAAI,SAAS,EACrB,OAAO,EACP,YAAY,EACZ,YAAY,EACb,MAAM,4BAA4B,CAAC;AAGpC,eAAO,MAAM,gBAAgB,eACf,SAAS,GAAG,MAAM,iGAG7B,UAOF,CAAC;AAEF,eAAO,MAAM,mBAAmB,aAAc,SAAS,8CAAgC,aAQtF,CAAC;AAEF,eAAO,MAAM,wBAAwB,cACxB,MAAM,aACN,MAAM,GAAG,MAAM,EAAE,YAClB,SAAS,8CAElB,kBAWF,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAAe,MAAM,aAAa,MAAM,GAAG,MAAM,EAAE,2DAa/E,CAAC;AAEF,eAAO,MAAM,kBAAkB,YAAa,OAAO,8CAAgC,YAMlF,CAAC"}
|
|
@@ -16,17 +16,13 @@ export var createGroupIdentifyEvent = function (groupType, groupName, identify,
|
|
|
16
16
|
_a) });
|
|
17
17
|
return groupIdentify;
|
|
18
18
|
};
|
|
19
|
-
export var createGroupEvent = function (groupType, groupName) {
|
|
19
|
+
export var createGroupEvent = function (groupType, groupName, eventOptions) {
|
|
20
20
|
var _a;
|
|
21
21
|
var identify = new Identify();
|
|
22
22
|
identify.set(groupType, groupName);
|
|
23
|
-
var groupEvent = {
|
|
24
|
-
event_type: SpecialEventType.IDENTIFY,
|
|
25
|
-
user_properties: identify.getUserProperties(),
|
|
26
|
-
groups: (_a = {},
|
|
23
|
+
var groupEvent = __assign(__assign({}, eventOptions), { event_type: SpecialEventType.IDENTIFY, user_properties: identify.getUserProperties(), groups: (_a = {},
|
|
27
24
|
_a[groupType] = groupName,
|
|
28
|
-
_a)
|
|
29
|
-
};
|
|
25
|
+
_a) });
|
|
30
26
|
return groupEvent;
|
|
31
27
|
};
|
|
32
28
|
export var createRevenueEvent = function (revenue, eventOptions) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-builder.js","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":";AAAA,OAAO,EAKL,gBAAgB,GAKjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAC9B,UAA8B,EAC9B,eAAqC,EACrC,YAA2B;IAE3B,IAAM,SAAS,GAAc,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;IACtG,sCACK,SAAS,GACT,YAAY,GACZ,CAAC,eAAe,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC,EAC7D;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,mBAAmB,GAAG,UAAC,QA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AAQ,CAAC,iBAAiB,EAAE,GAC9C,CAAC;IAEF,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,wBAAwB,GAAG,UACtC,SAAiB,EACjB,SAA4B,EAC5B,QAAmB,EACnB,YAA2B;;IAE3B,IAAM,aAAa,yBACd,YAAY,KACf,UAAU,EAAE,gBAAgB,CAAC,cAAc,EAC3C,gBAAgB,EAAE,QAAQ,CAAC,iBAAiB,EAAE,EAC9C,MAAM;YACJ,GAAC,SAAS,IAAG,SAAS;kBAEzB,CAAC;IAEF,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAAC,SAAiB,EAAE,SAA4B,EAAE,YAA2B;;IAC3G,IAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAEnC,IAAM,UAAU,yBACX,YAAY,KACf,UAAU,EAAE,gBAAgB,CAAC,QAAQ,EACrC,eAAe,EAAE,QAAQ,CAAC,iBAAiB,EAAE,EAC7C,MAAM;YACJ,GAAC,SAAS,IAAG,SAAS;kBAEzB,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,kBAAkB,GAAG,UAAC,OAAgB,EAAE,YAA2B;IAC9E,6BACK,YAAY,KACf,UAAU,EAAE,gBAAgB,CAAC,OAAO,EACpC,gBAAgB,EAAE,OAAO,CAAC,kBAAkB,EAAE,IAC9C;AACJ,CAAC,CAAC","sourcesContent":["import {\n BaseEvent,\n TrackEvent,\n IdentifyEvent,\n GroupIdentifyEvent,\n SpecialEventType,\n Identify as IIdentify,\n Revenue,\n RevenueEvent,\n EventOptions,\n} from '@amplitude/analytics-types';\nimport { Identify } from '../identify';\n\nexport const createTrackEvent = (\n eventInput: BaseEvent | string,\n eventProperties?: Record<string, any>,\n eventOptions?: EventOptions,\n): TrackEvent => {\n const baseEvent: BaseEvent = typeof eventInput === 'string' ? { event_type: eventInput } : eventInput;\n return {\n ...baseEvent,\n ...eventOptions,\n ...(eventProperties && { event_properties: eventProperties }),\n };\n};\n\nexport const createIdentifyEvent = (identify: IIdentify, eventOptions?: EventOptions): IdentifyEvent => {\n const identifyEvent: IdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.IDENTIFY,\n user_properties: identify.getUserProperties(),\n };\n\n return identifyEvent;\n};\n\nexport const createGroupIdentifyEvent = (\n groupType: string,\n groupName: string | string[],\n identify: IIdentify,\n eventOptions?: EventOptions,\n): GroupIdentifyEvent => {\n const groupIdentify: GroupIdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.GROUP_IDENTIFY,\n group_properties: identify.getUserProperties(),\n groups: {\n [groupType]: groupName,\n },\n };\n\n return groupIdentify;\n};\n\nexport const createGroupEvent = (groupType: string, groupName: string | string[], eventOptions?: EventOptions) => {\n const identify = new Identify();\n identify.set(groupType, groupName);\n\n const groupEvent: IdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.IDENTIFY,\n user_properties: identify.getUserProperties(),\n groups: {\n [groupType]: groupName,\n },\n };\n return groupEvent;\n};\n\nexport const createRevenueEvent = (revenue: Revenue, eventOptions?: EventOptions): RevenueEvent => {\n return {\n ...eventOptions,\n event_type: SpecialEventType.REVENUE,\n event_properties: revenue.getEventProperties(),\n };\n};\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export declare const returnWrapper: <T extends (...args: any) => any>(fn: T) => (...args: Parameters<T>) => {
|
|
2
|
+
promise: ReturnType<T>;
|
|
3
|
+
};
|
|
3
4
|
//# sourceMappingURL=return-wrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"return-wrapper.d.ts","sourceRoot":"","sources":["../../../src/utils/return-wrapper.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"return-wrapper.d.ts","sourceRoot":"","sources":["../../../src/utils/return-wrapper.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,uBACH,GAAG,KAAK,GAAG;;CAG9B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"return-wrapper.js","sourceRoot":"","sources":["../../../src/utils/return-wrapper.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"return-wrapper.js","sourceRoot":"","sources":["../../../src/utils/return-wrapper.ts"],"names":[],"mappings":";AAAA,MAAM,CAAC,IAAM,aAAa,GACxB,UAAkC,EAAK;IACvC,OAAA;QAAC,cAAsB;aAAtB,UAAsB,EAAtB,qBAAsB,EAAtB,IAAsB;YAAtB,yBAAsB;;QAAK,OAAA,CAAC;YAC3B,OAAO,EAAE,EAAE,wCAAI,IAAI,UAAkB;SACtC,CAAC;IAF0B,CAE1B;AAFF,CAEE,CAAC","sourcesContent":["export const returnWrapper =\n <T extends (...args: any) => any>(fn: T) =>\n (...args: Parameters<T>) => ({\n promise: fn(...args) as ReturnType<T>,\n });\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/analytics-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Amplitude Inc",
|
|
6
6
|
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@amplitude/analytics-types": "^0.
|
|
36
|
+
"@amplitude/analytics-types": "^0.8.0",
|
|
37
37
|
"tslib": "^2.3.1"
|
|
38
38
|
},
|
|
39
39
|
"files": [
|
|
40
40
|
"lib"
|
|
41
41
|
],
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "c701a2b7ada6c8817bf28894f4d68cfa5dd0c403"
|
|
43
43
|
}
|