@misiki/gocommerce-connector 0.9.0 → 0.10.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 Faq, P as FaqService, Q as FeedbackService, R as Fulfillment, S as GalleryService, T as HomeLayout, U as HomeLayoutSection, V as HomeService, W as IdentityAddress, X as InitService, Y as Invitation, Z as LayoutCollection, _ as LayoutPage, $ as LayoutService, a0 as Lead, a1 as ListMeta, a2 as MeilisearchService, a3 as Member, a4 as Menu, a5 as MenuItem, a6 as MenuService, a7 as MenuSummary, a8 as Money, a9 as NewsletterService, aa as Offer, ab as Order, ac as OrderLine, ad as OrderService, ae as PageLayout, af as PageService, ag as PaymentIntent, ah as PaymentMethodService, ai as Plugin, aj as PluginService, aj as PluginsService, ak as PopularSearchService, al as PopularityService, am as Product, an as ProductOption, ao as ProductService, ap as ProfileService, aq as Quote, ar as REDIRECT_GATEWAYS, as as ReelsService, at as RegionService, au as RejectedLine, av as Review, aw as ReviewPage, ax as ReviewService, ay as SearchDoc, az as SearchResult, aA as SearchService, aB as SettingService, aB as SettingsService, aC as ShippingRate, aD as StateService, aE as StoreProfile, aF as StoreService, aG as StorefrontCategory, aH as StorefrontMenu, aI as StorefrontOrder, aJ as StorefrontProduct, aK as ThemeSettings, aL as ThemeSettingsResult, aM as UploadService, aN as UserService, aO as Variant, aP as VariantImage, aQ as VariantService, aR as VarniCustomDesignService, aS as VarniCustomProductService, aT as Vendor, aU as VendorService, aV as WarrantyService, aW as Wishlist, aX as WishlistItem, aY as WishlistService, aZ as addressService, a_ as authService, a$ as autocompleteService, b0 as b2bService, b1 as bannerService, b2 as blogService, b3 as cartService, b4 as categoryService, b5 as chatService, b6 as checkoutService, b7 as collectionService, b8 as contactService, b9 as countryService, ba as couponService, bb as currencyExponent, bc as currencyService, bd as dealService, be as demoRequestService, bf as emptyCart, bg as emptyPage, bh as enquiryService, bi as faqService, bj as feedbackService, bk as fromEngineAddress, bl as fromIdentityAddress, bm as fromSearchDoc, bn as galleryService, bo as homeService, bp as initService, bq as layoutService, br as mediaUrl, bs as meilisearchService, bt as menuService, bu as minorToMajor, bv as newsletterService, bw as orderService, bx as ownDomain, by as pageService, bz as paymentMethodService, bA as pluginService, bB as pluginsService, bC as popularSearchService, bD as popularityService, bE as priceOf, bF as productImages, bG as productService, bH as profileService, bI as qs, bJ as reelsService, bK as regionService, bL as reviewService, bM as searchService, bN as setRequestHost, bO as settingService, bP as settingsService, bQ as stateService, bR as staticStore, bS as storeForHost, bT as storeService, bU as toCart, bV as toCartLine, bW as toCategory, bX as toCmsPage, bY as toCollection, bZ as toEngineAddress, b_ as toIdentityAddress, b$ as toMajor, c0 as toMinor, c1 as toOrder, c2 as toPage, c3 as toProduct, c4 as toRating, c5 as toUser, c6 as toVariant, c7 as toVendor, c8 as uploadService, c9 as userService, ca as variantService, cb as varniCustomDesignService, cc as varniCustomProductService, cd as vendorService, ce as warrantyService, cf as wishlistService } from './index-72kQMxjZ.cjs';
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 Fulfillment, T as GalleryService, U as HomeLayout, V as HomeLayoutSection, W as HomeService, X as IdentityAddress, Y as InitService, Z as Invitation, _ as LayoutCollection, $ as LayoutPage, a0 as LayoutService, a1 as Lead, a2 as ListMeta, a3 as MeilisearchService, a4 as Member, a5 as Menu, a6 as MenuItem, a7 as MenuService, a8 as MenuSummary, a9 as Money, aa as NewsletterService, ab as Offer, ac as Order, ad as OrderLine, ae as OrderService, af as PageLayout, ag as PageService, ah as PaymentIntent, ai as PaymentMethodService, aj as Plugin, ak as PluginService, ak as PluginsService, al as PopularSearchService, am as PopularityService, an as Product, ao as ProductFacets, ap as ProductOption, aq as ProductService, ar as ProfileService, as as Quote, at as REDIRECT_GATEWAYS, au as ReelsService, av as RegionService, aw as RejectedLine, ax as Review, ay as ReviewPage, az as ReviewService, aA as SearchDoc, aB as SearchResult, aC as SearchService, aD as SettingService, aD as SettingsService, aE as ShippingRate, aF as StateService, aG as StoreProfile, aH as StoreService, aI as StorefrontCategory, aJ as StorefrontMenu, aK as StorefrontOrder, aL as StorefrontProduct, aM as ThemeSettings, aN as ThemeSettingsResult, aO as UploadService, aP as UserService, aQ as Variant, aR as VariantImage, aS as VariantService, aT as VarniCustomDesignService, aU as VarniCustomProductService, aV as Vendor, aW as VendorService, aX as WarrantyService, aY as Wishlist, aZ as WishlistItem, a_ as WishlistService, a$ as addressService, b0 as authService, b1 as autocompleteService, b2 as b2bService, b3 as bannerService, b4 as blogService, b5 as cartService, b6 as categoryService, b7 as chatService, b8 as checkoutService, b9 as collectionService, ba as contactService, bb as countryService, bc as couponService, bd as currencyExponent, be as currencyService, bf as dealService, bg as demoRequestService, bh as emptyCart, bi as emptyPage, bj as enquiryService, bk as faqService, bl as feedbackService, bm as fromEngineAddress, bn as fromIdentityAddress, bo as fromSearchDoc, bp as galleryService, bq as homeService, br as initService, bs as layoutService, bt as mediaUrl, bu as meilisearchService, bv as menuService, bw as minorToMajor, bx as newsletterService, by as orderService, bz as ownDomain, bA as pageService, bB as paymentMethodService, bC as pluginService, bD as pluginsService, bE as popularSearchService, bF as popularityService, bG as priceOf, bH as productImages, bI as productService, bJ as profileService, bK as qs, bL as reelsService, bM as regionService, bN as reviewService, bO as searchService, bP as setRequestHost, bQ as settingService, bR as settingsService, bS as stateService, bT as staticStore, bU as storeForHost, bV as storeService, bW as toCart, bX as toCartLine, bY as toCategory, bZ as toCmsPage, b_ as toCollection, b$ as toEngineAddress, c0 as toIdentityAddress, c1 as toMajor, c2 as toMinor, c3 as toOrder, c4 as toPage, c5 as toProduct, c6 as toRating, c7 as toStorefrontFacets, c8 as toUser, c9 as toVariant, ca as toVendor, cb as uploadService, cc as userService, cd as variantService, ce as varniCustomDesignService, cf as varniCustomProductService, cg as vendorService, ch as warrantyService, ci as wishlistService } from './index-mqcHZ96i.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 Faq, P as FaqService, Q as FeedbackService, R as Fulfillment, S as GalleryService, T as HomeLayout, U as HomeLayoutSection, V as HomeService, W as IdentityAddress, X as InitService, Y as Invitation, Z as LayoutCollection, _ as LayoutPage, $ as LayoutService, a0 as Lead, a1 as ListMeta, a2 as MeilisearchService, a3 as Member, a4 as Menu, a5 as MenuItem, a6 as MenuService, a7 as MenuSummary, a8 as Money, a9 as NewsletterService, aa as Offer, ab as Order, ac as OrderLine, ad as OrderService, ae as PageLayout, af as PageService, ag as PaymentIntent, ah as PaymentMethodService, ai as Plugin, aj as PluginService, aj as PluginsService, ak as PopularSearchService, al as PopularityService, am as Product, an as ProductOption, ao as ProductService, ap as ProfileService, aq as Quote, ar as REDIRECT_GATEWAYS, as as ReelsService, at as RegionService, au as RejectedLine, av as Review, aw as ReviewPage, ax as ReviewService, ay as SearchDoc, az as SearchResult, aA as SearchService, aB as SettingService, aB as SettingsService, aC as ShippingRate, aD as StateService, aE as StoreProfile, aF as StoreService, aG as StorefrontCategory, aH as StorefrontMenu, aI as StorefrontOrder, aJ as StorefrontProduct, aK as ThemeSettings, aL as ThemeSettingsResult, aM as UploadService, aN as UserService, aO as Variant, aP as VariantImage, aQ as VariantService, aR as VarniCustomDesignService, aS as VarniCustomProductService, aT as Vendor, aU as VendorService, aV as WarrantyService, aW as Wishlist, aX as WishlistItem, aY as WishlistService, aZ as addressService, a_ as authService, a$ as autocompleteService, b0 as b2bService, b1 as bannerService, b2 as blogService, b3 as cartService, b4 as categoryService, b5 as chatService, b6 as checkoutService, b7 as collectionService, b8 as contactService, b9 as countryService, ba as couponService, bb as currencyExponent, bc as currencyService, bd as dealService, be as demoRequestService, bf as emptyCart, bg as emptyPage, bh as enquiryService, bi as faqService, bj as feedbackService, bk as fromEngineAddress, bl as fromIdentityAddress, bm as fromSearchDoc, bn as galleryService, bo as homeService, bp as initService, bq as layoutService, br as mediaUrl, bs as meilisearchService, bt as menuService, bu as minorToMajor, bv as newsletterService, bw as orderService, bx as ownDomain, by as pageService, bz as paymentMethodService, bA as pluginService, bB as pluginsService, bC as popularSearchService, bD as popularityService, bE as priceOf, bF as productImages, bG as productService, bH as profileService, bI as qs, bJ as reelsService, bK as regionService, bL as reviewService, bM as searchService, bN as setRequestHost, bO as settingService, bP as settingsService, bQ as stateService, bR as staticStore, bS as storeForHost, bT as storeService, bU as toCart, bV as toCartLine, bW as toCategory, bX as toCmsPage, bY as toCollection, bZ as toEngineAddress, b_ as toIdentityAddress, b$ as toMajor, c0 as toMinor, c1 as toOrder, c2 as toPage, c3 as toProduct, c4 as toRating, c5 as toUser, c6 as toVariant, c7 as toVendor, c8 as uploadService, c9 as userService, ca as variantService, cb as varniCustomDesignService, cc as varniCustomProductService, cd as vendorService, ce as warrantyService, cf as wishlistService } from './index-72kQMxjZ.js';
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 Fulfillment, T as GalleryService, U as HomeLayout, V as HomeLayoutSection, W as HomeService, X as IdentityAddress, Y as InitService, Z as Invitation, _ as LayoutCollection, $ as LayoutPage, a0 as LayoutService, a1 as Lead, a2 as ListMeta, a3 as MeilisearchService, a4 as Member, a5 as Menu, a6 as MenuItem, a7 as MenuService, a8 as MenuSummary, a9 as Money, aa as NewsletterService, ab as Offer, ac as Order, ad as OrderLine, ae as OrderService, af as PageLayout, ag as PageService, ah as PaymentIntent, ai as PaymentMethodService, aj as Plugin, ak as PluginService, ak as PluginsService, al as PopularSearchService, am as PopularityService, an as Product, ao as ProductFacets, ap as ProductOption, aq as ProductService, ar as ProfileService, as as Quote, at as REDIRECT_GATEWAYS, au as ReelsService, av as RegionService, aw as RejectedLine, ax as Review, ay as ReviewPage, az as ReviewService, aA as SearchDoc, aB as SearchResult, aC as SearchService, aD as SettingService, aD as SettingsService, aE as ShippingRate, aF as StateService, aG as StoreProfile, aH as StoreService, aI as StorefrontCategory, aJ as StorefrontMenu, aK as StorefrontOrder, aL as StorefrontProduct, aM as ThemeSettings, aN as ThemeSettingsResult, aO as UploadService, aP as UserService, aQ as Variant, aR as VariantImage, aS as VariantService, aT as VarniCustomDesignService, aU as VarniCustomProductService, aV as Vendor, aW as VendorService, aX as WarrantyService, aY as Wishlist, aZ as WishlistItem, a_ as WishlistService, a$ as addressService, b0 as authService, b1 as autocompleteService, b2 as b2bService, b3 as bannerService, b4 as blogService, b5 as cartService, b6 as categoryService, b7 as chatService, b8 as checkoutService, b9 as collectionService, ba as contactService, bb as countryService, bc as couponService, bd as currencyExponent, be as currencyService, bf as dealService, bg as demoRequestService, bh as emptyCart, bi as emptyPage, bj as enquiryService, bk as faqService, bl as feedbackService, bm as fromEngineAddress, bn as fromIdentityAddress, bo as fromSearchDoc, bp as galleryService, bq as homeService, br as initService, bs as layoutService, bt as mediaUrl, bu as meilisearchService, bv as menuService, bw as minorToMajor, bx as newsletterService, by as orderService, bz as ownDomain, bA as pageService, bB as paymentMethodService, bC as pluginService, bD as pluginsService, bE as popularSearchService, bF as popularityService, bG as priceOf, bH as productImages, bI as productService, bJ as profileService, bK as qs, bL as reelsService, bM as regionService, bN as reviewService, bO as searchService, bP as setRequestHost, bQ as settingService, bR as settingsService, bS as stateService, bT as staticStore, bU as storeForHost, bV as storeService, bW as toCart, bX as toCartLine, bY as toCategory, bZ as toCmsPage, b_ as toCollection, b$ as toEngineAddress, c0 as toIdentityAddress, c1 as toMajor, c2 as toMinor, c3 as toOrder, c4 as toPage, c5 as toProduct, c6 as toRating, c7 as toStorefrontFacets, c8 as toUser, c9 as toVariant, ca as toVendor, cb as uploadService, cc as userService, cd as variantService, ce as varniCustomDesignService, cf as varniCustomProductService, cg as vendorService, ch as warrantyService, ci as wishlistService } from './index-mqcHZ96i.js';
2
2
 
3
3
  /**
4
4
  * The two ways a call through this connector fails.
package/dist/index.js CHANGED
@@ -1084,11 +1084,14 @@ var StoreFacts = class extends BaseService {
1084
1084
 
1085
1085
  // src/services/catalog.ts
1086
1086
  var PAGE_SIZE = 24;
1087
- function indexSort(sort) {
1088
- if (!sort) return void 0;
1087
+ function sortParts(sort) {
1089
1088
  const s = sort.trim();
1090
1089
  const [field, dir] = s.startsWith("-") ? [s.slice(1), "desc"] : s.includes(":") ? s.split(":") : [s, "asc"];
1091
- const d = dir === "desc" ? "desc" : "asc";
1090
+ return [field, dir === "desc" ? "desc" : "asc"];
1091
+ }
1092
+ function indexSort(sort) {
1093
+ if (!sort) return void 0;
1094
+ const [field, d] = sortParts(sort);
1092
1095
  switch (field) {
1093
1096
  case "price":
1094
1097
  return `price_minor:${d}`;
@@ -1104,6 +1107,20 @@ function indexSort(sort) {
1104
1107
  return void 0;
1105
1108
  }
1106
1109
  }
1110
+ function engineSort(sort) {
1111
+ if (!sort || NATURAL.has(sort)) return {};
1112
+ const [field, order] = sortParts(sort);
1113
+ const key = {
1114
+ price: "price",
1115
+ createdAt: "created_at",
1116
+ created_at: "created_at",
1117
+ updatedAt: "updated_at",
1118
+ updated_at: "updated_at",
1119
+ title: "title",
1120
+ name: "title"
1121
+ }[field];
1122
+ return key ? { sort: key, order } : {};
1123
+ }
1107
1124
  var NATURAL = /* @__PURE__ */ new Set([
1108
1125
  "-createdAt",
1109
1126
  "createdAt:desc",
@@ -1113,6 +1130,7 @@ var NATURAL = /* @__PURE__ */ new Set([
1113
1130
  "popularity:desc"
1114
1131
  ]);
1115
1132
  var quote = (s) => `"${s.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
1133
+ var legacyListing = /* @__PURE__ */ new Set();
1116
1134
  var CatalogService = class extends BaseService {
1117
1135
  facts = new StoreFacts(this._fetch);
1118
1136
  async queryCatalog(q) {
@@ -1122,6 +1140,39 @@ var CatalogService = class extends BaseService {
1122
1140
  const wantsRange = Number.isFinite(q.priceFrom) || Number.isFinite(q.priceTo);
1123
1141
  const sortKey = q.sort && !NATURAL.has(q.sort) ? indexSort(q.sort) : void 0;
1124
1142
  const hierarchy = q.category ? await this.facts.hierarchy(q.category) : [];
1143
+ const attr = Object.entries(q.attributes ?? {}).flatMap(
1144
+ ([handle, values]) => values.filter(Boolean).map((v) => `${handle}:${v}`)
1145
+ );
1146
+ if (q.facets && !legacyListing.has(this.engineBase())) {
1147
+ const { currency } = await this.facts.ready();
1148
+ const minor = (n) => Number.isFinite(n) ? Math.max(0, toMinor(n, currency)) : void 0;
1149
+ const env2 = await this.engine("/api/products", {
1150
+ query: {
1151
+ q: search,
1152
+ page,
1153
+ limit,
1154
+ channel: this.creds.channel,
1155
+ category: q.category,
1156
+ tag: q.tags,
1157
+ vendor: q.vendors,
1158
+ product_type: q.productTypes,
1159
+ attr,
1160
+ price_min: minor(q.priceFrom),
1161
+ price_max: minor(q.priceTo),
1162
+ ...engineSort(q.sort),
1163
+ facets: 1
1164
+ }
1165
+ });
1166
+ if (env2.meta?.facets) {
1167
+ return {
1168
+ ...toPage(env2, (p) => toProduct(p)),
1169
+ categoryHierarchy: hierarchy,
1170
+ sorted: true,
1171
+ facets: env2.meta.facets
1172
+ };
1173
+ }
1174
+ legacyListing.add(this.engineBase());
1175
+ }
1125
1176
  if ((sortKey || wantsRange) && await this.facts.pluginOn("meilisearch")) {
1126
1177
  const filters = [];
1127
1178
  if (q.category) {
@@ -1169,9 +1220,6 @@ var CatalogService = class extends BaseService {
1169
1220
  sorted
1170
1221
  };
1171
1222
  }
1172
- const attr = Object.entries(q.attributes ?? {}).flatMap(
1173
- ([handle, values]) => values.filter(Boolean).map((v) => `${handle}:${v}`)
1174
- );
1175
1223
  const env = await this.engine("/api/products", {
1176
1224
  query: { q: search, page, limit, channel: this.creds.channel, attr }
1177
1225
  });
@@ -1239,17 +1287,46 @@ var ProductService = class extends CatalogService {
1239
1287
  async listTrendingProducts({ page = 1, limit } = {}) {
1240
1288
  return this.shelf("trending", { page, limit });
1241
1289
  }
1242
- /** More from this product's category. */
1290
+ /**
1291
+ * More like this product. Given `product` (a slug or id), it is the
1292
+ * product's category first, then its collections, then the newest — never
1293
+ * the product itself. Many shops never fill in categories, and an empty
1294
+ * rail under every product page reads as a broken shop.
1295
+ *
1296
+ * Without `product`, it is the old answer: more from `categoryId`.
1297
+ */
1243
1298
  async listRelatedProducts({
1244
1299
  page = 1,
1245
1300
  categoryId,
1301
+ product,
1246
1302
  limit
1247
1303
  } = {}) {
1304
+ if (product) return this.relatedTo(String(product), limit);
1248
1305
  if (!categoryId) return this.list({ page, limit });
1249
1306
  const category = (await this.facts.categories()).find((c) => String(c.id) === String(categoryId));
1250
1307
  if (!category) return this.list({ page, limit });
1251
1308
  return this.list({ page, limit, categories: category.slug });
1252
1309
  }
1310
+ async relatedTo(slug, limit) {
1311
+ const size = Math.min(100, Math.max(1, Number(limit) || PAGE_SIZE));
1312
+ const p = await this.findProduct(slug);
1313
+ const self = String(p.id);
1314
+ const picked = /* @__PURE__ */ new Map();
1315
+ const add = (rows) => {
1316
+ for (const r of rows) {
1317
+ if (picked.size >= size) return;
1318
+ if (r.id !== self && !picked.has(r.id)) picked.set(r.id, r);
1319
+ }
1320
+ };
1321
+ if (p.category) add((await this.list({ limit: size + 1, categories: p.category.slug })).data);
1322
+ for (const c of p.collections ?? []) {
1323
+ if (picked.size >= size) break;
1324
+ add((await this.shelf(c.slug, { page: 1, limit: size + 1 })).data);
1325
+ }
1326
+ if (picked.size < size) add((await this.list({ limit: size + 1 })).data);
1327
+ const data = [...picked.values()];
1328
+ return { data, count: data.length, pageSize: size, noOfPage: 1, page: 1 };
1329
+ }
1253
1330
  async shelf(slug, { page, sort, limit }) {
1254
1331
  const size = Math.min(100, Math.max(1, Number(limit) || PAGE_SIZE));
1255
1332
  try {
@@ -1308,16 +1385,44 @@ var num = (v) => {
1308
1385
  const n = Number(v);
1309
1386
  return Number.isFinite(n) ? n : void 0;
1310
1387
  };
1388
+ function decodeOnce(v) {
1389
+ try {
1390
+ return decodeURIComponent(v);
1391
+ } catch {
1392
+ return v;
1393
+ }
1394
+ }
1395
+ function listParam(p, key) {
1396
+ const out = p.getAll(key).flatMap((v) => decodeOnce(v).split(",")).map((v) => v.trim()).filter(Boolean);
1397
+ return out.length ? out : void 0;
1398
+ }
1311
1399
  function attributesFrom(p) {
1312
1400
  const out = {};
1313
- for (const [key, value] of p) {
1401
+ for (const key of new Set(p.keys())) {
1314
1402
  if (!key.startsWith("attributes.")) continue;
1315
1403
  const handle = key.slice("attributes.".length);
1316
- const values = value.split(",").map((v) => decodeURIComponent(v).trim()).filter(Boolean);
1317
- if (handle && values.length) out[handle] = [...out[handle] ?? [], ...values];
1404
+ const values = listParam(p, key);
1405
+ if (handle && values) out[handle] = values;
1318
1406
  }
1319
1407
  return Object.keys(out).length ? out : void 0;
1320
1408
  }
1409
+ var counts = (values) => Object.fromEntries((values ?? []).map((v) => [v.value, v.count]));
1410
+ function toStorefrontFacets(f) {
1411
+ if (!f) return { priceStat: {}, categories: [], tags: [], allFilters: {} };
1412
+ const allFilters = {};
1413
+ const group = (key, values) => {
1414
+ if (values?.length) allFilters[key] = counts(values);
1415
+ };
1416
+ group("vendor", f.vendors);
1417
+ group("product_type", f.product_types);
1418
+ for (const [handle, values] of Object.entries(f.attributes ?? {})) group(`attributes.${handle}`, values);
1419
+ return {
1420
+ priceStat: f.price ? { min: toMajor(f.price.min), max: toMajor(f.price.max) } : {},
1421
+ categories: (f.categories ?? []).map((c) => ({ name: c.title, slug: c.slug, count: c.count })),
1422
+ tags: (f.tags ?? []).map((t) => ({ name: t.value, count: t.count })),
1423
+ allFilters
1424
+ };
1425
+ }
1321
1426
  var SearchService = class extends CatalogService {
1322
1427
  emptyResult() {
1323
1428
  return {
@@ -1325,7 +1430,7 @@ var SearchService = class extends CatalogService {
1325
1430
  count: 0,
1326
1431
  totalPages: 0,
1327
1432
  categoryHierarchy: [],
1328
- facets: { priceStat: {}, categories: [], tags: [], allFilters: {} }
1433
+ facets: toStorefrontFacets()
1329
1434
  };
1330
1435
  }
1331
1436
  async searchWithUrl(url, slug) {
@@ -1340,7 +1445,11 @@ var SearchService = class extends CatalogService {
1340
1445
  category: slug || p.get("categories")?.split(",")[0] || void 0,
1341
1446
  priceFrom: num(p.get("priceFrom")) ?? num(from ?? null),
1342
1447
  priceTo: num(p.get("priceTo")) ?? num(to ?? null),
1343
- attributes: attributesFrom(p)
1448
+ attributes: attributesFrom(p),
1449
+ tags: listParam(p, "tags"),
1450
+ vendors: listParam(p, "vendor"),
1451
+ productTypes: listParam(p, "product_type"),
1452
+ facets: true
1344
1453
  });
1345
1454
  return {
1346
1455
  data: res.data,
@@ -1348,7 +1457,7 @@ var SearchService = class extends CatalogService {
1348
1457
  totalPages: res.noOfPage,
1349
1458
  page: res.page,
1350
1459
  categoryHierarchy: res.categoryHierarchy,
1351
- facets: { priceStat: {}, categories: [], tags: [], allFilters: {} }
1460
+ facets: toStorefrontFacets(res.facets)
1352
1461
  };
1353
1462
  } catch (err) {
1354
1463
  if (err?.status === 404) return this.emptyResult();
@@ -3374,6 +3483,6 @@ function attemptKey(request) {
3374
3483
  }
3375
3484
  var b2bService = new B2bService();
3376
3485
 
3377
- 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, toUser, toVariant, toVendor, uploadService, userService, variantService, varniCustomDesignService, varniCustomProductService, vendorService, warrantyService, wishlistService };
3486
+ 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 };
3378
3487
  //# sourceMappingURL=index.js.map
3379
3488
  //# sourceMappingURL=index.js.map