@cimplify/sdk 0.103.0 → 0.104.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/advanced.d.mts +3 -3
  2. package/dist/advanced.d.ts +3 -3
  3. package/dist/advanced.js +22 -22
  4. package/dist/advanced.mjs +3 -3
  5. package/dist/{chunk-C2JSNJUC.mjs → chunk-2WPVUIHX.mjs} +52 -11
  6. package/dist/{chunk-JG5CQNCB.js → chunk-4BKOKHE3.js} +4 -0
  7. package/dist/{chunk-R6OLQ33I.js → chunk-5BDYDZ4U.js} +239 -87
  8. package/dist/{chunk-H7ACMHM3.mjs → chunk-5RT4HYMP.mjs} +32 -4
  9. package/dist/{chunk-NNG6IFFX.js → chunk-7PDEX54K.js} +3 -3
  10. package/dist/{chunk-M4URVKHE.mjs → chunk-DYIAX3WI.mjs} +1 -1
  11. package/dist/{chunk-QOWPGS7Z.js → chunk-E4K2VQDD.js} +35 -5
  12. package/dist/{chunk-VNPEYLB2.mjs → chunk-H3RATH4B.mjs} +4 -0
  13. package/dist/{chunk-JSWJ4XDE.js → chunk-IQFFSKE2.js} +315 -108
  14. package/dist/{chunk-J6PNHDHL.mjs → chunk-OCCNG6MO.mjs} +284 -77
  15. package/dist/{chunk-GERXZQSX.mjs → chunk-OKADBZAI.mjs} +171 -20
  16. package/dist/{chunk-VIL6IQCG.js → chunk-YVAEY3VC.js} +54 -13
  17. package/dist/{client-Dqg2mc-7.d.ts → client-BVNWjk6W.d.ts} +2 -2
  18. package/dist/{client-BfpNjJ_a.d.mts → client-BuLcOWLv.d.ts} +115 -23
  19. package/dist/{client-DHBwvh7U.d.ts → client-D5AoobFc.d.mts} +115 -23
  20. package/dist/{client-DpqRobY9.d.mts → client-fM716k7G.d.mts} +2 -2
  21. package/dist/{index-C8uDqLwJ.d.ts → index-BtcoqrY1.d.ts} +3 -3
  22. package/dist/{index-e2y6AK70.d.mts → index-D7Tf3v7c.d.mts} +3 -3
  23. package/dist/index.d.mts +10 -8
  24. package/dist/index.d.ts +10 -8
  25. package/dist/index.js +107 -106
  26. package/dist/index.mjs +6 -5
  27. package/dist/{link-cuNVYc2s.d.mts → link-D9iSVxt5.d.mts} +12 -1
  28. package/dist/{link-cuNVYc2s.d.ts → link-D9iSVxt5.d.ts} +12 -1
  29. package/dist/mock/cli.mjs +53 -10
  30. package/dist/mock/library.js +53 -10
  31. package/dist/mock/library.mjs +53 -10
  32. package/dist/mock/msw.js +53 -10
  33. package/dist/mock/msw.mjs +53 -10
  34. package/dist/{payment-H5LoIvXU.d.mts → payment-g0HFkEDU.d.mts} +519 -54
  35. package/dist/{payment-H5LoIvXU.d.ts → payment-g0HFkEDU.d.ts} +519 -54
  36. package/dist/{price-C2RqscMY.d.ts → price-BLIeAb8K.d.ts} +1 -1
  37. package/dist/{price-BvePgDXe.d.mts → price-Czq_cTC_.d.mts} +1 -1
  38. package/dist/react.d.mts +4 -4
  39. package/dist/react.d.ts +4 -4
  40. package/dist/react.js +193 -169
  41. package/dist/react.mjs +54 -30
  42. package/dist/{server-C7FyLdrz.d.mts → server-BkVhOIwn.d.mts} +4 -2
  43. package/dist/{server-DoXIpSd7.d.ts → server-DKK_D-PP.d.ts} +4 -2
  44. package/dist/server.d.mts +4 -4
  45. package/dist/server.d.ts +4 -4
  46. package/dist/server.js +11 -10
  47. package/dist/server.mjs +5 -4
  48. package/dist/testing/msw.d.mts +2 -2
  49. package/dist/testing/msw.d.ts +2 -2
  50. package/dist/testing/msw.js +3 -3
  51. package/dist/testing/msw.mjs +2 -2
  52. package/dist/testing/suite.d.mts +6 -6
  53. package/dist/testing/suite.d.ts +6 -6
  54. package/dist/testing/suite.js +25 -25
  55. package/dist/testing/suite.mjs +6 -6
  56. package/dist/testing.d.mts +46 -6
  57. package/dist/testing.d.ts +46 -6
  58. package/dist/testing.js +94 -82
  59. package/dist/testing.mjs +13 -9
  60. package/dist/utils.d.mts +4 -4
  61. package/dist/utils.d.ts +4 -4
  62. package/dist/utils.js +31 -31
  63. package/dist/utils.mjs +2 -2
  64. package/package.json +1 -1
  65. package/registry/chat-widget.json +1 -1
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkJSWJ4XDE_js = require('./chunk-JSWJ4XDE.js');
4
- var chunkJG5CQNCB_js = require('./chunk-JG5CQNCB.js');
3
+ var chunkXREIZ56K_js = require('./chunk-XREIZ56K.js');
4
+ var chunkIQFFSKE2_js = require('./chunk-IQFFSKE2.js');
5
+ var chunk4BKOKHE3_js = require('./chunk-4BKOKHE3.js');
5
6
 
6
7
  // src/store-credit.ts
7
8
  var StoreCreditQueries = class {
@@ -13,7 +14,7 @@ var StoreCreditQueries = class {
13
14
  * currency. Requires a signed-in customer; returns an error otherwise.
14
15
  */
15
16
  async balance() {
16
- return chunkJSWJ4XDE_js.safe(this.client.get("/api/v1/store-credit/balance"));
17
+ return chunkIQFFSKE2_js.safe(this.client.get("/api/v1/store-credit/balance"));
17
18
  }
18
19
  };
19
20
 
@@ -208,6 +209,7 @@ var ActivityService = class {
208
209
  utm_campaign: utm("campaign"),
209
210
  utm_term: utm("term"),
210
211
  utm_content: utm("content"),
212
+ social_commerce_ref: params.get("social_commerce_ref") || void 0,
211
213
  screen_width: window.screen?.width,
212
214
  screen_height: window.screen?.height,
213
215
  viewport_width: window.innerWidth,
@@ -262,7 +264,7 @@ var ActivityService = class {
262
264
  this.sendEvents([event]);
263
265
  }
264
266
  async getState() {
265
- return chunkJSWJ4XDE_js.safe(this.client.get("/api/v1/activity/state"));
267
+ return chunkIQFFSKE2_js.safe(this.client.get("/api/v1/activity/state"));
266
268
  }
267
269
  async getRecommendations(options) {
268
270
  const params = new URLSearchParams();
@@ -270,10 +272,10 @@ var ActivityService = class {
270
272
  if (options?.limit) params.set("limit", String(options.limit));
271
273
  const query = params.toString();
272
274
  const path = query ? `/api/v1/activity/recommendations?${query}` : "/api/v1/activity/recommendations";
273
- return chunkJSWJ4XDE_js.safe(this.client.get(path));
275
+ return chunkIQFFSKE2_js.safe(this.client.get(path));
274
276
  }
275
277
  async dismissMessage(code) {
276
- return chunkJSWJ4XDE_js.safe(
278
+ return chunkIQFFSKE2_js.safe(
277
279
  this.client.post("/api/v1/activity/messages/dismiss", { code })
278
280
  );
279
281
  }
@@ -369,16 +371,16 @@ var SubscriptionService = class {
369
371
  this.client = client;
370
372
  }
371
373
  async list() {
372
- return chunkJSWJ4XDE_js.safe(this.client.get("/api/v1/subscriptions"));
374
+ return chunkIQFFSKE2_js.safe(this.client.get("/api/v1/subscriptions"));
373
375
  }
374
376
  async get(id) {
375
377
  const encodedId = encodeURIComponent(id);
376
- return chunkJSWJ4XDE_js.safe(this.client.get(`/api/v1/subscriptions/${encodedId}`));
378
+ return chunkIQFFSKE2_js.safe(this.client.get(`/api/v1/subscriptions/${encodedId}`));
377
379
  }
378
380
  async cancel(id, reason, opts) {
379
381
  const encodedId = encodeURIComponent(id);
380
- const idempotencyKey = opts?.idempotencyKey ?? chunkJSWJ4XDE_js.generateIdempotencyKey();
381
- return chunkJSWJ4XDE_js.safe(
382
+ const idempotencyKey = opts?.idempotencyKey ?? chunkIQFFSKE2_js.generateIdempotencyKey();
383
+ return chunkIQFFSKE2_js.safe(
382
384
  this.client.post(
383
385
  `/api/v1/subscriptions/${encodedId}/cancel`,
384
386
  { reason },
@@ -388,20 +390,20 @@ var SubscriptionService = class {
388
390
  }
389
391
  async pause(id) {
390
392
  const encodedId = encodeURIComponent(id);
391
- return chunkJSWJ4XDE_js.safe(
393
+ return chunkIQFFSKE2_js.safe(
392
394
  this.client.post(`/api/v1/subscriptions/${encodedId}/pause`)
393
395
  );
394
396
  }
395
397
  async resume(id) {
396
398
  const encodedId = encodeURIComponent(id);
397
- return chunkJSWJ4XDE_js.safe(
399
+ return chunkIQFFSKE2_js.safe(
398
400
  this.client.post(`/api/v1/subscriptions/${encodedId}/resume`)
399
401
  );
400
402
  }
401
403
  async skipNextRenewal(id, opts) {
402
404
  const encodedId = encodeURIComponent(id);
403
- const idempotencyKey = opts?.idempotencyKey ?? chunkJSWJ4XDE_js.generateIdempotencyKey();
404
- return chunkJSWJ4XDE_js.safe(
405
+ const idempotencyKey = opts?.idempotencyKey ?? chunkIQFFSKE2_js.generateIdempotencyKey();
406
+ return chunkIQFFSKE2_js.safe(
405
407
  this.client.post(
406
408
  `/api/v1/subscriptions/${encodedId}/skip`,
407
409
  void 0,
@@ -416,14 +418,14 @@ var UploadService = class {
416
418
  constructor(client) {
417
419
  this.client = client;
418
420
  }
419
- async init(filename, contentType, sizeBytes, opts) {
420
- const idempotencyKey = opts?.idempotencyKey ?? chunkJSWJ4XDE_js.generateIdempotencyKey();
421
- return chunkJSWJ4XDE_js.safe(
421
+ async init(filename, contentType2, sizeBytes, opts) {
422
+ const idempotencyKey = opts?.idempotencyKey ?? chunkIQFFSKE2_js.generateIdempotencyKey();
423
+ return chunkIQFFSKE2_js.safe(
422
424
  this.client.post(
423
425
  "/api/v1/uploads/init",
424
426
  {
425
427
  filename,
426
- content_type: contentType,
428
+ content_type: contentType2,
427
429
  size_bytes: sizeBytes
428
430
  },
429
431
  { idempotencyKey }
@@ -431,7 +433,7 @@ var UploadService = class {
431
433
  );
432
434
  }
433
435
  async confirm(uploadId) {
434
- return chunkJSWJ4XDE_js.safe(
436
+ return chunkIQFFSKE2_js.safe(
435
437
  this.client.post("/api/v1/uploads/confirm", {
436
438
  upload_id: uploadId
437
439
  })
@@ -450,7 +452,7 @@ var UploadService = class {
450
452
  if (!uploadResponse.ok) {
451
453
  return {
452
454
  ok: false,
453
- error: new chunkJG5CQNCB_js.CimplifyError(
455
+ error: new chunk4BKOKHE3_js.CimplifyError(
454
456
  "UPLOAD_FAILED",
455
457
  `Upload failed with status ${uploadResponse.status}`,
456
458
  true
@@ -460,7 +462,7 @@ var UploadService = class {
460
462
  } catch (error) {
461
463
  return {
462
464
  ok: false,
463
- error: new chunkJG5CQNCB_js.CimplifyError(
465
+ error: new chunk4BKOKHE3_js.CimplifyError(
464
466
  "UPLOAD_FAILED",
465
467
  error instanceof Error ? error.message : "Upload failed",
466
468
  true
@@ -477,7 +479,7 @@ var PlacesService = class {
477
479
  this.client = client;
478
480
  }
479
481
  async autocomplete(input, sessionToken) {
480
- return chunkJSWJ4XDE_js.safe(
482
+ return chunkIQFFSKE2_js.safe(
481
483
  this.client.post("/api/v1/places/autocomplete", {
482
484
  input,
483
485
  sessionToken
@@ -485,7 +487,7 @@ var PlacesService = class {
485
487
  );
486
488
  }
487
489
  async details(placeId, sessionToken) {
488
- return chunkJSWJ4XDE_js.safe(
490
+ return chunkIQFFSKE2_js.safe(
489
491
  this.client.post("/api/v1/places/details", {
490
492
  place_id: placeId,
491
493
  sessionToken
@@ -504,7 +506,7 @@ var DeliveryService = class {
504
506
  params.set("dropoff_lat", String(dropoffLat));
505
507
  params.set("dropoff_lng", String(dropoffLng));
506
508
  if (country) params.set("country", country);
507
- return chunkJSWJ4XDE_js.safe(this.client.get(`/api/v1/delivery/fee?${params.toString()}`));
509
+ return chunkIQFFSKE2_js.safe(this.client.get(`/api/v1/delivery/fee?${params.toString()}`));
508
510
  }
509
511
  async getOptions(queryOrLatitude, longitude, legacyOptions) {
510
512
  const query = typeof queryOrLatitude === "number" ? {
@@ -518,12 +520,105 @@ var DeliveryService = class {
518
520
  if (query.country) params.set("country", query.country);
519
521
  if (query.currency) params.set("currency", query.currency);
520
522
  if (query.orderValue != null) params.set("order_value", String(query.orderValue));
521
- return chunkJSWJ4XDE_js.safe(
523
+ return chunkIQFFSKE2_js.safe(
522
524
  this.client.get(`/api/v1/delivery/options?${params.toString()}`)
523
525
  );
524
526
  }
525
527
  };
526
528
 
529
+ // src/chat-wire.ts
530
+ function senderType(message) {
531
+ if (message.sender_side === "account") return "customer";
532
+ if (message.sender_side === "system") return "system";
533
+ return message.authorship === "ai" ? "bot" : "agent";
534
+ }
535
+ function contentType(message) {
536
+ if (message.content_type === "rich") {
537
+ return message.structured_content?.["kind"] === "reaction" ? "reaction" : "interactive";
538
+ }
539
+ if (message.content_type === "media") {
540
+ const mime = message.media[0]?.mime_type ?? "";
541
+ if (mime.startsWith("image/")) return "image";
542
+ if (mime.startsWith("video/")) return "video";
543
+ if (mime.startsWith("audio/")) return "audio";
544
+ return "document";
545
+ }
546
+ return "text";
547
+ }
548
+ function unresolvedReply(id) {
549
+ return { id, sender_type: "system", preview: "Earlier message" };
550
+ }
551
+ function chatMessagesFromWire(messages) {
552
+ const converted = messages.map((message) => ({
553
+ id: message.id,
554
+ sequence: message.sequence,
555
+ sender_type: senderType(message),
556
+ content: message.content,
557
+ content_type: contentType(message),
558
+ attachments: Array.isArray(message.media) ? message.media : [],
559
+ metadata: message.structured_content ?? {},
560
+ reply_to: message.reply_to_message_id ? unresolvedReply(message.reply_to_message_id) : void 0,
561
+ edited_at: message.edited_at,
562
+ deleted_at: message.deleted_at,
563
+ created_at: message.created_at
564
+ }));
565
+ const byId = new Map(converted.map((message) => [message.id, message]));
566
+ return converted.map((message) => {
567
+ const targetId = message.reply_to?.id;
568
+ const target = targetId ? byId.get(targetId) : void 0;
569
+ if (!targetId || !target) return message;
570
+ return {
571
+ ...message,
572
+ reply_to: {
573
+ id: targetId,
574
+ sender_type: target.sender_type,
575
+ preview: chunkXREIZ56K_js.messagePreview(target.content)
576
+ }
577
+ };
578
+ });
579
+ }
580
+ function chatMessageFromWire(message) {
581
+ return chatMessagesFromWire([message])[0];
582
+ }
583
+ function chatRealtimeUpdateFromWire(envelope) {
584
+ if (envelope.type === "message_created" && envelope.data) {
585
+ return {
586
+ kind: "message",
587
+ message: chatMessageFromWire(envelope.data)
588
+ };
589
+ }
590
+ if (envelope.type === "message_updated" && envelope.data) {
591
+ return {
592
+ kind: "message_updated",
593
+ message: chatMessageFromWire(envelope.data)
594
+ };
595
+ }
596
+ if (envelope.type === "read" && envelope.data) {
597
+ const read = envelope.data;
598
+ if (read.reader_side === "business" && typeof read.occurred_at === "string") {
599
+ return { kind: "business_read", occurredAt: read.occurred_at };
600
+ }
601
+ return { kind: "none" };
602
+ }
603
+ if (envelope.type === "history_imported") {
604
+ return { kind: "reload" };
605
+ }
606
+ if (envelope.type === "ai_mode_changed" && envelope.data) {
607
+ const mode = envelope.data.mode;
608
+ if (mode === "auto" || mode === "assist" || mode === "off") {
609
+ return { kind: "ai_mode", mode };
610
+ }
611
+ return { kind: "none" };
612
+ }
613
+ if (envelope.type === "handoff_requested") {
614
+ return { kind: "handoff" };
615
+ }
616
+ if (envelope.type === "resync") {
617
+ return { kind: "resync", latestSequence: envelope.latest_sequence };
618
+ }
619
+ return { kind: "none" };
620
+ }
621
+
527
622
  // src/internal/events.ts
528
623
  var MUTATION_ERROR = "mutation:error";
529
624
  var AUTH_TOKEN_CHANGED = "auth:token-changed";
@@ -586,16 +681,18 @@ var SupportService = class {
586
681
  * Claim the anonymous session for the verified Link identity: the server
587
682
  * verifies the access token, rotates the session token (adopted here, so
588
683
  * every subsequent request rides the bound session), folds the guest cart
589
- * in, and adopts or merges the widget conversation.
684
+ * in, and opens or reuses the account's canonical direct Chat thread.
590
685
  *
591
686
  * Idempotent and single-flight: concurrent calls share one request, and a
592
687
  * token already claimed by this instance short-circuits without a network
593
- * round trip. Emits `session:claimed` on the client's event channel.
688
+ * round trip. A session already bound to another Link account is rejected
689
+ * rather than transferring that account's cart. Emits `session:claimed` on
690
+ * the client's event channel.
594
691
  */
595
692
  async claimConversation() {
596
693
  const accessToken = this.client.getAccessToken();
597
694
  if (!accessToken) {
598
- return chunkJSWJ4XDE_js.err(new chunkJG5CQNCB_js.CimplifyError("not_authenticated", "No access token to claim with"));
695
+ return chunkIQFFSKE2_js.err(new chunk4BKOKHE3_js.CimplifyError("not_authenticated", "No access token to claim with"));
599
696
  }
600
697
  if (this.claimInFlight) {
601
698
  if (this.claimInFlightToken === accessToken) return this.claimInFlight;
@@ -603,12 +700,12 @@ var SupportService = class {
603
700
  return this.claimConversation();
604
701
  }
605
702
  if (this.lastClaimedAccessToken === accessToken) {
606
- return chunkJSWJ4XDE_js.err(new chunkJG5CQNCB_js.CimplifyError("already_claimed", "Session already claimed for this token"));
703
+ return chunkIQFFSKE2_js.err(new chunk4BKOKHE3_js.CimplifyError("already_claimed", "Session already claimed for this token"));
607
704
  }
608
705
  const epoch = this.client.getSessionEpoch();
609
706
  this.claimInFlightToken = accessToken;
610
707
  this.claimInFlight = (async () => {
611
- const result = await chunkJSWJ4XDE_js.safe(
708
+ const result = await chunkIQFFSKE2_js.safe(
612
709
  this.client.post(
613
710
  "/api/v1/support/conversation/claim",
614
711
  { access_token: accessToken },
@@ -617,8 +714,8 @@ var SupportService = class {
617
714
  );
618
715
  if (result.ok) {
619
716
  if (this.client.getSessionEpoch() !== epoch) {
620
- return chunkJSWJ4XDE_js.err(
621
- new chunkJG5CQNCB_js.CimplifyError("session_cleared", "Session was cleared during the claim")
717
+ return chunkIQFFSKE2_js.err(
718
+ new chunk4BKOKHE3_js.CimplifyError("session_cleared", "Session was cleared during the claim")
622
719
  );
623
720
  }
624
721
  this.lastClaimedAccessToken = accessToken;
@@ -627,7 +724,7 @@ var SupportService = class {
627
724
  this.client.publishSessionClaimed(this.claimedName);
628
725
  this.client.events.emit(SESSION_CLAIMED, {
629
726
  sessionToken: result.value.session_token,
630
- threadId: result.value.thread_id ?? null,
727
+ threadId: result.value.thread.id,
631
728
  customerName: result.value.customer_name
632
729
  });
633
730
  }
@@ -640,30 +737,54 @@ var SupportService = class {
640
737
  this.claimInFlightToken = null;
641
738
  }
642
739
  }
740
+ /**
741
+ * Retry verified external-history discovery for the current storefront.
742
+ * Launch scope is intentionally WhatsApp-only because it is the registered
743
+ * bidirectional transport. Results are per envelope and omit provider ids,
744
+ * contact values, account ids, and message bodies.
745
+ */
746
+ async claimExternalChats() {
747
+ if (!this.client.getAccessToken()) {
748
+ return chunkIQFFSKE2_js.err(new chunk4BKOKHE3_js.CimplifyError("not_authenticated", "No access token to claim with"));
749
+ }
750
+ return chunkIQFFSKE2_js.safe(
751
+ (async () => {
752
+ const businessId = await this.client.resolveBusinessId();
753
+ return this.client.post("/v1/me/chats/external-claims", {
754
+ business_id: businessId
755
+ });
756
+ })()
757
+ );
758
+ }
643
759
  /**
644
760
  * Peek at the conversation without creating one: resolves the existing
645
761
  * thread (or null) so a page load can hydrate history without littering
646
762
  * the inbox with empty threads.
647
763
  */
648
764
  async peekConversation() {
649
- const result = await chunkJSWJ4XDE_js.safe(
765
+ const result = await chunkIQFFSKE2_js.safe(
650
766
  this.client.get("/api/v1/support/conversation")
651
767
  );
652
768
  if (!result.ok) return result;
653
- if (!result.value.conversation) return chunkJSWJ4XDE_js.ok(null);
654
- return chunkJSWJ4XDE_js.ok({
769
+ if (!result.value.conversation) return chunkIQFFSKE2_js.ok(null);
770
+ return chunkIQFFSKE2_js.ok({
655
771
  conversation: result.value.conversation,
656
- messages: result.value.messages
772
+ messages: chatMessagesFromWire(result.value.messages)
657
773
  });
658
774
  }
659
775
  /** Open (or resume) the customer's widget conversation. */
660
776
  async openConversation(opts) {
661
- const idempotencyKey = opts?.idempotencyKey ?? chunkJSWJ4XDE_js.generateIdempotencyKey();
662
- return chunkJSWJ4XDE_js.safe(
777
+ const idempotencyKey = opts?.idempotencyKey ?? chunkIQFFSKE2_js.generateIdempotencyKey();
778
+ const result = await chunkIQFFSKE2_js.safe(
663
779
  this.client.post("/api/v1/support/conversation", void 0, {
664
780
  idempotencyKey
665
781
  })
666
782
  );
783
+ if (!result.ok) return result;
784
+ return chunkIQFFSKE2_js.ok({
785
+ conversation: result.value.conversation,
786
+ messages: chatMessagesFromWire(result.value.messages)
787
+ });
667
788
  }
668
789
  /**
669
790
  * Send a message in the active conversation.
@@ -674,8 +795,8 @@ var SupportService = class {
674
795
  * server resolves it thread-scoped and echoes the quote as `reply_to`.
675
796
  */
676
797
  async sendMessage(content, opts) {
677
- const idempotencyKey = opts?.idempotencyKey ?? chunkJSWJ4XDE_js.generateIdempotencyKey();
678
- return chunkJSWJ4XDE_js.safe(
798
+ const idempotencyKey = opts?.idempotencyKey ?? chunkIQFFSKE2_js.generateIdempotencyKey();
799
+ const result = await chunkIQFFSKE2_js.safe(
679
800
  this.client.post(
680
801
  "/api/v1/support/conversation/messages",
681
802
  {
@@ -687,6 +808,7 @@ var SupportService = class {
687
808
  { idempotencyKey }
688
809
  )
689
810
  );
811
+ return result.ok ? chunkIQFFSKE2_js.ok(chatMessageFromWire(result.value.message)) : result;
690
812
  }
691
813
  /**
692
814
  * Poll for messages. `after` pages forward (live updates); `before` pages
@@ -694,26 +816,32 @@ var SupportService = class {
694
816
  */
695
817
  async getMessages(options = {}) {
696
818
  const params = new URLSearchParams();
697
- if (options.after) params.set("after", options.after);
698
- if (options.before) params.set("before", options.before);
819
+ if (options.afterSequence !== void 0)
820
+ params.set("after_sequence", String(options.afterSequence));
821
+ if (options.beforeSequence !== void 0)
822
+ params.set("before_sequence", String(options.beforeSequence));
699
823
  if (options.limit) params.set("limit", String(options.limit));
700
824
  const query = params.toString();
701
825
  const path = query ? `/api/v1/support/conversation/messages?${query}` : "/api/v1/support/conversation/messages";
702
- return chunkJSWJ4XDE_js.safe(this.client.get(path));
826
+ const result = await chunkIQFFSKE2_js.safe(this.client.get(path));
827
+ return result.ok ? chunkIQFFSKE2_js.ok(chatMessagesFromWire(result.value)) : result;
703
828
  }
704
829
  /** React to a message in the active conversation by its `ChatMessage.id`. */
705
830
  async reactToMessage(messageId, emoji) {
706
- return chunkJSWJ4XDE_js.safe(
831
+ const clientId = chunkIQFFSKE2_js.generateIdempotencyKey();
832
+ const result = await chunkIQFFSKE2_js.safe(
707
833
  this.client.post(
708
834
  `/api/v1/support/conversation/messages/${messageId}/reactions`,
709
- { emoji }
835
+ { emoji, client_id: clientId },
836
+ { idempotencyKey: clientId }
710
837
  )
711
838
  );
839
+ return result.ok ? chunkIQFFSKE2_js.ok(chatMessageFromWire(result.value.message)) : result;
712
840
  }
713
841
  /** Ask for a person: flags the thread for the merchant's inbox. */
714
842
  async requestHuman(opts) {
715
- const idempotencyKey = opts?.idempotencyKey ?? chunkJSWJ4XDE_js.generateIdempotencyKey();
716
- return chunkJSWJ4XDE_js.safe(
843
+ const idempotencyKey = opts?.idempotencyKey ?? chunkIQFFSKE2_js.generateIdempotencyKey();
844
+ return chunkIQFFSKE2_js.safe(
717
845
  this.client.post(
718
846
  "/api/v1/support/conversation/handoff",
719
847
  void 0,
@@ -845,10 +973,10 @@ var PaystackAuthorizationAdapter = class {
845
973
  };
846
974
 
847
975
  // src/payment-authorization/providers/stripe.ts
848
- async function loadStripeFromPeer(publicKey) {
976
+ async function loadStripeFromPeer(publicKey, options) {
849
977
  try {
850
978
  const imported = await import('@stripe/stripe-js');
851
- return imported.loadStripe ? imported.loadStripe(publicKey) : null;
979
+ return imported.loadStripe ? imported.loadStripe(publicKey, options) : null;
852
980
  } catch {
853
981
  return null;
854
982
  }
@@ -956,7 +1084,10 @@ var StripeAuthorizationAdapter = class {
956
1084
  }
957
1085
  let stripe;
958
1086
  try {
959
- stripe = await this.loadStripe(context.action.public_key);
1087
+ stripe = await this.loadStripe(
1088
+ context.action.public_key,
1089
+ context.action.provider_account_id ? { stripeAccount: context.action.provider_account_id } : void 0
1090
+ );
960
1091
  } catch (error) {
961
1092
  return {
962
1093
  status: "failed",
@@ -1221,16 +1352,16 @@ function isRetryable(error) {
1221
1352
  if (error instanceof DOMException && error.name === "AbortError") {
1222
1353
  return true;
1223
1354
  }
1224
- if (error instanceof chunkJG5CQNCB_js.CimplifyError) {
1355
+ if (error instanceof chunk4BKOKHE3_js.CimplifyError) {
1225
1356
  return error.retryable;
1226
1357
  }
1227
1358
  return false;
1228
1359
  }
1229
1360
  function toNetworkError(error, isTestMode) {
1230
1361
  if (error instanceof DOMException && error.name === "AbortError") {
1231
- return chunkJG5CQNCB_js.enrichError(
1232
- new chunkJG5CQNCB_js.CimplifyError(
1233
- chunkJG5CQNCB_js.ErrorCode.TIMEOUT,
1362
+ return chunk4BKOKHE3_js.enrichError(
1363
+ new chunk4BKOKHE3_js.CimplifyError(
1364
+ chunk4BKOKHE3_js.ErrorCode.TIMEOUT,
1234
1365
  "Request timed out. Please check your connection and try again.",
1235
1366
  true
1236
1367
  ),
@@ -1238,21 +1369,21 @@ function toNetworkError(error, isTestMode) {
1238
1369
  );
1239
1370
  }
1240
1371
  if (error instanceof TypeError && error.message.includes("fetch")) {
1241
- return chunkJG5CQNCB_js.enrichError(
1242
- new chunkJG5CQNCB_js.CimplifyError(
1243
- chunkJG5CQNCB_js.ErrorCode.NETWORK_ERROR,
1372
+ return chunk4BKOKHE3_js.enrichError(
1373
+ new chunk4BKOKHE3_js.CimplifyError(
1374
+ chunk4BKOKHE3_js.ErrorCode.NETWORK_ERROR,
1244
1375
  "Network error. Please check your internet connection.",
1245
1376
  true
1246
1377
  ),
1247
1378
  { isTestMode }
1248
1379
  );
1249
1380
  }
1250
- if (error instanceof chunkJG5CQNCB_js.CimplifyError) {
1251
- return chunkJG5CQNCB_js.enrichError(error, { isTestMode });
1381
+ if (error instanceof chunk4BKOKHE3_js.CimplifyError) {
1382
+ return chunk4BKOKHE3_js.enrichError(error, { isTestMode });
1252
1383
  }
1253
- return chunkJG5CQNCB_js.enrichError(
1254
- new chunkJG5CQNCB_js.CimplifyError(
1255
- chunkJG5CQNCB_js.ErrorCode.UNKNOWN_ERROR,
1384
+ return chunk4BKOKHE3_js.enrichError(
1385
+ new chunk4BKOKHE3_js.CimplifyError(
1386
+ chunk4BKOKHE3_js.ErrorCode.UNKNOWN_ERROR,
1256
1387
  error instanceof Error ? error.message : "An unknown error occurred",
1257
1388
  false
1258
1389
  ),
@@ -1379,7 +1510,8 @@ var CimplifyClient = class {
1379
1510
  * refresh restore) binds the anonymous session so the conversation, cart
1380
1511
  * and orders survive a cleared browser. Best-effort by design — a failed
1381
1512
  * claim leaves the session anonymous, exactly as it was. Called by the
1382
- * auth flows, never by the raw token setter.
1513
+ * merchant auth flows, never by the raw token setter. Global Link clients
1514
+ * have no storefront tenant and therefore activate without this step.
1383
1515
  */
1384
1516
  autoClaimChatIdentity() {
1385
1517
  if (typeof window === "undefined" || !this.sessionToken || !this.accessToken) return;
@@ -1421,9 +1553,28 @@ var CimplifyClient = class {
1421
1553
  getSessionEpoch() {
1422
1554
  return this.sessionEpoch;
1423
1555
  }
1556
+ /** Monotonic fence for async work scoped to the current storefront tenant. */
1557
+ getPublicKeyEpoch() {
1558
+ return this.publicKeyEpoch;
1559
+ }
1424
1560
  getSessionToken() {
1425
1561
  return this.sessionToken;
1426
1562
  }
1563
+ /** Whether the current transport session is known to have been claimed for
1564
+ * a Link identity, even when its in-memory bearer is absent after reload or
1565
+ * a failed refresh. The sync marker is written only after canonical claim
1566
+ * rotation and is replaced with `cleared` when a fresh session is minted. */
1567
+ hasClaimedSessionAuthority() {
1568
+ if (!this.sessionToken) return false;
1569
+ try {
1570
+ const raw = this.safeStorage()?.getItem(SESSION_SYNC_STORAGE_KEY);
1571
+ if (!raw) return false;
1572
+ const payload = JSON.parse(raw);
1573
+ return payload.type === "claimed" && payload.token === this.sessionToken;
1574
+ } catch {
1575
+ return false;
1576
+ }
1577
+ }
1427
1578
  publishSessionClaimed(customerName) {
1428
1579
  if (!this.sessionToken) return;
1429
1580
  this.broadcastSessionSync({
@@ -1557,15 +1708,15 @@ var CimplifyClient = class {
1557
1708
  const resolution = (async () => {
1558
1709
  const result = await this.business.getInfo();
1559
1710
  if (!result.ok || !result.value?.id) {
1560
- throw new chunkJG5CQNCB_js.CimplifyError(
1561
- chunkJG5CQNCB_js.ErrorCode.NOT_FOUND,
1711
+ throw new chunk4BKOKHE3_js.CimplifyError(
1712
+ chunk4BKOKHE3_js.ErrorCode.NOT_FOUND,
1562
1713
  "Unable to resolve business ID from the current public key.",
1563
1714
  true
1564
1715
  );
1565
1716
  }
1566
1717
  if (this.publicKeyEpoch !== publicKeyEpoch) {
1567
- throw new chunkJG5CQNCB_js.CimplifyError(
1568
- chunkJG5CQNCB_js.ErrorCode.TENANT_CONTEXT_CHANGED,
1718
+ throw new chunk4BKOKHE3_js.CimplifyError(
1719
+ chunk4BKOKHE3_js.ErrorCode.TENANT_CONTEXT_CHANGED,
1569
1720
  "The storefront tenant changed while resolving its business identity.",
1570
1721
  true
1571
1722
  );
@@ -1708,7 +1859,7 @@ var CimplifyClient = class {
1708
1859
  if (response.status >= 400 && response.status < 500) {
1709
1860
  this.hooks.onRequestError?.({
1710
1861
  ...context,
1711
- error: new chunkJG5CQNCB_js.CimplifyError(
1862
+ error: new chunk4BKOKHE3_js.CimplifyError(
1712
1863
  `HTTP_${response.status}`,
1713
1864
  `Request failed with status ${response.status}`,
1714
1865
  false
@@ -1734,7 +1885,7 @@ var CimplifyClient = class {
1734
1885
  }
1735
1886
  this.hooks.onRequestError?.({
1736
1887
  ...context,
1737
- error: new chunkJG5CQNCB_js.CimplifyError(
1888
+ error: new chunk4BKOKHE3_js.CimplifyError(
1738
1889
  "SERVER_ERROR",
1739
1890
  `Server error ${response.status} after ${retryCount} retries`,
1740
1891
  false
@@ -1894,12 +2045,12 @@ var CimplifyClient = class {
1894
2045
  const retryable = typeof json.error === "object" && typeof json.error?.retryable === "boolean" ? json.error.retryable : false;
1895
2046
  if (errorCode === "IDEMPOTENCY_MISMATCH") {
1896
2047
  const originalCreatedAt = typeof json.error === "object" && json.error?.original_created_at || "";
1897
- throw new chunkJG5CQNCB_js.IdempotencyMismatchError(errorMessage, originalCreatedAt);
2048
+ throw new chunk4BKOKHE3_js.IdempotencyMismatchError(errorMessage, originalCreatedAt);
1898
2049
  }
1899
- const error = chunkJG5CQNCB_js.enrichError(new chunkJG5CQNCB_js.CimplifyError(errorCode, errorMessage, retryable), {
2050
+ const error = chunk4BKOKHE3_js.enrichError(new chunk4BKOKHE3_js.CimplifyError(errorCode, errorMessage, retryable), {
1900
2051
  isTestMode: this.isTestMode()
1901
2052
  });
1902
- if ((response.status === 401 || error.code === chunkJG5CQNCB_js.ErrorCode.UNAUTHORIZED) && this.accessToken) {
2053
+ if ((response.status === 401 || error.code === chunk4BKOKHE3_js.ErrorCode.UNAUTHORIZED) && this.accessToken) {
1903
2054
  console.warn(
1904
2055
  "[Cimplify] Received 401 Unauthorized. Access token may be missing/expired. Refresh authentication and retry the request."
1905
2056
  );
@@ -1907,8 +2058,8 @@ var CimplifyClient = class {
1907
2058
  throw error;
1908
2059
  }
1909
2060
  if (json?.success === false || json?.error?.code || json?.error?.message) {
1910
- const error = chunkJG5CQNCB_js.enrichError(
1911
- new chunkJG5CQNCB_js.CimplifyError(
2061
+ const error = chunk4BKOKHE3_js.enrichError(
2062
+ new chunk4BKOKHE3_js.CimplifyError(
1912
2063
  json.error?.code || "API_ERROR",
1913
2064
  json.error?.message || "An error occurred",
1914
2065
  json.error?.retryable || false
@@ -1924,25 +2075,25 @@ var CimplifyClient = class {
1924
2075
  }
1925
2076
  get catalogue() {
1926
2077
  if (!this._catalogue) {
1927
- this._catalogue = new chunkJSWJ4XDE_js.CatalogueQueries(this);
2078
+ this._catalogue = new chunkIQFFSKE2_js.CatalogueQueries(this);
1928
2079
  }
1929
2080
  return this._catalogue;
1930
2081
  }
1931
2082
  get cart() {
1932
2083
  if (!this._cart) {
1933
- this._cart = new chunkJSWJ4XDE_js.CartOperations(this);
2084
+ this._cart = new chunkIQFFSKE2_js.CartOperations(this);
1934
2085
  }
1935
2086
  return this._cart;
1936
2087
  }
1937
2088
  get checkout() {
1938
2089
  if (!this._checkout) {
1939
- this._checkout = new chunkJSWJ4XDE_js.CheckoutService(this);
2090
+ this._checkout = new chunkIQFFSKE2_js.CheckoutService(this);
1940
2091
  }
1941
2092
  return this._checkout;
1942
2093
  }
1943
2094
  get orders() {
1944
2095
  if (!this._orders) {
1945
- this._orders = new chunkJSWJ4XDE_js.OrderQueries(this);
2096
+ this._orders = new chunkIQFFSKE2_js.OrderQueries(this);
1946
2097
  }
1947
2098
  return this._orders;
1948
2099
  }
@@ -1972,43 +2123,43 @@ var CimplifyClient = class {
1972
2123
  }
1973
2124
  get link() {
1974
2125
  if (!this._link) {
1975
- this._link = new chunkJSWJ4XDE_js.LinkService(this);
2126
+ this._link = new chunkIQFFSKE2_js.LinkService(this);
1976
2127
  }
1977
2128
  return this._link;
1978
2129
  }
1979
2130
  get auth() {
1980
2131
  if (!this._auth) {
1981
- this._auth = new chunkJSWJ4XDE_js.AuthService(this);
2132
+ this._auth = new chunkIQFFSKE2_js.AuthService(this);
1982
2133
  }
1983
2134
  return this._auth;
1984
2135
  }
1985
2136
  get business() {
1986
2137
  if (!this._business) {
1987
- this._business = new chunkJSWJ4XDE_js.BusinessService(this);
2138
+ this._business = new chunkIQFFSKE2_js.BusinessService(this);
1988
2139
  }
1989
2140
  return this._business;
1990
2141
  }
1991
2142
  get inventory() {
1992
2143
  if (!this._inventory) {
1993
- this._inventory = new chunkJSWJ4XDE_js.InventoryService(this);
2144
+ this._inventory = new chunkIQFFSKE2_js.InventoryService(this);
1994
2145
  }
1995
2146
  return this._inventory;
1996
2147
  }
1997
2148
  get scheduling() {
1998
2149
  if (!this._scheduling) {
1999
- this._scheduling = new chunkJSWJ4XDE_js.SchedulingService(this);
2150
+ this._scheduling = new chunkIQFFSKE2_js.SchedulingService(this);
2000
2151
  }
2001
2152
  return this._scheduling;
2002
2153
  }
2003
2154
  get lite() {
2004
2155
  if (!this._lite) {
2005
- this._lite = new chunkJSWJ4XDE_js.LiteService(this);
2156
+ this._lite = new chunkIQFFSKE2_js.LiteService(this);
2006
2157
  }
2007
2158
  return this._lite;
2008
2159
  }
2009
2160
  get fx() {
2010
2161
  if (!this._fx) {
2011
- this._fx = new chunkJSWJ4XDE_js.FxService(this);
2162
+ this._fx = new chunkIQFFSKE2_js.FxService(this);
2012
2163
  }
2013
2164
  return this._fx;
2014
2165
  }
@@ -2043,7 +2194,7 @@ var CimplifyClient = class {
2043
2194
  if (businessId) {
2044
2195
  this.setBusinessId(businessId);
2045
2196
  }
2046
- return chunkJSWJ4XDE_js.createElements(this, businessId ?? this.businessId ?? void 0, options);
2197
+ return chunkIQFFSKE2_js.createElements(this, businessId ?? this.businessId ?? void 0, options);
2047
2198
  }
2048
2199
  };
2049
2200
  function createCimplifyClient(config = {}) {
@@ -2065,5 +2216,6 @@ exports.StripeAuthorizationAdapter = StripeAuthorizationAdapter;
2065
2216
  exports.SubscriptionService = SubscriptionService;
2066
2217
  exports.SupportService = SupportService;
2067
2218
  exports.UploadService = UploadService;
2219
+ exports.chatRealtimeUpdateFromWire = chatRealtimeUpdateFromWire;
2068
2220
  exports.createCimplifyClient = createCimplifyClient;
2069
2221
  exports.createDefaultPaymentAuthorizationAdapterRegistry = createDefaultPaymentAuthorizationAdapterRegistry;