@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.
@@ -1286,6 +1286,11 @@ declare class StoreFacts extends BaseService {
1286
1286
  }>;
1287
1287
  /** The store's own name and how a buyer reaches it, as set in its panel. */
1288
1288
  profile(): Promise<StoreProfile>;
1289
+ /** Where the store delivers (D117): its priced zones' countries, or everywhere. */
1290
+ shipsTo(): Promise<{
1291
+ everywhere: boolean;
1292
+ countries: string[];
1293
+ }>;
1289
1294
  checkoutOptions(): Promise<CheckoutOptions>;
1290
1295
  /**
1291
1296
  * The whole tree, flat and depth-first. Past 500 categories the engine
@@ -1286,6 +1286,11 @@ declare class StoreFacts extends BaseService {
1286
1286
  }>;
1287
1287
  /** The store's own name and how a buyer reaches it, as set in its panel. */
1288
1288
  profile(): Promise<StoreProfile>;
1289
+ /** Where the store delivers (D117): its priced zones' countries, or everywhere. */
1290
+ shipsTo(): Promise<{
1291
+ everywhere: boolean;
1292
+ countries: string[];
1293
+ }>;
1289
1294
  checkoutOptions(): Promise<CheckoutOptions>;
1290
1295
  /**
1291
1296
  * The whole tree, flat and depth-first. Past 500 categories the engine
package/dist/index.cjs CHANGED
@@ -1032,6 +1032,13 @@ var StoreFacts = class extends BaseService {
1032
1032
  profile() {
1033
1033
  return remember(this.key("profile"), () => this.data("/api/store"));
1034
1034
  }
1035
+ /** Where the store delivers (D117): its priced zones' countries, or everywhere. */
1036
+ shipsTo() {
1037
+ return remember(this.key("ships-to"), async () => {
1038
+ const r = await this.data("/api/checkout/countries");
1039
+ return { everywhere: r?.everywhere ?? true, countries: r?.countries ?? [] };
1040
+ });
1041
+ }
1035
1042
  checkoutOptions() {
1036
1043
  return remember(this.key("checkout"), () => this.data("/api/checkout"));
1037
1044
  }
@@ -2576,12 +2583,14 @@ var StoreService = class extends BaseService {
2576
2583
  return super.post(path, data);
2577
2584
  }
2578
2585
  async live() {
2579
- const [ready, plugins, menus, base, profile] = await Promise.all([
2586
+ const [ready, plugins, menus, base, profile, ships] = await Promise.all([
2580
2587
  this.facts.ready(),
2581
2588
  this.facts.plugins().catch(() => /* @__PURE__ */ new Map()),
2582
2589
  new MenuService(this._fetch).engineMenus(),
2583
2590
  readStaticStore(),
2584
- this.facts.profile().catch(() => null)
2591
+ this.facts.profile().catch(() => null),
2592
+ // An engine without the route rules nothing out.
2593
+ this.facts.shipsTo().catch(() => ({ everywhere: true, countries: [] }))
2585
2594
  ]);
2586
2595
  const code = ready.currency;
2587
2596
  const sameCurrency = (base.currency?.code ?? base.currencyCode) === code;
@@ -2611,6 +2620,7 @@ var StoreService = class extends BaseService {
2611
2620
  }
2612
2621
  },
2613
2622
  ...menus?.length ? { menu: menus } : {},
2623
+ ...deliverable(base, ships),
2614
2624
  // The one way this store signs customers in (D116), which the sign-in
2615
2625
  // form reads as PHONE or EMAIL. Without the accounts module the static
2616
2626
  // record says.
@@ -2619,6 +2629,20 @@ var StoreService = class extends BaseService {
2619
2629
  }
2620
2630
  };
2621
2631
  var storeService = new StoreService();
2632
+ function deliverable(base, ships) {
2633
+ if (ships.everywhere || !ships.countries.length) return {};
2634
+ const known = new Map((base.countries ?? []).map((c) => [String(c.code).toUpperCase(), c]));
2635
+ const countries = ships.countries.map((code) => known.get(code) ?? { code, name: regionName(code) });
2636
+ const keep = base.country && ships.countries.includes(String(base.country.code).toUpperCase());
2637
+ return { countries, ...keep ? {} : { country: countries[0] } };
2638
+ }
2639
+ function regionName(code) {
2640
+ try {
2641
+ return new Intl.DisplayNames(["en"], { type: "region" }).of(code) ?? code;
2642
+ } catch {
2643
+ return code;
2644
+ }
2645
+ }
2622
2646
 
2623
2647
  // src/services/page-service.ts
2624
2648
  var PageService = class extends BaseService {