@xylabs/pixel 2.0.5 → 4.6.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 (73) hide show
  1. package/.eslintcache +1 -0
  2. package/dist/browser/index.mjs +17 -44
  3. package/dist/browser/index.mjs.map +1 -1
  4. package/dist/{browser → types}/Api/Api.d.ts +1 -1
  5. package/dist/{browser → types}/Api/UserEvent.d.ts +2 -2
  6. package/dist/types/Api/index.d.ts +4 -0
  7. package/dist/types/FunnelStartedFields.d.ts +5 -0
  8. package/dist/{browser → types}/Pixel.d.ts +3 -3
  9. package/dist/{browser → types}/PurchaseFields.d.ts +1 -1
  10. package/dist/types/TestStartedFields.d.ts +5 -0
  11. package/dist/types/UserClickFields.d.ts +8 -0
  12. package/dist/{browser → types}/UserClickFields.d.ts.map +1 -1
  13. package/dist/{browser → types}/UserEventHandler.d.ts +9 -8
  14. package/dist/types/UserEventHandler.d.ts.map +1 -0
  15. package/dist/types/ViewContentFields.d.ts +6 -0
  16. package/dist/{browser → types}/XyUserEventHandler.d.ts +5 -5
  17. package/dist/types/index.d.ts +15 -0
  18. package/package.json +12 -30
  19. package/src/Api/Api.ts +1 -1
  20. package/src/Api/UserEvent.ts +2 -2
  21. package/src/Api/index.ts +3 -3
  22. package/src/FunnelStartedFields.ts +1 -1
  23. package/src/Pixel.ts +8 -8
  24. package/src/PurchaseFields.ts +1 -1
  25. package/src/Referrer.ts +2 -2
  26. package/src/TestStartedFields.ts +1 -1
  27. package/src/UniqueUserId.ts +2 -2
  28. package/src/UserClickFields.ts +3 -1
  29. package/src/UserEventHandler.ts +9 -8
  30. package/src/UtmFields.ts +4 -4
  31. package/src/ViewContentFields.ts +1 -1
  32. package/src/XyUserEventHandler.ts +6 -6
  33. package/src/getSystemInfo.ts +2 -2
  34. package/src/index.ts +14 -14
  35. package/src/spec/Pixel.spec.ts +3 -1
  36. package/tsconfig.json +4 -0
  37. package/dist/browser/Api/index.d.ts +0 -4
  38. package/dist/browser/FunnelStartedFields.d.ts +0 -5
  39. package/dist/browser/TestStartedFields.d.ts +0 -5
  40. package/dist/browser/UserClickFields.d.ts +0 -6
  41. package/dist/browser/UserEventHandler.d.ts.map +0 -1
  42. package/dist/browser/ViewContentFields.d.ts +0 -6
  43. package/dist/browser/index.d.ts +0 -15
  44. package/eslint.config.mjs +0 -43
  45. package/jest.config.cjs +0 -25
  46. package/vitest.config.ts +0 -12
  47. package/vitest.startup.ts +0 -8
  48. /package/dist/{browser → types}/Api/Api.d.ts.map +0 -0
  49. /package/dist/{browser → types}/Api/UserEvent.d.ts.map +0 -0
  50. /package/dist/{browser → types}/Api/UserEventSystem.d.ts +0 -0
  51. /package/dist/{browser → types}/Api/UserEventSystem.d.ts.map +0 -0
  52. /package/dist/{browser → types}/Api/index.d.ts.map +0 -0
  53. /package/dist/{browser → types}/CommonFields.d.ts +0 -0
  54. /package/dist/{browser → types}/CommonFields.d.ts.map +0 -0
  55. /package/dist/{browser → types}/ExIds.d.ts +0 -0
  56. /package/dist/{browser → types}/ExIds.d.ts.map +0 -0
  57. /package/dist/{browser → types}/FunnelStartedFields.d.ts.map +0 -0
  58. /package/dist/{browser → types}/Pixel.d.ts.map +0 -0
  59. /package/dist/{browser → types}/PurchaseFields.d.ts.map +0 -0
  60. /package/dist/{browser → types}/Referrer.d.ts +0 -0
  61. /package/dist/{browser → types}/Referrer.d.ts.map +0 -0
  62. /package/dist/{browser → types}/TestStartedFields.d.ts.map +0 -0
  63. /package/dist/{browser → types}/UniqueUserId.d.ts +0 -0
  64. /package/dist/{browser → types}/UniqueUserId.d.ts.map +0 -0
  65. /package/dist/{browser → types}/UtmFields.d.ts +0 -0
  66. /package/dist/{browser → types}/UtmFields.d.ts.map +0 -0
  67. /package/dist/{browser → types}/ViewContentFields.d.ts.map +0 -0
  68. /package/dist/{browser → types}/XyLabsTrackingEventJson.d.ts +0 -0
  69. /package/dist/{browser → types}/XyLabsTrackingEventJson.d.ts.map +0 -0
  70. /package/dist/{browser → types}/XyUserEventHandler.d.ts.map +0 -0
  71. /package/dist/{browser → types}/getSystemInfo.d.ts +0 -0
  72. /package/dist/{browser → types}/getSystemInfo.d.ts.map +0 -0
  73. /package/dist/{browser → types}/index.d.ts.map +0 -0
package/.eslintcache ADDED
@@ -0,0 +1 @@
1
+ [{"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/Api/Api.ts":"1","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/Api/UserEvent.ts":"2","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/Api/UserEventSystem.ts":"3","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/Api/index.ts":"4","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/CommonFields.ts":"5","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/ExIds.ts":"6","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/FunnelStartedFields.ts":"7","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/Pixel.ts":"8","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/PurchaseFields.ts":"9","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/Referrer.ts":"10","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/TestStartedFields.ts":"11","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/UniqueUserId.ts":"12","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/UserClickFields.ts":"13","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/UserEventHandler.ts":"14","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/UtmFields.ts":"15","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/ViewContentFields.ts":"16","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/XyLabsTrackingEventJson.ts":"17","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/XyUserEventHandler.ts":"18","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/getSystemInfo.ts":"19","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/index.ts":"20","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/spec/Pixel.spec.ts":"21","/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/xy.config.ts":"22"},{"size":597,"mtime":1742231940381,"results":"23","hashOfConfig":"24"},{"size":539,"mtime":1742231940309,"results":"25","hashOfConfig":"24"},{"size":91,"mtime":1742231576636,"results":"26","hashOfConfig":"24"},{"size":93,"mtime":1742231940435,"results":"27","hashOfConfig":"24"},{"size":72,"mtime":1742231576636,"results":"28","hashOfConfig":"24"},{"size":147,"mtime":1742231576636,"results":"29","hashOfConfig":"24"},{"size":132,"mtime":1742231940245,"results":"30","hashOfConfig":"24"},{"size":3118,"mtime":1742232082186,"results":"31","hashOfConfig":"24"},{"size":175,"mtime":1742231940691,"results":"32","hashOfConfig":"24"},{"size":897,"mtime":1742232095988,"results":"33","hashOfConfig":"24"},{"size":130,"mtime":1742231940756,"results":"34","hashOfConfig":"24"},{"size":382,"mtime":1742232105045,"results":"35","hashOfConfig":"24"},{"size":196,"mtime":1742231940804,"results":"36","hashOfConfig":"24"},{"size":784,"mtime":1742232150116,"results":"37","hashOfConfig":"24"},{"size":1379,"mtime":1742232116074,"results":"38","hashOfConfig":"24"},{"size":145,"mtime":1742231940859,"results":"39","hashOfConfig":"24"},{"size":440,"mtime":1742231576637,"results":"40","hashOfConfig":"24"},{"size":1309,"mtime":1742231940978,"results":"41","hashOfConfig":"24"},{"size":355,"mtime":1742231940519,"results":"42","hashOfConfig":"24"},{"size":502,"mtime":1742231941029,"results":"43","hashOfConfig":"24"},{"size":360,"mtime":1742232643436,"results":"44","hashOfConfig":"24"},{"size":194,"mtime":1742231576638,"results":"45","hashOfConfig":"24"},{"filePath":"46","messages":"47","suppressedMessages":"48","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"sm8jh6",{"filePath":"49","messages":"50","suppressedMessages":"51","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"52","messages":"53","suppressedMessages":"54","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"55","messages":"56","suppressedMessages":"57","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"58","messages":"59","suppressedMessages":"60","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"61","messages":"62","suppressedMessages":"63","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"64","messages":"65","suppressedMessages":"66","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"67","messages":"68","suppressedMessages":"69","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"70","messages":"71","suppressedMessages":"72","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"73","messages":"74","suppressedMessages":"75","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"76","messages":"77","suppressedMessages":"78","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"79","messages":"80","suppressedMessages":"81","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"82","messages":"83","suppressedMessages":"84","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"85","messages":"86","suppressedMessages":"87","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"88","messages":"89","suppressedMessages":"90","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"91","messages":"92","suppressedMessages":"93","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"94","messages":"95","suppressedMessages":"96","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"97","messages":"98","suppressedMessages":"99","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"100","messages":"101","suppressedMessages":"102","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"103","messages":"104","suppressedMessages":"105","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"106","messages":"107","suppressedMessages":"108","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"109","messages":"110","suppressedMessages":"111","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/Api/Api.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/Api/UserEvent.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/Api/UserEventSystem.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/Api/index.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/CommonFields.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/ExIds.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/FunnelStartedFields.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/Pixel.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/PurchaseFields.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/Referrer.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/TestStartedFields.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/UniqueUserId.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/UserClickFields.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/UserEventHandler.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/UtmFields.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/ViewContentFields.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/XyLabsTrackingEventJson.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/XyUserEventHandler.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/getSystemInfo.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/index.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/src/spec/Pixel.spec.ts",[],[],"/Users/arietrouw/Github/xylabs/sdk-js/packages/pixel/xy.config.ts",[],[]]
@@ -1,6 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
1
  // src/Api/Api.ts
5
2
  import axios from "axios";
6
3
  var apiBaseUri = {
@@ -9,9 +6,6 @@ var apiBaseUri = {
9
6
  prod: "https://pixel.xylabs.com"
10
7
  };
11
8
  var PixelApi = class {
12
- static {
13
- __name(this, "PixelApi");
14
- }
15
9
  endPoint;
16
10
  /* baseUri can either be a preset (prod, beta, local), or a specific uri */
17
11
  constructor(baseUri = "prod") {
@@ -31,20 +25,17 @@ import md5 from "spark-md5";
31
25
  // src/getSystemInfo.ts
32
26
  import Bowser from "bowser";
33
27
  var systemInfo;
34
- var getSystemInfo = /* @__PURE__ */ __name(() => {
28
+ var getSystemInfo = () => {
35
29
  try {
36
- systemInfo = systemInfo || Bowser.getParser(window.navigator.userAgent).getResult();
30
+ systemInfo = systemInfo || Bowser.getParser(globalThis.navigator.userAgent).getResult();
37
31
  } catch (ex) {
38
32
  console.log(`getSystemInfo Error: ${ex}`);
39
33
  }
40
34
  return systemInfo;
41
- }, "getSystemInfo");
35
+ };
42
36
 
43
37
  // src/Referrer.ts
44
38
  var Referrer = class _Referrer {
45
- static {
46
- __name(this, "Referrer");
47
- }
48
39
  static storageId = "_coin_referrer";
49
40
  local;
50
41
  session;
@@ -52,7 +43,7 @@ var Referrer = class _Referrer {
52
43
  this.session = this.getFromSession() ?? document.referrer;
53
44
  sessionStorage.setItem(_Referrer.storageId, this.session);
54
45
  this.local = this.getFromLocal() ?? document.referrer;
55
- window.localStorage.setItem(_Referrer.storageId, this.local);
46
+ globalThis.localStorage.setItem(_Referrer.storageId, this.local);
56
47
  }
57
48
  toJson() {
58
49
  if (this.local && this.local.length > 0 || this.session && this.session.length > 0) {
@@ -63,7 +54,7 @@ var Referrer = class _Referrer {
63
54
  }
64
55
  }
65
56
  getFromLocal() {
66
- const value = window.localStorage.getItem(_Referrer.storageId);
57
+ const value = globalThis.localStorage.getItem(_Referrer.storageId);
67
58
  if (value && value.length > 0) {
68
59
  return value;
69
60
  }
@@ -78,14 +69,11 @@ var Referrer = class _Referrer {
78
69
 
79
70
  // src/UniqueUserId.ts
80
71
  var UniqueUserId = class _UniqueUserId {
81
- static {
82
- __name(this, "UniqueUserId");
83
- }
84
72
  static localStorageId = "_coin_cid";
85
73
  id;
86
74
  constructor() {
87
- this.id = window.localStorage.getItem(_UniqueUserId.localStorageId) ?? this.generateId();
88
- window.localStorage.setItem(_UniqueUserId.localStorageId, this.id);
75
+ this.id = globalThis.localStorage.getItem(_UniqueUserId.localStorageId) ?? this.generateId();
76
+ globalThis.localStorage.setItem(_UniqueUserId.localStorageId, this.id);
89
77
  }
90
78
  toString() {
91
79
  return this.id;
@@ -98,13 +86,10 @@ var UniqueUserId = class _UniqueUserId {
98
86
  // src/UtmFields.ts
99
87
  import isEqual from "fast-deep-equal";
100
88
  var UtmFields = class _UtmFields {
101
- static {
102
- __name(this, "UtmFields");
103
- }
104
89
  static localStorageId = "_coin_utm";
105
90
  fields = [];
106
91
  constructor() {
107
- const storedString = window.localStorage.getItem(_UtmFields.localStorageId) ?? "[]";
92
+ const storedString = globalThis.localStorage.getItem(_UtmFields.localStorageId) ?? "[]";
108
93
  try {
109
94
  this.fields = JSON.parse(storedString);
110
95
  } catch {
@@ -114,20 +99,20 @@ var UtmFields = class _UtmFields {
114
99
  this.fields = [];
115
100
  }
116
101
  this.update();
117
- window.localStorage.setItem(_UtmFields.localStorageId, JSON.stringify(this.fields));
102
+ globalThis.localStorage.setItem(_UtmFields.localStorageId, JSON.stringify(this.fields));
118
103
  }
119
- getUtmRecord = /* @__PURE__ */ __name(() => {
104
+ getUtmRecord = () => {
120
105
  const record = {};
121
106
  const parsedQueryString = document.location.search.split("?")[1]?.split("&") ?? [];
122
- parsedQueryString.map((item) => {
107
+ for (const item of parsedQueryString) {
123
108
  const [fullKey, value] = item.split("=");
124
109
  const [keyCategory, keyName] = fullKey.split("_");
125
110
  if (keyCategory === "utm") {
126
111
  record[keyName] = value;
127
112
  }
128
- });
113
+ }
129
114
  return Object.keys(record).length > 0 ? record : null;
130
- }, "getUtmRecord");
115
+ };
131
116
  toString() {
132
117
  return JSON.stringify(this.fields);
133
118
  }
@@ -144,9 +129,6 @@ var UtmFields = class _UtmFields {
144
129
  // src/Pixel.ts
145
130
  var emailHashLocalStorageName = "xy_email_hash";
146
131
  var XyPixel = class _XyPixel {
147
- static {
148
- __name(this, "XyPixel");
149
- }
150
132
  static api = new PixelApi();
151
133
  static _instance;
152
134
  static utmFieldsObj;
@@ -162,7 +144,7 @@ var XyPixel = class _XyPixel {
162
144
  this.email_hash = localStorage.getItem(emailHashLocalStorageName);
163
145
  }
164
146
  static get instance() {
165
- return assertEx(this._instance, "XyPixel uninitialized");
147
+ return assertEx(this._instance, () => "XyPixel uninitialized");
166
148
  }
167
149
  static init(pixelId) {
168
150
  this._instance = new _XyPixel(pixelId);
@@ -171,12 +153,12 @@ var XyPixel = class _XyPixel {
171
153
  static selectApi(api) {
172
154
  this.api = api;
173
155
  }
174
- static utmFields = /* @__PURE__ */ __name(() => {
156
+ static utmFields = () => {
175
157
  if (_XyPixel.utmFieldsObj === void 0) {
176
158
  _XyPixel.utmFieldsObj = new UtmFields();
177
159
  }
178
160
  return _XyPixel.utmFieldsObj;
179
- }, "utmFields");
161
+ };
180
162
  identify(email) {
181
163
  this.email = email;
182
164
  this.email_hash = email ? md5.hash(email, true) : void 0;
@@ -216,10 +198,7 @@ var XyPixel = class _XyPixel {
216
198
  await api.trackEvents(events);
217
199
  } catch (ex) {
218
200
  if (events) {
219
- this.queue = [
220
- ...this.queue,
221
- ...events
222
- ];
201
+ this.queue = [...this.queue, ...events];
223
202
  }
224
203
  console.error(ex);
225
204
  }
@@ -241,17 +220,11 @@ var XyPixel = class _XyPixel {
241
220
 
242
221
  // src/UserEventHandler.ts
243
222
  var UserEventHandler = class {
244
- static {
245
- __name(this, "UserEventHandler");
246
- }
247
223
  };
248
224
 
249
225
  // src/XyUserEventHandler.ts
250
226
  import { toJsonObject } from "@xylabs/object";
251
227
  var XyUserEventHandler = class extends UserEventHandler {
252
- static {
253
- __name(this, "XyUserEventHandler");
254
- }
255
228
  constructor() {
256
229
  super();
257
230
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Api/Api.ts","../../src/Pixel.ts","../../src/getSystemInfo.ts","../../src/Referrer.ts","../../src/UniqueUserId.ts","../../src/UtmFields.ts","../../src/UserEventHandler.ts","../../src/XyUserEventHandler.ts"],"sourcesContent":["import axios from 'axios'\n\nimport type { UserEvent } from './UserEvent.js'\n\nconst apiBaseUri: Record<string, string> = {\n beta: 'https://pixel.xylabs.com',\n local: 'http://localhost:3030',\n prod: 'https://pixel.xylabs.com',\n}\n\nexport class PixelApi {\n private endPoint: string\n\n /* baseUri can either be a preset (prod, beta, local), or a specific uri */\n constructor(baseUri = 'prod') {\n this.endPoint = apiBaseUri[baseUri] ? `${apiBaseUri[baseUri]}/t/event/queue` : baseUri\n }\n\n async trackEvents(events: UserEvent[]) {\n return (await axios.post(this.endPoint, events)).data\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { JsonObject } from '@xylabs/object'\nimport { Mutex } from 'async-mutex'\nimport Cookies from 'js-cookie'\nimport md5 from 'spark-md5'\n\nimport type { UserEvent } from './Api/index.js'\nimport { PixelApi } from './Api/index.js'\nimport type { ExIds } from './ExIds.js'\nimport { getSystemInfo } from './getSystemInfo.js'\nimport { Referrer } from './Referrer.js'\nimport { UniqueUserId } from './UniqueUserId.js'\nimport { UtmFields } from './UtmFields.js'\n\nconst emailHashLocalStorageName = 'xy_email_hash'\n\nexport class XyPixel {\n static api = new PixelApi()\n\n private static _instance?: XyPixel\n private static utmFieldsObj: UtmFields\n\n cid = new UniqueUserId().id\n email?: string\n email_hash?: string | null\n exids?: ExIds\n pixelId?: string\n\n queue: UserEvent[] = []\n\n private queueMutex = new Mutex()\n\n private constructor(pixelId: string) {\n this.pixelId = pixelId\n this.email_hash = localStorage.getItem(emailHashLocalStorageName)\n }\n\n static get instance(): XyPixel {\n return assertEx(this._instance, 'XyPixel uninitialized')\n }\n\n static init(pixelId: string) {\n this._instance = new XyPixel(pixelId)\n return this._instance\n }\n\n static selectApi(api: PixelApi) {\n this.api = api\n }\n\n private static utmFields = () => {\n if (XyPixel.utmFieldsObj === undefined) {\n XyPixel.utmFieldsObj = new UtmFields()\n }\n return XyPixel.utmFieldsObj\n }\n\n identify(email?: string) {\n this.email = email\n this.email_hash = email ? md5.hash(email, true) : undefined\n if (this.email_hash) {\n localStorage.setItem(emailHashLocalStorageName, this.email_hash)\n }\n }\n\n async send<T extends JsonObject>(event: string, fields?: T, eventId?: string) {\n this.updateFbId()\n const utm = XyPixel.utmFields().update()\n const referrer = new Referrer()\n this.queue.push({\n cid: this.cid,\n create_time: Date.now(),\n email_hash: this.email_hash ?? undefined,\n event,\n event_id: eventId,\n exids: this.exids,\n fields,\n host: document.location.host,\n pathname: document.location.pathname,\n pixel: this.pixelId,\n referrer: referrer.toJson(),\n system: getSystemInfo(),\n utm,\n })\n await this.tryFlushQueue()\n }\n\n private async tryFlushQueue() {\n await this.queueMutex.runExclusive(async () => {\n if (this.queue.length === 0) return\n const api = XyPixel.api\n if (api) {\n const events = this.queue\n this.queue = []\n try {\n await api.trackEvents(events)\n } catch (ex) {\n if (events) {\n // put it back since it failed\n this.queue = [...this.queue, ...events]\n }\n console.error(ex)\n }\n }\n })\n }\n\n private updateFbId() {\n this.exids = {\n fbc: Cookies.get('_fbc'),\n fbp: Cookies.get('_fbp'),\n ga: Cookies.get('_ga'),\n gclid: Cookies.get('_gcl_aw'),\n rdt_uid: Cookies.get('rdt_uid'),\n scid: Cookies.get('_scid'),\n tt_sessionId: sessionStorage.getItem('tt_sessionId') ?? undefined,\n }\n }\n}\n","import Bowser from 'bowser'\n\nimport type { UserEventSystem } from './Api/index.js'\n\nlet systemInfo: UserEventSystem | undefined\n\nexport const getSystemInfo = () => {\n try {\n systemInfo = systemInfo || Bowser.getParser(window.navigator.userAgent).getResult()\n } catch (ex) {\n console.log(`getSystemInfo Error: ${ex}`)\n }\n return systemInfo\n}\n","export class Referrer {\n private static storageId = '_coin_referrer'\n local: string\n session: string\n constructor() {\n this.session = this.getFromSession() ?? document.referrer\n sessionStorage.setItem(Referrer.storageId, this.session)\n this.local = this.getFromLocal() ?? document.referrer\n window.localStorage.setItem(Referrer.storageId, this.local)\n }\n\n toJson() {\n if ((this.local && this.local.length > 0) || (this.session && this.session.length > 0)) {\n return {\n local: this.local,\n session: this.session,\n }\n }\n }\n\n private getFromLocal() {\n const value = window.localStorage.getItem(Referrer.storageId)\n if (value && value.length > 0) {\n return value\n }\n }\n\n private getFromSession() {\n const value = sessionStorage.getItem(Referrer.storageId)\n if (value && value.length > 0) {\n return value\n }\n }\n}\n","export class UniqueUserId {\n private static localStorageId = '_coin_cid'\n id: string\n\n constructor() {\n this.id = window.localStorage.getItem(UniqueUserId.localStorageId) ?? this.generateId()\n window.localStorage.setItem(UniqueUserId.localStorageId, this.id)\n }\n\n toString() {\n return this.id\n }\n\n private generateId() {\n return crypto.randomUUID()\n }\n}\n","import isEqual from 'fast-deep-equal'\n\nexport class UtmFields {\n private static localStorageId = '_coin_utm'\n fields: Record<string, string>[] = []\n constructor() {\n const storedString = window.localStorage.getItem(UtmFields.localStorageId) ?? '[]'\n try {\n this.fields = JSON.parse(storedString)\n } catch {\n this.fields = []\n }\n // this clears the old object version if needed\n if (!Array.isArray(this.fields)) {\n this.fields = []\n }\n this.update()\n window.localStorage.setItem(UtmFields.localStorageId, JSON.stringify(this.fields))\n }\n\n getUtmRecord = () => {\n const record: Record<string, string> = {}\n const parsedQueryString = document.location.search.split('?')[1]?.split('&') ?? []\n parsedQueryString.map((item) => {\n const [fullKey, value] = item.split('=')\n const [keyCategory, keyName] = fullKey.split('_')\n if (keyCategory === 'utm') {\n record[keyName] = value\n }\n })\n return Object.keys(record).length > 0 ? record : null\n }\n\n toString() {\n return JSON.stringify(this.fields)\n }\n\n // check the query string and if there an new/updated utm values, add them to the fields\n update() {\n const record = this.getUtmRecord()\n if (record && !isEqual(this.fields.at(-1), record)) {\n this.fields.push(record)\n }\n return this.fields ?? undefined\n }\n}\n","import type { EmptyObject } from '@xylabs/object'\n\nimport type { FunnelStartedFields } from './FunnelStartedFields.js'\nimport type { TestStartedFields } from './TestStartedFields.js'\nimport type { UserClickFields } from './UserClickFields.js'\nimport type { ViewContentFields } from './ViewContentFields.js'\n\nexport abstract class UserEventHandler<TData extends EmptyObject> {\n abstract funnelStarted<T extends TData>(fields: T | FunnelStartedFields): Promise<void>\n abstract testStarted<T extends TData>(fields: T | TestStartedFields): Promise<void>\n abstract userClick<T extends TData>(fields: T | UserClickFields): Promise<void>\n abstract viewContent<T extends TData>(fields: T | ViewContentFields): Promise<void>\n}\n","import { type EmptyObject, toJsonObject } from '@xylabs/object'\n\nimport type { FunnelStartedFields } from './FunnelStartedFields.js'\nimport { XyPixel } from './Pixel.js'\nimport type { PurchaseFields } from './PurchaseFields.ts'\nimport type { TestStartedFields } from './TestStartedFields.js'\nimport type { UserClickFields } from './UserClickFields.js'\nimport { UserEventHandler } from './UserEventHandler.js'\nimport type { ViewContentFields } from './ViewContentFields.js'\n\nexport class XyUserEventHandler<T extends EmptyObject = EmptyObject> extends UserEventHandler<T> {\n constructor() {\n super()\n }\n\n async funnelStarted(fields: T | FunnelStartedFields) {\n return await XyPixel.instance.send('FunnelStarted', toJsonObject(fields, [], 10))\n }\n\n async purchase(fields: T | PurchaseFields) {\n return await XyPixel.instance.send('Purchase', toJsonObject(fields, [], 10))\n }\n\n async testStarted(fields: T | TestStartedFields) {\n return await XyPixel.instance.send('TestStarted', toJsonObject(fields, [], 10))\n }\n\n async userClick(fields: T | UserClickFields) {\n return await XyPixel.instance.send('ViewPage', toJsonObject(fields, [], 10))\n }\n\n async viewContent(fields: T | ViewContentFields) {\n return await XyPixel.instance.send('ViewContent', toJsonObject(fields, [], 10))\n }\n}\n"],"mappings":";;;;AAAA,OAAOA,WAAW;AAIlB,IAAMC,aAAqC;EACzCC,MAAM;EACNC,OAAO;EACPC,MAAM;AACR;AAEO,IAAMC,WAAN,MAAMA;EAVb,OAUaA;;;EACHC;;EAGRC,YAAYC,UAAU,QAAQ;AAC5B,SAAKF,WAAWL,WAAWO,OAAAA,IAAW,GAAGP,WAAWO,OAAAA,CAAQ,mBAAmBA;EACjF;EAEA,MAAMC,YAAYC,QAAqB;AACrC,YAAQ,MAAMC,MAAMC,KAAK,KAAKN,UAAUI,MAAAA,GAASG;EACnD;AACF;;;ACrBA,SAASC,gBAAgB;AAEzB,SAASC,aAAa;AACtB,OAAOC,aAAa;AACpB,OAAOC,SAAS;;;ACJhB,OAAOC,YAAY;AAInB,IAAIC;AAEG,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M,YAAYN,QAA+B;AAC/C,WAAO,MAAMC,QAAQC,SAASC,KAAK,eAAeC,aAAaJ,QAAQ,CAAA,GAAI,EAAA,CAAA;EAC7E;EAEA,MAAMO,UAAUP,QAA6B;AAC3C,WAAO,MAAMC,QAAQC,SAASC,KAAK,YAAYC,aAAaJ,QAAQ,CAAA,GAAI,EAAA,CAAA;EAC1E;EAEA,MAAMQ,YAAYR,QAA+B;AAC/C,WAAO,MAAMC,QAAQC,SAASC,KAAK,eAAeC,aAAaJ,QAAQ,CAAA,GAAI,EAAA,CAAA;EAC7E;AACF;","names":["axios","apiBaseUri","beta","local","prod","PixelApi","endPoint","constructor","baseUri","trackEvents","events","axios","post","data","assertEx","Mutex","Cookies","md5","Bowser","systemInfo","getSystemInfo","Bowser","getParser","window","navigator","userAgent","getResult","ex","console","log","Referrer","storageId","local","session","constructor","getFromSession","document","referrer","sessionStorage","setItem","getFromLocal","window","localStorage","toJson","length","value","getItem","UniqueUserId","localStorageId","id","constructor","window","localStorage","getItem","generateId","setItem","toString","crypto","randomUUID","isEqual","UtmFields","localStorageId","fields","constructor","storedString","window","localStorage","getItem","JSON","parse","Array","isArray","update","setItem","stringify","getUtmRecord","record","parsedQueryString","document","location","search","split","map","item","fullKey","value","keyCategory","keyName","Object","keys","length","toString","isEqual","at","push","undefined","emailHashLocalStorageName","XyPixel","api","PixelApi","_instance","utmFieldsObj","cid","UniqueUserId","id","email","email_hash","exids","pixelId","queue","queueMutex","Mutex","localStorage","getItem","instance","assertEx","init","selectApi","utmFields","undefined","UtmFields","identify","md5","hash","setItem","send","event","fields","eventId","updateFbId","utm","update","referrer","Referrer","push","create_time","Date","now","event_id","host","document","location","pathname","pixel","toJson","system","getSystemInfo","tryFlushQueue","runExclusive","length","events","trackEvents","ex","console","error","fbc","Cookies","get","fbp","ga","gclid","rdt_uid","scid","tt_sessionId","sessionStorage","UserEventHandler","toJsonObject","XyUserEventHandler","UserEventHandler","constructor","funnelStarted","fields","XyPixel","instance","send","toJsonObject","purchase","testStarted","userClick","viewContent"]}
1
+ {"version":3,"sources":["../../src/Api/Api.ts","../../src/Pixel.ts","../../src/getSystemInfo.ts","../../src/Referrer.ts","../../src/UniqueUserId.ts","../../src/UtmFields.ts","../../src/UserEventHandler.ts","../../src/XyUserEventHandler.ts"],"sourcesContent":["import axios from 'axios'\n\nimport type { UserEvent } from './UserEvent.ts'\n\nconst apiBaseUri: Record<string, string> = {\n beta: 'https://pixel.xylabs.com',\n local: 'http://localhost:3030',\n prod: 'https://pixel.xylabs.com',\n}\n\nexport class PixelApi {\n private endPoint: string\n\n /* baseUri can either be a preset (prod, beta, local), or a specific uri */\n constructor(baseUri = 'prod') {\n this.endPoint = apiBaseUri[baseUri] ? `${apiBaseUri[baseUri]}/t/event/queue` : baseUri\n }\n\n async trackEvents(events: UserEvent[]) {\n return (await axios.post(this.endPoint, events)).data\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { JsonObject } from '@xylabs/object'\nimport { Mutex } from 'async-mutex'\nimport Cookies from 'js-cookie'\nimport md5 from 'spark-md5'\n\nimport type { UserEvent } from './Api/index.ts'\nimport { PixelApi } from './Api/index.ts'\nimport type { ExIds } from './ExIds.ts'\nimport { getSystemInfo } from './getSystemInfo.ts'\nimport { Referrer } from './Referrer.ts'\nimport { UniqueUserId } from './UniqueUserId.ts'\nimport { UtmFields } from './UtmFields.ts'\n\nconst emailHashLocalStorageName = 'xy_email_hash'\n\nexport class XyPixel {\n static api = new PixelApi()\n\n private static _instance?: XyPixel\n private static utmFieldsObj: UtmFields\n\n cid = new UniqueUserId().id\n email?: string\n email_hash?: string | null\n exids?: ExIds\n pixelId?: string\n\n queue: UserEvent[] = []\n\n private queueMutex = new Mutex()\n\n private constructor(pixelId: string) {\n this.pixelId = pixelId\n this.email_hash = localStorage.getItem(emailHashLocalStorageName)\n }\n\n static get instance(): XyPixel {\n return assertEx(this._instance, () => 'XyPixel uninitialized')\n }\n\n static init(pixelId: string) {\n this._instance = new XyPixel(pixelId)\n return this._instance\n }\n\n static selectApi(api: PixelApi) {\n this.api = api\n }\n\n private static utmFields = () => {\n if (XyPixel.utmFieldsObj === undefined) {\n XyPixel.utmFieldsObj = new UtmFields()\n }\n return XyPixel.utmFieldsObj\n }\n\n identify(email?: string) {\n this.email = email\n this.email_hash = email ? md5.hash(email, true) : undefined\n if (this.email_hash) {\n localStorage.setItem(emailHashLocalStorageName, this.email_hash)\n }\n }\n\n async send<T extends JsonObject>(event: string, fields?: T, eventId?: string) {\n this.updateFbId()\n const utm = XyPixel.utmFields().update()\n const referrer = new Referrer()\n this.queue.push({\n cid: this.cid,\n create_time: Date.now(),\n email_hash: this.email_hash ?? undefined,\n event,\n event_id: eventId,\n exids: this.exids,\n fields,\n host: document.location.host,\n pathname: document.location.pathname,\n pixel: this.pixelId,\n referrer: referrer.toJson(),\n system: getSystemInfo(),\n utm,\n })\n await this.tryFlushQueue()\n }\n\n private async tryFlushQueue() {\n await this.queueMutex.runExclusive(async () => {\n if (this.queue.length === 0) return\n const api = XyPixel.api\n if (api) {\n const events = this.queue\n this.queue = []\n try {\n await api.trackEvents(events)\n } catch (ex) {\n if (events) {\n // put it back since it failed\n this.queue = [...this.queue, ...events]\n }\n console.error(ex)\n }\n }\n })\n }\n\n private updateFbId() {\n this.exids = {\n fbc: Cookies.get('_fbc'),\n fbp: Cookies.get('_fbp'),\n ga: Cookies.get('_ga'),\n gclid: Cookies.get('_gcl_aw'),\n rdt_uid: Cookies.get('rdt_uid'),\n scid: Cookies.get('_scid'),\n tt_sessionId: sessionStorage.getItem('tt_sessionId') ?? undefined,\n }\n }\n}\n","import Bowser from 'bowser'\n\nimport type { UserEventSystem } from './Api/index.ts'\n\nlet systemInfo: UserEventSystem | undefined\n\nexport const getSystemInfo = () => {\n try {\n systemInfo = systemInfo || Bowser.getParser(globalThis.navigator.userAgent).getResult()\n } catch (ex) {\n console.log(`getSystemInfo Error: ${ex}`)\n }\n return systemInfo\n}\n","export class Referrer {\n private static storageId = '_coin_referrer'\n local: string\n session: string\n constructor() {\n this.session = this.getFromSession() ?? document.referrer\n sessionStorage.setItem(Referrer.storageId, this.session)\n this.local = this.getFromLocal() ?? document.referrer\n globalThis.localStorage.setItem(Referrer.storageId, this.local)\n }\n\n toJson() {\n if ((this.local && this.local.length > 0) || (this.session && this.session.length > 0)) {\n return {\n local: this.local,\n session: this.session,\n }\n }\n }\n\n private getFromLocal() {\n const value = globalThis.localStorage.getItem(Referrer.storageId)\n if (value && value.length > 0) {\n return value\n }\n }\n\n private getFromSession() {\n const value = sessionStorage.getItem(Referrer.storageId)\n if (value && value.length > 0) {\n return value\n }\n }\n}\n","export class UniqueUserId {\n private static localStorageId = '_coin_cid'\n id: string\n\n constructor() {\n this.id = globalThis.localStorage.getItem(UniqueUserId.localStorageId) ?? this.generateId()\n globalThis.localStorage.setItem(UniqueUserId.localStorageId, this.id)\n }\n\n toString() {\n return this.id\n }\n\n private generateId() {\n return crypto.randomUUID()\n }\n}\n","import isEqual from 'fast-deep-equal'\n\nexport class UtmFields {\n private static localStorageId = '_coin_utm'\n fields: Record<string, string>[] = []\n constructor() {\n const storedString = globalThis.localStorage.getItem(UtmFields.localStorageId) ?? '[]'\n try {\n this.fields = JSON.parse(storedString)\n } catch {\n this.fields = []\n }\n // this clears the old object version if needed\n if (!Array.isArray(this.fields)) {\n this.fields = []\n }\n this.update()\n globalThis.localStorage.setItem(UtmFields.localStorageId, JSON.stringify(this.fields))\n }\n\n getUtmRecord = () => {\n const record: Record<string, string> = {}\n const parsedQueryString = document.location.search.split('?')[1]?.split('&') ?? []\n for (const item of parsedQueryString) {\n const [fullKey, value] = item.split('=')\n const [keyCategory, keyName] = fullKey.split('_')\n if (keyCategory === 'utm') {\n record[keyName] = value\n }\n }\n return Object.keys(record).length > 0 ? record : null\n }\n\n toString() {\n return JSON.stringify(this.fields)\n }\n\n // check the query string and if there an new/updated utm values, add them to the fields\n update() {\n const record = this.getUtmRecord()\n if (record && !isEqual(this.fields.at(-1), record)) {\n this.fields.push(record)\n }\n return this.fields ?? undefined\n }\n}\n","import type { EmptyObject } from '@xylabs/object'\nimport type { Promisable } from '@xylabs/promise'\n\nimport type { FunnelStartedFields } from './FunnelStartedFields.ts'\nimport type { TestStartedFields } from './TestStartedFields.ts'\nimport type { UserClickFields } from './UserClickFields.ts'\nimport type { ViewContentFields } from './ViewContentFields.ts'\n\nexport abstract class UserEventHandler<TData extends EmptyObject> {\n abstract funnelStarted<T extends TData>(fields: T | FunnelStartedFields): Promisable<void>\n abstract testStarted<T extends TData>(fields: T | TestStartedFields): Promisable<void>\n abstract userClick<T extends TData>(fields: T | UserClickFields): Promisable<void>\n abstract viewContent<T extends TData>(fields: T | ViewContentFields): Promisable<void>\n}\n","import { type EmptyObject, toJsonObject } from '@xylabs/object'\n\nimport type { FunnelStartedFields } from './FunnelStartedFields.ts'\nimport { XyPixel } from './Pixel.ts'\nimport type { PurchaseFields } from './PurchaseFields.ts'\nimport type { TestStartedFields } from './TestStartedFields.ts'\nimport type { UserClickFields } from './UserClickFields.ts'\nimport { UserEventHandler } from './UserEventHandler.ts'\nimport type { ViewContentFields } from './ViewContentFields.ts'\n\nexport class XyUserEventHandler<T extends EmptyObject = EmptyObject> extends UserEventHandler<T> {\n constructor() {\n super()\n }\n\n async funnelStarted(fields: T | FunnelStartedFields) {\n return await XyPixel.instance.send('FunnelStarted', toJsonObject(fields, [], 10))\n }\n\n async purchase(fields: T | PurchaseFields) {\n return await XyPixel.instance.send('Purchase', toJsonObject(fields, [], 10))\n }\n\n async testStarted(fields: T | TestStartedFields) {\n return await XyPixel.instance.send('TestStarted', toJsonObject(fields, [], 10))\n }\n\n async userClick(fields: T | UserClickFields) {\n return await XyPixel.instance.send('ViewPage', toJsonObject(fields, [], 10))\n }\n\n async viewContent(fields: T | ViewContentFields) {\n return await XyPixel.instance.send('ViewContent', toJsonObject(fields, [], 10))\n }\n}\n"],"mappings":";AAAA,OAAO,WAAW;AAIlB,IAAM,aAAqC;AAAA,EACzC,MAAM;AAA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AI,SAAS;AAAA,MAC9B,MAAM,QAAQ,IAAI,OAAO;AAAA,MACzB,cAAc,eAAe,QAAQ,cAAc,KAAK;AAAA,IAC1D;AAAA,EACF;AACF;;;AK9GO,IAAe,mBAAf,MAA2D;AAKlE;;;ACbA,SAA2B,oBAAoB;AAUxC,IAAM,qBAAN,cAAsE,iBAAoB;AAAA,EAC/F,cAAc;AACZ,UAAM;AAAA,EACR;AAAA,EAEA,MAAM,cAAc,QAAiC;AACnD,WAAO,MAAM,QAAQ,SAAS,KAAK,iBAAiB,aAAa,QAAQ,CAAC,GAAG,EAAE,CAAC;AAAA,EAClF;AAAA,EAEA,MAAM,SAAS,QAA4B;AACzC,WAAO,MAAM,QAAQ,SAAS,KAAK,YAAY,aAAa,QAAQ,CAAC,GAAG,EAAE,CAAC;AAAA,EAC7E;AAAA,EAEA,MAAM,YAAY,QAA+B;AAC/C,WAAO,MAAM,QAAQ,SAAS,KAAK,eAAe,aAAa,QAAQ,CAAC,GAAG,EAAE,CAAC;AAAA,EAChF;AAAA,EAEA,MAAM,UAAU,QAA6B;AAC3C,WAAO,MAAM,QAAQ,SAAS,KAAK,YAAY,aAAa,QAAQ,CAAC,GAAG,EAAE,CAAC;AAAA,EAC7E;AAAA,EAEA,MAAM,YAAY,QAA+B;AAC/C,WAAO,MAAM,QAAQ,SAAS,KAAK,eAAe,aAAa,QAAQ,CAAC,GAAG,EAAE,CAAC;AAAA,EAChF;AACF;","names":[]}
@@ -1,4 +1,4 @@
1
- import type { UserEvent } from './UserEvent.js';
1
+ import type { UserEvent } from './UserEvent.ts';
2
2
  export declare class PixelApi {
3
3
  private endPoint;
4
4
  constructor(baseUri?: string);
@@ -1,5 +1,5 @@
1
- import type { ExIds } from '../ExIds.js';
2
- import type { UserEventSystem } from './UserEventSystem.js';
1
+ import type { ExIds } from '../ExIds.ts';
2
+ import type { UserEventSystem } from './UserEventSystem.ts';
3
3
  export interface UserEvent {
4
4
  cid: string;
5
5
  create_time?: number;
@@ -0,0 +1,4 @@
1
+ export * from './Api.ts';
2
+ export * from './UserEvent.ts';
3
+ export * from './UserEventSystem.ts';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ import type { CommonFields } from './CommonFields.ts';
2
+ export interface FunnelStartedFields extends CommonFields {
3
+ name: string;
4
+ }
5
+ //# sourceMappingURL=FunnelStartedFields.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import type { JsonObject } from '@xylabs/object';
2
- import type { UserEvent } from './Api/index.js';
3
- import { PixelApi } from './Api/index.js';
4
- import type { ExIds } from './ExIds.js';
2
+ import type { UserEvent } from './Api/index.ts';
3
+ import { PixelApi } from './Api/index.ts';
4
+ import type { ExIds } from './ExIds.ts';
5
5
  export declare class XyPixel {
6
6
  static api: PixelApi;
7
7
  private static _instance?;
@@ -1,4 +1,4 @@
1
- import type { CommonFields } from './CommonFields.js';
1
+ import type { CommonFields } from './CommonFields.ts';
2
2
  export interface PurchaseFields extends CommonFields {
3
3
  id: string;
4
4
  name?: string;
@@ -0,0 +1,5 @@
1
+ import type { CommonFields } from './CommonFields.ts';
2
+ export interface TestStartedFields extends CommonFields {
3
+ name: string;
4
+ }
5
+ //# sourceMappingURL=TestStartedFields.d.ts.map
@@ -0,0 +1,8 @@
1
+ import type { CommonFields } from './CommonFields.ts';
2
+ export interface UserClickFields extends CommonFields {
3
+ elementName: string;
4
+ elementType: string;
5
+ intent?: string;
6
+ placement?: string;
7
+ }
8
+ //# sourceMappingURL=UserClickFields.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UserClickFields.d.ts","sourceRoot":"","sources":["../../src/UserClickFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,WAAW,eAAgB,SAAQ,YAAY;IACnD,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;CACpB"}
1
+ {"version":3,"file":"UserClickFields.d.ts","sourceRoot":"","sources":["../../src/UserClickFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,WAAW,eAAgB,SAAQ,YAAY;IACnD,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
@@ -1,12 +1,13 @@
1
1
  import type { EmptyObject } from '@xylabs/object';
2
- import type { FunnelStartedFields } from './FunnelStartedFields.js';
3
- import type { TestStartedFields } from './TestStartedFields.js';
4
- import type { UserClickFields } from './UserClickFields.js';
5
- import type { ViewContentFields } from './ViewContentFields.js';
2
+ import type { Promisable } from '@xylabs/promise';
3
+ import type { FunnelStartedFields } from './FunnelStartedFields.ts';
4
+ import type { TestStartedFields } from './TestStartedFields.ts';
5
+ import type { UserClickFields } from './UserClickFields.ts';
6
+ import type { ViewContentFields } from './ViewContentFields.ts';
6
7
  export declare abstract class UserEventHandler<TData extends EmptyObject> {
7
- abstract funnelStarted<T extends TData>(fields: T | FunnelStartedFields): Promise<void>;
8
- abstract testStarted<T extends TData>(fields: T | TestStartedFields): Promise<void>;
9
- abstract userClick<T extends TData>(fields: T | UserClickFields): Promise<void>;
10
- abstract viewContent<T extends TData>(fields: T | ViewContentFields): Promise<void>;
8
+ abstract funnelStarted<T extends TData>(fields: T | FunnelStartedFields): Promisable<void>;
9
+ abstract testStarted<T extends TData>(fields: T | TestStartedFields): Promisable<void>;
10
+ abstract userClick<T extends TData>(fields: T | UserClickFields): Promisable<void>;
11
+ abstract viewContent<T extends TData>(fields: T | ViewContentFields): Promisable<void>;
11
12
  }
12
13
  //# sourceMappingURL=UserEventHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserEventHandler.d.ts","sourceRoot":"","sources":["../../src/UserEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,8BAAsB,gBAAgB,CAAC,KAAK,SAAS,WAAW;IAC9D,QAAQ,CAAC,aAAa,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,CAAC,GAAG,mBAAmB,GAAG,UAAU,CAAC,IAAI,CAAC;IAC1F,QAAQ,CAAC,WAAW,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,CAAC,GAAG,iBAAiB,GAAG,UAAU,CAAC,IAAI,CAAC;IACtF,QAAQ,CAAC,SAAS,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,CAAC,GAAG,eAAe,GAAG,UAAU,CAAC,IAAI,CAAC;IAClF,QAAQ,CAAC,WAAW,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,CAAC,GAAG,iBAAiB,GAAG,UAAU,CAAC,IAAI,CAAC;CACvF"}
@@ -0,0 +1,6 @@
1
+ import type { CommonFields } from './CommonFields.ts';
2
+ export interface ViewContentFields extends CommonFields {
3
+ name: string;
4
+ path: string;
5
+ }
6
+ //# sourceMappingURL=ViewContentFields.d.ts.map
@@ -1,10 +1,10 @@
1
1
  import { type EmptyObject } from '@xylabs/object';
2
- import type { FunnelStartedFields } from './FunnelStartedFields.js';
2
+ import type { FunnelStartedFields } from './FunnelStartedFields.ts';
3
3
  import type { PurchaseFields } from './PurchaseFields.ts';
4
- import type { TestStartedFields } from './TestStartedFields.js';
5
- import type { UserClickFields } from './UserClickFields.js';
6
- import { UserEventHandler } from './UserEventHandler.js';
7
- import type { ViewContentFields } from './ViewContentFields.js';
4
+ import type { TestStartedFields } from './TestStartedFields.ts';
5
+ import type { UserClickFields } from './UserClickFields.ts';
6
+ import { UserEventHandler } from './UserEventHandler.ts';
7
+ import type { ViewContentFields } from './ViewContentFields.ts';
8
8
  export declare class XyUserEventHandler<T extends EmptyObject = EmptyObject> extends UserEventHandler<T> {
9
9
  constructor();
10
10
  funnelStarted(fields: T | FunnelStartedFields): Promise<void>;
@@ -0,0 +1,15 @@
1
+ export * from './Api/index.ts';
2
+ export * from './CommonFields.ts';
3
+ export * from './FunnelStartedFields.ts';
4
+ export * from './Pixel.ts';
5
+ export * from './PurchaseFields.ts';
6
+ export * from './Referrer.ts';
7
+ export * from './TestStartedFields.ts';
8
+ export * from './UniqueUserId.ts';
9
+ export * from './UserClickFields.ts';
10
+ export * from './UserEventHandler.ts';
11
+ export * from './UtmFields.ts';
12
+ export * from './ViewContentFields.ts';
13
+ export * from './XyLabsTrackingEventJson.ts';
14
+ export * from './XyUserEventHandler.ts';
15
+ //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/pixel",
3
- "version": "2.0.5",
3
+ "version": "4.6.1",
4
4
  "description": "Event Client for xylabs ESB",
5
5
  "homepage": "https://xylabs.com",
6
6
  "bugs": {
@@ -21,49 +21,31 @@
21
21
  "type": "module",
22
22
  "exports": {
23
23
  ".": {
24
- "types": "./dist/browser/index.d.ts",
24
+ "types": "./dist/types/index.d.ts",
25
25
  "default": "./dist/browser/index.mjs"
26
26
  },
27
27
  "./package.json": "./package.json"
28
28
  },
29
29
  "module": "dist/browser/index.mjs",
30
- "types": "dist/browser/index.d.ts",
30
+ "types": "dist/types/index.d.ts",
31
31
  "dependencies": {
32
- "@xylabs/assert": "^4.0.10",
33
- "@xylabs/object": "^4.0.10",
32
+ "@xylabs/assert": "^4.6.1",
33
+ "@xylabs/object": "^4.6.1",
34
34
  "async-mutex": "^0.5.0",
35
- "axios": "^1.7.7",
35
+ "axios": "^1.8.3",
36
36
  "bowser": "^2.11.0",
37
37
  "fast-deep-equal": "^3.1.3",
38
38
  "js-cookie": "^3.0.5",
39
39
  "spark-md5": "^3.0.2"
40
40
  },
41
41
  "devDependencies": {
42
- "@types/jest": "^29.5.12",
43
42
  "@types/js-cookie": "^3.0.6",
44
- "@types/jsdom": "^21.1.7",
45
- "@types/lodash-es": "^4.17.12",
46
- "@types/node": "^22.5.4",
47
- "@types/randombytes": "^2.0.3",
48
- "@types/spark-md5": "^3.0.4",
49
- "@xylabs/eslint-config-flat": "^4.0.7",
50
- "@xylabs/ts-scripts-yarn3": "^4.0.7",
51
- "@xylabs/tsconfig-dom": "^4.0.7",
52
- "@xylabs/tsconfig-dom-jest": "^4.0.7",
53
- "@xylabs/tsconfig-jest": "^4.0.7",
54
- "axios": "^1.7.7",
55
- "dotenv": "^16.4.5",
56
- "eslint": "^9.9.1",
57
- "eslint-import-resolver-typescript": "^3.6.3",
58
- "jest": "^29.7.0",
59
- "jest-environment-jsdom": "^29.7.0",
60
- "jsdom": "^25.0.0",
61
- "npm-package-json-lint": "^8.0.0",
62
- "reflect-metadata": "^0.2.2",
63
- "ts-jest": "^29.2.5",
64
- "ts-node": "^10.9.2",
65
- "typescript": "^5.5.4",
66
- "vitest": "^2.0.5"
43
+ "@types/node": "^22.13.10",
44
+ "@types/spark-md5": "^3.0.5",
45
+ "@xylabs/ts-scripts-yarn3": "^6.1.4",
46
+ "@xylabs/tsconfig-dom": "^6.1.4",
47
+ "axios": "^1.8.3",
48
+ "typescript": "^5.8.2"
67
49
  },
68
50
  "packageManager": "yarn@4.4.0",
69
51
  "publishConfig": {
package/src/Api/Api.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import axios from 'axios'
2
2
 
3
- import type { UserEvent } from './UserEvent.js'
3
+ import type { UserEvent } from './UserEvent.ts'
4
4
 
5
5
  const apiBaseUri: Record<string, string> = {
6
6
  beta: 'https://pixel.xylabs.com',
@@ -1,5 +1,5 @@
1
- import type { ExIds } from '../ExIds.js'
2
- import type { UserEventSystem } from './UserEventSystem.js'
1
+ import type { ExIds } from '../ExIds.ts'
2
+ import type { UserEventSystem } from './UserEventSystem.ts'
3
3
 
4
4
  export interface UserEvent {
5
5
  cid: string
package/src/Api/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './Api.js'
2
- export * from './UserEvent.js'
3
- export * from './UserEventSystem.js'
1
+ export * from './Api.ts'
2
+ export * from './UserEvent.ts'
3
+ export * from './UserEventSystem.ts'
@@ -1,4 +1,4 @@
1
- import type { CommonFields } from './CommonFields.js'
1
+ import type { CommonFields } from './CommonFields.ts'
2
2
 
3
3
  export interface FunnelStartedFields extends CommonFields {
4
4
  name: string
package/src/Pixel.ts CHANGED
@@ -4,13 +4,13 @@ import { Mutex } from 'async-mutex'
4
4
  import Cookies from 'js-cookie'
5
5
  import md5 from 'spark-md5'
6
6
 
7
- import type { UserEvent } from './Api/index.js'
8
- import { PixelApi } from './Api/index.js'
9
- import type { ExIds } from './ExIds.js'
10
- import { getSystemInfo } from './getSystemInfo.js'
11
- import { Referrer } from './Referrer.js'
12
- import { UniqueUserId } from './UniqueUserId.js'
13
- import { UtmFields } from './UtmFields.js'
7
+ import type { UserEvent } from './Api/index.ts'
8
+ import { PixelApi } from './Api/index.ts'
9
+ import type { ExIds } from './ExIds.ts'
10
+ import { getSystemInfo } from './getSystemInfo.ts'
11
+ import { Referrer } from './Referrer.ts'
12
+ import { UniqueUserId } from './UniqueUserId.ts'
13
+ import { UtmFields } from './UtmFields.ts'
14
14
 
15
15
  const emailHashLocalStorageName = 'xy_email_hash'
16
16
 
@@ -36,7 +36,7 @@ export class XyPixel {
36
36
  }
37
37
 
38
38
  static get instance(): XyPixel {
39
- return assertEx(this._instance, 'XyPixel uninitialized')
39
+ return assertEx(this._instance, () => 'XyPixel uninitialized')
40
40
  }
41
41
 
42
42
  static init(pixelId: string) {
@@ -1,4 +1,4 @@
1
- import type { CommonFields } from './CommonFields.js'
1
+ import type { CommonFields } from './CommonFields.ts'
2
2
 
3
3
  export interface PurchaseFields extends CommonFields {
4
4
  id: string
package/src/Referrer.ts CHANGED
@@ -6,7 +6,7 @@ export class Referrer {
6
6
  this.session = this.getFromSession() ?? document.referrer
7
7
  sessionStorage.setItem(Referrer.storageId, this.session)
8
8
  this.local = this.getFromLocal() ?? document.referrer
9
- window.localStorage.setItem(Referrer.storageId, this.local)
9
+ globalThis.localStorage.setItem(Referrer.storageId, this.local)
10
10
  }
11
11
 
12
12
  toJson() {
@@ -19,7 +19,7 @@ export class Referrer {
19
19
  }
20
20
 
21
21
  private getFromLocal() {
22
- const value = window.localStorage.getItem(Referrer.storageId)
22
+ const value = globalThis.localStorage.getItem(Referrer.storageId)
23
23
  if (value && value.length > 0) {
24
24
  return value
25
25
  }
@@ -1,4 +1,4 @@
1
- import type { CommonFields } from './CommonFields.js'
1
+ import type { CommonFields } from './CommonFields.ts'
2
2
 
3
3
  export interface TestStartedFields extends CommonFields {
4
4
  name: string
@@ -3,8 +3,8 @@ export class UniqueUserId {
3
3
  id: string
4
4
 
5
5
  constructor() {
6
- this.id = window.localStorage.getItem(UniqueUserId.localStorageId) ?? this.generateId()
7
- window.localStorage.setItem(UniqueUserId.localStorageId, this.id)
6
+ this.id = globalThis.localStorage.getItem(UniqueUserId.localStorageId) ?? this.generateId()
7
+ globalThis.localStorage.setItem(UniqueUserId.localStorageId, this.id)
8
8
  }
9
9
 
10
10
  toString() {
@@ -1,6 +1,8 @@
1
- import type { CommonFields } from './CommonFields.js'
1
+ import type { CommonFields } from './CommonFields.ts'
2
2
 
3
3
  export interface UserClickFields extends CommonFields {
4
4
  elementName: string
5
5
  elementType: string
6
+ intent?: string
7
+ placement?: string
6
8
  }
@@ -1,13 +1,14 @@
1
1
  import type { EmptyObject } from '@xylabs/object'
2
+ import type { Promisable } from '@xylabs/promise'
2
3
 
3
- import type { FunnelStartedFields } from './FunnelStartedFields.js'
4
- import type { TestStartedFields } from './TestStartedFields.js'
5
- import type { UserClickFields } from './UserClickFields.js'
6
- import type { ViewContentFields } from './ViewContentFields.js'
4
+ import type { FunnelStartedFields } from './FunnelStartedFields.ts'
5
+ import type { TestStartedFields } from './TestStartedFields.ts'
6
+ import type { UserClickFields } from './UserClickFields.ts'
7
+ import type { ViewContentFields } from './ViewContentFields.ts'
7
8
 
8
9
  export abstract class UserEventHandler<TData extends EmptyObject> {
9
- abstract funnelStarted<T extends TData>(fields: T | FunnelStartedFields): Promise<void>
10
- abstract testStarted<T extends TData>(fields: T | TestStartedFields): Promise<void>
11
- abstract userClick<T extends TData>(fields: T | UserClickFields): Promise<void>
12
- abstract viewContent<T extends TData>(fields: T | ViewContentFields): Promise<void>
10
+ abstract funnelStarted<T extends TData>(fields: T | FunnelStartedFields): Promisable<void>
11
+ abstract testStarted<T extends TData>(fields: T | TestStartedFields): Promisable<void>
12
+ abstract userClick<T extends TData>(fields: T | UserClickFields): Promisable<void>
13
+ abstract viewContent<T extends TData>(fields: T | ViewContentFields): Promisable<void>
13
14
  }
package/src/UtmFields.ts CHANGED
@@ -4,7 +4,7 @@ export class UtmFields {
4
4
  private static localStorageId = '_coin_utm'
5
5
  fields: Record<string, string>[] = []
6
6
  constructor() {
7
- const storedString = window.localStorage.getItem(UtmFields.localStorageId) ?? '[]'
7
+ const storedString = globalThis.localStorage.getItem(UtmFields.localStorageId) ?? '[]'
8
8
  try {
9
9
  this.fields = JSON.parse(storedString)
10
10
  } catch {
@@ -15,19 +15,19 @@ export class UtmFields {
15
15
  this.fields = []
16
16
  }
17
17
  this.update()
18
- window.localStorage.setItem(UtmFields.localStorageId, JSON.stringify(this.fields))
18
+ globalThis.localStorage.setItem(UtmFields.localStorageId, JSON.stringify(this.fields))
19
19
  }
20
20
 
21
21
  getUtmRecord = () => {
22
22
  const record: Record<string, string> = {}
23
23
  const parsedQueryString = document.location.search.split('?')[1]?.split('&') ?? []
24
- parsedQueryString.map((item) => {
24
+ for (const item of parsedQueryString) {
25
25
  const [fullKey, value] = item.split('=')
26
26
  const [keyCategory, keyName] = fullKey.split('_')
27
27
  if (keyCategory === 'utm') {
28
28
  record[keyName] = value
29
29
  }
30
- })
30
+ }
31
31
  return Object.keys(record).length > 0 ? record : null
32
32
  }
33
33
 
@@ -1,4 +1,4 @@
1
- import type { CommonFields } from './CommonFields.js'
1
+ import type { CommonFields } from './CommonFields.ts'
2
2
 
3
3
  export interface ViewContentFields extends CommonFields {
4
4
  name: string
@@ -1,12 +1,12 @@
1
1
  import { type EmptyObject, toJsonObject } from '@xylabs/object'
2
2
 
3
- import type { FunnelStartedFields } from './FunnelStartedFields.js'
4
- import { XyPixel } from './Pixel.js'
3
+ import type { FunnelStartedFields } from './FunnelStartedFields.ts'
4
+ import { XyPixel } from './Pixel.ts'
5
5
  import type { PurchaseFields } from './PurchaseFields.ts'
6
- import type { TestStartedFields } from './TestStartedFields.js'
7
- import type { UserClickFields } from './UserClickFields.js'
8
- import { UserEventHandler } from './UserEventHandler.js'
9
- import type { ViewContentFields } from './ViewContentFields.js'
6
+ import type { TestStartedFields } from './TestStartedFields.ts'
7
+ import type { UserClickFields } from './UserClickFields.ts'
8
+ import { UserEventHandler } from './UserEventHandler.ts'
9
+ import type { ViewContentFields } from './ViewContentFields.ts'
10
10
 
11
11
  export class XyUserEventHandler<T extends EmptyObject = EmptyObject> extends UserEventHandler<T> {
12
12
  constructor() {
@@ -1,12 +1,12 @@
1
1
  import Bowser from 'bowser'
2
2
 
3
- import type { UserEventSystem } from './Api/index.js'
3
+ import type { UserEventSystem } from './Api/index.ts'
4
4
 
5
5
  let systemInfo: UserEventSystem | undefined
6
6
 
7
7
  export const getSystemInfo = () => {
8
8
  try {
9
- systemInfo = systemInfo || Bowser.getParser(window.navigator.userAgent).getResult()
9
+ systemInfo = systemInfo || Bowser.getParser(globalThis.navigator.userAgent).getResult()
10
10
  } catch (ex) {
11
11
  console.log(`getSystemInfo Error: ${ex}`)
12
12
  }
package/src/index.ts CHANGED
@@ -1,14 +1,14 @@
1
- export * from './Api/index.js'
2
- export * from './CommonFields.js'
3
- export * from './FunnelStartedFields.js'
4
- export * from './Pixel.js'
5
- export * from './PurchaseFields.js'
6
- export * from './Referrer.js'
7
- export * from './TestStartedFields.js'
8
- export * from './UniqueUserId.js'
9
- export * from './UserClickFields.js'
10
- export * from './UserEventHandler.js'
11
- export * from './UtmFields.js'
12
- export * from './ViewContentFields.js'
13
- export * from './XyLabsTrackingEventJson.js'
14
- export * from './XyUserEventHandler.js'
1
+ export * from './Api/index.ts'
2
+ export * from './CommonFields.ts'
3
+ export * from './FunnelStartedFields.ts'
4
+ export * from './Pixel.ts'
5
+ export * from './PurchaseFields.ts'
6
+ export * from './Referrer.ts'
7
+ export * from './TestStartedFields.ts'
8
+ export * from './UniqueUserId.ts'
9
+ export * from './UserClickFields.ts'
10
+ export * from './UserEventHandler.ts'
11
+ export * from './UtmFields.ts'
12
+ export * from './ViewContentFields.ts'
13
+ export * from './XyLabsTrackingEventJson.ts'
14
+ export * from './XyUserEventHandler.ts'
@@ -1,7 +1,9 @@
1
1
  /**
2
- * @jest-environment jsdom
2
+ * @vitest-environment jsdom
3
3
  */
4
4
 
5
+ import { expect, test } from 'vitest'
6
+
5
7
  import { PixelApi } from '../Api/index.ts'
6
8
  import { XyPixel } from '../Pixel.ts'
7
9
 
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "exclude": ["./node_modules", "./**/node_modules", "./dist", "./**/dist", "./**/docs", ".*"],
3
+ "extends": "@xylabs/tsconfig-dom",
4
+ }
@@ -1,4 +0,0 @@
1
- export * from './Api.js';
2
- export * from './UserEvent.js';
3
- export * from './UserEventSystem.js';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1,5 +0,0 @@
1
- import type { CommonFields } from './CommonFields.js';
2
- export interface FunnelStartedFields extends CommonFields {
3
- name: string;
4
- }
5
- //# sourceMappingURL=FunnelStartedFields.d.ts.map
@@ -1,5 +0,0 @@
1
- import type { CommonFields } from './CommonFields.js';
2
- export interface TestStartedFields extends CommonFields {
3
- name: string;
4
- }
5
- //# sourceMappingURL=TestStartedFields.d.ts.map
@@ -1,6 +0,0 @@
1
- import type { CommonFields } from './CommonFields.js';
2
- export interface UserClickFields extends CommonFields {
3
- elementName: string;
4
- elementType: string;
5
- }
6
- //# sourceMappingURL=UserClickFields.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UserEventHandler.d.ts","sourceRoot":"","sources":["../../src/UserEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,8BAAsB,gBAAgB,CAAC,KAAK,SAAS,WAAW;IAC9D,QAAQ,CAAC,aAAa,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,CAAC,GAAG,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IACvF,QAAQ,CAAC,WAAW,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,CAAC,GAAG,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IACnF,QAAQ,CAAC,SAAS,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,CAAC,GAAG,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAC/E,QAAQ,CAAC,WAAW,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,CAAC,GAAG,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CACpF"}
@@ -1,6 +0,0 @@
1
- import type { CommonFields } from './CommonFields.js';
2
- export interface ViewContentFields extends CommonFields {
3
- name: string;
4
- path: string;
5
- }
6
- //# sourceMappingURL=ViewContentFields.d.ts.map
@@ -1,15 +0,0 @@
1
- export * from './Api/index.js';
2
- export * from './CommonFields.js';
3
- export * from './FunnelStartedFields.js';
4
- export * from './Pixel.js';
5
- export * from './PurchaseFields.js';
6
- export * from './Referrer.js';
7
- export * from './TestStartedFields.js';
8
- export * from './UniqueUserId.js';
9
- export * from './UserClickFields.js';
10
- export * from './UserEventHandler.js';
11
- export * from './UtmFields.js';
12
- export * from './ViewContentFields.js';
13
- export * from './XyLabsTrackingEventJson.js';
14
- export * from './XyUserEventHandler.js';
15
- //# sourceMappingURL=index.d.ts.map
package/eslint.config.mjs DELETED
@@ -1,43 +0,0 @@
1
- // eslint.config.mjs
2
-
3
- import {
4
- config as xylabsConfig, rulesConfig, importConfig,
5
- } from '@xylabs/eslint-config-flat'
6
-
7
- export default [
8
- { ignores: ['.yarn/**', 'jest.config.cjs', '**/dist/**', 'dist', 'build/**', 'node_modules/**', 'eslint.config.mjs'] },
9
- ...xylabsConfig,
10
- {
11
- rules: {
12
- 'no-restricted-imports': [
13
- 'warn',
14
- {
15
- paths: [
16
- ...rulesConfig.rules['no-restricted-imports'][1].paths,
17
- '@types/node',
18
- '@xyo-network/archivist',
19
- '@xyo-network/bridge',
20
- '@xyo-network/core',
21
- '@xyo-network/diviner',
22
- '@xyo-network/module',
23
- '@xyo-network/modules',
24
- '@xyo-network/node',
25
- '@xyo-network/sdk',
26
- '@xyo-network/plugins',
27
- '@xyo-network/protocol',
28
- '@xyo-network/sentinel',
29
- '@xyo-network/witness',
30
- '@xyo-network/core-payload-plugins',
31
- ],
32
- },
33
- ],
34
- },
35
- },
36
- {
37
- ...importConfig,
38
- rules: {
39
- ...importConfig.rules,
40
- 'import-x/no-cycle': ['warn', { maxDepth: 5 }],
41
- },
42
- },
43
- ]
package/jest.config.cjs DELETED
@@ -1,25 +0,0 @@
1
- const generateJestConfig = ({ esModules }) => {
2
- const esModulesList = Array.isArray(esModules) ? esModules.join('|') : esModules
3
- return {
4
- moduleNameMapper: {
5
- '^(\\.{1,2}/.*)\\.js$': '$1',
6
- },
7
- preset: 'ts-jest',
8
- testEnvironment: 'jsdom',
9
- testRegex: String.raw`(/__tests__/.*|(\.|/)(test|spec))\.tsx?$`,
10
- transform: {
11
- [`(${esModulesList}).+\\.js$`]: 'babel-jest',
12
- '^.+\\.tsx?$': [
13
- 'ts-jest',
14
- {
15
- tsconfig: 'tsconfig.test.json',
16
- useESM: true,
17
- },
18
- ],
19
- },
20
- transformIgnorePatterns: [`./node_modules/(?!${esModulesList})`],
21
- }
22
- }
23
-
24
- // eslint-disable-next-line no-undef
25
- module.exports = generateJestConfig({ esModules: ['is-ip', 'ip-regex'] })
package/vitest.config.ts DELETED
@@ -1,12 +0,0 @@
1
- import dotenv from 'dotenv'
2
- // eslint-disable-next-line import-x/no-internal-modules
3
- import { defineConfig } from 'vitest/config'
4
-
5
- dotenv.config()
6
-
7
- export default defineConfig({
8
- test: {
9
- globals: true,
10
- setupFiles: ['./vitest.startup.ts'],
11
- },
12
- })
package/vitest.startup.ts DELETED
@@ -1,8 +0,0 @@
1
- import * as matchers from 'jest-extended'
2
- import { expect, vi } from 'vitest'
3
-
4
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
- (globalThis as any).jest = vi // replace jest with vi
6
-
7
- // Extend Vitest's expect with jest-extended matchers
8
- expect.extend(matchers)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes