@misiki/gocommerce-connector 0.7.0 → 0.9.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.
@@ -2742,12 +2742,28 @@ var pageService = new PageService();
2742
2742
  var faqService = new FaqService();
2743
2743
 
2744
2744
  // src/services/layout-service.ts
2745
- var IMAGE_KEYS = ["image", "mobile_image"];
2745
+ var MEDIA_KEYS = /* @__PURE__ */ new Set(["image", "mobile_image", "poster", "video_file"]);
2746
2746
  var LayoutService = class extends BaseService {
2747
2747
  async getHomeLayout({ preview } = {}) {
2748
+ return this.getPageLayout("home", { preview });
2749
+ }
2750
+ /**
2751
+ * The template every product page is drawn in: the sections around the
2752
+ * product's core (`main-product`). Null when none is published, so the
2753
+ * product page draws exactly as it did before templates existed.
2754
+ */
2755
+ async getProductLayout({ preview } = {}) {
2756
+ return this.getPageLayout("product", { preview });
2757
+ }
2758
+ /** The template every collection page is drawn in, around its grid (`main-collection`). */
2759
+ async getCollectionLayout({ preview } = {}) {
2760
+ return this.getPageLayout("collection", { preview });
2761
+ }
2762
+ /** Any arranged page by its key; null for none, as the three above. */
2763
+ async getPageLayout(page, { preview } = {}) {
2748
2764
  let layout;
2749
2765
  try {
2750
- layout = await this.data("/x/layouts/home", {
2766
+ layout = await this.data(`/x/layouts/${encodeURIComponent(page)}`, {
2751
2767
  query: { preview: preview?.trim() || void 0 }
2752
2768
  });
2753
2769
  } catch (err) {
@@ -2760,17 +2776,53 @@ var LayoutService = class extends BaseService {
2760
2776
  theme: layout.theme,
2761
2777
  revision: layout.revision,
2762
2778
  preview: !!layout.preview,
2779
+ themeSettings: tokens(layout.theme_settings),
2763
2780
  sections: (layout.sections ?? []).map(toSection)
2764
2781
  };
2765
2782
  }
2783
+ /**
2784
+ * The store's design tokens, for a page other than the home page: the
2785
+ * published ones, or a preview key's draft. Null when there are none to
2786
+ * apply — nothing published, the editor off, an engine without the
2787
+ * module — and on any failure too: a missing look must never cost the
2788
+ * page.
2789
+ */
2790
+ async getThemeSettings({ preview } = {}) {
2791
+ try {
2792
+ const out = await this.data("/x/layouts/theme", {
2793
+ query: { preview: preview?.trim() || void 0 }
2794
+ });
2795
+ if (!out) return null;
2796
+ return { revision: out.revision, preview: !!out.preview, settings: tokens(out.settings) ?? {} };
2797
+ } catch {
2798
+ return null;
2799
+ }
2800
+ }
2766
2801
  };
2767
- function toSection(s) {
2768
- const settings = { ...s.settings ?? {} };
2769
- for (const key of IMAGE_KEYS) {
2770
- if (typeof settings[key] === "string") settings[key] = mediaUrl(settings[key]);
2802
+ function tokens(v) {
2803
+ return v && typeof v === "object" && !Array.isArray(v) && Object.keys(v).length ? { ...v } : null;
2804
+ }
2805
+ function withMedia(value, key) {
2806
+ if (Array.isArray(value)) return value.map((x) => withMedia(x, null));
2807
+ if (value && typeof value === "object") {
2808
+ return Object.fromEntries(Object.entries(value).map(([k, x]) => [k, withMedia(x, k)]));
2771
2809
  }
2810
+ if (key && MEDIA_KEYS.has(key) && typeof value === "string") return mediaUrl(value);
2811
+ return value;
2812
+ }
2813
+ function toSection(s) {
2814
+ const settings = withMedia(s.settings ?? {}, null);
2772
2815
  const out = { id: s.id, type: s.type, settings };
2773
2816
  if (s.type === "product-grid") out.products = (s.products ?? []).map((p) => toProduct(p));
2817
+ if (s.type === "collection-list") {
2818
+ out.collections = (s.collections ?? []).map((c) => ({
2819
+ id: String(c.id),
2820
+ title: c.title,
2821
+ slug: c.slug,
2822
+ link: `/collections/${c.slug}`,
2823
+ image: mediaUrl(c.image) ?? null
2824
+ }));
2825
+ }
2774
2826
  return out;
2775
2827
  }
2776
2828
  var layoutService = new LayoutService();