@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.
@@ -214,14 +214,16 @@ var BaseService = class _BaseService {
214
214
  }
215
215
  /**
216
216
  * The store this call is for: the request host's subdomain under
217
- * `baseDomain`, else the static `store`. Read per call, never stored on the
218
- * instance, because the server shares one process (and one credentials
219
- * object) across every concurrent request and each may be for a different host.
217
+ * `baseDomain`, else the static `store`, else the host itself when it is a
218
+ * store's own domain (the engine answers only a verified one). Read per call,
219
+ * never stored on the instance, because the server shares one process (and
220
+ * one credentials object) across every concurrent request and each may be
221
+ * for a different host.
220
222
  */
221
223
  get store() {
222
224
  const { baseDomain, store } = this.creds;
223
225
  const host = typeof window !== "undefined" ? window.location?.hostname : requestHost?.();
224
- return storeForHost(host, baseDomain) ?? store;
226
+ return storeForHost(host, baseDomain) ?? store ?? ownDomain(host, baseDomain);
225
227
  }
226
228
  /**
227
229
  * The engine's base URL from wherever this code runs. In the browser a
@@ -371,6 +373,14 @@ function storeForHost(host, baseDomain) {
371
373
  const slug = h.slice(0, -suffix.length);
372
374
  return slug && !slug.includes(".") ? slug : void 0;
373
375
  }
376
+ function ownDomain(host, baseDomain) {
377
+ if (!host || !baseDomain) return void 0;
378
+ const h = host.toLowerCase().replace(/:\d+$/, "").replace(/\.$/, "");
379
+ const base = baseDomain.toLowerCase().replace(/^\.+/, "").replace(/\.$/, "");
380
+ if (!h.includes(".") || h === base || h.endsWith("." + base) || h.endsWith(".localhost")) return void 0;
381
+ if (/^[\d.]+$/.test(h) || h.includes(":") || h.startsWith("[")) return void 0;
382
+ return h;
383
+ }
374
384
  var unreachable = (base, cause) => new GoCommerceError(`Could not reach the commerce engine at ${base}: ${cause?.message ?? cause}`, 0);
375
385
  function qs(query) {
376
386
  if (!query) return "";
@@ -3194,6 +3204,7 @@ exports.meilisearchService = meilisearchService;
3194
3204
  exports.menuService = menuService;
3195
3205
  exports.newsletterService = newsletterService;
3196
3206
  exports.orderService = orderService;
3207
+ exports.ownDomain = ownDomain;
3197
3208
  exports.pageService = pageService;
3198
3209
  exports.paymentMethodService = paymentMethodService;
3199
3210
  exports.pluginService = pluginService;