@haakco/custd-sdk 2.4.0 → 3.71.2

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 (183) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +586 -40
  3. package/dist/admin-accounting-evidence.d.ts +48 -0
  4. package/dist/admin-accounting-evidence.js +24 -0
  5. package/dist/admin-app-releases.d.ts +116 -0
  6. package/dist/admin-app-releases.js +8 -0
  7. package/dist/admin-apps.d.ts +120 -0
  8. package/dist/admin-apps.js +47 -0
  9. package/dist/admin-auth-project-domain.d.ts +125 -0
  10. package/dist/admin-auth-project-domain.js +37 -0
  11. package/dist/admin-auth-projects.d.ts +989 -0
  12. package/dist/admin-auth-projects.js +527 -0
  13. package/dist/admin-campaign-email.d.ts +120 -0
  14. package/dist/admin-campaign-email.js +64 -0
  15. package/dist/admin-client-setup.d.ts +22 -0
  16. package/dist/admin-client-setup.js +11 -1
  17. package/dist/admin-data-scopes.d.ts +93 -0
  18. package/dist/admin-data-scopes.js +154 -0
  19. package/dist/admin-email-relay.d.ts +66 -0
  20. package/dist/admin-email-relay.js +25 -0
  21. package/dist/admin-environment-policy.d.ts +32 -0
  22. package/dist/admin-environment-policy.js +26 -0
  23. package/dist/admin-error-issues.d.ts +91 -0
  24. package/dist/admin-error-issues.js +52 -0
  25. package/dist/admin-event-types.d.ts +57 -0
  26. package/dist/admin-event-types.js +28 -0
  27. package/dist/admin-impersonation.d.ts +48 -0
  28. package/dist/admin-impersonation.js +27 -0
  29. package/dist/admin-ingest-claims.d.ts +35 -0
  30. package/dist/admin-ingest-claims.js +26 -0
  31. package/dist/admin-managed-audit.d.ts +13 -0
  32. package/dist/admin-managed-audit.js +13 -0
  33. package/dist/admin-measurement-projects.d.ts +166 -0
  34. package/dist/admin-measurement-projects.js +120 -0
  35. package/dist/admin-notification-destinations.d.ts +31 -0
  36. package/dist/admin-notification-destinations.js +19 -0
  37. package/dist/admin-notification-webhooks.d.ts +64 -0
  38. package/dist/admin-notification-webhooks.js +42 -0
  39. package/dist/admin-oauth-client-admissions.d.ts +65 -0
  40. package/dist/admin-oauth-client-admissions.js +46 -0
  41. package/dist/admin-offboarding.d.ts +20 -6
  42. package/dist/admin-offboarding.js +27 -6
  43. package/dist/admin-predictions.d.ts +127 -8
  44. package/dist/admin-predictions.js +22 -12
  45. package/dist/admin-privacy-erasures.d.ts +24 -12
  46. package/dist/admin-privacy-erasures.js +3 -2
  47. package/dist/admin-retention.d.ts +72 -24
  48. package/dist/admin-retention.js +38 -13
  49. package/dist/admin-rls.d.ts +94 -0
  50. package/dist/admin-rls.js +33 -0
  51. package/dist/admin-sdk-usage.d.ts +41 -0
  52. package/dist/admin-sdk-usage.js +23 -0
  53. package/dist/admin-site-ai.d.ts +72 -0
  54. package/dist/admin-site-ai.js +1 -0
  55. package/dist/admin-site-analytics.d.ts +52 -0
  56. package/dist/admin-site-analytics.js +14 -0
  57. package/dist/admin-site-audit-pages.d.ts +76 -0
  58. package/dist/admin-site-audit-pages.js +27 -0
  59. package/dist/admin-site-campaign-links.d.ts +40 -0
  60. package/dist/admin-site-campaign-links.js +9 -0
  61. package/dist/admin-site-domains.d.ts +733 -0
  62. package/dist/admin-site-domains.js +768 -0
  63. package/dist/admin-site-export.d.ts +76 -0
  64. package/dist/admin-site-export.js +15 -0
  65. package/dist/admin-site-insights-tasks.d.ts +44 -0
  66. package/dist/admin-site-insights-tasks.js +28 -0
  67. package/dist/admin-site-insights.d.ts +527 -0
  68. package/dist/admin-site-insights.js +61 -0
  69. package/dist/admin-site-links.d.ts +87 -0
  70. package/dist/admin-site-links.js +16 -0
  71. package/dist/admin-site-monitors.d.ts +110 -0
  72. package/dist/admin-site-monitors.js +25 -0
  73. package/dist/admin-site-next-actions.d.ts +93 -0
  74. package/dist/admin-site-next-actions.js +36 -0
  75. package/dist/admin-site-page-queries.d.ts +63 -0
  76. package/dist/admin-site-page-queries.js +20 -0
  77. package/dist/admin-site-rankings.d.ts +98 -0
  78. package/dist/admin-site-rankings.js +46 -0
  79. package/dist/admin-site-regional-trends.d.ts +30 -0
  80. package/dist/admin-site-regional-trends.js +1 -0
  81. package/dist/admin-site-saved-reports.d.ts +45 -0
  82. package/dist/admin-site-saved-reports.js +13 -0
  83. package/dist/admin-site-search-pool.d.ts +77 -0
  84. package/dist/admin-site-search-pool.js +41 -0
  85. package/dist/admin-site-search-value.d.ts +97 -0
  86. package/dist/admin-site-search-value.js +29 -0
  87. package/dist/admin-site-status-page.d.ts +57 -0
  88. package/dist/admin-site-status-page.js +10 -0
  89. package/dist/admin-site-traffic.d.ts +145 -0
  90. package/dist/admin-site-traffic.js +32 -0
  91. package/dist/admin-site-web-data.d.ts +258 -0
  92. package/dist/admin-site-web-data.js +60 -0
  93. package/dist/admin-subject-exports.d.ts +58 -27
  94. package/dist/admin-subject-exports.js +32 -16
  95. package/dist/admin-support-access.d.ts +32 -0
  96. package/dist/admin-support-access.js +21 -0
  97. package/dist/admin-system.d.ts +283 -0
  98. package/dist/admin-system.js +65 -0
  99. package/dist/admin-tenant-storage.d.ts +22 -14
  100. package/dist/admin-tenant-storage.js +13 -14
  101. package/dist/admin-timeplans.d.ts +276 -2
  102. package/dist/admin-timeplans.js +54 -0
  103. package/dist/admin-uncertainty-models.d.ts +42 -0
  104. package/dist/admin-uncertainty-models.js +53 -0
  105. package/dist/admin-usage.d.ts +124 -0
  106. package/dist/admin-usage.js +169 -0
  107. package/dist/admin-users.d.ts +124 -0
  108. package/dist/admin-users.js +82 -0
  109. package/dist/admin-workflow-timings.d.ts +367 -0
  110. package/dist/admin-workflow-timings.js +117 -0
  111. package/dist/analytics-events.d.ts +82 -0
  112. package/dist/analytics-events.js +157 -0
  113. package/dist/analytics-reads.d.ts +81 -0
  114. package/dist/analytics-reads.js +5 -0
  115. package/dist/app-account.d.ts +84 -0
  116. package/dist/app-account.js +177 -0
  117. package/dist/app-alerts.d.ts +120 -0
  118. package/dist/app-alerts.js +44 -0
  119. package/dist/app-items.d.ts +786 -0
  120. package/dist/app-items.js +524 -0
  121. package/dist/app-live.d.ts +84 -0
  122. package/dist/app-live.js +228 -0
  123. package/dist/app-meetings.d.ts +95 -0
  124. package/dist/app-meetings.js +26 -0
  125. package/dist/app-models.d.ts +271 -0
  126. package/dist/app-models.js +83 -0
  127. package/dist/app-push.d.ts +64 -0
  128. package/dist/app-push.js +178 -0
  129. package/dist/backend-lifecycle.d.ts +2 -2
  130. package/dist/browser-manifest.json +5 -5
  131. package/dist/browser-script-BWnwDjAC.js +711 -0
  132. package/dist/browser-sign-in.d.ts +153 -0
  133. package/dist/browser-sign-in.js +410 -0
  134. package/dist/browser-tracker.d.ts +95 -0
  135. package/dist/browser-tracker.js +362 -40
  136. package/dist/browser-web-vitals.d.ts +22 -0
  137. package/dist/browser-web-vitals.js +116 -0
  138. package/dist/browser.d.ts +9 -0
  139. package/dist/browser.js +9 -0
  140. package/dist/download-stream.d.ts +16 -0
  141. package/dist/download-stream.js +55 -0
  142. package/dist/error-capture.d.ts +62 -0
  143. package/dist/error-capture.js +168 -0
  144. package/dist/hosted-app.d.ts +115 -0
  145. package/dist/hosted-app.js +275 -0
  146. package/dist/index.d.ts +1168 -154
  147. package/dist/index.js +682 -162
  148. package/dist/ingest-operations.d.ts +483 -0
  149. package/dist/ingest-operations.js +154 -0
  150. package/dist/measurement.d.ts +164 -0
  151. package/dist/measurement.js +104 -0
  152. package/dist/parsers.d.ts +149 -0
  153. package/dist/parsers.js +115 -0
  154. package/dist/public-reads.d.ts +79 -0
  155. package/dist/public-reads.js +57 -0
  156. package/dist/reporting-catalogue.d.ts +264 -0
  157. package/dist/reporting-catalogue.js +5 -0
  158. package/dist/response-lists.d.ts +16 -0
  159. package/dist/response-lists.generated.d.ts +7 -0
  160. package/dist/response-lists.generated.js +1927 -0
  161. package/dist/response-lists.js +70 -0
  162. package/dist/response-validation.d.ts +30 -0
  163. package/dist/response-validation.js +94 -0
  164. package/dist/schema-registry.d.ts +45 -0
  165. package/dist/schema-registry.js +9 -0
  166. package/dist/secure-url.d.ts +4 -0
  167. package/dist/secure-url.js +23 -0
  168. package/dist/site-ai-owner.d.ts +34 -0
  169. package/dist/site-ai-owner.js +99 -0
  170. package/dist/site-monitor-reports.d.ts +15 -0
  171. package/dist/site-monitor-reports.js +87 -0
  172. package/dist/testing/fake-custd.d.ts +150 -0
  173. package/dist/testing/fake-custd.js +842 -0
  174. package/dist/testing/fake-results.d.ts +30 -0
  175. package/dist/testing/fake-results.js +293 -0
  176. package/dist/testing.d.ts +2 -0
  177. package/dist/testing.js +3 -0
  178. package/dist/version.d.ts +2 -2
  179. package/dist/version.js +1 -1
  180. package/package.json +25 -14
  181. package/dist/browser-script-BvgjdZSO.js +0 -429
  182. package/dist/fixtures.d.ts +0 -10
  183. package/dist/fixtures.js +0 -57
@@ -1,429 +0,0 @@
1
- //#endregion
2
- //#region src/index.ts
3
- var e = class {
4
- constructor() {
5
- this.events = [];
6
- }
7
- load() {
8
- return [...this.events];
9
- }
10
- save(e) {
11
- this.events = [...e];
12
- }
13
- clear() {
14
- this.events = [];
15
- }
16
- }, t = class {
17
- constructor(e = "custd_event_queue") {
18
- this.key = e;
19
- }
20
- load() {
21
- if (typeof localStorage > "u") return [];
22
- let e = localStorage.getItem(this.key);
23
- if (!e) return [];
24
- try {
25
- let t = JSON.parse(e);
26
- if (Array.isArray(t)) return t;
27
- } catch {
28
- return [];
29
- }
30
- return [];
31
- }
32
- save(e) {
33
- typeof localStorage > "u" || localStorage.setItem(this.key, JSON.stringify(e));
34
- }
35
- clear() {
36
- typeof localStorage > "u" || localStorage.removeItem(this.key);
37
- }
38
- }, n = /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/, r = "custd.environment", i = /^[a-z][a-z0-9-]{0,31}$/;
39
- function a(e) {
40
- if (e !== "") {
41
- if (e !== e.trim() || !i.test(e)) throw Error(`custd: environment ${JSON.stringify(e)} must be lowercase letters, digits and hyphens, at most 32 characters`);
42
- if (e === "unclassified") throw Error("custd: environment \"unclassified\" is reserved");
43
- }
44
- }
45
- function o(e, t) {
46
- let n = e.environment || t || "";
47
- n !== "" && (e.labels = { ...e.labels ?? {} }, e.labels["custd.environment"] === void 0 && (e.labels[r] = n));
48
- }
49
- function s(e) {
50
- if ("resolvedLabels" in e || "vocabularyFingerprint" in e) throw Error("custd: server-owned label fields are not accepted");
51
- if (e.labels === void 0) return;
52
- if (e.labels === null || typeof e.labels != "object" || Array.isArray(e.labels)) throw Error("custd: labels must be an object of strings");
53
- let t = Object.entries(e.labels);
54
- if (t.length > 16) throw Error("custd: labels may contain at most 16 entries");
55
- for (let [e, r] of t) {
56
- if (!n.test(e) || c(e) > 64 || e.startsWith("custd.")) throw Error(`custd: labels.${e} has an invalid key`);
57
- if (typeof r != "string" || r === "" || r !== r.trim() || c(r) > 128) throw Error(`custd: labels.${e} has an invalid value`);
58
- }
59
- }
60
- function c(e) {
61
- return new TextEncoder().encode(e).length;
62
- }
63
- function l(e) {
64
- let t = [];
65
- if (e.eventUuid || t.push("eventUuid"), e.eventTypeSlug || t.push("eventTypeSlug"), e.schemaVersion || t.push("schemaVersion"), e.timestamp || t.push("timestamp"), e.context || t.push("context"), e.payload || t.push("payload"), e.payload?.siteUuid || t.push("payload.siteUuid"), e.context?.device?.type || t.push("context.device.type"), t.length > 0) throw Error(`custd: missing required browser fields: ${t.join(", ")}`);
66
- a(e.environment ?? ""), s(e);
67
- }
68
- function u(e, t = {}) {
69
- return t.mode === "browser-cookieless" ? {
70
- ...e,
71
- eventUuid: e.eventUuid || g(),
72
- sessionId: e.sessionId ?? "",
73
- anonymousId: e.anonymousId ?? ""
74
- } : {
75
- ...e,
76
- eventUuid: e.eventUuid || g(),
77
- sessionId: e.sessionId || g(),
78
- anonymousId: e.anonymousId || g()
79
- };
80
- }
81
- var d = class extends Error {};
82
- function f(e) {
83
- return {
84
- maxAttempts: e?.maxAttempts ?? 3,
85
- baseDelayMs: e?.baseDelayMs ?? 200,
86
- maxDelayMs: e?.maxDelayMs ?? 2e3,
87
- jitter: e?.jitter ?? .2,
88
- retryOnStatuses: e?.retryOnStatuses ?? [
89
- 408,
90
- 429,
91
- 500,
92
- 502,
93
- 503,
94
- 504
95
- ]
96
- };
97
- }
98
- async function p(e, t) {
99
- let n = 0;
100
- for (;;) {
101
- n++;
102
- try {
103
- return await t();
104
- } catch (t) {
105
- if (!(t instanceof d || t instanceof TypeError) || n >= e.maxAttempts) throw t;
106
- await h(m(e, n));
107
- }
108
- }
109
- }
110
- function m(e, t) {
111
- let n = e.baseDelayMs * 2 ** (t - 1), r = Math.min(n, e.maxDelayMs), i = r * e.jitter * (Math.random() * 2 - 1);
112
- return Math.max(0, r + i);
113
- }
114
- function h(e) {
115
- return new Promise((t) => setTimeout(t, e));
116
- }
117
- function g() {
118
- return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (e) => (Number(e) ^ Math.random() * 16 >> Number(e) / 4).toString(16));
119
- }
120
- //#endregion
121
- //#region src/browser-tracker.ts
122
- var _ = "1.0.0", v = 1e3, y = "[redacted]", b = /^[A-Za-z][A-Za-z0-9._~-]{0,63}$/u, x = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu, S = /^[A-Za-z0-9_-]{24,}$/u, C = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/u;
123
- function w(e) {
124
- return new T(e);
125
- }
126
- var T = class {
127
- constructor(e) {
128
- this.queue = [], this.installedSpaTracking = !1, this.originalPushState = null, this.originalReplaceState = null, this.onlineHandler = () => void this.flush(), this.pagehideHandler = () => this.flushWithKeepalive(), this.popstateHandler = () => void this.trackPageView(), this.config = e, this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.queueStorage = e.queueStorage ?? W(e.siteUuid, e.persistentQueue === !0), this.retry = f(e.retry), this.maxQueueSize = e.maxQueueSize ?? 1e3, this.queue = this.queueStorage.load(), this.trimQueue(), this.consent = e.consent === "required" ? "denied" : "granted", this.trackingDisabled() && this.clearStoredState(), Z(this.baseUrl, "baseUrl"), ee(e), window.addEventListener("online", this.onlineHandler), window.addEventListener("pagehide", this.pagehideHandler);
129
- }
130
- async track(e, t = {}) {
131
- if (this.trackingDisabled()) return;
132
- let n = this.buildEvent(e, t);
133
- if ((this.config.batchSize ?? 0) > 1) {
134
- this.enqueue(n), this.queue.length >= (this.config.batchSize ?? 0) && await this.flush();
135
- return;
136
- }
137
- await this.sendEvent(n);
138
- }
139
- trackPageView() {
140
- return this.track("page-view", M());
141
- }
142
- installSpaTracking() {
143
- this.installedSpaTracking || (this.installedSpaTracking = !0, this.originalPushState = window.history.pushState, this.originalReplaceState = window.history.replaceState, window.history.pushState = this.wrapHistoryMethod(this.originalPushState), window.history.replaceState = this.wrapHistoryMethod(this.originalReplaceState), window.addEventListener("popstate", this.popstateHandler), this.config.trackInitialPageView !== !1 && this.trackPageView());
144
- }
145
- setConsent(e) {
146
- this.consent = e, e === "denied" && this.clearStoredState();
147
- }
148
- async flush() {
149
- if (this.trackingDisabled()) {
150
- this.clearStoredState();
151
- return;
152
- }
153
- if (this.queue.length === 0 || !Y()) return;
154
- let e = this.queue.splice(0, this.queue.length);
155
- try {
156
- await this.sendBatch(e);
157
- } catch (t) {
158
- throw this.queue.unshift(...e), this.trimQueue(), this.queueStorage.save(this.queue), t;
159
- }
160
- this.queueStorage.save(this.queue);
161
- }
162
- close() {
163
- window.removeEventListener("online", this.onlineHandler), window.removeEventListener("pagehide", this.pagehideHandler), window.removeEventListener("popstate", this.popstateHandler), this.originalPushState && (window.history.pushState = this.originalPushState), this.originalReplaceState && (window.history.replaceState = this.originalReplaceState), this.installedSpaTracking = !1, this.originalPushState = null, this.originalReplaceState = null;
164
- }
165
- wrapHistoryMethod(e) {
166
- return ((...t) => {
167
- let n = e.apply(window.history, t);
168
- return this.trackPageView(), n;
169
- });
170
- }
171
- trackingDisabled() {
172
- return !!(this.consent !== "granted" || J());
173
- }
174
- enqueue(e) {
175
- this.queue.push(e), this.trimQueue(), this.queueStorage.save(this.queue);
176
- }
177
- trimQueue() {
178
- this.queue.length > this.maxQueueSize && (this.queue = this.queue.slice(this.queue.length - this.maxQueueSize));
179
- }
180
- clearStoredState() {
181
- this.queue = [], this.queueStorage.clear(), typeof localStorage < "u" && (localStorage.removeItem(E(this.config.siteUuid)), localStorage.removeItem(O(this.config.siteUuid))), typeof sessionStorage < "u" && sessionStorage.removeItem(D(this.config.siteUuid));
182
- }
183
- buildEvent(e, t) {
184
- let n = this.identityFields(), r = u({
185
- eventTypeSlug: e,
186
- schemaVersion: _,
187
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
188
- ...n,
189
- context: j(),
190
- payload: {
191
- siteUuid: this.config.siteUuid,
192
- ...t
193
- }
194
- }, { mode: this.config.identityMode === "extended" ? "producer" : "browser-cookieless" });
195
- return l(r), o(r, this.config.environment), r;
196
- }
197
- identityFields() {
198
- return this.config.identityMode === "extended" ? {
199
- anonymousId: U(E(this.config.siteUuid), localStorage),
200
- sessionId: U(D(this.config.siteUuid), sessionStorage)
201
- } : {
202
- anonymousId: "",
203
- sessionId: ""
204
- };
205
- }
206
- async sendEvent(e) {
207
- await p(this.retry, async () => {
208
- I(await fetch(`${this.baseUrl}/api/v1/collect/events`, {
209
- method: "POST",
210
- headers: F(this.config.writeKey),
211
- body: JSON.stringify(e),
212
- credentials: "omit"
213
- }));
214
- });
215
- }
216
- async sendBatch(e, t = !1) {
217
- await p(this.retry, async () => {
218
- I(await fetch(`${this.baseUrl}/api/v1/collect/events/batch`, {
219
- method: "POST",
220
- headers: F(this.config.writeKey),
221
- body: JSON.stringify({ events: e }),
222
- credentials: "omit",
223
- keepalive: t
224
- }));
225
- });
226
- }
227
- flushWithKeepalive() {
228
- if (this.trackingDisabled()) {
229
- this.clearStoredState();
230
- return;
231
- }
232
- if (this.queue.length === 0) return;
233
- let e = this.queue.splice(0, this.queue.length);
234
- this.sendBatch(e, !0).then(() => {
235
- this.queueStorage.save(this.queue);
236
- }, () => {
237
- this.queue.unshift(...e), this.trimQueue(), this.queueStorage.save(this.queue);
238
- });
239
- }
240
- };
241
- function E(e) {
242
- return `custd:${e}:anonymous_id`;
243
- }
244
- function D(e) {
245
- return `custd:${e}:session_id`;
246
- }
247
- function O(e) {
248
- return `custd:${e}:event_queue`;
249
- }
250
- async function k(e) {
251
- let t = e ?? G(), n = L();
252
- try {
253
- let e = t.dataset.siteUuid, r = t.dataset.writeKey;
254
- if (!e || !r) throw Error("custd: browser script requires data-site-uuid and data-write-key");
255
- let i = t.dataset.baseUrl ?? new URL(t.src).origin;
256
- Z(i, "baseUrl");
257
- let a = await A(i, e), o = w({
258
- baseUrl: i,
259
- siteUuid: e,
260
- writeKey: r,
261
- identityMode: a.identityMode,
262
- allowedOrigins: a.allowedOrigins,
263
- batchSize: Number(t.dataset.batchSize || q(a)),
264
- consent: K(t, a),
265
- persistentQueue: t.dataset.persistentQueue === "true"
266
- });
267
- return window.custd = {
268
- track: (e, t) => o.track(e, t),
269
- trackPageView: () => o.trackPageView(),
270
- setConsent: (e) => o.setConsent(e)
271
- }, await B(o, n), o;
272
- } catch (e) {
273
- throw V(n, e), H(e), e;
274
- }
275
- }
276
- async function A(e, t) {
277
- let n = await fetch(`${e.replace(/\/$/, "")}/api/v1/sites/${encodeURIComponent(t)}/config`, { credentials: "omit" });
278
- if (!n.ok) throw Error(`custd: site config request failed with status ${n.status}`);
279
- return await n.json();
280
- }
281
- function j() {
282
- return {
283
- page: {
284
- path: N(window.location.pathname),
285
- title: document.title
286
- },
287
- device: { type: X() },
288
- locale: navigator.language,
289
- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
290
- };
291
- }
292
- function M() {
293
- let e = new URL(window.location.href).searchParams, t = e.get("ref") ?? "";
294
- return e.get("source") !== "powered-by" || !C.test(t) ? {} : {
295
- utmSource: t,
296
- utmMedium: "powered-by"
297
- };
298
- }
299
- function N(e) {
300
- return (e.startsWith("/") ? e : `/${e}`).split("/").map(P).join("/") || "/";
301
- }
302
- function P(e) {
303
- if (e === "") return "";
304
- let t;
305
- try {
306
- t = decodeURIComponent(e);
307
- } catch {
308
- return y;
309
- }
310
- return !b.test(t) || x.test(t) || /^\d+$/u.test(t) || S.test(t) ? y : t;
311
- }
312
- function F(e) {
313
- return {
314
- "Content-Type": "application/json",
315
- Authorization: `Bearer ${e}`
316
- };
317
- }
318
- function I(e) {
319
- if (!e.ok) throw [
320
- 408,
321
- 429,
322
- 500,
323
- 502,
324
- 503,
325
- 504
326
- ].includes(e.status) ? new d(`custd: retryable collector status ${e.status}`) : Error(`custd: collector request failed with status ${e.status}`);
327
- }
328
- function ee(e) {
329
- let t = e.allowedOrigins ?? [];
330
- if (t.length === 0) throw Error("custd: site config must include allowed origins for this site");
331
- if (!t.includes(window.location.origin)) throw Error("custd: origin is not allowed for this site");
332
- }
333
- function L() {
334
- let e = {
335
- calls: [],
336
- promises: []
337
- };
338
- return window.custd = {
339
- track: (t, n) => R(e, {
340
- type: "track",
341
- eventTypeSlug: t,
342
- payload: n
343
- }),
344
- trackPageView: () => R(e, { type: "trackPageView" }),
345
- setConsent: (t) => {
346
- z(e, {
347
- type: "setConsent",
348
- state: t
349
- });
350
- }
351
- }, e;
352
- }
353
- function R(e, t) {
354
- return e.calls.length >= v ? Promise.reject(/* @__PURE__ */ Error("custd: queued global call limit exceeded")) : new Promise((n, r) => {
355
- e.calls.push(t), e.promises.push({
356
- resolve: n,
357
- reject: r
358
- });
359
- });
360
- }
361
- function z(e, t) {
362
- e.calls.length >= v || e.calls.push(t);
363
- }
364
- async function B(e, t) {
365
- for (let n of t.calls) {
366
- let r = n.type === "setConsent" ? void 0 : t.promises.shift();
367
- try {
368
- n.type === "track" ? await e.track(n.eventTypeSlug, n.payload) : n.type === "trackPageView" ? await e.trackPageView() : e.setConsent(n.state), r?.resolve();
369
- } catch (e) {
370
- r?.reject(e);
371
- }
372
- }
373
- }
374
- function V(e, t) {
375
- for (let n of e.promises.splice(0, e.promises.length)) n.reject(t);
376
- }
377
- function H(e) {
378
- window.custd = {
379
- track: () => Promise.reject(e),
380
- trackPageView: () => Promise.reject(e),
381
- setConsent: () => {
382
- throw e;
383
- }
384
- };
385
- }
386
- function U(e, t) {
387
- let n = t.getItem(e);
388
- if (n) return n;
389
- let r = $();
390
- return t.setItem(e, r), r;
391
- }
392
- function W(n, r) {
393
- return !r || typeof localStorage > "u" ? new e() : new t(`custd:${n}:event_queue`);
394
- }
395
- function G() {
396
- let e = document.currentScript;
397
- if (!e) throw Error("custd: browser script could not find document.currentScript");
398
- return e;
399
- }
400
- function K(e, t) {
401
- return e.dataset.consent === "granted" ? "granted" : t.identityMode === "extended" ? "required" : void 0;
402
- }
403
- function q(e) {
404
- return e.identityMode === "extended" ? 25 : 1;
405
- }
406
- function J() {
407
- let e = navigator.doNotTrack;
408
- return e === "1" || e === "yes";
409
- }
410
- function Y() {
411
- return typeof navigator.onLine != "boolean" || navigator.onLine;
412
- }
413
- function X() {
414
- return /Mobi|Android/i.test(navigator.userAgent) ? "mobile" : "desktop";
415
- }
416
- function Z(e, t) {
417
- let n = new URL(e);
418
- if (n.protocol !== "https:" && !(n.protocol === "http:" && Q(n.hostname))) throw Error(`custd: ${t} must use https unless it targets localhost`);
419
- }
420
- function Q(e) {
421
- return e === "localhost" || e === "127.0.0.1" || e === "::1" || e === "host.docker.internal";
422
- }
423
- function $() {
424
- return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (e) => (Number(e) ^ Math.random() * 16 >> Number(e) / 4).toString(16));
425
- }
426
- //#endregion
427
- //#region src/browser-script.ts
428
- k(Array.from(document.scripts).find((e) => e.src === import.meta.url)).then((e) => e.installSpaTracking()).catch(() => void 0);
429
- //#endregion
@@ -1,10 +0,0 @@
1
- /**
2
- * readLifecycleFixture loads a shared lifecycle contract fixture under
3
- * contract-fixtures/lifecycle/{namespace}/{name}. Tests resolve the same
4
- * fixtures used by the Go SDK's matrix; the fixture paths are the canonical
5
- * wire-format contracts.
6
- *
7
- * Throws when the fixture is missing so a miss fails loudly rather than
8
- * silently producing an empty body.
9
- */
10
- export declare function readLifecycleFixture(namespace: string, name: string): unknown;
package/dist/fixtures.js DELETED
@@ -1,57 +0,0 @@
1
- // Shared contract fixture loader for tests.
2
- //
3
- // The TypeScript SDK ships inside the custd-sdk monorepo. The shared lifecycle
4
- // fixtures live at <monorepo>/contract-fixtures/lifecycle/{namespace}/{name},
5
- // and the monorepo also resolves to a standalone release where the fixtures
6
- // are vendored at <module>/contract-fixtures/lifecycle/{namespace}/{name}.
7
- //
8
- // Tests resolve fixtures via either path so the same fixtures work under both
9
- // layouts. The standalone-release layout is the typical npm install; the
10
- // monorepo layout is the typical local-development layout.
11
- import { readFileSync } from "node:fs";
12
- import { dirname, resolve } from "node:path";
13
- import { fileURLToPath } from "node:url";
14
- // findFixtureRoot walks upward from the current module to find the monorepo
15
- // root that contains the contract-fixtures directory. When the SDK is running
16
- // inside the standalone release split, fixtures live at <module>/contract-fixtures.
17
- function findFixtureRoot() {
18
- // node:url import.meta.url is available in both ESM and Node test contexts.
19
- const modulePath = fileURLToPath(import.meta.url);
20
- let cursor = dirname(modulePath);
21
- for (let depth = 0; depth < 8; depth++) {
22
- const candidate = resolve(cursor, "contract-fixtures");
23
- try {
24
- // Cheap probe: if the file exists, we landed at the correct root.
25
- readFileSync(resolve(candidate, "lifecycle", "matrix.json"));
26
- return candidate;
27
- }
28
- catch {
29
- const parent = dirname(cursor);
30
- if (parent === cursor) {
31
- break;
32
- }
33
- cursor = parent;
34
- }
35
- }
36
- throw new Error("custd-sdk: contract-fixtures root not found");
37
- }
38
- const fixtureRoot = findFixtureRoot();
39
- /**
40
- * readLifecycleFixture loads a shared lifecycle contract fixture under
41
- * contract-fixtures/lifecycle/{namespace}/{name}. Tests resolve the same
42
- * fixtures used by the Go SDK's matrix; the fixture paths are the canonical
43
- * wire-format contracts.
44
- *
45
- * Throws when the fixture is missing so a miss fails loudly rather than
46
- * silently producing an empty body.
47
- */
48
- export function readLifecycleFixture(namespace, name) {
49
- const relPath = `lifecycle/${namespace}/${name}`;
50
- try {
51
- const text = readFileSync(resolve(fixtureRoot, relPath), "utf8");
52
- return JSON.parse(text);
53
- }
54
- catch (err) {
55
- throw new Error(`custd-sdk: lifecycle fixture ${namespace}/${name} not found: ${err.message}`);
56
- }
57
- }