@amplitude/analytics-core 0.3.0 → 0.4.1

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 (137) hide show
  1. package/lib/cjs/config.d.ts +8 -8
  2. package/lib/cjs/config.d.ts.map +1 -1
  3. package/lib/cjs/config.js +8 -7
  4. package/lib/cjs/config.js.map +1 -1
  5. package/lib/cjs/core-client.d.ts +5 -4
  6. package/lib/cjs/core-client.d.ts.map +1 -1
  7. package/lib/cjs/core-client.js +8 -4
  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 +3 -1
  30. package/lib/cjs/index.d.ts.map +1 -1
  31. package/lib/cjs/index.js +7 -3
  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 +17 -4
  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/transports/base.d.ts +7 -0
  46. package/lib/cjs/transports/base.d.ts.map +1 -0
  47. package/lib/cjs/transports/base.js +103 -0
  48. package/lib/cjs/transports/base.js.map +1 -0
  49. package/lib/cjs/utils/event-builder.d.ts +2 -2
  50. package/lib/cjs/utils/event-builder.d.ts.map +1 -1
  51. package/lib/cjs/utils/event-builder.js +4 -10
  52. package/lib/cjs/utils/event-builder.js.map +1 -1
  53. package/lib/cjs/utils/uuid.d.ts +10 -0
  54. package/lib/cjs/utils/uuid.d.ts.map +1 -0
  55. package/lib/cjs/utils/uuid.js +31 -0
  56. package/lib/cjs/utils/uuid.js.map +1 -0
  57. package/lib/esm/config.d.ts +8 -8
  58. package/lib/esm/config.d.ts.map +1 -1
  59. package/lib/esm/config.js +8 -7
  60. package/lib/esm/config.js.map +1 -1
  61. package/lib/esm/core-client.d.ts +5 -4
  62. package/lib/esm/core-client.d.ts.map +1 -1
  63. package/lib/esm/core-client.js +9 -5
  64. package/lib/esm/core-client.js.map +1 -1
  65. package/lib/esm/event-bridge/event-bridge-channel.d.ts +10 -0
  66. package/lib/esm/event-bridge/event-bridge-channel.d.ts.map +1 -0
  67. package/lib/esm/event-bridge/event-bridge-channel.js +30 -0
  68. package/lib/esm/event-bridge/event-bridge-channel.js.map +1 -0
  69. package/lib/esm/event-bridge/event-bridge-container.d.ts +6 -0
  70. package/lib/esm/event-bridge/event-bridge-container.d.ts.map +1 -0
  71. package/lib/esm/event-bridge/event-bridge-container.js +15 -0
  72. package/lib/esm/event-bridge/event-bridge-container.js.map +1 -0
  73. package/lib/esm/event-bridge/event-bridge.d.ts +8 -0
  74. package/lib/esm/event-bridge/event-bridge.d.ts.map +1 -0
  75. package/lib/esm/event-bridge/event-bridge.js +21 -0
  76. package/lib/esm/event-bridge/event-bridge.js.map +1 -0
  77. package/lib/esm/event-bridge/event-channel.d.ts +5 -0
  78. package/lib/esm/event-bridge/event-channel.d.ts.map +1 -0
  79. package/lib/esm/event-bridge/event-channel.js +6 -0
  80. package/lib/esm/event-bridge/event-channel.js.map +1 -0
  81. package/lib/esm/event-bridge/event-receiver.d.ts +8 -0
  82. package/lib/esm/event-bridge/event-receiver.d.ts.map +1 -0
  83. package/lib/esm/event-bridge/event-receiver.js +25 -0
  84. package/lib/esm/event-bridge/event-receiver.js.map +1 -0
  85. package/lib/esm/index.d.ts +3 -1
  86. package/lib/esm/index.d.ts.map +1 -1
  87. package/lib/esm/index.js +3 -1
  88. package/lib/esm/index.js.map +1 -1
  89. package/lib/esm/plugins/destination.d.ts +2 -1
  90. package/lib/esm/plugins/destination.d.ts.map +1 -1
  91. package/lib/esm/plugins/destination.js +17 -4
  92. package/lib/esm/plugins/destination.js.map +1 -1
  93. package/lib/esm/storage/memory.d.ts +11 -0
  94. package/lib/esm/storage/memory.d.ts.map +1 -0
  95. package/lib/esm/storage/memory.js +27 -0
  96. package/lib/esm/storage/memory.js.map +1 -0
  97. package/lib/esm/timeline.d.ts +1 -0
  98. package/lib/esm/timeline.d.ts.map +1 -1
  99. package/lib/esm/timeline.js +14 -0
  100. package/lib/esm/timeline.js.map +1 -1
  101. package/lib/esm/transports/base.d.ts +7 -0
  102. package/lib/esm/transports/base.d.ts.map +1 -0
  103. package/lib/esm/transports/base.js +101 -0
  104. package/lib/esm/transports/base.js.map +1 -0
  105. package/lib/esm/utils/event-builder.d.ts +2 -2
  106. package/lib/esm/utils/event-builder.d.ts.map +1 -1
  107. package/lib/esm/utils/event-builder.js +4 -10
  108. package/lib/esm/utils/event-builder.js.map +1 -1
  109. package/lib/esm/utils/uuid.d.ts +10 -0
  110. package/lib/esm/utils/uuid.d.ts.map +1 -0
  111. package/lib/esm/utils/uuid.js +28 -0
  112. package/lib/esm/utils/uuid.js.map +1 -0
  113. package/package.json +3 -3
  114. package/lib/cjs/transports/http.d.ts +0 -5
  115. package/lib/cjs/transports/http.d.ts.map +0 -1
  116. package/lib/cjs/transports/http.js +0 -51
  117. package/lib/cjs/transports/http.js.map +0 -1
  118. package/lib/cjs/utils/response-builder.d.ts +0 -3
  119. package/lib/cjs/utils/response-builder.d.ts.map +0 -1
  120. package/lib/cjs/utils/response-builder.js +0 -75
  121. package/lib/cjs/utils/response-builder.js.map +0 -1
  122. package/lib/cjs/utils/status-builder.d.ts +0 -3
  123. package/lib/cjs/utils/status-builder.d.ts.map +0 -1
  124. package/lib/cjs/utils/status-builder.js +0 -26
  125. package/lib/cjs/utils/status-builder.js.map +0 -1
  126. package/lib/esm/transports/http.d.ts +0 -5
  127. package/lib/esm/transports/http.d.ts.map +0 -1
  128. package/lib/esm/transports/http.js +0 -49
  129. package/lib/esm/transports/http.js.map +0 -1
  130. package/lib/esm/utils/response-builder.d.ts +0 -3
  131. package/lib/esm/utils/response-builder.d.ts.map +0 -1
  132. package/lib/esm/utils/response-builder.js +0 -72
  133. package/lib/esm/utils/response-builder.js.map +0 -1
  134. package/lib/esm/utils/status-builder.d.ts +0 -3
  135. package/lib/esm/utils/status-builder.d.ts.map +0 -1
  136. package/lib/esm/utils/status-builder.js +0 -23
  137. package/lib/esm/utils/status-builder.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/transports/base.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAElF,qBAAa,aAAc,YAAW,SAAS;IAC7C,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAIrE,aAAa,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,QAAQ,GAAG,IAAI;IAqEjE,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CA2BlC"}
@@ -0,0 +1,101 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
4
+ import { Status } from '@amplitude/analytics-types';
5
+ var BaseTransport = /** @class */ (function () {
6
+ function BaseTransport() {
7
+ }
8
+ BaseTransport.prototype.send = function (_serverUrl, _payload) {
9
+ return Promise.resolve(null);
10
+ };
11
+ BaseTransport.prototype.buildResponse = function (responseJSON) {
12
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
13
+ if (typeof responseJSON !== 'object') {
14
+ return null;
15
+ }
16
+ var statusCode = responseJSON.code || 0;
17
+ var status = this.buildStatus(statusCode);
18
+ switch (status) {
19
+ case Status.Success:
20
+ return {
21
+ status: status,
22
+ statusCode: statusCode,
23
+ body: {
24
+ eventsIngested: (_a = responseJSON.events_ingested) !== null && _a !== void 0 ? _a : 0,
25
+ payloadSizeBytes: (_b = responseJSON.payload_size_bytes) !== null && _b !== void 0 ? _b : 0,
26
+ serverUploadTime: (_c = responseJSON.server_upload_time) !== null && _c !== void 0 ? _c : 0,
27
+ },
28
+ };
29
+ case Status.Invalid:
30
+ return {
31
+ status: status,
32
+ statusCode: statusCode,
33
+ body: {
34
+ error: (_d = responseJSON.error) !== null && _d !== void 0 ? _d : '',
35
+ missingField: (_e = responseJSON.missing_field) !== null && _e !== void 0 ? _e : '',
36
+ eventsWithInvalidFields: (_f = responseJSON.events_with_invalid_fields) !== null && _f !== void 0 ? _f : {},
37
+ eventsWithMissingFields: (_g = responseJSON.events_with_missing_fields) !== null && _g !== void 0 ? _g : {},
38
+ eventsWithInvalidIdLengths: (_h = responseJSON.events_with_invalid_id_lengths) !== null && _h !== void 0 ? _h : {},
39
+ epsThreshold: (_j = responseJSON.eps_threshold) !== null && _j !== void 0 ? _j : 0,
40
+ exceededDailyQuotaDevices: (_k = responseJSON.exceeded_daily_quota_devices) !== null && _k !== void 0 ? _k : {},
41
+ silencedDevices: (_l = responseJSON.silenced_devices) !== null && _l !== void 0 ? _l : [],
42
+ silencedEvents: (_m = responseJSON.silenced_events) !== null && _m !== void 0 ? _m : [],
43
+ throttledDevices: (_o = responseJSON.throttled_devices) !== null && _o !== void 0 ? _o : {},
44
+ throttledEvents: (_p = responseJSON.throttled_events) !== null && _p !== void 0 ? _p : [],
45
+ },
46
+ };
47
+ case Status.PayloadTooLarge:
48
+ return {
49
+ status: status,
50
+ statusCode: statusCode,
51
+ body: {
52
+ error: (_q = responseJSON.error) !== null && _q !== void 0 ? _q : '',
53
+ },
54
+ };
55
+ case Status.RateLimit:
56
+ return {
57
+ status: status,
58
+ statusCode: statusCode,
59
+ body: {
60
+ error: (_r = responseJSON.error) !== null && _r !== void 0 ? _r : '',
61
+ epsThreshold: (_s = responseJSON.eps_threshold) !== null && _s !== void 0 ? _s : 0,
62
+ throttledDevices: (_t = responseJSON.throttled_devices) !== null && _t !== void 0 ? _t : {},
63
+ throttledUsers: (_u = responseJSON.throttled_users) !== null && _u !== void 0 ? _u : {},
64
+ exceededDailyQuotaDevices: (_v = responseJSON.exceeded_daily_quota_devices) !== null && _v !== void 0 ? _v : {},
65
+ exceededDailyQuotaUsers: (_w = responseJSON.exceeded_daily_quota_users) !== null && _w !== void 0 ? _w : {},
66
+ throttledEvents: (_x = responseJSON.throttled_events) !== null && _x !== void 0 ? _x : [],
67
+ },
68
+ };
69
+ case Status.Timeout:
70
+ default:
71
+ return {
72
+ status: status,
73
+ statusCode: statusCode,
74
+ };
75
+ }
76
+ };
77
+ BaseTransport.prototype.buildStatus = function (code) {
78
+ if (code >= 200 && code < 300) {
79
+ return Status.Success;
80
+ }
81
+ if (code === 429) {
82
+ return Status.RateLimit;
83
+ }
84
+ if (code === 413) {
85
+ return Status.PayloadTooLarge;
86
+ }
87
+ if (code === 408) {
88
+ return Status.Timeout;
89
+ }
90
+ if (code >= 400 && code < 500) {
91
+ return Status.Invalid;
92
+ }
93
+ if (code >= 500) {
94
+ return Status.Failed;
95
+ }
96
+ return Status.Unknown;
97
+ };
98
+ return BaseTransport;
99
+ }());
100
+ export { BaseTransport };
101
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/transports/base.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,4DAA4D;AAC5D,sDAAsD;AACtD,OAAO,EAAqB,MAAM,EAAa,MAAM,4BAA4B,CAAC;AAElF;IAAA;IAqGA,CAAC;IApGC,4BAAI,GAAJ,UAAK,UAAkB,EAAE,QAAiB;QACxC,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,qCAAa,GAAb,UAAc,YAAiC;;QAC7C,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;YACpC,OAAO,IAAI,CAAC;SACb;QAED,IAAM,UAAU,GAAG,YAAY,CAAC,IAAI,IAAI,CAAC,CAAC;QAC1C,IAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAE5C,QAAQ,MAAM,EAAE;YACd,KAAK,MAAM,CAAC,OAAO;gBACjB,OAAO;oBACL,MAAM,QAAA;oBACN,UAAU,YAAA;oBACV,IAAI,EAAE;wBACJ,cAAc,EAAE,MAAA,YAAY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safe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\nimport { Payload, Response, Status, Transport } from '@amplitude/analytics-types';\n\nexport class BaseTransport implements Transport {\n send(_serverUrl: string, _payload: Payload): Promise<Response | null> {\n return Promise.resolve(null);\n }\n\n buildResponse(responseJSON: Record<string, any>): Response | null {\n if (typeof responseJSON !== 'object') {\n return null;\n }\n\n const statusCode = responseJSON.code || 0;\n const status = this.buildStatus(statusCode);\n\n switch (status) {\n case Status.Success:\n return {\n status,\n statusCode,\n body: {\n eventsIngested: responseJSON.events_ingested ?? 0,\n payloadSizeBytes: responseJSON.payload_size_bytes ?? 0,\n serverUploadTime: responseJSON.server_upload_time ?? 0,\n },\n };\n\n case Status.Invalid:\n return {\n status,\n statusCode,\n body: {\n error: responseJSON.error ?? '',\n missingField: responseJSON.missing_field ?? '',\n eventsWithInvalidFields: responseJSON.events_with_invalid_fields ?? {},\n eventsWithMissingFields: responseJSON.events_with_missing_fields ?? {},\n eventsWithInvalidIdLengths: responseJSON.events_with_invalid_id_lengths ?? {},\n epsThreshold: responseJSON.eps_threshold ?? 0,\n exceededDailyQuotaDevices: responseJSON.exceeded_daily_quota_devices ?? {},\n silencedDevices: responseJSON.silenced_devices ?? [],\n silencedEvents: responseJSON.silenced_events ?? [],\n throttledDevices: responseJSON.throttled_devices ?? {},\n throttledEvents: responseJSON.throttled_events ?? [],\n },\n };\n case Status.PayloadTooLarge:\n return {\n status,\n statusCode,\n body: {\n error: responseJSON.error ?? '',\n },\n };\n case Status.RateLimit:\n return {\n status,\n statusCode,\n body: {\n error: responseJSON.error ?? '',\n epsThreshold: responseJSON.eps_threshold ?? 0,\n throttledDevices: responseJSON.throttled_devices ?? {},\n throttledUsers: responseJSON.throttled_users ?? {},\n exceededDailyQuotaDevices: responseJSON.exceeded_daily_quota_devices ?? {},\n exceededDailyQuotaUsers: responseJSON.exceeded_daily_quota_users ?? {},\n throttledEvents: responseJSON.throttled_events ?? [],\n },\n };\n case Status.Timeout:\n default:\n return {\n status,\n statusCode,\n };\n }\n }\n\n buildStatus(code: number): Status {\n if (code >= 200 && code < 300) {\n return Status.Success;\n }\n\n if (code === 429) {\n return Status.RateLimit;\n }\n\n if (code === 413) {\n return Status.PayloadTooLarge;\n }\n\n if (code === 408) {\n return Status.Timeout;\n }\n\n if (code >= 400 && code < 500) {\n return Status.Invalid;\n }\n\n if (code >= 500) {\n return Status.Failed;\n }\n\n return Status.Unknown;\n }\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: (userId: string | undefined, deviceId: string | undefined, identify: IIdentify, eventOptions?: EventOptions | undefined) => IdentifyEvent;
4
- export declare const createGroupIdentifyEvent: (userId: string | undefined, deviceId: string | undefined, groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions | undefined) => GroupIdentifyEvent;
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,WACtB,MAAM,GAAG,SAAS,YAChB,MAAM,GAAG,SAAS,YAClB,SAAS,8CAElB,aAaF,CAAC;AAEF,eAAO,MAAM,wBAAwB,WAC3B,MAAM,GAAG,SAAS,YAChB,MAAM,GAAG,SAAS,aACjB,MAAM,aACN,MAAM,GAAG,MAAM,EAAE,YAClB,SAAS,8CAElB,kBAgBF,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAAe,MAAM,aAAa,MAAM,GAAG,MAAM,EAAE,kBAY/E,CAAC;AAEF,eAAO,MAAM,kBAAkB,YAAa,OAAO,8CAAgC,YAMlF,CAAC"}
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"}
@@ -5,21 +5,15 @@ export var createTrackEvent = function (eventInput, eventProperties, eventOption
5
5
  var baseEvent = typeof eventInput === 'string' ? { event_type: eventInput } : eventInput;
6
6
  return __assign(__assign(__assign({}, baseEvent), eventOptions), (eventProperties && { event_properties: eventProperties }));
7
7
  };
8
- export var createIdentifyEvent = function (userId, deviceId, identify, eventOptions) {
9
- var identifyEvent = __assign(__assign({}, eventOptions), { event_type: SpecialEventType.IDENTIFY, user_properties: identify.getUserProperties(), user_id: userId });
10
- if (deviceId !== undefined && deviceId.length > 0) {
11
- identifyEvent.device_id = deviceId;
12
- }
8
+ export var createIdentifyEvent = function (identify, eventOptions) {
9
+ var identifyEvent = __assign(__assign({}, eventOptions), { event_type: SpecialEventType.IDENTIFY, user_properties: identify.getUserProperties() });
13
10
  return identifyEvent;
14
11
  };
15
- export var createGroupIdentifyEvent = function (userId, deviceId, groupType, groupName, identify, eventOptions) {
12
+ export var createGroupIdentifyEvent = function (groupType, groupName, identify, eventOptions) {
16
13
  var _a;
17
14
  var groupIdentify = __assign(__assign({}, eventOptions), { event_type: SpecialEventType.GROUP_IDENTIFY, group_properties: identify.getUserProperties(), groups: (_a = {},
18
15
  _a[groupType] = groupName,
19
- _a), user_id: userId });
20
- if (deviceId !== undefined && deviceId.length > 0) {
21
- groupIdentify.device_id = deviceId;
22
- }
16
+ _a) });
23
17
  return groupIdentify;
24
18
  };
25
19
  export var createGroupEvent = function (groupType, groupName) {
@@ -1 +1 @@
1
- {"version":3,"file":"event-builder.js","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":";AAAA,OAAO,EAKL,gBAAgB,GAKjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAC9B,UAA8B,EAC9B,eAAqC,EACrC,YAA2B;IAE3B,IAAM,SAAS,GAAc,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;IACtG,sCACK,SAAS,GACT,YAAY,GACZ,CAAC,eAAe,IAAI,EAAE,gBAAgB,EAAE,e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AC7C,MAAM;YACJ,GAAC,SAAS,IAAG,SAAS;eACvB;KACF,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,kBAAkB,GAAG,UAAC,OAAgB,EAAE,YAA2B;IAC9E,6BACK,YAAY,KACf,UAAU,EAAE,gBAAgB,CAAC,OAAO,EACpC,gBAAgB,EAAE,OAAO,CAAC,kBAAkB,EAAE,IAC9C;AACJ,CAAC,CAAC","sourcesContent":["import {\n BaseEvent,\n TrackEvent,\n IdentifyEvent,\n GroupIdentifyEvent,\n SpecialEventType,\n Identify as IIdentify,\n Revenue,\n RevenueEvent,\n EventOptions,\n} from '@amplitude/analytics-types';\nimport { Identify } from '../identify';\n\nexport const createTrackEvent = (\n eventInput: BaseEvent | string,\n eventProperties?: Record<string, any>,\n eventOptions?: EventOptions,\n): TrackEvent => {\n const baseEvent: BaseEvent = typeof eventInput === 'string' ? { event_type: eventInput } : eventInput;\n return {\n ...baseEvent,\n ...eventOptions,\n ...(eventProperties && { event_properties: eventProperties }),\n };\n};\n\nexport const createIdentifyEvent = (\n userId: string | undefined,\n deviceId: string | undefined,\n identify: IIdentify,\n eventOptions?: EventOptions,\n): IdentifyEvent => {\n const identifyEvent: IdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.IDENTIFY,\n user_properties: identify.getUserProperties(),\n user_id: userId,\n };\n\n if (deviceId !== undefined && deviceId.length > 0) {\n identifyEvent.device_id = deviceId;\n }\n\n return identifyEvent;\n};\n\nexport const createGroupIdentifyEvent = (\n userId: string | undefined,\n deviceId: string | undefined,\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 user_id: userId,\n };\n\n if (deviceId !== undefined && deviceId.length > 0) {\n groupIdentify.device_id = deviceId;\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"]}
1
+ {"version":3,"file":"event-builder.js","sourceRoot":"","sources":["../../../src/utils/event-builder.ts"],"names":[],"mappings":";AAAA,OAAO,EAKL,gBAAgB,GAKjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAC9B,UAA8B,EAC9B,eAAqC,EACrC,YAA2B;IAE3B,IAAM,SAAS,GAAc,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;IACtG,sCACK,SAAS,GACT,YAAY,GACZ,CAAC,eAAe,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC,EAC7D;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,mBAAmB,GAAG,UAAC,QAAmB,EAAE,YAA2B;IAClF,IAAM,aAAa,yBACd,YAAY,KACf,UAAU,EAAE,gBAAgB,CAAC,QAAQ,EACrC,eAAe,EAAE,QAAQ,CAAC,iBAAiB,EAAE,GAC9C,CAAC;IAEF,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,wBAAwB,GAAG,UACtC,SAAiB,EACjB,SAA4B,EAC5B,QAAmB,EACnB,YAA2B;;IAE3B,IAAM,aAAa,yBACd,YAAY,KACf,UAAU,EAAE,gBAAgB,CAAC,cAAc,EAC3C,gBAAgB,EAAE,QAAQ,CAAC,iBAAiB,EAAE,EAC9C,MAAM;YACJ,GAAC,SAAS,IAAG,SAAS;kBAEzB,CAAC;IAEF,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAAC,SAAiB,EAAE,SAA4B;;IAC9E,IAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAEnC,IAAM,UAAU,GAAkB;QAChC,UAAU,EAAE,gBAAgB,CAAC,QAAQ;QACrC,eAAe,EAAE,QAAQ,CAAC,iBAAiB,EAAE;QAC7C,MAAM;YACJ,GAAC,SAAS,IAAG,SAAS;eACvB;KACF,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,kBAAkB,GAAG,UAAC,OAAgB,EAAE,YAA2B;IAC9E,6BACK,YAAY,KACf,UAAU,EAAE,gBAAgB,CAAC,OAAO,EACpC,gBAAgB,EAAE,OAAO,CAAC,kBAAkB,EAAE,IAC9C;AACJ,CAAC,CAAC","sourcesContent":["import {\n BaseEvent,\n TrackEvent,\n IdentifyEvent,\n GroupIdentifyEvent,\n SpecialEventType,\n Identify as IIdentify,\n Revenue,\n RevenueEvent,\n EventOptions,\n} from '@amplitude/analytics-types';\nimport { Identify } from '../identify';\n\nexport const createTrackEvent = (\n eventInput: BaseEvent | string,\n eventProperties?: Record<string, any>,\n eventOptions?: EventOptions,\n): TrackEvent => {\n const baseEvent: BaseEvent = typeof eventInput === 'string' ? { event_type: eventInput } : eventInput;\n return {\n ...baseEvent,\n ...eventOptions,\n ...(eventProperties && { event_properties: eventProperties }),\n };\n};\n\nexport const createIdentifyEvent = (identify: IIdentify, eventOptions?: EventOptions): IdentifyEvent => {\n const identifyEvent: IdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.IDENTIFY,\n user_properties: identify.getUserProperties(),\n };\n\n return identifyEvent;\n};\n\nexport const createGroupIdentifyEvent = (\n groupType: string,\n groupName: string | string[],\n identify: IIdentify,\n eventOptions?: EventOptions,\n): GroupIdentifyEvent => {\n const groupIdentify: GroupIdentifyEvent = {\n ...eventOptions,\n event_type: SpecialEventType.GROUP_IDENTIFY,\n group_properties: identify.getUserProperties(),\n groups: {\n [groupType]: groupName,\n },\n };\n\n return groupIdentify;\n};\n\nexport const createGroupEvent = (groupType: string, groupName: string | string[]) => {\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,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.0",
3
+ "version": "0.4.1",
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.0",
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": "3899a210e9848fcf66a4cd2b353ea2c0c6dd45dc"
41
+ "gitHead": "77f86840a33e9812eff986c3dec7f6372edea6eb"
42
42
  }
@@ -1,5 +0,0 @@
1
- import { Payload, Response, Transport } from '@amplitude/analytics-types';
2
- export declare class Http implements Transport {
3
- send(serverUrl: string, payload: Payload): Promise<Response | null>;
4
- }
5
- //# 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;AAI1E,qBAAa,IAAK,YAAW,SAAS;IACpC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAwCpE"}
@@ -1,51 +0,0 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.Http = void 0;
3
- var http = require("http");
4
- var response_builder_1 = require("../utils/response-builder");
5
- var Http = /** @class */ (function () {
6
- function Http() {
7
- }
8
- Http.prototype.send = function (serverUrl, payload) {
9
- var url = new URL(serverUrl);
10
- var requestPayload = JSON.stringify(payload);
11
- var options = {
12
- headers: {
13
- 'Content-Type': 'application/json',
14
- 'Content-Length': Buffer.byteLength(requestPayload),
15
- },
16
- hostname: url.hostname,
17
- method: 'POST',
18
- path: url.pathname,
19
- port: url.port,
20
- protocol: url.protocol,
21
- };
22
- return new Promise(function (resolve) {
23
- var req = http.request(options, function (res) {
24
- res.setEncoding('utf8');
25
- var responsePayload = '';
26
- res.on('data', function (chunk) {
27
- responsePayload += chunk;
28
- });
29
- res.on('end', function () {
30
- if (res.complete && responsePayload.length > 0) {
31
- try {
32
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
33
- var parsedResponsePayload = JSON.parse(responsePayload);
34
- var result = (0, response_builder_1.buildResponse)(parsedResponsePayload);
35
- resolve(result);
36
- return;
37
- }
38
- catch (_a) {
39
- resolve(null);
40
- }
41
- }
42
- });
43
- });
44
- req.on('error', response_builder_1.buildResponse);
45
- req.end(requestPayload);
46
- });
47
- };
48
- return Http;
49
- }());
50
- exports.Http = Http;
51
- //# sourceMappingURL=http.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":";;AACA,2BAA6B;AAC7B,8DAA0D;AAE1D;IAAA;IAyCA,CAAC;IAxCC,mBAAI,GAAJ,UAAK,SAAiB,EAAE,OAAgB;QACtC,IAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;QAC/B,IAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAM,OAAO,GAAG;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,gBAAgB,EAAE,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC;aACpD;YACD,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,GAAG,CAAC,QAAQ;YAClB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB,CAAC;QACF,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO;YACzB,IAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,UAAC,GAAG;gBACpC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;gBACxB,IAAI,eAAe,GAAG,EAAE,CAAC;gBACzB,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,UAAC,KAAa;oBAC3B,eAAe,IAAI,KAAK,CAAC;gBAC3B,CAAC,CAAC,CAAC;gBAEH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE;oBACZ,IAAI,GAAG,CAAC,QAAQ,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE;wBAC9C,IAAI;4BACF,mEAAmE;4BACnE,IAAM,qBAAqB,GAAwB,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;4BAC/E,IAAM,MAAM,GAAG,IAAA,gCAAa,EAAC,qBAAqB,CAAC,CAAC;4BACpD,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,gCAAa,CAAC,CAAC;YAC/B,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IACH,WAAC;AAAD,CAAC,AAzCD,IAyCC;AAzCY,oBAAI","sourcesContent":["import { Payload, Response, Transport } from '@amplitude/analytics-types';\nimport * as http from 'http';\nimport { buildResponse } from '../utils/response-builder';\n\nexport class Http 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 = buildResponse(parsedResponsePayload);\n resolve(result);\n return;\n } catch {\n resolve(null);\n }\n }\n });\n });\n req.on('error', buildResponse);\n req.end(requestPayload);\n });\n }\n}\n"]}
@@ -1,3 +0,0 @@
1
- import { Response } from '@amplitude/analytics-types';
2
- export declare const buildResponse: (responseJSON: Record<string, any>) => Response | null;
3
- //# sourceMappingURL=response-builder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"response-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/response-builder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAU,MAAM,4BAA4B,CAAC;AAG9D,eAAO,MAAM,aAAa,iBAAkB,OAAO,MAAM,EAAE,GAAG,CAAC,KAAG,QAAQ,GAAG,IAmE5E,CAAC"}
@@ -1,75 +0,0 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.buildResponse = void 0;
3
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
4
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
5
- /* eslint-disable @typescript-eslint/no-unsafe-call */
6
- var analytics_types_1 = require("@amplitude/analytics-types");
7
- var status_builder_1 = require("./status-builder");
8
- var buildResponse = function (responseJSON) {
9
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
10
- if (typeof responseJSON !== 'object') {
11
- return null;
12
- }
13
- var statusCode = responseJSON.code || 0;
14
- var status = (0, status_builder_1.buildStatus)(statusCode);
15
- switch (status) {
16
- case analytics_types_1.Status.Success:
17
- return {
18
- status: status,
19
- statusCode: statusCode,
20
- body: {
21
- eventsIngested: (_a = responseJSON.events_ingested) !== null && _a !== void 0 ? _a : 0,
22
- payloadSizeBytes: (_b = responseJSON.payload_size_bytes) !== null && _b !== void 0 ? _b : 0,
23
- serverUploadTime: (_c = responseJSON.server_upload_time) !== null && _c !== void 0 ? _c : 0,
24
- },
25
- };
26
- case analytics_types_1.Status.Invalid:
27
- return {
28
- status: status,
29
- statusCode: statusCode,
30
- body: {
31
- error: (_d = responseJSON.error) !== null && _d !== void 0 ? _d : '',
32
- missingField: (_e = responseJSON.missing_field) !== null && _e !== void 0 ? _e : '',
33
- eventsWithInvalidFields: (_f = responseJSON.events_with_invalid_fields) !== null && _f !== void 0 ? _f : {},
34
- eventsWithMissingFields: (_g = responseJSON.events_with_missing_fields) !== null && _g !== void 0 ? _g : {},
35
- eventsWithInvalidIdLengths: (_h = responseJSON.events_with_invalid_id_lengths) !== null && _h !== void 0 ? _h : {},
36
- epsThreshold: (_j = responseJSON.eps_threshold) !== null && _j !== void 0 ? _j : 0,
37
- exceededDailyQuotaDevices: (_k = responseJSON.exceeded_daily_quota_devices) !== null && _k !== void 0 ? _k : {},
38
- silencedDevices: (_l = responseJSON.silenced_devices) !== null && _l !== void 0 ? _l : [],
39
- silencedEvents: (_m = responseJSON.silenced_events) !== null && _m !== void 0 ? _m : [],
40
- throttledDevices: (_o = responseJSON.throttled_devices) !== null && _o !== void 0 ? _o : {},
41
- throttledEvents: (_p = responseJSON.throttled_events) !== null && _p !== void 0 ? _p : [],
42
- },
43
- };
44
- case analytics_types_1.Status.PayloadTooLarge:
45
- return {
46
- status: status,
47
- statusCode: statusCode,
48
- body: {
49
- error: (_q = responseJSON.error) !== null && _q !== void 0 ? _q : '',
50
- },
51
- };
52
- case analytics_types_1.Status.RateLimit:
53
- return {
54
- status: status,
55
- statusCode: statusCode,
56
- body: {
57
- error: (_r = responseJSON.error) !== null && _r !== void 0 ? _r : '',
58
- epsThreshold: (_s = responseJSON.eps_threshold) !== null && _s !== void 0 ? _s : 0,
59
- throttledDevices: (_t = responseJSON.throttled_devices) !== null && _t !== void 0 ? _t : {},
60
- throttledUsers: (_u = responseJSON.throttled_users) !== null && _u !== void 0 ? _u : {},
61
- exceededDailyQuotaDevices: (_v = responseJSON.exceeded_daily_quota_devices) !== null && _v !== void 0 ? _v : {},
62
- exceededDailyQuotaUsers: (_w = responseJSON.exceeded_daily_quota_users) !== null && _w !== void 0 ? _w : {},
63
- throttledEvents: (_x = responseJSON.throttled_events) !== null && _x !== void 0 ? _x : [],
64
- },
65
- };
66
- case analytics_types_1.Status.Timeout:
67
- default:
68
- return {
69
- status: status,
70
- statusCode: statusCode,
71
- };
72
- }
73
- };
74
- exports.buildResponse = buildResponse;
75
- //# sourceMappingURL=response-builder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"response-builder.js","sourceRoot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AAgB,mCAAI,EAAE;oBACpD,cAAc,EAAE,MAAA,YAAY,CAAC,eAAe,mCAAI,EAAE;oBAClD,gBAAgB,EAAE,MAAA,YAAY,CAAC,iBAAiB,mCAAI,EAAE;oBACtD,eAAe,EAAE,MAAA,YAAY,CAAC,gBAAgB,mCAAI,EAAE;iBACrD;aACF,CAAC;QACJ,KAAK,wBAAM,CAAC,eAAe;YACzB,OAAO;gBACL,MAAM,QAAA;gBACN,UAAU,YAAA;gBACV,IAAI,EAAE;oBACJ,KAAK,EAAE,MAAA,YAAY,CAAC,KAAK,mCAAI,EAAE;iBAChC;aACF,CAAC;QACJ,KAAK,wBAAM,CAAC,SAAS;YACnB,OAAO;gBACL,MAAM,QAAA;gBACN,UAAU,YAAA;gBACV,IAAI,EAAE;oBACJ,KAAK,EAAE,MAAA,YAAY,CAAC,KAAK,mCAAI,EAAE;oBAC/B,YAAY,EAAE,MAAA,YAAY,CAAC,aAAa,mCAAI,CAAC;oBAC7C,gBAAgB,EAAE,MAAA,YAAY,CAAC,iBAAiB,mCAAI,EAAE;oBACtD,cAAc,EAAE,MAAA,YAAY,CAAC,eAAe,mCAAI,EAAE;oBAClD,yBAAyB,EAAE,MAAA,YAAY,CAAC,4BAA4B,mCAAI,EAAE;oBAC1E,uBAAuB,EAAE,MAAA,YAAY,CAAC,0BAA0B,mCAAI,EAAE;oBACtE,eAAe,EAAE,MAAA,YAAY,CAAC,gBAAgB,mCAAI,EAAE;iBACrD;aACF,CAAC;QACJ,KAAK,wBAAM,CAAC,OAAO,CAAC;QACpB;YACE,OAAO;gBACL,MAAM,QAAA;gBACN,UAAU,YAAA;aACX,CAAC;KACL;AACH,CAAC,CAAC;AAnEW,QAAA,aAAa,iBAmExB","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\nimport { Response, Status } from '@amplitude/analytics-types';\nimport { buildStatus } from './status-builder';\n\nexport const buildResponse = (responseJSON: Record<string, any>): Response | null => {\n if (typeof responseJSON !== 'object') {\n return null;\n }\n\n const statusCode = responseJSON.code || 0;\n const status = buildStatus(statusCode);\n\n switch (status) {\n case Status.Success:\n return {\n status,\n statusCode,\n body: {\n eventsIngested: responseJSON.events_ingested ?? 0,\n payloadSizeBytes: responseJSON.payload_size_bytes ?? 0,\n serverUploadTime: responseJSON.server_upload_time ?? 0,\n },\n };\n\n case Status.Invalid:\n return {\n status,\n statusCode,\n body: {\n error: responseJSON.error ?? '',\n missingField: responseJSON.missing_field ?? '',\n eventsWithInvalidFields: responseJSON.events_with_invalid_fields ?? {},\n eventsWithMissingFields: responseJSON.events_with_missing_fields ?? {},\n eventsWithInvalidIdLengths: responseJSON.events_with_invalid_id_lengths ?? {},\n epsThreshold: responseJSON.eps_threshold ?? 0,\n exceededDailyQuotaDevices: responseJSON.exceeded_daily_quota_devices ?? {},\n silencedDevices: responseJSON.silenced_devices ?? [],\n silencedEvents: responseJSON.silenced_events ?? [],\n throttledDevices: responseJSON.throttled_devices ?? {},\n throttledEvents: responseJSON.throttled_events ?? [],\n },\n };\n case Status.PayloadTooLarge:\n return {\n status,\n statusCode,\n body: {\n error: responseJSON.error ?? '',\n },\n };\n case Status.RateLimit:\n return {\n status,\n statusCode,\n body: {\n error: responseJSON.error ?? '',\n epsThreshold: responseJSON.eps_threshold ?? 0,\n throttledDevices: responseJSON.throttled_devices ?? {},\n throttledUsers: responseJSON.throttled_users ?? {},\n exceededDailyQuotaDevices: responseJSON.exceeded_daily_quota_devices ?? {},\n exceededDailyQuotaUsers: responseJSON.exceeded_daily_quota_users ?? {},\n throttledEvents: responseJSON.throttled_events ?? [],\n },\n };\n case Status.Timeout:\n default:\n return {\n status,\n statusCode,\n };\n }\n};\n"]}
@@ -1,3 +0,0 @@
1
- import { Status } from '@amplitude/analytics-types';
2
- export declare function buildStatus(code: number): Status;
3
- //# sourceMappingURL=status-builder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"status-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/status-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA0BhD"}
@@ -1,26 +0,0 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.buildStatus = void 0;
3
- var analytics_types_1 = require("@amplitude/analytics-types");
4
- function buildStatus(code) {
5
- if (code >= 200 && code < 300) {
6
- return analytics_types_1.Status.Success;
7
- }
8
- if (code === 429) {
9
- return analytics_types_1.Status.RateLimit;
10
- }
11
- if (code === 413) {
12
- return analytics_types_1.Status.PayloadTooLarge;
13
- }
14
- if (code === 408) {
15
- return analytics_types_1.Status.Timeout;
16
- }
17
- if (code >= 400 && code < 500) {
18
- return analytics_types_1.Status.Invalid;
19
- }
20
- if (code >= 500) {
21
- return analytics_types_1.Status.Failed;
22
- }
23
- return analytics_types_1.Status.Unknown;
24
- }
25
- exports.buildStatus = buildStatus;
26
- //# sourceMappingURL=status-builder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"status-builder.js","sourceRoot":"","sources":["../../../src/utils/status-builder.ts"],"names":[],"mappings":";;AAAA,8DAAoD;AAEpD,SAAgB,WAAW,CAAC,IAAY;IACtC,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,GAAG,GAAG,EAAE;QAC7B,OAAO,wBAAM,CAAC,OAAO,CAAC;KACvB;IAED,IAAI,IAAI,KAAK,GAAG,EAAE;QAChB,OAAO,wBAAM,CAAC,SAAS,CAAC;KACzB;IAED,IAAI,IAAI,KAAK,GAAG,EAAE;QAChB,OAAO,wBAAM,CAAC,eAAe,CAAC;KAC/B;IAED,IAAI,IAAI,KAAK,GAAG,EAAE;QAChB,OAAO,wBAAM,CAAC,OAAO,CAAC;KACvB;IAED,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,GAAG,GAAG,EAAE;QAC7B,OAAO,wBAAM,CAAC,OAAO,CAAC;KACvB;IAED,IAAI,IAAI,IAAI,GAAG,EAAE;QACf,OAAO,wBAAM,CAAC,MAAM,CAAC;KACtB;IAED,OAAO,wBAAM,CAAC,OAAO,CAAC;AACxB,CAAC;AA1BD,kCA0BC","sourcesContent":["import { Status } from '@amplitude/analytics-types';\n\nexport function buildStatus(code: number): Status {\n if (code >= 200 && code < 300) {\n return Status.Success;\n }\n\n if (code === 429) {\n return Status.RateLimit;\n }\n\n if (code === 413) {\n return Status.PayloadTooLarge;\n }\n\n if (code === 408) {\n return Status.Timeout;\n }\n\n if (code >= 400 && code < 500) {\n return Status.Invalid;\n }\n\n if (code >= 500) {\n return Status.Failed;\n }\n\n return Status.Unknown;\n}\n"]}
@@ -1,5 +0,0 @@
1
- import { Payload, Response, Transport } from '@amplitude/analytics-types';
2
- export declare class Http implements Transport {
3
- send(serverUrl: string, payload: Payload): Promise<Response | null>;
4
- }
5
- //# 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;AAI1E,qBAAa,IAAK,YAAW,SAAS;IACpC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAwCpE"}
@@ -1,49 +0,0 @@
1
- import * as http from 'http';
2
- import { buildResponse } from '../utils/response-builder';
3
- var Http = /** @class */ (function () {
4
- function Http() {
5
- }
6
- Http.prototype.send = function (serverUrl, payload) {
7
- var url = new URL(serverUrl);
8
- var requestPayload = JSON.stringify(payload);
9
- var options = {
10
- headers: {
11
- 'Content-Type': 'application/json',
12
- 'Content-Length': Buffer.byteLength(requestPayload),
13
- },
14
- hostname: url.hostname,
15
- method: 'POST',
16
- path: url.pathname,
17
- port: url.port,
18
- protocol: url.protocol,
19
- };
20
- return new Promise(function (resolve) {
21
- var req = http.request(options, function (res) {
22
- res.setEncoding('utf8');
23
- var responsePayload = '';
24
- res.on('data', function (chunk) {
25
- responsePayload += chunk;
26
- });
27
- res.on('end', function () {
28
- if (res.complete && responsePayload.length > 0) {
29
- try {
30
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
31
- var parsedResponsePayload = JSON.parse(responsePayload);
32
- var result = buildResponse(parsedResponsePayload);
33
- resolve(result);
34
- return;
35
- }
36
- catch (_a) {
37
- resolve(null);
38
- }
39
- }
40
- });
41
- });
42
- req.on('error', buildResponse);
43
- req.end(requestPayload);
44
- });
45
- };
46
- return Http;
47
- }());
48
- export { Http };
49
- //# sourceMappingURL=http.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D;IAAA;IAyCA,CAAC;IAxCC,mBAAI,GAAJ,UAAK,SAAiB,EAAE,OAAgB;QACtC,IAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;QAC/B,IAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAM,OAAO,GAAG;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,gBAAgB,EAAE,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC;aACpD;YACD,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,GAAG,CAAC,QAAQ;YAClB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB,CAAC;QACF,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO;YACzB,IAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,UAAC,GAAG;gBACpC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;gBACxB,IAAI,eAAe,GAAG,EAAE,CAAC;gBACzB,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,UAAC,KAAa;oBAC3B,eAAe,IAAI,KAAK,CAAC;gBAC3B,CAAC,CAAC,CAAC;gBAEH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE;oBACZ,IAAI,GAAG,CAAC,QAAQ,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE;wBAC9C,IAAI;4BACF,mEAAmE;4BACnE,IAAM,qBAAqB,GAAwB,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;4BAC/E,IAAM,MAAM,GAAG,aAAa,CAAC,qBAAqB,CAAC,CAAC;4BACpD,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,aAAa,CAAC,CAAC;YAC/B,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IACH,WAAC;AAAD,CAAC,AAzCD,IAyCC","sourcesContent":["import { Payload, Response, Transport } from '@amplitude/analytics-types';\nimport * as http from 'http';\nimport { buildResponse } from '../utils/response-builder';\n\nexport class Http 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 = buildResponse(parsedResponsePayload);\n resolve(result);\n return;\n } catch {\n resolve(null);\n }\n }\n });\n });\n req.on('error', buildResponse);\n req.end(requestPayload);\n });\n }\n}\n"]}
@@ -1,3 +0,0 @@
1
- import { Response } from '@amplitude/analytics-types';
2
- export declare const buildResponse: (responseJSON: Record<string, any>) => Response | null;
3
- //# sourceMappingURL=response-builder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"response-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/response-builder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAU,MAAM,4BAA4B,CAAC;AAG9D,eAAO,MAAM,aAAa,iBAAkB,OAAO,MAAM,EAAE,GAAG,CAAC,KAAG,QAAQ,GAAG,IAmE5E,CAAC"}
@@ -1,72 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
2
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
- /* eslint-disable @typescript-eslint/no-unsafe-call */
4
- import { Status } from '@amplitude/analytics-types';
5
- import { buildStatus } from './status-builder';
6
- export var buildResponse = function (responseJSON) {
7
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
8
- if (typeof responseJSON !== 'object') {
9
- return null;
10
- }
11
- var statusCode = responseJSON.code || 0;
12
- var status = buildStatus(statusCode);
13
- switch (status) {
14
- case Status.Success:
15
- return {
16
- status: status,
17
- statusCode: statusCode,
18
- body: {
19
- eventsIngested: (_a = responseJSON.events_ingested) !== null && _a !== void 0 ? _a : 0,
20
- payloadSizeBytes: (_b = responseJSON.payload_size_bytes) !== null && _b !== void 0 ? _b : 0,
21
- serverUploadTime: (_c = responseJSON.server_upload_time) !== null && _c !== void 0 ? _c : 0,
22
- },
23
- };
24
- case Status.Invalid:
25
- return {
26
- status: status,
27
- statusCode: statusCode,
28
- body: {
29
- error: (_d = responseJSON.error) !== null && _d !== void 0 ? _d : '',
30
- missingField: (_e = responseJSON.missing_field) !== null && _e !== void 0 ? _e : '',
31
- eventsWithInvalidFields: (_f = responseJSON.events_with_invalid_fields) !== null && _f !== void 0 ? _f : {},
32
- eventsWithMissingFields: (_g = responseJSON.events_with_missing_fields) !== null && _g !== void 0 ? _g : {},
33
- eventsWithInvalidIdLengths: (_h = responseJSON.events_with_invalid_id_lengths) !== null && _h !== void 0 ? _h : {},
34
- epsThreshold: (_j = responseJSON.eps_threshold) !== null && _j !== void 0 ? _j : 0,
35
- exceededDailyQuotaDevices: (_k = responseJSON.exceeded_daily_quota_devices) !== null && _k !== void 0 ? _k : {},
36
- silencedDevices: (_l = responseJSON.silenced_devices) !== null && _l !== void 0 ? _l : [],
37
- silencedEvents: (_m = responseJSON.silenced_events) !== null && _m !== void 0 ? _m : [],
38
- throttledDevices: (_o = responseJSON.throttled_devices) !== null && _o !== void 0 ? _o : {},
39
- throttledEvents: (_p = responseJSON.throttled_events) !== null && _p !== void 0 ? _p : [],
40
- },
41
- };
42
- case Status.PayloadTooLarge:
43
- return {
44
- status: status,
45
- statusCode: statusCode,
46
- body: {
47
- error: (_q = responseJSON.error) !== null && _q !== void 0 ? _q : '',
48
- },
49
- };
50
- case Status.RateLimit:
51
- return {
52
- status: status,
53
- statusCode: statusCode,
54
- body: {
55
- error: (_r = responseJSON.error) !== null && _r !== void 0 ? _r : '',
56
- epsThreshold: (_s = responseJSON.eps_threshold) !== null && _s !== void 0 ? _s : 0,
57
- throttledDevices: (_t = responseJSON.throttled_devices) !== null && _t !== void 0 ? _t : {},
58
- throttledUsers: (_u = responseJSON.throttled_users) !== null && _u !== void 0 ? _u : {},
59
- exceededDailyQuotaDevices: (_v = responseJSON.exceeded_daily_quota_devices) !== null && _v !== void 0 ? _v : {},
60
- exceededDailyQuotaUsers: (_w = responseJSON.exceeded_daily_quota_users) !== null && _w !== void 0 ? _w : {},
61
- throttledEvents: (_x = responseJSON.throttled_events) !== null && _x !== void 0 ? _x : [],
62
- },
63
- };
64
- case Status.Timeout:
65
- default:
66
- return {
67
- status: status,
68
- statusCode: statusCode,
69
- };
70
- }
71
- };
72
- //# sourceMappingURL=response-builder.js.map