@dataships/sdk 0.0.0-stage → 2.0.1

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,338 @@
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/session/previewUpsertResponse.ts
11
+ var DEFAULT_EMAIL_OPT_IN_TEXT = "We would like to email you news and promotions. Tick to opt in.";
12
+ 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.";
13
+ var DEFAULT_SMS_OPT_IN_TEXT = "We would like to text you news and promotions. Tick to opt in.";
14
+ 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.";
15
+ var fakeEmailUpsertResponse = {
16
+ consentSessionId: "01HQB3QRZVV0737R0R25BTQBGF",
17
+ consents: [
18
+ {
19
+ channel: "EMAIL",
20
+ consentType: "OPT_IN",
21
+ checked: false,
22
+ widgetConfig: {
23
+ text: DEFAULT_EMAIL_OPT_IN_TEXT,
24
+ consentDescription: DEFAULT_EMAIL_OPT_IN_CONSENT_DESCRIPTION,
25
+ 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',
26
+ policyURL: "https://dataships.io/privacy-centre",
27
+ mobileTermsOfServiceURL: null,
28
+ privacyEmail: "privacy@example.com",
29
+ placeholderValues: null
30
+ }
31
+ }
32
+ ],
33
+ userVerificationRequired: null,
34
+ lastHeartbeat: "2026-06-17T00:00:00Z",
35
+ identifier: null
36
+ };
37
+ var fakePhoneUpsertResponse = {
38
+ consentSessionId: "01HQB3QRZVV0737R0R25BTQBGG",
39
+ consents: [
40
+ {
41
+ channel: "SMS",
42
+ consentType: "OPT_IN",
43
+ checked: false,
44
+ widgetConfig: {
45
+ text: DEFAULT_SMS_OPT_IN_TEXT,
46
+ consentDescription: DEFAULT_SMS_OPT_IN_CONSENT_DESCRIPTION,
47
+ 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',
48
+ policyURL: "https://dataships.io/privacy-centre",
49
+ mobileTermsOfServiceURL: "https://dataships.io/mobile-terms",
50
+ privacyEmail: "privacy@example.com",
51
+ placeholderValues: null
52
+ }
53
+ }
54
+ ],
55
+ userVerificationRequired: false,
56
+ lastHeartbeat: "2026-06-17T00:00:00Z",
57
+ identifier: null
58
+ };
59
+ var MARKETING_MODAL_HREF = "#dataships-marketing-modal";
60
+ var CHECKBOX_LABEL_BOLD_PHRASES = ["consent", "object", "opt in", "opt out", "STOP", "HELP"];
61
+ var CONSENT_DESCRIPTION_BOLD_PHRASES = ["STOP", "HELP"];
62
+ var escapeHtml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
63
+ var escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
64
+ var wrapPhrase = (html, phrase, wrap) => html.replace(
65
+ new RegExp(`${escapeRegExp(escapeHtml(phrase))}(?![^<]*>)(?![^<]*</a>)`, "gi"),
66
+ wrap
67
+ );
68
+ var toHtmlCopy = (text, widgetConfig, boldPhrases) => {
69
+ let html = escapeHtml(text);
70
+ const links = [
71
+ ["Terms of Service", widgetConfig.mobileTermsOfServiceURL],
72
+ ["Privacy Policy", widgetConfig.policyURL],
73
+ ["Click here", MARKETING_MODAL_HREF]
74
+ ];
75
+ for (const [phrase, href] of links) {
76
+ if (!href) continue;
77
+ html = wrapPhrase(html, phrase, (match) => `<a href="${escapeHtml(href)}">${match}</a>`);
78
+ }
79
+ for (const phrase of boldPhrases) {
80
+ html = wrapPhrase(html, phrase, (match) => `<strong>${match}</strong>`);
81
+ }
82
+ return `<p>${html}</p>`;
83
+ };
84
+ var withHtmlCopy = (response) => ({
85
+ ...response,
86
+ consents: response.consents.map((consent) => {
87
+ const { widgetConfig } = consent;
88
+ return {
89
+ ...consent,
90
+ widgetConfig: {
91
+ ...widgetConfig,
92
+ text: widgetConfig.text === null ? null : toHtmlCopy(widgetConfig.text, widgetConfig, CHECKBOX_LABEL_BOLD_PHRASES),
93
+ consentDescription: widgetConfig.consentDescription === null ? null : toHtmlCopy(
94
+ widgetConfig.consentDescription,
95
+ widgetConfig,
96
+ CONSENT_DESCRIPTION_BOLD_PHRASES
97
+ )
98
+ }
99
+ };
100
+ })
101
+ });
102
+ var previewUpsertResponse = (identifierType, format = "json") => {
103
+ const response = identifierType === "PHONE" ? fakePhoneUpsertResponse : fakeEmailUpsertResponse;
104
+ return format === "html" ? withHtmlCopy(response) : response;
105
+ };
106
+
107
+ // src/utils/uuid.ts
108
+ var randomUuid = (cryptoObj = globalThis.crypto) => {
109
+ if (cryptoObj && typeof cryptoObj.randomUUID === "function") {
110
+ return cryptoObj.randomUUID();
111
+ }
112
+ const bytes = new Uint8Array(16);
113
+ if (cryptoObj && typeof cryptoObj.getRandomValues === "function") {
114
+ cryptoObj.getRandomValues(bytes);
115
+ } else {
116
+ for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256);
117
+ }
118
+ bytes[6] = bytes[6] & 15 | 64;
119
+ bytes[8] = bytes[8] & 63 | 128;
120
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
121
+ 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("");
122
+ };
123
+
124
+ // src/adapters/beacon.ts
125
+ var DATASHIPS_SESSION_ID_MAX_LENGTH = 100;
126
+ var _explicitId, _storageKey, _window, _id, _SessionBeacon_instances, safeStorage_fn;
127
+ var SessionBeacon = class {
128
+ constructor(opts) {
129
+ __privateAdd(this, _SessionBeacon_instances);
130
+ __privateAdd(this, _explicitId);
131
+ __privateAdd(this, _storageKey);
132
+ __privateAdd(this, _window);
133
+ __privateAdd(this, _id, null);
134
+ if (opts.explicitId != null) assertSessionId(opts.explicitId);
135
+ __privateSet(this, _explicitId, opts.explicitId ?? null);
136
+ __privateSet(this, _storageKey, opts.storageKey);
137
+ __privateSet(this, _window, opts.window ?? globalThis.window);
138
+ }
139
+ /**
140
+ * The beacon for this page. On first use a stored id is reused when
141
+ * `reusable(stored)` says so, otherwise a fresh UUID is minted; the record is
142
+ * rewritten with `step` every time so the next page knows where it was last
143
+ * used. Later calls return the same id for the adapter's lifetime.
144
+ */
145
+ resolve(step, reusable) {
146
+ if (__privateGet(this, _explicitId)) return __privateGet(this, _explicitId);
147
+ const storage = __privateMethod(this, _SessionBeacon_instances, safeStorage_fn).call(this);
148
+ if (null === __privateGet(this, _id)) {
149
+ const stored = storage ? readStored(storage, __privateGet(this, _storageKey)) : null;
150
+ __privateSet(this, _id, stored && reusable(stored) ? stored.id : randomUuid(__privateGet(this, _window)?.crypto));
151
+ }
152
+ if (storage) {
153
+ try {
154
+ storage.setItem(__privateGet(this, _storageKey), JSON.stringify({ id: __privateGet(this, _id), lastStep: step }));
155
+ } catch {
156
+ }
157
+ }
158
+ return __privateGet(this, _id);
159
+ }
160
+ /** Discard the beacon so the next {@link resolve} mints a fresh one. No-op for an integrator-owned id. */
161
+ reset() {
162
+ if (__privateGet(this, _explicitId)) return;
163
+ __privateSet(this, _id, null);
164
+ const storage = __privateMethod(this, _SessionBeacon_instances, safeStorage_fn).call(this);
165
+ if (!storage) return;
166
+ try {
167
+ storage.removeItem(__privateGet(this, _storageKey));
168
+ } catch {
169
+ }
170
+ }
171
+ };
172
+ _explicitId = new WeakMap();
173
+ _storageKey = new WeakMap();
174
+ _window = new WeakMap();
175
+ _id = new WeakMap();
176
+ _SessionBeacon_instances = new WeakSet();
177
+ safeStorage_fn = function() {
178
+ try {
179
+ return __privateGet(this, _window)?.localStorage ?? null;
180
+ } catch {
181
+ return null;
182
+ }
183
+ };
184
+ var assertSessionId = (id) => {
185
+ if (typeof id !== "string" || id.length === 0) {
186
+ throw new Error("datashipsSessionId must be a non-empty string");
187
+ }
188
+ if (id.length > DATASHIPS_SESSION_ID_MAX_LENGTH) {
189
+ throw new Error(
190
+ `datashipsSessionId must be at most ${DATASHIPS_SESSION_ID_MAX_LENGTH} characters`
191
+ );
192
+ }
193
+ };
194
+ var readStored = (storage, key) => {
195
+ let raw;
196
+ try {
197
+ raw = storage.getItem(key);
198
+ } catch {
199
+ return null;
200
+ }
201
+ if (!raw) return null;
202
+ try {
203
+ const parsed = JSON.parse(raw);
204
+ if (typeof parsed?.id !== "string" || parsed.id.length === 0) return null;
205
+ return { id: parsed.id, lastStep: typeof parsed.lastStep === "string" ? parsed.lastStep : null };
206
+ } catch {
207
+ return null;
208
+ }
209
+ };
210
+
211
+ // src/types.ts
212
+ var SUPPORTED_LOCALES = [
213
+ "en",
214
+ "es",
215
+ "de",
216
+ "pt",
217
+ "ro",
218
+ "hr",
219
+ "da",
220
+ "fi",
221
+ "fr",
222
+ "hu",
223
+ "it",
224
+ "nb",
225
+ "pl",
226
+ "sk",
227
+ "sv",
228
+ "nl",
229
+ "el",
230
+ "cs",
231
+ "zh",
232
+ "ja",
233
+ "is"
234
+ ];
235
+
236
+ // src/adapters/locale.ts
237
+ var coerceLocale = (raw) => {
238
+ if (!raw) return "en";
239
+ const head = raw.split(/[_-]/)[0]?.toLowerCase() ?? "";
240
+ return SUPPORTED_LOCALES.includes(head) ? head : "en";
241
+ };
242
+
243
+ // src/adapters/custom-platform-signup/index.ts
244
+ var CUSTOM_PLATFORM_SIGNUP_INTEGRATION_TYPE = "CUSTOM_PLATFORM_SIGNUP";
245
+ var STORAGE_KEY_PREFIX = "datashipsSignupSessionId:";
246
+ var DEFAULT_STORAGE_SCOPE = "default";
247
+ var _locale, _user, _identifiers, _storageScope, _beacon;
248
+ var CustomPlatformSignupAdapter = class {
249
+ constructor(opts = {}) {
250
+ this.name = "CustomPlatformSignupAdapter";
251
+ this.sessionApi = "consent-session";
252
+ this.integrationType = CUSTOM_PLATFORM_SIGNUP_INTEGRATION_TYPE;
253
+ __privateAdd(this, _locale);
254
+ __privateAdd(this, _user);
255
+ __privateAdd(this, _identifiers, {});
256
+ __privateAdd(this, _storageScope);
257
+ __privateAdd(this, _beacon);
258
+ __privateSet(this, _locale, coerceLocale(opts.locale));
259
+ __privateSet(this, _user, opts.user ?? {});
260
+ __privateSet(this, _storageScope, opts.storageScope ?? DEFAULT_STORAGE_SCOPE);
261
+ try {
262
+ __privateSet(this, _beacon, new SessionBeacon({
263
+ explicitId: opts.datashipsSessionId,
264
+ storageKey: `${STORAGE_KEY_PREFIX}${__privateGet(this, _storageScope)}`,
265
+ window: opts.window
266
+ }));
267
+ } catch (e) {
268
+ throw new Error(`CustomPlatformSignupAdapter: ${e.message}`);
269
+ }
270
+ this.previewMode = opts.previewMode ?? false;
271
+ }
272
+ /** Synthetic upsert response served in {@link previewMode}, matching the requested identifier type. */
273
+ getPreviewUpsertResponse(identifierType = "EMAIL", format) {
274
+ return previewUpsertResponse(identifierType, format);
275
+ }
276
+ getLocale() {
277
+ return __privateGet(this, _locale);
278
+ }
279
+ /** Change the envelope locale, e.g. when the visitor switches language on the form. */
280
+ setLocale(locale) {
281
+ __privateSet(this, _locale, coerceLocale(locale));
282
+ }
283
+ /**
284
+ * Remember an identifier the visitor typed so later calls resolve it without
285
+ * the user resolver. Pass null to fall back to the resolver again. An
286
+ * explicit `upsertSession({ identifier })` still takes precedence.
287
+ */
288
+ setIdentifier(identifierType, value) {
289
+ if (value === null) delete __privateGet(this, _identifiers)[identifierType];
290
+ else __privateGet(this, _identifiers)[identifierType] = value;
291
+ }
292
+ async getIdentifier(identifierType) {
293
+ const pinned = __privateGet(this, _identifiers)[identifierType];
294
+ if (pinned !== void 0) return { identifier: normalise(pinned), identifierType };
295
+ const user = await this.getUser();
296
+ const identifier = "PHONE" === identifierType ? user.phone : user.email;
297
+ return { identifier: normalise(identifier), identifierType };
298
+ }
299
+ /** The user as the merchant's form or backend knows them right now, names and contacts trimmed. */
300
+ async getUser() {
301
+ const raw = typeof __privateGet(this, _user) === "function" ? await __privateGet(this, _user).call(this) : __privateGet(this, _user);
302
+ return {
303
+ firstName: normalise(raw.firstName),
304
+ lastName: normalise(raw.lastName),
305
+ email: normalise(raw.email),
306
+ phone: normalise(raw.phone)
307
+ };
308
+ }
309
+ /** The beacon this form fill is known by; resolved (and persisted) on first use. */
310
+ getDatashipsSessionId() {
311
+ return __privateGet(this, _beacon).resolve(null, () => true);
312
+ }
313
+ /**
314
+ * Discard the current beacon so the next call mints a fresh one. Call it once
315
+ * the form has been submitted, so a second signup on this browser opens a new
316
+ * session instead of touching the completed one. No-op for an
317
+ * integrator-owned id.
318
+ */
319
+ resetDatashipsSessionId() {
320
+ __privateGet(this, _beacon).reset();
321
+ }
322
+ async getSessionContext() {
323
+ return { datashipsSessionId: this.getDatashipsSessionId() };
324
+ }
325
+ };
326
+ _locale = new WeakMap();
327
+ _user = new WeakMap();
328
+ _identifiers = new WeakMap();
329
+ _storageScope = new WeakMap();
330
+ _beacon = new WeakMap();
331
+ var normalise = (value) => {
332
+ const trimmed = value?.trim();
333
+ return trimmed ? trimmed : null;
334
+ };
335
+
336
+ export { CUSTOM_PLATFORM_SIGNUP_INTEGRATION_TYPE, CustomPlatformSignupAdapter, DATASHIPS_SESSION_ID_MAX_LENGTH, coerceLocale };
337
+ //# sourceMappingURL=index.js.map
338
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/session/previewUpsertResponse.ts","../../../src/utils/uuid.ts","../../../src/adapters/beacon.ts","../../../src/types.ts","../../../src/adapters/locale.ts","../../../src/adapters/custom-platform-signup/index.ts"],"names":[],"mappings":";;;;;;;;;;AAeA,IAAM,yBAAA,GACJ,iEAAA;AACF,IAAM,wCAAA,GACJ,6IAAA;AACF,IAAM,uBAAA,GACJ,gEAAA;AACF,IAAM,sCAAA,GACJ,yiBAAA;AAaK,IAAM,uBAAA,GAAiD;AAAA,EAC5D,gBAAA,EAAkB,4BAAA;AAAA,EAClB,QAAA,EAAU;AAAA,IACR;AAAA,MACE,OAAA,EAAS,OAAA;AAAA,MACT,WAAA,EAAa,QAAA;AAAA,MACb,OAAA,EAAS,KAAA;AAAA,MACT,YAAA,EAAc;AAAA,QACZ,IAAA,EAAM,yBAAA;AAAA,QACN,kBAAA,EAAoB,wCAAA;AAAA,QACpB,oBAAA,EACE,kWAAA;AAAA,QACF,SAAA,EAAW,qCAAA;AAAA,QACX,uBAAA,EAAyB,IAAA;AAAA,QACzB,YAAA,EAAc,qBAAA;AAAA,QACd,iBAAA,EAAmB;AAAA;AACrB;AACF,GACF;AAAA,EACA,wBAAA,EAA0B,IAAA;AAAA,EAC1B,aAAA,EAAe,sBAAA;AAAA,EACf,UAAA,EAAY;A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AAO;AAAA,MACL,SAAA,EAAW,SAAA,CAAU,GAAA,CAAI,SAAS,CAAA;AAAA,MAClC,QAAA,EAAU,SAAA,CAAU,GAAA,CAAI,QAAQ,CAAA;AAAA,MAChC,KAAA,EAAO,SAAA,CAAU,GAAA,CAAI,KAAK,CAAA;AAAA,MAC1B,KAAA,EAAO,SAAA,CAAU,GAAA,CAAI,KAAK;AAAA,KAC5B;AAAA,EACF;AAAA;AAAA,EAGA,qBAAA,GAAgC;AAC9B,IAAA,OAAO,YAAA,CAAA,IAAA,EAAK,OAAA,CAAA,CAAQ,OAAA,CAAQ,IAAA,EAAM,MAAM,IAAI,CAAA;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,uBAAA,GAAgC;AAC9B,IAAA,YAAA,CAAA,IAAA,EAAK,SAAQ,KAAA,EAAM;AAAA,EACrB;AAAA,EAEA,MAAM,iBAAA,GAAiE;AACrE,IAAA,OAAO,EAAE,kBAAA,EAAoB,IAAA,CAAK,qBAAA,EAAsB,EAAE;AAAA,EAC5D;AACF;AAvFE,OAAA,GAAA,IAAA,OAAA,EAAA;AACA,KAAA,GAAA,IAAA,OAAA,EAAA;AACA,YAAA,GAAA,IAAA,OAAA,EAAA;AACA,aAAA,GAAA,IAAA,OAAA,EAAA;AACS,OAAA,GAAA,IAAA,OAAA,EAAA;AAsFX,IAAM,SAAA,GAAY,CAAC,KAAA,KAAoD;AACrE,EAAA,MAAM,OAAA,GAAU,OAAO,IAAA,EAAK;AAC5B,EAAA,OAAO,UAAU,OAAA,GAAU,IAAA;AAC7B,CAAA","file":"index.js"}
@@ -0,0 +1,100 @@
1
+ import { E as Environment, S as SupportedLocale, C as ConsentSessionAdapter, I as IdentifierType, a as ConsentCopyFormat, U as UpsertSessionResponse, b as ConsentSessionIdentifier } from '../../types-vPJjFMJw.js';
2
+
3
+ /**
4
+ * This represents the information sent by the ISML form the backend used in the Thank You page.
5
+ */
6
+ interface SalesforceConfig {
7
+ publicKey: string;
8
+ /**
9
+ * JWT the cartridge mints at render with the merchant's signing key
10
+ * (`{ iss: <public key>, iat, exp }`, ES256). Sent verbatim as the Bearer
11
+ * token; null only when the page rendered none (preview mode).
12
+ */
13
+ token: string | null;
14
+ env: Environment;
15
+ previewMode: boolean;
16
+ storeIdentifier: string;
17
+ locale: SupportedLocale;
18
+ basketUuid: string | null;
19
+ email: string | null;
20
+ phone: string | null;
21
+ orderId: string | null;
22
+ orderToken: string | null;
23
+ }
24
+ interface GetConfigFromScriptTagOptions {
25
+ /** Override the document for tests. */
26
+ document?: Document;
27
+ /** Override the selector used to locate the Dataships script tag. */
28
+ scriptSelector?: string;
29
+ }
30
+ /**
31
+ * Locate the Dataships SFCC bundle <script> tag and read its `data-*`
32
+ * attributes into a typed config object. Throws if required attributes
33
+ * are missing — those are server-rendered by the ISML template so any
34
+ * absence indicates a misconfigured cartridge or template.
35
+ *
36
+ * Optional attributes (`data-basket-uuid`, `data-email`, `data-phone`,
37
+ * `data-order-id`, `data-order-token`) may be empty on certain pages or for
38
+ * guest shoppers; they normalise to `null`. The two order-* attributes are
39
+ * server-rendered from `pdict.order` on confirmation pages and are the
40
+ * canonical source for the placed order's identifiers — SFRA's Order-Confirm
41
+ * URL does not reliably expose them as query params.
42
+ *
43
+ * `data-public-key` and `data-token` are the merchant credentials: the public
44
+ * key travels as `X-Api-Key`, the token as `Authorization: Bearer`.
45
+ * `data-store-identifier` (the SFCC `site@instance` value) is kept for
46
+ * telemetry only. `data-locale` is an SFCC
47
+ * locale string like `en_US`; the first segment is returned when it maps to a
48
+ * `SupportedLocale`, otherwise `"en"`.
49
+ */
50
+ declare const getConfigFromScriptTag: (opts?: GetConfigFromScriptTagOptions) => SalesforceConfig;
51
+
52
+ type SalesforceCollectionStep = "CHECKOUT_INFORMATION" | "THANK_YOU";
53
+ /**
54
+ * Integration-specific fields the Salesforce adapter contributes to the
55
+ * consent-session envelope, merged under `integration`. The client injects
56
+ * `type`; the identifier and `locale` travel at the top level; the merchant is
57
+ * identified by the `X-Api-Key` header.
58
+ */
59
+ interface SalesforceSessionContext {
60
+ collectionStep: SalesforceCollectionStep;
61
+ datashipsOrderUuid: string;
62
+ basketUuid: string | null;
63
+ orderId: string | null;
64
+ orderToken: string | null;
65
+ }
66
+
67
+ interface SalesforceAdapterOptions {
68
+ /**
69
+ * Pre-resolved config. If omitted, the adapter will call
70
+ * `getConfigFromScriptTag()` on construction.
71
+ */
72
+ config?: SalesforceConfig;
73
+ /** Override the window for tests. Defaults to `globalThis.window`. */
74
+ window?: Window;
75
+ /** Override the document for tests when resolving config from the script tag. */
76
+ document?: Document;
77
+ }
78
+ declare class SalesforceAdapter implements ConsentSessionAdapter<SalesforceSessionContext> {
79
+ #private;
80
+ readonly name: string;
81
+ readonly sessionApi: "consent-session";
82
+ readonly integrationType = "SALESFORCE_SNIPPET";
83
+ readonly config: SalesforceConfig;
84
+ /**
85
+ * When true we never call the API; instead we serve fake email data so
86
+ * merchants can style the snippet without a backend. Driven by the
87
+ * `data-preview-mode` site preference (a Salesforce toggle), independent of
88
+ * {@link SalesforceConfig.env}: with preview mode off, every env makes live
89
+ * calls (non-production envs to the client's explicit `baseUrl`).
90
+ */
91
+ readonly previewMode: boolean;
92
+ constructor(opts?: SalesforceAdapterOptions);
93
+ /** Synthetic upsert response served in {@link previewMode}; email-only at launch. */
94
+ getPreviewUpsertResponse(identifierType?: IdentifierType, format?: ConsentCopyFormat): UpsertSessionResponse;
95
+ getLocale(): SupportedLocale;
96
+ getIdentifier(identifierType: IdentifierType): ConsentSessionIdentifier;
97
+ getSessionContext(): Promise<SalesforceSessionContext>;
98
+ }
99
+
100
+ export { type GetConfigFromScriptTagOptions, SalesforceAdapter, type SalesforceAdapterOptions, type SalesforceCollectionStep, type SalesforceConfig, type SalesforceSessionContext, getConfigFromScriptTag };