@callimacus/thamyr-core 4.14.1 → 4.15.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.
@@ -493,6 +493,20 @@ type ShopifyStorefrontSettings = {
493
493
  };
494
494
  cartEnabled: boolean;
495
495
  };
496
+ type WooCommerceCart$1 = {
497
+ /**
498
+ * The site’s address: checkout opens there.
499
+ */
500
+ store: string;
501
+ /**
502
+ * The Store API root, `…/wp-json/wc/store/v1` (or `…/?rest_route=/wc/store/v1` on plain permalinks): append the route, e.g. `/cart/add-item`.
503
+ */
504
+ storeApi: string;
505
+ /**
506
+ * The `Cart-Token` header for the next cart call.
507
+ */
508
+ cartToken: string;
509
+ };
496
510
  type SkesisItemPage = {
497
511
  /**
498
512
  * The canonical page path, `/map/{locale}/{slug}/{id}`, as the sitemap lists it
@@ -837,15 +851,18 @@ type BlockPatchOutput = {
837
851
  type CartCommandOutput = {
838
852
  storyId: string;
839
853
  chapterId: string;
840
- command: 'shopify-add';
841
854
  /**
842
- * The Shopify product variant to add.
855
+ * The cart that adds it: the Shopify cart, or the WooCommerce Store API cart.
856
+ */
857
+ command: 'shopify-add' | 'woocommerce-add';
858
+ /**
859
+ * What to add: a Shopify product variant gid for `shopify-add`, a WooCommerce product or variation id for `woocommerce-add`.
843
860
  */
844
861
  variantId: string;
845
862
  quantity: number;
846
863
  item: {
847
864
  /**
848
- * The item the chat showed (`shopify:product:<gid>`).
865
+ * The item the chat showed (`shopify:product:<gid>`, `wordpress:product:<id>`).
849
866
  */
850
867
  id: string;
851
868
  name: string;
@@ -939,6 +956,10 @@ type CreateRoundContextOutput = {
939
956
  * The client runs a Shopify cart in the shopper's browser: the chat may then answer an add to the bag with a `cart-command`. Without it, an add to the bag shows the item's details.
940
957
  */
941
958
  shopifyCart?: boolean;
959
+ /**
960
+ * The client runs a WooCommerce cart in the shopper's browser: the chat may then answer an add to the bag of the store's product with a `cart-command`. Without it, an add to the bag shows the item's details.
961
+ */
962
+ woocommerceCart?: boolean;
942
963
  [key: string]: unknown;
943
964
  };
944
965
  type CustomBlockOutput = {
@@ -1096,7 +1117,7 @@ type SlDocumentOutput = {
1096
1117
  publishedAt?: string | null;
1097
1118
  unpublishedAt?: string | null;
1098
1119
  authors?: Array<string>;
1099
- source?: 'backoffice' | 'api' | 'salesforce';
1120
+ source?: 'backoffice' | 'api' | 'wordpress' | 'salesforce';
1100
1121
  slug?: string;
1101
1122
  documentGroupId: string;
1102
1123
  id: string;
@@ -1143,6 +1164,10 @@ type SlDocumentSectionOutput = {
1143
1164
  height: number;
1144
1165
  };
1145
1166
  poster?: string;
1167
+ /**
1168
+ * Length in seconds.
1169
+ */
1170
+ duration?: number;
1146
1171
  playerConfig?: {
1147
1172
  autoplay: boolean;
1148
1173
  muted: boolean;
@@ -1515,10 +1540,15 @@ type SkesisSimilarResponse = {
1515
1540
  item: SkesisItem;
1516
1541
  }>;
1517
1542
  /**
1518
- * Present only when the request set `explain: true`: what each stage of the pipeline decided, keyed by stage (search runs plan, route, retrieve, assess, relax and rank; the other pipelines a subset), plus `timings` in milliseconds. Decisions only — never what the engine was told.
1543
+ * System callers only: how the engine ran this request. Nobody else gets the key.
1519
1544
  */
1520
- trace?: {
1521
- [key: string]: unknown;
1545
+ diagnostic?: {
1546
+ /**
1547
+ * Present only when the request set `explain: true`: what each stage of the pipeline decided, keyed by stage (search runs retrieve, assess and rank; the other pipelines a subset), plus `timings` in milliseconds. Decisions only — never what the engine was told.
1548
+ */
1549
+ trace?: {
1550
+ [key: string]: unknown;
1551
+ };
1522
1552
  };
1523
1553
  };
1524
1554
  type SkesisRelatedResponse = {
@@ -1532,10 +1562,15 @@ type SkesisRelatedResponse = {
1532
1562
  }>;
1533
1563
  usedFallback: boolean;
1534
1564
  /**
1535
- * Present only when the request set `explain: true`: what each stage of the pipeline decided, keyed by stage (search runs plan, route, retrieve, assess, relax and rank; the other pipelines a subset), plus `timings` in milliseconds. Decisions only — never what the engine was told.
1565
+ * System callers only: how the engine ran this request. Nobody else gets the key.
1536
1566
  */
1537
- trace?: {
1538
- [key: string]: unknown;
1567
+ diagnostic?: {
1568
+ /**
1569
+ * Present only when the request set `explain: true`: what each stage of the pipeline decided, keyed by stage (search runs retrieve, assess and rank; the other pipelines a subset), plus `timings` in milliseconds. Decisions only — never what the engine was told.
1570
+ */
1571
+ trace?: {
1572
+ [key: string]: unknown;
1573
+ };
1539
1574
  };
1540
1575
  };
1541
1576
  /**
@@ -3063,6 +3098,34 @@ type ShopifyGetStorefrontSettingsResponses = {
3063
3098
  */
3064
3099
  200: ShopifyStorefrontSettings;
3065
3100
  };
3101
+ type WoocommerceStartCartErrors = {
3102
+ /**
3103
+ * Validation error
3104
+ */
3105
+ 400: unknown;
3106
+ /**
3107
+ * Missing or invalid access token
3108
+ */
3109
+ 401: unknown;
3110
+ /**
3111
+ * The caller is not permitted to perform this operation
3112
+ */
3113
+ 403: PinaxForbidden;
3114
+ /**
3115
+ * No WordPress site with WooCommerce is connected to this project
3116
+ */
3117
+ 404: PublicError;
3118
+ /**
3119
+ * The store did not answer.
3120
+ */
3121
+ 502: PublicError;
3122
+ };
3123
+ type WoocommerceStartCartResponses = {
3124
+ /**
3125
+ * Success
3126
+ */
3127
+ 200: WooCommerceCart$1;
3128
+ };
3066
3129
  type SkesisSimilarErrors = {
3067
3130
  /**
3068
3131
  * Validation error
@@ -3341,6 +3404,14 @@ declare class Shopify extends HeyApiClient {
3341
3404
  */
3342
3405
  getStorefrontSettings<ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>): RequestResult<ShopifyGetStorefrontSettingsResponses, ShopifyGetStorefrontSettingsErrors, ThrowOnError>;
3343
3406
  }
3407
+ declare class Woocommerce extends HeyApiClient {
3408
+ /**
3409
+ * Start a WooCommerce cart
3410
+ *
3411
+ * A new, empty cart on the WooCommerce store of the WordPress site connected to the project: the site’s address, the Store API root and the cart’s first token. Every cart call after this one goes from the browser to the store with the token, and each answer carries the token to send next. Not found while no WordPress site is connected, or the site sends no cart token (no WooCommerce on it).
3412
+ */
3413
+ startCart<ThrowOnError extends boolean = false>(options?: Options<never, ThrowOnError>): RequestResult<WoocommerceStartCartResponses, WoocommerceStartCartErrors, ThrowOnError>;
3414
+ }
3344
3415
  declare class Skesis extends HeyApiClient {
3345
3416
  /**
3346
3417
  * Similar items
@@ -3390,6 +3461,8 @@ declare class CallimacusApi extends HeyApiClient {
3390
3461
  get cart(): Cart;
3391
3462
  private _shopify?;
3392
3463
  get shopify(): Shopify;
3464
+ private _woocommerce?;
3465
+ get woocommerce(): Woocommerce;
3393
3466
  private _skesis?;
3394
3467
  get skesis(): Skesis;
3395
3468
  }
@@ -3453,10 +3526,11 @@ type ThamyrResponse = ThamyrResponse$1;
3453
3526
  */
3454
3527
  type BlockPatch = BlockPatchOutput;
3455
3528
  /**
3456
- An add to the bag the chat asks the shopper's browser to make in its Shopify cart,
3457
- at most once: it comes only on the socket whose round asked for it, only to a client
3458
- that declared `context.shopifyCart`, and is never stored with the round, so a replay
3459
- never sends it again. Run it with the Shopify cart (`@callimacus/thamyr-react` does).
3529
+ An add to the bag the chat asks the shopper's browser to make in its Shopify or
3530
+ WooCommerce cart, at most once: it comes only on the socket whose round asked for it,
3531
+ only to a client that declared `context.shopifyCart` or `context.woocommerceCart`, and
3532
+ is never stored with the round, so a replay never sends it again. Run it with the cart
3533
+ its `command` names (`@callimacus/thamyr-react` does).
3460
3534
  */
3461
3535
  type CartCommand = CartCommandOutput;
3462
3536
  /**
@@ -3593,6 +3667,10 @@ type InteractionContext = {
3593
3667
  The client runs a Shopify cart (`useShopifyCart`): a round that declares it may get the chat's add to the bag as a `cart-command`.
3594
3668
  */
3595
3669
  shopifyCart?: boolean;
3670
+ /**
3671
+ The client runs a WooCommerce cart (`useWooCommerceCart`): a round that declares it may get the chat's add to the bag of the store's product as a `cart-command`.
3672
+ */
3673
+ woocommerceCart?: boolean;
3596
3674
  };
3597
3675
  type UiObserverConfig = {
3598
3676
  enabled?: boolean;
@@ -4466,6 +4544,24 @@ Whether `variantId` is a Shopify product variant gid (`gid://shopify/ProductVari
4466
4544
  */
4467
4545
  declare const isVariantGid: (variantId: string) => boolean;
4468
4546
  /**
4547
+ A lock kept in `storage` for browsers without Web Locks: a lease with an owner
4548
+ and an expiry, read back after a short pause so two tabs that wrote at once
4549
+ agree on the last writer. Bounded: a tab waits `waitMs` at most, and a lease a
4550
+ crashed tab left behind expires after `ttlMs`.
4551
+ @internal
4552
+ */
4553
+ declare function leaseLock(storage: CartStorage, timing?: {
4554
+ waitMs?: number;
4555
+ ttlMs?: number;
4556
+ retryMs?: number;
4557
+ settleMs?: number;
4558
+ }): CartLock;
4559
+ /**
4560
+ The browser's Web Locks as a {@link CartLock}; undefined where there are none.
4561
+ @internal
4562
+ */
4563
+ declare function webLocks(): CartLock | undefined;
4564
+ /**
4469
4565
  The browser's storage, or one kept in memory where the browser refuses it. Pass the same one to every
4470
4566
  cart client of a page, so they share the cart id even where the browser keeps nothing.
4471
4567
  */
@@ -4483,6 +4579,166 @@ const {data, error, warnings} = await cart.addItem('gid://shopify/ProductVariant
4483
4579
  */
4484
4580
  declare function createShopifyCart(options: ShopifyCartClientOptions): ShopifyCartClient;
4485
4581
 
4582
+ /**
4583
+ Money as the Store API sends it: an integer string in the currency's minor unit, so `"1999"` with `currency_minor_unit: 2` is 19.99.
4584
+ */
4585
+ type WooCommerceMoney = {
4586
+ currency_code: string;
4587
+ currency_minor_unit: number;
4588
+ currency_symbol: string;
4589
+ };
4590
+ type WooCommerceCartItem = {
4591
+ /**
4592
+ The line's key: what `removeItem` and `updateQuantity` take.
4593
+ */
4594
+ key: string;
4595
+ /**
4596
+ The product, or the variation, the line holds.
4597
+ */
4598
+ id: number;
4599
+ quantity: number;
4600
+ name: string;
4601
+ permalink: string;
4602
+ images: Array<{
4603
+ src: string;
4604
+ thumbnail: string;
4605
+ alt: string;
4606
+ }>;
4607
+ /**
4608
+ The variation's attributes as the shopper reads them (`{attribute: 'Size', value: 'Medium'}`).
4609
+ */
4610
+ variation: Array<{
4611
+ attribute: string;
4612
+ value: string;
4613
+ }>;
4614
+ prices: WooCommerceMoney & {
4615
+ price: string;
4616
+ regular_price: string;
4617
+ sale_price: string;
4618
+ };
4619
+ totals: WooCommerceMoney & {
4620
+ line_subtotal: string;
4621
+ line_total: string;
4622
+ };
4623
+ };
4624
+ /**
4625
+ The cart as the Store API answers it (`/wc/store/v1/cart`), its fields WooCommerce's own; the ones a bag shows are typed.
4626
+ */
4627
+ type WooCommerceCart = {
4628
+ items: WooCommerceCartItem[];
4629
+ items_count: number;
4630
+ totals: WooCommerceMoney & {
4631
+ total_items: string;
4632
+ total_price: string;
4633
+ total_tax: string;
4634
+ };
4635
+ /**
4636
+ The store's notices on the cart as it stands: a line it no longer sells, a quantity it cut.
4637
+ */
4638
+ errors: Array<{
4639
+ code: string;
4640
+ message: string;
4641
+ }>;
4642
+ };
4643
+ /**
4644
+ - `cart_unavailable`: no store is connected to the site's project, or the store refuses the call (a security plugin).
4645
+ - `invalid_input`: not a product id, or not a whole quantity.
4646
+ - `refused`: the store said no (sold out, not for sale, a line no longer there); its words are in `message`.
4647
+ - `no_cart`: nothing to change or check out.
4648
+ - `throttled`: the store is rate limiting (429).
4649
+ - `busy`: another tab held the cart's start for too long.
4650
+ - `network`: no answer, or none in time. The store answers a token it no longer accepts without CORS headers, so that reads as this too.
4651
+ - `http`: any other failed status.
4652
+ */
4653
+ type WooCommerceCartErrorCode = 'cart_unavailable' | 'invalid_input' | 'refused' | 'no_cart' | 'throttled' | 'busy' | 'network' | 'http';
4654
+ type WooCommerceCartError = {
4655
+ code: WooCommerceCartErrorCode;
4656
+ message: string;
4657
+ /**
4658
+ The HTTP status, when the store answered with one.
4659
+ */
4660
+ status?: number;
4661
+ /**
4662
+ The store's own code for a refusal (`woocommerce_rest_product_out_of_stock`).
4663
+ */
4664
+ storeCode?: string;
4665
+ };
4666
+ /**
4667
+ What a cart method resolves, never rejects with. `data` is the cart (`undefined`: none yet), or
4668
+ the checkout URL for `checkout`. A refusal carries no cart: read it again with `getCart`.
4669
+ */
4670
+ type WooCommerceCartResult<T = WooCommerceCart | undefined> = {
4671
+ data: T;
4672
+ error?: undefined;
4673
+ } | {
4674
+ data?: undefined;
4675
+ error: WooCommerceCartError;
4676
+ };
4677
+ /**
4678
+ What callimacus-core's `POST /api/v3/woocommerce/cart` answers: the site, its Store API root and a new cart's first token.
4679
+ */
4680
+ type WooCommerceStart = {
4681
+ store: string;
4682
+ storeApi: string;
4683
+ cartToken: string;
4684
+ };
4685
+ type WooCommerceCartClientOptions = {
4686
+ /**
4687
+ Starts a cart on the store through callimacus-core; undefined (or a rejection) when the project has no store connected.
4688
+ */
4689
+ start: () => Promise<WooCommerceStart | undefined>;
4690
+ /**
4691
+ Defaults to the global `fetch`.
4692
+ */
4693
+ fetch?: (input: string, init: RequestInit) => Promise<Response>;
4694
+ /**
4695
+ Where the token is kept: `createPageStorage()`, shared by every cart client of the page.
4696
+ */
4697
+ storage: CartStorage;
4698
+ /**
4699
+ The lock the tabs start the cart under: `navigator.locks`, or `leaseLock(storage)` where there are none.
4700
+ */
4701
+ lock: CartLock;
4702
+ /**
4703
+ Sends the shopper to checkout. Defaults to `location.assign`.
4704
+ */
4705
+ navigate?: (url: string) => void;
4706
+ };
4707
+ type WooCommerceCartClient = {
4708
+ /**
4709
+ The cart as the store has it now; `data: undefined` when there is none yet, and the store is not asked then.
4710
+ */
4711
+ getCart: () => Promise<WooCommerceCartResult>;
4712
+ /**
4713
+ Adds `quantity` (default 1) of a product or a variation, by its WooCommerce id; starts the cart on the first add.
4714
+ */
4715
+ addItem: (productId: string | number, quantity?: number) => Promise<WooCommerceCartResult>;
4716
+ /**
4717
+ Removes a line (`WooCommerceCartItem.key`).
4718
+ */
4719
+ removeItem: (key: string) => Promise<WooCommerceCartResult>;
4720
+ /**
4721
+ Sets a line's quantity; 0 removes it.
4722
+ */
4723
+ updateQuantity: (key: string, quantity: number) => Promise<WooCommerceCartResult>;
4724
+ /**
4725
+ Sends the shopper to the store's checkout with the cart's lines, and resolves its URL. The cart moves to the
4726
+ store: the bag here is empty after, whether or not the shopper buys. An empty cart goes nowhere (`no_cart`).
4727
+ */
4728
+ checkout: () => Promise<WooCommerceCartResult<string>>;
4729
+ };
4730
+ /**
4731
+ The WooCommerce cart in the shopper's browser, on the Store API of the store `start` names. Every method resolves
4732
+ a {@link WooCommerceCartResult} and never rejects.
4733
+ @example
4734
+ ```ts
4735
+ const storage = createPageStorage();
4736
+ const cart = createWooCommerceCart({start: async () => startFromCore(), storage, lock: leaseLock(storage)});
4737
+ const {data, error} = await cart.addItem(201, 1);
4738
+ ```
4739
+ */
4740
+ declare function createWooCommerceCart(options: WooCommerceCartClientOptions): WooCommerceCartClient;
4741
+
4486
4742
  /**
4487
4743
  Logger utility for Thamyr SDK
4488
4744
  Provides configurable logging that can be enabled/disabled to avoid console spam
@@ -4573,5 +4829,5 @@ declare function transformImageUrl(cdnUrl: string, edits: ImageEdits): string;
4573
4829
  */
4574
4830
  declare function randomUuid(): string;
4575
4831
 
4576
- export { ACTION_TYPES, ADD_TO_CART_RESULT_BLOCK, CallimacusApi, CallimacusEvent, CallimacusService, ChapterStatus, ClientEvents, DELIVER_RESULT_BLOCK, GalleryMode, LANDING_VALUE_MAX_LENGTH, MAX_HANDSHAKE_RETRIES, SLInputEventType, STOREFRONT_API_VERSION, ServerEvents, ThamyrHttpError, ThamyrResponseType, UserInteractionType, actionOf, addToCartResultOf, applyBlockPatch, blockKeyOf, callimacusService, cartSettingsFor, classifyConnectError, createContractClient, createPageStorage, createShopifyCart, deliverResultOf, extractTtsAudio, fieldsOf, interactionRound, isCustomBlock, isMasterProduct, isSetProduct, isVariantGid, landingRound, logger, mergeShopifySettings, parseConnectRejection, parseMapPath, randomUuid, readShopifySettings, receptorsOf, resolveMapPage, shouldRetryHandshake, transformImageUrl };
4577
- export type { Action, ActionType, AddToCartResult, BCProduct, Basket, Block, BlockPatch, BoundingBox, CallimacusErrorMessage, CartCommand, CartLock, CartStorage, Chapter, ClientInfo, ConnectRejection, ConnectionStatusCallback, ContractClient, CustomBlock, DeliverResult, DocumentIndexEntry, ErrorCallback, ErrorMessage, Gallery, GenericProduct, HomePage, Image, ImageEdits, ImageFormatEdit, ImageResizeEdit, InteractionContext, InteractionId, InteractionOptions, InteractionPayload, InteractionPayloadMap, LegacyBlock, LocalizedEPArtwork, LocalizedEPChapter, LogLevel, LoggerConfig, MapPage, MapPath, MasterProduct, MasterProductWithVariationGroup, OptionItem, ProductItem, ProductMatch, RecommendationsResponse, RiveManifest, RoundOptions, SLDocument, SLDocumentSection, SLInputEvent, ServerResponseCallback, SetProduct, ShopifyCart, ShopifyCartClient, ShopifyCartClientOptions, ShopifyCartError, ShopifyCartErrorCode, ShopifyCartLine, ShopifyCartResult, ShopifyCartSettings, ShopifyCartWarning, ShopifyConfig, ShopifyMoney, ShopifySettings, ShopifyStorefront, ShopifyUserError, SkesisItem, SkesisItemPage, SkesisRelatedResponse, SkesisSimilarResponse, Story, SuggestPayload, Suggestions, ThamyrInteractionMap, ThamyrResponse, Topic, TopicContentsPage, TopicSummary, TtsAudio, UiElement, UiObserverConfig, UiSnapshot, UserInteraction, Variant, VariationAttribute, VariationGroup, Video, WhisperPayload };
4832
+ export { ACTION_TYPES, ADD_TO_CART_RESULT_BLOCK, CallimacusApi, CallimacusEvent, CallimacusService, ChapterStatus, ClientEvents, DELIVER_RESULT_BLOCK, GalleryMode, LANDING_VALUE_MAX_LENGTH, MAX_HANDSHAKE_RETRIES, SLInputEventType, STOREFRONT_API_VERSION, ServerEvents, ThamyrHttpError, ThamyrResponseType, UserInteractionType, actionOf, addToCartResultOf, applyBlockPatch, blockKeyOf, callimacusService, cartSettingsFor, classifyConnectError, createContractClient, createPageStorage, createShopifyCart, createWooCommerceCart, deliverResultOf, extractTtsAudio, fieldsOf, interactionRound, isCustomBlock, isMasterProduct, isSetProduct, isVariantGid, landingRound, leaseLock, logger, mergeShopifySettings, parseConnectRejection, parseMapPath, randomUuid, readShopifySettings, receptorsOf, resolveMapPage, shouldRetryHandshake, transformImageUrl, webLocks };
4833
+ export type { Action, ActionType, AddToCartResult, BCProduct, Basket, Block, BlockPatch, BoundingBox, CallimacusErrorMessage, CartCommand, CartLock, CartStorage, Chapter, ClientInfo, ConnectRejection, ConnectionStatusCallback, ContractClient, CustomBlock, DeliverResult, DocumentIndexEntry, ErrorCallback, ErrorMessage, Gallery, GenericProduct, HomePage, Image, ImageEdits, ImageFormatEdit, ImageResizeEdit, InteractionContext, InteractionId, InteractionOptions, InteractionPayload, InteractionPayloadMap, LegacyBlock, LocalizedEPArtwork, LocalizedEPChapter, LogLevel, LoggerConfig, MapPage, MapPath, MasterProduct, MasterProductWithVariationGroup, OptionItem, ProductItem, ProductMatch, RecommendationsResponse, RiveManifest, RoundOptions, SLDocument, SLDocumentSection, SLInputEvent, ServerResponseCallback, SetProduct, ShopifyCart, ShopifyCartClient, ShopifyCartClientOptions, ShopifyCartError, ShopifyCartErrorCode, ShopifyCartLine, ShopifyCartResult, ShopifyCartSettings, ShopifyCartWarning, ShopifyConfig, ShopifyMoney, ShopifySettings, ShopifyStorefront, ShopifyUserError, SkesisItem, SkesisItemPage, SkesisRelatedResponse, SkesisSimilarResponse, Story, SuggestPayload, Suggestions, ThamyrInteractionMap, ThamyrResponse, Topic, TopicContentsPage, TopicSummary, TtsAudio, UiElement, UiObserverConfig, UiSnapshot, UserInteraction, Variant, VariationAttribute, VariationGroup, Video, WhisperPayload, WooCommerceCart, WooCommerceCartClient, WooCommerceCartClientOptions, WooCommerceCartError, WooCommerceCartErrorCode, WooCommerceCartItem, WooCommerceCartResult, WooCommerceMoney, WooCommerceStart };