@dataships/sdk 0.0.0-stage → 2.0.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.
@@ -0,0 +1,278 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ 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);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
8
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
+
10
+ // src/utils/uuid.ts
11
+ var randomUuid = (cryptoObj = globalThis.crypto) => {
12
+ if (cryptoObj && typeof cryptoObj.randomUUID === "function") {
13
+ return cryptoObj.randomUUID();
14
+ }
15
+ const bytes = new Uint8Array(16);
16
+ if (cryptoObj && typeof cryptoObj.getRandomValues === "function") {
17
+ cryptoObj.getRandomValues(bytes);
18
+ } else {
19
+ for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256);
20
+ }
21
+ bytes[6] = bytes[6] & 15 | 64;
22
+ bytes[8] = bytes[8] & 63 | 128;
23
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
24
+ 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("");
25
+ };
26
+
27
+ // src/types.ts
28
+ var SUPPORTED_LOCALES = [
29
+ "en",
30
+ "es",
31
+ "de",
32
+ "pt",
33
+ "ro",
34
+ "hr",
35
+ "da",
36
+ "fi",
37
+ "fr",
38
+ "hu",
39
+ "it",
40
+ "nb",
41
+ "pl",
42
+ "sk",
43
+ "sv",
44
+ "nl",
45
+ "el",
46
+ "cs",
47
+ "zh",
48
+ "ja",
49
+ "is"
50
+ ];
51
+
52
+ // src/adapters/salesforce/bootstrap.ts
53
+ var DEFAULT_SELECTOR = "script[data-public-key]";
54
+ var getConfigFromScriptTag = (opts = {}) => {
55
+ const doc = opts.document ?? document;
56
+ const selector = opts.scriptSelector ?? DEFAULT_SELECTOR;
57
+ const element = doc.querySelector(selector);
58
+ if (!element) {
59
+ throw new Error(
60
+ `Dataships SDK: unable to locate the Dataships script tag using selector ${selector}`
61
+ );
62
+ }
63
+ const required = (name) => {
64
+ const value = element.getAttribute(name);
65
+ if (!value) {
66
+ throw new Error(
67
+ `Dataships SDK: Dataships script tag is missing required attribute ${name}`
68
+ );
69
+ }
70
+ return value;
71
+ };
72
+ const optional = (name) => {
73
+ const value = element.getAttribute(name);
74
+ return value && value.length > 0 ? value : null;
75
+ };
76
+ const bool = (name) => (optional(name) ?? "").toLowerCase() === "true";
77
+ return {
78
+ publicKey: required("data-public-key"),
79
+ token: optional("data-token"),
80
+ // Default to `local` (the local backend) when `data-env` is omitted. Preview
81
+ // mode is now a separate concern (see `data-preview-mode`), so an env-less
82
+ // cartridge no longer implies fake data — a real deploy must still set
83
+ // `data-env` explicitly to reach staging/production.
84
+ env: optional("data-env") ?? "local",
85
+ previewMode: bool("data-preview-mode"),
86
+ storeIdentifier: required("data-store-identifier"),
87
+ locale: localeFromSfcc(optional("data-locale")),
88
+ basketUuid: optional("data-basket-uuid"),
89
+ email: optional("data-email"),
90
+ phone: optional("data-phone"),
91
+ orderId: optional("data-order-id"),
92
+ orderToken: optional("data-order-token")
93
+ };
94
+ };
95
+ var localeFromSfcc = (raw) => {
96
+ if (!raw) return "en";
97
+ const head = raw.split(/[_-]/)[0]?.toLowerCase() ?? "";
98
+ return SUPPORTED_LOCALES.includes(head) ? head : "en";
99
+ };
100
+
101
+ // src/session/previewUpsertResponse.ts
102
+ var fakeEmailUpsertResponse = {
103
+ consentSessionId: "01HQB3QRZVV0737R0R25BTQBGF",
104
+ consents: [
105
+ {
106
+ channel: "EMAIL",
107
+ consentType: "OPT_IN",
108
+ checked: false,
109
+ widgetConfig: {
110
+ text: "Subscribe to our newsletter for exclusive offers and updates.",
111
+ consentDescription: "Click here for an overview of how your personal data is processed for marketing purposes or see our Privacy Policy for further information.",
112
+ 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',
113
+ policyURL: "https://dataships.io/privacy-centre",
114
+ mobileTermsOfServiceURL: null,
115
+ privacyEmail: "privacy@example.com",
116
+ placeholderValues: null
117
+ }
118
+ }
119
+ ],
120
+ userVerificationRequired: null,
121
+ lastHeartbeat: "2026-06-17T00:00:00Z",
122
+ identifier: null
123
+ };
124
+ var fakePhoneUpsertResponse = {
125
+ consentSessionId: "01HQB3QRZVV0737R0R25BTQBGG",
126
+ consents: [
127
+ {
128
+ channel: "SMS",
129
+ consentType: "OPT_IN",
130
+ checked: false,
131
+ widgetConfig: {
132
+ text: "Text me with news and exclusive offers. Msg & data rates may apply. Reply STOP to unsubscribe.",
133
+ consentDescription: "Click here for an overview of how your personal data is processed for marketing purposes or see our Privacy Policy for further information.",
134
+ 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',
135
+ policyURL: "https://dataships.io/privacy-centre",
136
+ mobileTermsOfServiceURL: "https://dataships.io/mobile-terms",
137
+ privacyEmail: "privacy@example.com",
138
+ placeholderValues: null
139
+ }
140
+ }
141
+ ],
142
+ userVerificationRequired: false,
143
+ lastHeartbeat: "2026-06-17T00:00:00Z",
144
+ identifier: null
145
+ };
146
+ var previewUpsertResponse = (identifierType) => identifierType === "PHONE" ? fakePhoneUpsertResponse : fakeEmailUpsertResponse;
147
+
148
+ // src/adapters/salesforce/index.ts
149
+ var DATASHIPS_ORDER_UUID_KEY_PREFIX = "datashipsOrderUuid:";
150
+ var _window, _SalesforceAdapter_instances, resolveCollectionStep_fn, isCheckoutPath_fn, urlParams_fn, getOrSetOrderUuid_fn, orderUuidKey_fn, readStoredOrderUuid_fn, safeLocalStorage_fn;
151
+ var SalesforceAdapter = class {
152
+ constructor(opts = {}) {
153
+ __privateAdd(this, _SalesforceAdapter_instances);
154
+ this.name = "SalesforceAdapter";
155
+ this.sessionApi = "consent-session";
156
+ this.integrationType = "SALESFORCE_SNIPPET";
157
+ __privateAdd(this, _window);
158
+ __privateSet(this, _window, opts.window ?? globalThis.window);
159
+ this.config = opts.config ?? getConfigFromScriptTag({ document: opts.document });
160
+ this.previewMode = this.config.previewMode;
161
+ }
162
+ /** Synthetic upsert response served in {@link previewMode}; email-only at launch. */
163
+ getPreviewUpsertResponse(identifierType = "EMAIL") {
164
+ return previewUpsertResponse(identifierType);
165
+ }
166
+ getLocale() {
167
+ return this.config.locale;
168
+ }
169
+ getIdentifier(identifierType) {
170
+ const identifier = "PHONE" === identifierType ? this.config.phone : this.config.email;
171
+ return { identifier, identifierType };
172
+ }
173
+ async getSessionContext() {
174
+ const params = __privateMethod(this, _SalesforceAdapter_instances, urlParams_fn).call(this);
175
+ const orderId = this.config.orderId ?? params.get("ID");
176
+ const orderToken = this.config.orderToken ?? params.get("token");
177
+ const collectionStep = __privateMethod(this, _SalesforceAdapter_instances, resolveCollectionStep_fn).call(this, orderId, orderToken);
178
+ const isThankYou = collectionStep === "THANK_YOU";
179
+ return {
180
+ collectionStep,
181
+ datashipsOrderUuid: __privateMethod(this, _SalesforceAdapter_instances, getOrSetOrderUuid_fn).call(this),
182
+ basketUuid: isThankYou ? null : this.config.basketUuid,
183
+ orderId: isThankYou ? orderId : null,
184
+ orderToken: isThankYou ? orderToken : null
185
+ };
186
+ }
187
+ };
188
+ _window = new WeakMap();
189
+ _SalesforceAdapter_instances = new WeakSet();
190
+ /**
191
+ * Decide the collection step from the data the cartridge already renders: an
192
+ * order id/token means the order is placed (THANK_YOU); otherwise a basket
193
+ * means we're mid-checkout (CHECKOUT_INFORMATION). Fall back to path-sniffing
194
+ * only when neither signal is present (e.g. a checkout page before a basket
195
+ * exists).
196
+ */
197
+ resolveCollectionStep_fn = function(orderId, orderToken) {
198
+ if (orderId || orderToken) return "THANK_YOU";
199
+ if (this.config.basketUuid) return "CHECKOUT_INFORMATION";
200
+ return __privateMethod(this, _SalesforceAdapter_instances, isCheckoutPath_fn).call(this) ? "CHECKOUT_INFORMATION" : "THANK_YOU";
201
+ };
202
+ isCheckoutPath_fn = function() {
203
+ const path = __privateGet(this, _window).location.pathname.toLowerCase();
204
+ if (path.includes("order-confirm")) return false;
205
+ return path.includes("checkout");
206
+ };
207
+ urlParams_fn = function() {
208
+ return new URLSearchParams(__privateGet(this, _window).location.search);
209
+ };
210
+ /**
211
+ * Resolve the datashipsOrderUuid for this page view.
212
+ *
213
+ * Lifecycle:
214
+ * - On checkout pages where SFCC has a basket: tie the UUID to that basket.
215
+ * Same `basketUuid` across visits → reuse the same UUID; new basket → fresh UUID.
216
+ * - On the confirmation page (no current basket but a stored entry exists):
217
+ * reuse the stored UUID so the THANK_YOU upsert correlates with the
218
+ * CHECKOUT_INFORMATION session backend-side.
219
+ * - No prior entry and no basket: generate a UUID for this page view only;
220
+ * nothing is persisted (we don't know what basket to associate it with). A
221
+ * confirmation reached without a stored entry — cleared storage, a different
222
+ * device, or a direct landing — therefore emits a fresh, non-correlating
223
+ * UUID. This is best-effort correlation by design.
224
+ *
225
+ * The localStorage key is scoped by `storeIdentifier` so multi-site SFCC
226
+ * instances sharing a hostname don't cross-correlate.
227
+ */
228
+ getOrSetOrderUuid_fn = function() {
229
+ const storage = __privateMethod(this, _SalesforceAdapter_instances, safeLocalStorage_fn).call(this);
230
+ const key = __privateMethod(this, _SalesforceAdapter_instances, orderUuidKey_fn).call(this);
231
+ const currentBasketUuid = this.config.basketUuid;
232
+ const stored = storage ? __privateMethod(this, _SalesforceAdapter_instances, readStoredOrderUuid_fn).call(this, storage, key) : null;
233
+ if (stored) {
234
+ if (null !== currentBasketUuid && stored.basketUuid === currentBasketUuid) {
235
+ return stored.uuid;
236
+ }
237
+ if (null === currentBasketUuid) {
238
+ return stored.uuid;
239
+ }
240
+ }
241
+ const fresh = randomUuid(__privateGet(this, _window).crypto);
242
+ if (storage && null !== currentBasketUuid) {
243
+ try {
244
+ storage.setItem(
245
+ key,
246
+ JSON.stringify({ uuid: fresh, basketUuid: currentBasketUuid })
247
+ );
248
+ } catch {
249
+ }
250
+ }
251
+ return fresh;
252
+ };
253
+ orderUuidKey_fn = function() {
254
+ return `${DATASHIPS_ORDER_UUID_KEY_PREFIX}${this.config.storeIdentifier}`;
255
+ };
256
+ readStoredOrderUuid_fn = function(storage, key) {
257
+ const raw = storage.getItem(key);
258
+ if (!raw) return null;
259
+ try {
260
+ const parsed = JSON.parse(raw);
261
+ if (typeof parsed?.uuid !== "string") return null;
262
+ const basketUuid = typeof parsed.basketUuid === "string" ? parsed.basketUuid : null;
263
+ return { uuid: parsed.uuid, basketUuid };
264
+ } catch {
265
+ return null;
266
+ }
267
+ };
268
+ safeLocalStorage_fn = function() {
269
+ try {
270
+ return __privateGet(this, _window).localStorage;
271
+ } catch {
272
+ return null;
273
+ }
274
+ };
275
+
276
+ export { SalesforceAdapter, getConfigFromScriptTag };
277
+ //# sourceMappingURL=index.js.map
278
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/uuid.ts","../../../src/types.ts","../../../src/adapters/salesforce/bootstrap.ts","../../../src/session/previewUpsertResponse.ts","../../../src/adapters/salesforce/index.ts"],"names":[],"mappings":";;;;;;;;;;AAUO,IAAM,UAAA,GAAa,CACxB,SAAA,GAAgC,UAAA,CA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OAAO,KAAA;AACT,CAAA;AAEA,eAAA,GAAa,WAAW;AACtB,EAAA,OAAO,CAAA,EAAG,+BAA+B,CAAA,EAAG,IAAA,CAAK,OAAO,eAAe,CAAA,CAAA;AACzE,CAAA;AAEA,sBAAA,GAAoB,SAAC,SAAkB,GAAA,EAAqC;AAC1E,EAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,OAAA,CAAQ,GAAG,CAAA;AAC/B,EAAA,IAAI,CAAC,KAAK,OAAO,IAAA;AACjB,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA;AAC7B,IAAA,IAAI,OAAO,MAAA,EAAQ,IAAA,KAAS,QAAA,EAAU,OAAO,IAAA;AAC7C,IAAA,MAAM,aACJ,OAAO,MAAA,CAAO,UAAA,KAAe,QAAA,GAAW,OAAO,UAAA,GAAa,IAAA;AAC9D,IAAA,OAAO,EAAE,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,UAAA,EAAW;AAAA,EACzC,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF,CAAA;AAEA,mBAAA,GAAiB,WAAmB;AAClC,EAAA,IAAI;AACF,IAAA,OAAO,mBAAK,OAAA,CAAA,CAAQ,YAAA;AAAA,EACtB,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF,CAAA","file":"index.js"}
@@ -0,0 +1,102 @@
1
+ import { C as ConsentSessionAdapter, I as IdentifierType, U as UpsertSessionResponse, S as SupportedLocale, a as ConsentSessionIdentifier } from '../../types-Bfm_pCq7.js';
2
+ export { c as coerceLocale } from '../../locale-DwOMogGu.js';
3
+
4
+ /**
5
+ * Where in the Shopify checkout the extension renders. Mirrors core-api's
6
+ * `WidgetType` as accepted by the `SHOPIFY_CHECKOUT` integration:
7
+ *
8
+ * - `CHECKOUT_INFORMATION` — the contact / delivery step, before purchase.
9
+ * - `THANK_YOU` — the order confirmation page right after purchase.
10
+ */
11
+ type ShopifyCheckoutCollectionStep = "CHECKOUT_INFORMATION" | "THANK_YOU";
12
+ /**
13
+ * Checkout facts the extension reads from the Shopify checkout API and that
14
+ * can change while the buyer is on the page (a wallet picked, the order id
15
+ * appearing on the thank-you page). Absent values are not sent.
16
+ */
17
+ interface ShopifyCheckoutDetails {
18
+ /** The order id, once the order exists (thank-you page). */
19
+ orderId?: string | null;
20
+ /** `shopify.checkoutToken`. */
21
+ checkoutToken?: string | null;
22
+ /** Whether the buyer paid with an accelerated / express wallet. */
23
+ isAcceleratedPayment?: boolean | null;
24
+ /** The wallet's name, e.g. `shop_pay`, `apple_pay`. */
25
+ wallet?: string | null;
26
+ }
27
+ /**
28
+ * Integration-specific fields the Shopify checkout adapter contributes to the
29
+ * consent-session envelope, merged under `integration`. The client injects
30
+ * `type: "SHOPIFY_CHECKOUT"`; the identifier and `locale` travel at the top
31
+ * level; the shop is identified by the `X-Api-Key` header and the Shopify
32
+ * session token, never by the body.
33
+ *
34
+ * `datashipsOrderUuid` ties the email and SMS extensions and the thank-you page
35
+ * of one checkout together (the extension stores it as a cart attribute). It
36
+ * is optional: core-api needs one of it, `checkoutToken` or `orderId`.
37
+ */
38
+ interface ShopifyCheckoutSessionContext extends ShopifyCheckoutDetails {
39
+ collectionStep: ShopifyCheckoutCollectionStep;
40
+ datashipsOrderUuid?: string;
41
+ }
42
+
43
+ /** `integration.type` discriminator core-api routes to the Shopify checkout lifecycle. */
44
+ declare const SHOPIFY_CHECKOUT_INTEGRATION_TYPE = "SHOPIFY_CHECKOUT";
45
+
46
+ interface ShopifyCheckoutAdapterOptions extends ShopifyCheckoutDetails {
47
+ /** Which checkout surface the extension renders on. Change it later with {@link ShopifyCheckoutAdapter.setCollectionStep}. */
48
+ collectionStep: ShopifyCheckoutCollectionStep;
49
+ /** The checkout's Dataships order UUID (the extension's cart attribute), when it has one. */
50
+ datashipsOrderUuid?: string | null;
51
+ /**
52
+ * The buyer's language, e.g. `shopify.localization.language.isoCode`. Any
53
+ * BCP 47 / POSIX style string is accepted; the first segment is used when it
54
+ * maps to a {@link SupportedLocale}, otherwise `"en"`.
55
+ */
56
+ locale?: string;
57
+ /** Buyer email already known to the checkout. */
58
+ email?: string | null;
59
+ /** Buyer E.164 phone already known to the checkout. */
60
+ phone?: string | null;
61
+ /**
62
+ * When true the client never calls the API and serves synthetic email data
63
+ * instead. Defaults to false.
64
+ */
65
+ previewMode?: boolean;
66
+ }
67
+ /**
68
+ * Consent-session adapter for the Shopify checkout UI extensions. Drives the
69
+ * `SHOPIFY_CHECKOUT` upsert type on `POST /v1/consent-session`.
70
+ *
71
+ * Has no DOM or `window` dependency: checkout UI extensions run in a sandboxed
72
+ * worker, so every input comes from the Shopify checkout API through the
73
+ * options and setters. Pair it with `auth: { publicKey, getToken: () =>
74
+ * shopify.sessionToken.get() }` so each request carries a fresh session token.
75
+ */
76
+ declare class ShopifyCheckoutAdapter implements ConsentSessionAdapter<ShopifyCheckoutSessionContext> {
77
+ #private;
78
+ readonly name: string;
79
+ readonly sessionApi: "consent-session";
80
+ readonly integrationType = "SHOPIFY_CHECKOUT";
81
+ readonly previewMode: boolean;
82
+ constructor(opts: ShopifyCheckoutAdapterOptions);
83
+ /** Synthetic upsert response served in {@link previewMode}, matching the requested identifier type. */
84
+ getPreviewUpsertResponse(identifierType?: IdentifierType): UpsertSessionResponse;
85
+ getLocale(): SupportedLocale;
86
+ setLocale(locale: string | null | undefined): void;
87
+ get collectionStep(): ShopifyCheckoutCollectionStep;
88
+ setCollectionStep(step: ShopifyCheckoutCollectionStep): void;
89
+ get datashipsOrderUuid(): string | null;
90
+ /** Merge checkout facts that changed since construction; an explicit `undefined` clears a field. */
91
+ setCheckoutDetails(details: ShopifyCheckoutDetails): void;
92
+ /**
93
+ * Remember an identifier the buyer typed so later calls (a refresh, a
94
+ * remount) resolve it without the caller passing it again. An explicit
95
+ * `upsertSession({ identifier })` still takes precedence.
96
+ */
97
+ setIdentifier(identifierType: IdentifierType, value: string | null): void;
98
+ getIdentifier(identifierType: IdentifierType): ConsentSessionIdentifier;
99
+ getSessionContext(): Promise<ShopifyCheckoutSessionContext>;
100
+ }
101
+
102
+ export { SHOPIFY_CHECKOUT_INTEGRATION_TYPE, ShopifyCheckoutAdapter, type ShopifyCheckoutAdapterOptions, type ShopifyCheckoutCollectionStep, type ShopifyCheckoutDetails, type ShopifyCheckoutSessionContext };
@@ -0,0 +1,178 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ 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);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
8
+
9
+ // src/session/previewUpsertResponse.ts
10
+ var fakeEmailUpsertResponse = {
11
+ consentSessionId: "01HQB3QRZVV0737R0R25BTQBGF",
12
+ consents: [
13
+ {
14
+ channel: "EMAIL",
15
+ consentType: "OPT_IN",
16
+ checked: false,
17
+ widgetConfig: {
18
+ text: "Subscribe to our newsletter for exclusive offers and updates.",
19
+ consentDescription: "Click here for an overview of how your personal data is processed for marketing purposes or see our Privacy Policy for further information.",
20
+ 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',
21
+ policyURL: "https://dataships.io/privacy-centre",
22
+ mobileTermsOfServiceURL: null,
23
+ privacyEmail: "privacy@example.com",
24
+ placeholderValues: null
25
+ }
26
+ }
27
+ ],
28
+ userVerificationRequired: null,
29
+ lastHeartbeat: "2026-06-17T00:00:00Z",
30
+ identifier: null
31
+ };
32
+ var fakePhoneUpsertResponse = {
33
+ consentSessionId: "01HQB3QRZVV0737R0R25BTQBGG",
34
+ consents: [
35
+ {
36
+ channel: "SMS",
37
+ consentType: "OPT_IN",
38
+ checked: false,
39
+ widgetConfig: {
40
+ text: "Text me with news and exclusive offers. Msg & data rates may apply. Reply STOP to unsubscribe.",
41
+ consentDescription: "Click here for an overview of how your personal data is processed for marketing purposes or see our Privacy Policy for further information.",
42
+ 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',
43
+ policyURL: "https://dataships.io/privacy-centre",
44
+ mobileTermsOfServiceURL: "https://dataships.io/mobile-terms",
45
+ privacyEmail: "privacy@example.com",
46
+ placeholderValues: null
47
+ }
48
+ }
49
+ ],
50
+ userVerificationRequired: false,
51
+ lastHeartbeat: "2026-06-17T00:00:00Z",
52
+ identifier: null
53
+ };
54
+ var previewUpsertResponse = (identifierType) => identifierType === "PHONE" ? fakePhoneUpsertResponse : fakeEmailUpsertResponse;
55
+
56
+ // src/types.ts
57
+ var SUPPORTED_LOCALES = [
58
+ "en",
59
+ "es",
60
+ "de",
61
+ "pt",
62
+ "ro",
63
+ "hr",
64
+ "da",
65
+ "fi",
66
+ "fr",
67
+ "hu",
68
+ "it",
69
+ "nb",
70
+ "pl",
71
+ "sk",
72
+ "sv",
73
+ "nl",
74
+ "el",
75
+ "cs",
76
+ "zh",
77
+ "ja",
78
+ "is"
79
+ ];
80
+
81
+ // src/adapters/locale.ts
82
+ var coerceLocale = (raw) => {
83
+ if (!raw) return "en";
84
+ const head = raw.split(/[_-]/)[0]?.toLowerCase() ?? "";
85
+ return SUPPORTED_LOCALES.includes(head) ? head : "en";
86
+ };
87
+
88
+ // src/adapters/shopify-checkout/index.ts
89
+ var SHOPIFY_CHECKOUT_INTEGRATION_TYPE = "SHOPIFY_CHECKOUT";
90
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
91
+ var _datashipsOrderUuid, _collectionStep, _locale, _identifiers, _details;
92
+ var ShopifyCheckoutAdapter = class {
93
+ constructor(opts) {
94
+ this.name = "ShopifyCheckoutAdapter";
95
+ this.sessionApi = "consent-session";
96
+ this.integrationType = SHOPIFY_CHECKOUT_INTEGRATION_TYPE;
97
+ __privateAdd(this, _datashipsOrderUuid);
98
+ __privateAdd(this, _collectionStep);
99
+ __privateAdd(this, _locale);
100
+ __privateAdd(this, _identifiers);
101
+ __privateAdd(this, _details);
102
+ if (!opts || !opts.collectionStep) {
103
+ throw new Error("ShopifyCheckoutAdapter: `collectionStep` is required");
104
+ }
105
+ if (opts.datashipsOrderUuid != null && !UUID.test(opts.datashipsOrderUuid)) {
106
+ throw new Error(
107
+ "ShopifyCheckoutAdapter: `datashipsOrderUuid` must be a UUID"
108
+ );
109
+ }
110
+ __privateSet(this, _collectionStep, opts.collectionStep);
111
+ __privateSet(this, _datashipsOrderUuid, opts.datashipsOrderUuid ?? null);
112
+ __privateSet(this, _locale, coerceLocale(opts.locale));
113
+ __privateSet(this, _identifiers, {
114
+ EMAIL: opts.email ?? null,
115
+ PHONE: opts.phone ?? null
116
+ });
117
+ __privateSet(this, _details, {
118
+ orderId: opts.orderId,
119
+ checkoutToken: opts.checkoutToken,
120
+ isAcceleratedPayment: opts.isAcceleratedPayment,
121
+ wallet: opts.wallet
122
+ });
123
+ this.previewMode = opts.previewMode ?? false;
124
+ }
125
+ /** Synthetic upsert response served in {@link previewMode}, matching the requested identifier type. */
126
+ getPreviewUpsertResponse(identifierType = "EMAIL") {
127
+ return previewUpsertResponse(identifierType);
128
+ }
129
+ getLocale() {
130
+ return __privateGet(this, _locale);
131
+ }
132
+ setLocale(locale) {
133
+ __privateSet(this, _locale, coerceLocale(locale));
134
+ }
135
+ get collectionStep() {
136
+ return __privateGet(this, _collectionStep);
137
+ }
138
+ setCollectionStep(step) {
139
+ __privateSet(this, _collectionStep, step);
140
+ }
141
+ get datashipsOrderUuid() {
142
+ return __privateGet(this, _datashipsOrderUuid);
143
+ }
144
+ /** Merge checkout facts that changed since construction; an explicit `undefined` clears a field. */
145
+ setCheckoutDetails(details) {
146
+ __privateSet(this, _details, { ...__privateGet(this, _details), ...details });
147
+ }
148
+ /**
149
+ * Remember an identifier the buyer typed so later calls (a refresh, a
150
+ * remount) resolve it without the caller passing it again. An explicit
151
+ * `upsertSession({ identifier })` still takes precedence.
152
+ */
153
+ setIdentifier(identifierType, value) {
154
+ __privateGet(this, _identifiers)[identifierType] = value;
155
+ }
156
+ getIdentifier(identifierType) {
157
+ return { identifier: __privateGet(this, _identifiers)[identifierType], identifierType };
158
+ }
159
+ async getSessionContext() {
160
+ return {
161
+ collectionStep: __privateGet(this, _collectionStep),
162
+ ...__privateGet(this, _datashipsOrderUuid) !== null && { datashipsOrderUuid: __privateGet(this, _datashipsOrderUuid) },
163
+ ...definedOnly(__privateGet(this, _details))
164
+ };
165
+ }
166
+ };
167
+ _datashipsOrderUuid = new WeakMap();
168
+ _collectionStep = new WeakMap();
169
+ _locale = new WeakMap();
170
+ _identifiers = new WeakMap();
171
+ _details = new WeakMap();
172
+ var definedOnly = (details) => Object.fromEntries(
173
+ Object.entries(details).filter(([, value]) => value !== void 0)
174
+ );
175
+
176
+ export { SHOPIFY_CHECKOUT_INTEGRATION_TYPE, ShopifyCheckoutAdapter, coerceLocale };
177
+ //# sourceMappingURL=index.js.map
178
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/session/previewUpsertResponse.ts","../../../src/types.ts","../../../src/adapters/locale.ts","../../../src/adapters/shopify-checkout/index.ts"],"names":[],"mappings":";;;;;;;;;AAYO,IAAM,uBAAA,GAAiD;AAAA,EAC5D,gBAAA,EAAkB,4BAAA;AAAA,EACl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AO,WAAA;AAAA,EACL,MAAA,CAAO,OAAA,CAAQ,OAAO,CAAA,CAAE,MAAA,CAAO,CAAC,GAAG,KAAK,CAAA,KAAM,KAAA,KAAU,MAAS;AACnE,CAAA","file":"index.js"}
@@ -0,0 +1,4 @@
1
+ /** core-api caps `datashipsSessionId` at 100 characters (`#[Assert\Length(max: 100)]`). */
2
+ declare const DATASHIPS_SESSION_ID_MAX_LENGTH = 100;
3
+
4
+ export { DATASHIPS_SESSION_ID_MAX_LENGTH as D };
@@ -0,0 +1,6 @@
1
+ "use strict";var Dataships=(()=>{var Se=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var Ct=Object.getOwnPropertyNames;var gt=Object.prototype.hasOwnProperty;var _e=t=>{throw TypeError(t)};var It=(t,e)=>{for(var o in e)Se(t,o,{get:e[o],enumerable:!0})},Tt=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Ct(e))!gt.call(t,a)&&a!==o&&Se(t,a,{get:()=>e[a],enumerable:!(s=mt(e,a))||s.enumerable});return t};var Et=t=>Tt(Se({},"__esModule",{value:!0}),t);var fe=(t,e,o)=>e.has(t)||_e("Cannot "+o);var n=(t,e,o)=>(fe(t,e,"read from private field"),o?o.call(t):e.get(t)),i=(t,e,o)=>e.has(t)?_e("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,o),r=(t,e,o,s)=>(fe(t,e,"write to private field"),s?s.call(t,o):e.set(t,o),o),p=(t,e,o)=>(fe(t,e,"access private method"),o);var Xt={};It(Xt,{CONSENT_SESSION_ALREADY_PROCESSED:()=>G,CONSENT_SESSION_SUBMIT_PATH:()=>pe,COUNTRY_NOT_FOUND_CODE:()=>ye,CUSTOM_PLATFORM_CHECKOUT_INTEGRATION_TYPE:()=>ft,CUSTOM_PLATFORM_SIGNUP_INTEGRATION_TYPE:()=>ht,CustomPlatformCheckoutAdapter:()=>we,CustomPlatformSignupAdapter:()=>ve,DATASHIPS_SESSION_ID_MAX_LENGTH:()=>Z,DatashipsClient:()=>ue,DatashipsError:()=>h,DatashipsHttpError:()=>h,SHOPIFY_CHECKOUT_INTEGRATION_TYPE:()=>it,SUBMIT_VERIFICATION_CODE_ERROR_CODES:()=>Ve,SUPPORTED_LOCALES:()=>D,SalesforceAdapter:()=>Re,ShopifyCheckoutAdapter:()=>Ee,UNSAFE_SERVER_KEY_APP_MARKER:()=>re,UNSAFE_SERVER_KEY_WARNING:()=>he,authHeaders:()=>ie,buildSubmitRequest:()=>ce,coerceLocale:()=>C,defaultRetryPolicy:()=>$,fakeEmailUpsertResponse:()=>Ie,fakePhoneUpsertResponse:()=>Te,getConfigFromScriptTag:()=>de,noRetryPolicy:()=>W,normaliseSubmitUser:()=>Ce,previewUpsertResponse:()=>m,randomUuid:()=>N,sha256Hex:()=>rt,upsertSessionRetryPolicy:()=>ae,verificationErrorCodeFromBody:()=>le,version:()=>Jt});var Rt="ds_sk_",Oe=t=>t.startsWith(Rt),bt=t=>"serverKey"in t,k=t=>"unsafeServerKey"in t,se=t=>typeof t.getToken=="function",Ue=async t=>{let e=await t.getToken();if(!e)throw new Error("DatashipsClient: auth.getToken() returned an empty token");return{publicKey:t.publicKey,token:e}},re="unsafe-server-key",he="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.",ke=t=>{if(k(t)){if(!t.unsafeServerKey||!Oe(t.unsafeServerKey))throw new Error("DatashipsClient: auth.unsafeServerKey must be a server key (ds_sk_\u2026); a public key belongs in auth: { publicKey, token }");wt();return}if(Oe(t.publicKey))throw new Error("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");let e="getToken"in t&&t.getToken!==void 0;if(e&&"token"in t&&t.token!==void 0)throw new Error("DatashipsClient: pass either auth.token or auth.getToken, not both");if(e){if(!se(t))throw new Error("DatashipsClient: auth.getToken must be a function");return}if(!t.token)throw new Error("DatashipsClient: auth.token is required with a public key (the merchant's server mints it), or auth.getToken to fetch one per request")};var wt=()=>{globalThis.console?.warn?.(he)},ie=t=>k(t)?{"X-Api-Key":t.unsafeServerKey}:bt(t)?{"X-Api-Key":t.serverKey}:{"X-Api-Key":t.publicKey,Authorization:`Bearer ${t.token}`};var At="https://api.dataships.io",Ne=(t="production",e)=>{if(e)return e;if(t==="production")return At;throw new Error(`Dataships SDK: env "${t}" has no default base URL; pass \`baseUrl\``)};var vt=new Set([400,401,403,404,417,422,426]),Pt=t=>t!==void 0&&vt.has(t),G="CONSENT_SESSION_ALREADY_PROCESSED",xt=new Set([G]),_t=t=>t!==void 0&&xt.has(t),De=4,Ot=t=>t>=De?0:t*2e3,$={shouldRetry:(t,e,o)=>!Pt(e)&&!_t(o)&&t<De,delayMs:Ot},ae=$,W={shouldRetry:()=>!1,delayMs:()=>0};var h=class extends Error{constructor(e){super(`Dataships request failed (${e.status||"network"})`),this.name="DatashipsError",this.status=e.status,this.body=e.body,this.challenge=e.challenge??null,this.code=J(e.body),this.reason=Ut(e.body)}get isAuthenticationFailure(){return this.status===401||this.status===403}get isSessionProcessed(){return this.code===G}};var J=t=>{if(typeof t!="object"||t===null)return null;let e=t.errors;if(!Array.isArray(e))return null;let o=e[0]?.code;return typeof o=="string"?o:null},Ut=t=>{if(typeof t!="object"||t===null)return null;let e=t.message;return typeof e=="string"&&e.length>0?e:null};var Le="/v1/consent-session",Ke="/v1/consent-session/consent",Me="/v1/consent-session/heartbeat",Fe="/v1/consent-session/trigger-verification-code",He="/v1/consent-session/submit-verification-code",pe="/v1/consent-session/submit";var ye="COUNTRY_NOT_FOUND",Ve=["CODE_EXPIRED","CODE_INVALID","NUMBER_MAX_ATTEMPTS_EXCEEDED"],le=J,Be=t=>({identifier:t.identifier,identifierType:t.identifierType,locale:t.locale,...t.userIp?{userIp:t.userIp}:{},...t.format?{format:t.format}:{},integration:{...t.context,type:t.integrationType}}),qe=t=>t.status===422&&t.code===ye,me=()=>({consentSessionId:null,consents:[],userVerificationRequired:null,lastHeartbeat:null,identifier:null}),je=t=>({consentSessionId:t.consentSessionId,channel:t.channel,consent:t.consent}),Ye=t=>({consentSessionId:t.consentSessionId}),Ge=t=>({consentSessionId:t.consentSessionId}),$e=t=>({consentSessionId:t.consentSessionId,verificationCode:t.verificationCode,referenceId:t.referenceId}),ce=t=>{let e={...t.details};return e.submittedAt instanceof Date&&(e.submittedAt=e.submittedAt.toISOString()),typeof e.billingCountryCode=="string"&&(e.billingCountryCode=e.billingCountryCode.trim().toUpperCase()),{datashipsSessionId:t.datashipsSessionId,user:Ce(t.user),integration:{...e,type:t.integrationType}}},Ce=t=>{let e=t?.firstName?.trim()??"",o=t?.lastName?.trim()??"";if(!e||!o)throw new Error("submitSession: user.firstName and user.lastName are required (core-api refuses a blank name)");return{firstName:e,lastName:o}};var We=async t=>{let{adapter:e,input:o}=t,s=o.identifier??(await e.getIdentifier(o.identifierType)).identifier,a=await e.getSessionContext(),l=Be({integrationType:e.integrationType,locale:e.getLocale(),identifier:s,identifierType:o.identifierType,userIp:o.userIp,format:o.format,context:a});try{return await t.post({path:Le,body:l,retry:t.retry})??me()}catch(u){if(u instanceof h&&qe(u))return me();throw u}},Je=t=>t.post({path:Ke,body:je({consentSessionId:t.consentSessionId,channel:t.channel,consent:t.consent}),retry:t.retry}),Xe=t=>t.post({path:Me,body:Ye({consentSessionId:t.consentSessionId}),retry:t.retry}),Qe=t=>t.post({path:Fe,body:Ge({consentSessionId:t.consentSessionId}),retry:W}),Ze=async t=>{try{return await t.post({path:He,body:$e({consentSessionId:t.consentSessionId,verificationCode:t.verificationCode,referenceId:t.referenceId}),retry:W}),{verified:!0,errorCode:null}}catch(e){if(e instanceof h&&e.status===400)return{verified:!1,errorCode:le(e.body)};throw e}},ze=async t=>{let{adapter:e,input:o}=t,s=o.datashipsSessionId??e.getDatashipsSessionId?.();if(!s)throw new Error("submitSession: datashipsSessionId is required; this adapter holds no beacon of its own");await t.post({path:pe,body:ce({datashipsSessionId:s,integrationType:e.integrationType,user:o.user,details:o.details}),retry:t.retry}),o.datashipsSessionId===void 0&&o.resetBeacon!==!1&&e.resetDatashipsSessionId?.()};var et=async({url:t,headers:e,body:o,fetch:s,retry:a})=>{let l=0;for(;;){let u,S,y=typeof e=="function"?await e():e;try{u=await s(t,{method:"POST",headers:{"Content-Type":"application/json",...y},body:JSON.stringify(o)})}catch(U){S=U}let E=u?.status;if((u?.ok??!1)&&u){let U=await u.text();return U?JSON.parse(U):void 0}let Pe=u?await Nt(u):null,yt=J(Pe)??void 0;if(!a.shouldRetry(l,E,yt))throw S||new h({status:E??0,body:Pe,challenge:u?.headers.get("WWW-Authenticate")??null});l+=1;let xe=a.delayMs(l);xe>0&&await new Promise(U=>setTimeout(U,xe))}},Nt=async t=>{let e=await t.text();if(!e)return null;try{return JSON.parse(e)}catch{return e}};var Dt=210*1e3,Lt=600*1e3,f,X,Q,b,c,tt,ot,nt,ge,st,R,ue=class{constructor(e){i(this,c);i(this,f);i(this,X);i(this,Q);i(this,b);if(this.adapter=e.adapter,e.auth&&ke(e.auth),!e.auth&&!e.adapter.previewMode)throw new Error("DatashipsClient: `auth: { publicKey, token }` (or `{ publicKey, getToken }`) is required unless the adapter runs in preview mode");this.publicKey=e.auth&&!k(e.auth)?e.auth.publicKey:null,r(this,f,e.auth??null),this.app=e.app,this.version=e.version,this.baseUrl=Ne(e.env,e.baseUrl),r(this,X,e.fetch??globalThis.fetch.bind(globalThis)),r(this,Q,e.retry?.upsertSession??ae),r(this,b,e.retry?.default??$)}get auth(){return n(this,f)}get isUnsafeServerKey(){return n(this,f)!==null&&k(n(this,f))}setToken(e){if(!n(this,f))throw new Error("DatashipsClient: setToken() requires a client constructed with `auth`");if(k(n(this,f)))throw new Error("DatashipsClient: setToken() does not apply under auth.unsafeServerKey; there is no token to rotate");if(se(n(this,f)))throw new Error("DatashipsClient: setToken() does not apply under auth.getToken; the provider is called before every request");if(!e)throw new Error("DatashipsClient: token must be a non-empty string");r(this,f,{...n(this,f),token:e})}async upsertSession(e){let o=p(this,c,tt).call(this,e.identifierType);return o||We({adapter:this.adapter,input:e,post:p(this,c,R).bind(this),retry:n(this,Q)})}async saveConsent(e){this.adapter.previewMode||await Je({consentSessionId:p(this,c,ge).call(this,e.session),channel:e.channel,consent:e.consent,post:p(this,c,R).bind(this),retry:n(this,b)})}async triggerVerificationCode(e){return this.adapter.previewMode?{userVerificationTriggered:!1,referenceId:null,codeLength:null,resendAfterSeconds:null}:Qe({consentSessionId:e.consentSessionId,post:p(this,c,R).bind(this)})}async submitVerificationCode(e){return this.adapter.previewMode?{verified:!0,errorCode:null}:Ze({...e,post:p(this,c,R).bind(this)})}async submitSession(e){let o=this.adapter;if(o.previewMode){e.datashipsSessionId===void 0&&e.resetBeacon!==!1&&o.resetDatashipsSessionId?.();return}await ze({adapter:o,input:e,post:p(this,c,R).bind(this),retry:n(this,b)})}startHeartbeat(e,o={}){if(this.adapter.previewMode)return()=>{};let s=o.intervalMs??Dt,a=o.durationMs??Lt,l=Date.now(),u=!1,S=()=>{u||(u=!0,clearInterval(y))},y=setInterval(()=>{if(Date.now()-l>=a){S();return}p(this,c,st).call(this,e).catch(E=>{o.onError?.(E),E instanceof h&&(E.isAuthenticationFailure||E.isSessionProcessed)&&S()})},s);return S}};f=new WeakMap,X=new WeakMap,Q=new WeakMap,b=new WeakMap,c=new WeakSet,tt=function(e){return this.adapter.previewMode&&this.adapter.getPreviewUpsertResponse?this.adapter.getPreviewUpsertResponse(e):null},ot=async function(){let e=p(this,c,nt).call(this);return ie(se(e)?await Ue(e):e)},nt=function(){if(!n(this,f))throw new Error("DatashipsClient: no credentials configured; pass `auth: { publicKey, token }`");return n(this,f)},ge=function(e){if(!e.consentSessionId)throw new Error("DatashipsClient: consentSessionId is required");return e.consentSessionId},st=async function(e){await Xe({consentSessionId:p(this,c,ge).call(this,e),post:p(this,c,R).bind(this),retry:n(this,b)})},R=async function(e){let o={"X-Dataships-App":`${this.app} (SDK: ${this.adapter.name}${this.isUnsafeServerKey?`; ${re}`:""})`,"X-Dataships-Version":`${this.version} (SDK: 2.0.0)`};return et({url:`${this.baseUrl}${e.path}`,headers:async()=>({...await p(this,c,ot).call(this),...o}),body:e.body,fetch:n(this,X),retry:e.retry})};var rt=async t=>{let e=new TextEncoder().encode(t),o=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(o)).map(s=>s.toString(16).padStart(2,"0")).join("")};var N=(t=globalThis.crypto)=>{if(t&&typeof t.randomUUID=="function")return t.randomUUID();let e=new Uint8Array(16);if(t&&typeof t.getRandomValues=="function")t.getRandomValues(e);else for(let s=0;s<16;s++)e[s]=Math.floor(Math.random()*256);e[6]=e[6]&15|64,e[8]=e[8]&63|128;let o=Array.from(e,s=>s.toString(16).padStart(2,"0"));return o.slice(0,4).join("")+"-"+o.slice(4,6).join("")+"-"+o.slice(6,8).join("")+"-"+o.slice(8,10).join("")+"-"+o.slice(10,16).join("")};var Ie={consentSessionId:"01HQB3QRZVV0737R0R25BTQBGF",consents:[{channel:"EMAIL",consentType:"OPT_IN",checked:!1,widgetConfig:{text:"Subscribe to our newsletter for exclusive offers and updates.",consentDescription:"Click here for an overview of how your personal data is processed for marketing purposes or see our Privacy Policy for further information.",marketingInformation:`<h1>Marketing Information</h1>
2
+ <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>
3
+ `,policyURL:"https://dataships.io/privacy-centre",mobileTermsOfServiceURL:null,privacyEmail:"privacy@example.com",placeholderValues:null}}],userVerificationRequired:null,lastHeartbeat:"2026-06-17T00:00:00Z",identifier:null},Te={consentSessionId:"01HQB3QRZVV0737R0R25BTQBGG",consents:[{channel:"SMS",consentType:"OPT_IN",checked:!1,widgetConfig:{text:"Text me with news and exclusive offers. Msg & data rates may apply. Reply STOP to unsubscribe.",consentDescription:"Click here for an overview of how your personal data is processed for marketing purposes or see our Privacy Policy for further information.",marketingInformation:`<h1>Marketing Information</h1>
4
+ <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>
5
+ `,policyURL:"https://dataships.io/privacy-centre",mobileTermsOfServiceURL:"https://dataships.io/mobile-terms",privacyEmail:"privacy@example.com",placeholderValues:null}}],userVerificationRequired:!1,lastHeartbeat:"2026-06-17T00:00:00Z",identifier:null},m=t=>t==="PHONE"?Te:Ie;var D=["en","es","de","pt","ro","hr","da","fi","fr","hu","it","nb","pl","sk","sv","nl","el","cs","zh","ja","is"];var C=t=>{if(!t)return"en";let e=t.split(/[_-]/)[0]?.toLowerCase()??"";return D.includes(e)?e:"en"};var it="SHOPIFY_CHECKOUT";var Kt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,w,A,L,K,v,Ee=class{constructor(e){this.name="ShopifyCheckoutAdapter";this.sessionApi="consent-session";this.integrationType=it;i(this,w);i(this,A);i(this,L);i(this,K);i(this,v);if(!e||!e.collectionStep)throw new Error("ShopifyCheckoutAdapter: `collectionStep` is required");if(e.datashipsOrderUuid!=null&&!Kt.test(e.datashipsOrderUuid))throw new Error("ShopifyCheckoutAdapter: `datashipsOrderUuid` must be a UUID");r(this,A,e.collectionStep),r(this,w,e.datashipsOrderUuid??null),r(this,L,C(e.locale)),r(this,K,{EMAIL:e.email??null,PHONE:e.phone??null}),r(this,v,{orderId:e.orderId,checkoutToken:e.checkoutToken,isAcceleratedPayment:e.isAcceleratedPayment,wallet:e.wallet}),this.previewMode=e.previewMode??!1}getPreviewUpsertResponse(e="EMAIL"){return m(e)}getLocale(){return n(this,L)}setLocale(e){r(this,L,C(e))}get collectionStep(){return n(this,A)}setCollectionStep(e){r(this,A,e)}get datashipsOrderUuid(){return n(this,w)}setCheckoutDetails(e){r(this,v,{...n(this,v),...e})}setIdentifier(e,o){n(this,K)[e]=o}getIdentifier(e){return{identifier:n(this,K)[e],identifierType:e}}async getSessionContext(){return{collectionStep:n(this,A),...n(this,w)!==null&&{datashipsOrderUuid:n(this,w)},...Mt(n(this,v))}}};w=new WeakMap,A=new WeakMap,L=new WeakMap,K=new WeakMap,v=new WeakMap;var Mt=t=>Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0));var Ft="script[data-public-key]",de=(t={})=>{let e=t.document??document,o=t.scriptSelector??Ft,s=e.querySelector(o);if(!s)throw new Error(`Dataships SDK: unable to locate the Dataships script tag using selector ${o}`);let a=S=>{let y=s.getAttribute(S);if(!y)throw new Error(`Dataships SDK: Dataships script tag is missing required attribute ${S}`);return y},l=S=>{let y=s.getAttribute(S);return y&&y.length>0?y:null},u=S=>(l(S)??"").toLowerCase()==="true";return{publicKey:a("data-public-key"),token:l("data-token"),env:l("data-env")??"local",previewMode:u("data-preview-mode"),storeIdentifier:a("data-store-identifier"),locale:Ht(l("data-locale")),basketUuid:l("data-basket-uuid"),email:l("data-email"),phone:l("data-phone"),orderId:l("data-order-id"),orderToken:l("data-order-token")}},Ht=t=>{if(!t)return"en";let e=t.split(/[_-]/)[0]?.toLowerCase()??"";return D.includes(e)?e:"en"};var Vt="datashipsOrderUuid:",g,d,at,pt,lt,ct,ut,dt,St,Re=class{constructor(e={}){i(this,d);this.name="SalesforceAdapter";this.sessionApi="consent-session";this.integrationType="SALESFORCE_SNIPPET";i(this,g);r(this,g,e.window??globalThis.window),this.config=e.config??de({document:e.document}),this.previewMode=this.config.previewMode}getPreviewUpsertResponse(e="EMAIL"){return m(e)}getLocale(){return this.config.locale}getIdentifier(e){return{identifier:e==="PHONE"?this.config.phone:this.config.email,identifierType:e}}async getSessionContext(){let e=p(this,d,lt).call(this),o=this.config.orderId??e.get("ID"),s=this.config.orderToken??e.get("token"),a=p(this,d,at).call(this,o,s),l=a==="THANK_YOU";return{collectionStep:a,datashipsOrderUuid:p(this,d,ct).call(this),basketUuid:l?null:this.config.basketUuid,orderId:l?o:null,orderToken:l?s:null}}};g=new WeakMap,d=new WeakSet,at=function(e,o){return e||o?"THANK_YOU":this.config.basketUuid||p(this,d,pt).call(this)?"CHECKOUT_INFORMATION":"THANK_YOU"},pt=function(){let e=n(this,g).location.pathname.toLowerCase();return e.includes("order-confirm")?!1:e.includes("checkout")},lt=function(){return new URLSearchParams(n(this,g).location.search)},ct=function(){let e=p(this,d,St).call(this),o=p(this,d,ut).call(this),s=this.config.basketUuid,a=e?p(this,d,dt).call(this,e,o):null;if(a&&(s!==null&&a.basketUuid===s||s===null))return a.uuid;let l=N(n(this,g).crypto);if(e&&s!==null)try{e.setItem(o,JSON.stringify({uuid:l,basketUuid:s}))}catch{}return l},ut=function(){return`${Vt}${this.config.storeIdentifier}`},dt=function(e,o){let s=e.getItem(o);if(!s)return null;try{let a=JSON.parse(s);if(typeof a?.uuid!="string")return null;let l=typeof a.basketUuid=="string"?a.basketUuid:null;return{uuid:a.uuid,basketUuid:l}}catch{return null}},St=function(){try{return n(this,g).localStorage}catch{return null}};var Z=100,P,x,M,I,z,be,F=class{constructor(e){i(this,z);i(this,P);i(this,x);i(this,M);i(this,I,null);e.explicitId!=null&&Bt(e.explicitId),r(this,P,e.explicitId??null),r(this,x,e.storageKey),r(this,M,e.window??globalThis.window)}resolve(e,o){if(n(this,P))return n(this,P);let s=p(this,z,be).call(this);if(n(this,I)===null){let a=s?qt(s,n(this,x)):null;r(this,I,a&&o(a)?a.id:N(n(this,M)?.crypto))}if(s)try{s.setItem(n(this,x),JSON.stringify({id:n(this,I),lastStep:e}))}catch{}return n(this,I)}reset(){if(n(this,P))return;r(this,I,null);let e=p(this,z,be).call(this);if(e)try{e.removeItem(n(this,x))}catch{}}};P=new WeakMap,x=new WeakMap,M=new WeakMap,I=new WeakMap,z=new WeakSet,be=function(){try{return n(this,M)?.localStorage??null}catch{return null}};var Bt=t=>{if(typeof t!="string"||t.length===0)throw new Error("datashipsSessionId must be a non-empty string");if(t.length>Z)throw new Error(`datashipsSessionId must be at most ${Z} characters`)},qt=(t,e)=>{let o;try{o=t.getItem(e)}catch{return null}if(!o)return null;try{let s=JSON.parse(o);return typeof s?.id!="string"||s.id.length===0?null:{id:s.id,lastStep:typeof s.lastStep=="string"?s.lastStep:null}}catch{return null}};var ft="CUSTOM_PLATFORM_CHECKOUT";var jt="datashipsSessionId:",Yt="default",T,ee,_,H,te,V,oe,Ae,we=class{constructor(e){i(this,oe);this.name="CustomPlatformCheckoutAdapter";this.sessionApi="consent-session";this.integrationType=ft;i(this,T);i(this,ee);i(this,_);i(this,H);i(this,te);i(this,V);if(!e||!e.collectionStep)throw new Error("CustomPlatformCheckoutAdapter: `collectionStep` is required");r(this,T,e.collectionStep),r(this,ee,C(e.locale)),r(this,_,e.isFastCheckout??!1),r(this,H,{EMAIL:e.email??null,PHONE:e.phone??null}),r(this,te,e.storageScope??Yt);try{r(this,V,new F({explicitId:e.datashipsSessionId,storageKey:`${jt}${n(this,te)}`,window:e.window}))}catch(o){throw new Error(`CustomPlatformCheckoutAdapter: ${o.message}`)}this.previewMode=e.previewMode??!1}getPreviewUpsertResponse(e="EMAIL"){return m(e)}getLocale(){return n(this,ee)}get collectionStep(){return n(this,T)}setCollectionStep(e){r(this,T,e)}get isFastCheckout(){return n(this,_)}setFastCheckout(e){r(this,_,e)}setIdentifier(e,o){n(this,H)[e]=o}getIdentifier(e){return{identifier:n(this,H)[e],identifierType:e}}getDatashipsSessionId(){return p(this,oe,Ae).call(this)}resetDatashipsSessionId(){n(this,V).reset()}async getSessionContext(){return{collectionStep:n(this,T),datashipsSessionId:p(this,oe,Ae).call(this),isFastCheckout:n(this,_)}}};T=new WeakMap,ee=new WeakMap,_=new WeakMap,H=new WeakMap,te=new WeakMap,V=new WeakMap,oe=new WeakSet,Ae=function(){let e=n(this,T);return n(this,V).resolve(e,o=>{let s=Gt(o.lastStep)?o.lastStep:"CHECKOUT_INFORMATION";return!(e==="CHECKOUT_INFORMATION"&&s!=="CHECKOUT_INFORMATION")})};var Gt=t=>t==="CHECKOUT_INFORMATION"||t==="THANK_YOU"||t==="ORDER_STATUS";var ht="CUSTOM_PLATFORM_SIGNUP";var $t="datashipsSignupSessionId:",Wt="default",q,O,j,ne,Y,ve=class{constructor(e={}){this.name="CustomPlatformSignupAdapter";this.sessionApi="consent-session";this.integrationType=ht;i(this,q);i(this,O);i(this,j,{});i(this,ne);i(this,Y);r(this,q,C(e.locale)),r(this,O,e.user??{}),r(this,ne,e.storageScope??Wt);try{r(this,Y,new F({explicitId:e.datashipsSessionId,storageKey:`${$t}${n(this,ne)}`,window:e.window}))}catch(o){throw new Error(`CustomPlatformSignupAdapter: ${o.message}`)}this.previewMode=e.previewMode??!1}getPreviewUpsertResponse(e="EMAIL"){return m(e)}getLocale(){return n(this,q)}setLocale(e){r(this,q,C(e))}setIdentifier(e,o){o===null?delete n(this,j)[e]:n(this,j)[e]=o}async getIdentifier(e){let o=n(this,j)[e];if(o!==void 0)return{identifier:B(o),identifierType:e};let s=await this.getUser(),a=e==="PHONE"?s.phone:s.email;return{identifier:B(a),identifierType:e}}async getUser(){let e=typeof n(this,O)=="function"?await n(this,O).call(this):n(this,O);return{firstName:B(e.firstName),lastName:B(e.lastName),email:B(e.email),phone:B(e.phone)}}getDatashipsSessionId(){return n(this,Y).resolve(null,()=>!0)}resetDatashipsSessionId(){n(this,Y).reset()}async getSessionContext(){return{datashipsSessionId:this.getDatashipsSessionId()}}};q=new WeakMap,O=new WeakMap,j=new WeakMap,ne=new WeakMap,Y=new WeakMap;var B=t=>{let e=t?.trim();return e||null};var Jt="2.0.0";return Et(Xt);})();
6
+ //# sourceMappingURL=dataships.min.js.map