@misiki/gocommerce-connector 0.28.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AddOn, a as Address, b as AddressService, c as AppliedDiscount, d as Approval, e as AuthResponse, f as AuthService, g as AutocompleteService, B as B2bPlaced, h as B2bRole, i as B2bService, j as BannerService, k as BaseService, l as BlogService, C as Cart, m as CartLine, n as CartOffer, o as CartService, p as CatalogService, q as Category, r as CategoryService, s as ChatService, t as CheckoutOptions, u as CheckoutResult, v as CheckoutService, w as CmsPage, x as Collection, y as CollectionService, z as Company, D as CompanyOrder, E as ContactService, F as CountryService, G as CouponService, H as Credentials, I as Credit, J as CurrencyService, K as Customer, L as CustomizerDesign, M as CustomizerDocument, N as CustomizerEditor, O as CustomizerFile, P as CustomizerLayer, Q as CustomizerSavedDesign, R as CustomizerService, S as CustomizerSetup, T as CustomizerUpload, U as DealService, V as DemoRequestService, W as EngineRequest, X as EnquiryService, Y as Envelope, Z as FacetValue, _ as Faq, $ as FaqService, a0 as FeedbackService, a1 as FooterSettings, a2 as FreeShipping, a3 as Fulfillment, a4 as GalleryService, a5 as GooglePlace, a6 as GoogleReview, a7 as GoogleReviewService, a8 as GoogleReviews, a9 as GoogleSurvey, aa as HeaderSettings, ab as HomeLayout, ac as HomeLayoutSection, ad as HomeService, ae as IdentityAddress, af as InitService, ag as Invitation, ah as LayoutCollection, ai as LayoutPage, aj as LayoutService, ak as Lead, al as ListMeta, am as MeilisearchService, an as Member, ao as Menu, ap as MenuItem, aq as MenuService, ar as MenuSummary, as as Money, at as NewsletterService, au as Offer, av as OpeningHours, aw as Order, ax as OrderLine, ay as OrderService, az as PageLayout, aA as PageService, aB as PaymentIntent, aC as PaymentMethodService, aD as Plugin, aE as PluginService, aE as PluginsService, aF as PopularSearchService, aG as PopularityService, aH as Postcode, aI as Product, aJ as ProductFacets, aK as ProductOption, aL as ProductService, aM as ProfileService, aN as Quote, aO as REDIRECT_GATEWAYS, aP as ReelsService, aQ as RegionService, aR as RejectedLine, aS as Review, aT as ReviewPage, aU as ReviewService, aV as SearchDoc, aW as SearchResult, aX as SearchService, aY as SettingService, aY as SettingsService, aZ as ShippingRate, a_ as SiteChrome, a$ as SiteFooter, b0 as SiteHeader, b1 as SocialLink, b2 as StateService, b3 as StoreProfile, b4 as StoreService, b5 as StorefrontCategory, b6 as StorefrontMenu, b7 as StorefrontOrder, b8 as StorefrontProduct, b9 as ThemeSettings, ba as ThemeSettingsResult, bb as UploadService, bc as UserService, bd as Variant, be as VariantImage, bf as VariantService, bg as VarniCustomDesignService, bh as VarniCustomProductService, bi as Vendor, bj as VendorService, bk as WarrantyService, bl as WhatsappConsent, bm as WhatsappConsentOffer, bn as WhatsappService, bo as Wishlist, bp as WishlistItem, bq as WishlistService, br as addressService, bs as authService, bt as autocompleteService, bu as b2bService, bv as bannerService, bw as blogService, bx as cartService, by as categoryService, bz as chatService, bA as checkoutService, bB as collectionService, bC as contactService, bD as countryService, bE as couponService, bF as currencyExponent, bG as currencyService, bH as customizerService, bI as dealService, bJ as demoRequestService, bK as emptyCart, bL as emptyPage, bM as enquiryService, bN as faqService, bO as feedbackService, bP as fromEngineAddress, bQ as fromIdentityAddress, bR as fromSearchDoc, bS as galleryService, bT as googleReviewService, bU as homeService, bV as initService, bW as layoutService, bX as mediaUrl, bY as meilisearchService, bZ as menuService, b_ as minorToMajor, b$ as newsletterService, c0 as orderService, c1 as ownDomain, c2 as pageService, c3 as paymentMethodService, c4 as pluginService, c5 as pluginsService, c6 as popularSearchService, c7 as popularityService, c8 as priceOf, c9 as productImages, ca as productService, cb as productVideos, cc as profileService, cd as qs, ce as reelsService, cf as regionService, cg as reviewService, ch as searchService, ci as setRequestHost, cj as settingService, ck as settingsService, cl as stateService, cm as staticStore, cn as storeForHost, co as storeService, cp as toAddOn, cq as toCart, cr as toCartLine, cs as toCartOffer, ct as toCategory, cu as toCmsPage, cv as toCollection, cw as toEngineAddress, cx as toFreeShipping, cy as toIdentityAddress, cz as toMajor, cA as toMinor, cB as toOrder, cC as toPage, cD as toProduct, cE as toRating, cF as toStorefrontFacets, cG as toUser, cH as toVariant, cI as toVendor, cJ as uploadService, cK as userService, cL as variantService, cM as varniCustomDesignService, cN as varniCustomProductService, cO as vendorService, cP as warrantyService, cQ as whatsappService, cR as wishlistService } from './index-BaFtBtaA.cjs';
1
+ export { A as AddOn, a as Address, b as AddressService, c as AppliedDiscount, d as Approval, e as AuthResponse, f as AuthService, g as AutocompleteService, B as B2bPlaced, h as B2bRole, i as B2bService, j as BannerService, k as BaseService, l as BlogService, C as Cart, m as CartLine, n as CartOffer, o as CartService, p as CatalogService, q as Category, r as CategoryService, s as ChatService, t as CheckoutOptions, u as CheckoutQuote, v as CheckoutResult, w as CheckoutService, x as CmsPage, y as Collection, z as CollectionService, D as Company, E as CompanyOrder, F as ContactService, G as CountryService, H as CouponService, I as Credentials, J as Credit, K as CurrencyService, L as Customer, M as CustomizerDesign, N as CustomizerDocument, O as CustomizerEditor, P as CustomizerFile, Q as CustomizerLayer, R as CustomizerSavedDesign, S as CustomizerService, T as CustomizerSetup, U as CustomizerUpload, V as DealService, W as DemoRequestService, X as EngineRequest, Y as EnquiryService, Z as Envelope, _ as FacetValue, $ as Faq, a0 as FaqService, a1 as FeedbackService, a2 as FooterSettings, a3 as FreeShipping, a4 as Fulfillment, a5 as GalleryService, a6 as GooglePlace, a7 as GoogleReview, a8 as GoogleReviewService, a9 as GoogleReviews, aa as GoogleSurvey, ab as HeaderSettings, ac as HomeLayout, ad as HomeLayoutSection, ae as HomeService, af as IdentityAddress, ag as InitService, ah as Invitation, ai as LayoutCollection, aj as LayoutPage, ak as LayoutService, al as Lead, am as ListMeta, an as MeilisearchService, ao as Member, ap as Menu, aq as MenuItem, ar as MenuService, as as MenuSummary, at as Money, au as NewsletterService, av as Offer, aw as OpeningHours, ax as Order, ay as OrderLine, az as OrderService, aA as PageLayout, aB as PageService, aC as PaymentIntent, aD as PaymentMethodService, aE as Plugin, aF as PluginService, aF as PluginsService, aG as PopularSearchService, aH as PopularityService, aI as Postcode, aJ as Product, aK as ProductFacets, aL as ProductOption, aM as ProductService, aN as ProfileService, aO as Quote, aP as REDIRECT_GATEWAYS, aQ as ReelsService, aR as RegionService, aS as RejectedLine, aT as Review, aU as ReviewPage, aV as ReviewService, aW as SearchDoc, aX as SearchResult, aY as SearchService, aZ as SettingService, aZ as SettingsService, a_ as ShippingRate, a$ as SiteChrome, b0 as SiteFooter, b1 as SiteHeader, b2 as SocialLink, b3 as StateService, b4 as StoreClosed, b5 as StorePass, b6 as StorePassAnswer, b7 as StoreProfile, b8 as StoreService, b9 as StoreUnlock, ba as StorefrontCategory, bb as StorefrontMenu, bc as StorefrontOrder, bd as StorefrontProduct, be as ThemeSettings, bf as ThemeSettingsResult, bg as UploadService, bh as UserService, bi as Variant, bj as VariantImage, bk as VariantService, bl as VarniCustomDesignService, bm as VarniCustomProductService, bn as Vendor, bo as VendorService, bp as WarrantyService, bq as WhatsappConsent, br as WhatsappConsentOffer, bs as WhatsappService, bt as Wishlist, bu as WishlistItem, bv as WishlistService, bw as addressService, bx as authService, by as autocompleteService, bz as b2bService, bA as bannerService, bB as blogService, bC as cartService, bD as categoryService, bE as chatService, bF as checkoutService, bG as collectionService, bH as contactService, bI as countryService, bJ as couponService, bK as currencyExponent, bL as currencyService, bM as customizerService, bN as dealService, bO as demoRequestService, bP as emptyCart, bQ as emptyPage, bR as enquiryService, bS as faqService, bT as feedbackService, bU as fromEngineAddress, bV as fromIdentityAddress, bW as fromSearchDoc, bX as galleryService, bY as googleReviewService, bZ as homeService, b_ as initService, b$ as layoutService, c0 as mediaUrl, c1 as meilisearchService, c2 as menuService, c3 as minorToMajor, c4 as newsletterService, c5 as orderService, c6 as ownDomain, c7 as pageService, c8 as paymentMethodService, c9 as pluginService, ca as pluginsService, cb as popularSearchService, cc as popularityService, cd as priceOf, ce as productImages, cf as productService, cg as productVideos, ch as profileService, ci as qs, cj as reelsService, ck as regionService, cl as reviewService, cm as searchService, cn as setRequestHost, co as settingService, cp as settingsService, cq as stateService, cr as staticStore, cs as storeForHost, ct as storeService, cu as toAddOn, cv as toCart, cw as toCartLine, cx as toCartOffer, cy as toCategory, cz as toCheckoutQuote, cA as toCmsPage, cB as toCollection, cC as toEngineAddress, cD as toFreeShipping, cE as toIdentityAddress, cF as toMajor, cG as toMinor, cH as toOrder, cI as toPage, cJ as toProduct, cK as toRating, cL as toStorefrontFacets, cM as toUser, cN as toVariant, cO as toVendor, cP as uploadService, cQ as userService, cR as variantService, cS as varniCustomDesignService, cT as varniCustomProductService, cU as vendorService, cV as warrantyService, cW as whatsappService, cX as wishlistService } from './index-BdXhbm20.cjs';
2
2
 
3
3
  /**
4
4
  * The two ways a call through this connector fails.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AddOn, a as Address, b as AddressService, c as AppliedDiscount, d as Approval, e as AuthResponse, f as AuthService, g as AutocompleteService, B as B2bPlaced, h as B2bRole, i as B2bService, j as BannerService, k as BaseService, l as BlogService, C as Cart, m as CartLine, n as CartOffer, o as CartService, p as CatalogService, q as Category, r as CategoryService, s as ChatService, t as CheckoutOptions, u as CheckoutResult, v as CheckoutService, w as CmsPage, x as Collection, y as CollectionService, z as Company, D as CompanyOrder, E as ContactService, F as CountryService, G as CouponService, H as Credentials, I as Credit, J as CurrencyService, K as Customer, L as CustomizerDesign, M as CustomizerDocument, N as CustomizerEditor, O as CustomizerFile, P as CustomizerLayer, Q as CustomizerSavedDesign, R as CustomizerService, S as CustomizerSetup, T as CustomizerUpload, U as DealService, V as DemoRequestService, W as EngineRequest, X as EnquiryService, Y as Envelope, Z as FacetValue, _ as Faq, $ as FaqService, a0 as FeedbackService, a1 as FooterSettings, a2 as FreeShipping, a3 as Fulfillment, a4 as GalleryService, a5 as GooglePlace, a6 as GoogleReview, a7 as GoogleReviewService, a8 as GoogleReviews, a9 as GoogleSurvey, aa as HeaderSettings, ab as HomeLayout, ac as HomeLayoutSection, ad as HomeService, ae as IdentityAddress, af as InitService, ag as Invitation, ah as LayoutCollection, ai as LayoutPage, aj as LayoutService, ak as Lead, al as ListMeta, am as MeilisearchService, an as Member, ao as Menu, ap as MenuItem, aq as MenuService, ar as MenuSummary, as as Money, at as NewsletterService, au as Offer, av as OpeningHours, aw as Order, ax as OrderLine, ay as OrderService, az as PageLayout, aA as PageService, aB as PaymentIntent, aC as PaymentMethodService, aD as Plugin, aE as PluginService, aE as PluginsService, aF as PopularSearchService, aG as PopularityService, aH as Postcode, aI as Product, aJ as ProductFacets, aK as ProductOption, aL as ProductService, aM as ProfileService, aN as Quote, aO as REDIRECT_GATEWAYS, aP as ReelsService, aQ as RegionService, aR as RejectedLine, aS as Review, aT as ReviewPage, aU as ReviewService, aV as SearchDoc, aW as SearchResult, aX as SearchService, aY as SettingService, aY as SettingsService, aZ as ShippingRate, a_ as SiteChrome, a$ as SiteFooter, b0 as SiteHeader, b1 as SocialLink, b2 as StateService, b3 as StoreProfile, b4 as StoreService, b5 as StorefrontCategory, b6 as StorefrontMenu, b7 as StorefrontOrder, b8 as StorefrontProduct, b9 as ThemeSettings, ba as ThemeSettingsResult, bb as UploadService, bc as UserService, bd as Variant, be as VariantImage, bf as VariantService, bg as VarniCustomDesignService, bh as VarniCustomProductService, bi as Vendor, bj as VendorService, bk as WarrantyService, bl as WhatsappConsent, bm as WhatsappConsentOffer, bn as WhatsappService, bo as Wishlist, bp as WishlistItem, bq as WishlistService, br as addressService, bs as authService, bt as autocompleteService, bu as b2bService, bv as bannerService, bw as blogService, bx as cartService, by as categoryService, bz as chatService, bA as checkoutService, bB as collectionService, bC as contactService, bD as countryService, bE as couponService, bF as currencyExponent, bG as currencyService, bH as customizerService, bI as dealService, bJ as demoRequestService, bK as emptyCart, bL as emptyPage, bM as enquiryService, bN as faqService, bO as feedbackService, bP as fromEngineAddress, bQ as fromIdentityAddress, bR as fromSearchDoc, bS as galleryService, bT as googleReviewService, bU as homeService, bV as initService, bW as layoutService, bX as mediaUrl, bY as meilisearchService, bZ as menuService, b_ as minorToMajor, b$ as newsletterService, c0 as orderService, c1 as ownDomain, c2 as pageService, c3 as paymentMethodService, c4 as pluginService, c5 as pluginsService, c6 as popularSearchService, c7 as popularityService, c8 as priceOf, c9 as productImages, ca as productService, cb as productVideos, cc as profileService, cd as qs, ce as reelsService, cf as regionService, cg as reviewService, ch as searchService, ci as setRequestHost, cj as settingService, ck as settingsService, cl as stateService, cm as staticStore, cn as storeForHost, co as storeService, cp as toAddOn, cq as toCart, cr as toCartLine, cs as toCartOffer, ct as toCategory, cu as toCmsPage, cv as toCollection, cw as toEngineAddress, cx as toFreeShipping, cy as toIdentityAddress, cz as toMajor, cA as toMinor, cB as toOrder, cC as toPage, cD as toProduct, cE as toRating, cF as toStorefrontFacets, cG as toUser, cH as toVariant, cI as toVendor, cJ as uploadService, cK as userService, cL as variantService, cM as varniCustomDesignService, cN as varniCustomProductService, cO as vendorService, cP as warrantyService, cQ as whatsappService, cR as wishlistService } from './index-BaFtBtaA.js';
1
+ export { A as AddOn, a as Address, b as AddressService, c as AppliedDiscount, d as Approval, e as AuthResponse, f as AuthService, g as AutocompleteService, B as B2bPlaced, h as B2bRole, i as B2bService, j as BannerService, k as BaseService, l as BlogService, C as Cart, m as CartLine, n as CartOffer, o as CartService, p as CatalogService, q as Category, r as CategoryService, s as ChatService, t as CheckoutOptions, u as CheckoutQuote, v as CheckoutResult, w as CheckoutService, x as CmsPage, y as Collection, z as CollectionService, D as Company, E as CompanyOrder, F as ContactService, G as CountryService, H as CouponService, I as Credentials, J as Credit, K as CurrencyService, L as Customer, M as CustomizerDesign, N as CustomizerDocument, O as CustomizerEditor, P as CustomizerFile, Q as CustomizerLayer, R as CustomizerSavedDesign, S as CustomizerService, T as CustomizerSetup, U as CustomizerUpload, V as DealService, W as DemoRequestService, X as EngineRequest, Y as EnquiryService, Z as Envelope, _ as FacetValue, $ as Faq, a0 as FaqService, a1 as FeedbackService, a2 as FooterSettings, a3 as FreeShipping, a4 as Fulfillment, a5 as GalleryService, a6 as GooglePlace, a7 as GoogleReview, a8 as GoogleReviewService, a9 as GoogleReviews, aa as GoogleSurvey, ab as HeaderSettings, ac as HomeLayout, ad as HomeLayoutSection, ae as HomeService, af as IdentityAddress, ag as InitService, ah as Invitation, ai as LayoutCollection, aj as LayoutPage, ak as LayoutService, al as Lead, am as ListMeta, an as MeilisearchService, ao as Member, ap as Menu, aq as MenuItem, ar as MenuService, as as MenuSummary, at as Money, au as NewsletterService, av as Offer, aw as OpeningHours, ax as Order, ay as OrderLine, az as OrderService, aA as PageLayout, aB as PageService, aC as PaymentIntent, aD as PaymentMethodService, aE as Plugin, aF as PluginService, aF as PluginsService, aG as PopularSearchService, aH as PopularityService, aI as Postcode, aJ as Product, aK as ProductFacets, aL as ProductOption, aM as ProductService, aN as ProfileService, aO as Quote, aP as REDIRECT_GATEWAYS, aQ as ReelsService, aR as RegionService, aS as RejectedLine, aT as Review, aU as ReviewPage, aV as ReviewService, aW as SearchDoc, aX as SearchResult, aY as SearchService, aZ as SettingService, aZ as SettingsService, a_ as ShippingRate, a$ as SiteChrome, b0 as SiteFooter, b1 as SiteHeader, b2 as SocialLink, b3 as StateService, b4 as StoreClosed, b5 as StorePass, b6 as StorePassAnswer, b7 as StoreProfile, b8 as StoreService, b9 as StoreUnlock, ba as StorefrontCategory, bb as StorefrontMenu, bc as StorefrontOrder, bd as StorefrontProduct, be as ThemeSettings, bf as ThemeSettingsResult, bg as UploadService, bh as UserService, bi as Variant, bj as VariantImage, bk as VariantService, bl as VarniCustomDesignService, bm as VarniCustomProductService, bn as Vendor, bo as VendorService, bp as WarrantyService, bq as WhatsappConsent, br as WhatsappConsentOffer, bs as WhatsappService, bt as Wishlist, bu as WishlistItem, bv as WishlistService, bw as addressService, bx as authService, by as autocompleteService, bz as b2bService, bA as bannerService, bB as blogService, bC as cartService, bD as categoryService, bE as chatService, bF as checkoutService, bG as collectionService, bH as contactService, bI as countryService, bJ as couponService, bK as currencyExponent, bL as currencyService, bM as customizerService, bN as dealService, bO as demoRequestService, bP as emptyCart, bQ as emptyPage, bR as enquiryService, bS as faqService, bT as feedbackService, bU as fromEngineAddress, bV as fromIdentityAddress, bW as fromSearchDoc, bX as galleryService, bY as googleReviewService, bZ as homeService, b_ as initService, b$ as layoutService, c0 as mediaUrl, c1 as meilisearchService, c2 as menuService, c3 as minorToMajor, c4 as newsletterService, c5 as orderService, c6 as ownDomain, c7 as pageService, c8 as paymentMethodService, c9 as pluginService, ca as pluginsService, cb as popularSearchService, cc as popularityService, cd as priceOf, ce as productImages, cf as productService, cg as productVideos, ch as profileService, ci as qs, cj as reelsService, ck as regionService, cl as reviewService, cm as searchService, cn as setRequestHost, co as settingService, cp as settingsService, cq as stateService, cr as staticStore, cs as storeForHost, ct as storeService, cu as toAddOn, cv as toCart, cw as toCartLine, cx as toCartOffer, cy as toCategory, cz as toCheckoutQuote, cA as toCmsPage, cB as toCollection, cC as toEngineAddress, cD as toFreeShipping, cE as toIdentityAddress, cF as toMajor, cG as toMinor, cH as toOrder, cI as toPage, cJ as toProduct, cK as toRating, cL as toStorefrontFacets, cM as toUser, cN as toVariant, cO as toVendor, cP as uploadService, cQ as userService, cR as variantService, cS as varniCustomDesignService, cT as varniCustomProductService, cU as vendorService, cV as warrantyService, cW as whatsappService, cX as wishlistService } from './index-BdXhbm20.js';
2
2
 
3
3
  /**
4
4
  * The two ways a call through this connector fails.
package/dist/index.js CHANGED
@@ -132,8 +132,17 @@ function remember(key, load, ttl = TTL_MS) {
132
132
  });
133
133
  return value;
134
134
  }
135
+ var known = /* @__PURE__ */ new Map();
136
+ function keep(key, value) {
137
+ known.set(key, value);
138
+ return value;
139
+ }
140
+ function recall(key) {
141
+ return known.get(key);
142
+ }
135
143
  function forgetAll() {
136
144
  entries.clear();
145
+ known.clear();
137
146
  }
138
147
 
139
148
  // src/browser.ts
@@ -1118,7 +1127,22 @@ function toCartOffer(o, currency) {
1118
1127
  applies: o.applies,
1119
1128
  amount: o.amount ? toMajor(o.amount) : null,
1120
1129
  remaining: o.remaining ? toMajor(o.remaining) : null,
1121
- reason: o.reason ?? ""
1130
+ reason: o.reason ?? "",
1131
+ autoApply: !!o.auto_apply
1132
+ };
1133
+ }
1134
+ function toCheckoutQuote(q) {
1135
+ const d = q.discount;
1136
+ return {
1137
+ subtotal: toMajor(q.subtotal),
1138
+ shippingCharges: toMajor(q.shipping),
1139
+ shippingMethod: q.shipping_method ?? null,
1140
+ discount: toMajor(d?.amount),
1141
+ coupon: d ? { code: d.code, title: d.title, autoApplied: d.auto_applied, freeShipping: !!d.free_shipping } : null,
1142
+ tax: toMajor(q.tax),
1143
+ taxIncluded: q.tax_inclusive,
1144
+ codCharges: toMajor(q.payment_fee),
1145
+ total: toMajor(q.total)
1122
1146
  };
1123
1147
  }
1124
1148
  function toFreeShipping(f) {
@@ -1591,7 +1615,23 @@ function attributesFrom(p) {
1591
1615
  return Object.keys(out).length ? out : void 0;
1592
1616
  }
1593
1617
  var counts = (values) => Object.fromEntries((values ?? []).map((v) => [v.value, v.count]));
1594
- function toStorefrontFacets(f) {
1618
+ function categoryFacets(counted, tree) {
1619
+ const byId = new Map(tree.map((c) => [c.id, c]));
1620
+ const totals = /* @__PURE__ */ new Map();
1621
+ for (const { id: id2, count } of counted) {
1622
+ for (let c = byId.get(id2); c; c = c.parent_id === null ? void 0 : byId.get(c.parent_id)) {
1623
+ totals.set(c.id, (totals.get(c.id) ?? 0) + count);
1624
+ }
1625
+ }
1626
+ const kept = tree.filter((c) => totals.has(c.id)).sort((a, b) => a.position - b.position || a.id - b.id);
1627
+ const parentOf = (c) => c.parent_id !== null && byId.has(c.parent_id) ? c.parent_id : null;
1628
+ const under = (parent) => kept.filter((c) => parentOf(c) === parent).flatMap((c) => [{ name: c.title, slug: c.slug, count: totals.get(c.id), depth: c.depth }, ...under(c.id)]);
1629
+ return [
1630
+ ...under(null),
1631
+ ...counted.filter((c) => !byId.has(c.id)).map((c) => ({ name: c.title, slug: c.slug, count: c.count, depth: 0 }))
1632
+ ];
1633
+ }
1634
+ function toStorefrontFacets(f, tree = []) {
1595
1635
  if (!f) return { priceStat: {}, categories: [], tags: [], allFilters: {} };
1596
1636
  const allFilters = {};
1597
1637
  const group = (key, values) => {
@@ -1602,7 +1642,7 @@ function toStorefrontFacets(f) {
1602
1642
  for (const [handle, values] of Object.entries(f.attributes ?? {})) group(`attributes.${handle}`, values);
1603
1643
  return {
1604
1644
  priceStat: f.price ? { min: toMajor(f.price.min), max: toMajor(f.price.max) } : {},
1605
- categories: (f.categories ?? []).map((c) => ({ name: c.title, slug: c.slug, count: c.count })),
1645
+ categories: categoryFacets(f.categories ?? [], tree),
1606
1646
  tags: (f.tags ?? []).map((t) => ({ name: t.value, count: t.count })),
1607
1647
  allFilters
1608
1648
  };
@@ -1635,13 +1675,14 @@ var SearchService = class extends CatalogService {
1635
1675
  productTypes: listParam(p, "product_type"),
1636
1676
  facets: true
1637
1677
  });
1678
+ const tree = res.facets?.categories?.length ? await this.facts.categories().catch(() => []) : [];
1638
1679
  return {
1639
1680
  data: res.data,
1640
1681
  count: res.count,
1641
1682
  totalPages: res.noOfPage,
1642
1683
  page: res.page,
1643
1684
  categoryHierarchy: res.categoryHierarchy,
1644
- facets: toStorefrontFacets(res.facets)
1685
+ facets: toStorefrontFacets(res.facets, tree)
1645
1686
  };
1646
1687
  } catch (err) {
1647
1688
  if (err?.status === 404) return this.emptyResult();
@@ -2109,6 +2150,7 @@ var customizerService = new CustomizerService();
2109
2150
 
2110
2151
  // src/services/checkout-service.ts
2111
2152
  var CheckoutService = class extends BaseService {
2153
+ expected = /* @__PURE__ */ new Map();
2112
2154
  /** Delivery options for the address on the cart: `{ data: [{ id, name, base_rate }] }`. */
2113
2155
  async getShippingRates({ cartId } = {}) {
2114
2156
  const id2 = cartId || storedCartId();
@@ -2280,6 +2322,64 @@ var CheckoutService = class extends BaseService {
2280
2322
  );
2281
2323
  return { methods: options.methods ?? [], currency: options.currency };
2282
2324
  }
2325
+ /**
2326
+ * What checkout would charge for the cart now, by the storefront's method
2327
+ * code (`COD`, `RAZORPAY`, `PAYPAL`) or none yet (D185). Null until the
2328
+ * address step has stored an address, and null from an engine before D185.
2329
+ *
2330
+ * A refusal is checkout's own: the same GoCommerceError, with the same
2331
+ * message, that placing the order would raise now.
2332
+ */
2333
+ async getQuote({ cartId, method = "" } = {}) {
2334
+ const id2 = cartId || storedCartId();
2335
+ if (!id2 || !cartExtras(id2).shippingAddress) return null;
2336
+ const { extras, email, address } = await this.storedCheckout(id2);
2337
+ const code = method.toLowerCase() === "paypal" ? await this.redirectGateway() : method.toLowerCase();
2338
+ try {
2339
+ const quote2 = await this.data("/api/checkout/quote", {
2340
+ query: {
2341
+ cart: id2,
2342
+ country: address.country,
2343
+ state: address.state,
2344
+ shipping_rate_id: extras.shippingRateId || void 0,
2345
+ method: code || void 0,
2346
+ email: email || void 0
2347
+ }
2348
+ });
2349
+ return toCheckoutQuote(quote2);
2350
+ } catch (err) {
2351
+ if (err instanceof GoCommerceError && (err.status === 405 || err.status === 404 && err.message.startsWith("no route for "))) {
2352
+ return null;
2353
+ }
2354
+ throw err;
2355
+ }
2356
+ }
2357
+ /**
2358
+ * The total on screen as the shopper confirms, from getQuote, or null when nothing was quoted
2359
+ * (D185). Every order placed for the cart then carries it, and checkout refuses one whose own
2360
+ * total differs instead of charging it: `onChange` gets checkout's figures now and the sentence
2361
+ * the placing call fails with.
2362
+ */
2363
+ expectTotal({
2364
+ cartId,
2365
+ total,
2366
+ onChange
2367
+ }) {
2368
+ const id2 = cartId || storedCartId();
2369
+ if (!id2) return;
2370
+ if (typeof total === "number") this.expected.set(id2, { total, onChange });
2371
+ else this.expected.delete(id2);
2372
+ }
2373
+ async storedCheckout(cartId) {
2374
+ const id2 = cartId || storedCartId();
2375
+ if (!id2) throw new GoCommerceError("Your bag is empty.", 400);
2376
+ const extras = cartExtras(id2);
2377
+ const ship = extras.shippingAddress;
2378
+ if (!ship) throw new GoCommerceError("Add a delivery address first.", 400);
2379
+ const cart = await this.data(`/api/carts/${encodeURIComponent(id2)}`);
2380
+ const email = cart.email || (ship.email ? String(ship.email) : "");
2381
+ return { id: id2, extras, email, address: toEngineAddress(ship), currency: cart.currency };
2382
+ }
2283
2383
  async redirectGateway() {
2284
2384
  const { methods } = await this.listMethods();
2285
2385
  return methods.find((m) => REDIRECT_GATEWAYS.has(m.code))?.code;
@@ -2295,15 +2395,8 @@ var CheckoutService = class extends BaseService {
2295
2395
  * the engine refuses a key replayed with a different body.
2296
2396
  */
2297
2397
  async place(code, cartId, extra = {}) {
2298
- const id2 = cartId || storedCartId();
2299
- if (!id2) throw new GoCommerceError("Your bag is empty.", 400);
2300
- const extras = cartExtras(id2);
2301
- const ship = extras.shippingAddress;
2302
- if (!ship) throw new GoCommerceError("Add a delivery address first.", 400);
2303
- const cart = await this.data(`/api/carts/${encodeURIComponent(id2)}`);
2304
- const email = cart.email || (ship.email ? String(ship.email) : "");
2398
+ const { id: id2, extras, email, address, currency } = await this.storedCheckout(cartId);
2305
2399
  if (!email) throw new GoCommerceError("Add an email address so we can send your receipt.", 400);
2306
- const address = toEngineAddress(ship);
2307
2400
  const body = {
2308
2401
  cart_id: id2,
2309
2402
  email,
@@ -2326,10 +2419,23 @@ var CheckoutService = class extends BaseService {
2326
2419
  ...meta ? { meta_capi: meta } : {},
2327
2420
  ...attribution ? { attribution } : {}
2328
2421
  };
2422
+ const expected = this.expected.get(id2);
2329
2423
  const result = await this.data(`/api/checkout/${encodeURIComponent(code)}`, {
2330
2424
  method: "POST",
2331
- body: Object.keys(metadata).length ? { ...body, metadata } : body,
2425
+ body: {
2426
+ ...Object.keys(metadata).length ? { ...body, metadata } : body,
2427
+ ...expected ? { quoted_total_minor: toMinor(expected.total, currency) } : {}
2428
+ },
2332
2429
  headers: { "Idempotency-Key": key }
2430
+ }).catch((err) => {
2431
+ if (keyAlreadyUsed(err)) {
2432
+ throw new GoCommerceError("This order was already placed in another tab. Check that tab for its confirmation.", 400, err.code);
2433
+ }
2434
+ const now = movedTotal(err);
2435
+ if (!expected || !now) throw err;
2436
+ const message = `Your total changed to ${shopperAmount(now.total, currency)}. Check the new total and confirm again.`;
2437
+ expected.onChange?.(now, message);
2438
+ throw new GoCommerceError(message, 409, "total_changed", now);
2333
2439
  });
2334
2440
  if (result.order.access_token) {
2335
2441
  rememberOrder({
@@ -2352,6 +2458,21 @@ var CheckoutService = class extends BaseService {
2352
2458
  };
2353
2459
  var REDIRECT_GATEWAYS = /* @__PURE__ */ new Set(["adyen", "paddle", "lemonsqueezy", "creem", "hyperswitch", "revenuecat"]);
2354
2460
  var unsupported = (method, why) => new NotSupportedError("CheckoutService", method, why);
2461
+ function keyAlreadyUsed(err) {
2462
+ return err instanceof GoCommerceError && err.status === 400 && err.message.includes("Idempotency-Key was already used");
2463
+ }
2464
+ function movedTotal(err) {
2465
+ if (!(err instanceof GoCommerceError) || err.code !== "total_changed") return null;
2466
+ const now = err.details;
2467
+ return now?.total ? toCheckoutQuote(now) : null;
2468
+ }
2469
+ function shopperAmount(amount, currency) {
2470
+ return new Intl.NumberFormat(currency === "INR" ? "en-IN" : "en", {
2471
+ style: "currency",
2472
+ currency,
2473
+ ...Number.isInteger(amount) ? { minimumFractionDigits: 0 } : {}
2474
+ }).format(amount);
2475
+ }
2355
2476
  function newKey() {
2356
2477
  const c = globalThis.crypto;
2357
2478
  if (c?.randomUUID) return c.randomUUID();
@@ -2413,7 +2534,8 @@ var CouponService = class extends BaseService {
2413
2534
  minAmount: o.minAmount,
2414
2535
  description: o.applies ? o.title : o.remaining !== null ? `${o.title}. Add ${o.remaining} more to use this.` : o.reason || o.title,
2415
2536
  applies: o.applies,
2416
- remaining: o.remaining
2537
+ remaining: o.remaining,
2538
+ autoApply: o.autoApply
2417
2539
  }));
2418
2540
  return { data, count: data.length, pageSize: data.length, noOfPage: 1, page: 1 };
2419
2541
  }
@@ -3166,15 +3288,18 @@ var StoreService = class extends BaseService {
3166
3288
  async getStoreByIdOrDomain(_args = {}) {
3167
3289
  const base = await readStaticStore();
3168
3290
  const store = this.store;
3169
- if (store) {
3170
- await this.facts.plugins().catch((err) => {
3171
- if (isStoreMissing(err)) {
3291
+ const [plugins, live] = await Promise.all([
3292
+ this.facts.plugins().catch((err) => {
3293
+ if (store && isStoreMissing(err)) {
3172
3294
  throw new GoCommerceError(`store not found: no store "${store}" on this engine`, 404, "store_not_found");
3173
3295
  }
3174
- });
3175
- }
3176
- const live = await this.live().catch(() => ({}));
3177
- return { ...base, ...live, id: base.id || "gocommerce" };
3296
+ return void 0;
3297
+ }),
3298
+ this.live().catch(() => ({}))
3299
+ ]);
3300
+ const known2 = `${this.creds.apiUrl ?? ""}|${store ?? ""}|closed`;
3301
+ const closed = plugins ? keep(known2, closedOf(plugins)) : recall(known2);
3302
+ return { ...base, ...live, closed, id: base.id || "gocommerce" };
3178
3303
  }
3179
3304
  async getStore(storeId) {
3180
3305
  return this.getStoreByIdOrDomain({ storeId });
@@ -3209,6 +3334,46 @@ var StoreService = class extends BaseService {
3209
3334
  }
3210
3335
  return super.post(path, data);
3211
3336
  }
3337
+ /**
3338
+ * A closed store's password (D170), traded for a pass. Never throws. The
3339
+ * engine allows 20 tries an hour per client, and sees this server as the
3340
+ * client unless `clientAddress`, the shopper's, travels as `X-Forwarded-For`.
3341
+ */
3342
+ async unlockStore(password, { clientAddress } = {}) {
3343
+ const typed = password.trim();
3344
+ if (!typed) return { outcome: "wrong" };
3345
+ try {
3346
+ return { outcome: "unlocked", pass: await this.storePass({ password: typed }, clientAddress) };
3347
+ } catch (err) {
3348
+ return { outcome: err instanceof GoCommerceError && UNLOCK_REFUSED[err.status] || "unavailable" };
3349
+ }
3350
+ }
3351
+ /**
3352
+ * A pass checked without spending a try: the pass, or null when it is wrong,
3353
+ * expired, ended by a new password, or the store takes none now. Throws when
3354
+ * the engine cannot say.
3355
+ */
3356
+ async checkStorePass(token) {
3357
+ if (!token) return null;
3358
+ try {
3359
+ return await this.storePass({ token });
3360
+ } catch (err) {
3361
+ if (err instanceof GoCommerceError && (err.status === 422 || err.status === 404)) return null;
3362
+ throw err;
3363
+ }
3364
+ }
3365
+ async storePass(body, clientAddress) {
3366
+ const answer = await this.data("/api/store/password", {
3367
+ method: "POST",
3368
+ body,
3369
+ headers: clientAddress && ONE_IP_ADDRESS.test(clientAddress) ? { "X-Forwarded-For": clientAddress } : void 0
3370
+ });
3371
+ const expiresAt = new Date(answer?.expires_at ?? NaN);
3372
+ if (!answer?.token || Number.isNaN(expiresAt.getTime())) {
3373
+ throw new GoCommerceError("The commerce engine answered a store pass without its token or expiry.", 502);
3374
+ }
3375
+ return { token: answer.token, expiresAt };
3376
+ }
3212
3377
  async live() {
3213
3378
  const [ready, plugins, menus, base, profile, ships] = await Promise.all([
3214
3379
  this.facts.ready(),
@@ -3326,6 +3491,17 @@ var StoreService = class extends BaseService {
3326
3491
  }
3327
3492
  };
3328
3493
  var storeService = new StoreService();
3494
+ var ONE_IP_ADDRESS = /^[\da-f.:]{2,45}$/i;
3495
+ var UNLOCK_REFUSED = {
3496
+ 422: "wrong",
3497
+ 429: "throttled",
3498
+ 404: "open"
3499
+ };
3500
+ function closedOf(plugins) {
3501
+ const plugin = plugins?.get("store-close");
3502
+ if (!plugin) return void 0;
3503
+ return { message: String(plugin.settings?.message ?? ""), password: plugin.settings?.password === true };
3504
+ }
3329
3505
  var AD_TAGS = [
3330
3506
  ["meta-pixel", "pixel_id", "facebookPixel"],
3331
3507
  ["microsoft-clarity", "project_id", "microsoftClarity"],
@@ -3354,10 +3530,10 @@ function googleTags(plugins) {
3354
3530
  }
3355
3531
  function deliverable(base, ships) {
3356
3532
  if (ships.everywhere || !ships.countries.length) return {};
3357
- const known = new Map((base.countries ?? []).map((c) => [String(c.code).toUpperCase(), c]));
3358
- const countries = ships.countries.map((code) => known.get(code) ?? { code, name: regionName(code) });
3359
- const keep = base.country && ships.countries.includes(String(base.country.code).toUpperCase());
3360
- return { countries, ...keep ? {} : { country: countries[0] } };
3533
+ const known2 = new Map((base.countries ?? []).map((c) => [String(c.code).toUpperCase(), c]));
3534
+ const countries = ships.countries.map((code) => known2.get(code) ?? { code, name: regionName(code) });
3535
+ const keep2 = base.country && ships.countries.includes(String(base.country.code).toUpperCase());
3536
+ return { countries, ...keep2 ? {} : { country: countries[0] } };
3361
3537
  }
3362
3538
  function regionName(code) {
3363
3539
  try {
@@ -3512,7 +3688,8 @@ function toSection(s) {
3512
3688
  title: c.title,
3513
3689
  slug: c.slug,
3514
3690
  link: `/collections/${c.slug}`,
3515
- image: mediaUrl(c.image) ?? null
3691
+ image: mediaUrl(c.image) ?? null,
3692
+ description: c.description || null
3516
3693
  }));
3517
3694
  }
3518
3695
  return out;
@@ -4098,6 +4275,6 @@ function attemptKey(request) {
4098
4275
  }
4099
4276
  var b2bService = new B2bService();
4100
4277
 
4101
- export { AddressService, AuthService, AutocompleteService, B2bService, BannerService, BaseService, BlogService, CartService, CatalogService, CategoryService, ChatService, CheckoutService, CollectionService, ContactService, CountryService, CouponService, CurrencyService, CustomizerService, DealService, DemoRequestService, EnquiryService, FaqService, FeedbackService, GalleryService, GoCommerceError, GoogleReviewService, HomeService, InitService, LayoutService, MeilisearchService, MenuService, NewsletterService, NotSupportedError, OrderService, PageService, PaymentMethodService, PluginService, PluginService as PluginsService, PopularSearchService, PopularityService, ProductService, ProfileService, REDIRECT_GATEWAYS, ReelsService, RegionService, ReviewService, SearchService, SettingService, SettingService as SettingsService, StateService, StoreService, UploadService, UserService, VariantService, VarniCustomDesignService, VarniCustomProductService, VendorService, WarrantyService, WhatsappService, WishlistService, addressService, authService, autocompleteService, b2bService, bannerService, blogService, cartService, categoryService, chatService, checkoutService, forgetAll as clearStoreCache, collectionService, connectorName, contactService, countryService, couponService, currencyExponent, currencyService, customizerService, dealService, demoRequestService, emptyCart, emptyPage, enquiryService, faqService, feedbackService, fromEngineAddress, fromIdentityAddress, fromSearchDoc, galleryService, googleReviewService, hasStaticStore, homeService, initService, layoutService, mediaUrl, meilisearchService, menuService, minorToMajor, newsletterService, orderService, ownDomain, pageService, paymentMethodService, pluginService, pluginsService, popularSearchService, popularityService, priceOf, productImages, productService, productVideos, profileService, qs, readStaticStore, reelsService, regionService, reviewService, searchService, serveRestLocally, setRequestHost, setStaticStore, settingService, settingsService, stateService, staticStore, storeForHost, storeService, toAddOn, toCart, toCartLine, toCartOffer, toCategory, toCmsPage, toCollection, toEngineAddress, toFreeShipping, toIdentityAddress, toMajor, toMinor, toOrder, toPage, toProduct, toRating, toStorefrontFacets, toUser, toVariant, toVendor, uploadService, userService, variantService, varniCustomDesignService, varniCustomProductService, vendorService, warrantyService, whatsappService, wishlistService };
4278
+ export { AddressService, AuthService, AutocompleteService, B2bService, BannerService, BaseService, BlogService, CartService, CatalogService, CategoryService, ChatService, CheckoutService, CollectionService, ContactService, CountryService, CouponService, CurrencyService, CustomizerService, DealService, DemoRequestService, EnquiryService, FaqService, FeedbackService, GalleryService, GoCommerceError, GoogleReviewService, HomeService, InitService, LayoutService, MeilisearchService, MenuService, NewsletterService, NotSupportedError, OrderService, PageService, PaymentMethodService, PluginService, PluginService as PluginsService, PopularSearchService, PopularityService, ProductService, ProfileService, REDIRECT_GATEWAYS, ReelsService, RegionService, ReviewService, SearchService, SettingService, SettingService as SettingsService, StateService, StoreService, UploadService, UserService, VariantService, VarniCustomDesignService, VarniCustomProductService, VendorService, WarrantyService, WhatsappService, WishlistService, addressService, authService, autocompleteService, b2bService, bannerService, blogService, cartService, categoryService, chatService, checkoutService, forgetAll as clearStoreCache, collectionService, connectorName, contactService, countryService, couponService, currencyExponent, currencyService, customizerService, dealService, demoRequestService, emptyCart, emptyPage, enquiryService, faqService, feedbackService, fromEngineAddress, fromIdentityAddress, fromSearchDoc, galleryService, googleReviewService, hasStaticStore, homeService, initService, layoutService, mediaUrl, meilisearchService, menuService, minorToMajor, newsletterService, orderService, ownDomain, pageService, paymentMethodService, pluginService, pluginsService, popularSearchService, popularityService, priceOf, productImages, productService, productVideos, profileService, qs, readStaticStore, reelsService, regionService, reviewService, searchService, serveRestLocally, setRequestHost, setStaticStore, settingService, settingsService, stateService, staticStore, storeForHost, storeService, toAddOn, toCart, toCartLine, toCartOffer, toCategory, toCheckoutQuote, toCmsPage, toCollection, toEngineAddress, toFreeShipping, toIdentityAddress, toMajor, toMinor, toOrder, toPage, toProduct, toRating, toStorefrontFacets, toUser, toVariant, toVendor, uploadService, userService, variantService, varniCustomDesignService, varniCustomProductService, vendorService, warrantyService, whatsappService, wishlistService };
4102
4279
  //# sourceMappingURL=index.js.map
4103
4280
  //# sourceMappingURL=index.js.map