@customerio/cdp-analytics-core 0.0.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 (220) hide show
  1. package/LICENSE.MD +22 -0
  2. package/README.md +3 -0
  3. package/dist/cjs/analytics/dispatch.js +54 -0
  4. package/dist/cjs/analytics/dispatch.js.map +1 -0
  5. package/dist/cjs/analytics/index.js +3 -0
  6. package/dist/cjs/analytics/index.js.map +1 -0
  7. package/dist/cjs/callback/index.js +46 -0
  8. package/dist/cjs/callback/index.js.map +1 -0
  9. package/dist/cjs/connection/index.js +16 -0
  10. package/dist/cjs/connection/index.js.map +1 -0
  11. package/dist/cjs/context/index.js +87 -0
  12. package/dist/cjs/context/index.js.map +1 -0
  13. package/dist/cjs/emitter/index.js +66 -0
  14. package/dist/cjs/emitter/index.js.map +1 -0
  15. package/dist/cjs/emitter/interface.js +3 -0
  16. package/dist/cjs/emitter/interface.js.map +1 -0
  17. package/dist/cjs/events/index.js +149 -0
  18. package/dist/cjs/events/index.js.map +1 -0
  19. package/dist/cjs/events/interfaces.js +3 -0
  20. package/dist/cjs/events/interfaces.js.map +1 -0
  21. package/dist/cjs/index.js +25 -0
  22. package/dist/cjs/index.js.map +1 -0
  23. package/dist/cjs/logger/index.js +62 -0
  24. package/dist/cjs/logger/index.js.map +1 -0
  25. package/dist/cjs/plugins/index.js +3 -0
  26. package/dist/cjs/plugins/index.js.map +1 -0
  27. package/dist/cjs/priority-queue/backoff.js +10 -0
  28. package/dist/cjs/priority-queue/backoff.js.map +1 -0
  29. package/dist/cjs/priority-queue/index.js +92 -0
  30. package/dist/cjs/priority-queue/index.js.map +1 -0
  31. package/dist/cjs/queue/delivery.js +69 -0
  32. package/dist/cjs/queue/delivery.js.map +1 -0
  33. package/dist/cjs/queue/event-queue.js +340 -0
  34. package/dist/cjs/queue/event-queue.js.map +1 -0
  35. package/dist/cjs/stats/index.js +96 -0
  36. package/dist/cjs/stats/index.js.map +1 -0
  37. package/dist/cjs/task/task-group.js +24 -0
  38. package/dist/cjs/task/task-group.js.map +1 -0
  39. package/dist/cjs/user/index.js +3 -0
  40. package/dist/cjs/user/index.js.map +1 -0
  41. package/dist/cjs/utils/bind-all.js +18 -0
  42. package/dist/cjs/utils/bind-all.js.map +1 -0
  43. package/dist/cjs/utils/environment.js +12 -0
  44. package/dist/cjs/utils/environment.js.map +1 -0
  45. package/dist/cjs/utils/get-global.js +21 -0
  46. package/dist/cjs/utils/get-global.js.map +1 -0
  47. package/dist/cjs/utils/group-by.js +28 -0
  48. package/dist/cjs/utils/group-by.js.map +1 -0
  49. package/dist/cjs/utils/has-properties.js +13 -0
  50. package/dist/cjs/utils/has-properties.js.map +1 -0
  51. package/dist/cjs/utils/is-plain-object.js +28 -0
  52. package/dist/cjs/utils/is-plain-object.js.map +1 -0
  53. package/dist/cjs/utils/is-thenable.js +15 -0
  54. package/dist/cjs/utils/is-thenable.js.map +1 -0
  55. package/dist/cjs/utils/p-while.js +25 -0
  56. package/dist/cjs/utils/p-while.js.map +1 -0
  57. package/dist/cjs/utils/pick.js +10 -0
  58. package/dist/cjs/utils/pick.js.map +1 -0
  59. package/dist/cjs/utils/ts-helpers.js +3 -0
  60. package/dist/cjs/utils/ts-helpers.js.map +1 -0
  61. package/dist/cjs/validation/assertions.js +41 -0
  62. package/dist/cjs/validation/assertions.js.map +1 -0
  63. package/dist/cjs/validation/helpers.js +26 -0
  64. package/dist/cjs/validation/helpers.js.map +1 -0
  65. package/dist/esm/analytics/dispatch.js +49 -0
  66. package/dist/esm/analytics/dispatch.js.map +1 -0
  67. package/dist/esm/analytics/index.js +2 -0
  68. package/dist/esm/analytics/index.js.map +1 -0
  69. package/dist/esm/callback/index.js +40 -0
  70. package/dist/esm/callback/index.js.map +1 -0
  71. package/dist/esm/connection/index.js +11 -0
  72. package/dist/esm/connection/index.js.map +1 -0
  73. package/dist/esm/context/index.js +84 -0
  74. package/dist/esm/context/index.js.map +1 -0
  75. package/dist/esm/emitter/index.js +63 -0
  76. package/dist/esm/emitter/index.js.map +1 -0
  77. package/dist/esm/emitter/interface.js +2 -0
  78. package/dist/esm/emitter/interface.js.map +1 -0
  79. package/dist/esm/events/index.js +146 -0
  80. package/dist/esm/events/index.js.map +1 -0
  81. package/dist/esm/events/interfaces.js +2 -0
  82. package/dist/esm/events/interfaces.js.map +1 -0
  83. package/dist/esm/index.js +19 -0
  84. package/dist/esm/index.js.map +1 -0
  85. package/dist/esm/logger/index.js +59 -0
  86. package/dist/esm/logger/index.js.map +1 -0
  87. package/dist/esm/plugins/index.js +2 -0
  88. package/dist/esm/plugins/index.js.map +1 -0
  89. package/dist/esm/priority-queue/backoff.js +6 -0
  90. package/dist/esm/priority-queue/backoff.js.map +1 -0
  91. package/dist/esm/priority-queue/index.js +89 -0
  92. package/dist/esm/priority-queue/index.js.map +1 -0
  93. package/dist/esm/queue/delivery.js +64 -0
  94. package/dist/esm/queue/delivery.js.map +1 -0
  95. package/dist/esm/queue/event-queue.js +337 -0
  96. package/dist/esm/queue/event-queue.js.map +1 -0
  97. package/dist/esm/stats/index.js +93 -0
  98. package/dist/esm/stats/index.js.map +1 -0
  99. package/dist/esm/task/task-group.js +20 -0
  100. package/dist/esm/task/task-group.js.map +1 -0
  101. package/dist/esm/user/index.js +2 -0
  102. package/dist/esm/user/index.js.map +1 -0
  103. package/dist/esm/utils/bind-all.js +14 -0
  104. package/dist/esm/utils/bind-all.js.map +1 -0
  105. package/dist/esm/utils/environment.js +7 -0
  106. package/dist/esm/utils/environment.js.map +1 -0
  107. package/dist/esm/utils/get-global.js +17 -0
  108. package/dist/esm/utils/get-global.js.map +1 -0
  109. package/dist/esm/utils/group-by.js +24 -0
  110. package/dist/esm/utils/group-by.js.map +1 -0
  111. package/dist/esm/utils/has-properties.js +9 -0
  112. package/dist/esm/utils/has-properties.js.map +1 -0
  113. package/dist/esm/utils/is-plain-object.js +24 -0
  114. package/dist/esm/utils/is-plain-object.js.map +1 -0
  115. package/dist/esm/utils/is-thenable.js +11 -0
  116. package/dist/esm/utils/is-thenable.js.map +1 -0
  117. package/dist/esm/utils/p-while.js +21 -0
  118. package/dist/esm/utils/p-while.js.map +1 -0
  119. package/dist/esm/utils/pick.js +6 -0
  120. package/dist/esm/utils/pick.js.map +1 -0
  121. package/dist/esm/utils/ts-helpers.js +2 -0
  122. package/dist/esm/utils/ts-helpers.js.map +1 -0
  123. package/dist/esm/validation/assertions.js +37 -0
  124. package/dist/esm/validation/assertions.js.map +1 -0
  125. package/dist/esm/validation/helpers.js +18 -0
  126. package/dist/esm/validation/helpers.js.map +1 -0
  127. package/dist/types/analytics/dispatch.d.ts +20 -0
  128. package/dist/types/analytics/dispatch.d.ts.map +1 -0
  129. package/dist/types/analytics/index.d.ts +12 -0
  130. package/dist/types/analytics/index.d.ts.map +1 -0
  131. package/dist/types/callback/index.d.ts +11 -0
  132. package/dist/types/callback/index.d.ts.map +1 -0
  133. package/dist/types/connection/index.d.ts +3 -0
  134. package/dist/types/connection/index.d.ts.map +1 -0
  135. package/dist/types/context/index.d.ts +44 -0
  136. package/dist/types/context/index.d.ts.map +1 -0
  137. package/dist/types/emitter/index.d.ts +25 -0
  138. package/dist/types/emitter/index.d.ts.map +1 -0
  139. package/dist/types/emitter/interface.d.ts +27 -0
  140. package/dist/types/emitter/interface.d.ts.map +1 -0
  141. package/dist/types/events/index.d.ts +27 -0
  142. package/dist/types/events/index.d.ts.map +1 -0
  143. package/dist/types/events/interfaces.d.ts +373 -0
  144. package/dist/types/events/interfaces.d.ts.map +1 -0
  145. package/dist/types/index.d.ts +19 -0
  146. package/dist/types/index.d.ts.map +1 -0
  147. package/dist/types/logger/index.d.ts +19 -0
  148. package/dist/types/logger/index.d.ts.map +1 -0
  149. package/dist/types/plugins/index.d.ts +25 -0
  150. package/dist/types/plugins/index.d.ts.map +1 -0
  151. package/dist/types/priority-queue/backoff.d.ts +13 -0
  152. package/dist/types/priority-queue/backoff.d.ts.map +1 -0
  153. package/dist/types/priority-queue/index.d.ts +25 -0
  154. package/dist/types/priority-queue/index.d.ts.map +1 -0
  155. package/dist/types/queue/delivery.d.ts +5 -0
  156. package/dist/types/queue/delivery.d.ts.map +1 -0
  157. package/dist/types/queue/event-queue.d.ts +43 -0
  158. package/dist/types/queue/event-queue.d.ts.map +1 -0
  159. package/dist/types/stats/index.d.ts +34 -0
  160. package/dist/types/stats/index.d.ts.map +1 -0
  161. package/dist/types/task/task-group.d.ts +6 -0
  162. package/dist/types/task/task-group.d.ts.map +1 -0
  163. package/dist/types/user/index.d.ts +6 -0
  164. package/dist/types/user/index.d.ts.map +1 -0
  165. package/dist/types/utils/bind-all.d.ts +4 -0
  166. package/dist/types/utils/bind-all.d.ts.map +1 -0
  167. package/dist/types/utils/environment.d.ts +3 -0
  168. package/dist/types/utils/environment.d.ts.map +1 -0
  169. package/dist/types/utils/get-global.d.ts +2 -0
  170. package/dist/types/utils/get-global.d.ts.map +1 -0
  171. package/dist/types/utils/group-by.d.ts +4 -0
  172. package/dist/types/utils/group-by.d.ts.map +1 -0
  173. package/dist/types/utils/has-properties.d.ts +4 -0
  174. package/dist/types/utils/has-properties.d.ts.map +1 -0
  175. package/dist/types/utils/is-plain-object.d.ts +2 -0
  176. package/dist/types/utils/is-plain-object.d.ts.map +1 -0
  177. package/dist/types/utils/is-thenable.d.ts +6 -0
  178. package/dist/types/utils/is-thenable.d.ts.map +1 -0
  179. package/dist/types/utils/p-while.d.ts +2 -0
  180. package/dist/types/utils/p-while.d.ts.map +1 -0
  181. package/dist/types/utils/pick.d.ts +2 -0
  182. package/dist/types/utils/pick.d.ts.map +1 -0
  183. package/dist/types/utils/ts-helpers.d.ts +13 -0
  184. package/dist/types/utils/ts-helpers.d.ts.map +1 -0
  185. package/dist/types/validation/assertions.d.ts +7 -0
  186. package/dist/types/validation/assertions.d.ts.map +1 -0
  187. package/dist/types/validation/helpers.d.ts +7 -0
  188. package/dist/types/validation/helpers.d.ts.map +1 -0
  189. package/package.json +39 -0
  190. package/src/analytics/dispatch.ts +58 -0
  191. package/src/analytics/index.ts +11 -0
  192. package/src/callback/index.ts +51 -0
  193. package/src/connection/index.ts +13 -0
  194. package/src/context/index.ts +123 -0
  195. package/src/emitter/index.ts +65 -0
  196. package/src/emitter/interface.ts +31 -0
  197. package/src/events/index.ts +280 -0
  198. package/src/events/interfaces.ts +447 -0
  199. package/src/index.ts +18 -0
  200. package/src/logger/index.ts +74 -0
  201. package/src/plugins/index.ts +43 -0
  202. package/src/priority-queue/backoff.ts +24 -0
  203. package/src/priority-queue/index.ts +103 -0
  204. package/src/queue/delivery.ts +73 -0
  205. package/src/queue/event-queue.ts +320 -0
  206. package/src/stats/index.ts +88 -0
  207. package/src/task/task-group.ts +31 -0
  208. package/src/user/index.ts +7 -0
  209. package/src/utils/bind-all.ts +19 -0
  210. package/src/utils/environment.ts +7 -0
  211. package/src/utils/get-global.ts +16 -0
  212. package/src/utils/group-by.ts +30 -0
  213. package/src/utils/has-properties.ts +7 -0
  214. package/src/utils/is-plain-object.ts +26 -0
  215. package/src/utils/is-thenable.ts +9 -0
  216. package/src/utils/p-while.ts +12 -0
  217. package/src/utils/pick.ts +8 -0
  218. package/src/utils/ts-helpers.ts +13 -0
  219. package/src/validation/assertions.ts +43 -0
  220. package/src/validation/helpers.ts +27 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/user/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bindAll = void 0;
4
+ function bindAll(obj) {
5
+ var proto = obj.constructor.prototype;
6
+ for (var _i = 0, _a = Object.getOwnPropertyNames(proto); _i < _a.length; _i++) {
7
+ var key = _a[_i];
8
+ if (key !== 'constructor') {
9
+ var desc = Object.getOwnPropertyDescriptor(obj.constructor.prototype, key);
10
+ if (!!desc && typeof desc.value === 'function') {
11
+ obj[key] = obj[key].bind(obj);
12
+ }
13
+ }
14
+ }
15
+ return obj;
16
+ }
17
+ exports.bindAll = bindAll;
18
+ //# sourceMappingURL=bind-all.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bind-all.js","sourceRoot":"","sources":["../../../src/utils/bind-all.ts"],"names":[],"mappings":";;;AAAA,SAAgB,OAAO,CAGrB,GAAY;IACZ,IAAM,KAAK,GAAG,GAAG,CAAC,WAAW,CAAC,SAAS,CAAA;IACvC,KAAkB,UAAiC,EAAjC,KAAA,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAjC,cAAiC,EAAjC,IAAiC,EAAE;QAAhD,IAAM,GAAG,SAAA;QACZ,IAAI,GAAG,KAAK,aAAa,EAAE;YACzB,IAAM,IAAI,GAAG,MAAM,CAAC,wBAAwB,CAC1C,GAAG,CAAC,WAAW,CAAC,SAAS,EACzB,GAAG,CACJ,CAAA;YACD,IAAI,CAAC,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,UAAU,EAAE;gBAC9C,GAAG,CAAC,GAAc,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;aACzC;SACF;KACF;IAED,OAAO,GAAG,CAAA;AACZ,CAAC;AAlBD,0BAkBC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isServer = exports.isBrowser = void 0;
4
+ function isBrowser() {
5
+ return typeof window !== 'undefined';
6
+ }
7
+ exports.isBrowser = isBrowser;
8
+ function isServer() {
9
+ return !isBrowser();
10
+ }
11
+ exports.isServer = isServer;
12
+ //# sourceMappingURL=environment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.js","sourceRoot":"","sources":["../../../src/utils/environment.ts"],"names":[],"mappings":";;;AAAA,SAAgB,SAAS;IACvB,OAAO,OAAO,MAAM,KAAK,WAAW,CAAA;AACtC,CAAC;AAFD,8BAEC;AAED,SAAgB,QAAQ;IACtB,OAAO,CAAC,SAAS,EAAE,CAAA;AACrB,CAAC;AAFD,4BAEC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGlobal = void 0;
4
+ // This an imperfect polyfill for globalThis
5
+ var getGlobal = function () {
6
+ if (typeof globalThis !== 'undefined') {
7
+ return globalThis;
8
+ }
9
+ if (typeof self !== 'undefined') {
10
+ return self;
11
+ }
12
+ if (typeof window !== 'undefined') {
13
+ return window;
14
+ }
15
+ if (typeof global !== 'undefined') {
16
+ return global;
17
+ }
18
+ return null;
19
+ };
20
+ exports.getGlobal = getGlobal;
21
+ //# sourceMappingURL=get-global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-global.js","sourceRoot":"","sources":["../../../src/utils/get-global.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AACrC,IAAM,SAAS,GAAG;IACvB,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE;QACrC,OAAO,UAAU,CAAA;KAClB;IACD,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC/B,OAAO,IAAI,CAAA;KACZ;IACD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,MAAM,CAAA;KACd;IACD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,MAAM,CAAA;KACd;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAdY,QAAA,SAAS,aAcrB"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.groupBy = void 0;
4
+ var tslib_1 = require("tslib");
5
+ function groupBy(collection, grouper) {
6
+ var results = {};
7
+ collection.forEach(function (item) {
8
+ var _a;
9
+ var key = undefined;
10
+ if (typeof grouper === 'string') {
11
+ var suggestedKey = item[grouper];
12
+ key =
13
+ typeof suggestedKey !== 'string'
14
+ ? JSON.stringify(suggestedKey)
15
+ : suggestedKey;
16
+ }
17
+ else if (grouper instanceof Function) {
18
+ key = grouper(item);
19
+ }
20
+ if (key === undefined) {
21
+ return;
22
+ }
23
+ results[key] = tslib_1.__spreadArray(tslib_1.__spreadArray([], ((_a = results[key]) !== null && _a !== void 0 ? _a : []), true), [item], false);
24
+ });
25
+ return results;
26
+ }
27
+ exports.groupBy = groupBy;
28
+ //# sourceMappingURL=group-by.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-by.js","sourceRoot":"","sources":["../../../src/utils/group-by.ts"],"names":[],"mappings":";;;;AAEA,SAAgB,OAAO,CACrB,UAAe,EACf,OAA6B;IAE7B,IAAM,OAAO,GAAwB,EAAE,CAAA;IAEvC,UAAU,CAAC,OAAO,CAAC,UAAC,IAAI;;QACtB,IAAI,GAAG,GAAgC,SAAS,CAAA;QAEhD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,IAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,CAAA;YAClC,GAAG;gBACD,OAAO,YAAY,KAAK,QAAQ;oBAC9B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;oBAC9B,CAAC,CAAC,YAAY,CAAA;SACnB;aAAM,IAAI,OAAO,YAAY,QAAQ,EAAE;YACtC,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;SACpB;QAED,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,OAAM;SACP;QAED,OAAO,CAAC,GAAG,CAAC,mDAAO,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,mCAAI,EAAE,CAAC,UAAE,IAAI,SAAC,CAAA;IAChD,CAAC,CAAC,CAAA;IAEF,OAAO,OAAO,CAAA;AAChB,CAAC;AA3BD,0BA2BC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasProperties = void 0;
4
+ function hasProperties(obj) {
5
+ var keys = [];
6
+ for (var _i = 1; _i < arguments.length; _i++) {
7
+ keys[_i - 1] = arguments[_i];
8
+ }
9
+ // eslint-disable-next-line no-prototype-builtins
10
+ return !!obj && keys.every(function (key) { return obj.hasOwnProperty(key); });
11
+ }
12
+ exports.hasProperties = hasProperties;
13
+ //# sourceMappingURL=has-properties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-properties.js","sourceRoot":"","sources":["../../../src/utils/has-properties.ts"],"names":[],"mappings":";;;AAAA,SAAgB,aAAa,CAC3B,GAAM;IACN,cAAY;SAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;QAAZ,6BAAY;;IAEZ,iDAAiD;IACjD,OAAO,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,EAAvB,CAAuB,CAAC,CAAA;AAC9D,CAAC;AAND,sCAMC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ // Code derived from https://github.com/jonschlinkert/is-plain-object/blob/master/is-plain-object.js
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.isPlainObject = void 0;
5
+ function isObject(o) {
6
+ return Object.prototype.toString.call(o) === '[object Object]';
7
+ }
8
+ function isPlainObject(o) {
9
+ if (isObject(o) === false)
10
+ return false;
11
+ // If has modified constructor
12
+ var ctor = o.constructor;
13
+ if (ctor === undefined)
14
+ return true;
15
+ // If has modified prototype
16
+ var prot = ctor.prototype;
17
+ if (isObject(prot) === false)
18
+ return false;
19
+ // If constructor does not have an Object-specific method
20
+ // eslint-disable-next-line no-prototype-builtins
21
+ if (prot.hasOwnProperty('isPrototypeOf') === false) {
22
+ return false;
23
+ }
24
+ // Most likely a plain Object
25
+ return true;
26
+ }
27
+ exports.isPlainObject = isPlainObject;
28
+ //# sourceMappingURL=is-plain-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-plain-object.js","sourceRoot":"","sources":["../../../src/utils/is-plain-object.ts"],"names":[],"mappings":";AAAA,oGAAoG;;;AAEpG,SAAS,QAAQ,CAAC,CAAU;IAC1B,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAA;AAChE,CAAC;AAED,SAAgB,aAAa,CAAC,CAAU;IACtC,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,KAAK;QAAE,OAAO,KAAK,CAAA;IAEvC,8BAA8B;IAC9B,IAAM,IAAI,GAAI,CAAS,CAAC,WAAW,CAAA;IACnC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,IAAI,CAAA;IAEnC,4BAA4B;IAC5B,IAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAA;IAC3B,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,KAAK;QAAE,OAAO,KAAK,CAAA;IAE1C,yDAAyD;IACzD,iDAAiD;IACjD,IAAK,IAAe,CAAC,cAAc,CAAC,eAAe,CAAC,KAAK,KAAK,EAAE;QAC9D,OAAO,KAAK,CAAA;KACb;IAED,6BAA6B;IAC7B,OAAO,IAAI,CAAA;AACb,CAAC;AAnBD,sCAmBC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isThenable = void 0;
4
+ /**
5
+ * Check if thenable
6
+ * (instanceof Promise doesn't respect realms)
7
+ */
8
+ var isThenable = function (value) {
9
+ return typeof value === 'object' &&
10
+ value !== null &&
11
+ 'then' in value &&
12
+ typeof value.then === 'function';
13
+ };
14
+ exports.isThenable = isThenable;
15
+ //# sourceMappingURL=is-thenable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-thenable.js","sourceRoot":"","sources":["../../../src/utils/is-thenable.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,IAAM,UAAU,GAAG,UAAC,KAAc;IACvC,OAAA,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAQ,KAAa,CAAC,IAAI,KAAK,UAAU;AAHzC,CAGyC,CAAA;AAJ9B,QAAA,UAAU,cAIoB"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pWhile = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var pWhile = function (condition, action) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
6
+ var loop;
7
+ return tslib_1.__generator(this, function (_a) {
8
+ loop = function (actionResult) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
9
+ var _a;
10
+ return tslib_1.__generator(this, function (_b) {
11
+ switch (_b.label) {
12
+ case 0:
13
+ if (!condition(actionResult)) return [3 /*break*/, 2];
14
+ _a = loop;
15
+ return [4 /*yield*/, action()];
16
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
17
+ case 2: return [2 /*return*/];
18
+ }
19
+ });
20
+ }); };
21
+ return [2 /*return*/, loop(undefined)];
22
+ });
23
+ }); };
24
+ exports.pWhile = pWhile;
25
+ //# sourceMappingURL=p-while.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"p-while.js","sourceRoot":"","sources":["../../../src/utils/p-while.ts"],"names":[],"mappings":";;;;AAAO,IAAM,MAAM,GAAG,UACpB,SAA4C,EAC5C,MAAgC;;;QAE1B,IAAI,GAAG,UAAO,YAA2B;;;;;6BACzC,SAAS,CAAC,YAAY,CAAC,EAAvB,wBAAuB;wBAClB,KAAA,IAAI,CAAA;wBAAC,qBAAM,MAAM,EAAE,EAAA;4BAA1B,sBAAO,kBAAK,SAAc,EAAC,EAAA;;;;aAE9B,CAAA;QAED,sBAAO,IAAI,CAAC,SAAS,CAAC,EAAA;;KACvB,CAAA;AAXY,QAAA,MAAM,UAWlB"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pickBy = void 0;
4
+ var pickBy = function (obj, fn) {
5
+ return Object.keys(obj)
6
+ .filter(function (k) { return fn(k, obj[k]); })
7
+ .reduce(function (acc, key) { return ((acc[key] = obj[key]), acc); }, {});
8
+ };
9
+ exports.pickBy = pickBy;
10
+ //# sourceMappingURL=pick.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pick.js","sourceRoot":"","sources":["../../../src/utils/pick.ts"],"names":[],"mappings":";;;AAAO,IAAM,MAAM,GAAG,UACpB,GAAM,EACN,EAAgC;IAEhC,OAAQ,MAAM,CAAC,IAAI,CAAC,GAAG,CAAS;SAC7B,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAb,CAAa,CAAC;SAC5B,MAAM,CAAC,UAAC,GAAG,EAAE,GAAG,IAAK,OAAA,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,EAA5B,CAA4B,EAAE,EAAgB,CAAC,CAAA;AACzE,CAAC,CAAA;AAPY,QAAA,MAAM,UAOlB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ts-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-helpers.js","sourceRoot":"","sources":["../../../src/utils/ts-helpers.ts"],"names":[],"mappings":""}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateEvent = exports.ValidationError = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var helpers_1 = require("./helpers");
6
+ var ValidationError = /** @class */ (function (_super) {
7
+ tslib_1.__extends(ValidationError, _super);
8
+ function ValidationError(field, message) {
9
+ var _this = _super.call(this, message) || this;
10
+ _this.field = field;
11
+ return _this;
12
+ }
13
+ return ValidationError;
14
+ }(Error));
15
+ exports.ValidationError = ValidationError;
16
+ function validateEvent(event) {
17
+ if (!event || typeof event !== 'object') {
18
+ throw new ValidationError('event', 'Event is missing');
19
+ }
20
+ if (!(0, helpers_1.isString)(event.type)) {
21
+ throw new ValidationError('type', 'type is not a string');
22
+ }
23
+ if (event.type === 'track') {
24
+ if (!(0, helpers_1.isString)(event.event)) {
25
+ throw new ValidationError('event', 'Event is not a string');
26
+ }
27
+ if (!(0, helpers_1.isPlainObject)(event.properties)) {
28
+ throw new ValidationError('properties', 'properties is not an object');
29
+ }
30
+ }
31
+ if (['group', 'identify'].includes(event.type)) {
32
+ if (!(0, helpers_1.isPlainObject)(event.traits)) {
33
+ throw new ValidationError('traits', 'traits is not an object');
34
+ }
35
+ }
36
+ if (!(0, helpers_1.hasUser)(event)) {
37
+ throw new ValidationError('userId/anonymousId/previousId/groupId', 'Must have userId or anonymousId or previousId or groupId');
38
+ }
39
+ }
40
+ exports.validateEvent = validateEvent;
41
+ //# sourceMappingURL=assertions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertions.js","sourceRoot":"","sources":["../../../src/validation/assertions.ts"],"names":[],"mappings":";;;;AACA,qCAA4D;AAE5D;IAAqC,2CAAK;IAGxC,yBAAY,KAAa,EAAE,OAAe;QAA1C,YACE,kBAAM,OAAO,CAAC,SAEf;QADC,KAAI,CAAC,KAAK,GAAG,KAAK,CAAA;;IACpB,CAAC;IACH,sBAAC;AAAD,CAAC,AAPD,CAAqC,KAAK,GAOzC;AAPY,0CAAe;AAS5B,SAAgB,aAAa,CAAC,KAAkC;IAC9D,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACvC,MAAM,IAAI,eAAe,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAA;KACvD;IAED,IAAI,CAAC,IAAA,kBAAQ,EAAC,KAAK,CAAC,IAAI,CAAC,EAAE;QACzB,MAAM,IAAI,eAAe,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAA;KAC1D;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE;QAC1B,IAAI,CAAC,IAAA,kBAAQ,EAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YAC1B,MAAM,IAAI,eAAe,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAA;SAC5D;QACD,IAAI,CAAC,IAAA,uBAAa,EAAC,KAAK,CAAC,UAAU,CAAC,EAAE;YACpC,MAAM,IAAI,eAAe,CAAC,YAAY,EAAE,6BAA6B,CAAC,CAAA;SACvE;KACF;IAED,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;QAC9C,IAAI,CAAC,IAAA,uBAAa,EAAC,KAAK,CAAC,MAAM,CAAC,EAAE;YAChC,MAAM,IAAI,eAAe,CAAC,QAAQ,EAAE,yBAAyB,CAAC,CAAA;SAC/D;KACF;IAED,IAAI,CAAC,IAAA,iBAAO,EAAC,KAAK,CAAC,EAAE;QACnB,MAAM,IAAI,eAAe,CACvB,uCAAuC,EACvC,0DAA0D,CAC3D,CAAA;KACF;AACH,CAAC;AA9BD,sCA8BC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasUser = exports.isPlainObject = exports.isFunction = exports.isNumber = exports.isString = void 0;
4
+ function isString(obj) {
5
+ return typeof obj === 'string';
6
+ }
7
+ exports.isString = isString;
8
+ function isNumber(obj) {
9
+ return typeof obj === 'number';
10
+ }
11
+ exports.isNumber = isNumber;
12
+ function isFunction(obj) {
13
+ return typeof obj === 'function';
14
+ }
15
+ exports.isFunction = isFunction;
16
+ function isPlainObject(obj) {
17
+ return (Object.prototype.toString.call(obj).slice(8, -1).toLowerCase() === 'object');
18
+ }
19
+ exports.isPlainObject = isPlainObject;
20
+ function hasUser(event) {
21
+ var _a, _b, _c;
22
+ var id = (_c = (_b = (_a = event.userId) !== null && _a !== void 0 ? _a : event.anonymousId) !== null && _b !== void 0 ? _b : event.groupId) !== null && _c !== void 0 ? _c : event.previousId;
23
+ return isString(id);
24
+ }
25
+ exports.hasUser = hasUser;
26
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/validation/helpers.ts"],"names":[],"mappings":";;;AAEA,SAAgB,QAAQ,CAAC,GAAY;IACnC,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAA;AAChC,CAAC;AAFD,4BAEC;AAED,SAAgB,QAAQ,CAAC,GAAY;IACnC,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAA;AAChC,CAAC;AAFD,4BAEC;AAED,SAAgB,UAAU,CAAC,GAAY;IACrC,OAAO,OAAO,GAAG,KAAK,UAAU,CAAA;AAClC,CAAC;AAFD,gCAEC;AAED,SAAgB,aAAa,CAC3B,GAAY;IAEZ,OAAO,CACL,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,QAAQ,CAC5E,CAAA;AACH,CAAC;AAND,sCAMC;AAED,SAAgB,OAAO,CAAC,KAA0B;;IAChD,IAAM,EAAE,GACN,MAAA,MAAA,MAAA,KAAK,CAAC,MAAM,mCAAI,KAAK,CAAC,WAAW,mCAAI,KAAK,CAAC,OAAO,mCAAI,KAAK,CAAC,UAAU,CAAA;IACxE,OAAO,QAAQ,CAAC,EAAE,CAAC,CAAA;AACrB,CAAC;AAJD,0BAIC"}
@@ -0,0 +1,49 @@
1
+ import { __awaiter, __generator } from "tslib";
2
+ import { invokeCallback } from '../callback';
3
+ /* The amount of time in ms to wait before invoking the callback. */
4
+ export var getDelay = function (startTimeInEpochMS, timeoutInMS) {
5
+ var elapsedTime = Date.now() - startTimeInEpochMS;
6
+ // increasing the timeout increases the delay by almost the same amount -- this is weird legacy behavior.
7
+ return Math.max((timeoutInMS !== null && timeoutInMS !== void 0 ? timeoutInMS : 300) - elapsedTime, 0);
8
+ };
9
+ /**
10
+ * Push an event into the dispatch queue and invoke any callbacks.
11
+ *
12
+ * @param event - Event to enqueue.
13
+ * @param queue - Queue to dispatch against.
14
+ * @param emitter - This is typically an instance of "Analytics" -- used for metrics / progress information.
15
+ * @param options
16
+ */
17
+ export function dispatch(ctx, queue, emitter, options) {
18
+ return __awaiter(this, void 0, void 0, function () {
19
+ var startTime, dispatched;
20
+ return __generator(this, function (_a) {
21
+ switch (_a.label) {
22
+ case 0:
23
+ emitter.emit('dispatch_start', ctx);
24
+ startTime = Date.now();
25
+ if (!queue.isEmpty()) return [3 /*break*/, 2];
26
+ return [4 /*yield*/, queue.dispatchSingle(ctx)];
27
+ case 1:
28
+ dispatched = _a.sent();
29
+ return [3 /*break*/, 4];
30
+ case 2: return [4 /*yield*/, queue.dispatch(ctx)];
31
+ case 3:
32
+ dispatched = _a.sent();
33
+ _a.label = 4;
34
+ case 4:
35
+ if (!(options === null || options === void 0 ? void 0 : options.callback)) return [3 /*break*/, 6];
36
+ return [4 /*yield*/, invokeCallback(dispatched, options.callback, getDelay(startTime, options.timeout))];
37
+ case 5:
38
+ dispatched = _a.sent();
39
+ _a.label = 6;
40
+ case 6:
41
+ if (options === null || options === void 0 ? void 0 : options.debug) {
42
+ dispatched.flush();
43
+ }
44
+ return [2 /*return*/, dispatched];
45
+ }
46
+ });
47
+ });
48
+ }
49
+ //# sourceMappingURL=dispatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../../src/analytics/dispatch.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAS5C,oEAAoE;AACpE,MAAM,CAAC,IAAM,QAAQ,GAAG,UAAC,kBAA0B,EAAE,WAAoB;IACvE,IAAM,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,kBAAkB,CAAA;IACnD,yGAAyG;IACzG,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,GAAG,CAAC,GAAG,WAAW,EAAE,CAAC,CAAC,CAAA;AACxD,CAAC,CAAA;AACD;;;;;;;GAOG;AACH,MAAM,UAAgB,QAAQ,CAI5B,GAAQ,EACR,KAAS,EACT,OAAgB,EAChB,OAA8B;;;;;;oBAE9B,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAA;oBAE7B,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;yBAExB,KAAK,CAAC,OAAO,EAAE,EAAf,wBAAe;oBACJ,qBAAM,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAA;;oBAA5C,UAAU,GAAG,SAA+B,CAAA;;wBAE/B,qBAAM,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAA;;oBAAtC,UAAU,GAAG,SAAyB,CAAA;;;yBAGpC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,CAAA,EAAjB,wBAAiB;oBACN,qBAAM,cAAc,CAC/B,UAAU,EACV,OAAO,CAAC,QAAQ,EAChB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CACrC,EAAA;;oBAJD,UAAU,GAAG,SAIZ,CAAA;;;oBAEH,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,EAAE;wBAClB,UAAU,CAAC,KAAK,EAAE,CAAA;qBACnB;oBAED,sBAAO,UAAU,EAAA;;;;CAClB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/analytics/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,40 @@
1
+ export function pTimeout(promise, timeout) {
2
+ return new Promise(function (resolve, reject) {
3
+ var timeoutId = setTimeout(function () {
4
+ reject(Error('Promise timed out'));
5
+ }, timeout);
6
+ promise
7
+ .then(function (val) {
8
+ clearTimeout(timeoutId);
9
+ return resolve(val);
10
+ })
11
+ .catch(reject);
12
+ });
13
+ }
14
+ export function sleep(timeoutInMs) {
15
+ return new Promise(function (resolve) { return setTimeout(resolve, timeoutInMs); });
16
+ }
17
+ /**
18
+ * @param ctx
19
+ * @param callback - the function to invoke
20
+ * @param delay - aka "timeout". The amount of time in ms to wait before invoking the callback.
21
+ */
22
+ export function invokeCallback(ctx, callback, delay) {
23
+ var cb = function () {
24
+ try {
25
+ return Promise.resolve(callback(ctx));
26
+ }
27
+ catch (err) {
28
+ return Promise.reject(err);
29
+ }
30
+ };
31
+ return (sleep(delay)
32
+ // pTimeout ensures that the callback can't cause the context to hang
33
+ .then(function () { return pTimeout(cb(), 1000); })
34
+ .catch(function (err) {
35
+ ctx === null || ctx === void 0 ? void 0 : ctx.log('warn', 'Callback Error', { error: err });
36
+ ctx === null || ctx === void 0 ? void 0 : ctx.stats.increment('callback_error');
37
+ })
38
+ .then(function () { return ctx; }));
39
+ }
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/callback/index.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,QAAQ,CAAI,OAAmB,EAAE,OAAe;IAC9D,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACjC,IAAM,SAAS,GAAG,UAAU,CAAC;YAC3B,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAA;QACpC,CAAC,EAAE,OAAO,CAAC,CAAA;QAEX,OAAO;aACJ,IAAI,CAAC,UAAC,GAAG;YACR,YAAY,CAAC,SAAS,CAAC,CAAA;YACvB,OAAO,OAAO,CAAC,GAAG,CAAC,CAAA;QACrB,CAAC,CAAC;aACD,KAAK,CAAC,MAAM,CAAC,CAAA;IAClB,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,WAAmB;IACvC,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,IAAK,OAAA,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC,EAAhC,CAAgC,CAAC,CAAA;AACnE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,GAAQ,EACR,QAAuB,EACvB,KAAa;IAEb,IAAM,EAAE,GAAG;QACT,IAAI;YACF,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;SACtC;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;SAC3B;IACH,CAAC,CAAA;IAED,OAAO,CACL,KAAK,CAAC,KAAK,CAAC;QACV,qEAAqE;SACpE,IAAI,CAAC,cAAM,OAAA,QAAQ,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAApB,CAAoB,CAAC;SAChC,KAAK,CAAC,UAAC,GAAG;QACT,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;QAClD,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAA;IACxC,CAAC,CAAC;SACD,IAAI,CAAC,cAAM,OAAA,GAAG,EAAH,CAAG,CAAC,CACnB,CAAA;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { isBrowser } from '../utils/environment';
2
+ export function isOnline() {
3
+ if (isBrowser()) {
4
+ return window.navigator.onLine;
5
+ }
6
+ return true;
7
+ }
8
+ export function isOffline() {
9
+ return !isOnline();
10
+ }
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAEhD,MAAM,UAAU,QAAQ;IACtB,IAAI,SAAS,EAAE,EAAE;QACf,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,CAAA;KAC/B;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,OAAO,CAAC,QAAQ,EAAE,CAAA;AACpB,CAAC"}
@@ -0,0 +1,84 @@
1
+ import { v4 as uuid } from '@lukeed/uuid';
2
+ import { dset } from 'dset';
3
+ import { CoreLogger } from '../logger';
4
+ import { NullStats } from '../stats';
5
+ var ContextCancelation = /** @class */ (function () {
6
+ function ContextCancelation(options) {
7
+ var _a, _b, _c;
8
+ this.retry = (_a = options.retry) !== null && _a !== void 0 ? _a : true;
9
+ this.type = (_b = options.type) !== null && _b !== void 0 ? _b : 'plugin Error';
10
+ this.reason = (_c = options.reason) !== null && _c !== void 0 ? _c : '';
11
+ }
12
+ return ContextCancelation;
13
+ }());
14
+ export { ContextCancelation };
15
+ var CoreContext = /** @class */ (function () {
16
+ function CoreContext(event, id, stats, logger) {
17
+ if (id === void 0) { id = uuid(); }
18
+ if (stats === void 0) { stats = new NullStats(); }
19
+ if (logger === void 0) { logger = new CoreLogger(); }
20
+ this.attempts = 0;
21
+ this.event = event;
22
+ this._id = id;
23
+ this.logger = logger;
24
+ this.stats = stats;
25
+ }
26
+ CoreContext.system = function () {
27
+ // This should be overridden by the subclass to return an instance of the subclass.
28
+ };
29
+ CoreContext.prototype.isSame = function (other) {
30
+ return other.id === this.id;
31
+ };
32
+ CoreContext.prototype.cancel = function (error) {
33
+ if (error) {
34
+ throw error;
35
+ }
36
+ throw new ContextCancelation({ reason: 'Context Cancel' });
37
+ };
38
+ CoreContext.prototype.log = function (level, message, extras) {
39
+ this.logger.log(level, message, extras);
40
+ };
41
+ Object.defineProperty(CoreContext.prototype, "id", {
42
+ get: function () {
43
+ return this._id;
44
+ },
45
+ enumerable: false,
46
+ configurable: true
47
+ });
48
+ CoreContext.prototype.updateEvent = function (path, val) {
49
+ var _a;
50
+ // Don't allow integrations that are set to false to be overwritten with integration settings.
51
+ if (path.split('.')[0] === 'integrations') {
52
+ var integrationName = path.split('.')[1];
53
+ if (((_a = this.event.integrations) === null || _a === void 0 ? void 0 : _a[integrationName]) === false) {
54
+ return this.event;
55
+ }
56
+ }
57
+ dset(this.event, path, val);
58
+ return this.event;
59
+ };
60
+ CoreContext.prototype.failedDelivery = function () {
61
+ return this._failedDelivery;
62
+ };
63
+ CoreContext.prototype.setFailedDelivery = function (options) {
64
+ this._failedDelivery = options;
65
+ };
66
+ CoreContext.prototype.logs = function () {
67
+ return this.logger.logs;
68
+ };
69
+ CoreContext.prototype.flush = function () {
70
+ this.logger.flush();
71
+ this.stats.flush();
72
+ };
73
+ CoreContext.prototype.toJSON = function () {
74
+ return {
75
+ id: this._id,
76
+ event: this.event,
77
+ logs: this.logger.logs,
78
+ metrics: this.stats.metrics,
79
+ };
80
+ };
81
+ return CoreContext;
82
+ }());
83
+ export { CoreContext };
84
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/context/index.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Event Emitter that takes the expected contract as a generic
3
+ * @example
4
+ * ```ts
5
+ * type Contract = {
6
+ * delivery_success: [DeliverySuccessResponse, Metrics],
7
+ * delivery_failure: [DeliveryError]
8
+ * }
9
+ * new Emitter<Contract>()
10
+ * .on('delivery_success', (res, metrics) => ...)
11
+ * .on('delivery_failure', (err) => ...)
12
+ * ```
13
+ */
14
+ var Emitter = /** @class */ (function () {
15
+ function Emitter() {
16
+ this.callbacks = {};
17
+ }
18
+ Emitter.prototype.on = function (event, callback) {
19
+ if (!this.callbacks[event]) {
20
+ this.callbacks[event] = [callback];
21
+ }
22
+ else {
23
+ this.callbacks[event].push(callback);
24
+ }
25
+ return this;
26
+ };
27
+ Emitter.prototype.once = function (event, callback) {
28
+ var _this = this;
29
+ var on = function () {
30
+ var args = [];
31
+ for (var _i = 0; _i < arguments.length; _i++) {
32
+ args[_i] = arguments[_i];
33
+ }
34
+ _this.off(event, on);
35
+ callback.apply(_this, args);
36
+ };
37
+ this.on(event, on);
38
+ return this;
39
+ };
40
+ Emitter.prototype.off = function (event, callback) {
41
+ var _a;
42
+ var fns = (_a = this.callbacks[event]) !== null && _a !== void 0 ? _a : [];
43
+ var without = fns.filter(function (fn) { return fn !== callback; });
44
+ this.callbacks[event] = without;
45
+ return this;
46
+ };
47
+ Emitter.prototype.emit = function (event) {
48
+ var _this = this;
49
+ var _a;
50
+ var args = [];
51
+ for (var _i = 1; _i < arguments.length; _i++) {
52
+ args[_i - 1] = arguments[_i];
53
+ }
54
+ var callbacks = (_a = this.callbacks[event]) !== null && _a !== void 0 ? _a : [];
55
+ callbacks.forEach(function (callback) {
56
+ callback.apply(_this, args);
57
+ });
58
+ return this;
59
+ };
60
+ return Emitter;
61
+ }());
62
+ export { Emitter };
63
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/emitter/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH;IAAA;QACU,cAAS,GAAsB,EAAE,CAAA;IA8C3C,CAAC;IA7CC,oBAAE,GAAF,UACE,KAAgB,EAChB,QAAgD;QAEhD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;YAC1B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAwB,CAAA;SAC1D;aAAM;YACL,IAAI,CAAC,SAAS,CAAC,KAAK,CAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;SACtC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,sBAAI,GAAJ,UACE,KAAgB,EAChB,QAAgD;QAFlD,iBAWC;QAPC,IAAM,EAAE,GAAG;YAAC,cAA4B;iBAA5B,UAA4B,EAA5B,qBAA4B,EAA5B,IAA4B;gBAA5B,yBAA4B;;YACtC,KAAI,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;YACnB,QAAQ,CAAC,KAAK,CAAC,KAAI,EAAE,IAAI,CAAC,CAAA;QAC5B,CAAC,CAAA;QAED,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QAClB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,qBAAG,GAAH,UACE,KAAgB,EAChB,QAAgD;;QAEhD,IAAM,GAAG,GAAG,MAAA,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,mCAAI,EAAE,CAAA;QACvC,IAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,UAAC,EAAE,IAAK,OAAA,EAAE,KAAK,QAAQ,EAAf,CAAe,CAAwB,CAAA;QAC1E,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,OAAO,CAAA;QAC/B,OAAO,IAAI,CAAA;IACb,CAAC;IAED,sBAAI,GAAJ,UACE,KAAgB;QADlB,iBASC;;QAPC,cAA4B;aAA5B,UAA4B,EAA5B,qBAA4B,EAA5B,IAA4B;YAA5B,6BAA4B;;QAE5B,IAAM,SAAS,GAAG,MAAA,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,mCAAI,EAAE,CAAA;QAC7C,SAAS,CAAC,OAAO,CAAC,UAAC,QAAQ;YACzB,QAAQ,CAAC,KAAK,CAAC,KAAI,EAAE,IAAI,CAAC,CAAA;QAC5B,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IACH,cAAC;AAAD,CAAC,AA/CD,IA+CC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../src/emitter/interface.ts"],"names":[],"mappings":""}