@usethrottle/storefront-react 0.0.0-stage → 0.1.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/CLAUDE.md +67 -0
- package/README.md +119 -2
- package/dist/StorefrontProvider-Br4wUHui.d.cts +559 -0
- package/dist/StorefrontProvider-DLEPEjg6.d.ts +559 -0
- package/dist/account/index.cjs +69 -0
- package/dist/account/index.cjs.map +1 -0
- package/dist/account/index.d.cts +23 -0
- package/dist/account/index.d.ts +23 -0
- package/dist/account/index.js +68 -0
- package/dist/account/index.js.map +1 -0
- package/dist/chunk-2LCPIY2P.cjs +16 -0
- package/dist/chunk-2LCPIY2P.cjs.map +1 -0
- package/dist/chunk-3A72UY6T.js +2126 -0
- package/dist/chunk-3A72UY6T.js.map +1 -0
- package/dist/chunk-3JMIVAHN.js +185 -0
- package/dist/chunk-3JMIVAHN.js.map +1 -0
- package/dist/chunk-4J6AGWNC.cjs +24 -0
- package/dist/chunk-4J6AGWNC.cjs.map +1 -0
- package/dist/chunk-4U6MYDZV.js +17 -0
- package/dist/chunk-4U6MYDZV.js.map +1 -0
- package/dist/chunk-66HDJVPS.js +22 -0
- package/dist/chunk-66HDJVPS.js.map +1 -0
- package/dist/chunk-6X2OZSNV.cjs +83 -0
- package/dist/chunk-6X2OZSNV.cjs.map +1 -0
- package/dist/chunk-6ZMMZ245.cjs +2127 -0
- package/dist/chunk-6ZMMZ245.cjs.map +1 -0
- package/dist/chunk-7R37CVAB.cjs +23 -0
- package/dist/chunk-7R37CVAB.cjs.map +1 -0
- package/dist/chunk-A3IFWQUV.js +368 -0
- package/dist/chunk-A3IFWQUV.js.map +1 -0
- package/dist/chunk-AYC2YK4E.cjs +95 -0
- package/dist/chunk-AYC2YK4E.cjs.map +1 -0
- package/dist/chunk-AZV5U7YB.cjs +18 -0
- package/dist/chunk-AZV5U7YB.cjs.map +1 -0
- package/dist/chunk-CE2SKNQP.cjs +71 -0
- package/dist/chunk-CE2SKNQP.cjs.map +1 -0
- package/dist/chunk-D76CRI4X.js +2175 -0
- package/dist/chunk-D76CRI4X.js.map +1 -0
- package/dist/chunk-DOAII637.cjs +186 -0
- package/dist/chunk-DOAII637.cjs.map +1 -0
- package/dist/chunk-DYHHAOMG.cjs +17 -0
- package/dist/chunk-DYHHAOMG.cjs.map +1 -0
- package/dist/chunk-EYSVU5SJ.js +196 -0
- package/dist/chunk-EYSVU5SJ.js.map +1 -0
- package/dist/chunk-HSUUDZWS.js +37 -0
- package/dist/chunk-HSUUDZWS.js.map +1 -0
- package/dist/chunk-HZ6VEN6Q.cjs +101 -0
- package/dist/chunk-HZ6VEN6Q.cjs.map +1 -0
- package/dist/chunk-IJOTLGPT.js +16 -0
- package/dist/chunk-IJOTLGPT.js.map +1 -0
- package/dist/chunk-ISDATHVC.js +219 -0
- package/dist/chunk-ISDATHVC.js.map +1 -0
- package/dist/chunk-LW2A6USV.js +100 -0
- package/dist/chunk-LW2A6USV.js.map +1 -0
- package/dist/chunk-M4YXSLRG.cjs +369 -0
- package/dist/chunk-M4YXSLRG.cjs.map +1 -0
- package/dist/chunk-NDUEJJLP.cjs +2176 -0
- package/dist/chunk-NDUEJJLP.cjs.map +1 -0
- package/dist/chunk-NNE4FYRT.js +820 -0
- package/dist/chunk-NNE4FYRT.js.map +1 -0
- package/dist/chunk-NW3EFHY2.js +15 -0
- package/dist/chunk-NW3EFHY2.js.map +1 -0
- package/dist/chunk-NZRUQUN5.js +167 -0
- package/dist/chunk-NZRUQUN5.js.map +1 -0
- package/dist/chunk-P6HHE57S.cjs +38 -0
- package/dist/chunk-P6HHE57S.cjs.map +1 -0
- package/dist/chunk-PHY7AY27.cjs +197 -0
- package/dist/chunk-PHY7AY27.cjs.map +1 -0
- package/dist/chunk-PNJOFFTL.cjs +128 -0
- package/dist/chunk-PNJOFFTL.cjs.map +1 -0
- package/dist/chunk-PXZQ4ONA.js +127 -0
- package/dist/chunk-PXZQ4ONA.js.map +1 -0
- package/dist/chunk-Q3VTUBPP.js +82 -0
- package/dist/chunk-Q3VTUBPP.js.map +1 -0
- package/dist/chunk-Q3XFD5UI.js +45 -0
- package/dist/chunk-Q3XFD5UI.js.map +1 -0
- package/dist/chunk-QM7KTT7F.js +94 -0
- package/dist/chunk-QM7KTT7F.js.map +1 -0
- package/dist/chunk-RLWZOLXL.js +70 -0
- package/dist/chunk-RLWZOLXL.js.map +1 -0
- package/dist/chunk-SV53BRP2.js +23 -0
- package/dist/chunk-SV53BRP2.js.map +1 -0
- package/dist/chunk-VWXJO427.cjs +821 -0
- package/dist/chunk-VWXJO427.cjs.map +1 -0
- package/dist/chunk-WIIOJDHR.cjs +220 -0
- package/dist/chunk-WIIOJDHR.cjs.map +1 -0
- package/dist/chunk-XQHGFWLG.cjs +46 -0
- package/dist/chunk-XQHGFWLG.cjs.map +1 -0
- package/dist/chunk-ZHCXI2ZZ.cjs +168 -0
- package/dist/chunk-ZHCXI2ZZ.cjs.map +1 -0
- package/dist/index-RSj2Rg62.d.cts +8 -0
- package/dist/index-RSj2Rg62.d.ts +8 -0
- package/dist/index.cjs +2829 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1718 -0
- package/dist/index.d.ts +1718 -0
- package/dist/index.js +2828 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata-QhKw-tvz.d.cts +188 -0
- package/dist/metadata-QhKw-tvz.d.ts +188 -0
- package/dist/next/client.cjs +84 -0
- package/dist/next/client.cjs.map +1 -0
- package/dist/next/client.d.cts +40 -0
- package/dist/next/client.d.ts +40 -0
- package/dist/next/client.js +83 -0
- package/dist/next/client.js.map +1 -0
- package/dist/next/index.cjs +1090 -0
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +218 -0
- package/dist/next/index.d.ts +218 -0
- package/dist/next/index.js +1049 -0
- package/dist/next/index.js.map +1 -0
- package/dist/server/index.cjs +994 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +229 -0
- package/dist/server/index.d.ts +229 -0
- package/dist/server/index.js +951 -0
- package/dist/server/index.js.map +1 -0
- package/dist/styles.css +2111 -0
- package/dist/use-part-DCfFk7kf.d.ts +24 -0
- package/dist/use-part-DgjPBL_O.d.cts +24 -0
- package/package.json +121 -3
|
@@ -0,0 +1,951 @@
|
|
|
1
|
+
// src/server/client.ts
|
|
2
|
+
import { createServerCatalogClient } from "@usethrottle/catalog/server";
|
|
3
|
+
var STOREFRONT_CACHE_POLICY = {
|
|
4
|
+
settings: "until-changed",
|
|
5
|
+
navigation: "until-changed",
|
|
6
|
+
pages: "until-changed",
|
|
7
|
+
product: "until-changed",
|
|
8
|
+
listings: "until-changed",
|
|
9
|
+
facets: "until-changed",
|
|
10
|
+
related: "until-changed",
|
|
11
|
+
reviews: "until-changed",
|
|
12
|
+
search: "no-store"
|
|
13
|
+
};
|
|
14
|
+
function createStorefrontServerClient(o) {
|
|
15
|
+
return createServerCatalogClient({
|
|
16
|
+
publishableKey: o.catalogKey,
|
|
17
|
+
cachePolicy: { ...STOREFRONT_CACHE_POLICY, ...o.cachePolicy },
|
|
18
|
+
...o.baseUrl ? { baseUrl: o.baseUrl } : {},
|
|
19
|
+
...o.previewToken ? { previewToken: o.previewToken } : {}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/server/loaders.ts
|
|
24
|
+
import { isCatalogError, t } from "@usethrottle/catalog";
|
|
25
|
+
|
|
26
|
+
// src/settings/defaults.ts
|
|
27
|
+
import { DEFAULT_STRINGS } from "@usethrottle/catalog";
|
|
28
|
+
var DEFAULT_SETTINGS = {
|
|
29
|
+
storefrontId: "default",
|
|
30
|
+
brand: { storeName: "", logo: { light: null, dark: null }, favicon: null },
|
|
31
|
+
theme: {
|
|
32
|
+
light: {
|
|
33
|
+
colorPrimary: "#18181b",
|
|
34
|
+
colorPrimaryForeground: "#fafafa",
|
|
35
|
+
colorBackground: "#ffffff",
|
|
36
|
+
colorSurface: "#f4f4f5",
|
|
37
|
+
colorForeground: "#18181b",
|
|
38
|
+
colorMuted: "#f4f4f5",
|
|
39
|
+
colorMutedForeground: "#71717a",
|
|
40
|
+
colorBorder: "#e4e4e7",
|
|
41
|
+
colorBorderControl: "#d4d4d8",
|
|
42
|
+
colorAccent: "#2563eb",
|
|
43
|
+
colorSale: "#b91c1c",
|
|
44
|
+
colorSuccess: "#15803d",
|
|
45
|
+
colorWarning: "#b45309",
|
|
46
|
+
colorDanger: "#b91c1c"
|
|
47
|
+
},
|
|
48
|
+
dark: {
|
|
49
|
+
colorPrimary: "#fafafa",
|
|
50
|
+
colorPrimaryForeground: "#18181b",
|
|
51
|
+
colorBackground: "#09090b",
|
|
52
|
+
colorSurface: "#18181b",
|
|
53
|
+
colorForeground: "#fafafa",
|
|
54
|
+
colorMuted: "#27272a",
|
|
55
|
+
colorMutedForeground: "#a1a1aa",
|
|
56
|
+
colorBorder: "#27272a",
|
|
57
|
+
colorBorderControl: "#3f3f46",
|
|
58
|
+
colorAccent: "#60a5fa",
|
|
59
|
+
colorSale: "#f87171",
|
|
60
|
+
colorSuccess: "#4ade80",
|
|
61
|
+
colorWarning: "#fbbf24",
|
|
62
|
+
colorDanger: "#f87171"
|
|
63
|
+
},
|
|
64
|
+
fonts: { heading: "system-sans", body: "system-sans", mono: "system-mono" },
|
|
65
|
+
radius: 8,
|
|
66
|
+
spacingScale: "comfortable",
|
|
67
|
+
colorScheme: "auto"
|
|
68
|
+
},
|
|
69
|
+
navigation: { header: [], footer: [] },
|
|
70
|
+
home: {
|
|
71
|
+
hero: { image: null, heading: "", subheading: "", ctaLabel: "", ctaTarget: null },
|
|
72
|
+
shelves: [
|
|
73
|
+
{ kind: "featured", limit: 8 },
|
|
74
|
+
{ kind: "newest", limit: 8 }
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
announcement: { enabled: false, message: "", target: null, startsAt: null, endsAt: null },
|
|
78
|
+
listing: {
|
|
79
|
+
pageSize: 24,
|
|
80
|
+
pagination: "numbered",
|
|
81
|
+
columns: { desktop: 4, mobile: 2 },
|
|
82
|
+
defaultSort: "featured",
|
|
83
|
+
filterLayout: "sidebar",
|
|
84
|
+
sorts: [
|
|
85
|
+
{ key: "relevance", enabled: true, label: "Best match" },
|
|
86
|
+
{ key: "featured", enabled: true, label: "Featured" },
|
|
87
|
+
{ key: "manual", enabled: true, label: "Collection order" },
|
|
88
|
+
{ key: "title_asc", enabled: true, label: "Name: A\u2013Z" },
|
|
89
|
+
{ key: "title_desc", enabled: true, label: "Name: Z\u2013A" },
|
|
90
|
+
{ key: "price_asc", enabled: true, label: "Price: low to high" },
|
|
91
|
+
{ key: "price_desc", enabled: true, label: "Price: high to low" },
|
|
92
|
+
{ key: "newest", enabled: true, label: "Newest" },
|
|
93
|
+
{ key: "updated", enabled: true, label: "Recently updated" },
|
|
94
|
+
{ key: "best_rated", enabled: true, label: "Best rated" }
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
card: {
|
|
98
|
+
style: "standard",
|
|
99
|
+
showRating: true,
|
|
100
|
+
showSwatches: true,
|
|
101
|
+
showBrand: true,
|
|
102
|
+
showCompareAt: true,
|
|
103
|
+
showBadges: true,
|
|
104
|
+
secondImageOnHover: false,
|
|
105
|
+
quickAdd: false
|
|
106
|
+
},
|
|
107
|
+
badges: {
|
|
108
|
+
sale: { enabled: true, label: "Sale", colour: "#b91c1c" },
|
|
109
|
+
new: { enabled: true, label: "New", colour: "#2563eb", days: 30 },
|
|
110
|
+
lowStock: { enabled: true, label: "Low stock" },
|
|
111
|
+
custom: []
|
|
112
|
+
},
|
|
113
|
+
stock: {
|
|
114
|
+
hideOutOfStock: false,
|
|
115
|
+
showExactCount: false,
|
|
116
|
+
words: {
|
|
117
|
+
inStock: "In stock",
|
|
118
|
+
lowStock: "Only {count} left",
|
|
119
|
+
outOfStock: "Out of stock",
|
|
120
|
+
backorder: "Available on backorder",
|
|
121
|
+
preorder: "Pre-order"
|
|
122
|
+
},
|
|
123
|
+
lowStockThreshold: null
|
|
124
|
+
},
|
|
125
|
+
product: {
|
|
126
|
+
layout: "classic",
|
|
127
|
+
sectionsStyle: "auto",
|
|
128
|
+
sections: [
|
|
129
|
+
{ key: "description", enabled: true, title: "Description", pageHandle: null },
|
|
130
|
+
{ key: "specs", enabled: true, title: "Specifications", pageHandle: null },
|
|
131
|
+
{ key: "shipping", enabled: false, title: "Shipping", pageHandle: null },
|
|
132
|
+
{ key: "tags", enabled: false, title: "Tags", pageHandle: null },
|
|
133
|
+
{ key: "categories", enabled: false, title: "Categories", pageHandle: null },
|
|
134
|
+
{ key: "related", enabled: true, title: "You may also like", pageHandle: null },
|
|
135
|
+
{ key: "reviews", enabled: true, title: "Reviews", pageHandle: null }
|
|
136
|
+
],
|
|
137
|
+
relatedLimit: 8,
|
|
138
|
+
relatedTitle: "You may also like"
|
|
139
|
+
},
|
|
140
|
+
seo: { titleTemplate: "{page} \u2013 {store}", defaultDescription: "", shareImage: null },
|
|
141
|
+
strings: { ...DEFAULT_STRINGS },
|
|
142
|
+
routes: {
|
|
143
|
+
product: "/p/{handle}",
|
|
144
|
+
category: "/c/{handle}",
|
|
145
|
+
collection: "/collections/{handle}",
|
|
146
|
+
tag: "/tags/{tag}",
|
|
147
|
+
page: "/pages/{handle}",
|
|
148
|
+
search: "/search?q={q}",
|
|
149
|
+
shop: "/shop"
|
|
150
|
+
},
|
|
151
|
+
preview: { storeUrl: null }
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// src/settings/guards.ts
|
|
155
|
+
var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
156
|
+
var isUnsafeKey = (key) => key === "__proto__" || key === "constructor" || key === "prototype";
|
|
157
|
+
|
|
158
|
+
// src/settings/normalize.ts
|
|
159
|
+
var SORT_KEYS = [
|
|
160
|
+
"relevance",
|
|
161
|
+
"featured",
|
|
162
|
+
"manual",
|
|
163
|
+
"title_asc",
|
|
164
|
+
"title_desc",
|
|
165
|
+
"price_asc",
|
|
166
|
+
"price_desc",
|
|
167
|
+
"newest",
|
|
168
|
+
"updated",
|
|
169
|
+
"best_rated"
|
|
170
|
+
];
|
|
171
|
+
var ENUMS = [
|
|
172
|
+
[["theme", "colorScheme"], ["light", "dark", "auto"]],
|
|
173
|
+
[["theme", "spacingScale"], ["compact", "comfortable", "roomy"]],
|
|
174
|
+
[["listing", "pagination"], ["numbered", "load_more", "infinite"]],
|
|
175
|
+
[["listing", "filterLayout"], ["sidebar", "topbar", "drawer"]],
|
|
176
|
+
[["listing", "defaultSort"], SORT_KEYS],
|
|
177
|
+
[["card", "style"], ["standard", "minimal", "overlay", "row"]],
|
|
178
|
+
[["product", "layout"], ["classic", "stacked", "editorial"]],
|
|
179
|
+
[["product", "sectionsStyle"], ["auto", "tabs", "accordion", "stacked"]]
|
|
180
|
+
];
|
|
181
|
+
var SECTION_KEYS = ["description", "specs", "shipping", "tags", "categories", "related", "reviews"];
|
|
182
|
+
function fill(defaults, raw) {
|
|
183
|
+
if (isRecord(defaults)) {
|
|
184
|
+
const given = isRecord(raw) ? raw : {};
|
|
185
|
+
const out = {};
|
|
186
|
+
for (const key of Object.keys(defaults)) out[key] = fill(defaults[key], given[key]);
|
|
187
|
+
for (const key of Object.keys(given)) if (!isUnsafeKey(key) && !(key in out)) out[key] = given[key];
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
if (Array.isArray(defaults)) return Array.isArray(raw) ? raw : defaults;
|
|
191
|
+
if (defaults === null) return raw === void 0 ? null : raw;
|
|
192
|
+
if (typeof defaults === "number") return typeof raw === "number" && Number.isFinite(raw) ? raw : defaults;
|
|
193
|
+
return typeof raw === typeof defaults ? raw : defaults;
|
|
194
|
+
}
|
|
195
|
+
function cleanMenu(items) {
|
|
196
|
+
if (!Array.isArray(items)) return [];
|
|
197
|
+
return items.flatMap((item) => {
|
|
198
|
+
if (!isRecord(item) || typeof item.label !== "string" || !isRecord(item.target)) return [];
|
|
199
|
+
if (item.children === void 0) return [item];
|
|
200
|
+
if (!Array.isArray(item.children)) return [];
|
|
201
|
+
return [{ ...item, children: cleanMenu(item.children) }];
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
var warned = /* @__PURE__ */ new Set();
|
|
205
|
+
function warnOnce(key, message) {
|
|
206
|
+
if (process.env.NODE_ENV === "production" || warned.has(key)) return;
|
|
207
|
+
warned.add(key);
|
|
208
|
+
console.warn(`[@usethrottle/storefront-react] ${message}`);
|
|
209
|
+
}
|
|
210
|
+
function get(obj, path) {
|
|
211
|
+
let at = obj;
|
|
212
|
+
for (const key of path) at = isRecord(at) ? at[key] : void 0;
|
|
213
|
+
return at;
|
|
214
|
+
}
|
|
215
|
+
function set(obj, path, value) {
|
|
216
|
+
let at = obj;
|
|
217
|
+
for (const key of path.slice(0, -1)) at = at[key];
|
|
218
|
+
at[path[path.length - 1]] = value;
|
|
219
|
+
}
|
|
220
|
+
function normalizeSettings(raw) {
|
|
221
|
+
const out = fill(DEFAULT_SETTINGS, raw);
|
|
222
|
+
const strings = out.strings;
|
|
223
|
+
const defaultStrings = DEFAULT_SETTINGS.strings;
|
|
224
|
+
for (const key of Object.keys(defaultStrings)) if (strings[key] === "") strings[key] = defaultStrings[key];
|
|
225
|
+
for (const [path, allowed] of ENUMS) {
|
|
226
|
+
const value = get(out, path);
|
|
227
|
+
if (typeof value === "string" && allowed.includes(value)) continue;
|
|
228
|
+
const dotted = path.join(".");
|
|
229
|
+
warnOnce(`enum:${dotted}`, `settings.${dotted} has an unknown value (${JSON.stringify(value)}); using the default.`);
|
|
230
|
+
set(out, path, get(DEFAULT_SETTINGS, path));
|
|
231
|
+
}
|
|
232
|
+
const listing = out.listing;
|
|
233
|
+
listing.sorts = listing.sorts.filter(
|
|
234
|
+
(s) => isRecord(s) && typeof s.key === "string" && SORT_KEYS.includes(s.key)
|
|
235
|
+
);
|
|
236
|
+
const product = out.product;
|
|
237
|
+
product.sections = product.sections.filter(
|
|
238
|
+
(s) => isRecord(s) && typeof s.key === "string" && SECTION_KEYS.includes(s.key)
|
|
239
|
+
);
|
|
240
|
+
const nav = out.navigation;
|
|
241
|
+
nav.header = cleanMenu(nav.header);
|
|
242
|
+
nav.footer = cleanMenu(nav.footer);
|
|
243
|
+
const badges = out.badges;
|
|
244
|
+
badges.custom = badges.custom.filter(isRecord);
|
|
245
|
+
const home = out.home;
|
|
246
|
+
home.shelves = home.shelves.filter(isRecord);
|
|
247
|
+
return out;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/url/shop-list-query.ts
|
|
251
|
+
import { formatRange } from "@usethrottle/catalog/url";
|
|
252
|
+
var LITE_FIELDS = [
|
|
253
|
+
"availability",
|
|
254
|
+
"badges",
|
|
255
|
+
"brand",
|
|
256
|
+
"featured",
|
|
257
|
+
"handle",
|
|
258
|
+
"images",
|
|
259
|
+
"lowStock",
|
|
260
|
+
"optionSwatches",
|
|
261
|
+
"priceRange",
|
|
262
|
+
"productType",
|
|
263
|
+
"rating",
|
|
264
|
+
"seo",
|
|
265
|
+
"title",
|
|
266
|
+
"variantCount"
|
|
267
|
+
];
|
|
268
|
+
function cardFields(settings) {
|
|
269
|
+
return settings.card.showBadges && settings.badges.custom.length > 0 ? [...LITE_FIELDS, "tags"] : void 0;
|
|
270
|
+
}
|
|
271
|
+
function shopListQuery(query, source, settings, o = {}) {
|
|
272
|
+
const { listing } = settings;
|
|
273
|
+
const filters = {};
|
|
274
|
+
for (const [key, values] of Object.entries(query.filters)) filters[key] = [...values];
|
|
275
|
+
for (const [key, range] of Object.entries(query.ranges)) (filters[key] ??= []).push(formatRange(range));
|
|
276
|
+
const out = {
|
|
277
|
+
limit: listing.pageSize,
|
|
278
|
+
facets: true,
|
|
279
|
+
...o.fields ? { fields: o.fields } : {},
|
|
280
|
+
...query.page > 1 ? { page: query.page } : {},
|
|
281
|
+
...query.q ? { q: query.q } : {},
|
|
282
|
+
...Object.keys(filters).length > 0 ? { filters } : {},
|
|
283
|
+
...source.kind === "collection" ? { collection: source.handle } : {},
|
|
284
|
+
...source.kind === "category" ? { category: source.handle } : {},
|
|
285
|
+
...source.kind === "tag" ? { tags: [source.handle] } : {}
|
|
286
|
+
};
|
|
287
|
+
if (query.sort !== listing.defaultSort) {
|
|
288
|
+
const usable = query.sort === "relevance" ? Boolean(query.q) : query.sort === "manual" ? o.manualCollection === true : true;
|
|
289
|
+
if (usable) out.sort = query.sort;
|
|
290
|
+
} else if ((source.kind === "all" || source.kind === "category" || source.kind === "tag") && !["featured", "relevance", "manual"].includes(listing.defaultSort)) {
|
|
291
|
+
out.sort = listing.defaultSort;
|
|
292
|
+
}
|
|
293
|
+
return out;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/url/shop-query.ts
|
|
297
|
+
import {
|
|
298
|
+
formatRange as formatRange2,
|
|
299
|
+
parseRange,
|
|
300
|
+
parseShopQuery as parseCatalogQuery,
|
|
301
|
+
serializeShopQuery
|
|
302
|
+
} from "@usethrottle/catalog/url";
|
|
303
|
+
var enabledSorts = (settings) => new Set(settings.listing.sorts.filter((s) => s.enabled).map((s) => s.key));
|
|
304
|
+
function explicitSort(params, settings) {
|
|
305
|
+
const { sort } = parseCatalogQuery(params);
|
|
306
|
+
return sort !== void 0 && enabledSorts(settings).has(sort) ? sort : null;
|
|
307
|
+
}
|
|
308
|
+
function parseShopQuery(params, settings, rangeKeys) {
|
|
309
|
+
const ranged = rangeKeys === void 0 ? null : new Set(rangeKeys);
|
|
310
|
+
const raw = parseCatalogQuery(params);
|
|
311
|
+
const filters = {};
|
|
312
|
+
const ranges = {};
|
|
313
|
+
for (const key of Object.keys(raw.filters ?? {})) {
|
|
314
|
+
if (isUnsafeKey(key)) continue;
|
|
315
|
+
for (const value of raw.filters[key]) {
|
|
316
|
+
const range = ranged === null || ranged.has(key) ? parseRange(value) : null;
|
|
317
|
+
if (range) {
|
|
318
|
+
if (!Object.hasOwn(ranges, key)) ranges[key] = range;
|
|
319
|
+
} else (filters[key] ??= []).push(value);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
for (const key of Object.keys(filters)) filters[key] = [...new Set(filters[key])].sort();
|
|
323
|
+
const query = {
|
|
324
|
+
filters,
|
|
325
|
+
ranges,
|
|
326
|
+
sort: explicitSort(params, settings) ?? settings.listing.defaultSort,
|
|
327
|
+
page: raw.page !== void 0 && raw.page >= 1 ? raw.page : 1
|
|
328
|
+
};
|
|
329
|
+
if (raw.q) query.q = raw.q;
|
|
330
|
+
return query;
|
|
331
|
+
}
|
|
332
|
+
function toCatalogQuery(q, settings) {
|
|
333
|
+
const filters = {};
|
|
334
|
+
for (const key of Object.keys(q.filters)) filters[key] = [...q.filters[key]];
|
|
335
|
+
for (const key of Object.keys(q.ranges)) (filters[key] ??= []).push(formatRange2(q.ranges[key]));
|
|
336
|
+
for (const key of Object.keys(filters)) filters[key] = [...new Set(filters[key])].sort();
|
|
337
|
+
return {
|
|
338
|
+
...q.q ? { q: q.q } : {},
|
|
339
|
+
...Object.keys(filters).length > 0 ? { filters } : {},
|
|
340
|
+
...q.sort !== settings.listing.defaultSort ? { sort: q.sort } : {},
|
|
341
|
+
...q.page > 1 ? { page: q.page } : {}
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function shopQueryToSearch(q, settings) {
|
|
345
|
+
return serializeShopQuery(toCatalogQuery(q, settings));
|
|
346
|
+
}
|
|
347
|
+
function pageWindow(current, count) {
|
|
348
|
+
const pages = [.../* @__PURE__ */ new Set([1, current - 1, current, current + 1, count])].filter((p) => p >= 1 && p <= count).sort((a, b) => a - b);
|
|
349
|
+
const out = [];
|
|
350
|
+
for (const [i, p] of pages.entries()) {
|
|
351
|
+
if (i > 0 && p - pages[i - 1] > 1) out.push(null);
|
|
352
|
+
out.push(p);
|
|
353
|
+
}
|
|
354
|
+
return out;
|
|
355
|
+
}
|
|
356
|
+
function variantFromSearch(params, product) {
|
|
357
|
+
const value = params instanceof URLSearchParams ? params.get("variant") : params.variant;
|
|
358
|
+
const sku = Array.isArray(value) ? value[0] : value;
|
|
359
|
+
return sku !== void 0 && product.variants.some((v) => v.sku === sku) ? sku : null;
|
|
360
|
+
}
|
|
361
|
+
var filterValueCount = (q) => Object.values(q.filters).reduce((n, values) => n + values.length, 0) + Object.keys(q.ranges).length;
|
|
362
|
+
function robotsForShopQuery(q, settings) {
|
|
363
|
+
return { index: filterValueCount(q) <= 1 && q.sort === settings.listing.defaultSort && !q.q, follow: true };
|
|
364
|
+
}
|
|
365
|
+
function canonicalForShopQuery(baseUrl, pathname, q, settings, source) {
|
|
366
|
+
const first = [
|
|
367
|
+
...Object.entries(q.filters).flatMap(([key, values]) => values.map((value) => ({ key, value }))),
|
|
368
|
+
...Object.entries(q.ranges).map(([key, range]) => ({ key, value: formatRange2(range) }))
|
|
369
|
+
].sort((a, b) => a.key === b.key ? a.value.localeCompare(b.value) : a.key.localeCompare(b.key))[0];
|
|
370
|
+
const kept = {
|
|
371
|
+
filters: {},
|
|
372
|
+
ranges: {},
|
|
373
|
+
sort: settings.listing.defaultSort,
|
|
374
|
+
page: q.page,
|
|
375
|
+
...q.q && source?.kind === "search" ? { q: q.q } : {}
|
|
376
|
+
};
|
|
377
|
+
if (first) {
|
|
378
|
+
const range = parseRange(first.value);
|
|
379
|
+
if (range) kept.ranges[first.key] = range;
|
|
380
|
+
else kept.filters[first.key] = [first.value];
|
|
381
|
+
}
|
|
382
|
+
const search = shopQueryToSearch(kept, settings);
|
|
383
|
+
return `${baseUrl.replace(/\/+$/u, "")}${pathname}${search ? `?${search}` : ""}`;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// src/url/routes.ts
|
|
387
|
+
var fill2 = (pattern, name, value) => pattern.split(`{${name}}`).join(encodeURIComponent(value));
|
|
388
|
+
function routeHref(settings, kind, value, site) {
|
|
389
|
+
if (kind === "search") return fill2(settings.routes.search, "q", value);
|
|
390
|
+
const pattern = kind === "page" && site?.routes.page ? site.routes.page : settings.routes[kind];
|
|
391
|
+
return fill2(pattern, kind === "tag" ? "tag" : "handle", value);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// src/server/reviews-page.ts
|
|
395
|
+
var REVIEWS_PAGE_SIZE = 10;
|
|
396
|
+
|
|
397
|
+
// src/server/loaders.ts
|
|
398
|
+
var callOf = ({ locale, currency }) => ({
|
|
399
|
+
...locale ? { locale } : {},
|
|
400
|
+
...currency ? { currency } : {}
|
|
401
|
+
});
|
|
402
|
+
var primaryCall = (i) => ({
|
|
403
|
+
...callOf(i),
|
|
404
|
+
...i.primaryCache === "no-store" ? { fetchInit: { cache: "no-store" } } : {}
|
|
405
|
+
});
|
|
406
|
+
var generatedAt = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
407
|
+
async function orNull(request) {
|
|
408
|
+
try {
|
|
409
|
+
return await request;
|
|
410
|
+
} catch (error) {
|
|
411
|
+
if (isCatalogError(error) && error.code === "NOT_FOUND") return null;
|
|
412
|
+
throw error;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
async function loadConfig({ client, locale }) {
|
|
416
|
+
const config = await client.config(locale ? { locale } : void 0);
|
|
417
|
+
const definitions = config.filters;
|
|
418
|
+
return {
|
|
419
|
+
settings: normalizeSettings(config.settings),
|
|
420
|
+
// `/config` says whether reviews are on and shown on lists; absent (an older catalog) means they are.
|
|
421
|
+
reviewsOnLists: config.reviews?.enabled !== false && config.reviews?.onLists !== false,
|
|
422
|
+
reviewsEnabled: config.reviews?.enabled !== false,
|
|
423
|
+
// Undefined (every `a..b` value is a range) when the catalog sends no facet definitions.
|
|
424
|
+
rangeKeys: Array.isArray(definitions) ? definitions.filter((f) => f?.display === "range").map((f) => String(f.key)) : void 0
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
async function loadSettings(i) {
|
|
428
|
+
return (await loadConfig(i)).settings;
|
|
429
|
+
}
|
|
430
|
+
var text = (value) => value && value.trim() ? value : void 0;
|
|
431
|
+
function baseCrumbs(settings) {
|
|
432
|
+
const store = settings.brand.storeName.trim();
|
|
433
|
+
return store ? [{ name: store, href: "/" }] : [];
|
|
434
|
+
}
|
|
435
|
+
async function loadEntity(client, source, settings, call, primary) {
|
|
436
|
+
const shop = { name: t(settings, "shop.title"), href: settings.routes.shop };
|
|
437
|
+
const home = baseCrumbs(settings);
|
|
438
|
+
switch (source.kind) {
|
|
439
|
+
case "all":
|
|
440
|
+
return {
|
|
441
|
+
title: shop.name,
|
|
442
|
+
description: text(t(settings, "shop.description")),
|
|
443
|
+
breadcrumbs: [...home, shop]
|
|
444
|
+
};
|
|
445
|
+
case "search": {
|
|
446
|
+
const title = t(settings, "search.results", { q: source.q });
|
|
447
|
+
return { title, breadcrumbs: [...home, { name: title, href: routeHref(settings, "search", source.q) }] };
|
|
448
|
+
}
|
|
449
|
+
case "tag":
|
|
450
|
+
return {
|
|
451
|
+
title: source.handle,
|
|
452
|
+
breadcrumbs: [...home, shop, { name: source.handle, href: routeHref(settings, "tag", source.handle) }]
|
|
453
|
+
};
|
|
454
|
+
case "collection": {
|
|
455
|
+
const answer = await orNull(client.collections.get(source.handle, primary));
|
|
456
|
+
if (!answer) return null;
|
|
457
|
+
if ("redirectTo" in answer) return { redirectTo: answer.redirectTo };
|
|
458
|
+
const { collection } = answer;
|
|
459
|
+
const description = text(collection.seo.description) ?? text(collection.description);
|
|
460
|
+
return {
|
|
461
|
+
title: collection.title,
|
|
462
|
+
...text(collection.seo.title) ? { seoTitle: text(collection.seo.title) } : {},
|
|
463
|
+
...description ? { description } : {},
|
|
464
|
+
kind: collection.kind,
|
|
465
|
+
breadcrumbs: [
|
|
466
|
+
...home,
|
|
467
|
+
shop,
|
|
468
|
+
{ name: collection.title, href: routeHref(settings, "collection", collection.handle) }
|
|
469
|
+
]
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
case "category": {
|
|
473
|
+
const answer = await orNull(client.categories.get(source.handle, primary));
|
|
474
|
+
if (!answer) return null;
|
|
475
|
+
const { category } = answer;
|
|
476
|
+
const trail = answer.breadcrumbs.map((c) => ({ name: c.name, href: routeHref(settings, "category", c.handle) }));
|
|
477
|
+
if (answer.breadcrumbs.at(-1)?.handle !== category.handle)
|
|
478
|
+
trail.push({ name: category.name, href: routeHref(settings, "category", category.handle) });
|
|
479
|
+
return {
|
|
480
|
+
title: category.name,
|
|
481
|
+
...text(category.seoTitle) ? { seoTitle: text(category.seoTitle) } : {},
|
|
482
|
+
...text(category.description) ? { description: text(category.description) } : {},
|
|
483
|
+
breadcrumbs: [...home, shop, ...trail]
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
async function loadListing(i) {
|
|
489
|
+
const { client, source } = i;
|
|
490
|
+
const call = callOf(i);
|
|
491
|
+
const { settings, reviewsOnLists, rangeKeys } = await loadConfig(i);
|
|
492
|
+
const parsed = parseShopQuery(i.searchParams, settings, rangeKeys);
|
|
493
|
+
const query = source.kind === "search" ? { ...parsed, q: source.q } : parsed;
|
|
494
|
+
const entityRequest = loadEntity(client, source, settings, call, primaryCall(i));
|
|
495
|
+
const first = source.kind === "collection" && query.sort === "manual" ? await entityRequest : void 0;
|
|
496
|
+
if (first && "redirectTo" in first) return first;
|
|
497
|
+
const manualCollection = first !== void 0 && first !== null && "kind" in first && first.kind === "manual";
|
|
498
|
+
const listCall = query.q ? { ...call, fetchInit: { cache: "no-store" } } : call;
|
|
499
|
+
const [entity, list] = await Promise.all([
|
|
500
|
+
entityRequest,
|
|
501
|
+
orNull(client.products.list(shopListQuery(query, source, settings, { fields: cardFields(settings), manualCollection }), listCall))
|
|
502
|
+
]);
|
|
503
|
+
if (entity === null || list === null) return null;
|
|
504
|
+
if ("redirectTo" in entity) return entity;
|
|
505
|
+
const narrowed = Object.keys(query.filters).length > 0 || Object.keys(query.ranges).length > 0 || Boolean(query.q);
|
|
506
|
+
if (source.kind === "tag" && list.products.length === 0 && !narrowed) return null;
|
|
507
|
+
return {
|
|
508
|
+
source,
|
|
509
|
+
query,
|
|
510
|
+
list,
|
|
511
|
+
facets: list.filters ?? [],
|
|
512
|
+
title: entity.title,
|
|
513
|
+
...entity.seoTitle ? { seoTitle: entity.seoTitle } : {},
|
|
514
|
+
...entity.description ? { description: entity.description } : {},
|
|
515
|
+
...entity.kind ? { collectionKind: entity.kind } : {},
|
|
516
|
+
breadcrumbs: entity.breadcrumbs,
|
|
517
|
+
settings,
|
|
518
|
+
reviewsOnLists,
|
|
519
|
+
generatedAt: generatedAt()
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
var loadShopAll = loadListing;
|
|
523
|
+
async function loadSearch({ q, ...rest }) {
|
|
524
|
+
const data = await loadListing({ ...rest, source: { kind: "search", q } });
|
|
525
|
+
if (data === null || "redirectTo" in data) throw new Error("A search listing answered with no data.");
|
|
526
|
+
return data;
|
|
527
|
+
}
|
|
528
|
+
async function loadProduct(i) {
|
|
529
|
+
const { client, handle } = i;
|
|
530
|
+
const call = callOf(i);
|
|
531
|
+
const { settings, reviewsOnLists, reviewsEnabled } = await loadConfig(i);
|
|
532
|
+
const sections = settings.product.sections;
|
|
533
|
+
const relatedOn = sections.some((s) => s.key === "related" && s.enabled);
|
|
534
|
+
const reviewsSection = sections.some((s) => s.key === "reviews" && s.enabled);
|
|
535
|
+
const shippingHandle = sections.find((s) => s.key === "shipping" && s.enabled)?.pageHandle ?? null;
|
|
536
|
+
const [answer, related, reviews, shippingPage] = await Promise.all([
|
|
537
|
+
orNull(client.products.get(handle, primaryCall(i))),
|
|
538
|
+
relatedOn ? client.products.related(handle, { ...call, limit: settings.product.relatedLimit }).then((r) => r.products).catch((error) => {
|
|
539
|
+
if (isCatalogError(error)) return [];
|
|
540
|
+
throw error;
|
|
541
|
+
}) : Promise.resolve([]),
|
|
542
|
+
// The first page of reviews, the reviews cache kind of the client's policy: a 404 is "no reviews to show".
|
|
543
|
+
reviewsSection && reviewsEnabled ? client.reviews.list(handle, { sort: "newest", limit: REVIEWS_PAGE_SIZE, ...call }).then((r) => "redirectTo" in r ? void 0 : r).catch((error) => {
|
|
544
|
+
if (!isCatalogError(error)) throw error;
|
|
545
|
+
return error.code === "NOT_FOUND" ? null : void 0;
|
|
546
|
+
}) : Promise.resolve(reviewsSection ? null : void 0),
|
|
547
|
+
// The shipping page's body, for a store with no Builder; a missing page is null. Any other failure leaves it to the client.
|
|
548
|
+
shippingHandle && i.builder ? Promise.resolve(null) : shippingHandle ? client.pages.get(shippingHandle, call).then((p) => p.bodyHtml || null).catch((error) => {
|
|
549
|
+
if (!isCatalogError(error)) throw error;
|
|
550
|
+
return error.code === "PAGE_NOT_FOUND" || error.code === "NOT_FOUND" ? null : void 0;
|
|
551
|
+
}) : Promise.resolve(void 0)
|
|
552
|
+
]);
|
|
553
|
+
if (answer === null) return null;
|
|
554
|
+
if ("redirectTo" in answer) return { redirectTo: answer.redirectTo };
|
|
555
|
+
return {
|
|
556
|
+
product: answer.product,
|
|
557
|
+
variantSku: variantFromSearch(i.searchParams, answer.product),
|
|
558
|
+
related,
|
|
559
|
+
...reviews !== void 0 ? { reviews } : {},
|
|
560
|
+
...shippingPage !== void 0 ? { shippingPage } : {},
|
|
561
|
+
settings,
|
|
562
|
+
reviewsOnLists,
|
|
563
|
+
generatedAt: generatedAt()
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// src/server/merch.ts
|
|
568
|
+
import { isCatalogError as isCatalogError2 } from "@usethrottle/catalog";
|
|
569
|
+
|
|
570
|
+
// src/merch/product-source.ts
|
|
571
|
+
var MAX_MERCH_LIMIT = 96;
|
|
572
|
+
function clampLimit(limit) {
|
|
573
|
+
return Number.isFinite(limit) ? Math.min(MAX_MERCH_LIMIT, Math.max(1, Math.floor(limit))) : 1;
|
|
574
|
+
}
|
|
575
|
+
function manualHandles(source) {
|
|
576
|
+
return [...new Set(source.handles.filter((h) => typeof h === "string" && h.trim() !== ""))];
|
|
577
|
+
}
|
|
578
|
+
function isEmptySource(source) {
|
|
579
|
+
if (source.kind === "manual") return manualHandles(source).length === 0;
|
|
580
|
+
if (source.kind === "collection" || source.kind === "category" || source.kind === "tag") return source.handle.trim() === "";
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
function productSourceQuery(source, limit, o = {}) {
|
|
584
|
+
const more = o.fields ? { fields: o.fields } : {};
|
|
585
|
+
const size = clampLimit(limit);
|
|
586
|
+
switch (source.kind) {
|
|
587
|
+
case "collection":
|
|
588
|
+
return { collection: source.handle, limit: size, ...more };
|
|
589
|
+
case "category":
|
|
590
|
+
return { category: source.handle, limit: size, ...more };
|
|
591
|
+
case "tag":
|
|
592
|
+
return { tags: [source.handle], limit: size, ...more };
|
|
593
|
+
case "featured":
|
|
594
|
+
return { featured: true, limit: size, ...more };
|
|
595
|
+
case "newest":
|
|
596
|
+
case "best_rated":
|
|
597
|
+
return { sort: source.kind, limit: size, ...more };
|
|
598
|
+
case "manual": {
|
|
599
|
+
const handles = manualHandles(source).slice(0, size);
|
|
600
|
+
return { handles, limit: Math.max(1, handles.length), ...more };
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
function orderByHandles(products, handles) {
|
|
605
|
+
const byHandle = new Map(products.map((p) => [p.handle, p]));
|
|
606
|
+
return handles.flatMap((h) => {
|
|
607
|
+
const found = byHandle.get(h);
|
|
608
|
+
return found ? [found] : [];
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
function sourceProducts(source, products, limit) {
|
|
612
|
+
const ordered = source.kind === "manual" ? orderByHandles(products, manualHandles(source)) : [...products];
|
|
613
|
+
return ordered.slice(0, clampLimit(limit));
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
// src/server/merch.ts
|
|
617
|
+
async function orNull2(request) {
|
|
618
|
+
try {
|
|
619
|
+
return await request;
|
|
620
|
+
} catch (error) {
|
|
621
|
+
if (isCatalogError2(error) && error.code === "NOT_FOUND") return null;
|
|
622
|
+
throw error;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
async function collectionTitle(client, handle, call) {
|
|
626
|
+
const first = await orNull2(client.collections.get(handle, call));
|
|
627
|
+
if (!first) return void 0;
|
|
628
|
+
const answer = "redirectTo" in first ? await orNull2(client.collections.get(first.redirectTo, call)) : first;
|
|
629
|
+
return answer && "collection" in answer ? answer.collection.title : void 0;
|
|
630
|
+
}
|
|
631
|
+
async function loadMerchProducts(i) {
|
|
632
|
+
const { client, source, limit } = i;
|
|
633
|
+
const generatedAt2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
634
|
+
if (isEmptySource(source)) return { products: [], generatedAt: generatedAt2 };
|
|
635
|
+
const call = { ...i.locale ? { locale: i.locale } : {}, ...i.currency ? { currency: i.currency } : {} };
|
|
636
|
+
const settings = i.settings ?? await loadSettings({ client, ...i.locale ? { locale: i.locale } : {} });
|
|
637
|
+
const query = productSourceQuery(source, limit, { fields: cardFields(settings) });
|
|
638
|
+
const [list, title] = await Promise.all([
|
|
639
|
+
orNull2(client.products.list(query, call)),
|
|
640
|
+
source.kind === "collection" ? collectionTitle(client, source.handle, call) : Promise.resolve(void 0)
|
|
641
|
+
]);
|
|
642
|
+
if (!list) return { products: [], generatedAt: generatedAt2 };
|
|
643
|
+
return {
|
|
644
|
+
products: sourceProducts(source, list.products, limit),
|
|
645
|
+
generatedAt: generatedAt2,
|
|
646
|
+
...title ? { title } : {},
|
|
647
|
+
...list.priceContext ? { priceContext: list.priceContext } : {}
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// src/seo/json-ld.ts
|
|
652
|
+
import { toDecimalString } from "@usethrottle/money";
|
|
653
|
+
var SCHEMA = "https://schema.org";
|
|
654
|
+
var availabilityOf = (states) => {
|
|
655
|
+
if (states.includes("in_stock")) return `${SCHEMA}/InStock`;
|
|
656
|
+
if (states.includes("preorder")) return `${SCHEMA}/PreOrder`;
|
|
657
|
+
if (states.includes("backorder")) return `${SCHEMA}/BackOrder`;
|
|
658
|
+
return `${SCHEMA}/OutOfStock`;
|
|
659
|
+
};
|
|
660
|
+
function productJsonLd(product, o) {
|
|
661
|
+
const priced = product.variants.map((v) => ({ minor: v.salePriceMinor ?? v.priceMinor, currency: v.currency ?? o.currency })).filter((p) => p.minor !== null && p.currency === o.currency);
|
|
662
|
+
const lowest = priced.sort((a, b) => a.minor - b.minor)[0];
|
|
663
|
+
const price = lowest ?? (product.priceRange ? { minor: product.priceRange.minMinor, currency: product.priceRange.currency } : null);
|
|
664
|
+
const store = o.settings.brand.storeName.trim();
|
|
665
|
+
const description = product.shortDescription ?? product.description;
|
|
666
|
+
return {
|
|
667
|
+
"@context": SCHEMA,
|
|
668
|
+
"@type": "Product",
|
|
669
|
+
name: product.title ?? product.handle,
|
|
670
|
+
...description ? { description } : {},
|
|
671
|
+
...product.images.length > 0 ? { image: product.images.map((i) => i.url) } : {},
|
|
672
|
+
...product.brand ? { brand: { "@type": "Brand", name: product.brand } } : {},
|
|
673
|
+
...product.variants[0] ? { sku: product.variants[0].sku } : {},
|
|
674
|
+
url: o.url,
|
|
675
|
+
offers: {
|
|
676
|
+
"@type": "Offer",
|
|
677
|
+
url: o.url,
|
|
678
|
+
...price ? { price: toDecimalString(price.minor, price.currency), priceCurrency: price.currency } : {},
|
|
679
|
+
availability: availabilityOf(
|
|
680
|
+
product.variants.length > 0 ? product.variants.map((v) => v.availability) : [product.availability]
|
|
681
|
+
),
|
|
682
|
+
...store ? { seller: { "@type": "Organization", name: store } } : {}
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
function breadcrumbJsonLd(crumbs) {
|
|
687
|
+
return {
|
|
688
|
+
"@context": SCHEMA,
|
|
689
|
+
"@type": "BreadcrumbList",
|
|
690
|
+
itemListElement: crumbs.map((c, i) => ({ "@type": "ListItem", position: i + 1, name: c.name, item: c.url }))
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
function itemListJsonLd(products, o) {
|
|
694
|
+
const base = o.baseUrl.replace(/\/+$/u, "");
|
|
695
|
+
return {
|
|
696
|
+
"@context": SCHEMA,
|
|
697
|
+
"@type": "ItemList",
|
|
698
|
+
itemListElement: products.map((p, i) => ({
|
|
699
|
+
"@type": "ListItem",
|
|
700
|
+
position: i + 1,
|
|
701
|
+
url: `${base}${routeHref(o.settings, "product", p.handle)}`,
|
|
702
|
+
...p.title ? { name: p.title } : {}
|
|
703
|
+
}))
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// src/site/resolve.ts
|
|
708
|
+
import { PRESET_NAMES, PRESET_TOKENS } from "@usethrottle/ui/presets";
|
|
709
|
+
|
|
710
|
+
// src/site/menu.ts
|
|
711
|
+
import {
|
|
712
|
+
resolveMenuTarget
|
|
713
|
+
} from "@usethrottle/catalog";
|
|
714
|
+
function menuHref(settings, target) {
|
|
715
|
+
return resolveMenuTarget(settings, target);
|
|
716
|
+
}
|
|
717
|
+
function menuItems(settings, items) {
|
|
718
|
+
if (!Array.isArray(items)) return [];
|
|
719
|
+
return items.flatMap((item) => {
|
|
720
|
+
if (typeof item !== "object" || item === null || typeof item.label !== "string") return [];
|
|
721
|
+
if (typeof item.target !== "object" || item.target === null) return [];
|
|
722
|
+
if (item.children !== void 0 && !Array.isArray(item.children)) return [];
|
|
723
|
+
const href = menuHref(settings, item.target);
|
|
724
|
+
if (typeof href !== "string") return [];
|
|
725
|
+
const children = menuItems(settings, item.children ?? []);
|
|
726
|
+
const out = { label: item.label, href, kind: item.target.kind };
|
|
727
|
+
if (typeof item.target.handle === "string") out.handle = item.target.handle;
|
|
728
|
+
if (children.length > 0) out.children = children;
|
|
729
|
+
return [out];
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// src/site/catalog-adapter.ts
|
|
734
|
+
var mediaUrl = (media) => typeof media === "object" && media !== null && typeof media.url === "string" ? media.url : void 0;
|
|
735
|
+
var SITE_STRING_KEYS = ["footer.copyright", "nav.menu", "nav.account"];
|
|
736
|
+
function catalogSiteDesign(settings) {
|
|
737
|
+
const { brand, theme, announcement, seo } = settings;
|
|
738
|
+
const logo = {
|
|
739
|
+
...mediaUrl(brand.logo?.light) ? { light: mediaUrl(brand.logo?.light) } : {},
|
|
740
|
+
...mediaUrl(brand.logo?.dark) ? { dark: mediaUrl(brand.logo?.dark) } : {}
|
|
741
|
+
};
|
|
742
|
+
const strings = {};
|
|
743
|
+
for (const key of SITE_STRING_KEYS) {
|
|
744
|
+
const value = settings.strings[key];
|
|
745
|
+
if (value) strings[key] = value;
|
|
746
|
+
}
|
|
747
|
+
const href = announcement.enabled && typeof announcement.target === "object" && announcement.target !== null ? menuHref(settings, announcement.target) : null;
|
|
748
|
+
return {
|
|
749
|
+
source: "catalog-adapter",
|
|
750
|
+
brand: {
|
|
751
|
+
storeName: brand.storeName,
|
|
752
|
+
logo: Object.keys(logo).length > 0 ? logo : null,
|
|
753
|
+
favicon: mediaUrl(brand.favicon) ?? null
|
|
754
|
+
},
|
|
755
|
+
theme: {
|
|
756
|
+
customized: true,
|
|
757
|
+
values: {
|
|
758
|
+
light: theme.light,
|
|
759
|
+
dark: theme.dark,
|
|
760
|
+
fonts: theme.fonts,
|
|
761
|
+
radius: theme.radius,
|
|
762
|
+
spacingScale: theme.spacingScale
|
|
763
|
+
},
|
|
764
|
+
colorScheme: theme.colorScheme
|
|
765
|
+
},
|
|
766
|
+
menus: {
|
|
767
|
+
header: menuItems(settings, settings.navigation.header),
|
|
768
|
+
footer: menuItems(settings, settings.navigation.footer)
|
|
769
|
+
},
|
|
770
|
+
announcement: announcement.enabled && announcement.message ? { message: announcement.message, ...href ? { href } : {} } : null,
|
|
771
|
+
strings,
|
|
772
|
+
seo: {
|
|
773
|
+
titleTemplate: seo.titleTemplate,
|
|
774
|
+
...seo.defaultDescription ? { defaultDescription: seo.defaultDescription } : {},
|
|
775
|
+
...mediaUrl(seo.shareImage) ? { shareImage: mediaUrl(seo.shareImage) } : {}
|
|
776
|
+
},
|
|
777
|
+
routes: { page: settings.routes.page }
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// src/site/resolve.ts
|
|
782
|
+
function mergeTokens(base, ...layers) {
|
|
783
|
+
let out = base;
|
|
784
|
+
for (const layer of layers) {
|
|
785
|
+
if (layer === void 0) continue;
|
|
786
|
+
if (isRecord(out) && isRecord(layer)) {
|
|
787
|
+
const next = { ...out };
|
|
788
|
+
for (const key of Object.keys(layer)) {
|
|
789
|
+
if (isUnsafeKey(key)) continue;
|
|
790
|
+
next[key] = mergeTokens(out[key], layer[key]);
|
|
791
|
+
}
|
|
792
|
+
out = next;
|
|
793
|
+
} else {
|
|
794
|
+
out = layer;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
return out;
|
|
798
|
+
}
|
|
799
|
+
function definedEntries(map, ok) {
|
|
800
|
+
const out = {};
|
|
801
|
+
if (!isRecord(map)) return out;
|
|
802
|
+
for (const [key, value] of Object.entries(map)) if (ok(value) && !isUnsafeKey(key)) out[key] = value;
|
|
803
|
+
return out;
|
|
804
|
+
}
|
|
805
|
+
var isMenu = (v) => Array.isArray(v);
|
|
806
|
+
var isString = (v) => typeof v === "string";
|
|
807
|
+
var isPreset = (v) => PRESET_NAMES.includes(v);
|
|
808
|
+
var warned2 = /* @__PURE__ */ new Set();
|
|
809
|
+
var SHADOW_MESSAGE = {
|
|
810
|
+
preset: "The `preset` prop is ignored: the site design (the Throttle Builder) sets the preset and takes precedence.",
|
|
811
|
+
theme: "The `theme` prop is merged under the site design's theme values (the Throttle Builder): any token the site sets wins over it.",
|
|
812
|
+
scheme: "The `scheme` prop is ignored: the site design (the Throttle Builder) sets the colour scheme and takes precedence."
|
|
813
|
+
};
|
|
814
|
+
function warnShadowed(prop) {
|
|
815
|
+
if (process.env.NODE_ENV === "production" || warned2.has(prop)) return;
|
|
816
|
+
warned2.add(prop);
|
|
817
|
+
console.warn(`[@usethrottle/storefront-react] ${SHADOW_MESSAGE[prop]} Remove the prop, or change it in the Builder.`);
|
|
818
|
+
}
|
|
819
|
+
function resolveSiteDesign(input) {
|
|
820
|
+
const { site, settings } = input;
|
|
821
|
+
const adapter = catalogSiteDesign(settings);
|
|
822
|
+
const siteTheme = site?.theme;
|
|
823
|
+
const adapterTheme = adapter.theme;
|
|
824
|
+
const propsGiven = input.preset !== void 0 || input.theme !== void 0;
|
|
825
|
+
const adapterThemeActive = siteTheme === void 0 && !propsGiven;
|
|
826
|
+
const sitePreset = isPreset(siteTheme?.preset) ? siteTheme.preset : void 0;
|
|
827
|
+
const preset = sitePreset ?? (isPreset(input.preset) ? input.preset : "clean");
|
|
828
|
+
const siteValues = siteTheme && siteTheme.customized !== false ? siteTheme.values : void 0;
|
|
829
|
+
const winningValues = siteTheme ? siteValues : adapterThemeActive ? adapterTheme?.values : void 0;
|
|
830
|
+
const theme = mergeTokens(PRESET_TOKENS[preset], input.theme, winningValues);
|
|
831
|
+
const scheme = siteTheme?.colorScheme ?? input.scheme ?? (adapterThemeActive ? adapterTheme?.colorScheme : void 0) ?? "auto";
|
|
832
|
+
if (siteTheme) {
|
|
833
|
+
if (input.preset !== void 0 && siteTheme.preset !== void 0) warnShadowed("preset");
|
|
834
|
+
if (input.theme !== void 0 && siteValues !== void 0) warnShadowed("theme");
|
|
835
|
+
if (input.scheme !== void 0 && siteTheme.colorScheme !== void 0) warnShadowed("scheme");
|
|
836
|
+
}
|
|
837
|
+
const brand = {
|
|
838
|
+
storeName: site?.brand?.storeName ?? adapter.brand?.storeName ?? "",
|
|
839
|
+
logo: site?.brand?.logo !== void 0 ? site.brand.logo : adapter.brand?.logo ?? null
|
|
840
|
+
};
|
|
841
|
+
const builderStrings = definedEntries(site?.strings, isString);
|
|
842
|
+
const siteSeo = site?.seo;
|
|
843
|
+
const adapterSeo = adapter.seo;
|
|
844
|
+
const defaultDescription = siteSeo?.defaultDescription ?? adapterSeo?.defaultDescription;
|
|
845
|
+
const shareImage = siteSeo?.shareImage ?? adapterSeo?.shareImage;
|
|
846
|
+
return {
|
|
847
|
+
source: site ? site.source : "catalog-adapter",
|
|
848
|
+
preset,
|
|
849
|
+
scheme,
|
|
850
|
+
theme,
|
|
851
|
+
brand,
|
|
852
|
+
menus: { ...adapter.menus, ...definedEntries(site?.menus, isMenu) },
|
|
853
|
+
announcement: site?.announcement !== void 0 ? site.announcement : adapter.announcement ?? null,
|
|
854
|
+
strings: { ...adapter.strings, ...builderStrings },
|
|
855
|
+
builderStrings,
|
|
856
|
+
seo: {
|
|
857
|
+
titleTemplate: siteSeo?.titleTemplate ?? adapterSeo?.titleTemplate ?? settings.seo.titleTemplate,
|
|
858
|
+
...defaultDescription !== void 0 ? { defaultDescription } : {},
|
|
859
|
+
...shareImage !== void 0 ? { shareImage } : {}
|
|
860
|
+
},
|
|
861
|
+
routes: { page: site?.routes?.page ?? adapter.routes?.page ?? settings.routes.page },
|
|
862
|
+
throttlePublishableKey: input.throttlePublishableKey ?? site?.connections?.throttlePublishableKey ?? null,
|
|
863
|
+
pageOutlet: site?.pageOutlet ?? null
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// src/seo/metadata.ts
|
|
868
|
+
var origin = (baseUrl) => baseUrl.replace(/\/+$/u, "");
|
|
869
|
+
var absolute = (baseUrl, path) => `${origin(baseUrl)}${path}`;
|
|
870
|
+
function pageTitle(template, store, page) {
|
|
871
|
+
const name = page.trim();
|
|
872
|
+
const shop = store.trim();
|
|
873
|
+
if (name === "") return shop;
|
|
874
|
+
if (shop === "") return name;
|
|
875
|
+
return template.split("{page}").join(name).split("{store}").join(shop);
|
|
876
|
+
}
|
|
877
|
+
function resolved(data, o) {
|
|
878
|
+
return resolveSiteDesign({ site: o.site ?? null, settings: data.settings });
|
|
879
|
+
}
|
|
880
|
+
var nonEmpty = (value) => value && value.trim() ? value : void 0;
|
|
881
|
+
function openGraph(title, description, images) {
|
|
882
|
+
const urls = images.filter((u) => Boolean(u));
|
|
883
|
+
return { title, ...description ? { description } : {}, ...urls.length > 0 ? { images: urls } : {} };
|
|
884
|
+
}
|
|
885
|
+
function listingPath(settings, source) {
|
|
886
|
+
switch (source.kind) {
|
|
887
|
+
case "all":
|
|
888
|
+
return settings.routes.shop;
|
|
889
|
+
case "search":
|
|
890
|
+
return settings.routes.search.split("?")[0];
|
|
891
|
+
default:
|
|
892
|
+
return routeHref(settings, source.kind, source.handle);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
function shopAllMetadata(data, o) {
|
|
896
|
+
const site = resolved(data, o);
|
|
897
|
+
const title = pageTitle(site.seo.titleTemplate, site.brand.storeName, data.seoTitle ?? data.title);
|
|
898
|
+
const description = nonEmpty(data.description) ?? nonEmpty(site.seo.defaultDescription);
|
|
899
|
+
return {
|
|
900
|
+
title,
|
|
901
|
+
...description ? { description } : {},
|
|
902
|
+
alternates: {
|
|
903
|
+
canonical: canonicalForShopQuery(o.baseUrl, listingPath(data.settings, data.source), data.query, data.settings, data.source)
|
|
904
|
+
},
|
|
905
|
+
robots: robotsForShopQuery(data.query, data.settings),
|
|
906
|
+
openGraph: openGraph(title, description, [site.seo.shareImage])
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
function searchMetadata(data, o) {
|
|
910
|
+
return { ...shopAllMetadata(data, o), robots: { index: false, follow: true } };
|
|
911
|
+
}
|
|
912
|
+
function productMetadata(data, o) {
|
|
913
|
+
const { product } = data;
|
|
914
|
+
const site = resolved(data, o);
|
|
915
|
+
const name = nonEmpty(product.seoTitle) ?? nonEmpty(product.seo?.title) ?? product.title ?? product.handle;
|
|
916
|
+
const title = pageTitle(site.seo.titleTemplate, site.brand.storeName, name);
|
|
917
|
+
const description = nonEmpty(product.seoDescription) ?? nonEmpty(product.seo?.description) ?? nonEmpty(product.shortDescription) ?? nonEmpty(product.description) ?? nonEmpty(site.seo.defaultDescription);
|
|
918
|
+
return {
|
|
919
|
+
title,
|
|
920
|
+
...description ? { description } : {},
|
|
921
|
+
alternates: { canonical: absolute(o.baseUrl, routeHref(data.settings, "product", product.handle)) },
|
|
922
|
+
openGraph: openGraph(title, description, [product.images[0]?.url ?? site.seo.shareImage])
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
export {
|
|
926
|
+
STOREFRONT_CACHE_POLICY,
|
|
927
|
+
breadcrumbJsonLd,
|
|
928
|
+
canonicalForShopQuery,
|
|
929
|
+
cardFields,
|
|
930
|
+
createStorefrontServerClient,
|
|
931
|
+
itemListJsonLd,
|
|
932
|
+
loadMerchProducts,
|
|
933
|
+
loadProduct,
|
|
934
|
+
loadSearch,
|
|
935
|
+
loadSettings,
|
|
936
|
+
loadShopAll,
|
|
937
|
+
pageWindow,
|
|
938
|
+
parseShopQuery,
|
|
939
|
+
productJsonLd,
|
|
940
|
+
productMetadata,
|
|
941
|
+
productSourceQuery,
|
|
942
|
+
resolveSiteDesign,
|
|
943
|
+
robotsForShopQuery,
|
|
944
|
+
routeHref,
|
|
945
|
+
searchMetadata,
|
|
946
|
+
shopAllMetadata,
|
|
947
|
+
shopListQuery,
|
|
948
|
+
shopQueryToSearch,
|
|
949
|
+
variantFromSearch
|
|
950
|
+
};
|
|
951
|
+
//# sourceMappingURL=index.js.map
|