@ekomerc/storefront 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/README.md +452 -0
- package/dist/errors.cjs +60 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +80 -0
- package/dist/errors.js +60 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.cjs +3266 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +952 -0
- package/dist/index.js +3267 -0
- package/dist/index.js.map +1 -0
- package/dist/types.cjs +2 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +68 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,952 @@
|
|
|
1
|
+
import { Result } from 'neverthrow';
|
|
2
|
+
|
|
3
|
+
export declare interface AccountOperations {
|
|
4
|
+
orders(args?: {
|
|
5
|
+
first?: number;
|
|
6
|
+
after?: string;
|
|
7
|
+
last?: number;
|
|
8
|
+
before?: string;
|
|
9
|
+
}): Promise<Result<PaginatedResult<CustomerOrder>, StorefrontError>>;
|
|
10
|
+
addresses(): Promise<Result<CustomerAddress[], StorefrontError>>;
|
|
11
|
+
createAddress(input: CustomerAddressInput): Promise<Result<CustomerAddress, StorefrontError>>;
|
|
12
|
+
updateAddress(addressId: string, input: CustomerAddressUpdateInput): Promise<Result<CustomerAddress, StorefrontError>>;
|
|
13
|
+
deleteAddress(addressId: string): Promise<Result<string, StorefrontError>>;
|
|
14
|
+
update(input: CustomerUpdateInput): Promise<Result<Customer, StorefrontError>>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export declare interface Address {
|
|
18
|
+
firstName: string | null;
|
|
19
|
+
lastName: string | null;
|
|
20
|
+
company: string | null;
|
|
21
|
+
address1: string;
|
|
22
|
+
address2: string | null;
|
|
23
|
+
city: string;
|
|
24
|
+
province: string | null;
|
|
25
|
+
provinceCode: string | null;
|
|
26
|
+
country: string;
|
|
27
|
+
countryCode: string;
|
|
28
|
+
zip: string;
|
|
29
|
+
phone: string | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare interface AnalyticsClickIds {
|
|
33
|
+
schemaVersion: 1;
|
|
34
|
+
capturedAt: string | null;
|
|
35
|
+
gclid: string | null;
|
|
36
|
+
gbraid: string | null;
|
|
37
|
+
wbraid: string | null;
|
|
38
|
+
ttclid: string | null;
|
|
39
|
+
fbclid: string | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
declare type AnalyticsConsentState = "granted" | "denied" | "unknown";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Optional context overrides for a tracking call.
|
|
46
|
+
*/
|
|
47
|
+
export declare interface AnalyticsContext {
|
|
48
|
+
storeSlug?: string;
|
|
49
|
+
path?: string;
|
|
50
|
+
referrer?: string | null;
|
|
51
|
+
occurredAt?: Date | string;
|
|
52
|
+
sessionId?: string;
|
|
53
|
+
visitorId?: string;
|
|
54
|
+
customerId?: string | null;
|
|
55
|
+
utmSource?: string | null;
|
|
56
|
+
utmMedium?: string | null;
|
|
57
|
+
utmCampaign?: string | null;
|
|
58
|
+
utmTerm?: string | null;
|
|
59
|
+
utmContent?: string | null;
|
|
60
|
+
consentState?: AnalyticsConsentState;
|
|
61
|
+
clickIds?: Partial<Omit<AnalyticsClickIds, "schemaVersion">>;
|
|
62
|
+
deviceType?: string;
|
|
63
|
+
deviceOs?: string | null;
|
|
64
|
+
deviceBrowser?: string | null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Error detail for a single ingest payload item.
|
|
69
|
+
*/
|
|
70
|
+
export declare interface AnalyticsErrorItem {
|
|
71
|
+
/**
|
|
72
|
+
* Index of the event in the request `events` array.
|
|
73
|
+
*/
|
|
74
|
+
index: number;
|
|
75
|
+
/**
|
|
76
|
+
* Server-assigned identifier for the event, if available.
|
|
77
|
+
*/
|
|
78
|
+
eventId: string | null;
|
|
79
|
+
/**
|
|
80
|
+
* Validation or processing error code.
|
|
81
|
+
*/
|
|
82
|
+
code: string;
|
|
83
|
+
/**
|
|
84
|
+
* Human-readable description of the failure.
|
|
85
|
+
*/
|
|
86
|
+
message: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Canonical analytics event type values accepted by the storefront ingest endpoint.
|
|
91
|
+
*/
|
|
92
|
+
export declare type AnalyticsEventType = "analytics.page_view" | "analytics.product_view" | "analytics.collection_view" | "analytics.search_performed" | "analytics.add_to_cart" | "analytics.remove_from_cart" | "analytics.checkout_started" | "analytics.checkout_step_completed" | "analytics.checkout_completed" | "analytics.custom";
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Response summary from the analytics ingest endpoint.
|
|
96
|
+
*/
|
|
97
|
+
export declare interface AnalyticsIngestResponse {
|
|
98
|
+
/**
|
|
99
|
+
* Number of events accepted and persisted.
|
|
100
|
+
*/
|
|
101
|
+
acceptedCount: number;
|
|
102
|
+
/**
|
|
103
|
+
* Number of events recognized as duplicates.
|
|
104
|
+
*/
|
|
105
|
+
duplicateCount: number;
|
|
106
|
+
/**
|
|
107
|
+
* Number of events rejected by validation or storage.
|
|
108
|
+
*/
|
|
109
|
+
rejectedCount: number;
|
|
110
|
+
/**
|
|
111
|
+
* Per-item errors, aligned by event index.
|
|
112
|
+
*/
|
|
113
|
+
errors: AnalyticsErrorItem[];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Primitive value allowed in analytics custom event properties.
|
|
118
|
+
*/
|
|
119
|
+
export declare type AnalyticsJsonPrimitive = string | number | boolean | null;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Recursive JSON value allowed in analytics custom event properties.
|
|
123
|
+
*/
|
|
124
|
+
export declare type AnalyticsJsonValue = AnalyticsJsonPrimitive | AnalyticsJsonValue[] | {
|
|
125
|
+
[key: string]: AnalyticsJsonValue;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export declare interface AnalyticsOperations {
|
|
129
|
+
/**
|
|
130
|
+
* Track an analytics event.
|
|
131
|
+
*
|
|
132
|
+
* Supports preset event names (`page_view`, `product_view`, `add_to_cart`, etc.),
|
|
133
|
+
* canonical names (`analytics.page_view`, ...), and custom events.
|
|
134
|
+
*
|
|
135
|
+
* Custom event names are sent as `analytics.custom` with `eventName` included in `properties`.
|
|
136
|
+
*
|
|
137
|
+
* @param eventName - Preset/event-name to track.
|
|
138
|
+
* @param context - Optional per-call context overrides.
|
|
139
|
+
* @returns Tracking result with ingest summary, or network/validation error.
|
|
140
|
+
*/
|
|
141
|
+
track(eventName: "page_view", context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
142
|
+
/**
|
|
143
|
+
* Track a product page view.
|
|
144
|
+
*/
|
|
145
|
+
track(eventName: "product_view", input: PresetPropertiesByName<"product_view">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
146
|
+
/**
|
|
147
|
+
* Track a collection page view.
|
|
148
|
+
*/
|
|
149
|
+
track(eventName: "collection_view", input: PresetPropertiesByName<"collection_view">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
150
|
+
/**
|
|
151
|
+
* Track search execution.
|
|
152
|
+
*/
|
|
153
|
+
track(eventName: "search_performed", input: PresetPropertiesByName<"search_performed">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
154
|
+
/**
|
|
155
|
+
* Track adding items to cart.
|
|
156
|
+
*/
|
|
157
|
+
track(eventName: "add_to_cart", input: PresetPropertiesByName<"add_to_cart">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
158
|
+
/**
|
|
159
|
+
* Track removing items from cart.
|
|
160
|
+
*/
|
|
161
|
+
track(eventName: "remove_from_cart", input: PresetPropertiesByName<"remove_from_cart">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
162
|
+
/**
|
|
163
|
+
* Track checkout start.
|
|
164
|
+
*/
|
|
165
|
+
track(eventName: "checkout_started", input: PresetPropertiesByName<"checkout_started">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
166
|
+
/**
|
|
167
|
+
* Track checkout step completion.
|
|
168
|
+
*/
|
|
169
|
+
track(eventName: "checkout_step_completed", input: PresetPropertiesByName<"checkout_step_completed">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
170
|
+
/**
|
|
171
|
+
* Track successful checkout completion.
|
|
172
|
+
*/
|
|
173
|
+
track(eventName: "checkout_completed", input: PresetPropertiesByName<"checkout_completed">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
174
|
+
/**
|
|
175
|
+
* Track a custom analytics event.
|
|
176
|
+
*
|
|
177
|
+
* Example:
|
|
178
|
+
* `client.analytics.track("homepage.hero_clicked", { section: "hero", position: 1 })`
|
|
179
|
+
*/
|
|
180
|
+
track(eventName: string, properties: AnalyticsProperties, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Supported preset event names accepted by `track()`.
|
|
185
|
+
*/
|
|
186
|
+
export declare type AnalyticsPresetEventName = "page_view" | "product_view" | "collection_view" | "search_performed" | "add_to_cart" | "remove_from_cart" | "checkout_started" | "checkout_step_completed" | "checkout_completed";
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Generic analytics event property bag.
|
|
190
|
+
*/
|
|
191
|
+
export declare interface AnalyticsProperties {
|
|
192
|
+
[key: string]: AnalyticsJsonValue;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Event name accepted by `track()`.
|
|
197
|
+
* Preset names (e.g. `product_view`) are normalized to `analytics.*` types.
|
|
198
|
+
* Unknown names are sent as `analytics.custom` with `{ eventName: <name> }`.
|
|
199
|
+
*/
|
|
200
|
+
export declare type AnalyticsTrackEventName = AnalyticsPresetEventName | AnalyticsEventType | string;
|
|
201
|
+
|
|
202
|
+
export declare interface AppliedDiscount {
|
|
203
|
+
promotionId: string;
|
|
204
|
+
discountClass: string;
|
|
205
|
+
discountType: string;
|
|
206
|
+
discountAmount: number;
|
|
207
|
+
description: string;
|
|
208
|
+
isAutomatic: boolean;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export declare interface AppliedPromoCode {
|
|
212
|
+
code: string;
|
|
213
|
+
discountType: string;
|
|
214
|
+
discountAmount: number;
|
|
215
|
+
description: string;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Authentication error - invalid/revoked API key, 401/403 responses
|
|
220
|
+
*/
|
|
221
|
+
export declare class AuthError extends StorefrontError {
|
|
222
|
+
constructor(message: string, options?: {
|
|
223
|
+
cause?: Error;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export declare interface AuthOperations {
|
|
228
|
+
register(input: {
|
|
229
|
+
email: string;
|
|
230
|
+
password: string;
|
|
231
|
+
name?: string;
|
|
232
|
+
}): Promise<Result<{
|
|
233
|
+
customer: Customer;
|
|
234
|
+
token: string;
|
|
235
|
+
}, StorefrontError>>;
|
|
236
|
+
login(input: {
|
|
237
|
+
email: string;
|
|
238
|
+
password: string;
|
|
239
|
+
}): Promise<Result<{
|
|
240
|
+
customer: Customer;
|
|
241
|
+
token: string;
|
|
242
|
+
}, StorefrontError>>;
|
|
243
|
+
logout(): void;
|
|
244
|
+
requestPasswordReset(email: string): Promise<Result<{
|
|
245
|
+
success: boolean;
|
|
246
|
+
}, StorefrontError>>;
|
|
247
|
+
resetPassword(input: {
|
|
248
|
+
token: string;
|
|
249
|
+
newPassword: string;
|
|
250
|
+
}): Promise<Result<{
|
|
251
|
+
success: boolean;
|
|
252
|
+
}, StorefrontError>>;
|
|
253
|
+
verifyEmail(token: string): Promise<Result<Customer, StorefrontError>>;
|
|
254
|
+
me(): Promise<Result<Customer | null, StorefrontError>>;
|
|
255
|
+
isLoggedIn(): boolean;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export declare interface AvailablePaymentMethod {
|
|
259
|
+
method: string;
|
|
260
|
+
displayName: string;
|
|
261
|
+
additionalFee: number;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export declare interface CacheHelpers {
|
|
265
|
+
clear(): void;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export declare interface Cart {
|
|
269
|
+
id: string;
|
|
270
|
+
token: string;
|
|
271
|
+
status: CartStatus;
|
|
272
|
+
items: CartItem[];
|
|
273
|
+
totalItems: number;
|
|
274
|
+
totalPrice: number;
|
|
275
|
+
taxTotal: number;
|
|
276
|
+
shippingTotal: number;
|
|
277
|
+
total: number;
|
|
278
|
+
discountTotal: number;
|
|
279
|
+
appliedPromoCode: AppliedPromoCode | null;
|
|
280
|
+
appliedDiscounts: AppliedDiscount[];
|
|
281
|
+
customerEmail: string | null;
|
|
282
|
+
customerPhone: string | null;
|
|
283
|
+
shippingAddress: Address | null;
|
|
284
|
+
billingAddress: Address | null;
|
|
285
|
+
notes: string | null;
|
|
286
|
+
paymentMethod: string | null;
|
|
287
|
+
shippingRateId: string | null;
|
|
288
|
+
checkoutStartedAt?: string | null;
|
|
289
|
+
checkoutExpiresAt?: string | null;
|
|
290
|
+
createdAt: string;
|
|
291
|
+
updatedAt: string;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export declare const CART_TOKEN_KEY = "ekomerc_cart_token";
|
|
295
|
+
|
|
296
|
+
export declare interface CartItem {
|
|
297
|
+
id: string;
|
|
298
|
+
variantId: string;
|
|
299
|
+
quantity: number;
|
|
300
|
+
priceAtAdd: number;
|
|
301
|
+
effectiveUnitPrice: number;
|
|
302
|
+
lineTotal: number;
|
|
303
|
+
taxAmount: number;
|
|
304
|
+
variant: ProductVariant | null;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export declare interface CartOperations {
|
|
308
|
+
get(): Promise<Result<Cart | null, StorefrontError>>;
|
|
309
|
+
create(): Promise<Result<Cart, StorefrontError>>;
|
|
310
|
+
addItem(variantId: string, quantity: number): Promise<Result<Cart, StorefrontError>>;
|
|
311
|
+
updateItem(variantId: string, quantity: number): Promise<Result<Cart, StorefrontError>>;
|
|
312
|
+
removeItem(variantId: string): Promise<Result<Cart, StorefrontError>>;
|
|
313
|
+
clear(): Promise<Result<Cart, StorefrontError>>;
|
|
314
|
+
applyPromoCode(code: string): Promise<Result<Cart, StorefrontError>>;
|
|
315
|
+
removePromoCode(): Promise<Result<Cart, StorefrontError>>;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export declare type CartStatus = "active" | "checkout" | "converted" | "abandoned" | "expired";
|
|
319
|
+
|
|
320
|
+
export declare interface CategoriesOperations {
|
|
321
|
+
tree(): Promise<Result<Category[], StorefrontError>>;
|
|
322
|
+
flat(): Promise<Result<FlatCategory[], StorefrontError>>;
|
|
323
|
+
get(idOrHandle: string): Promise<Result<Category, StorefrontError>>;
|
|
324
|
+
getProducts(idOrHandle: string, options?: CategoryProductsOptions): Promise<Result<PaginatedResult<Product>, StorefrontError>>;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export declare interface Category {
|
|
328
|
+
id: string;
|
|
329
|
+
name: string;
|
|
330
|
+
handle: string;
|
|
331
|
+
description: string | null;
|
|
332
|
+
metaTitle: string | null;
|
|
333
|
+
metaDescription: string | null;
|
|
334
|
+
imageAsset: {
|
|
335
|
+
url: string;
|
|
336
|
+
altText: string | null;
|
|
337
|
+
width: number | null;
|
|
338
|
+
height: number | null;
|
|
339
|
+
} | null;
|
|
340
|
+
parent: Category | null;
|
|
341
|
+
children: Category[];
|
|
342
|
+
ancestors: Category[];
|
|
343
|
+
productCount: number;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export declare interface CategoryProductsOptions {
|
|
347
|
+
first?: number;
|
|
348
|
+
after?: string;
|
|
349
|
+
includeDescendants?: boolean;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export declare interface CheckoutData {
|
|
353
|
+
email?: string;
|
|
354
|
+
phone?: string;
|
|
355
|
+
shippingAddress?: Address;
|
|
356
|
+
billingAddress?: Address;
|
|
357
|
+
notes?: string;
|
|
358
|
+
emailMarketingConsent?: boolean | null;
|
|
359
|
+
paymentMethod?: string;
|
|
360
|
+
shippingRateId?: string;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export declare interface CheckoutOperations {
|
|
364
|
+
start(): Promise<Result<Cart, StorefrontError>>;
|
|
365
|
+
update(data: CheckoutData): Promise<Result<Cart, StorefrontError>>;
|
|
366
|
+
complete(): Promise<Result<Order, StorefrontError>>;
|
|
367
|
+
abandon(): Promise<Result<Cart, StorefrontError>>;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Checkout step identifiers for `checkout_step_completed` analytics events.
|
|
372
|
+
*/
|
|
373
|
+
export declare type CheckoutStep = "contact" | "shipping" | "payment" | "review";
|
|
374
|
+
|
|
375
|
+
export declare interface Collection {
|
|
376
|
+
id: string;
|
|
377
|
+
handle: string;
|
|
378
|
+
title: string;
|
|
379
|
+
description: string | null;
|
|
380
|
+
type: CollectionType;
|
|
381
|
+
sortOrder: CollectionSortOrder;
|
|
382
|
+
metaTitle: string | null;
|
|
383
|
+
metaDescription: string | null;
|
|
384
|
+
productCount: number;
|
|
385
|
+
imageAsset: {
|
|
386
|
+
url: string;
|
|
387
|
+
altText: string | null;
|
|
388
|
+
width: number | null;
|
|
389
|
+
height: number | null;
|
|
390
|
+
} | null;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export declare interface CollectionProductsOptions {
|
|
394
|
+
first?: number;
|
|
395
|
+
after?: string;
|
|
396
|
+
sort?: CollectionProductSort;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export declare type CollectionProductSort = "manual" | "best_selling" | "newest" | "price_asc" | "price_desc";
|
|
400
|
+
|
|
401
|
+
export declare interface CollectionsListOptions {
|
|
402
|
+
first?: number;
|
|
403
|
+
after?: string;
|
|
404
|
+
search?: string;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export declare interface CollectionsOperations {
|
|
408
|
+
list(options?: CollectionsListOptions): Promise<Result<PaginatedResult<Collection>, StorefrontError>>;
|
|
409
|
+
get(idOrHandle: string): Promise<Result<Collection, StorefrontError>>;
|
|
410
|
+
getProducts(idOrHandle: string, options?: CollectionProductsOptions): Promise<Result<PaginatedResult<Product>, StorefrontError>>;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export declare type CollectionSortOrder = "manual" | "best_selling" | "newest" | "price_asc" | "price_desc";
|
|
414
|
+
|
|
415
|
+
export declare type CollectionType = "manual" | "intelligent";
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Detect environment and create appropriate default adapter
|
|
419
|
+
*/
|
|
420
|
+
export declare function createDefaultAdapter(): StorageAdapter;
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* localStorage adapter for browser environments
|
|
424
|
+
*/
|
|
425
|
+
export declare function createLocalStorageAdapter(): StorageAdapter;
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* In-memory adapter for SSR or testing
|
|
429
|
+
*/
|
|
430
|
+
export declare function createMemoryAdapter(): StorageAdapter;
|
|
431
|
+
|
|
432
|
+
export declare function createQueryCache(): QueryCache;
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Create a new Storefront SDK client
|
|
436
|
+
*
|
|
437
|
+
* @param config - Client configuration including endpoint, API key, and optional storage adapter
|
|
438
|
+
* @returns A configured StorefrontClient instance
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```typescript
|
|
442
|
+
* import { createStorefrontClient } from "@ekomerc/storefront";
|
|
443
|
+
*
|
|
444
|
+
* const client = createStorefrontClient({
|
|
445
|
+
* endpoint: "https://api.mystore.com/storefront",
|
|
446
|
+
* apiKey: "sfk_abc123...",
|
|
447
|
+
* });
|
|
448
|
+
*
|
|
449
|
+
* // Query products
|
|
450
|
+
* const result = await client.query({
|
|
451
|
+
* query: `query { products { edges { node { id title } } } }`,
|
|
452
|
+
* });
|
|
453
|
+
*
|
|
454
|
+
* if (result.isOk()) {
|
|
455
|
+
* console.log(result.value);
|
|
456
|
+
* } else {
|
|
457
|
+
* console.error(result.error);
|
|
458
|
+
* }
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
export declare function createStorefrontClient(config: StorefrontClientConfig): StorefrontClient;
|
|
462
|
+
|
|
463
|
+
export declare interface Customer {
|
|
464
|
+
id: string;
|
|
465
|
+
name: string | null;
|
|
466
|
+
email: string;
|
|
467
|
+
emailVerified: boolean;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
export declare const CUSTOMER_TOKEN_KEY = "ekomerc_customer_token";
|
|
471
|
+
|
|
472
|
+
export declare interface CustomerAddress {
|
|
473
|
+
id: string;
|
|
474
|
+
label: string | null;
|
|
475
|
+
firstName: string | null;
|
|
476
|
+
lastName: string | null;
|
|
477
|
+
addressLine1: string;
|
|
478
|
+
addressLine2: string | null;
|
|
479
|
+
city: string;
|
|
480
|
+
postalCode: string | null;
|
|
481
|
+
phone: string | null;
|
|
482
|
+
isDefault: boolean;
|
|
483
|
+
createdAt: string;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export declare interface CustomerAddressInput {
|
|
487
|
+
label?: string;
|
|
488
|
+
firstName?: string;
|
|
489
|
+
lastName?: string;
|
|
490
|
+
addressLine1: string;
|
|
491
|
+
addressLine2?: string;
|
|
492
|
+
city: string;
|
|
493
|
+
postalCode?: string;
|
|
494
|
+
phone?: string;
|
|
495
|
+
isDefault?: boolean;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
export declare interface CustomerAddressUpdateInput {
|
|
499
|
+
label?: string;
|
|
500
|
+
firstName?: string;
|
|
501
|
+
lastName?: string;
|
|
502
|
+
addressLine1?: string;
|
|
503
|
+
addressLine2?: string;
|
|
504
|
+
city?: string;
|
|
505
|
+
postalCode?: string;
|
|
506
|
+
phone?: string;
|
|
507
|
+
isDefault?: boolean;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
export declare interface CustomerOrder {
|
|
511
|
+
id: string;
|
|
512
|
+
orderNumber: string;
|
|
513
|
+
status: string;
|
|
514
|
+
email: string;
|
|
515
|
+
phone: string | null;
|
|
516
|
+
subtotal: number;
|
|
517
|
+
total: number;
|
|
518
|
+
note: string | null;
|
|
519
|
+
items: CustomerOrderItem[];
|
|
520
|
+
createdAt: string;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
export declare interface CustomerOrderItem {
|
|
524
|
+
id: string;
|
|
525
|
+
productTitle: string;
|
|
526
|
+
variantTitle: string | null;
|
|
527
|
+
sku: string | null;
|
|
528
|
+
quantity: number;
|
|
529
|
+
unitPrice: number;
|
|
530
|
+
totalPrice: number;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
export declare interface CustomerUpdateInput {
|
|
534
|
+
name?: string;
|
|
535
|
+
email?: string;
|
|
536
|
+
currentPassword?: string;
|
|
537
|
+
newPassword?: string;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Extract userErrors from mutation result and convert to ValidationError if present
|
|
542
|
+
*/
|
|
543
|
+
export declare function extractUserErrors<T extends {
|
|
544
|
+
userErrors?: Array<{
|
|
545
|
+
field: string | null;
|
|
546
|
+
message: string;
|
|
547
|
+
}>;
|
|
548
|
+
}>(data: T, fieldName: keyof T): Result<Exclude<T[keyof T], undefined>, ValidationError>;
|
|
549
|
+
|
|
550
|
+
export declare interface FlatCategory {
|
|
551
|
+
id: string;
|
|
552
|
+
name: string;
|
|
553
|
+
handle: string;
|
|
554
|
+
description: string | null;
|
|
555
|
+
metaTitle: string | null;
|
|
556
|
+
metaDescription: string | null;
|
|
557
|
+
imageUrl: string | null;
|
|
558
|
+
parentId: string | null;
|
|
559
|
+
depth: number;
|
|
560
|
+
hasChildren: boolean;
|
|
561
|
+
productCount: number;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
export declare interface GraphQLClient {
|
|
565
|
+
query<T>(request: GraphQLRequest, options?: {
|
|
566
|
+
cache?: boolean;
|
|
567
|
+
}): Promise<Result<T, StorefrontError>>;
|
|
568
|
+
mutate<T>(request: GraphQLRequest): Promise<Result<T, StorefrontError>>;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* GraphQL error - unexpected GraphQL errors
|
|
573
|
+
*/
|
|
574
|
+
export declare class GraphQLError extends StorefrontError {
|
|
575
|
+
readonly graphqlErrors: Array<{
|
|
576
|
+
message: string;
|
|
577
|
+
path?: readonly (string | number)[];
|
|
578
|
+
}>;
|
|
579
|
+
constructor(message: string, graphqlErrors: Array<{
|
|
580
|
+
message: string;
|
|
581
|
+
path?: readonly (string | number)[];
|
|
582
|
+
}>, options?: {
|
|
583
|
+
cause?: Error;
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
export declare interface GraphQLRequest {
|
|
588
|
+
query: string;
|
|
589
|
+
variables?: Record<string, unknown>;
|
|
590
|
+
operationName?: string;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
export declare interface GraphQLResponse<T = unknown> {
|
|
594
|
+
data?: T;
|
|
595
|
+
errors?: Array<{
|
|
596
|
+
message: string;
|
|
597
|
+
path?: readonly (string | number)[];
|
|
598
|
+
}>;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Network error - fetch failed, connection issues
|
|
603
|
+
*/
|
|
604
|
+
export declare class NetworkError extends StorefrontError {
|
|
605
|
+
constructor(message: string, options?: {
|
|
606
|
+
cause?: Error;
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* Not found error - resource doesn't exist
|
|
612
|
+
*/
|
|
613
|
+
export declare class NotFoundError extends StorefrontError {
|
|
614
|
+
constructor(message: string, options?: {
|
|
615
|
+
cause?: Error;
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
export declare interface Order {
|
|
620
|
+
id: string;
|
|
621
|
+
orderNumber: string;
|
|
622
|
+
email: string | null;
|
|
623
|
+
phone: string | null;
|
|
624
|
+
status: string;
|
|
625
|
+
shippingAddress: Address | null;
|
|
626
|
+
subtotal: number;
|
|
627
|
+
total: number;
|
|
628
|
+
note: string | null;
|
|
629
|
+
items: OrderItem[];
|
|
630
|
+
paymentInstructions: PaymentInstructions | null;
|
|
631
|
+
createdAt: string;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
export declare interface OrderItem {
|
|
635
|
+
id: string;
|
|
636
|
+
productTitle: string;
|
|
637
|
+
variantTitle: string | null;
|
|
638
|
+
sku: string | null;
|
|
639
|
+
quantity: number;
|
|
640
|
+
unitPrice: number;
|
|
641
|
+
totalPrice: number;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
export declare interface PageInfo {
|
|
645
|
+
hasNextPage: boolean;
|
|
646
|
+
hasPreviousPage: boolean;
|
|
647
|
+
startCursor: string | null;
|
|
648
|
+
endCursor: string | null;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
export declare interface PaginatedResult<T> {
|
|
652
|
+
items: T[];
|
|
653
|
+
pageInfo: PageInfo;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
export declare interface PaymentInstructions {
|
|
657
|
+
bankAccount: string;
|
|
658
|
+
recipientName: string;
|
|
659
|
+
referenceNumber: string;
|
|
660
|
+
ipsQrCodeBase64: string;
|
|
661
|
+
expiresAt: string;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export declare interface PaymentsOperations {
|
|
665
|
+
getAvailableMethods(): Promise<Result<AvailablePaymentMethod[], StorefrontError>>;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
declare type PresetEventProperties = {
|
|
669
|
+
page_view: {};
|
|
670
|
+
product_view: {
|
|
671
|
+
productId: string;
|
|
672
|
+
variantId?: string | null;
|
|
673
|
+
};
|
|
674
|
+
collection_view: {
|
|
675
|
+
collectionId: string;
|
|
676
|
+
};
|
|
677
|
+
search_performed: {
|
|
678
|
+
query: string;
|
|
679
|
+
resultsCount: number;
|
|
680
|
+
};
|
|
681
|
+
add_to_cart: {
|
|
682
|
+
cartId: string;
|
|
683
|
+
quantity: number;
|
|
684
|
+
itemsCount: number;
|
|
685
|
+
cartValue: number;
|
|
686
|
+
};
|
|
687
|
+
remove_from_cart: {
|
|
688
|
+
cartId: string;
|
|
689
|
+
quantity: number;
|
|
690
|
+
itemsCount: number;
|
|
691
|
+
cartValue: number;
|
|
692
|
+
};
|
|
693
|
+
checkout_started: {
|
|
694
|
+
cartId: string;
|
|
695
|
+
};
|
|
696
|
+
checkout_step_completed: {
|
|
697
|
+
cartId: string;
|
|
698
|
+
step: CheckoutStep;
|
|
699
|
+
};
|
|
700
|
+
checkout_completed: {
|
|
701
|
+
orderId: string;
|
|
702
|
+
cartId: string;
|
|
703
|
+
orderTotal: number;
|
|
704
|
+
};
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
declare type PresetPropertiesByName<T extends AnalyticsPresetEventName> = PresetEventProperties[T];
|
|
708
|
+
|
|
709
|
+
export declare interface Product {
|
|
710
|
+
id: string;
|
|
711
|
+
handle: string;
|
|
712
|
+
title: string;
|
|
713
|
+
description: string | null;
|
|
714
|
+
vendor: string | null;
|
|
715
|
+
productType: string | null;
|
|
716
|
+
metaTitle: string | null;
|
|
717
|
+
metaDescription: string | null;
|
|
718
|
+
publishedAt: string | null;
|
|
719
|
+
createdAt: string;
|
|
720
|
+
availableForSale: boolean;
|
|
721
|
+
media: ProductImage[];
|
|
722
|
+
options: ProductOption[];
|
|
723
|
+
variants: ProductVariant[];
|
|
724
|
+
categories: Category[];
|
|
725
|
+
primaryCategory: Category | null;
|
|
726
|
+
tags: Tag[];
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
export declare interface ProductFilter {
|
|
730
|
+
search?: string | null;
|
|
731
|
+
categoryHandle?: string | null;
|
|
732
|
+
categoryId?: string | null;
|
|
733
|
+
includeDescendants?: boolean | null;
|
|
734
|
+
collectionHandle?: string | null;
|
|
735
|
+
collectionId?: string | null;
|
|
736
|
+
tags?: string[] | null;
|
|
737
|
+
vendor?: string | null;
|
|
738
|
+
productType?: string | null;
|
|
739
|
+
minPrice?: number | null;
|
|
740
|
+
maxPrice?: number | null;
|
|
741
|
+
availableForSale?: boolean | null;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
export declare interface ProductImage {
|
|
745
|
+
id: string;
|
|
746
|
+
url: string;
|
|
747
|
+
altText: string | null;
|
|
748
|
+
position: number;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
export declare interface ProductOption {
|
|
752
|
+
id: string;
|
|
753
|
+
name: string;
|
|
754
|
+
position: number;
|
|
755
|
+
values: ProductOptionValue[];
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
export declare interface ProductOptionValue {
|
|
759
|
+
id: string;
|
|
760
|
+
value: string;
|
|
761
|
+
position: number;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
export declare interface ProductsListOptions {
|
|
765
|
+
first?: number;
|
|
766
|
+
after?: string;
|
|
767
|
+
filter?: ProductFilter;
|
|
768
|
+
sort?: ProductSortKey;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
export declare interface ProductsOperations {
|
|
772
|
+
list(options?: ProductsListOptions): Promise<Result<PaginatedResult<Product>, StorefrontError>>;
|
|
773
|
+
get(idOrHandle: string): Promise<Result<Product, StorefrontError>>;
|
|
774
|
+
getByHandles(handles: string[]): Promise<Result<(Product | null)[], StorefrontError>>;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
export declare type ProductSortKey = "CREATED_AT" | "TITLE" | "PRICE_ASC" | "PRICE_DESC" | "BEST_SELLING";
|
|
778
|
+
|
|
779
|
+
export declare interface ProductVariant {
|
|
780
|
+
id: string;
|
|
781
|
+
title: string;
|
|
782
|
+
sku: string | null;
|
|
783
|
+
price: number;
|
|
784
|
+
compareAtPrice: number | null;
|
|
785
|
+
weight: number | null;
|
|
786
|
+
weightUnit: WeightUnit;
|
|
787
|
+
requiresShipping: boolean;
|
|
788
|
+
availableForSale: boolean;
|
|
789
|
+
quantity: number;
|
|
790
|
+
selectedOptions: ProductOptionValue[];
|
|
791
|
+
image: ProductImage | null;
|
|
792
|
+
isOnSale: boolean;
|
|
793
|
+
quantityPricing: QuantityPricingTier[];
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
export declare interface QuantityPricingTier {
|
|
797
|
+
minQuantity: number;
|
|
798
|
+
price: number;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
export declare interface QueryCache {
|
|
802
|
+
get<T>(key: string): T | null;
|
|
803
|
+
set<T>(key: string, value: T, ttl: number): void;
|
|
804
|
+
clear(): void;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
export declare interface ShippingOperations {
|
|
808
|
+
getAvailableRates(): Promise<Result<ShippingRate[], StorefrontError>>;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
export declare interface ShippingRate {
|
|
812
|
+
id: string;
|
|
813
|
+
name: string;
|
|
814
|
+
price: number;
|
|
815
|
+
minOrderAmount: number | null;
|
|
816
|
+
estimatedDaysMin: number | null;
|
|
817
|
+
estimatedDaysMax: number | null;
|
|
818
|
+
isFree: boolean;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
export declare interface SocialLinks {
|
|
822
|
+
instagram?: string;
|
|
823
|
+
facebook?: string;
|
|
824
|
+
tiktok?: string;
|
|
825
|
+
twitter?: string;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* State error - invalid cart state transition
|
|
830
|
+
*/
|
|
831
|
+
export declare class StateError extends StorefrontError {
|
|
832
|
+
readonly state: string;
|
|
833
|
+
constructor(message: string, state: string, options?: {
|
|
834
|
+
cause?: Error;
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* Re-export generated GraphQL types once codegen runs
|
|
840
|
+
* For now, define placeholder types that will be replaced
|
|
841
|
+
*/
|
|
842
|
+
export declare interface StorageAdapter {
|
|
843
|
+
get(key: string): string | null;
|
|
844
|
+
set(key: string, value: string): void;
|
|
845
|
+
remove(key: string): void;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
export declare interface Store {
|
|
849
|
+
id: string;
|
|
850
|
+
name: string;
|
|
851
|
+
slug: string;
|
|
852
|
+
description: string | null;
|
|
853
|
+
currency: string;
|
|
854
|
+
timezone: string;
|
|
855
|
+
logoUrl: string | null;
|
|
856
|
+
contactPhone: string | null;
|
|
857
|
+
socialLinks: SocialLinks;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
export declare interface StorefrontClient {
|
|
861
|
+
readonly config: StorefrontClientConfig;
|
|
862
|
+
readonly cache: CacheHelpers;
|
|
863
|
+
readonly products: ProductsOperations;
|
|
864
|
+
readonly collections: CollectionsOperations;
|
|
865
|
+
readonly categories: CategoriesOperations;
|
|
866
|
+
readonly cart: CartOperations;
|
|
867
|
+
readonly checkout: CheckoutOperations;
|
|
868
|
+
readonly payments: PaymentsOperations;
|
|
869
|
+
readonly auth: AuthOperations;
|
|
870
|
+
readonly account: AccountOperations;
|
|
871
|
+
readonly shipping: ShippingOperations;
|
|
872
|
+
readonly analytics: AnalyticsOperations;
|
|
873
|
+
/**
|
|
874
|
+
* Execute a GraphQL query with optional caching
|
|
875
|
+
*/
|
|
876
|
+
query<T>(request: GraphQLRequest, options?: {
|
|
877
|
+
cache?: boolean;
|
|
878
|
+
}): Promise<Result<T, StorefrontError>>;
|
|
879
|
+
/**
|
|
880
|
+
* Execute a GraphQL mutation (never cached)
|
|
881
|
+
*/
|
|
882
|
+
mutate<T>(request: GraphQLRequest): Promise<Result<T, StorefrontError>>;
|
|
883
|
+
/**
|
|
884
|
+
* Get the current cart token from storage
|
|
885
|
+
*/
|
|
886
|
+
getCartToken(): string | null;
|
|
887
|
+
/**
|
|
888
|
+
* Set the cart token in storage
|
|
889
|
+
*/
|
|
890
|
+
setCartToken(token: string): void;
|
|
891
|
+
/**
|
|
892
|
+
* Clear the cart token from storage
|
|
893
|
+
*/
|
|
894
|
+
clearCartToken(): void;
|
|
895
|
+
/**
|
|
896
|
+
* Get the current customer JWT token from storage
|
|
897
|
+
*/
|
|
898
|
+
getCustomerToken(): string | null;
|
|
899
|
+
/**
|
|
900
|
+
* Set the customer JWT token in storage
|
|
901
|
+
*/
|
|
902
|
+
setCustomerToken(token: string): void;
|
|
903
|
+
/**
|
|
904
|
+
* Clear the customer JWT token from storage
|
|
905
|
+
*/
|
|
906
|
+
clearCustomerToken(): void;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
export declare interface StorefrontClientConfig {
|
|
910
|
+
endpoint: string;
|
|
911
|
+
apiKey: string;
|
|
912
|
+
storage?: StorageAdapter;
|
|
913
|
+
cacheTTL?: number;
|
|
914
|
+
storeSlug?: string;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
* Base class for all Storefront SDK errors
|
|
919
|
+
*/
|
|
920
|
+
export declare class StorefrontError extends Error {
|
|
921
|
+
readonly code: string;
|
|
922
|
+
constructor(message: string, code: string, options?: {
|
|
923
|
+
cause?: Error;
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
export declare type StorefrontResult<T> = Result<T, StorefrontError>;
|
|
928
|
+
|
|
929
|
+
export declare interface Tag {
|
|
930
|
+
id: string;
|
|
931
|
+
name: string;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Validation error - userErrors from mutations
|
|
936
|
+
*/
|
|
937
|
+
export declare class ValidationError extends StorefrontError {
|
|
938
|
+
readonly userErrors: Array<{
|
|
939
|
+
field: string | null;
|
|
940
|
+
message: string;
|
|
941
|
+
}>;
|
|
942
|
+
constructor(message: string, userErrors: Array<{
|
|
943
|
+
field: string | null;
|
|
944
|
+
message: string;
|
|
945
|
+
}>, options?: {
|
|
946
|
+
cause?: Error;
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
export declare type WeightUnit = "g" | "kg" | "lb" | "oz";
|
|
951
|
+
|
|
952
|
+
export { }
|