@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.
- package/LICENSE +202 -0
- package/README.md +327 -2
- package/dist/adapters/custom-platform-checkout/index.d.ts +139 -0
- package/dist/adapters/custom-platform-checkout/index.js +304 -0
- package/dist/adapters/custom-platform-checkout/index.js.map +1 -0
- package/dist/adapters/custom-platform-signup/index.d.ts +119 -0
- package/dist/adapters/custom-platform-signup/index.js +288 -0
- package/dist/adapters/custom-platform-signup/index.js.map +1 -0
- package/dist/adapters/salesforce/index.d.ts +100 -0
- package/dist/adapters/salesforce/index.js +278 -0
- package/dist/adapters/salesforce/index.js.map +1 -0
- package/dist/adapters/shopify-checkout/index.d.ts +102 -0
- package/dist/adapters/shopify-checkout/index.js +178 -0
- package/dist/adapters/shopify-checkout/index.js.map +1 -0
- package/dist/beacon-B8v41O8P.d.ts +4 -0
- package/dist/dataships.min.js +6 -0
- package/dist/dataships.min.js.map +1 -0
- package/dist/index.d.ts +185 -0
- package/dist/index.js +713 -0
- package/dist/index.js.map +1 -0
- package/dist/integrity.json +9 -0
- package/dist/locale-DwOMogGu.d.ts +9 -0
- package/dist/retry--aRf_ryF.d.ts +130 -0
- package/dist/server.d.ts +72 -0
- package/dist/server.js +455 -0
- package/dist/server.js.map +1 -0
- package/dist/types-Bfm_pCq7.d.ts +233 -0
- package/package.json +83 -4
|
@@ -0,0 +1,288 @@
|
|
|
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 fakeEmailUpsertResponse = {
|
|
12
|
+
consentSessionId: "01HQB3QRZVV0737R0R25BTQBGF",
|
|
13
|
+
consents: [
|
|
14
|
+
{
|
|
15
|
+
channel: "EMAIL",
|
|
16
|
+
consentType: "OPT_IN",
|
|
17
|
+
checked: false,
|
|
18
|
+
widgetConfig: {
|
|
19
|
+
text: "Subscribe to our newsletter for exclusive offers and updates.",
|
|
20
|
+
consentDescription: "Click here for an overview of how your personal data is processed for marketing purposes or see our Privacy Policy for further information.",
|
|
21
|
+
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',
|
|
22
|
+
policyURL: "https://dataships.io/privacy-centre",
|
|
23
|
+
mobileTermsOfServiceURL: null,
|
|
24
|
+
privacyEmail: "privacy@example.com",
|
|
25
|
+
placeholderValues: null
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
userVerificationRequired: null,
|
|
30
|
+
lastHeartbeat: "2026-06-17T00:00:00Z",
|
|
31
|
+
identifier: null
|
|
32
|
+
};
|
|
33
|
+
var fakePhoneUpsertResponse = {
|
|
34
|
+
consentSessionId: "01HQB3QRZVV0737R0R25BTQBGG",
|
|
35
|
+
consents: [
|
|
36
|
+
{
|
|
37
|
+
channel: "SMS",
|
|
38
|
+
consentType: "OPT_IN",
|
|
39
|
+
checked: false,
|
|
40
|
+
widgetConfig: {
|
|
41
|
+
text: "Text me with news and exclusive offers. Msg & data rates may apply. Reply STOP to unsubscribe.",
|
|
42
|
+
consentDescription: "Click here for an overview of how your personal data is processed for marketing purposes or see our Privacy Policy for further information.",
|
|
43
|
+
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',
|
|
44
|
+
policyURL: "https://dataships.io/privacy-centre",
|
|
45
|
+
mobileTermsOfServiceURL: "https://dataships.io/mobile-terms",
|
|
46
|
+
privacyEmail: "privacy@example.com",
|
|
47
|
+
placeholderValues: null
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
userVerificationRequired: false,
|
|
52
|
+
lastHeartbeat: "2026-06-17T00:00:00Z",
|
|
53
|
+
identifier: null
|
|
54
|
+
};
|
|
55
|
+
var previewUpsertResponse = (identifierType) => identifierType === "PHONE" ? fakePhoneUpsertResponse : fakeEmailUpsertResponse;
|
|
56
|
+
|
|
57
|
+
// src/utils/uuid.ts
|
|
58
|
+
var randomUuid = (cryptoObj = globalThis.crypto) => {
|
|
59
|
+
if (cryptoObj && typeof cryptoObj.randomUUID === "function") {
|
|
60
|
+
return cryptoObj.randomUUID();
|
|
61
|
+
}
|
|
62
|
+
const bytes = new Uint8Array(16);
|
|
63
|
+
if (cryptoObj && typeof cryptoObj.getRandomValues === "function") {
|
|
64
|
+
cryptoObj.getRandomValues(bytes);
|
|
65
|
+
} else {
|
|
66
|
+
for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
67
|
+
}
|
|
68
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
69
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
70
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
71
|
+
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("");
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// src/adapters/beacon.ts
|
|
75
|
+
var DATASHIPS_SESSION_ID_MAX_LENGTH = 100;
|
|
76
|
+
var _explicitId, _storageKey, _window, _id, _SessionBeacon_instances, safeStorage_fn;
|
|
77
|
+
var SessionBeacon = class {
|
|
78
|
+
constructor(opts) {
|
|
79
|
+
__privateAdd(this, _SessionBeacon_instances);
|
|
80
|
+
__privateAdd(this, _explicitId);
|
|
81
|
+
__privateAdd(this, _storageKey);
|
|
82
|
+
__privateAdd(this, _window);
|
|
83
|
+
__privateAdd(this, _id, null);
|
|
84
|
+
if (opts.explicitId != null) assertSessionId(opts.explicitId);
|
|
85
|
+
__privateSet(this, _explicitId, opts.explicitId ?? null);
|
|
86
|
+
__privateSet(this, _storageKey, opts.storageKey);
|
|
87
|
+
__privateSet(this, _window, opts.window ?? globalThis.window);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The beacon for this page. On first use a stored id is reused when
|
|
91
|
+
* `reusable(stored)` says so, otherwise a fresh UUID is minted; the record is
|
|
92
|
+
* rewritten with `step` every time so the next page knows where it was last
|
|
93
|
+
* used. Later calls return the same id for the adapter's lifetime.
|
|
94
|
+
*/
|
|
95
|
+
resolve(step, reusable) {
|
|
96
|
+
if (__privateGet(this, _explicitId)) return __privateGet(this, _explicitId);
|
|
97
|
+
const storage = __privateMethod(this, _SessionBeacon_instances, safeStorage_fn).call(this);
|
|
98
|
+
if (null === __privateGet(this, _id)) {
|
|
99
|
+
const stored = storage ? readStored(storage, __privateGet(this, _storageKey)) : null;
|
|
100
|
+
__privateSet(this, _id, stored && reusable(stored) ? stored.id : randomUuid(__privateGet(this, _window)?.crypto));
|
|
101
|
+
}
|
|
102
|
+
if (storage) {
|
|
103
|
+
try {
|
|
104
|
+
storage.setItem(__privateGet(this, _storageKey), JSON.stringify({ id: __privateGet(this, _id), lastStep: step }));
|
|
105
|
+
} catch {
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return __privateGet(this, _id);
|
|
109
|
+
}
|
|
110
|
+
/** Discard the beacon so the next {@link resolve} mints a fresh one. No-op for an integrator-owned id. */
|
|
111
|
+
reset() {
|
|
112
|
+
if (__privateGet(this, _explicitId)) return;
|
|
113
|
+
__privateSet(this, _id, null);
|
|
114
|
+
const storage = __privateMethod(this, _SessionBeacon_instances, safeStorage_fn).call(this);
|
|
115
|
+
if (!storage) return;
|
|
116
|
+
try {
|
|
117
|
+
storage.removeItem(__privateGet(this, _storageKey));
|
|
118
|
+
} catch {
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
_explicitId = new WeakMap();
|
|
123
|
+
_storageKey = new WeakMap();
|
|
124
|
+
_window = new WeakMap();
|
|
125
|
+
_id = new WeakMap();
|
|
126
|
+
_SessionBeacon_instances = new WeakSet();
|
|
127
|
+
safeStorage_fn = function() {
|
|
128
|
+
try {
|
|
129
|
+
return __privateGet(this, _window)?.localStorage ?? null;
|
|
130
|
+
} catch {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
var assertSessionId = (id) => {
|
|
135
|
+
if (typeof id !== "string" || id.length === 0) {
|
|
136
|
+
throw new Error("datashipsSessionId must be a non-empty string");
|
|
137
|
+
}
|
|
138
|
+
if (id.length > DATASHIPS_SESSION_ID_MAX_LENGTH) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
`datashipsSessionId must be at most ${DATASHIPS_SESSION_ID_MAX_LENGTH} characters`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
var readStored = (storage, key) => {
|
|
145
|
+
let raw;
|
|
146
|
+
try {
|
|
147
|
+
raw = storage.getItem(key);
|
|
148
|
+
} catch {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
if (!raw) return null;
|
|
152
|
+
try {
|
|
153
|
+
const parsed = JSON.parse(raw);
|
|
154
|
+
if (typeof parsed?.id !== "string" || parsed.id.length === 0) return null;
|
|
155
|
+
return { id: parsed.id, lastStep: typeof parsed.lastStep === "string" ? parsed.lastStep : null };
|
|
156
|
+
} catch {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// src/types.ts
|
|
162
|
+
var SUPPORTED_LOCALES = [
|
|
163
|
+
"en",
|
|
164
|
+
"es",
|
|
165
|
+
"de",
|
|
166
|
+
"pt",
|
|
167
|
+
"ro",
|
|
168
|
+
"hr",
|
|
169
|
+
"da",
|
|
170
|
+
"fi",
|
|
171
|
+
"fr",
|
|
172
|
+
"hu",
|
|
173
|
+
"it",
|
|
174
|
+
"nb",
|
|
175
|
+
"pl",
|
|
176
|
+
"sk",
|
|
177
|
+
"sv",
|
|
178
|
+
"nl",
|
|
179
|
+
"el",
|
|
180
|
+
"cs",
|
|
181
|
+
"zh",
|
|
182
|
+
"ja",
|
|
183
|
+
"is"
|
|
184
|
+
];
|
|
185
|
+
|
|
186
|
+
// src/adapters/locale.ts
|
|
187
|
+
var coerceLocale = (raw) => {
|
|
188
|
+
if (!raw) return "en";
|
|
189
|
+
const head = raw.split(/[_-]/)[0]?.toLowerCase() ?? "";
|
|
190
|
+
return SUPPORTED_LOCALES.includes(head) ? head : "en";
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// src/adapters/custom-platform-signup/index.ts
|
|
194
|
+
var CUSTOM_PLATFORM_SIGNUP_INTEGRATION_TYPE = "CUSTOM_PLATFORM_SIGNUP";
|
|
195
|
+
var STORAGE_KEY_PREFIX = "datashipsSignupSessionId:";
|
|
196
|
+
var DEFAULT_STORAGE_SCOPE = "default";
|
|
197
|
+
var _locale, _user, _identifiers, _storageScope, _beacon;
|
|
198
|
+
var CustomPlatformSignupAdapter = class {
|
|
199
|
+
constructor(opts = {}) {
|
|
200
|
+
this.name = "CustomPlatformSignupAdapter";
|
|
201
|
+
this.sessionApi = "consent-session";
|
|
202
|
+
this.integrationType = CUSTOM_PLATFORM_SIGNUP_INTEGRATION_TYPE;
|
|
203
|
+
__privateAdd(this, _locale);
|
|
204
|
+
__privateAdd(this, _user);
|
|
205
|
+
__privateAdd(this, _identifiers, {});
|
|
206
|
+
__privateAdd(this, _storageScope);
|
|
207
|
+
__privateAdd(this, _beacon);
|
|
208
|
+
__privateSet(this, _locale, coerceLocale(opts.locale));
|
|
209
|
+
__privateSet(this, _user, opts.user ?? {});
|
|
210
|
+
__privateSet(this, _storageScope, opts.storageScope ?? DEFAULT_STORAGE_SCOPE);
|
|
211
|
+
try {
|
|
212
|
+
__privateSet(this, _beacon, new SessionBeacon({
|
|
213
|
+
explicitId: opts.datashipsSessionId,
|
|
214
|
+
storageKey: `${STORAGE_KEY_PREFIX}${__privateGet(this, _storageScope)}`,
|
|
215
|
+
window: opts.window
|
|
216
|
+
}));
|
|
217
|
+
} catch (e) {
|
|
218
|
+
throw new Error(`CustomPlatformSignupAdapter: ${e.message}`);
|
|
219
|
+
}
|
|
220
|
+
this.previewMode = opts.previewMode ?? false;
|
|
221
|
+
}
|
|
222
|
+
/** Synthetic upsert response served in {@link previewMode}, matching the requested identifier type. */
|
|
223
|
+
getPreviewUpsertResponse(identifierType = "EMAIL") {
|
|
224
|
+
return previewUpsertResponse(identifierType);
|
|
225
|
+
}
|
|
226
|
+
getLocale() {
|
|
227
|
+
return __privateGet(this, _locale);
|
|
228
|
+
}
|
|
229
|
+
/** Change the envelope locale, e.g. when the visitor switches language on the form. */
|
|
230
|
+
setLocale(locale) {
|
|
231
|
+
__privateSet(this, _locale, coerceLocale(locale));
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Remember an identifier the visitor typed so later calls resolve it without
|
|
235
|
+
* the user resolver. Pass null to fall back to the resolver again. An
|
|
236
|
+
* explicit `upsertSession({ identifier })` still takes precedence.
|
|
237
|
+
*/
|
|
238
|
+
setIdentifier(identifierType, value) {
|
|
239
|
+
if (value === null) delete __privateGet(this, _identifiers)[identifierType];
|
|
240
|
+
else __privateGet(this, _identifiers)[identifierType] = value;
|
|
241
|
+
}
|
|
242
|
+
async getIdentifier(identifierType) {
|
|
243
|
+
const pinned = __privateGet(this, _identifiers)[identifierType];
|
|
244
|
+
if (pinned !== void 0) return { identifier: normalise(pinned), identifierType };
|
|
245
|
+
const user = await this.getUser();
|
|
246
|
+
const identifier = "PHONE" === identifierType ? user.phone : user.email;
|
|
247
|
+
return { identifier: normalise(identifier), identifierType };
|
|
248
|
+
}
|
|
249
|
+
/** The user as the merchant's form or backend knows them right now, names and contacts trimmed. */
|
|
250
|
+
async getUser() {
|
|
251
|
+
const raw = typeof __privateGet(this, _user) === "function" ? await __privateGet(this, _user).call(this) : __privateGet(this, _user);
|
|
252
|
+
return {
|
|
253
|
+
firstName: normalise(raw.firstName),
|
|
254
|
+
lastName: normalise(raw.lastName),
|
|
255
|
+
email: normalise(raw.email),
|
|
256
|
+
phone: normalise(raw.phone)
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
/** The beacon this form fill is known by; resolved (and persisted) on first use. */
|
|
260
|
+
getDatashipsSessionId() {
|
|
261
|
+
return __privateGet(this, _beacon).resolve(null, () => true);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Discard the current beacon so the next call mints a fresh one. Call it once
|
|
265
|
+
* the form has been submitted, so a second signup on this browser opens a new
|
|
266
|
+
* session instead of touching the completed one. No-op for an
|
|
267
|
+
* integrator-owned id.
|
|
268
|
+
*/
|
|
269
|
+
resetDatashipsSessionId() {
|
|
270
|
+
__privateGet(this, _beacon).reset();
|
|
271
|
+
}
|
|
272
|
+
async getSessionContext() {
|
|
273
|
+
return { datashipsSessionId: this.getDatashipsSessionId() };
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
_locale = new WeakMap();
|
|
277
|
+
_user = new WeakMap();
|
|
278
|
+
_identifiers = new WeakMap();
|
|
279
|
+
_storageScope = new WeakMap();
|
|
280
|
+
_beacon = new WeakMap();
|
|
281
|
+
var normalise = (value) => {
|
|
282
|
+
const trimmed = value?.trim();
|
|
283
|
+
return trimmed ? trimmed : null;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
export { CUSTOM_PLATFORM_SIGNUP_INTEGRATION_TYPE, CustomPlatformSignupAdapter, DATASHIPS_SESSION_ID_MAX_LENGTH, coerceLocale };
|
|
287
|
+
//# sourceMappingURL=index.js.map
|
|
288
|
+
//# 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":";;;;;;;;;;AAYO,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,+DAAA;AAAA,QACN,kBAAA,EACE,6IAAA;AAAA,QACF,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;AACd,CAAA;AAQO,IAAM,uBAAA,GAAiD;AAAA,EAC5D,gBAAA,EAAkB,4BAAA;AAAA,EAClB,QAAA,EAAU;AAAA,IACR;AAAA,MACE,OAAA,EAAS,KAAA;AAAA,MACT,WAAA,EAAa,QAAA;AAAA,MACb,OAAA,EAAS,KAAA;AAAA,MACT,YAAA,EAAc;AAAA,QACZ,IAAA,EAAM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AAA,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;AApFE,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;AAmFX,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, U as UpsertSessionResponse, a as ConsentSessionIdentifier } from '../../types-Bfm_pCq7.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): 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 };
|