@commerce-blocks/sdk 1.0.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/LICENSE +21 -0
- package/README.md +816 -0
- package/dist/index.d.ts +1009 -0
- package/dist/index.js +2075 -0
- package/package.json +63 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1009 @@
|
|
|
1
|
+
import { batch } from '@preact/signals-core';
|
|
2
|
+
import { computed } from '@preact/signals-core';
|
|
3
|
+
import { effect } from '@preact/signals-core';
|
|
4
|
+
import { ReadonlySignal } from '@preact/signals-core';
|
|
5
|
+
import { Signal } from '@preact/signals-core';
|
|
6
|
+
import { signal } from '@preact/signals-core';
|
|
7
|
+
|
|
8
|
+
export declare function and(...expressions: (FilterExpression | FilterGroup)[]): FilterGroup;
|
|
9
|
+
|
|
10
|
+
export declare interface ApiError {
|
|
11
|
+
readonly _tag: 'ApiError';
|
|
12
|
+
readonly code: ApiErrorCode;
|
|
13
|
+
readonly source: ApiSource;
|
|
14
|
+
readonly message: string;
|
|
15
|
+
readonly timestamp: string;
|
|
16
|
+
readonly status?: number;
|
|
17
|
+
readonly retryable: boolean;
|
|
18
|
+
readonly retryAfterMs?: number;
|
|
19
|
+
readonly request?: RequestContext;
|
|
20
|
+
readonly response?: ResponseContext;
|
|
21
|
+
readonly cause?: unknown;
|
|
22
|
+
readonly details?: {
|
|
23
|
+
readonly graphqlErrors?: GraphQLErrorDetail[];
|
|
24
|
+
readonly requestId?: string;
|
|
25
|
+
readonly shop?: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare type ApiErrorCode = 'UNAUTHORIZED' | 'FORBIDDEN' | 'NOT_FOUND' | 'RATE_LIMITED' | 'SERVICE_UNAVAILABLE' | 'GRAPHQL_ERROR' | 'PARSE_ERROR' | 'UNKNOWN';
|
|
30
|
+
|
|
31
|
+
declare type ApiSource = 'layers' | 'shopify';
|
|
32
|
+
|
|
33
|
+
export declare interface AutocompleteController {
|
|
34
|
+
execute: (query: string) => void;
|
|
35
|
+
state: ReadonlySignal<QueryState<PredictiveSearchResponse>>;
|
|
36
|
+
dispose: () => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export declare interface AutocompleteOptions {
|
|
40
|
+
debounceMs?: number;
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare interface BaseProduct {
|
|
45
|
+
id: ID;
|
|
46
|
+
gid: ProductGID;
|
|
47
|
+
numericId: number;
|
|
48
|
+
title: string;
|
|
49
|
+
handle: string;
|
|
50
|
+
type: string;
|
|
51
|
+
vendor: string;
|
|
52
|
+
description: string;
|
|
53
|
+
availableForSale: boolean;
|
|
54
|
+
images: Image_2[];
|
|
55
|
+
priceRange: {
|
|
56
|
+
min: Price;
|
|
57
|
+
max: Price;
|
|
58
|
+
};
|
|
59
|
+
compareAtPriceRange?: {
|
|
60
|
+
min: Price;
|
|
61
|
+
max: Price;
|
|
62
|
+
};
|
|
63
|
+
options: RichProductOption[];
|
|
64
|
+
tags: string[];
|
|
65
|
+
variants: ProductVariant[];
|
|
66
|
+
selectedOptions: ProductOption[];
|
|
67
|
+
metafields: Record<string, Record<string, unknown>> | unknown[];
|
|
68
|
+
calculated?: Record<string, unknown>;
|
|
69
|
+
isGiftCard: boolean;
|
|
70
|
+
onlineStoreUrl: string | null;
|
|
71
|
+
totalInventory: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { batch }
|
|
75
|
+
|
|
76
|
+
declare interface BlocksContext {
|
|
77
|
+
productsInCart?: {
|
|
78
|
+
productId: string;
|
|
79
|
+
variantId?: string;
|
|
80
|
+
quantity?: number;
|
|
81
|
+
}[];
|
|
82
|
+
geo?: {
|
|
83
|
+
country?: string;
|
|
84
|
+
province?: string;
|
|
85
|
+
city?: string;
|
|
86
|
+
};
|
|
87
|
+
custom?: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export declare interface BlocksController<P extends Product = Product> {
|
|
91
|
+
state: ReadonlySignal<QueryState<BlocksResult<P>>>;
|
|
92
|
+
execute: (query?: BlocksExecuteQuery) => Promise<Result<BlocksResult<P>, SdkError>>;
|
|
93
|
+
dispose: () => void;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export declare interface BlocksExecuteQuery {
|
|
97
|
+
page?: number;
|
|
98
|
+
limit?: number;
|
|
99
|
+
filters?: unknown;
|
|
100
|
+
signal?: AbortSignal;
|
|
101
|
+
discountEntitlements?: DiscountEntitlement[];
|
|
102
|
+
context?: BlocksContext;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export declare type BlocksExtender<P extends Product = Product> = (result: BlocksResult<P>, raw: LayersResponse & {
|
|
106
|
+
block?: BlocksInfo;
|
|
107
|
+
}) => BlocksResult<P>;
|
|
108
|
+
|
|
109
|
+
declare interface BlocksInfo {
|
|
110
|
+
id: string;
|
|
111
|
+
title: string;
|
|
112
|
+
anchor_type: 'product' | 'collection' | 'cart' | 'none';
|
|
113
|
+
strategy_type: 'interaction' | 'similar_products' | 'manual';
|
|
114
|
+
strategy_key: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export declare interface BlocksOptions {
|
|
118
|
+
blockId: string;
|
|
119
|
+
anchorId?: string;
|
|
120
|
+
anchorHandle?: string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export declare interface BlocksResult<P extends Product = Product> extends LayersPagination {
|
|
124
|
+
products: P[];
|
|
125
|
+
facets: Record<string, Record<string, number>>;
|
|
126
|
+
_meta?: LayersMeta;
|
|
127
|
+
block?: BlocksInfo;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export declare interface CollectionController<P extends Product = Product> {
|
|
131
|
+
state: ReadonlySignal<QueryState<CollectionResult<P>>>;
|
|
132
|
+
execute: (query?: CollectionExecuteQuery) => Promise<Result<CollectionResult<P>, SdkError>>;
|
|
133
|
+
dispose: () => void;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export declare interface CollectionExecuteQuery {
|
|
137
|
+
page?: number;
|
|
138
|
+
limit?: number;
|
|
139
|
+
filters?: unknown;
|
|
140
|
+
sortOrderCode?: string;
|
|
141
|
+
signal?: AbortSignal;
|
|
142
|
+
includeMeta?: boolean;
|
|
143
|
+
collectionMetafields?: {
|
|
144
|
+
namespace: string;
|
|
145
|
+
key: string;
|
|
146
|
+
}[];
|
|
147
|
+
includeFilters?: boolean;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export declare type CollectionExtender<P extends Product = Product> = (result: CollectionResult<P>, raw: LayersResponse) => CollectionResult<P>;
|
|
151
|
+
|
|
152
|
+
declare interface CollectionMeta {
|
|
153
|
+
handle: string;
|
|
154
|
+
title?: string;
|
|
155
|
+
description?: string;
|
|
156
|
+
descriptionHtml?: string;
|
|
157
|
+
image?: {
|
|
158
|
+
url: string;
|
|
159
|
+
alt?: string;
|
|
160
|
+
width?: number;
|
|
161
|
+
height?: number;
|
|
162
|
+
};
|
|
163
|
+
metafields?: (MetafieldResult_2 | null)[];
|
|
164
|
+
totalProducts: number;
|
|
165
|
+
totalPages: number;
|
|
166
|
+
lastPageFetched: number;
|
|
167
|
+
facets?: Record<string, Record<string, number>>;
|
|
168
|
+
lastFetched: number;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export declare interface CollectionOptions {
|
|
172
|
+
handle: string;
|
|
173
|
+
defaultSort?: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export declare interface CollectionResult<P extends Product = Product> extends LayersPagination {
|
|
177
|
+
products: P[];
|
|
178
|
+
facets: Record<string, Record<string, number>>;
|
|
179
|
+
_meta?: LayersMeta;
|
|
180
|
+
collection?: ShopifyCollection;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
declare type CommerceBlocksID = `${CommerceBlocksType}-${OptionSegment}` | `${CommerceBlocksType}-${OptionSegment}-${OptionSegment}` | `${CommerceBlocksType}-${OptionSegment}-${OptionSegment}-${OptionSegment}`;
|
|
184
|
+
|
|
185
|
+
declare type CommerceBlocksType = 'Product' | 'ProductVariant';
|
|
186
|
+
|
|
187
|
+
export { computed }
|
|
188
|
+
|
|
189
|
+
export declare interface ConfigError {
|
|
190
|
+
readonly _tag: 'ConfigError';
|
|
191
|
+
readonly code: ConfigErrorCode;
|
|
192
|
+
readonly message: string;
|
|
193
|
+
readonly timestamp: string;
|
|
194
|
+
readonly field: string;
|
|
195
|
+
readonly value?: unknown;
|
|
196
|
+
readonly expected?: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
declare type ConfigErrorCode = 'MISSING_CONFIG' | 'INVALID_CONFIG';
|
|
200
|
+
|
|
201
|
+
export declare function createSdk<P extends Product = Product>(config: SdkConfig<P>): Result<Sdk<P>, ConfigError>;
|
|
202
|
+
|
|
203
|
+
declare type CustomFetch = (url: string, init?: RequestInit) => Promise<Response>;
|
|
204
|
+
|
|
205
|
+
declare interface DiscountEntitlement {
|
|
206
|
+
entitled: {
|
|
207
|
+
all?: boolean;
|
|
208
|
+
products?: string[];
|
|
209
|
+
variants?: (string | number)[];
|
|
210
|
+
collections?: string[];
|
|
211
|
+
};
|
|
212
|
+
discount: {
|
|
213
|
+
type: 'PERCENTAGE' | 'FIXED_AMOUNT';
|
|
214
|
+
value: number;
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export { effect }
|
|
219
|
+
|
|
220
|
+
declare interface Entry<T> {
|
|
221
|
+
data: T;
|
|
222
|
+
timestamp: number;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export declare function eq(property: string, value: FilterValue): FilterExpression;
|
|
226
|
+
|
|
227
|
+
export declare function exists(property: string): FilterExpression;
|
|
228
|
+
|
|
229
|
+
declare interface FeaturedMedia {
|
|
230
|
+
mediaContentType?: string;
|
|
231
|
+
alt: string;
|
|
232
|
+
src: string;
|
|
233
|
+
width: number;
|
|
234
|
+
height: number;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export declare function filter(expression: FilterExpression | FilterGroup): FilterGroupParam;
|
|
238
|
+
|
|
239
|
+
declare enum FilterConditional {
|
|
240
|
+
And = "AND",
|
|
241
|
+
Or = "OR"
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export declare interface FilterExpression {
|
|
245
|
+
property: string;
|
|
246
|
+
operator: FilterOperator;
|
|
247
|
+
values: (string | number | boolean)[];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export declare interface FilterGroup {
|
|
251
|
+
conditional: FilterConditional;
|
|
252
|
+
expressions: (FilterExpression | FilterGroup)[];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
declare interface FilterGroupParam {
|
|
256
|
+
filter_group: FilterGroup;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export declare type FilterMap = Record<string, FilterMapEntry>;
|
|
260
|
+
|
|
261
|
+
export declare type FilterMapEntry = string | {
|
|
262
|
+
property: string;
|
|
263
|
+
values?: Record<string, string>;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
declare enum FilterOperator {
|
|
267
|
+
Equal = "eq",
|
|
268
|
+
NotEqual = "not_eq",
|
|
269
|
+
In = "in",
|
|
270
|
+
NotIn = "not_in",
|
|
271
|
+
GreaterThan = "gt",
|
|
272
|
+
GreaterThanOrEqual = "gte",
|
|
273
|
+
LessThan = "lt",
|
|
274
|
+
LessThanOrEqual = "lte",
|
|
275
|
+
Exists = "exists",
|
|
276
|
+
NotExists = "not_exists"
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
declare interface FilterResult {
|
|
280
|
+
id: string;
|
|
281
|
+
label: string;
|
|
282
|
+
type: 'LIST' | 'PRICE_RANGE' | 'BOOLEAN';
|
|
283
|
+
values: FilterValueResult[];
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export declare type FilterTransformer = (filters: unknown) => FilterGroup | undefined;
|
|
287
|
+
|
|
288
|
+
declare type FilterValue = string | number | boolean;
|
|
289
|
+
|
|
290
|
+
declare interface FilterValueResult {
|
|
291
|
+
id: string;
|
|
292
|
+
label: string;
|
|
293
|
+
count: number;
|
|
294
|
+
input: string;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export declare function getSdk(): Result<Sdk, ConfigError>;
|
|
298
|
+
|
|
299
|
+
declare interface GraphQLErrorDetail {
|
|
300
|
+
readonly message: string;
|
|
301
|
+
readonly locations?: {
|
|
302
|
+
line: number;
|
|
303
|
+
column: number;
|
|
304
|
+
}[];
|
|
305
|
+
readonly path?: (string | number)[];
|
|
306
|
+
readonly extensions?: Record<string, unknown>;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export declare function gt(property: string, value: number): FilterExpression;
|
|
310
|
+
|
|
311
|
+
export declare function gte(property: string, value: number): FilterExpression;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Minimal SDK Error Types
|
|
315
|
+
*
|
|
316
|
+
* 4 error types cover all scenarios:
|
|
317
|
+
* - NetworkError: Connection failed before response
|
|
318
|
+
* - ApiError: API returned an error response
|
|
319
|
+
* - ValidationError: Pre-request validation failed
|
|
320
|
+
* - ConfigError: SDK misconfigured
|
|
321
|
+
*/
|
|
322
|
+
declare type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
323
|
+
|
|
324
|
+
declare type ID = CommerceBlocksID;
|
|
325
|
+
|
|
326
|
+
declare interface Image_2 {
|
|
327
|
+
url: string;
|
|
328
|
+
alt: string;
|
|
329
|
+
width: number;
|
|
330
|
+
height: number;
|
|
331
|
+
}
|
|
332
|
+
export { Image_2 as Image }
|
|
333
|
+
|
|
334
|
+
declare interface ImageResult {
|
|
335
|
+
url: string;
|
|
336
|
+
altText: string | null;
|
|
337
|
+
width: number;
|
|
338
|
+
height: number;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export declare interface ImageSearchOptions {
|
|
342
|
+
imageId: string;
|
|
343
|
+
page?: number;
|
|
344
|
+
limit?: number;
|
|
345
|
+
filters?: unknown;
|
|
346
|
+
tuning?: LayersTuning;
|
|
347
|
+
signal?: AbortSignal;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export declare function inValues(property: string, values: FilterValue[]): FilterExpression;
|
|
351
|
+
|
|
352
|
+
export declare function isInitialized(): boolean;
|
|
353
|
+
|
|
354
|
+
export declare function isRetryable(error: SdkError): boolean;
|
|
355
|
+
|
|
356
|
+
export declare function isSdkError(error: unknown): error is SdkError;
|
|
357
|
+
|
|
358
|
+
declare interface LayersClientConfig extends LayersFetchConfig {
|
|
359
|
+
sorts: Sort[];
|
|
360
|
+
facets: string[];
|
|
361
|
+
attributes?: string[];
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
declare interface LayersFacets {
|
|
365
|
+
facets?: Record<string, Record<string, number>>;
|
|
366
|
+
facetRanges?: Record<string, {
|
|
367
|
+
min: number;
|
|
368
|
+
max: number;
|
|
369
|
+
}>;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
declare interface LayersFetchConfig {
|
|
373
|
+
layersPublicToken: string;
|
|
374
|
+
layersBaseUrl?: string;
|
|
375
|
+
fetch?: CustomFetch;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
declare interface LayersMeta {
|
|
379
|
+
experimentsRan?: {
|
|
380
|
+
id: string;
|
|
381
|
+
group: 'control' | 'variation';
|
|
382
|
+
}[];
|
|
383
|
+
appliedRules?: string[];
|
|
384
|
+
variantBreakouts?: {
|
|
385
|
+
id: string;
|
|
386
|
+
name: string;
|
|
387
|
+
optionCode: string;
|
|
388
|
+
}[];
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
declare interface LayersPagination {
|
|
392
|
+
page: number;
|
|
393
|
+
totalPages: number;
|
|
394
|
+
totalResults: number;
|
|
395
|
+
resultsPerPage?: number;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
declare type LayersProduct = ProductResult;
|
|
399
|
+
|
|
400
|
+
declare interface LayersResponse extends LayersPagination, LayersFacets {
|
|
401
|
+
results: (ProductResult | VariantResult_2)[];
|
|
402
|
+
attributionToken: string;
|
|
403
|
+
_meta?: LayersMeta;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
declare interface LayersTuning {
|
|
407
|
+
textualWeight?: number;
|
|
408
|
+
visualWeight?: number;
|
|
409
|
+
multipleFactor?: number;
|
|
410
|
+
minimumMatch?: number;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
declare interface LayersVariant {
|
|
414
|
+
id: number;
|
|
415
|
+
title: string;
|
|
416
|
+
available: boolean;
|
|
417
|
+
sku: string;
|
|
418
|
+
price: string;
|
|
419
|
+
compare_at_price?: string | null;
|
|
420
|
+
selected_options: {
|
|
421
|
+
name: string;
|
|
422
|
+
value: string;
|
|
423
|
+
optionValue?: {
|
|
424
|
+
swatch?: unknown | null;
|
|
425
|
+
linkedMetafieldValue?: unknown | null;
|
|
426
|
+
};
|
|
427
|
+
}[];
|
|
428
|
+
position: number;
|
|
429
|
+
featured_media?: FeaturedMedia | null;
|
|
430
|
+
created_at?: string;
|
|
431
|
+
updated_at?: string;
|
|
432
|
+
requires_selling_plan?: boolean;
|
|
433
|
+
has_selling_plan?: boolean;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export declare function lt(property: string, value: number): FilterExpression;
|
|
437
|
+
|
|
438
|
+
export declare function lte(property: string, value: number): FilterExpression;
|
|
439
|
+
|
|
440
|
+
declare interface MatchedVariant extends LayersVariant {
|
|
441
|
+
metafields?: VariantMetafield[];
|
|
442
|
+
inventory_policy?: string;
|
|
443
|
+
inventory_quantity?: number;
|
|
444
|
+
product_id?: number;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export declare interface Metafield extends MetafieldIdentifier {
|
|
448
|
+
value: string;
|
|
449
|
+
type: string;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
declare interface MetafieldIdentifier {
|
|
453
|
+
namespace: string;
|
|
454
|
+
key: string;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
declare interface MetafieldResult {
|
|
458
|
+
namespace: string;
|
|
459
|
+
key: string;
|
|
460
|
+
value: string;
|
|
461
|
+
type: string;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
declare interface MetafieldResult_2 {
|
|
465
|
+
namespace: string;
|
|
466
|
+
key: string;
|
|
467
|
+
value: string;
|
|
468
|
+
type: string;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
declare interface MoneyResult {
|
|
472
|
+
amount: string;
|
|
473
|
+
currencyCode: string;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export declare interface NetworkError {
|
|
477
|
+
readonly _tag: 'NetworkError';
|
|
478
|
+
readonly code: NetworkErrorCode;
|
|
479
|
+
readonly message: string;
|
|
480
|
+
readonly timestamp: string;
|
|
481
|
+
readonly retryable: boolean;
|
|
482
|
+
readonly retryAfterMs?: number;
|
|
483
|
+
readonly request?: RequestContext;
|
|
484
|
+
readonly cause?: unknown;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
declare type NetworkErrorCode = 'TIMEOUT' | 'CONNECTION_FAILED' | 'DNS_FAILED' | 'SSL_ERROR' | 'ABORTED' | 'OFFLINE';
|
|
488
|
+
|
|
489
|
+
export declare function notEq(property: string, value: FilterValue): FilterExpression;
|
|
490
|
+
|
|
491
|
+
export declare function notExists(property: string): FilterExpression;
|
|
492
|
+
|
|
493
|
+
export declare function notIn(property: string, values: FilterValue[]): FilterExpression;
|
|
494
|
+
|
|
495
|
+
declare type OptionSegment = `${string}:${string}`;
|
|
496
|
+
|
|
497
|
+
declare interface OptionV2 {
|
|
498
|
+
name: string;
|
|
499
|
+
code: string;
|
|
500
|
+
values: {
|
|
501
|
+
value: string;
|
|
502
|
+
swatch: {
|
|
503
|
+
color: string | null;
|
|
504
|
+
image: {
|
|
505
|
+
alt: string;
|
|
506
|
+
url: string;
|
|
507
|
+
} | null;
|
|
508
|
+
} | null;
|
|
509
|
+
linked_metafield_value: unknown | null;
|
|
510
|
+
}[];
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
declare interface OptionValueResult {
|
|
514
|
+
id: string;
|
|
515
|
+
name: string;
|
|
516
|
+
swatch: SwatchResult | null;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export declare function or(...expressions: (FilterExpression | FilterGroup)[]): FilterGroup;
|
|
520
|
+
|
|
521
|
+
declare interface PageMeta {
|
|
522
|
+
handle: string;
|
|
523
|
+
title?: string;
|
|
524
|
+
body?: string;
|
|
525
|
+
bodySummary?: string;
|
|
526
|
+
lastFetched: number;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
declare interface PredictiveSearchResponse {
|
|
530
|
+
matchedQueries: {
|
|
531
|
+
query_text: string;
|
|
532
|
+
num_searches: number;
|
|
533
|
+
}[];
|
|
534
|
+
originalQuery: string;
|
|
535
|
+
normalizedQuery: string;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
declare type PrepareSearchQuery = Pick<SearchQuery, 'query' | 'filters' | 'tuning' | 'signal'>;
|
|
539
|
+
|
|
540
|
+
declare interface PrepareSearchResult {
|
|
541
|
+
searchId: string;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export declare interface Price {
|
|
545
|
+
amount: number;
|
|
546
|
+
currencyCode: string;
|
|
547
|
+
formatted: string;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
declare interface PriceRangeResult {
|
|
551
|
+
minVariantPrice: MoneyResult;
|
|
552
|
+
maxVariantPrice: MoneyResult;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
export declare type Product = BaseProduct;
|
|
556
|
+
|
|
557
|
+
declare interface ProductCategory {
|
|
558
|
+
id: string;
|
|
559
|
+
name: string;
|
|
560
|
+
full_name: string;
|
|
561
|
+
is_leaf: boolean;
|
|
562
|
+
is_root: boolean;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
declare type ProductExtender<P extends Product = Product> = (input: ProductExtenderInput) => P;
|
|
566
|
+
|
|
567
|
+
declare interface ProductExtenderInput {
|
|
568
|
+
base: Product;
|
|
569
|
+
raw: LayersProduct;
|
|
570
|
+
shopify: ShopifyProduct | null;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
declare type ProductGID = ShopifyGID<'Product'>;
|
|
574
|
+
|
|
575
|
+
declare interface ProductImage {
|
|
576
|
+
alt: string;
|
|
577
|
+
src: string;
|
|
578
|
+
width: number;
|
|
579
|
+
height: number;
|
|
580
|
+
position?: number;
|
|
581
|
+
variant_ids?: number[];
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
export declare interface ProductOption {
|
|
585
|
+
name: string;
|
|
586
|
+
value: string;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
declare interface ProductOptionResult {
|
|
590
|
+
id: string;
|
|
591
|
+
name: string;
|
|
592
|
+
optionValues: OptionValueResult[];
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
declare interface ProductResult {
|
|
596
|
+
__typename?: 'Product';
|
|
597
|
+
id: number;
|
|
598
|
+
title: string;
|
|
599
|
+
body_html?: string;
|
|
600
|
+
vendor?: string;
|
|
601
|
+
product_type?: string;
|
|
602
|
+
created_at?: string;
|
|
603
|
+
handle?: string;
|
|
604
|
+
updated_at?: string;
|
|
605
|
+
published_at?: string;
|
|
606
|
+
tags?: string[];
|
|
607
|
+
combined_listing_parent_product_id?: number | null;
|
|
608
|
+
combined_listing_role?: string | null;
|
|
609
|
+
images?: ProductImage[];
|
|
610
|
+
metafields?: Record<string, Record<string, unknown>> | unknown[];
|
|
611
|
+
calculated?: Record<string, unknown> | unknown[];
|
|
612
|
+
category?: ProductCategory | null;
|
|
613
|
+
first_or_matched_variant?: MatchedVariant;
|
|
614
|
+
featured_media?: FeaturedMedia | null;
|
|
615
|
+
available?: boolean;
|
|
616
|
+
price_range?: {
|
|
617
|
+
from: number;
|
|
618
|
+
to: number;
|
|
619
|
+
compare_at_price?: number;
|
|
620
|
+
};
|
|
621
|
+
options?: Record<string, string[]>;
|
|
622
|
+
original_options?: Record<string, string[]>;
|
|
623
|
+
options_v2?: OptionV2[];
|
|
624
|
+
named_tags?: Record<string, string | number | boolean | string[]> | unknown[];
|
|
625
|
+
is_gift_card?: boolean;
|
|
626
|
+
has_variants_that_require_components?: boolean;
|
|
627
|
+
variants?: LayersVariant[];
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
export declare interface ProductVariant {
|
|
631
|
+
id: ID;
|
|
632
|
+
gid: VariantGID;
|
|
633
|
+
numericId: number;
|
|
634
|
+
title: string;
|
|
635
|
+
availableForSale: boolean;
|
|
636
|
+
currentlyNotInStock: boolean;
|
|
637
|
+
quantityAvailable: number;
|
|
638
|
+
sku: string | null;
|
|
639
|
+
barcode: string | null;
|
|
640
|
+
weight: number | null;
|
|
641
|
+
weightUnit: 'KILOGRAMS' | 'GRAMS' | 'POUNDS' | 'OUNCES' | null;
|
|
642
|
+
requiresShipping: boolean;
|
|
643
|
+
price: Price;
|
|
644
|
+
compareAtPrice: Price | null;
|
|
645
|
+
image: Image_2 | null;
|
|
646
|
+
selectedOptions: ProductOption[];
|
|
647
|
+
metafields: Metafield[];
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
declare interface QueryResult<P extends Product = Product> {
|
|
651
|
+
products: P[];
|
|
652
|
+
totalResults: number;
|
|
653
|
+
totalPages: number;
|
|
654
|
+
page: number;
|
|
655
|
+
facets?: Record<string, Record<string, number>>;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
export declare interface QueryState<T> {
|
|
659
|
+
data: T | null;
|
|
660
|
+
error: SdkError | null;
|
|
661
|
+
isFetching: boolean;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export { ReadonlySignal }
|
|
665
|
+
|
|
666
|
+
declare interface RequestContext {
|
|
667
|
+
readonly method: HttpMethod;
|
|
668
|
+
readonly url: string;
|
|
669
|
+
readonly headers?: Record<string, string>;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
declare interface ResponseContext {
|
|
673
|
+
readonly status: number;
|
|
674
|
+
readonly statusText: string;
|
|
675
|
+
readonly headers?: Record<string, string>;
|
|
676
|
+
readonly body?: string;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
declare type Result<T, E = Error> = {
|
|
680
|
+
data: T;
|
|
681
|
+
error?: never;
|
|
682
|
+
} | {
|
|
683
|
+
data?: never;
|
|
684
|
+
error: E;
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
export declare interface RichProductOption extends ProductOption {
|
|
688
|
+
swatch?: Swatch;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
export declare interface Sdk<P extends Product = Product> {
|
|
692
|
+
collection: (options: CollectionOptions) => CollectionController<P>;
|
|
693
|
+
blocks: (options: BlocksOptions) => BlocksController<P>;
|
|
694
|
+
autocomplete: (options?: AutocompleteOptions) => AutocompleteController;
|
|
695
|
+
search: () => SearchController<P>;
|
|
696
|
+
storefront: (query: StorefrontQuery) => ReadonlySignal<QueryState<StorefrontResult<P>>>;
|
|
697
|
+
uploadImage: (options: UploadImageOptions) => ReadonlySignal<QueryState<UploadImageResult>>;
|
|
698
|
+
imageSearch: (options: ImageSearchOptions) => ReadonlySignal<QueryState<SearchResult<P>>>;
|
|
699
|
+
config: SdkConfig<P>;
|
|
700
|
+
store: Store<P>;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
export declare interface SdkConfig<P extends Product = Product> extends LayersClientConfig, Partial<StorefrontClientConfig> {
|
|
704
|
+
enableStorefront?: boolean;
|
|
705
|
+
includeMeta?: boolean;
|
|
706
|
+
currencyCode?: string;
|
|
707
|
+
formatPrice?: (amount: number, currencyCode: string) => string;
|
|
708
|
+
swatches?: Swatch[];
|
|
709
|
+
options?: string[];
|
|
710
|
+
productMetafields?: {
|
|
711
|
+
namespace: string;
|
|
712
|
+
key: string;
|
|
713
|
+
}[];
|
|
714
|
+
variantMetafields?: {
|
|
715
|
+
namespace: string;
|
|
716
|
+
key: string;
|
|
717
|
+
}[];
|
|
718
|
+
collectionMetafields?: {
|
|
719
|
+
namespace: string;
|
|
720
|
+
key: string;
|
|
721
|
+
}[];
|
|
722
|
+
pageMetafields?: {
|
|
723
|
+
namespace: string;
|
|
724
|
+
key: string;
|
|
725
|
+
}[];
|
|
726
|
+
storefrontApiVersion?: string;
|
|
727
|
+
cacheMaxProducts?: number;
|
|
728
|
+
cacheMaxEntries?: number;
|
|
729
|
+
cacheTtl?: number;
|
|
730
|
+
extendProduct?: ProductExtender<P>;
|
|
731
|
+
transformFilters?: FilterTransformer;
|
|
732
|
+
filterMap?: FilterMap;
|
|
733
|
+
extendCollection?: CollectionExtender<P>;
|
|
734
|
+
extendSearch?: SearchExtender<P>;
|
|
735
|
+
extendBlock?: BlocksExtender<P>;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
export declare type SdkError = NetworkError | ApiError | ValidationError | ConfigError;
|
|
739
|
+
|
|
740
|
+
export declare interface SearchController<P extends Product = Product> {
|
|
741
|
+
state: ReadonlySignal<QueryState<SearchResult<P>>>;
|
|
742
|
+
prepare: (query: PrepareSearchQuery) => Promise<Result<PrepareSearchResult, SdkError>>;
|
|
743
|
+
execute: (query: SearchQuery) => Promise<Result<SearchResult<P>, SdkError>>;
|
|
744
|
+
dispose: () => void;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
export declare type SearchExtender<P extends Product = Product> = (result: SearchResult<P>, raw: LayersResponse) => SearchResult<P>;
|
|
748
|
+
|
|
749
|
+
export declare interface SearchQuery {
|
|
750
|
+
query: string;
|
|
751
|
+
searchId?: string;
|
|
752
|
+
page?: number;
|
|
753
|
+
limit?: number;
|
|
754
|
+
filters?: unknown;
|
|
755
|
+
tuning?: LayersTuning;
|
|
756
|
+
signal?: AbortSignal;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
export declare interface SearchResult<P extends Product = Product> extends LayersPagination {
|
|
760
|
+
products: P[];
|
|
761
|
+
facets: Record<string, Record<string, number>>;
|
|
762
|
+
_meta?: LayersMeta;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
declare interface SelectedOptionResult {
|
|
766
|
+
name: string;
|
|
767
|
+
value: string;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
declare interface SeoResult {
|
|
771
|
+
title: string | null;
|
|
772
|
+
description: string | null;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
declare interface ShopifyCollection {
|
|
776
|
+
id: string;
|
|
777
|
+
handle: string;
|
|
778
|
+
title: string;
|
|
779
|
+
description: string;
|
|
780
|
+
descriptionHtml: string;
|
|
781
|
+
image: ImageResult | null;
|
|
782
|
+
seo: SeoResult;
|
|
783
|
+
updatedAt: string;
|
|
784
|
+
metafields?: (MetafieldResult | null)[];
|
|
785
|
+
products?: {
|
|
786
|
+
filters: FilterResult[];
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
declare type ShopifyGID<T extends ShopifyType> = `gid://shopify/${T}/${number}`;
|
|
791
|
+
|
|
792
|
+
declare interface ShopifyPage {
|
|
793
|
+
id: string;
|
|
794
|
+
handle: string;
|
|
795
|
+
title: string;
|
|
796
|
+
body: string;
|
|
797
|
+
bodySummary: string;
|
|
798
|
+
seo: SeoResult;
|
|
799
|
+
createdAt: string;
|
|
800
|
+
updatedAt: string;
|
|
801
|
+
onlineStoreUrl: string | null;
|
|
802
|
+
metafields?: (MetafieldResult | null)[];
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
declare interface ShopifyProduct {
|
|
806
|
+
id: string;
|
|
807
|
+
title: string;
|
|
808
|
+
handle: string;
|
|
809
|
+
description: string;
|
|
810
|
+
descriptionHtml: string;
|
|
811
|
+
vendor: string;
|
|
812
|
+
productType: string;
|
|
813
|
+
tags: string[];
|
|
814
|
+
availableForSale: boolean;
|
|
815
|
+
isGiftCard: boolean;
|
|
816
|
+
totalInventory: number;
|
|
817
|
+
onlineStoreUrl: string | null;
|
|
818
|
+
featuredImage: ImageResult | null;
|
|
819
|
+
images: {
|
|
820
|
+
nodes: ImageResult[];
|
|
821
|
+
};
|
|
822
|
+
priceRange: PriceRangeResult;
|
|
823
|
+
compareAtPriceRange: PriceRangeResult;
|
|
824
|
+
options: ProductOptionResult[];
|
|
825
|
+
variants: {
|
|
826
|
+
nodes: VariantResult[];
|
|
827
|
+
};
|
|
828
|
+
selectedOrFirstAvailableVariant: VariantResult | null;
|
|
829
|
+
metafields?: (MetafieldResult | null)[];
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
declare type ShopifyType = 'Product' | 'ProductVariant' | 'Collection';
|
|
833
|
+
|
|
834
|
+
export { Signal }
|
|
835
|
+
|
|
836
|
+
export { signal }
|
|
837
|
+
|
|
838
|
+
declare interface Sort {
|
|
839
|
+
label: string;
|
|
840
|
+
code: string;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
declare interface Store<P extends Product = Product> {
|
|
844
|
+
products: {
|
|
845
|
+
get(gid: ProductGID): P | undefined;
|
|
846
|
+
getMany(gids: ProductGID[]): {
|
|
847
|
+
cached: P[];
|
|
848
|
+
missing: ProductGID[];
|
|
849
|
+
};
|
|
850
|
+
set(products: P[]): void;
|
|
851
|
+
has(gid: ProductGID): boolean;
|
|
852
|
+
};
|
|
853
|
+
queries: {
|
|
854
|
+
get(key: string): ReadonlySignal<Entry<QueryResult<P>> | null>;
|
|
855
|
+
set(key: string, result: QueryResult<P>): void;
|
|
856
|
+
isExpired(key: string): boolean;
|
|
857
|
+
invalidate(pattern: string): void;
|
|
858
|
+
};
|
|
859
|
+
collections: {
|
|
860
|
+
get(handle: string): CollectionMeta | undefined;
|
|
861
|
+
set(handle: string, meta: Omit<CollectionMeta, 'handle'>): void;
|
|
862
|
+
delete(handle: string): void;
|
|
863
|
+
};
|
|
864
|
+
pages: {
|
|
865
|
+
get(handle: string): PageMeta | undefined;
|
|
866
|
+
set(handle: string, meta: Omit<PageMeta, 'handle'>): void;
|
|
867
|
+
delete(handle: string): void;
|
|
868
|
+
};
|
|
869
|
+
persist(): void;
|
|
870
|
+
restore(): void;
|
|
871
|
+
clear(): void;
|
|
872
|
+
readonly stats: {
|
|
873
|
+
products: number;
|
|
874
|
+
queries: number;
|
|
875
|
+
collections: number;
|
|
876
|
+
pages: number;
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
declare interface StorefrontClientConfig {
|
|
881
|
+
shop: string;
|
|
882
|
+
storefrontPublicToken: string;
|
|
883
|
+
storefrontApiVersion?: string;
|
|
884
|
+
fetch?: CustomFetch;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
export declare interface StorefrontQuery {
|
|
888
|
+
ids: string[];
|
|
889
|
+
meta?: {
|
|
890
|
+
collection?: string;
|
|
891
|
+
page?: string;
|
|
892
|
+
includeFilters?: boolean;
|
|
893
|
+
};
|
|
894
|
+
productMetafields?: {
|
|
895
|
+
namespace: string;
|
|
896
|
+
key: string;
|
|
897
|
+
}[];
|
|
898
|
+
variantMetafields?: {
|
|
899
|
+
namespace: string;
|
|
900
|
+
key: string;
|
|
901
|
+
}[];
|
|
902
|
+
collectionMetafields?: {
|
|
903
|
+
namespace: string;
|
|
904
|
+
key: string;
|
|
905
|
+
}[];
|
|
906
|
+
pageMetafields?: {
|
|
907
|
+
namespace: string;
|
|
908
|
+
key: string;
|
|
909
|
+
}[];
|
|
910
|
+
signal?: AbortSignal;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
export declare interface StorefrontResult<P extends Product = Product> {
|
|
914
|
+
products: P[];
|
|
915
|
+
collection?: ShopifyCollection;
|
|
916
|
+
page?: ShopifyPage;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
export declare interface Swatch {
|
|
920
|
+
name: string | null;
|
|
921
|
+
value: string;
|
|
922
|
+
color: string | null;
|
|
923
|
+
imageUrl: string | null;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
declare interface SwatchResult {
|
|
927
|
+
color: string | null;
|
|
928
|
+
image: {
|
|
929
|
+
previewImage: {
|
|
930
|
+
url: string;
|
|
931
|
+
};
|
|
932
|
+
} | null;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
export declare interface UploadImageOptions {
|
|
936
|
+
image: File | Blob;
|
|
937
|
+
signal?: AbortSignal;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
export declare interface UploadImageResult {
|
|
941
|
+
imageId: string;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
export declare interface ValidationError {
|
|
945
|
+
readonly _tag: 'ValidationError';
|
|
946
|
+
readonly code: 'VALIDATION_FAILED';
|
|
947
|
+
readonly message: string;
|
|
948
|
+
readonly timestamp: string;
|
|
949
|
+
readonly operation: string;
|
|
950
|
+
readonly fields: ValidationFieldError[];
|
|
951
|
+
readonly input?: unknown;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
declare type ValidationErrorCode = 'REQUIRED_FIELD' | 'INVALID_TYPE' | 'INVALID_FORMAT' | 'OUT_OF_RANGE' | 'INVALID_LENGTH' | 'INVALID_PATTERN' | 'INVALID_ENUM';
|
|
955
|
+
|
|
956
|
+
declare interface ValidationFieldError {
|
|
957
|
+
readonly path: string[];
|
|
958
|
+
readonly field: string;
|
|
959
|
+
readonly code: ValidationErrorCode;
|
|
960
|
+
readonly message: string;
|
|
961
|
+
readonly value?: unknown;
|
|
962
|
+
readonly expected?: string;
|
|
963
|
+
readonly constraints?: {
|
|
964
|
+
min?: number;
|
|
965
|
+
max?: number;
|
|
966
|
+
minLength?: number;
|
|
967
|
+
maxLength?: number;
|
|
968
|
+
pattern?: string;
|
|
969
|
+
allowedValues?: string[];
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
declare type VariantGID = ShopifyGID<'ProductVariant'>;
|
|
974
|
+
|
|
975
|
+
declare interface VariantMetafield {
|
|
976
|
+
key: string;
|
|
977
|
+
value: string;
|
|
978
|
+
namespace: string;
|
|
979
|
+
created_at: string;
|
|
980
|
+
updated_at: string;
|
|
981
|
+
value_type: string;
|
|
982
|
+
compare_digest: string;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
declare interface VariantResult {
|
|
986
|
+
id: string;
|
|
987
|
+
title: string;
|
|
988
|
+
availableForSale: boolean;
|
|
989
|
+
currentlyNotInStock: boolean;
|
|
990
|
+
quantityAvailable: number;
|
|
991
|
+
sku: string | null;
|
|
992
|
+
barcode: string | null;
|
|
993
|
+
weight: number | null;
|
|
994
|
+
weightUnit: 'KILOGRAMS' | 'GRAMS' | 'POUNDS' | 'OUNCES' | null;
|
|
995
|
+
requiresShipping: boolean;
|
|
996
|
+
price: MoneyResult;
|
|
997
|
+
compareAtPrice: MoneyResult | null;
|
|
998
|
+
selectedOptions: SelectedOptionResult[];
|
|
999
|
+
image: ImageResult | null;
|
|
1000
|
+
metafields?: (MetafieldResult | null)[];
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
declare interface VariantResult_2 extends Omit<ProductResult, '__typename'> {
|
|
1004
|
+
__typename: 'Variant';
|
|
1005
|
+
product_id: number;
|
|
1006
|
+
variant_id: number;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
export { }
|