@cimplify/sdk 0.89.0 → 0.92.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.
Files changed (69) hide show
  1. package/dist/advanced.d.mts +3 -3
  2. package/dist/advanced.d.ts +3 -3
  3. package/dist/advanced.js +20 -20
  4. package/dist/advanced.mjs +1 -1
  5. package/dist/{chunk-JHJTXAPS.js → chunk-3MBMIEWT.js} +4 -4
  6. package/dist/{chunk-DENWOZEA.mjs → chunk-3XD2FVP4.mjs} +163 -43
  7. package/dist/{chunk-M4ALCELT.mjs → chunk-54H2YYIW.mjs} +2 -2
  8. package/dist/{chunk-T2CJ67QV.js → chunk-DCRN67NO.js} +201 -78
  9. package/dist/{chunk-T7Z25EY4.js → chunk-HKN3YG76.js} +84 -0
  10. package/dist/{chunk-GHFDYM5K.js → chunk-IVJEUGWF.js} +10 -1
  11. package/dist/{chunk-ROBTTS3Q.js → chunk-OAHSF542.js} +40 -1
  12. package/dist/{chunk-APBLFZ2I.mjs → chunk-PYBFTMHI.mjs} +40 -1
  13. package/dist/{chunk-OZDDHSIB.mjs → chunk-RRBY35TJ.mjs} +80 -1
  14. package/dist/{chunk-ZU4ZRYUR.mjs → chunk-T7LDBZZZ.mjs} +10 -1
  15. package/dist/chunk-U4MW6PYU.mjs +23 -0
  16. package/dist/chunk-XREIZ56K.js +26 -0
  17. package/dist/{client-CqZgdUtw.d.ts → client-BQbSKlHS.d.mts} +165 -11
  18. package/dist/{client-CAY2NbRG.d.mts → client-Bw4HtLP1.d.mts} +2 -2
  19. package/dist/{client-D8ZFs-sq.d.mts → client-CeW3acve.d.ts} +165 -11
  20. package/dist/{client-CUbwb6Om.d.ts → client-Otzv_rgP.d.ts} +2 -2
  21. package/dist/{index-CmWOz9bi.d.mts → index-CmIboQjl.d.mts} +3 -3
  22. package/dist/{index-Bc5qUxAt.d.ts → index-DgoRwz8l.d.ts} +3 -3
  23. package/dist/index.d.mts +49 -7
  24. package/dist/index.d.ts +49 -7
  25. package/dist/index.js +109 -82
  26. package/dist/index.mjs +11 -5
  27. package/dist/mock/cli.mjs +61 -1
  28. package/dist/mock/library.js +61 -1
  29. package/dist/mock/library.mjs +61 -1
  30. package/dist/mock/msw.js +61 -1
  31. package/dist/mock/msw.mjs +61 -1
  32. package/dist/{payment-Dcgb9n1n.d.mts → payment-BFtLqiG2.d.mts} +1 -1
  33. package/dist/{payment-Xq0WDZXh.d.ts → payment-Cq8FT1B6.d.ts} +1 -1
  34. package/dist/{price-DAAjKgAp.d.ts → price-DaFXT-Lr.d.ts} +1 -1
  35. package/dist/{price--Ma_WO5_.d.mts → price-DleDWk_s.d.mts} +1 -1
  36. package/dist/{product-BakHcsP2.d.ts → product-bZ8G5Z8D.d.mts} +95 -2
  37. package/dist/{product-BakHcsP2.d.mts → product-bZ8G5Z8D.d.ts} +95 -2
  38. package/dist/react.d.mts +471 -8
  39. package/dist/react.d.ts +471 -8
  40. package/dist/react.js +2787 -402
  41. package/dist/react.mjs +2699 -337
  42. package/dist/{server-Bk_hlefX.d.mts → server-D-iK-bNt.d.mts} +8 -1
  43. package/dist/{server-Bei5lBrc.d.ts → server-DwsY9hlX.d.ts} +8 -1
  44. package/dist/server.d.mts +4 -4
  45. package/dist/server.d.ts +4 -4
  46. package/dist/server.js +7 -7
  47. package/dist/server.mjs +2 -2
  48. package/dist/styles.css +1 -1
  49. package/dist/testing/msw.d.mts +2 -2
  50. package/dist/testing/msw.d.ts +2 -2
  51. package/dist/testing/msw.js +3 -2
  52. package/dist/testing/msw.mjs +2 -1
  53. package/dist/testing/suite.d.mts +6 -6
  54. package/dist/testing/suite.d.ts +6 -6
  55. package/dist/testing/suite.js +24 -23
  56. package/dist/testing/suite.mjs +5 -4
  57. package/dist/testing.d.mts +5 -5
  58. package/dist/testing.d.ts +5 -5
  59. package/dist/testing.js +80 -79
  60. package/dist/testing.mjs +6 -5
  61. package/dist/utils.d.mts +4 -4
  62. package/dist/utils.d.ts +4 -4
  63. package/package.json +4 -1
  64. package/registry/booking-page.json +1 -1
  65. package/registry/chat-widget.json +1 -1
  66. package/registry/customer-input-fields.json +1 -1
  67. package/registry/date-slot-picker.json +1 -1
  68. package/registry/product-customizer.json +1 -1
  69. package/registry/rental-service-card.json +1 -1
@@ -1,6 +1,6 @@
1
- export { k as AuthService, C as BusinessService, O as CartOperations, P as CatalogueQueries, a8 as CheckoutOperations, a8 as CheckoutService, ae as CimplifyElement, af as CimplifyElements, aG as ELEMENT_TYPES, aH as EVENT_TYPES, aK as ElementEventType, aL as ElementOptions, aM as ElementType, aU as ElementsOptions, b0 as FetchQuoteInput, b9 as FxService, bd as GetProductsOptions, bg as InventoryService, bo as LinkService, bs as LiteService, bz as MESSAGE_TYPES, b$ as OrderQueries, cl as PriceQuote, cr as QuoteBundleSelectionInput, cs as QuoteCompositeSelectionInput, ct as QuoteDynamicBuckets, cu as QuoteStatus, cv as QuoteUiMessage, cx as RefreshQuoteInput, cy as RefreshQuoteResult, c_ as SchedulingService, dE as createElements } from './client-D8ZFs-sq.mjs';
2
- import './product-BakHcsP2.mjs';
3
- import './payment-Dcgb9n1n.mjs';
1
+ export { k as AuthService, C as BusinessService, O as CartOperations, P as CatalogueQueries, ab as CheckoutOperations, ab as CheckoutService, ah as CimplifyElement, ai as CimplifyElements, aK as ELEMENT_TYPES, aL as EVENT_TYPES, aO as ElementEventType, aP as ElementOptions, aQ as ElementType, aY as ElementsOptions, b4 as FetchQuoteInput, bd as FxService, bh as GetProductsOptions, bk as InventoryService, bs as LinkService, by as LiteService, bF as MESSAGE_TYPES, c5 as OrderQueries, cr as PriceQuote, cx as QuoteBundleSelectionInput, cy as QuoteCompositeSelectionInput, cz as QuoteDynamicBuckets, cA as QuoteStatus, cB as QuoteUiMessage, cD as RefreshQuoteInput, cE as RefreshQuoteResult, d4 as SchedulingService, dK as createElements } from './client-BQbSKlHS.mjs';
2
+ import './product-bZ8G5Z8D.mjs';
3
+ import './payment-BFtLqiG2.mjs';
4
4
 
5
5
  declare function generateIdempotencyKey(prefix?: string): string;
6
6
 
@@ -1,6 +1,6 @@
1
- export { k as AuthService, C as BusinessService, O as CartOperations, P as CatalogueQueries, a8 as CheckoutOperations, a8 as CheckoutService, ae as CimplifyElement, af as CimplifyElements, aG as ELEMENT_TYPES, aH as EVENT_TYPES, aK as ElementEventType, aL as ElementOptions, aM as ElementType, aU as ElementsOptions, b0 as FetchQuoteInput, b9 as FxService, bd as GetProductsOptions, bg as InventoryService, bo as LinkService, bs as LiteService, bz as MESSAGE_TYPES, b$ as OrderQueries, cl as PriceQuote, cr as QuoteBundleSelectionInput, cs as QuoteCompositeSelectionInput, ct as QuoteDynamicBuckets, cu as QuoteStatus, cv as QuoteUiMessage, cx as RefreshQuoteInput, cy as RefreshQuoteResult, c_ as SchedulingService, dE as createElements } from './client-CqZgdUtw.js';
2
- import './product-BakHcsP2.js';
3
- import './payment-Xq0WDZXh.js';
1
+ export { k as AuthService, C as BusinessService, O as CartOperations, P as CatalogueQueries, ab as CheckoutOperations, ab as CheckoutService, ah as CimplifyElement, ai as CimplifyElements, aK as ELEMENT_TYPES, aL as EVENT_TYPES, aO as ElementEventType, aP as ElementOptions, aQ as ElementType, aY as ElementsOptions, b4 as FetchQuoteInput, bd as FxService, bh as GetProductsOptions, bk as InventoryService, bs as LinkService, by as LiteService, bF as MESSAGE_TYPES, c5 as OrderQueries, cr as PriceQuote, cx as QuoteBundleSelectionInput, cy as QuoteCompositeSelectionInput, cz as QuoteDynamicBuckets, cA as QuoteStatus, cB as QuoteUiMessage, cD as RefreshQuoteInput, cE as RefreshQuoteResult, d4 as SchedulingService, dK as createElements } from './client-CeW3acve.js';
2
+ import './product-bZ8G5Z8D.js';
3
+ import './payment-Cq8FT1B6.js';
4
4
 
5
5
  declare function generateIdempotencyKey(prefix?: string): string;
6
6
 
package/dist/advanced.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkGHFDYM5K_js = require('./chunk-GHFDYM5K.js');
3
+ var chunkIVJEUGWF_js = require('./chunk-IVJEUGWF.js');
4
4
  require('./chunk-PTPOQVXS.js');
5
5
  require('./chunk-AETVRBKI.js');
6
6
  require('./chunk-OWW5GUSB.js');
@@ -9,77 +9,77 @@ require('./chunk-OWW5GUSB.js');
9
9
 
10
10
  Object.defineProperty(exports, "AuthService", {
11
11
  enumerable: true,
12
- get: function () { return chunkGHFDYM5K_js.AuthService; }
12
+ get: function () { return chunkIVJEUGWF_js.AuthService; }
13
13
  });
14
14
  Object.defineProperty(exports, "BusinessService", {
15
15
  enumerable: true,
16
- get: function () { return chunkGHFDYM5K_js.BusinessService; }
16
+ get: function () { return chunkIVJEUGWF_js.BusinessService; }
17
17
  });
18
18
  Object.defineProperty(exports, "CartOperations", {
19
19
  enumerable: true,
20
- get: function () { return chunkGHFDYM5K_js.CartOperations; }
20
+ get: function () { return chunkIVJEUGWF_js.CartOperations; }
21
21
  });
22
22
  Object.defineProperty(exports, "CatalogueQueries", {
23
23
  enumerable: true,
24
- get: function () { return chunkGHFDYM5K_js.CatalogueQueries; }
24
+ get: function () { return chunkIVJEUGWF_js.CatalogueQueries; }
25
25
  });
26
26
  Object.defineProperty(exports, "CheckoutOperations", {
27
27
  enumerable: true,
28
- get: function () { return chunkGHFDYM5K_js.CheckoutService; }
28
+ get: function () { return chunkIVJEUGWF_js.CheckoutService; }
29
29
  });
30
30
  Object.defineProperty(exports, "CheckoutService", {
31
31
  enumerable: true,
32
- get: function () { return chunkGHFDYM5K_js.CheckoutService; }
32
+ get: function () { return chunkIVJEUGWF_js.CheckoutService; }
33
33
  });
34
34
  Object.defineProperty(exports, "CimplifyElement", {
35
35
  enumerable: true,
36
- get: function () { return chunkGHFDYM5K_js.CimplifyElement; }
36
+ get: function () { return chunkIVJEUGWF_js.CimplifyElement; }
37
37
  });
38
38
  Object.defineProperty(exports, "CimplifyElements", {
39
39
  enumerable: true,
40
- get: function () { return chunkGHFDYM5K_js.CimplifyElements; }
40
+ get: function () { return chunkIVJEUGWF_js.CimplifyElements; }
41
41
  });
42
42
  Object.defineProperty(exports, "ELEMENT_TYPES", {
43
43
  enumerable: true,
44
- get: function () { return chunkGHFDYM5K_js.ELEMENT_TYPES; }
44
+ get: function () { return chunkIVJEUGWF_js.ELEMENT_TYPES; }
45
45
  });
46
46
  Object.defineProperty(exports, "EVENT_TYPES", {
47
47
  enumerable: true,
48
- get: function () { return chunkGHFDYM5K_js.EVENT_TYPES; }
48
+ get: function () { return chunkIVJEUGWF_js.EVENT_TYPES; }
49
49
  });
50
50
  Object.defineProperty(exports, "FxService", {
51
51
  enumerable: true,
52
- get: function () { return chunkGHFDYM5K_js.FxService; }
52
+ get: function () { return chunkIVJEUGWF_js.FxService; }
53
53
  });
54
54
  Object.defineProperty(exports, "InventoryService", {
55
55
  enumerable: true,
56
- get: function () { return chunkGHFDYM5K_js.InventoryService; }
56
+ get: function () { return chunkIVJEUGWF_js.InventoryService; }
57
57
  });
58
58
  Object.defineProperty(exports, "LinkService", {
59
59
  enumerable: true,
60
- get: function () { return chunkGHFDYM5K_js.LinkService; }
60
+ get: function () { return chunkIVJEUGWF_js.LinkService; }
61
61
  });
62
62
  Object.defineProperty(exports, "LiteService", {
63
63
  enumerable: true,
64
- get: function () { return chunkGHFDYM5K_js.LiteService; }
64
+ get: function () { return chunkIVJEUGWF_js.LiteService; }
65
65
  });
66
66
  Object.defineProperty(exports, "MESSAGE_TYPES", {
67
67
  enumerable: true,
68
- get: function () { return chunkGHFDYM5K_js.MESSAGE_TYPES; }
68
+ get: function () { return chunkIVJEUGWF_js.MESSAGE_TYPES; }
69
69
  });
70
70
  Object.defineProperty(exports, "OrderQueries", {
71
71
  enumerable: true,
72
- get: function () { return chunkGHFDYM5K_js.OrderQueries; }
72
+ get: function () { return chunkIVJEUGWF_js.OrderQueries; }
73
73
  });
74
74
  Object.defineProperty(exports, "SchedulingService", {
75
75
  enumerable: true,
76
- get: function () { return chunkGHFDYM5K_js.SchedulingService; }
76
+ get: function () { return chunkIVJEUGWF_js.SchedulingService; }
77
77
  });
78
78
  Object.defineProperty(exports, "createElements", {
79
79
  enumerable: true,
80
- get: function () { return chunkGHFDYM5K_js.createElements; }
80
+ get: function () { return chunkIVJEUGWF_js.createElements; }
81
81
  });
82
82
  Object.defineProperty(exports, "generateIdempotencyKey", {
83
83
  enumerable: true,
84
- get: function () { return chunkGHFDYM5K_js.generateIdempotencyKey; }
84
+ get: function () { return chunkIVJEUGWF_js.generateIdempotencyKey; }
85
85
  });
package/dist/advanced.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { AuthService, BusinessService, CartOperations, CatalogueQueries, CheckoutService as CheckoutOperations, CheckoutService, CimplifyElement, CimplifyElements, ELEMENT_TYPES, EVENT_TYPES, FxService, InventoryService, LinkService, LiteService, MESSAGE_TYPES, OrderQueries, SchedulingService, createElements, generateIdempotencyKey } from './chunk-ZU4ZRYUR.mjs';
1
+ export { AuthService, BusinessService, CartOperations, CatalogueQueries, CheckoutService as CheckoutOperations, CheckoutService, CimplifyElement, CimplifyElements, ELEMENT_TYPES, EVENT_TYPES, FxService, InventoryService, LinkService, LiteService, MESSAGE_TYPES, OrderQueries, SchedulingService, createElements, generateIdempotencyKey } from './chunk-T7LDBZZZ.mjs';
2
2
  import './chunk-KFLGQGMC.mjs';
3
3
  import './chunk-K5EN2W2Q.mjs';
4
4
  import './chunk-3G6RQLXK.mjs';
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkROBTTS3Q_js = require('./chunk-ROBTTS3Q.js');
4
- var chunkT2CJ67QV_js = require('./chunk-T2CJ67QV.js');
3
+ var chunkOAHSF542_js = require('./chunk-OAHSF542.js');
4
+ var chunkDCRN67NO_js = require('./chunk-DCRN67NO.js');
5
5
  var zod = require('zod');
6
6
 
7
7
  var cimplifyRegistry = zod.z.registry();
@@ -600,7 +600,7 @@ async function toForwardedRequest(input, init) {
600
600
  };
601
601
  }
602
602
  function createTestClient(options = {}) {
603
- const mock = chunkROBTTS3Q_js.createMockApp(options);
603
+ const mock = chunkOAHSF542_js.createMockApp(options);
604
604
  let sessionToken;
605
605
  const fetchImpl = async (input, init) => {
606
606
  const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
@@ -619,7 +619,7 @@ function createTestClient(options = {}) {
619
619
  if (echoed) sessionToken = echoed;
620
620
  return res;
621
621
  };
622
- const client = chunkT2CJ67QV_js.createCimplifyClient({
622
+ const client = chunkDCRN67NO_js.createCimplifyClient({
623
623
  baseUrl: TEST_BASE_URL,
624
624
  // Link mock lives at /v1/link on the same Hono app, so point the SDK's
625
625
  // separate Link transport at the same TEST_BASE_URL.
@@ -1,4 +1,4 @@
1
- import { safe, generateIdempotencyKey, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-ZU4ZRYUR.mjs';
1
+ import { safe, generateIdempotencyKey, err, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-T7LDBZZZ.mjs';
2
2
  import { CimplifyError, ErrorCode, IdempotencyMismatchError, enrichError } from './chunk-K5EN2W2Q.mjs';
3
3
 
4
4
  // src/store-credit.ts
@@ -293,10 +293,101 @@ var DeliveryService = class {
293
293
  }
294
294
  };
295
295
 
296
+ // src/internal/events.ts
297
+ var MUTATION_ERROR = "mutation:error";
298
+ var AUTH_TOKEN_CHANGED = "auth:token-changed";
299
+ var SESSION_CLAIMED = "session:claimed";
300
+ var SESSION_CLEARED = "session:cleared";
301
+ function createClientEvents() {
302
+ const listeners = /* @__PURE__ */ new Map();
303
+ return {
304
+ on(name, listener) {
305
+ let set = listeners.get(name);
306
+ if (!set) {
307
+ set = /* @__PURE__ */ new Set();
308
+ listeners.set(name, set);
309
+ }
310
+ set.add(listener);
311
+ return () => {
312
+ set?.delete(listener);
313
+ };
314
+ },
315
+ off(name, listener) {
316
+ listeners.get(name)?.delete(listener);
317
+ },
318
+ emit(name, payload) {
319
+ const set = listeners.get(name);
320
+ if (!set) return;
321
+ const snapshot = Array.from(set);
322
+ for (const listener of snapshot) {
323
+ try {
324
+ listener(payload);
325
+ } catch (err2) {
326
+ console.error(`[Cimplify] event listener for "${name}" threw:`, err2);
327
+ }
328
+ }
329
+ }
330
+ };
331
+ }
332
+
296
333
  // src/support.ts
297
334
  var SupportService = class {
298
335
  constructor(client) {
299
336
  this.client = client;
337
+ this.claimInFlight = null;
338
+ this.lastClaimedAccessToken = null;
339
+ this.claimedName = null;
340
+ this.client.events.on(SESSION_CLEARED, () => {
341
+ this.lastClaimedAccessToken = null;
342
+ this.claimedName = null;
343
+ });
344
+ }
345
+ /** The verified customer this session's conversation was claimed for, null while anonymous. */
346
+ get claimedCustomerName() {
347
+ return this.claimedName;
348
+ }
349
+ /**
350
+ * Claim the anonymous session for the verified Link identity: the server
351
+ * verifies the access token, rotates the session token (adopted here, so
352
+ * every subsequent request rides the bound session), folds the guest cart
353
+ * in, and adopts or merges the widget conversation.
354
+ *
355
+ * Idempotent and single-flight: concurrent calls share one request, and a
356
+ * token already claimed by this instance short-circuits without a network
357
+ * round trip. Emits `session:claimed` on the client's event channel.
358
+ */
359
+ async claimConversation() {
360
+ const accessToken = this.client.getAccessToken();
361
+ if (!accessToken) {
362
+ return err(new CimplifyError("not_authenticated", "No access token to claim with"));
363
+ }
364
+ if (this.claimInFlight) return this.claimInFlight;
365
+ if (this.lastClaimedAccessToken === accessToken) {
366
+ return err(new CimplifyError("already_claimed", "Session already claimed for this token"));
367
+ }
368
+ this.claimInFlight = (async () => {
369
+ const result = await safe(
370
+ this.client.post("/api/v1/support/conversation/claim", {
371
+ access_token: accessToken
372
+ })
373
+ );
374
+ if (result.ok) {
375
+ this.lastClaimedAccessToken = accessToken;
376
+ this.claimedName = result.value.customer_name || null;
377
+ this.client.adoptSessionToken(result.value.session_token);
378
+ this.client.events.emit(SESSION_CLAIMED, {
379
+ sessionToken: result.value.session_token,
380
+ threadId: result.value.thread_id ?? null,
381
+ customerName: result.value.customer_name
382
+ });
383
+ }
384
+ return result;
385
+ })();
386
+ try {
387
+ return await this.claimInFlight;
388
+ } finally {
389
+ this.claimInFlight = null;
390
+ }
300
391
  }
301
392
  /** Open (or resume) the customer's widget conversation. */
302
393
  async openConversation(opts) {
@@ -312,61 +403,59 @@ var SupportService = class {
312
403
  *
313
404
  * The idempotency key doubles as the message `client_id`: the backend
314
405
  * dedupes on it, so client retries of the same send never insert twice.
406
+ * `replyToMessageId` quotes another message by its `ChatMessage.id`; the
407
+ * server resolves it thread-scoped and echoes the quote as `reply_to`.
315
408
  */
316
409
  async sendMessage(content, opts) {
317
410
  const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
318
411
  return safe(
319
412
  this.client.post(
320
413
  "/api/v1/support/conversation/messages",
321
- { content, client_id: idempotencyKey },
414
+ {
415
+ content,
416
+ client_id: idempotencyKey,
417
+ reply_to_message_id: opts?.replyToMessageId,
418
+ upload_ids: opts?.attachments?.map((a) => a.upload_id)
419
+ },
322
420
  { idempotencyKey }
323
421
  )
324
422
  );
325
423
  }
326
- /** Poll for new messages since the given cursor. */
424
+ /**
425
+ * Poll for messages. `after` pages forward (live updates); `before` pages
426
+ * backward for scrollback into older history.
427
+ */
327
428
  async getMessages(options = {}) {
328
429
  const params = new URLSearchParams();
329
430
  if (options.after) params.set("after", options.after);
431
+ if (options.before) params.set("before", options.before);
330
432
  if (options.limit) params.set("limit", String(options.limit));
331
433
  const query = params.toString();
332
434
  const path = query ? `/api/v1/support/conversation/messages?${query}` : "/api/v1/support/conversation/messages";
333
435
  return safe(this.client.get(path));
334
436
  }
437
+ /** React to a message in the active conversation by its `ChatMessage.id`. */
438
+ async reactToMessage(messageId, emoji) {
439
+ return safe(
440
+ this.client.post(
441
+ `/api/v1/support/conversation/messages/${messageId}/reactions`,
442
+ { emoji }
443
+ )
444
+ );
445
+ }
446
+ /** Ask for a person: flags the thread for the merchant's inbox. */
447
+ async requestHuman(opts) {
448
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
449
+ return safe(
450
+ this.client.post(
451
+ "/api/v1/support/conversation/handoff",
452
+ void 0,
453
+ { idempotencyKey }
454
+ )
455
+ );
456
+ }
335
457
  };
336
458
 
337
- // src/internal/events.ts
338
- function createClientEvents() {
339
- const listeners = /* @__PURE__ */ new Map();
340
- return {
341
- on(name, listener) {
342
- let set = listeners.get(name);
343
- if (!set) {
344
- set = /* @__PURE__ */ new Set();
345
- listeners.set(name, set);
346
- }
347
- set.add(listener);
348
- return () => {
349
- set?.delete(listener);
350
- };
351
- },
352
- off(name, listener) {
353
- listeners.get(name)?.delete(listener);
354
- },
355
- emit(name, payload) {
356
- const set = listeners.get(name);
357
- if (!set) return;
358
- const snapshot = Array.from(set);
359
- for (const listener of snapshot) {
360
- try {
361
- listener(payload);
362
- } catch (err) {
363
- console.error(`[Cimplify] event listener for "${name}" threw:`, err);
364
- }
365
- }
366
- }
367
- };
368
- }
369
-
370
459
  // src/client.ts
371
460
  var SESSION_TOKEN_STORAGE_KEY = "cimplify_session_token";
372
461
  var ORDER_TOKEN_PREFIX = "cimplify_ot_";
@@ -546,6 +635,28 @@ var CimplifyClient = class {
546
635
  newToken: token,
547
636
  source: "manual"
548
637
  });
638
+ this.events.emit(AUTH_TOKEN_CHANGED, { token });
639
+ }
640
+ /**
641
+ * Zero-UI claim: a freshly verified customer identity (OTP verify, silent
642
+ * refresh restore) binds the anonymous session so the conversation, cart
643
+ * and orders survive a cleared browser. Best-effort by design — a failed
644
+ * claim leaves the session anonymous, exactly as it was. Called by the
645
+ * auth flows, never by the raw token setter.
646
+ */
647
+ autoClaimChatIdentity() {
648
+ if (typeof window === "undefined" || !this.sessionToken || !this.accessToken) return;
649
+ void this.support.claimConversation();
650
+ }
651
+ /**
652
+ * Adopt a server-rotated session token (claim flow). The old token stays
653
+ * in flight-safe use until the next request; the storage swap makes the
654
+ * rotation durable across reloads.
655
+ */
656
+ adoptSessionToken(token) {
657
+ if (!token || token === this.sessionToken) return;
658
+ this.sessionToken = token;
659
+ this.saveSessionToken(token);
549
660
  }
550
661
  clearSession() {
551
662
  const previous = this.accessToken;
@@ -560,6 +671,8 @@ var CimplifyClient = class {
560
671
  newToken: null,
561
672
  source: "clear"
562
673
  });
674
+ this.events.emit(AUTH_TOKEN_CHANGED, { token: null });
675
+ this.events.emit(SESSION_CLEARED, {});
563
676
  }
564
677
  setOrderToken(orderId, token) {
565
678
  if (typeof window !== "undefined" && window.localStorage) {
@@ -658,9 +771,16 @@ var CimplifyClient = class {
658
771
  async authedFetch(url, options) {
659
772
  return this.resilientFetch(url, options);
660
773
  }
774
+ // Storage guards: even the `window.localStorage` property access throws in
775
+ // some sandboxed iframes and strict private-browsing modes. These run in the
776
+ // constructor at module load, so a throw would white-screen the whole app —
777
+ // fall back to an in-memory session token instead.
661
778
  loadSessionToken() {
662
- if (typeof window !== "undefined" && window.localStorage) {
663
- return localStorage.getItem(SESSION_TOKEN_STORAGE_KEY);
779
+ try {
780
+ if (typeof window !== "undefined" && window.localStorage) {
781
+ return localStorage.getItem(SESSION_TOKEN_STORAGE_KEY);
782
+ }
783
+ } catch {
664
784
  }
665
785
  return null;
666
786
  }
@@ -674,7 +794,7 @@ var CimplifyClient = class {
674
794
  * every visitor to one session, so SSR keeps the lazy server-minted flow.
675
795
  */
676
796
  mintSessionToken() {
677
- if (typeof window === "undefined" || !window.localStorage) {
797
+ if (typeof window === "undefined") {
678
798
  return null;
679
799
  }
680
800
  const token = generateSessionToken();
@@ -682,11 +802,11 @@ var CimplifyClient = class {
682
802
  return token;
683
803
  }
684
804
  saveSessionToken(token) {
685
- if (typeof window !== "undefined" && window.localStorage) {
686
- try {
805
+ try {
806
+ if (typeof window !== "undefined" && window.localStorage) {
687
807
  localStorage.setItem(SESSION_TOKEN_STORAGE_KEY, token);
688
- } catch {
689
808
  }
809
+ } catch {
690
810
  }
691
811
  }
692
812
  captureSessionToken(response) {
@@ -1085,4 +1205,4 @@ function createCimplifyClient(config = {}) {
1085
1205
  return new CimplifyClient(config);
1086
1206
  }
1087
1207
 
1088
- export { ActivityService, CimplifyClient, DeliveryService, PlacesService, StoreCreditQueries, SubscriptionService, SupportService, UploadService, createCimplifyClient };
1208
+ export { ActivityService, CimplifyClient, DeliveryService, MUTATION_ERROR, PlacesService, SESSION_CLAIMED, SESSION_CLEARED, StoreCreditQueries, SubscriptionService, SupportService, UploadService, createCimplifyClient };
@@ -1,5 +1,5 @@
1
- import { createMockApp } from './chunk-APBLFZ2I.mjs';
2
- import { createCimplifyClient } from './chunk-DENWOZEA.mjs';
1
+ import { createMockApp } from './chunk-PYBFTMHI.mjs';
2
+ import { createCimplifyClient } from './chunk-3XD2FVP4.mjs';
3
3
  import { z } from 'zod';
4
4
 
5
5
  var cimplifyRegistry = z.registry();