@cimplify/sdk 0.103.0 → 0.104.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/advanced.d.mts +3 -3
- package/dist/advanced.d.ts +3 -3
- package/dist/advanced.js +22 -22
- package/dist/advanced.mjs +3 -3
- package/dist/{chunk-C2JSNJUC.mjs → chunk-2WPVUIHX.mjs} +52 -11
- package/dist/{chunk-JG5CQNCB.js → chunk-4BKOKHE3.js} +4 -0
- package/dist/{chunk-R6OLQ33I.js → chunk-5BDYDZ4U.js} +239 -87
- package/dist/{chunk-H7ACMHM3.mjs → chunk-5RT4HYMP.mjs} +32 -4
- package/dist/{chunk-NNG6IFFX.js → chunk-7PDEX54K.js} +3 -3
- package/dist/{chunk-M4URVKHE.mjs → chunk-DYIAX3WI.mjs} +1 -1
- package/dist/{chunk-QOWPGS7Z.js → chunk-E4K2VQDD.js} +35 -5
- package/dist/{chunk-VNPEYLB2.mjs → chunk-H3RATH4B.mjs} +4 -0
- package/dist/{chunk-JSWJ4XDE.js → chunk-IQFFSKE2.js} +315 -108
- package/dist/{chunk-J6PNHDHL.mjs → chunk-OCCNG6MO.mjs} +284 -77
- package/dist/{chunk-GERXZQSX.mjs → chunk-OKADBZAI.mjs} +171 -20
- package/dist/{chunk-VIL6IQCG.js → chunk-YVAEY3VC.js} +54 -13
- package/dist/{client-Dqg2mc-7.d.ts → client-BVNWjk6W.d.ts} +2 -2
- package/dist/{client-BfpNjJ_a.d.mts → client-BuLcOWLv.d.ts} +115 -23
- package/dist/{client-DHBwvh7U.d.ts → client-D5AoobFc.d.mts} +115 -23
- package/dist/{client-DpqRobY9.d.mts → client-fM716k7G.d.mts} +2 -2
- package/dist/{index-C8uDqLwJ.d.ts → index-BtcoqrY1.d.ts} +3 -3
- package/dist/{index-e2y6AK70.d.mts → index-D7Tf3v7c.d.mts} +3 -3
- package/dist/index.d.mts +10 -8
- package/dist/index.d.ts +10 -8
- package/dist/index.js +107 -106
- package/dist/index.mjs +6 -5
- package/dist/{link-cuNVYc2s.d.mts → link-D9iSVxt5.d.mts} +12 -1
- package/dist/{link-cuNVYc2s.d.ts → link-D9iSVxt5.d.ts} +12 -1
- package/dist/mock/cli.mjs +53 -10
- package/dist/mock/library.js +53 -10
- package/dist/mock/library.mjs +53 -10
- package/dist/mock/msw.js +53 -10
- package/dist/mock/msw.mjs +53 -10
- package/dist/{payment-H5LoIvXU.d.mts → payment-g0HFkEDU.d.mts} +519 -54
- package/dist/{payment-H5LoIvXU.d.ts → payment-g0HFkEDU.d.ts} +519 -54
- package/dist/{price-C2RqscMY.d.ts → price-BLIeAb8K.d.ts} +1 -1
- package/dist/{price-BvePgDXe.d.mts → price-Czq_cTC_.d.mts} +1 -1
- package/dist/react.d.mts +4 -4
- package/dist/react.d.ts +4 -4
- package/dist/react.js +193 -169
- package/dist/react.mjs +54 -30
- package/dist/{server-C7FyLdrz.d.mts → server-BkVhOIwn.d.mts} +4 -2
- package/dist/{server-DoXIpSd7.d.ts → server-DKK_D-PP.d.ts} +4 -2
- package/dist/server.d.mts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.js +11 -10
- package/dist/server.mjs +5 -4
- package/dist/testing/msw.d.mts +2 -2
- package/dist/testing/msw.d.ts +2 -2
- package/dist/testing/msw.js +3 -3
- package/dist/testing/msw.mjs +2 -2
- package/dist/testing/suite.d.mts +6 -6
- package/dist/testing/suite.d.ts +6 -6
- package/dist/testing/suite.js +25 -25
- package/dist/testing/suite.mjs +6 -6
- package/dist/testing.d.mts +46 -6
- package/dist/testing.d.ts +46 -6
- package/dist/testing.js +94 -82
- package/dist/testing.mjs +13 -9
- package/dist/utils.d.mts +4 -4
- package/dist/utils.d.ts +4 -4
- package/dist/utils.js +31 -31
- package/dist/utils.mjs +2 -2
- package/package.json +1 -1
- package/registry/chat-widget.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkCNN7Z2IP_js = require('./chunk-CNN7Z2IP.js');
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var chunk7PDEX54K_js = require('./chunk-7PDEX54K.js');
|
|
5
|
+
var chunk4BKOKHE3_js = require('./chunk-4BKOKHE3.js');
|
|
6
6
|
|
|
7
7
|
// src/types/result.ts
|
|
8
8
|
function ok(value) {
|
|
@@ -117,11 +117,11 @@ function clearIntentIdempotencyKey(scope, storage = sessionStorageOrNull()) {
|
|
|
117
117
|
|
|
118
118
|
// src/internal/safe.ts
|
|
119
119
|
function toCimplifyError(error) {
|
|
120
|
-
if (error instanceof
|
|
120
|
+
if (error instanceof chunk4BKOKHE3_js.CimplifyError) return chunk4BKOKHE3_js.enrichError(error);
|
|
121
121
|
if (error instanceof Error) {
|
|
122
|
-
return
|
|
122
|
+
return chunk4BKOKHE3_js.enrichError(new chunk4BKOKHE3_js.CimplifyError(chunk4BKOKHE3_js.ErrorCode.UNKNOWN_ERROR, error.message, false));
|
|
123
123
|
}
|
|
124
|
-
return
|
|
124
|
+
return chunk4BKOKHE3_js.enrichError(new chunk4BKOKHE3_js.CimplifyError(chunk4BKOKHE3_js.ErrorCode.UNKNOWN_ERROR, String(error), false));
|
|
125
125
|
}
|
|
126
126
|
async function safe(promise) {
|
|
127
127
|
try {
|
|
@@ -696,7 +696,7 @@ var CartOperations = class {
|
|
|
696
696
|
if (typeof updates.quantity !== "number") {
|
|
697
697
|
return {
|
|
698
698
|
ok: false,
|
|
699
|
-
error: new
|
|
699
|
+
error: new chunk4BKOKHE3_js.CimplifyError(
|
|
700
700
|
"VALIDATION_ERROR",
|
|
701
701
|
"updateItem requires a quantity; richer mid-cart edits are not supported"
|
|
702
702
|
)
|
|
@@ -909,7 +909,7 @@ var CheckoutResolver = class {
|
|
|
909
909
|
return this.finalizeSuccess(checkoutResult);
|
|
910
910
|
}
|
|
911
911
|
if (this.isFailureStatus(checkoutResult.payment_status)) {
|
|
912
|
-
const normalized =
|
|
912
|
+
const normalized = chunk7PDEX54K_js.normalizeStatusResponse({
|
|
913
913
|
status: checkoutResult.payment_status,
|
|
914
914
|
paid: false
|
|
915
915
|
});
|
|
@@ -1045,7 +1045,7 @@ var CheckoutResolver = class {
|
|
|
1045
1045
|
case NEXT_ACTION_REDIRECT: {
|
|
1046
1046
|
const limitFailure = this.consumeAuthorizationStep(resolutionState);
|
|
1047
1047
|
if (limitFailure) return limitFailure;
|
|
1048
|
-
const authorizationUrl =
|
|
1048
|
+
const authorizationUrl = chunk7PDEX54K_js.paymentAuthorizationUrl(action.authorization_url);
|
|
1049
1049
|
if (!authorizationUrl) {
|
|
1050
1050
|
return this.fail(
|
|
1051
1051
|
"INVALID_REDIRECT_AUTHORIZATION",
|
|
@@ -1169,22 +1169,22 @@ var CheckoutResolver = class {
|
|
|
1169
1169
|
if (statusResult.value.reference) {
|
|
1170
1170
|
paymentReference = statusResult.value.reference;
|
|
1171
1171
|
}
|
|
1172
|
-
const normalized =
|
|
1173
|
-
if (normalized.paid ||
|
|
1172
|
+
const normalized = chunk7PDEX54K_js.normalizeStatusResponse(statusResult.value);
|
|
1173
|
+
if (normalized.paid || chunk7PDEX54K_js.isPaymentStatusSuccess(normalized.status)) {
|
|
1174
1174
|
return this.finalizeSuccess({
|
|
1175
1175
|
...latestCheckoutResult,
|
|
1176
1176
|
payment_status: normalized.status,
|
|
1177
1177
|
payment_reference: paymentReference || latestCheckoutResult.payment_reference
|
|
1178
1178
|
});
|
|
1179
1179
|
}
|
|
1180
|
-
if (
|
|
1180
|
+
if (chunk7PDEX54K_js.isPaymentStatusFailure(normalized.status)) {
|
|
1181
1181
|
return this.fail(
|
|
1182
1182
|
normalized.status ? normalized.status.toUpperCase() : "PAYMENT_FAILED",
|
|
1183
1183
|
normalized.message || "Payment failed during confirmation.",
|
|
1184
1184
|
false
|
|
1185
1185
|
);
|
|
1186
1186
|
}
|
|
1187
|
-
if (
|
|
1187
|
+
if (chunk7PDEX54K_js.isPaymentStatusRequiresAction(normalized.status)) {
|
|
1188
1188
|
const authorizationType = latestCheckoutResult.authorization_type;
|
|
1189
1189
|
const paymentId = latestCheckoutResult.payment_id;
|
|
1190
1190
|
if (!authorizationType || !normalizeAuthorizationType(authorizationType) || !paymentId) {
|
|
@@ -1413,14 +1413,14 @@ var CheckoutResolver = class {
|
|
|
1413
1413
|
getOrderCurrency(checkoutResult) {
|
|
1414
1414
|
if (checkoutResult.fx?.pay_currency) {
|
|
1415
1415
|
const currency2 = checkoutResult.fx.pay_currency.trim().toUpperCase();
|
|
1416
|
-
return
|
|
1416
|
+
return chunk4BKOKHE3_js.isSupportedCurrency(currency2) ? currency2 : void 0;
|
|
1417
1417
|
}
|
|
1418
1418
|
if (this.checkoutData.pay_currency) {
|
|
1419
1419
|
const currency2 = this.checkoutData.pay_currency.trim().toUpperCase();
|
|
1420
|
-
return
|
|
1420
|
+
return chunk4BKOKHE3_js.isSupportedCurrency(currency2) ? currency2 : void 0;
|
|
1421
1421
|
}
|
|
1422
1422
|
const currency = this.cartCurrency.trim().toUpperCase();
|
|
1423
|
-
return
|
|
1423
|
+
return chunk4BKOKHE3_js.isSupportedCurrency(currency) ? currency : void 0;
|
|
1424
1424
|
}
|
|
1425
1425
|
emit(status, context = {}) {
|
|
1426
1426
|
if (!this.onStatusChange) {
|
|
@@ -1451,12 +1451,12 @@ var CheckoutResolver = class {
|
|
|
1451
1451
|
};
|
|
1452
1452
|
}
|
|
1453
1453
|
isSuccessfulStatus(status) {
|
|
1454
|
-
const normalized =
|
|
1455
|
-
return normalized.paid ||
|
|
1454
|
+
const normalized = chunk7PDEX54K_js.normalizeStatusResponse({ status, paid: false });
|
|
1455
|
+
return normalized.paid || chunk7PDEX54K_js.isPaymentStatusSuccess(normalized.status);
|
|
1456
1456
|
}
|
|
1457
1457
|
isFailureStatus(status) {
|
|
1458
|
-
const normalized =
|
|
1459
|
-
return
|
|
1458
|
+
const normalized = chunk7PDEX54K_js.normalizeStatusResponse({ status, paid: false });
|
|
1459
|
+
return chunk7PDEX54K_js.isPaymentStatusFailure(normalized.status);
|
|
1460
1460
|
}
|
|
1461
1461
|
ensureNotAborted() {
|
|
1462
1462
|
if (this.signal?.aborted) {
|
|
@@ -1544,14 +1544,14 @@ var CheckoutService = class {
|
|
|
1544
1544
|
}
|
|
1545
1545
|
validateCheckoutData(data) {
|
|
1546
1546
|
if (isOfflinePaymentMethod(data.payment_method)) {
|
|
1547
|
-
return new
|
|
1547
|
+
return new chunk4BKOKHE3_js.CimplifyError(
|
|
1548
1548
|
"INVALID_PAYMENT_METHOD",
|
|
1549
1549
|
"Offline payment isn't available for online checkout. Please pay by card or mobile money.",
|
|
1550
1550
|
false
|
|
1551
1551
|
);
|
|
1552
1552
|
}
|
|
1553
1553
|
if (!isValidCustomerName(data.customer?.name)) {
|
|
1554
|
-
return new
|
|
1554
|
+
return new chunk4BKOKHE3_js.CimplifyError(
|
|
1555
1555
|
"INVALID_CUSTOMER_NAME",
|
|
1556
1556
|
"Enter your name, not a phone number.",
|
|
1557
1557
|
false
|
|
@@ -1566,10 +1566,10 @@ var CheckoutService = class {
|
|
|
1566
1566
|
/** Available storefront collection methods for one presentment currency. */
|
|
1567
1567
|
async collectionOptions(currency) {
|
|
1568
1568
|
const normalized = currency.trim().toUpperCase();
|
|
1569
|
-
if (!
|
|
1569
|
+
if (!chunk4BKOKHE3_js.isSupportedCurrency(normalized)) {
|
|
1570
1570
|
return err(
|
|
1571
|
-
new
|
|
1572
|
-
|
|
1571
|
+
new chunk4BKOKHE3_js.CimplifyError(
|
|
1572
|
+
chunk4BKOKHE3_js.ErrorCode.UNSUPPORTED_CURRENCY,
|
|
1573
1573
|
"No online payment method is available for this currency.",
|
|
1574
1574
|
false
|
|
1575
1575
|
)
|
|
@@ -1583,8 +1583,8 @@ var CheckoutService = class {
|
|
|
1583
1583
|
if (!response.ok) return response;
|
|
1584
1584
|
const options = normalizeCollectionOptions(response.value, normalized);
|
|
1585
1585
|
return options ? ok(options) : err(
|
|
1586
|
-
new
|
|
1587
|
-
|
|
1586
|
+
new chunk4BKOKHE3_js.CimplifyError(
|
|
1587
|
+
chunk4BKOKHE3_js.ErrorCode.PAYMENT_CAPABILITY_MISMATCH,
|
|
1588
1588
|
"Payment methods could not be verified for this currency.",
|
|
1589
1589
|
false
|
|
1590
1590
|
)
|
|
@@ -1620,14 +1620,14 @@ var CheckoutService = class {
|
|
|
1620
1620
|
if (result.value.bill_token) {
|
|
1621
1621
|
this.client.setOrderToken(result.value.order_id, result.value.bill_token);
|
|
1622
1622
|
}
|
|
1623
|
-
} else if (result.error.code !==
|
|
1623
|
+
} else if (result.error.code !== chunk4BKOKHE3_js.ErrorCode.NETWORK_ERROR && result.error.code !== chunk4BKOKHE3_js.ErrorCode.TIMEOUT) {
|
|
1624
1624
|
clearIntentIdempotencyKey(intentScope);
|
|
1625
1625
|
}
|
|
1626
1626
|
return result;
|
|
1627
1627
|
}
|
|
1628
1628
|
async initializePayment(_orderId, _method) {
|
|
1629
1629
|
return err(
|
|
1630
|
-
new
|
|
1630
|
+
new chunk4BKOKHE3_js.CimplifyError(
|
|
1631
1631
|
"NOT_IMPLEMENTED",
|
|
1632
1632
|
"initializePayment is not available in REST mode.",
|
|
1633
1633
|
false
|
|
@@ -1704,7 +1704,7 @@ var CheckoutService = class {
|
|
|
1704
1704
|
pay_deposit: data.pay_deposit
|
|
1705
1705
|
};
|
|
1706
1706
|
const rawBaseCurrency = typeof cart.pricing.currency === "string" ? cart.pricing.currency.trim().toUpperCase() : "";
|
|
1707
|
-
if (!
|
|
1707
|
+
if (!chunk4BKOKHE3_js.isSupportedCurrency(rawBaseCurrency)) {
|
|
1708
1708
|
return ok(
|
|
1709
1709
|
toTerminalFailure(
|
|
1710
1710
|
"INVALID_CURRENCY",
|
|
@@ -1715,7 +1715,7 @@ var CheckoutService = class {
|
|
|
1715
1715
|
}
|
|
1716
1716
|
const baseCurrency = rawBaseCurrency;
|
|
1717
1717
|
const payCurrency = data.pay_currency?.trim().toUpperCase();
|
|
1718
|
-
if (payCurrency && !
|
|
1718
|
+
if (payCurrency && !chunk4BKOKHE3_js.isSupportedCurrency(payCurrency)) {
|
|
1719
1719
|
return ok(
|
|
1720
1720
|
toTerminalFailure(
|
|
1721
1721
|
"INVALID_CURRENCY",
|
|
@@ -1724,7 +1724,7 @@ var CheckoutService = class {
|
|
|
1724
1724
|
)
|
|
1725
1725
|
);
|
|
1726
1726
|
}
|
|
1727
|
-
const payCurrencyCode = payCurrency &&
|
|
1727
|
+
const payCurrencyCode = payCurrency && chunk4BKOKHE3_js.isSupportedCurrency(payCurrency) ? payCurrency : void 0;
|
|
1728
1728
|
const cartTotalAmount = typeof cart.pricing.total_price === "number" ? cart.pricing.total_price : Number.parseFloat(cart.pricing.total_price || "0");
|
|
1729
1729
|
if (payCurrencyCode && payCurrencyCode !== baseCurrency && !checkoutData.fx_quote_id && Number.isFinite(cartTotalAmount) && cartTotalAmount > 0) {
|
|
1730
1730
|
const fxQuoteResult = await this.client.fx.lockQuote({
|
|
@@ -1835,43 +1835,86 @@ function encodePathSegment(value) {
|
|
|
1835
1835
|
var LinkService = class {
|
|
1836
1836
|
constructor(client) {
|
|
1837
1837
|
this.client = client;
|
|
1838
|
+
this.activationGeneration = 0;
|
|
1839
|
+
}
|
|
1840
|
+
beginActivation() {
|
|
1841
|
+
return {
|
|
1842
|
+
generation: ++this.activationGeneration,
|
|
1843
|
+
sessionEpoch: this.client.getSessionEpoch(),
|
|
1844
|
+
publicKeyEpoch: this.client.getPublicKeyEpoch()
|
|
1845
|
+
};
|
|
1846
|
+
}
|
|
1847
|
+
isActivationFenceCurrent(fence) {
|
|
1848
|
+
return fence.generation === this.activationGeneration && fence.sessionEpoch === this.client.getSessionEpoch() && fence.publicKeyEpoch === this.client.getPublicKeyEpoch();
|
|
1849
|
+
}
|
|
1850
|
+
supersededActivation() {
|
|
1851
|
+
return {
|
|
1852
|
+
ok: false,
|
|
1853
|
+
error: new chunk4BKOKHE3_js.CimplifyError(
|
|
1854
|
+
"session_superseded",
|
|
1855
|
+
"A newer authentication session replaced this one"
|
|
1856
|
+
)
|
|
1857
|
+
};
|
|
1858
|
+
}
|
|
1859
|
+
async activateAuthenticatedSession(result, fence) {
|
|
1860
|
+
if (!result.ok || !result.value.session_token) return result;
|
|
1861
|
+
if (!this.isActivationFenceCurrent(fence)) return this.supersededActivation();
|
|
1862
|
+
const accessToken = result.value.session_token;
|
|
1863
|
+
this.client.setAccessToken(accessToken);
|
|
1864
|
+
const installedSessionEpoch = this.client.getSessionEpoch();
|
|
1865
|
+
if (!this.client.getPublicKey().trim()) {
|
|
1866
|
+
this.client.activity.refreshIdentity();
|
|
1867
|
+
return result;
|
|
1868
|
+
}
|
|
1869
|
+
const claim = await this.client.support.claimConversation();
|
|
1870
|
+
if (fence.generation !== this.activationGeneration || fence.publicKeyEpoch !== this.client.getPublicKeyEpoch() || this.client.getAccessToken() !== accessToken) {
|
|
1871
|
+
return this.supersededActivation();
|
|
1872
|
+
}
|
|
1873
|
+
if (!claim.ok && claim.error.code !== "already_claimed") {
|
|
1874
|
+
if (this.client.getSessionEpoch() !== installedSessionEpoch) {
|
|
1875
|
+
return this.supersededActivation();
|
|
1876
|
+
}
|
|
1877
|
+
if (this.client.hasClaimedSessionAuthority()) {
|
|
1878
|
+
this.client.clearSession();
|
|
1879
|
+
} else {
|
|
1880
|
+
this.client.setAccessToken(null);
|
|
1881
|
+
}
|
|
1882
|
+
return claim;
|
|
1883
|
+
}
|
|
1884
|
+
this.client.activity.refreshIdentity();
|
|
1885
|
+
return result;
|
|
1838
1886
|
}
|
|
1839
1887
|
async requestOtp(input, opts) {
|
|
1840
1888
|
const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
|
|
1841
1889
|
return safe(
|
|
1842
|
-
this.client.linkPost("/v1/link/auth/request-otp", input, {
|
|
1890
|
+
this.client.linkPost("/v1/link/auth/request-otp", input, {
|
|
1891
|
+
idempotencyKey
|
|
1892
|
+
})
|
|
1843
1893
|
);
|
|
1844
1894
|
}
|
|
1845
1895
|
async verifyOtp(input, opts) {
|
|
1846
1896
|
const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
|
|
1897
|
+
const activationFence = opts?.activateSession === false ? null : this.beginActivation();
|
|
1847
1898
|
const { business_id: _ignoredBusinessId, ...body } = input;
|
|
1848
1899
|
const result = await safe(
|
|
1849
1900
|
this.client.linkPost("/v1/link/auth/verify-otp", body, { idempotencyKey })
|
|
1850
1901
|
);
|
|
1851
|
-
|
|
1852
|
-
this.client.setAccessToken(result.value.session_token);
|
|
1853
|
-
this.client.activity.refreshIdentity();
|
|
1854
|
-
this.client.autoClaimChatIdentity();
|
|
1855
|
-
}
|
|
1856
|
-
return result;
|
|
1902
|
+
return activationFence ? this.activateAuthenticatedSession(result, activationFence) : result;
|
|
1857
1903
|
}
|
|
1858
1904
|
async refreshSession(sessionToken, opts) {
|
|
1859
1905
|
const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
|
|
1906
|
+
const activationFence = opts?.activateSession === false ? null : this.beginActivation();
|
|
1860
1907
|
const body = sessionToken ? { session_token: sessionToken } : {};
|
|
1861
1908
|
const result = await safe(
|
|
1862
1909
|
this.client.linkPost("/v1/link/auth/refresh", body, { idempotencyKey })
|
|
1863
1910
|
);
|
|
1864
|
-
|
|
1865
|
-
this.client.setAccessToken(result.value.session_token);
|
|
1866
|
-
this.client.activity.refreshIdentity();
|
|
1867
|
-
this.client.autoClaimChatIdentity();
|
|
1868
|
-
}
|
|
1869
|
-
return result;
|
|
1911
|
+
return activationFence ? this.activateAuthenticatedSession(result, activationFence) : result;
|
|
1870
1912
|
}
|
|
1871
1913
|
async logout() {
|
|
1872
|
-
|
|
1914
|
+
this.activationGeneration += 1;
|
|
1915
|
+
const request = safe(this.client.linkPost("/v1/link/auth/logout"));
|
|
1873
1916
|
this.client.clearSession();
|
|
1874
|
-
return
|
|
1917
|
+
return request;
|
|
1875
1918
|
}
|
|
1876
1919
|
async checkStatus(contact) {
|
|
1877
1920
|
return safe(this.client.linkPost("/v1/link/check-status", { contact }));
|
|
@@ -1917,11 +1960,9 @@ var LinkService = class {
|
|
|
1917
1960
|
async enrollAndLinkOrder(data, opts) {
|
|
1918
1961
|
const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
|
|
1919
1962
|
return safe(
|
|
1920
|
-
this.client.linkPost(
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
{ idempotencyKey }
|
|
1924
|
-
)
|
|
1963
|
+
this.client.linkPost("/v1/link/enroll-and-link-order", data, {
|
|
1964
|
+
idempotencyKey
|
|
1965
|
+
})
|
|
1925
1966
|
);
|
|
1926
1967
|
}
|
|
1927
1968
|
async updatePreferences(preferences) {
|
|
@@ -2090,7 +2131,7 @@ var BusinessService = class {
|
|
|
2090
2131
|
if (!result.ok) return err(result.error);
|
|
2091
2132
|
const location = result.value.find((item) => item.id === locationId);
|
|
2092
2133
|
if (!location) {
|
|
2093
|
-
return err(new
|
|
2134
|
+
return err(new chunk4BKOKHE3_js.CimplifyError(chunk4BKOKHE3_js.ErrorCode.NOT_FOUND, `Location not found: ${locationId}`, false));
|
|
2094
2135
|
}
|
|
2095
2136
|
return ok(location);
|
|
2096
2137
|
}
|
|
@@ -2344,6 +2385,7 @@ var MESSAGE_TYPES = {
|
|
|
2344
2385
|
INIT: "init",
|
|
2345
2386
|
SET_TOKEN: "set_token",
|
|
2346
2387
|
SET_SESSION: "set_session",
|
|
2388
|
+
SESSION_CLEARED: "session_cleared",
|
|
2347
2389
|
SET_CART: "set_cart",
|
|
2348
2390
|
GET_DATA: "get_data",
|
|
2349
2391
|
NAVIGATE: "navigate",
|
|
@@ -2360,6 +2402,8 @@ var MESSAGE_TYPES = {
|
|
|
2360
2402
|
LOGOUT_COMPLETE: "logout_complete",
|
|
2361
2403
|
AUTH_REQUESTED: "auth_requested",
|
|
2362
2404
|
SESSION_ESTABLISHED: "session_established",
|
|
2405
|
+
SESSION_ESTABLISHMENT_FAILED: "session_establishment_failed",
|
|
2406
|
+
CONTINUE_WITHOUT_SAVED_DETAILS: "continue_without_saved_details",
|
|
2363
2407
|
CONTACT_PROVIDED: "contact_provided",
|
|
2364
2408
|
CHECKOUT_STATUS: "checkout_status",
|
|
2365
2409
|
CHECKOUT_COMPLETE: "checkout_complete",
|
|
@@ -2710,7 +2754,7 @@ function startRedirectSignIn(opts, authorizeEndpoint, pkce, state) {
|
|
|
2710
2754
|
|
|
2711
2755
|
// src/elements.ts
|
|
2712
2756
|
function toCheckoutError(code, message, recoverable) {
|
|
2713
|
-
const hint =
|
|
2757
|
+
const hint = chunk4BKOKHE3_js.getErrorHint(code);
|
|
2714
2758
|
return {
|
|
2715
2759
|
success: false,
|
|
2716
2760
|
error: {
|
|
@@ -2723,6 +2767,7 @@ function toCheckoutError(code, message, recoverable) {
|
|
|
2723
2767
|
};
|
|
2724
2768
|
}
|
|
2725
2769
|
var DEFAULT_LINK_URL = "https://link.cimplify.io";
|
|
2770
|
+
var AUTH_ESTABLISHMENT_WAIT_MS = 8e3;
|
|
2726
2771
|
var AUTH_CONTACT_TYPES = new Set(Object.values(ELEMENTS_AUTH_CONTACT_TYPES));
|
|
2727
2772
|
var AUTH_MODES = new Set(Object.values(ELEMENTS_AUTH_MODES));
|
|
2728
2773
|
var AUTH_PROMPTS = new Set(Object.values(ELEMENTS_AUTH_PROMPTS));
|
|
@@ -2773,6 +2818,7 @@ var KNOWN_IFRAME_TYPES = /* @__PURE__ */ new Set([
|
|
|
2773
2818
|
MESSAGE_TYPES.HEIGHT_CHANGE,
|
|
2774
2819
|
MESSAGE_TYPES.AUTH_REQUESTED,
|
|
2775
2820
|
MESSAGE_TYPES.SESSION_ESTABLISHED,
|
|
2821
|
+
MESSAGE_TYPES.CONTINUE_WITHOUT_SAVED_DETAILS,
|
|
2776
2822
|
MESSAGE_TYPES.ERROR,
|
|
2777
2823
|
MESSAGE_TYPES.ADDRESS_CHANGED,
|
|
2778
2824
|
MESSAGE_TYPES.ADDRESS_SELECTED,
|
|
@@ -2817,6 +2863,7 @@ function parseIframeMessage(data) {
|
|
|
2817
2863
|
if (!record.method || typeof record.method !== "object") return null;
|
|
2818
2864
|
break;
|
|
2819
2865
|
case MESSAGE_TYPES.CONTACT_PROVIDED:
|
|
2866
|
+
case MESSAGE_TYPES.CONTINUE_WITHOUT_SAVED_DETAILS:
|
|
2820
2867
|
if (typeof record.contact !== "string" || typeof record.contactType !== "string") return null;
|
|
2821
2868
|
break;
|
|
2822
2869
|
case MESSAGE_TYPES.ERROR:
|
|
@@ -2826,7 +2873,8 @@ function parseIframeMessage(data) {
|
|
|
2826
2873
|
if (typeof record.success !== "boolean") return null;
|
|
2827
2874
|
break;
|
|
2828
2875
|
case MESSAGE_TYPES.CHECKOUT_STATUS:
|
|
2829
|
-
if (typeof record.status !== "string" || !record.context || typeof record.context !== "object")
|
|
2876
|
+
if (typeof record.status !== "string" || !record.context || typeof record.context !== "object")
|
|
2877
|
+
return null;
|
|
2830
2878
|
break;
|
|
2831
2879
|
case MESSAGE_TYPES.READY:
|
|
2832
2880
|
case MESSAGE_TYPES.HEIGHT_CHANGE:
|
|
@@ -2849,6 +2897,8 @@ var CimplifyElements = class {
|
|
|
2849
2897
|
this.paymentData = null;
|
|
2850
2898
|
this.checkoutInProgress = false;
|
|
2851
2899
|
this.authInProgress = false;
|
|
2900
|
+
this.authEstablishmentInProgress = false;
|
|
2901
|
+
this.authGeneration = 0;
|
|
2852
2902
|
this.activeCheckoutAbort = null;
|
|
2853
2903
|
this.businessIdResolvePromise = null;
|
|
2854
2904
|
this.client = client;
|
|
@@ -2883,6 +2933,12 @@ var CimplifyElements = class {
|
|
|
2883
2933
|
}
|
|
2884
2934
|
}
|
|
2885
2935
|
destroy() {
|
|
2936
|
+
this.authGeneration += 1;
|
|
2937
|
+
if (this.authEstablishmentInProgress) {
|
|
2938
|
+
this.client.setAccessToken(null);
|
|
2939
|
+
}
|
|
2940
|
+
this.authInProgress = false;
|
|
2941
|
+
this.authEstablishmentInProgress = false;
|
|
2886
2942
|
this.elements.forEach((element) => element.destroy());
|
|
2887
2943
|
this.elements.clear();
|
|
2888
2944
|
if (typeof window !== "undefined") {
|
|
@@ -2920,16 +2976,27 @@ var CimplifyElements = class {
|
|
|
2920
2976
|
processCheckout(options) {
|
|
2921
2977
|
let abortFn = null;
|
|
2922
2978
|
const task = (async () => {
|
|
2923
|
-
this.debug("[cimplify:checkout] processCheckout called", {
|
|
2979
|
+
this.debug("[cimplify:checkout] processCheckout called", {
|
|
2980
|
+
cart_id: options.cart_id,
|
|
2981
|
+
order_type: options.order_type,
|
|
2982
|
+
location_id: options.location_id
|
|
2983
|
+
});
|
|
2924
2984
|
if (this.checkoutInProgress) {
|
|
2925
2985
|
this.debug("[cimplify:checkout] BLOCKED: already processing");
|
|
2926
|
-
return toCheckoutError(
|
|
2927
|
-
"ALREADY_PROCESSING",
|
|
2928
|
-
"Checkout is already in progress.",
|
|
2929
|
-
false
|
|
2930
|
-
);
|
|
2986
|
+
return toCheckoutError("ALREADY_PROCESSING", "Checkout is already in progress.", false);
|
|
2931
2987
|
}
|
|
2932
2988
|
this.checkoutInProgress = true;
|
|
2989
|
+
if (this.authEstablishmentInProgress) {
|
|
2990
|
+
await this.waitForAuthEstablishment(AUTH_ESTABLISHMENT_WAIT_MS);
|
|
2991
|
+
if (this.authEstablishmentInProgress) {
|
|
2992
|
+
this.checkoutInProgress = false;
|
|
2993
|
+
return toCheckoutError(
|
|
2994
|
+
"AUTH_INCOMPLETE",
|
|
2995
|
+
"Authentication must finish establishing the checkout session.",
|
|
2996
|
+
true
|
|
2997
|
+
);
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
2933
3000
|
if (!options.cart_id) {
|
|
2934
3001
|
this.debug("[cimplify:checkout] BLOCKED: no cart_id");
|
|
2935
3002
|
this.checkoutInProgress = false;
|
|
@@ -2987,7 +3054,11 @@ var CimplifyElements = class {
|
|
|
2987
3054
|
}
|
|
2988
3055
|
await this.hydrateCustomerData();
|
|
2989
3056
|
}
|
|
2990
|
-
this.debug("[cimplify:checkout] customer data hydrated", {
|
|
3057
|
+
this.debug("[cimplify:checkout] customer data hydrated", {
|
|
3058
|
+
customerData: this.customerData,
|
|
3059
|
+
accountId: this.accountId,
|
|
3060
|
+
isUnifiedCheckout
|
|
3061
|
+
});
|
|
2991
3062
|
const processMessage = {
|
|
2992
3063
|
type: MESSAGE_TYPES.PROCESS_CHECKOUT,
|
|
2993
3064
|
cart_id: options.cart_id,
|
|
@@ -3051,7 +3122,10 @@ var CimplifyElements = class {
|
|
|
3051
3122
|
return;
|
|
3052
3123
|
}
|
|
3053
3124
|
if (message.type === MESSAGE_TYPES.CHECKOUT_COMPLETE) {
|
|
3054
|
-
this.debug("[cimplify:checkout] received checkout_complete", {
|
|
3125
|
+
this.debug("[cimplify:checkout] received checkout_complete", {
|
|
3126
|
+
success: message.success,
|
|
3127
|
+
error: message.error
|
|
3128
|
+
});
|
|
3055
3129
|
settle({
|
|
3056
3130
|
success: message.success,
|
|
3057
3131
|
order: message.order,
|
|
@@ -3062,11 +3136,7 @@ var CimplifyElements = class {
|
|
|
3062
3136
|
if (message.type === MESSAGE_TYPES.LOGOUT_COMPLETE) {
|
|
3063
3137
|
checkoutElement.sendMessage({ type: MESSAGE_TYPES.ABORT_CHECKOUT });
|
|
3064
3138
|
settle(
|
|
3065
|
-
toCheckoutError(
|
|
3066
|
-
"AUTH_LOST",
|
|
3067
|
-
"Authentication was cleared during checkout.",
|
|
3068
|
-
true
|
|
3069
|
-
)
|
|
3139
|
+
toCheckoutError("AUTH_LOST", "Authentication was cleared during checkout.", true)
|
|
3070
3140
|
);
|
|
3071
3141
|
}
|
|
3072
3142
|
};
|
|
@@ -3075,16 +3145,16 @@ var CimplifyElements = class {
|
|
|
3075
3145
|
}
|
|
3076
3146
|
abortFn = () => {
|
|
3077
3147
|
checkoutElement.sendMessage({ type: MESSAGE_TYPES.ABORT_CHECKOUT });
|
|
3078
|
-
settle(
|
|
3079
|
-
toCheckoutError(
|
|
3080
|
-
"CANCELLED",
|
|
3081
|
-
"Checkout was cancelled.",
|
|
3082
|
-
true
|
|
3083
|
-
)
|
|
3084
|
-
);
|
|
3148
|
+
settle(toCheckoutError("CANCELLED", "Checkout was cancelled.", true));
|
|
3085
3149
|
};
|
|
3086
3150
|
this.activeCheckoutAbort = abortFn;
|
|
3087
|
-
this.debug("[cimplify:checkout] sending process_checkout to checkout iframe", {
|
|
3151
|
+
this.debug("[cimplify:checkout] sending process_checkout to checkout iframe", {
|
|
3152
|
+
cart_id: processMessage.cart_id,
|
|
3153
|
+
order_type: processMessage.order_type,
|
|
3154
|
+
hasCustomer: !!processMessage.customer,
|
|
3155
|
+
hasAddress: !!processMessage.address,
|
|
3156
|
+
isUnifiedCheckout
|
|
3157
|
+
});
|
|
3088
3158
|
checkoutElement.sendMessage(processMessage);
|
|
3089
3159
|
this.debug("[cimplify:checkout] postMessage sent, waiting for checkout_complete...");
|
|
3090
3160
|
});
|
|
@@ -3130,11 +3200,16 @@ var CimplifyElements = class {
|
|
|
3130
3200
|
getAppearance() {
|
|
3131
3201
|
return this.options.appearance;
|
|
3132
3202
|
}
|
|
3133
|
-
|
|
3134
|
-
|
|
3203
|
+
isAuthGenerationCurrent(generation, token) {
|
|
3204
|
+
return this.authGeneration === generation && this.client.getAccessToken() === token;
|
|
3205
|
+
}
|
|
3206
|
+
async hydrateCustomerData(generation = this.authGeneration, token = this.accessToken, force = false) {
|
|
3207
|
+
if (!token || !this.isAuthGenerationCurrent(generation, token)) return false;
|
|
3208
|
+
if (this.customerData && !force) return true;
|
|
3135
3209
|
const linkDataResult = await this.client.link.getLinkData();
|
|
3210
|
+
if (!this.isAuthGenerationCurrent(generation, token)) return false;
|
|
3136
3211
|
if (!linkDataResult.ok || !linkDataResult.value?.customer) {
|
|
3137
|
-
return;
|
|
3212
|
+
return true;
|
|
3138
3213
|
}
|
|
3139
3214
|
const customer = linkDataResult.value.customer;
|
|
3140
3215
|
this.customerData = {
|
|
@@ -3143,6 +3218,7 @@ var CimplifyElements = class {
|
|
|
3143
3218
|
phone: customer.phone || null
|
|
3144
3219
|
};
|
|
3145
3220
|
this.customerId = customer.id;
|
|
3221
|
+
return true;
|
|
3146
3222
|
}
|
|
3147
3223
|
sourceElementFor(event, message) {
|
|
3148
3224
|
for (const element of this.elements.values()) {
|
|
@@ -3181,48 +3257,123 @@ var CimplifyElements = class {
|
|
|
3181
3257
|
} catch {
|
|
3182
3258
|
}
|
|
3183
3259
|
}
|
|
3260
|
+
clearClaimedAuthorityAfterRestoreFailure() {
|
|
3261
|
+
if (!this.client.getAccessToken() && !this.client.hasClaimedSessionAuthority()) return;
|
|
3262
|
+
this.accessToken = null;
|
|
3263
|
+
this.accountId = null;
|
|
3264
|
+
this.customerId = null;
|
|
3265
|
+
this.customerData = null;
|
|
3266
|
+
this.addressData = null;
|
|
3267
|
+
this.paymentData = null;
|
|
3268
|
+
this.authEstablishmentInProgress = false;
|
|
3269
|
+
this.client.clearSession();
|
|
3270
|
+
this.broadcastClearedSession();
|
|
3271
|
+
}
|
|
3184
3272
|
async restoreSession() {
|
|
3185
3273
|
if (typeof window === "undefined" || this.accessToken) return;
|
|
3274
|
+
const generation = ++this.authGeneration;
|
|
3186
3275
|
const storageKey = this.sessionStorageKey();
|
|
3187
3276
|
if (!storageKey) return;
|
|
3188
3277
|
let refreshToken = null;
|
|
3189
3278
|
try {
|
|
3190
3279
|
refreshToken = window.localStorage.getItem(storageKey);
|
|
3191
3280
|
} catch {
|
|
3281
|
+
this.clearClaimedAuthorityAfterRestoreFailure();
|
|
3282
|
+
return;
|
|
3283
|
+
}
|
|
3284
|
+
if (!refreshToken) {
|
|
3285
|
+
this.clearClaimedAuthorityAfterRestoreFailure();
|
|
3192
3286
|
return;
|
|
3193
3287
|
}
|
|
3194
|
-
|
|
3195
|
-
|
|
3288
|
+
const result = await this.client.link.refreshSession(refreshToken, {
|
|
3289
|
+
activateSession: false
|
|
3290
|
+
});
|
|
3291
|
+
if (this.authGeneration !== generation) return;
|
|
3196
3292
|
if (!result.ok || !result.value.session_token) {
|
|
3197
3293
|
this.clearPersistedSession();
|
|
3294
|
+
this.clearClaimedAuthorityAfterRestoreFailure();
|
|
3198
3295
|
return;
|
|
3199
3296
|
}
|
|
3200
3297
|
this.persistRefreshToken(result.value.refresh_token ?? void 0);
|
|
3201
|
-
const
|
|
3202
|
-
|
|
3203
|
-
|
|
3298
|
+
const application = await this.applyAccessToken(result.value.session_token, generation);
|
|
3299
|
+
if (application.kind === "claim_failed") {
|
|
3300
|
+
this.clearPersistedSession();
|
|
3301
|
+
this.broadcastClearedSession();
|
|
3302
|
+
return;
|
|
3303
|
+
}
|
|
3304
|
+
if (application.kind !== "authenticated" || !this.broadcastAccessToken(result.value.session_token, generation)) {
|
|
3305
|
+
return;
|
|
3306
|
+
}
|
|
3307
|
+
this.elements.forEach((element) => element._emitAuthenticated(application.data));
|
|
3204
3308
|
}
|
|
3205
|
-
async applyAccessToken(token) {
|
|
3309
|
+
async applyAccessToken(token, generation) {
|
|
3310
|
+
if (this.authGeneration !== generation) return { kind: "incomplete" };
|
|
3311
|
+
this.authEstablishmentInProgress = true;
|
|
3312
|
+
this.accessToken = null;
|
|
3313
|
+
this.accountId = null;
|
|
3314
|
+
this.customerId = null;
|
|
3315
|
+
this.customerData = null;
|
|
3316
|
+
this.addressData = null;
|
|
3317
|
+
this.paymentData = null;
|
|
3318
|
+
this.client.setAccessToken(token);
|
|
3319
|
+
const claim = await this.client.support.claimConversation();
|
|
3320
|
+
if (!this.isAuthGenerationCurrent(generation, token)) return { kind: "incomplete" };
|
|
3321
|
+
if (!claim.ok && claim.error.code !== "already_claimed") {
|
|
3322
|
+
if (this.client.hasClaimedSessionAuthority()) {
|
|
3323
|
+
this.client.clearSession();
|
|
3324
|
+
} else {
|
|
3325
|
+
this.client.setAccessToken(null);
|
|
3326
|
+
}
|
|
3327
|
+
this.authEstablishmentInProgress = false;
|
|
3328
|
+
return {
|
|
3329
|
+
kind: "claim_failed",
|
|
3330
|
+
code: claim.error.code,
|
|
3331
|
+
message: claim.error.userMessage
|
|
3332
|
+
};
|
|
3333
|
+
}
|
|
3206
3334
|
this.accessToken = token;
|
|
3207
3335
|
this.accountId = decodeJwtSub(token);
|
|
3208
|
-
this.
|
|
3209
|
-
|
|
3210
|
-
|
|
3336
|
+
if (!await this.hydrateCustomerData(generation, token, true)) {
|
|
3337
|
+
return { kind: "incomplete" };
|
|
3338
|
+
}
|
|
3339
|
+
if (!this.isAuthGenerationCurrent(generation, token)) return { kind: "incomplete" };
|
|
3340
|
+
this.authEstablishmentInProgress = false;
|
|
3211
3341
|
return {
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3342
|
+
kind: "authenticated",
|
|
3343
|
+
data: {
|
|
3344
|
+
accountId: this.accountId ?? "",
|
|
3345
|
+
customerId: this.customerId ?? "",
|
|
3346
|
+
token,
|
|
3347
|
+
customer: this.customerData ?? { name: "", email: null, phone: null }
|
|
3348
|
+
}
|
|
3216
3349
|
};
|
|
3217
3350
|
}
|
|
3218
|
-
|
|
3351
|
+
async waitForAuthEstablishment(timeoutMs) {
|
|
3352
|
+
const deadline = Date.now() + timeoutMs;
|
|
3353
|
+
while (this.authEstablishmentInProgress && Date.now() < deadline) {
|
|
3354
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3357
|
+
broadcastAccessToken(token, generation) {
|
|
3358
|
+
if (!this.isAuthGenerationCurrent(generation, token) || this.accessToken !== token || this.authEstablishmentInProgress) {
|
|
3359
|
+
return false;
|
|
3360
|
+
}
|
|
3219
3361
|
const sessionToken = this.client.getSessionToken();
|
|
3220
3362
|
this.elements.forEach((element) => {
|
|
3221
|
-
element.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
|
|
3222
3363
|
if (sessionToken) {
|
|
3223
3364
|
element.sendMessage({ type: MESSAGE_TYPES.SET_SESSION, sessionToken });
|
|
3224
3365
|
}
|
|
3366
|
+
element.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
|
|
3367
|
+
});
|
|
3368
|
+
return true;
|
|
3369
|
+
}
|
|
3370
|
+
broadcastClearedSession() {
|
|
3371
|
+
const sessionToken = this.client.getSessionToken();
|
|
3372
|
+
if (!sessionToken) return null;
|
|
3373
|
+
this.elements.forEach((element) => {
|
|
3374
|
+
element.sendMessage({ type: MESSAGE_TYPES.SESSION_CLEARED, sessionToken });
|
|
3225
3375
|
});
|
|
3376
|
+
return sessionToken;
|
|
3226
3377
|
}
|
|
3227
3378
|
startEmbeddedAuth(sourceElement, request) {
|
|
3228
3379
|
if (this.authInProgress) return;
|
|
@@ -3236,6 +3387,7 @@ var CimplifyElements = class {
|
|
|
3236
3387
|
});
|
|
3237
3388
|
return;
|
|
3238
3389
|
}
|
|
3390
|
+
const generation = ++this.authGeneration;
|
|
3239
3391
|
this.authInProgress = true;
|
|
3240
3392
|
void startSignIn({
|
|
3241
3393
|
clientId,
|
|
@@ -3250,6 +3402,7 @@ var CimplifyElements = class {
|
|
|
3250
3402
|
mode: "modal",
|
|
3251
3403
|
silentFirst: request.mode === ELEMENTS_AUTH_MODES.CHECKOUT && request.prompt !== ELEMENTS_AUTH_PROMPTS.LOGIN,
|
|
3252
3404
|
onSuccess: async ({ accessToken }) => {
|
|
3405
|
+
if (this.authGeneration !== generation) return;
|
|
3253
3406
|
this.authInProgress = false;
|
|
3254
3407
|
if (!accessToken) {
|
|
3255
3408
|
sourceElement._emitError({
|
|
@@ -3258,11 +3411,18 @@ var CimplifyElements = class {
|
|
|
3258
3411
|
});
|
|
3259
3412
|
return;
|
|
3260
3413
|
}
|
|
3261
|
-
const
|
|
3262
|
-
this.broadcastAccessToken(accessToken)
|
|
3263
|
-
|
|
3414
|
+
const application = await this.applyAccessToken(accessToken, generation);
|
|
3415
|
+
if (application.kind === "authenticated" && this.broadcastAccessToken(accessToken, generation)) {
|
|
3416
|
+
sourceElement._emitAuthenticated(application.data);
|
|
3417
|
+
} else if (application.kind === "claim_failed") {
|
|
3418
|
+
sourceElement._emitError({
|
|
3419
|
+
code: application.code,
|
|
3420
|
+
message: application.message
|
|
3421
|
+
});
|
|
3422
|
+
}
|
|
3264
3423
|
},
|
|
3265
3424
|
onError: (err2) => {
|
|
3425
|
+
if (this.authGeneration !== generation) return;
|
|
3266
3426
|
this.authInProgress = false;
|
|
3267
3427
|
sourceElement._emitError({
|
|
3268
3428
|
code: err2.error,
|
|
@@ -3270,6 +3430,7 @@ var CimplifyElements = class {
|
|
|
3270
3430
|
});
|
|
3271
3431
|
}
|
|
3272
3432
|
}).catch((error) => {
|
|
3433
|
+
if (this.authGeneration !== generation) return;
|
|
3273
3434
|
this.authInProgress = false;
|
|
3274
3435
|
sourceElement._emitError({
|
|
3275
3436
|
code: "AUTH_START_FAILED",
|
|
@@ -3290,11 +3451,29 @@ var CimplifyElements = class {
|
|
|
3290
3451
|
this.startEmbeddedAuth(sourceElement, message);
|
|
3291
3452
|
break;
|
|
3292
3453
|
case MESSAGE_TYPES.SESSION_ESTABLISHED:
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
this.
|
|
3296
|
-
|
|
3297
|
-
|
|
3454
|
+
{
|
|
3455
|
+
this.authInProgress = false;
|
|
3456
|
+
const generation = ++this.authGeneration;
|
|
3457
|
+
void this.applyAccessToken(message.accessToken, generation).then((application) => {
|
|
3458
|
+
if (this.authGeneration !== generation) return;
|
|
3459
|
+
if (application.kind === "claim_failed") {
|
|
3460
|
+
this.clearPersistedSession();
|
|
3461
|
+
sourceElement.sendMessage({
|
|
3462
|
+
type: MESSAGE_TYPES.SESSION_ESTABLISHMENT_FAILED,
|
|
3463
|
+
accessToken: message.accessToken,
|
|
3464
|
+
code: application.code,
|
|
3465
|
+
message: application.message
|
|
3466
|
+
});
|
|
3467
|
+
this.broadcastClearedSession();
|
|
3468
|
+
return;
|
|
3469
|
+
}
|
|
3470
|
+
if (application.kind !== "authenticated" || !this.broadcastAccessToken(message.accessToken, generation)) {
|
|
3471
|
+
return;
|
|
3472
|
+
}
|
|
3473
|
+
this.persistRefreshToken(message.refreshToken);
|
|
3474
|
+
sourceElement._emitAuthenticated(application.data);
|
|
3475
|
+
});
|
|
3476
|
+
}
|
|
3298
3477
|
break;
|
|
3299
3478
|
case MESSAGE_TYPES.ADDRESS_CHANGED:
|
|
3300
3479
|
case MESSAGE_TYPES.ADDRESS_SELECTED:
|
|
@@ -3313,7 +3492,35 @@ var CimplifyElements = class {
|
|
|
3313
3492
|
this.customerData.phone = message.contact;
|
|
3314
3493
|
}
|
|
3315
3494
|
break;
|
|
3495
|
+
case MESSAGE_TYPES.CONTINUE_WITHOUT_SAVED_DETAILS: {
|
|
3496
|
+
this.authGeneration += 1;
|
|
3497
|
+
this.authInProgress = false;
|
|
3498
|
+
this.authEstablishmentInProgress = false;
|
|
3499
|
+
const carriedIdentityAuthority = Boolean(this.client.getAccessToken()) || this.client.hasClaimedSessionAuthority();
|
|
3500
|
+
this.accessToken = null;
|
|
3501
|
+
this.accountId = null;
|
|
3502
|
+
this.customerId = null;
|
|
3503
|
+
this.customerData = { name: "", email: null, phone: null };
|
|
3504
|
+
this.addressData = null;
|
|
3505
|
+
this.paymentData = null;
|
|
3506
|
+
this.clearPersistedSession();
|
|
3507
|
+
if (carriedIdentityAuthority) {
|
|
3508
|
+
this.client.clearSession();
|
|
3509
|
+
} else {
|
|
3510
|
+
this.client.setAccessToken(null);
|
|
3511
|
+
}
|
|
3512
|
+
this.broadcastClearedSession();
|
|
3513
|
+
if (message.contactType === "email") {
|
|
3514
|
+
this.customerData.email = message.contact;
|
|
3515
|
+
} else {
|
|
3516
|
+
this.customerData.phone = message.contact;
|
|
3517
|
+
}
|
|
3518
|
+
break;
|
|
3519
|
+
}
|
|
3316
3520
|
case MESSAGE_TYPES.LOGOUT_COMPLETE:
|
|
3521
|
+
this.authGeneration += 1;
|
|
3522
|
+
this.authInProgress = false;
|
|
3523
|
+
this.authEstablishmentInProgress = false;
|
|
3317
3524
|
if (this.checkoutInProgress && this.activeCheckoutAbort) {
|
|
3318
3525
|
this.activeCheckoutAbort();
|
|
3319
3526
|
}
|
|
@@ -3325,6 +3532,7 @@ var CimplifyElements = class {
|
|
|
3325
3532
|
this.paymentData = null;
|
|
3326
3533
|
this.clearPersistedSession();
|
|
3327
3534
|
this.client.clearSession();
|
|
3535
|
+
this.broadcastClearedSession();
|
|
3328
3536
|
break;
|
|
3329
3537
|
}
|
|
3330
3538
|
}
|
|
@@ -3458,10 +3666,9 @@ var CimplifyElement = class {
|
|
|
3458
3666
|
const iframe = this.iframe;
|
|
3459
3667
|
if (!iframe || !iframe.isConnected) {
|
|
3460
3668
|
if (iframe && !iframe.isConnected) {
|
|
3461
|
-
console.warn(
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
);
|
|
3669
|
+
console.warn("[cimplify:checkout] sendMessage DROPPED \u2014 iframe detached", {
|
|
3670
|
+
type: message.type
|
|
3671
|
+
});
|
|
3465
3672
|
}
|
|
3466
3673
|
return;
|
|
3467
3674
|
}
|
|
@@ -3560,13 +3767,13 @@ var CimplifyElement = class {
|
|
|
3560
3767
|
submitLabel: this.options.submitLabel
|
|
3561
3768
|
});
|
|
3562
3769
|
const token = this.parent.getAccessToken();
|
|
3563
|
-
if (token) {
|
|
3564
|
-
this.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
|
|
3565
|
-
}
|
|
3566
3770
|
const sessionToken = this.parent.getSessionToken();
|
|
3567
3771
|
if (sessionToken) {
|
|
3568
3772
|
this.sendMessage({ type: MESSAGE_TYPES.SET_SESSION, sessionToken });
|
|
3569
3773
|
}
|
|
3774
|
+
if (token) {
|
|
3775
|
+
this.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
|
|
3776
|
+
}
|
|
3570
3777
|
this.pendingInit = null;
|
|
3571
3778
|
}
|
|
3572
3779
|
this.flushPending();
|