@shop-on/theme-server 0.9.0 → 0.11.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/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/menu.d.ts
CHANGED
|
@@ -1,156 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
id: string;
|
|
7
|
-
items: {
|
|
8
|
-
nodes: {
|
|
9
|
-
children: {
|
|
10
|
-
children: {
|
|
11
|
-
id: string;
|
|
12
|
-
itemType: "ARTICLE" | "BLOG" | "COLLECTION" | "HTTP" | "PAGE" | "POLICY" | "PRODUCT";
|
|
13
|
-
resource: {
|
|
14
|
-
__typename?: "ShopArticle" | undefined;
|
|
15
|
-
} | {
|
|
16
|
-
__typename?: "ShopBlog" | undefined;
|
|
17
|
-
} | {
|
|
18
|
-
__typename?: "ShopCollection" | undefined;
|
|
19
|
-
handle: string;
|
|
20
|
-
image: {
|
|
21
|
-
__typename: "ShopFont";
|
|
22
|
-
alt: string | null;
|
|
23
|
-
id: string;
|
|
24
|
-
thumbhash: string | null;
|
|
25
|
-
} | {
|
|
26
|
-
__typename: "ShopMediaImage";
|
|
27
|
-
alt: string | null;
|
|
28
|
-
focalPoint: {
|
|
29
|
-
x: number;
|
|
30
|
-
y: number;
|
|
31
|
-
} | null;
|
|
32
|
-
height: number | null;
|
|
33
|
-
id: string;
|
|
34
|
-
thumbUrl: string | null;
|
|
35
|
-
thumbhash: string | null;
|
|
36
|
-
url: string | null;
|
|
37
|
-
url2x: string | null;
|
|
38
|
-
url3x: string | null;
|
|
39
|
-
width: number | null;
|
|
40
|
-
} | {
|
|
41
|
-
__typename: "ShopVideo";
|
|
42
|
-
alt: string | null;
|
|
43
|
-
id: string;
|
|
44
|
-
thumbhash: string | null;
|
|
45
|
-
} | null;
|
|
46
|
-
} | {
|
|
47
|
-
__typename?: "ShopPage" | undefined;
|
|
48
|
-
} | {
|
|
49
|
-
__typename?: "ShopPolicy" | undefined;
|
|
50
|
-
} | {
|
|
51
|
-
__typename?: "ShopProduct" | undefined;
|
|
52
|
-
} | null;
|
|
53
|
-
title: string;
|
|
54
|
-
url: string | null;
|
|
55
|
-
}[];
|
|
56
|
-
id: string;
|
|
57
|
-
itemType: "ARTICLE" | "BLOG" | "COLLECTION" | "HTTP" | "PAGE" | "POLICY" | "PRODUCT";
|
|
58
|
-
resource: {
|
|
59
|
-
__typename?: "ShopArticle" | undefined;
|
|
60
|
-
} | {
|
|
61
|
-
__typename?: "ShopBlog" | undefined;
|
|
62
|
-
} | {
|
|
63
|
-
__typename?: "ShopCollection" | undefined;
|
|
64
|
-
handle: string;
|
|
65
|
-
image: {
|
|
66
|
-
__typename: "ShopFont";
|
|
67
|
-
alt: string | null;
|
|
68
|
-
id: string;
|
|
69
|
-
thumbhash: string | null;
|
|
70
|
-
} | {
|
|
71
|
-
__typename: "ShopMediaImage";
|
|
72
|
-
alt: string | null;
|
|
73
|
-
focalPoint: {
|
|
74
|
-
x: number;
|
|
75
|
-
y: number;
|
|
76
|
-
} | null;
|
|
77
|
-
height: number | null;
|
|
78
|
-
id: string;
|
|
79
|
-
thumbUrl: string | null;
|
|
80
|
-
thumbhash: string | null;
|
|
81
|
-
url: string | null;
|
|
82
|
-
url2x: string | null;
|
|
83
|
-
url3x: string | null;
|
|
84
|
-
width: number | null;
|
|
85
|
-
} | {
|
|
86
|
-
__typename: "ShopVideo";
|
|
87
|
-
alt: string | null;
|
|
88
|
-
id: string;
|
|
89
|
-
thumbhash: string | null;
|
|
90
|
-
} | null;
|
|
91
|
-
} | {
|
|
92
|
-
__typename?: "ShopPage" | undefined;
|
|
93
|
-
} | {
|
|
94
|
-
__typename?: "ShopPolicy" | undefined;
|
|
95
|
-
} | {
|
|
96
|
-
__typename?: "ShopProduct" | undefined;
|
|
97
|
-
} | null;
|
|
98
|
-
title: string;
|
|
99
|
-
url: string | null;
|
|
100
|
-
}[];
|
|
101
|
-
id: string;
|
|
102
|
-
itemType: "ARTICLE" | "BLOG" | "COLLECTION" | "HTTP" | "PAGE" | "POLICY" | "PRODUCT";
|
|
103
|
-
resource: {
|
|
104
|
-
__typename?: "ShopArticle" | undefined;
|
|
105
|
-
} | {
|
|
106
|
-
__typename?: "ShopBlog" | undefined;
|
|
107
|
-
} | {
|
|
108
|
-
__typename?: "ShopCollection" | undefined;
|
|
109
|
-
handle: string;
|
|
110
|
-
image: {
|
|
111
|
-
__typename: "ShopFont";
|
|
112
|
-
alt: string | null;
|
|
113
|
-
id: string;
|
|
114
|
-
thumbhash: string | null;
|
|
115
|
-
} | {
|
|
116
|
-
__typename: "ShopMediaImage";
|
|
117
|
-
alt: string | null;
|
|
118
|
-
focalPoint: {
|
|
119
|
-
x: number;
|
|
120
|
-
y: number;
|
|
121
|
-
} | null;
|
|
122
|
-
height: number | null;
|
|
123
|
-
id: string;
|
|
124
|
-
thumbUrl: string | null;
|
|
125
|
-
thumbhash: string | null;
|
|
126
|
-
url: string | null;
|
|
127
|
-
url2x: string | null;
|
|
128
|
-
url3x: string | null;
|
|
129
|
-
width: number | null;
|
|
130
|
-
} | {
|
|
131
|
-
__typename: "ShopVideo";
|
|
132
|
-
alt: string | null;
|
|
133
|
-
id: string;
|
|
134
|
-
thumbhash: string | null;
|
|
135
|
-
} | null;
|
|
136
|
-
} | {
|
|
137
|
-
__typename?: "ShopPage" | undefined;
|
|
138
|
-
} | {
|
|
139
|
-
__typename?: "ShopPolicy" | undefined;
|
|
140
|
-
} | {
|
|
141
|
-
__typename?: "ShopProduct" | undefined;
|
|
142
|
-
} | null;
|
|
143
|
-
title: string;
|
|
144
|
-
url: string | null;
|
|
145
|
-
}[];
|
|
146
|
-
};
|
|
147
|
-
title: string;
|
|
148
|
-
} | null;
|
|
149
|
-
}, {
|
|
1
|
+
import { ImageFileInfo } from "./files.js";
|
|
2
|
+
/** What a menu link leads to, read now; a URL link, and one whose destination is gone, has none. */
|
|
3
|
+
export type MenuResource = {
|
|
4
|
+
kind: "product" | "page" | "blog";
|
|
5
|
+
id: string;
|
|
150
6
|
handle: string;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
7
|
+
title: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: "collection";
|
|
10
|
+
id: string;
|
|
11
|
+
handle: string;
|
|
12
|
+
title: string;
|
|
13
|
+
image: ImageFileInfo | null;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "article";
|
|
16
|
+
id: string;
|
|
17
|
+
handle: string;
|
|
18
|
+
title: string;
|
|
19
|
+
blogHandle: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: "policy";
|
|
22
|
+
handle: string;
|
|
23
|
+
title: string;
|
|
24
|
+
};
|
|
25
|
+
export type MenuLinkKind = "url" | "product" | "collection" | "page" | "blog" | "article" | "policy";
|
|
26
|
+
export type MenuItemData = {
|
|
27
|
+
id: string;
|
|
28
|
+
title: string;
|
|
29
|
+
/** Where it leads: a URL link's own, else its destination's storefront path.
|
|
30
|
+
* Null when the destination is gone (deleted, or a policy not written): the
|
|
31
|
+
* link keeps its place and its children and is drawn as text. */
|
|
32
|
+
url: string | null;
|
|
33
|
+
kind: MenuLinkKind;
|
|
34
|
+
resource: MenuResource | null;
|
|
35
|
+
/** The links under it (three levels in all). */
|
|
36
|
+
items: MenuItemData[];
|
|
37
|
+
};
|
|
38
|
+
export type MenuData = {
|
|
39
|
+
id: string;
|
|
40
|
+
handle: string;
|
|
41
|
+
title: string;
|
|
42
|
+
items: MenuItemData[];
|
|
43
|
+
};
|
|
44
|
+
/** A menu with every link, in the read's language (titles,
|
|
45
|
+
* and the resources' own). Null for a handle the shop lacks, and on a failed
|
|
46
|
+
* read: a header renders without it. */
|
|
47
|
+
export declare function fetchMenu(handle: string, locale?: string): Promise<MenuData | null>;
|
package/dist/menu.js
CHANGED
|
@@ -1,71 +1,61 @@
|
|
|
1
1
|
import { memoTTL } from "./cache.js";
|
|
2
|
-
import { graphql, request } from "./graphql.js";
|
|
3
2
|
import { getContentVersion } from "./content-version.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
nodes {
|
|
44
|
-
...MenuItemFields
|
|
45
|
-
children {
|
|
46
|
-
...MenuItemFields
|
|
47
|
-
children {
|
|
48
|
-
...MenuItemFields
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
`, [MenuItemFragment]);
|
|
3
|
+
import { imageFileInfo } from "./files.js";
|
|
4
|
+
import { orFallback, orNotFound, storefront } from "./storefront.js";
|
|
5
|
+
// src/menu.ts
|
|
6
|
+
/** The width a collection link's image is drawn at: an image-led mega menu's
|
|
7
|
+
* tile (Horizon's `collection_images` / `featured_collections` submenus). */
|
|
8
|
+
const MENU_COLLECTION_IMAGE_WIDTH = 640;
|
|
9
|
+
function toResource(resource) {
|
|
10
|
+
switch (resource.kind) {
|
|
11
|
+
case "collection": return {
|
|
12
|
+
kind: "collection",
|
|
13
|
+
id: resource.id,
|
|
14
|
+
handle: resource.handle,
|
|
15
|
+
title: resource.title,
|
|
16
|
+
image: resource.image ? imageFileInfo(resource.image, MENU_COLLECTION_IMAGE_WIDTH) : null
|
|
17
|
+
};
|
|
18
|
+
case "article": return { ...resource };
|
|
19
|
+
case "policy": return {
|
|
20
|
+
kind: "policy",
|
|
21
|
+
handle: resource.handle,
|
|
22
|
+
title: resource.title
|
|
23
|
+
};
|
|
24
|
+
default: return {
|
|
25
|
+
kind: resource.kind,
|
|
26
|
+
id: resource.id,
|
|
27
|
+
handle: resource.handle,
|
|
28
|
+
title: resource.title
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function toItem(link) {
|
|
33
|
+
return {
|
|
34
|
+
id: link.id,
|
|
35
|
+
title: link.title,
|
|
36
|
+
url: link.url,
|
|
37
|
+
kind: link.kind,
|
|
38
|
+
resource: link.resource ? toResource(link.resource) : null,
|
|
39
|
+
items: link.items.map(toItem)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
56
42
|
const fetchMenuCached = memoTTL(async (handle, locale) => {
|
|
57
|
-
|
|
43
|
+
const menu = await orNotFound(storefront(locale).menus.get({ handle }));
|
|
44
|
+
if (!menu) return null;
|
|
45
|
+
return {
|
|
46
|
+
id: menu.id,
|
|
47
|
+
handle: menu.handle,
|
|
48
|
+
title: menu.title,
|
|
49
|
+
items: menu.items.map(toItem)
|
|
50
|
+
};
|
|
58
51
|
}, {
|
|
59
52
|
key: (handle, locale) => `${handle}|${locale ?? ""}`,
|
|
60
53
|
version: getContentVersion
|
|
61
54
|
});
|
|
55
|
+
/** A menu with every link, in the read's language (titles,
|
|
56
|
+
* and the resources' own). Null for a handle the shop lacks, and on a failed
|
|
57
|
+
* read: a header renders without it. */
|
|
62
58
|
async function fetchMenu(handle, locale) {
|
|
63
|
-
|
|
64
|
-
return await fetchMenuCached(handle, locale);
|
|
65
|
-
} catch (err) {
|
|
66
|
-
console.warn(`[fetchMenu] failed for handle="${handle}":`, err);
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
59
|
+
return orFallback(fetchMenuCached(handle, locale), null, "fetchMenu");
|
|
69
60
|
}
|
|
70
|
-
//#endregion
|
|
71
61
|
export { fetchMenu };
|
package/dist/metafields.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/** A value as JSON holds it: what a metafield's value is on the wire, and
|
|
2
|
+
* what a server function's answer may carry. */
|
|
3
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
};
|
|
6
|
+
/** A resource's storefront metafields keyed `"namespace.key"`, each its
|
|
7
|
+
* value type's name and its value (theme-contract's `CustomDataValue`). */
|
|
3
8
|
export type MetafieldMap = Record<string, {
|
|
4
9
|
type: string;
|
|
5
|
-
value:
|
|
6
|
-
}>;
|
|
7
|
-
//#endregion
|
|
10
|
+
value: JsonValue;
|
|
11
|
+
}>;
|
package/dist/metafields.js
CHANGED
|
@@ -1,43 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return Object.fromEntries(nodes.map((m) => [`${m.namespace}.${m.key}`, {
|
|
1
|
+
// src/metafields.ts
|
|
2
|
+
/** The values of a storefront procedure's custom data (`storefrontCustomData`)
|
|
3
|
+
* as the `"namespace.key"`-keyed map every reader uses. */
|
|
4
|
+
function customDataMap(data) {
|
|
5
|
+
return Object.fromEntries(data.values.map((m) => [`${m.namespace}.${m.key}`, {
|
|
7
6
|
type: m.type,
|
|
8
7
|
value: m.value
|
|
9
8
|
}]));
|
|
10
9
|
}
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (!Array.isArray(arr)) return [];
|
|
16
|
-
return arr.filter((x) => x != null).map(String);
|
|
17
|
-
} catch {
|
|
18
|
-
return [];
|
|
19
|
-
}
|
|
10
|
+
/** The cache-key segment for a list of `namespace.key` names: sorted, so two
|
|
11
|
+
* callers naming the same keys in another order share one entry. */
|
|
12
|
+
function metafieldKeysKey(keys) {
|
|
13
|
+
return keys?.length ? [...keys].sort().join(",") : "";
|
|
20
14
|
}
|
|
21
|
-
|
|
22
|
-
* dynamic source. `read` returns the resource's metafield nodes, or `null`
|
|
23
|
-
* when the resource is missing. A resource with no published fields is `{}`
|
|
24
|
-
* and IS cached; a missing resource or a failed read is retried next time.
|
|
25
|
-
* Either way the caller gets `{}`, so the template renders its literal. */
|
|
26
|
-
function metafieldsReader(name, read) {
|
|
27
|
-
const cached = memoTTL(async (ref, locale) => {
|
|
28
|
-
try {
|
|
29
|
-
const nodes = await read(ref, locale);
|
|
30
|
-
return nodes ? toMetafieldMap(nodes) : null;
|
|
31
|
-
} catch (err) {
|
|
32
|
-
console.warn(`[${name}] failed:`, err);
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
}, {
|
|
36
|
-
key: (ref, locale) => `${name}|${ref}|${locale ?? ""}`,
|
|
37
|
-
shouldCache: (v) => v !== null,
|
|
38
|
-
version: getContentVersion
|
|
39
|
-
});
|
|
40
|
-
return async (ref, locale) => await cached(ref, locale) ?? {};
|
|
41
|
-
}
|
|
42
|
-
//#endregion
|
|
43
|
-
export { metafieldsReader, parseListValues, toMetafieldMap };
|
|
15
|
+
export { customDataMap, metafieldKeysKey };
|
package/dist/metaobject.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { FileInfo } from "./files.js";
|
|
2
|
-
|
|
2
|
+
import { JsonValue } from "./metafields.js";
|
|
3
3
|
export type MetaobjectFieldData = {
|
|
4
4
|
key: string;
|
|
5
|
+
/** The value type, snake_case: `color`, `single_line_text`, `rich_text`… */
|
|
5
6
|
type: string;
|
|
6
|
-
value:
|
|
7
|
-
|
|
7
|
+
/** The type's wire value: a list's an array, a rich text's its node tree, a
|
|
8
|
+
* reference's the target's id. */
|
|
9
|
+
value: JsonValue;
|
|
10
|
+
/** A `file_reference` field's file, resolved; null when it is gone or is
|
|
11
|
+
* neither an image nor a video. */
|
|
8
12
|
file?: FileInfo | null;
|
|
9
13
|
};
|
|
10
14
|
export type MetaobjectData = {
|
|
@@ -14,5 +18,6 @@ export type MetaobjectData = {
|
|
|
14
18
|
display_name: string;
|
|
15
19
|
fields: Record<string, MetaobjectFieldData>;
|
|
16
20
|
};
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
/** A metaobject entry by id; null for one a buyer may not read, an id that is
|
|
22
|
+
* no entry's (no call is made), and on a failed read. */
|
|
23
|
+
export declare function fetchMetaobject(id: string): Promise<MetaobjectData | null>;
|
package/dist/metaobject.js
CHANGED
|
@@ -1,84 +1,61 @@
|
|
|
1
|
+
import { liteId } from "./api-contract/src/ids.js";
|
|
1
2
|
import { memoTTL } from "./cache.js";
|
|
2
|
-
import {
|
|
3
|
+
import { coalescedReads } from "./coalesce.js";
|
|
3
4
|
import { getContentVersion } from "./content-version.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type
|
|
17
|
-
value
|
|
18
|
-
reference {
|
|
19
|
-
__typename
|
|
20
|
-
... on ShopMediaImage {
|
|
21
|
-
id
|
|
22
|
-
alt
|
|
23
|
-
thumbhash
|
|
24
|
-
width
|
|
25
|
-
height
|
|
26
|
-
url(transform: { maxWidth: 256 })
|
|
27
|
-
url2x: url(transform: { maxWidth: 256, scale: 2 })
|
|
28
|
-
url3x: url(transform: { maxWidth: 256, scale: 3 })
|
|
29
|
-
thumbUrl: url(transform: { maxWidth: 64 })
|
|
30
|
-
focalPoint {
|
|
31
|
-
x
|
|
32
|
-
y
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
... on ShopVideo {
|
|
36
|
-
id
|
|
37
|
-
alt
|
|
38
|
-
url
|
|
39
|
-
hlsUrl
|
|
40
|
-
width
|
|
41
|
-
height
|
|
42
|
-
duration
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
`);
|
|
49
|
-
const fetchMetaobjectCached = memoTTL(async (id) => {
|
|
50
|
-
const m = (await request(FetchMetaobjectQuery, { id })).metaobject;
|
|
51
|
-
if (!m) return null;
|
|
5
|
+
import { imageFileInfo, videoFileInfo } from "./files.js";
|
|
6
|
+
import { orFallback, storefront } from "./storefront.js";
|
|
7
|
+
// src/metaobject.ts
|
|
8
|
+
/** The width a field's referenced image (and a video's poster) is drawn at. */
|
|
9
|
+
const FIELD_FILE_WIDTH = 256;
|
|
10
|
+
function fieldFile(id, files) {
|
|
11
|
+
const file = typeof id === "string" ? files.find((f) => f.id === id) : void 0;
|
|
12
|
+
if (file?.image) return imageFileInfo(file.image, FIELD_FILE_WIDTH);
|
|
13
|
+
if (file?.video) return videoFileInfo(file.video, FIELD_FILE_WIDTH);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
function toMetaobject({ entry, files }) {
|
|
52
17
|
const fields = {};
|
|
53
|
-
for (const f of
|
|
54
|
-
const
|
|
18
|
+
for (const f of entry.fields) {
|
|
19
|
+
const field = {
|
|
55
20
|
key: f.key,
|
|
56
21
|
type: f.type,
|
|
57
|
-
value: f.value
|
|
22
|
+
value: f.value
|
|
58
23
|
};
|
|
59
|
-
if (f.type
|
|
60
|
-
|
|
61
|
-
fields[f.key] = entry;
|
|
24
|
+
if (f.type === "file_reference" && !f.list) field.file = fieldFile(f.value, files);
|
|
25
|
+
fields[f.key] = field;
|
|
62
26
|
}
|
|
63
27
|
return {
|
|
64
|
-
id:
|
|
65
|
-
handle:
|
|
66
|
-
type:
|
|
67
|
-
display_name:
|
|
28
|
+
id: entry.id,
|
|
29
|
+
handle: entry.handle,
|
|
30
|
+
type: entry.type,
|
|
31
|
+
display_name: entry.displayName,
|
|
68
32
|
fields
|
|
69
33
|
};
|
|
34
|
+
}
|
|
35
|
+
/** Entry reads of this request's tick share a `metaobjects.entries` call;
|
|
36
|
+
* each carries the call's referenced files. */
|
|
37
|
+
const coalescedEntry = coalescedReads({
|
|
38
|
+
max: 50,
|
|
39
|
+
matches: ({ entry }, ref) => entry.id === ref
|
|
40
|
+
});
|
|
41
|
+
const fetchMetaobjectCached = memoTTL(async (id) => {
|
|
42
|
+
const found = await coalescedEntry("", id, async (refs) => {
|
|
43
|
+
const answer = await storefront().metaobjects.entries({ refs: refs.map((ref) => ({ metaobjectId: liteId("metaobject").parse(ref) })) });
|
|
44
|
+
return answer.items.map((entry) => ({
|
|
45
|
+
entry,
|
|
46
|
+
files: answer.references.files
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
49
|
+
return found && toMetaobject(found);
|
|
70
50
|
}, {
|
|
71
51
|
key: (id) => `metaobject|${id}`,
|
|
72
52
|
shouldCache: (v) => v !== null,
|
|
73
53
|
version: getContentVersion
|
|
74
54
|
});
|
|
55
|
+
/** A metaobject entry by id; null for one a buyer may not read, an id that is
|
|
56
|
+
* no entry's (no call is made), and on a failed read. */
|
|
75
57
|
async function fetchMetaobject(id) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
} catch (err) {
|
|
79
|
-
console.warn("[fetchMetaobject] failed:", err);
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
58
|
+
if (!liteId("metaobject").safeParse(id).success) return null;
|
|
59
|
+
return orFallback(fetchMetaobjectCached(id), null, "fetchMetaobject");
|
|
82
60
|
}
|
|
83
|
-
//#endregion
|
|
84
61
|
export { fetchMetaobject };
|
package/dist/money.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Money } from "@shop-on/theme-runtime/money";
|
|
2
|
+
/** An api amount (möngö) as the `Money` a theme reads. */
|
|
3
|
+
export declare function toMoney(mnt: number): Money;
|
|
4
|
+
/** A buyer's amount in tögrög (a price filter's bound) as the api's möngö,
|
|
5
|
+
* to the nearest möngö; null for one the api would refuse (negative, not a
|
|
6
|
+
* number, or past what a möngö amount holds). */
|
|
7
|
+
export declare function toMnt(amount: number): number | null;
|
package/dist/money.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/money.ts
|
|
2
|
+
/** MNT is the only currency the api holds. */
|
|
3
|
+
const CURRENCY = "MNT";
|
|
4
|
+
/** An api amount (möngö) as the `Money` a theme reads. */
|
|
5
|
+
function toMoney(mnt) {
|
|
6
|
+
return {
|
|
7
|
+
amount: mnt / 100,
|
|
8
|
+
currencyCode: CURRENCY
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** A buyer's amount in tögrög (a price filter's bound) as the api's möngö,
|
|
12
|
+
* to the nearest möngö; null for one the api would refuse (negative, not a
|
|
13
|
+
* number, or past what a möngö amount holds). */
|
|
14
|
+
function toMnt(amount) {
|
|
15
|
+
const mnt = Math.round(amount * 100);
|
|
16
|
+
return Number.isSafeInteger(mnt) && mnt >= 0 ? mnt : null;
|
|
17
|
+
}
|
|
18
|
+
export { toMnt, toMoney };
|
package/dist/newsletter.d.ts
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
1
|
+
/** Why the api did not record the sign-up, for the form to word:
|
|
2
|
+
* `TURNSTILE_FAILED` (the bot check did not pass), `VALIDATION_FAILED`
|
|
3
|
+
* (`field` the input it names, `email`), `RATE_LIMITED` (too many sign-ups
|
|
4
|
+
* from this buyer's address, for this email or at this shop; nothing was
|
|
5
|
+
* recorded, so the form says to try later, never that it worked). */
|
|
4
6
|
export type SubscribeNewsletterResult = {
|
|
5
7
|
ok: true;
|
|
6
8
|
} | {
|
|
7
9
|
ok: false;
|
|
8
|
-
code:
|
|
9
|
-
|
|
10
|
+
code: "TURNSTILE_FAILED";
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
code: "VALIDATION_FAILED";
|
|
14
|
+
field: string | null;
|
|
15
|
+
} | {
|
|
16
|
+
ok: false;
|
|
17
|
+
code: "RATE_LIMITED";
|
|
18
|
+
retryAfterSeconds: number;
|
|
10
19
|
};
|
|
11
|
-
/** Subscribe `email`.
|
|
12
|
-
*
|
|
20
|
+
/** Subscribe `email`. The token goes only when the form has one: a shop
|
|
21
|
+
* without a widget asks for none. Any other failure throws. */
|
|
13
22
|
export declare function subscribeNewsletter(input: {
|
|
14
23
|
email: string;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
/** The widget's token; empty or absent when the shop has no widget. */
|
|
25
|
+
turnstileToken?: string;
|
|
26
|
+
}): Promise<SubscribeNewsletterResult>;
|