@misiki/gocommerce-connector 0.3.1 → 0.4.1

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 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 settingService, bD as settingsService, bE as stateService, bF as staticStore, bG as storeService, bR as toPage, bX as uploadService, bY as userService, bZ as variantService, b_ as varniCustomDesignService, b$ as varniCustomProductService, c0 as vendorService, c1 as warrantyService, c2 as wishlistService } from '../index-D8lNRhqJ.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, az as StoreService, aB as StorefrontMenu, aE as UploadService, aF as UserService, aI as VariantService, aJ as VarniCustomDesignService, aK as VarniCustomProductService, aM as VendorService, aN as WarrantyService, aQ as WishlistService, aR as addressService, aS as authService, aT as autocompleteService, aU as b2bService, aV as bannerService, aW as blogService, aX as cartService, aY as categoryService, aZ as chatService, a_ as checkoutService, a$ as collectionService, b0 as contactService, b1 as countryService, b2 as couponService, b4 as currencyService, b5 as dealService, b6 as demoRequestService, b8 as emptyPage, b9 as enquiryService, ba as faqService, bb as feedbackService, bf as galleryService, bg as homeService, bh as initService, bi as mediaUrl, bj as meilisearchService, bk as menuService, bm as newsletterService, bn as orderService, bo as pageService, bp as paymentMethodService, bq as pluginService, br as pluginsService, bs as popularSearchService, bt as popularityService, bw as productService, bx as profileService, by as qs, bz as reelsService, bA as regionService, bB as reviewService, bC as searchService, bD as setRequestHost, bE as settingService, bF as settingsService, bG as stateService, bH as staticStore, bI as storeForHost, bJ as storeService, bU as toPage, b_ as uploadService, b$ as userService, c0 as variantService, c1 as varniCustomDesignService, c2 as varniCustomProductService, c3 as vendorService, c4 as warrantyService, c5 as wishlistService } from '../index-DIj1rK1d.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 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 settingService, bD as settingsService, bE as stateService, bF as staticStore, bG as storeService, bR as toPage, bX as uploadService, bY as userService, bZ as variantService, b_ as varniCustomDesignService, b$ as varniCustomProductService, c0 as vendorService, c1 as warrantyService, c2 as wishlistService } from '../index-D8lNRhqJ.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, az as StoreService, aB as StorefrontMenu, aE as UploadService, aF as UserService, aI as VariantService, aJ as VarniCustomDesignService, aK as VarniCustomProductService, aM as VendorService, aN as WarrantyService, aQ as WishlistService, aR as addressService, aS as authService, aT as autocompleteService, aU as b2bService, aV as bannerService, aW as blogService, aX as cartService, aY as categoryService, aZ as chatService, a_ as checkoutService, a$ as collectionService, b0 as contactService, b1 as countryService, b2 as couponService, b4 as currencyService, b5 as dealService, b6 as demoRequestService, b8 as emptyPage, b9 as enquiryService, ba as faqService, bb as feedbackService, bf as galleryService, bg as homeService, bh as initService, bi as mediaUrl, bj as meilisearchService, bk as menuService, bm as newsletterService, bn as orderService, bo as pageService, bp as paymentMethodService, bq as pluginService, br as pluginsService, bs as popularSearchService, bt as popularityService, bw as productService, bx as profileService, by as qs, bz as reelsService, bA as regionService, bB as reviewService, bC as searchService, bD as setRequestHost, bE as settingService, bF as settingsService, bG as stateService, bH as staticStore, bI as storeForHost, bJ as storeService, bU as toPage, b_ as uploadService, b$ as userService, c0 as variantService, c1 as varniCustomDesignService, c2 as varniCustomProductService, c3 as vendorService, c4 as warrantyService, c5 as wishlistService } from '../index-DIj1rK1d.js';
@@ -210,6 +210,17 @@ var BaseService = class _BaseService {
210
210
  get creds() {
211
211
  return _BaseService._credentials;
212
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
+ }
213
224
  /**
214
225
  * The engine's base URL from wherever this code runs. In the browser a
215
226
  * configured proxy path wins, because the engine answers no CORS preflight.
@@ -243,7 +254,8 @@ var BaseService = class _BaseService {
243
254
  const url = this.engineURL(path, lang ? { lang, ...req.query } : req.query);
244
255
  const headers = { Accept: "application/json", ...req.headers };
245
256
  if (req.body !== void 0) headers["Content-Type"] = "application/json";
246
- if (this.creds.store) headers["X-Store"] = this.creds.store;
257
+ const store = this.store;
258
+ if (store) headers["X-Store"] = store;
247
259
  if (req.auth) {
248
260
  const token = sessionToken();
249
261
  if (!token) throw new GoCommerceError("Please sign in to continue.", 401, "unauthorized");
@@ -345,6 +357,18 @@ var BaseService = class _BaseService {
345
357
  return body;
346
358
  }
347
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
+ }
348
372
  var unreachable = (base, cause) => new GoCommerceError(`Could not reach the commerce engine at ${base}: ${cause?.message ?? cause}`, 0);
349
373
  function qs(query) {
350
374
  if (!query) return "";
@@ -946,7 +970,7 @@ function remember(key, load, ttl = TTL_MS) {
946
970
  // src/services/facts.ts
947
971
  var StoreFacts = class extends BaseService {
948
972
  key(name) {
949
- return `${this.engineBase()}|${this.creds.store ?? ""}|${name}`;
973
+ return `${this.engineBase()}|${this.store ?? ""}|${name}`;
950
974
  }
951
975
  /** Enabled plugins by key. A module that is not installed has no key here. */
952
976
  plugins() {
@@ -966,6 +990,10 @@ var StoreFacts = class extends BaseService {
966
990
  ready() {
967
991
  return remember(this.key("ready"), () => this.data("/health/ready"));
968
992
  }
993
+ /** The store's own name and how a buyer reaches it, as set in its panel. */
994
+ profile() {
995
+ return remember(this.key("profile"), () => this.data("/api/store"));
996
+ }
969
997
  checkoutOptions() {
970
998
  return remember(this.key("checkout"), () => this.data("/api/checkout"));
971
999
  }
@@ -2376,7 +2404,7 @@ var MenuService = class extends BaseService {
2376
2404
  /** The header and footer menus, or `null` when the module is not there. Cached: a menu is store-level. */
2377
2405
  async engineMenus() {
2378
2406
  if (!await this.facts.pluginOn("navigation")) return null;
2379
- return remember(`${this.engineBase()}|${this.creds.store ?? ""}|menus`, async () => {
2407
+ return remember(`${this.engineBase()}|${this.store ?? ""}|menus`, async () => {
2380
2408
  const out = [];
2381
2409
  for (const handle of ["header", "footer"]) {
2382
2410
  try {
@@ -2413,6 +2441,7 @@ var NewsletterService = class extends BaseService {
2413
2441
  var newsletterService = new NewsletterService();
2414
2442
 
2415
2443
  // src/services/store-service.ts
2444
+ var isStoreMissing = (err) => err instanceof GoCommerceError && err.status === 404 && (err.code === "store_not_found" || /store not found|no such store/i.test(err.message));
2416
2445
  function symbolFor(code) {
2417
2446
  try {
2418
2447
  const part = new Intl.NumberFormat("en", { style: "currency", currency: code }).formatToParts(0).find((p) => p.type === "currency");
@@ -2425,6 +2454,14 @@ var StoreService = class extends BaseService {
2425
2454
  facts = new StoreFacts(this._fetch);
2426
2455
  async getStoreByIdOrDomain(_args = {}) {
2427
2456
  const base = await readStaticStore();
2457
+ const store = this.store;
2458
+ if (store) {
2459
+ await this.facts.plugins().catch((err) => {
2460
+ if (isStoreMissing(err)) {
2461
+ throw new GoCommerceError(`store not found: no store "${store}" on this engine`, 404, "store_not_found");
2462
+ }
2463
+ });
2464
+ }
2428
2465
  const live = await this.live().catch(() => ({}));
2429
2466
  return { ...base, ...live, id: base.id || "gocommerce" };
2430
2467
  }
@@ -2462,17 +2499,22 @@ var StoreService = class extends BaseService {
2462
2499
  return super.post(path, data);
2463
2500
  }
2464
2501
  async live() {
2465
- const [ready, plugins, menus, base] = await Promise.all([
2502
+ const [ready, plugins, menus, base, profile] = await Promise.all([
2466
2503
  this.facts.ready(),
2467
2504
  this.facts.plugins().catch(() => /* @__PURE__ */ new Map()),
2468
2505
  new MenuService(this._fetch).engineMenus(),
2469
- readStaticStore()
2506
+ readStaticStore(),
2507
+ this.facts.profile().catch(() => null)
2470
2508
  ]);
2471
2509
  const code = ready.currency;
2472
2510
  const sameCurrency = (base.currency?.code ?? base.currencyCode) === code;
2473
2511
  const flag = (on) => ({ ...on ? { active: true } : { active: false } });
2474
2512
  const basePlugins = base.plugins ?? {};
2475
2513
  return {
2514
+ // Only what the owner filled in: an empty name keeps the static one.
2515
+ ...profile?.name ? { name: profile.name } : {},
2516
+ ...profile?.email ? { businessEmail: profile.email } : {},
2517
+ ...profile?.phone ? { businessPhone: profile.phone } : {},
2476
2518
  currencyCode: code,
2477
2519
  currencySymbol: sameCurrency ? base.currencySymbol ?? symbolFor(code) : symbolFor(code),
2478
2520
  currency: {
@@ -3060,6 +3102,6 @@ function attemptKey(request) {
3060
3102
  }
3061
3103
  var b2bService = new B2bService();
3062
3104
 
3063
- 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, settingService, settingsService, stateService, staticStore, storeService, toPage, uploadService, userService, variantService, varniCustomDesignService, varniCustomProductService, vendorService, warrantyService, wishlistService };
3105
+ 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 };
3064
3106
  //# sourceMappingURL=index.js.map
3065
3107
  //# sourceMappingURL=index.js.map