@misiki/gocommerce-connector 0.10.0 → 0.11.0

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.
@@ -2660,21 +2660,38 @@ var MenuService = class extends BaseService {
2660
2660
  const m = await this.data(`/x/navigation/menus/${encodeURIComponent(handle)}`);
2661
2661
  return { menuId: m.handle, name: m.title, items: (m.items ?? []).map(toItem) };
2662
2662
  }
2663
- /** The header and footer menus, or `null` when the module is not there. Cached: a menu is store-level. */
2663
+ /**
2664
+ * The header and footer menus, or `null` when the module is not there. Cached: a menu is
2665
+ * store-level. Each is the menu the shop chose for it in the theme editor's header or footer
2666
+ * (GoCommerce D131), still under the `header` / `footer` id every storefront looks for, so the
2667
+ * choice reaches every place that draws one; the menus named so are the default.
2668
+ */
2664
2669
  async engineMenus() {
2665
2670
  if (!await this.facts.pluginOn("navigation")) return null;
2666
2671
  return remember(`${this.engineBase()}|${this.store ?? ""}|menus`, async () => {
2667
2672
  const out = [];
2668
- for (const handle of ["header", "footer"]) {
2673
+ for (const part of ["header", "footer"]) {
2669
2674
  try {
2670
- const m = await this.data(`/x/navigation/menus/${handle}`);
2671
- out.push({ menuId: handle, name: m.title, items: (m.items ?? []).map(toItem) });
2675
+ const handle = await this.chosenMenu(part);
2676
+ const m = await this.data(`/x/navigation/menus/${encodeURIComponent(handle)}`);
2677
+ out.push({ menuId: part, name: m.title, items: (m.items ?? []).map(toItem) });
2672
2678
  } catch {
2673
2679
  }
2674
2680
  }
2675
2681
  return out;
2676
2682
  }).catch(() => null);
2677
2683
  }
2684
+ /** The handle of the menu the published header or footer names, else the part's own name. */
2685
+ async chosenMenu(part) {
2686
+ if (!await this.facts.pluginOn("layouts")) return part;
2687
+ try {
2688
+ const layout = await this.data(`/x/layouts/${part}`);
2689
+ const menu = layout?.sections?.find((s) => s.type === part)?.settings?.menu;
2690
+ return typeof menu === "string" && menu ? menu : part;
2691
+ } catch {
2692
+ return part;
2693
+ }
2694
+ }
2678
2695
  };
2679
2696
  var menuService = new MenuService();
2680
2697
  var readStaticStore = async () => {
@@ -2792,7 +2809,10 @@ var StoreService = class extends BaseService {
2792
2809
  isProductReviewsAndRatings: {
2793
2810
  ...basePlugins.isProductReviewsAndRatings,
2794
2811
  ...flag(plugins.has("product-reviews"))
2795
- }
2812
+ },
2813
+ // The footer's sign-up box posts to ext/newsletter, and the theme editor's footer
2814
+ // switch (D131) can only show it while that is on.
2815
+ newsletter: { ...basePlugins.newsletter, ...flag(plugins.has("newsletter")) }
2796
2816
  },
2797
2817
  ...menus?.length ? { menu: menus } : {},
2798
2818
  ...deliverable(base, ships),
@@ -2907,6 +2927,35 @@ var LayoutService = class extends BaseService {
2907
2927
  return null;
2908
2928
  }
2909
2929
  }
2930
+ /**
2931
+ * The header the shop set in the theme editor (D131), drawn on every
2932
+ * page: the published one, or a preview key's draft. Null — the
2933
+ * storefront's own header — when none is published, the editor is off, the
2934
+ * engine is older, or anything fails: a header is never worth an error page.
2935
+ */
2936
+ async getHeader({ preview } = {}) {
2937
+ return this.chrome("header", preview);
2938
+ }
2939
+ /** The footer the shop set in the theme editor (D131); null for the storefront's own, as getHeader. */
2940
+ async getFooter({ preview } = {}) {
2941
+ return this.chrome("footer", preview);
2942
+ }
2943
+ async chrome(page, preview) {
2944
+ let layout;
2945
+ try {
2946
+ layout = await this.getPageLayout(page, { preview });
2947
+ } catch {
2948
+ return null;
2949
+ }
2950
+ const section = layout?.sections.find((s) => s.type === page);
2951
+ if (!layout || !section) return null;
2952
+ const settings = { ...section.settings };
2953
+ let menu = null;
2954
+ if (typeof settings.menu === "string" && settings.menu) {
2955
+ menu = await new MenuService(this._fetch).getMenu(settings.menu).catch(() => null);
2956
+ }
2957
+ return { revision: layout.revision, preview: layout.preview, settings, menu };
2958
+ }
2910
2959
  };
2911
2960
  function tokens(v) {
2912
2961
  return v && typeof v === "object" && !Array.isArray(v) && Object.keys(v).length ? { ...v } : null;