@amplitude/analytics-core 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/config.d.ts +5 -7
- package/lib/cjs/config.d.ts.map +1 -1
- package/lib/cjs/config.js +12 -5
- package/lib/cjs/config.js.map +1 -1
- package/lib/cjs/core-client.d.ts +5 -4
- package/lib/cjs/core-client.d.ts.map +1 -1
- package/lib/cjs/core-client.js +8 -4
- package/lib/cjs/core-client.js.map +1 -1
- package/lib/cjs/event-bridge/event-bridge-channel.d.ts +10 -0
- package/lib/cjs/event-bridge/event-bridge-channel.d.ts.map +1 -0
- package/lib/cjs/event-bridge/event-bridge-channel.js +32 -0
- package/lib/cjs/event-bridge/event-bridge-channel.js.map +1 -0
- package/lib/cjs/event-bridge/event-bridge-container.d.ts +6 -0
- package/lib/cjs/event-bridge/event-bridge-container.d.ts.map +1 -0
- package/lib/cjs/event-bridge/event-bridge-container.js +17 -0
- package/lib/cjs/event-bridge/event-bridge-container.js.map +1 -0
- package/lib/cjs/event-bridge/event-bridge.d.ts +8 -0
- package/lib/cjs/event-bridge/event-bridge.d.ts.map +1 -0
- package/lib/cjs/event-bridge/event-bridge.js +23 -0
- package/lib/cjs/event-bridge/event-bridge.js.map +1 -0
- package/lib/cjs/event-bridge/event-channel.d.ts +5 -0
- package/lib/cjs/event-bridge/event-channel.d.ts.map +1 -0
- package/lib/cjs/event-bridge/event-channel.js +8 -0
- package/lib/cjs/event-bridge/event-channel.js.map +1 -0
- package/lib/cjs/event-bridge/event-receiver.d.ts +8 -0
- package/lib/cjs/event-bridge/event-receiver.d.ts.map +1 -0
- package/lib/cjs/event-bridge/event-receiver.js +27 -0
- package/lib/cjs/event-bridge/event-receiver.js.map +1 -0
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +7 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/plugins/destination.d.ts +2 -1
- package/lib/cjs/plugins/destination.d.ts.map +1 -1
- package/lib/cjs/plugins/destination.js +13 -3
- package/lib/cjs/plugins/destination.js.map +1 -1
- package/lib/cjs/storage/memory.d.ts +11 -0
- package/lib/cjs/storage/memory.d.ts.map +1 -0
- package/lib/cjs/storage/memory.js +29 -0
- package/lib/cjs/storage/memory.js.map +1 -0
- package/lib/cjs/timeline.d.ts +1 -0
- package/lib/cjs/timeline.d.ts.map +1 -1
- package/lib/cjs/timeline.js +16 -1
- package/lib/cjs/timeline.js.map +1 -1
- package/lib/cjs/utils/event-builder.d.ts +2 -2
- package/lib/cjs/utils/event-builder.d.ts.map +1 -1
- package/lib/cjs/utils/event-builder.js +4 -10
- package/lib/cjs/utils/event-builder.js.map +1 -1
- package/lib/cjs/utils/uuid.d.ts +10 -0
- package/lib/cjs/utils/uuid.d.ts.map +1 -0
- package/lib/cjs/utils/uuid.js +31 -0
- package/lib/cjs/utils/uuid.js.map +1 -0
- package/lib/esm/config.d.ts +5 -7
- package/lib/esm/config.d.ts.map +1 -1
- package/lib/esm/config.js +12 -5
- package/lib/esm/config.js.map +1 -1
- package/lib/esm/core-client.d.ts +5 -4
- package/lib/esm/core-client.d.ts.map +1 -1
- package/lib/esm/core-client.js +9 -5
- package/lib/esm/core-client.js.map +1 -1
- package/lib/esm/event-bridge/event-bridge-channel.d.ts +10 -0
- package/lib/esm/event-bridge/event-bridge-channel.d.ts.map +1 -0
- package/lib/esm/event-bridge/event-bridge-channel.js +30 -0
- package/lib/esm/event-bridge/event-bridge-channel.js.map +1 -0
- package/lib/esm/event-bridge/event-bridge-container.d.ts +6 -0
- package/lib/esm/event-bridge/event-bridge-container.d.ts.map +1 -0
- package/lib/esm/event-bridge/event-bridge-container.js +15 -0
- package/lib/esm/event-bridge/event-bridge-container.js.map +1 -0
- package/lib/esm/event-bridge/event-bridge.d.ts +8 -0
- package/lib/esm/event-bridge/event-bridge.d.ts.map +1 -0
- package/lib/esm/event-bridge/event-bridge.js +21 -0
- package/lib/esm/event-bridge/event-bridge.js.map +1 -0
- package/lib/esm/event-bridge/event-channel.d.ts +5 -0
- package/lib/esm/event-bridge/event-channel.d.ts.map +1 -0
- package/lib/esm/event-bridge/event-channel.js +6 -0
- package/lib/esm/event-bridge/event-channel.js.map +1 -0
- package/lib/esm/event-bridge/event-receiver.d.ts +8 -0
- package/lib/esm/event-bridge/event-receiver.d.ts.map +1 -0
- package/lib/esm/event-bridge/event-receiver.js +25 -0
- package/lib/esm/event-bridge/event-receiver.js.map +1 -0
- package/lib/esm/index.d.ts +3 -0
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +3 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/plugins/destination.d.ts +2 -1
- package/lib/esm/plugins/destination.d.ts.map +1 -1
- package/lib/esm/plugins/destination.js +13 -3
- package/lib/esm/plugins/destination.js.map +1 -1
- package/lib/esm/storage/memory.d.ts +11 -0
- package/lib/esm/storage/memory.d.ts.map +1 -0
- package/lib/esm/storage/memory.js +27 -0
- package/lib/esm/storage/memory.js.map +1 -0
- package/lib/esm/timeline.d.ts +1 -0
- package/lib/esm/timeline.d.ts.map +1 -1
- package/lib/esm/timeline.js +14 -0
- package/lib/esm/timeline.js.map +1 -1
- package/lib/esm/utils/event-builder.d.ts +2 -2
- package/lib/esm/utils/event-builder.d.ts.map +1 -1
- package/lib/esm/utils/event-builder.js +4 -10
- package/lib/esm/utils/event-builder.js.map +1 -1
- package/lib/esm/utils/uuid.d.ts +10 -0
- package/lib/esm/utils/uuid.d.ts.map +1 -0
- package/lib/esm/utils/uuid.js +28 -0
- package/lib/esm/utils/uuid.js.map +1 -0
- package/package.json +3 -3
- package/lib/cjs/transports/http.d.ts +0 -6
- package/lib/cjs/transports/http.d.ts.map +0 -1
- package/lib/cjs/transports/http.js +0 -55
- package/lib/cjs/transports/http.js.map +0 -1
- package/lib/esm/transports/http.d.ts +0 -6
- package/lib/esm/transports/http.d.ts.map +0 -1
- package/lib/esm/transports/http.js +0 -53
- package/lib/esm/transports/http.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../../src/plugins/destination.ts"],"names":[],"mappings":";;;AAAA,8DAaoC;AACpC,wCAAiG;AACjG,0CAA8C;AAC9C,wCAAuC;AACvC,0DAAsD;AACtD,oCAA+C;AAE/C;IAAA;QACE,SAAI,GAAG,WAAW,CAAC;QACnB,SAAI,GAAG,4BAAU,CAAC,WAAoB,CAAC;QAEvC,YAAO,GAAG,IAAI,CAAC;QACf,aAAQ,GAAG,KAAK,CAAC;QACjB,eAAU,GAAG,EAAE,CAAC;QAChB,WAAM,GAAe,IAAI,GAAG,EAAE,CAAC;QAK/B,cAAS,GAAG,KAAK,CAAC;QAClB,UAAK,GAAc,EAAE,CAAC;IAoNxB,CAAC;IAlNC,2BAAK,GAAL,UAAM,MAAc;QAApB,iBAWC;QAVC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,UAAU,GAAG,UAAG,0BAAc,cAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC;QAC7E,IAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAChE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,uBAAuB;QACxC,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAC/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;SACtE;QAED,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,6BAAO,GAAP,UAAQ,K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AAO;QACpC,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK,IAAK,OAAA,KAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAtB,CAAsB,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC;IAED,sCAAgB,GAAhB;QAAA,iBAIC;QAJgB,gBAAkB;aAAlB,UAAkB,EAAlB,qBAAkB,EAAlB,IAAkB;YAAlB,2BAAkB;;QACjC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU;YAAE,OAAO;QACpC,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK,IAAK,OAAA,KAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAzB,CAAyB,CAAC,CAAC;QACrD,IAAI,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC;IAED,8BAAQ,GAAR;QACE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU;YAAE,OAAO;QACpC,IAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC;IACH,kBAAC;AAAD,CAAC,AAjOD,IAiOC;AAjOY,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 { MISSING_API_KEY_MESSAGE, SUCCESS_MESSAGE, UNEXPECTED_ERROR_MESSAGE } 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 backoff = 1000;\n throttle = 30000;\n storageKey = '';\n backup: Set<Event> = new Set();\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 setup(config: Config) {\n this.config = config;\n\n this.storageKey = `${STORAGE_PREFIX}_${this.config.apiKey.substring(0, 10)}`;\n const unsent = this.config.storageProvider.get(this.storageKey);\n this.snapshot(); // 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 delay: 0,\n };\n this.addToQueue(context);\n });\n }\n\n addToQueue(...list: Context[]) {\n const tryable = list.filter((context) => {\n if (context.attempts < this.config.flushMaxRetries) {\n return true;\n }\n this.fulfillRequest([context], 500, Status.Unknown);\n return false;\n });\n\n this.addToBackup(...tryable.map((context) => context.event));\n tryable.forEach((context) => {\n context.attempts += 1;\n const delay = context.delay;\n context.delay = 0;\n if (context.attempts === 1 && !context.delay) {\n this.queue = this.queue.concat(context);\n this.schedule(this.config.flushIntervalMillis);\n return;\n }\n setTimeout(() => {\n this.queue = this.queue.concat(context);\n this.schedule(this.config.flushIntervalMillis);\n }, delay || context.attempts * this.backoff);\n });\n }\n\n schedule(timeout: number) {\n if (this.scheduled) return;\n this.scheduled = true;\n setTimeout(() => {\n void this.flush().then(() => {\n this.scheduled = false;\n if (this.queue.length > 0) {\n this.schedule(timeout);\n }\n });\n }, timeout);\n }\n\n async flush() {\n const list = this.queue;\n this.queue = [];\n const batches = chunk(list, this.config.flushQueueSize);\n await Promise.all(batches.map((batch) => this.send(batch)));\n }\n\n async send(list: Context[]) {\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 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) {\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.delay = this.throttle;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handleOtherReponse(list: Context[]) {\n this.addToQueue(...list);\n }\n\n fulfillRequest(list: Context[], code: number, message: string) {\n this.removeFromBackup(...list.map((context) => context.event));\n list.forEach((context) => context.callback(buildResult(context.event, code, message)));\n }\n\n addToBackup(...events: Event[]) {\n if (!this.config.saveEvents) return;\n events.forEach((event) => this.backup.add(event));\n this.snapshot();\n }\n\n removeFromBackup(...events: Event[]) {\n if (!this.config.saveEvents) return;\n events.forEach((event) => this.backup.delete(event));\n this.snapshot();\n }\n\n snapshot() {\n if (!this.config.saveEvents) return;\n const events = Array.from(this.backup);\n 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,wCAAiG;AACjG,0CAA8C;AAC9C,wCAAuC;AACvC,0DAAsD;AACtD,oCAA+C;AAE/C;IAAA;QACE,SAAI,GAAG,WAAW,CAAC;QACnB,SAAI,GAAG,4BAAU,CAAC,WAAoB,CAAC;QAEvC,YAAO,GAAG,IAAI,CAAC;QACf,aAAQ,GAAG,KAAK,CAAC;QACjB,eAAU,GAAG,EAAE,CAAC;QAChB,WAAM,GAAe,IAAI,GAAG,EAAE,CAAC;QAK/B,cAAS,GAAG,KAAK,CAAC;QAClB,UAAK,GAAc,EAAE,CAA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K,OAAA,KAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAtB,CAAsB,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC;IAED,sCAAgB,GAAhB;QAAA,iBAIC;QAJgB,gBAAkB;aAAlB,UAAkB,EAAlB,qBAAkB,EAAlB,IAAkB;YAAlB,2BAAkB;;QACjC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU;YAAE,OAAO;QACpC,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK,IAAK,OAAA,KAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAzB,CAAyB,CAAC,CAAC;QACrD,IAAI,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC;IAED,8BAAQ,GAAR;QACE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU;YAAE,OAAO;QACpC,IAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC;IACH,kBAAC;AAAD,CAAC,AA3OD,IA2OC;AA3OY,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 { MISSING_API_KEY_MESSAGE, SUCCESS_MESSAGE, UNEXPECTED_ERROR_MESSAGE } 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 backoff = 1000;\n throttle = 30000;\n storageKey = '';\n backup: Set<Event> = new Set();\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 queueBuffer: Set<Context> = new Set();\n\n setup(config: Config) {\n this.config = config;\n\n this.storageKey = `${STORAGE_PREFIX}_${this.config.apiKey.substring(0, 10)}`;\n const unsent = this.config.storageProvider.get(this.storageKey);\n this.snapshot(); // 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 delay: 0,\n };\n this.addToQueue(context);\n });\n }\n\n addToQueue(...list: Context[]) {\n const tryable = list.filter((context) => {\n if (context.attempts < this.config.flushMaxRetries) {\n return true;\n }\n this.fulfillRequest([context], 500, Status.Unknown);\n return false;\n });\n\n this.addToBackup(...tryable.map((context) => context.event));\n tryable.forEach((context) => {\n context.attempts += 1;\n const delay = context.delay;\n context.delay = 0;\n if (context.attempts === 1 && !context.delay) {\n this.queue = this.queue.concat(context);\n this.schedule(this.config.flushIntervalMillis);\n return;\n }\n this.queueBuffer.add(context);\n setTimeout(() => {\n if (this.queueBuffer.has(context)) {\n this.queueBuffer.delete(context);\n this.queue = this.queue.concat(context);\n this.schedule(this.config.flushIntervalMillis);\n }\n }, delay || context.attempts * this.backoff);\n });\n }\n\n schedule(timeout: number) {\n if (this.scheduled) return;\n this.scheduled = true;\n setTimeout(() => {\n void this.flush().then(() => {\n this.scheduled = false;\n if (this.queue.length > 0) {\n this.schedule(timeout);\n }\n });\n }, timeout);\n }\n\n async flush(includeQueueBuffer = false) {\n const list = this.queue;\n this.queue = [];\n\n if (includeQueueBuffer) {\n list.push(...this.queueBuffer.values());\n this.queueBuffer.clear();\n }\n const batches = chunk(list, this.config.flushQueueSize);\n await Promise.all(batches.map((batch) => this.send(batch)));\n }\n\n async send(list: Context[]) {\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 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) {\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.delay = this.throttle;\n }\n return true;\n });\n\n this.addToQueue(...retry);\n }\n\n handleOtherReponse(list: Context[]) {\n this.addToQueue(...list);\n }\n\n fulfillRequest(list: Context[], code: number, message: string) {\n this.removeFromBackup(...list.map((context) => context.event));\n list.forEach((context) => context.callback(buildResult(context.event, code, message)));\n }\n\n addToBackup(...events: Event[]) {\n if (!this.config.saveEvents) return;\n events.forEach((event) => this.backup.add(event));\n this.snapshot();\n }\n\n removeFromBackup(...events: Event[]) {\n if (!this.config.saveEvents) return;\n events.forEach((event) => this.backup.delete(event));\n this.snapshot();\n }\n\n snapshot() {\n if (!this.config.saveEvents) return;\n const events = Array.from(this.backup);\n this.config.storageProvider.set(this.storageKey, events);\n }\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Storage } from '@amplitude/analytics-types';
|
|
2
|
+
export declare class MemoryStorage<T> implements Storage<T> {
|
|
3
|
+
memoryStorage: Map<string, T>;
|
|
4
|
+
isEnabled(): boolean;
|
|
5
|
+
get(key: string): T | undefined;
|
|
6
|
+
getRaw(key: string): string | undefined;
|
|
7
|
+
set(key: string, value: T): void;
|
|
8
|
+
remove(key: string): void;
|
|
9
|
+
reset(): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/storage/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,OAAO,CAAC,CAAC,CAAC;IACjD,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAa;IAE1C,SAAS,IAAI,OAAO;IAIpB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAI/B,MAAM,CAAC,GAAG,EAAE,MAAM;IAKlB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAIzB,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB,KAAK;CAGN"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.MemoryStorage = void 0;
|
|
3
|
+
var MemoryStorage = /** @class */ (function () {
|
|
4
|
+
function MemoryStorage() {
|
|
5
|
+
this.memoryStorage = new Map();
|
|
6
|
+
}
|
|
7
|
+
MemoryStorage.prototype.isEnabled = function () {
|
|
8
|
+
return true;
|
|
9
|
+
};
|
|
10
|
+
MemoryStorage.prototype.get = function (key) {
|
|
11
|
+
return this.memoryStorage.get(key);
|
|
12
|
+
};
|
|
13
|
+
MemoryStorage.prototype.getRaw = function (key) {
|
|
14
|
+
var value = this.get(key);
|
|
15
|
+
return value ? JSON.stringify(value) : undefined;
|
|
16
|
+
};
|
|
17
|
+
MemoryStorage.prototype.set = function (key, value) {
|
|
18
|
+
this.memoryStorage.set(key, value);
|
|
19
|
+
};
|
|
20
|
+
MemoryStorage.prototype.remove = function (key) {
|
|
21
|
+
this.memoryStorage.delete(key);
|
|
22
|
+
};
|
|
23
|
+
MemoryStorage.prototype.reset = function () {
|
|
24
|
+
this.memoryStorage.clear();
|
|
25
|
+
};
|
|
26
|
+
return MemoryStorage;
|
|
27
|
+
}());
|
|
28
|
+
exports.MemoryStorage = MemoryStorage;
|
|
29
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/storage/memory.ts"],"names":[],"mappings":";;AAEA;IAAA;QACE,kBAAa,GAAmB,IAAI,GAAG,EAAE,CAAC;IA0B5C,CAAC;IAxBC,iCAAS,GAAT;QACE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,2BAAG,GAAH,UAAI,GAAW;QACb,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IAED,8BAAM,GAAN,UAAO,GAAW;QAChB,IAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACnD,CAAC;IAED,2BAAG,GAAH,UAAI,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,8BAAM,GAAN,UAAO,GAAW;QAChB,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAED,6BAAK,GAAL;QACE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IACH,oBAAC;AAAD,CAAC,AA3BD,IA2BC;AA3BY,sCAAa","sourcesContent":["import { Storage } from '@amplitude/analytics-types';\n\nexport class MemoryStorage<T> implements Storage<T> {\n memoryStorage: Map<string, T> = new Map();\n\n isEnabled(): boolean {\n return true;\n }\n\n get(key: string): T | undefined {\n return this.memoryStorage.get(key);\n }\n\n getRaw(key: string) {\n const value = this.get(key);\n return value ? JSON.stringify(value) : undefined;\n }\n\n set(key: string, value: T) {\n this.memoryStorage.set(key, value);\n }\n\n remove(key: string) {\n this.memoryStorage.delete(key);\n }\n\n reset() {\n this.memoryStorage.clear();\n }\n}\n"]}
|
package/lib/cjs/timeline.d.ts
CHANGED
|
@@ -5,4 +5,5 @@ export declare const deregister: (pluginName: string, config: Config) => Promise
|
|
|
5
5
|
export declare const push: (event: Event, config: Config) => Promise<Result>;
|
|
6
6
|
export declare const scheduleApply: (timeout: number) => void;
|
|
7
7
|
export declare const apply: () => Promise<void>;
|
|
8
|
+
export declare const flush: (config: Config) => Promise<void>;
|
|
8
9
|
//# sourceMappingURL=timeline.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EAGN,KAAK,EACL,aAAa,EACb,MAAM,EAEN,MAAM,EACP,MAAM,4BAA4B,CAAC;AAIpC,eAAO,MAAM,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,EAAO,CAAC;AAG5D,eAAO,MAAM,QAAQ,WAAkB,MAAM,UAAU,MAAM,kBAG5D,CAAC;AAEF,eAAO,MAAM,UAAU,eAAgB,MAAM,UAAU,MAAM,kBAM5D,CAAC;AAEF,eAAO,MAAM,IAAI,UAAW,KAAK,UAAU,MAAM,oBAShD,CAAC;AAEF,eAAO,MAAM,aAAa,YAAa,MAAM,SAW5C,CAAC;AAEF,eAAO,MAAM,KAAK,qBAwCjB,CAAC;AAEF,eAAO,MAAM,KAAK,WAAkB,MAAM,kBAQzC,CAAC"}
|
package/lib/cjs/timeline.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var _this = this;
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.apply = exports.scheduleApply = exports.push = exports.deregister = exports.register = exports.queue = void 0;
|
|
3
|
+
exports.flush = exports.apply = exports.scheduleApply = exports.push = exports.deregister = exports.register = exports.queue = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var analytics_types_1 = require("@amplitude/analytics-types");
|
|
6
6
|
var messages_1 = require("./messages");
|
|
@@ -131,4 +131,19 @@ var apply = function () { return (0, tslib_1.__awaiter)(_this, void 0, void 0, f
|
|
|
131
131
|
});
|
|
132
132
|
}); };
|
|
133
133
|
exports.apply = apply;
|
|
134
|
+
var flush = function (config) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
|
|
135
|
+
var destination, flushDestinations;
|
|
136
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
137
|
+
switch (_a.label) {
|
|
138
|
+
case 0:
|
|
139
|
+
destination = config.plugins.filter(function (plugin) { return plugin.type === analytics_types_1.PluginType.DESTINATION; });
|
|
140
|
+
flushDestinations = destination.map(function (plugin) { return plugin.flush && plugin.flush(true); });
|
|
141
|
+
return [4 /*yield*/, Promise.all(flushDestinations)];
|
|
142
|
+
case 1:
|
|
143
|
+
_a.sent();
|
|
144
|
+
return [2 /*return*/];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}); };
|
|
148
|
+
exports.flush = flush;
|
|
134
149
|
//# sourceMappingURL=timeline.js.map
|
package/lib/cjs/timeline.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,iBA0GA;;;;AA1GA,8DAWoC;AACpC,uCAA6C;AAC7C,yDAAqD;AAExC,QAAA,KAAK,GAAuC,EAAE,CAAC;AAC5D,IAAI,QAAQ,GAAG,KAAK,CAAC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UAAU,6BAAQ,KAAK,CAAE,CAAC;oBAChC,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,UAAC,CAAC,IAAK,OAAA,IAAA,4BAAW,EAAC,UAAU,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAArC,CAAqC,CAAC,CAAC;gBACxF,CAAC,CAAC,CAAC;gBAEH,KAAK,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,UAAC,EAAQ;wBAAR,KAAA,0BAAQ,EAAP,MAAM,QAAA;oBACjD,OAAO,CAAC,MAAM,CAAC,CAAC;gBAClB,CAAC,CAAC,CAAC;gBAEH,sBAAO;;;KACR,CAAC;AAxCW,QAAA,KAAK,SAwChB;AAEK,IAAM,KAAK,GAAG,UAAO,MAAc;;;;;gBAClC,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CACvC,UAAC,MAAc,IAA2C,OAAA,MAAM,CAAC,IAAI,KAAK,4BAAU,CAAC,WAAW,EAAtC,CAAsC,CACjG,CAAC;gBAEI,iBAAiB,GAAG,WAAW,CAAC,GAAG,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAlC,CAAkC,CAAC,CAAC;gBAE1F,qBAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAA;;gBAApC,SAAoC,CAAC;;;;KACtC,CAAC;AARW,QAAA,KAAK,SAQhB","sourcesContent":["import {\n AmplitudeDestinationPlugin,\n BeforePlugin,\n Config,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n EventCallback,\n Plugin,\n PluginType,\n Result,\n} from '@amplitude/analytics-types';\nimport { OPT_OUT_MESSAGE } from './messages';\nimport { buildResult } from './utils/result-builder';\n\nexport const queue: [Event, EventCallback, Plugin[]][] = [];\nlet applying = false;\n\nexport const register = async (plugin: Plugin, config: Config) => {\n await plugin.setup(config);\n config.plugins.push(plugin);\n};\n\nexport const deregister = (pluginName: string, config: Config) => {\n config.plugins.splice(\n config.plugins.findIndex((plugin) => plugin.name === pluginName),\n 1,\n );\n return Promise.resolve();\n};\n\nexport const push = (event: Event, config: Config) => {\n return new Promise<Result>((resolve) => {\n if (config.optOut) {\n resolve(buildResult(event, 0, OPT_OUT_MESSAGE));\n return;\n }\n queue.push([event, resolve, config.plugins]);\n scheduleApply(0);\n });\n};\n\nexport const scheduleApply = (timeout: number) => {\n if (applying) return;\n applying = true;\n setTimeout(() => {\n void apply().then(() => {\n applying = false;\n if (queue.length > 0) {\n scheduleApply(0);\n }\n });\n }, timeout);\n};\n\nexport const apply = async () => {\n const item = queue.shift();\n\n if (!item) {\n return;\n }\n\n let [event] = item;\n const [, resolve, plugins] = item;\n\n const before = 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 = 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 = 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\nexport const flush = async (config: Config) => {\n const destination = config.plugins.filter<AmplitudeDestinationPlugin>(\n (plugin: Plugin): plugin is AmplitudeDestinationPlugin => plugin.type === PluginType.DESTINATION,\n );\n\n const flushDestinations = destination.map((plugin) => plugin.flush && plugin.flush(true));\n\n await Promise.all(flushDestinations);\n};\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseEvent, TrackEvent, IdentifyEvent, GroupIdentifyEvent, Identify as IIdentify, Revenue, RevenueEvent, EventOptions } from '@amplitude/analytics-types';
|
|
2
2
|
export declare const createTrackEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => TrackEvent;
|
|
3
|
-
export declare const createIdentifyEvent: (
|
|
4
|
-
export declare const createGroupIdentifyEvent: (
|
|
3
|
+
export declare const createIdentifyEvent: (identify: IIdentify, eventOptions?: EventOptions | undefined) => IdentifyEvent;
|
|
4
|
+
export declare const createGroupIdentifyEvent: (groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions | undefined) => GroupIdentifyEvent;
|
|
5
5
|
export declare const createGroupEvent: (groupType: string, groupName: string | string[]) => 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,
|
|
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,kBAY/E,CAAC;AAEF,eAAO,MAAM,kBAAkB,YAAa,OAAO,8CAAgC,YAMlF,CAAC"}
|
|
@@ -8,22 +8,16 @@ var createTrackEvent = function (eventInput, eventProperties, eventOptions) {
|
|
|
8
8
|
return (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, baseEvent), eventOptions), (eventProperties && { event_properties: eventProperties }));
|
|
9
9
|
};
|
|
10
10
|
exports.createTrackEvent = createTrackEvent;
|
|
11
|
-
var createIdentifyEvent = function (
|
|
12
|
-
var identifyEvent = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, eventOptions), { event_type: analytics_types_1.SpecialEventType.IDENTIFY, user_properties: identify.getUserProperties()
|
|
13
|
-
if (deviceId !== undefined && deviceId.length > 0) {
|
|
14
|
-
identifyEvent.device_id = deviceId;
|
|
15
|
-
}
|
|
11
|
+
var createIdentifyEvent = function (identify, eventOptions) {
|
|
12
|
+
var identifyEvent = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, eventOptions), { event_type: analytics_types_1.SpecialEventType.IDENTIFY, user_properties: identify.getUserProperties() });
|
|
16
13
|
return identifyEvent;
|
|
17
14
|
};
|
|
18
15
|
exports.createIdentifyEvent = createIdentifyEvent;
|
|
19
|
-
var createGroupIdentifyEvent = function (
|
|
16
|
+
var createGroupIdentifyEvent = function (groupType, groupName, identify, eventOptions) {
|
|
20
17
|
var _a;
|
|
21
18
|
var groupIdentify = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, eventOptions), { event_type: analytics_types_1.SpecialEventType.GROUP_IDENTIFY, group_properties: identify.getUserProperties(), groups: (_a = {},
|
|
22
19
|
_a[groupType] = groupName,
|
|
23
|
-
_a)
|
|
24
|
-
if (deviceId !== undefined && deviceId.length > 0) {
|
|
25
|
-
groupIdentify.device_id = deviceId;
|
|
26
|
-
}
|
|
20
|
+
_a) });
|
|
27
21
|
return groupIdentify;
|
|
28
22
|
};
|
|
29
23
|
exports.createGroupIdentifyEvent = createGroupIdentifyEvent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-builder.js","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":";;;AAAA,8DAUoC;AACpC,wCAAuC;AAEhC,IAAM,gBAAgB,GAAG,UAC9B,UAA8B,EAC9B,eAAqC,EACrC,YAA2B;IAE3B,IAAM,SAAS,GAAc,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;IACtG,6EACK,SAAS,GACT,YAAY,GACZ,CAAC,eAAe,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC,EAC7D;AACJ,CAAC,CAAC;AAXW,QAAA,gBAAgB,oBAW3B;AAEK,IAAM,mBAAmB,GAAG,
|
|
1
|
+
{"version":3,"file":"event-builder.js","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":";;;AAAA,8DAUoC;AACpC,wCAAuC;AAEhC,IAAM,gBAAgB,GAAG,UAC9B,UAA8B,EAC9B,eAAqC,EACrC,YAA2B;IAE3B,IAAM,SAAS,GAAc,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;IACtG,6EACK,SAAS,GACT,YAAY,GACZ,CAAC,eAAe,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC,EAC7D;AACJ,CAAC,CAAC;AAXW,QAAA,gBAAgB,oBAW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rackEvent,\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[]) => {\n const identify = new Identify();\n identify.set(groupType, groupName);\n\n const groupEvent: IdentifyEvent = {\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"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source: [jed's gist]{@link https://gist.github.com/982883}.
|
|
3
|
+
* Returns a random v4 UUID of the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx,
|
|
4
|
+
* where each x is replaced with a random hexadecimal digit from 0 to f, and
|
|
5
|
+
* y is replaced with a random hexadecimal digit from 8 to b.
|
|
6
|
+
* Used to generate UUIDs for deviceIds.
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
export declare const UUID: (a?: any) => string;
|
|
10
|
+
//# sourceMappingURL=uuid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../../src/utils/uuid.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,OAAiB,GAAG,KAAG,MAuBvC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.UUID = void 0;
|
|
3
|
+
/**
|
|
4
|
+
* Source: [jed's gist]{@link https://gist.github.com/982883}.
|
|
5
|
+
* Returns a random v4 UUID of the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx,
|
|
6
|
+
* where each x is replaced with a random hexadecimal digit from 0 to f, and
|
|
7
|
+
* y is replaced with a random hexadecimal digit from 8 to b.
|
|
8
|
+
* Used to generate UUIDs for deviceIds.
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
var UUID = function (a) {
|
|
12
|
+
return a // if the placeholder was passed, return
|
|
13
|
+
? // a random number from 0 to 15
|
|
14
|
+
(a ^ // unless b is 8,
|
|
15
|
+
((Math.random() * // in which case
|
|
16
|
+
16) >> // a random number from
|
|
17
|
+
(a / 4))) // 8 to 11
|
|
18
|
+
.toString(16) // in hexadecimal
|
|
19
|
+
: // or otherwise a concatenated string:
|
|
20
|
+
(String(1e7) + // 10000000 +
|
|
21
|
+
String(-1e3) + // -1000 +
|
|
22
|
+
String(-4e3) + // -4000 +
|
|
23
|
+
String(-8e3) + // -80000000 +
|
|
24
|
+
String(-1e11)) // -100000000000,
|
|
25
|
+
.replace(
|
|
26
|
+
// replacing
|
|
27
|
+
/[018]/g, // zeroes, ones, and eights with
|
|
28
|
+
exports.UUID);
|
|
29
|
+
};
|
|
30
|
+
exports.UUID = UUID;
|
|
31
|
+
//# sourceMappingURL=uuid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../../src/utils/uuid.ts"],"names":[],"mappings":";;AAAA;;;;;;;GAOG;AACI,IAAM,IAAI,GAAG,UAAU,CAAO;IACnC,OAAO,CAAC,CAAC,wCAAwC;QAC/C,CAAC,CAAC,+BAA+B;YAC/B,CACE,CAAC,GAAG,iBAAiB;gBACrB,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,gBAAgB;oBAChC,EAAE,CAAC,IAAI,uBAAuB;oBAC9B,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CACX,CAAC,UAAU;iBACT,QAAQ,CAAC,EAAE,CAAC,CAAC,iBAAiB;QACnC,CAAC,CAAC,sCAAsC;YACtC,CACE,MAAM,CAAC,GAAG,CAAC,GAAG,aAAa;gBAC3B,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,UAAU;gBACzB,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,UAAU;gBACzB,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,cAAc;gBAC7B,MAAM,CAAC,CAAC,IAAI,CAAC,CACd,CAAC,iBAAiB;iBAChB,OAAO;YACN,YAAY;YACZ,QAAQ,EAAE,gCAAgC;YAC1C,YAAI,CACL,CAAC;AACV,CAAC,CAAC;AAvBW,QAAA,IAAI,QAuBf","sourcesContent":["/**\n * Source: [jed's gist]{@link https://gist.github.com/982883}.\n * Returns a random v4 UUID of the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx,\n * where each x is replaced with a random hexadecimal digit from 0 to f, and\n * y is replaced with a random hexadecimal digit from 8 to b.\n * Used to generate UUIDs for deviceIds.\n * @private\n */\nexport const UUID = function (a?: any): string {\n return a // if the placeholder was passed, return\n ? // a random number from 0 to 15\n (\n a ^ // unless b is 8,\n ((Math.random() * // in which case\n 16) >> // a random number from\n (a / 4))\n ) // 8 to 11\n .toString(16) // in hexadecimal\n : // or otherwise a concatenated string:\n (\n String(1e7) + // 10000000 +\n String(-1e3) + // -1000 +\n String(-4e3) + // -4000 +\n String(-8e3) + // -80000000 +\n String(-1e11)\n ) // -100000000000,\n .replace(\n // replacing\n /[018]/g, // zeroes, ones, and eights with\n UUID, // random hex digits\n );\n};\n"]}
|
package/lib/esm/config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Event, Config as IConfig, Logger as ILogger, InitOptions, LogLevel, Storage, Transport, Plugin, ServerZone } from '@amplitude/analytics-types';
|
|
1
|
+
import { Event, Config as IConfig, Logger as ILogger, InitOptions, LogLevel, Storage, Transport, Plan, Plugin, ServerZone } from '@amplitude/analytics-types';
|
|
2
2
|
import { Logger } from './logger';
|
|
3
3
|
export declare const getDefaultConfig: () => {
|
|
4
4
|
flushMaxRetries: number;
|
|
@@ -15,25 +15,23 @@ export declare const getDefaultConfig: () => {
|
|
|
15
15
|
};
|
|
16
16
|
export declare class Config implements IConfig {
|
|
17
17
|
apiKey: string;
|
|
18
|
-
appVersion?: string;
|
|
19
|
-
userId?: string;
|
|
20
|
-
deviceId?: string;
|
|
21
|
-
sessionId?: number;
|
|
22
18
|
flushIntervalMillis: number;
|
|
23
19
|
flushMaxRetries: number;
|
|
24
20
|
flushQueueSize: number;
|
|
25
21
|
loggerProvider: ILogger;
|
|
26
22
|
logLevel: LogLevel;
|
|
27
23
|
minIdLength?: number;
|
|
28
|
-
|
|
24
|
+
plan?: Plan;
|
|
29
25
|
plugins: Plugin[];
|
|
30
|
-
optOut: boolean;
|
|
31
26
|
saveEvents: boolean;
|
|
32
27
|
serverUrl: string | undefined;
|
|
33
28
|
serverZone?: ServerZone;
|
|
34
29
|
transportProvider: Transport;
|
|
35
30
|
storageProvider: Storage<Event[]>;
|
|
36
31
|
useBatch: boolean;
|
|
32
|
+
private _optOut;
|
|
33
|
+
get optOut(): boolean;
|
|
34
|
+
set optOut(optOut: boolean);
|
|
37
35
|
constructor(options: InitOptions<IConfig>);
|
|
38
36
|
}
|
|
39
37
|
export declare const getServerUrl: (serverZone: ServerZone, useBatch: boolean) => "https://api2.amplitude.com/2/httpapi" | "https://api.eu.amplitude.com/2/httpapi" | "https://api2.amplitude.com/batch" | "https://api.eu.amplitude.com/batch";
|
package/lib/esm/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,IAAI,OAAO,EACjB,MAAM,IAAI,OAAO,EACjB,WAAW,EACX,QAAQ,EACR,OAAO,EACP,SAAS,EACT,MAAM,EACN,UAAU,EACX,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,eAAO,MAAM,gBAAgB;;;;;;;;;;;;CAY3B,CAAC;AAEH,qBAAa,MAAO,YAAW,OAAO;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,IAAI,OAAO,EACjB,MAAM,IAAI,OAAO,EACjB,WAAW,EACX,QAAQ,EACR,OAAO,EACP,SAAS,EACT,IAAI,EACJ,MAAM,EACN,UAAU,EACX,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,eAAO,MAAM,gBAAgB;;;;;;;;;;;;CAY3B,CAAC;AAEH,qBAAa,MAAO,YAAW,OAAO;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,eAAe,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IAClC,QAAQ,EAAE,OAAO,CAAC;IAElB,OAAO,CAAC,OAAO,CAAS;IACxB,IAAI,MAAM,IAGS,OAAO,CADzB;IACD,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,EAEzB;gBAEW,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC;CAwB1C;AAED,eAAO,MAAM,YAAY,eAAgB,UAAU,YAAY,OAAO,kKAKrE,CAAC;AAEF,eAAO,MAAM,kBAAkB,oCAEjB,UAAU,aACZ,OAAO;;;;;;CAUlB,CAAC"}
|
package/lib/esm/config.js
CHANGED
|
@@ -17,19 +17,16 @@ export var getDefaultConfig = function () { return ({
|
|
|
17
17
|
var Config = /** @class */ (function () {
|
|
18
18
|
function Config(options) {
|
|
19
19
|
var _a, _b, _c, _d;
|
|
20
|
+
this._optOut = false;
|
|
20
21
|
var defaultConfig = getDefaultConfig();
|
|
21
22
|
this.apiKey = options.apiKey;
|
|
22
|
-
this.appVersion = options.appVersion;
|
|
23
|
-
this.userId = options.userId;
|
|
24
|
-
this.deviceId = options.deviceId;
|
|
25
|
-
this.sessionId = options.sessionId;
|
|
26
23
|
this.flushIntervalMillis = options.flushIntervalMillis || defaultConfig.flushIntervalMillis;
|
|
27
24
|
this.flushMaxRetries = options.flushMaxRetries || defaultConfig.flushMaxRetries;
|
|
28
25
|
this.flushQueueSize = options.flushQueueSize || defaultConfig.flushQueueSize;
|
|
29
26
|
this.loggerProvider = options.loggerProvider || defaultConfig.loggerProvider;
|
|
30
27
|
this.logLevel = (_a = options.logLevel) !== null && _a !== void 0 ? _a : defaultConfig.logLevel;
|
|
31
28
|
this.minIdLength = options.minIdLength;
|
|
32
|
-
this.
|
|
29
|
+
this.plan = options.plan;
|
|
33
30
|
this.plugins = defaultConfig.plugins;
|
|
34
31
|
this.optOut = (_b = options.optOut) !== null && _b !== void 0 ? _b : defaultConfig.optOut;
|
|
35
32
|
this.saveEvents = (_c = options.saveEvents) !== null && _c !== void 0 ? _c : defaultConfig.saveEvents;
|
|
@@ -43,6 +40,16 @@ var Config = /** @class */ (function () {
|
|
|
43
40
|
this.serverZone = serverConfig.serverZone;
|
|
44
41
|
this.serverUrl = serverConfig.serverUrl;
|
|
45
42
|
}
|
|
43
|
+
Object.defineProperty(Config.prototype, "optOut", {
|
|
44
|
+
get: function () {
|
|
45
|
+
return this._optOut;
|
|
46
|
+
},
|
|
47
|
+
set: function (optOut) {
|
|
48
|
+
this._optOut = optOut;
|
|
49
|
+
},
|
|
50
|
+
enumerable: false,
|
|
51
|
+
configurable: true
|
|
52
|
+
});
|
|
46
53
|
return Config;
|
|
47
54
|
}());
|
|
48
55
|
export { Config };
|
package/lib/esm/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,QAAQ,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,QAAQ,EAKR,UAAU,GACX,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,CAAC,IAA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SAAc,EACd,UAAsD,EACtD,QAA+C;IAF/C,0BAAA,EAAA,cAAc;IACd,2BAAA,EAAA,aAAyB,gBAAgB,EAAE,CAAC,UAAU;IACtD,yBAAA,EAAA,WAAoB,gBAAgB,EAAE,CAAC,QAAQ;IAE/C,IAAI,SAAS,EAAE;QACb,OAAO,EAAE,SAAS,WAAA,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;KAC7C;IACD,IAAM,WAAW,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC,UAAU,CAAC;IACrH,OAAO;QACL,UAAU,EAAE,WAAW;QACvB,SAAS,EAAE,YAAY,CAAC,WAAW,EAAE,QAAQ,CAAC;KAC/C,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n Event,\n Config as IConfig,\n Logger as ILogger,\n InitOptions,\n LogLevel,\n Storage,\n Transport,\n Plan,\n Plugin,\n ServerZone,\n} from '@amplitude/analytics-types';\nimport {\n AMPLITUDE_SERVER_URL,\n AMPLITUDE_BATCH_SERVER_URL,\n EU_AMPLITUDE_SERVER_URL,\n EU_AMPLITUDE_BATCH_SERVER_URL,\n} from './constants';\n\nimport { Logger } from './logger';\n\nexport const getDefaultConfig = () => ({\n flushMaxRetries: 5,\n flushQueueSize: 10,\n flushIntervalMillis: 1000,\n logLevel: LogLevel.Warn,\n loggerProvider: new Logger(),\n saveEvents: true,\n optOut: false,\n plugins: [],\n serverUrl: AMPLITUDE_SERVER_URL,\n serverZone: ServerZone.US,\n useBatch: false,\n});\n\nexport class Config implements IConfig {\n apiKey: string;\n flushIntervalMillis: number;\n flushMaxRetries: number;\n flushQueueSize: number;\n loggerProvider: ILogger;\n logLevel: LogLevel;\n minIdLength?: number;\n plan?: Plan;\n plugins: Plugin[];\n saveEvents: boolean;\n serverUrl: string | undefined;\n serverZone?: ServerZone;\n transportProvider: Transport;\n storageProvider: Storage<Event[]>;\n useBatch: boolean;\n\n private _optOut = false;\n get optOut() {\n return this._optOut;\n }\n set optOut(optOut: boolean) {\n this._optOut = optOut;\n }\n\n constructor(options: InitOptions<IConfig>) {\n const defaultConfig = getDefaultConfig();\n this.apiKey = options.apiKey;\n this.flushIntervalMillis = options.flushIntervalMillis || defaultConfig.flushIntervalMillis;\n this.flushMaxRetries = options.flushMaxRetries || defaultConfig.flushMaxRetries;\n this.flushQueueSize = options.flushQueueSize || defaultConfig.flushQueueSize;\n this.loggerProvider = options.loggerProvider || defaultConfig.loggerProvider;\n this.logLevel = options.logLevel ?? defaultConfig.logLevel;\n this.minIdLength = options.minIdLength;\n this.plan = options.plan;\n this.plugins = defaultConfig.plugins;\n this.optOut = options.optOut ?? defaultConfig.optOut;\n this.saveEvents = options.saveEvents ?? defaultConfig.saveEvents;\n this.serverUrl = options.serverUrl;\n this.serverZone = options.serverZone || defaultConfig.serverZone;\n this.storageProvider = options.storageProvider;\n this.transportProvider = options.transportProvider;\n this.useBatch = options.useBatch ?? defaultConfig.useBatch;\n this.loggerProvider.enable(this.logLevel);\n\n const serverConfig = createServerConfig(options.serverUrl, options.serverZone, options.useBatch);\n this.serverZone = serverConfig.serverZone;\n this.serverUrl = serverConfig.serverUrl;\n }\n}\n\nexport const getServerUrl = (serverZone: ServerZone, useBatch: boolean) => {\n if (serverZone === ServerZone.EU) {\n return useBatch ? EU_AMPLITUDE_BATCH_SERVER_URL : EU_AMPLITUDE_SERVER_URL;\n }\n return useBatch ? AMPLITUDE_BATCH_SERVER_URL : AMPLITUDE_SERVER_URL;\n};\n\nexport const createServerConfig = (\n serverUrl = '',\n serverZone: ServerZone = getDefaultConfig().serverZone,\n useBatch: boolean = getDefaultConfig().useBatch,\n) => {\n if (serverUrl) {\n return { serverUrl, serverZone: undefined };\n }\n const _serverZone = [ServerZone.US, ServerZone.EU].includes(serverZone) ? serverZone : getDefaultConfig().serverZone;\n return {\n serverZone: _serverZone,\n serverUrl: getServerUrl(_serverZone, useBatch),\n };\n};\n"]}
|
package/lib/esm/core-client.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types';
|
|
2
|
-
export declare class AmplitudeCore<T extends Config> {
|
|
1
|
+
import { CoreClient, Config, Event, BaseEvent, EventOptions, Identify, Plugin, Revenue } from '@amplitude/analytics-types';
|
|
2
|
+
export declare class AmplitudeCore<T extends Config> implements CoreClient<T> {
|
|
3
3
|
name: string;
|
|
4
4
|
config: T;
|
|
5
5
|
constructor(name?: string);
|
|
6
6
|
init(_apiKey: string | undefined, _userId: string | undefined, config: T): Promise<void>;
|
|
7
7
|
track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
8
8
|
logEvent: (eventInput: BaseEvent | string, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => Promise<import("@amplitude/analytics-types").Result>;
|
|
9
|
-
identify(identify: Identify, eventOptions?: EventOptions
|
|
10
|
-
groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions
|
|
9
|
+
identify(identify: Identify, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
10
|
+
groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
11
11
|
setGroup(groupType: string, groupName: string | string[]): Promise<import("@amplitude/analytics-types").Result>;
|
|
12
12
|
revenue(revenue: Revenue, eventOptions?: EventOptions): Promise<import("@amplitude/analytics-types").Result>;
|
|
13
13
|
add(plugin: Plugin): Promise<void>;
|
|
14
14
|
remove(pluginName: string): Promise<void>;
|
|
15
15
|
dispatch(event: Event): Promise<import("@amplitude/analytics-types").Result>;
|
|
16
16
|
setOptOut(optOut: boolean): void;
|
|
17
|
+
flush(): Promise<void>;
|
|
17
18
|
}
|
|
18
19
|
//# sourceMappingURL=core-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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;AAUpC,qBAAa,aAAa,CAAC,CAAC,SAAS,MAAM,CAAE,YAAW,UAAU,CAAC,CAAC,CAAC;IACnE,IAAI,EAAE,MAAM,CAAC;IAGb,MAAM,EAAE,CAAC,CAAC;gBAEE,IAAI,SAAa;IAK7B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,CAAC;IAKxE,KAAK,CAAC,UAAU,EAAE,SAAS,GAAG,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,YAAY,CAAC,EAAE,YAAY;IAKxG,QAAQ,eALU,SAAS,GAAG,MAAM,sJAKH;IAEjC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,YAAY;IAKxD,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,YAAY;IAK9G,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;IAKxD,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,YAAY;IAK/C,GAAG,CAAC,MAAM,EAAE,MAAM;IAKlB,MAAM,CAAC,UAAU,EAAE,MAAM;IAKzB,QAAQ,CAAC,KAAK,EAAE,KAAK;IAgB3B,SAAS,CAAC,MAAM,EAAE,OAAO;IAKzB,KAAK;CAIN"}
|
package/lib/esm/core-client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter, __generator } from "tslib";
|
|
2
2
|
import { createGroupIdentifyEvent, createIdentifyEvent, createTrackEvent, createRevenueEvent, createGroupEvent, } from './utils/event-builder';
|
|
3
|
-
import { deregister, push, register } from './timeline';
|
|
3
|
+
import { deregister, flush, push, register } from './timeline';
|
|
4
4
|
import { buildResult } from './utils/result-builder';
|
|
5
5
|
var AmplitudeCore = /** @class */ (function () {
|
|
6
6
|
function AmplitudeCore(name) {
|
|
@@ -17,12 +17,12 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
17
17
|
var event = createTrackEvent(eventInput, eventProperties, eventOptions);
|
|
18
18
|
return this.dispatch(event);
|
|
19
19
|
};
|
|
20
|
-
AmplitudeCore.prototype.identify = function (identify, eventOptions
|
|
21
|
-
var event = createIdentifyEvent(
|
|
20
|
+
AmplitudeCore.prototype.identify = function (identify, eventOptions) {
|
|
21
|
+
var event = createIdentifyEvent(identify, eventOptions);
|
|
22
22
|
return this.dispatch(event);
|
|
23
23
|
};
|
|
24
|
-
AmplitudeCore.prototype.groupIdentify = function (groupType, groupName, identify, eventOptions
|
|
25
|
-
var event = createGroupIdentifyEvent(
|
|
24
|
+
AmplitudeCore.prototype.groupIdentify = function (groupType, groupName, identify, eventOptions) {
|
|
25
|
+
var event = createGroupIdentifyEvent(groupType, groupName, identify, eventOptions);
|
|
26
26
|
return this.dispatch(event);
|
|
27
27
|
};
|
|
28
28
|
AmplitudeCore.prototype.setGroup = function (groupType, groupName) {
|
|
@@ -82,6 +82,10 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
82
82
|
var config = this.config;
|
|
83
83
|
config.optOut = Boolean(optOut);
|
|
84
84
|
};
|
|
85
|
+
AmplitudeCore.prototype.flush = function () {
|
|
86
|
+
var config = this.config;
|
|
87
|
+
return flush(config);
|
|
88
|
+
};
|
|
85
89
|
return AmplitudeCore;
|
|
86
90
|
}());
|
|
87
91
|
export { AmplitudeCore };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";
|
|
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,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD;IAME,uBAAY,IAAiB;QAAjB,qBAAA,EAAA,iBAAiB;QAe7B,aAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAd/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,gDAAgD;IAChD,4BAAI,GAAJ,UAAK,OAA2B,EAAE,OAA2B,EAAE,MAAS;QACtE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,6BAAK,GAAL,UAAM,UAA8B,EAAE,eAAqC,EAAE,YAA2B;QACtG,IAAM,KAAK,GAAG,gBAAgB,CAAC,UAAU,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAID,gCAAQ,GAAR,UAAS,QAAkB,EAAE,YAA2B;QACtD,IAAM,KAAK,GAAG,mBAAmB,CAAC,QAAQ,EAAE,YAA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AAO,CAAC,CAAC;yBAChD;6BAAM;4BACL,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;yBAClD;wBACD,sBAAO,MAAM,EAAC;;;wBAER,OAAO,GAAG,MAAM,CAAC,GAAC,CAAC,CAAC;wBAC1B,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;wBAC1C,sBAAO,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,EAAC;;;;;KAEzC;IAED,iCAAS,GAAT,UAAU,MAAe;QACvB,IAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAED,6BAAK,GAAL;QACE,IAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IACH,oBAAC;AAAD,CAAC,AA9ED,IA8EC","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 { deregister, flush, push, register } from './timeline';\nimport { buildResult } from './utils/result-builder';\nexport class AmplitudeCore<T extends Config> implements CoreClient<T> {\n name: string;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: T;\n\n constructor(name = '$default') {\n this.name = name;\n }\n\n // NOTE: Do not use `_apiKey` and `_userId` here\n init(_apiKey: string | undefined, _userId: string | undefined, config: T) {\n this.config = config;\n return Promise.resolve();\n }\n\n track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions) {\n const event = createTrackEvent(eventInput, eventProperties, eventOptions);\n return this.dispatch(event);\n }\n\n logEvent = this.track.bind(this);\n\n identify(identify: Identify, eventOptions?: EventOptions) {\n const event = createIdentifyEvent(identify, eventOptions);\n return this.dispatch(event);\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: Identify, eventOptions?: EventOptions) {\n const event = createGroupIdentifyEvent(groupType, groupName, identify, eventOptions);\n return this.dispatch(event);\n }\n\n setGroup(groupType: string, groupName: string | string[]) {\n const event = createGroupEvent(groupType, groupName);\n return this.dispatch(event);\n }\n\n revenue(revenue: Revenue, eventOptions?: EventOptions) {\n const event = createRevenueEvent(revenue, eventOptions);\n return this.dispatch(event);\n }\n\n async add(plugin: Plugin) {\n const config = this.config;\n return register(plugin, config);\n }\n\n async remove(pluginName: string) {\n const config = this.config;\n return deregister(pluginName, config);\n }\n\n async dispatch(event: Event) {\n try {\n const result = await push(event, this.config);\n if (result.code === 200) {\n this.config.loggerProvider.log(result.message);\n } else {\n this.config.loggerProvider.error(result.message);\n }\n return result;\n } catch (e) {\n const message = String(e);\n this.config.loggerProvider.error(message);\n return buildResult(event, 0, message);\n }\n }\n\n setOptOut(optOut: boolean) {\n const config = this.config;\n config.optOut = Boolean(optOut);\n }\n\n flush() {\n const config = this.config;\n return flush(config);\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Event, EventBridgeReceiver } from '@amplitude/analytics-types';
|
|
2
|
+
export declare class EventBridgeChannel {
|
|
3
|
+
channel: string;
|
|
4
|
+
queue: Event[];
|
|
5
|
+
receiver: EventBridgeReceiver | undefined;
|
|
6
|
+
constructor(channel: string);
|
|
7
|
+
sendEvent(event: Event): void;
|
|
8
|
+
setReceiver(receiver: EventBridgeReceiver): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=event-bridge-channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bridge-channel.d.ts","sourceRoot":"","sources":["../../../src/event-bridge/event-bridge-channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAIxE,qBAAa,kBAAkB;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,EAAE,CAAM;IACpB,QAAQ,EAAE,mBAAmB,GAAG,SAAS,CAAC;gBAE9B,OAAO,EAAE,MAAM;IAI3B,SAAS,CAAC,KAAK,EAAE,KAAK;IAQtB,WAAW,CAAC,QAAQ,EAAE,mBAAmB;CAW1C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { __read, __spreadArray } from "tslib";
|
|
2
|
+
var QUEUE_CAPACITY = 512;
|
|
3
|
+
var EventBridgeChannel = /** @class */ (function () {
|
|
4
|
+
function EventBridgeChannel(channel) {
|
|
5
|
+
this.queue = [];
|
|
6
|
+
this.channel = channel;
|
|
7
|
+
}
|
|
8
|
+
EventBridgeChannel.prototype.sendEvent = function (event) {
|
|
9
|
+
if (!this.receiver) {
|
|
10
|
+
this.queue = __spreadArray(__spreadArray([], __read(this.queue.slice(0, QUEUE_CAPACITY)), false), [event], false);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
this.receiver.receive(this.channel, event);
|
|
14
|
+
};
|
|
15
|
+
EventBridgeChannel.prototype.setReceiver = function (receiver) {
|
|
16
|
+
var _this = this;
|
|
17
|
+
if (this.receiver) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
this.receiver = receiver;
|
|
21
|
+
var events = this.queue;
|
|
22
|
+
this.queue = [];
|
|
23
|
+
events.forEach(function (event) {
|
|
24
|
+
_this.receiver.receive(_this.channel, event);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
return EventBridgeChannel;
|
|
28
|
+
}());
|
|
29
|
+
export { EventBridgeChannel };
|
|
30
|
+
//# sourceMappingURL=event-bridge-channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bridge-channel.js","sourceRoot":"","sources":["../../../src/event-bridge/event-bridge-channel.ts"],"names":[],"mappings":";AAEA,IAAM,cAAc,GAAG,GAAG,CAAC;AAE3B;IAKE,4BAAY,OAAe;QAH3B,UAAK,GAAY,EAAE,CAAC;QAIlB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,sCAAS,GAAT,UAAU,KAAY;QACpB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,KAAK,0CAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,YAAE,KAAK,SAAC,CAAC;YAC7D,OAAO;SACR;QACD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC7C,CAAC;IAED,wCAAW,GAAX,UAAY,QAA6B;QAAzC,iBAUC;QATC,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,OAAO;SACR;QACD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK;YAClB,KAAI,CAAC,QAAgC,CAAC,OAAO,CAAC,KAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;IACL,CAAC;IACH,yBAAC;AAAD,CAAC,AA5BD,IA4BC","sourcesContent":["import { Event, EventBridgeReceiver } from '@amplitude/analytics-types';\n\nconst QUEUE_CAPACITY = 512;\n\nexport class EventBridgeChannel {\n channel: string;\n queue: Event[] = [];\n receiver: EventBridgeReceiver | undefined;\n\n constructor(channel: string) {\n this.channel = channel;\n }\n\n sendEvent(event: Event) {\n if (!this.receiver) {\n this.queue = [...this.queue.slice(0, QUEUE_CAPACITY), event];\n return;\n }\n this.receiver.receive(this.channel, event);\n }\n\n setReceiver(receiver: EventBridgeReceiver) {\n if (this.receiver) {\n return;\n }\n this.receiver = receiver;\n const events = this.queue;\n this.queue = [];\n events.forEach((event) => {\n (this.receiver as EventBridgeReceiver).receive(this.channel, event);\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { EventBridge as IEventBridge } from '@amplitude/analytics-types';
|
|
2
|
+
export declare class EventBridgeContainer {
|
|
3
|
+
static instances: Record<string, IEventBridge>;
|
|
4
|
+
static getInstance(instanceName: string): IEventBridge;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=event-bridge-container.d.ts.map
|