@misiki/gocommerce-connector 0.11.0 → 0.12.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 Address, a as AddressService, b as AppliedDiscount, c as Approval, d as AuthResponse, e as AuthService, f as AutocompleteService, B as B2bPlaced, g as B2bRole, h as B2bService, i as BannerService, j as BaseService, k as BlogService, C as Cart, l as CartLine, m as CartService, n as CatalogService, o as Category, p as CategoryService, q as ChatService, r as CheckoutOptions, s as CheckoutResult, t as CheckoutService, u as CmsPage, v as Collection, w as CollectionService, x as Company, y as CompanyOrder, z as ContactService, D as CountryService, E as CouponService, F as Credentials, G as Credit, H as CurrencyService, I as Customer, J as DealService, K as DemoRequestService, L as EngineRequest, M as EnquiryService, N as Envelope, O as FacetValue, P as Faq, Q as FaqService, R as FeedbackService, S as FooterSettings, T as Fulfillment, U as GalleryService, V as HeaderSettings, W as HomeLayout, X as HomeLayoutSection, Y as HomeService, Z as IdentityAddress, _ as InitService, $ as Invitation, a0 as LayoutCollection, a1 as LayoutPage, a2 as LayoutService, a3 as Lead, a4 as ListMeta, a5 as MeilisearchService, a6 as Member, a7 as Menu, a8 as MenuItem, a9 as MenuService, aa as MenuSummary, ab as Money, ac as NewsletterService, ad as Offer, ae as Order, af as OrderLine, ag as OrderService, ah as PageLayout, ai as PageService, aj as PaymentIntent, ak as PaymentMethodService, al as Plugin, am as PluginService, am as PluginsService, an as PopularSearchService, ao as PopularityService, ap as Product, aq as ProductFacets, ar as ProductOption, as as ProductService, at as ProfileService, au as Quote, av as REDIRECT_GATEWAYS, aw as ReelsService, ax as RegionService, ay as RejectedLine, az as Review, aA as ReviewPage, aB as ReviewService, aC as SearchDoc, aD as SearchResult, aE as SearchService, aF as SettingService, aF as SettingsService, aG as ShippingRate, aH as SiteChrome, aI as SiteFooter, aJ as SiteHeader, aK as SocialLink, aL as StateService, aM as StoreProfile, aN as StoreService, aO as StorefrontCategory, aP as StorefrontMenu, aQ as StorefrontOrder, aR as StorefrontProduct, aS as ThemeSettings, aT as ThemeSettingsResult, aU as UploadService, aV as UserService, aW as Variant, aX as VariantImage, aY as VariantService, aZ as VarniCustomDesignService, a_ as VarniCustomProductService, a$ as Vendor, b0 as VendorService, b1 as WarrantyService, b2 as Wishlist, b3 as WishlistItem, b4 as WishlistService, b5 as addressService, b6 as authService, b7 as autocompleteService, b8 as b2bService, b9 as bannerService, ba as blogService, bb as cartService, bc as categoryService, bd as chatService, be as checkoutService, bf as collectionService, bg as contactService, bh as countryService, bi as couponService, bj as currencyExponent, bk as currencyService, bl as dealService, bm as demoRequestService, bn as emptyCart, bo as emptyPage, bp as enquiryService, bq as faqService, br as feedbackService, bs as fromEngineAddress, bt as fromIdentityAddress, bu as fromSearchDoc, bv as galleryService, bw as homeService, bx as initService, by as layoutService, bz as mediaUrl, bA as meilisearchService, bB as menuService, bC as minorToMajor, bD as newsletterService, bE as orderService, bF as ownDomain, bG as pageService, bH as paymentMethodService, bI as pluginService, bJ as pluginsService, bK as popularSearchService, bL as popularityService, bM as priceOf, bN as productImages, bO as productService, bP as profileService, bQ as qs, bR as reelsService, bS as regionService, bT as reviewService, bU as searchService, bV as setRequestHost, bW as settingService, bX as settingsService, bY as stateService, bZ as staticStore, b_ as storeForHost, b$ as storeService, c0 as toCart, c1 as toCartLine, c2 as toCategory, c3 as toCmsPage, c4 as toCollection, c5 as toEngineAddress, c6 as toIdentityAddress, c7 as toMajor, c8 as toMinor, c9 as toOrder, ca as toPage, cb as toProduct, cc as toRating, cd as toStorefrontFacets, ce as toUser, cf as toVariant, cg as toVendor, ch as uploadService, ci as userService, cj as variantService, ck as varniCustomDesignService, cl as varniCustomProductService, cm as vendorService, cn as warrantyService, co as wishlistService } from './index-90wdO5MM.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 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 DealService, M as DemoRequestService, N as EngineRequest, O as EnquiryService, P as Envelope, Q as FacetValue, R as Faq, S as FaqService, T as FeedbackService, U as FooterSettings, V as FreeShipping, W as Fulfillment, X as GalleryService, Y as HeaderSettings, Z as HomeLayout, _ as HomeLayoutSection, $ as HomeService, a0 as IdentityAddress, a1 as InitService, a2 as Invitation, a3 as LayoutCollection, a4 as LayoutPage, a5 as LayoutService, a6 as Lead, a7 as ListMeta, a8 as MeilisearchService, a9 as Member, aa as Menu, ab as MenuItem, ac as MenuService, ad as MenuSummary, ae as Money, af as NewsletterService, ag as Offer, ah as Order, ai as OrderLine, aj as OrderService, ak as PageLayout, al as PageService, am as PaymentIntent, an as PaymentMethodService, ao as Plugin, ap as PluginService, ap as PluginsService, aq as PopularSearchService, ar as PopularityService, as as Product, at as ProductFacets, au as ProductOption, av as ProductService, aw as ProfileService, ax as Quote, ay as REDIRECT_GATEWAYS, az as ReelsService, aA as RegionService, aB as RejectedLine, aC as Review, aD as ReviewPage, aE as ReviewService, aF as SearchDoc, aG as SearchResult, aH as SearchService, aI as SettingService, aI as SettingsService, aJ as ShippingRate, aK as SiteChrome, aL as SiteFooter, aM as SiteHeader, aN as SocialLink, aO as StateService, aP as StoreProfile, aQ as StoreService, aR as StorefrontCategory, aS as StorefrontMenu, aT as StorefrontOrder, aU as StorefrontProduct, aV as ThemeSettings, aW as ThemeSettingsResult, aX as UploadService, aY as UserService, aZ as Variant, a_ as VariantImage, a$ as VariantService, b0 as VarniCustomDesignService, b1 as VarniCustomProductService, b2 as Vendor, b3 as VendorService, b4 as WarrantyService, b5 as Wishlist, b6 as WishlistItem, b7 as WishlistService, b8 as addressService, b9 as authService, ba as autocompleteService, bb as b2bService, bc as bannerService, bd as blogService, be as cartService, bf as categoryService, bg as chatService, bh as checkoutService, bi as collectionService, bj as contactService, bk as countryService, bl as couponService, bm as currencyExponent, bn as currencyService, bo as dealService, bp as demoRequestService, bq as emptyCart, br as emptyPage, bs as enquiryService, bt as faqService, bu as feedbackService, bv as fromEngineAddress, bw as fromIdentityAddress, bx as fromSearchDoc, by as galleryService, bz as homeService, bA as initService, bB as layoutService, bC as mediaUrl, bD as meilisearchService, bE as menuService, bF as minorToMajor, bG as newsletterService, bH as orderService, bI as ownDomain, bJ as pageService, bK as paymentMethodService, bL as pluginService, bM as pluginsService, bN as popularSearchService, bO as popularityService, bP as priceOf, bQ as productImages, bR as productService, bS as profileService, bT as qs, bU as reelsService, bV as regionService, bW as reviewService, bX as searchService, bY as setRequestHost, bZ as settingService, b_ as settingsService, b$ as stateService, c0 as staticStore, c1 as storeForHost, c2 as storeService, c3 as toAddOn, c4 as toCart, c5 as toCartLine, c6 as toCartOffer, c7 as toCategory, c8 as toCmsPage, c9 as toCollection, ca as toEngineAddress, cb as toFreeShipping, cc as toIdentityAddress, cd as toMajor, ce as toMinor, cf as toOrder, cg as toPage, ch as toProduct, ci as toRating, cj as toStorefrontFacets, ck as toUser, cl as toVariant, cm as toVendor, cn as uploadService, co as userService, cp as variantService, cq as varniCustomDesignService, cr as varniCustomProductService, cs as vendorService, ct as warrantyService, cu as wishlistService } from './index-Bu4bVBBm.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 Address, a as AddressService, b as AppliedDiscount, c as Approval, d as AuthResponse, e as AuthService, f as AutocompleteService, B as B2bPlaced, g as B2bRole, h as B2bService, i as BannerService, j as BaseService, k as BlogService, C as Cart, l as CartLine, m as CartService, n as CatalogService, o as Category, p as CategoryService, q as ChatService, r as CheckoutOptions, s as CheckoutResult, t as CheckoutService, u as CmsPage, v as Collection, w as CollectionService, x as Company, y as CompanyOrder, z as ContactService, D as CountryService, E as CouponService, F as Credentials, G as Credit, H as CurrencyService, I as Customer, J as DealService, K as DemoRequestService, L as EngineRequest, M as EnquiryService, N as Envelope, O as FacetValue, P as Faq, Q as FaqService, R as FeedbackService, S as FooterSettings, T as Fulfillment, U as GalleryService, V as HeaderSettings, W as HomeLayout, X as HomeLayoutSection, Y as HomeService, Z as IdentityAddress, _ as InitService, $ as Invitation, a0 as LayoutCollection, a1 as LayoutPage, a2 as LayoutService, a3 as Lead, a4 as ListMeta, a5 as MeilisearchService, a6 as Member, a7 as Menu, a8 as MenuItem, a9 as MenuService, aa as MenuSummary, ab as Money, ac as NewsletterService, ad as Offer, ae as Order, af as OrderLine, ag as OrderService, ah as PageLayout, ai as PageService, aj as PaymentIntent, ak as PaymentMethodService, al as Plugin, am as PluginService, am as PluginsService, an as PopularSearchService, ao as PopularityService, ap as Product, aq as ProductFacets, ar as ProductOption, as as ProductService, at as ProfileService, au as Quote, av as REDIRECT_GATEWAYS, aw as ReelsService, ax as RegionService, ay as RejectedLine, az as Review, aA as ReviewPage, aB as ReviewService, aC as SearchDoc, aD as SearchResult, aE as SearchService, aF as SettingService, aF as SettingsService, aG as ShippingRate, aH as SiteChrome, aI as SiteFooter, aJ as SiteHeader, aK as SocialLink, aL as StateService, aM as StoreProfile, aN as StoreService, aO as StorefrontCategory, aP as StorefrontMenu, aQ as StorefrontOrder, aR as StorefrontProduct, aS as ThemeSettings, aT as ThemeSettingsResult, aU as UploadService, aV as UserService, aW as Variant, aX as VariantImage, aY as VariantService, aZ as VarniCustomDesignService, a_ as VarniCustomProductService, a$ as Vendor, b0 as VendorService, b1 as WarrantyService, b2 as Wishlist, b3 as WishlistItem, b4 as WishlistService, b5 as addressService, b6 as authService, b7 as autocompleteService, b8 as b2bService, b9 as bannerService, ba as blogService, bb as cartService, bc as categoryService, bd as chatService, be as checkoutService, bf as collectionService, bg as contactService, bh as countryService, bi as couponService, bj as currencyExponent, bk as currencyService, bl as dealService, bm as demoRequestService, bn as emptyCart, bo as emptyPage, bp as enquiryService, bq as faqService, br as feedbackService, bs as fromEngineAddress, bt as fromIdentityAddress, bu as fromSearchDoc, bv as galleryService, bw as homeService, bx as initService, by as layoutService, bz as mediaUrl, bA as meilisearchService, bB as menuService, bC as minorToMajor, bD as newsletterService, bE as orderService, bF as ownDomain, bG as pageService, bH as paymentMethodService, bI as pluginService, bJ as pluginsService, bK as popularSearchService, bL as popularityService, bM as priceOf, bN as productImages, bO as productService, bP as profileService, bQ as qs, bR as reelsService, bS as regionService, bT as reviewService, bU as searchService, bV as setRequestHost, bW as settingService, bX as settingsService, bY as stateService, bZ as staticStore, b_ as storeForHost, b$ as storeService, c0 as toCart, c1 as toCartLine, c2 as toCategory, c3 as toCmsPage, c4 as toCollection, c5 as toEngineAddress, c6 as toIdentityAddress, c7 as toMajor, c8 as toMinor, c9 as toOrder, ca as toPage, cb as toProduct, cc as toRating, cd as toStorefrontFacets, ce as toUser, cf as toVariant, cg as toVendor, ch as uploadService, ci as userService, cj as variantService, ck as varniCustomDesignService, cl as varniCustomProductService, cm as vendorService, cn as warrantyService, co as wishlistService } from './index-90wdO5MM.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 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 DealService, M as DemoRequestService, N as EngineRequest, O as EnquiryService, P as Envelope, Q as FacetValue, R as Faq, S as FaqService, T as FeedbackService, U as FooterSettings, V as FreeShipping, W as Fulfillment, X as GalleryService, Y as HeaderSettings, Z as HomeLayout, _ as HomeLayoutSection, $ as HomeService, a0 as IdentityAddress, a1 as InitService, a2 as Invitation, a3 as LayoutCollection, a4 as LayoutPage, a5 as LayoutService, a6 as Lead, a7 as ListMeta, a8 as MeilisearchService, a9 as Member, aa as Menu, ab as MenuItem, ac as MenuService, ad as MenuSummary, ae as Money, af as NewsletterService, ag as Offer, ah as Order, ai as OrderLine, aj as OrderService, ak as PageLayout, al as PageService, am as PaymentIntent, an as PaymentMethodService, ao as Plugin, ap as PluginService, ap as PluginsService, aq as PopularSearchService, ar as PopularityService, as as Product, at as ProductFacets, au as ProductOption, av as ProductService, aw as ProfileService, ax as Quote, ay as REDIRECT_GATEWAYS, az as ReelsService, aA as RegionService, aB as RejectedLine, aC as Review, aD as ReviewPage, aE as ReviewService, aF as SearchDoc, aG as SearchResult, aH as SearchService, aI as SettingService, aI as SettingsService, aJ as ShippingRate, aK as SiteChrome, aL as SiteFooter, aM as SiteHeader, aN as SocialLink, aO as StateService, aP as StoreProfile, aQ as StoreService, aR as StorefrontCategory, aS as StorefrontMenu, aT as StorefrontOrder, aU as StorefrontProduct, aV as ThemeSettings, aW as ThemeSettingsResult, aX as UploadService, aY as UserService, aZ as Variant, a_ as VariantImage, a$ as VariantService, b0 as VarniCustomDesignService, b1 as VarniCustomProductService, b2 as Vendor, b3 as VendorService, b4 as WarrantyService, b5 as Wishlist, b6 as WishlistItem, b7 as WishlistService, b8 as addressService, b9 as authService, ba as autocompleteService, bb as b2bService, bc as bannerService, bd as blogService, be as cartService, bf as categoryService, bg as chatService, bh as checkoutService, bi as collectionService, bj as contactService, bk as countryService, bl as couponService, bm as currencyExponent, bn as currencyService, bo as dealService, bp as demoRequestService, bq as emptyCart, br as emptyPage, bs as enquiryService, bt as faqService, bu as feedbackService, bv as fromEngineAddress, bw as fromIdentityAddress, bx as fromSearchDoc, by as galleryService, bz as homeService, bA as initService, bB as layoutService, bC as mediaUrl, bD as meilisearchService, bE as menuService, bF as minorToMajor, bG as newsletterService, bH as orderService, bI as ownDomain, bJ as pageService, bK as paymentMethodService, bL as pluginService, bM as pluginsService, bN as popularSearchService, bO as popularityService, bP as priceOf, bQ as productImages, bR as productService, bS as profileService, bT as qs, bU as reelsService, bV as regionService, bW as reviewService, bX as searchService, bY as setRequestHost, bZ as settingService, b_ as settingsService, b$ as stateService, c0 as staticStore, c1 as storeForHost, c2 as storeService, c3 as toAddOn, c4 as toCart, c5 as toCartLine, c6 as toCartOffer, c7 as toCategory, c8 as toCmsPage, c9 as toCollection, ca as toEngineAddress, cb as toFreeShipping, cc as toIdentityAddress, cd as toMajor, ce as toMinor, cf as toOrder, cg as toPage, ch as toProduct, ci as toRating, cj as toStorefrontFacets, ck as toUser, cl as toVariant, cm as toVendor, cn as uploadService, co as userService, cp as variantService, cq as varniCustomDesignService, cr as varniCustomProductService, cs as vendorService, ct as warrantyService, cu as wishlistService } from './index-Bu4bVBBm.js';
2
2
 
3
3
  /**
4
4
  * The two ways a call through this connector fails.
package/dist/index.js CHANGED
@@ -763,7 +763,12 @@ function toCartLine(l, extra = {}) {
763
763
  variantTitle: l.variant_label ?? "",
764
764
  qty: l.quantity,
765
765
  price: toMajor(l.unit_price),
766
- mrp: toMajor(l.unit_price),
766
+ // The variant's compare-at price, where the shop set one above what the
767
+ // line costs: what the basket's "you save" is measured from.
768
+ mrp: l.compare_at_price && l.compare_at_price.amount_minor > l.unit_price.amount_minor ? toMajor(l.compare_at_price) : toMajor(l.unit_price),
769
+ /** The add-on this line was bought as (D133), or null on an ordinary line. */
770
+ addOnId: l.add_on_id ? str(l.add_on_id) : null,
771
+ addOnFor: l.add_on_for ? str(l.add_on_for) : null,
767
772
  subtotal: toMajor(l.total),
768
773
  total: toMajor(l.total),
769
774
  inStock: l.in_stock,
@@ -997,6 +1002,45 @@ function toUser(c) {
997
1002
  };
998
1003
  }
999
1004
  var priceOf = (m) => m ? toMajor(m) : 0;
1005
+ function toAddOn(a) {
1006
+ return {
1007
+ id: str(a.id),
1008
+ productId: str(a.item.product_id),
1009
+ variantId: str(a.variant_id),
1010
+ slug: a.item.slug,
1011
+ title: a.item.title,
1012
+ variantTitle: a.item.variant_label ?? "",
1013
+ thumbnail: mediaUrl(a.item.image_url ?? null),
1014
+ price: toMajor(a.offer_price ?? a.price),
1015
+ regularPrice: toMajor(a.price),
1016
+ hasOffer: !!a.offer_price && a.offer_price.amount_minor < a.price.amount_minor,
1017
+ inStock: a.item.in_stock
1018
+ };
1019
+ }
1020
+ function toCartOffer(o, currency) {
1021
+ const isPercent = o.kind === "percentage";
1022
+ return {
1023
+ code: o.code,
1024
+ title: o.title,
1025
+ isPercent,
1026
+ freeShipping: o.kind === "free_shipping",
1027
+ /** The percentage for a percentage code, the amount for a fixed one. */
1028
+ value: isPercent ? (o.value_bp ?? 0) / 100 : minorToMajor(o.value_minor ?? 0, currency),
1029
+ minAmount: o.min_subtotal_minor ? minorToMajor(o.min_subtotal_minor, currency) : null,
1030
+ applies: o.applies,
1031
+ amount: o.amount ? toMajor(o.amount) : null,
1032
+ remaining: o.remaining ? toMajor(o.remaining) : null,
1033
+ reason: o.reason ?? ""
1034
+ };
1035
+ }
1036
+ function toFreeShipping(f) {
1037
+ return {
1038
+ qualifies: f.qualifies,
1039
+ threshold: f.threshold ? toMajor(f.threshold) : null,
1040
+ remaining: f.remaining ? toMajor(f.remaining) : null,
1041
+ subtotal: toMajor(f.subtotal)
1042
+ };
1043
+ }
1000
1044
 
1001
1045
  // src/services/facts.ts
1002
1046
  var StoreFacts = class extends BaseService {
@@ -1307,6 +1351,36 @@ var ProductService = class extends CatalogService {
1307
1351
  if (!category) return this.list({ page, limit });
1308
1352
  return this.list({ page, limit, categories: category.slug });
1309
1353
  }
1354
+ /**
1355
+ * What the shop offers with a product, ticked in its buy box (D133): each
1356
+ * add-on at the price ticking it adds. Only add-ons that can be bought
1357
+ * arrive; an engine without the route offers none.
1358
+ */
1359
+ async listAddOns({ product }) {
1360
+ const p = await this.findProduct(String(product));
1361
+ try {
1362
+ return (await this.data("/api/add-ons", { query: { product_id: p.id } }) ?? []).map(toAddOn);
1363
+ } catch (err) {
1364
+ if (err instanceof GoCommerceError && err.status === 404) return [];
1365
+ throw err;
1366
+ }
1367
+ }
1368
+ /**
1369
+ * "You may also like": the products the shop chose for this one, at their
1370
+ * own prices (D133). Curated only, and empty when none were chosen: the
1371
+ * related products already fill in from the category, and the page should
1372
+ * not draw the same fill twice.
1373
+ */
1374
+ async listCrossSells({ product, limit }) {
1375
+ const p = await this.findProduct(String(product));
1376
+ try {
1377
+ const rows = await this.data("/api/cross-sells", { query: { product_id: p.id, limit } }) ?? [];
1378
+ return rows.map((r) => toProduct(r));
1379
+ } catch (err) {
1380
+ if (err instanceof GoCommerceError && err.status === 404) return [];
1381
+ throw err;
1382
+ }
1383
+ }
1310
1384
  async relatedTo(slug, limit) {
1311
1385
  const size = Math.min(100, Math.max(1, Number(limit) || PAGE_SIZE));
1312
1386
  const p = await this.findProduct(slug);
@@ -1646,6 +1720,88 @@ var CartService = class extends BaseService {
1646
1720
  throw err;
1647
1721
  }
1648
1722
  }
1723
+ /**
1724
+ * Adds an add-on from a product's "Complete the set" (D133) at its offer
1725
+ * price. The product it is offered with has to be in the bag already, so
1726
+ * this is called after adding it; the engine refuses one too many with the
1727
+ * sentence the shopper is shown.
1728
+ */
1729
+ async addAddOn({ cartId, addOnId, qty = 1 }) {
1730
+ const id2 = clean(cartId) ?? storedCartId();
1731
+ if (!id2) throw new GoCommerceError("Add the product to your bag first.", 409);
1732
+ return this.present(
1733
+ await this.data(`/api/carts/${encodeURIComponent(id2)}/line-items`, {
1734
+ method: "POST",
1735
+ body: { add_on_id: Number(addOnId), quantity: Number(qty) }
1736
+ })
1737
+ );
1738
+ }
1739
+ /**
1740
+ * The codes the shop chose to show (D133), each with what it takes off this
1741
+ * bag or how much more the bag needs. None without a bag.
1742
+ */
1743
+ async getOffers({ cartId } = {}) {
1744
+ const id2 = clean(cartId) ?? storedCartId();
1745
+ if (!id2) return [];
1746
+ try {
1747
+ const rows = await this.data(`/api/carts/${encodeURIComponent(id2)}/offers`) ?? [];
1748
+ const currency = await this.currency();
1749
+ return rows.map((o) => toCartOffer(o, o.amount?.currency ?? o.remaining?.currency ?? currency));
1750
+ } catch (err) {
1751
+ if (err instanceof GoCommerceError && err.status === 404) return [];
1752
+ throw err;
1753
+ }
1754
+ }
1755
+ /**
1756
+ * How far the bag is from free delivery (D133), read from the store's own
1757
+ * rates for the country (the store's own when none is given). Null when
1758
+ * the engine cannot say: a bar with a made-up figure is worse than none.
1759
+ */
1760
+ async getFreeShipping({ cartId, country, state } = {}) {
1761
+ const id2 = clean(cartId) ?? storedCartId();
1762
+ if (!id2) return null;
1763
+ const where = country ?? cartExtras(id2).shippingAddress?.country ?? void 0;
1764
+ try {
1765
+ return toFreeShipping(
1766
+ await this.data(`/api/carts/${encodeURIComponent(id2)}/free-shipping`, {
1767
+ query: { country: where || void 0, state: state || void 0 }
1768
+ })
1769
+ );
1770
+ } catch (err) {
1771
+ if (err instanceof GoCommerceError && err.status === 404) return null;
1772
+ throw err;
1773
+ }
1774
+ }
1775
+ /**
1776
+ * "You may be interested in" (D133): what the bag's products suggest, less
1777
+ * what it holds; with nothing curated, the first product's related
1778
+ * products, still less what it holds.
1779
+ */
1780
+ async listCrossSells({ cartId, limit = 12 } = {}) {
1781
+ const id2 = clean(cartId) ?? storedCartId();
1782
+ if (!id2) return [];
1783
+ let curated = [];
1784
+ try {
1785
+ curated = await this.data(`/api/carts/${encodeURIComponent(id2)}/cross-sells`, { query: { limit } }) ?? [];
1786
+ } catch (err) {
1787
+ if (!(err instanceof GoCommerceError) || err.status !== 404) throw err;
1788
+ }
1789
+ if (curated.length) return curated.map((p) => toProduct(p));
1790
+ let cart;
1791
+ try {
1792
+ cart = await this.data(`/api/carts/${encodeURIComponent(id2)}`);
1793
+ } catch {
1794
+ return [];
1795
+ }
1796
+ const held = new Set((cart.line_items ?? []).map((l) => String(l.product_id)));
1797
+ const first = cart.line_items?.[0];
1798
+ if (!first) return [];
1799
+ const related = await new ProductService(this._fetch).listRelatedProducts({
1800
+ product: String(first.product_id),
1801
+ limit: limit + held.size
1802
+ });
1803
+ return related.data.filter((p) => !held.has(String(p.id))).slice(0, limit);
1804
+ }
1649
1805
  /** `qty` is the new total; 0 takes the line out. */
1650
1806
  async updateCart({
1651
1807
  cartId,
@@ -2079,7 +2235,20 @@ var paymentMethodService = new PaymentMethodService();
2079
2235
  // src/services/coupon-service.ts
2080
2236
  var CouponService = class extends BaseService {
2081
2237
  async listCoupons(_args = {}) {
2082
- return emptyPage();
2238
+ const offers = await new CartService(this._fetch).getOffers().catch(() => []);
2239
+ if (!offers.length) return emptyPage();
2240
+ const data = offers.map((o) => ({
2241
+ id: o.code,
2242
+ code: o.code,
2243
+ title: o.title,
2244
+ isPercent: o.isPercent,
2245
+ amount: o.value,
2246
+ minAmount: o.minAmount,
2247
+ description: o.applies ? o.title : o.remaining !== null ? `${o.title}. Add ${o.remaining} more to use this.` : o.reason || o.title,
2248
+ applies: o.applies,
2249
+ remaining: o.remaining
2250
+ }));
2251
+ return { data, count: data.length, pageSize: data.length, noOfPage: 1, page: 1 };
2083
2252
  }
2084
2253
  };
2085
2254
  var couponService = new CouponService();
@@ -2826,7 +2995,10 @@ var StoreService = class extends BaseService {
2826
2995
  },
2827
2996
  // The footer's sign-up box posts to ext/newsletter, and the theme editor's footer
2828
2997
  // switch (D131) can only show it while that is on.
2829
- newsletter: { ...basePlugins.newsletter, ...flag(plugins.has("newsletter")) }
2998
+ newsletter: { ...basePlugins.newsletter, ...flag(plugins.has("newsletter")) },
2999
+ // Discount codes are core: every GoCommerce store takes them, so
3000
+ // the code box is shown whatever the static record says.
3001
+ isDiscountCoupons: { ...basePlugins.isDiscountCoupons, active: true }
2830
3002
  },
2831
3003
  ...menus?.length ? { menu: menus } : {},
2832
3004
  ...deliverable(base, ships),
@@ -3532,6 +3704,6 @@ function attemptKey(request) {
3532
3704
  }
3533
3705
  var b2bService = new B2bService();
3534
3706
 
3535
- export { AddressService, AuthService, AutocompleteService, B2bService, BannerService, BaseService, BlogService, CartService, CatalogService, CategoryService, ChatService, CheckoutService, CollectionService, ContactService, CountryService, CouponService, CurrencyService, DealService, DemoRequestService, EnquiryService, FaqService, FeedbackService, GalleryService, GoCommerceError, 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, WishlistService, addressService, authService, autocompleteService, b2bService, bannerService, blogService, cartService, categoryService, chatService, checkoutService, forgetAll as clearStoreCache, collectionService, connectorName, contactService, countryService, couponService, currencyExponent, currencyService, dealService, demoRequestService, emptyCart, emptyPage, enquiryService, faqService, feedbackService, fromEngineAddress, fromIdentityAddress, fromSearchDoc, galleryService, hasStaticStore, homeService, initService, layoutService, mediaUrl, meilisearchService, menuService, minorToMajor, newsletterService, orderService, ownDomain, pageService, paymentMethodService, pluginService, pluginsService, popularSearchService, popularityService, priceOf, productImages, productService, profileService, qs, readStaticStore, reelsService, regionService, reviewService, searchService, serveRestLocally, setRequestHost, setStaticStore, settingService, settingsService, stateService, staticStore, storeForHost, storeService, toCart, toCartLine, toCategory, toCmsPage, toCollection, toEngineAddress, toIdentityAddress, toMajor, toMinor, toOrder, toPage, toProduct, toRating, toStorefrontFacets, toUser, toVariant, toVendor, uploadService, userService, variantService, varniCustomDesignService, varniCustomProductService, vendorService, warrantyService, wishlistService };
3707
+ export { AddressService, AuthService, AutocompleteService, B2bService, BannerService, BaseService, BlogService, CartService, CatalogService, CategoryService, ChatService, CheckoutService, CollectionService, ContactService, CountryService, CouponService, CurrencyService, DealService, DemoRequestService, EnquiryService, FaqService, FeedbackService, GalleryService, GoCommerceError, 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, WishlistService, addressService, authService, autocompleteService, b2bService, bannerService, blogService, cartService, categoryService, chatService, checkoutService, forgetAll as clearStoreCache, collectionService, connectorName, contactService, countryService, couponService, currencyExponent, currencyService, dealService, demoRequestService, emptyCart, emptyPage, enquiryService, faqService, feedbackService, fromEngineAddress, fromIdentityAddress, fromSearchDoc, galleryService, hasStaticStore, homeService, initService, layoutService, mediaUrl, meilisearchService, menuService, minorToMajor, newsletterService, orderService, ownDomain, pageService, paymentMethodService, pluginService, pluginsService, popularSearchService, popularityService, priceOf, productImages, productService, 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, wishlistService };
3536
3708
  //# sourceMappingURL=index.js.map
3537
3709
  //# sourceMappingURL=index.js.map