@shop-on/theme-server 0.10.0 → 0.11.1
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/dist/account-state.js +1 -2
- package/dist/account.d.ts +1 -3
- package/dist/account.js +1 -3
- package/dist/activity.d.ts +1 -3
- package/dist/activity.js +1 -2
- package/dist/analytics-proxy.d.ts +8 -14
- package/dist/analytics-proxy.js +111 -28
- package/dist/analytics-script-proxy.d.ts +1 -5
- package/dist/analytics-script-proxy.js +4 -14
- package/dist/api-contract/src/addresses.js +32 -0
- package/dist/api-contract/src/areas.js +49 -0
- package/dist/api-contract/src/custom-data.d.ts +31 -0
- package/dist/api-contract/src/custom-data.js +303 -0
- package/dist/api-contract/src/ids.js +110 -0
- package/dist/api-contract/src/image.js +65 -0
- package/dist/api-contract/src/limits.js +44 -0
- package/dist/api-contract/src/media.js +13 -0
- package/dist/api-contract/src/pickup.js +11 -0
- package/dist/api-contract/src/recommendations.js +4 -0
- package/dist/api-contract/src/shops.js +27 -0
- package/dist/api-contract/src/storefront/analytics.d.ts +100 -0
- package/dist/api-contract/src/storefront/analytics.js +138 -0
- package/dist/api-contract/src/storefront/areas.d.ts +2 -0
- package/dist/api-contract/src/storefront/cart.d.ts +132 -0
- package/dist/api-contract/src/storefront/cart.js +248 -0
- package/dist/api-contract/src/storefront/catalog.d.ts +3 -0
- package/dist/api-contract/src/storefront/checkout-analytics.d.ts +2 -0
- package/dist/api-contract/src/storefront/checkout.d.ts +2 -0
- package/dist/api-contract/src/storefront/checkout.js +624 -0
- package/dist/api-contract/src/storefront/client.d.ts +3 -0
- package/dist/api-contract/src/storefront/client.js +6 -0
- package/dist/api-contract/src/storefront/content.d.ts +3 -0
- package/dist/api-contract/src/storefront/custom-data.d.ts +2 -0
- package/dist/api-contract/src/storefront/custom-data.js +27 -0
- package/dist/api-contract/src/storefront/customer.d.ts +2 -0
- package/dist/api-contract/src/storefront/customer.js +261 -0
- package/dist/api-contract/src/storefront/downloads.d.ts +2 -0
- package/dist/api-contract/src/storefront/draft-order-invoice.d.ts +2 -0
- package/dist/api-contract/src/storefront/forms.d.ts +2 -0
- package/dist/api-contract/src/storefront/forms.js +82 -0
- package/dist/api-contract/src/storefront/index.d.ts +20956 -0
- package/dist/api-contract/src/storefront/orders.d.ts +2 -0
- package/dist/api-contract/src/storefront/policies.d.ts +2 -0
- package/dist/api-contract/src/storefront/procedure.d.ts +2 -0
- package/dist/api-contract/src/storefront/procedure.js +29 -0
- package/dist/api-contract/src/storefront/reviews.d.ts +20 -0
- package/dist/api-contract/src/storefront/search.d.ts +3 -0
- package/dist/api-contract/src/storefront/seo.d.ts +2 -0
- package/dist/api-contract/src/storefront/seo.js +132 -0
- package/dist/api-contract/src/storefront/shop.d.ts +2 -0
- package/dist/api-contract/src/storefront/shop.js +101 -0
- package/dist/api-contract/src/taxonomy.js +5 -0
- package/dist/api-contract/src/text.js +15 -0
- package/dist/api-contract/src/theme-documents.js +13 -0
- package/dist/api-contract/src/theme-translations.d.ts +14 -0
- package/dist/api-contract/src/theme-translations.js +30 -0
- package/dist/api-contract/src/video.js +19 -0
- package/dist/availability.d.ts +6 -3
- package/dist/availability.js +11 -5
- package/dist/blog.d.ts +53 -59
- package/dist/blog.js +197 -497
- package/dist/cache.d.ts +5 -6
- package/dist/cache.js +1 -2
- package/dist/canonical-host.d.ts +4 -6
- package/dist/canonical-host.js +5 -6
- package/dist/card.js +159 -0
- package/dist/cart-customer.d.ts +1 -3
- package/dist/cart-customer.js +64 -105
- package/dist/cart-mutations.d.ts +43 -77
- package/dist/cart-mutations.js +106 -232
- package/dist/cart-recommendations.d.ts +1 -3
- package/dist/cart-recommendations.js +1 -2
- package/dist/cart-session.d.ts +1 -3
- package/dist/cart-session.js +1 -2
- package/dist/cart.d.ts +63 -224
- package/dist/cart.js +70 -197
- package/dist/checkout.d.ts +13 -17
- package/dist/checkout.js +75 -101
- package/dist/coalesce.js +57 -0
- package/dist/collection.d.ts +89 -298
- package/dist/collection.js +210 -656
- package/dist/contact.d.ts +20 -10
- package/dist/contact.js +36 -30
- package/dist/content-version.d.ts +37 -21
- package/dist/content-version.js +64 -42
- package/dist/contract-kit/src/client.d.ts +12 -0
- package/dist/contract-kit/src/client.js +156 -0
- package/dist/contract-kit/src/errors.d.ts +1 -0
- package/dist/contract-kit/src/errors.js +81 -0
- package/dist/contract-kit/src/ids.d.ts +1 -0
- package/dist/contract-kit/src/ids.js +118 -0
- package/dist/contract-kit/src/index.d.ts +7 -0
- package/dist/contract-kit/src/money.d.ts +1 -0
- package/dist/contract-kit/src/money.js +10 -0
- package/dist/contract-kit/src/pagination.d.ts +1 -0
- package/dist/contract-kit/src/procedure.d.ts +69 -0
- package/dist/contract-kit/src/procedure.js +16 -0
- package/dist/contract-kit/src/realtime.d.ts +1 -0
- package/dist/cookie-secret.js +1 -2
- package/dist/csrf.js +1 -2
- package/dist/customer-handoff.d.ts +1 -3
- package/dist/customer-handoff.js +10 -25
- package/dist/customer-session.d.ts +1 -3
- package/dist/customer-session.js +1 -2
- package/dist/customer.d.ts +2 -3
- package/dist/customer.js +27 -44
- package/dist/files.d.ts +49 -10
- package/dist/files.js +106 -89
- package/dist/fonts.d.ts +3 -5
- package/dist/fonts.js +16 -35
- package/dist/html.d.ts +1 -3
- package/dist/html.js +1 -2
- package/dist/liquid.d.ts +4 -10
- package/dist/liquid.js +25 -32
- package/dist/listing.js +79 -0
- package/dist/marketing-cookies.d.ts +1 -3
- package/dist/marketing-cookies.js +1 -2
- package/dist/menu.d.ts +46 -155
- package/dist/menu.js +51 -61
- package/dist/metafields.d.ts +9 -5
- package/dist/metafields.js +10 -38
- package/dist/metaobject.d.ts +10 -5
- package/dist/metaobject.js +43 -66
- package/dist/money.d.ts +7 -0
- package/dist/money.js +18 -0
- package/dist/newsletter.d.ts +19 -10
- package/dist/newsletter.js +31 -25
- package/dist/page.d.ts +13 -17
- package/dist/page.js +49 -105
- package/dist/password-session.d.ts +1 -3
- package/dist/password-session.js +1 -2
- package/dist/password.d.ts +25 -18
- package/dist/password.js +41 -59
- package/dist/policy.d.ts +7 -7
- package/dist/policy.js +19 -55
- package/dist/product.d.ts +42 -67
- package/dist/product.js +144 -644
- package/dist/read-ahead.d.ts +18 -0
- package/dist/read-ahead.js +32 -0
- package/dist/recommendations.d.ts +6 -12
- package/dist/recommendations.js +36 -60
- package/dist/review.d.ts +134 -94
- package/dist/review.js +257 -469
- package/dist/search.d.ts +59 -64
- package/dist/search.js +170 -469
- package/dist/seo-context.d.ts +1 -3
- package/dist/seo-context.js +4 -5
- package/dist/seo-documents.d.ts +50 -0
- package/dist/seo-documents.js +149 -0
- package/dist/shop-seo.d.ts +3 -5
- package/dist/shop-seo.js +7 -26
- package/dist/shop.d.ts +38 -42
- package/dist/shop.js +37 -51
- package/dist/store-availability.d.ts +12 -14
- package/dist/store-availability.js +18 -56
- package/dist/storefront.js +199 -0
- package/dist/structured-data.d.ts +3 -28
- package/dist/structured-data.js +19 -49
- package/dist/trace.js +1 -2
- package/dist/translations.d.ts +26 -31
- package/dist/translations.js +55 -28
- package/package.json +16 -14
- package/dist/graphql-env.d.ts +0 -22778
- package/dist/graphql.d.ts +0 -64
- package/dist/graphql.js +0 -344
- package/dist/schema.storefront.graphql +0 -10483
- package/dist/seo-proxy.d.ts +0 -11
- package/dist/seo-proxy.js +0 -26
package/dist/files.js
CHANGED
|
@@ -1,47 +1,10 @@
|
|
|
1
|
+
import { liteId } from "./api-contract/src/ids.js";
|
|
2
|
+
import { imageUrl } from "./api-contract/src/image.js";
|
|
1
3
|
import { memoTTL } from "./cache.js";
|
|
2
|
-
import {
|
|
4
|
+
import { coalescedReads } from "./coalesce.js";
|
|
3
5
|
import { getContentVersion } from "./content-version.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
query FileById(
|
|
7
|
-
$id: ID!
|
|
8
|
-
$transform: ImageTransformInput
|
|
9
|
-
$transform1_5x: ImageTransformInput
|
|
10
|
-
$transform2x: ImageTransformInput
|
|
11
|
-
$transform3x: ImageTransformInput
|
|
12
|
-
) {
|
|
13
|
-
node(id: $id) {
|
|
14
|
-
__typename
|
|
15
|
-
... on ShopMediaImage {
|
|
16
|
-
id
|
|
17
|
-
alt
|
|
18
|
-
thumbhash
|
|
19
|
-
width
|
|
20
|
-
height
|
|
21
|
-
url(transform: $transform)
|
|
22
|
-
url1_5x: url(transform: $transform1_5x)
|
|
23
|
-
url2x: url(transform: $transform2x)
|
|
24
|
-
url3x: url(transform: $transform3x)
|
|
25
|
-
focalPoint {
|
|
26
|
-
x
|
|
27
|
-
y
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
... on ShopVideo {
|
|
31
|
-
id
|
|
32
|
-
alt
|
|
33
|
-
url
|
|
34
|
-
hlsUrl
|
|
35
|
-
preview {
|
|
36
|
-
url(transform: $transform)
|
|
37
|
-
}
|
|
38
|
-
width
|
|
39
|
-
height
|
|
40
|
-
duration
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
`);
|
|
6
|
+
import { orFallback, storefront } from "./storefront.js";
|
|
7
|
+
// src/files.ts
|
|
45
8
|
function buildSrcset(entries) {
|
|
46
9
|
const parts = [];
|
|
47
10
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -74,24 +37,21 @@ function ladderSrcset(node, baseWidth) {
|
|
|
74
37
|
}
|
|
75
38
|
function toFileInfo(node, extra = {}) {
|
|
76
39
|
if (!node) return null;
|
|
77
|
-
if (node.__typename === "ShopMediaImage") {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
} : null
|
|
93
|
-
};
|
|
94
|
-
}
|
|
40
|
+
if (node.__typename === "ShopMediaImage") return {
|
|
41
|
+
kind: "image",
|
|
42
|
+
id: node.id ?? "",
|
|
43
|
+
alt: node.alt ?? null,
|
|
44
|
+
url: node.url ?? null,
|
|
45
|
+
srcset: extra.baseWidth != null ? ladderSrcset(node, extra.baseWidth) : null,
|
|
46
|
+
thumbUrl: node.thumbUrl ?? null,
|
|
47
|
+
thumbhash: node.thumbhash ?? null,
|
|
48
|
+
width: node.width ?? null,
|
|
49
|
+
height: node.height ?? null,
|
|
50
|
+
focalPoint: node.focalPoint ? {
|
|
51
|
+
x: node.focalPoint.x,
|
|
52
|
+
y: node.focalPoint.y
|
|
53
|
+
} : null
|
|
54
|
+
};
|
|
95
55
|
if (node.__typename === "ShopVideo") {
|
|
96
56
|
const hlsUrl = node.hlsUrl ?? null;
|
|
97
57
|
return {
|
|
@@ -108,41 +68,98 @@ function toFileInfo(node, extra = {}) {
|
|
|
108
68
|
}
|
|
109
69
|
return null;
|
|
110
70
|
}
|
|
111
|
-
|
|
112
|
-
|
|
71
|
+
/** `image` as every renderer draws it: `url` at `baseWidth`, a srcset of its
|
|
72
|
+
* 1×, 1.5×, 2× and 3× rungs, and an 80px thumb. A rung past the original's
|
|
73
|
+
* width is left out and every size is `scale-down`, so an image is never
|
|
74
|
+
* enlarged (legacy's `maxWidth`); an image that cannot be resized is its
|
|
75
|
+
* original, with no srcset. */
|
|
76
|
+
function imageFileInfo(image, baseWidth) {
|
|
77
|
+
const at = (width) => imageUrl(image, {
|
|
78
|
+
width,
|
|
79
|
+
fit: "scale-down"
|
|
80
|
+
});
|
|
81
|
+
const rungs = [
|
|
82
|
+
1,
|
|
83
|
+
1.5,
|
|
84
|
+
2,
|
|
85
|
+
3
|
|
86
|
+
].map((factor) => Math.round(baseWidth * factor)).filter((width, index) => index === 0 || width <= image.width);
|
|
113
87
|
return {
|
|
114
|
-
|
|
115
|
-
|
|
88
|
+
kind: "image",
|
|
89
|
+
id: image.id,
|
|
90
|
+
alt: image.alt,
|
|
91
|
+
url: at(baseWidth),
|
|
92
|
+
srcset: buildSrcset(rungs.map((width) => ({
|
|
93
|
+
url: at(width),
|
|
94
|
+
w: width
|
|
95
|
+
}))),
|
|
96
|
+
thumbUrl: at(80),
|
|
97
|
+
thumbhash: image.thumbhash,
|
|
98
|
+
width: image.width,
|
|
99
|
+
height: image.height,
|
|
100
|
+
focalPoint: image.focalPoint && {
|
|
101
|
+
x: image.focalPoint.x,
|
|
102
|
+
y: image.focalPoint.y
|
|
103
|
+
}
|
|
116
104
|
};
|
|
117
105
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
106
|
+
/** `video` as every player loads it: the HLS bundle, and its poster at
|
|
107
|
+
* `baseWidth`. The MP4 stays off the payload: a ready video always has its
|
|
108
|
+
* bundle. */
|
|
109
|
+
function videoFileInfo(video, baseWidth) {
|
|
121
110
|
return {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
111
|
+
kind: "video",
|
|
112
|
+
id: video.id,
|
|
113
|
+
alt: video.alt,
|
|
114
|
+
url: null,
|
|
115
|
+
hlsUrl: video.hlsUrl,
|
|
116
|
+
previewUrl: imageUrl(video.poster, {
|
|
117
|
+
width: baseWidth,
|
|
118
|
+
fit: "scale-down"
|
|
119
|
+
}),
|
|
120
|
+
width: video.width,
|
|
121
|
+
height: video.height,
|
|
122
|
+
duration: video.durationMs / 1e3
|
|
125
123
|
};
|
|
126
124
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
125
|
+
/** A product's media item (`@shop-on/api-contract/media`) as renderers draw
|
|
126
|
+
* it; its id is its file's, the one a variant's media ids name. Null while
|
|
127
|
+
* the file is still processing. */
|
|
128
|
+
function mediaFileInfo(media, baseWidth) {
|
|
129
|
+
if (media.image) return imageFileInfo(media.image, baseWidth);
|
|
130
|
+
if (media.video) return videoFileInfo(media.video, baseWidth);
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
/** The width an image is drawn at in `transform`'s box: never past its own
|
|
134
|
+
* width, a height-only box scaled through its aspect; with no box, as it is. */
|
|
135
|
+
function boxWidth(size, transform) {
|
|
136
|
+
const byWidth = transform?.maxWidth ?? size.width;
|
|
137
|
+
const byHeight = transform?.maxHeight ? Math.round(size.width * transform.maxHeight / size.height) : size.width;
|
|
138
|
+
return Math.max(1, Math.min(byWidth, byHeight, size.width));
|
|
139
|
+
}
|
|
140
|
+
/** The library files one request's tick names go out in one `files.cards`
|
|
141
|
+
* call: a page of twenty image settings is one call. */
|
|
142
|
+
const coalescedFile = coalescedReads({
|
|
143
|
+
max: 50,
|
|
144
|
+
matches: (file, ref) => file.fileId === ref
|
|
145
|
+
});
|
|
146
|
+
const readFile = memoTTL(async ({ id, transform }) => {
|
|
147
|
+
const file = await coalescedFile("", id, async (refs) => {
|
|
148
|
+
return (await storefront().files.cards({ refs: refs.map((ref) => ({ fileId: liteId("file").parse(ref) })) })).items;
|
|
149
|
+
});
|
|
150
|
+
if (file?.image) return imageFileInfo(file.image, boxWidth(file.image, transform));
|
|
151
|
+
if (file?.video) return videoFileInfo(file.video, boxWidth(file.video, transform));
|
|
152
|
+
return null;
|
|
143
153
|
}, {
|
|
144
|
-
key: ({ id, transform }) => `${id}|${transform
|
|
154
|
+
key: ({ id, transform }) => `${id}|${transform?.maxWidth ?? ""}x${transform?.maxHeight ?? ""}`,
|
|
145
155
|
version: getContentVersion
|
|
146
156
|
});
|
|
147
|
-
|
|
148
|
-
|
|
157
|
+
/** A library file by its id (an `image_picker`, `video` or logo setting), an
|
|
158
|
+
* image drawn in `transform`'s box. Null for anything a buyer may not see: not
|
|
159
|
+
* a `file_…` id (no call), still processing, not the library's, a font or a
|
|
160
|
+
* document; and on a failed read, which is not cached. */
|
|
161
|
+
async function fetchFileById(file) {
|
|
162
|
+
if (!liteId("file").safeParse(file.id).success) return null;
|
|
163
|
+
return orFallback(readFile(file), null, "fetchFileById");
|
|
164
|
+
}
|
|
165
|
+
export { fetchFileById, imageFileInfo, mediaFileInfo, toFileInfo, videoFileInfo };
|
package/dist/fonts.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { UploadedFont } from "@shop-on/theme-runtime/fonts";
|
|
2
|
-
//#region src/fonts.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* The uploaded font family a `font_picker` value names, or null when it names
|
|
5
|
-
* none this shop can draw. A Google family, `system-ui` and
|
|
6
|
-
* make no request: only
|
|
4
|
+
* none this shop can draw. A Google family, `system-ui` and another kind's id
|
|
5
|
+
* make no request: only a `font_family_…` id is ever a family's.
|
|
7
6
|
*/
|
|
8
|
-
export declare function fetchUploadedFont(value: string): Promise<UploadedFont | null>;
|
|
9
|
-
//#endregion
|
|
7
|
+
export declare function fetchUploadedFont(value: string): Promise<UploadedFont | null>;
|
package/dist/fonts.js
CHANGED
|
@@ -1,48 +1,30 @@
|
|
|
1
|
+
import { liteId } from "./api-contract/src/ids.js";
|
|
1
2
|
import { memoTTL } from "./cache.js";
|
|
2
|
-
import { graphql, request } from "./graphql.js";
|
|
3
3
|
import { getContentVersion } from "./content-version.js";
|
|
4
|
+
import { orNotFound, storefront } from "./storefront.js";
|
|
4
5
|
import { fontFormat, isRenderableFace, uploadedFontFamily } from "@shop-on/theme-runtime/fonts";
|
|
5
|
-
|
|
6
|
-
const UploadedFontFamilyQuery = graphql(`
|
|
7
|
-
query UploadedFontFamily($id: ID!) {
|
|
8
|
-
node(id: $id) {
|
|
9
|
-
__typename
|
|
10
|
-
... on ShopFontFamily {
|
|
11
|
-
id
|
|
12
|
-
faces {
|
|
13
|
-
weightMin
|
|
14
|
-
weightMax
|
|
15
|
-
style
|
|
16
|
-
file {
|
|
17
|
-
url
|
|
18
|
-
contentType
|
|
19
|
-
byteSize
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
`);
|
|
6
|
+
// src/fonts.ts
|
|
26
7
|
const fetchFontFamily = memoTTL(async (id) => {
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
|
|
8
|
+
const fontFamilyId = liteId("font_family").safeParse(id);
|
|
9
|
+
if (!fontFamilyId.success) return null;
|
|
10
|
+
const family = await orNotFound(storefront().fonts.get({ fontFamilyId: fontFamilyId.data }));
|
|
11
|
+
if (!family) return null;
|
|
30
12
|
const faces = [];
|
|
31
|
-
for (const face of
|
|
32
|
-
const format = fontFormat(face.
|
|
33
|
-
if (!
|
|
13
|
+
for (const face of family.faces) {
|
|
14
|
+
const format = fontFormat(face.contentType);
|
|
15
|
+
if (!format) continue;
|
|
34
16
|
const candidate = {
|
|
35
|
-
url: face.
|
|
17
|
+
url: face.url,
|
|
36
18
|
format,
|
|
37
|
-
byteSize:
|
|
19
|
+
byteSize: face.byteSize,
|
|
38
20
|
weightMin: face.weightMin,
|
|
39
21
|
weightMax: face.weightMax,
|
|
40
|
-
style: face.style
|
|
22
|
+
style: face.style
|
|
41
23
|
};
|
|
42
24
|
if (isRenderableFace(candidate)) faces.push(candidate);
|
|
43
25
|
}
|
|
44
26
|
return faces.length > 0 ? {
|
|
45
|
-
id
|
|
27
|
+
id,
|
|
46
28
|
faces
|
|
47
29
|
} : null;
|
|
48
30
|
}, {
|
|
@@ -51,11 +33,10 @@ const fetchFontFamily = memoTTL(async (id) => {
|
|
|
51
33
|
});
|
|
52
34
|
/**
|
|
53
35
|
* The uploaded font family a `font_picker` value names, or null when it names
|
|
54
|
-
* none this shop can draw. A Google family, `system-ui` and
|
|
55
|
-
* make no request: only
|
|
36
|
+
* none this shop can draw. A Google family, `system-ui` and another kind's id
|
|
37
|
+
* make no request: only a `font_family_…` id is ever a family's.
|
|
56
38
|
*/
|
|
57
39
|
async function fetchUploadedFont(value) {
|
|
58
40
|
return uploadedFontFamily(value) === null ? null : fetchFontFamily(value);
|
|
59
41
|
}
|
|
60
|
-
//#endregion
|
|
61
42
|
export { fetchUploadedFont };
|
package/dist/html.d.ts
CHANGED
package/dist/html.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/html.ts
|
|
2
2
|
const REPLACEMENTS = {
|
|
3
3
|
"&": "&",
|
|
4
4
|
"<": "<",
|
|
@@ -9,5 +9,4 @@ const REPLACEMENTS = {
|
|
|
9
9
|
function escapeHtmlAttr(value) {
|
|
10
10
|
return value.replace(/[&<>"']/g, (ch) => REPLACEMENTS[ch] ?? ch);
|
|
11
11
|
}
|
|
12
|
-
//#endregion
|
|
13
12
|
export { escapeHtmlAttr };
|
package/dist/liquid.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { MenuData } from "./menu.js";
|
|
|
3
3
|
import { MetaobjectData } from "./metaobject.js";
|
|
4
4
|
import { ProductData } from "./product.js";
|
|
5
5
|
import { Money } from "@shop-on/theme-runtime/money";
|
|
6
|
-
//#region src/liquid.d.ts
|
|
7
6
|
export type LiquidImage = {
|
|
8
7
|
url: string | null;
|
|
9
8
|
alt: string | null;
|
|
@@ -151,7 +150,7 @@ export type CustomPage = {
|
|
|
151
150
|
content: SafeHtml;
|
|
152
151
|
};
|
|
153
152
|
/** `content` is `SafeHtml`: `Shop::Page` sanitizes `body` on every assignment
|
|
154
|
-
* (`sanitizes_html :body`,
|
|
153
|
+
* (`sanitizes_html :body`, legacy/api/app/models/shop/page.rb) and its
|
|
155
154
|
* translations are html-format rows, sanitized on write
|
|
156
155
|
* (`Shop::Translation#sanitize_html_value`). */
|
|
157
156
|
export declare function customPage(page: {
|
|
@@ -159,18 +158,14 @@ export declare function customPage(page: {
|
|
|
159
158
|
title: string;
|
|
160
159
|
bodyHtml: string;
|
|
161
160
|
}): CustomPage;
|
|
162
|
-
export type CustomEntryField = {
|
|
163
|
-
type: string;
|
|
164
|
-
value: string | null;
|
|
165
|
-
values: string[];
|
|
161
|
+
export type CustomEntryField = CustomMetafield & {
|
|
166
162
|
image: CustomImage | null;
|
|
167
|
-
html: SafeHtml | null;
|
|
168
163
|
};
|
|
169
164
|
export type CustomEntry = {
|
|
170
165
|
handle: string;
|
|
171
166
|
type: string;
|
|
172
167
|
name: string;
|
|
173
|
-
/** A nested entry reference stays its
|
|
168
|
+
/** A nested entry reference stays its id, as in `MetaobjectData`. */
|
|
174
169
|
fields: Record<string, CustomEntryField>;
|
|
175
170
|
};
|
|
176
171
|
export declare function customEntry(entry: MetaobjectData): CustomEntry;
|
|
@@ -196,5 +191,4 @@ export declare function renderCustomLiquid(args: {
|
|
|
196
191
|
}): Promise<{
|
|
197
192
|
html: string;
|
|
198
193
|
error?: string;
|
|
199
|
-
}>;
|
|
200
|
-
//#endregion
|
|
194
|
+
}>;
|
package/dist/liquid.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { escapeHtmlAttr } from "./html.js";
|
|
2
|
-
import { parseListValues } from "./metafields.js";
|
|
3
2
|
import { Context, Liquid } from "liquidjs";
|
|
4
3
|
import { normalizeCustomUrl } from "@shop-on/theme-contract";
|
|
5
4
|
import { CUSTOM_LIQUID_PARSE_OPTIONS, restrictToCustomTags } from "@shop-on/theme-contract/custom-section";
|
|
6
5
|
import { formatMoney } from "@shop-on/theme-runtime/money";
|
|
7
6
|
import { productHref } from "@shop-on/theme-runtime/product-href";
|
|
8
7
|
import { serializeRichText } from "@shop-on/theme-runtime/richtext";
|
|
9
|
-
|
|
8
|
+
// src/liquid.ts
|
|
10
9
|
const ENGINES = /* @__PURE__ */ new Map();
|
|
11
10
|
const MAX_ENGINES = 16;
|
|
12
11
|
const DEFAULT_LOCALE = "en-US";
|
|
@@ -203,13 +202,19 @@ function imageUrl(value, width) {
|
|
|
203
202
|
if (variants.length === 0) return image.url;
|
|
204
203
|
return (variants.find((v) => v.w >= want) ?? variants.at(-1)).url;
|
|
205
204
|
}
|
|
206
|
-
/** A
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
205
|
+
/** A wire value (the api's: lowercase type, a list's value an array) as the
|
|
206
|
+
* drop a template reads: `value` its text (a list or a rich text tree as its
|
|
207
|
+
* JSON), `values` a list's items, `html` a rich text's HTML through the one
|
|
208
|
+
* serializer. */
|
|
209
|
+
function customMetafield(type, value) {
|
|
210
|
+
const text = (v) => typeof v === "string" ? v : JSON.stringify(v);
|
|
211
|
+
const values = Array.isArray(value) ? value.filter((v) => v != null).map(text) : [];
|
|
212
|
+
const tree = type === "rich_text" ? serializeRichText(value) : null;
|
|
213
|
+
return hideSafeHtml({
|
|
214
|
+
type,
|
|
215
|
+
value: text(value),
|
|
216
|
+
values
|
|
217
|
+
}, "html", tree === null ? null : new SafeHtml(tree));
|
|
213
218
|
}
|
|
214
219
|
const nonNull = (v) => v !== null;
|
|
215
220
|
function nestMetafields(map) {
|
|
@@ -218,13 +223,8 @@ function nestMetafields(map) {
|
|
|
218
223
|
const dot = path.indexOf(".");
|
|
219
224
|
if (dot <= 0) continue;
|
|
220
225
|
const namespace = path.slice(0, dot);
|
|
221
|
-
const values = type.startsWith("LIST_") ? parseListValues(value) : [];
|
|
222
226
|
const keys = byNamespace.get(namespace) ?? [];
|
|
223
|
-
keys.push([path.slice(dot + 1),
|
|
224
|
-
type,
|
|
225
|
-
value,
|
|
226
|
-
values
|
|
227
|
-
}, "html", richTextHtml(type, value))]);
|
|
227
|
+
keys.push([path.slice(dot + 1), customMetafield(type, value)]);
|
|
228
228
|
byNamespace.set(namespace, keys);
|
|
229
229
|
}
|
|
230
230
|
return Object.fromEntries([...byNamespace].map(([namespace, keys]) => [namespace, Object.fromEntries(keys)]));
|
|
@@ -254,17 +254,17 @@ function menuLink(item, depth) {
|
|
|
254
254
|
return {
|
|
255
255
|
title: item.title,
|
|
256
256
|
url: item.url ?? "",
|
|
257
|
-
links: depth < MENU_DEPTH ?
|
|
257
|
+
links: depth < MENU_DEPTH ? item.items.map((c) => menuLink(c, depth + 1)) : []
|
|
258
258
|
};
|
|
259
259
|
}
|
|
260
260
|
function customMenu(menu) {
|
|
261
261
|
return {
|
|
262
262
|
title: menu.title,
|
|
263
|
-
links: menu.items.
|
|
263
|
+
links: menu.items.map((item) => menuLink(item, 1))
|
|
264
264
|
};
|
|
265
265
|
}
|
|
266
266
|
/** `content` is `SafeHtml`: `Shop::Page` sanitizes `body` on every assignment
|
|
267
|
-
* (`sanitizes_html :body`,
|
|
267
|
+
* (`sanitizes_html :body`, legacy/api/app/models/shop/page.rb) and its
|
|
268
268
|
* translations are html-format rows, sanitized on write
|
|
269
269
|
* (`Shop::Translation#sanitize_html_value`). */
|
|
270
270
|
function customPage(page) {
|
|
@@ -278,12 +278,13 @@ function customEntry(entry) {
|
|
|
278
278
|
handle: entry.handle,
|
|
279
279
|
type: entry.type,
|
|
280
280
|
name: entry.display_name,
|
|
281
|
-
fields: Object.fromEntries(Object.entries(entry.fields).map(([key, f]) =>
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
281
|
+
fields: Object.fromEntries(Object.entries(entry.fields).map(([key, f]) => {
|
|
282
|
+
const { html, ...field } = customMetafield(f.type, f.value);
|
|
283
|
+
return [key, hideSafeHtml({
|
|
284
|
+
...field,
|
|
285
|
+
image: customImage(f.file)
|
|
286
|
+
}, "html", html)];
|
|
287
|
+
}))
|
|
287
288
|
};
|
|
288
289
|
}
|
|
289
290
|
const LOCALIZE = "localizePath";
|
|
@@ -304,13 +305,6 @@ function customEngineFor(locale) {
|
|
|
304
305
|
outputEscape: escapeOutput
|
|
305
306
|
});
|
|
306
307
|
restrictToCustomTags(engine);
|
|
307
|
-
const Cycle = engine.tags.cycle;
|
|
308
|
-
class EscapedCycle extends Cycle {
|
|
309
|
-
*render(ctx, emitter) {
|
|
310
|
-
return escapeText(yield super.render(ctx, emitter));
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
engine.registerTag("cycle", EscapedCycle);
|
|
314
308
|
engine.registerFilter("raw", (v) => v);
|
|
315
309
|
const map = engine.filters.map;
|
|
316
310
|
engine.registerFilter("map", function* (...args) {
|
|
@@ -348,5 +342,4 @@ async function renderCustomLiquid(args) {
|
|
|
348
342
|
};
|
|
349
343
|
}
|
|
350
344
|
}
|
|
351
|
-
//#endregion
|
|
352
345
|
export { SafeHtml, customCollection, customEntry, customImage, customMenu, customPage, customProduct, liquidCollection, liquidProduct, renderCustomLiquid, renderLiquid };
|
package/dist/listing.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { LISTING_OFFSET_MAX } from "./api-contract/src/limits.js";
|
|
2
|
+
import { cardShape, swatchImageUrl } from "./card.js";
|
|
3
|
+
import { imageFileInfo } from "./files.js";
|
|
4
|
+
import { toMnt, toMoney } from "./money.js";
|
|
5
|
+
/** The card a listing's products carry. */
|
|
6
|
+
function listingCard(input) {
|
|
7
|
+
return cardShape({
|
|
8
|
+
media: input.mediaFirst,
|
|
9
|
+
options: input.includeOptions,
|
|
10
|
+
metafieldKeys: [...input.metafieldKeys ?? []]
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/** The URL's ticked values as a listing's selections. A key no facet could
|
|
14
|
+
* have, or a value too long, is dropped rather than failing the listing: it
|
|
15
|
+
* must render for any URL a buyer can type. */
|
|
16
|
+
function selectionsOf(filters) {
|
|
17
|
+
return Object.fromEntries(Object.entries(filters).flatMap(([key, values]) => {
|
|
18
|
+
const kept = values.filter((v) => v.length <= 255).slice(0, 50);
|
|
19
|
+
return key.length > 0 && key.length <= 600 && kept.length > 0 ? [[key, kept]] : [];
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
/** A URL's price bound (tögrög, a decimal) as the api's möngö. */
|
|
23
|
+
function priceBound(amount) {
|
|
24
|
+
return amount === void 0 ? void 0 : toMnt(Number(amount)) ?? void 0;
|
|
25
|
+
}
|
|
26
|
+
/** Page `page` (1-based) of `perPage` as the api's offset and limit. */
|
|
27
|
+
function pageInput(page, perPage) {
|
|
28
|
+
return {
|
|
29
|
+
offset: Math.min((Math.max(1, page) - 1) * perPage, LISTING_OFFSET_MAX),
|
|
30
|
+
limit: Math.min(perPage, 50)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** A listing's filters and page as the api's listing input; the sort is the caller's. */
|
|
34
|
+
function listingInput(filter, page, perPage) {
|
|
35
|
+
return {
|
|
36
|
+
selections: selectionsOf(filter?.filters ?? {}),
|
|
37
|
+
priceFrom: priceBound(filter?.price_min),
|
|
38
|
+
priceTo: priceBound(filter?.price_max),
|
|
39
|
+
...pageInput(page, perPage)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** A listing's facets as a theme reads them, in the api's order, each value
|
|
43
|
+
* `selected` as the URL ticked it. */
|
|
44
|
+
function toFacets(facets, selections) {
|
|
45
|
+
return facets.map((f) => ({
|
|
46
|
+
key: f.key,
|
|
47
|
+
label: f.label,
|
|
48
|
+
presentation: f.presentation,
|
|
49
|
+
values: f.values.map((v) => ({
|
|
50
|
+
value: v.value,
|
|
51
|
+
label: v.label,
|
|
52
|
+
count: v.count,
|
|
53
|
+
selected: selections[f.key]?.includes(v.value) ?? false,
|
|
54
|
+
color: v.color,
|
|
55
|
+
image: v.image ? swatchImageUrl(v.image) : null
|
|
56
|
+
}))
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
/** A listing's price range (möngö) as the slider's bounds (tögrög). */
|
|
60
|
+
function toPriceBounds(range) {
|
|
61
|
+
return range ? {
|
|
62
|
+
min: toMoney(range.min).amount,
|
|
63
|
+
max: toMoney(range.max).amount
|
|
64
|
+
} : {
|
|
65
|
+
min: null,
|
|
66
|
+
max: null
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** A collection card as a list of collections draws it (the index, a query's matches). */
|
|
70
|
+
function toCollectionListItem(c) {
|
|
71
|
+
return {
|
|
72
|
+
handle: c.handle,
|
|
73
|
+
title: c.title,
|
|
74
|
+
description: c.descriptionText,
|
|
75
|
+
image: c.featuredImage ? imageFileInfo(c.featuredImage, 640) : null,
|
|
76
|
+
products_count: c.productsCount
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export { listingCard, listingInput, pageInput, toCollectionListItem, toFacets, toPriceBounds };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/marketing-cookies.d.ts
|
|
2
1
|
/** Attribution read off the request cookies. A key is absent, never empty. */
|
|
3
2
|
export interface MarketingCookies {
|
|
4
3
|
fbp?: string;
|
|
@@ -11,5 +10,4 @@ export interface MarketingCookies {
|
|
|
11
10
|
* the header is missing or carries none — the caller then sends no attribution
|
|
12
11
|
* at all rather than a hash of nulls.
|
|
13
12
|
*/
|
|
14
|
-
export declare function parseMarketingCookies(cookie: string | null | undefined): MarketingCookies;
|
|
15
|
-
//#endregion
|
|
13
|
+
export declare function parseMarketingCookies(cookie: string | null | undefined): MarketingCookies;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/marketing-cookies.ts
|
|
2
2
|
const MAX_LENGTH = 256;
|
|
3
3
|
const MAX_COOKIES_LENGTH = 2048;
|
|
4
4
|
const ALLOWED_NAMES = /* @__PURE__ */ new Set([
|
|
@@ -44,5 +44,4 @@ function parseMarketingCookies(cookie) {
|
|
|
44
44
|
if (cookies) result.cookies = cookies;
|
|
45
45
|
return result;
|
|
46
46
|
}
|
|
47
|
-
//#endregion
|
|
48
47
|
export { parseMarketingCookies };
|