@dataships/launcher 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/integrity.json +2 -2
- package/dist/launcher.js +169 -30
- package/dist/modules/{alia-0.1.1.js → alia-0.3.0.js} +1255 -395
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// node_modules/@dataships/sdk/dist/index.js
|
|
1
|
+
// node_modules/@dataships/elements/node_modules/@dataships/sdk/dist/index.js
|
|
2
2
|
var __typeError = (msg) => {
|
|
3
3
|
throw TypeError(msg);
|
|
4
4
|
};
|
|
@@ -483,7 +483,7 @@ var DatashipsClient = class {
|
|
|
483
483
|
*
|
|
484
484
|
* `user.firstName` / `lastName` are required (the backend refuses a blank
|
|
485
485
|
* name; the SDK refuses it before sending), unless the adapter's
|
|
486
|
-
* `submitRequiresUser` is false, as on
|
|
486
|
+
* `submitRequiresUser` is false, as on the Alia form adapters: then `user` may be
|
|
487
487
|
* omitted and the submit goes without it. The beacon defaults to the
|
|
488
488
|
* adapter's own `datashipsSessionId`, which is then discarded once the
|
|
489
489
|
* submit is accepted. Idempotent on the backend; a
|
|
@@ -585,7 +585,7 @@ post_fn = async function(args) {
|
|
|
585
585
|
const staticHeaders = {
|
|
586
586
|
// The marker lets the backend tell an exposed key in a page from a genuine server call.
|
|
587
587
|
"X-Dataships-App": `${this.app} (SDK: ${this.adapter.name}${this.isUnsafeServerKey ? `; ${UNSAFE_SERVER_KEY_APP_MARKER}` : ""})`,
|
|
588
|
-
"X-Dataships-Version": `${this.version} (SDK: ${"2.
|
|
588
|
+
"X-Dataships-Version": `${this.version} (SDK: ${"2.4.0"})`
|
|
589
589
|
};
|
|
590
590
|
return postJson({
|
|
591
591
|
url: `${this.baseUrl}${args.path}`,
|
|
@@ -600,7 +600,7 @@ post_fn = async function(args) {
|
|
|
600
600
|
});
|
|
601
601
|
};
|
|
602
602
|
|
|
603
|
-
// node_modules/@dataships/sdk/dist/adapters/custom-platform-checkout/index.js
|
|
603
|
+
// node_modules/@dataships/elements/node_modules/@dataships/sdk/dist/adapters/custom-platform-checkout/index.js
|
|
604
604
|
var __typeError2 = (msg) => {
|
|
605
605
|
throw TypeError(msg);
|
|
606
606
|
};
|
|
@@ -952,7 +952,7 @@ resolveSessionId_fn = function() {
|
|
|
952
952
|
};
|
|
953
953
|
var isCollectionStep = (value) => value === "CHECKOUT_INFORMATION" || value === "THANK_YOU" || value === "ORDER_STATUS";
|
|
954
954
|
|
|
955
|
-
// node_modules/@dataships/sdk/dist/adapters/custom-platform-signup/index.js
|
|
955
|
+
// node_modules/@dataships/elements/node_modules/@dataships/sdk/dist/adapters/custom-platform-signup/index.js
|
|
956
956
|
var __typeError3 = (msg) => {
|
|
957
957
|
throw TypeError(msg);
|
|
958
958
|
};
|
|
@@ -1338,9 +1338,22 @@ var BASE_STYLES = (
|
|
|
1338
1338
|
}
|
|
1339
1339
|
.link:focus-visible { outline: 2px solid var(--ds-color-primary, #1f6feb); outline-offset: 2px; border-radius: 2px; }
|
|
1340
1340
|
|
|
1341
|
-
.text { margin: 0; }
|
|
1342
1341
|
.description { margin: 0; font-size: 0.875em; color: var(--ds-color-text-secondary, #6b7280); }
|
|
1343
1342
|
|
|
1343
|
+
/* Styled by a class of the host page (\`className\`): the copy takes what the element has. */
|
|
1344
|
+
:host([data-host-styled]) .description { font-size: var(--ds-font-size, inherit); color: var(--ds-color-text-secondary, inherit); }
|
|
1345
|
+
:host([data-host-styled]) .root .link { color: var(--ds-color-primary, inherit); }
|
|
1346
|
+
/* The modal has its own background, so it must not take the page's text styles. */
|
|
1347
|
+
:host([data-host-styled]) .modal { color: var(--ds-color-text, #111827); font-size: 1rem; text-align: start; }
|
|
1348
|
+
|
|
1349
|
+
.preview-badge {
|
|
1350
|
+
justify-self: center;
|
|
1351
|
+
margin: 0;
|
|
1352
|
+
padding: 0.15em 0.6em;
|
|
1353
|
+
font-size: var(--ds-font-size, inherit);
|
|
1354
|
+
border-radius: var(--ds-border-radius, 6px);
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1344
1357
|
.modal {
|
|
1345
1358
|
max-width: min(560px, 90vw);
|
|
1346
1359
|
padding: 0;
|
|
@@ -1362,10 +1375,10 @@ var BASE_STYLES = (
|
|
|
1362
1375
|
`
|
|
1363
1376
|
);
|
|
1364
1377
|
var WORDS = {
|
|
1365
|
-
en: { clickHere: "Click here", privacyPolicy: "Privacy Policy", consent: "consent", object: "object", optIn: "opt in", optOut: "opt out" },
|
|
1366
|
-
es: { clickHere: "Haz clic aqu\xED", privacyPolicy: "Pol\xEDtica de privacidad", consent: "consentimiento", object: "oponerte", optIn: "inscribirte", optOut: "no quieres recibirlo" },
|
|
1367
|
-
de: { clickHere: "Klicken Sie hier", privacyPolicy: "Datenschutzrichtlinie", consent: "Zustimmung", object: "protestieren", optIn: "zuzustimmen", optOut: "widersprechen" },
|
|
1368
|
-
fr: { clickHere: "Cliquez ici", privacyPolicy: "Politique de confidentialit\xE9", consent: "consentement", object: "d\xE9sapprouver", optIn: "accepter", optOut: "refuser" }
|
|
1378
|
+
en: { clickHere: "Click here", privacyPolicy: "Privacy Policy", termsOfService: "Terms of Service", consent: "consent", object: "object", optIn: "opt in", optOut: "opt out" },
|
|
1379
|
+
es: { clickHere: "Haz clic aqu\xED", privacyPolicy: "Pol\xEDtica de privacidad", termsOfService: "Condiciones del servicio", consent: "consentimiento", object: "oponerte", optIn: "inscribirte", optOut: "no quieres recibirlo" },
|
|
1380
|
+
de: { clickHere: "Klicken Sie hier", privacyPolicy: "Datenschutzrichtlinie", termsOfService: "Servicebedingungen", consent: "Zustimmung", object: "protestieren", optIn: "zuzustimmen", optOut: "widersprechen" },
|
|
1381
|
+
fr: { clickHere: "Cliquez ici", privacyPolicy: "Politique de confidentialit\xE9", termsOfService: "Conditions d'utilisation", consent: "consentement", object: "d\xE9sapprouver", optIn: "accepter", optOut: "refuser" }
|
|
1369
1382
|
};
|
|
1370
1383
|
var escapeRegExp3 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1371
1384
|
var formatCopy = (text, locale, rules) => {
|
|
@@ -1383,10 +1396,11 @@ var formatCopy = (text, locale, rules) => {
|
|
|
1383
1396
|
var ALLOWED_TAGS = /* @__PURE__ */ new Set(["H1", "H2", "H3", "P", "BR", "UL", "OL", "LI", "A", "STRONG", "B", "EM", "I"]);
|
|
1384
1397
|
var DROPPED_TAGS = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "IFRAME", "OBJECT", "EMBED", "NOSCRIPT", "SVG", "MATH", "TITLE", "TEXTAREA", "SELECT"]);
|
|
1385
1398
|
var ALLOWED_PROTOCOLS = /* @__PURE__ */ new Set(["https:", "mailto:"]);
|
|
1386
|
-
var
|
|
1399
|
+
var CONFIG_URL_PROTOCOLS = /* @__PURE__ */ new Set(["https:", "http:", "mailto:"]);
|
|
1400
|
+
var safeHref = (href, protocols = ALLOWED_PROTOCOLS) => {
|
|
1387
1401
|
if (!href) return null;
|
|
1388
1402
|
try {
|
|
1389
|
-
return
|
|
1403
|
+
return protocols.has(new URL(href.trim()).protocol) ? href.trim() : null;
|
|
1390
1404
|
} catch {
|
|
1391
1405
|
return null;
|
|
1392
1406
|
}
|
|
@@ -1467,6 +1481,7 @@ var el = (tag, { className, text, attrs = {} } = {}, children = []) => {
|
|
|
1467
1481
|
for (const c of children) node.append(c);
|
|
1468
1482
|
return node;
|
|
1469
1483
|
};
|
|
1484
|
+
var PREVIEW_BADGE = "Preview \xB7 nothing is recorded";
|
|
1470
1485
|
var _shadow;
|
|
1471
1486
|
var _root;
|
|
1472
1487
|
var _onConsentChange;
|
|
@@ -1507,21 +1522,20 @@ _shadow = /* @__PURE__ */ new WeakMap();
|
|
|
1507
1522
|
_root = /* @__PURE__ */ new WeakMap();
|
|
1508
1523
|
_onConsentChange = /* @__PURE__ */ new WeakMap();
|
|
1509
1524
|
_DatashipsWidget_instances = /* @__PURE__ */ new WeakSet();
|
|
1510
|
-
renderInto_fn = function(response, { page, locale = "en", heading = "Email marketing preferences" }) {
|
|
1525
|
+
renderInto_fn = function(response, { page, locale = "en", heading = "Email marketing preferences", channel = "EMAIL", preview = false }) {
|
|
1511
1526
|
__privateGet4(this, _root)?.remove();
|
|
1512
1527
|
__privateSet4(this, _root, null);
|
|
1513
|
-
const item = (response?.consents ?? []).find((c) => c.channel ===
|
|
1528
|
+
const item = (response?.consents ?? []).find((c) => c.channel === channel);
|
|
1514
1529
|
if (!item) {
|
|
1515
1530
|
this.removeAttribute("data-visible");
|
|
1516
1531
|
return;
|
|
1517
1532
|
}
|
|
1518
1533
|
const cfg = item.widgetConfig ?? {};
|
|
1519
|
-
const
|
|
1520
|
-
const showCheckbox =
|
|
1521
|
-
const showText = textOnly && !!cfg.text;
|
|
1534
|
+
const description = page === "form" ? cfg.consentDescription || cfg.text : cfg.consentDescription;
|
|
1535
|
+
const showCheckbox = page !== "form" && item.consentType !== "NONE" && !!cfg.text;
|
|
1522
1536
|
const isControl = !cfg.consentDescription && !cfg.marketingInformation;
|
|
1523
1537
|
const boxed = page === "confirmation";
|
|
1524
|
-
if (!showCheckbox && !
|
|
1538
|
+
if (!showCheckbox && !description) {
|
|
1525
1539
|
this.removeAttribute("data-visible");
|
|
1526
1540
|
return;
|
|
1527
1541
|
}
|
|
@@ -1535,6 +1549,10 @@ renderInto_fn = function(response, { page, locale = "en", heading = "Email marke
|
|
|
1535
1549
|
modal?.setAttribute("open", "");
|
|
1536
1550
|
}
|
|
1537
1551
|
};
|
|
1552
|
+
const link = (text, href) => {
|
|
1553
|
+
const safe = safeHref(href ?? null, CONFIG_URL_PROTOCOLS);
|
|
1554
|
+
return safe ? el("a", { className: "link", text, attrs: { href: safe, target: "_blank", rel: "noreferrer noopener" } }) : document.createTextNode(text);
|
|
1555
|
+
};
|
|
1538
1556
|
const rules = (policyURL) => ({
|
|
1539
1557
|
consent: (m) => el("strong", { text: m }),
|
|
1540
1558
|
object: (m) => el("strong", { text: m }),
|
|
@@ -1546,7 +1564,9 @@ renderInto_fn = function(response, { page, locale = "en", heading = "Email marke
|
|
|
1546
1564
|
b.addEventListener("click", openModal);
|
|
1547
1565
|
return b;
|
|
1548
1566
|
},
|
|
1549
|
-
privacyPolicy: (m) =>
|
|
1567
|
+
privacyPolicy: (m) => link(m, policyURL),
|
|
1568
|
+
// SMS copy also names the mobile terms; email copy keeps linking the privacy policy only.
|
|
1569
|
+
...channel === "SMS" ? { termsOfService: (m) => link(m, cfg.mobileTermsOfServiceURL) } : {}
|
|
1550
1570
|
});
|
|
1551
1571
|
if (showCheckbox) {
|
|
1552
1572
|
const id = "dataships-consent-checkbox";
|
|
@@ -1570,13 +1590,11 @@ renderInto_fn = function(response, { page, locale = "en", heading = "Email marke
|
|
|
1570
1590
|
});
|
|
1571
1591
|
root.append(el("div", { className: "consent" }, [checkbox, label]));
|
|
1572
1592
|
}
|
|
1573
|
-
if (
|
|
1574
|
-
root.append(el("p", { className: "
|
|
1575
|
-
}
|
|
1576
|
-
if (cfg.consentDescription) {
|
|
1577
|
-
root.append(el("p", { className: "description" }, formatCopy(cfg.consentDescription, locale, rules(cfg.policyURL))));
|
|
1593
|
+
if (description) {
|
|
1594
|
+
root.append(el("p", { className: "description" }, formatCopy(description, locale, rules(cfg.policyURL))));
|
|
1578
1595
|
}
|
|
1579
1596
|
if (modal) root.append(modal);
|
|
1597
|
+
if (preview) root.append(el("p", { className: "preview-badge", text: PREVIEW_BADGE }));
|
|
1580
1598
|
__privateGet4(this, _shadow).append(root);
|
|
1581
1599
|
__privateSet4(this, _root, root);
|
|
1582
1600
|
this.setAttribute("data-visible", "");
|
|
@@ -1633,7 +1651,7 @@ var createSdkClient = (opts) => {
|
|
|
1633
1651
|
...preview ? {} : opts.unsafeServerKey ? { auth: { unsafeServerKey: opts.unsafeServerKey } } : { auth: { publicKey: opts.publicKey, token: opts.token } },
|
|
1634
1652
|
env: opts.env ?? "production",
|
|
1635
1653
|
app: ELEMENTS_APP_NAME,
|
|
1636
|
-
version: "2.
|
|
1654
|
+
version: "2.6.0",
|
|
1637
1655
|
adapter,
|
|
1638
1656
|
...opts.baseUrl ? { baseUrl: opts.baseUrl } : {},
|
|
1639
1657
|
...opts.fetch ? { fetch: opts.fetch } : {}
|
|
@@ -1654,6 +1672,7 @@ var _client;
|
|
|
1654
1672
|
var _log;
|
|
1655
1673
|
var _emit;
|
|
1656
1674
|
var _heartbeat;
|
|
1675
|
+
var _identifierType;
|
|
1657
1676
|
var _onResponse;
|
|
1658
1677
|
var _stopHeartbeat;
|
|
1659
1678
|
var Session = class {
|
|
@@ -1661,10 +1680,12 @@ var Session = class {
|
|
|
1661
1680
|
this.response = null;
|
|
1662
1681
|
this.ids = { consentSessionId: null };
|
|
1663
1682
|
this.lastIdentifier = null;
|
|
1683
|
+
this.ok = false;
|
|
1664
1684
|
__privateAdd4(this, _client);
|
|
1665
1685
|
__privateAdd4(this, _log);
|
|
1666
1686
|
__privateAdd4(this, _emit);
|
|
1667
1687
|
__privateAdd4(this, _heartbeat);
|
|
1688
|
+
__privateAdd4(this, _identifierType);
|
|
1668
1689
|
__privateAdd4(this, _onResponse);
|
|
1669
1690
|
__privateAdd4(this, _stopHeartbeat, () => {
|
|
1670
1691
|
});
|
|
@@ -1672,14 +1693,22 @@ var Session = class {
|
|
|
1672
1693
|
__privateSet4(this, _log, opts.log);
|
|
1673
1694
|
__privateSet4(this, _emit, opts.emit);
|
|
1674
1695
|
__privateSet4(this, _heartbeat, opts.heartbeat);
|
|
1696
|
+
__privateSet4(this, _identifierType, opts.identifierType ?? "EMAIL");
|
|
1675
1697
|
__privateSet4(this, _onResponse, opts.onResponse);
|
|
1676
1698
|
}
|
|
1677
|
-
/**
|
|
1678
|
-
|
|
1699
|
+
/**
|
|
1700
|
+
* Open or update the session. Never rejects: a failure is logged and renders nothing.
|
|
1701
|
+
* With `keepOnFailure` a failure leaves the session, its heartbeat and what is rendered
|
|
1702
|
+
* as they were: the session opened before is still there, and so is the text the
|
|
1703
|
+
* visitor is reading.
|
|
1704
|
+
*/
|
|
1705
|
+
async upsert(identifier, { keepOnFailure = false } = {}) {
|
|
1706
|
+
const previousIdentifier = this.lastIdentifier;
|
|
1679
1707
|
this.lastIdentifier = identifier;
|
|
1680
1708
|
const who = identifier ? "set" : "anonymous";
|
|
1681
1709
|
try {
|
|
1682
|
-
this.response = await __privateGet4(this, _client).upsertSession({ identifierType:
|
|
1710
|
+
this.response = await __privateGet4(this, _client).upsertSession({ identifierType: __privateGet4(this, _identifierType), ...identifier ? { identifier } : {} });
|
|
1711
|
+
this.ok = true;
|
|
1683
1712
|
const consents = this.response.consents.map((c) => `${c.channel}:${c.consentType}`);
|
|
1684
1713
|
__privateGet4(this, _log).call(this, "upsert ok", { consentSessionId: this.response.consentSessionId, consents, identifier: who });
|
|
1685
1714
|
__privateGet4(this, _emit).call(this, "dataships:upsert", { ok: true, consentSessionId: this.response.consentSessionId, consents, identifier: who });
|
|
@@ -1687,6 +1716,11 @@ var Session = class {
|
|
|
1687
1716
|
const error = describeError(e);
|
|
1688
1717
|
__privateGet4(this, _log).call(this, "upsert failed", error);
|
|
1689
1718
|
__privateGet4(this, _emit).call(this, "dataships:upsert", { ok: false, consentSessionId: null, consents: [], identifier: who, error });
|
|
1719
|
+
this.ok = false;
|
|
1720
|
+
if (keepOnFailure) {
|
|
1721
|
+
this.lastIdentifier = previousIdentifier;
|
|
1722
|
+
return;
|
|
1723
|
+
}
|
|
1690
1724
|
this.response = null;
|
|
1691
1725
|
}
|
|
1692
1726
|
this.ids = { consentSessionId: this.response?.consentSessionId ?? null };
|
|
@@ -1720,23 +1754,31 @@ _client = /* @__PURE__ */ new WeakMap();
|
|
|
1720
1754
|
_log = /* @__PURE__ */ new WeakMap();
|
|
1721
1755
|
_emit = /* @__PURE__ */ new WeakMap();
|
|
1722
1756
|
_heartbeat = /* @__PURE__ */ new WeakMap();
|
|
1757
|
+
_identifierType = /* @__PURE__ */ new WeakMap();
|
|
1723
1758
|
_onResponse = /* @__PURE__ */ new WeakMap();
|
|
1724
1759
|
_stopHeartbeat = /* @__PURE__ */ new WeakMap();
|
|
1725
1760
|
var _pending;
|
|
1726
1761
|
var _onMutation;
|
|
1727
1762
|
var _observer;
|
|
1763
|
+
var _root2;
|
|
1728
1764
|
var _DomWatcher_instances;
|
|
1729
1765
|
var ensureObserving_fn;
|
|
1730
1766
|
var DomWatcher = class {
|
|
1731
|
-
constructor() {
|
|
1767
|
+
constructor(root = document) {
|
|
1732
1768
|
__privateAdd4(this, _DomWatcher_instances);
|
|
1733
1769
|
__privateAdd4(this, _pending, /* @__PURE__ */ new Map());
|
|
1734
1770
|
__privateAdd4(this, _onMutation, []);
|
|
1735
1771
|
__privateAdd4(this, _observer, null);
|
|
1772
|
+
__privateAdd4(this, _root2);
|
|
1773
|
+
__privateSet4(this, _root2, root);
|
|
1774
|
+
}
|
|
1775
|
+
/** The first match in this watcher's root, if it is there now. */
|
|
1776
|
+
find(selector) {
|
|
1777
|
+
return __privateGet4(this, _root2).querySelector(selector);
|
|
1736
1778
|
}
|
|
1737
1779
|
/** Run `cb` with the first match now, or once the host renders one. */
|
|
1738
1780
|
once(selector, cb) {
|
|
1739
|
-
const now =
|
|
1781
|
+
const now = this.find(selector);
|
|
1740
1782
|
if (now) {
|
|
1741
1783
|
cb(now);
|
|
1742
1784
|
return;
|
|
@@ -1761,12 +1803,13 @@ var DomWatcher = class {
|
|
|
1761
1803
|
_pending = /* @__PURE__ */ new WeakMap();
|
|
1762
1804
|
_onMutation = /* @__PURE__ */ new WeakMap();
|
|
1763
1805
|
_observer = /* @__PURE__ */ new WeakMap();
|
|
1806
|
+
_root2 = /* @__PURE__ */ new WeakMap();
|
|
1764
1807
|
_DomWatcher_instances = /* @__PURE__ */ new WeakSet();
|
|
1765
1808
|
ensureObserving_fn = function() {
|
|
1766
1809
|
if (__privateGet4(this, _observer)) return;
|
|
1767
1810
|
__privateSet4(this, _observer, new MutationObserver(() => {
|
|
1768
1811
|
for (const [selector, cbs] of [...__privateGet4(this, _pending)]) {
|
|
1769
|
-
const found =
|
|
1812
|
+
const found = this.find(selector);
|
|
1770
1813
|
if (!found) continue;
|
|
1771
1814
|
__privateGet4(this, _pending).delete(selector);
|
|
1772
1815
|
cbs.forEach((cb) => cb(found));
|
|
@@ -1774,7 +1817,8 @@ ensureObserving_fn = function() {
|
|
|
1774
1817
|
__privateGet4(this, _onMutation).forEach((fn) => fn());
|
|
1775
1818
|
if (!__privateGet4(this, _pending).size && !__privateGet4(this, _onMutation).length) this.stop();
|
|
1776
1819
|
}));
|
|
1777
|
-
__privateGet4(this,
|
|
1820
|
+
const target = "body" in __privateGet4(this, _root2) ? __privateGet4(this, _root2).body : __privateGet4(this, _root2);
|
|
1821
|
+
__privateGet4(this, _observer).observe(target, { childList: true, subtree: true });
|
|
1778
1822
|
};
|
|
1779
1823
|
var keepPlaced = (dom, widget, target, position) => {
|
|
1780
1824
|
const place = (anchor) => {
|
|
@@ -1784,7 +1828,7 @@ var keepPlaced = (dom, widget, target, position) => {
|
|
|
1784
1828
|
place(anchor);
|
|
1785
1829
|
dom.onEveryMutation(() => {
|
|
1786
1830
|
if (widget.isConnected) return;
|
|
1787
|
-
const a =
|
|
1831
|
+
const a = dom.find(target);
|
|
1788
1832
|
if (a) place(a);
|
|
1789
1833
|
});
|
|
1790
1834
|
});
|
|
@@ -1905,81 +1949,63 @@ var confirmationPage = {
|
|
|
1905
1949
|
};
|
|
1906
1950
|
var formPage = {
|
|
1907
1951
|
heartbeat: true,
|
|
1952
|
+
identifierType: (config) => config.phoneInput ? "PHONE" : "EMAIL",
|
|
1908
1953
|
validate(config) {
|
|
1909
1954
|
if (!config.client) fail("client is required on the form page (build the SDK client with the form's adapter and pass it in)");
|
|
1910
|
-
if (!config.emailInput) fail("emailInput is required on the form page");
|
|
1955
|
+
if (!config.emailInput && !config.phoneInput) fail("emailInput or phoneInput is required on the form page");
|
|
1956
|
+
if (config.emailInput && config.phoneInput) fail("pass either emailInput or phoneInput on the form page, not both (mount once per step)");
|
|
1911
1957
|
},
|
|
1912
1958
|
start({ config, client, log, emit, session, dom, onCleanup }) {
|
|
1913
|
-
|
|
1959
|
+
const phoneStep = !!config.phoneInput;
|
|
1960
|
+
let identifierUpdate = Promise.resolve();
|
|
1914
1961
|
let submitted = false;
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
}
|
|
1922
|
-
let consented = false;
|
|
1923
|
-
let consenting = null;
|
|
1924
|
-
const consent = () => {
|
|
1925
|
-
if (consented) return Promise.resolve();
|
|
1926
|
-
consenting ?? (consenting = (async () => {
|
|
1927
|
-
await emailSettled();
|
|
1928
|
-
const saved = await session.saveConsent(true);
|
|
1929
|
-
consented = saved;
|
|
1930
|
-
emit("dataships:consent", { consent: true, saved });
|
|
1931
|
-
consenting = null;
|
|
1932
|
-
})());
|
|
1933
|
-
return consenting;
|
|
1934
|
-
};
|
|
1962
|
+
let watcher = null;
|
|
1963
|
+
if (config.emailInput) {
|
|
1964
|
+
const emailWatcher = new EmailWatcher({ onEmail: (email) => submitted ? Promise.resolve() : identifierUpdate = session.upsert(email) });
|
|
1965
|
+
watcher = emailWatcher;
|
|
1966
|
+
dom.once(config.emailInput, (node) => emailWatcher.attach(node));
|
|
1967
|
+
onCleanup(() => emailWatcher.stop());
|
|
1968
|
+
}
|
|
1935
1969
|
let submitting = null;
|
|
1936
|
-
const submit = () => {
|
|
1970
|
+
const submit = (input) => {
|
|
1937
1971
|
submitting ?? (submitting = (async () => {
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1972
|
+
const refused = (error) => {
|
|
1973
|
+
log("submit failed", error);
|
|
1974
|
+
emit("dataships:submit", { ok: false, page: "form", error });
|
|
1941
1975
|
submitting = null;
|
|
1942
|
-
|
|
1976
|
+
};
|
|
1977
|
+
await watcher?.flush();
|
|
1978
|
+
await identifierUpdate;
|
|
1979
|
+
const phone = input?.phone;
|
|
1980
|
+
if (phoneStep && !phone) return refused("no phone number was given");
|
|
1981
|
+
if (phone && phoneStep) {
|
|
1982
|
+
await (identifierUpdate = session.upsert(phone, { keepOnFailure: true }));
|
|
1983
|
+
if (!session.ok) return refused("the phone number could not be saved");
|
|
1943
1984
|
}
|
|
1944
|
-
await emailSettled();
|
|
1945
1985
|
try {
|
|
1946
|
-
await client.submitSession({ details: {} });
|
|
1986
|
+
await client.submitSession({ details: { identifierType: phoneStep ? "PHONE" : "EMAIL", ...config.submitDetails } });
|
|
1947
1987
|
submitted = true;
|
|
1948
|
-
watcher
|
|
1988
|
+
watcher?.stop();
|
|
1949
1989
|
session.stop();
|
|
1950
1990
|
log("submit ok", { page: "form" });
|
|
1951
1991
|
emit("dataships:submit", { ok: true, page: "form" });
|
|
1952
1992
|
} catch (e) {
|
|
1953
|
-
|
|
1954
|
-
log("submit failed", error);
|
|
1955
|
-
emit("dataships:submit", { ok: false, page: "form", error });
|
|
1956
|
-
submitting = null;
|
|
1993
|
+
refused(describeError(e));
|
|
1957
1994
|
}
|
|
1958
1995
|
})());
|
|
1959
1996
|
return submitting;
|
|
1960
1997
|
};
|
|
1961
|
-
const submitIfConsented = () => {
|
|
1962
|
-
if (consented || consenting) void submit();
|
|
1963
|
-
};
|
|
1964
|
-
const onVisibility = () => {
|
|
1965
|
-
if (document.visibilityState === "hidden") submitIfConsented();
|
|
1966
|
-
};
|
|
1967
|
-
document.addEventListener("visibilitychange", onVisibility);
|
|
1968
|
-
window.addEventListener("pagehide", submitIfConsented);
|
|
1969
|
-
onCleanup(() => {
|
|
1970
|
-
document.removeEventListener("visibilitychange", onVisibility);
|
|
1971
|
-
window.removeEventListener("pagehide", submitIfConsented);
|
|
1972
|
-
});
|
|
1973
1998
|
const refresh = () => submitted ? Promise.resolve() : session.upsert(session.lastIdentifier);
|
|
1974
|
-
return { ready: session.upsert(null), refresh,
|
|
1999
|
+
return { ready: session.upsert(null), refresh, submit };
|
|
1975
2000
|
}
|
|
1976
2001
|
};
|
|
1977
|
-
var readInput = (selector) => selector ? (
|
|
2002
|
+
var readInput = (root, selector) => selector ? (root.querySelector(selector)?.value ?? "").trim() : "";
|
|
1978
2003
|
var readSignupNames = (config) => {
|
|
1979
2004
|
const fromResolver = config.user?.() ?? {};
|
|
2005
|
+
const root = config.root ?? document;
|
|
1980
2006
|
return {
|
|
1981
|
-
firstName: (fromResolver.firstName ?? readInput(config.firstNameInput)).trim(),
|
|
1982
|
-
lastName: (fromResolver.lastName ?? readInput(config.lastNameInput)).trim()
|
|
2007
|
+
firstName: (fromResolver.firstName ?? readInput(root, config.firstNameInput)).trim(),
|
|
2008
|
+
lastName: (fromResolver.lastName ?? readInput(root, config.lastNameInput)).trim()
|
|
1983
2009
|
};
|
|
1984
2010
|
};
|
|
1985
2011
|
var signupPage = {
|
|
@@ -2053,7 +2079,7 @@ var signupPage = {
|
|
|
2053
2079
|
dom.once(config.emailInput, (node) => {
|
|
2054
2080
|
watcher.attach(node);
|
|
2055
2081
|
if ((config.submit ?? "form") !== "form") return;
|
|
2056
|
-
const form = config.form ? document.querySelector(config.form) : node.closest("form");
|
|
2082
|
+
const form = config.form ? (config.root ?? document).querySelector(config.form) : node.closest("form");
|
|
2057
2083
|
if (form) interceptForm(form);
|
|
2058
2084
|
else log('signup form not found; native submit is not intercepted (use submit: "manual" and handle.submit())');
|
|
2059
2085
|
});
|
|
@@ -2066,13 +2092,20 @@ var pages = {
|
|
|
2066
2092
|
signup: signupPage,
|
|
2067
2093
|
form: formPage
|
|
2068
2094
|
};
|
|
2069
|
-
var
|
|
2095
|
+
var registries = /* @__PURE__ */ new WeakMap();
|
|
2096
|
+
var registryFor = (root) => {
|
|
2097
|
+
let registry = registries.get(root);
|
|
2098
|
+
if (!registry) registries.set(root, registry = /* @__PURE__ */ new Map());
|
|
2099
|
+
return registry;
|
|
2100
|
+
};
|
|
2070
2101
|
var validate = (config) => {
|
|
2071
2102
|
if (!config || typeof config !== "object") fail("config object is required");
|
|
2072
2103
|
if (!config.publicKey) fail("publicKey is required");
|
|
2073
2104
|
if (!(config.page in pages)) fail('page must be "checkout", "confirmation", "signup" or "form"');
|
|
2074
2105
|
if (!config.mount) fail("mount (CSS selector) is required");
|
|
2075
2106
|
if (config.position !== void 0 && config.position !== "after" && config.position !== "before") fail('position must be "after" or "before"');
|
|
2107
|
+
if (config.className !== void 0 && typeof config.className !== "string") fail("className must be a string of class names separated by spaces");
|
|
2108
|
+
if (config.root !== void 0 && typeof config.root?.querySelector !== "function") fail("root must be a document or a shadow root");
|
|
2076
2109
|
pages[config.page].validate(config);
|
|
2077
2110
|
if (!config.client && !config.preview && !config.token && !config.unsafeServerKey) fail("token is required for live calls (the merchant server mints it); pass `preview: true` to style without credentials, or `client` to bring your own");
|
|
2078
2111
|
if (config.token && config.unsafeServerKey) fail("pass either token or unsafeServerKey, not both");
|
|
@@ -2101,8 +2134,12 @@ var resolveClient = (config, log) => {
|
|
|
2101
2134
|
var mount = (config) => {
|
|
2102
2135
|
validate(config);
|
|
2103
2136
|
defineWidget();
|
|
2104
|
-
const { page,
|
|
2137
|
+
const { page, appearance = {}, locale = "en", position = "after" } = config;
|
|
2138
|
+
const target = config.mount;
|
|
2139
|
+
const preview = config.preview === true;
|
|
2105
2140
|
const log = config.log ?? defaultLog;
|
|
2141
|
+
const root = config.root ?? document;
|
|
2142
|
+
const registry = registryFor(root);
|
|
2106
2143
|
const existing = registry.get(target);
|
|
2107
2144
|
if (existing) {
|
|
2108
2145
|
existing.update({ appearance, page });
|
|
@@ -2110,14 +2147,21 @@ var mount = (config) => {
|
|
|
2110
2147
|
}
|
|
2111
2148
|
const client = resolveClient(config, log);
|
|
2112
2149
|
const strategy = pages[page];
|
|
2150
|
+
const identifierType = strategy.identifierType?.(config) ?? "EMAIL";
|
|
2151
|
+
const channel = identifierType === "PHONE" ? "SMS" : "EMAIL";
|
|
2113
2152
|
const widget = document.createElement(WIDGET_TAG);
|
|
2114
2153
|
widget.setAttribute("data-page", page);
|
|
2115
2154
|
widget.setAppearance(appearance);
|
|
2155
|
+
const classNames = config.className?.trim().split(/\s+/).filter(Boolean) ?? [];
|
|
2156
|
+
if (classNames.length) {
|
|
2157
|
+
widget.classList.add(...classNames);
|
|
2158
|
+
widget.setAttribute("data-host-styled", "");
|
|
2159
|
+
}
|
|
2116
2160
|
const cleanups = [];
|
|
2117
2161
|
const onCleanup = (fn) => {
|
|
2118
2162
|
cleanups.push(fn);
|
|
2119
2163
|
};
|
|
2120
|
-
const dom = new DomWatcher();
|
|
2164
|
+
const dom = new DomWatcher(root);
|
|
2121
2165
|
onCleanup(() => dom.stop());
|
|
2122
2166
|
const emit = emitterFor(widget);
|
|
2123
2167
|
const session = new Session({
|
|
@@ -2125,7 +2169,8 @@ var mount = (config) => {
|
|
|
2125
2169
|
log,
|
|
2126
2170
|
emit,
|
|
2127
2171
|
heartbeat: strategy.heartbeat,
|
|
2128
|
-
|
|
2172
|
+
identifierType,
|
|
2173
|
+
onResponse: (response) => widget.render(response, { page, locale, channel, preview })
|
|
2129
2174
|
});
|
|
2130
2175
|
widget.onConsentChange = (consent) => session.saveConsent(consent);
|
|
2131
2176
|
keepPlaced(dom, widget, target, position);
|
|
@@ -2135,7 +2180,7 @@ var mount = (config) => {
|
|
|
2135
2180
|
update: ({ appearance: a, page: p }) => {
|
|
2136
2181
|
widget.setAppearance(a);
|
|
2137
2182
|
if (p !== page) log("page change on a repeat mount() is not supported; unmount first");
|
|
2138
|
-
widget.render(session.response, { page, locale });
|
|
2183
|
+
widget.render(session.response, { page, locale, channel, preview });
|
|
2139
2184
|
},
|
|
2140
2185
|
handle: {
|
|
2141
2186
|
ready,
|
|
@@ -2147,7 +2192,6 @@ var mount = (config) => {
|
|
|
2147
2192
|
},
|
|
2148
2193
|
refresh: run.refresh ?? (() => session.upsert(session.lastIdentifier)),
|
|
2149
2194
|
...run.submit ? { submit: run.submit } : {},
|
|
2150
|
-
...run.consent ? { consent: run.consent } : {},
|
|
2151
2195
|
element: widget
|
|
2152
2196
|
}
|
|
2153
2197
|
};
|
|
@@ -2155,7 +2199,7 @@ var mount = (config) => {
|
|
|
2155
2199
|
return entry.handle;
|
|
2156
2200
|
};
|
|
2157
2201
|
|
|
2158
|
-
// node_modules/@dataships/sdk/dist/
|
|
2202
|
+
// node_modules/@dataships/sdk/dist/index.js
|
|
2159
2203
|
var __typeError5 = (msg) => {
|
|
2160
2204
|
throw TypeError(msg);
|
|
2161
2205
|
};
|
|
@@ -2164,226 +2208,752 @@ var __privateGet5 = (obj, member, getter) => (__accessCheck5(obj, member, "read
|
|
|
2164
2208
|
var __privateAdd5 = (obj, member, value) => member.has(obj) ? __typeError5("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
2165
2209
|
var __privateSet5 = (obj, member, value, setter) => (__accessCheck5(obj, member, "write to private field"), member.set(obj, value), value);
|
|
2166
2210
|
var __privateMethod5 = (obj, member, method) => (__accessCheck5(obj, member, "access private method"), method);
|
|
2167
|
-
var
|
|
2168
|
-
var
|
|
2169
|
-
var
|
|
2170
|
-
var
|
|
2171
|
-
var
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
widgetConfig: {
|
|
2179
|
-
text: DEFAULT_EMAIL_OPT_IN_TEXT3,
|
|
2180
|
-
consentDescription: DEFAULT_EMAIL_OPT_IN_CONSENT_DESCRIPTION3,
|
|
2181
|
-
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',
|
|
2182
|
-
policyURL: "https://dataships.io/privacy-centre",
|
|
2183
|
-
mobileTermsOfServiceURL: null,
|
|
2184
|
-
privacyEmail: "privacy@example.com",
|
|
2185
|
-
placeholderValues: null
|
|
2186
|
-
}
|
|
2187
|
-
}
|
|
2188
|
-
],
|
|
2189
|
-
userVerificationRequired: null,
|
|
2190
|
-
lastHeartbeat: "2026-06-17T00:00:00Z",
|
|
2191
|
-
identifier: null
|
|
2211
|
+
var SERVER_KEY_PREFIX2 = "ds_sk_";
|
|
2212
|
+
var isServerKey2 = (key) => key.startsWith(SERVER_KEY_PREFIX2);
|
|
2213
|
+
var isServerKeyAuth2 = (auth) => "serverKey" in auth;
|
|
2214
|
+
var isUnsafeServerKeyAuth2 = (auth) => "unsafeServerKey" in auth;
|
|
2215
|
+
var isTokenProviderAuth2 = (auth) => typeof auth.getToken === "function";
|
|
2216
|
+
var resolveTokenProviderAuth2 = async (auth) => {
|
|
2217
|
+
const token = await auth.getToken();
|
|
2218
|
+
if (!token) {
|
|
2219
|
+
throw new Error("DatashipsClient: auth.getToken() returned an empty token");
|
|
2220
|
+
}
|
|
2221
|
+
return { publicKey: auth.publicKey, token };
|
|
2192
2222
|
};
|
|
2193
|
-
var
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
text: DEFAULT_SMS_OPT_IN_TEXT3,
|
|
2202
|
-
consentDescription: DEFAULT_SMS_OPT_IN_CONSENT_DESCRIPTION3,
|
|
2203
|
-
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',
|
|
2204
|
-
policyURL: "https://dataships.io/privacy-centre",
|
|
2205
|
-
mobileTermsOfServiceURL: "https://dataships.io/mobile-terms",
|
|
2206
|
-
privacyEmail: "privacy@example.com",
|
|
2207
|
-
placeholderValues: null
|
|
2208
|
-
}
|
|
2223
|
+
var UNSAFE_SERVER_KEY_APP_MARKER2 = "unsafe-server-key";
|
|
2224
|
+
var UNSAFE_SERVER_KEY_WARNING2 = "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.";
|
|
2225
|
+
var assertBrowserAuth2 = (auth) => {
|
|
2226
|
+
if (isUnsafeServerKeyAuth2(auth)) {
|
|
2227
|
+
if (!auth.unsafeServerKey || !isServerKey2(auth.unsafeServerKey)) {
|
|
2228
|
+
throw new Error(
|
|
2229
|
+
"DatashipsClient: auth.unsafeServerKey must be a server key (ds_sk_\u2026); a public key belongs in auth: { publicKey, token }"
|
|
2230
|
+
);
|
|
2209
2231
|
}
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
lastHeartbeat: "2026-06-17T00:00:00Z",
|
|
2213
|
-
identifier: null
|
|
2214
|
-
};
|
|
2215
|
-
var MARKETING_MODAL_HREF3 = "#dataships-marketing-modal";
|
|
2216
|
-
var CHECKBOX_LABEL_BOLD_PHRASES3 = ["consent", "object", "opt in", "opt out", "STOP", "HELP"];
|
|
2217
|
-
var CONSENT_DESCRIPTION_BOLD_PHRASES3 = ["STOP", "HELP"];
|
|
2218
|
-
var escapeHtml3 = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
2219
|
-
var escapeRegExp4 = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2220
|
-
var wrapPhrase3 = (html, phrase, wrap) => html.replace(
|
|
2221
|
-
new RegExp(`${escapeRegExp4(escapeHtml3(phrase))}(?![^<]*>)(?![^<]*</a>)`, "gi"),
|
|
2222
|
-
wrap
|
|
2223
|
-
);
|
|
2224
|
-
var toHtmlCopy3 = (text, widgetConfig, boldPhrases) => {
|
|
2225
|
-
let html = escapeHtml3(text);
|
|
2226
|
-
const links = [
|
|
2227
|
-
["Terms of Service", widgetConfig.mobileTermsOfServiceURL],
|
|
2228
|
-
["Privacy Policy", widgetConfig.policyURL],
|
|
2229
|
-
["Click here", MARKETING_MODAL_HREF3]
|
|
2230
|
-
];
|
|
2231
|
-
for (const [phrase, href] of links) {
|
|
2232
|
-
if (!href) continue;
|
|
2233
|
-
html = wrapPhrase3(html, phrase, (match) => `<a href="${escapeHtml3(href)}">${match}</a>`);
|
|
2234
|
-
}
|
|
2235
|
-
for (const phrase of boldPhrases) {
|
|
2236
|
-
html = wrapPhrase3(html, phrase, (match) => `<strong>${match}</strong>`);
|
|
2232
|
+
warnUnsafeServerKey2();
|
|
2233
|
+
return;
|
|
2237
2234
|
}
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
consents: response.consents.map((consent) => {
|
|
2243
|
-
const { widgetConfig } = consent;
|
|
2244
|
-
return {
|
|
2245
|
-
...consent,
|
|
2246
|
-
widgetConfig: {
|
|
2247
|
-
...widgetConfig,
|
|
2248
|
-
text: widgetConfig.text === null ? null : toHtmlCopy3(widgetConfig.text, widgetConfig, CHECKBOX_LABEL_BOLD_PHRASES3),
|
|
2249
|
-
consentDescription: widgetConfig.consentDescription === null ? null : toHtmlCopy3(
|
|
2250
|
-
widgetConfig.consentDescription,
|
|
2251
|
-
widgetConfig,
|
|
2252
|
-
CONSENT_DESCRIPTION_BOLD_PHRASES3
|
|
2253
|
-
)
|
|
2254
|
-
}
|
|
2255
|
-
};
|
|
2256
|
-
})
|
|
2257
|
-
});
|
|
2258
|
-
var previewUpsertResponse3 = (identifierType, format = "json") => {
|
|
2259
|
-
const response = identifierType === "PHONE" ? fakePhoneUpsertResponse3 : fakeEmailUpsertResponse3;
|
|
2260
|
-
return format === "html" ? withHtmlCopy3(response) : response;
|
|
2261
|
-
};
|
|
2262
|
-
var randomUuid3 = (cryptoObj = globalThis.crypto) => {
|
|
2263
|
-
if (cryptoObj && typeof cryptoObj.randomUUID === "function") {
|
|
2264
|
-
return cryptoObj.randomUUID();
|
|
2235
|
+
if (isServerKey2(auth.publicKey)) {
|
|
2236
|
+
throw new Error(
|
|
2237
|
+
"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"
|
|
2238
|
+
);
|
|
2265
2239
|
}
|
|
2266
|
-
const
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
2240
|
+
const hasProvider = "getToken" in auth && auth.getToken !== void 0;
|
|
2241
|
+
const hook = auth.onUnauthorized;
|
|
2242
|
+
if (hook !== void 0 && typeof hook !== "function") {
|
|
2243
|
+
throw new Error("DatashipsClient: auth.onUnauthorized must be a function");
|
|
2271
2244
|
}
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
};
|
|
2277
|
-
var DATASHIPS_SESSION_ID_MAX_LENGTH3 = 100;
|
|
2278
|
-
var _explicitId3;
|
|
2279
|
-
var _storageKey3;
|
|
2280
|
-
var _window3;
|
|
2281
|
-
var _id3;
|
|
2282
|
-
var _SessionBeacon_instances3;
|
|
2283
|
-
var safeStorage_fn3;
|
|
2284
|
-
var SessionBeacon3 = class {
|
|
2285
|
-
constructor(opts) {
|
|
2286
|
-
__privateAdd5(this, _SessionBeacon_instances3);
|
|
2287
|
-
__privateAdd5(this, _explicitId3);
|
|
2288
|
-
__privateAdd5(this, _storageKey3);
|
|
2289
|
-
__privateAdd5(this, _window3);
|
|
2290
|
-
__privateAdd5(this, _id3, null);
|
|
2291
|
-
if (opts.explicitId != null) assertSessionId3(opts.explicitId);
|
|
2292
|
-
__privateSet5(this, _explicitId3, opts.explicitId ?? null);
|
|
2293
|
-
__privateSet5(this, _storageKey3, opts.storageKey);
|
|
2294
|
-
__privateSet5(this, _window3, opts.window ?? globalThis.window);
|
|
2245
|
+
if (hook !== void 0 && !hasProvider) {
|
|
2246
|
+
throw new Error(
|
|
2247
|
+
"DatashipsClient: auth.onUnauthorized requires getToken; a fixed token cannot be refreshed for the retry"
|
|
2248
|
+
);
|
|
2295
2249
|
}
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
* used. Later calls return the same id for the adapter's lifetime.
|
|
2301
|
-
*/
|
|
2302
|
-
resolve(step, reusable) {
|
|
2303
|
-
if (__privateGet5(this, _explicitId3)) return __privateGet5(this, _explicitId3);
|
|
2304
|
-
const storage = __privateMethod5(this, _SessionBeacon_instances3, safeStorage_fn3).call(this);
|
|
2305
|
-
if (null === __privateGet5(this, _id3)) {
|
|
2306
|
-
const stored = storage ? readStored3(storage, __privateGet5(this, _storageKey3)) : null;
|
|
2307
|
-
__privateSet5(this, _id3, stored && reusable(stored) ? stored.id : randomUuid3(__privateGet5(this, _window3)?.crypto));
|
|
2308
|
-
}
|
|
2309
|
-
if (storage) {
|
|
2310
|
-
try {
|
|
2311
|
-
storage.setItem(__privateGet5(this, _storageKey3), JSON.stringify({ id: __privateGet5(this, _id3), lastStep: step }));
|
|
2312
|
-
} catch {
|
|
2313
|
-
}
|
|
2314
|
-
}
|
|
2315
|
-
return __privateGet5(this, _id3);
|
|
2250
|
+
if (hasProvider && "token" in auth && auth.token !== void 0) {
|
|
2251
|
+
throw new Error(
|
|
2252
|
+
"DatashipsClient: pass either auth.token or auth.getToken, not both"
|
|
2253
|
+
);
|
|
2316
2254
|
}
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
__privateSet5(this, _id3, null);
|
|
2321
|
-
const storage = __privateMethod5(this, _SessionBeacon_instances3, safeStorage_fn3).call(this);
|
|
2322
|
-
if (!storage) return;
|
|
2323
|
-
try {
|
|
2324
|
-
storage.removeItem(__privateGet5(this, _storageKey3));
|
|
2325
|
-
} catch {
|
|
2255
|
+
if (hasProvider) {
|
|
2256
|
+
if (!isTokenProviderAuth2(auth)) {
|
|
2257
|
+
throw new Error("DatashipsClient: auth.getToken must be a function");
|
|
2326
2258
|
}
|
|
2259
|
+
return;
|
|
2327
2260
|
}
|
|
2328
|
-
|
|
2329
|
-
_explicitId3 = /* @__PURE__ */ new WeakMap();
|
|
2330
|
-
_storageKey3 = /* @__PURE__ */ new WeakMap();
|
|
2331
|
-
_window3 = /* @__PURE__ */ new WeakMap();
|
|
2332
|
-
_id3 = /* @__PURE__ */ new WeakMap();
|
|
2333
|
-
_SessionBeacon_instances3 = /* @__PURE__ */ new WeakSet();
|
|
2334
|
-
safeStorage_fn3 = function() {
|
|
2335
|
-
try {
|
|
2336
|
-
return __privateGet5(this, _window3)?.localStorage ?? null;
|
|
2337
|
-
} catch {
|
|
2338
|
-
return null;
|
|
2339
|
-
}
|
|
2340
|
-
};
|
|
2341
|
-
var assertSessionId3 = (id) => {
|
|
2342
|
-
if (typeof id !== "string" || id.length === 0) {
|
|
2343
|
-
throw new Error("datashipsSessionId must be a non-empty string");
|
|
2344
|
-
}
|
|
2345
|
-
if (id.length > DATASHIPS_SESSION_ID_MAX_LENGTH3) {
|
|
2261
|
+
if (!auth.token) {
|
|
2346
2262
|
throw new Error(
|
|
2347
|
-
|
|
2263
|
+
"DatashipsClient: auth.token is required with a public key (the merchant's server mints it), or auth.getToken to fetch one per request"
|
|
2348
2264
|
);
|
|
2349
2265
|
}
|
|
2350
2266
|
};
|
|
2351
|
-
var
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2267
|
+
var warnUnsafeServerKey2 = () => {
|
|
2268
|
+
const c = globalThis.console;
|
|
2269
|
+
c?.warn?.(UNSAFE_SERVER_KEY_WARNING2);
|
|
2270
|
+
};
|
|
2271
|
+
var authHeaders2 = (auth) => {
|
|
2272
|
+
if (isUnsafeServerKeyAuth2(auth)) return { "X-Api-Key": auth.unsafeServerKey };
|
|
2273
|
+
return isServerKeyAuth2(auth) ? { "X-Api-Key": auth.serverKey } : { "X-Api-Key": auth.publicKey, Authorization: `Bearer ${auth.token}` };
|
|
2274
|
+
};
|
|
2275
|
+
var PRODUCTION_BASE_URL2 = "https://api.dataships.io";
|
|
2276
|
+
var resolveBaseUrl2 = (env = "production", baseUrl) => {
|
|
2277
|
+
if (baseUrl) return baseUrl;
|
|
2278
|
+
if (env === "production") return PRODUCTION_BASE_URL2;
|
|
2279
|
+
throw new Error(
|
|
2280
|
+
`Dataships SDK: env "${env}" has no default base URL; pass \`baseUrl\``
|
|
2281
|
+
);
|
|
2282
|
+
};
|
|
2283
|
+
var TERMINAL_STATUSES2 = /* @__PURE__ */ new Set([
|
|
2284
|
+
400,
|
|
2285
|
+
401,
|
|
2286
|
+
403,
|
|
2287
|
+
404,
|
|
2288
|
+
417,
|
|
2289
|
+
422,
|
|
2290
|
+
426
|
|
2291
|
+
]);
|
|
2292
|
+
var isTerminalStatus2 = (status) => status !== void 0 && TERMINAL_STATUSES2.has(status);
|
|
2293
|
+
var CONSENT_SESSION_ALREADY_PROCESSED2 = "CONSENT_SESSION_ALREADY_PROCESSED";
|
|
2294
|
+
var TERMINAL_ERROR_CODES2 = /* @__PURE__ */ new Set([
|
|
2295
|
+
CONSENT_SESSION_ALREADY_PROCESSED2
|
|
2296
|
+
]);
|
|
2297
|
+
var isTerminalErrorCode2 = (errorCode) => errorCode !== void 0 && TERMINAL_ERROR_CODES2.has(errorCode);
|
|
2298
|
+
var MAX_FAILURES2 = 4;
|
|
2299
|
+
var backoffMs2 = (failureCount) => failureCount >= MAX_FAILURES2 ? 0 : failureCount * 2e3;
|
|
2300
|
+
var defaultRetryPolicy2 = {
|
|
2301
|
+
shouldRetry: (failureCount, status, errorCode) => !isTerminalStatus2(status) && !isTerminalErrorCode2(errorCode) && failureCount < MAX_FAILURES2,
|
|
2302
|
+
delayMs: backoffMs2
|
|
2303
|
+
};
|
|
2304
|
+
var upsertSessionRetryPolicy2 = defaultRetryPolicy2;
|
|
2305
|
+
var noRetryPolicy2 = {
|
|
2306
|
+
shouldRetry: () => false,
|
|
2307
|
+
delayMs: () => 0
|
|
2308
|
+
};
|
|
2309
|
+
var DatashipsError2 = class extends Error {
|
|
2310
|
+
constructor(args) {
|
|
2311
|
+
super(`Dataships request failed (${args.status || "network"})`);
|
|
2312
|
+
this.name = "DatashipsError";
|
|
2313
|
+
this.status = args.status;
|
|
2314
|
+
this.body = args.body;
|
|
2315
|
+
this.challenge = args.challenge ?? null;
|
|
2316
|
+
this.code = errorCodeFromBody2(args.body);
|
|
2317
|
+
this.reason = reasonFromBody2(args.body);
|
|
2357
2318
|
}
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
return
|
|
2319
|
+
/** 401 (missing / refused credential) or 403 (unknown, revoked or disabled key). */
|
|
2320
|
+
get isAuthenticationFailure() {
|
|
2321
|
+
return this.status === 401 || this.status === 403;
|
|
2322
|
+
}
|
|
2323
|
+
/** 409 `CONSENT_SESSION_ALREADY_PROCESSED`: the session is closed; no later call on it can succeed. */
|
|
2324
|
+
get isSessionProcessed() {
|
|
2325
|
+
return this.code === CONSENT_SESSION_ALREADY_PROCESSED2;
|
|
2365
2326
|
}
|
|
2366
2327
|
};
|
|
2367
|
-
var
|
|
2368
|
-
"
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
"
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
"
|
|
2376
|
-
|
|
2377
|
-
"
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2328
|
+
var errorCodeFromBody2 = (body) => {
|
|
2329
|
+
if (typeof body !== "object" || body === null) return null;
|
|
2330
|
+
const errors = body.errors;
|
|
2331
|
+
if (!Array.isArray(errors)) return null;
|
|
2332
|
+
const code = errors[0]?.code;
|
|
2333
|
+
return typeof code === "string" ? code : null;
|
|
2334
|
+
};
|
|
2335
|
+
var reasonFromBody2 = (body) => {
|
|
2336
|
+
if (typeof body !== "object" || body === null) return null;
|
|
2337
|
+
const message = body.message;
|
|
2338
|
+
return typeof message === "string" && message.length > 0 ? message : null;
|
|
2339
|
+
};
|
|
2340
|
+
var CONSENT_SESSION_START_PATH2 = "/v1/consent-session";
|
|
2341
|
+
var CONSENT_SESSION_CONSENT_PATH2 = "/v1/consent-session/consent";
|
|
2342
|
+
var CONSENT_SESSION_HEARTBEAT_PATH2 = "/v1/consent-session/heartbeat";
|
|
2343
|
+
var CONSENT_SESSION_TRIGGER_VERIFICATION_CODE_PATH2 = "/v1/consent-session/trigger-verification-code";
|
|
2344
|
+
var CONSENT_SESSION_SUBMIT_VERIFICATION_CODE_PATH2 = "/v1/consent-session/submit-verification-code";
|
|
2345
|
+
var CONSENT_SESSION_SUBMIT_PATH2 = "/v1/consent-session/submit";
|
|
2346
|
+
var COUNTRY_NOT_FOUND_CODE2 = "COUNTRY_NOT_FOUND";
|
|
2347
|
+
var verificationErrorCodeFromBody2 = errorCodeFromBody2;
|
|
2348
|
+
var buildUpsertRequest2 = (args) => ({
|
|
2349
|
+
identifier: args.identifier,
|
|
2350
|
+
identifierType: args.identifierType,
|
|
2351
|
+
locale: args.locale,
|
|
2352
|
+
...args.userIp ? { userIp: args.userIp } : {},
|
|
2353
|
+
...args.format ? { format: args.format } : {},
|
|
2354
|
+
integration: {
|
|
2355
|
+
...args.context,
|
|
2356
|
+
type: args.integrationType
|
|
2357
|
+
}
|
|
2358
|
+
});
|
|
2359
|
+
var isCountryNotFound2 = (error) => error.status === 422 && error.code === COUNTRY_NOT_FOUND_CODE2;
|
|
2360
|
+
var emptyUpsertResponse2 = () => ({
|
|
2361
|
+
consentSessionId: null,
|
|
2362
|
+
consents: [],
|
|
2363
|
+
userVerificationRequired: null,
|
|
2364
|
+
lastHeartbeat: null,
|
|
2365
|
+
identifier: null
|
|
2366
|
+
});
|
|
2367
|
+
var buildSaveConsentRequest2 = (args) => ({
|
|
2368
|
+
consentSessionId: args.consentSessionId,
|
|
2369
|
+
channel: args.channel,
|
|
2370
|
+
consent: args.consent
|
|
2371
|
+
});
|
|
2372
|
+
var buildHeartbeatRequest2 = (args) => ({
|
|
2373
|
+
consentSessionId: args.consentSessionId
|
|
2374
|
+
});
|
|
2375
|
+
var buildTriggerVerificationCodeRequest2 = (args) => ({
|
|
2376
|
+
consentSessionId: args.consentSessionId
|
|
2377
|
+
});
|
|
2378
|
+
var buildSubmitVerificationCodeRequest2 = (args) => ({
|
|
2379
|
+
consentSessionId: args.consentSessionId,
|
|
2380
|
+
verificationCode: args.verificationCode,
|
|
2381
|
+
referenceId: args.referenceId
|
|
2382
|
+
});
|
|
2383
|
+
var buildSubmitRequest2 = (args) => {
|
|
2384
|
+
const details = { ...args.details };
|
|
2385
|
+
if (details.submittedAt instanceof Date) details.submittedAt = details.submittedAt.toISOString();
|
|
2386
|
+
if (typeof details.billingCountryCode === "string") {
|
|
2387
|
+
details.billingCountryCode = details.billingCountryCode.trim().toUpperCase();
|
|
2388
|
+
}
|
|
2389
|
+
const omitUser = args.user === void 0 && args.requiresUser === false;
|
|
2390
|
+
return {
|
|
2391
|
+
datashipsSessionId: args.datashipsSessionId,
|
|
2392
|
+
...omitUser ? {} : { user: normaliseSubmitUser2(args.user) },
|
|
2393
|
+
integration: { ...details, type: args.integrationType }
|
|
2394
|
+
};
|
|
2395
|
+
};
|
|
2396
|
+
var normaliseSubmitUser2 = (user) => {
|
|
2397
|
+
const firstName = user?.firstName?.trim() ?? "";
|
|
2398
|
+
const lastName = user?.lastName?.trim() ?? "";
|
|
2399
|
+
if (!firstName || !lastName) {
|
|
2400
|
+
throw new Error(
|
|
2401
|
+
"submitSession: user.firstName and user.lastName are required (core-api refuses a blank name)"
|
|
2402
|
+
);
|
|
2403
|
+
}
|
|
2404
|
+
return { firstName, lastName };
|
|
2405
|
+
};
|
|
2406
|
+
var upsertSession2 = async (args) => {
|
|
2407
|
+
const { adapter, input } = args;
|
|
2408
|
+
const identifier = input.identifier ?? (await adapter.getIdentifier(input.identifierType)).identifier;
|
|
2409
|
+
const context = await adapter.getSessionContext();
|
|
2410
|
+
const body = buildUpsertRequest2({
|
|
2411
|
+
integrationType: adapter.integrationType,
|
|
2412
|
+
locale: adapter.getLocale(),
|
|
2413
|
+
identifier,
|
|
2414
|
+
identifierType: input.identifierType,
|
|
2415
|
+
userIp: input.userIp,
|
|
2416
|
+
format: input.format,
|
|
2417
|
+
context
|
|
2418
|
+
});
|
|
2419
|
+
try {
|
|
2420
|
+
const response = await args.post({
|
|
2421
|
+
path: CONSENT_SESSION_START_PATH2,
|
|
2422
|
+
body,
|
|
2423
|
+
retry: args.retry
|
|
2424
|
+
});
|
|
2425
|
+
return response ?? emptyUpsertResponse2();
|
|
2426
|
+
} catch (error) {
|
|
2427
|
+
if (error instanceof DatashipsError2 && isCountryNotFound2(error)) {
|
|
2428
|
+
return emptyUpsertResponse2();
|
|
2429
|
+
}
|
|
2430
|
+
throw error;
|
|
2431
|
+
}
|
|
2432
|
+
};
|
|
2433
|
+
var saveConsent2 = (args) => args.post({
|
|
2434
|
+
path: CONSENT_SESSION_CONSENT_PATH2,
|
|
2435
|
+
body: buildSaveConsentRequest2({
|
|
2436
|
+
consentSessionId: args.consentSessionId,
|
|
2437
|
+
channel: args.channel,
|
|
2438
|
+
consent: args.consent
|
|
2439
|
+
}),
|
|
2440
|
+
retry: args.retry
|
|
2441
|
+
});
|
|
2442
|
+
var heartbeat2 = (args) => args.post({
|
|
2443
|
+
path: CONSENT_SESSION_HEARTBEAT_PATH2,
|
|
2444
|
+
body: buildHeartbeatRequest2({ consentSessionId: args.consentSessionId }),
|
|
2445
|
+
retry: args.retry
|
|
2446
|
+
});
|
|
2447
|
+
var triggerVerificationCode2 = (args) => args.post({
|
|
2448
|
+
path: CONSENT_SESSION_TRIGGER_VERIFICATION_CODE_PATH2,
|
|
2449
|
+
body: buildTriggerVerificationCodeRequest2({
|
|
2450
|
+
consentSessionId: args.consentSessionId
|
|
2451
|
+
}),
|
|
2452
|
+
retry: noRetryPolicy2
|
|
2453
|
+
});
|
|
2454
|
+
var submitVerificationCode2 = async (args) => {
|
|
2455
|
+
try {
|
|
2456
|
+
await args.post({
|
|
2457
|
+
path: CONSENT_SESSION_SUBMIT_VERIFICATION_CODE_PATH2,
|
|
2458
|
+
body: buildSubmitVerificationCodeRequest2({
|
|
2459
|
+
consentSessionId: args.consentSessionId,
|
|
2460
|
+
verificationCode: args.verificationCode,
|
|
2461
|
+
referenceId: args.referenceId
|
|
2462
|
+
}),
|
|
2463
|
+
retry: noRetryPolicy2
|
|
2464
|
+
});
|
|
2465
|
+
return { verified: true, errorCode: null };
|
|
2466
|
+
} catch (error) {
|
|
2467
|
+
if (error instanceof DatashipsError2 && error.status === 400) {
|
|
2468
|
+
return {
|
|
2469
|
+
verified: false,
|
|
2470
|
+
errorCode: verificationErrorCodeFromBody2(error.body)
|
|
2471
|
+
};
|
|
2472
|
+
}
|
|
2473
|
+
throw error;
|
|
2474
|
+
}
|
|
2475
|
+
};
|
|
2476
|
+
var submitSession2 = async (args) => {
|
|
2477
|
+
const { adapter, input } = args;
|
|
2478
|
+
const datashipsSessionId = input.datashipsSessionId ?? adapter.getDatashipsSessionId?.();
|
|
2479
|
+
if (!datashipsSessionId) {
|
|
2480
|
+
throw new Error(
|
|
2481
|
+
"submitSession: datashipsSessionId is required; this adapter holds no beacon of its own"
|
|
2482
|
+
);
|
|
2483
|
+
}
|
|
2484
|
+
await args.post({
|
|
2485
|
+
path: CONSENT_SESSION_SUBMIT_PATH2,
|
|
2486
|
+
body: buildSubmitRequest2({
|
|
2487
|
+
datashipsSessionId,
|
|
2488
|
+
integrationType: adapter.integrationType,
|
|
2489
|
+
user: input.user,
|
|
2490
|
+
details: input.details,
|
|
2491
|
+
requiresUser: adapter.submitRequiresUser
|
|
2492
|
+
}),
|
|
2493
|
+
retry: args.retry
|
|
2494
|
+
});
|
|
2495
|
+
if (input.datashipsSessionId === void 0 && input.resetBeacon !== false) {
|
|
2496
|
+
adapter.resetDatashipsSessionId?.();
|
|
2497
|
+
}
|
|
2498
|
+
};
|
|
2499
|
+
var postJson2 = async ({
|
|
2500
|
+
url,
|
|
2501
|
+
headers,
|
|
2502
|
+
body,
|
|
2503
|
+
fetch,
|
|
2504
|
+
retry
|
|
2505
|
+
}) => {
|
|
2506
|
+
let attempt = 0;
|
|
2507
|
+
while (true) {
|
|
2508
|
+
let response;
|
|
2509
|
+
let networkError;
|
|
2510
|
+
const attemptHeaders = typeof headers === "function" ? await headers() : headers;
|
|
2511
|
+
try {
|
|
2512
|
+
response = await fetch(url, {
|
|
2513
|
+
method: "POST",
|
|
2514
|
+
headers: { "Content-Type": "application/json", ...attemptHeaders },
|
|
2515
|
+
body: JSON.stringify(body)
|
|
2516
|
+
});
|
|
2517
|
+
} catch (err) {
|
|
2518
|
+
networkError = err;
|
|
2519
|
+
}
|
|
2520
|
+
const status = response?.status;
|
|
2521
|
+
const ok = response?.ok ?? false;
|
|
2522
|
+
if (ok && response) {
|
|
2523
|
+
const text = await response.text();
|
|
2524
|
+
return text ? JSON.parse(text) : void 0;
|
|
2525
|
+
}
|
|
2526
|
+
const errorBody = response ? await readBody2(response) : null;
|
|
2527
|
+
const errorCode = errorCodeFromBody2(errorBody) ?? void 0;
|
|
2528
|
+
if (!retry.shouldRetry(attempt, status, errorCode)) {
|
|
2529
|
+
if (networkError) throw networkError;
|
|
2530
|
+
throw new DatashipsError2({
|
|
2531
|
+
status: status ?? 0,
|
|
2532
|
+
body: errorBody,
|
|
2533
|
+
challenge: response?.headers.get("WWW-Authenticate") ?? null
|
|
2534
|
+
});
|
|
2535
|
+
}
|
|
2536
|
+
attempt += 1;
|
|
2537
|
+
const delay = retry.delayMs(attempt);
|
|
2538
|
+
if (delay > 0) await new Promise((r) => setTimeout(r, delay));
|
|
2539
|
+
}
|
|
2540
|
+
};
|
|
2541
|
+
var readBody2 = async (response) => {
|
|
2542
|
+
const text = await response.text();
|
|
2543
|
+
if (!text) return null;
|
|
2544
|
+
try {
|
|
2545
|
+
return JSON.parse(text);
|
|
2546
|
+
} catch {
|
|
2547
|
+
return text;
|
|
2548
|
+
}
|
|
2549
|
+
};
|
|
2550
|
+
var DEFAULT_HEARTBEAT_INTERVAL_MS2 = 210 * 1e3;
|
|
2551
|
+
var DEFAULT_HEARTBEAT_DURATION_MS2 = 10 * 60 * 1e3;
|
|
2552
|
+
var _auth2;
|
|
2553
|
+
var _fetch2;
|
|
2554
|
+
var _upsertSessionRetry2;
|
|
2555
|
+
var _defaultRetry2;
|
|
2556
|
+
var _DatashipsClient_instances2;
|
|
2557
|
+
var previewUpsertResponse_fn2;
|
|
2558
|
+
var credentialHeaders_fn2;
|
|
2559
|
+
var requireAuth_fn2;
|
|
2560
|
+
var requireConsentSessionId_fn2;
|
|
2561
|
+
var sendHeartbeat_fn2;
|
|
2562
|
+
var post_fn2;
|
|
2563
|
+
var send_fn;
|
|
2564
|
+
var DatashipsClient2 = class {
|
|
2565
|
+
constructor(opts) {
|
|
2566
|
+
__privateAdd5(this, _DatashipsClient_instances2);
|
|
2567
|
+
__privateAdd5(this, _auth2);
|
|
2568
|
+
__privateAdd5(this, _fetch2);
|
|
2569
|
+
__privateAdd5(this, _upsertSessionRetry2);
|
|
2570
|
+
__privateAdd5(this, _defaultRetry2);
|
|
2571
|
+
this.adapter = opts.adapter;
|
|
2572
|
+
if (opts.auth) assertBrowserAuth2(opts.auth);
|
|
2573
|
+
if (!opts.auth && !opts.adapter.previewMode) {
|
|
2574
|
+
throw new Error(
|
|
2575
|
+
"DatashipsClient: `auth: { publicKey, token }` (or `{ publicKey, getToken }`) is required unless the adapter runs in preview mode"
|
|
2576
|
+
);
|
|
2577
|
+
}
|
|
2578
|
+
this.publicKey = opts.auth && !isUnsafeServerKeyAuth2(opts.auth) ? opts.auth.publicKey : null;
|
|
2579
|
+
__privateSet5(this, _auth2, opts.auth ?? null);
|
|
2580
|
+
this.app = opts.app;
|
|
2581
|
+
this.version = opts.version;
|
|
2582
|
+
this.baseUrl = resolveBaseUrl2(opts.env, opts.baseUrl);
|
|
2583
|
+
__privateSet5(this, _fetch2, opts.fetch ?? globalThis.fetch.bind(globalThis));
|
|
2584
|
+
__privateSet5(this, _upsertSessionRetry2, opts.retry?.upsertSession ?? upsertSessionRetryPolicy2);
|
|
2585
|
+
__privateSet5(this, _defaultRetry2, opts.retry?.default ?? defaultRetryPolicy2);
|
|
2586
|
+
}
|
|
2587
|
+
/** The credentials in use, or null for a preview-mode client constructed without them. */
|
|
2588
|
+
get auth() {
|
|
2589
|
+
return __privateGet5(this, _auth2);
|
|
2590
|
+
}
|
|
2591
|
+
/** Whether this client runs on the unsafe server-key escape hatch. */
|
|
2592
|
+
get isUnsafeServerKey() {
|
|
2593
|
+
return __privateGet5(this, _auth2) !== null && isUnsafeServerKeyAuth2(__privateGet5(this, _auth2));
|
|
2594
|
+
}
|
|
2595
|
+
/**
|
|
2596
|
+
* Replace the Bearer token before it expires. The next call and any running
|
|
2597
|
+
* heartbeat use it; a missed rotation surfaces as a 401 on the next call.
|
|
2598
|
+
* Not applicable under `auth.getToken`, which already fetches one per request.
|
|
2599
|
+
*/
|
|
2600
|
+
setToken(token) {
|
|
2601
|
+
if (!__privateGet5(this, _auth2)) {
|
|
2602
|
+
throw new Error(
|
|
2603
|
+
"DatashipsClient: setToken() requires a client constructed with `auth`"
|
|
2604
|
+
);
|
|
2605
|
+
}
|
|
2606
|
+
if (isUnsafeServerKeyAuth2(__privateGet5(this, _auth2))) {
|
|
2607
|
+
throw new Error(
|
|
2608
|
+
"DatashipsClient: setToken() does not apply under auth.unsafeServerKey; there is no token to rotate"
|
|
2609
|
+
);
|
|
2610
|
+
}
|
|
2611
|
+
if (isTokenProviderAuth2(__privateGet5(this, _auth2))) {
|
|
2612
|
+
throw new Error(
|
|
2613
|
+
"DatashipsClient: setToken() does not apply under auth.getToken; the provider is called before every request"
|
|
2614
|
+
);
|
|
2615
|
+
}
|
|
2616
|
+
if (!token) {
|
|
2617
|
+
throw new Error("DatashipsClient: token must be a non-empty string");
|
|
2618
|
+
}
|
|
2619
|
+
__privateSet5(this, _auth2, { ...__privateGet5(this, _auth2), token });
|
|
2620
|
+
}
|
|
2621
|
+
/**
|
|
2622
|
+
* Open or update the consent session for one identifier type
|
|
2623
|
+
* (`POST /v1/consent-session`, contract v2). The client only states which
|
|
2624
|
+
* identifier type it holds; the server decides the channels and returns one
|
|
2625
|
+
* entry per channel to render. An empty `consents` means render nothing:
|
|
2626
|
+
* that also covers a 204 No Content (a surface that never collects, no
|
|
2627
|
+
* eligible channel, or a checkout that already asked on an earlier step) and
|
|
2628
|
+
* a user IP the API could not geolocate (422 COUNTRY_NOT_FOUND), both of
|
|
2629
|
+
* which resolve instead of throwing.
|
|
2630
|
+
*/
|
|
2631
|
+
async upsertSession(input) {
|
|
2632
|
+
const preview = __privateMethod5(this, _DatashipsClient_instances2, previewUpsertResponse_fn2).call(this, input.identifierType, input.format);
|
|
2633
|
+
if (preview) return preview;
|
|
2634
|
+
return upsertSession2({
|
|
2635
|
+
adapter: this.adapter,
|
|
2636
|
+
input,
|
|
2637
|
+
post: __privateMethod5(this, _DatashipsClient_instances2, post_fn2).bind(this),
|
|
2638
|
+
retry: __privateGet5(this, _upsertSessionRetry2)
|
|
2639
|
+
});
|
|
2640
|
+
}
|
|
2641
|
+
async saveConsent(input) {
|
|
2642
|
+
if (this.adapter.previewMode) return;
|
|
2643
|
+
await saveConsent2({
|
|
2644
|
+
consentSessionId: __privateMethod5(this, _DatashipsClient_instances2, requireConsentSessionId_fn2).call(this, input.session),
|
|
2645
|
+
channel: input.channel,
|
|
2646
|
+
consent: input.consent,
|
|
2647
|
+
post: __privateMethod5(this, _DatashipsClient_instances2, post_fn2).bind(this),
|
|
2648
|
+
retry: __privateGet5(this, _defaultRetry2)
|
|
2649
|
+
});
|
|
2650
|
+
}
|
|
2651
|
+
/**
|
|
2652
|
+
* Ask the backend to send an OTP verification code to the phone-channel
|
|
2653
|
+
* session's number. `referenceId` must be echoed back on
|
|
2654
|
+
* {@link submitVerificationCode}. Never retried — a retry could send the
|
|
2655
|
+
* buyer duplicate codes.
|
|
2656
|
+
*
|
|
2657
|
+
* In preview mode no code is sent and `{ userVerificationTriggered: false }` is
|
|
2658
|
+
* returned, mirroring a store without verification enabled.
|
|
2659
|
+
*/
|
|
2660
|
+
async triggerVerificationCode(input) {
|
|
2661
|
+
if (this.adapter.previewMode) {
|
|
2662
|
+
return {
|
|
2663
|
+
userVerificationTriggered: false,
|
|
2664
|
+
referenceId: null,
|
|
2665
|
+
codeLength: null,
|
|
2666
|
+
resendAfterSeconds: null
|
|
2667
|
+
};
|
|
2668
|
+
}
|
|
2669
|
+
return triggerVerificationCode2({
|
|
2670
|
+
consentSessionId: input.consentSessionId,
|
|
2671
|
+
post: __privateMethod5(this, _DatashipsClient_instances2, post_fn2).bind(this)
|
|
2672
|
+
});
|
|
2673
|
+
}
|
|
2674
|
+
/**
|
|
2675
|
+
* Submit the OTP code the buyer received. Resolves
|
|
2676
|
+
* `{ verified: true, errorCode: null }` on 2xx. A 400 rejection resolves
|
|
2677
|
+
* `{ verified: false, errorCode }` with the body's `errors[0].code` (see
|
|
2678
|
+
* `SUBMIT_VERIFICATION_CODE_ERROR_CODES`), or `null` when the body carries
|
|
2679
|
+
* none. Any other failure throws. Never retried — a rejection is definitive.
|
|
2680
|
+
*
|
|
2681
|
+
* In preview mode resolves verified without a network call.
|
|
2682
|
+
*/
|
|
2683
|
+
async submitVerificationCode(input) {
|
|
2684
|
+
if (this.adapter.previewMode) return { verified: true, errorCode: null };
|
|
2685
|
+
return submitVerificationCode2({
|
|
2686
|
+
...input,
|
|
2687
|
+
post: __privateMethod5(this, _DatashipsClient_instances2, post_fn2).bind(this)
|
|
2688
|
+
});
|
|
2689
|
+
}
|
|
2690
|
+
/**
|
|
2691
|
+
* Complete the sessions opened under a beacon: the placed order (or the
|
|
2692
|
+
* flow's equivalent) lands on every sibling session and processing is
|
|
2693
|
+
* queued (`POST /v1/consent-session/submit`).
|
|
2694
|
+
*
|
|
2695
|
+
* `user.firstName` / `lastName` are required (the backend refuses a blank
|
|
2696
|
+
* name; the SDK refuses it before sending), unless the adapter's
|
|
2697
|
+
* `submitRequiresUser` is false, as on the Alia form adapters: then `user` may be
|
|
2698
|
+
* omitted and the submit goes without it. The beacon defaults to the
|
|
2699
|
+
* adapter's own `datashipsSessionId`, which is then discarded once the
|
|
2700
|
+
* submit is accepted. Idempotent on the backend; a
|
|
2701
|
+
* beacon that matches no session is accepted silently. Retried on 409 and
|
|
2702
|
+
* server errors like any other call.
|
|
2703
|
+
*
|
|
2704
|
+
* In preview mode nothing is sent; the beacon is still discarded so a
|
|
2705
|
+
* styled sandbox behaves like a real checkout.
|
|
2706
|
+
*/
|
|
2707
|
+
async submitSession(input) {
|
|
2708
|
+
const adapter = this.adapter;
|
|
2709
|
+
if (adapter.previewMode) {
|
|
2710
|
+
if (input.datashipsSessionId === void 0 && input.resetBeacon !== false) {
|
|
2711
|
+
adapter.resetDatashipsSessionId?.();
|
|
2712
|
+
}
|
|
2713
|
+
return;
|
|
2714
|
+
}
|
|
2715
|
+
await submitSession2({
|
|
2716
|
+
adapter,
|
|
2717
|
+
input,
|
|
2718
|
+
post: __privateMethod5(this, _DatashipsClient_instances2, post_fn2).bind(this),
|
|
2719
|
+
retry: __privateGet5(this, _defaultRetry2)
|
|
2720
|
+
});
|
|
2721
|
+
}
|
|
2722
|
+
/**
|
|
2723
|
+
* Begin a periodic heartbeat. Returns an idempotent stop function. The
|
|
2724
|
+
* scheduler stops itself at the duration limit, when the credential is
|
|
2725
|
+
* refused (401 / 403) and when the session has already been processed; every
|
|
2726
|
+
* failure is reported through `onError`.
|
|
2727
|
+
*/
|
|
2728
|
+
startHeartbeat(session, opts = {}) {
|
|
2729
|
+
if (this.adapter.previewMode) return () => {
|
|
2730
|
+
};
|
|
2731
|
+
const intervalMs = opts.intervalMs ?? DEFAULT_HEARTBEAT_INTERVAL_MS2;
|
|
2732
|
+
const durationMs = opts.durationMs ?? DEFAULT_HEARTBEAT_DURATION_MS2;
|
|
2733
|
+
const startedAt = Date.now();
|
|
2734
|
+
let stopped = false;
|
|
2735
|
+
const stop = () => {
|
|
2736
|
+
if (stopped) return;
|
|
2737
|
+
stopped = true;
|
|
2738
|
+
clearInterval(handle);
|
|
2739
|
+
};
|
|
2740
|
+
const handle = setInterval(() => {
|
|
2741
|
+
if (Date.now() - startedAt >= durationMs) {
|
|
2742
|
+
stop();
|
|
2743
|
+
return;
|
|
2744
|
+
}
|
|
2745
|
+
__privateMethod5(this, _DatashipsClient_instances2, sendHeartbeat_fn2).call(this, session).catch((error) => {
|
|
2746
|
+
opts.onError?.(error);
|
|
2747
|
+
if (error instanceof DatashipsError2 && (error.isAuthenticationFailure || error.isSessionProcessed)) {
|
|
2748
|
+
stop();
|
|
2749
|
+
}
|
|
2750
|
+
});
|
|
2751
|
+
}, intervalMs);
|
|
2752
|
+
return stop;
|
|
2753
|
+
}
|
|
2754
|
+
};
|
|
2755
|
+
_auth2 = /* @__PURE__ */ new WeakMap();
|
|
2756
|
+
_fetch2 = /* @__PURE__ */ new WeakMap();
|
|
2757
|
+
_upsertSessionRetry2 = /* @__PURE__ */ new WeakMap();
|
|
2758
|
+
_defaultRetry2 = /* @__PURE__ */ new WeakMap();
|
|
2759
|
+
_DatashipsClient_instances2 = /* @__PURE__ */ new WeakSet();
|
|
2760
|
+
previewUpsertResponse_fn2 = function(identifierType, format) {
|
|
2761
|
+
if (this.adapter.previewMode && this.adapter.getPreviewUpsertResponse) {
|
|
2762
|
+
return this.adapter.getPreviewUpsertResponse(identifierType, format);
|
|
2763
|
+
}
|
|
2764
|
+
return null;
|
|
2765
|
+
};
|
|
2766
|
+
credentialHeaders_fn2 = async function() {
|
|
2767
|
+
const auth = __privateMethod5(this, _DatashipsClient_instances2, requireAuth_fn2).call(this);
|
|
2768
|
+
return authHeaders2(
|
|
2769
|
+
isTokenProviderAuth2(auth) ? await resolveTokenProviderAuth2(auth) : auth
|
|
2770
|
+
);
|
|
2771
|
+
};
|
|
2772
|
+
requireAuth_fn2 = function() {
|
|
2773
|
+
if (!__privateGet5(this, _auth2)) {
|
|
2774
|
+
throw new Error(
|
|
2775
|
+
"DatashipsClient: no credentials configured; pass `auth: { publicKey, token }`"
|
|
2776
|
+
);
|
|
2777
|
+
}
|
|
2778
|
+
return __privateGet5(this, _auth2);
|
|
2779
|
+
};
|
|
2780
|
+
requireConsentSessionId_fn2 = function(session) {
|
|
2781
|
+
if (!session.consentSessionId) {
|
|
2782
|
+
throw new Error(
|
|
2783
|
+
"DatashipsClient: consentSessionId is required"
|
|
2784
|
+
);
|
|
2785
|
+
}
|
|
2786
|
+
return session.consentSessionId;
|
|
2787
|
+
};
|
|
2788
|
+
sendHeartbeat_fn2 = async function(session) {
|
|
2789
|
+
await heartbeat2({
|
|
2790
|
+
consentSessionId: __privateMethod5(this, _DatashipsClient_instances2, requireConsentSessionId_fn2).call(this, session),
|
|
2791
|
+
post: __privateMethod5(this, _DatashipsClient_instances2, post_fn2).bind(this),
|
|
2792
|
+
retry: __privateGet5(this, _defaultRetry2)
|
|
2793
|
+
});
|
|
2794
|
+
};
|
|
2795
|
+
post_fn2 = async function(args) {
|
|
2796
|
+
try {
|
|
2797
|
+
return await __privateMethod5(this, _DatashipsClient_instances2, send_fn).call(this, args);
|
|
2798
|
+
} catch (error) {
|
|
2799
|
+
const auth = __privateGet5(this, _auth2);
|
|
2800
|
+
if (!(error instanceof DatashipsError2) || error.status !== 401 || !auth || !isTokenProviderAuth2(auth) || !auth.onUnauthorized) {
|
|
2801
|
+
throw error;
|
|
2802
|
+
}
|
|
2803
|
+
let credentials;
|
|
2804
|
+
try {
|
|
2805
|
+
await auth.onUnauthorized();
|
|
2806
|
+
credentials = await __privateMethod5(this, _DatashipsClient_instances2, credentialHeaders_fn2).call(this);
|
|
2807
|
+
} catch {
|
|
2808
|
+
throw error;
|
|
2809
|
+
}
|
|
2810
|
+
return __privateMethod5(this, _DatashipsClient_instances2, send_fn).call(this, { ...args, retry: noRetryPolicy2 }, credentials);
|
|
2811
|
+
}
|
|
2812
|
+
};
|
|
2813
|
+
send_fn = async function(args, credentials) {
|
|
2814
|
+
let pending = credentials;
|
|
2815
|
+
const staticHeaders = {
|
|
2816
|
+
// The marker lets the backend tell an exposed key in a page from a genuine server call.
|
|
2817
|
+
"X-Dataships-App": `${this.app} (SDK: ${this.adapter.name}${this.isUnsafeServerKey ? `; ${UNSAFE_SERVER_KEY_APP_MARKER2}` : ""})`,
|
|
2818
|
+
"X-Dataships-Version": `${this.version} (SDK: ${"2.5.0"})`
|
|
2819
|
+
};
|
|
2820
|
+
return postJson2({
|
|
2821
|
+
url: `${this.baseUrl}${args.path}`,
|
|
2822
|
+
// Resolved per attempt so a token provider hands every retry a fresh token.
|
|
2823
|
+
headers: async () => {
|
|
2824
|
+
const resolved = pending ?? await __privateMethod5(this, _DatashipsClient_instances2, credentialHeaders_fn2).call(this);
|
|
2825
|
+
pending = void 0;
|
|
2826
|
+
return { ...resolved, ...staticHeaders };
|
|
2827
|
+
},
|
|
2828
|
+
body: args.body,
|
|
2829
|
+
fetch: __privateGet5(this, _fetch2),
|
|
2830
|
+
retry: args.retry
|
|
2831
|
+
});
|
|
2832
|
+
};
|
|
2833
|
+
|
|
2834
|
+
// node_modules/@dataships/sdk/dist/adapters/alia-form/index.js
|
|
2835
|
+
var __typeError6 = (msg) => {
|
|
2836
|
+
throw TypeError(msg);
|
|
2837
|
+
};
|
|
2838
|
+
var __accessCheck6 = (obj, member, msg) => member.has(obj) || __typeError6("Cannot " + msg);
|
|
2839
|
+
var __privateGet6 = (obj, member, getter) => (__accessCheck6(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
2840
|
+
var __privateAdd6 = (obj, member, value) => member.has(obj) ? __typeError6("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
2841
|
+
var __privateSet6 = (obj, member, value, setter) => (__accessCheck6(obj, member, "write to private field"), member.set(obj, value), value);
|
|
2842
|
+
var DEFAULT_EMAIL_OPT_IN_TEXT3 = "We would like to email you news and promotions. Tick to opt in.";
|
|
2843
|
+
var DEFAULT_EMAIL_OPT_IN_CONSENT_DESCRIPTION3 = "Click here for an overview of how your personal data is processed for marketing purposes or see our Privacy Policy for further information.";
|
|
2844
|
+
var DEFAULT_SMS_OPT_IN_TEXT3 = "We would like to text you news and promotions. Tick to opt in.";
|
|
2845
|
+
var DEFAULT_SMS_OPT_IN_CONSENT_DESCRIPTION3 = "Based on the channel preferences set above, you agree to receive recurring automated marketing messages (e.g. AI content, cart reminders) from {{COMPANY_NAME}} at the number you provide. Consent is not a condition of purchase. We may share info with service providers per our Privacy Policy. Reply STOP to cancel or click the unsubscribe link (where available). For help reply HELP or email {{PRIVACY_EMAIL}}. Msg frequency varies. Msg & data rates may apply. By proceeding, you also agree to our Terms of Service (incl. arbitration) & Privacy Policy.";
|
|
2846
|
+
var fakeEmailUpsertResponse3 = {
|
|
2847
|
+
consentSessionId: "01HQB3QRZVV0737R0R25BTQBGF",
|
|
2848
|
+
consents: [
|
|
2849
|
+
{
|
|
2850
|
+
channel: "EMAIL",
|
|
2851
|
+
consentType: "OPT_IN",
|
|
2852
|
+
checked: false,
|
|
2853
|
+
widgetConfig: {
|
|
2854
|
+
text: DEFAULT_EMAIL_OPT_IN_TEXT3,
|
|
2855
|
+
consentDescription: DEFAULT_EMAIL_OPT_IN_CONSENT_DESCRIPTION3,
|
|
2856
|
+
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',
|
|
2857
|
+
policyURL: "https://dataships.io/privacy-centre",
|
|
2858
|
+
mobileTermsOfServiceURL: null,
|
|
2859
|
+
privacyEmail: "privacy@example.com",
|
|
2860
|
+
placeholderValues: null
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
],
|
|
2864
|
+
userVerificationRequired: null,
|
|
2865
|
+
lastHeartbeat: "2026-06-17T00:00:00Z",
|
|
2866
|
+
identifier: null
|
|
2867
|
+
};
|
|
2868
|
+
var fakePhoneUpsertResponse3 = {
|
|
2869
|
+
consentSessionId: "01HQB3QRZVV0737R0R25BTQBGG",
|
|
2870
|
+
consents: [
|
|
2871
|
+
{
|
|
2872
|
+
channel: "SMS",
|
|
2873
|
+
consentType: "OPT_IN",
|
|
2874
|
+
checked: false,
|
|
2875
|
+
widgetConfig: {
|
|
2876
|
+
text: DEFAULT_SMS_OPT_IN_TEXT3,
|
|
2877
|
+
consentDescription: DEFAULT_SMS_OPT_IN_CONSENT_DESCRIPTION3,
|
|
2878
|
+
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',
|
|
2879
|
+
policyURL: "https://dataships.io/privacy-centre",
|
|
2880
|
+
mobileTermsOfServiceURL: "https://dataships.io/mobile-terms",
|
|
2881
|
+
privacyEmail: "privacy@example.com",
|
|
2882
|
+
placeholderValues: null
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
],
|
|
2886
|
+
userVerificationRequired: false,
|
|
2887
|
+
lastHeartbeat: "2026-06-17T00:00:00Z",
|
|
2888
|
+
identifier: null
|
|
2889
|
+
};
|
|
2890
|
+
var MARKETING_MODAL_HREF3 = "#dataships-marketing-modal";
|
|
2891
|
+
var CHECKBOX_LABEL_BOLD_PHRASES3 = ["consent", "object", "opt in", "opt out", "STOP", "HELP"];
|
|
2892
|
+
var CONSENT_DESCRIPTION_BOLD_PHRASES3 = ["STOP", "HELP"];
|
|
2893
|
+
var escapeHtml3 = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
2894
|
+
var escapeRegExp4 = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2895
|
+
var wrapPhrase3 = (html, phrase, wrap) => html.replace(
|
|
2896
|
+
new RegExp(`${escapeRegExp4(escapeHtml3(phrase))}(?![^<]*>)(?![^<]*</a>)`, "gi"),
|
|
2897
|
+
wrap
|
|
2898
|
+
);
|
|
2899
|
+
var toHtmlCopy3 = (text, widgetConfig, boldPhrases) => {
|
|
2900
|
+
let html = escapeHtml3(text);
|
|
2901
|
+
const links = [
|
|
2902
|
+
["Terms of Service", widgetConfig.mobileTermsOfServiceURL],
|
|
2903
|
+
["Privacy Policy", widgetConfig.policyURL],
|
|
2904
|
+
["Click here", MARKETING_MODAL_HREF3]
|
|
2905
|
+
];
|
|
2906
|
+
for (const [phrase, href] of links) {
|
|
2907
|
+
if (!href) continue;
|
|
2908
|
+
html = wrapPhrase3(html, phrase, (match) => `<a href="${escapeHtml3(href)}">${match}</a>`);
|
|
2909
|
+
}
|
|
2910
|
+
for (const phrase of boldPhrases) {
|
|
2911
|
+
html = wrapPhrase3(html, phrase, (match) => `<strong>${match}</strong>`);
|
|
2912
|
+
}
|
|
2913
|
+
return `<p>${html}</p>`;
|
|
2914
|
+
};
|
|
2915
|
+
var withHtmlCopy3 = (response) => ({
|
|
2916
|
+
...response,
|
|
2917
|
+
consents: response.consents.map((consent) => {
|
|
2918
|
+
const { widgetConfig } = consent;
|
|
2919
|
+
return {
|
|
2920
|
+
...consent,
|
|
2921
|
+
widgetConfig: {
|
|
2922
|
+
...widgetConfig,
|
|
2923
|
+
text: widgetConfig.text === null ? null : toHtmlCopy3(widgetConfig.text, widgetConfig, CHECKBOX_LABEL_BOLD_PHRASES3),
|
|
2924
|
+
consentDescription: widgetConfig.consentDescription === null ? null : toHtmlCopy3(
|
|
2925
|
+
widgetConfig.consentDescription,
|
|
2926
|
+
widgetConfig,
|
|
2927
|
+
CONSENT_DESCRIPTION_BOLD_PHRASES3
|
|
2928
|
+
)
|
|
2929
|
+
}
|
|
2930
|
+
};
|
|
2931
|
+
})
|
|
2932
|
+
});
|
|
2933
|
+
var previewUpsertResponse3 = (identifierType, format = "json") => {
|
|
2934
|
+
const response = identifierType === "PHONE" ? fakePhoneUpsertResponse3 : fakeEmailUpsertResponse3;
|
|
2935
|
+
return format === "html" ? withHtmlCopy3(response) : response;
|
|
2936
|
+
};
|
|
2937
|
+
var SUPPORTED_LOCALES3 = [
|
|
2938
|
+
"en",
|
|
2939
|
+
"es",
|
|
2940
|
+
"de",
|
|
2941
|
+
"pt",
|
|
2942
|
+
"ro",
|
|
2943
|
+
"hr",
|
|
2944
|
+
"da",
|
|
2945
|
+
"fi",
|
|
2946
|
+
"fr",
|
|
2947
|
+
"hu",
|
|
2948
|
+
"it",
|
|
2949
|
+
"nb",
|
|
2950
|
+
"pl",
|
|
2951
|
+
"sk",
|
|
2952
|
+
"sv",
|
|
2953
|
+
"nl",
|
|
2954
|
+
"el",
|
|
2955
|
+
"cs",
|
|
2956
|
+
"zh",
|
|
2387
2957
|
"ja",
|
|
2388
2958
|
"is"
|
|
2389
2959
|
];
|
|
@@ -2392,70 +2962,102 @@ var coerceLocale3 = (raw) => {
|
|
|
2392
2962
|
const head = raw.split(/[_-]/)[0]?.toLowerCase() ?? "";
|
|
2393
2963
|
return SUPPORTED_LOCALES3.includes(head) ? head : "en";
|
|
2394
2964
|
};
|
|
2395
|
-
var
|
|
2396
|
-
var
|
|
2965
|
+
var ALIA_FORM_RENDER_INTEGRATION_TYPE = "ALIA_FORM_RENDER";
|
|
2966
|
+
var ALIA_FORM_LISTEN_INTEGRATION_TYPE = "ALIA_FORM_LISTEN";
|
|
2967
|
+
var _datashipsSessionId;
|
|
2397
2968
|
var _campaignId;
|
|
2398
2969
|
var _locale3;
|
|
2399
|
-
var
|
|
2400
|
-
|
|
2401
|
-
constructor(opts) {
|
|
2402
|
-
this.name = "AliaFormAdapter";
|
|
2970
|
+
var AliaFormAdapterBase = class {
|
|
2971
|
+
constructor(adapterName, opts) {
|
|
2403
2972
|
this.sessionApi = "consent-session";
|
|
2404
|
-
this.integrationType = ALIA_FORM_INTEGRATION_TYPE;
|
|
2405
2973
|
this.submitRequiresUser = false;
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
__privateSet5(this, _locale3, coerceLocale3(opts.locale));
|
|
2413
|
-
__privateSet5(this, _beacon3, new SessionBeacon3({
|
|
2414
|
-
storageKey: `${STORAGE_KEY_PREFIX3}${storageScope}:${popupId}`,
|
|
2415
|
-
window: opts.window
|
|
2416
|
-
}));
|
|
2417
|
-
this.previewMode = opts.previewMode ?? false;
|
|
2418
|
-
}
|
|
2419
|
-
/** Synthetic upsert response served in {@link previewMode}, matching the requested identifier type. */
|
|
2420
|
-
getPreviewUpsertResponse(identifierType = "EMAIL") {
|
|
2421
|
-
return previewUpsertResponse3(identifierType);
|
|
2974
|
+
__privateAdd6(this, _datashipsSessionId);
|
|
2975
|
+
__privateAdd6(this, _campaignId);
|
|
2976
|
+
__privateAdd6(this, _locale3);
|
|
2977
|
+
__privateSet6(this, _datashipsSessionId, required(adapterName, opts.datashipsSessionId, "datashipsSessionId"));
|
|
2978
|
+
__privateSet6(this, _campaignId, required(adapterName, opts.campaignId, "campaignId"));
|
|
2979
|
+
__privateSet6(this, _locale3, coerceLocale3(opts.locale));
|
|
2422
2980
|
}
|
|
2423
2981
|
getLocale() {
|
|
2424
|
-
return
|
|
2982
|
+
return __privateGet6(this, _locale3);
|
|
2425
2983
|
}
|
|
2426
2984
|
/** Change the envelope locale, e.g. when the visitor switches language. */
|
|
2427
2985
|
setLocale(locale) {
|
|
2428
|
-
|
|
2986
|
+
__privateSet6(this, _locale3, coerceLocale3(locale));
|
|
2429
2987
|
}
|
|
2430
2988
|
/** The adapter holds no contact: the popup's field is passed to `upsertSession({ identifier })`. */
|
|
2431
2989
|
getIdentifier(identifierType) {
|
|
2432
2990
|
return { identifier: null, identifierType };
|
|
2433
2991
|
}
|
|
2434
|
-
/** The
|
|
2992
|
+
/** The id the adapter was given; a submit leaves it in place. */
|
|
2435
2993
|
getDatashipsSessionId() {
|
|
2436
|
-
return
|
|
2437
|
-
}
|
|
2438
|
-
/** Discard the current beacon so the next call mints a fresh one, e.g. on every `alia:popupView`. */
|
|
2439
|
-
resetDatashipsSessionId() {
|
|
2440
|
-
__privateGet5(this, _beacon3).reset();
|
|
2994
|
+
return __privateGet6(this, _datashipsSessionId);
|
|
2441
2995
|
}
|
|
2442
|
-
|
|
2443
|
-
return { datashipsSessionId: this
|
|
2996
|
+
baseSessionContext() {
|
|
2997
|
+
return { datashipsSessionId: __privateGet6(this, _datashipsSessionId), campaignId: __privateGet6(this, _campaignId) };
|
|
2444
2998
|
}
|
|
2445
2999
|
};
|
|
3000
|
+
_datashipsSessionId = /* @__PURE__ */ new WeakMap();
|
|
2446
3001
|
_campaignId = /* @__PURE__ */ new WeakMap();
|
|
2447
3002
|
_locale3 = /* @__PURE__ */ new WeakMap();
|
|
2448
|
-
|
|
2449
|
-
|
|
3003
|
+
var AliaFormRenderAdapter = class extends AliaFormAdapterBase {
|
|
3004
|
+
constructor(opts) {
|
|
3005
|
+
super("AliaFormRenderAdapter", opts);
|
|
3006
|
+
this.name = "AliaFormRenderAdapter";
|
|
3007
|
+
this.integrationType = ALIA_FORM_RENDER_INTEGRATION_TYPE;
|
|
3008
|
+
this.previewMode = opts.previewMode ?? false;
|
|
3009
|
+
}
|
|
3010
|
+
/** Synthetic upsert response served in {@link previewMode}, matching the requested identifier type. */
|
|
3011
|
+
getPreviewUpsertResponse(identifierType = "EMAIL") {
|
|
3012
|
+
return previewUpsertResponse3(identifierType);
|
|
3013
|
+
}
|
|
3014
|
+
async getSessionContext() {
|
|
3015
|
+
return this.baseSessionContext();
|
|
3016
|
+
}
|
|
3017
|
+
};
|
|
3018
|
+
var _disclosureText;
|
|
3019
|
+
var _privacyPolicyUrl;
|
|
3020
|
+
var _termsUrl;
|
|
3021
|
+
var AliaFormListenAdapter = class extends AliaFormAdapterBase {
|
|
3022
|
+
constructor(opts) {
|
|
3023
|
+
super("AliaFormListenAdapter", opts);
|
|
3024
|
+
this.name = "AliaFormListenAdapter";
|
|
3025
|
+
this.integrationType = ALIA_FORM_LISTEN_INTEGRATION_TYPE;
|
|
3026
|
+
__privateAdd6(this, _disclosureText);
|
|
3027
|
+
__privateAdd6(this, _privacyPolicyUrl);
|
|
3028
|
+
__privateAdd6(this, _termsUrl);
|
|
3029
|
+
__privateSet6(this, _disclosureText, optional(opts.disclosureText));
|
|
3030
|
+
__privateSet6(this, _privacyPolicyUrl, optional(opts.privacyPolicyUrl));
|
|
3031
|
+
__privateSet6(this, _termsUrl, optional(opts.termsUrl));
|
|
3032
|
+
}
|
|
3033
|
+
async getSessionContext() {
|
|
3034
|
+
return {
|
|
3035
|
+
...this.baseSessionContext(),
|
|
3036
|
+
...__privateGet6(this, _disclosureText) === void 0 ? {} : { disclosureText: __privateGet6(this, _disclosureText) },
|
|
3037
|
+
...__privateGet6(this, _privacyPolicyUrl) === void 0 ? {} : { privacyPolicyUrl: __privateGet6(this, _privacyPolicyUrl) },
|
|
3038
|
+
...__privateGet6(this, _termsUrl) === void 0 ? {} : { termsUrl: __privateGet6(this, _termsUrl) }
|
|
3039
|
+
};
|
|
3040
|
+
}
|
|
3041
|
+
};
|
|
3042
|
+
_disclosureText = /* @__PURE__ */ new WeakMap();
|
|
3043
|
+
_privacyPolicyUrl = /* @__PURE__ */ new WeakMap();
|
|
3044
|
+
_termsUrl = /* @__PURE__ */ new WeakMap();
|
|
3045
|
+
var required = (adapterName, value, option) => {
|
|
2450
3046
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
2451
|
-
throw new Error(
|
|
3047
|
+
throw new Error(`${adapterName}: ${option} must be a non-empty string`);
|
|
2452
3048
|
}
|
|
2453
3049
|
return value;
|
|
2454
3050
|
};
|
|
3051
|
+
var optional = (value) => typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
2455
3052
|
|
|
2456
3053
|
// src/modules/alia/template.ts
|
|
2457
3054
|
var EMAIL_CONSENT = /\{\{\s*email_consent\s*\}\}/;
|
|
3055
|
+
var SMS_CONSENT = /\{\{\s*sms_consent\s*\}\}/;
|
|
2458
3056
|
var ANY_CONSENT = /\{\{\s*\w+_consent\s*\}\}/;
|
|
3057
|
+
var hasOwnWording = (markdown) => {
|
|
3058
|
+
const rest = markdown.replace(new RegExp(EMAIL_CONSENT, "g"), "");
|
|
3059
|
+
return rest.trim() !== "" && !ANY_CONSENT.test(rest);
|
|
3060
|
+
};
|
|
2459
3061
|
var FIBER_KEY_PREFIX = "__reactFiber$";
|
|
2460
3062
|
var MAX_HOPS = 60;
|
|
2461
3063
|
var MAX_DEPTH = 40;
|
|
@@ -2488,13 +3090,13 @@ var readSteps = (root) => {
|
|
|
2488
3090
|
}
|
|
2489
3091
|
return null;
|
|
2490
3092
|
};
|
|
2491
|
-
var findPlaceholderId = (steps) => {
|
|
3093
|
+
var findPlaceholderId = (steps, placeholder) => {
|
|
2492
3094
|
let visited = 0;
|
|
2493
3095
|
const search = (entry, depth) => {
|
|
2494
3096
|
if (!isBag(entry) || depth > MAX_DEPTH || ++visited > MAX_NODES)
|
|
2495
3097
|
return null;
|
|
2496
3098
|
const { node, id, children } = entry;
|
|
2497
|
-
if (isBag(node) && typeof node.markdown === "string" &&
|
|
3099
|
+
if (isBag(node) && typeof node.markdown === "string" && placeholder.test(node.markdown) && typeof id === "string" && SAFE_ID.test(id))
|
|
2498
3100
|
return id;
|
|
2499
3101
|
if (!Array.isArray(children)) return null;
|
|
2500
3102
|
for (const child of children) {
|
|
@@ -2509,14 +3111,14 @@ var findPlaceholderId = (steps) => {
|
|
|
2509
3111
|
}
|
|
2510
3112
|
return null;
|
|
2511
3113
|
};
|
|
2512
|
-
var findOwnText = (steps) => {
|
|
3114
|
+
var findOwnText = (steps, inputType) => {
|
|
2513
3115
|
let visited = 0;
|
|
2514
3116
|
const walk = (entry, depth, found) => {
|
|
2515
3117
|
if (!isBag(entry) || depth > MAX_DEPTH || ++visited > MAX_NODES) return;
|
|
2516
3118
|
const { node, id, children } = entry;
|
|
2517
3119
|
if (isBag(node)) {
|
|
2518
|
-
if (node.type ===
|
|
2519
|
-
if (node.sharedStyle === COMPLIANCE_STYLE && typeof node.markdown === "string" &&
|
|
3120
|
+
if (node.type === inputType) found.input = true;
|
|
3121
|
+
if (node.sharedStyle === COMPLIANCE_STYLE && typeof node.markdown === "string" && hasOwnWording(node.markdown) && typeof id === "string" && SAFE_ID.test(id))
|
|
2520
3122
|
found.ids.push(id);
|
|
2521
3123
|
}
|
|
2522
3124
|
if (Array.isArray(children))
|
|
@@ -2524,29 +3126,108 @@ var findOwnText = (steps) => {
|
|
|
2524
3126
|
};
|
|
2525
3127
|
const ids = [];
|
|
2526
3128
|
for (const step of steps) {
|
|
2527
|
-
const found = {
|
|
3129
|
+
const found = { input: false, ids: [] };
|
|
2528
3130
|
walk(step, 0, found);
|
|
2529
|
-
if (found.
|
|
3131
|
+
if (found.input) ids.push(...found.ids);
|
|
2530
3132
|
}
|
|
2531
3133
|
return ids;
|
|
2532
3134
|
};
|
|
2533
|
-
var
|
|
3135
|
+
var readDisclosure = (root, placeholder, inputType) => {
|
|
2534
3136
|
try {
|
|
2535
3137
|
const steps = readSteps(root);
|
|
2536
3138
|
if (!steps) return { kind: "unreadable" };
|
|
2537
|
-
const id = findPlaceholderId(steps);
|
|
2538
|
-
const ownText = findOwnText(steps);
|
|
3139
|
+
const id = findPlaceholderId(steps, placeholder);
|
|
3140
|
+
const ownText = findOwnText(steps, inputType);
|
|
2539
3141
|
return id ? { kind: "placeholder", id, ownText } : { kind: "none", ownText };
|
|
2540
3142
|
} catch {
|
|
2541
3143
|
return { kind: "unreadable" };
|
|
2542
3144
|
}
|
|
2543
3145
|
};
|
|
3146
|
+
var readEmailDisclosure = (root) => readDisclosure(root, EMAIL_CONSENT, "emailInput");
|
|
3147
|
+
var readSmsDisclosure = (root) => readDisclosure(root, SMS_CONSENT, "phoneInput");
|
|
2544
3148
|
|
|
2545
3149
|
// src/modules/alia/popups.ts
|
|
2546
3150
|
var ANCHOR_ATTRIBUTE = "data-dataships-anchor";
|
|
2547
3151
|
var STYLE_ATTRIBUTE = "data-dataships-launcher";
|
|
3152
|
+
var PENDING_ATTRIBUTE = "data-dataships-pending";
|
|
3153
|
+
var PENDING_LIMIT_MS = 3e4;
|
|
3154
|
+
var LOOK_ATTRIBUTE = "data-dataships-launcher-look";
|
|
3155
|
+
var FALLBACK_CLASS = "dataships-form-text";
|
|
3156
|
+
var COMPLIANCE_CLASS = "alia-style-compliance";
|
|
3157
|
+
var ALIA_STYLE_CLASS = /^alia-style-[\w-]+$/;
|
|
3158
|
+
var SCREEN_READER_ONLY = ".sr-only";
|
|
3159
|
+
var LOOK_PROPERTIES = [
|
|
3160
|
+
"color",
|
|
3161
|
+
"font-family",
|
|
3162
|
+
"font-size",
|
|
3163
|
+
"font-weight",
|
|
3164
|
+
"font-style",
|
|
3165
|
+
"line-height",
|
|
3166
|
+
"letter-spacing",
|
|
3167
|
+
"text-align",
|
|
3168
|
+
"text-transform",
|
|
3169
|
+
"opacity",
|
|
3170
|
+
"margin-top",
|
|
3171
|
+
"margin-bottom",
|
|
3172
|
+
"padding-top",
|
|
3173
|
+
"padding-right",
|
|
3174
|
+
"padding-bottom",
|
|
3175
|
+
"padding-left",
|
|
3176
|
+
"align-self"
|
|
3177
|
+
];
|
|
3178
|
+
var UNSAFE_CSS_VALUE = /[{}<;]/;
|
|
2548
3179
|
var SAFE_ID2 = /^[\w-]+$/;
|
|
2549
3180
|
var EMAIL_INPUT = 'input[name="email"]';
|
|
3181
|
+
var PHONE_INPUT = 'input[name="phone"]';
|
|
3182
|
+
var lookOf = (source) => {
|
|
3183
|
+
const view = source.ownerDocument.defaultView;
|
|
3184
|
+
if (!view) return "";
|
|
3185
|
+
const computed = view.getComputedStyle(source);
|
|
3186
|
+
const value = (property) => {
|
|
3187
|
+
const found = computed.getPropertyValue(property).trim();
|
|
3188
|
+
return UNSAFE_CSS_VALUE.test(found) ? "" : found;
|
|
3189
|
+
};
|
|
3190
|
+
const declarations = [];
|
|
3191
|
+
for (const property of LOOK_PROPERTIES) {
|
|
3192
|
+
const found = value(property);
|
|
3193
|
+
if (found) declarations.push(`${property}:${found}`);
|
|
3194
|
+
}
|
|
3195
|
+
const left = value("margin-left");
|
|
3196
|
+
const right = value("margin-right");
|
|
3197
|
+
if (left && left === right && parseFloat(left) > 0)
|
|
3198
|
+
declarations.push("margin-left:auto", "margin-right:auto");
|
|
3199
|
+
else {
|
|
3200
|
+
if (left) declarations.push(`margin-left:${left}`);
|
|
3201
|
+
if (right) declarations.push(`margin-right:${right}`);
|
|
3202
|
+
}
|
|
3203
|
+
const width = source.getBoundingClientRect().width;
|
|
3204
|
+
if (width > 0)
|
|
3205
|
+
declarations.push(
|
|
3206
|
+
"box-sizing:border-box",
|
|
3207
|
+
`max-width:${Math.ceil(width)}px`
|
|
3208
|
+
);
|
|
3209
|
+
return declarations.join(";");
|
|
3210
|
+
};
|
|
3211
|
+
var classOf = (source) => Array.from(source.classList).filter((name) => ALIA_STYLE_CLASS.test(name)).join(" ") || FALLBACK_CLASS;
|
|
3212
|
+
var textOf = (elements) => elements.map((element) => {
|
|
3213
|
+
const copy = element.cloneNode(true);
|
|
3214
|
+
for (const hidden of Array.from(
|
|
3215
|
+
copy.querySelectorAll(SCREEN_READER_ONLY)
|
|
3216
|
+
))
|
|
3217
|
+
hidden.remove();
|
|
3218
|
+
return (copy.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
3219
|
+
}).filter((text) => text !== "").join(" ");
|
|
3220
|
+
var linkOf = (elements, kind) => {
|
|
3221
|
+
for (const element of elements)
|
|
3222
|
+
for (const link of Array.from(
|
|
3223
|
+
element.querySelectorAll("a[href]")
|
|
3224
|
+
)) {
|
|
3225
|
+
const href = link.href;
|
|
3226
|
+
if (!/^https?:\/\//i.test(href)) continue;
|
|
3227
|
+
if (kind.test(textOf([link])) || kind.test(href)) return href;
|
|
3228
|
+
}
|
|
3229
|
+
return void 0;
|
|
3230
|
+
};
|
|
2550
3231
|
var idOf = (value) => {
|
|
2551
3232
|
const id = typeof value === "number" || typeof value === "string" ? `${value}` : "";
|
|
2552
3233
|
return SAFE_ID2.test(id) ? id : null;
|
|
@@ -2562,45 +3243,208 @@ var watchPopups = (context, deps) => {
|
|
|
2562
3243
|
popup.observer = null;
|
|
2563
3244
|
};
|
|
2564
3245
|
const track = (popupId, campaignId) => {
|
|
2565
|
-
const popup = {
|
|
3246
|
+
const popup = {
|
|
3247
|
+
handle: null,
|
|
3248
|
+
emailSettled: false,
|
|
3249
|
+
sms: null,
|
|
3250
|
+
observer: null,
|
|
3251
|
+
watched: null
|
|
3252
|
+
};
|
|
2566
3253
|
popups.set(popupId, popup);
|
|
2567
3254
|
const buttonSelector = `[${ANCHOR_ATTRIBUTE}="${popupId}"]`;
|
|
2568
|
-
const
|
|
3255
|
+
const smsButtonMark = `${popupId}-sms`;
|
|
3256
|
+
const smsButtonSelector = `[${ANCHOR_ATTRIBUTE}="${smsButtonMark}"]`;
|
|
3257
|
+
const smsType = context.preview ? "SINGLE" : context.elements.find((element) => element.id === campaignId)?.channels.find((entry) => entry.channel === "SMS")?.subscriptionType;
|
|
3258
|
+
const popupRootOf = (shadow) => shadow ? '[id^="alia-popup-root-"]' : `#alia-root-${popupId}`;
|
|
3259
|
+
const inPopup = (selector, shadow) => shadow ? selector : `#alia-root-${popupId} ${selector}`;
|
|
3260
|
+
const renderClientOptions = () => ({
|
|
3261
|
+
campaignId,
|
|
3262
|
+
datashipsSessionId: context.datashipsSessionId,
|
|
3263
|
+
publicKey: context.publicKey,
|
|
3264
|
+
baseUrl: context.baseUrl,
|
|
3265
|
+
auth: context.auth,
|
|
3266
|
+
preview: context.preview
|
|
3267
|
+
});
|
|
3268
|
+
const hideOwnText = (handle, ownText, shadow) => {
|
|
2569
3269
|
if (ownText.length === 0) return;
|
|
2570
|
-
const
|
|
3270
|
+
const widget = handle.element;
|
|
3271
|
+
const popupRoot = popupRootOf(shadow);
|
|
2571
3272
|
const shown = `${popupRoot}:has(${widget.localName}[data-visible])`;
|
|
3273
|
+
const pending = `${popupRoot}:has(${widget.localName}[${PENDING_ATTRIBUTE}])`;
|
|
3274
|
+
widget.setAttribute(PENDING_ATTRIBUTE, "");
|
|
3275
|
+
const settle = () => widget.removeAttribute(PENDING_ATTRIBUTE);
|
|
3276
|
+
const limit = setTimeout(settle, PENDING_LIMIT_MS);
|
|
3277
|
+
void handle.ready.then(() => {
|
|
3278
|
+
clearTimeout(limit);
|
|
3279
|
+
settle();
|
|
3280
|
+
});
|
|
2572
3281
|
const style = document.createElement("style");
|
|
2573
3282
|
style.setAttribute(STYLE_ATTRIBUTE, popupId);
|
|
2574
|
-
style.textContent = ownText.map(
|
|
3283
|
+
style.textContent = ownText.map(
|
|
3284
|
+
(id) => `${pending} #${id}{visibility:hidden!important}${shown} #${id}{display:none!important}`
|
|
3285
|
+
).join("");
|
|
2575
3286
|
(shadow ?? document.head).appendChild(style);
|
|
2576
3287
|
};
|
|
2577
|
-
const
|
|
3288
|
+
const giveLook = (widget, mount2, look, shadow) => {
|
|
3289
|
+
if (!look) return;
|
|
3290
|
+
const style = document.createElement("style");
|
|
3291
|
+
style.setAttribute(LOOK_ATTRIBUTE, popupId);
|
|
3292
|
+
style.textContent = `${popupRootOf(shadow)} ${mount2} + ${widget.localName}{${look}}`;
|
|
3293
|
+
(shadow ?? document.head).appendChild(style);
|
|
3294
|
+
};
|
|
3295
|
+
const mountAt = (step, mount2, ownText, source, shadow) => {
|
|
3296
|
+
const look = source ? lookOf(source) : "";
|
|
2578
3297
|
const handle = deps.mount({
|
|
2579
3298
|
page: "form",
|
|
2580
3299
|
publicKey: context.publicKey,
|
|
2581
|
-
client: deps.
|
|
2582
|
-
campaignId,
|
|
2583
|
-
popupId,
|
|
2584
|
-
publicKey: context.publicKey,
|
|
2585
|
-
baseUrl: context.baseUrl,
|
|
2586
|
-
token: context.token,
|
|
2587
|
-
preview: context.preview
|
|
2588
|
-
}),
|
|
3300
|
+
client: deps.createRenderClient(renderClientOptions()),
|
|
2589
3301
|
mount: mount2,
|
|
2590
3302
|
position: "after",
|
|
2591
|
-
|
|
2592
|
-
|
|
3303
|
+
...step,
|
|
3304
|
+
className: source ? classOf(source) : COMPLIANCE_CLASS,
|
|
3305
|
+
// Elements labels the widget as a preview only when told.
|
|
3306
|
+
preview: context.preview,
|
|
2593
3307
|
...shadow ? { root: shadow } : {},
|
|
3308
|
+
// The submit names the campaign, because one session id can hold several campaigns'
|
|
3309
|
+
// sessions, and the step's identifier type, so it completes this step's session only
|
|
3310
|
+
// and never contends with the other step's calls.
|
|
3311
|
+
submitDetails: {
|
|
3312
|
+
campaignId,
|
|
3313
|
+
identifierType: "emailInput" in step ? "EMAIL" : "PHONE"
|
|
3314
|
+
},
|
|
2594
3315
|
log: () => {
|
|
2595
3316
|
}
|
|
2596
3317
|
});
|
|
2597
|
-
|
|
2598
|
-
|
|
3318
|
+
hideOwnText(handle, ownText, shadow);
|
|
3319
|
+
giveLook(handle.element, mount2, look, shadow);
|
|
3320
|
+
return handle;
|
|
3321
|
+
};
|
|
3322
|
+
const elementsOf = (root, ids) => ids.map((id) => root.querySelector(`#${id}`)).filter((element) => element !== null);
|
|
3323
|
+
const tagSubmitButton = (root, input, mark) => {
|
|
3324
|
+
const button = root.querySelector(input)?.closest("form")?.querySelector('button[type="submit"]') ?? null;
|
|
3325
|
+
if (button && button.getAttribute(ANCHOR_ATTRIBUTE) !== mark)
|
|
3326
|
+
button.setAttribute(ANCHOR_ATTRIBUTE, mark);
|
|
3327
|
+
return button;
|
|
3328
|
+
};
|
|
3329
|
+
const checkEmail = (root, shadow) => {
|
|
3330
|
+
if (popup.handle) {
|
|
3331
|
+
if (!popup.emailSettled) tagSubmitButton(root, EMAIL_INPUT, popupId);
|
|
3332
|
+
return;
|
|
3333
|
+
}
|
|
3334
|
+
const step = { emailInput: inPopup(EMAIL_INPUT, shadow) };
|
|
3335
|
+
const disclosure = readEmailDisclosure(root);
|
|
3336
|
+
if (disclosure.kind === "placeholder") {
|
|
3337
|
+
const [node] = elementsOf(root, [disclosure.id]);
|
|
3338
|
+
if (!node) return;
|
|
3339
|
+
popup.handle = mountAt(
|
|
3340
|
+
step,
|
|
3341
|
+
`#${disclosure.id}`,
|
|
3342
|
+
disclosure.ownText,
|
|
3343
|
+
node,
|
|
3344
|
+
shadow
|
|
3345
|
+
);
|
|
3346
|
+
popup.emailSettled = true;
|
|
3347
|
+
return;
|
|
3348
|
+
}
|
|
3349
|
+
if (disclosure.kind === "unreadable" && !root.querySelector(EMAIL_INPUT))
|
|
3350
|
+
return;
|
|
3351
|
+
const ownText = disclosure.kind === "none" ? disclosure.ownText : [];
|
|
3352
|
+
tagSubmitButton(root, EMAIL_INPUT, popupId);
|
|
3353
|
+
popup.handle = mountAt(
|
|
3354
|
+
step,
|
|
3355
|
+
buttonSelector,
|
|
3356
|
+
ownText,
|
|
3357
|
+
elementsOf(root, ownText)[0] ?? null,
|
|
3358
|
+
shadow
|
|
3359
|
+
);
|
|
3360
|
+
};
|
|
3361
|
+
const renderSms = (root, shadow) => {
|
|
3362
|
+
const disclosure = readSmsDisclosure(root);
|
|
3363
|
+
const step = { phoneInput: inPopup(PHONE_INPUT, shadow) };
|
|
3364
|
+
const ownText = disclosure.kind === "unreadable" ? [] : disclosure.ownText;
|
|
3365
|
+
const [node] = disclosure.kind === "placeholder" ? elementsOf(root, [disclosure.id]) : [];
|
|
3366
|
+
if (disclosure.kind === "placeholder" && node) {
|
|
3367
|
+
const handle2 = mountAt(
|
|
3368
|
+
step,
|
|
3369
|
+
`#${disclosure.id}`,
|
|
3370
|
+
[disclosure.id, ...ownText],
|
|
3371
|
+
node,
|
|
3372
|
+
shadow
|
|
3373
|
+
);
|
|
3374
|
+
popup.sms = { kind: "render", handle: handle2, retag: false };
|
|
3375
|
+
return;
|
|
3376
|
+
}
|
|
3377
|
+
if (!tagSubmitButton(root, PHONE_INPUT, smsButtonMark)) return;
|
|
3378
|
+
const handle = mountAt(
|
|
3379
|
+
step,
|
|
3380
|
+
smsButtonSelector,
|
|
3381
|
+
ownText,
|
|
3382
|
+
elementsOf(root, ownText)[0] ?? null,
|
|
3383
|
+
shadow
|
|
3384
|
+
);
|
|
3385
|
+
popup.sms = { kind: "render", handle, retag: true };
|
|
3386
|
+
};
|
|
3387
|
+
const listenSms = (root) => {
|
|
3388
|
+
const auth = context.auth;
|
|
3389
|
+
const datashipsSessionId = context.datashipsSessionId;
|
|
3390
|
+
const disclosure = readSmsDisclosure(root);
|
|
3391
|
+
const shown = disclosure.kind === "unreadable" ? [] : elementsOf(root, [
|
|
3392
|
+
...disclosure.kind === "placeholder" ? [disclosure.id] : [],
|
|
3393
|
+
...disclosure.ownText
|
|
3394
|
+
]);
|
|
3395
|
+
const disclosureText = textOf(shown);
|
|
3396
|
+
if (disclosure.kind === "unreadable" || !auth || !datashipsSessionId) {
|
|
3397
|
+
popup.sms = { kind: "none" };
|
|
3398
|
+
return;
|
|
3399
|
+
}
|
|
3400
|
+
const privacyPolicyUrl = linkOf(shown, /privacy/i);
|
|
3401
|
+
const termsUrl = linkOf(shown, /terms/i);
|
|
3402
|
+
const client = deps.createListenClient({
|
|
3403
|
+
campaignId,
|
|
3404
|
+
datashipsSessionId,
|
|
3405
|
+
publicKey: context.publicKey,
|
|
3406
|
+
baseUrl: context.baseUrl,
|
|
3407
|
+
auth,
|
|
3408
|
+
...disclosureText ? { disclosureText } : {},
|
|
3409
|
+
...privacyPolicyUrl ? { privacyPolicyUrl } : {},
|
|
3410
|
+
...termsUrl ? { termsUrl } : {}
|
|
3411
|
+
});
|
|
3412
|
+
let last = client.upsertSession({ identifierType: "PHONE" }).catch(() => {
|
|
3413
|
+
});
|
|
3414
|
+
let sent = false;
|
|
3415
|
+
popup.sms = {
|
|
3416
|
+
kind: "listen",
|
|
3417
|
+
send: (phone) => {
|
|
3418
|
+
if (sent) return;
|
|
3419
|
+
sent = true;
|
|
3420
|
+
last = last.then(
|
|
3421
|
+
() => client.upsertSession({
|
|
3422
|
+
identifierType: "PHONE",
|
|
3423
|
+
identifier: phone
|
|
3424
|
+
})
|
|
3425
|
+
).then(
|
|
3426
|
+
() => client.submitSession({
|
|
3427
|
+
details: { campaignId, identifierType: "PHONE" }
|
|
3428
|
+
})
|
|
3429
|
+
).catch(() => {
|
|
3430
|
+
sent = false;
|
|
3431
|
+
});
|
|
3432
|
+
}
|
|
3433
|
+
};
|
|
2599
3434
|
};
|
|
2600
|
-
const
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
3435
|
+
const checkSms = (root, shadow) => {
|
|
3436
|
+
if (popup.sms) {
|
|
3437
|
+
if (popup.sms.kind === "render" && popup.sms.retag)
|
|
3438
|
+
tagSubmitButton(root, PHONE_INPUT, smsButtonMark);
|
|
3439
|
+
return;
|
|
3440
|
+
}
|
|
3441
|
+
if (smsType !== "SINGLE" && smsType !== "DOUBLE") {
|
|
3442
|
+
popup.sms = { kind: "none" };
|
|
3443
|
+
return;
|
|
3444
|
+
}
|
|
3445
|
+
if (!root.querySelector(PHONE_INPUT)) return;
|
|
3446
|
+
if (smsType === "SINGLE") renderSms(root, shadow);
|
|
3447
|
+
else listenSms(root);
|
|
2604
3448
|
};
|
|
2605
3449
|
const check = () => {
|
|
2606
3450
|
try {
|
|
@@ -2612,23 +3456,10 @@ var watchPopups = (context, deps) => {
|
|
|
2612
3456
|
popup.watched = shadow;
|
|
2613
3457
|
popup.observer?.observe(shadow, { childList: true, subtree: true });
|
|
2614
3458
|
}
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
return stopObserving(popup);
|
|
2620
|
-
}
|
|
2621
|
-
if (disclosure.kind === "unreadable" && !root.querySelector(EMAIL_INPUT))
|
|
2622
|
-
return;
|
|
2623
|
-
tagSubmitButton(root);
|
|
2624
|
-
mountAt(
|
|
2625
|
-
buttonSelector,
|
|
2626
|
-
disclosure.kind === "none" ? disclosure.ownText : [],
|
|
2627
|
-
shadow
|
|
2628
|
-
);
|
|
2629
|
-
return;
|
|
2630
|
-
}
|
|
2631
|
-
tagSubmitButton(root);
|
|
3459
|
+
checkEmail(root, shadow);
|
|
3460
|
+
checkSms(root, shadow);
|
|
3461
|
+
const smsDone = popup.sms !== null && !(popup.sms.kind === "render" && popup.sms.retag);
|
|
3462
|
+
if (popup.emailSettled && smsDone) stopObserving(popup);
|
|
2632
3463
|
} catch {
|
|
2633
3464
|
stopObserving(popup);
|
|
2634
3465
|
}
|
|
@@ -2642,17 +3473,24 @@ var watchPopups = (context, deps) => {
|
|
|
2642
3473
|
const campaignId = idOf(detail.campaignID);
|
|
2643
3474
|
if (!popupId || !campaignId || popups.has(popupId)) return;
|
|
2644
3475
|
if (!context.preview) {
|
|
2645
|
-
if (!context.
|
|
3476
|
+
if (!context.auth || !context.elements.some((element) => element.id === campaignId))
|
|
3477
|
+
return;
|
|
2646
3478
|
}
|
|
2647
3479
|
track(popupId, campaignId);
|
|
2648
3480
|
};
|
|
2649
3481
|
const onSignup = (detail) => {
|
|
2650
3482
|
const popupId = idOf(detail.popupID);
|
|
2651
|
-
const
|
|
2652
|
-
if (!
|
|
2653
|
-
if (typeof detail.email
|
|
2654
|
-
|
|
2655
|
-
|
|
3483
|
+
const popup = popupId ? popups.get(popupId) : void 0;
|
|
3484
|
+
if (!popup) return;
|
|
3485
|
+
if (typeof detail.email === "string" && detail.email !== "")
|
|
3486
|
+
void popup.handle?.submit?.().catch(() => {
|
|
3487
|
+
});
|
|
3488
|
+
const phone = detail.phone;
|
|
3489
|
+
if (typeof phone !== "string" || phone === "" || !popup.sms) return;
|
|
3490
|
+
if (popup.sms.kind === "render")
|
|
3491
|
+
void popup.sms.handle.submit?.({ phone }).catch(() => {
|
|
3492
|
+
});
|
|
3493
|
+
else if (popup.sms.kind === "listen") popup.sms.send(phone);
|
|
2656
3494
|
};
|
|
2657
3495
|
const onEvent = (event) => {
|
|
2658
3496
|
try {
|
|
@@ -2673,24 +3511,46 @@ var watchPopups = (context, deps) => {
|
|
|
2673
3511
|
};
|
|
2674
3512
|
|
|
2675
3513
|
// src/modules/alia/index.ts
|
|
2676
|
-
var
|
|
2677
|
-
|
|
3514
|
+
var PREVIEW_SESSION_ID = "preview";
|
|
3515
|
+
var createRenderClient = (options) => {
|
|
3516
|
+
const adapter = new AliaFormRenderAdapter({
|
|
3517
|
+
datashipsSessionId: options.datashipsSessionId ?? PREVIEW_SESSION_ID,
|
|
2678
3518
|
campaignId: options.campaignId,
|
|
2679
|
-
popupId: options.popupId,
|
|
2680
|
-
storageScope: options.publicKey,
|
|
2681
3519
|
previewMode: options.preview
|
|
2682
3520
|
});
|
|
2683
|
-
|
|
2684
|
-
return new DatashipsClient({
|
|
3521
|
+
return new DatashipsClient2({
|
|
2685
3522
|
adapter,
|
|
2686
3523
|
app: "launcher",
|
|
2687
|
-
version: "0.
|
|
3524
|
+
version: "0.3.0",
|
|
2688
3525
|
baseUrl: options.baseUrl,
|
|
2689
|
-
...options.
|
|
3526
|
+
...options.auth ? {
|
|
3527
|
+
auth: {
|
|
3528
|
+
publicKey: options.publicKey,
|
|
3529
|
+
getToken: options.auth.getToken,
|
|
3530
|
+
onUnauthorized: options.auth.onUnauthorized
|
|
3531
|
+
}
|
|
3532
|
+
} : {}
|
|
2690
3533
|
});
|
|
2691
3534
|
};
|
|
3535
|
+
var createListenClient = (options) => new DatashipsClient2({
|
|
3536
|
+
adapter: new AliaFormListenAdapter({
|
|
3537
|
+
datashipsSessionId: options.datashipsSessionId,
|
|
3538
|
+
campaignId: options.campaignId,
|
|
3539
|
+
...options.disclosureText ? { disclosureText: options.disclosureText } : {},
|
|
3540
|
+
...options.privacyPolicyUrl ? { privacyPolicyUrl: options.privacyPolicyUrl } : {},
|
|
3541
|
+
...options.termsUrl ? { termsUrl: options.termsUrl } : {}
|
|
3542
|
+
}),
|
|
3543
|
+
app: "launcher",
|
|
3544
|
+
version: "0.3.0",
|
|
3545
|
+
baseUrl: options.baseUrl,
|
|
3546
|
+
auth: {
|
|
3547
|
+
publicKey: options.publicKey,
|
|
3548
|
+
getToken: options.auth.getToken,
|
|
3549
|
+
onUnauthorized: options.auth.onUnauthorized
|
|
3550
|
+
}
|
|
3551
|
+
});
|
|
2692
3552
|
var start = (context) => {
|
|
2693
|
-
watchPopups(context, { mount,
|
|
3553
|
+
watchPopups(context, { mount, createRenderClient, createListenClient });
|
|
2694
3554
|
};
|
|
2695
3555
|
|
|
2696
|
-
export {
|
|
3556
|
+
export { createListenClient, createRenderClient, start };
|