@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,188 @@
|
|
|
1
|
+
import { SiteDesign } from '@usethrottle/ui';
|
|
2
|
+
import { ResolvedStorefrontSettings, StorefrontProduct, CatalogClient, ListProduct, StorefrontReviewsAnswer, StorefrontListAnswer, Filter } from '@usethrottle/catalog';
|
|
3
|
+
|
|
4
|
+
/** The settings a component reads: the catalog's resolved document with every field present. */
|
|
5
|
+
type NormalizedSettings = ResolvedStorefrontSettings;
|
|
6
|
+
|
|
7
|
+
/** What `searchParams` is in a Next page: a plain record (a value may repeat). */
|
|
8
|
+
type SearchParamsInput = Record<string, string | string[] | undefined>;
|
|
9
|
+
/**
|
|
10
|
+
* The shop selection as URL state. Filters and ranges are `filter.<key>` URL
|
|
11
|
+
* parameters (the catalog SDK's wire form: a range is one `min..max` value).
|
|
12
|
+
* `sort` is always the effective sort: the URL's, or the store's default.
|
|
13
|
+
*/
|
|
14
|
+
type ShopQuery = {
|
|
15
|
+
filters: Record<string, string[]>;
|
|
16
|
+
ranges: Record<string, {
|
|
17
|
+
min?: number;
|
|
18
|
+
max?: number;
|
|
19
|
+
}>;
|
|
20
|
+
sort: string;
|
|
21
|
+
page: number;
|
|
22
|
+
q?: string;
|
|
23
|
+
};
|
|
24
|
+
/** What a listing shows: the whole shop, one collection, category or tag (by path), or a search. */
|
|
25
|
+
type ShopSource = {
|
|
26
|
+
kind: 'all';
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'collection' | 'category' | 'tag';
|
|
29
|
+
handle: string;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'search';
|
|
32
|
+
q: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Reads the URL state. A sort the store has disabled (or does not know) falls
|
|
36
|
+
* back to `listing.defaultSort`; a page below 1 or not a number is 1.
|
|
37
|
+
* Parameters follow the catalog SDK's shop URL: `filter.<key>`, `sort`, `page`, `q`.
|
|
38
|
+
*
|
|
39
|
+
* `rangeKeys` names the range-type facets (`display: 'range'`). Only their
|
|
40
|
+
* `a..b` values become `ranges`; on any other key the text stays a filter
|
|
41
|
+
* value. Left out, every `a..b` value is read as a range.
|
|
42
|
+
*/
|
|
43
|
+
declare function parseShopQuery(params: URLSearchParams | SearchParamsInput, settings: NormalizedSettings, rangeKeys?: Iterable<string>): ShopQuery;
|
|
44
|
+
/** The canonical query string (no leading `?`): keys sorted, values sorted, defaults (the default sort, page 1) omitted. */
|
|
45
|
+
declare function shopQueryToSearch(q: ShopQuery, settings: NormalizedSettings): string;
|
|
46
|
+
/** The page numbers to show: the first, the last and the current one's neighbours, `null` for a gap. */
|
|
47
|
+
declare function pageWindow(current: number, count: number): Array<number | null>;
|
|
48
|
+
/** The variant a product URL names (`?variant=<sku>`), or null when it names none the product has. */
|
|
49
|
+
declare function variantFromSearch(params: URLSearchParams | SearchParamsInput, product: Pick<StorefrontProduct, 'variants'>): string | null;
|
|
50
|
+
/**
|
|
51
|
+
* R4: a shop URL is `noindex,follow` when it carries two or more filter
|
|
52
|
+
* values, a sort other than the store's default, or a search term (`q` on a
|
|
53
|
+
* listing; a search page is `noindex` on its own). Links are always followed.
|
|
54
|
+
*/
|
|
55
|
+
declare function robotsForShopQuery(q: ShopQuery, settings: NormalizedSettings): {
|
|
56
|
+
index: boolean;
|
|
57
|
+
follow: true;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* R4: the canonical URL keeps at most one filter value (the first by key, then
|
|
61
|
+
* value) and `page` above 1, and drops the sort. `q` stays only on a search
|
|
62
|
+
* page (`source.kind === 'search'`); on a listing it is dropped. Absolute:
|
|
63
|
+
* `baseUrl` + `pathname`.
|
|
64
|
+
*/
|
|
65
|
+
declare function canonicalForShopQuery(baseUrl: string, pathname: string, q: ShopQuery, settings: NormalizedSettings, source?: ShopSource): string;
|
|
66
|
+
|
|
67
|
+
/** What every loader's answer carries. Plain JSON: safe to pass from a server component to a client one. */
|
|
68
|
+
type LoaderMeta = {
|
|
69
|
+
settings: NormalizedSettings;
|
|
70
|
+
/** Whether the catalog's lists carry ratings (`/config` `reviews`): hand it to `StorefrontProvider`'s `reviewsOnLists`. */
|
|
71
|
+
reviewsOnLists?: boolean;
|
|
72
|
+
/** When the server built this answer (ISO 8601). */
|
|
73
|
+
generatedAt: string;
|
|
74
|
+
};
|
|
75
|
+
/** One breadcrumb: a name and a site-relative link. */
|
|
76
|
+
type Crumb = {
|
|
77
|
+
name: string;
|
|
78
|
+
href: string;
|
|
79
|
+
};
|
|
80
|
+
/** What `loadShopAll` answers: the listing a `ShopAll` page needs, plain JSON. */
|
|
81
|
+
type ShopAllData = LoaderMeta & {
|
|
82
|
+
source: ShopSource;
|
|
83
|
+
query: ShopQuery;
|
|
84
|
+
/** The catalog's answer for the page `query` names. `list.sort` is the sort it applied (a collection keeps its own order unless the URL asks otherwise). */
|
|
85
|
+
list: StorefrontListAnswer;
|
|
86
|
+
/** The filters of `list`, for the filter pieces. */
|
|
87
|
+
facets: Filter[];
|
|
88
|
+
/** The page's heading: the shop's, the collection's, category's or tag's name, or the search's. */
|
|
89
|
+
title: string;
|
|
90
|
+
/** The merchant's SEO title for the entity, when it set one. */
|
|
91
|
+
seoTitle?: string;
|
|
92
|
+
description?: string;
|
|
93
|
+
/** A collection's kind: `shopListQuery`'s `manualCollection` is `collectionKind === 'manual'`. */
|
|
94
|
+
collectionKind?: 'manual' | 'rule';
|
|
95
|
+
/** Site-relative links, the store's name first when it has one. */
|
|
96
|
+
breadcrumbs: Crumb[];
|
|
97
|
+
};
|
|
98
|
+
/** What `loadProduct` answers: the product page's data, plain JSON. */
|
|
99
|
+
type ProductData = LoaderMeta & {
|
|
100
|
+
product: StorefrontProduct;
|
|
101
|
+
/** The variant `?variant=` names, or null. */
|
|
102
|
+
variantSku: string | null;
|
|
103
|
+
related: ListProduct[];
|
|
104
|
+
/**
|
|
105
|
+
* The first page of reviews (newest first), when the reviews section is on. `null`: there are no
|
|
106
|
+
* reviews to show (the catalog has reviews off, or answered 404 for this product), so the client
|
|
107
|
+
* asks for nothing. Absent: not asked (the section is off, or the read failed), so the client asks.
|
|
108
|
+
*/
|
|
109
|
+
reviews?: Exclude<StorefrontReviewsAnswer, {
|
|
110
|
+
redirectTo: string;
|
|
111
|
+
}> | null;
|
|
112
|
+
/**
|
|
113
|
+
* The body (HTML) of the catalog content page named by the `shipping` section's `pageHandle`.
|
|
114
|
+
* `null`: the page is missing, or the loader was told a Builder is in use (`builder: true`).
|
|
115
|
+
* Absent: not asked (no such section or no handle). Only a store with no Builder uses it (R14).
|
|
116
|
+
*/
|
|
117
|
+
shippingPage?: string | null;
|
|
118
|
+
};
|
|
119
|
+
/** A renamed handle: the handle it lives under now. */
|
|
120
|
+
type RedirectData = {
|
|
121
|
+
redirectTo: string;
|
|
122
|
+
};
|
|
123
|
+
type LoaderInput = {
|
|
124
|
+
client: CatalogClient;
|
|
125
|
+
locale?: string;
|
|
126
|
+
currency?: string;
|
|
127
|
+
/**
|
|
128
|
+
* How the lookup of the page's own subject is cached: the product of `loadProduct`, the collection or
|
|
129
|
+
* category of `loadShopAll`. `'default'` keeps the client's cache policy (long: cleared by the revalidate
|
|
130
|
+
* webhook and the generation watcher). `'no-store'` reads it live on every request, so a deleted or
|
|
131
|
+
* renamed product answers 404 or a redirect at once and never a cached 200; the route then renders on
|
|
132
|
+
* demand (no ISR write, but a render and a catalog call per request). The config, lists, related
|
|
133
|
+
* products and reviews stay on the client's policy. Default `'default'`.
|
|
134
|
+
*/
|
|
135
|
+
primaryCache?: 'default' | 'no-store';
|
|
136
|
+
};
|
|
137
|
+
/** Input of `loadShopAll`: what to list (`source`) and the page's `searchParams`. */
|
|
138
|
+
type LoadShopAllInput = LoaderInput & {
|
|
139
|
+
source: ShopSource;
|
|
140
|
+
searchParams: SearchParamsInput;
|
|
141
|
+
};
|
|
142
|
+
/** Input of `loadProduct`: the product `handle` and the page's `searchParams` (`?variant=`). */
|
|
143
|
+
type LoadProductInput = LoaderInput & {
|
|
144
|
+
handle: string;
|
|
145
|
+
searchParams: SearchParamsInput;
|
|
146
|
+
/** A Builder renders the shipping page (R14): the loader then does not read the catalog's page, and `shippingPage` is null. */
|
|
147
|
+
builder?: boolean;
|
|
148
|
+
};
|
|
149
|
+
/** Input of `loadSearch`: the query `q` and the page's `searchParams`. Search is never cached. */
|
|
150
|
+
type LoadSearchInput = LoaderInput & {
|
|
151
|
+
q: string;
|
|
152
|
+
searchParams: SearchParamsInput;
|
|
153
|
+
};
|
|
154
|
+
/** Input of `loadSettings`. */
|
|
155
|
+
type LoadSettingsInput = {
|
|
156
|
+
client: CatalogClient;
|
|
157
|
+
locale?: string;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/** Page metadata, assignable to Next's `Metadata`. */
|
|
161
|
+
type StorefrontMetadata = {
|
|
162
|
+
title: string;
|
|
163
|
+
description?: string;
|
|
164
|
+
alternates: {
|
|
165
|
+
canonical: string;
|
|
166
|
+
};
|
|
167
|
+
robots?: {
|
|
168
|
+
index: boolean;
|
|
169
|
+
follow: boolean;
|
|
170
|
+
};
|
|
171
|
+
openGraph?: {
|
|
172
|
+
title: string;
|
|
173
|
+
description?: string;
|
|
174
|
+
images?: string[];
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
type MetadataOptions = {
|
|
178
|
+
baseUrl: string;
|
|
179
|
+
site?: SiteDesign | null;
|
|
180
|
+
};
|
|
181
|
+
/** A shop, collection, category or tag page: the entity's SEO title, the canonical and robots of R4. */
|
|
182
|
+
declare function shopAllMetadata(data: ShopAllData, o: MetadataOptions): StorefrontMetadata;
|
|
183
|
+
/** Search results: indexable search pages only add near-duplicates, so they are `noindex,follow`. */
|
|
184
|
+
declare function searchMetadata(data: ShopAllData, o: MetadataOptions): StorefrontMetadata;
|
|
185
|
+
/** A product page: the merchant's SEO title and description, the first image, a canonical without `?variant=`. */
|
|
186
|
+
declare function productMetadata(data: ProductData, o: MetadataOptions): StorefrontMetadata;
|
|
187
|
+
|
|
188
|
+
export { type Crumb as C, type LoadProductInput as L, type NormalizedSettings as N, type ProductData as P, type RedirectData as R, type SearchParamsInput as S, type LoadSearchInput as a, type LoadSettingsInput as b, type LoadShopAllInput as c, type LoaderMeta as d, type ShopAllData as e, type ShopQuery as f, type ShopSource as g, type StorefrontMetadata as h, canonicalForShopQuery as i, parseShopQuery as j, productMetadata as k, shopAllMetadata as l, shopQueryToSearch as m, pageWindow as p, robotsForShopQuery as r, searchMetadata as s, variantFromSearch as v };
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { SiteDesign } from '@usethrottle/ui';
|
|
2
|
+
import { ResolvedStorefrontSettings, StorefrontProduct, CatalogClient, ListProduct, StorefrontReviewsAnswer, StorefrontListAnswer, Filter } from '@usethrottle/catalog';
|
|
3
|
+
|
|
4
|
+
/** The settings a component reads: the catalog's resolved document with every field present. */
|
|
5
|
+
type NormalizedSettings = ResolvedStorefrontSettings;
|
|
6
|
+
|
|
7
|
+
/** What `searchParams` is in a Next page: a plain record (a value may repeat). */
|
|
8
|
+
type SearchParamsInput = Record<string, string | string[] | undefined>;
|
|
9
|
+
/**
|
|
10
|
+
* The shop selection as URL state. Filters and ranges are `filter.<key>` URL
|
|
11
|
+
* parameters (the catalog SDK's wire form: a range is one `min..max` value).
|
|
12
|
+
* `sort` is always the effective sort: the URL's, or the store's default.
|
|
13
|
+
*/
|
|
14
|
+
type ShopQuery = {
|
|
15
|
+
filters: Record<string, string[]>;
|
|
16
|
+
ranges: Record<string, {
|
|
17
|
+
min?: number;
|
|
18
|
+
max?: number;
|
|
19
|
+
}>;
|
|
20
|
+
sort: string;
|
|
21
|
+
page: number;
|
|
22
|
+
q?: string;
|
|
23
|
+
};
|
|
24
|
+
/** What a listing shows: the whole shop, one collection, category or tag (by path), or a search. */
|
|
25
|
+
type ShopSource = {
|
|
26
|
+
kind: 'all';
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'collection' | 'category' | 'tag';
|
|
29
|
+
handle: string;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'search';
|
|
32
|
+
q: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Reads the URL state. A sort the store has disabled (or does not know) falls
|
|
36
|
+
* back to `listing.defaultSort`; a page below 1 or not a number is 1.
|
|
37
|
+
* Parameters follow the catalog SDK's shop URL: `filter.<key>`, `sort`, `page`, `q`.
|
|
38
|
+
*
|
|
39
|
+
* `rangeKeys` names the range-type facets (`display: 'range'`). Only their
|
|
40
|
+
* `a..b` values become `ranges`; on any other key the text stays a filter
|
|
41
|
+
* value. Left out, every `a..b` value is read as a range.
|
|
42
|
+
*/
|
|
43
|
+
declare function parseShopQuery(params: URLSearchParams | SearchParamsInput, settings: NormalizedSettings, rangeKeys?: Iterable<string>): ShopQuery;
|
|
44
|
+
/** The canonical query string (no leading `?`): keys sorted, values sorted, defaults (the default sort, page 1) omitted. */
|
|
45
|
+
declare function shopQueryToSearch(q: ShopQuery, settings: NormalizedSettings): string;
|
|
46
|
+
/** The page numbers to show: the first, the last and the current one's neighbours, `null` for a gap. */
|
|
47
|
+
declare function pageWindow(current: number, count: number): Array<number | null>;
|
|
48
|
+
/** The variant a product URL names (`?variant=<sku>`), or null when it names none the product has. */
|
|
49
|
+
declare function variantFromSearch(params: URLSearchParams | SearchParamsInput, product: Pick<StorefrontProduct, 'variants'>): string | null;
|
|
50
|
+
/**
|
|
51
|
+
* R4: a shop URL is `noindex,follow` when it carries two or more filter
|
|
52
|
+
* values, a sort other than the store's default, or a search term (`q` on a
|
|
53
|
+
* listing; a search page is `noindex` on its own). Links are always followed.
|
|
54
|
+
*/
|
|
55
|
+
declare function robotsForShopQuery(q: ShopQuery, settings: NormalizedSettings): {
|
|
56
|
+
index: boolean;
|
|
57
|
+
follow: true;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* R4: the canonical URL keeps at most one filter value (the first by key, then
|
|
61
|
+
* value) and `page` above 1, and drops the sort. `q` stays only on a search
|
|
62
|
+
* page (`source.kind === 'search'`); on a listing it is dropped. Absolute:
|
|
63
|
+
* `baseUrl` + `pathname`.
|
|
64
|
+
*/
|
|
65
|
+
declare function canonicalForShopQuery(baseUrl: string, pathname: string, q: ShopQuery, settings: NormalizedSettings, source?: ShopSource): string;
|
|
66
|
+
|
|
67
|
+
/** What every loader's answer carries. Plain JSON: safe to pass from a server component to a client one. */
|
|
68
|
+
type LoaderMeta = {
|
|
69
|
+
settings: NormalizedSettings;
|
|
70
|
+
/** Whether the catalog's lists carry ratings (`/config` `reviews`): hand it to `StorefrontProvider`'s `reviewsOnLists`. */
|
|
71
|
+
reviewsOnLists?: boolean;
|
|
72
|
+
/** When the server built this answer (ISO 8601). */
|
|
73
|
+
generatedAt: string;
|
|
74
|
+
};
|
|
75
|
+
/** One breadcrumb: a name and a site-relative link. */
|
|
76
|
+
type Crumb = {
|
|
77
|
+
name: string;
|
|
78
|
+
href: string;
|
|
79
|
+
};
|
|
80
|
+
/** What `loadShopAll` answers: the listing a `ShopAll` page needs, plain JSON. */
|
|
81
|
+
type ShopAllData = LoaderMeta & {
|
|
82
|
+
source: ShopSource;
|
|
83
|
+
query: ShopQuery;
|
|
84
|
+
/** The catalog's answer for the page `query` names. `list.sort` is the sort it applied (a collection keeps its own order unless the URL asks otherwise). */
|
|
85
|
+
list: StorefrontListAnswer;
|
|
86
|
+
/** The filters of `list`, for the filter pieces. */
|
|
87
|
+
facets: Filter[];
|
|
88
|
+
/** The page's heading: the shop's, the collection's, category's or tag's name, or the search's. */
|
|
89
|
+
title: string;
|
|
90
|
+
/** The merchant's SEO title for the entity, when it set one. */
|
|
91
|
+
seoTitle?: string;
|
|
92
|
+
description?: string;
|
|
93
|
+
/** A collection's kind: `shopListQuery`'s `manualCollection` is `collectionKind === 'manual'`. */
|
|
94
|
+
collectionKind?: 'manual' | 'rule';
|
|
95
|
+
/** Site-relative links, the store's name first when it has one. */
|
|
96
|
+
breadcrumbs: Crumb[];
|
|
97
|
+
};
|
|
98
|
+
/** What `loadProduct` answers: the product page's data, plain JSON. */
|
|
99
|
+
type ProductData = LoaderMeta & {
|
|
100
|
+
product: StorefrontProduct;
|
|
101
|
+
/** The variant `?variant=` names, or null. */
|
|
102
|
+
variantSku: string | null;
|
|
103
|
+
related: ListProduct[];
|
|
104
|
+
/**
|
|
105
|
+
* The first page of reviews (newest first), when the reviews section is on. `null`: there are no
|
|
106
|
+
* reviews to show (the catalog has reviews off, or answered 404 for this product), so the client
|
|
107
|
+
* asks for nothing. Absent: not asked (the section is off, or the read failed), so the client asks.
|
|
108
|
+
*/
|
|
109
|
+
reviews?: Exclude<StorefrontReviewsAnswer, {
|
|
110
|
+
redirectTo: string;
|
|
111
|
+
}> | null;
|
|
112
|
+
/**
|
|
113
|
+
* The body (HTML) of the catalog content page named by the `shipping` section's `pageHandle`.
|
|
114
|
+
* `null`: the page is missing, or the loader was told a Builder is in use (`builder: true`).
|
|
115
|
+
* Absent: not asked (no such section or no handle). Only a store with no Builder uses it (R14).
|
|
116
|
+
*/
|
|
117
|
+
shippingPage?: string | null;
|
|
118
|
+
};
|
|
119
|
+
/** A renamed handle: the handle it lives under now. */
|
|
120
|
+
type RedirectData = {
|
|
121
|
+
redirectTo: string;
|
|
122
|
+
};
|
|
123
|
+
type LoaderInput = {
|
|
124
|
+
client: CatalogClient;
|
|
125
|
+
locale?: string;
|
|
126
|
+
currency?: string;
|
|
127
|
+
/**
|
|
128
|
+
* How the lookup of the page's own subject is cached: the product of `loadProduct`, the collection or
|
|
129
|
+
* category of `loadShopAll`. `'default'` keeps the client's cache policy (long: cleared by the revalidate
|
|
130
|
+
* webhook and the generation watcher). `'no-store'` reads it live on every request, so a deleted or
|
|
131
|
+
* renamed product answers 404 or a redirect at once and never a cached 200; the route then renders on
|
|
132
|
+
* demand (no ISR write, but a render and a catalog call per request). The config, lists, related
|
|
133
|
+
* products and reviews stay on the client's policy. Default `'default'`.
|
|
134
|
+
*/
|
|
135
|
+
primaryCache?: 'default' | 'no-store';
|
|
136
|
+
};
|
|
137
|
+
/** Input of `loadShopAll`: what to list (`source`) and the page's `searchParams`. */
|
|
138
|
+
type LoadShopAllInput = LoaderInput & {
|
|
139
|
+
source: ShopSource;
|
|
140
|
+
searchParams: SearchParamsInput;
|
|
141
|
+
};
|
|
142
|
+
/** Input of `loadProduct`: the product `handle` and the page's `searchParams` (`?variant=`). */
|
|
143
|
+
type LoadProductInput = LoaderInput & {
|
|
144
|
+
handle: string;
|
|
145
|
+
searchParams: SearchParamsInput;
|
|
146
|
+
/** A Builder renders the shipping page (R14): the loader then does not read the catalog's page, and `shippingPage` is null. */
|
|
147
|
+
builder?: boolean;
|
|
148
|
+
};
|
|
149
|
+
/** Input of `loadSearch`: the query `q` and the page's `searchParams`. Search is never cached. */
|
|
150
|
+
type LoadSearchInput = LoaderInput & {
|
|
151
|
+
q: string;
|
|
152
|
+
searchParams: SearchParamsInput;
|
|
153
|
+
};
|
|
154
|
+
/** Input of `loadSettings`. */
|
|
155
|
+
type LoadSettingsInput = {
|
|
156
|
+
client: CatalogClient;
|
|
157
|
+
locale?: string;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/** Page metadata, assignable to Next's `Metadata`. */
|
|
161
|
+
type StorefrontMetadata = {
|
|
162
|
+
title: string;
|
|
163
|
+
description?: string;
|
|
164
|
+
alternates: {
|
|
165
|
+
canonical: string;
|
|
166
|
+
};
|
|
167
|
+
robots?: {
|
|
168
|
+
index: boolean;
|
|
169
|
+
follow: boolean;
|
|
170
|
+
};
|
|
171
|
+
openGraph?: {
|
|
172
|
+
title: string;
|
|
173
|
+
description?: string;
|
|
174
|
+
images?: string[];
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
type MetadataOptions = {
|
|
178
|
+
baseUrl: string;
|
|
179
|
+
site?: SiteDesign | null;
|
|
180
|
+
};
|
|
181
|
+
/** A shop, collection, category or tag page: the entity's SEO title, the canonical and robots of R4. */
|
|
182
|
+
declare function shopAllMetadata(data: ShopAllData, o: MetadataOptions): StorefrontMetadata;
|
|
183
|
+
/** Search results: indexable search pages only add near-duplicates, so they are `noindex,follow`. */
|
|
184
|
+
declare function searchMetadata(data: ShopAllData, o: MetadataOptions): StorefrontMetadata;
|
|
185
|
+
/** A product page: the merchant's SEO title and description, the first image, a canonical without `?variant=`. */
|
|
186
|
+
declare function productMetadata(data: ProductData, o: MetadataOptions): StorefrontMetadata;
|
|
187
|
+
|
|
188
|
+
export { type Crumb as C, type LoadProductInput as L, type NormalizedSettings as N, type ProductData as P, type RedirectData as R, type SearchParamsInput as S, type LoadSearchInput as a, type LoadSettingsInput as b, type LoadShopAllInput as c, type LoaderMeta as d, type ShopAllData as e, type ShopQuery as f, type ShopSource as g, type StorefrontMetadata as h, canonicalForShopQuery as i, parseShopQuery as j, productMetadata as k, shopAllMetadata as l, shopQueryToSearch as m, pageWindow as p, robotsForShopQuery as r, searchMetadata as s, variantFromSearch as v };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunk6ZMMZ245cjs = require('../chunk-6ZMMZ245.cjs');
|
|
6
|
+
require('../chunk-2LCPIY2P.cjs');
|
|
7
|
+
require('../chunk-M4YXSLRG.cjs');
|
|
8
|
+
require('../chunk-VWXJO427.cjs');
|
|
9
|
+
|
|
10
|
+
// src/next/client.tsx
|
|
11
|
+
var _linkjs = require('next/link.js'); var _linkjs2 = _interopRequireDefault(_linkjs);
|
|
12
|
+
var _navigationjs = require('next/navigation.js');
|
|
13
|
+
var _react = require('react');
|
|
14
|
+
|
|
15
|
+
// src/next/sync-client.ts
|
|
16
|
+
var THROTTLED_RETRY_MS = 5100;
|
|
17
|
+
var MAX_RETRY_MS = 65e3;
|
|
18
|
+
async function syncServerGeneration(path) {
|
|
19
|
+
const ask = async () => {
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(path, { method: "POST", cache: "no-store" });
|
|
22
|
+
if (!response.ok) return void 0;
|
|
23
|
+
const answer = await response.json();
|
|
24
|
+
if (typeof _optionalChain([answer, 'optionalAccess', _ => _.retryAfterMs]) === "number") return Math.min(Math.max(answer.retryAfterMs, 0) + 100, MAX_RETRY_MS);
|
|
25
|
+
return _optionalChain([answer, 'optionalAccess', _2 => _2.throttled]) === true ? THROTTLED_RETRY_MS : void 0;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const wait = await ask();
|
|
31
|
+
if (wait !== void 0) {
|
|
32
|
+
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
33
|
+
await ask();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/next/client.tsx
|
|
38
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
39
|
+
var Link = ({ prefetch, ...anchor }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _linkjs2.default, { prefetch, ...anchor });
|
|
40
|
+
function SearchParamsBridge({ seen, onChange }) {
|
|
41
|
+
const query = _nullishCoalesce(_optionalChain([_navigationjs.useSearchParams.call(void 0, ), 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]), () => ( ""));
|
|
42
|
+
seen.current = query;
|
|
43
|
+
_react.useEffect.call(void 0, () => onChange(query), [query, onChange]);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function StorefrontNextProvider(props) {
|
|
47
|
+
const seen = _react.useRef.call(void 0, null);
|
|
48
|
+
const [read, setRead] = _react.useState.call(void 0, null);
|
|
49
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
50
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Suspense, { fallback: null, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SearchParamsBridge, { seen, onChange: setRead }) }),
|
|
51
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, NextProviderBody, { ...props, seen, read })
|
|
52
|
+
] });
|
|
53
|
+
}
|
|
54
|
+
function NextProviderBody({
|
|
55
|
+
syncPath = "/api/throttle/sync",
|
|
56
|
+
seen,
|
|
57
|
+
read,
|
|
58
|
+
...props
|
|
59
|
+
}) {
|
|
60
|
+
const next = _navigationjs.useRouter.call(void 0, );
|
|
61
|
+
const pathname = _navigationjs.usePathname.call(void 0, );
|
|
62
|
+
const query = _nullishCoalesce(_nullishCoalesce(seen.current, () => ( read)), () => ( ""));
|
|
63
|
+
const router = _react.useMemo.call(void 0,
|
|
64
|
+
() => ({
|
|
65
|
+
pathname: _nullishCoalesce(pathname, () => ( "/")),
|
|
66
|
+
searchParams: new URLSearchParams(query),
|
|
67
|
+
push: (href, options) => next.push(href, options),
|
|
68
|
+
replace: (href, options) => next.replace(href, options)
|
|
69
|
+
}),
|
|
70
|
+
[next, pathname, query]
|
|
71
|
+
);
|
|
72
|
+
const onGenerationChange = _react.useCallback.call(void 0, () => {
|
|
73
|
+
void (async () => {
|
|
74
|
+
if (syncPath !== null) await syncServerGeneration(syncPath);
|
|
75
|
+
next.refresh();
|
|
76
|
+
})();
|
|
77
|
+
}, [next, syncPath]);
|
|
78
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk6ZMMZ245cjs.StorefrontProvider, { ...props, router, linkComponent: Link, onGenerationChange });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
exports.StorefrontNextProvider = StorefrontNextProvider; exports.syncServerGeneration = syncServerGeneration;
|
|
84
|
+
//# sourceMappingURL=client.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/app-throttle/app-throttle/packages/storefront-react/dist/next/client.cjs","../../src/next/client.tsx","../../src/next/sync-client.ts"],"names":[],"mappings":"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","file":"/home/runner/work/app-throttle/app-throttle/packages/storefront-react/dist/next/client.cjs","sourcesContent":[null,"import NextLink from 'next/link.js';\nimport { usePathname, useRouter, useSearchParams } from 'next/navigation.js';\nimport { Suspense, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { StorefrontProvider, type StorefrontProviderProps } from '../provider/StorefrontProvider';\nimport type { StorefrontRouter } from '../provider/router';\nimport type { LinkComponent } from '../link';\nimport { syncServerGeneration } from './sync-client';\n\nexport { syncServerGeneration } from './sync-client';\n\n/**\n * The props of `StorefrontNextProvider`: those of `StorefrontProvider` except the router, the link and `onGenerationChange`, which it supplies, plus `syncPath`.\n */\nexport type StorefrontNextProviderProps = Omit<StorefrontProviderProps, 'router' | 'linkComponent' | 'onGenerationChange'> & {\n /**\n * The route that clears the server's cache when the catalog changed (`createGenerationSyncHandler`).\n * Default `'/api/throttle/sync'`; `null` skips the POST and the refresh alone follows.\n */\n syncPath?: string | null;\n};\n\n// `.js` suffixes: `next` has no exports map, so native Node ESM (a plain import of this entry) needs the file name.\nconst Link: LinkComponent = ({ prefetch, ...anchor }) => <NextLink prefetch={prefetch} {...anchor} />;\n\ntype QuerySeen = { current: string | null };\n\n/**\n * Reads the URL's query for the provider. It renders nothing and has no children, and sits in its own\n * `<Suspense>`: on a statically rendered route `useSearchParams` suspends (client rendering up to the\n * nearest boundary), and that must stop here, not take the whole storefront tree with it (the server could\n * then neither send the page nor answer a 404). While it renders it leaves the query in `seen`; the body\n * renders after it, as its next sibling, so a render of the tree (on the server, in hydration, on a\n * navigation) always reads the query of the URL it renders for. `onChange` only makes the body render again\n * when the browser reads a query the server could not (a static route), or when only the query changed.\n */\nfunction SearchParamsBridge({ seen, onChange }: { seen: QuerySeen; onChange(query: string): void }) {\n const query = useSearchParams()?.toString() ?? '';\n seen.current = query;\n useEffect(() => onChange(query), [query, onChange]);\n return null;\n}\n\n/**\n * `StorefrontProvider` for the Next App Router: navigation through `useRouter`, `usePathname` and\n * `useSearchParams`, links through `next/link`, and, when the catalog's generation changes in an open\n * tab (`generationWatch`, every 60 s at the least, `false` to turn it off), a POST to `syncPath` and then\n * `router.refresh()`. The signed webhook (`createRevalidateHandler`) stays the primary path.\n *\n * The query comes from `useSearchParams`, read in a small component of its own inside a `<Suspense>`, so a\n * statically rendered route is sent with the whole tree (the query is empty until the browser reads the\n * URL; a product page then takes `?variant=` from it) and a missing page can still answer 404.\n */\nexport function StorefrontNextProvider(props: StorefrontNextProviderProps) {\n const seen = useRef<string | null>(null);\n const [read, setRead] = useState<string | null>(null);\n return (\n <>\n <Suspense fallback={null}>\n <SearchParamsBridge seen={seen} onChange={setRead} />\n </Suspense>\n <NextProviderBody {...props} seen={seen} read={read} />\n </>\n );\n}\n\nfunction NextProviderBody({\n syncPath = '/api/throttle/sync',\n seen,\n read,\n ...props\n}: StorefrontNextProviderProps & { seen: QuerySeen; read: string | null }) {\n const next = useRouter();\n const pathname = usePathname();\n // `seen` is the query of the URL being rendered (the bridge rendered just before this); `read` is only\n // what the browser reported, for the one case where the bridge could not render (a static route's first pass).\n const query = seen.current ?? read ?? '';\n const router = useMemo<StorefrontRouter>(\n () => ({\n pathname: pathname ?? '/',\n searchParams: new URLSearchParams(query),\n push: (href, options) => next.push(href, options),\n replace: (href, options) => next.replace(href, options),\n }),\n [next, pathname, query],\n );\n const onGenerationChange = useCallback(() => {\n void (async () => {\n if (syncPath !== null) await syncServerGeneration(syncPath);\n next.refresh();\n })();\n }, [next, syncPath]);\n return <StorefrontProvider {...props} router={router} linkComponent={Link} onGenerationChange={onGenerationChange} />;\n}\n","/** How long a throttled answer waits before the one more ask: the server's 5 s window plus a margin. */\nconst THROTTLED_RETRY_MS = 5100;\n/** The longest a deferred clearing is waited for (the server's window is 60 s). */\nconst MAX_RETRY_MS = 65_000;\n\n/**\n * Asks the server to check the catalog's generation and clear its cache if it moved, so the\n * `router.refresh()` that follows renders the change. A throttled answer (another tab or request read a\n * moment ago) is asked once more after 5100 ms. An answer with `retryAfterMs` (the change was found but\n * the minute's one clearing was spent) is asked once more after that long. Every failure resolves: the\n * refresh still happens.\n */\nexport async function syncServerGeneration(path: string): Promise<void> {\n const ask = async (): Promise<number | undefined> => {\n try {\n const response = await fetch(path, { method: 'POST', cache: 'no-store' });\n if (!response.ok) return undefined;\n const answer = (await response.json()) as { throttled?: boolean; retryAfterMs?: number } | null;\n if (typeof answer?.retryAfterMs === 'number') return Math.min(Math.max(answer.retryAfterMs, 0) + 100, MAX_RETRY_MS);\n return answer?.throttled === true ? THROTTLED_RETRY_MS : undefined;\n } catch {\n return undefined;\n }\n };\n const wait = await ask();\n if (wait !== undefined) {\n await new Promise<void>((resolve) => setTimeout(resolve, wait));\n await ask();\n }\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { m as StorefrontProviderProps } from '../StorefrontProvider-Br4wUHui.cjs';
|
|
3
|
+
import '@usethrottle/catalog';
|
|
4
|
+
import '@usethrottle/catalog/react';
|
|
5
|
+
import '@usethrottle/ui';
|
|
6
|
+
import 'react';
|
|
7
|
+
import '../index-RSj2Rg62.cjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Asks the server to check the catalog's generation and clear its cache if it moved, so the
|
|
11
|
+
* `router.refresh()` that follows renders the change. A throttled answer (another tab or request read a
|
|
12
|
+
* moment ago) is asked once more after 5100 ms. An answer with `retryAfterMs` (the change was found but
|
|
13
|
+
* the minute's one clearing was spent) is asked once more after that long. Every failure resolves: the
|
|
14
|
+
* refresh still happens.
|
|
15
|
+
*/
|
|
16
|
+
declare function syncServerGeneration(path: string): Promise<void>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The props of `StorefrontNextProvider`: those of `StorefrontProvider` except the router, the link and `onGenerationChange`, which it supplies, plus `syncPath`.
|
|
20
|
+
*/
|
|
21
|
+
type StorefrontNextProviderProps = Omit<StorefrontProviderProps, 'router' | 'linkComponent' | 'onGenerationChange'> & {
|
|
22
|
+
/**
|
|
23
|
+
* The route that clears the server's cache when the catalog changed (`createGenerationSyncHandler`).
|
|
24
|
+
* Default `'/api/throttle/sync'`; `null` skips the POST and the refresh alone follows.
|
|
25
|
+
*/
|
|
26
|
+
syncPath?: string | null;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* `StorefrontProvider` for the Next App Router: navigation through `useRouter`, `usePathname` and
|
|
30
|
+
* `useSearchParams`, links through `next/link`, and, when the catalog's generation changes in an open
|
|
31
|
+
* tab (`generationWatch`, every 60 s at the least, `false` to turn it off), a POST to `syncPath` and then
|
|
32
|
+
* `router.refresh()`. The signed webhook (`createRevalidateHandler`) stays the primary path.
|
|
33
|
+
*
|
|
34
|
+
* The query comes from `useSearchParams`, read in a small component of its own inside a `<Suspense>`, so a
|
|
35
|
+
* statically rendered route is sent with the whole tree (the query is empty until the browser reads the
|
|
36
|
+
* URL; a product page then takes `?variant=` from it) and a missing page can still answer 404.
|
|
37
|
+
*/
|
|
38
|
+
declare function StorefrontNextProvider(props: StorefrontNextProviderProps): react_jsx_runtime.JSX.Element;
|
|
39
|
+
|
|
40
|
+
export { StorefrontNextProvider, type StorefrontNextProviderProps, syncServerGeneration };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { m as StorefrontProviderProps } from '../StorefrontProvider-DLEPEjg6.js';
|
|
3
|
+
import '@usethrottle/catalog';
|
|
4
|
+
import '@usethrottle/catalog/react';
|
|
5
|
+
import '@usethrottle/ui';
|
|
6
|
+
import 'react';
|
|
7
|
+
import '../index-RSj2Rg62.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Asks the server to check the catalog's generation and clear its cache if it moved, so the
|
|
11
|
+
* `router.refresh()` that follows renders the change. A throttled answer (another tab or request read a
|
|
12
|
+
* moment ago) is asked once more after 5100 ms. An answer with `retryAfterMs` (the change was found but
|
|
13
|
+
* the minute's one clearing was spent) is asked once more after that long. Every failure resolves: the
|
|
14
|
+
* refresh still happens.
|
|
15
|
+
*/
|
|
16
|
+
declare function syncServerGeneration(path: string): Promise<void>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The props of `StorefrontNextProvider`: those of `StorefrontProvider` except the router, the link and `onGenerationChange`, which it supplies, plus `syncPath`.
|
|
20
|
+
*/
|
|
21
|
+
type StorefrontNextProviderProps = Omit<StorefrontProviderProps, 'router' | 'linkComponent' | 'onGenerationChange'> & {
|
|
22
|
+
/**
|
|
23
|
+
* The route that clears the server's cache when the catalog changed (`createGenerationSyncHandler`).
|
|
24
|
+
* Default `'/api/throttle/sync'`; `null` skips the POST and the refresh alone follows.
|
|
25
|
+
*/
|
|
26
|
+
syncPath?: string | null;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* `StorefrontProvider` for the Next App Router: navigation through `useRouter`, `usePathname` and
|
|
30
|
+
* `useSearchParams`, links through `next/link`, and, when the catalog's generation changes in an open
|
|
31
|
+
* tab (`generationWatch`, every 60 s at the least, `false` to turn it off), a POST to `syncPath` and then
|
|
32
|
+
* `router.refresh()`. The signed webhook (`createRevalidateHandler`) stays the primary path.
|
|
33
|
+
*
|
|
34
|
+
* The query comes from `useSearchParams`, read in a small component of its own inside a `<Suspense>`, so a
|
|
35
|
+
* statically rendered route is sent with the whole tree (the query is empty until the browser reads the
|
|
36
|
+
* URL; a product page then takes `?variant=` from it) and a missing page can still answer 404.
|
|
37
|
+
*/
|
|
38
|
+
declare function StorefrontNextProvider(props: StorefrontNextProviderProps): react_jsx_runtime.JSX.Element;
|
|
39
|
+
|
|
40
|
+
export { StorefrontNextProvider, type StorefrontNextProviderProps, syncServerGeneration };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
StorefrontProvider
|
|
4
|
+
} from "../chunk-3A72UY6T.js";
|
|
5
|
+
import "../chunk-NW3EFHY2.js";
|
|
6
|
+
import "../chunk-A3IFWQUV.js";
|
|
7
|
+
import "../chunk-NNE4FYRT.js";
|
|
8
|
+
|
|
9
|
+
// src/next/client.tsx
|
|
10
|
+
import NextLink from "next/link.js";
|
|
11
|
+
import { usePathname, useRouter, useSearchParams } from "next/navigation.js";
|
|
12
|
+
import { Suspense, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
13
|
+
|
|
14
|
+
// src/next/sync-client.ts
|
|
15
|
+
var THROTTLED_RETRY_MS = 5100;
|
|
16
|
+
var MAX_RETRY_MS = 65e3;
|
|
17
|
+
async function syncServerGeneration(path) {
|
|
18
|
+
const ask = async () => {
|
|
19
|
+
try {
|
|
20
|
+
const response = await fetch(path, { method: "POST", cache: "no-store" });
|
|
21
|
+
if (!response.ok) return void 0;
|
|
22
|
+
const answer = await response.json();
|
|
23
|
+
if (typeof answer?.retryAfterMs === "number") return Math.min(Math.max(answer.retryAfterMs, 0) + 100, MAX_RETRY_MS);
|
|
24
|
+
return answer?.throttled === true ? THROTTLED_RETRY_MS : void 0;
|
|
25
|
+
} catch {
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const wait = await ask();
|
|
30
|
+
if (wait !== void 0) {
|
|
31
|
+
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
32
|
+
await ask();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/next/client.tsx
|
|
37
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
38
|
+
var Link = ({ prefetch, ...anchor }) => /* @__PURE__ */ jsx(NextLink, { prefetch, ...anchor });
|
|
39
|
+
function SearchParamsBridge({ seen, onChange }) {
|
|
40
|
+
const query = useSearchParams()?.toString() ?? "";
|
|
41
|
+
seen.current = query;
|
|
42
|
+
useEffect(() => onChange(query), [query, onChange]);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function StorefrontNextProvider(props) {
|
|
46
|
+
const seen = useRef(null);
|
|
47
|
+
const [read, setRead] = useState(null);
|
|
48
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
49
|
+
/* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(SearchParamsBridge, { seen, onChange: setRead }) }),
|
|
50
|
+
/* @__PURE__ */ jsx(NextProviderBody, { ...props, seen, read })
|
|
51
|
+
] });
|
|
52
|
+
}
|
|
53
|
+
function NextProviderBody({
|
|
54
|
+
syncPath = "/api/throttle/sync",
|
|
55
|
+
seen,
|
|
56
|
+
read,
|
|
57
|
+
...props
|
|
58
|
+
}) {
|
|
59
|
+
const next = useRouter();
|
|
60
|
+
const pathname = usePathname();
|
|
61
|
+
const query = seen.current ?? read ?? "";
|
|
62
|
+
const router = useMemo(
|
|
63
|
+
() => ({
|
|
64
|
+
pathname: pathname ?? "/",
|
|
65
|
+
searchParams: new URLSearchParams(query),
|
|
66
|
+
push: (href, options) => next.push(href, options),
|
|
67
|
+
replace: (href, options) => next.replace(href, options)
|
|
68
|
+
}),
|
|
69
|
+
[next, pathname, query]
|
|
70
|
+
);
|
|
71
|
+
const onGenerationChange = useCallback(() => {
|
|
72
|
+
void (async () => {
|
|
73
|
+
if (syncPath !== null) await syncServerGeneration(syncPath);
|
|
74
|
+
next.refresh();
|
|
75
|
+
})();
|
|
76
|
+
}, [next, syncPath]);
|
|
77
|
+
return /* @__PURE__ */ jsx(StorefrontProvider, { ...props, router, linkComponent: Link, onGenerationChange });
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
StorefrontNextProvider,
|
|
81
|
+
syncServerGeneration
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=client.js.map
|