@misiki/gocommerce-connector 0.6.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.
@@ -2034,6 +2034,31 @@ var OrderService = class extends BaseService {
2034
2034
  async listPublic(_args = {}) {
2035
2035
  return emptyPage();
2036
2036
  }
2037
+ /**
2038
+ * Opens an order with its number and the email or phone on it, no code. The
2039
+ * engine answers one 404 for an unknown number and a wrong contact. The
2040
+ * token it answers is kept like an order placed in this browser, so the
2041
+ * order page and `getOrder` read it again.
2042
+ */
2043
+ async openOrder({ orderNo, contact }) {
2044
+ const res = await this.data(
2045
+ `/api/orders/${encodeURIComponent(orderNo.trim())}/open`,
2046
+ { method: "POST", body: { contact: contact.trim() } }
2047
+ );
2048
+ rememberOrder({ number: res.order.number, token: res.access_token, cartId: "" });
2049
+ return { data: [toOrder(res.order)] };
2050
+ }
2051
+ /**
2052
+ * Opens an order from the link in its emails, which carries the order's key
2053
+ * (`/order-tracking?order=…&key=…`). The key is kept like an order placed in
2054
+ * this browser, so the page can drop it from the address bar.
2055
+ */
2056
+ async openOrderWithKey({ orderNo, key }) {
2057
+ const number = orderNo.trim();
2058
+ const order = await this.data(`/api/orders/${encodeURIComponent(number)}`, { query: { token: key.trim() } });
2059
+ rememberOrder({ number: order.number, token: key.trim(), cartId: "" });
2060
+ return { data: [toOrder(order)] };
2061
+ }
2037
2062
  /**
2038
2063
  * Sends a 4-digit code to the email or phone on the order, when `contact`
2039
2064
  * is that email or phone. The engine answers the same either way, so this
@@ -2717,7 +2742,7 @@ var pageService = new PageService();
2717
2742
  var faqService = new FaqService();
2718
2743
 
2719
2744
  // src/services/layout-service.ts
2720
- var IMAGE_KEYS = ["image", "mobile_image"];
2745
+ var MEDIA_KEYS = /* @__PURE__ */ new Set(["image", "mobile_image", "poster", "video_file"]);
2721
2746
  var LayoutService = class extends BaseService {
2722
2747
  async getHomeLayout({ preview } = {}) {
2723
2748
  let layout;
@@ -2735,17 +2760,53 @@ var LayoutService = class extends BaseService {
2735
2760
  theme: layout.theme,
2736
2761
  revision: layout.revision,
2737
2762
  preview: !!layout.preview,
2763
+ themeSettings: tokens(layout.theme_settings),
2738
2764
  sections: (layout.sections ?? []).map(toSection)
2739
2765
  };
2740
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
+ }
2741
2785
  };
2742
- function toSection(s) {
2743
- const settings = { ...s.settings ?? {} };
2744
- for (const key of IMAGE_KEYS) {
2745
- 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)]));
2746
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);
2747
2799
  const out = { id: s.id, type: s.type, settings };
2748
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
+ }
2749
2810
  return out;
2750
2811
  }
2751
2812
  var layoutService = new LayoutService();