@dataships/launcher 0.1.0 → 0.2.0
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.
- package/dist/integrity.json +2 -2
- package/dist/launcher.js +26 -9
- package/dist/modules/alia-0.2.0.js +2901 -0
- package/package.json +3 -1
- package/dist/modules/alia-0.1.0.js +0 -5
|
@@ -0,0 +1,2901 @@
|
|
|
1
|
+
// node_modules/@dataships/sdk/dist/index.js
|
|
2
|
+
var __typeError = (msg) => {
|
|
3
|
+
throw TypeError(msg);
|
|
4
|
+
};
|
|
5
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
6
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
7
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
8
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
9
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
10
|
+
var SERVER_KEY_PREFIX = "ds_sk_";
|
|
11
|
+
var isServerKey = (key) => key.startsWith(SERVER_KEY_PREFIX);
|
|
12
|
+
var isServerKeyAuth = (auth) => "serverKey" in auth;
|
|
13
|
+
var isUnsafeServerKeyAuth = (auth) => "unsafeServerKey" in auth;
|
|
14
|
+
var isTokenProviderAuth = (auth) => typeof auth.getToken === "function";
|
|
15
|
+
var resolveTokenProviderAuth = async (auth) => {
|
|
16
|
+
const token = await auth.getToken();
|
|
17
|
+
if (!token) {
|
|
18
|
+
throw new Error("DatashipsClient: auth.getToken() returned an empty token");
|
|
19
|
+
}
|
|
20
|
+
return { publicKey: auth.publicKey, token };
|
|
21
|
+
};
|
|
22
|
+
var UNSAFE_SERVER_KEY_APP_MARKER = "unsafe-server-key";
|
|
23
|
+
var UNSAFE_SERVER_KEY_WARNING = "Dataships SDK: the merchant SERVER KEY is being used in the browser (auth.unsafeServerKey). Anyone who views this page's source can act as this merchant until the key is revoked. Mint a short-lived token on your server and pass auth: { publicKey, token } instead.";
|
|
24
|
+
var assertBrowserAuth = (auth) => {
|
|
25
|
+
if (isUnsafeServerKeyAuth(auth)) {
|
|
26
|
+
if (!auth.unsafeServerKey || !isServerKey(auth.unsafeServerKey)) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
"DatashipsClient: auth.unsafeServerKey must be a server key (ds_sk_\u2026); a public key belongs in auth: { publicKey, token }"
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
warnUnsafeServerKey();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (isServerKey(auth.publicKey)) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
"DatashipsClient: a server key (ds_sk_\u2026) must never be used in the browser; use the public key with a merchant-signed token, or DatashipsServerClient from '@dataships/sdk/server' on your server"
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
const hasProvider = "getToken" in auth && auth.getToken !== void 0;
|
|
40
|
+
if (hasProvider && "token" in auth && auth.token !== void 0) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
"DatashipsClient: pass either auth.token or auth.getToken, not both"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
if (hasProvider) {
|
|
46
|
+
if (!isTokenProviderAuth(auth)) {
|
|
47
|
+
throw new Error("DatashipsClient: auth.getToken must be a function");
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!auth.token) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
"DatashipsClient: auth.token is required with a public key (the merchant's server mints it), or auth.getToken to fetch one per request"
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var warnUnsafeServerKey = () => {
|
|
58
|
+
const c = globalThis.console;
|
|
59
|
+
c?.warn?.(UNSAFE_SERVER_KEY_WARNING);
|
|
60
|
+
};
|
|
61
|
+
var authHeaders = (auth) => {
|
|
62
|
+
if (isUnsafeServerKeyAuth(auth)) return { "X-Api-Key": auth.unsafeServerKey };
|
|
63
|
+
return isServerKeyAuth(auth) ? { "X-Api-Key": auth.serverKey } : { "X-Api-Key": auth.publicKey, Authorization: `Bearer ${auth.token}` };
|
|
64
|
+
};
|
|
65
|
+
var PRODUCTION_BASE_URL = "https://api.dataships.io";
|
|
66
|
+
var resolveBaseUrl = (env = "production", baseUrl) => {
|
|
67
|
+
if (baseUrl) return baseUrl;
|
|
68
|
+
if (env === "production") return PRODUCTION_BASE_URL;
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Dataships SDK: env "${env}" has no default base URL; pass \`baseUrl\``
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
74
|
+
400,
|
|
75
|
+
401,
|
|
76
|
+
403,
|
|
77
|
+
404,
|
|
78
|
+
417,
|
|
79
|
+
422,
|
|
80
|
+
426
|
|
81
|
+
]);
|
|
82
|
+
var isTerminalStatus = (status) => status !== void 0 && TERMINAL_STATUSES.has(status);
|
|
83
|
+
var CONSENT_SESSION_ALREADY_PROCESSED = "CONSENT_SESSION_ALREADY_PROCESSED";
|
|
84
|
+
var TERMINAL_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
85
|
+
CONSENT_SESSION_ALREADY_PROCESSED
|
|
86
|
+
]);
|
|
87
|
+
var isTerminalErrorCode = (errorCode) => errorCode !== void 0 && TERMINAL_ERROR_CODES.has(errorCode);
|
|
88
|
+
var MAX_FAILURES = 4;
|
|
89
|
+
var backoffMs = (failureCount) => failureCount >= MAX_FAILURES ? 0 : failureCount * 2e3;
|
|
90
|
+
var defaultRetryPolicy = {
|
|
91
|
+
shouldRetry: (failureCount, status, errorCode) => !isTerminalStatus(status) && !isTerminalErrorCode(errorCode) && failureCount < MAX_FAILURES,
|
|
92
|
+
delayMs: backoffMs
|
|
93
|
+
};
|
|
94
|
+
var upsertSessionRetryPolicy = defaultRetryPolicy;
|
|
95
|
+
var noRetryPolicy = {
|
|
96
|
+
shouldRetry: () => false,
|
|
97
|
+
delayMs: () => 0
|
|
98
|
+
};
|
|
99
|
+
var DatashipsError = class extends Error {
|
|
100
|
+
constructor(args) {
|
|
101
|
+
super(`Dataships request failed (${args.status || "network"})`);
|
|
102
|
+
this.name = "DatashipsError";
|
|
103
|
+
this.status = args.status;
|
|
104
|
+
this.body = args.body;
|
|
105
|
+
this.challenge = args.challenge ?? null;
|
|
106
|
+
this.code = errorCodeFromBody(args.body);
|
|
107
|
+
this.reason = reasonFromBody(args.body);
|
|
108
|
+
}
|
|
109
|
+
/** 401 (missing / refused credential) or 403 (unknown, revoked or disabled key). */
|
|
110
|
+
get isAuthenticationFailure() {
|
|
111
|
+
return this.status === 401 || this.status === 403;
|
|
112
|
+
}
|
|
113
|
+
/** 409 `CONSENT_SESSION_ALREADY_PROCESSED`: the session is closed; no later call on it can succeed. */
|
|
114
|
+
get isSessionProcessed() {
|
|
115
|
+
return this.code === CONSENT_SESSION_ALREADY_PROCESSED;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var errorCodeFromBody = (body) => {
|
|
119
|
+
if (typeof body !== "object" || body === null) return null;
|
|
120
|
+
const errors = body.errors;
|
|
121
|
+
if (!Array.isArray(errors)) return null;
|
|
122
|
+
const code = errors[0]?.code;
|
|
123
|
+
return typeof code === "string" ? code : null;
|
|
124
|
+
};
|
|
125
|
+
var reasonFromBody = (body) => {
|
|
126
|
+
if (typeof body !== "object" || body === null) return null;
|
|
127
|
+
const message = body.message;
|
|
128
|
+
return typeof message === "string" && message.length > 0 ? message : null;
|
|
129
|
+
};
|
|
130
|
+
var CONSENT_SESSION_START_PATH = "/v1/consent-session";
|
|
131
|
+
var CONSENT_SESSION_CONSENT_PATH = "/v1/consent-session/consent";
|
|
132
|
+
var CONSENT_SESSION_HEARTBEAT_PATH = "/v1/consent-session/heartbeat";
|
|
133
|
+
var CONSENT_SESSION_TRIGGER_VERIFICATION_CODE_PATH = "/v1/consent-session/trigger-verification-code";
|
|
134
|
+
var CONSENT_SESSION_SUBMIT_VERIFICATION_CODE_PATH = "/v1/consent-session/submit-verification-code";
|
|
135
|
+
var CONSENT_SESSION_SUBMIT_PATH = "/v1/consent-session/submit";
|
|
136
|
+
var COUNTRY_NOT_FOUND_CODE = "COUNTRY_NOT_FOUND";
|
|
137
|
+
var verificationErrorCodeFromBody = errorCodeFromBody;
|
|
138
|
+
var buildUpsertRequest = (args) => ({
|
|
139
|
+
identifier: args.identifier,
|
|
140
|
+
identifierType: args.identifierType,
|
|
141
|
+
locale: args.locale,
|
|
142
|
+
...args.userIp ? { userIp: args.userIp } : {},
|
|
143
|
+
...args.format ? { format: args.format } : {},
|
|
144
|
+
integration: {
|
|
145
|
+
...args.context,
|
|
146
|
+
type: args.integrationType
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
var isCountryNotFound = (error) => error.status === 422 && error.code === COUNTRY_NOT_FOUND_CODE;
|
|
150
|
+
var emptyUpsertResponse = () => ({
|
|
151
|
+
consentSessionId: null,
|
|
152
|
+
consents: [],
|
|
153
|
+
userVerificationRequired: null,
|
|
154
|
+
lastHeartbeat: null,
|
|
155
|
+
identifier: null
|
|
156
|
+
});
|
|
157
|
+
var buildSaveConsentRequest = (args) => ({
|
|
158
|
+
consentSessionId: args.consentSessionId,
|
|
159
|
+
channel: args.channel,
|
|
160
|
+
consent: args.consent
|
|
161
|
+
});
|
|
162
|
+
var buildHeartbeatRequest = (args) => ({
|
|
163
|
+
consentSessionId: args.consentSessionId
|
|
164
|
+
});
|
|
165
|
+
var buildTriggerVerificationCodeRequest = (args) => ({
|
|
166
|
+
consentSessionId: args.consentSessionId
|
|
167
|
+
});
|
|
168
|
+
var buildSubmitVerificationCodeRequest = (args) => ({
|
|
169
|
+
consentSessionId: args.consentSessionId,
|
|
170
|
+
verificationCode: args.verificationCode,
|
|
171
|
+
referenceId: args.referenceId
|
|
172
|
+
});
|
|
173
|
+
var buildSubmitRequest = (args) => {
|
|
174
|
+
const details = { ...args.details };
|
|
175
|
+
if (details.submittedAt instanceof Date) details.submittedAt = details.submittedAt.toISOString();
|
|
176
|
+
if (typeof details.billingCountryCode === "string") {
|
|
177
|
+
details.billingCountryCode = details.billingCountryCode.trim().toUpperCase();
|
|
178
|
+
}
|
|
179
|
+
const omitUser = args.user === void 0 && args.requiresUser === false;
|
|
180
|
+
return {
|
|
181
|
+
datashipsSessionId: args.datashipsSessionId,
|
|
182
|
+
...omitUser ? {} : { user: normaliseSubmitUser(args.user) },
|
|
183
|
+
integration: { ...details, type: args.integrationType }
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
var normaliseSubmitUser = (user) => {
|
|
187
|
+
const firstName = user?.firstName?.trim() ?? "";
|
|
188
|
+
const lastName = user?.lastName?.trim() ?? "";
|
|
189
|
+
if (!firstName || !lastName) {
|
|
190
|
+
throw new Error(
|
|
191
|
+
"submitSession: user.firstName and user.lastName are required (core-api refuses a blank name)"
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
return { firstName, lastName };
|
|
195
|
+
};
|
|
196
|
+
var upsertSession = async (args) => {
|
|
197
|
+
const { adapter, input } = args;
|
|
198
|
+
const identifier = input.identifier ?? (await adapter.getIdentifier(input.identifierType)).identifier;
|
|
199
|
+
const context = await adapter.getSessionContext();
|
|
200
|
+
const body = buildUpsertRequest({
|
|
201
|
+
integrationType: adapter.integrationType,
|
|
202
|
+
locale: adapter.getLocale(),
|
|
203
|
+
identifier,
|
|
204
|
+
identifierType: input.identifierType,
|
|
205
|
+
userIp: input.userIp,
|
|
206
|
+
format: input.format,
|
|
207
|
+
context
|
|
208
|
+
});
|
|
209
|
+
try {
|
|
210
|
+
const response = await args.post({
|
|
211
|
+
path: CONSENT_SESSION_START_PATH,
|
|
212
|
+
body,
|
|
213
|
+
retry: args.retry
|
|
214
|
+
});
|
|
215
|
+
return response ?? emptyUpsertResponse();
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (error instanceof DatashipsError && isCountryNotFound(error)) {
|
|
218
|
+
return emptyUpsertResponse();
|
|
219
|
+
}
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
var saveConsent = (args) => args.post({
|
|
224
|
+
path: CONSENT_SESSION_CONSENT_PATH,
|
|
225
|
+
body: buildSaveConsentRequest({
|
|
226
|
+
consentSessionId: args.consentSessionId,
|
|
227
|
+
channel: args.channel,
|
|
228
|
+
consent: args.consent
|
|
229
|
+
}),
|
|
230
|
+
retry: args.retry
|
|
231
|
+
});
|
|
232
|
+
var heartbeat = (args) => args.post({
|
|
233
|
+
path: CONSENT_SESSION_HEARTBEAT_PATH,
|
|
234
|
+
body: buildHeartbeatRequest({ consentSessionId: args.consentSessionId }),
|
|
235
|
+
retry: args.retry
|
|
236
|
+
});
|
|
237
|
+
var triggerVerificationCode = (args) => args.post({
|
|
238
|
+
path: CONSENT_SESSION_TRIGGER_VERIFICATION_CODE_PATH,
|
|
239
|
+
body: buildTriggerVerificationCodeRequest({
|
|
240
|
+
consentSessionId: args.consentSessionId
|
|
241
|
+
}),
|
|
242
|
+
retry: noRetryPolicy
|
|
243
|
+
});
|
|
244
|
+
var submitVerificationCode = async (args) => {
|
|
245
|
+
try {
|
|
246
|
+
await args.post({
|
|
247
|
+
path: CONSENT_SESSION_SUBMIT_VERIFICATION_CODE_PATH,
|
|
248
|
+
body: buildSubmitVerificationCodeRequest({
|
|
249
|
+
consentSessionId: args.consentSessionId,
|
|
250
|
+
verificationCode: args.verificationCode,
|
|
251
|
+
referenceId: args.referenceId
|
|
252
|
+
}),
|
|
253
|
+
retry: noRetryPolicy
|
|
254
|
+
});
|
|
255
|
+
return { verified: true, errorCode: null };
|
|
256
|
+
} catch (error) {
|
|
257
|
+
if (error instanceof DatashipsError && error.status === 400) {
|
|
258
|
+
return {
|
|
259
|
+
verified: false,
|
|
260
|
+
errorCode: verificationErrorCodeFromBody(error.body)
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
var submitSession = async (args) => {
|
|
267
|
+
const { adapter, input } = args;
|
|
268
|
+
const datashipsSessionId = input.datashipsSessionId ?? adapter.getDatashipsSessionId?.();
|
|
269
|
+
if (!datashipsSessionId) {
|
|
270
|
+
throw new Error(
|
|
271
|
+
"submitSession: datashipsSessionId is required; this adapter holds no beacon of its own"
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
await args.post({
|
|
275
|
+
path: CONSENT_SESSION_SUBMIT_PATH,
|
|
276
|
+
body: buildSubmitRequest({
|
|
277
|
+
datashipsSessionId,
|
|
278
|
+
integrationType: adapter.integrationType,
|
|
279
|
+
user: input.user,
|
|
280
|
+
details: input.details,
|
|
281
|
+
requiresUser: adapter.submitRequiresUser
|
|
282
|
+
}),
|
|
283
|
+
retry: args.retry
|
|
284
|
+
});
|
|
285
|
+
if (input.datashipsSessionId === void 0 && input.resetBeacon !== false) {
|
|
286
|
+
adapter.resetDatashipsSessionId?.();
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
var postJson = async ({
|
|
290
|
+
url,
|
|
291
|
+
headers,
|
|
292
|
+
body,
|
|
293
|
+
fetch,
|
|
294
|
+
retry
|
|
295
|
+
}) => {
|
|
296
|
+
let attempt = 0;
|
|
297
|
+
while (true) {
|
|
298
|
+
let response;
|
|
299
|
+
let networkError;
|
|
300
|
+
const attemptHeaders = typeof headers === "function" ? await headers() : headers;
|
|
301
|
+
try {
|
|
302
|
+
response = await fetch(url, {
|
|
303
|
+
method: "POST",
|
|
304
|
+
headers: { "Content-Type": "application/json", ...attemptHeaders },
|
|
305
|
+
body: JSON.stringify(body)
|
|
306
|
+
});
|
|
307
|
+
} catch (err) {
|
|
308
|
+
networkError = err;
|
|
309
|
+
}
|
|
310
|
+
const status = response?.status;
|
|
311
|
+
const ok = response?.ok ?? false;
|
|
312
|
+
if (ok && response) {
|
|
313
|
+
const text = await response.text();
|
|
314
|
+
return text ? JSON.parse(text) : void 0;
|
|
315
|
+
}
|
|
316
|
+
const errorBody = response ? await readBody(response) : null;
|
|
317
|
+
const errorCode = errorCodeFromBody(errorBody) ?? void 0;
|
|
318
|
+
if (!retry.shouldRetry(attempt, status, errorCode)) {
|
|
319
|
+
if (networkError) throw networkError;
|
|
320
|
+
throw new DatashipsError({
|
|
321
|
+
status: status ?? 0,
|
|
322
|
+
body: errorBody,
|
|
323
|
+
challenge: response?.headers.get("WWW-Authenticate") ?? null
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
attempt += 1;
|
|
327
|
+
const delay = retry.delayMs(attempt);
|
|
328
|
+
if (delay > 0) await new Promise((r) => setTimeout(r, delay));
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
var readBody = async (response) => {
|
|
332
|
+
const text = await response.text();
|
|
333
|
+
if (!text) return null;
|
|
334
|
+
try {
|
|
335
|
+
return JSON.parse(text);
|
|
336
|
+
} catch {
|
|
337
|
+
return text;
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
var DEFAULT_HEARTBEAT_INTERVAL_MS = 210 * 1e3;
|
|
341
|
+
var DEFAULT_HEARTBEAT_DURATION_MS = 10 * 60 * 1e3;
|
|
342
|
+
var _auth;
|
|
343
|
+
var _fetch;
|
|
344
|
+
var _upsertSessionRetry;
|
|
345
|
+
var _defaultRetry;
|
|
346
|
+
var _DatashipsClient_instances;
|
|
347
|
+
var previewUpsertResponse_fn;
|
|
348
|
+
var credentialHeaders_fn;
|
|
349
|
+
var requireAuth_fn;
|
|
350
|
+
var requireConsentSessionId_fn;
|
|
351
|
+
var sendHeartbeat_fn;
|
|
352
|
+
var post_fn;
|
|
353
|
+
var DatashipsClient = class {
|
|
354
|
+
constructor(opts) {
|
|
355
|
+
__privateAdd(this, _DatashipsClient_instances);
|
|
356
|
+
__privateAdd(this, _auth);
|
|
357
|
+
__privateAdd(this, _fetch);
|
|
358
|
+
__privateAdd(this, _upsertSessionRetry);
|
|
359
|
+
__privateAdd(this, _defaultRetry);
|
|
360
|
+
this.adapter = opts.adapter;
|
|
361
|
+
if (opts.auth) assertBrowserAuth(opts.auth);
|
|
362
|
+
if (!opts.auth && !opts.adapter.previewMode) {
|
|
363
|
+
throw new Error(
|
|
364
|
+
"DatashipsClient: `auth: { publicKey, token }` (or `{ publicKey, getToken }`) is required unless the adapter runs in preview mode"
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
this.publicKey = opts.auth && !isUnsafeServerKeyAuth(opts.auth) ? opts.auth.publicKey : null;
|
|
368
|
+
__privateSet(this, _auth, opts.auth ?? null);
|
|
369
|
+
this.app = opts.app;
|
|
370
|
+
this.version = opts.version;
|
|
371
|
+
this.baseUrl = resolveBaseUrl(opts.env, opts.baseUrl);
|
|
372
|
+
__privateSet(this, _fetch, opts.fetch ?? globalThis.fetch.bind(globalThis));
|
|
373
|
+
__privateSet(this, _upsertSessionRetry, opts.retry?.upsertSession ?? upsertSessionRetryPolicy);
|
|
374
|
+
__privateSet(this, _defaultRetry, opts.retry?.default ?? defaultRetryPolicy);
|
|
375
|
+
}
|
|
376
|
+
/** The credentials in use, or null for a preview-mode client constructed without them. */
|
|
377
|
+
get auth() {
|
|
378
|
+
return __privateGet(this, _auth);
|
|
379
|
+
}
|
|
380
|
+
/** Whether this client runs on the unsafe server-key escape hatch. */
|
|
381
|
+
get isUnsafeServerKey() {
|
|
382
|
+
return __privateGet(this, _auth) !== null && isUnsafeServerKeyAuth(__privateGet(this, _auth));
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Replace the Bearer token before it expires. The next call and any running
|
|
386
|
+
* heartbeat use it; a missed rotation surfaces as a 401 on the next call.
|
|
387
|
+
* Not applicable under `auth.getToken`, which already fetches one per request.
|
|
388
|
+
*/
|
|
389
|
+
setToken(token) {
|
|
390
|
+
if (!__privateGet(this, _auth)) {
|
|
391
|
+
throw new Error(
|
|
392
|
+
"DatashipsClient: setToken() requires a client constructed with `auth`"
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
if (isUnsafeServerKeyAuth(__privateGet(this, _auth))) {
|
|
396
|
+
throw new Error(
|
|
397
|
+
"DatashipsClient: setToken() does not apply under auth.unsafeServerKey; there is no token to rotate"
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
if (isTokenProviderAuth(__privateGet(this, _auth))) {
|
|
401
|
+
throw new Error(
|
|
402
|
+
"DatashipsClient: setToken() does not apply under auth.getToken; the provider is called before every request"
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
if (!token) {
|
|
406
|
+
throw new Error("DatashipsClient: token must be a non-empty string");
|
|
407
|
+
}
|
|
408
|
+
__privateSet(this, _auth, { ...__privateGet(this, _auth), token });
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Open or update the consent session for one identifier type
|
|
412
|
+
* (`POST /v1/consent-session`, contract v2). The client only states which
|
|
413
|
+
* identifier type it holds; the server decides the channels and returns one
|
|
414
|
+
* entry per channel to render. An empty `consents` means render nothing:
|
|
415
|
+
* that also covers a 204 No Content (a surface that never collects, no
|
|
416
|
+
* eligible channel, or a checkout that already asked on an earlier step) and
|
|
417
|
+
* a user IP the API could not geolocate (422 COUNTRY_NOT_FOUND), both of
|
|
418
|
+
* which resolve instead of throwing.
|
|
419
|
+
*/
|
|
420
|
+
async upsertSession(input) {
|
|
421
|
+
const preview = __privateMethod(this, _DatashipsClient_instances, previewUpsertResponse_fn).call(this, input.identifierType, input.format);
|
|
422
|
+
if (preview) return preview;
|
|
423
|
+
return upsertSession({
|
|
424
|
+
adapter: this.adapter,
|
|
425
|
+
input,
|
|
426
|
+
post: __privateMethod(this, _DatashipsClient_instances, post_fn).bind(this),
|
|
427
|
+
retry: __privateGet(this, _upsertSessionRetry)
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
async saveConsent(input) {
|
|
431
|
+
if (this.adapter.previewMode) return;
|
|
432
|
+
await saveConsent({
|
|
433
|
+
consentSessionId: __privateMethod(this, _DatashipsClient_instances, requireConsentSessionId_fn).call(this, input.session),
|
|
434
|
+
channel: input.channel,
|
|
435
|
+
consent: input.consent,
|
|
436
|
+
post: __privateMethod(this, _DatashipsClient_instances, post_fn).bind(this),
|
|
437
|
+
retry: __privateGet(this, _defaultRetry)
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Ask the backend to send an OTP verification code to the phone-channel
|
|
442
|
+
* session's number. `referenceId` must be echoed back on
|
|
443
|
+
* {@link submitVerificationCode}. Never retried — a retry could send the
|
|
444
|
+
* buyer duplicate codes.
|
|
445
|
+
*
|
|
446
|
+
* In preview mode no code is sent and `{ userVerificationTriggered: false }` is
|
|
447
|
+
* returned, mirroring a store without verification enabled.
|
|
448
|
+
*/
|
|
449
|
+
async triggerVerificationCode(input) {
|
|
450
|
+
if (this.adapter.previewMode) {
|
|
451
|
+
return {
|
|
452
|
+
userVerificationTriggered: false,
|
|
453
|
+
referenceId: null,
|
|
454
|
+
codeLength: null,
|
|
455
|
+
resendAfterSeconds: null
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
return triggerVerificationCode({
|
|
459
|
+
consentSessionId: input.consentSessionId,
|
|
460
|
+
post: __privateMethod(this, _DatashipsClient_instances, post_fn).bind(this)
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Submit the OTP code the buyer received. Resolves
|
|
465
|
+
* `{ verified: true, errorCode: null }` on 2xx. A 400 rejection resolves
|
|
466
|
+
* `{ verified: false, errorCode }` with the body's `errors[0].code` (see
|
|
467
|
+
* `SUBMIT_VERIFICATION_CODE_ERROR_CODES`), or `null` when the body carries
|
|
468
|
+
* none. Any other failure throws. Never retried — a rejection is definitive.
|
|
469
|
+
*
|
|
470
|
+
* In preview mode resolves verified without a network call.
|
|
471
|
+
*/
|
|
472
|
+
async submitVerificationCode(input) {
|
|
473
|
+
if (this.adapter.previewMode) return { verified: true, errorCode: null };
|
|
474
|
+
return submitVerificationCode({
|
|
475
|
+
...input,
|
|
476
|
+
post: __privateMethod(this, _DatashipsClient_instances, post_fn).bind(this)
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Complete the sessions opened under a beacon: the placed order (or the
|
|
481
|
+
* flow's equivalent) lands on every sibling session and processing is
|
|
482
|
+
* queued (`POST /v1/consent-session/submit`).
|
|
483
|
+
*
|
|
484
|
+
* `user.firstName` / `lastName` are required (the backend refuses a blank
|
|
485
|
+
* name; the SDK refuses it before sending), unless the adapter's
|
|
486
|
+
* `submitRequiresUser` is false, as on the Alia form adapters: then `user` may be
|
|
487
|
+
* omitted and the submit goes without it. The beacon defaults to the
|
|
488
|
+
* adapter's own `datashipsSessionId`, which is then discarded once the
|
|
489
|
+
* submit is accepted. Idempotent on the backend; a
|
|
490
|
+
* beacon that matches no session is accepted silently. Retried on 409 and
|
|
491
|
+
* server errors like any other call.
|
|
492
|
+
*
|
|
493
|
+
* In preview mode nothing is sent; the beacon is still discarded so a
|
|
494
|
+
* styled sandbox behaves like a real checkout.
|
|
495
|
+
*/
|
|
496
|
+
async submitSession(input) {
|
|
497
|
+
const adapter = this.adapter;
|
|
498
|
+
if (adapter.previewMode) {
|
|
499
|
+
if (input.datashipsSessionId === void 0 && input.resetBeacon !== false) {
|
|
500
|
+
adapter.resetDatashipsSessionId?.();
|
|
501
|
+
}
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
await submitSession({
|
|
505
|
+
adapter,
|
|
506
|
+
input,
|
|
507
|
+
post: __privateMethod(this, _DatashipsClient_instances, post_fn).bind(this),
|
|
508
|
+
retry: __privateGet(this, _defaultRetry)
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Begin a periodic heartbeat. Returns an idempotent stop function. The
|
|
513
|
+
* scheduler stops itself at the duration limit, when the credential is
|
|
514
|
+
* refused (401 / 403) and when the session has already been processed; every
|
|
515
|
+
* failure is reported through `onError`.
|
|
516
|
+
*/
|
|
517
|
+
startHeartbeat(session, opts = {}) {
|
|
518
|
+
if (this.adapter.previewMode) return () => {
|
|
519
|
+
};
|
|
520
|
+
const intervalMs = opts.intervalMs ?? DEFAULT_HEARTBEAT_INTERVAL_MS;
|
|
521
|
+
const durationMs = opts.durationMs ?? DEFAULT_HEARTBEAT_DURATION_MS;
|
|
522
|
+
const startedAt = Date.now();
|
|
523
|
+
let stopped = false;
|
|
524
|
+
const stop = () => {
|
|
525
|
+
if (stopped) return;
|
|
526
|
+
stopped = true;
|
|
527
|
+
clearInterval(handle);
|
|
528
|
+
};
|
|
529
|
+
const handle = setInterval(() => {
|
|
530
|
+
if (Date.now() - startedAt >= durationMs) {
|
|
531
|
+
stop();
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
__privateMethod(this, _DatashipsClient_instances, sendHeartbeat_fn).call(this, session).catch((error) => {
|
|
535
|
+
opts.onError?.(error);
|
|
536
|
+
if (error instanceof DatashipsError && (error.isAuthenticationFailure || error.isSessionProcessed)) {
|
|
537
|
+
stop();
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
}, intervalMs);
|
|
541
|
+
return stop;
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
_auth = /* @__PURE__ */ new WeakMap();
|
|
545
|
+
_fetch = /* @__PURE__ */ new WeakMap();
|
|
546
|
+
_upsertSessionRetry = /* @__PURE__ */ new WeakMap();
|
|
547
|
+
_defaultRetry = /* @__PURE__ */ new WeakMap();
|
|
548
|
+
_DatashipsClient_instances = /* @__PURE__ */ new WeakSet();
|
|
549
|
+
previewUpsertResponse_fn = function(identifierType, format) {
|
|
550
|
+
if (this.adapter.previewMode && this.adapter.getPreviewUpsertResponse) {
|
|
551
|
+
return this.adapter.getPreviewUpsertResponse(identifierType, format);
|
|
552
|
+
}
|
|
553
|
+
return null;
|
|
554
|
+
};
|
|
555
|
+
credentialHeaders_fn = async function() {
|
|
556
|
+
const auth = __privateMethod(this, _DatashipsClient_instances, requireAuth_fn).call(this);
|
|
557
|
+
return authHeaders(
|
|
558
|
+
isTokenProviderAuth(auth) ? await resolveTokenProviderAuth(auth) : auth
|
|
559
|
+
);
|
|
560
|
+
};
|
|
561
|
+
requireAuth_fn = function() {
|
|
562
|
+
if (!__privateGet(this, _auth)) {
|
|
563
|
+
throw new Error(
|
|
564
|
+
"DatashipsClient: no credentials configured; pass `auth: { publicKey, token }`"
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
return __privateGet(this, _auth);
|
|
568
|
+
};
|
|
569
|
+
requireConsentSessionId_fn = function(session) {
|
|
570
|
+
if (!session.consentSessionId) {
|
|
571
|
+
throw new Error(
|
|
572
|
+
"DatashipsClient: consentSessionId is required"
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
return session.consentSessionId;
|
|
576
|
+
};
|
|
577
|
+
sendHeartbeat_fn = async function(session) {
|
|
578
|
+
await heartbeat({
|
|
579
|
+
consentSessionId: __privateMethod(this, _DatashipsClient_instances, requireConsentSessionId_fn).call(this, session),
|
|
580
|
+
post: __privateMethod(this, _DatashipsClient_instances, post_fn).bind(this),
|
|
581
|
+
retry: __privateGet(this, _defaultRetry)
|
|
582
|
+
});
|
|
583
|
+
};
|
|
584
|
+
post_fn = async function(args) {
|
|
585
|
+
const staticHeaders = {
|
|
586
|
+
// The marker lets the backend tell an exposed key in a page from a genuine server call.
|
|
587
|
+
"X-Dataships-App": `${this.app} (SDK: ${this.adapter.name}${this.isUnsafeServerKey ? `; ${UNSAFE_SERVER_KEY_APP_MARKER}` : ""})`,
|
|
588
|
+
"X-Dataships-Version": `${this.version} (SDK: ${"2.4.0"})`
|
|
589
|
+
};
|
|
590
|
+
return postJson({
|
|
591
|
+
url: `${this.baseUrl}${args.path}`,
|
|
592
|
+
// Resolved per attempt so a token provider hands every retry a fresh token.
|
|
593
|
+
headers: async () => ({
|
|
594
|
+
...await __privateMethod(this, _DatashipsClient_instances, credentialHeaders_fn).call(this),
|
|
595
|
+
...staticHeaders
|
|
596
|
+
}),
|
|
597
|
+
body: args.body,
|
|
598
|
+
fetch: __privateGet(this, _fetch),
|
|
599
|
+
retry: args.retry
|
|
600
|
+
});
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
// node_modules/@dataships/sdk/dist/adapters/custom-platform-checkout/index.js
|
|
604
|
+
var __typeError2 = (msg) => {
|
|
605
|
+
throw TypeError(msg);
|
|
606
|
+
};
|
|
607
|
+
var __accessCheck2 = (obj, member, msg) => member.has(obj) || __typeError2("Cannot " + msg);
|
|
608
|
+
var __privateGet2 = (obj, member, getter) => (__accessCheck2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
609
|
+
var __privateAdd2 = (obj, member, value) => member.has(obj) ? __typeError2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
610
|
+
var __privateSet2 = (obj, member, value, setter) => (__accessCheck2(obj, member, "write to private field"), member.set(obj, value), value);
|
|
611
|
+
var __privateMethod2 = (obj, member, method) => (__accessCheck2(obj, member, "access private method"), method);
|
|
612
|
+
var DEFAULT_EMAIL_OPT_IN_TEXT = "We would like to email you news and promotions. Tick to opt in.";
|
|
613
|
+
var DEFAULT_EMAIL_OPT_IN_CONSENT_DESCRIPTION = "Click here for an overview of how your personal data is processed for marketing purposes or see our Privacy Policy for further information.";
|
|
614
|
+
var DEFAULT_SMS_OPT_IN_TEXT = "We would like to text you news and promotions. Tick to opt in.";
|
|
615
|
+
var DEFAULT_SMS_OPT_IN_CONSENT_DESCRIPTION = "Based on the channel preferences set above, you agree to receive recurring automated marketing messages (e.g. AI content, cart reminders) from {{COMPANY_NAME}} at the number you provide. Consent is not a condition of purchase. We may share info with service providers per our Privacy Policy. Reply STOP to cancel or click the unsubscribe link (where available). For help reply HELP or email {{PRIVACY_EMAIL}}. Msg frequency varies. Msg & data rates may apply. By proceeding, you also agree to our Terms of Service (incl. arbitration) & Privacy Policy.";
|
|
616
|
+
var fakeEmailUpsertResponse = {
|
|
617
|
+
consentSessionId: "01HQB3QRZVV0737R0R25BTQBGF",
|
|
618
|
+
consents: [
|
|
619
|
+
{
|
|
620
|
+
channel: "EMAIL",
|
|
621
|
+
consentType: "OPT_IN",
|
|
622
|
+
checked: false,
|
|
623
|
+
widgetConfig: {
|
|
624
|
+
text: DEFAULT_EMAIL_OPT_IN_TEXT,
|
|
625
|
+
consentDescription: DEFAULT_EMAIL_OPT_IN_CONSENT_DESCRIPTION,
|
|
626
|
+
marketingInformation: '<h1>Marketing Information</h1>\n<p>We may send you direct marketing communications, product information and promotional offers. You can withdraw your consent at any time. See our <a href="https://dataships.io/privacy-centre">Privacy Policy</a> or contact us at <a href="mailto:privacy@example.com">privacy@example.com</a> for further information.</p>\n',
|
|
627
|
+
policyURL: "https://dataships.io/privacy-centre",
|
|
628
|
+
mobileTermsOfServiceURL: null,
|
|
629
|
+
privacyEmail: "privacy@example.com",
|
|
630
|
+
placeholderValues: null
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
],
|
|
634
|
+
userVerificationRequired: null,
|
|
635
|
+
lastHeartbeat: "2026-06-17T00:00:00Z",
|
|
636
|
+
identifier: null
|
|
637
|
+
};
|
|
638
|
+
var fakePhoneUpsertResponse = {
|
|
639
|
+
consentSessionId: "01HQB3QRZVV0737R0R25BTQBGG",
|
|
640
|
+
consents: [
|
|
641
|
+
{
|
|
642
|
+
channel: "SMS",
|
|
643
|
+
consentType: "OPT_IN",
|
|
644
|
+
checked: false,
|
|
645
|
+
widgetConfig: {
|
|
646
|
+
text: DEFAULT_SMS_OPT_IN_TEXT,
|
|
647
|
+
consentDescription: DEFAULT_SMS_OPT_IN_CONSENT_DESCRIPTION,
|
|
648
|
+
marketingInformation: '<h1>Marketing Information</h1>\n<p>We may send you marketing text messages about products and promotional offers. Message frequency varies. You can withdraw your consent at any time by replying STOP. See our <a href="https://dataships.io/privacy-centre">Privacy Policy</a> or contact us at <a href="mailto:privacy@example.com">privacy@example.com</a> for further information.</p>\n',
|
|
649
|
+
policyURL: "https://dataships.io/privacy-centre",
|
|
650
|
+
mobileTermsOfServiceURL: "https://dataships.io/mobile-terms",
|
|
651
|
+
privacyEmail: "privacy@example.com",
|
|
652
|
+
placeholderValues: null
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
],
|
|
656
|
+
userVerificationRequired: false,
|
|
657
|
+
lastHeartbeat: "2026-06-17T00:00:00Z",
|
|
658
|
+
identifier: null
|
|
659
|
+
};
|
|
660
|
+
var MARKETING_MODAL_HREF = "#dataships-marketing-modal";
|
|
661
|
+
var CHECKBOX_LABEL_BOLD_PHRASES = ["consent", "object", "opt in", "opt out", "STOP", "HELP"];
|
|
662
|
+
var CONSENT_DESCRIPTION_BOLD_PHRASES = ["STOP", "HELP"];
|
|
663
|
+
var escapeHtml = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
664
|
+
var escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
665
|
+
var wrapPhrase = (html, phrase, wrap) => html.replace(
|
|
666
|
+
new RegExp(`${escapeRegExp(escapeHtml(phrase))}(?![^<]*>)(?![^<]*</a>)`, "gi"),
|
|
667
|
+
wrap
|
|
668
|
+
);
|
|
669
|
+
var toHtmlCopy = (text, widgetConfig, boldPhrases) => {
|
|
670
|
+
let html = escapeHtml(text);
|
|
671
|
+
const links = [
|
|
672
|
+
["Terms of Service", widgetConfig.mobileTermsOfServiceURL],
|
|
673
|
+
["Privacy Policy", widgetConfig.policyURL],
|
|
674
|
+
["Click here", MARKETING_MODAL_HREF]
|
|
675
|
+
];
|
|
676
|
+
for (const [phrase, href] of links) {
|
|
677
|
+
if (!href) continue;
|
|
678
|
+
html = wrapPhrase(html, phrase, (match) => `<a href="${escapeHtml(href)}">${match}</a>`);
|
|
679
|
+
}
|
|
680
|
+
for (const phrase of boldPhrases) {
|
|
681
|
+
html = wrapPhrase(html, phrase, (match) => `<strong>${match}</strong>`);
|
|
682
|
+
}
|
|
683
|
+
return `<p>${html}</p>`;
|
|
684
|
+
};
|
|
685
|
+
var withHtmlCopy = (response) => ({
|
|
686
|
+
...response,
|
|
687
|
+
consents: response.consents.map((consent) => {
|
|
688
|
+
const { widgetConfig } = consent;
|
|
689
|
+
return {
|
|
690
|
+
...consent,
|
|
691
|
+
widgetConfig: {
|
|
692
|
+
...widgetConfig,
|
|
693
|
+
text: widgetConfig.text === null ? null : toHtmlCopy(widgetConfig.text, widgetConfig, CHECKBOX_LABEL_BOLD_PHRASES),
|
|
694
|
+
consentDescription: widgetConfig.consentDescription === null ? null : toHtmlCopy(
|
|
695
|
+
widgetConfig.consentDescription,
|
|
696
|
+
widgetConfig,
|
|
697
|
+
CONSENT_DESCRIPTION_BOLD_PHRASES
|
|
698
|
+
)
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
})
|
|
702
|
+
});
|
|
703
|
+
var previewUpsertResponse = (identifierType, format = "json") => {
|
|
704
|
+
const response = identifierType === "PHONE" ? fakePhoneUpsertResponse : fakeEmailUpsertResponse;
|
|
705
|
+
return format === "html" ? withHtmlCopy(response) : response;
|
|
706
|
+
};
|
|
707
|
+
var randomUuid = (cryptoObj = globalThis.crypto) => {
|
|
708
|
+
if (cryptoObj && typeof cryptoObj.randomUUID === "function") {
|
|
709
|
+
return cryptoObj.randomUUID();
|
|
710
|
+
}
|
|
711
|
+
const bytes = new Uint8Array(16);
|
|
712
|
+
if (cryptoObj && typeof cryptoObj.getRandomValues === "function") {
|
|
713
|
+
cryptoObj.getRandomValues(bytes);
|
|
714
|
+
} else {
|
|
715
|
+
for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
716
|
+
}
|
|
717
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
718
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
719
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
720
|
+
return hex.slice(0, 4).join("") + "-" + hex.slice(4, 6).join("") + "-" + hex.slice(6, 8).join("") + "-" + hex.slice(8, 10).join("") + "-" + hex.slice(10, 16).join("");
|
|
721
|
+
};
|
|
722
|
+
var DATASHIPS_SESSION_ID_MAX_LENGTH = 100;
|
|
723
|
+
var _explicitId;
|
|
724
|
+
var _storageKey;
|
|
725
|
+
var _window;
|
|
726
|
+
var _id;
|
|
727
|
+
var _SessionBeacon_instances;
|
|
728
|
+
var safeStorage_fn;
|
|
729
|
+
var SessionBeacon = class {
|
|
730
|
+
constructor(opts) {
|
|
731
|
+
__privateAdd2(this, _SessionBeacon_instances);
|
|
732
|
+
__privateAdd2(this, _explicitId);
|
|
733
|
+
__privateAdd2(this, _storageKey);
|
|
734
|
+
__privateAdd2(this, _window);
|
|
735
|
+
__privateAdd2(this, _id, null);
|
|
736
|
+
if (opts.explicitId != null) assertSessionId(opts.explicitId);
|
|
737
|
+
__privateSet2(this, _explicitId, opts.explicitId ?? null);
|
|
738
|
+
__privateSet2(this, _storageKey, opts.storageKey);
|
|
739
|
+
__privateSet2(this, _window, opts.window ?? globalThis.window);
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* The beacon for this page. On first use a stored id is reused when
|
|
743
|
+
* `reusable(stored)` says so, otherwise a fresh UUID is minted; the record is
|
|
744
|
+
* rewritten with `step` every time so the next page knows where it was last
|
|
745
|
+
* used. Later calls return the same id for the adapter's lifetime.
|
|
746
|
+
*/
|
|
747
|
+
resolve(step, reusable) {
|
|
748
|
+
if (__privateGet2(this, _explicitId)) return __privateGet2(this, _explicitId);
|
|
749
|
+
const storage = __privateMethod2(this, _SessionBeacon_instances, safeStorage_fn).call(this);
|
|
750
|
+
if (null === __privateGet2(this, _id)) {
|
|
751
|
+
const stored = storage ? readStored(storage, __privateGet2(this, _storageKey)) : null;
|
|
752
|
+
__privateSet2(this, _id, stored && reusable(stored) ? stored.id : randomUuid(__privateGet2(this, _window)?.crypto));
|
|
753
|
+
}
|
|
754
|
+
if (storage) {
|
|
755
|
+
try {
|
|
756
|
+
storage.setItem(__privateGet2(this, _storageKey), JSON.stringify({ id: __privateGet2(this, _id), lastStep: step }));
|
|
757
|
+
} catch {
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return __privateGet2(this, _id);
|
|
761
|
+
}
|
|
762
|
+
/** Discard the beacon so the next {@link resolve} mints a fresh one. No-op for an integrator-owned id. */
|
|
763
|
+
reset() {
|
|
764
|
+
if (__privateGet2(this, _explicitId)) return;
|
|
765
|
+
__privateSet2(this, _id, null);
|
|
766
|
+
const storage = __privateMethod2(this, _SessionBeacon_instances, safeStorage_fn).call(this);
|
|
767
|
+
if (!storage) return;
|
|
768
|
+
try {
|
|
769
|
+
storage.removeItem(__privateGet2(this, _storageKey));
|
|
770
|
+
} catch {
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
_explicitId = /* @__PURE__ */ new WeakMap();
|
|
775
|
+
_storageKey = /* @__PURE__ */ new WeakMap();
|
|
776
|
+
_window = /* @__PURE__ */ new WeakMap();
|
|
777
|
+
_id = /* @__PURE__ */ new WeakMap();
|
|
778
|
+
_SessionBeacon_instances = /* @__PURE__ */ new WeakSet();
|
|
779
|
+
safeStorage_fn = function() {
|
|
780
|
+
try {
|
|
781
|
+
return __privateGet2(this, _window)?.localStorage ?? null;
|
|
782
|
+
} catch {
|
|
783
|
+
return null;
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
var assertSessionId = (id) => {
|
|
787
|
+
if (typeof id !== "string" || id.length === 0) {
|
|
788
|
+
throw new Error("datashipsSessionId must be a non-empty string");
|
|
789
|
+
}
|
|
790
|
+
if (id.length > DATASHIPS_SESSION_ID_MAX_LENGTH) {
|
|
791
|
+
throw new Error(
|
|
792
|
+
`datashipsSessionId must be at most ${DATASHIPS_SESSION_ID_MAX_LENGTH} characters`
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
var readStored = (storage, key) => {
|
|
797
|
+
let raw;
|
|
798
|
+
try {
|
|
799
|
+
raw = storage.getItem(key);
|
|
800
|
+
} catch {
|
|
801
|
+
return null;
|
|
802
|
+
}
|
|
803
|
+
if (!raw) return null;
|
|
804
|
+
try {
|
|
805
|
+
const parsed = JSON.parse(raw);
|
|
806
|
+
if (typeof parsed?.id !== "string" || parsed.id.length === 0) return null;
|
|
807
|
+
return { id: parsed.id, lastStep: typeof parsed.lastStep === "string" ? parsed.lastStep : null };
|
|
808
|
+
} catch {
|
|
809
|
+
return null;
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
var SUPPORTED_LOCALES = [
|
|
813
|
+
"en",
|
|
814
|
+
"es",
|
|
815
|
+
"de",
|
|
816
|
+
"pt",
|
|
817
|
+
"ro",
|
|
818
|
+
"hr",
|
|
819
|
+
"da",
|
|
820
|
+
"fi",
|
|
821
|
+
"fr",
|
|
822
|
+
"hu",
|
|
823
|
+
"it",
|
|
824
|
+
"nb",
|
|
825
|
+
"pl",
|
|
826
|
+
"sk",
|
|
827
|
+
"sv",
|
|
828
|
+
"nl",
|
|
829
|
+
"el",
|
|
830
|
+
"cs",
|
|
831
|
+
"zh",
|
|
832
|
+
"ja",
|
|
833
|
+
"is"
|
|
834
|
+
];
|
|
835
|
+
var coerceLocale = (raw) => {
|
|
836
|
+
if (!raw) return "en";
|
|
837
|
+
const head = raw.split(/[_-]/)[0]?.toLowerCase() ?? "";
|
|
838
|
+
return SUPPORTED_LOCALES.includes(head) ? head : "en";
|
|
839
|
+
};
|
|
840
|
+
var CUSTOM_PLATFORM_CHECKOUT_INTEGRATION_TYPE = "CUSTOM_PLATFORM_CHECKOUT";
|
|
841
|
+
var STORAGE_KEY_PREFIX = "datashipsSessionId:";
|
|
842
|
+
var DEFAULT_STORAGE_SCOPE = "default";
|
|
843
|
+
var _collectionStep;
|
|
844
|
+
var _locale;
|
|
845
|
+
var _isFastCheckout;
|
|
846
|
+
var _identifiers;
|
|
847
|
+
var _storageScope;
|
|
848
|
+
var _beacon;
|
|
849
|
+
var _CustomPlatformCheckoutAdapter_instances;
|
|
850
|
+
var resolveSessionId_fn;
|
|
851
|
+
var CustomPlatformCheckoutAdapter = class {
|
|
852
|
+
constructor(opts) {
|
|
853
|
+
__privateAdd2(this, _CustomPlatformCheckoutAdapter_instances);
|
|
854
|
+
this.name = "CustomPlatformCheckoutAdapter";
|
|
855
|
+
this.sessionApi = "consent-session";
|
|
856
|
+
this.integrationType = CUSTOM_PLATFORM_CHECKOUT_INTEGRATION_TYPE;
|
|
857
|
+
__privateAdd2(this, _collectionStep);
|
|
858
|
+
__privateAdd2(this, _locale);
|
|
859
|
+
__privateAdd2(this, _isFastCheckout);
|
|
860
|
+
__privateAdd2(this, _identifiers);
|
|
861
|
+
__privateAdd2(this, _storageScope);
|
|
862
|
+
__privateAdd2(this, _beacon);
|
|
863
|
+
if (!opts || !opts.collectionStep) {
|
|
864
|
+
throw new Error(
|
|
865
|
+
"CustomPlatformCheckoutAdapter: `collectionStep` is required"
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
__privateSet2(this, _collectionStep, opts.collectionStep);
|
|
869
|
+
__privateSet2(this, _locale, coerceLocale(opts.locale));
|
|
870
|
+
__privateSet2(this, _isFastCheckout, opts.isFastCheckout ?? false);
|
|
871
|
+
__privateSet2(this, _identifiers, {
|
|
872
|
+
EMAIL: opts.email ?? null,
|
|
873
|
+
PHONE: opts.phone ?? null
|
|
874
|
+
});
|
|
875
|
+
__privateSet2(this, _storageScope, opts.storageScope ?? DEFAULT_STORAGE_SCOPE);
|
|
876
|
+
try {
|
|
877
|
+
__privateSet2(this, _beacon, new SessionBeacon({
|
|
878
|
+
explicitId: opts.datashipsSessionId,
|
|
879
|
+
storageKey: `${STORAGE_KEY_PREFIX}${__privateGet2(this, _storageScope)}`,
|
|
880
|
+
window: opts.window
|
|
881
|
+
}));
|
|
882
|
+
} catch (e) {
|
|
883
|
+
throw new Error(`CustomPlatformCheckoutAdapter: ${e.message}`);
|
|
884
|
+
}
|
|
885
|
+
this.previewMode = opts.previewMode ?? false;
|
|
886
|
+
}
|
|
887
|
+
/** Synthetic upsert response served in {@link previewMode}, matching the requested identifier type. */
|
|
888
|
+
getPreviewUpsertResponse(identifierType = "EMAIL", format) {
|
|
889
|
+
return previewUpsertResponse(identifierType, format);
|
|
890
|
+
}
|
|
891
|
+
getLocale() {
|
|
892
|
+
return __privateGet2(this, _locale);
|
|
893
|
+
}
|
|
894
|
+
get collectionStep() {
|
|
895
|
+
return __privateGet2(this, _collectionStep);
|
|
896
|
+
}
|
|
897
|
+
/** Move the same adapter to another step, e.g. a single-page checkout reaching its confirmation view. */
|
|
898
|
+
setCollectionStep(step) {
|
|
899
|
+
__privateSet2(this, _collectionStep, step);
|
|
900
|
+
}
|
|
901
|
+
get isFastCheckout() {
|
|
902
|
+
return __privateGet2(this, _isFastCheckout);
|
|
903
|
+
}
|
|
904
|
+
setFastCheckout(isFastCheckout) {
|
|
905
|
+
__privateSet2(this, _isFastCheckout, isFastCheckout);
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Remember an identifier the shopper typed so later calls (a refresh, a
|
|
909
|
+
* remount) resolve it without the caller passing it again. An explicit
|
|
910
|
+
* `upsertSession({ identifier })` still takes precedence.
|
|
911
|
+
*/
|
|
912
|
+
setIdentifier(identifierType, value) {
|
|
913
|
+
__privateGet2(this, _identifiers)[identifierType] = value;
|
|
914
|
+
}
|
|
915
|
+
getIdentifier(identifierType) {
|
|
916
|
+
return { identifier: __privateGet2(this, _identifiers)[identifierType], identifierType };
|
|
917
|
+
}
|
|
918
|
+
/** The beacon this checkout is known by; resolved (and persisted) on first use. */
|
|
919
|
+
getDatashipsSessionId() {
|
|
920
|
+
return __privateMethod2(this, _CustomPlatformCheckoutAdapter_instances, resolveSessionId_fn).call(this);
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Discard the current beacon so the next call mints a fresh one. Call it once
|
|
924
|
+
* the order has been submitted, so the next checkout on this browser opens a
|
|
925
|
+
* new session instead of touching the processed one. No-op for an
|
|
926
|
+
* integrator-owned id.
|
|
927
|
+
*/
|
|
928
|
+
resetDatashipsSessionId() {
|
|
929
|
+
__privateGet2(this, _beacon).reset();
|
|
930
|
+
}
|
|
931
|
+
async getSessionContext() {
|
|
932
|
+
return {
|
|
933
|
+
collectionStep: __privateGet2(this, _collectionStep),
|
|
934
|
+
datashipsSessionId: __privateMethod2(this, _CustomPlatformCheckoutAdapter_instances, resolveSessionId_fn).call(this),
|
|
935
|
+
isFastCheckout: __privateGet2(this, _isFastCheckout)
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
};
|
|
939
|
+
_collectionStep = /* @__PURE__ */ new WeakMap();
|
|
940
|
+
_locale = /* @__PURE__ */ new WeakMap();
|
|
941
|
+
_isFastCheckout = /* @__PURE__ */ new WeakMap();
|
|
942
|
+
_identifiers = /* @__PURE__ */ new WeakMap();
|
|
943
|
+
_storageScope = /* @__PURE__ */ new WeakMap();
|
|
944
|
+
_beacon = /* @__PURE__ */ new WeakMap();
|
|
945
|
+
_CustomPlatformCheckoutAdapter_instances = /* @__PURE__ */ new WeakSet();
|
|
946
|
+
resolveSessionId_fn = function() {
|
|
947
|
+
const step = __privateGet2(this, _collectionStep);
|
|
948
|
+
return __privateGet2(this, _beacon).resolve(step, (stored) => {
|
|
949
|
+
const lastStep = isCollectionStep(stored.lastStep) ? stored.lastStep : "CHECKOUT_INFORMATION";
|
|
950
|
+
return !(step === "CHECKOUT_INFORMATION" && lastStep !== "CHECKOUT_INFORMATION");
|
|
951
|
+
});
|
|
952
|
+
};
|
|
953
|
+
var isCollectionStep = (value) => value === "CHECKOUT_INFORMATION" || value === "THANK_YOU" || value === "ORDER_STATUS";
|
|
954
|
+
|
|
955
|
+
// node_modules/@dataships/sdk/dist/adapters/custom-platform-signup/index.js
|
|
956
|
+
var __typeError3 = (msg) => {
|
|
957
|
+
throw TypeError(msg);
|
|
958
|
+
};
|
|
959
|
+
var __accessCheck3 = (obj, member, msg) => member.has(obj) || __typeError3("Cannot " + msg);
|
|
960
|
+
var __privateGet3 = (obj, member, getter) => (__accessCheck3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
961
|
+
var __privateAdd3 = (obj, member, value) => member.has(obj) ? __typeError3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
962
|
+
var __privateSet3 = (obj, member, value, setter) => (__accessCheck3(obj, member, "write to private field"), member.set(obj, value), value);
|
|
963
|
+
var __privateMethod3 = (obj, member, method) => (__accessCheck3(obj, member, "access private method"), method);
|
|
964
|
+
var DEFAULT_EMAIL_OPT_IN_TEXT2 = "We would like to email you news and promotions. Tick to opt in.";
|
|
965
|
+
var DEFAULT_EMAIL_OPT_IN_CONSENT_DESCRIPTION2 = "Click here for an overview of how your personal data is processed for marketing purposes or see our Privacy Policy for further information.";
|
|
966
|
+
var DEFAULT_SMS_OPT_IN_TEXT2 = "We would like to text you news and promotions. Tick to opt in.";
|
|
967
|
+
var DEFAULT_SMS_OPT_IN_CONSENT_DESCRIPTION2 = "Based on the channel preferences set above, you agree to receive recurring automated marketing messages (e.g. AI content, cart reminders) from {{COMPANY_NAME}} at the number you provide. Consent is not a condition of purchase. We may share info with service providers per our Privacy Policy. Reply STOP to cancel or click the unsubscribe link (where available). For help reply HELP or email {{PRIVACY_EMAIL}}. Msg frequency varies. Msg & data rates may apply. By proceeding, you also agree to our Terms of Service (incl. arbitration) & Privacy Policy.";
|
|
968
|
+
var fakeEmailUpsertResponse2 = {
|
|
969
|
+
consentSessionId: "01HQB3QRZVV0737R0R25BTQBGF",
|
|
970
|
+
consents: [
|
|
971
|
+
{
|
|
972
|
+
channel: "EMAIL",
|
|
973
|
+
consentType: "OPT_IN",
|
|
974
|
+
checked: false,
|
|
975
|
+
widgetConfig: {
|
|
976
|
+
text: DEFAULT_EMAIL_OPT_IN_TEXT2,
|
|
977
|
+
consentDescription: DEFAULT_EMAIL_OPT_IN_CONSENT_DESCRIPTION2,
|
|
978
|
+
marketingInformation: '<h1>Marketing Information</h1>\n<p>We may send you direct marketing communications, product information and promotional offers. You can withdraw your consent at any time. See our <a href="https://dataships.io/privacy-centre">Privacy Policy</a> or contact us at <a href="mailto:privacy@example.com">privacy@example.com</a> for further information.</p>\n',
|
|
979
|
+
policyURL: "https://dataships.io/privacy-centre",
|
|
980
|
+
mobileTermsOfServiceURL: null,
|
|
981
|
+
privacyEmail: "privacy@example.com",
|
|
982
|
+
placeholderValues: null
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
],
|
|
986
|
+
userVerificationRequired: null,
|
|
987
|
+
lastHeartbeat: "2026-06-17T00:00:00Z",
|
|
988
|
+
identifier: null
|
|
989
|
+
};
|
|
990
|
+
var fakePhoneUpsertResponse2 = {
|
|
991
|
+
consentSessionId: "01HQB3QRZVV0737R0R25BTQBGG",
|
|
992
|
+
consents: [
|
|
993
|
+
{
|
|
994
|
+
channel: "SMS",
|
|
995
|
+
consentType: "OPT_IN",
|
|
996
|
+
checked: false,
|
|
997
|
+
widgetConfig: {
|
|
998
|
+
text: DEFAULT_SMS_OPT_IN_TEXT2,
|
|
999
|
+
consentDescription: DEFAULT_SMS_OPT_IN_CONSENT_DESCRIPTION2,
|
|
1000
|
+
marketingInformation: '<h1>Marketing Information</h1>\n<p>We may send you marketing text messages about products and promotional offers. Message frequency varies. You can withdraw your consent at any time by replying STOP. See our <a href="https://dataships.io/privacy-centre">Privacy Policy</a> or contact us at <a href="mailto:privacy@example.com">privacy@example.com</a> for further information.</p>\n',
|
|
1001
|
+
policyURL: "https://dataships.io/privacy-centre",
|
|
1002
|
+
mobileTermsOfServiceURL: "https://dataships.io/mobile-terms",
|
|
1003
|
+
privacyEmail: "privacy@example.com",
|
|
1004
|
+
placeholderValues: null
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
],
|
|
1008
|
+
userVerificationRequired: false,
|
|
1009
|
+
lastHeartbeat: "2026-06-17T00:00:00Z",
|
|
1010
|
+
identifier: null
|
|
1011
|
+
};
|
|
1012
|
+
var MARKETING_MODAL_HREF2 = "#dataships-marketing-modal";
|
|
1013
|
+
var CHECKBOX_LABEL_BOLD_PHRASES2 = ["consent", "object", "opt in", "opt out", "STOP", "HELP"];
|
|
1014
|
+
var CONSENT_DESCRIPTION_BOLD_PHRASES2 = ["STOP", "HELP"];
|
|
1015
|
+
var escapeHtml2 = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1016
|
+
var escapeRegExp2 = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1017
|
+
var wrapPhrase2 = (html, phrase, wrap) => html.replace(
|
|
1018
|
+
new RegExp(`${escapeRegExp2(escapeHtml2(phrase))}(?![^<]*>)(?![^<]*</a>)`, "gi"),
|
|
1019
|
+
wrap
|
|
1020
|
+
);
|
|
1021
|
+
var toHtmlCopy2 = (text, widgetConfig, boldPhrases) => {
|
|
1022
|
+
let html = escapeHtml2(text);
|
|
1023
|
+
const links = [
|
|
1024
|
+
["Terms of Service", widgetConfig.mobileTermsOfServiceURL],
|
|
1025
|
+
["Privacy Policy", widgetConfig.policyURL],
|
|
1026
|
+
["Click here", MARKETING_MODAL_HREF2]
|
|
1027
|
+
];
|
|
1028
|
+
for (const [phrase, href] of links) {
|
|
1029
|
+
if (!href) continue;
|
|
1030
|
+
html = wrapPhrase2(html, phrase, (match) => `<a href="${escapeHtml2(href)}">${match}</a>`);
|
|
1031
|
+
}
|
|
1032
|
+
for (const phrase of boldPhrases) {
|
|
1033
|
+
html = wrapPhrase2(html, phrase, (match) => `<strong>${match}</strong>`);
|
|
1034
|
+
}
|
|
1035
|
+
return `<p>${html}</p>`;
|
|
1036
|
+
};
|
|
1037
|
+
var withHtmlCopy2 = (response) => ({
|
|
1038
|
+
...response,
|
|
1039
|
+
consents: response.consents.map((consent) => {
|
|
1040
|
+
const { widgetConfig } = consent;
|
|
1041
|
+
return {
|
|
1042
|
+
...consent,
|
|
1043
|
+
widgetConfig: {
|
|
1044
|
+
...widgetConfig,
|
|
1045
|
+
text: widgetConfig.text === null ? null : toHtmlCopy2(widgetConfig.text, widgetConfig, CHECKBOX_LABEL_BOLD_PHRASES2),
|
|
1046
|
+
consentDescription: widgetConfig.consentDescription === null ? null : toHtmlCopy2(
|
|
1047
|
+
widgetConfig.consentDescription,
|
|
1048
|
+
widgetConfig,
|
|
1049
|
+
CONSENT_DESCRIPTION_BOLD_PHRASES2
|
|
1050
|
+
)
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
})
|
|
1054
|
+
});
|
|
1055
|
+
var previewUpsertResponse2 = (identifierType, format = "json") => {
|
|
1056
|
+
const response = identifierType === "PHONE" ? fakePhoneUpsertResponse2 : fakeEmailUpsertResponse2;
|
|
1057
|
+
return format === "html" ? withHtmlCopy2(response) : response;
|
|
1058
|
+
};
|
|
1059
|
+
var randomUuid2 = (cryptoObj = globalThis.crypto) => {
|
|
1060
|
+
if (cryptoObj && typeof cryptoObj.randomUUID === "function") {
|
|
1061
|
+
return cryptoObj.randomUUID();
|
|
1062
|
+
}
|
|
1063
|
+
const bytes = new Uint8Array(16);
|
|
1064
|
+
if (cryptoObj && typeof cryptoObj.getRandomValues === "function") {
|
|
1065
|
+
cryptoObj.getRandomValues(bytes);
|
|
1066
|
+
} else {
|
|
1067
|
+
for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
1068
|
+
}
|
|
1069
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
1070
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
1071
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
1072
|
+
return hex.slice(0, 4).join("") + "-" + hex.slice(4, 6).join("") + "-" + hex.slice(6, 8).join("") + "-" + hex.slice(8, 10).join("") + "-" + hex.slice(10, 16).join("");
|
|
1073
|
+
};
|
|
1074
|
+
var DATASHIPS_SESSION_ID_MAX_LENGTH2 = 100;
|
|
1075
|
+
var _explicitId2;
|
|
1076
|
+
var _storageKey2;
|
|
1077
|
+
var _window2;
|
|
1078
|
+
var _id2;
|
|
1079
|
+
var _SessionBeacon_instances2;
|
|
1080
|
+
var safeStorage_fn2;
|
|
1081
|
+
var SessionBeacon2 = class {
|
|
1082
|
+
constructor(opts) {
|
|
1083
|
+
__privateAdd3(this, _SessionBeacon_instances2);
|
|
1084
|
+
__privateAdd3(this, _explicitId2);
|
|
1085
|
+
__privateAdd3(this, _storageKey2);
|
|
1086
|
+
__privateAdd3(this, _window2);
|
|
1087
|
+
__privateAdd3(this, _id2, null);
|
|
1088
|
+
if (opts.explicitId != null) assertSessionId2(opts.explicitId);
|
|
1089
|
+
__privateSet3(this, _explicitId2, opts.explicitId ?? null);
|
|
1090
|
+
__privateSet3(this, _storageKey2, opts.storageKey);
|
|
1091
|
+
__privateSet3(this, _window2, opts.window ?? globalThis.window);
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* The beacon for this page. On first use a stored id is reused when
|
|
1095
|
+
* `reusable(stored)` says so, otherwise a fresh UUID is minted; the record is
|
|
1096
|
+
* rewritten with `step` every time so the next page knows where it was last
|
|
1097
|
+
* used. Later calls return the same id for the adapter's lifetime.
|
|
1098
|
+
*/
|
|
1099
|
+
resolve(step, reusable) {
|
|
1100
|
+
if (__privateGet3(this, _explicitId2)) return __privateGet3(this, _explicitId2);
|
|
1101
|
+
const storage = __privateMethod3(this, _SessionBeacon_instances2, safeStorage_fn2).call(this);
|
|
1102
|
+
if (null === __privateGet3(this, _id2)) {
|
|
1103
|
+
const stored = storage ? readStored2(storage, __privateGet3(this, _storageKey2)) : null;
|
|
1104
|
+
__privateSet3(this, _id2, stored && reusable(stored) ? stored.id : randomUuid2(__privateGet3(this, _window2)?.crypto));
|
|
1105
|
+
}
|
|
1106
|
+
if (storage) {
|
|
1107
|
+
try {
|
|
1108
|
+
storage.setItem(__privateGet3(this, _storageKey2), JSON.stringify({ id: __privateGet3(this, _id2), lastStep: step }));
|
|
1109
|
+
} catch {
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
return __privateGet3(this, _id2);
|
|
1113
|
+
}
|
|
1114
|
+
/** Discard the beacon so the next {@link resolve} mints a fresh one. No-op for an integrator-owned id. */
|
|
1115
|
+
reset() {
|
|
1116
|
+
if (__privateGet3(this, _explicitId2)) return;
|
|
1117
|
+
__privateSet3(this, _id2, null);
|
|
1118
|
+
const storage = __privateMethod3(this, _SessionBeacon_instances2, safeStorage_fn2).call(this);
|
|
1119
|
+
if (!storage) return;
|
|
1120
|
+
try {
|
|
1121
|
+
storage.removeItem(__privateGet3(this, _storageKey2));
|
|
1122
|
+
} catch {
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
_explicitId2 = /* @__PURE__ */ new WeakMap();
|
|
1127
|
+
_storageKey2 = /* @__PURE__ */ new WeakMap();
|
|
1128
|
+
_window2 = /* @__PURE__ */ new WeakMap();
|
|
1129
|
+
_id2 = /* @__PURE__ */ new WeakMap();
|
|
1130
|
+
_SessionBeacon_instances2 = /* @__PURE__ */ new WeakSet();
|
|
1131
|
+
safeStorage_fn2 = function() {
|
|
1132
|
+
try {
|
|
1133
|
+
return __privateGet3(this, _window2)?.localStorage ?? null;
|
|
1134
|
+
} catch {
|
|
1135
|
+
return null;
|
|
1136
|
+
}
|
|
1137
|
+
};
|
|
1138
|
+
var assertSessionId2 = (id) => {
|
|
1139
|
+
if (typeof id !== "string" || id.length === 0) {
|
|
1140
|
+
throw new Error("datashipsSessionId must be a non-empty string");
|
|
1141
|
+
}
|
|
1142
|
+
if (id.length > DATASHIPS_SESSION_ID_MAX_LENGTH2) {
|
|
1143
|
+
throw new Error(
|
|
1144
|
+
`datashipsSessionId must be at most ${DATASHIPS_SESSION_ID_MAX_LENGTH2} characters`
|
|
1145
|
+
);
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
var readStored2 = (storage, key) => {
|
|
1149
|
+
let raw;
|
|
1150
|
+
try {
|
|
1151
|
+
raw = storage.getItem(key);
|
|
1152
|
+
} catch {
|
|
1153
|
+
return null;
|
|
1154
|
+
}
|
|
1155
|
+
if (!raw) return null;
|
|
1156
|
+
try {
|
|
1157
|
+
const parsed = JSON.parse(raw);
|
|
1158
|
+
if (typeof parsed?.id !== "string" || parsed.id.length === 0) return null;
|
|
1159
|
+
return { id: parsed.id, lastStep: typeof parsed.lastStep === "string" ? parsed.lastStep : null };
|
|
1160
|
+
} catch {
|
|
1161
|
+
return null;
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
var SUPPORTED_LOCALES2 = [
|
|
1165
|
+
"en",
|
|
1166
|
+
"es",
|
|
1167
|
+
"de",
|
|
1168
|
+
"pt",
|
|
1169
|
+
"ro",
|
|
1170
|
+
"hr",
|
|
1171
|
+
"da",
|
|
1172
|
+
"fi",
|
|
1173
|
+
"fr",
|
|
1174
|
+
"hu",
|
|
1175
|
+
"it",
|
|
1176
|
+
"nb",
|
|
1177
|
+
"pl",
|
|
1178
|
+
"sk",
|
|
1179
|
+
"sv",
|
|
1180
|
+
"nl",
|
|
1181
|
+
"el",
|
|
1182
|
+
"cs",
|
|
1183
|
+
"zh",
|
|
1184
|
+
"ja",
|
|
1185
|
+
"is"
|
|
1186
|
+
];
|
|
1187
|
+
var coerceLocale2 = (raw) => {
|
|
1188
|
+
if (!raw) return "en";
|
|
1189
|
+
const head = raw.split(/[_-]/)[0]?.toLowerCase() ?? "";
|
|
1190
|
+
return SUPPORTED_LOCALES2.includes(head) ? head : "en";
|
|
1191
|
+
};
|
|
1192
|
+
var CUSTOM_PLATFORM_SIGNUP_INTEGRATION_TYPE = "CUSTOM_PLATFORM_SIGNUP";
|
|
1193
|
+
var STORAGE_KEY_PREFIX2 = "datashipsSignupSessionId:";
|
|
1194
|
+
var DEFAULT_STORAGE_SCOPE2 = "default";
|
|
1195
|
+
var _locale2;
|
|
1196
|
+
var _user;
|
|
1197
|
+
var _identifiers2;
|
|
1198
|
+
var _storageScope2;
|
|
1199
|
+
var _beacon2;
|
|
1200
|
+
var CustomPlatformSignupAdapter = class {
|
|
1201
|
+
constructor(opts = {}) {
|
|
1202
|
+
this.name = "CustomPlatformSignupAdapter";
|
|
1203
|
+
this.sessionApi = "consent-session";
|
|
1204
|
+
this.integrationType = CUSTOM_PLATFORM_SIGNUP_INTEGRATION_TYPE;
|
|
1205
|
+
__privateAdd3(this, _locale2);
|
|
1206
|
+
__privateAdd3(this, _user);
|
|
1207
|
+
__privateAdd3(this, _identifiers2, {});
|
|
1208
|
+
__privateAdd3(this, _storageScope2);
|
|
1209
|
+
__privateAdd3(this, _beacon2);
|
|
1210
|
+
__privateSet3(this, _locale2, coerceLocale2(opts.locale));
|
|
1211
|
+
__privateSet3(this, _user, opts.user ?? {});
|
|
1212
|
+
__privateSet3(this, _storageScope2, opts.storageScope ?? DEFAULT_STORAGE_SCOPE2);
|
|
1213
|
+
try {
|
|
1214
|
+
__privateSet3(this, _beacon2, new SessionBeacon2({
|
|
1215
|
+
explicitId: opts.datashipsSessionId,
|
|
1216
|
+
storageKey: `${STORAGE_KEY_PREFIX2}${__privateGet3(this, _storageScope2)}`,
|
|
1217
|
+
window: opts.window
|
|
1218
|
+
}));
|
|
1219
|
+
} catch (e) {
|
|
1220
|
+
throw new Error(`CustomPlatformSignupAdapter: ${e.message}`);
|
|
1221
|
+
}
|
|
1222
|
+
this.previewMode = opts.previewMode ?? false;
|
|
1223
|
+
}
|
|
1224
|
+
/** Synthetic upsert response served in {@link previewMode}, matching the requested identifier type. */
|
|
1225
|
+
getPreviewUpsertResponse(identifierType = "EMAIL", format) {
|
|
1226
|
+
return previewUpsertResponse2(identifierType, format);
|
|
1227
|
+
}
|
|
1228
|
+
getLocale() {
|
|
1229
|
+
return __privateGet3(this, _locale2);
|
|
1230
|
+
}
|
|
1231
|
+
/** Change the envelope locale, e.g. when the visitor switches language on the form. */
|
|
1232
|
+
setLocale(locale) {
|
|
1233
|
+
__privateSet3(this, _locale2, coerceLocale2(locale));
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Remember an identifier the visitor typed so later calls resolve it without
|
|
1237
|
+
* the user resolver. Pass null to fall back to the resolver again. An
|
|
1238
|
+
* explicit `upsertSession({ identifier })` still takes precedence.
|
|
1239
|
+
*/
|
|
1240
|
+
setIdentifier(identifierType, value) {
|
|
1241
|
+
if (value === null) delete __privateGet3(this, _identifiers2)[identifierType];
|
|
1242
|
+
else __privateGet3(this, _identifiers2)[identifierType] = value;
|
|
1243
|
+
}
|
|
1244
|
+
async getIdentifier(identifierType) {
|
|
1245
|
+
const pinned = __privateGet3(this, _identifiers2)[identifierType];
|
|
1246
|
+
if (pinned !== void 0) return { identifier: normalise(pinned), identifierType };
|
|
1247
|
+
const user = await this.getUser();
|
|
1248
|
+
const identifier = "PHONE" === identifierType ? user.phone : user.email;
|
|
1249
|
+
return { identifier: normalise(identifier), identifierType };
|
|
1250
|
+
}
|
|
1251
|
+
/** The user as the merchant's form or backend knows them right now, names and contacts trimmed. */
|
|
1252
|
+
async getUser() {
|
|
1253
|
+
const raw = typeof __privateGet3(this, _user) === "function" ? await __privateGet3(this, _user).call(this) : __privateGet3(this, _user);
|
|
1254
|
+
return {
|
|
1255
|
+
firstName: normalise(raw.firstName),
|
|
1256
|
+
lastName: normalise(raw.lastName),
|
|
1257
|
+
email: normalise(raw.email),
|
|
1258
|
+
phone: normalise(raw.phone)
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
/** The beacon this form fill is known by; resolved (and persisted) on first use. */
|
|
1262
|
+
getDatashipsSessionId() {
|
|
1263
|
+
return __privateGet3(this, _beacon2).resolve(null, () => true);
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* Discard the current beacon so the next call mints a fresh one. Call it once
|
|
1267
|
+
* the form has been submitted, so a second signup on this browser opens a new
|
|
1268
|
+
* session instead of touching the completed one. No-op for an
|
|
1269
|
+
* integrator-owned id.
|
|
1270
|
+
*/
|
|
1271
|
+
resetDatashipsSessionId() {
|
|
1272
|
+
__privateGet3(this, _beacon2).reset();
|
|
1273
|
+
}
|
|
1274
|
+
async getSessionContext() {
|
|
1275
|
+
return { datashipsSessionId: this.getDatashipsSessionId() };
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
_locale2 = /* @__PURE__ */ new WeakMap();
|
|
1279
|
+
_user = /* @__PURE__ */ new WeakMap();
|
|
1280
|
+
_identifiers2 = /* @__PURE__ */ new WeakMap();
|
|
1281
|
+
_storageScope2 = /* @__PURE__ */ new WeakMap();
|
|
1282
|
+
_beacon2 = /* @__PURE__ */ new WeakMap();
|
|
1283
|
+
var normalise = (value) => {
|
|
1284
|
+
const trimmed = value?.trim();
|
|
1285
|
+
return trimmed ? trimmed : null;
|
|
1286
|
+
};
|
|
1287
|
+
|
|
1288
|
+
// node_modules/@dataships/elements/dist/elements.mjs
|
|
1289
|
+
var __typeError4 = (msg) => {
|
|
1290
|
+
throw TypeError(msg);
|
|
1291
|
+
};
|
|
1292
|
+
var __accessCheck4 = (obj, member, msg) => member.has(obj) || __typeError4("Cannot " + msg);
|
|
1293
|
+
var __privateGet4 = (obj, member, getter) => (__accessCheck4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
1294
|
+
var __privateAdd4 = (obj, member, value) => member.has(obj) ? __typeError4("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1295
|
+
var __privateSet4 = (obj, member, value, setter) => (__accessCheck4(obj, member, "write to private field"), member.set(obj, value), value);
|
|
1296
|
+
var __privateMethod4 = (obj, member, method) => (__accessCheck4(obj, member, "access private method"), method);
|
|
1297
|
+
var BASE_STYLES = (
|
|
1298
|
+
/* css */
|
|
1299
|
+
`
|
|
1300
|
+
:host {
|
|
1301
|
+
display: none;
|
|
1302
|
+
box-sizing: border-box;
|
|
1303
|
+
font-family: var(--ds-font-family, inherit);
|
|
1304
|
+
font-size: var(--ds-font-size, inherit);
|
|
1305
|
+
color: var(--ds-color-text, inherit);
|
|
1306
|
+
line-height: 1.45;
|
|
1307
|
+
}
|
|
1308
|
+
:host([data-visible]) { display: block; margin-block: calc(var(--ds-spacing, 12px) * 0.5) var(--ds-spacing, 12px); }
|
|
1309
|
+
*, *::before, *::after { box-sizing: inherit; }
|
|
1310
|
+
|
|
1311
|
+
.root { display: grid; gap: calc(var(--ds-spacing, 12px) * 0.66); }
|
|
1312
|
+
.root--boxed {
|
|
1313
|
+
padding: var(--ds-spacing, 12px);
|
|
1314
|
+
border: 1px solid var(--ds-color-border, #d1d5db);
|
|
1315
|
+
border-radius: var(--ds-border-radius, 6px);
|
|
1316
|
+
background: var(--ds-color-background, transparent);
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
.heading { margin: 0; font-size: 1.1em; font-weight: 600; }
|
|
1320
|
+
|
|
1321
|
+
.consent { display: grid; grid-template-columns: auto 1fr; gap: calc(var(--ds-spacing, 12px) * 0.75); align-items: start; }
|
|
1322
|
+
.checkbox {
|
|
1323
|
+
margin: 0.2em 0 0;
|
|
1324
|
+
width: 1.1em; height: 1.1em;
|
|
1325
|
+
accent-color: var(--ds-color-primary, #1f6feb);
|
|
1326
|
+
cursor: pointer;
|
|
1327
|
+
}
|
|
1328
|
+
.checkbox:disabled { cursor: progress; opacity: 0.6; }
|
|
1329
|
+
.checkbox:focus-visible { outline: 2px solid var(--ds-color-primary, #1f6feb); outline-offset: 2px; }
|
|
1330
|
+
.label { cursor: pointer; }
|
|
1331
|
+
.label--saving { opacity: 0.6; }
|
|
1332
|
+
|
|
1333
|
+
.link {
|
|
1334
|
+
color: var(--ds-color-primary, #1f6feb);
|
|
1335
|
+
text-decoration: underline;
|
|
1336
|
+
background: none; border: 0; padding: 0; margin: 0;
|
|
1337
|
+
font: inherit; cursor: pointer;
|
|
1338
|
+
}
|
|
1339
|
+
.link:focus-visible { outline: 2px solid var(--ds-color-primary, #1f6feb); outline-offset: 2px; border-radius: 2px; }
|
|
1340
|
+
|
|
1341
|
+
.description { margin: 0; font-size: 0.875em; color: var(--ds-color-text-secondary, #6b7280); }
|
|
1342
|
+
|
|
1343
|
+
/* Styled by a class of the host page (\`className\`): the copy takes what the element has. */
|
|
1344
|
+
:host([data-host-styled]) .description { font-size: var(--ds-font-size, inherit); color: var(--ds-color-text-secondary, inherit); }
|
|
1345
|
+
:host([data-host-styled]) .root .link { color: var(--ds-color-primary, inherit); }
|
|
1346
|
+
/* The modal has its own background, so it must not take the page's text styles. */
|
|
1347
|
+
:host([data-host-styled]) .modal { color: var(--ds-color-text, #111827); font-size: 1rem; text-align: start; }
|
|
1348
|
+
|
|
1349
|
+
.modal {
|
|
1350
|
+
max-width: min(560px, 90vw);
|
|
1351
|
+
padding: 0;
|
|
1352
|
+
border: 1px solid var(--ds-color-border, #d1d5db);
|
|
1353
|
+
border-radius: var(--ds-border-radius, 6px);
|
|
1354
|
+
background: var(--ds-color-background, #fff);
|
|
1355
|
+
color: var(--ds-color-text, inherit);
|
|
1356
|
+
font: inherit;
|
|
1357
|
+
}
|
|
1358
|
+
.modal::backdrop { background: rgb(0 0 0 / 0.45); }
|
|
1359
|
+
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: var(--ds-spacing, 12px); padding: var(--ds-spacing, 12px) calc(var(--ds-spacing, 12px) * 1.25); border-bottom: 1px solid var(--ds-color-border, #d1d5db); }
|
|
1360
|
+
.modal-title { margin: 0; font-size: 1.1em; font-weight: 600; }
|
|
1361
|
+
.modal-close { background: none; border: 0; font: inherit; font-size: 1.4em; line-height: 1; cursor: pointer; color: inherit; padding: 0 0.25em; }
|
|
1362
|
+
.modal-close:focus-visible { outline: 2px solid var(--ds-color-primary, #1f6feb); border-radius: 2px; }
|
|
1363
|
+
.modal-body { padding: var(--ds-spacing, 12px) calc(var(--ds-spacing, 12px) * 1.25); font-size: 0.95em; }
|
|
1364
|
+
.modal-body a { color: var(--ds-color-primary, #1f6feb); }
|
|
1365
|
+
.modal-body > :first-child { margin-top: 0; }
|
|
1366
|
+
.modal-body > :last-child { margin-bottom: 0; }
|
|
1367
|
+
`
|
|
1368
|
+
);
|
|
1369
|
+
var WORDS = {
|
|
1370
|
+
en: { clickHere: "Click here", privacyPolicy: "Privacy Policy", termsOfService: "Terms of Service", consent: "consent", object: "object", optIn: "opt in", optOut: "opt out" },
|
|
1371
|
+
es: { clickHere: "Haz clic aqu\xED", privacyPolicy: "Pol\xEDtica de privacidad", termsOfService: "Condiciones del servicio", consent: "consentimiento", object: "oponerte", optIn: "inscribirte", optOut: "no quieres recibirlo" },
|
|
1372
|
+
de: { clickHere: "Klicken Sie hier", privacyPolicy: "Datenschutzrichtlinie", termsOfService: "Servicebedingungen", consent: "Zustimmung", object: "protestieren", optIn: "zuzustimmen", optOut: "widersprechen" },
|
|
1373
|
+
fr: { clickHere: "Cliquez ici", privacyPolicy: "Politique de confidentialit\xE9", termsOfService: "Conditions d'utilisation", consent: "consentement", object: "d\xE9sapprouver", optIn: "accepter", optOut: "refuser" }
|
|
1374
|
+
};
|
|
1375
|
+
var escapeRegExp3 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1376
|
+
var formatCopy = (text, locale, rules) => {
|
|
1377
|
+
if (!text) return [];
|
|
1378
|
+
const map = WORDS[(locale || "en").split("-")[0]] ?? WORDS.en;
|
|
1379
|
+
const keys = Object.keys(rules).filter((k) => map[k]);
|
|
1380
|
+
if (!keys.length) return [document.createTextNode(text)];
|
|
1381
|
+
const regex = new RegExp(`(${keys.map((k) => escapeRegExp3(map[k])).join("|")})`, "gi");
|
|
1382
|
+
return text.split(regex).filter((part) => part !== "").map((part) => {
|
|
1383
|
+
const key = keys.find((k) => map[k].toLowerCase() === part.toLowerCase());
|
|
1384
|
+
const wrap = key ? rules[key] : void 0;
|
|
1385
|
+
return wrap ? wrap(part) : document.createTextNode(part);
|
|
1386
|
+
});
|
|
1387
|
+
};
|
|
1388
|
+
var ALLOWED_TAGS = /* @__PURE__ */ new Set(["H1", "H2", "H3", "P", "BR", "UL", "OL", "LI", "A", "STRONG", "B", "EM", "I"]);
|
|
1389
|
+
var DROPPED_TAGS = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "IFRAME", "OBJECT", "EMBED", "NOSCRIPT", "SVG", "MATH", "TITLE", "TEXTAREA", "SELECT"]);
|
|
1390
|
+
var ALLOWED_PROTOCOLS = /* @__PURE__ */ new Set(["https:", "mailto:"]);
|
|
1391
|
+
var CONFIG_URL_PROTOCOLS = /* @__PURE__ */ new Set(["https:", "http:", "mailto:"]);
|
|
1392
|
+
var safeHref = (href, protocols = ALLOWED_PROTOCOLS) => {
|
|
1393
|
+
if (!href) return null;
|
|
1394
|
+
try {
|
|
1395
|
+
return protocols.has(new URL(href.trim()).protocol) ? href.trim() : null;
|
|
1396
|
+
} catch {
|
|
1397
|
+
return null;
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
var sanitizeInto = (source, target) => {
|
|
1401
|
+
source.childNodes.forEach((node) => {
|
|
1402
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
1403
|
+
target.appendChild(document.createTextNode(node.textContent ?? ""));
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
1406
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return;
|
|
1407
|
+
const tag = node.tagName.toUpperCase();
|
|
1408
|
+
if (DROPPED_TAGS.has(tag)) return;
|
|
1409
|
+
if (!ALLOWED_TAGS.has(tag)) {
|
|
1410
|
+
sanitizeInto(node, target);
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
const clean = document.createElement(tag.toLowerCase());
|
|
1414
|
+
if (tag === "A") {
|
|
1415
|
+
const href = safeHref(node.getAttribute("href"));
|
|
1416
|
+
if (href) clean.setAttribute("href", href);
|
|
1417
|
+
if (href && /^https:/i.test(href)) {
|
|
1418
|
+
clean.setAttribute("target", "_blank");
|
|
1419
|
+
clean.setAttribute("rel", "noreferrer noopener");
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
sanitizeInto(node, clean);
|
|
1423
|
+
target.appendChild(clean);
|
|
1424
|
+
});
|
|
1425
|
+
};
|
|
1426
|
+
var sanitizeHtml = (html) => {
|
|
1427
|
+
const tpl = document.createElement("template");
|
|
1428
|
+
tpl.innerHTML = html || "";
|
|
1429
|
+
const out = document.createDocumentFragment();
|
|
1430
|
+
sanitizeInto(tpl.content, out);
|
|
1431
|
+
return out;
|
|
1432
|
+
};
|
|
1433
|
+
var splitMarketingHtml = (html) => {
|
|
1434
|
+
const body = sanitizeHtml(html);
|
|
1435
|
+
const heading = body.querySelector("h1, h2");
|
|
1436
|
+
const title = heading?.textContent?.trim() || null;
|
|
1437
|
+
heading?.remove();
|
|
1438
|
+
return { title, body };
|
|
1439
|
+
};
|
|
1440
|
+
var TOKENS = {
|
|
1441
|
+
colorPrimary: { css: "--ds-color-primary", default: "#1f6feb", doc: "checkbox accent, links, focus ring" },
|
|
1442
|
+
colorText: { css: "--ds-color-text", default: "inherit", doc: "label, heading, modal body" },
|
|
1443
|
+
colorTextSecondary: { css: "--ds-color-text-secondary", default: "#6b7280", doc: "description paragraph" },
|
|
1444
|
+
colorBackground: { css: "--ds-color-background", default: "transparent", doc: "confirmation box + modal" },
|
|
1445
|
+
colorBorder: { css: "--ds-color-border", default: "#d1d5db", doc: "confirmation box + modal border" },
|
|
1446
|
+
fontFamily: { css: "--ds-font-family", default: "inherit", doc: "inherit = the host page's font" },
|
|
1447
|
+
fontSize: { css: "--ds-font-size", default: "inherit", doc: "base; description scales from it" },
|
|
1448
|
+
borderRadius: { css: "--ds-border-radius", default: "6px", doc: "" },
|
|
1449
|
+
spacing: { css: "--ds-spacing", default: "12px", doc: "internal padding / gaps" }
|
|
1450
|
+
};
|
|
1451
|
+
var FORBIDDEN = /url\s*\(|expression\s*\(|!important|[;{}]/i;
|
|
1452
|
+
var validateAppearance = (appearance = {}) => {
|
|
1453
|
+
const errors = [];
|
|
1454
|
+
for (const [key, value] of Object.entries(appearance)) {
|
|
1455
|
+
if (!(key in TOKENS)) errors.push(`unknown appearance token "${key}"`);
|
|
1456
|
+
else if (typeof value !== "string") errors.push(`appearance.${key} must be a string`);
|
|
1457
|
+
else if (FORBIDDEN.test(value)) errors.push(`appearance.${key} contains a forbidden value`);
|
|
1458
|
+
}
|
|
1459
|
+
return errors;
|
|
1460
|
+
};
|
|
1461
|
+
var applyAppearance = (host, appearance = {}) => {
|
|
1462
|
+
for (const [key, meta] of Object.entries(TOKENS)) {
|
|
1463
|
+
const value = appearance[key];
|
|
1464
|
+
if (value) host.style.setProperty(meta.css, value);
|
|
1465
|
+
else host.style.removeProperty(meta.css);
|
|
1466
|
+
}
|
|
1467
|
+
};
|
|
1468
|
+
var el = (tag, { className, text, attrs = {} } = {}, children = []) => {
|
|
1469
|
+
const node = document.createElement(tag);
|
|
1470
|
+
if (className) node.className = className;
|
|
1471
|
+
if (text != null) node.textContent = text;
|
|
1472
|
+
for (const [k, v] of Object.entries(attrs)) if (v != null) node.setAttribute(k, v);
|
|
1473
|
+
for (const c of children) node.append(c);
|
|
1474
|
+
return node;
|
|
1475
|
+
};
|
|
1476
|
+
var _shadow;
|
|
1477
|
+
var _root;
|
|
1478
|
+
var _onConsentChange;
|
|
1479
|
+
var _DatashipsWidget_instances;
|
|
1480
|
+
var renderInto_fn;
|
|
1481
|
+
var buildModal_fn;
|
|
1482
|
+
var DatashipsWidget = class extends HTMLElement {
|
|
1483
|
+
constructor() {
|
|
1484
|
+
super();
|
|
1485
|
+
__privateAdd4(this, _DatashipsWidget_instances);
|
|
1486
|
+
__privateAdd4(this, _shadow);
|
|
1487
|
+
__privateAdd4(this, _root, null);
|
|
1488
|
+
__privateAdd4(this, _onConsentChange, null);
|
|
1489
|
+
__privateSet4(this, _shadow, this.attachShadow({ mode: "open" }));
|
|
1490
|
+
const style = document.createElement("style");
|
|
1491
|
+
style.textContent = BASE_STYLES;
|
|
1492
|
+
__privateGet4(this, _shadow).append(style);
|
|
1493
|
+
}
|
|
1494
|
+
/** Resolves false to revert the checkbox. */
|
|
1495
|
+
set onConsentChange(fn) {
|
|
1496
|
+
__privateSet4(this, _onConsentChange, fn);
|
|
1497
|
+
}
|
|
1498
|
+
setAppearance(appearance) {
|
|
1499
|
+
applyAppearance(this, appearance);
|
|
1500
|
+
}
|
|
1501
|
+
get visible() {
|
|
1502
|
+
return this.hasAttribute("data-visible");
|
|
1503
|
+
}
|
|
1504
|
+
render(response, options) {
|
|
1505
|
+
const wasVisible = this.visible;
|
|
1506
|
+
__privateMethod4(this, _DatashipsWidget_instances, renderInto_fn).call(this, response, options);
|
|
1507
|
+
if (this.visible !== wasVisible) {
|
|
1508
|
+
this.dispatchEvent(new CustomEvent("dataships:visibility", { detail: { visible: this.visible }, bubbles: true, composed: true }));
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
};
|
|
1512
|
+
_shadow = /* @__PURE__ */ new WeakMap();
|
|
1513
|
+
_root = /* @__PURE__ */ new WeakMap();
|
|
1514
|
+
_onConsentChange = /* @__PURE__ */ new WeakMap();
|
|
1515
|
+
_DatashipsWidget_instances = /* @__PURE__ */ new WeakSet();
|
|
1516
|
+
renderInto_fn = function(response, { page, locale = "en", heading = "Email marketing preferences", channel = "EMAIL" }) {
|
|
1517
|
+
__privateGet4(this, _root)?.remove();
|
|
1518
|
+
__privateSet4(this, _root, null);
|
|
1519
|
+
const item = (response?.consents ?? []).find((c) => c.channel === channel);
|
|
1520
|
+
if (!item) {
|
|
1521
|
+
this.removeAttribute("data-visible");
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
const cfg = item.widgetConfig ?? {};
|
|
1525
|
+
const description = page === "form" ? cfg.consentDescription || cfg.text : cfg.consentDescription;
|
|
1526
|
+
const showCheckbox = page !== "form" && item.consentType !== "NONE" && !!cfg.text;
|
|
1527
|
+
const isControl = !cfg.consentDescription && !cfg.marketingInformation;
|
|
1528
|
+
const boxed = page === "confirmation";
|
|
1529
|
+
if (!showCheckbox && !description) {
|
|
1530
|
+
this.removeAttribute("data-visible");
|
|
1531
|
+
return;
|
|
1532
|
+
}
|
|
1533
|
+
const root = el("section", { className: `root${boxed ? " root--boxed" : ""}`, attrs: { "data-page": page, "data-consent-type": item.consentType } });
|
|
1534
|
+
if (boxed && !isControl) root.append(el("h2", { className: "heading", text: heading }));
|
|
1535
|
+
const modal = __privateMethod4(this, _DatashipsWidget_instances, buildModal_fn).call(this, cfg);
|
|
1536
|
+
const openModal = () => {
|
|
1537
|
+
try {
|
|
1538
|
+
modal?.showModal();
|
|
1539
|
+
} catch {
|
|
1540
|
+
modal?.setAttribute("open", "");
|
|
1541
|
+
}
|
|
1542
|
+
};
|
|
1543
|
+
const link = (text, href) => {
|
|
1544
|
+
const safe = safeHref(href ?? null, CONFIG_URL_PROTOCOLS);
|
|
1545
|
+
return safe ? el("a", { className: "link", text, attrs: { href: safe, target: "_blank", rel: "noreferrer noopener" } }) : document.createTextNode(text);
|
|
1546
|
+
};
|
|
1547
|
+
const rules = (policyURL) => ({
|
|
1548
|
+
consent: (m) => el("strong", { text: m }),
|
|
1549
|
+
object: (m) => el("strong", { text: m }),
|
|
1550
|
+
optIn: (m) => el("strong", { text: m }),
|
|
1551
|
+
optOut: (m) => el("strong", { text: m }),
|
|
1552
|
+
clickHere: (m) => {
|
|
1553
|
+
if (!modal) return document.createTextNode(m);
|
|
1554
|
+
const b = el("button", { className: "link", text: m, attrs: { type: "button" } });
|
|
1555
|
+
b.addEventListener("click", openModal);
|
|
1556
|
+
return b;
|
|
1557
|
+
},
|
|
1558
|
+
privacyPolicy: (m) => link(m, policyURL),
|
|
1559
|
+
// SMS copy also names the mobile terms; email copy keeps linking the privacy policy only.
|
|
1560
|
+
...channel === "SMS" ? { termsOfService: (m) => link(m, cfg.mobileTermsOfServiceURL) } : {}
|
|
1561
|
+
});
|
|
1562
|
+
if (showCheckbox) {
|
|
1563
|
+
const id = "dataships-consent-checkbox";
|
|
1564
|
+
const checkbox = el("input", { className: "checkbox", attrs: { type: "checkbox", id, name: item.channel } });
|
|
1565
|
+
checkbox.checked = !!item.checked;
|
|
1566
|
+
const label = el("label", { className: "label", attrs: { for: id } }, formatCopy(cfg.text, locale, rules(cfg.policyURL)));
|
|
1567
|
+
checkbox.addEventListener("change", async () => {
|
|
1568
|
+
const next = checkbox.checked;
|
|
1569
|
+
checkbox.disabled = true;
|
|
1570
|
+
label.classList.add("label--saving");
|
|
1571
|
+
let ok = false;
|
|
1572
|
+
try {
|
|
1573
|
+
ok = __privateGet4(this, _onConsentChange) ? await __privateGet4(this, _onConsentChange).call(this, next) : true;
|
|
1574
|
+
} catch {
|
|
1575
|
+
ok = false;
|
|
1576
|
+
}
|
|
1577
|
+
if (!ok) checkbox.checked = !next;
|
|
1578
|
+
checkbox.disabled = false;
|
|
1579
|
+
label.classList.remove("label--saving");
|
|
1580
|
+
this.dispatchEvent(new CustomEvent("dataships:consent", { detail: { consent: checkbox.checked, saved: ok }, bubbles: true, composed: true }));
|
|
1581
|
+
});
|
|
1582
|
+
root.append(el("div", { className: "consent" }, [checkbox, label]));
|
|
1583
|
+
}
|
|
1584
|
+
if (description) {
|
|
1585
|
+
root.append(el("p", { className: "description" }, formatCopy(description, locale, rules(cfg.policyURL))));
|
|
1586
|
+
}
|
|
1587
|
+
if (modal) root.append(modal);
|
|
1588
|
+
__privateGet4(this, _shadow).append(root);
|
|
1589
|
+
__privateSet4(this, _root, root);
|
|
1590
|
+
this.setAttribute("data-visible", "");
|
|
1591
|
+
};
|
|
1592
|
+
buildModal_fn = function(cfg) {
|
|
1593
|
+
if (!cfg.marketingInformation) return null;
|
|
1594
|
+
const { title, body } = splitMarketingHtml(cfg.marketingInformation);
|
|
1595
|
+
const close = el("button", { className: "modal-close", text: "\xD7", attrs: { type: "button", "aria-label": "Close" } });
|
|
1596
|
+
const dialog = el("dialog", { className: "modal", attrs: { "aria-labelledby": title ? "dataships-modal-title" : null } }, [
|
|
1597
|
+
el("div", { className: "modal-header" }, [
|
|
1598
|
+
title ? el("h2", { className: "modal-title", text: title, attrs: { id: "dataships-modal-title" } }) : el("span"),
|
|
1599
|
+
close
|
|
1600
|
+
]),
|
|
1601
|
+
el("div", { className: "modal-body" }, [body])
|
|
1602
|
+
]);
|
|
1603
|
+
close.addEventListener("click", () => dialog.close());
|
|
1604
|
+
dialog.addEventListener("click", (e) => {
|
|
1605
|
+
if (e.target === dialog) dialog.close();
|
|
1606
|
+
});
|
|
1607
|
+
return dialog;
|
|
1608
|
+
};
|
|
1609
|
+
var WIDGET_TAG = "dataships-widget";
|
|
1610
|
+
var defineWidget = () => {
|
|
1611
|
+
if (typeof customElements !== "undefined" && !customElements.get(WIDGET_TAG)) {
|
|
1612
|
+
customElements.define(WIDGET_TAG, DatashipsWidget);
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
var ELEMENTS_APP_NAME = "dataships-elements";
|
|
1616
|
+
var collectionStepForPage = (page) => page === "confirmation" ? "THANK_YOU" : "CHECKOUT_INFORMATION";
|
|
1617
|
+
var createSdkClient = (opts) => {
|
|
1618
|
+
const preview = opts.preview ?? false;
|
|
1619
|
+
if (!preview && !opts.token && !opts.unsafeServerKey) {
|
|
1620
|
+
throw new Error("createSdkClient: token is required for live calls; pass preview: true to render without credentials");
|
|
1621
|
+
}
|
|
1622
|
+
if (opts.token && opts.unsafeServerKey) {
|
|
1623
|
+
throw new Error("createSdkClient: pass either token or unsafeServerKey, not both");
|
|
1624
|
+
}
|
|
1625
|
+
const adapter = opts.page === "signup" ? new CustomPlatformSignupAdapter({
|
|
1626
|
+
locale: opts.locale,
|
|
1627
|
+
storageScope: opts.publicKey,
|
|
1628
|
+
previewMode: preview,
|
|
1629
|
+
// The adapter reads the names fresh on every call, so what the shopper typed last wins.
|
|
1630
|
+
...opts.user ? { user: opts.user } : {}
|
|
1631
|
+
}) : new CustomPlatformCheckoutAdapter({
|
|
1632
|
+
collectionStep: collectionStepForPage(opts.page),
|
|
1633
|
+
locale: opts.locale,
|
|
1634
|
+
email: opts.email ?? null,
|
|
1635
|
+
isFastCheckout: opts.isFastCheckout ?? false,
|
|
1636
|
+
storageScope: opts.publicKey,
|
|
1637
|
+
previewMode: preview
|
|
1638
|
+
});
|
|
1639
|
+
const sdk = new DatashipsClient({
|
|
1640
|
+
// Preview makes no network call, so it needs no credentials (and a token may not exist yet).
|
|
1641
|
+
...preview ? {} : opts.unsafeServerKey ? { auth: { unsafeServerKey: opts.unsafeServerKey } } : { auth: { publicKey: opts.publicKey, token: opts.token } },
|
|
1642
|
+
env: opts.env ?? "production",
|
|
1643
|
+
app: ELEMENTS_APP_NAME,
|
|
1644
|
+
version: "2.5.0",
|
|
1645
|
+
adapter,
|
|
1646
|
+
...opts.baseUrl ? { baseUrl: opts.baseUrl } : {},
|
|
1647
|
+
...opts.fetch ? { fetch: opts.fetch } : {}
|
|
1648
|
+
});
|
|
1649
|
+
return { client: sdk, adapter, sdk };
|
|
1650
|
+
};
|
|
1651
|
+
var defaultLog = (message, data) => console.debug("[dataships-elements]", message, data ?? "");
|
|
1652
|
+
var describeError = (e) => {
|
|
1653
|
+
if (!(e instanceof Error)) return e;
|
|
1654
|
+
const err = e;
|
|
1655
|
+
if (typeof err.status !== "number") return err.message;
|
|
1656
|
+
return { message: err.message, status: err.status, code: err.code ?? null, reason: err.reason ?? null, challenge: err.challenge ?? null };
|
|
1657
|
+
};
|
|
1658
|
+
var fail = (msg) => {
|
|
1659
|
+
throw new Error(`DatashipsElements.mount: ${msg}`);
|
|
1660
|
+
};
|
|
1661
|
+
var _client;
|
|
1662
|
+
var _log;
|
|
1663
|
+
var _emit;
|
|
1664
|
+
var _heartbeat;
|
|
1665
|
+
var _identifierType;
|
|
1666
|
+
var _onResponse;
|
|
1667
|
+
var _stopHeartbeat;
|
|
1668
|
+
var Session = class {
|
|
1669
|
+
constructor(opts) {
|
|
1670
|
+
this.response = null;
|
|
1671
|
+
this.ids = { consentSessionId: null };
|
|
1672
|
+
this.lastIdentifier = null;
|
|
1673
|
+
this.ok = false;
|
|
1674
|
+
__privateAdd4(this, _client);
|
|
1675
|
+
__privateAdd4(this, _log);
|
|
1676
|
+
__privateAdd4(this, _emit);
|
|
1677
|
+
__privateAdd4(this, _heartbeat);
|
|
1678
|
+
__privateAdd4(this, _identifierType);
|
|
1679
|
+
__privateAdd4(this, _onResponse);
|
|
1680
|
+
__privateAdd4(this, _stopHeartbeat, () => {
|
|
1681
|
+
});
|
|
1682
|
+
__privateSet4(this, _client, opts.client);
|
|
1683
|
+
__privateSet4(this, _log, opts.log);
|
|
1684
|
+
__privateSet4(this, _emit, opts.emit);
|
|
1685
|
+
__privateSet4(this, _heartbeat, opts.heartbeat);
|
|
1686
|
+
__privateSet4(this, _identifierType, opts.identifierType ?? "EMAIL");
|
|
1687
|
+
__privateSet4(this, _onResponse, opts.onResponse);
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Open or update the session. Never rejects: a failure is logged and renders nothing.
|
|
1691
|
+
* With `keepOnFailure` a failure leaves the session, its heartbeat and what is rendered
|
|
1692
|
+
* as they were: the session opened before is still there, and so is the text the
|
|
1693
|
+
* visitor is reading.
|
|
1694
|
+
*/
|
|
1695
|
+
async upsert(identifier, { keepOnFailure = false } = {}) {
|
|
1696
|
+
const previousIdentifier = this.lastIdentifier;
|
|
1697
|
+
this.lastIdentifier = identifier;
|
|
1698
|
+
const who = identifier ? "set" : "anonymous";
|
|
1699
|
+
try {
|
|
1700
|
+
this.response = await __privateGet4(this, _client).upsertSession({ identifierType: __privateGet4(this, _identifierType), ...identifier ? { identifier } : {} });
|
|
1701
|
+
this.ok = true;
|
|
1702
|
+
const consents = this.response.consents.map((c) => `${c.channel}:${c.consentType}`);
|
|
1703
|
+
__privateGet4(this, _log).call(this, "upsert ok", { consentSessionId: this.response.consentSessionId, consents, identifier: who });
|
|
1704
|
+
__privateGet4(this, _emit).call(this, "dataships:upsert", { ok: true, consentSessionId: this.response.consentSessionId, consents, identifier: who });
|
|
1705
|
+
} catch (e) {
|
|
1706
|
+
const error = describeError(e);
|
|
1707
|
+
__privateGet4(this, _log).call(this, "upsert failed", error);
|
|
1708
|
+
__privateGet4(this, _emit).call(this, "dataships:upsert", { ok: false, consentSessionId: null, consents: [], identifier: who, error });
|
|
1709
|
+
this.ok = false;
|
|
1710
|
+
if (keepOnFailure) {
|
|
1711
|
+
this.lastIdentifier = previousIdentifier;
|
|
1712
|
+
return;
|
|
1713
|
+
}
|
|
1714
|
+
this.response = null;
|
|
1715
|
+
}
|
|
1716
|
+
this.ids = { consentSessionId: this.response?.consentSessionId ?? null };
|
|
1717
|
+
__privateGet4(this, _stopHeartbeat).call(this);
|
|
1718
|
+
if (__privateGet4(this, _heartbeat) && this.ids.consentSessionId) {
|
|
1719
|
+
__privateSet4(this, _stopHeartbeat, __privateGet4(this, _client).startHeartbeat(this.ids, { onError: (e) => __privateGet4(this, _log).call(this, "heartbeat failed", describeError(e)) }));
|
|
1720
|
+
}
|
|
1721
|
+
__privateGet4(this, _onResponse).call(this, this.response);
|
|
1722
|
+
}
|
|
1723
|
+
/** Save a consent choice; resolves false (and logs) when it cannot be saved, so the widget reverts. */
|
|
1724
|
+
async saveConsent(consent) {
|
|
1725
|
+
if (!this.ids.consentSessionId) {
|
|
1726
|
+
__privateGet4(this, _log).call(this, "consent not saved: no session yet");
|
|
1727
|
+
return false;
|
|
1728
|
+
}
|
|
1729
|
+
try {
|
|
1730
|
+
await __privateGet4(this, _client).saveConsent({ channel: "EMAIL", consent, session: this.ids });
|
|
1731
|
+
return true;
|
|
1732
|
+
} catch (e) {
|
|
1733
|
+
__privateGet4(this, _log).call(this, "consent failed", describeError(e));
|
|
1734
|
+
return false;
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
stop() {
|
|
1738
|
+
__privateGet4(this, _stopHeartbeat).call(this);
|
|
1739
|
+
__privateSet4(this, _stopHeartbeat, () => {
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
_client = /* @__PURE__ */ new WeakMap();
|
|
1744
|
+
_log = /* @__PURE__ */ new WeakMap();
|
|
1745
|
+
_emit = /* @__PURE__ */ new WeakMap();
|
|
1746
|
+
_heartbeat = /* @__PURE__ */ new WeakMap();
|
|
1747
|
+
_identifierType = /* @__PURE__ */ new WeakMap();
|
|
1748
|
+
_onResponse = /* @__PURE__ */ new WeakMap();
|
|
1749
|
+
_stopHeartbeat = /* @__PURE__ */ new WeakMap();
|
|
1750
|
+
var _pending;
|
|
1751
|
+
var _onMutation;
|
|
1752
|
+
var _observer;
|
|
1753
|
+
var _root2;
|
|
1754
|
+
var _DomWatcher_instances;
|
|
1755
|
+
var ensureObserving_fn;
|
|
1756
|
+
var DomWatcher = class {
|
|
1757
|
+
constructor(root = document) {
|
|
1758
|
+
__privateAdd4(this, _DomWatcher_instances);
|
|
1759
|
+
__privateAdd4(this, _pending, /* @__PURE__ */ new Map());
|
|
1760
|
+
__privateAdd4(this, _onMutation, []);
|
|
1761
|
+
__privateAdd4(this, _observer, null);
|
|
1762
|
+
__privateAdd4(this, _root2);
|
|
1763
|
+
__privateSet4(this, _root2, root);
|
|
1764
|
+
}
|
|
1765
|
+
/** The first match in this watcher's root, if it is there now. */
|
|
1766
|
+
find(selector) {
|
|
1767
|
+
return __privateGet4(this, _root2).querySelector(selector);
|
|
1768
|
+
}
|
|
1769
|
+
/** Run `cb` with the first match now, or once the host renders one. */
|
|
1770
|
+
once(selector, cb) {
|
|
1771
|
+
const now = this.find(selector);
|
|
1772
|
+
if (now) {
|
|
1773
|
+
cb(now);
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
const list = __privateGet4(this, _pending).get(selector) ?? [];
|
|
1777
|
+
list.push(cb);
|
|
1778
|
+
__privateGet4(this, _pending).set(selector, list);
|
|
1779
|
+
__privateMethod4(this, _DomWatcher_instances, ensureObserving_fn).call(this);
|
|
1780
|
+
}
|
|
1781
|
+
/** Run `fn` after every DOM mutation batch, for as long as the watcher lives. */
|
|
1782
|
+
onEveryMutation(fn) {
|
|
1783
|
+
__privateGet4(this, _onMutation).push(fn);
|
|
1784
|
+
__privateMethod4(this, _DomWatcher_instances, ensureObserving_fn).call(this);
|
|
1785
|
+
}
|
|
1786
|
+
stop() {
|
|
1787
|
+
__privateGet4(this, _observer)?.disconnect();
|
|
1788
|
+
__privateSet4(this, _observer, null);
|
|
1789
|
+
__privateGet4(this, _pending).clear();
|
|
1790
|
+
__privateSet4(this, _onMutation, []);
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
_pending = /* @__PURE__ */ new WeakMap();
|
|
1794
|
+
_onMutation = /* @__PURE__ */ new WeakMap();
|
|
1795
|
+
_observer = /* @__PURE__ */ new WeakMap();
|
|
1796
|
+
_root2 = /* @__PURE__ */ new WeakMap();
|
|
1797
|
+
_DomWatcher_instances = /* @__PURE__ */ new WeakSet();
|
|
1798
|
+
ensureObserving_fn = function() {
|
|
1799
|
+
if (__privateGet4(this, _observer)) return;
|
|
1800
|
+
__privateSet4(this, _observer, new MutationObserver(() => {
|
|
1801
|
+
for (const [selector, cbs] of [...__privateGet4(this, _pending)]) {
|
|
1802
|
+
const found = this.find(selector);
|
|
1803
|
+
if (!found) continue;
|
|
1804
|
+
__privateGet4(this, _pending).delete(selector);
|
|
1805
|
+
cbs.forEach((cb) => cb(found));
|
|
1806
|
+
}
|
|
1807
|
+
__privateGet4(this, _onMutation).forEach((fn) => fn());
|
|
1808
|
+
if (!__privateGet4(this, _pending).size && !__privateGet4(this, _onMutation).length) this.stop();
|
|
1809
|
+
}));
|
|
1810
|
+
const target = "body" in __privateGet4(this, _root2) ? __privateGet4(this, _root2).body : __privateGet4(this, _root2);
|
|
1811
|
+
__privateGet4(this, _observer).observe(target, { childList: true, subtree: true });
|
|
1812
|
+
};
|
|
1813
|
+
var keepPlaced = (dom, widget, target, position) => {
|
|
1814
|
+
const place = (anchor) => {
|
|
1815
|
+
if (!widget.isConnected) anchor.insertAdjacentElement(position === "before" ? "beforebegin" : "afterend", widget);
|
|
1816
|
+
};
|
|
1817
|
+
dom.once(target, (anchor) => {
|
|
1818
|
+
place(anchor);
|
|
1819
|
+
dom.onEveryMutation(() => {
|
|
1820
|
+
if (widget.isConnected) return;
|
|
1821
|
+
const a = dom.find(target);
|
|
1822
|
+
if (a) place(a);
|
|
1823
|
+
});
|
|
1824
|
+
});
|
|
1825
|
+
};
|
|
1826
|
+
var emitterFor = (target) => (name, detail) => {
|
|
1827
|
+
target.dispatchEvent(new CustomEvent(name, { detail, bubbles: true, composed: true }));
|
|
1828
|
+
};
|
|
1829
|
+
var isValidEmail = (v) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v);
|
|
1830
|
+
var _input;
|
|
1831
|
+
var _known;
|
|
1832
|
+
var _onEmail;
|
|
1833
|
+
var _stop;
|
|
1834
|
+
var EmailWatcher = class {
|
|
1835
|
+
constructor(opts) {
|
|
1836
|
+
__privateAdd4(this, _input, null);
|
|
1837
|
+
__privateAdd4(this, _known);
|
|
1838
|
+
__privateAdd4(this, _onEmail);
|
|
1839
|
+
__privateAdd4(this, _stop, () => {
|
|
1840
|
+
});
|
|
1841
|
+
__privateSet4(this, _onEmail, opts.onEmail);
|
|
1842
|
+
__privateSet4(this, _known, opts.current ?? null);
|
|
1843
|
+
}
|
|
1844
|
+
/** Attach to the input (immediately or once the host renders it). */
|
|
1845
|
+
attach(input) {
|
|
1846
|
+
__privateSet4(this, _input, input);
|
|
1847
|
+
const push = () => {
|
|
1848
|
+
void this.flush();
|
|
1849
|
+
};
|
|
1850
|
+
input.addEventListener("change", push);
|
|
1851
|
+
input.addEventListener("blur", push);
|
|
1852
|
+
__privateSet4(this, _stop, () => {
|
|
1853
|
+
input.removeEventListener("change", push);
|
|
1854
|
+
input.removeEventListener("blur", push);
|
|
1855
|
+
});
|
|
1856
|
+
if (input.value) push();
|
|
1857
|
+
}
|
|
1858
|
+
/** Report the current value if it is a new valid email; resolves once the upsert has run. */
|
|
1859
|
+
async flush() {
|
|
1860
|
+
const v = (__privateGet4(this, _input)?.value ?? "").trim();
|
|
1861
|
+
if (!isValidEmail(v) || v === __privateGet4(this, _known)) return;
|
|
1862
|
+
__privateSet4(this, _known, v);
|
|
1863
|
+
await __privateGet4(this, _onEmail).call(this, v);
|
|
1864
|
+
}
|
|
1865
|
+
stop() {
|
|
1866
|
+
__privateGet4(this, _stop).call(this);
|
|
1867
|
+
__privateSet4(this, _stop, () => {
|
|
1868
|
+
});
|
|
1869
|
+
}
|
|
1870
|
+
};
|
|
1871
|
+
_input = /* @__PURE__ */ new WeakMap();
|
|
1872
|
+
_known = /* @__PURE__ */ new WeakMap();
|
|
1873
|
+
_onEmail = /* @__PURE__ */ new WeakMap();
|
|
1874
|
+
_stop = /* @__PURE__ */ new WeakMap();
|
|
1875
|
+
var checkoutPage = {
|
|
1876
|
+
heartbeat: true,
|
|
1877
|
+
validate(config) {
|
|
1878
|
+
if (!config.emailInput) fail("emailInput is required on the checkout page");
|
|
1879
|
+
},
|
|
1880
|
+
start({ config, session, dom, onCleanup }) {
|
|
1881
|
+
const watcher = new EmailWatcher({ onEmail: (email) => session.upsert(email) });
|
|
1882
|
+
dom.once(config.emailInput, (node) => watcher.attach(node));
|
|
1883
|
+
onCleanup(() => watcher.stop());
|
|
1884
|
+
return { ready: session.upsert(null) };
|
|
1885
|
+
}
|
|
1886
|
+
};
|
|
1887
|
+
var SUBMITTED_KEY_PREFIX = "datashipsSubmitted:";
|
|
1888
|
+
var submittedKey = (publicKey, orderId) => `${SUBMITTED_KEY_PREFIX}${publicKey}:${orderId}`;
|
|
1889
|
+
var wasSubmitted = (key) => {
|
|
1890
|
+
try {
|
|
1891
|
+
return localStorage.getItem(key) !== null;
|
|
1892
|
+
} catch {
|
|
1893
|
+
return false;
|
|
1894
|
+
}
|
|
1895
|
+
};
|
|
1896
|
+
var markSubmitted = (key) => {
|
|
1897
|
+
try {
|
|
1898
|
+
localStorage.setItem(key, (/* @__PURE__ */ new Date()).toISOString());
|
|
1899
|
+
} catch {
|
|
1900
|
+
}
|
|
1901
|
+
};
|
|
1902
|
+
var confirmationPage = {
|
|
1903
|
+
heartbeat: false,
|
|
1904
|
+
validate(config) {
|
|
1905
|
+
if (!config.email) fail("email is required on the confirmation page");
|
|
1906
|
+
if (!config.order) return;
|
|
1907
|
+
const { id, total, billingCountryCode } = config.order;
|
|
1908
|
+
if (!id) fail("order.id is required");
|
|
1909
|
+
if (typeof total !== "number" || !Number.isFinite(total) || total < 0) fail("order.total must be a non-negative number");
|
|
1910
|
+
if (!/^[A-Za-z]{2}$/.test(billingCountryCode ?? "")) fail("order.billingCountryCode must be an ISO 3166-1 alpha-2 code");
|
|
1911
|
+
if (!config.user?.firstName?.trim() || !config.user?.lastName?.trim()) fail("user.firstName and user.lastName are required with order (the submit carries the buyer's names)");
|
|
1912
|
+
},
|
|
1913
|
+
start({ config, client, log, emit, session }) {
|
|
1914
|
+
const { order, email, user } = config;
|
|
1915
|
+
const guard = order ? submittedKey(config.publicKey, order.id) : null;
|
|
1916
|
+
if (guard && wasSubmitted(guard)) {
|
|
1917
|
+
log("confirmation: order already submitted, nothing to do", { orderId: order.id });
|
|
1918
|
+
return { ready: Promise.resolve(), refresh: async () => {
|
|
1919
|
+
} };
|
|
1920
|
+
}
|
|
1921
|
+
const submitOrder = async () => {
|
|
1922
|
+
if (!order) {
|
|
1923
|
+
log("confirmation: no `order` supplied, the checkout was not completed");
|
|
1924
|
+
return;
|
|
1925
|
+
}
|
|
1926
|
+
try {
|
|
1927
|
+
await client.submitSession({ user, details: order });
|
|
1928
|
+
if (guard) markSubmitted(guard);
|
|
1929
|
+
log("submit ok", { orderId: order.id });
|
|
1930
|
+
emit("dataships:submit", { ok: true, page: "confirmation", orderId: order.id });
|
|
1931
|
+
} catch (e) {
|
|
1932
|
+
const error = describeError(e);
|
|
1933
|
+
log("submit failed", error);
|
|
1934
|
+
emit("dataships:submit", { ok: false, page: "confirmation", orderId: order.id, error });
|
|
1935
|
+
}
|
|
1936
|
+
};
|
|
1937
|
+
return { ready: session.upsert(email).then(submitOrder) };
|
|
1938
|
+
}
|
|
1939
|
+
};
|
|
1940
|
+
var formPage = {
|
|
1941
|
+
heartbeat: true,
|
|
1942
|
+
identifierType: (config) => config.phoneInput ? "PHONE" : "EMAIL",
|
|
1943
|
+
validate(config) {
|
|
1944
|
+
if (!config.client) fail("client is required on the form page (build the SDK client with the form's adapter and pass it in)");
|
|
1945
|
+
if (!config.emailInput && !config.phoneInput) fail("emailInput or phoneInput is required on the form page");
|
|
1946
|
+
if (config.emailInput && config.phoneInput) fail("pass either emailInput or phoneInput on the form page, not both (mount once per step)");
|
|
1947
|
+
},
|
|
1948
|
+
start({ config, client, log, emit, session, dom, onCleanup }) {
|
|
1949
|
+
const phoneStep = !!config.phoneInput;
|
|
1950
|
+
let identifierUpdate = Promise.resolve();
|
|
1951
|
+
let submitted = false;
|
|
1952
|
+
let watcher = null;
|
|
1953
|
+
if (config.emailInput) {
|
|
1954
|
+
const emailWatcher = new EmailWatcher({ onEmail: (email) => submitted ? Promise.resolve() : identifierUpdate = session.upsert(email) });
|
|
1955
|
+
watcher = emailWatcher;
|
|
1956
|
+
dom.once(config.emailInput, (node) => emailWatcher.attach(node));
|
|
1957
|
+
onCleanup(() => emailWatcher.stop());
|
|
1958
|
+
}
|
|
1959
|
+
let submitting = null;
|
|
1960
|
+
const submit = (input) => {
|
|
1961
|
+
submitting ?? (submitting = (async () => {
|
|
1962
|
+
const refused = (error) => {
|
|
1963
|
+
log("submit failed", error);
|
|
1964
|
+
emit("dataships:submit", { ok: false, page: "form", error });
|
|
1965
|
+
submitting = null;
|
|
1966
|
+
};
|
|
1967
|
+
await watcher?.flush();
|
|
1968
|
+
await identifierUpdate;
|
|
1969
|
+
const phone = input?.phone;
|
|
1970
|
+
if (phoneStep && !phone) return refused("no phone number was given");
|
|
1971
|
+
if (phone && phoneStep) {
|
|
1972
|
+
await (identifierUpdate = session.upsert(phone, { keepOnFailure: true }));
|
|
1973
|
+
if (!session.ok) return refused("the phone number could not be saved");
|
|
1974
|
+
}
|
|
1975
|
+
try {
|
|
1976
|
+
await client.submitSession({ details: { identifierType: phoneStep ? "PHONE" : "EMAIL", ...config.submitDetails } });
|
|
1977
|
+
submitted = true;
|
|
1978
|
+
watcher?.stop();
|
|
1979
|
+
session.stop();
|
|
1980
|
+
log("submit ok", { page: "form" });
|
|
1981
|
+
emit("dataships:submit", { ok: true, page: "form" });
|
|
1982
|
+
} catch (e) {
|
|
1983
|
+
refused(describeError(e));
|
|
1984
|
+
}
|
|
1985
|
+
})());
|
|
1986
|
+
return submitting;
|
|
1987
|
+
};
|
|
1988
|
+
const refresh = () => submitted ? Promise.resolve() : session.upsert(session.lastIdentifier);
|
|
1989
|
+
return { ready: session.upsert(null), refresh, submit };
|
|
1990
|
+
}
|
|
1991
|
+
};
|
|
1992
|
+
var readInput = (root, selector) => selector ? (root.querySelector(selector)?.value ?? "").trim() : "";
|
|
1993
|
+
var readSignupNames = (config) => {
|
|
1994
|
+
const fromResolver = config.user?.() ?? {};
|
|
1995
|
+
const root = config.root ?? document;
|
|
1996
|
+
return {
|
|
1997
|
+
firstName: (fromResolver.firstName ?? readInput(root, config.firstNameInput)).trim(),
|
|
1998
|
+
lastName: (fromResolver.lastName ?? readInput(root, config.lastNameInput)).trim()
|
|
1999
|
+
};
|
|
2000
|
+
};
|
|
2001
|
+
var signupPage = {
|
|
2002
|
+
heartbeat: true,
|
|
2003
|
+
validate(config) {
|
|
2004
|
+
if (!config.emailInput) fail("emailInput is required on the signup page");
|
|
2005
|
+
if (!config.user && !(config.firstNameInput && config.lastNameInput)) fail("firstNameInput and lastNameInput (or a user resolver) are required on the signup page: the submit carries the shopper's names");
|
|
2006
|
+
if (config.submit !== void 0 && config.submit !== "form" && config.submit !== "manual") fail('submit must be "form" or "manual"');
|
|
2007
|
+
if (config.submitHoldMs !== void 0 && !(Number.isFinite(config.submitHoldMs) && config.submitHoldMs >= 0)) fail("submitHoldMs must be a non-negative number");
|
|
2008
|
+
},
|
|
2009
|
+
start({ config, client, log, emit, session, dom, onCleanup }) {
|
|
2010
|
+
let disposed = false;
|
|
2011
|
+
onCleanup(() => {
|
|
2012
|
+
disposed = true;
|
|
2013
|
+
});
|
|
2014
|
+
const watcher = new EmailWatcher({ onEmail: (email) => session.upsert(email) });
|
|
2015
|
+
onCleanup(() => watcher.stop());
|
|
2016
|
+
let completing = null;
|
|
2017
|
+
const complete = () => {
|
|
2018
|
+
if (completing) return completing;
|
|
2019
|
+
completing = (async () => {
|
|
2020
|
+
await watcher.flush();
|
|
2021
|
+
const user = readSignupNames(config);
|
|
2022
|
+
if (!user.firstName || !user.lastName) {
|
|
2023
|
+
log("submit skipped: the form has no first and last name yet");
|
|
2024
|
+
completing = null;
|
|
2025
|
+
return;
|
|
2026
|
+
}
|
|
2027
|
+
try {
|
|
2028
|
+
await client.submitSession({ user, details: {} });
|
|
2029
|
+
log("submit ok", { page: "signup" });
|
|
2030
|
+
emit("dataships:submit", { ok: true, page: "signup" });
|
|
2031
|
+
} catch (e) {
|
|
2032
|
+
const error = describeError(e);
|
|
2033
|
+
log("submit failed", error);
|
|
2034
|
+
emit("dataships:submit", { ok: false, page: "signup", error });
|
|
2035
|
+
completing = null;
|
|
2036
|
+
}
|
|
2037
|
+
})();
|
|
2038
|
+
return completing;
|
|
2039
|
+
};
|
|
2040
|
+
const interceptForm = (form) => {
|
|
2041
|
+
const holdMs = config.submitHoldMs ?? 3e3;
|
|
2042
|
+
let releasing = false;
|
|
2043
|
+
let timer;
|
|
2044
|
+
const onSubmit = (event) => {
|
|
2045
|
+
if (releasing) {
|
|
2046
|
+
releasing = false;
|
|
2047
|
+
return;
|
|
2048
|
+
}
|
|
2049
|
+
event.preventDefault();
|
|
2050
|
+
const submitter = event.submitter instanceof HTMLElement && form.contains(event.submitter) ? event.submitter : void 0;
|
|
2051
|
+
const release = () => {
|
|
2052
|
+
clearTimeout(timer);
|
|
2053
|
+
if (disposed) return;
|
|
2054
|
+
releasing = true;
|
|
2055
|
+
if (typeof form.requestSubmit === "function") form.requestSubmit(submitter);
|
|
2056
|
+
else form.submit();
|
|
2057
|
+
};
|
|
2058
|
+
const hold = new Promise((r) => {
|
|
2059
|
+
timer = setTimeout(r, holdMs);
|
|
2060
|
+
});
|
|
2061
|
+
void Promise.race([complete(), hold]).then(release, release);
|
|
2062
|
+
};
|
|
2063
|
+
form.addEventListener("submit", onSubmit);
|
|
2064
|
+
onCleanup(() => {
|
|
2065
|
+
form.removeEventListener("submit", onSubmit);
|
|
2066
|
+
clearTimeout(timer);
|
|
2067
|
+
});
|
|
2068
|
+
};
|
|
2069
|
+
dom.once(config.emailInput, (node) => {
|
|
2070
|
+
watcher.attach(node);
|
|
2071
|
+
if ((config.submit ?? "form") !== "form") return;
|
|
2072
|
+
const form = config.form ? (config.root ?? document).querySelector(config.form) : node.closest("form");
|
|
2073
|
+
if (form) interceptForm(form);
|
|
2074
|
+
else log('signup form not found; native submit is not intercepted (use submit: "manual" and handle.submit())');
|
|
2075
|
+
});
|
|
2076
|
+
return { ready: session.upsert(null), submit: complete };
|
|
2077
|
+
}
|
|
2078
|
+
};
|
|
2079
|
+
var pages = {
|
|
2080
|
+
checkout: checkoutPage,
|
|
2081
|
+
confirmation: confirmationPage,
|
|
2082
|
+
signup: signupPage,
|
|
2083
|
+
form: formPage
|
|
2084
|
+
};
|
|
2085
|
+
var registries = /* @__PURE__ */ new WeakMap();
|
|
2086
|
+
var registryFor = (root) => {
|
|
2087
|
+
let registry = registries.get(root);
|
|
2088
|
+
if (!registry) registries.set(root, registry = /* @__PURE__ */ new Map());
|
|
2089
|
+
return registry;
|
|
2090
|
+
};
|
|
2091
|
+
var validate = (config) => {
|
|
2092
|
+
if (!config || typeof config !== "object") fail("config object is required");
|
|
2093
|
+
if (!config.publicKey) fail("publicKey is required");
|
|
2094
|
+
if (!(config.page in pages)) fail('page must be "checkout", "confirmation", "signup" or "form"');
|
|
2095
|
+
if (!config.mount) fail("mount (CSS selector) is required");
|
|
2096
|
+
if (config.position !== void 0 && config.position !== "after" && config.position !== "before") fail('position must be "after" or "before"');
|
|
2097
|
+
if (config.className !== void 0 && typeof config.className !== "string") fail("className must be a string of class names separated by spaces");
|
|
2098
|
+
if (config.root !== void 0 && typeof config.root?.querySelector !== "function") fail("root must be a document or a shadow root");
|
|
2099
|
+
pages[config.page].validate(config);
|
|
2100
|
+
if (!config.client && !config.preview && !config.token && !config.unsafeServerKey) fail("token is required for live calls (the merchant server mints it); pass `preview: true` to style without credentials, or `client` to bring your own");
|
|
2101
|
+
if (config.token && config.unsafeServerKey) fail("pass either token or unsafeServerKey, not both");
|
|
2102
|
+
const errors = validateAppearance(config.appearance);
|
|
2103
|
+
if (errors.length) fail(errors.join("; "));
|
|
2104
|
+
};
|
|
2105
|
+
var resolveClient = (config, log) => {
|
|
2106
|
+
if (config.client) return config.client;
|
|
2107
|
+
if (config.page === "form") return fail("client is required on the form page");
|
|
2108
|
+
if (config.preview) log("preview mode: synthetic copy, no API calls, consent is not saved");
|
|
2109
|
+
else if (config.unsafeServerKey) log("UNSAFE: the merchant server key is exposed in this page; anyone can act as this merchant until it is revoked");
|
|
2110
|
+
return createSdkClient({
|
|
2111
|
+
publicKey: config.publicKey,
|
|
2112
|
+
token: config.token,
|
|
2113
|
+
unsafeServerKey: config.unsafeServerKey,
|
|
2114
|
+
preview: config.preview,
|
|
2115
|
+
env: config.env,
|
|
2116
|
+
baseUrl: config.baseUrl,
|
|
2117
|
+
page: config.page,
|
|
2118
|
+
locale: config.locale ?? "en",
|
|
2119
|
+
isFastCheckout: config.page === "confirmation" ? config.isFastCheckout : void 0,
|
|
2120
|
+
email: config.page === "confirmation" ? config.email : null,
|
|
2121
|
+
user: config.page === "signup" ? () => readSignupNames(config) : void 0
|
|
2122
|
+
}).client;
|
|
2123
|
+
};
|
|
2124
|
+
var mount = (config) => {
|
|
2125
|
+
validate(config);
|
|
2126
|
+
defineWidget();
|
|
2127
|
+
const { page, appearance = {}, locale = "en", position = "after" } = config;
|
|
2128
|
+
const target = config.mount;
|
|
2129
|
+
const log = config.log ?? defaultLog;
|
|
2130
|
+
const root = config.root ?? document;
|
|
2131
|
+
const registry = registryFor(root);
|
|
2132
|
+
const existing = registry.get(target);
|
|
2133
|
+
if (existing) {
|
|
2134
|
+
existing.update({ appearance, page });
|
|
2135
|
+
return existing.handle;
|
|
2136
|
+
}
|
|
2137
|
+
const client = resolveClient(config, log);
|
|
2138
|
+
const strategy = pages[page];
|
|
2139
|
+
const identifierType = strategy.identifierType?.(config) ?? "EMAIL";
|
|
2140
|
+
const channel = identifierType === "PHONE" ? "SMS" : "EMAIL";
|
|
2141
|
+
const widget = document.createElement(WIDGET_TAG);
|
|
2142
|
+
widget.setAttribute("data-page", page);
|
|
2143
|
+
widget.setAppearance(appearance);
|
|
2144
|
+
const classNames = config.className?.trim().split(/\s+/).filter(Boolean) ?? [];
|
|
2145
|
+
if (classNames.length) {
|
|
2146
|
+
widget.classList.add(...classNames);
|
|
2147
|
+
widget.setAttribute("data-host-styled", "");
|
|
2148
|
+
}
|
|
2149
|
+
const cleanups = [];
|
|
2150
|
+
const onCleanup = (fn) => {
|
|
2151
|
+
cleanups.push(fn);
|
|
2152
|
+
};
|
|
2153
|
+
const dom = new DomWatcher(root);
|
|
2154
|
+
onCleanup(() => dom.stop());
|
|
2155
|
+
const emit = emitterFor(widget);
|
|
2156
|
+
const session = new Session({
|
|
2157
|
+
client,
|
|
2158
|
+
log,
|
|
2159
|
+
emit,
|
|
2160
|
+
heartbeat: strategy.heartbeat,
|
|
2161
|
+
identifierType,
|
|
2162
|
+
onResponse: (response) => widget.render(response, { page, locale, channel })
|
|
2163
|
+
});
|
|
2164
|
+
widget.onConsentChange = (consent) => session.saveConsent(consent);
|
|
2165
|
+
keepPlaced(dom, widget, target, position);
|
|
2166
|
+
const run = strategy.start({ config, client, log, emit, session, dom, onCleanup });
|
|
2167
|
+
const ready = run.ready.catch((e) => log("page start failed", e instanceof Error ? e.message : e));
|
|
2168
|
+
const entry = {
|
|
2169
|
+
update: ({ appearance: a, page: p }) => {
|
|
2170
|
+
widget.setAppearance(a);
|
|
2171
|
+
if (p !== page) log("page change on a repeat mount() is not supported; unmount first");
|
|
2172
|
+
widget.render(session.response, { page, locale, channel });
|
|
2173
|
+
},
|
|
2174
|
+
handle: {
|
|
2175
|
+
ready,
|
|
2176
|
+
unmount: () => {
|
|
2177
|
+
session.stop();
|
|
2178
|
+
cleanups.forEach((fn) => fn());
|
|
2179
|
+
widget.remove();
|
|
2180
|
+
registry.delete(target);
|
|
2181
|
+
},
|
|
2182
|
+
refresh: run.refresh ?? (() => session.upsert(session.lastIdentifier)),
|
|
2183
|
+
...run.submit ? { submit: run.submit } : {},
|
|
2184
|
+
element: widget
|
|
2185
|
+
}
|
|
2186
|
+
};
|
|
2187
|
+
registry.set(target, entry);
|
|
2188
|
+
return entry.handle;
|
|
2189
|
+
};
|
|
2190
|
+
|
|
2191
|
+
// node_modules/@dataships/sdk/dist/adapters/alia-form/index.js
|
|
2192
|
+
var __typeError5 = (msg) => {
|
|
2193
|
+
throw TypeError(msg);
|
|
2194
|
+
};
|
|
2195
|
+
var __accessCheck5 = (obj, member, msg) => member.has(obj) || __typeError5("Cannot " + msg);
|
|
2196
|
+
var __privateGet5 = (obj, member, getter) => (__accessCheck5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
2197
|
+
var __privateAdd5 = (obj, member, value) => member.has(obj) ? __typeError5("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
2198
|
+
var __privateSet5 = (obj, member, value, setter) => (__accessCheck5(obj, member, "write to private field"), member.set(obj, value), value);
|
|
2199
|
+
var DEFAULT_EMAIL_OPT_IN_TEXT3 = "We would like to email you news and promotions. Tick to opt in.";
|
|
2200
|
+
var DEFAULT_EMAIL_OPT_IN_CONSENT_DESCRIPTION3 = "Click here for an overview of how your personal data is processed for marketing purposes or see our Privacy Policy for further information.";
|
|
2201
|
+
var DEFAULT_SMS_OPT_IN_TEXT3 = "We would like to text you news and promotions. Tick to opt in.";
|
|
2202
|
+
var DEFAULT_SMS_OPT_IN_CONSENT_DESCRIPTION3 = "Based on the channel preferences set above, you agree to receive recurring automated marketing messages (e.g. AI content, cart reminders) from {{COMPANY_NAME}} at the number you provide. Consent is not a condition of purchase. We may share info with service providers per our Privacy Policy. Reply STOP to cancel or click the unsubscribe link (where available). For help reply HELP or email {{PRIVACY_EMAIL}}. Msg frequency varies. Msg & data rates may apply. By proceeding, you also agree to our Terms of Service (incl. arbitration) & Privacy Policy.";
|
|
2203
|
+
var fakeEmailUpsertResponse3 = {
|
|
2204
|
+
consentSessionId: "01HQB3QRZVV0737R0R25BTQBGF",
|
|
2205
|
+
consents: [
|
|
2206
|
+
{
|
|
2207
|
+
channel: "EMAIL",
|
|
2208
|
+
consentType: "OPT_IN",
|
|
2209
|
+
checked: false,
|
|
2210
|
+
widgetConfig: {
|
|
2211
|
+
text: DEFAULT_EMAIL_OPT_IN_TEXT3,
|
|
2212
|
+
consentDescription: DEFAULT_EMAIL_OPT_IN_CONSENT_DESCRIPTION3,
|
|
2213
|
+
marketingInformation: '<h1>Marketing Information</h1>\n<p>We may send you direct marketing communications, product information and promotional offers. You can withdraw your consent at any time. See our <a href="https://dataships.io/privacy-centre">Privacy Policy</a> or contact us at <a href="mailto:privacy@example.com">privacy@example.com</a> for further information.</p>\n',
|
|
2214
|
+
policyURL: "https://dataships.io/privacy-centre",
|
|
2215
|
+
mobileTermsOfServiceURL: null,
|
|
2216
|
+
privacyEmail: "privacy@example.com",
|
|
2217
|
+
placeholderValues: null
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
],
|
|
2221
|
+
userVerificationRequired: null,
|
|
2222
|
+
lastHeartbeat: "2026-06-17T00:00:00Z",
|
|
2223
|
+
identifier: null
|
|
2224
|
+
};
|
|
2225
|
+
var fakePhoneUpsertResponse3 = {
|
|
2226
|
+
consentSessionId: "01HQB3QRZVV0737R0R25BTQBGG",
|
|
2227
|
+
consents: [
|
|
2228
|
+
{
|
|
2229
|
+
channel: "SMS",
|
|
2230
|
+
consentType: "OPT_IN",
|
|
2231
|
+
checked: false,
|
|
2232
|
+
widgetConfig: {
|
|
2233
|
+
text: DEFAULT_SMS_OPT_IN_TEXT3,
|
|
2234
|
+
consentDescription: DEFAULT_SMS_OPT_IN_CONSENT_DESCRIPTION3,
|
|
2235
|
+
marketingInformation: '<h1>Marketing Information</h1>\n<p>We may send you marketing text messages about products and promotional offers. Message frequency varies. You can withdraw your consent at any time by replying STOP. See our <a href="https://dataships.io/privacy-centre">Privacy Policy</a> or contact us at <a href="mailto:privacy@example.com">privacy@example.com</a> for further information.</p>\n',
|
|
2236
|
+
policyURL: "https://dataships.io/privacy-centre",
|
|
2237
|
+
mobileTermsOfServiceURL: "https://dataships.io/mobile-terms",
|
|
2238
|
+
privacyEmail: "privacy@example.com",
|
|
2239
|
+
placeholderValues: null
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
],
|
|
2243
|
+
userVerificationRequired: false,
|
|
2244
|
+
lastHeartbeat: "2026-06-17T00:00:00Z",
|
|
2245
|
+
identifier: null
|
|
2246
|
+
};
|
|
2247
|
+
var MARKETING_MODAL_HREF3 = "#dataships-marketing-modal";
|
|
2248
|
+
var CHECKBOX_LABEL_BOLD_PHRASES3 = ["consent", "object", "opt in", "opt out", "STOP", "HELP"];
|
|
2249
|
+
var CONSENT_DESCRIPTION_BOLD_PHRASES3 = ["STOP", "HELP"];
|
|
2250
|
+
var escapeHtml3 = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
2251
|
+
var escapeRegExp4 = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2252
|
+
var wrapPhrase3 = (html, phrase, wrap) => html.replace(
|
|
2253
|
+
new RegExp(`${escapeRegExp4(escapeHtml3(phrase))}(?![^<]*>)(?![^<]*</a>)`, "gi"),
|
|
2254
|
+
wrap
|
|
2255
|
+
);
|
|
2256
|
+
var toHtmlCopy3 = (text, widgetConfig, boldPhrases) => {
|
|
2257
|
+
let html = escapeHtml3(text);
|
|
2258
|
+
const links = [
|
|
2259
|
+
["Terms of Service", widgetConfig.mobileTermsOfServiceURL],
|
|
2260
|
+
["Privacy Policy", widgetConfig.policyURL],
|
|
2261
|
+
["Click here", MARKETING_MODAL_HREF3]
|
|
2262
|
+
];
|
|
2263
|
+
for (const [phrase, href] of links) {
|
|
2264
|
+
if (!href) continue;
|
|
2265
|
+
html = wrapPhrase3(html, phrase, (match) => `<a href="${escapeHtml3(href)}">${match}</a>`);
|
|
2266
|
+
}
|
|
2267
|
+
for (const phrase of boldPhrases) {
|
|
2268
|
+
html = wrapPhrase3(html, phrase, (match) => `<strong>${match}</strong>`);
|
|
2269
|
+
}
|
|
2270
|
+
return `<p>${html}</p>`;
|
|
2271
|
+
};
|
|
2272
|
+
var withHtmlCopy3 = (response) => ({
|
|
2273
|
+
...response,
|
|
2274
|
+
consents: response.consents.map((consent) => {
|
|
2275
|
+
const { widgetConfig } = consent;
|
|
2276
|
+
return {
|
|
2277
|
+
...consent,
|
|
2278
|
+
widgetConfig: {
|
|
2279
|
+
...widgetConfig,
|
|
2280
|
+
text: widgetConfig.text === null ? null : toHtmlCopy3(widgetConfig.text, widgetConfig, CHECKBOX_LABEL_BOLD_PHRASES3),
|
|
2281
|
+
consentDescription: widgetConfig.consentDescription === null ? null : toHtmlCopy3(
|
|
2282
|
+
widgetConfig.consentDescription,
|
|
2283
|
+
widgetConfig,
|
|
2284
|
+
CONSENT_DESCRIPTION_BOLD_PHRASES3
|
|
2285
|
+
)
|
|
2286
|
+
}
|
|
2287
|
+
};
|
|
2288
|
+
})
|
|
2289
|
+
});
|
|
2290
|
+
var previewUpsertResponse3 = (identifierType, format = "json") => {
|
|
2291
|
+
const response = identifierType === "PHONE" ? fakePhoneUpsertResponse3 : fakeEmailUpsertResponse3;
|
|
2292
|
+
return format === "html" ? withHtmlCopy3(response) : response;
|
|
2293
|
+
};
|
|
2294
|
+
var SUPPORTED_LOCALES3 = [
|
|
2295
|
+
"en",
|
|
2296
|
+
"es",
|
|
2297
|
+
"de",
|
|
2298
|
+
"pt",
|
|
2299
|
+
"ro",
|
|
2300
|
+
"hr",
|
|
2301
|
+
"da",
|
|
2302
|
+
"fi",
|
|
2303
|
+
"fr",
|
|
2304
|
+
"hu",
|
|
2305
|
+
"it",
|
|
2306
|
+
"nb",
|
|
2307
|
+
"pl",
|
|
2308
|
+
"sk",
|
|
2309
|
+
"sv",
|
|
2310
|
+
"nl",
|
|
2311
|
+
"el",
|
|
2312
|
+
"cs",
|
|
2313
|
+
"zh",
|
|
2314
|
+
"ja",
|
|
2315
|
+
"is"
|
|
2316
|
+
];
|
|
2317
|
+
var coerceLocale3 = (raw) => {
|
|
2318
|
+
if (!raw) return "en";
|
|
2319
|
+
const head = raw.split(/[_-]/)[0]?.toLowerCase() ?? "";
|
|
2320
|
+
return SUPPORTED_LOCALES3.includes(head) ? head : "en";
|
|
2321
|
+
};
|
|
2322
|
+
var ALIA_FORM_RENDER_INTEGRATION_TYPE = "ALIA_FORM_RENDER";
|
|
2323
|
+
var ALIA_FORM_LISTEN_INTEGRATION_TYPE = "ALIA_FORM_LISTEN";
|
|
2324
|
+
var _datashipsSessionId;
|
|
2325
|
+
var _campaignId;
|
|
2326
|
+
var _locale3;
|
|
2327
|
+
var AliaFormAdapterBase = class {
|
|
2328
|
+
constructor(adapterName, opts) {
|
|
2329
|
+
this.sessionApi = "consent-session";
|
|
2330
|
+
this.submitRequiresUser = false;
|
|
2331
|
+
__privateAdd5(this, _datashipsSessionId);
|
|
2332
|
+
__privateAdd5(this, _campaignId);
|
|
2333
|
+
__privateAdd5(this, _locale3);
|
|
2334
|
+
__privateSet5(this, _datashipsSessionId, required(adapterName, opts.datashipsSessionId, "datashipsSessionId"));
|
|
2335
|
+
__privateSet5(this, _campaignId, required(adapterName, opts.campaignId, "campaignId"));
|
|
2336
|
+
__privateSet5(this, _locale3, coerceLocale3(opts.locale));
|
|
2337
|
+
}
|
|
2338
|
+
getLocale() {
|
|
2339
|
+
return __privateGet5(this, _locale3);
|
|
2340
|
+
}
|
|
2341
|
+
/** Change the envelope locale, e.g. when the visitor switches language. */
|
|
2342
|
+
setLocale(locale) {
|
|
2343
|
+
__privateSet5(this, _locale3, coerceLocale3(locale));
|
|
2344
|
+
}
|
|
2345
|
+
/** The adapter holds no contact: the popup's field is passed to `upsertSession({ identifier })`. */
|
|
2346
|
+
getIdentifier(identifierType) {
|
|
2347
|
+
return { identifier: null, identifierType };
|
|
2348
|
+
}
|
|
2349
|
+
/** The id the adapter was given; a submit leaves it in place. */
|
|
2350
|
+
getDatashipsSessionId() {
|
|
2351
|
+
return __privateGet5(this, _datashipsSessionId);
|
|
2352
|
+
}
|
|
2353
|
+
baseSessionContext() {
|
|
2354
|
+
return { datashipsSessionId: __privateGet5(this, _datashipsSessionId), campaignId: __privateGet5(this, _campaignId) };
|
|
2355
|
+
}
|
|
2356
|
+
};
|
|
2357
|
+
_datashipsSessionId = /* @__PURE__ */ new WeakMap();
|
|
2358
|
+
_campaignId = /* @__PURE__ */ new WeakMap();
|
|
2359
|
+
_locale3 = /* @__PURE__ */ new WeakMap();
|
|
2360
|
+
var AliaFormRenderAdapter = class extends AliaFormAdapterBase {
|
|
2361
|
+
constructor(opts) {
|
|
2362
|
+
super("AliaFormRenderAdapter", opts);
|
|
2363
|
+
this.name = "AliaFormRenderAdapter";
|
|
2364
|
+
this.integrationType = ALIA_FORM_RENDER_INTEGRATION_TYPE;
|
|
2365
|
+
this.previewMode = opts.previewMode ?? false;
|
|
2366
|
+
}
|
|
2367
|
+
/** Synthetic upsert response served in {@link previewMode}, matching the requested identifier type. */
|
|
2368
|
+
getPreviewUpsertResponse(identifierType = "EMAIL") {
|
|
2369
|
+
return previewUpsertResponse3(identifierType);
|
|
2370
|
+
}
|
|
2371
|
+
async getSessionContext() {
|
|
2372
|
+
return this.baseSessionContext();
|
|
2373
|
+
}
|
|
2374
|
+
};
|
|
2375
|
+
var _disclosureText;
|
|
2376
|
+
var _privacyPolicyUrl;
|
|
2377
|
+
var _termsUrl;
|
|
2378
|
+
var AliaFormListenAdapter = class extends AliaFormAdapterBase {
|
|
2379
|
+
constructor(opts) {
|
|
2380
|
+
super("AliaFormListenAdapter", opts);
|
|
2381
|
+
this.name = "AliaFormListenAdapter";
|
|
2382
|
+
this.integrationType = ALIA_FORM_LISTEN_INTEGRATION_TYPE;
|
|
2383
|
+
__privateAdd5(this, _disclosureText);
|
|
2384
|
+
__privateAdd5(this, _privacyPolicyUrl);
|
|
2385
|
+
__privateAdd5(this, _termsUrl);
|
|
2386
|
+
__privateSet5(this, _disclosureText, optional(opts.disclosureText));
|
|
2387
|
+
__privateSet5(this, _privacyPolicyUrl, optional(opts.privacyPolicyUrl));
|
|
2388
|
+
__privateSet5(this, _termsUrl, optional(opts.termsUrl));
|
|
2389
|
+
}
|
|
2390
|
+
async getSessionContext() {
|
|
2391
|
+
return {
|
|
2392
|
+
...this.baseSessionContext(),
|
|
2393
|
+
...__privateGet5(this, _disclosureText) === void 0 ? {} : { disclosureText: __privateGet5(this, _disclosureText) },
|
|
2394
|
+
...__privateGet5(this, _privacyPolicyUrl) === void 0 ? {} : { privacyPolicyUrl: __privateGet5(this, _privacyPolicyUrl) },
|
|
2395
|
+
...__privateGet5(this, _termsUrl) === void 0 ? {} : { termsUrl: __privateGet5(this, _termsUrl) }
|
|
2396
|
+
};
|
|
2397
|
+
}
|
|
2398
|
+
};
|
|
2399
|
+
_disclosureText = /* @__PURE__ */ new WeakMap();
|
|
2400
|
+
_privacyPolicyUrl = /* @__PURE__ */ new WeakMap();
|
|
2401
|
+
_termsUrl = /* @__PURE__ */ new WeakMap();
|
|
2402
|
+
var required = (adapterName, value, option) => {
|
|
2403
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
2404
|
+
throw new Error(`${adapterName}: ${option} must be a non-empty string`);
|
|
2405
|
+
}
|
|
2406
|
+
return value;
|
|
2407
|
+
};
|
|
2408
|
+
var optional = (value) => typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
2409
|
+
|
|
2410
|
+
// src/modules/alia/template.ts
|
|
2411
|
+
var EMAIL_CONSENT = /\{\{\s*email_consent\s*\}\}/;
|
|
2412
|
+
var SMS_CONSENT = /\{\{\s*sms_consent\s*\}\}/;
|
|
2413
|
+
var ANY_CONSENT = /\{\{\s*\w+_consent\s*\}\}/;
|
|
2414
|
+
var hasOwnWording = (markdown) => {
|
|
2415
|
+
const rest = markdown.replace(new RegExp(EMAIL_CONSENT, "g"), "");
|
|
2416
|
+
return rest.trim() !== "" && !ANY_CONSENT.test(rest);
|
|
2417
|
+
};
|
|
2418
|
+
var FIBER_KEY_PREFIX = "__reactFiber$";
|
|
2419
|
+
var MAX_HOPS = 60;
|
|
2420
|
+
var MAX_DEPTH = 40;
|
|
2421
|
+
var MAX_NODES = 5e3;
|
|
2422
|
+
var SAFE_ID = /^[A-Za-z][\w-]*$/;
|
|
2423
|
+
var COMPLIANCE_STYLE = "compliance";
|
|
2424
|
+
var isBag = (value) => typeof value === "object" && value !== null;
|
|
2425
|
+
var fiberOf = (element) => {
|
|
2426
|
+
const key = Object.keys(element).find((k) => k.startsWith(FIBER_KEY_PREFIX));
|
|
2427
|
+
const fiber = key ? element[key] : null;
|
|
2428
|
+
return isBag(fiber) ? fiber : null;
|
|
2429
|
+
};
|
|
2430
|
+
var stepsAbove = (start2) => {
|
|
2431
|
+
let fiber = start2;
|
|
2432
|
+
for (let hop = 0; hop < MAX_HOPS && isBag(fiber); hop++) {
|
|
2433
|
+
const props = fiber.memoizedProps;
|
|
2434
|
+
const value = isBag(props) ? props.value : null;
|
|
2435
|
+
const template = isBag(value) ? value.template : null;
|
|
2436
|
+
const steps = isBag(template) ? template.steps : null;
|
|
2437
|
+
if (Array.isArray(steps)) return steps;
|
|
2438
|
+
fiber = fiber.return;
|
|
2439
|
+
}
|
|
2440
|
+
return null;
|
|
2441
|
+
};
|
|
2442
|
+
var readSteps = (root) => {
|
|
2443
|
+
for (const child of Array.from(root.children)) {
|
|
2444
|
+
const fiber = fiberOf(child);
|
|
2445
|
+
const steps = fiber && stepsAbove(fiber);
|
|
2446
|
+
if (steps) return steps;
|
|
2447
|
+
}
|
|
2448
|
+
return null;
|
|
2449
|
+
};
|
|
2450
|
+
var findPlaceholderId = (steps, placeholder) => {
|
|
2451
|
+
let visited = 0;
|
|
2452
|
+
const search = (entry, depth) => {
|
|
2453
|
+
if (!isBag(entry) || depth > MAX_DEPTH || ++visited > MAX_NODES)
|
|
2454
|
+
return null;
|
|
2455
|
+
const { node, id, children } = entry;
|
|
2456
|
+
if (isBag(node) && typeof node.markdown === "string" && placeholder.test(node.markdown) && typeof id === "string" && SAFE_ID.test(id))
|
|
2457
|
+
return id;
|
|
2458
|
+
if (!Array.isArray(children)) return null;
|
|
2459
|
+
for (const child of children) {
|
|
2460
|
+
const found = search(child, depth + 1);
|
|
2461
|
+
if (found) return found;
|
|
2462
|
+
}
|
|
2463
|
+
return null;
|
|
2464
|
+
};
|
|
2465
|
+
for (const step of steps) {
|
|
2466
|
+
const found = search(step, 0);
|
|
2467
|
+
if (found) return found;
|
|
2468
|
+
}
|
|
2469
|
+
return null;
|
|
2470
|
+
};
|
|
2471
|
+
var findOwnText = (steps, inputType) => {
|
|
2472
|
+
let visited = 0;
|
|
2473
|
+
const walk = (entry, depth, found) => {
|
|
2474
|
+
if (!isBag(entry) || depth > MAX_DEPTH || ++visited > MAX_NODES) return;
|
|
2475
|
+
const { node, id, children } = entry;
|
|
2476
|
+
if (isBag(node)) {
|
|
2477
|
+
if (node.type === inputType) found.input = true;
|
|
2478
|
+
if (node.sharedStyle === COMPLIANCE_STYLE && typeof node.markdown === "string" && hasOwnWording(node.markdown) && typeof id === "string" && SAFE_ID.test(id))
|
|
2479
|
+
found.ids.push(id);
|
|
2480
|
+
}
|
|
2481
|
+
if (Array.isArray(children))
|
|
2482
|
+
for (const child of children) walk(child, depth + 1, found);
|
|
2483
|
+
};
|
|
2484
|
+
const ids = [];
|
|
2485
|
+
for (const step of steps) {
|
|
2486
|
+
const found = { input: false, ids: [] };
|
|
2487
|
+
walk(step, 0, found);
|
|
2488
|
+
if (found.input) ids.push(...found.ids);
|
|
2489
|
+
}
|
|
2490
|
+
return ids;
|
|
2491
|
+
};
|
|
2492
|
+
var readDisclosure = (root, placeholder, inputType) => {
|
|
2493
|
+
try {
|
|
2494
|
+
const steps = readSteps(root);
|
|
2495
|
+
if (!steps) return { kind: "unreadable" };
|
|
2496
|
+
const id = findPlaceholderId(steps, placeholder);
|
|
2497
|
+
const ownText = findOwnText(steps, inputType);
|
|
2498
|
+
return id ? { kind: "placeholder", id, ownText } : { kind: "none", ownText };
|
|
2499
|
+
} catch {
|
|
2500
|
+
return { kind: "unreadable" };
|
|
2501
|
+
}
|
|
2502
|
+
};
|
|
2503
|
+
var readEmailDisclosure = (root) => readDisclosure(root, EMAIL_CONSENT, "emailInput");
|
|
2504
|
+
var readSmsDisclosure = (root) => readDisclosure(root, SMS_CONSENT, "phoneInput");
|
|
2505
|
+
|
|
2506
|
+
// src/modules/alia/popups.ts
|
|
2507
|
+
var ANCHOR_ATTRIBUTE = "data-dataships-anchor";
|
|
2508
|
+
var STYLE_ATTRIBUTE = "data-dataships-launcher";
|
|
2509
|
+
var PENDING_ATTRIBUTE = "data-dataships-pending";
|
|
2510
|
+
var PENDING_LIMIT_MS = 3e4;
|
|
2511
|
+
var LOOK_ATTRIBUTE = "data-dataships-launcher-look";
|
|
2512
|
+
var FALLBACK_CLASS = "dataships-form-text";
|
|
2513
|
+
var COMPLIANCE_CLASS = "alia-style-compliance";
|
|
2514
|
+
var ALIA_STYLE_CLASS = /^alia-style-[\w-]+$/;
|
|
2515
|
+
var SCREEN_READER_ONLY = ".sr-only";
|
|
2516
|
+
var LOOK_PROPERTIES = [
|
|
2517
|
+
"color",
|
|
2518
|
+
"font-family",
|
|
2519
|
+
"font-size",
|
|
2520
|
+
"font-weight",
|
|
2521
|
+
"font-style",
|
|
2522
|
+
"line-height",
|
|
2523
|
+
"letter-spacing",
|
|
2524
|
+
"text-align",
|
|
2525
|
+
"text-transform",
|
|
2526
|
+
"opacity",
|
|
2527
|
+
"margin-top",
|
|
2528
|
+
"margin-bottom",
|
|
2529
|
+
"padding-top",
|
|
2530
|
+
"padding-right",
|
|
2531
|
+
"padding-bottom",
|
|
2532
|
+
"padding-left",
|
|
2533
|
+
"align-self"
|
|
2534
|
+
];
|
|
2535
|
+
var UNSAFE_CSS_VALUE = /[{}<;]/;
|
|
2536
|
+
var SAFE_ID2 = /^[\w-]+$/;
|
|
2537
|
+
var EMAIL_INPUT = 'input[name="email"]';
|
|
2538
|
+
var PHONE_INPUT = 'input[name="phone"]';
|
|
2539
|
+
var lookOf = (source) => {
|
|
2540
|
+
const view = source.ownerDocument.defaultView;
|
|
2541
|
+
if (!view) return "";
|
|
2542
|
+
const computed = view.getComputedStyle(source);
|
|
2543
|
+
const value = (property) => {
|
|
2544
|
+
const found = computed.getPropertyValue(property).trim();
|
|
2545
|
+
return UNSAFE_CSS_VALUE.test(found) ? "" : found;
|
|
2546
|
+
};
|
|
2547
|
+
const declarations = [];
|
|
2548
|
+
for (const property of LOOK_PROPERTIES) {
|
|
2549
|
+
const found = value(property);
|
|
2550
|
+
if (found) declarations.push(`${property}:${found}`);
|
|
2551
|
+
}
|
|
2552
|
+
const left = value("margin-left");
|
|
2553
|
+
const right = value("margin-right");
|
|
2554
|
+
if (left && left === right && parseFloat(left) > 0)
|
|
2555
|
+
declarations.push("margin-left:auto", "margin-right:auto");
|
|
2556
|
+
else {
|
|
2557
|
+
if (left) declarations.push(`margin-left:${left}`);
|
|
2558
|
+
if (right) declarations.push(`margin-right:${right}`);
|
|
2559
|
+
}
|
|
2560
|
+
const width = source.getBoundingClientRect().width;
|
|
2561
|
+
if (width > 0)
|
|
2562
|
+
declarations.push(
|
|
2563
|
+
"box-sizing:border-box",
|
|
2564
|
+
`max-width:${Math.ceil(width)}px`
|
|
2565
|
+
);
|
|
2566
|
+
return declarations.join(";");
|
|
2567
|
+
};
|
|
2568
|
+
var classOf = (source) => Array.from(source.classList).filter((name) => ALIA_STYLE_CLASS.test(name)).join(" ") || FALLBACK_CLASS;
|
|
2569
|
+
var textOf = (elements) => elements.map((element) => {
|
|
2570
|
+
const copy = element.cloneNode(true);
|
|
2571
|
+
for (const hidden of Array.from(
|
|
2572
|
+
copy.querySelectorAll(SCREEN_READER_ONLY)
|
|
2573
|
+
))
|
|
2574
|
+
hidden.remove();
|
|
2575
|
+
return (copy.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
2576
|
+
}).filter((text) => text !== "").join(" ");
|
|
2577
|
+
var linkOf = (elements, kind) => {
|
|
2578
|
+
for (const element of elements)
|
|
2579
|
+
for (const link of Array.from(
|
|
2580
|
+
element.querySelectorAll("a[href]")
|
|
2581
|
+
)) {
|
|
2582
|
+
const href = link.href;
|
|
2583
|
+
if (!/^https?:\/\//i.test(href)) continue;
|
|
2584
|
+
if (kind.test(textOf([link])) || kind.test(href)) return href;
|
|
2585
|
+
}
|
|
2586
|
+
return void 0;
|
|
2587
|
+
};
|
|
2588
|
+
var idOf = (value) => {
|
|
2589
|
+
const id = typeof value === "number" || typeof value === "string" ? `${value}` : "";
|
|
2590
|
+
return SAFE_ID2.test(id) ? id : null;
|
|
2591
|
+
};
|
|
2592
|
+
var detailOf = (event) => {
|
|
2593
|
+
const detail = event.detail;
|
|
2594
|
+
return typeof detail === "object" && detail !== null ? detail : null;
|
|
2595
|
+
};
|
|
2596
|
+
var watchPopups = (context, deps) => {
|
|
2597
|
+
const popups = /* @__PURE__ */ new Map();
|
|
2598
|
+
const stopObserving = (popup) => {
|
|
2599
|
+
popup.observer?.disconnect();
|
|
2600
|
+
popup.observer = null;
|
|
2601
|
+
};
|
|
2602
|
+
const track = (popupId, campaignId) => {
|
|
2603
|
+
const popup = {
|
|
2604
|
+
handle: null,
|
|
2605
|
+
emailSettled: false,
|
|
2606
|
+
sms: null,
|
|
2607
|
+
observer: null,
|
|
2608
|
+
watched: null
|
|
2609
|
+
};
|
|
2610
|
+
popups.set(popupId, popup);
|
|
2611
|
+
const buttonSelector = `[${ANCHOR_ATTRIBUTE}="${popupId}"]`;
|
|
2612
|
+
const smsButtonMark = `${popupId}-sms`;
|
|
2613
|
+
const smsButtonSelector = `[${ANCHOR_ATTRIBUTE}="${smsButtonMark}"]`;
|
|
2614
|
+
const smsType = context.preview ? "SINGLE" : context.elements.find((element) => element.id === campaignId)?.channels.find((entry) => entry.channel === "SMS")?.subscriptionType;
|
|
2615
|
+
const popupRootOf = (shadow) => shadow ? '[id^="alia-popup-root-"]' : `#alia-root-${popupId}`;
|
|
2616
|
+
const inPopup = (selector, shadow) => shadow ? selector : `#alia-root-${popupId} ${selector}`;
|
|
2617
|
+
const renderClientOptions = () => ({
|
|
2618
|
+
campaignId,
|
|
2619
|
+
datashipsSessionId: context.datashipsSessionId,
|
|
2620
|
+
publicKey: context.publicKey,
|
|
2621
|
+
baseUrl: context.baseUrl,
|
|
2622
|
+
token: context.token,
|
|
2623
|
+
preview: context.preview
|
|
2624
|
+
});
|
|
2625
|
+
const hideOwnText = (handle, ownText, shadow) => {
|
|
2626
|
+
if (ownText.length === 0) return;
|
|
2627
|
+
const widget = handle.element;
|
|
2628
|
+
const popupRoot = popupRootOf(shadow);
|
|
2629
|
+
const shown = `${popupRoot}:has(${widget.localName}[data-visible])`;
|
|
2630
|
+
const pending = `${popupRoot}:has(${widget.localName}[${PENDING_ATTRIBUTE}])`;
|
|
2631
|
+
widget.setAttribute(PENDING_ATTRIBUTE, "");
|
|
2632
|
+
const settle = () => widget.removeAttribute(PENDING_ATTRIBUTE);
|
|
2633
|
+
const limit = setTimeout(settle, PENDING_LIMIT_MS);
|
|
2634
|
+
void handle.ready.then(() => {
|
|
2635
|
+
clearTimeout(limit);
|
|
2636
|
+
settle();
|
|
2637
|
+
});
|
|
2638
|
+
const style = document.createElement("style");
|
|
2639
|
+
style.setAttribute(STYLE_ATTRIBUTE, popupId);
|
|
2640
|
+
style.textContent = ownText.map(
|
|
2641
|
+
(id) => `${pending} #${id}{visibility:hidden!important}${shown} #${id}{display:none!important}`
|
|
2642
|
+
).join("");
|
|
2643
|
+
(shadow ?? document.head).appendChild(style);
|
|
2644
|
+
};
|
|
2645
|
+
const giveLook = (widget, mount2, look, shadow) => {
|
|
2646
|
+
if (!look) return;
|
|
2647
|
+
const style = document.createElement("style");
|
|
2648
|
+
style.setAttribute(LOOK_ATTRIBUTE, popupId);
|
|
2649
|
+
style.textContent = `${popupRootOf(shadow)} ${mount2} + ${widget.localName}{${look}}`;
|
|
2650
|
+
(shadow ?? document.head).appendChild(style);
|
|
2651
|
+
};
|
|
2652
|
+
const mountAt = (step, mount2, ownText, source, shadow) => {
|
|
2653
|
+
const look = source ? lookOf(source) : "";
|
|
2654
|
+
const handle = deps.mount({
|
|
2655
|
+
page: "form",
|
|
2656
|
+
publicKey: context.publicKey,
|
|
2657
|
+
client: deps.createRenderClient(renderClientOptions()),
|
|
2658
|
+
mount: mount2,
|
|
2659
|
+
position: "after",
|
|
2660
|
+
...step,
|
|
2661
|
+
className: source ? classOf(source) : COMPLIANCE_CLASS,
|
|
2662
|
+
...shadow ? { root: shadow } : {},
|
|
2663
|
+
// The submit names the campaign, because one session id can hold several campaigns'
|
|
2664
|
+
// sessions, and the step's identifier type, so it completes this step's session only
|
|
2665
|
+
// and never contends with the other step's calls.
|
|
2666
|
+
submitDetails: {
|
|
2667
|
+
campaignId,
|
|
2668
|
+
identifierType: "emailInput" in step ? "EMAIL" : "PHONE"
|
|
2669
|
+
},
|
|
2670
|
+
log: () => {
|
|
2671
|
+
}
|
|
2672
|
+
});
|
|
2673
|
+
hideOwnText(handle, ownText, shadow);
|
|
2674
|
+
giveLook(handle.element, mount2, look, shadow);
|
|
2675
|
+
return handle;
|
|
2676
|
+
};
|
|
2677
|
+
const elementsOf = (root, ids) => ids.map((id) => root.querySelector(`#${id}`)).filter((element) => element !== null);
|
|
2678
|
+
const tagSubmitButton = (root, input, mark) => {
|
|
2679
|
+
const button = root.querySelector(input)?.closest("form")?.querySelector('button[type="submit"]') ?? null;
|
|
2680
|
+
if (button && button.getAttribute(ANCHOR_ATTRIBUTE) !== mark)
|
|
2681
|
+
button.setAttribute(ANCHOR_ATTRIBUTE, mark);
|
|
2682
|
+
return button;
|
|
2683
|
+
};
|
|
2684
|
+
const checkEmail = (root, shadow) => {
|
|
2685
|
+
if (popup.handle) {
|
|
2686
|
+
if (!popup.emailSettled) tagSubmitButton(root, EMAIL_INPUT, popupId);
|
|
2687
|
+
return;
|
|
2688
|
+
}
|
|
2689
|
+
const step = { emailInput: inPopup(EMAIL_INPUT, shadow) };
|
|
2690
|
+
const disclosure = readEmailDisclosure(root);
|
|
2691
|
+
if (disclosure.kind === "placeholder") {
|
|
2692
|
+
const [node] = elementsOf(root, [disclosure.id]);
|
|
2693
|
+
if (!node) return;
|
|
2694
|
+
popup.handle = mountAt(
|
|
2695
|
+
step,
|
|
2696
|
+
`#${disclosure.id}`,
|
|
2697
|
+
disclosure.ownText,
|
|
2698
|
+
node,
|
|
2699
|
+
shadow
|
|
2700
|
+
);
|
|
2701
|
+
popup.emailSettled = true;
|
|
2702
|
+
return;
|
|
2703
|
+
}
|
|
2704
|
+
if (disclosure.kind === "unreadable" && !root.querySelector(EMAIL_INPUT))
|
|
2705
|
+
return;
|
|
2706
|
+
const ownText = disclosure.kind === "none" ? disclosure.ownText : [];
|
|
2707
|
+
tagSubmitButton(root, EMAIL_INPUT, popupId);
|
|
2708
|
+
popup.handle = mountAt(
|
|
2709
|
+
step,
|
|
2710
|
+
buttonSelector,
|
|
2711
|
+
ownText,
|
|
2712
|
+
elementsOf(root, ownText)[0] ?? null,
|
|
2713
|
+
shadow
|
|
2714
|
+
);
|
|
2715
|
+
};
|
|
2716
|
+
const renderSms = (root, shadow) => {
|
|
2717
|
+
const disclosure = readSmsDisclosure(root);
|
|
2718
|
+
const step = { phoneInput: inPopup(PHONE_INPUT, shadow) };
|
|
2719
|
+
const ownText = disclosure.kind === "unreadable" ? [] : disclosure.ownText;
|
|
2720
|
+
const [node] = disclosure.kind === "placeholder" ? elementsOf(root, [disclosure.id]) : [];
|
|
2721
|
+
if (disclosure.kind === "placeholder" && node) {
|
|
2722
|
+
const handle2 = mountAt(
|
|
2723
|
+
step,
|
|
2724
|
+
`#${disclosure.id}`,
|
|
2725
|
+
[disclosure.id, ...ownText],
|
|
2726
|
+
node,
|
|
2727
|
+
shadow
|
|
2728
|
+
);
|
|
2729
|
+
popup.sms = { kind: "render", handle: handle2, retag: false };
|
|
2730
|
+
return;
|
|
2731
|
+
}
|
|
2732
|
+
if (!tagSubmitButton(root, PHONE_INPUT, smsButtonMark)) return;
|
|
2733
|
+
const handle = mountAt(
|
|
2734
|
+
step,
|
|
2735
|
+
smsButtonSelector,
|
|
2736
|
+
ownText,
|
|
2737
|
+
elementsOf(root, ownText)[0] ?? null,
|
|
2738
|
+
shadow
|
|
2739
|
+
);
|
|
2740
|
+
popup.sms = { kind: "render", handle, retag: true };
|
|
2741
|
+
};
|
|
2742
|
+
const listenSms = (root) => {
|
|
2743
|
+
const token = context.token;
|
|
2744
|
+
const datashipsSessionId = context.datashipsSessionId;
|
|
2745
|
+
const disclosure = readSmsDisclosure(root);
|
|
2746
|
+
const shown = disclosure.kind === "unreadable" ? [] : elementsOf(root, [
|
|
2747
|
+
...disclosure.kind === "placeholder" ? [disclosure.id] : [],
|
|
2748
|
+
...disclosure.ownText
|
|
2749
|
+
]);
|
|
2750
|
+
const disclosureText = textOf(shown);
|
|
2751
|
+
if (disclosure.kind === "unreadable" || !token || !datashipsSessionId) {
|
|
2752
|
+
popup.sms = { kind: "none" };
|
|
2753
|
+
return;
|
|
2754
|
+
}
|
|
2755
|
+
const privacyPolicyUrl = linkOf(shown, /privacy/i);
|
|
2756
|
+
const termsUrl = linkOf(shown, /terms/i);
|
|
2757
|
+
const client = deps.createListenClient({
|
|
2758
|
+
campaignId,
|
|
2759
|
+
datashipsSessionId,
|
|
2760
|
+
publicKey: context.publicKey,
|
|
2761
|
+
baseUrl: context.baseUrl,
|
|
2762
|
+
token,
|
|
2763
|
+
...disclosureText ? { disclosureText } : {},
|
|
2764
|
+
...privacyPolicyUrl ? { privacyPolicyUrl } : {},
|
|
2765
|
+
...termsUrl ? { termsUrl } : {}
|
|
2766
|
+
});
|
|
2767
|
+
let last = client.upsertSession({ identifierType: "PHONE" }).catch(() => {
|
|
2768
|
+
});
|
|
2769
|
+
let sent = false;
|
|
2770
|
+
popup.sms = {
|
|
2771
|
+
kind: "listen",
|
|
2772
|
+
send: (phone) => {
|
|
2773
|
+
if (sent) return;
|
|
2774
|
+
sent = true;
|
|
2775
|
+
last = last.then(
|
|
2776
|
+
() => client.upsertSession({
|
|
2777
|
+
identifierType: "PHONE",
|
|
2778
|
+
identifier: phone
|
|
2779
|
+
})
|
|
2780
|
+
).then(
|
|
2781
|
+
() => client.submitSession({
|
|
2782
|
+
details: { campaignId, identifierType: "PHONE" }
|
|
2783
|
+
})
|
|
2784
|
+
).catch(() => {
|
|
2785
|
+
sent = false;
|
|
2786
|
+
});
|
|
2787
|
+
}
|
|
2788
|
+
};
|
|
2789
|
+
};
|
|
2790
|
+
const checkSms = (root, shadow) => {
|
|
2791
|
+
if (popup.sms) {
|
|
2792
|
+
if (popup.sms.kind === "render" && popup.sms.retag)
|
|
2793
|
+
tagSubmitButton(root, PHONE_INPUT, smsButtonMark);
|
|
2794
|
+
return;
|
|
2795
|
+
}
|
|
2796
|
+
if (smsType !== "SINGLE" && smsType !== "DOUBLE") {
|
|
2797
|
+
popup.sms = { kind: "none" };
|
|
2798
|
+
return;
|
|
2799
|
+
}
|
|
2800
|
+
if (!root.querySelector(PHONE_INPUT)) return;
|
|
2801
|
+
if (smsType === "SINGLE") renderSms(root, shadow);
|
|
2802
|
+
else listenSms(root);
|
|
2803
|
+
};
|
|
2804
|
+
const check = () => {
|
|
2805
|
+
try {
|
|
2806
|
+
const host = document.getElementById(`alia-root-${popupId}`);
|
|
2807
|
+
if (!host) return;
|
|
2808
|
+
const shadow = host.shadowRoot;
|
|
2809
|
+
const root = shadow ?? host;
|
|
2810
|
+
if (shadow && popup.watched !== shadow) {
|
|
2811
|
+
popup.watched = shadow;
|
|
2812
|
+
popup.observer?.observe(shadow, { childList: true, subtree: true });
|
|
2813
|
+
}
|
|
2814
|
+
checkEmail(root, shadow);
|
|
2815
|
+
checkSms(root, shadow);
|
|
2816
|
+
const smsDone = popup.sms !== null && !(popup.sms.kind === "render" && popup.sms.retag);
|
|
2817
|
+
if (popup.emailSettled && smsDone) stopObserving(popup);
|
|
2818
|
+
} catch {
|
|
2819
|
+
stopObserving(popup);
|
|
2820
|
+
}
|
|
2821
|
+
};
|
|
2822
|
+
popup.observer = new MutationObserver(check);
|
|
2823
|
+
popup.observer.observe(document.body, { childList: true, subtree: true });
|
|
2824
|
+
check();
|
|
2825
|
+
};
|
|
2826
|
+
const onPopupView = (detail) => {
|
|
2827
|
+
const popupId = idOf(detail.popupID);
|
|
2828
|
+
const campaignId = idOf(detail.campaignID);
|
|
2829
|
+
if (!popupId || !campaignId || popups.has(popupId)) return;
|
|
2830
|
+
if (!context.preview) {
|
|
2831
|
+
if (!context.token || !context.elements.some((element) => element.id === campaignId))
|
|
2832
|
+
return;
|
|
2833
|
+
}
|
|
2834
|
+
track(popupId, campaignId);
|
|
2835
|
+
};
|
|
2836
|
+
const onSignup = (detail) => {
|
|
2837
|
+
const popupId = idOf(detail.popupID);
|
|
2838
|
+
const popup = popupId ? popups.get(popupId) : void 0;
|
|
2839
|
+
if (!popup) return;
|
|
2840
|
+
if (typeof detail.email === "string" && detail.email !== "")
|
|
2841
|
+
void popup.handle?.submit?.().catch(() => {
|
|
2842
|
+
});
|
|
2843
|
+
const phone = detail.phone;
|
|
2844
|
+
if (typeof phone !== "string" || phone === "" || !popup.sms) return;
|
|
2845
|
+
if (popup.sms.kind === "render")
|
|
2846
|
+
void popup.sms.handle.submit?.({ phone }).catch(() => {
|
|
2847
|
+
});
|
|
2848
|
+
else if (popup.sms.kind === "listen") popup.sms.send(phone);
|
|
2849
|
+
};
|
|
2850
|
+
const onEvent = (event) => {
|
|
2851
|
+
try {
|
|
2852
|
+
const detail = detailOf(event);
|
|
2853
|
+
if (!detail) return;
|
|
2854
|
+
if (event.type === "alia:popupView") onPopupView(detail);
|
|
2855
|
+
else if (event.type === "alia:signup") onSignup(detail);
|
|
2856
|
+
} catch {
|
|
2857
|
+
}
|
|
2858
|
+
};
|
|
2859
|
+
const listened = ["alia:popupView", "alia:signup"];
|
|
2860
|
+
for (const event of context.events) onEvent(event);
|
|
2861
|
+
for (const name of listened) document.addEventListener(name, onEvent);
|
|
2862
|
+
return () => {
|
|
2863
|
+
for (const name of listened) document.removeEventListener(name, onEvent);
|
|
2864
|
+
for (const popup of popups.values()) stopObserving(popup);
|
|
2865
|
+
};
|
|
2866
|
+
};
|
|
2867
|
+
|
|
2868
|
+
// src/modules/alia/index.ts
|
|
2869
|
+
var PREVIEW_SESSION_ID = "preview";
|
|
2870
|
+
var createRenderClient = (options) => {
|
|
2871
|
+
const adapter = new AliaFormRenderAdapter({
|
|
2872
|
+
datashipsSessionId: options.datashipsSessionId ?? PREVIEW_SESSION_ID,
|
|
2873
|
+
campaignId: options.campaignId,
|
|
2874
|
+
previewMode: options.preview
|
|
2875
|
+
});
|
|
2876
|
+
return new DatashipsClient({
|
|
2877
|
+
adapter,
|
|
2878
|
+
app: "launcher",
|
|
2879
|
+
version: "0.2.0",
|
|
2880
|
+
baseUrl: options.baseUrl,
|
|
2881
|
+
...options.token ? { auth: { publicKey: options.publicKey, token: options.token } } : {}
|
|
2882
|
+
});
|
|
2883
|
+
};
|
|
2884
|
+
var createListenClient = (options) => new DatashipsClient({
|
|
2885
|
+
adapter: new AliaFormListenAdapter({
|
|
2886
|
+
datashipsSessionId: options.datashipsSessionId,
|
|
2887
|
+
campaignId: options.campaignId,
|
|
2888
|
+
...options.disclosureText ? { disclosureText: options.disclosureText } : {},
|
|
2889
|
+
...options.privacyPolicyUrl ? { privacyPolicyUrl: options.privacyPolicyUrl } : {},
|
|
2890
|
+
...options.termsUrl ? { termsUrl: options.termsUrl } : {}
|
|
2891
|
+
}),
|
|
2892
|
+
app: "launcher",
|
|
2893
|
+
version: "0.2.0",
|
|
2894
|
+
baseUrl: options.baseUrl,
|
|
2895
|
+
auth: { publicKey: options.publicKey, token: options.token }
|
|
2896
|
+
});
|
|
2897
|
+
var start = (context) => {
|
|
2898
|
+
watchPopups(context, { mount, createRenderClient, createListenClient });
|
|
2899
|
+
};
|
|
2900
|
+
|
|
2901
|
+
export { createListenClient, createRenderClient, start };
|