@misiki/gocommerce-connector 0.7.0 → 0.8.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,7 +2742,7 @@ 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
2748
  let layout;
@@ -2760,17 +2760,53 @@ var LayoutService = class extends BaseService {
2760
2760
  theme: layout.theme,
2761
2761
  revision: layout.revision,
2762
2762
  preview: !!layout.preview,
2763
+ themeSettings: tokens(layout.theme_settings),
2763
2764
  sections: (layout.sections ?? []).map(toSection)
2764
2765
  };
2765
2766
  }
2767
+ /**
2768
+ * The store's design tokens, for a page other than the home page: the
2769
+ * published ones, or a preview key's draft. Null when there are none to
2770
+ * apply — nothing published, the editor off, an engine without the
2771
+ * module — and on any failure too: a missing look must never cost the
2772
+ * page.
2773
+ */
2774
+ async getThemeSettings({ preview } = {}) {
2775
+ try {
2776
+ const out = await this.data("/x/layouts/theme", {
2777
+ query: { preview: preview?.trim() || void 0 }
2778
+ });
2779
+ if (!out) return null;
2780
+ return { revision: out.revision, preview: !!out.preview, settings: tokens(out.settings) ?? {} };
2781
+ } catch {
2782
+ return null;
2783
+ }
2784
+ }
2766
2785
  };
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]);
2786
+ function tokens(v) {
2787
+ return v && typeof v === "object" && !Array.isArray(v) && Object.keys(v).length ? { ...v } : null;
2788
+ }
2789
+ function withMedia(value, key) {
2790
+ if (Array.isArray(value)) return value.map((x) => withMedia(x, null));
2791
+ if (value && typeof value === "object") {
2792
+ return Object.fromEntries(Object.entries(value).map(([k, x]) => [k, withMedia(x, k)]));
2771
2793
  }
2794
+ if (key && MEDIA_KEYS.has(key) && typeof value === "string") return mediaUrl(value);
2795
+ return value;
2796
+ }
2797
+ function toSection(s) {
2798
+ const settings = withMedia(s.settings ?? {}, null);
2772
2799
  const out = { id: s.id, type: s.type, settings };
2773
2800
  if (s.type === "product-grid") out.products = (s.products ?? []).map((p) => toProduct(p));
2801
+ if (s.type === "collection-list") {
2802
+ out.collections = (s.collections ?? []).map((c) => ({
2803
+ id: String(c.id),
2804
+ title: c.title,
2805
+ slug: c.slug,
2806
+ link: `/collections/${c.slug}`,
2807
+ image: mediaUrl(c.image) ?? null
2808
+ }));
2809
+ }
2774
2810
  return out;
2775
2811
  }
2776
2812
  var layoutService = new LayoutService();