@croct/sdk 0.22.1 → 0.22.3

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 (67) hide show
  1. package/channel/httpBeaconChannel.cjs +12 -5
  2. package/channel/httpBeaconChannel.d.cts +5 -1
  3. package/channel/httpBeaconChannel.d.ts +5 -1
  4. package/channel/httpBeaconChannel.js +10 -4
  5. package/constants.cjs +1 -1
  6. package/constants.d.cts +2 -2
  7. package/constants.d.ts +2 -2
  8. package/constants.js +1 -1
  9. package/container.d.cts +3 -1
  10. package/container.d.ts +3 -1
  11. package/contentFetcher.cjs +22 -9
  12. package/contentFetcher.d.cts +19 -11
  13. package/contentFetcher.d.ts +19 -11
  14. package/contentFetcher.js +20 -8
  15. package/context.d.cts +2 -1
  16. package/context.d.ts +2 -1
  17. package/error.d.cts +8 -1
  18. package/error.d.ts +8 -1
  19. package/evaluator.cjs +62 -14
  20. package/evaluator.d.cts +35 -15
  21. package/evaluator.d.ts +35 -15
  22. package/evaluator.js +61 -14
  23. package/facade/contentFetcherFacade.d.cts +2 -0
  24. package/facade/contentFetcherFacade.d.ts +2 -0
  25. package/facade/evaluatorFacade.cjs +10 -18
  26. package/facade/evaluatorFacade.d.cts +2 -0
  27. package/facade/evaluatorFacade.d.ts +2 -0
  28. package/facade/evaluatorFacade.js +10 -18
  29. package/facade/index.d.cts +2 -0
  30. package/facade/index.d.ts +2 -0
  31. package/facade/sdkFacade.d.cts +3 -1
  32. package/facade/sdkFacade.d.ts +3 -1
  33. package/facade/sessionFacade.d.cts +1 -0
  34. package/facade/sessionFacade.d.ts +1 -0
  35. package/facade/sessionPatch.d.cts +1 -0
  36. package/facade/sessionPatch.d.ts +1 -0
  37. package/facade/trackerFacade.d.cts +1 -0
  38. package/facade/trackerFacade.d.ts +1 -0
  39. package/facade/userFacade.d.cts +1 -0
  40. package/facade/userFacade.d.ts +1 -0
  41. package/facade/userPatch.d.cts +1 -0
  42. package/facade/userPatch.d.ts +1 -0
  43. package/help.cjs +16 -4
  44. package/help.d.cts +4 -1
  45. package/help.d.ts +4 -1
  46. package/help.js +16 -4
  47. package/index.d.cts +2 -0
  48. package/index.d.ts +2 -0
  49. package/interactionMonitor.cjs +42 -9
  50. package/interactionMonitor.d.cts +1 -0
  51. package/interactionMonitor.d.ts +1 -0
  52. package/interactionMonitor.js +42 -9
  53. package/package.json +4 -4
  54. package/schema/ecommerceSchemas.cjs +1 -1
  55. package/schema/ecommerceSchemas.js +1 -1
  56. package/sdk.d.cts +3 -1
  57. package/sdk.d.ts +3 -1
  58. package/tab.cjs +2 -5
  59. package/tab.d.cts +2 -2
  60. package/tab.d.ts +2 -2
  61. package/tab.js +2 -5
  62. package/tracker.d.cts +1 -0
  63. package/tracker.d.ts +1 -0
  64. package/url.cjs +30 -0
  65. package/url.d.cts +12 -0
  66. package/url.d.ts +12 -0
  67. package/url.js +7 -0
package/help.js CHANGED
@@ -1,17 +1,29 @@
1
+ var AuthErrorType = /* @__PURE__ */ ((AuthErrorType2) => {
2
+ AuthErrorType2["FORBIDDEN_ORIGIN"] = "https://croct.help/api/authentication/forbidden-origin";
3
+ AuthErrorType2["QUOTA_EXCEEDED"] = "https://croct.help/api/authentication/quota-exceeded";
4
+ return AuthErrorType2;
5
+ })(AuthErrorType || {});
1
6
  var Help;
2
7
  ((Help2) => {
8
+ function forApiProblem(problem) {
9
+ switch (problem.type) {
10
+ case "https://croct.help/api/authentication/forbidden-origin" /* FORBIDDEN_ORIGIN */:
11
+ return "The origin of the request is not allowed in your application settings. For help, see https://croct.help/sdk/javascript/unauthorized-origin";
12
+ case "https://croct.help/api/authentication/quota-exceeded" /* QUOTA_EXCEEDED */:
13
+ return "The application has exceeded the monthly active users (MAU) quota. For help, see https://croct.help/sdk/javascript/mau-exceeded";
14
+ default:
15
+ return Help2.forStatusCode(problem.status);
16
+ }
17
+ }
18
+ Help2.forApiProblem = forApiProblem;
3
19
  function forStatusCode(statusCode) {
4
20
  switch (statusCode) {
5
21
  case 202:
6
22
  return "The service is temporarily suspended. For help, see https://croct.help/sdk/javascript/suspended-service";
7
23
  case 401:
8
24
  return "The request was not authorized, most likely due to invalid credentials. For help, see https://croct.help/sdk/javascript/invalid-credentials";
9
- case 403:
10
- return "The origin of the request is not allowed in your application settings. For help, see https://croct.help/sdk/javascript/unauthorized-origin";
11
25
  case 408:
12
26
  return "The request timed out. For help, see https://croct.help/sdk/javascript/request-timeout";
13
- case 423:
14
- return "The application has exceeded the monthly active users (MAU) quota. For help, see https://croct.help/sdk/javascript/mau-exceeded";
15
27
  default:
16
28
  return void 0;
17
29
  }
package/index.d.cts CHANGED
@@ -7,6 +7,7 @@ import './apiKey.cjs';
7
7
  import './cache/cache.cjs';
8
8
  import './tab.cjs';
9
9
  import './eventManager.cjs';
10
+ import './url.cjs';
10
11
  import './sdkEvents.cjs';
11
12
  import './logging/logger.cjs';
12
13
  import './tracker.cjs';
@@ -16,6 +17,7 @@ import './trackingEvents.cjs';
16
17
  import './patch.cjs';
17
18
  import './utilityTypes.cjs';
18
19
  import './evaluator.cjs';
20
+ import './error.cjs';
19
21
  import './sourceLocation.cjs';
20
22
  import './cid/assigner.cjs';
21
23
  import './contentFetcher.cjs';
package/index.d.ts CHANGED
@@ -7,6 +7,7 @@ import './apiKey.js';
7
7
  import './cache/cache.js';
8
8
  import './tab.js';
9
9
  import './eventManager.js';
10
+ import './url.js';
10
11
  import './sdkEvents.js';
11
12
  import './logging/logger.js';
12
13
  import './tracker.js';
@@ -16,6 +17,7 @@ import './trackingEvents.js';
16
17
  import './patch.js';
17
18
  import './utilityTypes.js';
18
19
  import './evaluator.js';
20
+ import './error.js';
19
21
  import './sourceLocation.js';
20
22
  import './cid/assigner.js';
21
23
  import './contentFetcher.js';
@@ -30,6 +30,7 @@ class InteractionMonitor {
30
30
  this.scrollDebounceInterval = options.scrollDebounceInterval ?? 250;
31
31
  this.handleClick = this.handleClick.bind(this);
32
32
  this.handleScroll = this.handleScroll.bind(this);
33
+ this.handleResize = this.handleResize.bind(this);
33
34
  }
34
35
  addListener(type, listener) {
35
36
  this.eventManager.addListener(type, listener);
@@ -47,6 +48,7 @@ class InteractionMonitor {
47
48
  this.enabled = true;
48
49
  window.addEventListener("click", this.handleClick, true);
49
50
  window.addEventListener("scroll", this.handleScroll, true);
51
+ window.addEventListener("resize", this.handleResize, true);
50
52
  }
51
53
  disable() {
52
54
  if (!this.enabled) {
@@ -55,6 +57,7 @@ class InteractionMonitor {
55
57
  this.enabled = false;
56
58
  window.removeEventListener("click", this.handleClick, true);
57
59
  window.removeEventListener("scroll", this.handleScroll, true);
60
+ window.removeEventListener("resize", this.handleResize, true);
58
61
  this.flushPendingScroll();
59
62
  }
60
63
  handleClick(event) {
@@ -75,22 +78,47 @@ class InteractionMonitor {
75
78
  }
76
79
  });
77
80
  }
81
+ handleResize() {
82
+ if (this.scrollDebounceTimer !== void 0) {
83
+ window.clearTimeout(this.scrollDebounceTimer);
84
+ this.scrollDebounceTimer = void 0;
85
+ }
86
+ const currentPosition = {
87
+ x: Math.max(0, Math.round(window.scrollX)),
88
+ y: Math.max(0, Math.round(window.scrollY))
89
+ };
90
+ const currentSurfaceSize = {
91
+ width: document.documentElement.scrollWidth,
92
+ height: document.documentElement.scrollHeight
93
+ };
94
+ this.scrollState = {
95
+ start: currentPosition,
96
+ lastPosition: currentPosition,
97
+ surfaceSize: currentSurfaceSize
98
+ };
99
+ }
78
100
  handleScroll() {
79
101
  const currentPosition = {
80
102
  x: Math.max(0, Math.round(window.scrollX)),
81
103
  y: Math.max(0, Math.round(window.scrollY))
82
104
  };
83
- if (this.scrollState === void 0) {
105
+ const currentSurfaceSize = {
106
+ width: document.documentElement.scrollWidth,
107
+ height: document.documentElement.scrollHeight
108
+ };
109
+ if (this.scrollState?.surfaceSize.width !== currentSurfaceSize.width || this.scrollState.surfaceSize.height !== currentSurfaceSize.height) {
84
110
  this.scrollState = {
85
111
  start: currentPosition,
86
- lastPosition: currentPosition
112
+ lastPosition: currentPosition,
113
+ surfaceSize: currentSurfaceSize
87
114
  };
88
115
  } else if (this.hasDirectionChanged(this.scrollState, currentPosition)) {
89
116
  const turningPoint = this.scrollState.lastPosition;
90
117
  this.flushPendingScroll(turningPoint);
91
118
  this.scrollState = {
92
119
  start: turningPoint,
93
- lastPosition: currentPosition
120
+ lastPosition: currentPosition,
121
+ surfaceSize: currentSurfaceSize
94
122
  };
95
123
  } else {
96
124
  this.scrollState.lastPosition = currentPosition;
@@ -148,12 +176,20 @@ class InteractionMonitor {
148
176
  if (this.scrollState === void 0) {
149
177
  return;
150
178
  }
151
- const { start } = this.scrollState;
179
+ const state = this.scrollState;
180
+ this.scrollState = void 0;
181
+ const currentSurfaceSize = {
182
+ width: document.documentElement.scrollWidth,
183
+ height: document.documentElement.scrollHeight
184
+ };
185
+ if (state.surfaceSize.width !== currentSurfaceSize.width || state.surfaceSize.height !== currentSurfaceSize.height) {
186
+ return;
187
+ }
188
+ const { start } = state;
152
189
  const destination = end ?? {
153
190
  x: Math.max(0, Math.round(window.scrollX)),
154
191
  y: Math.max(0, Math.round(window.scrollY))
155
192
  };
156
- this.scrollState = void 0;
157
193
  if (start.x === destination.x && start.y === destination.y) {
158
194
  return;
159
195
  }
@@ -161,10 +197,7 @@ class InteractionMonitor {
161
197
  type: "userScrolled",
162
198
  start,
163
199
  end: destination,
164
- surfaceSize: {
165
- width: document.documentElement.scrollWidth,
166
- height: document.documentElement.scrollHeight
167
- },
200
+ surfaceSize: state.surfaceSize,
168
201
  // Uses clientWidth/clientHeight instead of innerWidth/innerHeight to get the
169
202
  // layout viewport size, which remains stable regardless of pinch-to-zoom level
170
203
  // on mobile devices.
@@ -27,6 +27,7 @@ declare class InteractionMonitor {
27
27
  enable(): void;
28
28
  disable(): void;
29
29
  private handleClick;
30
+ private handleResize;
30
31
  private handleScroll;
31
32
  /**
32
33
  * Determines whether the scroll direction has reversed on either axis.
@@ -27,6 +27,7 @@ declare class InteractionMonitor {
27
27
  enable(): void;
28
28
  disable(): void;
29
29
  private handleClick;
30
+ private handleResize;
30
31
  private handleScroll;
31
32
  /**
32
33
  * Determines whether the scroll direction has reversed on either axis.
@@ -8,6 +8,7 @@ class InteractionMonitor {
8
8
  this.scrollDebounceInterval = options.scrollDebounceInterval ?? 250;
9
9
  this.handleClick = this.handleClick.bind(this);
10
10
  this.handleScroll = this.handleScroll.bind(this);
11
+ this.handleResize = this.handleResize.bind(this);
11
12
  }
12
13
  addListener(type, listener) {
13
14
  this.eventManager.addListener(type, listener);
@@ -25,6 +26,7 @@ class InteractionMonitor {
25
26
  this.enabled = true;
26
27
  window.addEventListener("click", this.handleClick, true);
27
28
  window.addEventListener("scroll", this.handleScroll, true);
29
+ window.addEventListener("resize", this.handleResize, true);
28
30
  }
29
31
  disable() {
30
32
  if (!this.enabled) {
@@ -33,6 +35,7 @@ class InteractionMonitor {
33
35
  this.enabled = false;
34
36
  window.removeEventListener("click", this.handleClick, true);
35
37
  window.removeEventListener("scroll", this.handleScroll, true);
38
+ window.removeEventListener("resize", this.handleResize, true);
36
39
  this.flushPendingScroll();
37
40
  }
38
41
  handleClick(event) {
@@ -53,22 +56,47 @@ class InteractionMonitor {
53
56
  }
54
57
  });
55
58
  }
59
+ handleResize() {
60
+ if (this.scrollDebounceTimer !== void 0) {
61
+ window.clearTimeout(this.scrollDebounceTimer);
62
+ this.scrollDebounceTimer = void 0;
63
+ }
64
+ const currentPosition = {
65
+ x: Math.max(0, Math.round(window.scrollX)),
66
+ y: Math.max(0, Math.round(window.scrollY))
67
+ };
68
+ const currentSurfaceSize = {
69
+ width: document.documentElement.scrollWidth,
70
+ height: document.documentElement.scrollHeight
71
+ };
72
+ this.scrollState = {
73
+ start: currentPosition,
74
+ lastPosition: currentPosition,
75
+ surfaceSize: currentSurfaceSize
76
+ };
77
+ }
56
78
  handleScroll() {
57
79
  const currentPosition = {
58
80
  x: Math.max(0, Math.round(window.scrollX)),
59
81
  y: Math.max(0, Math.round(window.scrollY))
60
82
  };
61
- if (this.scrollState === void 0) {
83
+ const currentSurfaceSize = {
84
+ width: document.documentElement.scrollWidth,
85
+ height: document.documentElement.scrollHeight
86
+ };
87
+ if (this.scrollState?.surfaceSize.width !== currentSurfaceSize.width || this.scrollState.surfaceSize.height !== currentSurfaceSize.height) {
62
88
  this.scrollState = {
63
89
  start: currentPosition,
64
- lastPosition: currentPosition
90
+ lastPosition: currentPosition,
91
+ surfaceSize: currentSurfaceSize
65
92
  };
66
93
  } else if (this.hasDirectionChanged(this.scrollState, currentPosition)) {
67
94
  const turningPoint = this.scrollState.lastPosition;
68
95
  this.flushPendingScroll(turningPoint);
69
96
  this.scrollState = {
70
97
  start: turningPoint,
71
- lastPosition: currentPosition
98
+ lastPosition: currentPosition,
99
+ surfaceSize: currentSurfaceSize
72
100
  };
73
101
  } else {
74
102
  this.scrollState.lastPosition = currentPosition;
@@ -126,12 +154,20 @@ class InteractionMonitor {
126
154
  if (this.scrollState === void 0) {
127
155
  return;
128
156
  }
129
- const { start } = this.scrollState;
157
+ const state = this.scrollState;
158
+ this.scrollState = void 0;
159
+ const currentSurfaceSize = {
160
+ width: document.documentElement.scrollWidth,
161
+ height: document.documentElement.scrollHeight
162
+ };
163
+ if (state.surfaceSize.width !== currentSurfaceSize.width || state.surfaceSize.height !== currentSurfaceSize.height) {
164
+ return;
165
+ }
166
+ const { start } = state;
130
167
  const destination = end ?? {
131
168
  x: Math.max(0, Math.round(window.scrollX)),
132
169
  y: Math.max(0, Math.round(window.scrollY))
133
170
  };
134
- this.scrollState = void 0;
135
171
  if (start.x === destination.x && start.y === destination.y) {
136
172
  return;
137
173
  }
@@ -139,10 +175,7 @@ class InteractionMonitor {
139
175
  type: "userScrolled",
140
176
  start,
141
177
  end: destination,
142
- surfaceSize: {
143
- width: document.documentElement.scrollWidth,
144
- height: document.documentElement.scrollHeight
145
- },
178
+ surfaceSize: state.surfaceSize,
146
179
  // Uses clientWidth/clientHeight instead of innerWidth/innerHeight to get the
147
180
  // layout viewport size, which remains stable regardless of pinch-to-zoom level
148
181
  // on mobile devices.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/sdk",
3
- "version": "0.22.1",
3
+ "version": "0.22.3",
4
4
  "description": "Croct SDK for JavaScript.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -88,17 +88,17 @@
88
88
  "@croct/eslint-plugin": "^0.8.3",
89
89
  "@eslint/eslintrc": "^3.3.3",
90
90
  "@fetch-mock/jest": "^0.2.20",
91
- "@typescript-eslint/parser": "^8.53.0",
92
91
  "@types/jest": "^30.0.0",
92
+ "@typescript-eslint/parser": "^8.53.0",
93
93
  "esbuild-fix-imports-plugin": "^1.0.19",
94
94
  "eslint": "^9.39.0",
95
95
  "fetch-mock": "^12.6.0",
96
96
  "jest": "^30.0.0",
97
97
  "jest-environment-jsdom": "^30.0.0",
98
98
  "jest-extended": "^7.0.0",
99
- "ts-jest": "^29.0.3",
99
+ "ts-jest": "^29.4.9",
100
100
  "tsup": "^8.4.0",
101
- "typescript": "^5.0.0"
101
+ "typescript": "^6.0.0"
102
102
  },
103
103
  "files": [
104
104
  "**/*.js",
@@ -198,7 +198,7 @@ const order = new import_validation.ObjectType({
198
198
  minimum: 1
199
199
  }),
200
200
  status: new import_validation.StringType({
201
- enumeration: ["placed", "paid", "complete"]
201
+ enumeration: ["placed", "paid", "completed"]
202
202
  })
203
203
  }
204
204
  });
@@ -172,7 +172,7 @@ const order = new ObjectType({
172
172
  minimum: 1
173
173
  }),
174
174
  status: new StringType({
175
- enumeration: ["placed", "paid", "complete"]
175
+ enumeration: ["placed", "paid", "completed"]
176
176
  })
177
177
  }
178
178
  });
package/sdk.d.cts CHANGED
@@ -5,17 +5,19 @@ import { Evaluator } from './evaluator.cjs';
5
5
  import { SdkEventMap } from './sdkEvents.cjs';
6
6
  import { EventManager } from './eventManager.cjs';
7
7
  import { CidAssigner } from './cid/assigner.cjs';
8
- import { UrlSanitizer } from './tab.cjs';
8
+ import { UrlSanitizer } from './url.cjs';
9
9
  import { ContentFetcher } from './contentFetcher.cjs';
10
10
  import { TokenStore } from './token/token.cjs';
11
11
  import { CookieCacheConfiguration } from './cache/cookieCache.cjs';
12
12
  import './cache/cache.cjs';
13
+ import './tab.cjs';
13
14
  import './channel/channel.cjs';
14
15
  import './retry/policy.cjs';
15
16
  import './trackingEvents.cjs';
16
17
  import './patch.cjs';
17
18
  import '@croct/json';
18
19
  import './utilityTypes.cjs';
20
+ import './error.cjs';
19
21
  import './sourceLocation.cjs';
20
22
  import './apiKey.cjs';
21
23
  import '@croct/content-model/definition';
package/sdk.d.ts CHANGED
@@ -5,17 +5,19 @@ import { Evaluator } from './evaluator.js';
5
5
  import { SdkEventMap } from './sdkEvents.js';
6
6
  import { EventManager } from './eventManager.js';
7
7
  import { CidAssigner } from './cid/assigner.js';
8
- import { UrlSanitizer } from './tab.js';
8
+ import { UrlSanitizer } from './url.js';
9
9
  import { ContentFetcher } from './contentFetcher.js';
10
10
  import { TokenStore } from './token/token.js';
11
11
  import { CookieCacheConfiguration } from './cache/cookieCache.js';
12
12
  import './cache/cache.js';
13
+ import './tab.js';
13
14
  import './channel/channel.js';
14
15
  import './retry/policy.js';
15
16
  import './trackingEvents.js';
16
17
  import './patch.js';
17
18
  import '@croct/json';
18
19
  import './utilityTypes.js';
20
+ import './error.js';
19
21
  import './sourceLocation.js';
20
22
  import './apiKey.js';
21
23
  import '@croct/content-model/definition';
package/tab.cjs CHANGED
@@ -21,6 +21,7 @@ __export(tab_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(tab_exports);
23
23
  var import_eventManager = require('./eventManager.cjs');
24
+ var import_url = require('./url.cjs');
24
25
  const EventMap = {
25
26
  focus: "focus",
26
27
  blur: "blur",
@@ -82,11 +83,7 @@ class Tab {
82
83
  this.eventManager.removeListener(type, listener);
83
84
  }
84
85
  sanitizeUrl(url) {
85
- const normalized = window.encodeURI(window.decodeURI(url));
86
- if (this.urlSanitizer !== void 0) {
87
- return this.urlSanitizer(normalized).toString();
88
- }
89
- return normalized;
86
+ return (0, import_url.sanitizeUrl)(url, this.urlSanitizer);
90
87
  }
91
88
  emit(type, event) {
92
89
  this.eventManager.dispatch(type, event);
package/tab.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { EventListener } from './eventManager.cjs';
2
+ import { UrlSanitizer } from './url.cjs';
2
3
 
3
4
  type TabEvent<T = Record<string, unknown>> = CustomEvent<{
4
5
  tab: Tab;
@@ -9,7 +10,6 @@ type TabVisibilityChangeEvent = TabEvent<{
9
10
  type TabUrlChangeEvent = TabEvent<{
10
11
  url: string;
11
12
  }>;
12
- type UrlSanitizer = (url: string) => URL;
13
13
  type TabEventMap = {
14
14
  focus: TabEvent;
15
15
  blur: TabEvent;
@@ -37,4 +37,4 @@ declare class Tab {
37
37
  private static addUrlChangeListener;
38
38
  }
39
39
 
40
- export { Tab, type TabEvent, type TabUrlChangeEvent, type TabVisibilityChangeEvent, type UrlSanitizer };
40
+ export { Tab, type TabEvent, type TabUrlChangeEvent, type TabVisibilityChangeEvent, UrlSanitizer };
package/tab.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { EventListener } from './eventManager.js';
2
+ import { UrlSanitizer } from './url.js';
2
3
 
3
4
  type TabEvent<T = Record<string, unknown>> = CustomEvent<{
4
5
  tab: Tab;
@@ -9,7 +10,6 @@ type TabVisibilityChangeEvent = TabEvent<{
9
10
  type TabUrlChangeEvent = TabEvent<{
10
11
  url: string;
11
12
  }>;
12
- type UrlSanitizer = (url: string) => URL;
13
13
  type TabEventMap = {
14
14
  focus: TabEvent;
15
15
  blur: TabEvent;
@@ -37,4 +37,4 @@ declare class Tab {
37
37
  private static addUrlChangeListener;
38
38
  }
39
39
 
40
- export { Tab, type TabEvent, type TabUrlChangeEvent, type TabVisibilityChangeEvent, type UrlSanitizer };
40
+ export { Tab, type TabEvent, type TabUrlChangeEvent, type TabVisibilityChangeEvent, UrlSanitizer };
package/tab.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { SynchronousEventManager } from "./eventManager.js";
2
+ import { sanitizeUrl } from "./url.js";
2
3
  const EventMap = {
3
4
  focus: "focus",
4
5
  blur: "blur",
@@ -60,11 +61,7 @@ class Tab {
60
61
  this.eventManager.removeListener(type, listener);
61
62
  }
62
63
  sanitizeUrl(url) {
63
- const normalized = window.encodeURI(window.decodeURI(url));
64
- if (this.urlSanitizer !== void 0) {
65
- return this.urlSanitizer(normalized).toString();
66
- }
67
- return normalized;
64
+ return sanitizeUrl(url, this.urlSanitizer);
68
65
  }
69
66
  emit(type, event) {
70
67
  this.eventManager.dispatch(type, event);
package/tracker.d.cts CHANGED
@@ -5,6 +5,7 @@ import { RetryPolicy } from './retry/policy.cjs';
5
5
  import { TokenProvider, Token } from './token/token.cjs';
6
6
  import { Beacon, TrackingEvent, TrackingEventContext, PartialTrackingEvent } from './trackingEvents.cjs';
7
7
  import './eventManager.cjs';
8
+ import './url.cjs';
8
9
  import '@croct/json';
9
10
  import './apiKey.cjs';
10
11
  import './patch.cjs';
package/tracker.d.ts CHANGED
@@ -5,6 +5,7 @@ import { RetryPolicy } from './retry/policy.js';
5
5
  import { TokenProvider, Token } from './token/token.js';
6
6
  import { Beacon, TrackingEvent, TrackingEventContext, PartialTrackingEvent } from './trackingEvents.js';
7
7
  import './eventManager.js';
8
+ import './url.js';
8
9
  import '@croct/json';
9
10
  import './apiKey.js';
10
11
  import './patch.js';
package/url.cjs ADDED
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var url_exports = {};
19
+ __export(url_exports, {
20
+ sanitizeUrl: () => sanitizeUrl
21
+ });
22
+ module.exports = __toCommonJS(url_exports);
23
+ function sanitizeUrl(url, sanitizer) {
24
+ const normalizedUrl = encodeURI(decodeURI(url));
25
+ return sanitizer !== void 0 ? sanitizer(normalizedUrl).toString() : normalizedUrl;
26
+ }
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ sanitizeUrl
30
+ });
package/url.d.cts ADDED
@@ -0,0 +1,12 @@
1
+ type UrlSanitizer = (url: string) => URL;
2
+ /**
3
+ * Normalizes the URL and sanitizes it, if a sanitizer is given.
4
+ *
5
+ * @param url The URL to sanitize.
6
+ * @param sanitizer The sanitizer to apply to the normalized URL.
7
+ *
8
+ * @returns The sanitized URL.
9
+ */
10
+ declare function sanitizeUrl(url: string, sanitizer?: UrlSanitizer): string;
11
+
12
+ export { type UrlSanitizer, sanitizeUrl };
package/url.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ type UrlSanitizer = (url: string) => URL;
2
+ /**
3
+ * Normalizes the URL and sanitizes it, if a sanitizer is given.
4
+ *
5
+ * @param url The URL to sanitize.
6
+ * @param sanitizer The sanitizer to apply to the normalized URL.
7
+ *
8
+ * @returns The sanitized URL.
9
+ */
10
+ declare function sanitizeUrl(url: string, sanitizer?: UrlSanitizer): string;
11
+
12
+ export { type UrlSanitizer, sanitizeUrl };
package/url.js ADDED
@@ -0,0 +1,7 @@
1
+ function sanitizeUrl(url, sanitizer) {
2
+ const normalizedUrl = encodeURI(decodeURI(url));
3
+ return sanitizer !== void 0 ? sanitizer(normalizedUrl).toString() : normalizedUrl;
4
+ }
5
+ export {
6
+ sanitizeUrl
7
+ };