@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
@@ -0,0 +1,711 @@
1
+ function e() {
2
+ let e = t(), s = typeof document < "u" && document.visibilityState === "hidden", c = {
3
+ lcp: void 0,
4
+ fcp: void 0
5
+ }, l = {
6
+ value: 0,
7
+ session: 0,
8
+ first: 0,
9
+ last: 0
10
+ }, u = /* @__PURE__ */ new Map(), d = [], f = (t, n, r = {}) => {
11
+ if (!e.includes(t)) return;
12
+ let i = new PerformanceObserver((e) => n(e.getEntries()));
13
+ i.observe({
14
+ type: t,
15
+ buffered: !0,
16
+ ...r
17
+ }), d.push(i);
18
+ };
19
+ return f("largest-contentful-paint", (e) => {
20
+ let t = e[e.length - 1];
21
+ t && (c.lcp = t.startTime);
22
+ }), f("paint", (e) => {
23
+ let t = e.find((e) => e.name === "first-contentful-paint");
24
+ t && (c.fcp = t.startTime);
25
+ }), f("layout-shift", (e) => n(l, e)), f("event", (e) => r(u, e), { durationThreshold: 40 }), f("first-input", (e) => r(u, e)), {
26
+ snapshot: () => {
27
+ let t = {};
28
+ return o(t, "lcp", s ? void 0 : c.lcp), o(t, "fcp", s ? void 0 : c.fcp), o(t, "inp", i(u)), o(t, "ttfb", a()), e.includes("layout-shift") && Number.isFinite(l.value) && l.value >= 0 && (t.cls = Math.round(l.value * 1e4) / 1e4), t;
29
+ },
30
+ stop: () => {
31
+ for (let e of d.splice(0, d.length)) e.disconnect();
32
+ }
33
+ };
34
+ }
35
+ function t() {
36
+ return typeof PerformanceObserver > "u" ? [] : PerformanceObserver.supportedEntryTypes ?? [];
37
+ }
38
+ function n(e, t) {
39
+ for (let n of t) n.hadRecentInput || (e.session > 0 && n.startTime - e.last < 1e3 && n.startTime - e.first < 5e3 ? e.session += n.value : (e.session = n.value, e.first = n.startTime), e.last = n.startTime, e.value = Math.max(e.value, e.session));
40
+ }
41
+ function r(e, t) {
42
+ for (let n of t) {
43
+ let t = n.interactionId ?? 0;
44
+ t === 0 || !e.has(t) && e.size >= 1e3 || e.set(t, Math.max(e.get(t) ?? 0, n.duration));
45
+ }
46
+ }
47
+ function i(e) {
48
+ if (e.size === 0) return;
49
+ let t = [...e.values()].sort((e, t) => t - e);
50
+ return t[Math.min(Math.floor(e.size / 50), t.length - 1)];
51
+ }
52
+ function a() {
53
+ if (typeof performance > "u" || typeof performance.getEntriesByType != "function") return;
54
+ let e = performance.getEntriesByType("navigation")[0];
55
+ if (e) return e.responseStart - Math.max(e.activationStart ?? 0, 0);
56
+ }
57
+ function o(e, t, n) {
58
+ n !== void 0 && Number.isFinite(n) && n >= 0 && (e[t] = Math.round(n));
59
+ }
60
+ // src/secure-url.ts
61
+ var s = [
62
+ "localhost",
63
+ "127.0.0.1",
64
+ "[::1]",
65
+ "host.docker.internal"
66
+ ];
67
+ function c(e) {
68
+ return s.includes(e);
69
+ }
70
+ // src/response-lists.generated.ts
71
+ var l = { "GET /api/v1/sites/{siteUuid}/config": ["allowedOrigins"] };
72
+ // src/response-lists.ts
73
+ function u(e) {
74
+ let t;
75
+ return function(n, r, i) {
76
+ t ??= f(e);
77
+ let [a = ""] = r.split("?", 1), o = t.find((e) => (e.method === n || e.method === "ANY") && e.pattern.test(a));
78
+ if (i === null && o?.fields.some((e) => e.length === 1 && e[0] === "[]")) return [];
79
+ for (let e of o?.fields ?? []) m(i, e, 0);
80
+ return i;
81
+ };
82
+ }
83
+ var d = /* @__PURE__ */ u(l);
84
+ function f(e) {
85
+ return Object.entries(e).map(([e, t]) => {
86
+ let [n = "", r = ""] = e.split(" "), i = r.split("/").map((e) => /^\{[^}]+\}$/.test(e) ? "[^/]+" : p(e));
87
+ return {
88
+ method: n,
89
+ pattern: RegExp(`^${i.join("/")}$`),
90
+ parameters: i.filter((e) => e === "[^/]+").length,
91
+ fields: t.map((e) => e.split(".").flatMap(ee))
92
+ };
93
+ }).sort((e, t) => e.parameters - t.parameters);
94
+ }
95
+ function ee(e) {
96
+ let t = e.replace(/(\[\])+$/, ""), n = (e.length - t.length) / 2;
97
+ return [...t ? [t] : [], ...Array(n).fill("[]")];
98
+ }
99
+ function p(e) {
100
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
101
+ }
102
+ function m(e, t, n) {
103
+ let r = t[n];
104
+ if (r === "[]") {
105
+ if (Array.isArray(e)) for (let r of e) m(r, t, n + 1);
106
+ return;
107
+ }
108
+ if (r === void 0 || typeof e != "object" || !e || Array.isArray(e)) return;
109
+ let i = e;
110
+ n === t.length - 1 ? i[r] === null && (i[r] = []) : m(i[r], t, n + 1);
111
+ }
112
+ // src/index.ts
113
+ var te = class {
114
+ constructor() {
115
+ this.events = [];
116
+ }
117
+ load() {
118
+ return [...this.events];
119
+ }
120
+ save(e) {
121
+ this.events = [...e];
122
+ }
123
+ clear() {
124
+ this.events = [];
125
+ }
126
+ }, ne = class {
127
+ constructor(e = "custd_event_queue") {
128
+ this.key = e;
129
+ }
130
+ load() {
131
+ if (typeof localStorage > "u") return [];
132
+ let e = localStorage.getItem(this.key);
133
+ if (!e) return [];
134
+ try {
135
+ let t = JSON.parse(e);
136
+ if (Array.isArray(t)) return t;
137
+ } catch {
138
+ return [];
139
+ }
140
+ return [];
141
+ }
142
+ save(e) {
143
+ typeof localStorage < "u" && localStorage.setItem(this.key, JSON.stringify(e));
144
+ }
145
+ clear() {
146
+ typeof localStorage < "u" && localStorage.removeItem(this.key);
147
+ }
148
+ }, re = /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/, h = "custd.environment", g = /^[a-z][a-z0-9-]{0,31}$/;
149
+ function _(e) {
150
+ if (e !== "") {
151
+ if (e !== e.trim() || !g.test(e)) throw Error(`custd: environment ${JSON.stringify(e)} must be lowercase letters, digits and hyphens, at most 32 characters`);
152
+ if (e === "unclassified") throw Error("custd: environment \"unclassified\" is reserved");
153
+ }
154
+ }
155
+ function v(e, t) {
156
+ let n = e.environment || t || "";
157
+ n !== "" && (e.labels = { ...e.labels ?? {} }, e.labels["custd.environment"] === void 0 && (e.labels[h] = n));
158
+ }
159
+ function y(e) {
160
+ if ("resolvedLabels" in e || "vocabularyFingerprint" in e) throw Error("custd: server-owned label fields are not accepted");
161
+ if (e.labels === void 0) return;
162
+ if (e.labels === null || typeof e.labels != "object" || Array.isArray(e.labels)) throw Error("custd: labels must be an object of strings");
163
+ let t = Object.entries(e.labels);
164
+ if (t.length > 16) throw Error("custd: labels may contain at most 16 entries");
165
+ for (let [e, n] of t) {
166
+ if (!re.test(e) || b(e) > 64 || e.startsWith("custd.")) throw Error(`custd: labels.${e} has an invalid key`);
167
+ if (typeof n != "string" || n === "" || n !== n.trim() || b(n) > 128) throw Error(`custd: labels.${e} has an invalid value`);
168
+ }
169
+ }
170
+ function b(e) {
171
+ return new TextEncoder().encode(e).length;
172
+ }
173
+ function ie(e) {
174
+ let t = [];
175
+ 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(", ")}`);
176
+ _(e.environment ?? ""), y(e);
177
+ }
178
+ function ae(e, t = {}) {
179
+ return t.mode === "browser-cookieless" ? {
180
+ ...e,
181
+ eventUuid: e.eventUuid || C(),
182
+ sessionId: e.sessionId ?? "",
183
+ anonymousId: e.anonymousId ?? ""
184
+ } : {
185
+ ...e,
186
+ eventUuid: e.eventUuid || C(),
187
+ sessionId: e.sessionId || C(),
188
+ anonymousId: e.anonymousId || C()
189
+ };
190
+ }
191
+ var x = class extends Error {};
192
+ function oe(e) {
193
+ return {
194
+ maxAttempts: e?.maxAttempts ?? 3,
195
+ baseDelayMs: e?.baseDelayMs ?? 200,
196
+ maxDelayMs: e?.maxDelayMs ?? 2e3,
197
+ jitter: e?.jitter ?? .2,
198
+ retryOnStatuses: e?.retryOnStatuses ?? [
199
+ 408,
200
+ 429,
201
+ 500,
202
+ 502,
203
+ 503,
204
+ 504
205
+ ]
206
+ };
207
+ }
208
+ async function S(e, t) {
209
+ let n = 0;
210
+ for (;;) {
211
+ n++;
212
+ try {
213
+ return await t();
214
+ } catch (t) {
215
+ if (!(t instanceof x || t instanceof TypeError) || n >= e.maxAttempts) throw t;
216
+ await ce(se(e, n));
217
+ }
218
+ }
219
+ }
220
+ function se(e, t) {
221
+ let n = e.baseDelayMs * 2 ** (t - 1), r = Math.min(n, e.maxDelayMs), i = r * e.jitter * (Math.random() * 2 - 1);
222
+ return Math.max(0, r + i);
223
+ }
224
+ function ce(e) {
225
+ return new Promise((t) => setTimeout(t, e));
226
+ }
227
+ function C() {
228
+ 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));
229
+ }
230
+ // src/browser-tracker.ts
231
+ var le = "1.0.0", w = "page-view", ue = "web-vitals", de = "ai-assistant", T = /* @__PURE__ */ new Map([
232
+ ["chatgpt.com", "chatgpt"],
233
+ ["chat.openai.com", "chatgpt"],
234
+ ["perplexity.ai", "perplexity"],
235
+ ["claude.ai", "claude"],
236
+ ["gemini.google.com", "gemini"],
237
+ ["bard.google.com", "gemini"],
238
+ ["copilot.microsoft.com", "copilot"],
239
+ ["chat.deepseek.com", "deepseek"],
240
+ ["chat.mistral.ai", "mistral"],
241
+ ["grok.com", "grok"],
242
+ ["meta.ai", "meta-ai"],
243
+ ["you.com", "you"],
244
+ ["phind.com", "phind"]
245
+ ]), E = /^[0-9]+\.[0-9]+\.[0-9]+$/u, D = 1e3, O = "[redacted]", k = /^[A-Za-z][A-Za-z0-9._~-]{0,63}$/u, A = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu, j = /^[A-Za-z0-9_-]{24,}$/u, M = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/u, N = [
246
+ ["utm_source", "utmSource"],
247
+ ["utm_medium", "utmMedium"],
248
+ ["utm_campaign", "utmCampaign"],
249
+ ["utm_term", "utmTerm"],
250
+ ["utm_content", "utmContent"]
251
+ ], P = 100, F = /^[A-Za-z0-9._~:{}*[\]-]*$/u, I = 1024, L = 200, R = /* @__PURE__ */ new Set([
252
+ 408,
253
+ 429,
254
+ 500,
255
+ 502,
256
+ 503,
257
+ 504
258
+ ]);
259
+ function z(e) {
260
+ return new B(e);
261
+ }
262
+ var B = class {
263
+ constructor(t) {
264
+ this.queue = [], this.installedSpaTracking = !1, this.lastTrackedPath = null, this.referrerClassified = !1, this.webVitals = null, this.originalPushState = null, this.originalReplaceState = null, this.onlineHandler = () => this.detach("flush", () => this.flush()), this.pagehideHandler = () => {
265
+ this.enqueueWebVitals(), this.flushWithKeepalive();
266
+ }, this.visibilityHandler = () => {
267
+ document.visibilityState === "hidden" && this.enqueueWebVitals() && this.flushWithKeepalive();
268
+ }, this.popstateHandler = () => this.detachPathChange(() => this.trackPageView()), this.config = t, this.baseUrl = t.baseUrl.replace(/\/$/, ""), this.schemaVersion = Y(t.schemaVersion), this.pageViewSchemaVersion = t.pageViewSchemaVersion === void 0 ? this.schemaVersion : Y(t.pageViewSchemaVersion), this.labels = { ...t.labels ?? {} }, this.queueStorage = t.queueStorage ?? je(t.siteUuid, t.persistentQueue === !0), this.retry = oe(t.retry), this.maxQueueSize = t.maxQueueSize ?? 1e3, this.queue = this.queueStorage.load(), this.trimQueue(), this.consent = t.consent === "required" ? "denied" : "granted", this.trackingDisabled() && this.clearStoredState(), $(this.baseUrl, "baseUrl"), Te(t), window.addEventListener("online", this.onlineHandler), window.addEventListener("pagehide", this.pagehideHandler), t.webVitals === !0 && (this.webVitalsPath = this.pageContext().path, this.webVitals = e(), window.addEventListener("visibilitychange", this.visibilityHandler));
269
+ }
270
+ async track(e, t = {}) {
271
+ if (this.trackingDisabled()) return;
272
+ let n = this.buildEvent(e, t);
273
+ (this.config.batchSize ?? 0) > 1 ? (this.enqueue(n), this.queue.length >= (this.config.batchSize ?? 0) && await this.flush()) : await this.sendEvent(n);
274
+ }
275
+ trackPageView() {
276
+ this.lastTrackedPath = window.location.pathname;
277
+ let e = this.trackingDisabled() ? {} : this.landingReferral();
278
+ return this.track("page-view", {
279
+ ...be(new URL(window.location.href).searchParams),
280
+ ...e
281
+ });
282
+ }
283
+ installSpaTracking() {
284
+ 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.detach("page-view", () => this.trackPageView()));
285
+ }
286
+ setConsent(e) {
287
+ this.consent = e, e === "denied" && this.clearStoredState();
288
+ }
289
+ async flush() {
290
+ if (this.trackingDisabled()) {
291
+ this.clearStoredState();
292
+ return;
293
+ }
294
+ if (this.queue.length === 0 || !Ie()) return;
295
+ let e = this.queue.splice(0, this.queue.length), t;
296
+ try {
297
+ t = await this.sendBatch(e);
298
+ } catch (t) {
299
+ throw this.queue.unshift(...e), this.trimQueue(), this.queueStorage.save(this.queue), t;
300
+ }
301
+ if (this.applyBatchOutcome("flush", t), t.retryable.length > 0) throw new K(t.retryableStatus ?? 503);
302
+ }
303
+ close() {
304
+ window.removeEventListener("online", this.onlineHandler), window.removeEventListener("pagehide", this.pagehideHandler), window.removeEventListener("popstate", this.popstateHandler), window.removeEventListener("visibilitychange", this.visibilityHandler), this.webVitals?.stop(), this.webVitals = null, this.originalPushState && (window.history.pushState = this.originalPushState), this.originalReplaceState && (window.history.replaceState = this.originalReplaceState), this.installedSpaTracking = !1, this.originalPushState = null, this.originalReplaceState = null;
305
+ }
306
+ wrapHistoryMethod(e) {
307
+ return ((...t) => {
308
+ let n = window.location.pathname, r = e.apply(window.history, t);
309
+ return window.location.pathname !== n && this.detach("page-view", () => this.trackPageView()), r;
310
+ });
311
+ }
312
+ trackingDisabled() {
313
+ return !!(this.consent !== "granted" || Fe());
314
+ }
315
+ enqueue(e) {
316
+ this.queue.push(e), this.trimQueue(), this.queueStorage.save(this.queue);
317
+ }
318
+ trimQueue() {
319
+ this.queue.length > this.maxQueueSize && (this.queue = this.queue.slice(this.queue.length - this.maxQueueSize));
320
+ }
321
+ clearStoredState() {
322
+ this.queue = [], this.queueStorage.clear(), typeof localStorage < "u" && (localStorage.removeItem(V(this.config.siteUuid)), localStorage.removeItem(fe(this.config.siteUuid))), typeof sessionStorage < "u" && sessionStorage.removeItem(H(this.config.siteUuid));
323
+ }
324
+ buildEvent(e, t) {
325
+ let n = this.identityFields(), r = this.pageContext(), i = {
326
+ eventTypeSlug: e,
327
+ schemaVersion: e === w ? this.pageViewSchemaVersion : this.schemaVersion,
328
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
329
+ ...n,
330
+ context: he(r),
331
+ payload: {
332
+ siteUuid: this.config.siteUuid,
333
+ ...e === w && r.path !== void 0 ? { path: r.path } : {},
334
+ ...t
335
+ }
336
+ };
337
+ Object.keys(this.labels).length > 0 && (i.labels = { ...this.labels });
338
+ let a = ae(i, { mode: this.config.identityMode === "extended" ? "producer" : "browser-cookieless" });
339
+ return ie(a), v(a, this.config.environment), a;
340
+ }
341
+ landingReferral() {
342
+ if (this.referrerClassified) return {};
343
+ this.referrerClassified = !0;
344
+ let e = ye(document.referrer);
345
+ return e ? {
346
+ referrerClass: de,
347
+ aiAssistant: e
348
+ } : {};
349
+ }
350
+ enqueueWebVitals() {
351
+ let e = this.webVitals;
352
+ if (!e || this.trackingDisabled()) return !1;
353
+ this.webVitals = null, e.stop();
354
+ let t = e.snapshot();
355
+ if (Object.keys(t).length === 0) return !1;
356
+ let n = this.webVitalsPath === void 0 ? {} : { path: this.webVitalsPath };
357
+ try {
358
+ this.enqueue(this.buildEvent(ue, {
359
+ ...n,
360
+ ...t
361
+ }));
362
+ } catch {
363
+ return !1;
364
+ }
365
+ return !0;
366
+ }
367
+ identityFields() {
368
+ return this.config.identityMode === "extended" ? {
369
+ anonymousId: Z(V(this.config.siteUuid), localStorage),
370
+ sessionId: Z(H(this.config.siteUuid), sessionStorage)
371
+ } : {
372
+ anonymousId: "",
373
+ sessionId: ""
374
+ };
375
+ }
376
+ async sendEvent(e) {
377
+ await S(this.retry, async () => {
378
+ W(await fetch(`${this.baseUrl}/api/v1/collect/events`, {
379
+ method: "POST",
380
+ headers: U(this.config.writeKey),
381
+ body: JSON.stringify(e),
382
+ credentials: "omit"
383
+ }));
384
+ });
385
+ }
386
+ async sendBatch(e, t = !1) {
387
+ return we(e, await S(this.retry, async () => {
388
+ let n = await fetch(`${this.baseUrl}/api/v1/collect/events/batch`, {
389
+ method: "POST",
390
+ headers: U(this.config.writeKey),
391
+ body: JSON.stringify({ events: e }),
392
+ credentials: "omit",
393
+ keepalive: t
394
+ });
395
+ return W(n), Ce(n, e.length);
396
+ }));
397
+ }
398
+ applyBatchOutcome(e, t) {
399
+ t.retryable.length > 0 && (this.queue.unshift(...t.retryable), this.trimQueue()), this.queueStorage.save(this.queue), t.rejected.length > 0 && this.notifyFailure({
400
+ source: e,
401
+ rejectedEvents: t.rejected.length
402
+ });
403
+ }
404
+ pageContext() {
405
+ let e = {
406
+ path: xe(window.location.pathname),
407
+ title: document.title
408
+ }, t = this.config.pageContext;
409
+ if (!t) return e;
410
+ let n;
411
+ try {
412
+ n = t(e);
413
+ } catch {
414
+ return {};
415
+ }
416
+ return ge(n, e.path);
417
+ }
418
+ detach(e, t) {
419
+ t().catch((t) => this.notifyFailure({
420
+ source: e,
421
+ status: J(t)
422
+ }));
423
+ }
424
+ detachPathChange(e) {
425
+ window.location.pathname !== this.lastTrackedPath && this.detach("page-view", e);
426
+ }
427
+ notifyFailure(e) {
428
+ let t = this.config.onFailure;
429
+ if (t) try {
430
+ Promise.resolve(t(e)).catch(() => void 0);
431
+ } catch {}
432
+ }
433
+ flushWithKeepalive() {
434
+ if (this.trackingDisabled()) {
435
+ this.clearStoredState();
436
+ return;
437
+ }
438
+ if (this.queue.length === 0) return;
439
+ let e = this.queue.splice(0, this.queue.length);
440
+ this.sendBatch(e, !0).then((e) => {
441
+ this.applyBatchOutcome("flush", e), e.retryable.length > 0 && this.notifyFailure({
442
+ source: "flush",
443
+ status: e.retryableStatus ?? 503
444
+ });
445
+ }, (t) => {
446
+ this.queue.unshift(...e), this.trimQueue(), this.queueStorage.save(this.queue), this.notifyFailure({
447
+ source: "flush",
448
+ status: J(t)
449
+ });
450
+ });
451
+ }
452
+ };
453
+ function V(e) {
454
+ return `custd:${e}:anonymous_id`;
455
+ }
456
+ function H(e) {
457
+ return `custd:${e}:session_id`;
458
+ }
459
+ function fe(e) {
460
+ return `custd:${e}:event_queue`;
461
+ }
462
+ async function pe(e) {
463
+ let t = e ?? Q(), n = Ee();
464
+ try {
465
+ let e = t.dataset.siteUuid, r = t.dataset.writeKey;
466
+ if (!e || !r) throw Error("custd: browser script requires data-site-uuid and data-write-key");
467
+ let i = t.dataset.baseUrl ?? new URL(t.src).origin;
468
+ $(i, "baseUrl");
469
+ let a = await me(i, e), o = z({
470
+ baseUrl: i,
471
+ siteUuid: e,
472
+ writeKey: r,
473
+ identityMode: a.identityMode,
474
+ allowedOrigins: a.allowedOrigins,
475
+ pageViewSchemaVersion: ze(a.pageViewSchemaVersion),
476
+ batchSize: Number(t.dataset.batchSize || Pe(a)),
477
+ consent: Me(t, a),
478
+ persistentQueue: t.dataset.persistentQueue === "true",
479
+ webVitals: t.dataset.webVitals === "true"
480
+ });
481
+ return window.custd = {
482
+ track: (e, t) => o.track(e, t),
483
+ trackPageView: () => o.trackPageView(),
484
+ setConsent: (e) => o.setConsent(e)
485
+ }, await Oe(o, n), o;
486
+ } catch (e) {
487
+ throw ke(n, e), Ae(e), e;
488
+ }
489
+ }
490
+ async function me(e, t, n = (e, t) => globalThis.fetch(e, t)) {
491
+ let r = `/api/v1/sites/${encodeURIComponent(t)}/config`, i = await n(`${e.replace(/\/$/, "")}${r}`, { credentials: "omit" });
492
+ if (!i.ok) throw Error(`custd: site config request failed with status ${i.status}`);
493
+ return d("GET", r, await i.json());
494
+ }
495
+ function he(e) {
496
+ let t = {
497
+ device: { type: Le() },
498
+ locale: navigator.language,
499
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
500
+ };
501
+ return (e.path !== void 0 || e.title !== void 0) && (t.page = e), t;
502
+ }
503
+ function ge(e, t) {
504
+ let n = {};
505
+ typeof e?.path == "string" && (n.path = _e(e.path) ? e.path : t);
506
+ let r = ve(e?.title);
507
+ return r !== void 0 && (n.title = r), n;
508
+ }
509
+ function _e(e) {
510
+ return e.length === 0 || e.length > I || !e.startsWith("/") || e.startsWith("//") ? !1 : e.split("/").every((e) => F.test(e));
511
+ }
512
+ function ve(e) {
513
+ if (typeof e != "string") return;
514
+ let t = e.replace(/[\p{Cc}]/gu, "").trim();
515
+ return t === "" ? void 0 : t.slice(0, L);
516
+ }
517
+ function ye(e) {
518
+ if (!e) return;
519
+ let t;
520
+ try {
521
+ t = new URL(e).hostname.toLowerCase();
522
+ } catch {
523
+ return;
524
+ }
525
+ return T.get(t.replace(/^www\./u, ""));
526
+ }
527
+ function be(e) {
528
+ let t = e.get("ref") ?? "";
529
+ if (e.get("source") === "powered-by" && M.test(t)) return {
530
+ utmSource: t,
531
+ utmMedium: "powered-by"
532
+ };
533
+ let n = {};
534
+ for (let [t, r] of N) {
535
+ let i = e.get(t)?.toLowerCase().split(/\p{White_Space}+/u).filter(Boolean).join("_");
536
+ i && [...i].length <= P && !/\p{Cc}/u.test(i) && (n[r] = i);
537
+ }
538
+ return n;
539
+ }
540
+ function xe(e) {
541
+ return (e.startsWith("/") ? e : `/${e}`).split("/").map(Se).join("/") || "/";
542
+ }
543
+ function Se(e) {
544
+ if (e === "") return "";
545
+ let t;
546
+ try {
547
+ t = decodeURIComponent(e);
548
+ } catch {
549
+ return O;
550
+ }
551
+ return !k.test(t) || A.test(t) || /^\d+$/u.test(t) || j.test(t) ? O : t;
552
+ }
553
+ function U(e) {
554
+ return {
555
+ "Content-Type": "application/json",
556
+ Authorization: `Bearer ${e}`
557
+ };
558
+ }
559
+ function W(e) {
560
+ if (!e.ok) throw R.has(e.status) ? new K(e.status) : new G(e.status);
561
+ }
562
+ var G = class extends Error {
563
+ constructor(e) {
564
+ super(`custd: collector request failed with status ${e}`), this.status = e;
565
+ }
566
+ }, K = class extends x {
567
+ constructor(e) {
568
+ super(`custd: retryable collector status ${e}`), this.status = e;
569
+ }
570
+ }, q = class extends x {
571
+ constructor() {
572
+ super("custd: collector response did not match the batch contract");
573
+ }
574
+ };
575
+ function J(e) {
576
+ if (e instanceof K || e instanceof G) return e.status;
577
+ }
578
+ async function Ce(e, t) {
579
+ let n;
580
+ try {
581
+ n = await e.json();
582
+ } catch {
583
+ throw new q();
584
+ }
585
+ let r = typeof n == "object" && n ? n.results : void 0;
586
+ if (!Array.isArray(r) || r.length !== t) throw new q();
587
+ return r.map((e) => {
588
+ let t = typeof e == "object" && e ? e : {};
589
+ if (typeof t.success != "boolean" || typeof t.status != "number") throw new q();
590
+ return {
591
+ success: t.success,
592
+ status: t.status
593
+ };
594
+ });
595
+ }
596
+ function we(e, t) {
597
+ let n = {
598
+ rejected: [],
599
+ retryable: []
600
+ };
601
+ return t.forEach((t, r) => {
602
+ t.success || (R.has(t.status) ? (n.retryable.push(e[r]), n.retryableStatus ??= t.status) : n.rejected.push(e[r]));
603
+ }), n;
604
+ }
605
+ function Y(e) {
606
+ if (e === void 0) return le;
607
+ if (!E.test(e)) throw Error(`custd: schemaVersion ${JSON.stringify(e)} must be a dotted numeric version such as "1.0.0"`);
608
+ return e;
609
+ }
610
+ function Te(e) {
611
+ let t = e.allowedOrigins ?? [];
612
+ if (t.length === 0) throw Error("custd: site config must include allowed origins for this site");
613
+ if (!t.includes(window.location.origin)) throw Error("custd: origin is not allowed for this site");
614
+ }
615
+ function Ee() {
616
+ let e = {
617
+ calls: [],
618
+ promises: []
619
+ };
620
+ return window.custd = {
621
+ track: (t, n) => X(e, {
622
+ type: "track",
623
+ eventTypeSlug: t,
624
+ payload: n
625
+ }),
626
+ trackPageView: () => X(e, { type: "trackPageView" }),
627
+ setConsent: (t) => {
628
+ De(e, {
629
+ type: "setConsent",
630
+ state: t
631
+ });
632
+ }
633
+ }, e;
634
+ }
635
+ function X(e, t) {
636
+ return e.calls.length >= D ? Promise.reject(/* @__PURE__ */ Error("custd: queued global call limit exceeded")) : new Promise((n, r) => {
637
+ e.calls.push(t), e.promises.push({
638
+ resolve: n,
639
+ reject: r
640
+ });
641
+ });
642
+ }
643
+ function De(e, t) {
644
+ e.calls.length >= D || e.calls.push(t);
645
+ }
646
+ async function Oe(e, t) {
647
+ for (let n of t.calls) {
648
+ let r = n.type === "setConsent" ? void 0 : t.promises.shift();
649
+ try {
650
+ n.type === "track" ? await e.track(n.eventTypeSlug, n.payload) : n.type === "trackPageView" ? await e.trackPageView() : e.setConsent(n.state), r?.resolve();
651
+ } catch (e) {
652
+ r?.reject(e);
653
+ }
654
+ }
655
+ }
656
+ function ke(e, t) {
657
+ for (let n of e.promises.splice(0, e.promises.length)) n.reject(t);
658
+ }
659
+ function Ae(e) {
660
+ window.custd = {
661
+ track: () => Promise.reject(e),
662
+ trackPageView: () => Promise.reject(e),
663
+ setConsent: () => {
664
+ throw e;
665
+ }
666
+ };
667
+ }
668
+ function Z(e, t) {
669
+ let n = t.getItem(e);
670
+ if (n) return n;
671
+ let r = Re();
672
+ return t.setItem(e, r), r;
673
+ }
674
+ function je(e, t) {
675
+ return !t || typeof localStorage > "u" ? new te() : new ne(`custd:${e}:event_queue`);
676
+ }
677
+ function Q() {
678
+ let e = document.currentScript;
679
+ if (!e) throw Error("custd: browser script could not find document.currentScript");
680
+ return e;
681
+ }
682
+ function Me(e, t) {
683
+ return e.dataset.consent === "granted" ? "granted" : Ne(t);
684
+ }
685
+ function Ne(e) {
686
+ return e.identityMode === "extended" ? "required" : void 0;
687
+ }
688
+ function Pe(e) {
689
+ return e.identityMode === "extended" ? 25 : 1;
690
+ }
691
+ function Fe() {
692
+ let e = navigator.doNotTrack;
693
+ return e === "1" || e === "yes";
694
+ }
695
+ function Ie() {
696
+ return typeof navigator.onLine != "boolean" || navigator.onLine;
697
+ }
698
+ function Le() {
699
+ return /Mobi|Android/i.test(navigator.userAgent) ? "mobile" : "desktop";
700
+ }
701
+ function $(e, t) {
702
+ let n = new URL(e);
703
+ if (n.protocol !== "https:" && !(n.protocol === "http:" && c(n.hostname))) throw Error(`custd: ${t} must use https unless it targets localhost`);
704
+ }
705
+ function Re() {
706
+ 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));
707
+ }
708
+ function ze(e) {
709
+ return typeof e == "string" && E.test(e) ? e : void 0;
710
+ }
711
+ pe(Array.from(document.scripts).find((e) => e.src === import.meta.url)).then((e) => e.installSpaTracking()).catch(() => void 0);