@misiki/gocommerce-connector 0.3.0 → 0.4.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.
@@ -1 +1 @@
1
- export { a as AddressService, c as Approval, e as AuthService, f as AutocompleteService, B as B2bPlaced, g as B2bRole, h as B2bService, i as BannerService, j as BaseService, k as BlogService, m as CartService, n as CatalogService, p as CategoryService, q as ChatService, t as CheckoutService, w as CollectionService, x as Company, y as CompanyOrder, z as ContactService, D as CountryService, E as CouponService, G as Credit, H as CurrencyService, J as DealService, K as DemoRequestService, L as EngineRequest, M as EnquiryService, P as FaqService, Q as FeedbackService, S as GalleryService, T as HomeService, V as InitService, W as Invitation, X as Lead, Z as MeilisearchService, _ as Member, a1 as MenuService, a4 as NewsletterService, a8 as OrderService, a9 as PageService, ab as PaymentMethodService, ad as PluginService, ad as PluginsService, ae as PopularSearchService, af as PopularityService, ai as ProductService, aj as ProfileService, ak as Quote, al as REDIRECT_GATEWAYS, am as ReelsService, an as RegionService, ao as RejectedLine, ar as ReviewService, au as SearchService, av as SettingService, av as SettingsService, ax as StateService, ay as StoreService, aA as StorefrontMenu, aD as UploadService, aE as UserService, aH as VariantService, aI as VarniCustomDesignService, aJ as VarniCustomProductService, aL as VendorService, aM as WarrantyService, aP as WishlistService, aQ as addressService, aR as authService, aS as autocompleteService, aT as b2bService, aU as bannerService, aV as blogService, aW as cartService, aX as categoryService, aY as chatService, aZ as checkoutService, a_ as collectionService, a$ as contactService, b0 as countryService, b1 as couponService, b3 as currencyService, b4 as dealService, b5 as demoRequestService, b7 as emptyPage, b8 as enquiryService, b9 as faqService, ba as feedbackService, be as galleryService, bf as homeService, bg as initService, bh as meilisearchService, bi as menuService, bk as newsletterService, bl as orderService, bm as pageService, bn as paymentMethodService, bo as pluginService, bp as pluginsService, bq as popularSearchService, br as popularityService, bu as productService, bv as profileService, bw as qs, bx as reelsService, by as regionService, bz as reviewService, bA as searchService, bB as settingService, bC as settingsService, bD as stateService, bE as staticStore, bF as storeService, bQ as toPage, bW as uploadService, bX as userService, bY as variantService, bZ as varniCustomDesignService, b_ as varniCustomProductService, b$ as vendorService, c0 as warrantyService, c1 as wishlistService } from '../index-BfbB3jQb.cjs';
1
+ export { a as AddressService, c as Approval, e as AuthService, f as AutocompleteService, B as B2bPlaced, g as B2bRole, h as B2bService, i as BannerService, j as BaseService, k as BlogService, m as CartService, n as CatalogService, p as CategoryService, q as ChatService, t as CheckoutService, w as CollectionService, x as Company, y as CompanyOrder, z as ContactService, D as CountryService, E as CouponService, G as Credit, H as CurrencyService, J as DealService, K as DemoRequestService, L as EngineRequest, M as EnquiryService, P as FaqService, Q as FeedbackService, S as GalleryService, T as HomeService, V as InitService, W as Invitation, X as Lead, Z as MeilisearchService, _ as Member, a1 as MenuService, a4 as NewsletterService, a8 as OrderService, a9 as PageService, ab as PaymentMethodService, ad as PluginService, ad as PluginsService, ae as PopularSearchService, af as PopularityService, ai as ProductService, aj as ProfileService, ak as Quote, al as REDIRECT_GATEWAYS, am as ReelsService, an as RegionService, ao as RejectedLine, ar as ReviewService, au as SearchService, av as SettingService, av as SettingsService, ax as StateService, ay as StoreService, aA as StorefrontMenu, aD as UploadService, aE as UserService, aH as VariantService, aI as VarniCustomDesignService, aJ as VarniCustomProductService, aL as VendorService, aM as WarrantyService, aP as WishlistService, aQ as addressService, aR as authService, aS as autocompleteService, aT as b2bService, aU as bannerService, aV as blogService, aW as cartService, aX as categoryService, aY as chatService, aZ as checkoutService, a_ as collectionService, a$ as contactService, b0 as countryService, b1 as couponService, b3 as currencyService, b4 as dealService, b5 as demoRequestService, b7 as emptyPage, b8 as enquiryService, b9 as faqService, ba as feedbackService, be as galleryService, bf as homeService, bg as initService, bh as mediaUrl, bi as meilisearchService, bj as menuService, bl as newsletterService, bm as orderService, bn as pageService, bo as paymentMethodService, bp as pluginService, bq as pluginsService, br as popularSearchService, bs as popularityService, bv as productService, bw as profileService, bx as qs, by as reelsService, bz as regionService, bA as reviewService, bB as searchService, bC as setRequestHost, bD as settingService, bE as settingsService, bF as stateService, bG as staticStore, bH as storeForHost, bI as storeService, bT as toPage, bZ as uploadService, b_ as userService, b$ as variantService, c0 as varniCustomDesignService, c1 as varniCustomProductService, c2 as vendorService, c3 as warrantyService, c4 as wishlistService } from '../index-iPG0fxzc.cjs';
@@ -1 +1 @@
1
- export { a as AddressService, c as Approval, e as AuthService, f as AutocompleteService, B as B2bPlaced, g as B2bRole, h as B2bService, i as BannerService, j as BaseService, k as BlogService, m as CartService, n as CatalogService, p as CategoryService, q as ChatService, t as CheckoutService, w as CollectionService, x as Company, y as CompanyOrder, z as ContactService, D as CountryService, E as CouponService, G as Credit, H as CurrencyService, J as DealService, K as DemoRequestService, L as EngineRequest, M as EnquiryService, P as FaqService, Q as FeedbackService, S as GalleryService, T as HomeService, V as InitService, W as Invitation, X as Lead, Z as MeilisearchService, _ as Member, a1 as MenuService, a4 as NewsletterService, a8 as OrderService, a9 as PageService, ab as PaymentMethodService, ad as PluginService, ad as PluginsService, ae as PopularSearchService, af as PopularityService, ai as ProductService, aj as ProfileService, ak as Quote, al as REDIRECT_GATEWAYS, am as ReelsService, an as RegionService, ao as RejectedLine, ar as ReviewService, au as SearchService, av as SettingService, av as SettingsService, ax as StateService, ay as StoreService, aA as StorefrontMenu, aD as UploadService, aE as UserService, aH as VariantService, aI as VarniCustomDesignService, aJ as VarniCustomProductService, aL as VendorService, aM as WarrantyService, aP as WishlistService, aQ as addressService, aR as authService, aS as autocompleteService, aT as b2bService, aU as bannerService, aV as blogService, aW as cartService, aX as categoryService, aY as chatService, aZ as checkoutService, a_ as collectionService, a$ as contactService, b0 as countryService, b1 as couponService, b3 as currencyService, b4 as dealService, b5 as demoRequestService, b7 as emptyPage, b8 as enquiryService, b9 as faqService, ba as feedbackService, be as galleryService, bf as homeService, bg as initService, bh as meilisearchService, bi as menuService, bk as newsletterService, bl as orderService, bm as pageService, bn as paymentMethodService, bo as pluginService, bp as pluginsService, bq as popularSearchService, br as popularityService, bu as productService, bv as profileService, bw as qs, bx as reelsService, by as regionService, bz as reviewService, bA as searchService, bB as settingService, bC as settingsService, bD as stateService, bE as staticStore, bF as storeService, bQ as toPage, bW as uploadService, bX as userService, bY as variantService, bZ as varniCustomDesignService, b_ as varniCustomProductService, b$ as vendorService, c0 as warrantyService, c1 as wishlistService } from '../index-BfbB3jQb.js';
1
+ export { a as AddressService, c as Approval, e as AuthService, f as AutocompleteService, B as B2bPlaced, g as B2bRole, h as B2bService, i as BannerService, j as BaseService, k as BlogService, m as CartService, n as CatalogService, p as CategoryService, q as ChatService, t as CheckoutService, w as CollectionService, x as Company, y as CompanyOrder, z as ContactService, D as CountryService, E as CouponService, G as Credit, H as CurrencyService, J as DealService, K as DemoRequestService, L as EngineRequest, M as EnquiryService, P as FaqService, Q as FeedbackService, S as GalleryService, T as HomeService, V as InitService, W as Invitation, X as Lead, Z as MeilisearchService, _ as Member, a1 as MenuService, a4 as NewsletterService, a8 as OrderService, a9 as PageService, ab as PaymentMethodService, ad as PluginService, ad as PluginsService, ae as PopularSearchService, af as PopularityService, ai as ProductService, aj as ProfileService, ak as Quote, al as REDIRECT_GATEWAYS, am as ReelsService, an as RegionService, ao as RejectedLine, ar as ReviewService, au as SearchService, av as SettingService, av as SettingsService, ax as StateService, ay as StoreService, aA as StorefrontMenu, aD as UploadService, aE as UserService, aH as VariantService, aI as VarniCustomDesignService, aJ as VarniCustomProductService, aL as VendorService, aM as WarrantyService, aP as WishlistService, aQ as addressService, aR as authService, aS as autocompleteService, aT as b2bService, aU as bannerService, aV as blogService, aW as cartService, aX as categoryService, aY as chatService, aZ as checkoutService, a_ as collectionService, a$ as contactService, b0 as countryService, b1 as couponService, b3 as currencyService, b4 as dealService, b5 as demoRequestService, b7 as emptyPage, b8 as enquiryService, b9 as faqService, ba as feedbackService, be as galleryService, bf as homeService, bg as initService, bh as mediaUrl, bi as meilisearchService, bj as menuService, bl as newsletterService, bm as orderService, bn as pageService, bo as paymentMethodService, bp as pluginService, bq as pluginsService, br as popularSearchService, bs as popularityService, bv as productService, bw as profileService, bx as qs, by as reelsService, bz as regionService, bA as reviewService, bB as searchService, bC as setRequestHost, bD as settingService, bE as settingsService, bF as stateService, bG as staticStore, bH as storeForHost, bI as storeService, bT as toPage, bZ as uploadService, b_ as userService, b$ as variantService, c0 as varniCustomDesignService, c1 as varniCustomProductService, c2 as vendorService, c3 as warrantyService, c4 as wishlistService } from '../index-iPG0fxzc.js';
@@ -189,6 +189,12 @@ var rememberWishlistToken = (token) => writeLocal(WISHLIST, token);
189
189
  var forgetWishlistToken = () => removeLocal(WISHLIST);
190
190
 
191
191
  // src/services/base.service.ts
192
+ function mediaUrl(url) {
193
+ if (!url) return null;
194
+ if (!url.startsWith("/") || url.startsWith("//")) return url;
195
+ const { apiUrl, proxyPath } = BaseService.getCredentials();
196
+ return (proxyPath || apiUrl || "").trim().replace(/\/+$/, "") + url;
197
+ }
192
198
  var BaseService = class _BaseService {
193
199
  static _credentials = { apiUrl: "" };
194
200
  _fetch;
@@ -204,6 +210,17 @@ var BaseService = class _BaseService {
204
210
  get creds() {
205
211
  return _BaseService._credentials;
206
212
  }
213
+ /**
214
+ * The store this call is for: the request host's subdomain under
215
+ * `baseDomain`, else the static `store`. Read per call, never stored on the
216
+ * instance, because the server shares one process (and one credentials
217
+ * object) across every concurrent request and each may be for a different host.
218
+ */
219
+ get store() {
220
+ const { baseDomain, store } = this.creds;
221
+ const host = typeof window !== "undefined" ? window.location?.hostname : requestHost?.();
222
+ return storeForHost(host, baseDomain) ?? store;
223
+ }
207
224
  /**
208
225
  * The engine's base URL from wherever this code runs. In the browser a
209
226
  * configured proxy path wins, because the engine answers no CORS preflight.
@@ -237,7 +254,8 @@ var BaseService = class _BaseService {
237
254
  const url = this.engineURL(path, lang ? { lang, ...req.query } : req.query);
238
255
  const headers = { Accept: "application/json", ...req.headers };
239
256
  if (req.body !== void 0) headers["Content-Type"] = "application/json";
240
- if (this.creds.store) headers["X-Store"] = this.creds.store;
257
+ const store = this.store;
258
+ if (store) headers["X-Store"] = store;
241
259
  if (req.auth) {
242
260
  const token = sessionToken();
243
261
  if (!token) throw new GoCommerceError("Please sign in to continue.", 401, "unauthorized");
@@ -339,6 +357,18 @@ var BaseService = class _BaseService {
339
357
  return body;
340
358
  }
341
359
  };
360
+ var requestHost;
361
+ function setRequestHost(fn) {
362
+ requestHost = fn;
363
+ }
364
+ function storeForHost(host, baseDomain) {
365
+ if (!host || !baseDomain) return void 0;
366
+ const h = host.toLowerCase().replace(/\.$/, "").replace(/:\d+$/, "");
367
+ const suffix = "." + baseDomain.toLowerCase().replace(/^\.+/, "").replace(/\.$/, "");
368
+ if (!h.endsWith(suffix)) return void 0;
369
+ const slug = h.slice(0, -suffix.length);
370
+ return slug && !slug.includes(".") ? slug : void 0;
371
+ }
342
372
  var unreachable = (base, cause) => new GoCommerceError(`Could not reach the commerce engine at ${base}: ${cause?.message ?? cause}`, 0);
343
373
  function qs(query) {
344
374
  if (!query) return "";
@@ -412,7 +442,8 @@ var liveVariants = (p) => arr(p.variants).filter((v) => v.active);
412
442
  function variantImages(v) {
413
443
  const out = [];
414
444
  for (const img of [v.image, ...arr(v.images)]) {
415
- if (img?.url && (img.kind ?? "image") === "image" && !out.includes(img.url)) out.push(img.url);
445
+ const url = mediaUrl(img?.url);
446
+ if (url && (img?.kind ?? "image") === "image" && !out.includes(url)) out.push(url);
416
447
  }
417
448
  return out;
418
449
  }
@@ -421,7 +452,7 @@ function productImages(p) {
421
452
  const push = (url) => {
422
453
  if (url && !out.includes(url)) out.push(url);
423
454
  };
424
- push(p.image_url);
455
+ push(mediaUrl(p.image_url));
425
456
  for (const v of arr(p.variants)) for (const url of variantImages(v)) push(url);
426
457
  return out;
427
458
  }
@@ -551,9 +582,9 @@ function fromSearchDoc(d) {
551
582
  mrp: price,
552
583
  minPrice: price,
553
584
  maxPrice: minorToMajor(d.price_max_minor, d.currency),
554
- thumbnail: d.image ?? null,
555
- image_url: d.image ?? null,
556
- images: d.image ?? "",
585
+ thumbnail: mediaUrl(d.image),
586
+ image_url: mediaUrl(d.image),
587
+ images: mediaUrl(d.image) ?? "",
557
588
  stock: d.in_stock ? 1 : 0,
558
589
  hasStock: d.in_stock,
559
590
  // The index cannot say how much is left, only whether any is; a card
@@ -582,7 +613,7 @@ function toCategory(c) {
582
613
  level: c.depth,
583
614
  rank: c.position,
584
615
  childCount: c.child_count,
585
- thumbnail: c.metadata?.image ?? null,
616
+ thumbnail: mediaUrl(c.metadata?.image),
586
617
  description: c.metadata?.description ?? null,
587
618
  isActive: true,
588
619
  isFeatured: false,
@@ -602,7 +633,7 @@ function toCollection(c) {
602
633
  description: c.description || null,
603
634
  subTitle: null,
604
635
  rank: str(c.position),
605
- thumbnail: c.metadata?.image ?? null,
636
+ thumbnail: mediaUrl(c.metadata?.image),
606
637
  isActive: true,
607
638
  metaTitle: c.title,
608
639
  metaDescription: c.description || null,
@@ -685,7 +716,7 @@ function toCartLine(l, extra = {}) {
685
716
  title: l.title,
686
717
  name: l.title,
687
718
  slug: extra.slug ?? "",
688
- thumbnail: extra.thumbnail ?? null,
719
+ thumbnail: mediaUrl(extra.thumbnail),
689
720
  variantTitle: l.variant_label ?? "",
690
721
  qty: l.quantity,
691
722
  price: toMajor(l.unit_price),
@@ -793,8 +824,8 @@ function toOrderLine(l, currency) {
793
824
  title: l.title,
794
825
  name: l.title,
795
826
  slug: "",
796
- thumbnail: l.image_url ?? null,
797
- img: l.image_url ?? null,
827
+ thumbnail: mediaUrl(l.image_url),
828
+ img: mediaUrl(l.image_url),
798
829
  variantTitle: l.variant_label ?? "",
799
830
  qty: l.quantity,
800
831
  shippedQty: l.shipped_quantity,
@@ -939,7 +970,7 @@ function remember(key, load, ttl = TTL_MS) {
939
970
  // src/services/facts.ts
940
971
  var StoreFacts = class extends BaseService {
941
972
  key(name) {
942
- return `${this.engineBase()}|${this.creds.store ?? ""}|${name}`;
973
+ return `${this.engineBase()}|${this.store ?? ""}|${name}`;
943
974
  }
944
975
  /** Enabled plugins by key. A module that is not installed has no key here. */
945
976
  plugins() {
@@ -1952,7 +1983,7 @@ var OrderService = class extends BaseService {
1952
1983
  productId: l.product_id,
1953
1984
  variantId: l.variant_id,
1954
1985
  title: l.title,
1955
- img: l.image_url ?? null,
1986
+ img: mediaUrl(l.image_url),
1956
1987
  price: toMajor(l.unit_price),
1957
1988
  qty: l.quantity
1958
1989
  });
@@ -2369,7 +2400,7 @@ var MenuService = class extends BaseService {
2369
2400
  /** The header and footer menus, or `null` when the module is not there. Cached: a menu is store-level. */
2370
2401
  async engineMenus() {
2371
2402
  if (!await this.facts.pluginOn("navigation")) return null;
2372
- return remember(`${this.engineBase()}|${this.creds.store ?? ""}|menus`, async () => {
2403
+ return remember(`${this.engineBase()}|${this.store ?? ""}|menus`, async () => {
2373
2404
  const out = [];
2374
2405
  for (const handle of ["header", "footer"]) {
2375
2406
  try {
@@ -2406,6 +2437,7 @@ var NewsletterService = class extends BaseService {
2406
2437
  var newsletterService = new NewsletterService();
2407
2438
 
2408
2439
  // src/services/store-service.ts
2440
+ var isStoreMissing = (err) => err instanceof GoCommerceError && err.status === 404 && (err.code === "store_not_found" || /store not found|no such store/i.test(err.message));
2409
2441
  function symbolFor(code) {
2410
2442
  try {
2411
2443
  const part = new Intl.NumberFormat("en", { style: "currency", currency: code }).formatToParts(0).find((p) => p.type === "currency");
@@ -2418,6 +2450,14 @@ var StoreService = class extends BaseService {
2418
2450
  facts = new StoreFacts(this._fetch);
2419
2451
  async getStoreByIdOrDomain(_args = {}) {
2420
2452
  const base = await readStaticStore();
2453
+ const store = this.store;
2454
+ if (store) {
2455
+ await this.facts.plugins().catch((err) => {
2456
+ if (isStoreMissing(err)) {
2457
+ throw new GoCommerceError(`store not found: no store "${store}" on this engine`, 404, "store_not_found");
2458
+ }
2459
+ });
2460
+ }
2421
2461
  const live = await this.live().catch(() => ({}));
2422
2462
  return { ...base, ...live, id: base.id || "gocommerce" };
2423
2463
  }
@@ -3053,6 +3093,6 @@ function attemptKey(request) {
3053
3093
  }
3054
3094
  var b2bService = new B2bService();
3055
3095
 
3056
- export { AddressService, AuthService, AutocompleteService, B2bService, BannerService, BaseService, BlogService, CartService, CatalogService, CategoryService, ChatService, CheckoutService, CollectionService, ContactService, CountryService, CouponService, CurrencyService, DealService, DemoRequestService, EnquiryService, FaqService, FeedbackService, GalleryService, HomeService, InitService, MeilisearchService, MenuService, NewsletterService, 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, collectionService, contactService, countryService, couponService, currencyService, dealService, demoRequestService, emptyPage, enquiryService, faqService, feedbackService, galleryService, homeService, initService, meilisearchService, menuService, newsletterService, orderService, pageService, paymentMethodService, pluginService, pluginsService, popularSearchService, popularityService, productService, profileService, qs, reelsService, regionService, reviewService, searchService, settingService, settingsService, stateService, staticStore, storeService, toPage, uploadService, userService, variantService, varniCustomDesignService, varniCustomProductService, vendorService, warrantyService, wishlistService };
3096
+ export { AddressService, AuthService, AutocompleteService, B2bService, BannerService, BaseService, BlogService, CartService, CatalogService, CategoryService, ChatService, CheckoutService, CollectionService, ContactService, CountryService, CouponService, CurrencyService, DealService, DemoRequestService, EnquiryService, FaqService, FeedbackService, GalleryService, HomeService, InitService, MeilisearchService, MenuService, NewsletterService, 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, collectionService, contactService, countryService, couponService, currencyService, dealService, demoRequestService, emptyPage, enquiryService, faqService, feedbackService, galleryService, homeService, initService, mediaUrl, meilisearchService, menuService, newsletterService, orderService, pageService, paymentMethodService, pluginService, pluginsService, popularSearchService, popularityService, productService, profileService, qs, reelsService, regionService, reviewService, searchService, setRequestHost, settingService, settingsService, stateService, staticStore, storeForHost, storeService, toPage, uploadService, userService, variantService, varniCustomDesignService, varniCustomProductService, vendorService, warrantyService, wishlistService };
3057
3097
  //# sourceMappingURL=index.js.map
3058
3098
  //# sourceMappingURL=index.js.map