@misiki/gocommerce-connector 0.4.5 → 0.4.6

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.
@@ -1013,6 +1013,13 @@ var StoreFacts = class extends BaseService {
1013
1013
  profile() {
1014
1014
  return remember(this.key("profile"), () => this.data("/api/store"));
1015
1015
  }
1016
+ /** Where the store delivers (D117): its priced zones' countries, or everywhere. */
1017
+ shipsTo() {
1018
+ return remember(this.key("ships-to"), async () => {
1019
+ const r = await this.data("/api/checkout/countries");
1020
+ return { everywhere: r?.everywhere ?? true, countries: r?.countries ?? [] };
1021
+ });
1022
+ }
1016
1023
  checkoutOptions() {
1017
1024
  return remember(this.key("checkout"), () => this.data("/api/checkout"));
1018
1025
  }
@@ -2560,12 +2567,14 @@ var StoreService = class extends BaseService {
2560
2567
  return super.post(path, data);
2561
2568
  }
2562
2569
  async live() {
2563
- const [ready, plugins, menus, base, profile] = await Promise.all([
2570
+ const [ready, plugins, menus, base, profile, ships] = await Promise.all([
2564
2571
  this.facts.ready(),
2565
2572
  this.facts.plugins().catch(() => /* @__PURE__ */ new Map()),
2566
2573
  new MenuService(this._fetch).engineMenus(),
2567
2574
  readStaticStore(),
2568
- this.facts.profile().catch(() => null)
2575
+ this.facts.profile().catch(() => null),
2576
+ // An engine without the route rules nothing out.
2577
+ this.facts.shipsTo().catch(() => ({ everywhere: true, countries: [] }))
2569
2578
  ]);
2570
2579
  const code = ready.currency;
2571
2580
  const sameCurrency = (base.currency?.code ?? base.currencyCode) === code;
@@ -2595,6 +2604,7 @@ var StoreService = class extends BaseService {
2595
2604
  }
2596
2605
  },
2597
2606
  ...menus?.length ? { menu: menus } : {},
2607
+ ...deliverable(base, ships),
2598
2608
  // The one way this store signs customers in (D116), which the sign-in
2599
2609
  // form reads as PHONE or EMAIL. Without the accounts module the static
2600
2610
  // record says.
@@ -2603,6 +2613,20 @@ var StoreService = class extends BaseService {
2603
2613
  }
2604
2614
  };
2605
2615
  var storeService = new StoreService();
2616
+ function deliverable(base, ships) {
2617
+ if (ships.everywhere || !ships.countries.length) return {};
2618
+ const known = new Map((base.countries ?? []).map((c) => [String(c.code).toUpperCase(), c]));
2619
+ const countries = ships.countries.map((code) => known.get(code) ?? { code, name: regionName(code) });
2620
+ const keep = base.country && ships.countries.includes(String(base.country.code).toUpperCase());
2621
+ return { countries, ...keep ? {} : { country: countries[0] } };
2622
+ }
2623
+ function regionName(code) {
2624
+ try {
2625
+ return new Intl.DisplayNames(["en"], { type: "region" }).of(code) ?? code;
2626
+ } catch {
2627
+ return code;
2628
+ }
2629
+ }
2606
2630
 
2607
2631
  // src/services/page-service.ts
2608
2632
  var PageService = class extends BaseService {