@cimplify/sdk 0.106.1 → 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-YHR6LFQ7.mjs → chunk-2I6YKE6Q.mjs} +55 -94
- package/dist/{chunk-LJSQ7TUV.js → chunk-73HY36Z7.js} +4 -4
- package/dist/{chunk-SFG2LMRD.js → chunk-HKCB73AJ.js} +55 -94
- package/dist/{chunk-IWXVKW22.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-ABAK4YVY.mjs → chunk-P4HYAV3L.mjs} +102 -82
- package/dist/{chunk-QKL5L5IU.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
|
@@ -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 };
|