@misiki/gocommerce-connector 0.12.0 → 0.14.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 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';
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-C0CR05Q4.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 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';
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-C0CR05Q4.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
  }
@@ -1187,14 +1214,17 @@ var CatalogService = class extends BaseService {
1187
1214
  const attr = Object.entries(q.attributes ?? {}).flatMap(
1188
1215
  ([handle, values]) => values.filter(Boolean).map((v) => `${handle}:${v}`)
1189
1216
  );
1190
- if (q.facets && !legacyListing.has(this.engineBase())) {
1217
+ const refined = attr.length > 0 || !!(q.tags?.length || q.vendors?.length || q.productTypes?.length);
1218
+ const triedIndex = !!search && !refined;
1219
+ const counted = q.facets && !legacyListing.has(this.engineBase());
1220
+ const facetListing = async (page2, limit2) => {
1191
1221
  const { currency } = await this.facts.ready();
1192
1222
  const minor = (n) => Number.isFinite(n) ? Math.max(0, toMinor(n, currency)) : void 0;
1193
- const env2 = await this.engine("/api/products", {
1223
+ return this.engine("/api/products", {
1194
1224
  query: {
1195
1225
  q: search,
1196
- page,
1197
- limit,
1226
+ page: page2,
1227
+ limit: limit2,
1198
1228
  channel: this.creds.channel,
1199
1229
  category: q.category,
1200
1230
  tag: q.tags,
@@ -1207,6 +1237,16 @@ var CatalogService = class extends BaseService {
1207
1237
  facets: 1
1208
1238
  }
1209
1239
  });
1240
+ };
1241
+ if (triedIndex && await this.facts.pluginOn("meilisearch")) {
1242
+ const [found, rail] = await Promise.all([
1243
+ this.fromIndex(q, { page, limit, search, sortKey, wantsRange, hierarchy }),
1244
+ counted ? facetListing(1, 1).catch(() => null) : null
1245
+ ]);
1246
+ if (found) return rail?.meta?.facets ? { ...found, facets: rail.meta.facets } : found;
1247
+ }
1248
+ if (counted) {
1249
+ const env2 = await facetListing(page, limit);
1210
1250
  if (env2.meta?.facets) {
1211
1251
  return {
1212
1252
  ...toPage(env2, (p) => toProduct(p)),
@@ -1217,39 +1257,9 @@ var CatalogService = class extends BaseService {
1217
1257
  }
1218
1258
  legacyListing.add(this.engineBase());
1219
1259
  }
1220
- if ((sortKey || wantsRange) && await this.facts.pluginOn("meilisearch")) {
1221
- const filters = [];
1222
- if (q.category) {
1223
- const names = (await this.facts.subtree(q.category).catch(() => [])).map(
1224
- (c) => quote(c.full_name)
1225
- );
1226
- if (!names.length) return { ...emptyCatalog(limit), categoryHierarchy: hierarchy, sorted: true };
1227
- filters.push(`category IN [${names.join(", ")}]`);
1228
- }
1229
- if (wantsRange) {
1230
- const { currency } = await this.facts.ready();
1231
- if (Number.isFinite(q.priceFrom)) filters.push(`price_minor >= ${toMinor(q.priceFrom, currency)}`);
1232
- if (Number.isFinite(q.priceTo)) filters.push(`price_minor <= ${toMinor(q.priceTo, currency)}`);
1233
- }
1234
- const res = await this.data("/x/meilisearch/search", {
1235
- query: {
1236
- q: search ?? "",
1237
- limit,
1238
- offset: (page - 1) * limit,
1239
- filter: filters.join(" AND ") || void 0,
1240
- sort: sortKey
1241
- }
1242
- });
1243
- const total = res.total ?? 0;
1244
- return {
1245
- data: (res.hits ?? []).map(fromSearchDoc),
1246
- count: total,
1247
- pageSize: limit,
1248
- noOfPage: Math.max(1, Math.ceil(total / limit)),
1249
- page,
1250
- categoryHierarchy: hierarchy,
1251
- sorted: true
1252
- };
1260
+ if (!triedIndex && (sortKey || wantsRange)) {
1261
+ const found = await this.fromIndex(q, { page, limit, search, sortKey, wantsRange, hierarchy });
1262
+ if (found) return found;
1253
1263
  }
1254
1264
  const sorted = !sortKey && !wantsRange;
1255
1265
  if (q.category && !search) {
@@ -1269,6 +1279,45 @@ var CatalogService = class extends BaseService {
1269
1279
  });
1270
1280
  return { ...toPage(env, (p) => toProduct(p)), categoryHierarchy: hierarchy, sorted };
1271
1281
  }
1282
+ /**
1283
+ * The shelf from the Meilisearch module, or null when the store has it off,
1284
+ * sells through a channel, finds nothing for the words, or it cannot answer (Meilisearch down: the engine says `unavailable`), so
1285
+ * the caller asks the database instead of showing the shopper an error.
1286
+ */
1287
+ async fromIndex(q, o) {
1288
+ if (this.creds.channel || !await this.facts.pluginOn("meilisearch")) return null;
1289
+ const filters = [];
1290
+ if (q.category) {
1291
+ const names = (await this.facts.subtree(q.category).catch(() => [])).map((c) => quote(c.full_name));
1292
+ if (!names.length) return { ...emptyCatalog(o.limit), categoryHierarchy: o.hierarchy, sorted: true };
1293
+ filters.push(`category IN [${names.join(", ")}]`);
1294
+ }
1295
+ if (o.wantsRange) {
1296
+ const { currency } = await this.facts.ready();
1297
+ if (Number.isFinite(q.priceFrom)) filters.push(`price_minor >= ${toMinor(q.priceFrom, currency)}`);
1298
+ if (Number.isFinite(q.priceTo)) filters.push(`price_minor <= ${toMinor(q.priceTo, currency)}`);
1299
+ }
1300
+ const res = await this.data("/x/meilisearch/search", {
1301
+ query: {
1302
+ q: o.search ?? "",
1303
+ limit: o.limit,
1304
+ offset: (o.page - 1) * o.limit,
1305
+ filter: filters.join(" AND ") || void 0,
1306
+ sort: o.sortKey
1307
+ }
1308
+ }).catch(() => null);
1309
+ if (!res || res.unavailable || o.search && !res.hits?.length) return null;
1310
+ const total = res.total ?? 0;
1311
+ return {
1312
+ data: (res.hits ?? []).map(fromSearchDoc),
1313
+ count: total,
1314
+ pageSize: o.limit,
1315
+ noOfPage: Math.max(1, Math.ceil(total / o.limit)),
1316
+ page: o.page,
1317
+ categoryHierarchy: o.hierarchy,
1318
+ sorted: true
1319
+ };
1320
+ }
1272
1321
  };
1273
1322
  function emptyCatalog(limit = PAGE_SIZE) {
1274
1323
  return { data: [], count: 0, pageSize: limit, noOfPage: 0, page: 1 };
@@ -1566,10 +1615,8 @@ var MeilisearchService = class extends CatalogService {
1566
1615
  async searchAutoComplete({ query, search, limit = 8 } = {}) {
1567
1616
  const q = (query ?? search ?? "").trim();
1568
1617
  if (!q) return { data: [] };
1569
- if (await this.facts.pluginOn("meilisearch")) {
1570
- const res = await this.data("/x/meilisearch/search", { query: { q, limit } });
1571
- return { data: (res.hits ?? []).map(fromSearchDoc) };
1572
- }
1618
+ const found = await this.fromIndex({}, { page: 1, limit, search: q, wantsRange: false, hierarchy: [] });
1619
+ if (found) return { data: found.data };
1573
1620
  const rows = await this.data("/api/products", { query: { q, limit, channel: this.creds.channel } }) ?? [];
1574
1621
  return { data: rows.map((p) => toProduct(p)) };
1575
1622
  }
@@ -2686,6 +2733,24 @@ var AddressService = class extends BaseService {
2686
2733
  });
2687
2734
  return fromIdentityAddress(a, currentMe()?.email);
2688
2735
  }
2736
+ /**
2737
+ * The city and state for a postcode (D134), for the address form to fill
2738
+ * in. India's six-digit PIN codes only, from the directory the engine was
2739
+ * given; null for anything it cannot answer, so the form simply leaves the
2740
+ * fields to the shopper.
2741
+ */
2742
+ async lookupPostcode({ country = "IN", postcode }) {
2743
+ const code = String(postcode ?? "").trim();
2744
+ const cc = String(country ?? "").trim().toUpperCase();
2745
+ if (cc !== "IN" || !/^[1-9][0-9]{5}$/.test(code)) return null;
2746
+ try {
2747
+ const p = await this.data(`/api/postcodes/${cc}/${code}`);
2748
+ return { country: p.country, postcode: p.postcode, city: p.city, state: p.state, stateCode: p.state_code };
2749
+ } catch (err) {
2750
+ if (err instanceof GoCommerceError && (err.status === 404 || err.status === 400)) return null;
2751
+ throw err;
2752
+ }
2753
+ }
2689
2754
  async deleteAddress(id2) {
2690
2755
  await this.engine(`/x/identity/me/addresses/${enc(id2)}`, { method: "DELETE", auth: true });
2691
2756
  return { id: String(id2), deleted: true };
@@ -3704,6 +3769,6 @@ function attemptKey(request) {
3704
3769
  }
3705
3770
  var b2bService = new B2bService();
3706
3771
 
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 };
3772
+ 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 };
3708
3773
  //# sourceMappingURL=index.js.map
3709
3774
  //# sourceMappingURL=index.js.map