@usethrottle/catalog 1.0.0 → 1.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/CHANGELOG.md +8 -0
- package/README.md +64 -7
- package/dist/admin.cjs +681 -0
- package/dist/admin.d.cts +660 -0
- package/dist/admin.d.ts +660 -0
- package/dist/admin.js +681 -0
- package/dist/{catalog-error-BWUoZCzY.d.ts → catalog-error-C_zLOtYA.d.ts} +3 -3
- package/dist/{catalog-error-DO6ANrGR.d.cts → catalog-error-s1BINNkt.d.cts} +3 -3
- package/dist/{chunk-ZFUELHUU.cjs → chunk-4ORXUW2U.cjs} +4 -2
- package/dist/{chunk-2PJXGAZF.js → chunk-JK2UY4CD.js} +3 -1
- package/dist/{client-BNtBTEyh.d.cts → client-BAoq6jmM.d.cts} +1 -1
- package/dist/{client-CHLvULRQ.d.ts → client-c2F-eCaL.d.ts} +1 -1
- package/dist/{types-DYfIvIaI.d.cts → contract-types-DhiThMEr.d.cts} +1 -272
- package/dist/{types-DYfIvIaI.d.ts → contract-types-DhiThMEr.d.ts} +1 -272
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +1 -1
- package/dist/react.cjs +17 -17
- package/dist/react.d.cts +5 -4
- package/dist/react.d.ts +5 -4
- package/dist/react.js +1 -1
- package/dist/server.cjs +14 -13
- package/dist/server.d.cts +3 -2
- package/dist/server.d.ts +3 -2
- package/dist/server.js +3 -2
- package/dist/types-DsjoG8ce.d.cts +276 -0
- package/dist/types-xQLID-4j.d.ts +276 -0
- package/dist/url.d.cts +1 -0
- package/dist/url.d.ts +1 -0
- package/package.json +11 -1
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { C as CartCheckAnswer, f as CartCreateRequest, e as CartCreateAnswer, a as StorefrontListAnswer, c as StorefrontProductAnswer, p as StorefrontRelatedAnswer, o as StorefrontFilterValuesAnswer, j as StorefrontCategoriesAnswer, k as StorefrontCategoryAnswer, s as StorefrontTagsAnswer, m as StorefrontCollectionsAnswer, l as StorefrontCollectionAnswer, r as StorefrontSuggestAnswer, n as StorefrontConfigAnswer, q as StorefrontReviewsAnswer, R as ReviewEligibilityAnswer, i as ReviewSubmitInput, h as ReviewSubmitAnswer } from './contract-types-DhiThMEr.cjs';
|
|
2
|
+
|
|
3
|
+
type QueryPairs = [string, string][];
|
|
4
|
+
|
|
5
|
+
/** One stored answer for ETag reuse (P6-R13). */
|
|
6
|
+
type CatalogHttpCacheEntry = {
|
|
7
|
+
etag: string;
|
|
8
|
+
body: unknown;
|
|
9
|
+
};
|
|
10
|
+
/** Caller-provided store for ETag reuse; without one nothing is sent (P6-R13). */
|
|
11
|
+
type CatalogHttpCache = {
|
|
12
|
+
get(key: string): CatalogHttpCacheEntry | undefined;
|
|
13
|
+
set(key: string, entry: CatalogHttpCacheEntry): void;
|
|
14
|
+
};
|
|
15
|
+
type CustomerTokenSource = () => string | null | undefined | Promise<string | null | undefined>;
|
|
16
|
+
type CatalogClientOptions = {
|
|
17
|
+
publishableKey: string;
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
fetch?: typeof fetch;
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
currency?: string;
|
|
22
|
+
locale?: string;
|
|
23
|
+
customerToken?: CustomerTokenSource;
|
|
24
|
+
cache?: CatalogHttpCache;
|
|
25
|
+
/** The customer partition of the cache key (P6-R13). */
|
|
26
|
+
cacheScope?: () => string;
|
|
27
|
+
indexingRetry?: false | {
|
|
28
|
+
maxWaitSeconds: number;
|
|
29
|
+
};
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
};
|
|
32
|
+
/** Next.js's `fetch` cache options; the SDK never imports Next. */
|
|
33
|
+
type NextFetchOptions = {
|
|
34
|
+
revalidate?: number | false;
|
|
35
|
+
tags?: string[];
|
|
36
|
+
};
|
|
37
|
+
type CallOptions = {
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
timeoutMs?: number;
|
|
40
|
+
currency?: string;
|
|
41
|
+
locale?: string;
|
|
42
|
+
/** Extra `fetch` init keys (for example Next's `next`); never overrides the request. */
|
|
43
|
+
fetchInit?: Record<string, unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* Sent as the `fetch` init's `next` (over `fetchInit.next`). The server
|
|
46
|
+
* client adds one to every cacheable GET (P6-R17); a plain client passes it
|
|
47
|
+
* through. A request that carries a customer token drops it and is sent
|
|
48
|
+
* `cache: 'no-store'`.
|
|
49
|
+
*/
|
|
50
|
+
next?: NextFetchOptions;
|
|
51
|
+
};
|
|
52
|
+
type RequestSpec = {
|
|
53
|
+
method: 'GET' | 'POST';
|
|
54
|
+
/** Already encoded, starting with `/`. */
|
|
55
|
+
path: string;
|
|
56
|
+
query?: QueryPairs;
|
|
57
|
+
body?: unknown;
|
|
58
|
+
/** `'optional'` and `'required'` both send a token when there is one; `tokenFallback` decides a `401`. */
|
|
59
|
+
customerToken: 'none' | 'optional' | 'required';
|
|
60
|
+
tokenFallback: 'anonymous' | 'throw';
|
|
61
|
+
/** The endpoint never answers a resource `404` (P6-R8 (b)). */
|
|
62
|
+
featureRoute: boolean;
|
|
63
|
+
idempotencyKey?: string;
|
|
64
|
+
/** `false` turns off the one indexing retry for this request (P6-R10). */
|
|
65
|
+
indexingRetry?: boolean;
|
|
66
|
+
ifNoneMatch?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Query context the transport appends to a GET: `'priced'` adds `currency`
|
|
69
|
+
* and `locale`, `'locale'` adds `locale` only (call options over client
|
|
70
|
+
* options). A POST takes them in its body, from `context()`.
|
|
71
|
+
*/
|
|
72
|
+
context?: 'priced' | 'locale';
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** A list sort the catalog knows. */
|
|
76
|
+
type StorefrontSort = StorefrontListAnswer['sort'];
|
|
77
|
+
/** An old handle's answer: where the resource lives now. */
|
|
78
|
+
type Redirect = {
|
|
79
|
+
redirectTo: string;
|
|
80
|
+
};
|
|
81
|
+
/** `fields`: `lite` (the list default), `full`, or top-level product keys. */
|
|
82
|
+
type FieldsOption = 'lite' | 'full' | readonly string[];
|
|
83
|
+
/** The `/products` (and `/filters/:key/values`) selection. */
|
|
84
|
+
type ProductsQuery = {
|
|
85
|
+
q?: string;
|
|
86
|
+
category?: string;
|
|
87
|
+
collection?: string;
|
|
88
|
+
/** Sent as repeated `tag`. */
|
|
89
|
+
tags?: string[];
|
|
90
|
+
featured?: boolean;
|
|
91
|
+
/** `filter.<key>`, one parameter per value; a range is one `min..max` value. */
|
|
92
|
+
filters?: Record<string, string | readonly string[]>;
|
|
93
|
+
handles?: string[];
|
|
94
|
+
skus?: string[];
|
|
95
|
+
vehicle?: {
|
|
96
|
+
year?: number;
|
|
97
|
+
make: string;
|
|
98
|
+
model: string;
|
|
99
|
+
submodel?: string;
|
|
100
|
+
engine?: string;
|
|
101
|
+
};
|
|
102
|
+
sort?: StorefrontSort | (string & {});
|
|
103
|
+
limit?: number;
|
|
104
|
+
page?: number;
|
|
105
|
+
cursor?: string;
|
|
106
|
+
/** `true` for every filter, or filter keys (repeated). */
|
|
107
|
+
facets?: boolean | readonly string[];
|
|
108
|
+
/** Comma-joined on the wire. */
|
|
109
|
+
fields?: FieldsOption;
|
|
110
|
+
/** Comma-joined on the wire. */
|
|
111
|
+
include?: readonly string[];
|
|
112
|
+
};
|
|
113
|
+
/** A line of a Throttle cart. */
|
|
114
|
+
type ThrottleLine = {
|
|
115
|
+
id: string;
|
|
116
|
+
referenceId: string | null;
|
|
117
|
+
name: string;
|
|
118
|
+
quantity: number;
|
|
119
|
+
unitPrice: number;
|
|
120
|
+
imageUrl: string | null;
|
|
121
|
+
resolution?: {
|
|
122
|
+
status: 'resolved' | 'refused' | 'stale';
|
|
123
|
+
code: string | null;
|
|
124
|
+
maxQuantity: number | null;
|
|
125
|
+
} | null;
|
|
126
|
+
};
|
|
127
|
+
/** Throttle's cart as a cart session answers it; other keys pass through. */
|
|
128
|
+
type ThrottleCart = {
|
|
129
|
+
cartId: string;
|
|
130
|
+
currency: string;
|
|
131
|
+
subtotal: number;
|
|
132
|
+
total: number;
|
|
133
|
+
unitCount: number;
|
|
134
|
+
lineItems?: ThrottleLine[];
|
|
135
|
+
lineResolver?: {
|
|
136
|
+
extensionId: string | null;
|
|
137
|
+
};
|
|
138
|
+
} & {
|
|
139
|
+
[key: string]: unknown;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* A cart session answer, `data` unwrapped. Throttle sends `status` and
|
|
143
|
+
* `expiresAt` on `get()` only; the mutations answer `{ cartSessionId, cart }`
|
|
144
|
+
* and `refresh()` adds `changed`.
|
|
145
|
+
*/
|
|
146
|
+
type CartSessionSnapshot = {
|
|
147
|
+
cartSessionId: string;
|
|
148
|
+
status?: string;
|
|
149
|
+
expiresAt?: string;
|
|
150
|
+
cart: ThrottleCart;
|
|
151
|
+
changed?: boolean;
|
|
152
|
+
};
|
|
153
|
+
/** The store's look, as Throttle answers it on a cart-session read. */
|
|
154
|
+
type CartSessionBranding = {
|
|
155
|
+
logoUrl: string | null;
|
|
156
|
+
primaryColor: string | null;
|
|
157
|
+
merchantName: string | null;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* What `CartSession.get()` answers: the snapshot plus the fields only the
|
|
161
|
+
* read carries. `metadata` is the session's own write-once metadata (the
|
|
162
|
+
* buyer's return, cancel and storefront URLs among it), so its keys are the
|
|
163
|
+
* caller's.
|
|
164
|
+
*/
|
|
165
|
+
type CartSessionDetail = CartSessionSnapshot & {
|
|
166
|
+
status: string;
|
|
167
|
+
expiresAt: string;
|
|
168
|
+
/** Throttle sends both today; an older deployment may omit them. */
|
|
169
|
+
branding?: CartSessionBranding;
|
|
170
|
+
metadata?: Record<string, unknown>;
|
|
171
|
+
};
|
|
172
|
+
type CartCheckoutInput = {
|
|
173
|
+
/** Absolute `http:` or `https:` URL; anything else is refused before a request. */
|
|
174
|
+
returnUrl: string;
|
|
175
|
+
/** Absolute `http:` or `https:` URL; anything else is refused before a request. */
|
|
176
|
+
cancelUrl: string;
|
|
177
|
+
customerEmail?: string;
|
|
178
|
+
keepOpen?: boolean;
|
|
179
|
+
};
|
|
180
|
+
type CartCheckout = {
|
|
181
|
+
checkoutUrl: string;
|
|
182
|
+
checkoutSessionId: string;
|
|
183
|
+
expiresAt: string;
|
|
184
|
+
};
|
|
185
|
+
/** Per-call options of a cart-session call. */
|
|
186
|
+
type SessionCallOptions = Pick<CallOptions, 'signal' | 'timeoutMs'>;
|
|
187
|
+
/** One Throttle cart session, addressed by its opaque id. */
|
|
188
|
+
type CartSession = {
|
|
189
|
+
readonly id: string;
|
|
190
|
+
get(call?: SessionCallOptions): Promise<CartSessionDetail>;
|
|
191
|
+
add(input: {
|
|
192
|
+
sku: string;
|
|
193
|
+
quantity?: number;
|
|
194
|
+
metadata?: Record<string, unknown>;
|
|
195
|
+
}, call?: SessionCallOptions): Promise<CartSessionSnapshot>;
|
|
196
|
+
update(lineId: string, quantity: number, call?: SessionCallOptions): Promise<CartSessionSnapshot>;
|
|
197
|
+
remove(lineId: string, call?: SessionCallOptions): Promise<CartSessionSnapshot>;
|
|
198
|
+
refresh(call?: SessionCallOptions): Promise<CartSessionSnapshot>;
|
|
199
|
+
/** Refuses non-http(s) URLs before a request, and never returns a non-http(s) `checkoutUrl`. */
|
|
200
|
+
checkout(input: CartCheckoutInput, call?: SessionCallOptions): Promise<CartCheckout>;
|
|
201
|
+
};
|
|
202
|
+
type ProductsNamespace = {
|
|
203
|
+
list(query?: ProductsQuery, call?: CallOptions): Promise<StorefrontListAnswer>;
|
|
204
|
+
/** Always the full product (`fields=full`, P6-R18), or a redirect. */
|
|
205
|
+
get(handle: string, opts?: {
|
|
206
|
+
include?: readonly string[];
|
|
207
|
+
} & CallOptions): Promise<StorefrontProductAnswer | Redirect>;
|
|
208
|
+
related(handle: string, opts?: {
|
|
209
|
+
limit?: number;
|
|
210
|
+
fields?: FieldsOption;
|
|
211
|
+
} & CallOptions): Promise<StorefrontRelatedAnswer>;
|
|
212
|
+
};
|
|
213
|
+
type FiltersNamespace = {
|
|
214
|
+
values(key: string, query?: ProductsQuery, call?: CallOptions): Promise<StorefrontFilterValuesAnswer>;
|
|
215
|
+
};
|
|
216
|
+
/** How many levels of the category tree to ask for (the storefront's limit is 10). */
|
|
217
|
+
type CategoryTreeDepth = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
218
|
+
type CategoriesNamespace = {
|
|
219
|
+
tree(opts?: {
|
|
220
|
+
depth?: CategoryTreeDepth;
|
|
221
|
+
} & CallOptions): Promise<StorefrontCategoriesAnswer>;
|
|
222
|
+
get(handle: string, call?: CallOptions): Promise<StorefrontCategoryAnswer>;
|
|
223
|
+
};
|
|
224
|
+
type TagsNamespace = {
|
|
225
|
+
list(opts?: {
|
|
226
|
+
q?: string;
|
|
227
|
+
limit?: number;
|
|
228
|
+
} & CallOptions): Promise<StorefrontTagsAnswer>;
|
|
229
|
+
};
|
|
230
|
+
type CollectionsNamespace = {
|
|
231
|
+
list(opts?: {
|
|
232
|
+
limit?: number;
|
|
233
|
+
cursor?: string;
|
|
234
|
+
} & CallOptions): Promise<StorefrontCollectionsAnswer>;
|
|
235
|
+
get(handle: string, call?: CallOptions): Promise<StorefrontCollectionAnswer>;
|
|
236
|
+
};
|
|
237
|
+
type ReviewsNamespace = {
|
|
238
|
+
list(handle: string, opts?: {
|
|
239
|
+
sort?: 'newest' | 'highest' | 'lowest';
|
|
240
|
+
rating?: 1 | 2 | 3 | 4 | 5;
|
|
241
|
+
limit?: number;
|
|
242
|
+
cursor?: string;
|
|
243
|
+
} & CallOptions): Promise<StorefrontReviewsAnswer>;
|
|
244
|
+
eligibility(handle: string, call?: CallOptions): Promise<ReviewEligibilityAnswer>;
|
|
245
|
+
submit(handle: string, input: ReviewSubmitInput, opts?: {
|
|
246
|
+
idempotencyKey?: string;
|
|
247
|
+
} & CallOptions): Promise<ReviewSubmitAnswer>;
|
|
248
|
+
};
|
|
249
|
+
type CartsNamespace = {
|
|
250
|
+
check(items: {
|
|
251
|
+
sku: string;
|
|
252
|
+
quantity: number;
|
|
253
|
+
}[], opts?: CallOptions): Promise<CartCheckAnswer>;
|
|
254
|
+
create(input: CartCreateRequest, opts?: {
|
|
255
|
+
idempotencyKey?: string;
|
|
256
|
+
} & CallOptions): Promise<CartCreateAnswer>;
|
|
257
|
+
/** Throttle's cart-session routes; no catalog key and no customer token are sent. */
|
|
258
|
+
session(sessionId: string, opts?: {
|
|
259
|
+
throttleBaseUrl?: string;
|
|
260
|
+
}): CartSession;
|
|
261
|
+
};
|
|
262
|
+
type CatalogNamespaces = {
|
|
263
|
+
readonly products: ProductsNamespace;
|
|
264
|
+
readonly filters: FiltersNamespace;
|
|
265
|
+
readonly categories: CategoriesNamespace;
|
|
266
|
+
readonly tags: TagsNamespace;
|
|
267
|
+
readonly collections: CollectionsNamespace;
|
|
268
|
+
readonly suggest: (q: string, opts?: {
|
|
269
|
+
limit?: number;
|
|
270
|
+
} & CallOptions) => Promise<StorefrontSuggestAnswer>;
|
|
271
|
+
readonly config: (call?: CallOptions) => Promise<StorefrontConfigAnswer>;
|
|
272
|
+
readonly reviews: ReviewsNamespace;
|
|
273
|
+
readonly carts: CartsNamespace;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
export type { CallOptions as C, FieldsOption as F, NextFetchOptions as N, ProductsNamespace as P, Redirect as R, SessionCallOptions as S, TagsNamespace as T, CartCheckout as a, CartCheckoutInput as b, CartSession as c, CartSessionBranding as d, CartSessionDetail as e, CartSessionSnapshot as f, CartsNamespace as g, CatalogClientOptions as h, CatalogHttpCache as i, CatalogHttpCacheEntry as j, CatalogNamespaces as k, CategoriesNamespace as l, CategoryTreeDepth as m, CollectionsNamespace as n, CustomerTokenSource as o, FiltersNamespace as p, ProductsQuery as q, ReviewsNamespace as r, StorefrontSort as s, ThrottleCart as t, ThrottleLine as u, RequestSpec as v };
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { C as CartCheckAnswer, f as CartCreateRequest, e as CartCreateAnswer, a as StorefrontListAnswer, c as StorefrontProductAnswer, p as StorefrontRelatedAnswer, o as StorefrontFilterValuesAnswer, j as StorefrontCategoriesAnswer, k as StorefrontCategoryAnswer, s as StorefrontTagsAnswer, m as StorefrontCollectionsAnswer, l as StorefrontCollectionAnswer, r as StorefrontSuggestAnswer, n as StorefrontConfigAnswer, q as StorefrontReviewsAnswer, R as ReviewEligibilityAnswer, i as ReviewSubmitInput, h as ReviewSubmitAnswer } from './contract-types-DhiThMEr.js';
|
|
2
|
+
|
|
3
|
+
type QueryPairs = [string, string][];
|
|
4
|
+
|
|
5
|
+
/** One stored answer for ETag reuse (P6-R13). */
|
|
6
|
+
type CatalogHttpCacheEntry = {
|
|
7
|
+
etag: string;
|
|
8
|
+
body: unknown;
|
|
9
|
+
};
|
|
10
|
+
/** Caller-provided store for ETag reuse; without one nothing is sent (P6-R13). */
|
|
11
|
+
type CatalogHttpCache = {
|
|
12
|
+
get(key: string): CatalogHttpCacheEntry | undefined;
|
|
13
|
+
set(key: string, entry: CatalogHttpCacheEntry): void;
|
|
14
|
+
};
|
|
15
|
+
type CustomerTokenSource = () => string | null | undefined | Promise<string | null | undefined>;
|
|
16
|
+
type CatalogClientOptions = {
|
|
17
|
+
publishableKey: string;
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
fetch?: typeof fetch;
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
currency?: string;
|
|
22
|
+
locale?: string;
|
|
23
|
+
customerToken?: CustomerTokenSource;
|
|
24
|
+
cache?: CatalogHttpCache;
|
|
25
|
+
/** The customer partition of the cache key (P6-R13). */
|
|
26
|
+
cacheScope?: () => string;
|
|
27
|
+
indexingRetry?: false | {
|
|
28
|
+
maxWaitSeconds: number;
|
|
29
|
+
};
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
};
|
|
32
|
+
/** Next.js's `fetch` cache options; the SDK never imports Next. */
|
|
33
|
+
type NextFetchOptions = {
|
|
34
|
+
revalidate?: number | false;
|
|
35
|
+
tags?: string[];
|
|
36
|
+
};
|
|
37
|
+
type CallOptions = {
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
timeoutMs?: number;
|
|
40
|
+
currency?: string;
|
|
41
|
+
locale?: string;
|
|
42
|
+
/** Extra `fetch` init keys (for example Next's `next`); never overrides the request. */
|
|
43
|
+
fetchInit?: Record<string, unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* Sent as the `fetch` init's `next` (over `fetchInit.next`). The server
|
|
46
|
+
* client adds one to every cacheable GET (P6-R17); a plain client passes it
|
|
47
|
+
* through. A request that carries a customer token drops it and is sent
|
|
48
|
+
* `cache: 'no-store'`.
|
|
49
|
+
*/
|
|
50
|
+
next?: NextFetchOptions;
|
|
51
|
+
};
|
|
52
|
+
type RequestSpec = {
|
|
53
|
+
method: 'GET' | 'POST';
|
|
54
|
+
/** Already encoded, starting with `/`. */
|
|
55
|
+
path: string;
|
|
56
|
+
query?: QueryPairs;
|
|
57
|
+
body?: unknown;
|
|
58
|
+
/** `'optional'` and `'required'` both send a token when there is one; `tokenFallback` decides a `401`. */
|
|
59
|
+
customerToken: 'none' | 'optional' | 'required';
|
|
60
|
+
tokenFallback: 'anonymous' | 'throw';
|
|
61
|
+
/** The endpoint never answers a resource `404` (P6-R8 (b)). */
|
|
62
|
+
featureRoute: boolean;
|
|
63
|
+
idempotencyKey?: string;
|
|
64
|
+
/** `false` turns off the one indexing retry for this request (P6-R10). */
|
|
65
|
+
indexingRetry?: boolean;
|
|
66
|
+
ifNoneMatch?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Query context the transport appends to a GET: `'priced'` adds `currency`
|
|
69
|
+
* and `locale`, `'locale'` adds `locale` only (call options over client
|
|
70
|
+
* options). A POST takes them in its body, from `context()`.
|
|
71
|
+
*/
|
|
72
|
+
context?: 'priced' | 'locale';
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** A list sort the catalog knows. */
|
|
76
|
+
type StorefrontSort = StorefrontListAnswer['sort'];
|
|
77
|
+
/** An old handle's answer: where the resource lives now. */
|
|
78
|
+
type Redirect = {
|
|
79
|
+
redirectTo: string;
|
|
80
|
+
};
|
|
81
|
+
/** `fields`: `lite` (the list default), `full`, or top-level product keys. */
|
|
82
|
+
type FieldsOption = 'lite' | 'full' | readonly string[];
|
|
83
|
+
/** The `/products` (and `/filters/:key/values`) selection. */
|
|
84
|
+
type ProductsQuery = {
|
|
85
|
+
q?: string;
|
|
86
|
+
category?: string;
|
|
87
|
+
collection?: string;
|
|
88
|
+
/** Sent as repeated `tag`. */
|
|
89
|
+
tags?: string[];
|
|
90
|
+
featured?: boolean;
|
|
91
|
+
/** `filter.<key>`, one parameter per value; a range is one `min..max` value. */
|
|
92
|
+
filters?: Record<string, string | readonly string[]>;
|
|
93
|
+
handles?: string[];
|
|
94
|
+
skus?: string[];
|
|
95
|
+
vehicle?: {
|
|
96
|
+
year?: number;
|
|
97
|
+
make: string;
|
|
98
|
+
model: string;
|
|
99
|
+
submodel?: string;
|
|
100
|
+
engine?: string;
|
|
101
|
+
};
|
|
102
|
+
sort?: StorefrontSort | (string & {});
|
|
103
|
+
limit?: number;
|
|
104
|
+
page?: number;
|
|
105
|
+
cursor?: string;
|
|
106
|
+
/** `true` for every filter, or filter keys (repeated). */
|
|
107
|
+
facets?: boolean | readonly string[];
|
|
108
|
+
/** Comma-joined on the wire. */
|
|
109
|
+
fields?: FieldsOption;
|
|
110
|
+
/** Comma-joined on the wire. */
|
|
111
|
+
include?: readonly string[];
|
|
112
|
+
};
|
|
113
|
+
/** A line of a Throttle cart. */
|
|
114
|
+
type ThrottleLine = {
|
|
115
|
+
id: string;
|
|
116
|
+
referenceId: string | null;
|
|
117
|
+
name: string;
|
|
118
|
+
quantity: number;
|
|
119
|
+
unitPrice: number;
|
|
120
|
+
imageUrl: string | null;
|
|
121
|
+
resolution?: {
|
|
122
|
+
status: 'resolved' | 'refused' | 'stale';
|
|
123
|
+
code: string | null;
|
|
124
|
+
maxQuantity: number | null;
|
|
125
|
+
} | null;
|
|
126
|
+
};
|
|
127
|
+
/** Throttle's cart as a cart session answers it; other keys pass through. */
|
|
128
|
+
type ThrottleCart = {
|
|
129
|
+
cartId: string;
|
|
130
|
+
currency: string;
|
|
131
|
+
subtotal: number;
|
|
132
|
+
total: number;
|
|
133
|
+
unitCount: number;
|
|
134
|
+
lineItems?: ThrottleLine[];
|
|
135
|
+
lineResolver?: {
|
|
136
|
+
extensionId: string | null;
|
|
137
|
+
};
|
|
138
|
+
} & {
|
|
139
|
+
[key: string]: unknown;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* A cart session answer, `data` unwrapped. Throttle sends `status` and
|
|
143
|
+
* `expiresAt` on `get()` only; the mutations answer `{ cartSessionId, cart }`
|
|
144
|
+
* and `refresh()` adds `changed`.
|
|
145
|
+
*/
|
|
146
|
+
type CartSessionSnapshot = {
|
|
147
|
+
cartSessionId: string;
|
|
148
|
+
status?: string;
|
|
149
|
+
expiresAt?: string;
|
|
150
|
+
cart: ThrottleCart;
|
|
151
|
+
changed?: boolean;
|
|
152
|
+
};
|
|
153
|
+
/** The store's look, as Throttle answers it on a cart-session read. */
|
|
154
|
+
type CartSessionBranding = {
|
|
155
|
+
logoUrl: string | null;
|
|
156
|
+
primaryColor: string | null;
|
|
157
|
+
merchantName: string | null;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* What `CartSession.get()` answers: the snapshot plus the fields only the
|
|
161
|
+
* read carries. `metadata` is the session's own write-once metadata (the
|
|
162
|
+
* buyer's return, cancel and storefront URLs among it), so its keys are the
|
|
163
|
+
* caller's.
|
|
164
|
+
*/
|
|
165
|
+
type CartSessionDetail = CartSessionSnapshot & {
|
|
166
|
+
status: string;
|
|
167
|
+
expiresAt: string;
|
|
168
|
+
/** Throttle sends both today; an older deployment may omit them. */
|
|
169
|
+
branding?: CartSessionBranding;
|
|
170
|
+
metadata?: Record<string, unknown>;
|
|
171
|
+
};
|
|
172
|
+
type CartCheckoutInput = {
|
|
173
|
+
/** Absolute `http:` or `https:` URL; anything else is refused before a request. */
|
|
174
|
+
returnUrl: string;
|
|
175
|
+
/** Absolute `http:` or `https:` URL; anything else is refused before a request. */
|
|
176
|
+
cancelUrl: string;
|
|
177
|
+
customerEmail?: string;
|
|
178
|
+
keepOpen?: boolean;
|
|
179
|
+
};
|
|
180
|
+
type CartCheckout = {
|
|
181
|
+
checkoutUrl: string;
|
|
182
|
+
checkoutSessionId: string;
|
|
183
|
+
expiresAt: string;
|
|
184
|
+
};
|
|
185
|
+
/** Per-call options of a cart-session call. */
|
|
186
|
+
type SessionCallOptions = Pick<CallOptions, 'signal' | 'timeoutMs'>;
|
|
187
|
+
/** One Throttle cart session, addressed by its opaque id. */
|
|
188
|
+
type CartSession = {
|
|
189
|
+
readonly id: string;
|
|
190
|
+
get(call?: SessionCallOptions): Promise<CartSessionDetail>;
|
|
191
|
+
add(input: {
|
|
192
|
+
sku: string;
|
|
193
|
+
quantity?: number;
|
|
194
|
+
metadata?: Record<string, unknown>;
|
|
195
|
+
}, call?: SessionCallOptions): Promise<CartSessionSnapshot>;
|
|
196
|
+
update(lineId: string, quantity: number, call?: SessionCallOptions): Promise<CartSessionSnapshot>;
|
|
197
|
+
remove(lineId: string, call?: SessionCallOptions): Promise<CartSessionSnapshot>;
|
|
198
|
+
refresh(call?: SessionCallOptions): Promise<CartSessionSnapshot>;
|
|
199
|
+
/** Refuses non-http(s) URLs before a request, and never returns a non-http(s) `checkoutUrl`. */
|
|
200
|
+
checkout(input: CartCheckoutInput, call?: SessionCallOptions): Promise<CartCheckout>;
|
|
201
|
+
};
|
|
202
|
+
type ProductsNamespace = {
|
|
203
|
+
list(query?: ProductsQuery, call?: CallOptions): Promise<StorefrontListAnswer>;
|
|
204
|
+
/** Always the full product (`fields=full`, P6-R18), or a redirect. */
|
|
205
|
+
get(handle: string, opts?: {
|
|
206
|
+
include?: readonly string[];
|
|
207
|
+
} & CallOptions): Promise<StorefrontProductAnswer | Redirect>;
|
|
208
|
+
related(handle: string, opts?: {
|
|
209
|
+
limit?: number;
|
|
210
|
+
fields?: FieldsOption;
|
|
211
|
+
} & CallOptions): Promise<StorefrontRelatedAnswer>;
|
|
212
|
+
};
|
|
213
|
+
type FiltersNamespace = {
|
|
214
|
+
values(key: string, query?: ProductsQuery, call?: CallOptions): Promise<StorefrontFilterValuesAnswer>;
|
|
215
|
+
};
|
|
216
|
+
/** How many levels of the category tree to ask for (the storefront's limit is 10). */
|
|
217
|
+
type CategoryTreeDepth = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
218
|
+
type CategoriesNamespace = {
|
|
219
|
+
tree(opts?: {
|
|
220
|
+
depth?: CategoryTreeDepth;
|
|
221
|
+
} & CallOptions): Promise<StorefrontCategoriesAnswer>;
|
|
222
|
+
get(handle: string, call?: CallOptions): Promise<StorefrontCategoryAnswer>;
|
|
223
|
+
};
|
|
224
|
+
type TagsNamespace = {
|
|
225
|
+
list(opts?: {
|
|
226
|
+
q?: string;
|
|
227
|
+
limit?: number;
|
|
228
|
+
} & CallOptions): Promise<StorefrontTagsAnswer>;
|
|
229
|
+
};
|
|
230
|
+
type CollectionsNamespace = {
|
|
231
|
+
list(opts?: {
|
|
232
|
+
limit?: number;
|
|
233
|
+
cursor?: string;
|
|
234
|
+
} & CallOptions): Promise<StorefrontCollectionsAnswer>;
|
|
235
|
+
get(handle: string, call?: CallOptions): Promise<StorefrontCollectionAnswer>;
|
|
236
|
+
};
|
|
237
|
+
type ReviewsNamespace = {
|
|
238
|
+
list(handle: string, opts?: {
|
|
239
|
+
sort?: 'newest' | 'highest' | 'lowest';
|
|
240
|
+
rating?: 1 | 2 | 3 | 4 | 5;
|
|
241
|
+
limit?: number;
|
|
242
|
+
cursor?: string;
|
|
243
|
+
} & CallOptions): Promise<StorefrontReviewsAnswer>;
|
|
244
|
+
eligibility(handle: string, call?: CallOptions): Promise<ReviewEligibilityAnswer>;
|
|
245
|
+
submit(handle: string, input: ReviewSubmitInput, opts?: {
|
|
246
|
+
idempotencyKey?: string;
|
|
247
|
+
} & CallOptions): Promise<ReviewSubmitAnswer>;
|
|
248
|
+
};
|
|
249
|
+
type CartsNamespace = {
|
|
250
|
+
check(items: {
|
|
251
|
+
sku: string;
|
|
252
|
+
quantity: number;
|
|
253
|
+
}[], opts?: CallOptions): Promise<CartCheckAnswer>;
|
|
254
|
+
create(input: CartCreateRequest, opts?: {
|
|
255
|
+
idempotencyKey?: string;
|
|
256
|
+
} & CallOptions): Promise<CartCreateAnswer>;
|
|
257
|
+
/** Throttle's cart-session routes; no catalog key and no customer token are sent. */
|
|
258
|
+
session(sessionId: string, opts?: {
|
|
259
|
+
throttleBaseUrl?: string;
|
|
260
|
+
}): CartSession;
|
|
261
|
+
};
|
|
262
|
+
type CatalogNamespaces = {
|
|
263
|
+
readonly products: ProductsNamespace;
|
|
264
|
+
readonly filters: FiltersNamespace;
|
|
265
|
+
readonly categories: CategoriesNamespace;
|
|
266
|
+
readonly tags: TagsNamespace;
|
|
267
|
+
readonly collections: CollectionsNamespace;
|
|
268
|
+
readonly suggest: (q: string, opts?: {
|
|
269
|
+
limit?: number;
|
|
270
|
+
} & CallOptions) => Promise<StorefrontSuggestAnswer>;
|
|
271
|
+
readonly config: (call?: CallOptions) => Promise<StorefrontConfigAnswer>;
|
|
272
|
+
readonly reviews: ReviewsNamespace;
|
|
273
|
+
readonly carts: CartsNamespace;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
export type { CallOptions as C, FieldsOption as F, NextFetchOptions as N, ProductsNamespace as P, Redirect as R, SessionCallOptions as S, TagsNamespace as T, CartCheckout as a, CartCheckoutInput as b, CartSession as c, CartSessionBranding as d, CartSessionDetail as e, CartSessionSnapshot as f, CartsNamespace as g, CatalogClientOptions as h, CatalogHttpCache as i, CatalogHttpCacheEntry as j, CatalogNamespaces as k, CategoriesNamespace as l, CategoryTreeDepth as m, CollectionsNamespace as n, CustomerTokenSource as o, FiltersNamespace as p, ProductsQuery as q, ReviewsNamespace as r, StorefrontSort as s, ThrottleCart as t, ThrottleLine as u, RequestSpec as v };
|
package/dist/url.d.cts
CHANGED
package/dist/url.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/catalog",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Storefront SDK for the Throttle Product Catalog: a typed client, React hooks, server helpers and URL helpers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -56,6 +56,16 @@
|
|
|
56
56
|
"default": "./dist/url.cjs"
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
|
+
"./admin": {
|
|
60
|
+
"import": {
|
|
61
|
+
"types": "./dist/admin.d.ts",
|
|
62
|
+
"default": "./dist/admin.js"
|
|
63
|
+
},
|
|
64
|
+
"require": {
|
|
65
|
+
"types": "./dist/admin.d.cts",
|
|
66
|
+
"default": "./dist/admin.cjs"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
59
69
|
"./package.json": "./package.json"
|
|
60
70
|
},
|
|
61
71
|
"files": [
|