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