@amplitude/analytics-core 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/lib/cjs/config.d.ts +2 -6
  2. package/lib/cjs/config.d.ts.map +1 -1
  3. package/lib/cjs/config.js +1 -5
  4. package/lib/cjs/config.js.map +1 -1
  5. package/lib/cjs/core-client.d.ts +3 -2
  6. package/lib/cjs/core-client.d.ts.map +1 -1
  7. package/lib/cjs/core-client.js +4 -0
  8. package/lib/cjs/core-client.js.map +1 -1
  9. package/lib/cjs/event-bridge/event-bridge-channel.d.ts +10 -0
  10. package/lib/cjs/event-bridge/event-bridge-channel.d.ts.map +1 -0
  11. package/lib/cjs/event-bridge/event-bridge-channel.js +32 -0
  12. package/lib/cjs/event-bridge/event-bridge-channel.js.map +1 -0
  13. package/lib/cjs/event-bridge/event-bridge-container.d.ts +6 -0
  14. package/lib/cjs/event-bridge/event-bridge-container.d.ts.map +1 -0
  15. package/lib/cjs/event-bridge/event-bridge-container.js +17 -0
  16. package/lib/cjs/event-bridge/event-bridge-container.js.map +1 -0
  17. package/lib/cjs/event-bridge/event-bridge.d.ts +8 -0
  18. package/lib/cjs/event-bridge/event-bridge.d.ts.map +1 -0
  19. package/lib/cjs/event-bridge/event-bridge.js +23 -0
  20. package/lib/cjs/event-bridge/event-bridge.js.map +1 -0
  21. package/lib/cjs/event-bridge/event-channel.d.ts +5 -0
  22. package/lib/cjs/event-bridge/event-channel.d.ts.map +1 -0
  23. package/lib/cjs/event-bridge/event-channel.js +8 -0
  24. package/lib/cjs/event-bridge/event-channel.js.map +1 -0
  25. package/lib/cjs/event-bridge/event-receiver.d.ts +8 -0
  26. package/lib/cjs/event-bridge/event-receiver.d.ts.map +1 -0
  27. package/lib/cjs/event-bridge/event-receiver.js +27 -0
  28. package/lib/cjs/event-bridge/event-receiver.js.map +1 -0
  29. package/lib/cjs/index.d.ts +2 -0
  30. package/lib/cjs/index.d.ts.map +1 -1
  31. package/lib/cjs/index.js +5 -1
  32. package/lib/cjs/index.js.map +1 -1
  33. package/lib/cjs/plugins/destination.d.ts +2 -1
  34. package/lib/cjs/plugins/destination.d.ts.map +1 -1
  35. package/lib/cjs/plugins/destination.js +13 -3
  36. package/lib/cjs/plugins/destination.js.map +1 -1
  37. package/lib/cjs/storage/memory.d.ts +11 -0
  38. package/lib/cjs/storage/memory.d.ts.map +1 -0
  39. package/lib/cjs/storage/memory.js +29 -0
  40. package/lib/cjs/storage/memory.js.map +1 -0
  41. package/lib/cjs/timeline.d.ts +1 -0
  42. package/lib/cjs/timeline.d.ts.map +1 -1
  43. package/lib/cjs/timeline.js +16 -1
  44. package/lib/cjs/timeline.js.map +1 -1
  45. package/lib/cjs/utils/uuid.d.ts +10 -0
  46. package/lib/cjs/utils/uuid.d.ts.map +1 -0
  47. package/lib/cjs/utils/uuid.js +31 -0
  48. package/lib/cjs/utils/uuid.js.map +1 -0
  49. package/lib/esm/config.d.ts +2 -6
  50. package/lib/esm/config.d.ts.map +1 -1
  51. package/lib/esm/config.js +1 -5
  52. package/lib/esm/config.js.map +1 -1
  53. package/lib/esm/core-client.d.ts +3 -2
  54. package/lib/esm/core-client.d.ts.map +1 -1
  55. package/lib/esm/core-client.js +5 -1
  56. package/lib/esm/core-client.js.map +1 -1
  57. package/lib/esm/event-bridge/event-bridge-channel.d.ts +10 -0
  58. package/lib/esm/event-bridge/event-bridge-channel.d.ts.map +1 -0
  59. package/lib/esm/event-bridge/event-bridge-channel.js +30 -0
  60. package/lib/esm/event-bridge/event-bridge-channel.js.map +1 -0
  61. package/lib/esm/event-bridge/event-bridge-container.d.ts +6 -0
  62. package/lib/esm/event-bridge/event-bridge-container.d.ts.map +1 -0
  63. package/lib/esm/event-bridge/event-bridge-container.js +15 -0
  64. package/lib/esm/event-bridge/event-bridge-container.js.map +1 -0
  65. package/lib/esm/event-bridge/event-bridge.d.ts +8 -0
  66. package/lib/esm/event-bridge/event-bridge.d.ts.map +1 -0
  67. package/lib/esm/event-bridge/event-bridge.js +21 -0
  68. package/lib/esm/event-bridge/event-bridge.js.map +1 -0
  69. package/lib/esm/event-bridge/event-channel.d.ts +5 -0
  70. package/lib/esm/event-bridge/event-channel.d.ts.map +1 -0
  71. package/lib/esm/event-bridge/event-channel.js +6 -0
  72. package/lib/esm/event-bridge/event-channel.js.map +1 -0
  73. package/lib/esm/event-bridge/event-receiver.d.ts +8 -0
  74. package/lib/esm/event-bridge/event-receiver.d.ts.map +1 -0
  75. package/lib/esm/event-bridge/event-receiver.js +25 -0
  76. package/lib/esm/event-bridge/event-receiver.js.map +1 -0
  77. package/lib/esm/index.d.ts +2 -0
  78. package/lib/esm/index.d.ts.map +1 -1
  79. package/lib/esm/index.js +2 -0
  80. package/lib/esm/index.js.map +1 -1
  81. package/lib/esm/plugins/destination.d.ts +2 -1
  82. package/lib/esm/plugins/destination.d.ts.map +1 -1
  83. package/lib/esm/plugins/destination.js +13 -3
  84. package/lib/esm/plugins/destination.js.map +1 -1
  85. package/lib/esm/storage/memory.d.ts +11 -0
  86. package/lib/esm/storage/memory.d.ts.map +1 -0
  87. package/lib/esm/storage/memory.js +27 -0
  88. package/lib/esm/storage/memory.js.map +1 -0
  89. package/lib/esm/timeline.d.ts +1 -0
  90. package/lib/esm/timeline.d.ts.map +1 -1
  91. package/lib/esm/timeline.js +14 -0
  92. package/lib/esm/timeline.js.map +1 -1
  93. package/lib/esm/utils/uuid.d.ts +10 -0
  94. package/lib/esm/utils/uuid.d.ts.map +1 -0
  95. package/lib/esm/utils/uuid.js +28 -0
  96. package/lib/esm/utils/uuid.js.map +1 -0
  97. package/package.json +3 -3
  98. package/lib/cjs/transports/http.d.ts +0 -6
  99. package/lib/cjs/transports/http.d.ts.map +0 -1
  100. package/lib/cjs/transports/http.js +0 -55
  101. package/lib/cjs/transports/http.js.map +0 -1
  102. package/lib/esm/transports/http.d.ts +0 -6
  103. package/lib/esm/transports/http.d.ts.map +0 -1
  104. package/lib/esm/transports/http.js +0 -53
  105. 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,OAAO,EAOL,UAAU,EAIV,MAAM,GAEP,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACjG,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,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,cAAc,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,GAA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CAAC,CAAC,EAA3D,CAA2D,CAAC,CAAC;IACzF,CAAC;IAED,iCAAW,GAAX;QAAA,iBAIC;QAJW,gBAAkB;aAAlB,UAAkB,EAAlB,qBAAkB,EAAlB,IAAkB;YAAlB,2BAAkB;;QAC5B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU;YAAE,OAAO;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","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,OAAO,EAOL,UAAU,EAIV,MAAM,GAEP,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACjG,OAAO,EAAE,cAAc,EAAE,MAAM,c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\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,27 @@
1
+ var MemoryStorage = /** @class */ (function () {
2
+ function MemoryStorage() {
3
+ this.memoryStorage = new Map();
4
+ }
5
+ MemoryStorage.prototype.isEnabled = function () {
6
+ return true;
7
+ };
8
+ MemoryStorage.prototype.get = function (key) {
9
+ return this.memoryStorage.get(key);
10
+ };
11
+ MemoryStorage.prototype.getRaw = function (key) {
12
+ var value = this.get(key);
13
+ return value ? JSON.stringify(value) : undefined;
14
+ };
15
+ MemoryStorage.prototype.set = function (key, value) {
16
+ this.memoryStorage.set(key, value);
17
+ };
18
+ MemoryStorage.prototype.remove = function (key) {
19
+ this.memoryStorage.delete(key);
20
+ };
21
+ MemoryStorage.prototype.reset = function () {
22
+ this.memoryStorage.clear();
23
+ };
24
+ return MemoryStorage;
25
+ }());
26
+ export { MemoryStorage };
27
+ //# 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","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"]}
@@ -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,EAEL,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"}
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"}
@@ -123,4 +123,18 @@ export var apply = function () { return __awaiter(void 0, void 0, void 0, functi
123
123
  }
124
124
  });
125
125
  }); };
126
+ export var flush = function (config) { return __awaiter(void 0, void 0, void 0, function () {
127
+ var destination, flushDestinations;
128
+ return __generator(this, function (_a) {
129
+ switch (_a.label) {
130
+ case 0:
131
+ destination = config.plugins.filter(function (plugin) { return plugin.type === PluginType.DESTINATION; });
132
+ flushDestinations = destination.map(function (plugin) { return plugin.flush && plugin.flush(true); });
133
+ return [4 /*yield*/, Promise.all(flushDestinations)];
134
+ case 1:
135
+ _a.sent();
136
+ return [2 /*return*/];
137
+ }
138
+ });
139
+ }); };
126
140
  //# sourceMappingURL=timeline.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":";AAAA,OAAO,EAQL,UAAU,GAEX,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,MAAM,CAAC,IAAM,KAAK,GAAuC,EAAE,CAAC;AAC5D,IAAI,QAAQ,GAAG,KAAK,CAAC;AAErB,MAAM,CAAC,IAAM,QAAQ,GAAG,UAAO,MAAc,EAAE,MAAc;;;oBAC3D,qBAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAA;;gBAA1B,SAA0B,CAAC;gBAC3B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;;;;KAC7B,CAAC;AAEF,MAA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AC,EAAQ;wBAAR,KAAA,aAAQ,EAAP,MAAM,QAAA;oBACjD,OAAO,CAAC,MAAM,CAAC,CAAC;gBAClB,CAAC,CAAC,CAAC;gBAEH,sBAAO;;;KACR,CAAC","sourcesContent":["import {\n BeforePlugin,\n Config,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n EventCallback,\n Plugin,\n PluginType,\n Result,\n} from '@amplitude/analytics-types';\nimport { OPT_OUT_MESSAGE } from './messages';\nimport { buildResult } from './utils/result-builder';\n\nexport 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"]}
1
+ {"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":";AAAA,OAAO,EASL,UAAU,GAEX,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,MAAM,CAAC,IAAM,KAAK,GAAuC,EAAE,CAAC;AAC5D,IAAI,QAAQ,GAAG,KAAK,CAAC;AAErB,MAAM,CAAC,IAAM,QAAQ,GAAG,UAAO,MAAc,EAAE,MAAc;;;oBAC3D,qBAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAA;;gBAA1B,SAA0B,CAAC;gBAC3B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;;;;KAC7B,CAAC;AAEF,MAAM,CAAC,IAAM,UAAU,GAAG,UAAC,UAAkB,EAAE,MAAc;IAC3D,MAAM,CAAC,OAAO,CAAC,MAAM,CACnB,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,IAAI,KAAK,UAAU,EAA1B,CAA0B,CAAC,EAChE,CAAC,CACF,CAAC;IACF,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,IAAI,GAAG,UAAC,KAAY,EAAE,MAAc;IAC/C,OAAO,IAAI,OAAO,CAAS,UAAC,OAAO;QACjC,IAAI,MAAM,CAAC,MAAM,EAAE;YACjB,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;YAChD,OAAO;SACR;Q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,GAAG,CAAC,iBAAiB,CAAC,EAAA;;gBAApC,SAAoC,CAAC;;;;KACtC,CAAC","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"]}
@@ -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,28 @@
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 var UUID = function (a) {
10
+ return a // if the placeholder was passed, return
11
+ ? // a random number from 0 to 15
12
+ (a ^ // unless b is 8,
13
+ ((Math.random() * // in which case
14
+ 16) >> // a random number from
15
+ (a / 4))) // 8 to 11
16
+ .toString(16) // in hexadecimal
17
+ : // or otherwise a concatenated string:
18
+ (String(1e7) + // 10000000 +
19
+ String(-1e3) + // -1000 +
20
+ String(-4e3) + // -4000 +
21
+ String(-8e3) + // -80000000 +
22
+ String(-1e11)) // -100000000000,
23
+ .replace(
24
+ // replacing
25
+ /[018]/g, // zeroes, ones, and eights with
26
+ UUID);
27
+ };
28
+ //# sourceMappingURL=uuid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../../src/utils/uuid.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,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,IAAI,CACL,CAAC;AACV,CAAC,CAAC","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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amplitude/analytics-core",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "",
5
5
  "author": "Amplitude Inc",
6
6
  "homepage": "https://github.com/amplitude/Amplitude-TypeScript",
@@ -32,11 +32,11 @@
32
32
  "url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
33
33
  },
34
34
  "dependencies": {
35
- "@amplitude/analytics-types": "^0.2.1",
35
+ "@amplitude/analytics-types": "^0.3.0",
36
36
  "tslib": "^2.3.1"
37
37
  },
38
38
  "files": [
39
39
  "lib"
40
40
  ],
41
- "gitHead": "d7589883b3d0e09be9b827a87bb6d2f4bee3a643"
41
+ "gitHead": "b76a2494587c6a27e2007047c1602269ed2b3403"
42
42
  }
@@ -1,6 +0,0 @@
1
- import { Payload, Response, Transport } from '@amplitude/analytics-types';
2
- import { BaseTransport } from './base';
3
- export declare class Http extends BaseTransport implements Transport {
4
- send(serverUrl: string, payload: Payload): Promise<Response | null>;
5
- }
6
- //# sourceMappingURL=http.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE1E,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,qBAAa,IAAK,SAAQ,aAAc,YAAW,SAAS;IAC1D,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAwCpE"}
@@ -1,55 +0,0 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.Http = void 0;
3
- var tslib_1 = require("tslib");
4
- var http = require("http");
5
- var base_1 = require("./base");
6
- var Http = /** @class */ (function (_super) {
7
- (0, tslib_1.__extends)(Http, _super);
8
- function Http() {
9
- return _super !== null && _super.apply(this, arguments) || this;
10
- }
11
- Http.prototype.send = function (serverUrl, payload) {
12
- var _this = this;
13
- var url = new URL(serverUrl);
14
- var requestPayload = JSON.stringify(payload);
15
- var options = {
16
- headers: {
17
- 'Content-Type': 'application/json',
18
- 'Content-Length': Buffer.byteLength(requestPayload),
19
- },
20
- hostname: url.hostname,
21
- method: 'POST',
22
- path: url.pathname,
23
- port: url.port,
24
- protocol: url.protocol,
25
- };
26
- return new Promise(function (resolve) {
27
- var req = http.request(options, function (res) {
28
- res.setEncoding('utf8');
29
- var responsePayload = '';
30
- res.on('data', function (chunk) {
31
- responsePayload += chunk;
32
- });
33
- res.on('end', function () {
34
- if (res.complete && responsePayload.length > 0) {
35
- try {
36
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
37
- var parsedResponsePayload = JSON.parse(responsePayload);
38
- var result = _this.buildResponse(parsedResponsePayload);
39
- resolve(result);
40
- return;
41
- }
42
- catch (_a) {
43
- resolve(null);
44
- }
45
- }
46
- });
47
- });
48
- req.on('error', _this.buildResponse.bind(_this));
49
- req.end(requestPayload);
50
- });
51
- };
52
- return Http;
53
- }(base_1.BaseTransport));
54
- exports.Http = Http;
55
- //# sourceMappingURL=http.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":";;;AACA,2BA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BAAC,WAAM;4BACN,OAAO,CAAC,IAAI,CAAC,CAAC;yBACf;qBACF;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YACH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,KAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAI,CAAC,CAAC,CAAC;YAC/C,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IACH,WAAC;AAAD,CAAC,AAzCD,CAA0B,oBAAa,GAyCtC;AAzCY,oBAAI","sourcesContent":["import { Payload, Response, Transport } from '@amplitude/analytics-types';\nimport * as http from 'http';\nimport { BaseTransport } from './base';\n\nexport class Http extends BaseTransport implements Transport {\n send(serverUrl: string, payload: Payload): Promise<Response | null> {\n const url = new URL(serverUrl);\n const requestPayload = JSON.stringify(payload);\n const options = {\n headers: {\n 'Content-Type': 'application/json',\n 'Content-Length': Buffer.byteLength(requestPayload),\n },\n hostname: url.hostname,\n method: 'POST',\n path: url.pathname,\n port: url.port,\n protocol: url.protocol,\n };\n return new Promise((resolve) => {\n const req = http.request(options, (res) => {\n res.setEncoding('utf8');\n let responsePayload = '';\n res.on('data', (chunk: string) => {\n responsePayload += chunk;\n });\n\n res.on('end', () => {\n if (res.complete && responsePayload.length > 0) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const parsedResponsePayload: Record<string, any> = JSON.parse(responsePayload);\n const result = this.buildResponse(parsedResponsePayload);\n resolve(result);\n return;\n } catch {\n resolve(null);\n }\n }\n });\n });\n req.on('error', this.buildResponse.bind(this));\n req.end(requestPayload);\n });\n }\n}\n"]}
@@ -1,6 +0,0 @@
1
- import { Payload, Response, Transport } from '@amplitude/analytics-types';
2
- import { BaseTransport } from './base';
3
- export declare class Http extends BaseTransport implements Transport {
4
- send(serverUrl: string, payload: Payload): Promise<Response | null>;
5
- }
6
- //# sourceMappingURL=http.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE1E,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,qBAAa,IAAK,SAAQ,aAAc,YAAW,SAAS;IAC1D,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAwCpE"}
@@ -1,53 +0,0 @@
1
- import { __extends } from "tslib";
2
- import * as http from 'http';
3
- import { BaseTransport } from './base';
4
- var Http = /** @class */ (function (_super) {
5
- __extends(Http, _super);
6
- function Http() {
7
- return _super !== null && _super.apply(this, arguments) || this;
8
- }
9
- Http.prototype.send = function (serverUrl, payload) {
10
- var _this = this;
11
- var url = new URL(serverUrl);
12
- var requestPayload = JSON.stringify(payload);
13
- var options = {
14
- headers: {
15
- 'Content-Type': 'application/json',
16
- 'Content-Length': Buffer.byteLength(requestPayload),
17
- },
18
- hostname: url.hostname,
19
- method: 'POST',
20
- path: url.pathname,
21
- port: url.port,
22
- protocol: url.protocol,
23
- };
24
- return new Promise(function (resolve) {
25
- var req = http.request(options, function (res) {
26
- res.setEncoding('utf8');
27
- var responsePayload = '';
28
- res.on('data', function (chunk) {
29
- responsePayload += chunk;
30
- });
31
- res.on('end', function () {
32
- if (res.complete && responsePayload.length > 0) {
33
- try {
34
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
35
- var parsedResponsePayload = JSON.parse(responsePayload);
36
- var result = _this.buildResponse(parsedResponsePayload);
37
- resolve(result);
38
- return;
39
- }
40
- catch (_a) {
41
- resolve(null);
42
- }
43
- }
44
- });
45
- });
46
- req.on('error', _this.buildResponse.bind(_this));
47
- req.end(requestPayload);
48
- });
49
- };
50
- return Http;
51
- }(BaseTransport));
52
- export { Http };
53
- //# sourceMappingURL=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C,KAAK,CAAC,eAAe,CAAC,CAAC;4BAC/E,IAAM,MAAM,GAAG,KAAI,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC;4BACzD,OAAO,CAAC,MAAM,CAAC,CAAC;4BAChB,OAAO;yBACR;wBAAC,WAAM;4BACN,OAAO,CAAC,IAAI,CAAC,CAAC;yBACf;qBACF;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YACH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,KAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAI,CAAC,CAAC,CAAC;YAC/C,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IACH,WAAC;AAAD,CAAC,AAzCD,CAA0B,aAAa,GAyCtC","sourcesContent":["import { Payload, Response, Transport } from '@amplitude/analytics-types';\nimport * as http from 'http';\nimport { BaseTransport } from './base';\n\nexport class Http extends BaseTransport implements Transport {\n send(serverUrl: string, payload: Payload): Promise<Response | null> {\n const url = new URL(serverUrl);\n const requestPayload = JSON.stringify(payload);\n const options = {\n headers: {\n 'Content-Type': 'application/json',\n 'Content-Length': Buffer.byteLength(requestPayload),\n },\n hostname: url.hostname,\n method: 'POST',\n path: url.pathname,\n port: url.port,\n protocol: url.protocol,\n };\n return new Promise((resolve) => {\n const req = http.request(options, (res) => {\n res.setEncoding('utf8');\n let responsePayload = '';\n res.on('data', (chunk: string) => {\n responsePayload += chunk;\n });\n\n res.on('end', () => {\n if (res.complete && responsePayload.length > 0) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const parsedResponsePayload: Record<string, any> = JSON.parse(responsePayload);\n const result = this.buildResponse(parsedResponsePayload);\n resolve(result);\n return;\n } catch {\n resolve(null);\n }\n }\n });\n });\n req.on('error', this.buildResponse.bind(this));\n req.end(requestPayload);\n });\n }\n}\n"]}