@cimplify/sdk 0.106.2 → 0.107.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 +20 -20
- package/dist/advanced.mjs +1 -1
- package/dist/{catalogue-ChBjPPME.d.ts → catalogue-BohD-jU_.d.mts} +44 -38
- package/dist/{catalogue-CVKH9faR.d.mts → catalogue-C4xKpirp.d.ts} +44 -38
- package/dist/{chunk-T3MXI7JD.mjs → chunk-2I6YKE6Q.mjs} +85 -126
- package/dist/{chunk-7O2BBPDM.js → chunk-73HY36Z7.js} +4 -4
- package/dist/{chunk-B7JH5D3J.js → chunk-HKCB73AJ.js} +85 -126
- package/dist/{chunk-4VTFTLH7.mjs → chunk-IWZKCL3P.mjs} +2 -2
- package/dist/{chunk-L4XKIMUO.mjs → chunk-MKZXZDHE.mjs} +17 -0
- package/dist/{chunk-NJK3THWT.js → chunk-NX5YBQZP.js} +17 -0
- package/dist/{chunk-LJAZ7H4I.mjs → chunk-P4HYAV3L.mjs} +102 -82
- package/dist/{chunk-BCLGREHS.js → chunk-W4ZFZPPY.js} +181 -160
- package/dist/{client-BfKFK7cn.d.mts → client-BBFfAtn4.d.mts} +2 -2
- package/dist/{client-DoczTJbs.d.ts → client-ByURQZM9.d.ts} +2 -2
- package/dist/{checkout-XoV4HNg2.d.mts → elements-Dtqe9Ekd.d.mts} +348 -361
- package/dist/{checkout-XoV4HNg2.d.ts → elements-Dtqe9Ekd.d.ts} +348 -361
- package/dist/{index-DEUorPUO.d.mts → index-7oz-hVVA.d.mts} +2 -2
- package/dist/{index-DRMBo26v.d.mts → index-B6mukQYB.d.mts} +2 -2
- package/dist/{index-Dn6xCpDe.d.ts → index-CvLuAMjQ.d.ts} +2 -2
- package/dist/{index-DweR60Cv.d.ts → index-DFqDU6yU.d.ts} +2 -2
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +71 -67
- package/dist/index.mjs +3 -3
- package/dist/mock/cli.mjs +17 -0
- package/dist/mock/library.js +17 -0
- package/dist/mock/library.mjs +17 -0
- package/dist/mock/msw.js +17 -0
- package/dist/mock/msw.mjs +17 -0
- package/dist/{price-De-sxcuj.d.ts → price-B4jL81ef.d.ts} +1 -1
- package/dist/{price-CUGIYRtD.d.mts → price-Pyq-vlrm.d.mts} +1 -1
- package/dist/react.d.mts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +34 -34
- package/dist/react.mjs +5 -5
- package/dist/{server-7soMMUgP.d.ts → server-Cowuvfbr.d.ts} +1 -1
- package/dist/{server-DDEJ7e9s.d.mts → server-KilvZJU0.d.mts} +1 -1
- package/dist/server.d.mts +3 -3
- package/dist/server.d.ts +3 -3
- package/dist/server.js +7 -7
- package/dist/server.mjs +2 -2
- package/dist/testing/msw.d.mts +2 -2
- package/dist/testing/msw.d.ts +2 -2
- package/dist/testing/msw.js +2 -2
- package/dist/testing/msw.mjs +1 -1
- package/dist/testing/suite.d.mts +5 -5
- package/dist/testing/suite.d.ts +5 -5
- package/dist/testing/suite.js +24 -24
- package/dist/testing/suite.mjs +4 -4
- package/dist/testing.d.mts +4 -4
- package/dist/testing.d.ts +4 -4
- package/dist/testing.js +116 -116
- package/dist/testing.mjs +5 -5
- package/dist/utils.d.mts +3 -3
- package/dist/utils.d.ts +3 -3
- package/package.json +1 -1
|
@@ -2407,7 +2407,7 @@ var LinkService = class {
|
|
|
2407
2407
|
this.client.activity.refreshIdentity();
|
|
2408
2408
|
return result;
|
|
2409
2409
|
}
|
|
2410
|
-
const claim = await this.client.
|
|
2410
|
+
const claim = await this.client.session.claim();
|
|
2411
2411
|
if (fence.generation !== this.activationGeneration || fence.publicKeyEpoch !== this.client.getPublicKeyEpoch() || this.client.getAccessToken() !== accessToken) {
|
|
2412
2412
|
return this.supersededActivation();
|
|
2413
2413
|
}
|
|
@@ -2631,7 +2631,7 @@ var AuthService = class {
|
|
|
2631
2631
|
if (result.ok && result.value.session_token) {
|
|
2632
2632
|
this.client.setAccessToken(result.value.session_token);
|
|
2633
2633
|
this.client.activity.refreshIdentity();
|
|
2634
|
-
this.client.
|
|
2634
|
+
this.client.autoClaimSession();
|
|
2635
2635
|
}
|
|
2636
2636
|
return result;
|
|
2637
2637
|
}
|
|
@@ -2924,13 +2924,10 @@ var ELEMENT_TYPES = {
|
|
|
2924
2924
|
};
|
|
2925
2925
|
var MESSAGE_TYPES = {
|
|
2926
2926
|
INIT: "init",
|
|
2927
|
-
|
|
2928
|
-
SET_SESSION: "set_session",
|
|
2927
|
+
IDENTITY: "identity",
|
|
2929
2928
|
SESSION_CLEARED: "session_cleared",
|
|
2930
2929
|
SET_CART: "set_cart",
|
|
2931
2930
|
GET_DATA: "get_data",
|
|
2932
|
-
NAVIGATE: "navigate",
|
|
2933
|
-
REFRESH_TOKEN: "refresh_token",
|
|
2934
2931
|
LOGOUT: "logout",
|
|
2935
2932
|
PROCESS_CHECKOUT: "process_checkout",
|
|
2936
2933
|
ABORT_CHECKOUT: "abort_checkout",
|
|
@@ -2943,7 +2940,6 @@ var MESSAGE_TYPES = {
|
|
|
2943
2940
|
LOGOUT_COMPLETE: "logout_complete",
|
|
2944
2941
|
AUTH_REQUESTED: "auth_requested",
|
|
2945
2942
|
SESSION_ESTABLISHED: "session_established",
|
|
2946
|
-
SESSION_ESTABLISHMENT_FAILED: "session_establishment_failed",
|
|
2947
2943
|
CONTINUE_WITHOUT_SAVED_DETAILS: "continue_without_saved_details",
|
|
2948
2944
|
CONTACT_PROVIDED: "contact_provided",
|
|
2949
2945
|
CHECKOUT_STATUS: "checkout_status",
|
|
@@ -3347,7 +3343,6 @@ function toCheckoutError(code, message, recoverable) {
|
|
|
3347
3343
|
};
|
|
3348
3344
|
}
|
|
3349
3345
|
var DEFAULT_LINK_URL = "https://link.cimplify.io";
|
|
3350
|
-
var AUTH_ESTABLISHMENT_WAIT_MS = 8e3;
|
|
3351
3346
|
var AUTH_CONTACT_TYPES = new Set(Object.values(ELEMENTS_AUTH_CONTACT_TYPES));
|
|
3352
3347
|
var AUTH_MODES = new Set(Object.values(ELEMENTS_AUTH_MODES));
|
|
3353
3348
|
var AUTH_PROMPTS = new Set(Object.values(ELEMENTS_AUTH_PROMPTS));
|
|
@@ -3378,6 +3373,11 @@ function decodeJwtSub(token) {
|
|
|
3378
3373
|
return "";
|
|
3379
3374
|
}
|
|
3380
3375
|
}
|
|
3376
|
+
function isClaimedCustomer(value) {
|
|
3377
|
+
if (!value || typeof value !== "object") return false;
|
|
3378
|
+
const record = value;
|
|
3379
|
+
return typeof record.id === "string" && typeof record.name === "string" && (record.email === null || typeof record.email === "string") && (record.phone === null || typeof record.phone === "string");
|
|
3380
|
+
}
|
|
3381
3381
|
function isAllowedOrigin(origin) {
|
|
3382
3382
|
try {
|
|
3383
3383
|
const url = new URL(origin);
|
|
@@ -3434,8 +3434,10 @@ function parseIframeMessage(data) {
|
|
|
3434
3434
|
}
|
|
3435
3435
|
break;
|
|
3436
3436
|
case MESSAGE_TYPES.SESSION_ESTABLISHED:
|
|
3437
|
+
if (typeof record.sessionToken !== "string" || !record.sessionToken.trim()) return null;
|
|
3437
3438
|
if (typeof record.accessToken !== "string" || !record.accessToken.trim()) return null;
|
|
3438
3439
|
if (record.refreshToken !== void 0 && typeof record.refreshToken !== "string") return null;
|
|
3440
|
+
if (!isClaimedCustomer(record.customer)) return null;
|
|
3439
3441
|
break;
|
|
3440
3442
|
case MESSAGE_TYPES.ADDRESS_CHANGED:
|
|
3441
3443
|
case MESSAGE_TYPES.ADDRESS_SELECTED:
|
|
@@ -3486,7 +3488,6 @@ var CimplifyElements = class {
|
|
|
3486
3488
|
this.paymentData = null;
|
|
3487
3489
|
this.checkoutInProgress = false;
|
|
3488
3490
|
this.authInProgress = false;
|
|
3489
|
-
this.authEstablishmentInProgress = false;
|
|
3490
3491
|
this.authGeneration = 0;
|
|
3491
3492
|
this.activeCheckoutAbort = null;
|
|
3492
3493
|
this.businessIdResolvePromise = null;
|
|
@@ -3501,7 +3502,7 @@ var CimplifyElements = class {
|
|
|
3501
3502
|
window.addEventListener("message", this.boundHandleMessage);
|
|
3502
3503
|
}
|
|
3503
3504
|
this.stopSessionSync = client.events.on(SESSION_CLAIMED, () => {
|
|
3504
|
-
if (!this.authInProgress
|
|
3505
|
+
if (!this.authInProgress) this._syncHostSession();
|
|
3505
3506
|
});
|
|
3506
3507
|
void this.restoreSession();
|
|
3507
3508
|
}
|
|
@@ -3510,20 +3511,24 @@ var CimplifyElements = class {
|
|
|
3510
3511
|
console.debug(...args);
|
|
3511
3512
|
}
|
|
3512
3513
|
}
|
|
3513
|
-
|
|
3514
|
-
if (this.authEstablishmentInProgress) return;
|
|
3514
|
+
_syncHostSession(element) {
|
|
3515
3515
|
const sessionToken = this.client.getSessionToken();
|
|
3516
|
-
|
|
3516
|
+
if (!sessionToken) return;
|
|
3517
|
+
const identity = {
|
|
3518
|
+
type: MESSAGE_TYPES.IDENTITY,
|
|
3519
|
+
sessionToken,
|
|
3520
|
+
accessToken: this.client.getAccessToken() ?? this.accessToken,
|
|
3521
|
+
customer: this.identityCustomer()
|
|
3522
|
+
};
|
|
3517
3523
|
const targets = element ? [element] : Array.from(this.elements.values());
|
|
3518
3524
|
for (const target of targets) {
|
|
3519
|
-
|
|
3520
|
-
target.sendMessage({ type: MESSAGE_TYPES.SET_SESSION, sessionToken });
|
|
3521
|
-
}
|
|
3522
|
-
if (token) {
|
|
3523
|
-
target.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
|
|
3524
|
-
}
|
|
3525
|
+
target.sendMessage(identity);
|
|
3525
3526
|
}
|
|
3526
3527
|
}
|
|
3528
|
+
identityCustomer() {
|
|
3529
|
+
if (!this.accessToken || !this.customerId || !this.customerData) return null;
|
|
3530
|
+
return { id: this.customerId, ...this.customerData };
|
|
3531
|
+
}
|
|
3527
3532
|
create(type, options = {}) {
|
|
3528
3533
|
const existing = this.elements.get(type);
|
|
3529
3534
|
if (existing) return existing;
|
|
@@ -3542,11 +3547,7 @@ var CimplifyElements = class {
|
|
|
3542
3547
|
}
|
|
3543
3548
|
destroy() {
|
|
3544
3549
|
this.authGeneration += 1;
|
|
3545
|
-
if (this.authEstablishmentInProgress) {
|
|
3546
|
-
this.client.setAccessToken(null);
|
|
3547
|
-
}
|
|
3548
3550
|
this.authInProgress = false;
|
|
3549
|
-
this.authEstablishmentInProgress = false;
|
|
3550
3551
|
this.stopSessionSync();
|
|
3551
3552
|
this.stopSessionSync = () => {
|
|
3552
3553
|
};
|
|
@@ -3606,17 +3607,6 @@ var CimplifyElements = class {
|
|
|
3606
3607
|
);
|
|
3607
3608
|
}
|
|
3608
3609
|
this.checkoutInProgress = true;
|
|
3609
|
-
if (this.authEstablishmentInProgress) {
|
|
3610
|
-
await this.waitForAuthEstablishment(AUTH_ESTABLISHMENT_WAIT_MS);
|
|
3611
|
-
if (this.authEstablishmentInProgress) {
|
|
3612
|
-
this.checkoutInProgress = false;
|
|
3613
|
-
return toCheckoutError(
|
|
3614
|
-
chunkAVXA4F6G_js.ErrorCode.AUTH_INCOMPLETE,
|
|
3615
|
-
"Authentication must finish establishing the checkout session.",
|
|
3616
|
-
true
|
|
3617
|
-
);
|
|
3618
|
-
}
|
|
3619
|
-
}
|
|
3620
3610
|
if (!options.cart_id && !options.intent_id) {
|
|
3621
3611
|
this.debug("[cimplify:checkout] BLOCKED: no cart_id or intent_id");
|
|
3622
3612
|
this.checkoutInProgress = false;
|
|
@@ -3821,7 +3811,7 @@ var CimplifyElements = class {
|
|
|
3821
3811
|
hasAddress: !!processMessage.address,
|
|
3822
3812
|
isUnifiedCheckout
|
|
3823
3813
|
});
|
|
3824
|
-
this.
|
|
3814
|
+
this._syncHostSession(checkoutElement);
|
|
3825
3815
|
checkoutElement.sendMessage(processMessage);
|
|
3826
3816
|
this.debug("[cimplify:checkout] postMessage sent, waiting for checkout_complete...");
|
|
3827
3817
|
});
|
|
@@ -3932,7 +3922,6 @@ var CimplifyElements = class {
|
|
|
3932
3922
|
this.customerData = null;
|
|
3933
3923
|
this.addressData = null;
|
|
3934
3924
|
this.paymentData = null;
|
|
3935
|
-
this.authEstablishmentInProgress = false;
|
|
3936
3925
|
this.client.clearSession();
|
|
3937
3926
|
this.broadcastClearedSession();
|
|
3938
3927
|
}
|
|
@@ -3968,73 +3957,73 @@ var CimplifyElements = class {
|
|
|
3968
3957
|
this.broadcastClearedSession();
|
|
3969
3958
|
return;
|
|
3970
3959
|
}
|
|
3971
|
-
if (application.kind !== "authenticated"
|
|
3972
|
-
|
|
3973
|
-
}
|
|
3960
|
+
if (application.kind !== "authenticated") return;
|
|
3961
|
+
this._syncHostSession();
|
|
3974
3962
|
this.elements.forEach((element) => element._emitAuthenticated(application.data));
|
|
3975
3963
|
}
|
|
3976
3964
|
async applyAccessToken(token, generation) {
|
|
3977
3965
|
if (this.authGeneration !== generation) return { kind: "incomplete" };
|
|
3978
|
-
this.
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
if (
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
} else {
|
|
3993
|
-
this.client.setAccessToken(null);
|
|
3994
|
-
}
|
|
3995
|
-
return {
|
|
3996
|
-
kind: "claim_failed",
|
|
3997
|
-
code: claim.error.code,
|
|
3998
|
-
message: claim.error.userMessage
|
|
3999
|
-
};
|
|
4000
|
-
}
|
|
4001
|
-
this.accessToken = token;
|
|
4002
|
-
this.accountId = decodeJwtSub(token);
|
|
4003
|
-
if (!await this.hydrateCustomerData(generation, token, true)) {
|
|
4004
|
-
return { kind: "incomplete" };
|
|
3966
|
+
this.accessToken = null;
|
|
3967
|
+
this.accountId = null;
|
|
3968
|
+
this.customerId = null;
|
|
3969
|
+
this.customerData = null;
|
|
3970
|
+
this.addressData = null;
|
|
3971
|
+
this.paymentData = null;
|
|
3972
|
+
this.client.setAccessToken(token);
|
|
3973
|
+
const claim = await this.client.session.claim();
|
|
3974
|
+
if (!this.isAuthGenerationCurrent(generation, token)) return { kind: "incomplete" };
|
|
3975
|
+
if (!claim.ok && claim.error.code !== "already_claimed") {
|
|
3976
|
+
if (this.client.hasClaimedSessionAuthority()) {
|
|
3977
|
+
this.client.clearSession();
|
|
3978
|
+
} else {
|
|
3979
|
+
this.client.setAccessToken(null);
|
|
4005
3980
|
}
|
|
4006
|
-
if (!this.isAuthGenerationCurrent(generation, token)) return { kind: "incomplete" };
|
|
4007
3981
|
return {
|
|
4008
|
-
kind: "
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
customerId: this.customerId ?? "",
|
|
4012
|
-
token,
|
|
4013
|
-
customer: this.customerData ?? { name: "", email: null, phone: null }
|
|
4014
|
-
}
|
|
3982
|
+
kind: "claim_failed",
|
|
3983
|
+
code: claim.error.code,
|
|
3984
|
+
message: claim.error.userMessage
|
|
4015
3985
|
};
|
|
4016
|
-
} finally {
|
|
4017
|
-
this.authEstablishmentInProgress = false;
|
|
4018
|
-
}
|
|
4019
|
-
}
|
|
4020
|
-
async waitForAuthEstablishment(timeoutMs) {
|
|
4021
|
-
const deadline = Date.now() + timeoutMs;
|
|
4022
|
-
while (this.authEstablishmentInProgress && Date.now() < deadline) {
|
|
4023
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
4024
3986
|
}
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
if (!this.
|
|
4028
|
-
return
|
|
3987
|
+
this.accessToken = token;
|
|
3988
|
+
this.accountId = decodeJwtSub(token);
|
|
3989
|
+
if (!await this.hydrateCustomerData(generation, token, true)) {
|
|
3990
|
+
return { kind: "incomplete" };
|
|
4029
3991
|
}
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
3992
|
+
if (!this.isAuthGenerationCurrent(generation, token)) return { kind: "incomplete" };
|
|
3993
|
+
return {
|
|
3994
|
+
kind: "authenticated",
|
|
3995
|
+
data: {
|
|
3996
|
+
accountId: this.accountId ?? "",
|
|
3997
|
+
customerId: this.customerId ?? "",
|
|
3998
|
+
token,
|
|
3999
|
+
customer: this.customerData ?? { name: "", email: null, phone: null }
|
|
4034
4000
|
}
|
|
4035
|
-
|
|
4001
|
+
};
|
|
4002
|
+
}
|
|
4003
|
+
adoptEstablishedSession(sourceElement, session) {
|
|
4004
|
+
this.authGeneration += 1;
|
|
4005
|
+
this.authInProgress = false;
|
|
4006
|
+
const { id, ...customer } = session.customer;
|
|
4007
|
+
this.accessToken = session.accessToken;
|
|
4008
|
+
this.accountId = decodeJwtSub(session.accessToken);
|
|
4009
|
+
this.customerId = id;
|
|
4010
|
+
this.customerData = customer;
|
|
4011
|
+
this.addressData = null;
|
|
4012
|
+
this.paymentData = null;
|
|
4013
|
+
this.client.setAccessToken(session.accessToken);
|
|
4014
|
+
this.persistRefreshToken(session.refreshToken);
|
|
4015
|
+
this.client.session.adopt(session.accessToken, {
|
|
4016
|
+
sessionToken: session.sessionToken,
|
|
4017
|
+
customerName: session.customer.name,
|
|
4018
|
+
customer: session.customer,
|
|
4019
|
+
cart: null
|
|
4020
|
+
});
|
|
4021
|
+
sourceElement._emitAuthenticated({
|
|
4022
|
+
accountId: this.accountId,
|
|
4023
|
+
customerId: id,
|
|
4024
|
+
token: session.accessToken,
|
|
4025
|
+
customer
|
|
4036
4026
|
});
|
|
4037
|
-
return true;
|
|
4038
4027
|
}
|
|
4039
4028
|
broadcastClearedSession() {
|
|
4040
4029
|
const sessionToken = this.client.getSessionToken();
|
|
@@ -4081,7 +4070,8 @@ var CimplifyElements = class {
|
|
|
4081
4070
|
return;
|
|
4082
4071
|
}
|
|
4083
4072
|
const application = await this.applyAccessToken(accessToken, generation);
|
|
4084
|
-
if (application.kind === "authenticated"
|
|
4073
|
+
if (application.kind === "authenticated") {
|
|
4074
|
+
this._syncHostSession();
|
|
4085
4075
|
sourceElement._emitAuthenticated(application.data);
|
|
4086
4076
|
} else if (application.kind === "claim_failed") {
|
|
4087
4077
|
sourceElement._emitError({
|
|
@@ -4120,29 +4110,7 @@ var CimplifyElements = class {
|
|
|
4120
4110
|
this.startEmbeddedAuth(sourceElement, message);
|
|
4121
4111
|
break;
|
|
4122
4112
|
case MESSAGE_TYPES.SESSION_ESTABLISHED:
|
|
4123
|
-
|
|
4124
|
-
this.authInProgress = false;
|
|
4125
|
-
const generation = ++this.authGeneration;
|
|
4126
|
-
void this.applyAccessToken(message.accessToken, generation).then((application) => {
|
|
4127
|
-
if (this.authGeneration !== generation) return;
|
|
4128
|
-
if (application.kind === "claim_failed") {
|
|
4129
|
-
this.clearPersistedSession();
|
|
4130
|
-
sourceElement.sendMessage({
|
|
4131
|
-
type: MESSAGE_TYPES.SESSION_ESTABLISHMENT_FAILED,
|
|
4132
|
-
accessToken: message.accessToken,
|
|
4133
|
-
code: application.code,
|
|
4134
|
-
message: application.message
|
|
4135
|
-
});
|
|
4136
|
-
this.broadcastClearedSession();
|
|
4137
|
-
return;
|
|
4138
|
-
}
|
|
4139
|
-
if (application.kind !== "authenticated" || !this.broadcastAccessToken(message.accessToken, generation)) {
|
|
4140
|
-
return;
|
|
4141
|
-
}
|
|
4142
|
-
this.persistRefreshToken(message.refreshToken);
|
|
4143
|
-
sourceElement._emitAuthenticated(application.data);
|
|
4144
|
-
});
|
|
4145
|
-
}
|
|
4113
|
+
this.adoptEstablishedSession(sourceElement, message);
|
|
4146
4114
|
break;
|
|
4147
4115
|
case MESSAGE_TYPES.ADDRESS_CHANGED:
|
|
4148
4116
|
case MESSAGE_TYPES.ADDRESS_SELECTED:
|
|
@@ -4164,7 +4132,6 @@ var CimplifyElements = class {
|
|
|
4164
4132
|
case MESSAGE_TYPES.CONTINUE_WITHOUT_SAVED_DETAILS: {
|
|
4165
4133
|
this.authGeneration += 1;
|
|
4166
4134
|
this.authInProgress = false;
|
|
4167
|
-
this.authEstablishmentInProgress = false;
|
|
4168
4135
|
const carriedIdentityAuthority = Boolean(this.client.getAccessToken()) || this.client.hasClaimedSessionAuthority();
|
|
4169
4136
|
this.accessToken = null;
|
|
4170
4137
|
this.accountId = null;
|
|
@@ -4189,7 +4156,6 @@ var CimplifyElements = class {
|
|
|
4189
4156
|
case MESSAGE_TYPES.LOGOUT_COMPLETE:
|
|
4190
4157
|
this.authGeneration += 1;
|
|
4191
4158
|
this.authInProgress = false;
|
|
4192
|
-
this.authEstablishmentInProgress = false;
|
|
4193
4159
|
if (this.checkoutInProgress && this.activeCheckoutAbort) {
|
|
4194
4160
|
this.activeCheckoutAbort();
|
|
4195
4161
|
}
|
|
@@ -4438,14 +4404,7 @@ var CimplifyElement = class {
|
|
|
4438
4404
|
hostedSessionId: this.options.hostedSessionId,
|
|
4439
4405
|
initialTerms: this.options.initialTerms
|
|
4440
4406
|
});
|
|
4441
|
-
|
|
4442
|
-
const sessionToken = this.parent.getSessionToken();
|
|
4443
|
-
if (sessionToken) {
|
|
4444
|
-
this.sendMessage({ type: MESSAGE_TYPES.SET_SESSION, sessionToken });
|
|
4445
|
-
}
|
|
4446
|
-
if (token) {
|
|
4447
|
-
this.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
|
|
4448
|
-
}
|
|
4407
|
+
this.parent._syncHostSession(this);
|
|
4449
4408
|
this.pendingInit = null;
|
|
4450
4409
|
}
|
|
4451
4410
|
this.flushPending();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createMockApp } from './chunk-
|
|
2
|
-
import { createCimplifyClient } from './chunk-
|
|
1
|
+
import { createMockApp } from './chunk-MKZXZDHE.mjs';
|
|
2
|
+
import { createCimplifyClient } from './chunk-P4HYAV3L.mjs';
|
|
3
3
|
import { PAYMENT_METHOD, ORDER_TYPE, AUTHORIZATION_TYPE, CHECKOUT_NEXT_ACTION } from './chunk-33VCYWVL.mjs';
|
|
4
4
|
import { PURCHASE_INTENT_SOURCE_KIND, PURCHASE_INTENT_SELLABLE_KIND, PURCHASE_INTENT_OFFER_KIND, PURCHASE_INTENT_LINE_CONFIGURATION_KIND, PURCHASE_INTENT_PAYMENT_METHOD, PURCHASE_INTENT_MOBILE_MONEY_NETWORK, MOBILE_MONEY_TENDER_AUTHORITY_KIND, CHECKOUT_COMPLIANCE_REASON, CHECKOUT_COMPLIANCE_LANE, PURCHASE_SURFACE, PURCHASE_DISPOSITION, PAYMENT_INSTRUMENT_DISPLAY_KIND, CHECKOUT_PROTECTION_STATUS, PAYMENT_OPTION_NEXT_ACTION, PAYMENT_OPTION_STATUS, PURCHASE_INTENT_PAYMENT_PROVIDER, PAYMENT_COLLECTION_MODE, PURCHASING_PRINCIPAL_KIND, CHECKOUT_PURCHASE_SURFACE, NATIVE_PURCHASE_PLATFORM, PURCHASE_INTENT_STATUS, CHECKOUT_TERMS_COMPONENT, CHECKOUT_TERMS_DELTA_KIND, CHECKOUT_MATERIAL_TERMS_COMPONENT, PURCHASE_INTENT_CONFIRM_STATUS, CHECKOUT_INVALIDATION_REASON } from './chunk-NJYR6GGM.mjs';
|
|
5
5
|
import { z } from 'zod';
|
|
@@ -2907,6 +2907,23 @@ function buildV1(deps) {
|
|
|
2907
2907
|
return tryRoute(c, () => deps.support.react(c.req.param("messageId"), body.emoji ?? ""));
|
|
2908
2908
|
});
|
|
2909
2909
|
app.post("/support/conversation/handoff", (c) => c.json({ data: { requested: true } }));
|
|
2910
|
+
app.post("/auth/session/claim", async (c) => {
|
|
2911
|
+
const body = await c.req.json().catch(() => ({}));
|
|
2912
|
+
if (!body.access_token) return c.json({ error: "access_token is required" }, 400);
|
|
2913
|
+
const session = c.var.session;
|
|
2914
|
+
return c.json({
|
|
2915
|
+
data: {
|
|
2916
|
+
session_token: session.token,
|
|
2917
|
+
customer: {
|
|
2918
|
+
id: session.customer_id ?? "cus_test",
|
|
2919
|
+
name: session.customer_name ?? "Test User",
|
|
2920
|
+
email: null,
|
|
2921
|
+
phone: null
|
|
2922
|
+
},
|
|
2923
|
+
cart: null
|
|
2924
|
+
}
|
|
2925
|
+
});
|
|
2926
|
+
});
|
|
2910
2927
|
app.post("/support/conversation/claim", async (c) => {
|
|
2911
2928
|
const body = await c.req.json().catch(() => ({}));
|
|
2912
2929
|
if (!body.access_token) return c.json({ error: "access_token is required" }, 400);
|
|
@@ -2909,6 +2909,23 @@ function buildV1(deps) {
|
|
|
2909
2909
|
return tryRoute(c, () => deps.support.react(c.req.param("messageId"), body.emoji ?? ""));
|
|
2910
2910
|
});
|
|
2911
2911
|
app.post("/support/conversation/handoff", (c) => c.json({ data: { requested: true } }));
|
|
2912
|
+
app.post("/auth/session/claim", async (c) => {
|
|
2913
|
+
const body = await c.req.json().catch(() => ({}));
|
|
2914
|
+
if (!body.access_token) return c.json({ error: "access_token is required" }, 400);
|
|
2915
|
+
const session = c.var.session;
|
|
2916
|
+
return c.json({
|
|
2917
|
+
data: {
|
|
2918
|
+
session_token: session.token,
|
|
2919
|
+
customer: {
|
|
2920
|
+
id: session.customer_id ?? "cus_test",
|
|
2921
|
+
name: session.customer_name ?? "Test User",
|
|
2922
|
+
email: null,
|
|
2923
|
+
phone: null
|
|
2924
|
+
},
|
|
2925
|
+
cart: null
|
|
2926
|
+
}
|
|
2927
|
+
});
|
|
2928
|
+
});
|
|
2912
2929
|
app.post("/support/conversation/claim", async (c) => {
|
|
2913
2930
|
const body = await c.req.json().catch(() => ({}));
|
|
2914
2931
|
if (!body.access_token) return c.json({ error: "access_token is required" }, 400);
|
|
@@ -1,5 +1,5 @@
|
|
|
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-
|
|
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-2I6YKE6Q.mjs';
|
|
3
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-NJYR6GGM.mjs';
|
|
4
4
|
|
|
5
5
|
// src/types/observability.ts
|
|
@@ -1076,85 +1076,9 @@ function chatRealtimeUpdateFromWire(envelope) {
|
|
|
1076
1076
|
}
|
|
1077
1077
|
|
|
1078
1078
|
// src/support.ts
|
|
1079
|
-
var CLAIM_TIMEOUT_MS = 15e3;
|
|
1080
1079
|
var SupportService = class {
|
|
1081
1080
|
constructor(client) {
|
|
1082
1081
|
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
1082
|
}
|
|
1159
1083
|
/**
|
|
1160
1084
|
* Retry verified external-history discovery for the current storefront.
|
|
@@ -1270,6 +1194,95 @@ var SupportService = class {
|
|
|
1270
1194
|
}
|
|
1271
1195
|
};
|
|
1272
1196
|
|
|
1197
|
+
// src/session.ts
|
|
1198
|
+
var CLAIM_TIMEOUT_MS = 15e3;
|
|
1199
|
+
var CLAIM_PATH = "/api/v1/auth/session/claim";
|
|
1200
|
+
var SessionService = class {
|
|
1201
|
+
constructor(client) {
|
|
1202
|
+
this.client = client;
|
|
1203
|
+
this.claimInFlight = null;
|
|
1204
|
+
this.claimInFlightToken = null;
|
|
1205
|
+
this.lastClaimedAccessToken = null;
|
|
1206
|
+
this.claimedName = null;
|
|
1207
|
+
this.client.events.on(SESSION_CLEARED, () => {
|
|
1208
|
+
this.lastClaimedAccessToken = null;
|
|
1209
|
+
this.claimedName = null;
|
|
1210
|
+
});
|
|
1211
|
+
this.client.events.on(SESSION_CLAIMED, (event) => {
|
|
1212
|
+
if (event.customerName) this.claimedName = event.customerName;
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
/** The verified customer this session is bound to, null while anonymous. */
|
|
1216
|
+
get claimedCustomerName() {
|
|
1217
|
+
return this.claimedName;
|
|
1218
|
+
}
|
|
1219
|
+
/** Adopt a session another holder already bound for this bearer. */
|
|
1220
|
+
adopt(accessToken, session) {
|
|
1221
|
+
this.lastClaimedAccessToken = accessToken;
|
|
1222
|
+
this.claimedName = session.customerName || null;
|
|
1223
|
+
this.client.adoptSessionToken(session.sessionToken);
|
|
1224
|
+
this.client.publishSessionClaimed(this.claimedName);
|
|
1225
|
+
this.client.events.emit(SESSION_CLAIMED, session);
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Bind the anonymous session to the verified Link identity in one server
|
|
1229
|
+
* transaction: verify the bearer, rotate the session token (adopted here),
|
|
1230
|
+
* fold the guest cart under the customer and re-price it. A repeat for the
|
|
1231
|
+
* same account and session returns the same session.
|
|
1232
|
+
*
|
|
1233
|
+
* Idempotent and single-flight: concurrent calls share one request, and a
|
|
1234
|
+
* token already claimed by this instance short-circuits without a network
|
|
1235
|
+
* round trip. A session already bound to another Link account is rejected
|
|
1236
|
+
* rather than transferring that account's cart. Emits `session:claimed` on
|
|
1237
|
+
* the client's event channel.
|
|
1238
|
+
*/
|
|
1239
|
+
async claim() {
|
|
1240
|
+
const accessToken = this.client.getAccessToken();
|
|
1241
|
+
if (!accessToken) {
|
|
1242
|
+
return err(new CimplifyError("not_authenticated", "No access token to claim with"));
|
|
1243
|
+
}
|
|
1244
|
+
if (this.claimInFlight) {
|
|
1245
|
+
if (this.claimInFlightToken === accessToken) return this.claimInFlight;
|
|
1246
|
+
await this.claimInFlight;
|
|
1247
|
+
return this.claim();
|
|
1248
|
+
}
|
|
1249
|
+
if (this.lastClaimedAccessToken === accessToken) {
|
|
1250
|
+
return err(new CimplifyError("already_claimed", "Session already claimed for this token"));
|
|
1251
|
+
}
|
|
1252
|
+
const epoch = this.client.getSessionEpoch();
|
|
1253
|
+
this.claimInFlightToken = accessToken;
|
|
1254
|
+
this.claimInFlight = (async () => {
|
|
1255
|
+
const result = await safe(
|
|
1256
|
+
this.client.post(
|
|
1257
|
+
CLAIM_PATH,
|
|
1258
|
+
{ access_token: accessToken },
|
|
1259
|
+
{ timeoutMs: CLAIM_TIMEOUT_MS }
|
|
1260
|
+
)
|
|
1261
|
+
);
|
|
1262
|
+
if (result.ok) {
|
|
1263
|
+
if (this.client.getSessionEpoch() !== epoch) {
|
|
1264
|
+
return err(
|
|
1265
|
+
new CimplifyError("session_cleared", "Session was cleared during the claim")
|
|
1266
|
+
);
|
|
1267
|
+
}
|
|
1268
|
+
this.adopt(accessToken, {
|
|
1269
|
+
sessionToken: result.value.session_token,
|
|
1270
|
+
customerName: result.value.customer.name,
|
|
1271
|
+
customer: result.value.customer,
|
|
1272
|
+
cart: result.value.cart
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
return result;
|
|
1276
|
+
})();
|
|
1277
|
+
try {
|
|
1278
|
+
return await this.claimInFlight;
|
|
1279
|
+
} finally {
|
|
1280
|
+
this.claimInFlight = null;
|
|
1281
|
+
this.claimInFlightToken = null;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
|
|
1273
1286
|
// src/internal/cross-tab-session.ts
|
|
1274
1287
|
var CROSS_TAB_SESSION_HUB_KEY = /* @__PURE__ */ Symbol.for("@cimplify/sdk.cross-tab-session-hub");
|
|
1275
1288
|
var SESSION_SYNC_STORAGE_KEY = "cimplify_session_sync";
|
|
@@ -1623,9 +1636,9 @@ var CimplifyClient = class {
|
|
|
1623
1636
|
* merchant auth flows, never by the raw token setter. Global Link clients
|
|
1624
1637
|
* have no storefront tenant and therefore activate without this step.
|
|
1625
1638
|
*/
|
|
1626
|
-
|
|
1639
|
+
autoClaimSession() {
|
|
1627
1640
|
if (typeof window === "undefined" || !this.sessionToken || !this.accessToken) return;
|
|
1628
|
-
void this.
|
|
1641
|
+
void this.session.claim();
|
|
1629
1642
|
}
|
|
1630
1643
|
/**
|
|
1631
1644
|
* Adopt a server-rotated session token (claim flow). The old token stays
|
|
@@ -1713,8 +1726,9 @@ var CimplifyClient = class {
|
|
|
1713
1726
|
this.sessionEpoch++;
|
|
1714
1727
|
this.events.emit(SESSION_CLAIMED, {
|
|
1715
1728
|
sessionToken: payload.token,
|
|
1716
|
-
|
|
1717
|
-
|
|
1729
|
+
customerName: payload.name ?? "",
|
|
1730
|
+
customer: null,
|
|
1731
|
+
cart: null
|
|
1718
1732
|
});
|
|
1719
1733
|
} else {
|
|
1720
1734
|
this.accessToken = null;
|
|
@@ -2371,6 +2385,12 @@ var CimplifyClient = class {
|
|
|
2371
2385
|
}
|
|
2372
2386
|
return this._support;
|
|
2373
2387
|
}
|
|
2388
|
+
get session() {
|
|
2389
|
+
if (!this._session) {
|
|
2390
|
+
this._session = new SessionService(this);
|
|
2391
|
+
}
|
|
2392
|
+
return this._session;
|
|
2393
|
+
}
|
|
2374
2394
|
buildWsUrl(path) {
|
|
2375
2395
|
const protocol = this.baseUrl.startsWith("https") ? "wss:" : "ws:";
|
|
2376
2396
|
const host = this.baseUrl.replace(/^https?:\/\//, "");
|
|
@@ -2391,4 +2411,4 @@ function createCimplifyClient(config = {}) {
|
|
|
2391
2411
|
return new CimplifyClient(config);
|
|
2392
2412
|
}
|
|
2393
2413
|
|
|
2394
|
-
export { ActivityService, CimplifyClient, DeliveryService, HostedPurchaseIntentService, PURCHASE_INTENT_ROUTE, PlacesService, PurchaseIntentResolver, PurchaseIntentService, SESSION_CHANGE_SOURCE, StoreCreditQueries, SubscriptionService, SupportService, UploadService, chatRealtimeUpdateFromWire, createCimplifyClient };
|
|
2414
|
+
export { ActivityService, CimplifyClient, DeliveryService, HostedPurchaseIntentService, PURCHASE_INTENT_ROUTE, PlacesService, PurchaseIntentResolver, PurchaseIntentService, SESSION_CHANGE_SOURCE, SessionService, StoreCreditQueries, SubscriptionService, SupportService, UploadService, chatRealtimeUpdateFromWire, createCimplifyClient };
|