@misiki/gocommerce-connector 0.4.2 → 0.4.3

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/README.md CHANGED
@@ -86,7 +86,10 @@ to the domain the engine hands out subdomains of and point every
86
86
  `<slug>.<base domain>` at the one deployment: a request for `acme.shopnx.in` is
87
87
  sent to the engine with `X-Store: acme`, by the same rule the engine applies to
88
88
  its own host (one label, case-insensitive, a port ignored). A host outside the
89
- base domain falls back to `PUBLIC_GOCOMMERCE_STORE`, or to no store at all.
89
+ base domain falls back to `PUBLIC_GOCOMMERCE_STORE`; without one it is sent as
90
+ it is, `X-Store: chillish.in`, which the engine answers when a store has added
91
+ and verified that domain. Point a store's own domain at this deployment and it
92
+ shows that store.
90
93
 
91
94
  The browser knows its own host. The server does not, so tell the connector where
92
95
  to read it, once, from `src/hooks.server.ts`:
@@ -1183,9 +1183,11 @@ declare class BaseService {
1183
1183
  protected get creds(): Credentials;
1184
1184
  /**
1185
1185
  * The store this call is for: the request host's subdomain under
1186
- * `baseDomain`, else the static `store`. Read per call, never stored on the
1187
- * instance, because the server shares one process (and one credentials
1188
- * object) across every concurrent request and each may be for a different host.
1186
+ * `baseDomain`, else the static `store`, else the host itself when it is a
1187
+ * store's own domain (the engine answers only a verified one). Read per call,
1188
+ * never stored on the instance, because the server shares one process (and
1189
+ * one credentials object) across every concurrent request and each may be
1190
+ * for a different host.
1189
1191
  */
1190
1192
  protected get store(): string | undefined;
1191
1193
  /**
@@ -1238,6 +1240,13 @@ declare function setRequestHost(fn: () => string | undefined): void;
1238
1240
  * `shopnx.in` itself name no store.
1239
1241
  */
1240
1242
  declare function storeForHost(host: string | undefined, baseDomain: string | undefined): string | undefined;
1243
+ /**
1244
+ * A host outside `baseDomain` is a store's own domain, such as `chillish.in`,
1245
+ * which the engine looks up among its verified domains. Only a storefront
1246
+ * serving many stores (one with a `baseDomain`) passes it on; the base domain
1247
+ * itself, `localhost` and bare addresses are nobody's.
1248
+ */
1249
+ declare function ownDomain(host: string | undefined, baseDomain: string | undefined): string | undefined;
1241
1250
  /** `?a=1&b=2`, dropping what was not asked for. Arrays repeat the key. */
1242
1251
  declare function qs(query?: Query): string;
1243
1252
  /** The family's list shape, from the engine's `{data, meta}`. Totals are the engine's, never invented. */
@@ -6506,4 +6515,4 @@ declare class B2bService extends BaseService {
6506
6515
  }
6507
6516
  declare const b2bService: B2bService;
6508
6517
 
6509
- export { type Menu as $, type Address as A, type B2bPlaced as B, type Cart as C, CountryService as D, CouponService as E, type Credentials as F, type Credit as G, CurrencyService as H, type Customer as I, DealService as J, DemoRequestService as K, type EngineRequest as L, EnquiryService as M, type Envelope as N, type Faq as O, FaqService as P, FeedbackService as Q, type Fulfillment as R, GalleryService as S, HomeService as T, type IdentityAddress as U, InitService as V, type Invitation as W, type Lead as X, type ListMeta as Y, MeilisearchService as Z, type Member as _, AddressService as a, collectionService as a$, type MenuItem as a0, MenuService as a1, type MenuSummary as a2, type Money as a3, NewsletterService as a4, type Offer as a5, type Order as a6, type OrderLine as a7, OrderService as a8, PageService as a9, type StorefrontCategory as aA, type StorefrontMenu as aB, type StorefrontOrder as aC, type StorefrontProduct as aD, UploadService as aE, UserService as aF, type Variant as aG, type VariantImage as aH, VariantService as aI, VarniCustomDesignService as aJ, VarniCustomProductService as aK, type Vendor as aL, VendorService as aM, WarrantyService as aN, type Wishlist as aO, type WishlistItem as aP, WishlistService as aQ, addressService as aR, authService as aS, autocompleteService as aT, b2bService as aU, bannerService as aV, blogService as aW, cartService as aX, categoryService as aY, chatService as aZ, checkoutService as a_, type PaymentIntent as aa, PaymentMethodService as ab, type Plugin as ac, PluginService as ad, PopularSearchService as ae, PopularityService as af, type Product as ag, type ProductOption as ah, ProductService as ai, ProfileService as aj, type Quote as ak, REDIRECT_GATEWAYS as al, ReelsService as am, RegionService as an, type RejectedLine as ao, type Review as ap, type ReviewPage as aq, ReviewService as ar, type SearchDoc as as, type SearchResult as at, SearchService as au, SettingService as av, type ShippingRate as aw, StateService as ax, type StoreProfile as ay, StoreService as az, type AppliedDiscount as b, userService as b$, contactService as b0, countryService as b1, couponService as b2, currencyExponent as b3, currencyService as b4, dealService as b5, demoRequestService as b6, emptyCart as b7, emptyPage as b8, enquiryService as b9, regionService as bA, reviewService as bB, searchService as bC, setRequestHost as bD, settingService as bE, settingsService as bF, stateService as bG, staticStore as bH, storeForHost as bI, storeService as bJ, toCart as bK, toCartLine as bL, toCategory as bM, toCmsPage as bN, toCollection as bO, toEngineAddress as bP, toIdentityAddress as bQ, toMajor as bR, toMinor as bS, toOrder as bT, toPage as bU, toProduct as bV, toRating as bW, toUser as bX, toVariant as bY, toVendor as bZ, uploadService as b_, faqService as ba, feedbackService as bb, fromEngineAddress as bc, fromIdentityAddress as bd, fromSearchDoc as be, galleryService as bf, homeService as bg, initService as bh, mediaUrl as bi, meilisearchService as bj, menuService as bk, minorToMajor as bl, newsletterService as bm, orderService as bn, pageService as bo, paymentMethodService as bp, pluginService as bq, pluginsService as br, popularSearchService as bs, popularityService as bt, priceOf as bu, productImages as bv, productService as bw, profileService as bx, qs as by, reelsService as bz, type Approval as c, variantService as c0, varniCustomDesignService as c1, varniCustomProductService as c2, vendorService as c3, warrantyService as c4, wishlistService as c5, type AuthResponse as d, AuthService as e, AutocompleteService as f, type B2bRole as g, B2bService as h, BannerService as i, BaseService as j, BlogService as k, type CartLine as l, CartService as m, CatalogService as n, type Category as o, CategoryService as p, ChatService as q, type CheckoutOptions as r, type CheckoutResult as s, CheckoutService as t, type CmsPage as u, type Collection as v, CollectionService as w, type Company as x, type CompanyOrder as y, ContactService as z };
6518
+ export { type Menu as $, type Address as A, type B2bPlaced as B, type Cart as C, CountryService as D, CouponService as E, type Credentials as F, type Credit as G, CurrencyService as H, type Customer as I, DealService as J, DemoRequestService as K, type EngineRequest as L, EnquiryService as M, type Envelope as N, type Faq as O, FaqService as P, FeedbackService as Q, type Fulfillment as R, GalleryService as S, HomeService as T, type IdentityAddress as U, InitService as V, type Invitation as W, type Lead as X, type ListMeta as Y, MeilisearchService as Z, type Member as _, AddressService as a, collectionService as a$, type MenuItem as a0, MenuService as a1, type MenuSummary as a2, type Money as a3, NewsletterService as a4, type Offer as a5, type Order as a6, type OrderLine as a7, OrderService as a8, PageService as a9, type StorefrontCategory as aA, type StorefrontMenu as aB, type StorefrontOrder as aC, type StorefrontProduct as aD, UploadService as aE, UserService as aF, type Variant as aG, type VariantImage as aH, VariantService as aI, VarniCustomDesignService as aJ, VarniCustomProductService as aK, type Vendor as aL, VendorService as aM, WarrantyService as aN, type Wishlist as aO, type WishlistItem as aP, WishlistService as aQ, addressService as aR, authService as aS, autocompleteService as aT, b2bService as aU, bannerService as aV, blogService as aW, cartService as aX, categoryService as aY, chatService as aZ, checkoutService as a_, type PaymentIntent as aa, PaymentMethodService as ab, type Plugin as ac, PluginService as ad, PopularSearchService as ae, PopularityService as af, type Product as ag, type ProductOption as ah, ProductService as ai, ProfileService as aj, type Quote as ak, REDIRECT_GATEWAYS as al, ReelsService as am, RegionService as an, type RejectedLine as ao, type Review as ap, type ReviewPage as aq, ReviewService as ar, type SearchDoc as as, type SearchResult as at, SearchService as au, SettingService as av, type ShippingRate as aw, StateService as ax, type StoreProfile as ay, StoreService as az, type AppliedDiscount as b, uploadService as b$, contactService as b0, countryService as b1, couponService as b2, currencyExponent as b3, currencyService as b4, dealService as b5, demoRequestService as b6, emptyCart as b7, emptyPage as b8, enquiryService as b9, reelsService as bA, regionService as bB, reviewService as bC, searchService as bD, setRequestHost as bE, settingService as bF, settingsService as bG, stateService as bH, staticStore as bI, storeForHost as bJ, storeService as bK, toCart as bL, toCartLine as bM, toCategory as bN, toCmsPage as bO, toCollection as bP, toEngineAddress as bQ, toIdentityAddress as bR, toMajor as bS, toMinor as bT, toOrder as bU, toPage as bV, toProduct as bW, toRating as bX, toUser as bY, toVariant as bZ, toVendor as b_, faqService as ba, feedbackService as bb, fromEngineAddress as bc, fromIdentityAddress as bd, fromSearchDoc as be, galleryService as bf, homeService as bg, initService as bh, mediaUrl as bi, meilisearchService as bj, menuService as bk, minorToMajor as bl, newsletterService as bm, orderService as bn, ownDomain as bo, pageService as bp, paymentMethodService as bq, pluginService as br, pluginsService as bs, popularSearchService as bt, popularityService as bu, priceOf as bv, productImages as bw, productService as bx, profileService as by, qs as bz, type Approval as c, userService as c0, variantService as c1, varniCustomDesignService as c2, varniCustomProductService as c3, vendorService as c4, warrantyService as c5, wishlistService as c6, type AuthResponse as d, AuthService as e, AutocompleteService as f, type B2bRole as g, B2bService as h, BannerService as i, BaseService as j, BlogService as k, type CartLine as l, CartService as m, CatalogService as n, type Category as o, CategoryService as p, ChatService as q, type CheckoutOptions as r, type CheckoutResult as s, CheckoutService as t, type CmsPage as u, type Collection as v, CollectionService as w, type Company as x, type CompanyOrder as y, ContactService as z };
@@ -1183,9 +1183,11 @@ declare class BaseService {
1183
1183
  protected get creds(): Credentials;
1184
1184
  /**
1185
1185
  * The store this call is for: the request host's subdomain under
1186
- * `baseDomain`, else the static `store`. Read per call, never stored on the
1187
- * instance, because the server shares one process (and one credentials
1188
- * object) across every concurrent request and each may be for a different host.
1186
+ * `baseDomain`, else the static `store`, else the host itself when it is a
1187
+ * store's own domain (the engine answers only a verified one). Read per call,
1188
+ * never stored on the instance, because the server shares one process (and
1189
+ * one credentials object) across every concurrent request and each may be
1190
+ * for a different host.
1189
1191
  */
1190
1192
  protected get store(): string | undefined;
1191
1193
  /**
@@ -1238,6 +1240,13 @@ declare function setRequestHost(fn: () => string | undefined): void;
1238
1240
  * `shopnx.in` itself name no store.
1239
1241
  */
1240
1242
  declare function storeForHost(host: string | undefined, baseDomain: string | undefined): string | undefined;
1243
+ /**
1244
+ * A host outside `baseDomain` is a store's own domain, such as `chillish.in`,
1245
+ * which the engine looks up among its verified domains. Only a storefront
1246
+ * serving many stores (one with a `baseDomain`) passes it on; the base domain
1247
+ * itself, `localhost` and bare addresses are nobody's.
1248
+ */
1249
+ declare function ownDomain(host: string | undefined, baseDomain: string | undefined): string | undefined;
1241
1250
  /** `?a=1&b=2`, dropping what was not asked for. Arrays repeat the key. */
1242
1251
  declare function qs(query?: Query): string;
1243
1252
  /** The family's list shape, from the engine's `{data, meta}`. Totals are the engine's, never invented. */
@@ -6506,4 +6515,4 @@ declare class B2bService extends BaseService {
6506
6515
  }
6507
6516
  declare const b2bService: B2bService;
6508
6517
 
6509
- export { type Menu as $, type Address as A, type B2bPlaced as B, type Cart as C, CountryService as D, CouponService as E, type Credentials as F, type Credit as G, CurrencyService as H, type Customer as I, DealService as J, DemoRequestService as K, type EngineRequest as L, EnquiryService as M, type Envelope as N, type Faq as O, FaqService as P, FeedbackService as Q, type Fulfillment as R, GalleryService as S, HomeService as T, type IdentityAddress as U, InitService as V, type Invitation as W, type Lead as X, type ListMeta as Y, MeilisearchService as Z, type Member as _, AddressService as a, collectionService as a$, type MenuItem as a0, MenuService as a1, type MenuSummary as a2, type Money as a3, NewsletterService as a4, type Offer as a5, type Order as a6, type OrderLine as a7, OrderService as a8, PageService as a9, type StorefrontCategory as aA, type StorefrontMenu as aB, type StorefrontOrder as aC, type StorefrontProduct as aD, UploadService as aE, UserService as aF, type Variant as aG, type VariantImage as aH, VariantService as aI, VarniCustomDesignService as aJ, VarniCustomProductService as aK, type Vendor as aL, VendorService as aM, WarrantyService as aN, type Wishlist as aO, type WishlistItem as aP, WishlistService as aQ, addressService as aR, authService as aS, autocompleteService as aT, b2bService as aU, bannerService as aV, blogService as aW, cartService as aX, categoryService as aY, chatService as aZ, checkoutService as a_, type PaymentIntent as aa, PaymentMethodService as ab, type Plugin as ac, PluginService as ad, PopularSearchService as ae, PopularityService as af, type Product as ag, type ProductOption as ah, ProductService as ai, ProfileService as aj, type Quote as ak, REDIRECT_GATEWAYS as al, ReelsService as am, RegionService as an, type RejectedLine as ao, type Review as ap, type ReviewPage as aq, ReviewService as ar, type SearchDoc as as, type SearchResult as at, SearchService as au, SettingService as av, type ShippingRate as aw, StateService as ax, type StoreProfile as ay, StoreService as az, type AppliedDiscount as b, userService as b$, contactService as b0, countryService as b1, couponService as b2, currencyExponent as b3, currencyService as b4, dealService as b5, demoRequestService as b6, emptyCart as b7, emptyPage as b8, enquiryService as b9, regionService as bA, reviewService as bB, searchService as bC, setRequestHost as bD, settingService as bE, settingsService as bF, stateService as bG, staticStore as bH, storeForHost as bI, storeService as bJ, toCart as bK, toCartLine as bL, toCategory as bM, toCmsPage as bN, toCollection as bO, toEngineAddress as bP, toIdentityAddress as bQ, toMajor as bR, toMinor as bS, toOrder as bT, toPage as bU, toProduct as bV, toRating as bW, toUser as bX, toVariant as bY, toVendor as bZ, uploadService as b_, faqService as ba, feedbackService as bb, fromEngineAddress as bc, fromIdentityAddress as bd, fromSearchDoc as be, galleryService as bf, homeService as bg, initService as bh, mediaUrl as bi, meilisearchService as bj, menuService as bk, minorToMajor as bl, newsletterService as bm, orderService as bn, pageService as bo, paymentMethodService as bp, pluginService as bq, pluginsService as br, popularSearchService as bs, popularityService as bt, priceOf as bu, productImages as bv, productService as bw, profileService as bx, qs as by, reelsService as bz, type Approval as c, variantService as c0, varniCustomDesignService as c1, varniCustomProductService as c2, vendorService as c3, warrantyService as c4, wishlistService as c5, type AuthResponse as d, AuthService as e, AutocompleteService as f, type B2bRole as g, B2bService as h, BannerService as i, BaseService as j, BlogService as k, type CartLine as l, CartService as m, CatalogService as n, type Category as o, CategoryService as p, ChatService as q, type CheckoutOptions as r, type CheckoutResult as s, CheckoutService as t, type CmsPage as u, type Collection as v, CollectionService as w, type Company as x, type CompanyOrder as y, ContactService as z };
6518
+ export { type Menu as $, type Address as A, type B2bPlaced as B, type Cart as C, CountryService as D, CouponService as E, type Credentials as F, type Credit as G, CurrencyService as H, type Customer as I, DealService as J, DemoRequestService as K, type EngineRequest as L, EnquiryService as M, type Envelope as N, type Faq as O, FaqService as P, FeedbackService as Q, type Fulfillment as R, GalleryService as S, HomeService as T, type IdentityAddress as U, InitService as V, type Invitation as W, type Lead as X, type ListMeta as Y, MeilisearchService as Z, type Member as _, AddressService as a, collectionService as a$, type MenuItem as a0, MenuService as a1, type MenuSummary as a2, type Money as a3, NewsletterService as a4, type Offer as a5, type Order as a6, type OrderLine as a7, OrderService as a8, PageService as a9, type StorefrontCategory as aA, type StorefrontMenu as aB, type StorefrontOrder as aC, type StorefrontProduct as aD, UploadService as aE, UserService as aF, type Variant as aG, type VariantImage as aH, VariantService as aI, VarniCustomDesignService as aJ, VarniCustomProductService as aK, type Vendor as aL, VendorService as aM, WarrantyService as aN, type Wishlist as aO, type WishlistItem as aP, WishlistService as aQ, addressService as aR, authService as aS, autocompleteService as aT, b2bService as aU, bannerService as aV, blogService as aW, cartService as aX, categoryService as aY, chatService as aZ, checkoutService as a_, type PaymentIntent as aa, PaymentMethodService as ab, type Plugin as ac, PluginService as ad, PopularSearchService as ae, PopularityService as af, type Product as ag, type ProductOption as ah, ProductService as ai, ProfileService as aj, type Quote as ak, REDIRECT_GATEWAYS as al, ReelsService as am, RegionService as an, type RejectedLine as ao, type Review as ap, type ReviewPage as aq, ReviewService as ar, type SearchDoc as as, type SearchResult as at, SearchService as au, SettingService as av, type ShippingRate as aw, StateService as ax, type StoreProfile as ay, StoreService as az, type AppliedDiscount as b, uploadService as b$, contactService as b0, countryService as b1, couponService as b2, currencyExponent as b3, currencyService as b4, dealService as b5, demoRequestService as b6, emptyCart as b7, emptyPage as b8, enquiryService as b9, reelsService as bA, regionService as bB, reviewService as bC, searchService as bD, setRequestHost as bE, settingService as bF, settingsService as bG, stateService as bH, staticStore as bI, storeForHost as bJ, storeService as bK, toCart as bL, toCartLine as bM, toCategory as bN, toCmsPage as bO, toCollection as bP, toEngineAddress as bQ, toIdentityAddress as bR, toMajor as bS, toMinor as bT, toOrder as bU, toPage as bV, toProduct as bW, toRating as bX, toUser as bY, toVariant as bZ, toVendor as b_, faqService as ba, feedbackService as bb, fromEngineAddress as bc, fromIdentityAddress as bd, fromSearchDoc as be, galleryService as bf, homeService as bg, initService as bh, mediaUrl as bi, meilisearchService as bj, menuService as bk, minorToMajor as bl, newsletterService as bm, orderService as bn, ownDomain as bo, pageService as bp, paymentMethodService as bq, pluginService as br, pluginsService as bs, popularSearchService as bt, popularityService as bu, priceOf as bv, productImages as bw, productService as bx, profileService as by, qs as bz, type Approval as c, userService as c0, variantService as c1, varniCustomDesignService as c2, varniCustomProductService as c3, vendorService as c4, warrantyService as c5, wishlistService as c6, type AuthResponse as d, AuthService as e, AutocompleteService as f, type B2bRole as g, B2bService as h, BannerService as i, BaseService as j, BlogService as k, type CartLine as l, CartService as m, CatalogService as n, type Category as o, CategoryService as p, ChatService as q, type CheckoutOptions as r, type CheckoutResult as s, CheckoutService as t, type CmsPage as u, type Collection as v, CollectionService as w, type Company as x, type CompanyOrder as y, ContactService as z };
package/dist/index.cjs CHANGED
@@ -287,14 +287,16 @@ var BaseService = class _BaseService {
287
287
  }
288
288
  /**
289
289
  * The store this call is for: the request host's subdomain under
290
- * `baseDomain`, else the static `store`. Read per call, never stored on the
291
- * instance, because the server shares one process (and one credentials
292
- * object) across every concurrent request and each may be for a different host.
290
+ * `baseDomain`, else the static `store`, else the host itself when it is a
291
+ * store's own domain (the engine answers only a verified one). Read per call,
292
+ * never stored on the instance, because the server shares one process (and
293
+ * one credentials object) across every concurrent request and each may be
294
+ * for a different host.
293
295
  */
294
296
  get store() {
295
297
  const { baseDomain, store } = this.creds;
296
298
  const host = typeof window !== "undefined" ? window.location?.hostname : requestHost?.();
297
- return storeForHost(host, baseDomain) ?? store;
299
+ return storeForHost(host, baseDomain) ?? store ?? ownDomain(host, baseDomain);
298
300
  }
299
301
  /**
300
302
  * The engine's base URL from wherever this code runs. In the browser a
@@ -444,6 +446,14 @@ function storeForHost(host, baseDomain) {
444
446
  const slug = h.slice(0, -suffix.length);
445
447
  return slug && !slug.includes(".") ? slug : void 0;
446
448
  }
449
+ function ownDomain(host, baseDomain) {
450
+ if (!host || !baseDomain) return void 0;
451
+ const h = host.toLowerCase().replace(/:\d+$/, "").replace(/\.$/, "");
452
+ const base = baseDomain.toLowerCase().replace(/^\.+/, "").replace(/\.$/, "");
453
+ if (!h.includes(".") || h === base || h.endsWith("." + base) || h.endsWith(".localhost")) return void 0;
454
+ if (/^[\d.]+$/.test(h) || h.includes(":") || h.startsWith("[")) return void 0;
455
+ return h;
456
+ }
447
457
  var unreachable = (base, cause) => new GoCommerceError(`Could not reach the commerce engine at ${base}: ${cause?.message ?? cause}`, 0);
448
458
  function qs(query) {
449
459
  if (!query) return "";
@@ -3221,6 +3231,7 @@ exports.menuService = menuService;
3221
3231
  exports.minorToMajor = minorToMajor;
3222
3232
  exports.newsletterService = newsletterService;
3223
3233
  exports.orderService = orderService;
3234
+ exports.ownDomain = ownDomain;
3224
3235
  exports.pageService = pageService;
3225
3236
  exports.paymentMethodService = paymentMethodService;
3226
3237
  exports.pluginService = pluginService;