@misiki/gocommerce-connector 0.11.0 → 0.13.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 Postcode, at as Product, au as ProductFacets, av as ProductOption, aw as ProductService, ax as ProfileService, ay as Quote, az as REDIRECT_GATEWAYS, aA as ReelsService, aB as RegionService, aC as RejectedLine, aD as Review, aE as ReviewPage, aF as ReviewService, aG as SearchDoc, aH as SearchResult, aI as SearchService, aJ as SettingService, aJ as SettingsService, aK as ShippingRate, aL as SiteChrome, aM as SiteFooter, aN as SiteHeader, aO as SocialLink, aP as StateService, aQ as StoreProfile, aR as StoreService, aS as StorefrontCategory, aT as StorefrontMenu, aU as StorefrontOrder, aV as StorefrontProduct, aW as ThemeSettings, aX as ThemeSettingsResult, aY as UploadService, aZ as UserService, a_ as Variant, a$ as VariantImage, b0 as VariantService, b1 as VarniCustomDesignService, b2 as VarniCustomProductService, b3 as Vendor, b4 as VendorService, b5 as WarrantyService, b6 as Wishlist, b7 as WishlistItem, b8 as WishlistService, b9 as addressService, ba as authService, bb as autocompleteService, bc as b2bService, bd as bannerService, be as blogService, bf as cartService, bg as categoryService, bh as chatService, bi as checkoutService, bj as collectionService, bk as contactService, bl as countryService, bm as couponService, bn as currencyExponent, bo as currencyService, bp as dealService, bq as demoRequestService, br as emptyCart, bs as emptyPage, bt as enquiryService, bu as faqService, bv as feedbackService, bw as fromEngineAddress, bx as fromIdentityAddress, by as fromSearchDoc, bz as galleryService, bA as homeService, bB as initService, bC as layoutService, bD as mediaUrl, bE as meilisearchService, bF as menuService, bG as minorToMajor, bH as newsletterService, bI as orderService, bJ as ownDomain, bK as pageService, bL as paymentMethodService, bM as pluginService, bN as pluginsService, bO as popularSearchService, bP as popularityService, bQ as priceOf, bR as productImages, bS as productService, bT as productVideos, bU as profileService, bV as qs, bW as reelsService, bX as regionService, bY as reviewService, bZ as searchService, b_ as setRequestHost, b$ as settingService, c0 as settingsService, c1 as stateService, c2 as staticStore, c3 as storeForHost, c4 as storeService, c5 as toAddOn, c6 as toCart, c7 as toCartLine, c8 as toCartOffer, c9 as toCategory, 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 wishlistService } from './index-DHKyh3CU.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 Postcode, at as Product, au as ProductFacets, av as ProductOption, aw as ProductService, ax as ProfileService, ay as Quote, az as REDIRECT_GATEWAYS, aA as ReelsService, aB as RegionService, aC as RejectedLine, aD as Review, aE as ReviewPage, aF as ReviewService, aG as SearchDoc, aH as SearchResult, aI as SearchService, aJ as SettingService, aJ as SettingsService, aK as ShippingRate, aL as SiteChrome, aM as SiteFooter, aN as SiteHeader, aO as SocialLink, aP as StateService, aQ as StoreProfile, aR as StoreService, aS as StorefrontCategory, aT as StorefrontMenu, aU as StorefrontOrder, aV as StorefrontProduct, aW as ThemeSettings, aX as ThemeSettingsResult, aY as UploadService, aZ as UserService, a_ as Variant, a$ as VariantImage, b0 as VariantService, b1 as VarniCustomDesignService, b2 as VarniCustomProductService, b3 as Vendor, b4 as VendorService, b5 as WarrantyService, b6 as Wishlist, b7 as WishlistItem, b8 as WishlistService, b9 as addressService, ba as authService, bb as autocompleteService, bc as b2bService, bd as bannerService, be as blogService, bf as cartService, bg as categoryService, bh as chatService, bi as checkoutService, bj as collectionService, bk as contactService, bl as countryService, bm as couponService, bn as currencyExponent, bo as currencyService, bp as dealService, bq as demoRequestService, br as emptyCart, bs as emptyPage, bt as enquiryService, bu as faqService, bv as feedbackService, bw as fromEngineAddress, bx as fromIdentityAddress, by as fromSearchDoc, bz as galleryService, bA as homeService, bB as initService, bC as layoutService, bD as mediaUrl, bE as meilisearchService, bF as menuService, bG as minorToMajor, bH as newsletterService, bI as orderService, bJ as ownDomain, bK as pageService, bL as paymentMethodService, bM as pluginService, bN as pluginsService, bO as popularSearchService, bP as popularityService, bQ as priceOf, bR as productImages, bS as productService, bT as productVideos, bU as profileService, bV as qs, bW as reelsService, bX as regionService, bY as reviewService, bZ as searchService, b_ as setRequestHost, b$ as settingService, c0 as settingsService, c1 as stateService, c2 as staticStore, c3 as storeForHost, c4 as storeService, c5 as toAddOn, c6 as toCart, c7 as toCartLine, c8 as toCartOffer, c9 as toCategory, 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 wishlistService } from './index-DHKyh3CU.js';
2
2
 
3
3
  /**
4
4
  * The two ways a call through this connector fails.
package/dist/index.js CHANGED
@@ -496,9 +496,27 @@ function productImages(p) {
496
496
  if (url && !out.includes(url)) out.push(url);
497
497
  };
498
498
  push(mediaUrl(p.image_url));
499
+ for (const m of arr(p.media)) if (m.kind === "image") push(mediaUrl(m.url));
499
500
  for (const v of arr(p.variants)) for (const url of variantImages(v)) push(url);
500
501
  return out;
501
502
  }
503
+ function productVideos(p) {
504
+ const out = [];
505
+ for (const m of arr(p.media)) {
506
+ const url = m.kind === "video" ? mediaUrl(m.url) : null;
507
+ if (url && !out.includes(url)) out.push(url);
508
+ }
509
+ return out;
510
+ }
511
+ function highlightsOf(p) {
512
+ const raw = p.metadata?.highlights;
513
+ if (!Array.isArray(raw)) return [];
514
+ return raw.filter((s) => typeof s === "string").map((s) => s.trim()).filter(Boolean);
515
+ }
516
+ function freeGiftOf(p) {
517
+ const raw = p.metadata?.free_gift;
518
+ return typeof raw === "string" && raw.trim() ? raw.trim() : null;
519
+ }
502
520
  function toVariant(v, p, optionless) {
503
521
  const images = variantImages(v);
504
522
  const options = arr(p.options);
@@ -546,6 +564,7 @@ function toProduct(p, extra = {}) {
546
564
  const lead = live[0] ?? arr(p.variants)[0];
547
565
  const optionless = arr(p.options).length === 0;
548
566
  const images = productImages(p);
567
+ const videos = productVideos(p);
549
568
  const prices = live.map((v) => toMajor(v.price));
550
569
  const tracked = live.filter((v) => v.track_inventory);
551
570
  const category = p.category;
@@ -572,8 +591,14 @@ function toProduct(p, extra = {}) {
572
591
  originCountry: lead?.origin_country ?? null,
573
592
  thumbnail: images[0] ?? null,
574
593
  image_url: images[0] ?? null,
575
- images: images.join(","),
594
+ images: [...images, ...videos].join(","),
576
595
  imageList: images,
596
+ videos,
597
+ // What the buy box says beside the price (D134): plain text, drawn as text.
598
+ highlights: highlightsOf(p),
599
+ freeGift: freeGiftOf(p),
600
+ // Counted by the engine, rounded down, and absent rather than zero.
601
+ soldAtLeast: typeof p.sold_at_least === "number" && p.sold_at_least > 0 ? p.sold_at_least : null,
577
602
  // Product-level stock is what a card shows before a variant is picked:
578
603
  // buyable when any live variant is, counted only where counting means
579
604
  // something.
@@ -746,7 +771,9 @@ function toIdentityAddress(a) {
746
771
  state: e.state ?? "",
747
772
  postal_code: e.postal_code,
748
773
  country: e.country,
749
- ...a.label ? { label: String(a.label) } : {},
774
+ // Sent whenever the form has it, empty included: the engine keeps a label it is not sent, so
775
+ // leaving out an emptied one would keep the old Home or Work (D134).
776
+ ...typeof a.label === "string" ? { label: a.label } : {},
750
777
  ...a.isPrimary ? { is_default: true } : {}
751
778
  };
752
779
  }
@@ -763,7 +790,12 @@ function toCartLine(l, extra = {}) {
763
790
  variantTitle: l.variant_label ?? "",
764
791
  qty: l.quantity,
765
792
  price: toMajor(l.unit_price),
766
- mrp: toMajor(l.unit_price),
793
+ // The variant's compare-at price, where the shop set one above what the
794
+ // line costs: what the basket's "you save" is measured from.
795
+ 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),
796
+ /** The add-on this line was bought as (D133), or null on an ordinary line. */
797
+ addOnId: l.add_on_id ? str(l.add_on_id) : null,
798
+ addOnFor: l.add_on_for ? str(l.add_on_for) : null,
767
799
  subtotal: toMajor(l.total),
768
800
  total: toMajor(l.total),
769
801
  inStock: l.in_stock,
@@ -997,6 +1029,45 @@ function toUser(c) {
997
1029
  };
998
1030
  }
999
1031
  var priceOf = (m) => m ? toMajor(m) : 0;
1032
+ function toAddOn(a) {
1033
+ return {
1034
+ id: str(a.id),
1035
+ productId: str(a.item.product_id),
1036
+ variantId: str(a.variant_id),
1037
+ slug: a.item.slug,
1038
+ title: a.item.title,
1039
+ variantTitle: a.item.variant_label ?? "",
1040
+ thumbnail: mediaUrl(a.item.image_url ?? null),
1041
+ price: toMajor(a.offer_price ?? a.price),
1042
+ regularPrice: toMajor(a.price),
1043
+ hasOffer: !!a.offer_price && a.offer_price.amount_minor < a.price.amount_minor,
1044
+ inStock: a.item.in_stock
1045
+ };
1046
+ }
1047
+ function toCartOffer(o, currency) {
1048
+ const isPercent = o.kind === "percentage";
1049
+ return {
1050
+ code: o.code,
1051
+ title: o.title,
1052
+ isPercent,
1053
+ freeShipping: o.kind === "free_shipping",
1054
+ /** The percentage for a percentage code, the amount for a fixed one. */
1055
+ value: isPercent ? (o.value_bp ?? 0) / 100 : minorToMajor(o.value_minor ?? 0, currency),
1056
+ minAmount: o.min_subtotal_minor ? minorToMajor(o.min_subtotal_minor, currency) : null,
1057
+ applies: o.applies,
1058
+ amount: o.amount ? toMajor(o.amount) : null,
1059
+ remaining: o.remaining ? toMajor(o.remaining) : null,
1060
+ reason: o.reason ?? ""
1061
+ };
1062
+ }
1063
+ function toFreeShipping(f) {
1064
+ return {
1065
+ qualifies: f.qualifies,
1066
+ threshold: f.threshold ? toMajor(f.threshold) : null,
1067
+ remaining: f.remaining ? toMajor(f.remaining) : null,
1068
+ subtotal: toMajor(f.subtotal)
1069
+ };
1070
+ }
1000
1071
 
1001
1072
  // src/services/facts.ts
1002
1073
  var StoreFacts = class extends BaseService {
@@ -1307,6 +1378,36 @@ var ProductService = class extends CatalogService {
1307
1378
  if (!category) return this.list({ page, limit });
1308
1379
  return this.list({ page, limit, categories: category.slug });
1309
1380
  }
1381
+ /**
1382
+ * What the shop offers with a product, ticked in its buy box (D133): each
1383
+ * add-on at the price ticking it adds. Only add-ons that can be bought
1384
+ * arrive; an engine without the route offers none.
1385
+ */
1386
+ async listAddOns({ product }) {
1387
+ const p = await this.findProduct(String(product));
1388
+ try {
1389
+ return (await this.data("/api/add-ons", { query: { product_id: p.id } }) ?? []).map(toAddOn);
1390
+ } catch (err) {
1391
+ if (err instanceof GoCommerceError && err.status === 404) return [];
1392
+ throw err;
1393
+ }
1394
+ }
1395
+ /**
1396
+ * "You may also like": the products the shop chose for this one, at their
1397
+ * own prices (D133). Curated only, and empty when none were chosen: the
1398
+ * related products already fill in from the category, and the page should
1399
+ * not draw the same fill twice.
1400
+ */
1401
+ async listCrossSells({ product, limit }) {
1402
+ const p = await this.findProduct(String(product));
1403
+ try {
1404
+ const rows = await this.data("/api/cross-sells", { query: { product_id: p.id, limit } }) ?? [];
1405
+ return rows.map((r) => toProduct(r));
1406
+ } catch (err) {
1407
+ if (err instanceof GoCommerceError && err.status === 404) return [];
1408
+ throw err;
1409
+ }
1410
+ }
1310
1411
  async relatedTo(slug, limit) {
1311
1412
  const size = Math.min(100, Math.max(1, Number(limit) || PAGE_SIZE));
1312
1413
  const p = await this.findProduct(slug);
@@ -1646,6 +1747,88 @@ var CartService = class extends BaseService {
1646
1747
  throw err;
1647
1748
  }
1648
1749
  }
1750
+ /**
1751
+ * Adds an add-on from a product's "Complete the set" (D133) at its offer
1752
+ * price. The product it is offered with has to be in the bag already, so
1753
+ * this is called after adding it; the engine refuses one too many with the
1754
+ * sentence the shopper is shown.
1755
+ */
1756
+ async addAddOn({ cartId, addOnId, qty = 1 }) {
1757
+ const id2 = clean(cartId) ?? storedCartId();
1758
+ if (!id2) throw new GoCommerceError("Add the product to your bag first.", 409);
1759
+ return this.present(
1760
+ await this.data(`/api/carts/${encodeURIComponent(id2)}/line-items`, {
1761
+ method: "POST",
1762
+ body: { add_on_id: Number(addOnId), quantity: Number(qty) }
1763
+ })
1764
+ );
1765
+ }
1766
+ /**
1767
+ * The codes the shop chose to show (D133), each with what it takes off this
1768
+ * bag or how much more the bag needs. None without a bag.
1769
+ */
1770
+ async getOffers({ cartId } = {}) {
1771
+ const id2 = clean(cartId) ?? storedCartId();
1772
+ if (!id2) return [];
1773
+ try {
1774
+ const rows = await this.data(`/api/carts/${encodeURIComponent(id2)}/offers`) ?? [];
1775
+ const currency = await this.currency();
1776
+ return rows.map((o) => toCartOffer(o, o.amount?.currency ?? o.remaining?.currency ?? currency));
1777
+ } catch (err) {
1778
+ if (err instanceof GoCommerceError && err.status === 404) return [];
1779
+ throw err;
1780
+ }
1781
+ }
1782
+ /**
1783
+ * How far the bag is from free delivery (D133), read from the store's own
1784
+ * rates for the country (the store's own when none is given). Null when
1785
+ * the engine cannot say: a bar with a made-up figure is worse than none.
1786
+ */
1787
+ async getFreeShipping({ cartId, country, state } = {}) {
1788
+ const id2 = clean(cartId) ?? storedCartId();
1789
+ if (!id2) return null;
1790
+ const where = country ?? cartExtras(id2).shippingAddress?.country ?? void 0;
1791
+ try {
1792
+ return toFreeShipping(
1793
+ await this.data(`/api/carts/${encodeURIComponent(id2)}/free-shipping`, {
1794
+ query: { country: where || void 0, state: state || void 0 }
1795
+ })
1796
+ );
1797
+ } catch (err) {
1798
+ if (err instanceof GoCommerceError && err.status === 404) return null;
1799
+ throw err;
1800
+ }
1801
+ }
1802
+ /**
1803
+ * "You may be interested in" (D133): what the bag's products suggest, less
1804
+ * what it holds; with nothing curated, the first product's related
1805
+ * products, still less what it holds.
1806
+ */
1807
+ async listCrossSells({ cartId, limit = 12 } = {}) {
1808
+ const id2 = clean(cartId) ?? storedCartId();
1809
+ if (!id2) return [];
1810
+ let curated = [];
1811
+ try {
1812
+ curated = await this.data(`/api/carts/${encodeURIComponent(id2)}/cross-sells`, { query: { limit } }) ?? [];
1813
+ } catch (err) {
1814
+ if (!(err instanceof GoCommerceError) || err.status !== 404) throw err;
1815
+ }
1816
+ if (curated.length) return curated.map((p) => toProduct(p));
1817
+ let cart;
1818
+ try {
1819
+ cart = await this.data(`/api/carts/${encodeURIComponent(id2)}`);
1820
+ } catch {
1821
+ return [];
1822
+ }
1823
+ const held = new Set((cart.line_items ?? []).map((l) => String(l.product_id)));
1824
+ const first = cart.line_items?.[0];
1825
+ if (!first) return [];
1826
+ const related = await new ProductService(this._fetch).listRelatedProducts({
1827
+ product: String(first.product_id),
1828
+ limit: limit + held.size
1829
+ });
1830
+ return related.data.filter((p) => !held.has(String(p.id))).slice(0, limit);
1831
+ }
1649
1832
  /** `qty` is the new total; 0 takes the line out. */
1650
1833
  async updateCart({
1651
1834
  cartId,
@@ -2079,7 +2262,20 @@ var paymentMethodService = new PaymentMethodService();
2079
2262
  // src/services/coupon-service.ts
2080
2263
  var CouponService = class extends BaseService {
2081
2264
  async listCoupons(_args = {}) {
2082
- return emptyPage();
2265
+ const offers = await new CartService(this._fetch).getOffers().catch(() => []);
2266
+ if (!offers.length) return emptyPage();
2267
+ const data = offers.map((o) => ({
2268
+ id: o.code,
2269
+ code: o.code,
2270
+ title: o.title,
2271
+ isPercent: o.isPercent,
2272
+ amount: o.value,
2273
+ minAmount: o.minAmount,
2274
+ description: o.applies ? o.title : o.remaining !== null ? `${o.title}. Add ${o.remaining} more to use this.` : o.reason || o.title,
2275
+ applies: o.applies,
2276
+ remaining: o.remaining
2277
+ }));
2278
+ return { data, count: data.length, pageSize: data.length, noOfPage: 1, page: 1 };
2083
2279
  }
2084
2280
  };
2085
2281
  var couponService = new CouponService();
@@ -2517,6 +2713,24 @@ var AddressService = class extends BaseService {
2517
2713
  });
2518
2714
  return fromIdentityAddress(a, currentMe()?.email);
2519
2715
  }
2716
+ /**
2717
+ * The city and state for a postcode (D134), for the address form to fill
2718
+ * in. India's six-digit PIN codes only, from the directory the engine was
2719
+ * given; null for anything it cannot answer, so the form simply leaves the
2720
+ * fields to the shopper.
2721
+ */
2722
+ async lookupPostcode({ country = "IN", postcode }) {
2723
+ const code = String(postcode ?? "").trim();
2724
+ const cc = String(country ?? "").trim().toUpperCase();
2725
+ if (cc !== "IN" || !/^[1-9][0-9]{5}$/.test(code)) return null;
2726
+ try {
2727
+ const p = await this.data(`/api/postcodes/${cc}/${code}`);
2728
+ return { country: p.country, postcode: p.postcode, city: p.city, state: p.state, stateCode: p.state_code };
2729
+ } catch (err) {
2730
+ if (err instanceof GoCommerceError && (err.status === 404 || err.status === 400)) return null;
2731
+ throw err;
2732
+ }
2733
+ }
2520
2734
  async deleteAddress(id2) {
2521
2735
  await this.engine(`/x/identity/me/addresses/${enc(id2)}`, { method: "DELETE", auth: true });
2522
2736
  return { id: String(id2), deleted: true };
@@ -2826,7 +3040,10 @@ var StoreService = class extends BaseService {
2826
3040
  },
2827
3041
  // The footer's sign-up box posts to ext/newsletter, and the theme editor's footer
2828
3042
  // switch (D131) can only show it while that is on.
2829
- newsletter: { ...basePlugins.newsletter, ...flag(plugins.has("newsletter")) }
3043
+ newsletter: { ...basePlugins.newsletter, ...flag(plugins.has("newsletter")) },
3044
+ // Discount codes are core: every GoCommerce store takes them, so
3045
+ // the code box is shown whatever the static record says.
3046
+ isDiscountCoupons: { ...basePlugins.isDiscountCoupons, active: true }
2830
3047
  },
2831
3048
  ...menus?.length ? { menu: menus } : {},
2832
3049
  ...deliverable(base, ships),
@@ -3532,6 +3749,6 @@ function attemptKey(request) {
3532
3749
  }
3533
3750
  var b2bService = new B2bService();
3534
3751
 
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 };
3752
+ 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, 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, wishlistService };
3536
3753
  //# sourceMappingURL=index.js.map
3537
3754
  //# sourceMappingURL=index.js.map