@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.
- package/README.md +18 -8
- package/dist/{index-D-hnd6-D.d.cts → index-inrM-B0Z.d.cts} +37 -2
- package/dist/{index-D-hnd6-D.d.ts → index-inrM-B0Z.d.ts} +37 -2
- package/dist/index.cjs +41 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +41 -5
- package/dist/index.js.map +1 -1
- package/dist/services/index.cjs +41 -5
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.d.cts +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +41 -5
- package/dist/services/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,10 +36,11 @@ engine's routes start with `/api` too.
|
|
|
36
36
|
|
|
37
37
|
### The engine
|
|
38
38
|
|
|
39
|
-
Start it with the modules the storefront has screens for
|
|
39
|
+
Start it with the modules the storefront has screens for. The flags go before
|
|
40
|
+
`serve`; the engine ignores any that come after it.
|
|
40
41
|
|
|
41
42
|
```bash
|
|
42
|
-
gocommerce
|
|
43
|
+
gocommerce -identity -wishlist -reviews -cms -faq -menus serve
|
|
43
44
|
```
|
|
44
45
|
|
|
45
46
|
Each is optional. Without `-identity` there is no sign-in (guest checkout
|
|
@@ -50,11 +51,19 @@ business buyers (see "Beyond the storefront's screens").
|
|
|
50
51
|
|
|
51
52
|
### The browser and CORS
|
|
52
53
|
|
|
53
|
-
The engine sends
|
|
54
|
-
|
|
55
|
-
the
|
|
54
|
+
The engine sends CORS headers only to the origins listed in
|
|
55
|
+
`GOCOMMERCE_CORS_ORIGINS` (comma-separated, or `*` for any). Unset, a browser on
|
|
56
|
+
the storefront's origin cannot read a response from the engine's. Server-side
|
|
57
|
+
rendering is unaffected; it is the bag, sign-in and checkout — which run in the
|
|
58
|
+
browser — that need a route.
|
|
56
59
|
|
|
57
|
-
|
|
60
|
+
The simplest is to list the storefront's origin when starting the engine,
|
|
61
|
+
`GOCOMMERCE_CORS_ORIGINS=https://shop.example`, and leave
|
|
62
|
+
`PUBLIC_GOCOMMERCE_PROXY_PATH` unset. The browser then calls
|
|
63
|
+
`PUBLIC_GOCOMMERCE_API_URL` directly, so that has to be an address the
|
|
64
|
+
shopper's browser can reach.
|
|
65
|
+
|
|
66
|
+
Or proxy a path on the storefront's own origin to the engine and name it in
|
|
58
67
|
`PUBLIC_GOCOMMERCE_PROXY_PATH`. The browser then calls
|
|
59
68
|
`https://shop.example/gocommerce/api/carts`, and the server keeps calling
|
|
60
69
|
`PUBLIC_GOCOMMERCE_API_URL` directly. With Caddy:
|
|
@@ -129,7 +138,8 @@ down stays best-effort: the storefront renders from its static record.
|
|
|
129
138
|
| reviews | `/x/reviews` |
|
|
130
139
|
| content pages (`/p/…`, legal pages) | `/x/cms/pages` |
|
|
131
140
|
| FAQ | `/x/faq` |
|
|
132
|
-
| composed home page | `/x/layouts/home` (`?preview=` for a draft) — `layoutService.getHomeLayout()`, null when the store has none |
|
|
141
|
+
| composed home page | `/x/layouts/home` (`?preview=` for a draft) — `layoutService.getHomeLayout()`, null when the store has none; carries `themeSettings` and each collection list's `collections` |
|
|
142
|
+
| theme settings | `/x/layouts/theme` (`?preview=` for a draft) — `layoutService.getThemeSettings()`, the store's colours, fonts and rounding for every page; null when there are none |
|
|
133
143
|
| menus | `/x/navigation/menus/{header,footer}`, laid over `store.menu`; any menu by handle |
|
|
134
144
|
| product specs table | the product's category attribute answers |
|
|
135
145
|
| attribute filters (`?attributes.color=Red`) | `/api/products?attr=color:Red` |
|
|
@@ -248,7 +258,7 @@ real one, seeding what they need through the admin API under names unique to
|
|
|
248
258
|
the run:
|
|
249
259
|
|
|
250
260
|
```bash
|
|
251
|
-
gocommerce
|
|
261
|
+
gocommerce -admin-token dev-token -identity -wishlist -reviews -cms -faq -menus -newsletter -contact -b2b serve
|
|
252
262
|
GOCOMMERCE_URL=http://127.0.0.1:8080 GOCOMMERCE_ADMIN_TOKEN=dev-token \
|
|
253
263
|
GOCOMMERCE_TEST_DB=postgres://…/the-stores-database npm test
|
|
254
264
|
```
|
|
@@ -5832,17 +5832,34 @@ declare class FaqService extends BaseService {
|
|
|
5832
5832
|
declare const pageService: PageService;
|
|
5833
5833
|
declare const faqService: FaqService;
|
|
5834
5834
|
|
|
5835
|
+
/**
|
|
5836
|
+
* The store's design tokens (ext/layouts, D127). Every key is optional and
|
|
5837
|
+
* an absent one means the storefront keeps its own look: colours are
|
|
5838
|
+
* `#rrggbb`, fonts are keys of the storefront's font list, `radius` is
|
|
5839
|
+
* none, small, medium or large.
|
|
5840
|
+
*/
|
|
5841
|
+
type ThemeSettings = Partial<Record<'background' | 'text' | 'accent' | 'accent_text' | 'muted' | 'heading_font' | 'body_font' | 'radius', string>>;
|
|
5842
|
+
/** A collection list's card: enough to draw a picture and a title and link to it. */
|
|
5843
|
+
type LayoutCollection = {
|
|
5844
|
+
id: string;
|
|
5845
|
+
title: string;
|
|
5846
|
+
slug: string;
|
|
5847
|
+
link: string;
|
|
5848
|
+
image: string | null;
|
|
5849
|
+
};
|
|
5835
5850
|
/**
|
|
5836
5851
|
* One section of a composed page. `settings` is the merchant's, as validated
|
|
5837
5852
|
* by the engine: plain text (never HTML) and links that are `/path` or
|
|
5838
5853
|
* `http(s)://`. A product grid also carries its products, resolved live and
|
|
5839
|
-
* mapped like any other product the storefront renders
|
|
5854
|
+
* mapped like any other product the storefront renders; a collection list
|
|
5855
|
+
* carries its collections.
|
|
5840
5856
|
*/
|
|
5841
5857
|
type HomeLayoutSection = {
|
|
5842
5858
|
id: string;
|
|
5843
5859
|
type: string;
|
|
5844
5860
|
settings: Record<string, unknown>;
|
|
5845
5861
|
products?: StorefrontProduct[];
|
|
5862
|
+
collections?: LayoutCollection[];
|
|
5846
5863
|
};
|
|
5847
5864
|
type HomeLayout = {
|
|
5848
5865
|
page: string;
|
|
@@ -5851,8 +5868,16 @@ type HomeLayout = {
|
|
|
5851
5868
|
revision?: number;
|
|
5852
5869
|
/** True when this is the saved draft shown through a preview key. */
|
|
5853
5870
|
preview: boolean;
|
|
5871
|
+
/** The design tokens published with the page, or null for none. */
|
|
5872
|
+
themeSettings: ThemeSettings | null;
|
|
5854
5873
|
sections: HomeLayoutSection[];
|
|
5855
5874
|
};
|
|
5875
|
+
/** The design tokens alone, for every page the storefront draws. */
|
|
5876
|
+
type ThemeSettingsResult = {
|
|
5877
|
+
revision?: number;
|
|
5878
|
+
preview: boolean;
|
|
5879
|
+
settings: ThemeSettings;
|
|
5880
|
+
};
|
|
5856
5881
|
/**
|
|
5857
5882
|
* Composed pages from ext/layouts. A store without one — the plugin off,
|
|
5858
5883
|
* nothing published, an engine built without the module, or a preview key
|
|
@@ -5863,6 +5888,16 @@ declare class LayoutService extends BaseService {
|
|
|
5863
5888
|
getHomeLayout({ preview }?: {
|
|
5864
5889
|
preview?: string | null;
|
|
5865
5890
|
}): Promise<HomeLayout | null>;
|
|
5891
|
+
/**
|
|
5892
|
+
* The store's design tokens, for a page other than the home page: the
|
|
5893
|
+
* published ones, or a preview key's draft. Null when there are none to
|
|
5894
|
+
* apply — nothing published, the editor off, an engine without the
|
|
5895
|
+
* module — and on any failure too: a missing look must never cost the
|
|
5896
|
+
* page.
|
|
5897
|
+
*/
|
|
5898
|
+
getThemeSettings({ preview }?: {
|
|
5899
|
+
preview?: string | null;
|
|
5900
|
+
}): Promise<ThemeSettingsResult | null>;
|
|
5866
5901
|
}
|
|
5867
5902
|
declare const layoutService: LayoutService;
|
|
5868
5903
|
|
|
@@ -7006,4 +7041,4 @@ declare class B2bService extends BaseService {
|
|
|
7006
7041
|
}
|
|
7007
7042
|
declare const b2bService: B2bService;
|
|
7008
7043
|
|
|
7009
|
-
export { type
|
|
7044
|
+
export { type Lead as $, type Address as A, type B2bPlaced as B, type Cart as C, CountryService as D, CouponService as E, type Credentials as F, type Credit as G, CurrencyService as H, type Customer as I, DealService as J, DemoRequestService as K, type EngineRequest as L, EnquiryService as M, type Envelope as N, type Faq as O, FaqService as P, FeedbackService as Q, type Fulfillment as R, GalleryService as S, type HomeLayout as T, type HomeLayoutSection as U, HomeService as V, type IdentityAddress as W, InitService as X, type Invitation as Y, type LayoutCollection as Z, LayoutService as _, AddressService as a, bannerService as a$, type ListMeta as a0, MeilisearchService as a1, type Member as a2, type Menu as a3, type MenuItem as a4, MenuService as a5, type MenuSummary as a6, type Money as a7, NewsletterService as a8, type Offer as a9, type ShippingRate as aA, StateService as aB, type StoreProfile as aC, StoreService as aD, type StorefrontCategory as aE, type StorefrontMenu as aF, type StorefrontOrder as aG, type StorefrontProduct as aH, type ThemeSettings as aI, type ThemeSettingsResult as aJ, UploadService as aK, UserService as aL, type Variant as aM, type VariantImage as aN, VariantService as aO, VarniCustomDesignService as aP, VarniCustomProductService as aQ, type Vendor as aR, VendorService as aS, WarrantyService as aT, type Wishlist as aU, type WishlistItem as aV, WishlistService as aW, addressService as aX, authService as aY, autocompleteService as aZ, b2bService as a_, type Order as aa, type OrderLine as ab, OrderService as ac, PageService as ad, type PaymentIntent as ae, PaymentMethodService as af, type Plugin as ag, PluginService as ah, PopularSearchService as ai, PopularityService as aj, type Product as ak, type ProductOption as al, ProductService as am, ProfileService as an, type Quote as ao, REDIRECT_GATEWAYS as ap, ReelsService as aq, RegionService as ar, type RejectedLine as as, type Review as at, type ReviewPage as au, ReviewService as av, type SearchDoc as aw, type SearchResult as ax, SearchService as ay, SettingService as az, type AppliedDiscount as b, toOrder as b$, blogService as b0, cartService as b1, categoryService as b2, chatService as b3, checkoutService as b4, collectionService as b5, contactService as b6, countryService as b7, couponService as b8, currencyExponent as b9, popularSearchService as bA, popularityService as bB, priceOf as bC, productImages as bD, productService as bE, profileService as bF, qs as bG, reelsService as bH, regionService as bI, reviewService as bJ, searchService as bK, setRequestHost as bL, settingService as bM, settingsService as bN, stateService as bO, staticStore as bP, storeForHost as bQ, storeService as bR, toCart as bS, toCartLine as bT, toCategory as bU, toCmsPage as bV, toCollection as bW, toEngineAddress as bX, toIdentityAddress as bY, toMajor as bZ, toMinor as b_, currencyService as ba, dealService as bb, demoRequestService as bc, emptyCart as bd, emptyPage as be, enquiryService as bf, faqService as bg, feedbackService as bh, fromEngineAddress as bi, fromIdentityAddress as bj, fromSearchDoc as bk, galleryService as bl, homeService as bm, initService as bn, layoutService as bo, mediaUrl as bp, meilisearchService as bq, menuService as br, minorToMajor as bs, newsletterService as bt, orderService as bu, ownDomain as bv, pageService as bw, paymentMethodService as bx, pluginService as by, pluginsService as bz, type Approval as c, toPage as c0, toProduct as c1, toRating as c2, toUser as c3, toVariant as c4, toVendor as c5, uploadService as c6, userService as c7, variantService as c8, varniCustomDesignService as c9, varniCustomProductService as ca, vendorService as cb, warrantyService as cc, wishlistService as cd, type AuthResponse as d, AuthService as e, AutocompleteService as f, type B2bRole as g, B2bService as h, BannerService as i, BaseService as j, BlogService as k, type CartLine as l, CartService as m, CatalogService as n, type Category as o, CategoryService as p, ChatService as q, type CheckoutOptions as r, type CheckoutResult as s, CheckoutService as t, type CmsPage as u, type Collection as v, CollectionService as w, type Company as x, type CompanyOrder as y, ContactService as z };
|
|
@@ -5832,17 +5832,34 @@ declare class FaqService extends BaseService {
|
|
|
5832
5832
|
declare const pageService: PageService;
|
|
5833
5833
|
declare const faqService: FaqService;
|
|
5834
5834
|
|
|
5835
|
+
/**
|
|
5836
|
+
* The store's design tokens (ext/layouts, D127). Every key is optional and
|
|
5837
|
+
* an absent one means the storefront keeps its own look: colours are
|
|
5838
|
+
* `#rrggbb`, fonts are keys of the storefront's font list, `radius` is
|
|
5839
|
+
* none, small, medium or large.
|
|
5840
|
+
*/
|
|
5841
|
+
type ThemeSettings = Partial<Record<'background' | 'text' | 'accent' | 'accent_text' | 'muted' | 'heading_font' | 'body_font' | 'radius', string>>;
|
|
5842
|
+
/** A collection list's card: enough to draw a picture and a title and link to it. */
|
|
5843
|
+
type LayoutCollection = {
|
|
5844
|
+
id: string;
|
|
5845
|
+
title: string;
|
|
5846
|
+
slug: string;
|
|
5847
|
+
link: string;
|
|
5848
|
+
image: string | null;
|
|
5849
|
+
};
|
|
5835
5850
|
/**
|
|
5836
5851
|
* One section of a composed page. `settings` is the merchant's, as validated
|
|
5837
5852
|
* by the engine: plain text (never HTML) and links that are `/path` or
|
|
5838
5853
|
* `http(s)://`. A product grid also carries its products, resolved live and
|
|
5839
|
-
* mapped like any other product the storefront renders
|
|
5854
|
+
* mapped like any other product the storefront renders; a collection list
|
|
5855
|
+
* carries its collections.
|
|
5840
5856
|
*/
|
|
5841
5857
|
type HomeLayoutSection = {
|
|
5842
5858
|
id: string;
|
|
5843
5859
|
type: string;
|
|
5844
5860
|
settings: Record<string, unknown>;
|
|
5845
5861
|
products?: StorefrontProduct[];
|
|
5862
|
+
collections?: LayoutCollection[];
|
|
5846
5863
|
};
|
|
5847
5864
|
type HomeLayout = {
|
|
5848
5865
|
page: string;
|
|
@@ -5851,8 +5868,16 @@ type HomeLayout = {
|
|
|
5851
5868
|
revision?: number;
|
|
5852
5869
|
/** True when this is the saved draft shown through a preview key. */
|
|
5853
5870
|
preview: boolean;
|
|
5871
|
+
/** The design tokens published with the page, or null for none. */
|
|
5872
|
+
themeSettings: ThemeSettings | null;
|
|
5854
5873
|
sections: HomeLayoutSection[];
|
|
5855
5874
|
};
|
|
5875
|
+
/** The design tokens alone, for every page the storefront draws. */
|
|
5876
|
+
type ThemeSettingsResult = {
|
|
5877
|
+
revision?: number;
|
|
5878
|
+
preview: boolean;
|
|
5879
|
+
settings: ThemeSettings;
|
|
5880
|
+
};
|
|
5856
5881
|
/**
|
|
5857
5882
|
* Composed pages from ext/layouts. A store without one — the plugin off,
|
|
5858
5883
|
* nothing published, an engine built without the module, or a preview key
|
|
@@ -5863,6 +5888,16 @@ declare class LayoutService extends BaseService {
|
|
|
5863
5888
|
getHomeLayout({ preview }?: {
|
|
5864
5889
|
preview?: string | null;
|
|
5865
5890
|
}): Promise<HomeLayout | null>;
|
|
5891
|
+
/**
|
|
5892
|
+
* The store's design tokens, for a page other than the home page: the
|
|
5893
|
+
* published ones, or a preview key's draft. Null when there are none to
|
|
5894
|
+
* apply — nothing published, the editor off, an engine without the
|
|
5895
|
+
* module — and on any failure too: a missing look must never cost the
|
|
5896
|
+
* page.
|
|
5897
|
+
*/
|
|
5898
|
+
getThemeSettings({ preview }?: {
|
|
5899
|
+
preview?: string | null;
|
|
5900
|
+
}): Promise<ThemeSettingsResult | null>;
|
|
5866
5901
|
}
|
|
5867
5902
|
declare const layoutService: LayoutService;
|
|
5868
5903
|
|
|
@@ -7006,4 +7041,4 @@ declare class B2bService extends BaseService {
|
|
|
7006
7041
|
}
|
|
7007
7042
|
declare const b2bService: B2bService;
|
|
7008
7043
|
|
|
7009
|
-
export { type
|
|
7044
|
+
export { type Lead as $, type Address as A, type B2bPlaced as B, type Cart as C, CountryService as D, CouponService as E, type Credentials as F, type Credit as G, CurrencyService as H, type Customer as I, DealService as J, DemoRequestService as K, type EngineRequest as L, EnquiryService as M, type Envelope as N, type Faq as O, FaqService as P, FeedbackService as Q, type Fulfillment as R, GalleryService as S, type HomeLayout as T, type HomeLayoutSection as U, HomeService as V, type IdentityAddress as W, InitService as X, type Invitation as Y, type LayoutCollection as Z, LayoutService as _, AddressService as a, bannerService as a$, type ListMeta as a0, MeilisearchService as a1, type Member as a2, type Menu as a3, type MenuItem as a4, MenuService as a5, type MenuSummary as a6, type Money as a7, NewsletterService as a8, type Offer as a9, type ShippingRate as aA, StateService as aB, type StoreProfile as aC, StoreService as aD, type StorefrontCategory as aE, type StorefrontMenu as aF, type StorefrontOrder as aG, type StorefrontProduct as aH, type ThemeSettings as aI, type ThemeSettingsResult as aJ, UploadService as aK, UserService as aL, type Variant as aM, type VariantImage as aN, VariantService as aO, VarniCustomDesignService as aP, VarniCustomProductService as aQ, type Vendor as aR, VendorService as aS, WarrantyService as aT, type Wishlist as aU, type WishlistItem as aV, WishlistService as aW, addressService as aX, authService as aY, autocompleteService as aZ, b2bService as a_, type Order as aa, type OrderLine as ab, OrderService as ac, PageService as ad, type PaymentIntent as ae, PaymentMethodService as af, type Plugin as ag, PluginService as ah, PopularSearchService as ai, PopularityService as aj, type Product as ak, type ProductOption as al, ProductService as am, ProfileService as an, type Quote as ao, REDIRECT_GATEWAYS as ap, ReelsService as aq, RegionService as ar, type RejectedLine as as, type Review as at, type ReviewPage as au, ReviewService as av, type SearchDoc as aw, type SearchResult as ax, SearchService as ay, SettingService as az, type AppliedDiscount as b, toOrder as b$, blogService as b0, cartService as b1, categoryService as b2, chatService as b3, checkoutService as b4, collectionService as b5, contactService as b6, countryService as b7, couponService as b8, currencyExponent as b9, popularSearchService as bA, popularityService as bB, priceOf as bC, productImages as bD, productService as bE, profileService as bF, qs as bG, reelsService as bH, regionService as bI, reviewService as bJ, searchService as bK, setRequestHost as bL, settingService as bM, settingsService as bN, stateService as bO, staticStore as bP, storeForHost as bQ, storeService as bR, toCart as bS, toCartLine as bT, toCategory as bU, toCmsPage as bV, toCollection as bW, toEngineAddress as bX, toIdentityAddress as bY, toMajor as bZ, toMinor as b_, currencyService as ba, dealService as bb, demoRequestService as bc, emptyCart as bd, emptyPage as be, enquiryService as bf, faqService as bg, feedbackService as bh, fromEngineAddress as bi, fromIdentityAddress as bj, fromSearchDoc as bk, galleryService as bl, homeService as bm, initService as bn, layoutService as bo, mediaUrl as bp, meilisearchService as bq, menuService as br, minorToMajor as bs, newsletterService as bt, orderService as bu, ownDomain as bv, pageService as bw, paymentMethodService as bx, pluginService as by, pluginsService as bz, type Approval as c, toPage as c0, toProduct as c1, toRating as c2, toUser as c3, toVariant as c4, toVendor as c5, uploadService as c6, userService as c7, variantService as c8, varniCustomDesignService as c9, varniCustomProductService as ca, vendorService as cb, warrantyService as cc, wishlistService as cd, type AuthResponse as d, AuthService as e, AutocompleteService as f, type B2bRole as g, B2bService as h, BannerService as i, BaseService as j, BlogService as k, type CartLine as l, CartService as m, CatalogService as n, type Category as o, CategoryService as p, ChatService as q, type CheckoutOptions as r, type CheckoutResult as s, CheckoutService as t, type CmsPage as u, type Collection as v, CollectionService as w, type Company as x, type CompanyOrder as y, ContactService as z };
|
package/dist/index.cjs
CHANGED
|
@@ -2758,7 +2758,7 @@ var pageService = new PageService();
|
|
|
2758
2758
|
var faqService = new FaqService();
|
|
2759
2759
|
|
|
2760
2760
|
// src/services/layout-service.ts
|
|
2761
|
-
var
|
|
2761
|
+
var MEDIA_KEYS = /* @__PURE__ */ new Set(["image", "mobile_image", "poster", "video_file"]);
|
|
2762
2762
|
var LayoutService = class extends BaseService {
|
|
2763
2763
|
async getHomeLayout({ preview } = {}) {
|
|
2764
2764
|
let layout;
|
|
@@ -2776,17 +2776,53 @@ var LayoutService = class extends BaseService {
|
|
|
2776
2776
|
theme: layout.theme,
|
|
2777
2777
|
revision: layout.revision,
|
|
2778
2778
|
preview: !!layout.preview,
|
|
2779
|
+
themeSettings: tokens(layout.theme_settings),
|
|
2779
2780
|
sections: (layout.sections ?? []).map(toSection)
|
|
2780
2781
|
};
|
|
2781
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
|
+
}
|
|
2782
2801
|
};
|
|
2783
|
-
function
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
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)]));
|
|
2787
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);
|
|
2788
2815
|
const out = { id: s.id, type: s.type, settings };
|
|
2789
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
|
+
}
|
|
2790
2826
|
return out;
|
|
2791
2827
|
}
|
|
2792
2828
|
var layoutService = new LayoutService();
|