@cimulate/copilot-widget 1.57.1 → 1.58.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,6 +35,8 @@ import { RefinedSearch } from '@cimulate/copilot-sdk';
35
35
  import { SearchParams } from '@cimulate/copilot-sdk';
36
36
  import { SessionContextEntry } from '@cimulate/agentforce-sdk';
37
37
 
38
+ export declare const addCartActionListener: (listener: EventListener) => void;
39
+
38
40
  export declare const addCartUpdateListener: (listener: EventListener) => void;
39
41
 
40
42
  declare interface AddToCartParams {
@@ -103,8 +105,56 @@ declare interface BrowseState extends CommonParams {
103
105
  categoryName?: string;
104
106
  }
105
107
 
108
+ export declare const CART_ACTION_EVENT = "cimulate:cart-action";
109
+
106
110
  export declare const CART_UPDATE_EVENT = "cimulate:cart-update";
107
111
 
112
+ /**
113
+ * `detail` of `cimulate:cart-action`. Call `respond` once with the latest cart
114
+ * after the storefront finishes the action. For `add`, `productId` identifies the
115
+ * selected purchasable product or variant. `itemId` is the basket line.
116
+ * `quantity` and `remove` also include `productId` (empty when the line has none)
117
+ * and `variants` (`lbl`, `type`, `value`), omitting entries with no value.
118
+ */
119
+ export declare type CartActionDetail = CartActionRequest & {
120
+ respond: (result: CartActionResult) => void;
121
+ };
122
+
123
+ export declare type CartActionRequest = {
124
+ action: "get";
125
+ } | {
126
+ action: "add";
127
+ productId: string;
128
+ quantity: number;
129
+ } | {
130
+ action: "quantity";
131
+ itemId: string;
132
+ quantity: number;
133
+ productId: string;
134
+ variants: CartItemVariant[];
135
+ } | {
136
+ action: "remove";
137
+ itemId: string;
138
+ productId: string;
139
+ variants: CartItemVariant[];
140
+ } | {
141
+ action: "coupon";
142
+ code: string;
143
+ };
144
+
145
+ /**
146
+ * Cart the storefront passes to `respond` after it handles `cimulate:cart-action`.
147
+ * `cart` on a failure is the basket the storefront still knows about, when it has one.
148
+ */
149
+ export declare type CartActionResult = {
150
+ ok: true;
151
+ cart: CartDetails;
152
+ } | {
153
+ ok: false;
154
+ error: string;
155
+ cart?: CartDetails;
156
+ };
157
+
108
158
  export declare type CartChange = CartLineChange | CartCouponChange;
109
159
 
110
160
  /** A change to the set of applied coupon codes. */
@@ -192,11 +242,8 @@ export declare interface CartMutationApi {
192
242
  }
193
243
 
194
244
  /**
195
- * The api handed to a `Cart` override. Deliberately narrower than the shared
196
- * {@link OverrideApi}: it has no `sendMessage`, so the most sensitive slot cannot
197
- * post arbitrary text or reconcile a message by id. Basket edits go through the
198
- * structured {@link CartMutationApi}; checkout and express payment stay
199
- * widget-owned.
245
+ * Structured basket mutations without `sendMessage`.
246
+ * Agent-mode checkout stays widget-owned; direct-mode overrides own payment controls.
200
247
  */
201
248
  export declare interface CartOverrideApi extends Pick<MessagingContextType, "isConnected"> {
202
249
  cart: CartMutationApi;
@@ -242,6 +289,13 @@ declare type CartResponseData = {
242
289
  };
243
290
  };
244
291
 
292
+ /**
293
+ * `"agent"` (default) edits the basket with natural-language prompts.
294
+ * `"direct"` dispatches `cimulate:cart-action` and renders the cart the
295
+ * storefront returns from `detail.respond`.
296
+ */
297
+ export declare type CartTransport = "agent" | "direct";
298
+
245
299
  /**
246
300
  * Primary action for a settled cart mutation, derived from the previous-vs-new
247
301
  * cart diff, or from the agent's `cartSummary.cartOperation` (matched
@@ -361,16 +415,9 @@ export declare interface ComponentOverrides {
361
415
  */
362
416
  OrderConfirmation?: OverrideTagName;
363
417
  /**
364
- * Replaces the in-chat cart BODY (items, totals, coupons) — a presentational
365
- * slot. Checkout and the Apple/Google Pay iframe are NOT part of it: the widget
366
- * keeps rendering them itself, beneath the override. The slot receives a
367
- * {@link CartOverrideProps} — a display-only {@link DisplayCart} (no
368
- * checkout/express URLs) and a {@link CartOverrideApi} whose `cart` methods are
369
- * the only way to mutate the basket; there is no `sendMessage`. The widget
370
- * marks every cart snapshot except the newest `readOnly` and refuses mutations
371
- * while it is set (or the cart is busy/disconnected), but an override should
372
- * also reflect `readOnly` in its controls so a shopper can't act on a stale
373
- * basket.
418
+ * Receives {@link CartOverrideProps} with display data and structured cart actions.
419
+ * Agent mode replaces the cart body; checkout stays widget-owned.
420
+ * Direct mode replaces the iframe or built-in cart and its payment controls.
374
421
  */
375
422
  Cart?: OverrideTagName;
376
423
  /**
@@ -501,13 +548,7 @@ declare type CouponEntry = string | StructuredCoupon;
501
548
 
502
549
  declare type DialogPosition = "top" | "top-left" | "top-right" | "bottom" | "bottom-left" | "bottom-right" | "left" | "right" | "center";
503
550
 
504
- /**
505
- * The cart summary handed to a `Cart` override: {@link CartDetails} minus the
506
- * transactional URLs. The widget renders checkout and Apple/Google Pay itself,
507
- * beneath the override, so `checkoutButtonUrl` and `expressPaymentUrl` never
508
- * enter customer markup — everything else is display data for the override to
509
- * lay out.
510
- */
551
+ /** Cart display data excludes checkout and express payment URLs in both modes. */
511
552
  export declare type DisplayCart = Omit<CartDetails, "checkoutButtonUrl" | "expressPaymentUrl">;
512
553
 
513
554
  declare const ENTRY_TYPES: readonly ["ask_cim", "search", "browse", "pdp"];
@@ -560,7 +601,7 @@ export declare function getAuthLinkKey(): Promise<string>;
560
601
 
561
602
  export declare function getPageContext(): PageContext | null;
562
603
 
563
- export declare type HeaderActionName = "close" | "toggleExpanded" | "toggleFullscreen" | "toggleDialogPosition" | "minimize" | "clearChat" | "endConversation" | "downloadTranscript";
604
+ export declare type HeaderActionName = "cart" | "close" | "toggleExpanded" | "toggleFullscreen" | "toggleDialogPosition" | "minimize" | "clearChat" | "endConversation" | "downloadTranscript";
564
605
 
565
606
  /**
566
607
  * Header controls a `HeaderActions` override can invoke. Each method calls the
@@ -734,6 +775,13 @@ export declare interface MessagingContextType {
734
775
  * is not connected or the request fails.
735
776
  */
736
777
  getAuthLinkKey: () => Promise<string>;
778
+ cartTransport: CartTransport;
779
+ directCart: CartDetails | null;
780
+ directCartError: string | null;
781
+ directCartLoading: boolean;
782
+ storefrontCartPageUrl: string;
783
+ loadDirectCart: () => Promise<void>;
784
+ applyDirectCartChange: (request: CartActionRequest) => Promise<SendMessageResult>;
737
785
  }
738
786
 
739
787
  /**
@@ -864,9 +912,20 @@ export declare interface MessagingModeConfig {
864
912
  * entries are ignored. `null` hides the connecting indicator entirely.
865
913
  */
866
914
  connectingMessages?: readonly string[] | null;
915
+ /**
916
+ * Who edits the basket. `"agent"` (default) sends the natural-language cart
917
+ * prompts. `"direct"` dispatches `cimulate:cart-action` and renders the cart
918
+ * the storefront passes to `detail.respond`.
919
+ */
920
+ cartTransport?: CartTransport;
921
+ /**
922
+ * Storefront cart page embedded in the cart tab. When set, that page replaces
923
+ * the built-in lines, coupon field, totals, and checkout.
924
+ */
925
+ storefrontCartPageUrl?: string;
867
926
  }
868
927
 
869
- export declare const MessagingProvider: ({ scrt2Url, orgId, esDeveloperName, routingAttributes, conversationId: configConversationId, continuationToken: configContinuationToken, lastEventId: configLastEventId, capabilitiesVersion, enablePageContext, enableLogging, onConnect, onMessage, onError, onProductResult, onEndConversation, onSessionUpdate, onWelcomeTimeout, children, }: MessagingProviderProps) => JSX_2.Element;
928
+ export declare const MessagingProvider: ({ scrt2Url, orgId, esDeveloperName, routingAttributes, conversationId: configConversationId, continuationToken: configContinuationToken, lastEventId: configLastEventId, capabilitiesVersion, enablePageContext, enableLogging, onConnect, onMessage, onError, onProductResult, onEndConversation, onSessionUpdate, onWelcomeTimeout, cartTransport, storefrontCartPageUrl, children, }: MessagingProviderProps) => JSX_2.Element;
870
929
 
871
930
  declare interface MessagingProviderProps {
872
931
  scrt2Url: string;
@@ -887,6 +946,8 @@ declare interface MessagingProviderProps {
887
946
  onEndConversation?: (conversationId: string | null) => Promise<void> | void;
888
947
  onSessionUpdate?: (update: MessagingSessionUpdate) => void;
889
948
  onWelcomeTimeout?: () => void;
949
+ cartTransport?: CartTransport;
950
+ storefrontCartPageUrl?: string;
890
951
  children: ReactNode;
891
952
  }
892
953
 
@@ -1121,7 +1182,8 @@ export declare interface OverrideFailureOptions {
1121
1182
  * - "Cart" → uses its own {@link CartOverrideProps}, not this
1122
1183
  * generic shape: a display-only {@link DisplayCart} plus
1123
1184
  * a structured `cart` mutation api and NO `sendMessage`.
1124
- * Checkout and express payment stay widget-owned. See
1185
+ * In agent mode, checkout and express payment stay widget-owned.
1186
+ * In direct mode, the override replaces the cart and its payment controls. See
1125
1187
  * ComponentOverrides.Cart.
1126
1188
  * - "HeaderActions" → uses its own {@link HeaderActionsOverrideProps}:
1127
1189
  * `payload.actions` is the live header state, and `api`
@@ -1359,6 +1421,8 @@ declare type RangeFilters = Array<{
1359
1421
  max: number;
1360
1422
  }>;
1361
1423
 
1424
+ export declare const removeCartActionListener: (listener: EventListener) => void;
1425
+
1362
1426
  export declare const removeCartUpdateListener: (listener: EventListener) => void;
1363
1427
 
1364
1428
  /**