@cimplify/sdk 0.106.2 → 0.107.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/{catalogue-CVKH9faR.d.mts → catalogue-AmW4XjaN.d.ts} +45 -38
- package/dist/{catalogue-ChBjPPME.d.ts → catalogue-rWd71Xi-.d.mts} +45 -38
- package/dist/{chunk-AVXA4F6G.js → chunk-ANT574FD.js} +29 -0
- package/dist/{chunk-BCLGREHS.js → chunk-CEML2737.js} +245 -219
- package/dist/{chunk-NYDVVNZI.mjs → chunk-JRGK3NXR.mjs} +1 -1
- package/dist/{chunk-NJYR6GGM.mjs → chunk-KG3WT4PR.mjs} +29 -1
- package/dist/{chunk-4VTFTLH7.mjs → chunk-NZMU7UUA.mjs} +3 -3
- package/dist/{chunk-B7JH5D3J.js → chunk-ONII7K3T.js} +262 -303
- package/dist/{chunk-T3MXI7JD.mjs → chunk-OTPLI3JY.mjs} +87 -128
- package/dist/{chunk-LJAZ7H4I.mjs → chunk-T4OU77DM.mjs} +108 -83
- package/dist/{chunk-7O2BBPDM.js → chunk-THSYGWUA.js} +70 -70
- package/dist/{chunk-NJK3THWT.js → chunk-UVRPC2P7.js} +90 -62
- package/dist/{chunk-UYFTOIFW.js → chunk-V32BCG7M.js} +6 -6
- package/dist/{chunk-L4XKIMUO.mjs → chunk-XBL3TMPC.mjs} +31 -3
- package/dist/{client-BfKFK7cn.d.mts → client-DlTJ2hUM.d.mts} +2 -2
- package/dist/{client-DoczTJbs.d.ts → client-ni-CfOSO.d.ts} +2 -2
- package/dist/{checkout-XoV4HNg2.d.mts → elements-BF1Y4aOi.d.mts} +575 -502
- package/dist/{checkout-XoV4HNg2.d.ts → elements-BF1Y4aOi.d.ts} +575 -502
- package/dist/{index-DweR60Cv.d.ts → index-CZ0bJm6k.d.ts} +2 -2
- package/dist/{index-DRMBo26v.d.mts → index-DML_W635.d.mts} +2 -2
- package/dist/{index-Dn6xCpDe.d.ts → index-DU7vffby.d.ts} +2 -2
- package/dist/{index-DEUorPUO.d.mts → index-DopYJKDL.d.mts} +2 -2
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +159 -151
- package/dist/index.mjs +5 -5
- package/dist/mock/cli.mjs +33 -2
- package/dist/mock/library.js +33 -2
- package/dist/mock/library.mjs +33 -2
- package/dist/mock/msw.js +33 -2
- package/dist/mock/msw.mjs +33 -2
- package/dist/{price-De-sxcuj.d.ts → price-B5t2mpsE.d.ts} +1 -1
- package/dist/{price-CUGIYRtD.d.mts → price-DI_U5oXU.d.mts} +1 -1
- package/dist/react.d.mts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +154 -154
- package/dist/react.mjs +7 -7
- package/dist/{server-7soMMUgP.d.ts → server-BItJAUTD.d.ts} +1 -1
- package/dist/{server-DDEJ7e9s.d.mts → server-Dq70vD7z.d.mts} +1 -1
- package/dist/server.d.mts +3 -3
- package/dist/server.d.ts +3 -3
- package/dist/server.js +10 -10
- package/dist/server.mjs +4 -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 +5 -5
- package/dist/testing/suite.d.ts +5 -5
- package/dist/testing/suite.js +26 -26
- package/dist/testing/suite.mjs +6 -6
- package/dist/testing.d.mts +4 -4
- package/dist/testing.d.ts +4 -4
- package/dist/testing.js +118 -118
- package/dist/testing.mjs +7 -7
- package/dist/utils.d.mts +3 -3
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +32 -32
- package/dist/utils.mjs +2 -2
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CHECKOUT_STATUS, PAYMENT_METHOD, CHECKOUT_NEXT_ACTION, CHECKOUT_ORDER_RESULT_STATUS, ORDER_TYPE, AUTHORIZATION_TYPE } from './chunk-33VCYWVL.mjs';
|
|
2
|
-
import { paymentAuthorizationUrl, purchaseIntentMobileMoneyNetwork } from './chunk-
|
|
3
|
-
import { ErrorCode, PURCHASE_INTENT_RESOLVE_STATUS, CimplifyError, PAYMENT_OPTION_STATUS, isSupportedCurrency, PURCHASE_INTENT_CONFIRM_STATUS, PURCHASE_INTENT_ACTION_DECISION, PURCHASE_INTENT_RESOLUTION_KIND, PURCHASE_INTENT_ERROR_CODE, enrichError, LEGACY_CHECKOUT_PAYMENT_METHOD_ALIAS, PURCHASE_INTENT_PAYMENT_METHOD, PURCHASE_INTENT_SOURCE_KIND, LEGACY_CHECKOUT_PAYMENT_STATUS, getErrorHint, MOBILE_MONEY_TENDER_AUTHORITY_KIND } from './chunk-
|
|
2
|
+
import { paymentAuthorizationUrl, purchaseIntentMobileMoneyNetwork } from './chunk-JRGK3NXR.mjs';
|
|
3
|
+
import { ErrorCode, PURCHASE_INTENT_RESOLVE_STATUS, CimplifyError, PAYMENT_OPTION_STATUS, isSupportedCurrency, PURCHASE_INTENT_CONFIRM_STATUS, PURCHASE_INTENT_ACTION_DECISION, PURCHASE_INTENT_RESOLUTION_KIND, PURCHASE_INTENT_ERROR_CODE, enrichError, LEGACY_CHECKOUT_PAYMENT_METHOD_ALIAS, PURCHASE_INTENT_PAYMENT_METHOD, PURCHASE_INTENT_SOURCE_KIND, LEGACY_CHECKOUT_PAYMENT_STATUS, getErrorHint, MOBILE_MONEY_TENDER_AUTHORITY_KIND } from './chunk-KG3WT4PR.mjs';
|
|
4
4
|
|
|
5
5
|
// src/types/result.ts
|
|
6
6
|
function ok(value) {
|
|
@@ -2405,7 +2405,7 @@ var LinkService = class {
|
|
|
2405
2405
|
this.client.activity.refreshIdentity();
|
|
2406
2406
|
return result;
|
|
2407
2407
|
}
|
|
2408
|
-
const claim = await this.client.
|
|
2408
|
+
const claim = await this.client.session.claim();
|
|
2409
2409
|
if (fence.generation !== this.activationGeneration || fence.publicKeyEpoch !== this.client.getPublicKeyEpoch() || this.client.getAccessToken() !== accessToken) {
|
|
2410
2410
|
return this.supersededActivation();
|
|
2411
2411
|
}
|
|
@@ -2629,7 +2629,7 @@ var AuthService = class {
|
|
|
2629
2629
|
if (result.ok && result.value.session_token) {
|
|
2630
2630
|
this.client.setAccessToken(result.value.session_token);
|
|
2631
2631
|
this.client.activity.refreshIdentity();
|
|
2632
|
-
this.client.
|
|
2632
|
+
this.client.autoClaimSession();
|
|
2633
2633
|
}
|
|
2634
2634
|
return result;
|
|
2635
2635
|
}
|
|
@@ -2922,13 +2922,10 @@ var ELEMENT_TYPES = {
|
|
|
2922
2922
|
};
|
|
2923
2923
|
var MESSAGE_TYPES = {
|
|
2924
2924
|
INIT: "init",
|
|
2925
|
-
|
|
2926
|
-
SET_SESSION: "set_session",
|
|
2925
|
+
IDENTITY: "identity",
|
|
2927
2926
|
SESSION_CLEARED: "session_cleared",
|
|
2928
2927
|
SET_CART: "set_cart",
|
|
2929
2928
|
GET_DATA: "get_data",
|
|
2930
|
-
NAVIGATE: "navigate",
|
|
2931
|
-
REFRESH_TOKEN: "refresh_token",
|
|
2932
2929
|
LOGOUT: "logout",
|
|
2933
2930
|
PROCESS_CHECKOUT: "process_checkout",
|
|
2934
2931
|
ABORT_CHECKOUT: "abort_checkout",
|
|
@@ -2941,7 +2938,6 @@ var MESSAGE_TYPES = {
|
|
|
2941
2938
|
LOGOUT_COMPLETE: "logout_complete",
|
|
2942
2939
|
AUTH_REQUESTED: "auth_requested",
|
|
2943
2940
|
SESSION_ESTABLISHED: "session_established",
|
|
2944
|
-
SESSION_ESTABLISHMENT_FAILED: "session_establishment_failed",
|
|
2945
2941
|
CONTINUE_WITHOUT_SAVED_DETAILS: "continue_without_saved_details",
|
|
2946
2942
|
CONTACT_PROVIDED: "contact_provided",
|
|
2947
2943
|
CHECKOUT_STATUS: "checkout_status",
|
|
@@ -3345,7 +3341,6 @@ function toCheckoutError(code, message, recoverable) {
|
|
|
3345
3341
|
};
|
|
3346
3342
|
}
|
|
3347
3343
|
var DEFAULT_LINK_URL = "https://link.cimplify.io";
|
|
3348
|
-
var AUTH_ESTABLISHMENT_WAIT_MS = 8e3;
|
|
3349
3344
|
var AUTH_CONTACT_TYPES = new Set(Object.values(ELEMENTS_AUTH_CONTACT_TYPES));
|
|
3350
3345
|
var AUTH_MODES = new Set(Object.values(ELEMENTS_AUTH_MODES));
|
|
3351
3346
|
var AUTH_PROMPTS = new Set(Object.values(ELEMENTS_AUTH_PROMPTS));
|
|
@@ -3376,6 +3371,11 @@ function decodeJwtSub(token) {
|
|
|
3376
3371
|
return "";
|
|
3377
3372
|
}
|
|
3378
3373
|
}
|
|
3374
|
+
function isClaimedCustomer(value) {
|
|
3375
|
+
if (!value || typeof value !== "object") return false;
|
|
3376
|
+
const record = value;
|
|
3377
|
+
return typeof record.id === "string" && typeof record.name === "string" && (record.email === null || typeof record.email === "string") && (record.phone === null || typeof record.phone === "string");
|
|
3378
|
+
}
|
|
3379
3379
|
function isAllowedOrigin(origin) {
|
|
3380
3380
|
try {
|
|
3381
3381
|
const url = new URL(origin);
|
|
@@ -3432,8 +3432,10 @@ function parseIframeMessage(data) {
|
|
|
3432
3432
|
}
|
|
3433
3433
|
break;
|
|
3434
3434
|
case MESSAGE_TYPES.SESSION_ESTABLISHED:
|
|
3435
|
+
if (typeof record.sessionToken !== "string" || !record.sessionToken.trim()) return null;
|
|
3435
3436
|
if (typeof record.accessToken !== "string" || !record.accessToken.trim()) return null;
|
|
3436
3437
|
if (record.refreshToken !== void 0 && typeof record.refreshToken !== "string") return null;
|
|
3438
|
+
if (!isClaimedCustomer(record.customer)) return null;
|
|
3437
3439
|
break;
|
|
3438
3440
|
case MESSAGE_TYPES.ADDRESS_CHANGED:
|
|
3439
3441
|
case MESSAGE_TYPES.ADDRESS_SELECTED:
|
|
@@ -3484,7 +3486,6 @@ var CimplifyElements = class {
|
|
|
3484
3486
|
this.paymentData = null;
|
|
3485
3487
|
this.checkoutInProgress = false;
|
|
3486
3488
|
this.authInProgress = false;
|
|
3487
|
-
this.authEstablishmentInProgress = false;
|
|
3488
3489
|
this.authGeneration = 0;
|
|
3489
3490
|
this.activeCheckoutAbort = null;
|
|
3490
3491
|
this.businessIdResolvePromise = null;
|
|
@@ -3499,7 +3500,7 @@ var CimplifyElements = class {
|
|
|
3499
3500
|
window.addEventListener("message", this.boundHandleMessage);
|
|
3500
3501
|
}
|
|
3501
3502
|
this.stopSessionSync = client.events.on(SESSION_CLAIMED, () => {
|
|
3502
|
-
if (!this.authInProgress
|
|
3503
|
+
if (!this.authInProgress) this._syncHostSession();
|
|
3503
3504
|
});
|
|
3504
3505
|
void this.restoreSession();
|
|
3505
3506
|
}
|
|
@@ -3508,20 +3509,24 @@ var CimplifyElements = class {
|
|
|
3508
3509
|
console.debug(...args);
|
|
3509
3510
|
}
|
|
3510
3511
|
}
|
|
3511
|
-
|
|
3512
|
-
if (this.authEstablishmentInProgress) return;
|
|
3512
|
+
_syncHostSession(element) {
|
|
3513
3513
|
const sessionToken = this.client.getSessionToken();
|
|
3514
|
-
|
|
3514
|
+
if (!sessionToken) return;
|
|
3515
|
+
const identity = {
|
|
3516
|
+
type: MESSAGE_TYPES.IDENTITY,
|
|
3517
|
+
sessionToken,
|
|
3518
|
+
accessToken: this.client.getAccessToken() ?? this.accessToken,
|
|
3519
|
+
customer: this.identityCustomer()
|
|
3520
|
+
};
|
|
3515
3521
|
const targets = element ? [element] : Array.from(this.elements.values());
|
|
3516
3522
|
for (const target of targets) {
|
|
3517
|
-
|
|
3518
|
-
target.sendMessage({ type: MESSAGE_TYPES.SET_SESSION, sessionToken });
|
|
3519
|
-
}
|
|
3520
|
-
if (token) {
|
|
3521
|
-
target.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
|
|
3522
|
-
}
|
|
3523
|
+
target.sendMessage(identity);
|
|
3523
3524
|
}
|
|
3524
3525
|
}
|
|
3526
|
+
identityCustomer() {
|
|
3527
|
+
if (!this.accessToken || !this.customerId || !this.customerData) return null;
|
|
3528
|
+
return { id: this.customerId, ...this.customerData };
|
|
3529
|
+
}
|
|
3525
3530
|
create(type, options = {}) {
|
|
3526
3531
|
const existing = this.elements.get(type);
|
|
3527
3532
|
if (existing) return existing;
|
|
@@ -3540,11 +3545,7 @@ var CimplifyElements = class {
|
|
|
3540
3545
|
}
|
|
3541
3546
|
destroy() {
|
|
3542
3547
|
this.authGeneration += 1;
|
|
3543
|
-
if (this.authEstablishmentInProgress) {
|
|
3544
|
-
this.client.setAccessToken(null);
|
|
3545
|
-
}
|
|
3546
3548
|
this.authInProgress = false;
|
|
3547
|
-
this.authEstablishmentInProgress = false;
|
|
3548
3549
|
this.stopSessionSync();
|
|
3549
3550
|
this.stopSessionSync = () => {
|
|
3550
3551
|
};
|
|
@@ -3604,17 +3605,6 @@ var CimplifyElements = class {
|
|
|
3604
3605
|
);
|
|
3605
3606
|
}
|
|
3606
3607
|
this.checkoutInProgress = true;
|
|
3607
|
-
if (this.authEstablishmentInProgress) {
|
|
3608
|
-
await this.waitForAuthEstablishment(AUTH_ESTABLISHMENT_WAIT_MS);
|
|
3609
|
-
if (this.authEstablishmentInProgress) {
|
|
3610
|
-
this.checkoutInProgress = false;
|
|
3611
|
-
return toCheckoutError(
|
|
3612
|
-
ErrorCode.AUTH_INCOMPLETE,
|
|
3613
|
-
"Authentication must finish establishing the checkout session.",
|
|
3614
|
-
true
|
|
3615
|
-
);
|
|
3616
|
-
}
|
|
3617
|
-
}
|
|
3618
3608
|
if (!options.cart_id && !options.intent_id) {
|
|
3619
3609
|
this.debug("[cimplify:checkout] BLOCKED: no cart_id or intent_id");
|
|
3620
3610
|
this.checkoutInProgress = false;
|
|
@@ -3819,7 +3809,7 @@ var CimplifyElements = class {
|
|
|
3819
3809
|
hasAddress: !!processMessage.address,
|
|
3820
3810
|
isUnifiedCheckout
|
|
3821
3811
|
});
|
|
3822
|
-
this.
|
|
3812
|
+
this._syncHostSession(checkoutElement);
|
|
3823
3813
|
checkoutElement.sendMessage(processMessage);
|
|
3824
3814
|
this.debug("[cimplify:checkout] postMessage sent, waiting for checkout_complete...");
|
|
3825
3815
|
});
|
|
@@ -3930,7 +3920,6 @@ var CimplifyElements = class {
|
|
|
3930
3920
|
this.customerData = null;
|
|
3931
3921
|
this.addressData = null;
|
|
3932
3922
|
this.paymentData = null;
|
|
3933
|
-
this.authEstablishmentInProgress = false;
|
|
3934
3923
|
this.client.clearSession();
|
|
3935
3924
|
this.broadcastClearedSession();
|
|
3936
3925
|
}
|
|
@@ -3966,73 +3955,73 @@ var CimplifyElements = class {
|
|
|
3966
3955
|
this.broadcastClearedSession();
|
|
3967
3956
|
return;
|
|
3968
3957
|
}
|
|
3969
|
-
if (application.kind !== "authenticated"
|
|
3970
|
-
|
|
3971
|
-
}
|
|
3958
|
+
if (application.kind !== "authenticated") return;
|
|
3959
|
+
this._syncHostSession();
|
|
3972
3960
|
this.elements.forEach((element) => element._emitAuthenticated(application.data));
|
|
3973
3961
|
}
|
|
3974
3962
|
async applyAccessToken(token, generation) {
|
|
3975
3963
|
if (this.authGeneration !== generation) return { kind: "incomplete" };
|
|
3976
|
-
this.
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
if (
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
} else {
|
|
3991
|
-
this.client.setAccessToken(null);
|
|
3992
|
-
}
|
|
3993
|
-
return {
|
|
3994
|
-
kind: "claim_failed",
|
|
3995
|
-
code: claim.error.code,
|
|
3996
|
-
message: claim.error.userMessage
|
|
3997
|
-
};
|
|
3998
|
-
}
|
|
3999
|
-
this.accessToken = token;
|
|
4000
|
-
this.accountId = decodeJwtSub(token);
|
|
4001
|
-
if (!await this.hydrateCustomerData(generation, token, true)) {
|
|
4002
|
-
return { kind: "incomplete" };
|
|
3964
|
+
this.accessToken = null;
|
|
3965
|
+
this.accountId = null;
|
|
3966
|
+
this.customerId = null;
|
|
3967
|
+
this.customerData = null;
|
|
3968
|
+
this.addressData = null;
|
|
3969
|
+
this.paymentData = null;
|
|
3970
|
+
this.client.setAccessToken(token);
|
|
3971
|
+
const claim = await this.client.session.claim();
|
|
3972
|
+
if (!this.isAuthGenerationCurrent(generation, token)) return { kind: "incomplete" };
|
|
3973
|
+
if (!claim.ok && claim.error.code !== "already_claimed") {
|
|
3974
|
+
if (this.client.hasClaimedSessionAuthority()) {
|
|
3975
|
+
this.client.clearSession();
|
|
3976
|
+
} else {
|
|
3977
|
+
this.client.setAccessToken(null);
|
|
4003
3978
|
}
|
|
4004
|
-
if (!this.isAuthGenerationCurrent(generation, token)) return { kind: "incomplete" };
|
|
4005
3979
|
return {
|
|
4006
|
-
kind: "
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
customerId: this.customerId ?? "",
|
|
4010
|
-
token,
|
|
4011
|
-
customer: this.customerData ?? { name: "", email: null, phone: null }
|
|
4012
|
-
}
|
|
3980
|
+
kind: "claim_failed",
|
|
3981
|
+
code: claim.error.code,
|
|
3982
|
+
message: claim.error.userMessage
|
|
4013
3983
|
};
|
|
4014
|
-
} finally {
|
|
4015
|
-
this.authEstablishmentInProgress = false;
|
|
4016
|
-
}
|
|
4017
|
-
}
|
|
4018
|
-
async waitForAuthEstablishment(timeoutMs) {
|
|
4019
|
-
const deadline = Date.now() + timeoutMs;
|
|
4020
|
-
while (this.authEstablishmentInProgress && Date.now() < deadline) {
|
|
4021
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
4022
3984
|
}
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
if (!this.
|
|
4026
|
-
return
|
|
3985
|
+
this.accessToken = token;
|
|
3986
|
+
this.accountId = decodeJwtSub(token);
|
|
3987
|
+
if (!await this.hydrateCustomerData(generation, token, true)) {
|
|
3988
|
+
return { kind: "incomplete" };
|
|
4027
3989
|
}
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
3990
|
+
if (!this.isAuthGenerationCurrent(generation, token)) return { kind: "incomplete" };
|
|
3991
|
+
return {
|
|
3992
|
+
kind: "authenticated",
|
|
3993
|
+
data: {
|
|
3994
|
+
accountId: this.accountId ?? "",
|
|
3995
|
+
customerId: this.customerId ?? "",
|
|
3996
|
+
token,
|
|
3997
|
+
customer: this.customerData ?? { name: "", email: null, phone: null }
|
|
4032
3998
|
}
|
|
4033
|
-
|
|
3999
|
+
};
|
|
4000
|
+
}
|
|
4001
|
+
adoptEstablishedSession(sourceElement, session) {
|
|
4002
|
+
this.authGeneration += 1;
|
|
4003
|
+
this.authInProgress = false;
|
|
4004
|
+
const { id, ...customer } = session.customer;
|
|
4005
|
+
this.accessToken = session.accessToken;
|
|
4006
|
+
this.accountId = decodeJwtSub(session.accessToken);
|
|
4007
|
+
this.customerId = id;
|
|
4008
|
+
this.customerData = customer;
|
|
4009
|
+
this.addressData = null;
|
|
4010
|
+
this.paymentData = null;
|
|
4011
|
+
this.client.setAccessToken(session.accessToken);
|
|
4012
|
+
this.persistRefreshToken(session.refreshToken);
|
|
4013
|
+
this.client.session.adopt(session.accessToken, {
|
|
4014
|
+
sessionToken: session.sessionToken,
|
|
4015
|
+
customerName: session.customer.name,
|
|
4016
|
+
customer: session.customer,
|
|
4017
|
+
cart: null
|
|
4018
|
+
});
|
|
4019
|
+
sourceElement._emitAuthenticated({
|
|
4020
|
+
accountId: this.accountId,
|
|
4021
|
+
customerId: id,
|
|
4022
|
+
token: session.accessToken,
|
|
4023
|
+
customer
|
|
4034
4024
|
});
|
|
4035
|
-
return true;
|
|
4036
4025
|
}
|
|
4037
4026
|
broadcastClearedSession() {
|
|
4038
4027
|
const sessionToken = this.client.getSessionToken();
|
|
@@ -4079,7 +4068,8 @@ var CimplifyElements = class {
|
|
|
4079
4068
|
return;
|
|
4080
4069
|
}
|
|
4081
4070
|
const application = await this.applyAccessToken(accessToken, generation);
|
|
4082
|
-
if (application.kind === "authenticated"
|
|
4071
|
+
if (application.kind === "authenticated") {
|
|
4072
|
+
this._syncHostSession();
|
|
4083
4073
|
sourceElement._emitAuthenticated(application.data);
|
|
4084
4074
|
} else if (application.kind === "claim_failed") {
|
|
4085
4075
|
sourceElement._emitError({
|
|
@@ -4118,29 +4108,7 @@ var CimplifyElements = class {
|
|
|
4118
4108
|
this.startEmbeddedAuth(sourceElement, message);
|
|
4119
4109
|
break;
|
|
4120
4110
|
case MESSAGE_TYPES.SESSION_ESTABLISHED:
|
|
4121
|
-
|
|
4122
|
-
this.authInProgress = false;
|
|
4123
|
-
const generation = ++this.authGeneration;
|
|
4124
|
-
void this.applyAccessToken(message.accessToken, generation).then((application) => {
|
|
4125
|
-
if (this.authGeneration !== generation) return;
|
|
4126
|
-
if (application.kind === "claim_failed") {
|
|
4127
|
-
this.clearPersistedSession();
|
|
4128
|
-
sourceElement.sendMessage({
|
|
4129
|
-
type: MESSAGE_TYPES.SESSION_ESTABLISHMENT_FAILED,
|
|
4130
|
-
accessToken: message.accessToken,
|
|
4131
|
-
code: application.code,
|
|
4132
|
-
message: application.message
|
|
4133
|
-
});
|
|
4134
|
-
this.broadcastClearedSession();
|
|
4135
|
-
return;
|
|
4136
|
-
}
|
|
4137
|
-
if (application.kind !== "authenticated" || !this.broadcastAccessToken(message.accessToken, generation)) {
|
|
4138
|
-
return;
|
|
4139
|
-
}
|
|
4140
|
-
this.persistRefreshToken(message.refreshToken);
|
|
4141
|
-
sourceElement._emitAuthenticated(application.data);
|
|
4142
|
-
});
|
|
4143
|
-
}
|
|
4111
|
+
this.adoptEstablishedSession(sourceElement, message);
|
|
4144
4112
|
break;
|
|
4145
4113
|
case MESSAGE_TYPES.ADDRESS_CHANGED:
|
|
4146
4114
|
case MESSAGE_TYPES.ADDRESS_SELECTED:
|
|
@@ -4162,7 +4130,6 @@ var CimplifyElements = class {
|
|
|
4162
4130
|
case MESSAGE_TYPES.CONTINUE_WITHOUT_SAVED_DETAILS: {
|
|
4163
4131
|
this.authGeneration += 1;
|
|
4164
4132
|
this.authInProgress = false;
|
|
4165
|
-
this.authEstablishmentInProgress = false;
|
|
4166
4133
|
const carriedIdentityAuthority = Boolean(this.client.getAccessToken()) || this.client.hasClaimedSessionAuthority();
|
|
4167
4134
|
this.accessToken = null;
|
|
4168
4135
|
this.accountId = null;
|
|
@@ -4187,7 +4154,6 @@ var CimplifyElements = class {
|
|
|
4187
4154
|
case MESSAGE_TYPES.LOGOUT_COMPLETE:
|
|
4188
4155
|
this.authGeneration += 1;
|
|
4189
4156
|
this.authInProgress = false;
|
|
4190
|
-
this.authEstablishmentInProgress = false;
|
|
4191
4157
|
if (this.checkoutInProgress && this.activeCheckoutAbort) {
|
|
4192
4158
|
this.activeCheckoutAbort();
|
|
4193
4159
|
}
|
|
@@ -4436,14 +4402,7 @@ var CimplifyElement = class {
|
|
|
4436
4402
|
hostedSessionId: this.options.hostedSessionId,
|
|
4437
4403
|
initialTerms: this.options.initialTerms
|
|
4438
4404
|
});
|
|
4439
|
-
|
|
4440
|
-
const sessionToken = this.parent.getSessionToken();
|
|
4441
|
-
if (sessionToken) {
|
|
4442
|
-
this.sendMessage({ type: MESSAGE_TYPES.SET_SESSION, sessionToken });
|
|
4443
|
-
}
|
|
4444
|
-
if (token) {
|
|
4445
|
-
this.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
|
|
4446
|
-
}
|
|
4405
|
+
this.parent._syncHostSession(this);
|
|
4447
4406
|
this.pendingInit = null;
|
|
4448
4407
|
}
|
|
4449
4408
|
this.flushPending();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { messagePreview } from './chunk-U4MW6PYU.mjs';
|
|
2
|
-
import { ok, err, safe, generateIdempotencyKey, SESSION_CLEARED, SESSION_CLAIMED, createClientEvents, createDefaultPaymentAuthorizationAdapterRegistry, AUTH_TOKEN_CHANGED, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-
|
|
3
|
-
import { PURCHASE_INTENT_RESOLVE_STATUS, PURCHASE_INTENT_CONFIRM_STATUS, PURCHASE_INTENT_RESOLUTION_KIND, PURCHASE_INTENT_ACTION_DECISION, CimplifyError, PURCHASE_INTENT_ERROR_CODE, ErrorCode, IdempotencyMismatchError, enrichError } from './chunk-
|
|
2
|
+
import { ok, err, safe, generateIdempotencyKey, SESSION_CLEARED, SESSION_CLAIMED, createClientEvents, createDefaultPaymentAuthorizationAdapterRegistry, AUTH_TOKEN_CHANGED, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-OTPLI3JY.mjs';
|
|
3
|
+
import { PURCHASE_INTENT_RESOLVE_STATUS, PURCHASE_INTENT_CONFIRM_STATUS, PURCHASE_INTENT_RESOLUTION_KIND, PURCHASE_INTENT_ACTION_DECISION, CimplifyError, PURCHASE_INTENT_ERROR_CODE, ErrorCode, IdempotencyMismatchError, enrichError } from './chunk-KG3WT4PR.mjs';
|
|
4
4
|
|
|
5
5
|
// src/types/observability.ts
|
|
6
6
|
var SESSION_CHANGE_SOURCE = {
|
|
@@ -741,7 +741,11 @@ var ActivityService = class {
|
|
|
741
741
|
void this.postEvents(events, session ?? this.sessions.beginEvent()).catch(() => {
|
|
742
742
|
});
|
|
743
743
|
}
|
|
744
|
+
hasStorefrontIdentity() {
|
|
745
|
+
return this.client.getPublicKey().trim().length > 0;
|
|
746
|
+
}
|
|
744
747
|
async postEvents(events, session) {
|
|
748
|
+
if (!this.hasStorefrontIdentity()) return;
|
|
745
749
|
const generation = this.captureGeneration();
|
|
746
750
|
await this.bootstrapSession(session, false, generation);
|
|
747
751
|
if (!this.isCurrentGeneration(generation)) return;
|
|
@@ -756,6 +760,7 @@ var ActivityService = class {
|
|
|
756
760
|
);
|
|
757
761
|
}
|
|
758
762
|
bootstrapSession(session, force = false, generation = this.captureGeneration()) {
|
|
763
|
+
if (!this.hasStorefrontIdentity()) return Promise.resolve();
|
|
759
764
|
if (!force && !session.requiresBootstrap) return Promise.resolve();
|
|
760
765
|
if (!force && this.bootstrapRequest?.sessionId === session.id && sameActivityGeneration(this.bootstrapRequest.generation, generation)) {
|
|
761
766
|
return this.bootstrapRequest.promise;
|
|
@@ -1076,85 +1081,9 @@ function chatRealtimeUpdateFromWire(envelope) {
|
|
|
1076
1081
|
}
|
|
1077
1082
|
|
|
1078
1083
|
// src/support.ts
|
|
1079
|
-
var CLAIM_TIMEOUT_MS = 15e3;
|
|
1080
1084
|
var SupportService = class {
|
|
1081
1085
|
constructor(client) {
|
|
1082
1086
|
this.client = client;
|
|
1083
|
-
this.claimInFlight = null;
|
|
1084
|
-
this.claimInFlightToken = null;
|
|
1085
|
-
this.lastClaimedAccessToken = null;
|
|
1086
|
-
this.claimedName = null;
|
|
1087
|
-
this.client.events.on(SESSION_CLEARED, () => {
|
|
1088
|
-
this.lastClaimedAccessToken = null;
|
|
1089
|
-
this.claimedName = null;
|
|
1090
|
-
});
|
|
1091
|
-
this.client.events.on(SESSION_CLAIMED, (event) => {
|
|
1092
|
-
if (event.customerName) this.claimedName = event.customerName;
|
|
1093
|
-
});
|
|
1094
|
-
}
|
|
1095
|
-
/** The verified customer this session's conversation was claimed for, null while anonymous. */
|
|
1096
|
-
get claimedCustomerName() {
|
|
1097
|
-
return this.claimedName;
|
|
1098
|
-
}
|
|
1099
|
-
/**
|
|
1100
|
-
* Claim the anonymous session for the verified Link identity: the server
|
|
1101
|
-
* verifies the access token, rotates the session token (adopted here, so
|
|
1102
|
-
* every subsequent request rides the bound session), folds the guest cart
|
|
1103
|
-
* in, and opens or reuses the account's canonical direct Chat thread.
|
|
1104
|
-
*
|
|
1105
|
-
* Idempotent and single-flight: concurrent calls share one request, and a
|
|
1106
|
-
* token already claimed by this instance short-circuits without a network
|
|
1107
|
-
* round trip. A session already bound to another Link account is rejected
|
|
1108
|
-
* rather than transferring that account's cart. Emits `session:claimed` on
|
|
1109
|
-
* the client's event channel.
|
|
1110
|
-
*/
|
|
1111
|
-
async claimConversation() {
|
|
1112
|
-
const accessToken = this.client.getAccessToken();
|
|
1113
|
-
if (!accessToken) {
|
|
1114
|
-
return err(new CimplifyError("not_authenticated", "No access token to claim with"));
|
|
1115
|
-
}
|
|
1116
|
-
if (this.claimInFlight) {
|
|
1117
|
-
if (this.claimInFlightToken === accessToken) return this.claimInFlight;
|
|
1118
|
-
await this.claimInFlight;
|
|
1119
|
-
return this.claimConversation();
|
|
1120
|
-
}
|
|
1121
|
-
if (this.lastClaimedAccessToken === accessToken) {
|
|
1122
|
-
return err(new CimplifyError("already_claimed", "Session already claimed for this token"));
|
|
1123
|
-
}
|
|
1124
|
-
const epoch = this.client.getSessionEpoch();
|
|
1125
|
-
this.claimInFlightToken = accessToken;
|
|
1126
|
-
this.claimInFlight = (async () => {
|
|
1127
|
-
const result = await safe(
|
|
1128
|
-
this.client.post(
|
|
1129
|
-
"/api/v1/support/conversation/claim",
|
|
1130
|
-
{ access_token: accessToken },
|
|
1131
|
-
{ timeoutMs: CLAIM_TIMEOUT_MS }
|
|
1132
|
-
)
|
|
1133
|
-
);
|
|
1134
|
-
if (result.ok) {
|
|
1135
|
-
if (this.client.getSessionEpoch() !== epoch) {
|
|
1136
|
-
return err(
|
|
1137
|
-
new CimplifyError("session_cleared", "Session was cleared during the claim")
|
|
1138
|
-
);
|
|
1139
|
-
}
|
|
1140
|
-
this.lastClaimedAccessToken = accessToken;
|
|
1141
|
-
this.claimedName = result.value.customer_name || null;
|
|
1142
|
-
this.client.adoptSessionToken(result.value.session_token);
|
|
1143
|
-
this.client.publishSessionClaimed(this.claimedName);
|
|
1144
|
-
this.client.events.emit(SESSION_CLAIMED, {
|
|
1145
|
-
sessionToken: result.value.session_token,
|
|
1146
|
-
threadId: result.value.thread.id,
|
|
1147
|
-
customerName: result.value.customer_name
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
return result;
|
|
1151
|
-
})();
|
|
1152
|
-
try {
|
|
1153
|
-
return await this.claimInFlight;
|
|
1154
|
-
} finally {
|
|
1155
|
-
this.claimInFlight = null;
|
|
1156
|
-
this.claimInFlightToken = null;
|
|
1157
|
-
}
|
|
1158
1087
|
}
|
|
1159
1088
|
/**
|
|
1160
1089
|
* Retry verified external-history discovery for the current storefront.
|
|
@@ -1270,6 +1199,95 @@ var SupportService = class {
|
|
|
1270
1199
|
}
|
|
1271
1200
|
};
|
|
1272
1201
|
|
|
1202
|
+
// src/session.ts
|
|
1203
|
+
var CLAIM_TIMEOUT_MS = 15e3;
|
|
1204
|
+
var CLAIM_PATH = "/api/v1/auth/session/claim";
|
|
1205
|
+
var SessionService = class {
|
|
1206
|
+
constructor(client) {
|
|
1207
|
+
this.client = client;
|
|
1208
|
+
this.claimInFlight = null;
|
|
1209
|
+
this.claimInFlightToken = null;
|
|
1210
|
+
this.lastClaimedAccessToken = null;
|
|
1211
|
+
this.claimedName = null;
|
|
1212
|
+
this.client.events.on(SESSION_CLEARED, () => {
|
|
1213
|
+
this.lastClaimedAccessToken = null;
|
|
1214
|
+
this.claimedName = null;
|
|
1215
|
+
});
|
|
1216
|
+
this.client.events.on(SESSION_CLAIMED, (event) => {
|
|
1217
|
+
if (event.customerName) this.claimedName = event.customerName;
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
/** The verified customer this session is bound to, null while anonymous. */
|
|
1221
|
+
get claimedCustomerName() {
|
|
1222
|
+
return this.claimedName;
|
|
1223
|
+
}
|
|
1224
|
+
/** Adopt a session another holder already bound for this bearer. */
|
|
1225
|
+
adopt(accessToken, session) {
|
|
1226
|
+
this.lastClaimedAccessToken = accessToken;
|
|
1227
|
+
this.claimedName = session.customerName || null;
|
|
1228
|
+
this.client.adoptSessionToken(session.sessionToken);
|
|
1229
|
+
this.client.publishSessionClaimed(this.claimedName);
|
|
1230
|
+
this.client.events.emit(SESSION_CLAIMED, session);
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* Bind the anonymous session to the verified Link identity in one server
|
|
1234
|
+
* transaction: verify the bearer, rotate the session token (adopted here),
|
|
1235
|
+
* fold the guest cart under the customer and re-price it. A repeat for the
|
|
1236
|
+
* same account and session returns the same session.
|
|
1237
|
+
*
|
|
1238
|
+
* Idempotent and single-flight: concurrent calls share one request, and a
|
|
1239
|
+
* token already claimed by this instance short-circuits without a network
|
|
1240
|
+
* round trip. A session already bound to another Link account is rejected
|
|
1241
|
+
* rather than transferring that account's cart. Emits `session:claimed` on
|
|
1242
|
+
* the client's event channel.
|
|
1243
|
+
*/
|
|
1244
|
+
async claim() {
|
|
1245
|
+
const accessToken = this.client.getAccessToken();
|
|
1246
|
+
if (!accessToken) {
|
|
1247
|
+
return err(new CimplifyError("not_authenticated", "No access token to claim with"));
|
|
1248
|
+
}
|
|
1249
|
+
if (this.claimInFlight) {
|
|
1250
|
+
if (this.claimInFlightToken === accessToken) return this.claimInFlight;
|
|
1251
|
+
await this.claimInFlight;
|
|
1252
|
+
return this.claim();
|
|
1253
|
+
}
|
|
1254
|
+
if (this.lastClaimedAccessToken === accessToken) {
|
|
1255
|
+
return err(new CimplifyError("already_claimed", "Session already claimed for this token"));
|
|
1256
|
+
}
|
|
1257
|
+
const epoch = this.client.getSessionEpoch();
|
|
1258
|
+
this.claimInFlightToken = accessToken;
|
|
1259
|
+
this.claimInFlight = (async () => {
|
|
1260
|
+
const result = await safe(
|
|
1261
|
+
this.client.post(
|
|
1262
|
+
CLAIM_PATH,
|
|
1263
|
+
{ access_token: accessToken },
|
|
1264
|
+
{ timeoutMs: CLAIM_TIMEOUT_MS }
|
|
1265
|
+
)
|
|
1266
|
+
);
|
|
1267
|
+
if (result.ok) {
|
|
1268
|
+
if (this.client.getSessionEpoch() !== epoch) {
|
|
1269
|
+
return err(
|
|
1270
|
+
new CimplifyError("session_cleared", "Session was cleared during the claim")
|
|
1271
|
+
);
|
|
1272
|
+
}
|
|
1273
|
+
this.adopt(accessToken, {
|
|
1274
|
+
sessionToken: result.value.session_token,
|
|
1275
|
+
customerName: result.value.customer.name,
|
|
1276
|
+
customer: result.value.customer,
|
|
1277
|
+
cart: result.value.cart
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
return result;
|
|
1281
|
+
})();
|
|
1282
|
+
try {
|
|
1283
|
+
return await this.claimInFlight;
|
|
1284
|
+
} finally {
|
|
1285
|
+
this.claimInFlight = null;
|
|
1286
|
+
this.claimInFlightToken = null;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
};
|
|
1290
|
+
|
|
1273
1291
|
// src/internal/cross-tab-session.ts
|
|
1274
1292
|
var CROSS_TAB_SESSION_HUB_KEY = /* @__PURE__ */ Symbol.for("@cimplify/sdk.cross-tab-session-hub");
|
|
1275
1293
|
var SESSION_SYNC_STORAGE_KEY = "cimplify_session_sync";
|
|
@@ -1623,9 +1641,9 @@ var CimplifyClient = class {
|
|
|
1623
1641
|
* merchant auth flows, never by the raw token setter. Global Link clients
|
|
1624
1642
|
* have no storefront tenant and therefore activate without this step.
|
|
1625
1643
|
*/
|
|
1626
|
-
|
|
1644
|
+
autoClaimSession() {
|
|
1627
1645
|
if (typeof window === "undefined" || !this.sessionToken || !this.accessToken) return;
|
|
1628
|
-
void this.
|
|
1646
|
+
void this.session.claim();
|
|
1629
1647
|
}
|
|
1630
1648
|
/**
|
|
1631
1649
|
* Adopt a server-rotated session token (claim flow). The old token stays
|
|
@@ -1713,8 +1731,9 @@ var CimplifyClient = class {
|
|
|
1713
1731
|
this.sessionEpoch++;
|
|
1714
1732
|
this.events.emit(SESSION_CLAIMED, {
|
|
1715
1733
|
sessionToken: payload.token,
|
|
1716
|
-
|
|
1717
|
-
|
|
1734
|
+
customerName: payload.name ?? "",
|
|
1735
|
+
customer: null,
|
|
1736
|
+
cart: null
|
|
1718
1737
|
});
|
|
1719
1738
|
} else {
|
|
1720
1739
|
this.accessToken = null;
|
|
@@ -2371,6 +2390,12 @@ var CimplifyClient = class {
|
|
|
2371
2390
|
}
|
|
2372
2391
|
return this._support;
|
|
2373
2392
|
}
|
|
2393
|
+
get session() {
|
|
2394
|
+
if (!this._session) {
|
|
2395
|
+
this._session = new SessionService(this);
|
|
2396
|
+
}
|
|
2397
|
+
return this._session;
|
|
2398
|
+
}
|
|
2374
2399
|
buildWsUrl(path) {
|
|
2375
2400
|
const protocol = this.baseUrl.startsWith("https") ? "wss:" : "ws:";
|
|
2376
2401
|
const host = this.baseUrl.replace(/^https?:\/\//, "");
|
|
@@ -2391,4 +2416,4 @@ function createCimplifyClient(config = {}) {
|
|
|
2391
2416
|
return new CimplifyClient(config);
|
|
2392
2417
|
}
|
|
2393
2418
|
|
|
2394
|
-
export { ActivityService, CimplifyClient, DeliveryService, HostedPurchaseIntentService, PURCHASE_INTENT_ROUTE, PlacesService, PurchaseIntentResolver, PurchaseIntentService, SESSION_CHANGE_SOURCE, StoreCreditQueries, SubscriptionService, SupportService, UploadService, chatRealtimeUpdateFromWire, createCimplifyClient };
|
|
2419
|
+
export { ActivityService, CimplifyClient, DeliveryService, HostedPurchaseIntentService, PURCHASE_INTENT_ROUTE, PlacesService, PurchaseIntentResolver, PurchaseIntentService, SESSION_CHANGE_SOURCE, SessionService, StoreCreditQueries, SubscriptionService, SupportService, UploadService, chatRealtimeUpdateFromWire, createCimplifyClient };
|