@ekomerc/storefront 0.1.0 → 0.1.3
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 +237 -10
- package/dist/README.md +679 -0
- package/dist/errors.d.cts +74 -0
- package/dist/errors.d.ts +74 -80
- package/dist/index.cjs +2840 -1810
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1493 -0
- package/dist/index.d.ts +1493 -952
- package/dist/index.js +2841 -1811
- package/dist/index.js.map +1 -1
- package/dist/package.json +45 -0
- package/dist/types.d.cts +656 -0
- package/dist/types.d.ts +656 -1
- package/package.json +12 -5
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1493 @@
|
|
|
1
|
+
import { Result } from 'neverthrow';
|
|
2
|
+
|
|
3
|
+
interface QueryCache {
|
|
4
|
+
get<T>(key: string): T | null;
|
|
5
|
+
set<T>(key: string, value: T, ttl: number): void;
|
|
6
|
+
clear(): void;
|
|
7
|
+
}
|
|
8
|
+
declare function createQueryCache(): QueryCache;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Base class for all Storefront SDK errors
|
|
12
|
+
*/
|
|
13
|
+
declare class StorefrontError extends Error {
|
|
14
|
+
readonly code: string;
|
|
15
|
+
constructor(message: string, code: string, options?: {
|
|
16
|
+
cause?: Error;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Network error - fetch failed, connection issues
|
|
21
|
+
*/
|
|
22
|
+
declare class NetworkError extends StorefrontError {
|
|
23
|
+
constructor(message: string, options?: {
|
|
24
|
+
cause?: Error;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Authentication error - invalid/revoked API key, 401/403 responses
|
|
29
|
+
*/
|
|
30
|
+
declare class AuthError extends StorefrontError {
|
|
31
|
+
constructor(message: string, options?: {
|
|
32
|
+
cause?: Error;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Validation error - userErrors from mutations
|
|
37
|
+
*/
|
|
38
|
+
declare class ValidationError extends StorefrontError {
|
|
39
|
+
readonly userErrors: Array<{
|
|
40
|
+
field: string | null;
|
|
41
|
+
message: string;
|
|
42
|
+
}>;
|
|
43
|
+
constructor(message: string, userErrors: Array<{
|
|
44
|
+
field: string | null;
|
|
45
|
+
message: string;
|
|
46
|
+
}>, options?: {
|
|
47
|
+
cause?: Error;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Not found error - resource doesn't exist
|
|
52
|
+
*/
|
|
53
|
+
declare class NotFoundError extends StorefrontError {
|
|
54
|
+
constructor(message: string, options?: {
|
|
55
|
+
cause?: Error;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* State error - invalid cart state transition
|
|
60
|
+
*/
|
|
61
|
+
declare class StateError extends StorefrontError {
|
|
62
|
+
readonly state: string;
|
|
63
|
+
constructor(message: string, state: string, options?: {
|
|
64
|
+
cause?: Error;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* GraphQL error - unexpected GraphQL errors
|
|
69
|
+
*/
|
|
70
|
+
declare class GraphQLError extends StorefrontError {
|
|
71
|
+
readonly graphqlErrors: Array<{
|
|
72
|
+
message: string;
|
|
73
|
+
path?: readonly (string | number)[];
|
|
74
|
+
}>;
|
|
75
|
+
constructor(message: string, graphqlErrors: Array<{
|
|
76
|
+
message: string;
|
|
77
|
+
path?: readonly (string | number)[];
|
|
78
|
+
}>, options?: {
|
|
79
|
+
cause?: Error;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare const TRACKING_POLICY_EVENT_TYPES: readonly ["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"];
|
|
84
|
+
type TrackingPolicyEventType = (typeof TRACKING_POLICY_EVENT_TYPES)[number];
|
|
85
|
+
declare const TRACKING_PROVIDERS: readonly ["gtm", "meta", "tiktok"];
|
|
86
|
+
type TrackingProvider = (typeof TRACKING_PROVIDERS)[number];
|
|
87
|
+
declare const GTM_STANDARD_EVENTS: readonly ["page_view", "view_item", "view_item_list", "search", "add_to_cart", "remove_from_cart", "begin_checkout", "purchase"];
|
|
88
|
+
type GtmStandardEventName = (typeof GTM_STANDARD_EVENTS)[number];
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Consent states emitted with browser-side analytics events.
|
|
92
|
+
*/
|
|
93
|
+
type AnalyticsConsentState = "granted" | "denied" | "unknown";
|
|
94
|
+
/**
|
|
95
|
+
* Runtime policies controlling how consent gates browser event dispatch.
|
|
96
|
+
*/
|
|
97
|
+
type AnalyticsDispatchOnUnknownConsent = boolean;
|
|
98
|
+
/**
|
|
99
|
+
* UTM parameters captured for a visitor session.
|
|
100
|
+
*/
|
|
101
|
+
interface AnalyticsUtm {
|
|
102
|
+
schemaVersion: 1;
|
|
103
|
+
source: string | null;
|
|
104
|
+
medium: string | null;
|
|
105
|
+
campaign: string | null;
|
|
106
|
+
term: string | null;
|
|
107
|
+
content: string | null;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Click identifiers captured from ad platforms and passed through analytics events.
|
|
111
|
+
*/
|
|
112
|
+
interface AnalyticsClickIds {
|
|
113
|
+
schemaVersion: 1;
|
|
114
|
+
capturedAt: string | null;
|
|
115
|
+
gclid: string | null;
|
|
116
|
+
gbraid: string | null;
|
|
117
|
+
wbraid: string | null;
|
|
118
|
+
ttclid: string | null;
|
|
119
|
+
fbclid: string | null;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Request context attached to each browser analytics event.
|
|
123
|
+
*/
|
|
124
|
+
interface AnalyticsEventContextPayload {
|
|
125
|
+
schemaVersion: 1;
|
|
126
|
+
path: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Primitive JSON values supported inside analytics properties.
|
|
130
|
+
*/
|
|
131
|
+
type AnalyticsJsonPrimitive = string | number | boolean | null;
|
|
132
|
+
/**
|
|
133
|
+
* Recursive JSON value shape supported by analytics event properties.
|
|
134
|
+
*/
|
|
135
|
+
type AnalyticsJsonValue = AnalyticsJsonPrimitive | AnalyticsJsonValue[] | {
|
|
136
|
+
[key: string]: AnalyticsJsonValue;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Arbitrary analytics event properties sent to ingest and browser adapters.
|
|
140
|
+
*/
|
|
141
|
+
interface AnalyticsProperties {
|
|
142
|
+
[key: string]: AnalyticsJsonValue;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Best-effort browser device fingerprint attached to an analytics event.
|
|
146
|
+
*/
|
|
147
|
+
interface AnalyticsBrowserEventDevice {
|
|
148
|
+
deviceType: string;
|
|
149
|
+
deviceOs: string | null;
|
|
150
|
+
deviceBrowser: string | null;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Canonical browser analytics event shape used by the storefront SDK.
|
|
154
|
+
*/
|
|
155
|
+
interface AnalyticsBrowserEvent {
|
|
156
|
+
schemaVersion: 1;
|
|
157
|
+
eventId: string;
|
|
158
|
+
eventType: TrackingPolicyEventType;
|
|
159
|
+
occurredAt: string;
|
|
160
|
+
sessionId: string;
|
|
161
|
+
visitorId: string;
|
|
162
|
+
customerId: string | null;
|
|
163
|
+
consentState: AnalyticsConsentState;
|
|
164
|
+
context: AnalyticsEventContextPayload;
|
|
165
|
+
referrer: string | null;
|
|
166
|
+
utm: AnalyticsUtm;
|
|
167
|
+
clickIds: AnalyticsClickIds;
|
|
168
|
+
device: AnalyticsBrowserEventDevice;
|
|
169
|
+
properties: AnalyticsProperties;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Consent state payload passed to browser adapters and diagnostics.
|
|
173
|
+
*/
|
|
174
|
+
interface AnalyticsConsentUpdate {
|
|
175
|
+
consentState: AnalyticsConsentState;
|
|
176
|
+
dispatchOnUnknownConsent: AnalyticsDispatchOnUnknownConsent;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Input provided to a browser adapter when dispatching an analytics event.
|
|
180
|
+
*/
|
|
181
|
+
interface AnalyticsAdapterDispatchInput {
|
|
182
|
+
event: AnalyticsBrowserEvent;
|
|
183
|
+
consent: AnalyticsConsentUpdate;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Reasons a browser adapter may skip dispatch instead of throwing.
|
|
187
|
+
*/
|
|
188
|
+
type AnalyticsAdapterSkipReason = "unsupported_event" | "consent_blocked" | "runtime_unavailable";
|
|
189
|
+
/**
|
|
190
|
+
* Structured result returned when a browser adapter intentionally skips dispatch.
|
|
191
|
+
*/
|
|
192
|
+
interface AnalyticsAdapterOperationSkippedResult {
|
|
193
|
+
status: "skipped";
|
|
194
|
+
reason: "runtime_unavailable";
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Result returned by browser adapter dispatch and consent-update hooks.
|
|
198
|
+
*/
|
|
199
|
+
type AnalyticsAdapterOperationResult = void | {
|
|
200
|
+
status: "success";
|
|
201
|
+
} | AnalyticsAdapterOperationSkippedResult;
|
|
202
|
+
/**
|
|
203
|
+
* Browser-side analytics adapter contract for GTM, Meta, TikTok, or custom integrations.
|
|
204
|
+
*/
|
|
205
|
+
interface AnalyticsBrowserAdapter {
|
|
206
|
+
provider: TrackingProvider;
|
|
207
|
+
dispatch(input: AnalyticsAdapterDispatchInput): AnalyticsAdapterOperationResult | Promise<AnalyticsAdapterOperationResult>;
|
|
208
|
+
updateConsent?(input: AnalyticsConsentUpdate): AnalyticsAdapterOperationResult | Promise<AnalyticsAdapterOperationResult>;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Diagnostic events emitted by the analytics runtime for ingest and adapter activity.
|
|
212
|
+
*/
|
|
213
|
+
type AnalyticsDiagnostic = {
|
|
214
|
+
target: "ingest";
|
|
215
|
+
status: "success";
|
|
216
|
+
event: AnalyticsBrowserEvent;
|
|
217
|
+
response: {
|
|
218
|
+
acceptedCount: number;
|
|
219
|
+
duplicateCount: number;
|
|
220
|
+
rejectedCount: number;
|
|
221
|
+
};
|
|
222
|
+
} | {
|
|
223
|
+
target: "ingest";
|
|
224
|
+
status: "error";
|
|
225
|
+
event: AnalyticsBrowserEvent;
|
|
226
|
+
error: Error;
|
|
227
|
+
} | {
|
|
228
|
+
target: "ingest";
|
|
229
|
+
status: "accepted_unknown";
|
|
230
|
+
event: AnalyticsBrowserEvent;
|
|
231
|
+
} | {
|
|
232
|
+
target: "queue";
|
|
233
|
+
status: "enqueued";
|
|
234
|
+
event: AnalyticsBrowserEvent;
|
|
235
|
+
} | {
|
|
236
|
+
target: "queue";
|
|
237
|
+
status: "flushed";
|
|
238
|
+
count: number;
|
|
239
|
+
} | {
|
|
240
|
+
target: "queue";
|
|
241
|
+
status: "evicted_full";
|
|
242
|
+
event: AnalyticsBrowserEvent;
|
|
243
|
+
} | {
|
|
244
|
+
target: "queue";
|
|
245
|
+
status: "evicted_expired";
|
|
246
|
+
eventId: string;
|
|
247
|
+
} | {
|
|
248
|
+
target: "adapter";
|
|
249
|
+
status: "success";
|
|
250
|
+
provider: TrackingProvider;
|
|
251
|
+
event: AnalyticsBrowserEvent;
|
|
252
|
+
} | {
|
|
253
|
+
target: "adapter";
|
|
254
|
+
status: "skipped";
|
|
255
|
+
provider: TrackingProvider;
|
|
256
|
+
event: AnalyticsBrowserEvent;
|
|
257
|
+
reason: AnalyticsAdapterSkipReason;
|
|
258
|
+
} | {
|
|
259
|
+
target: "adapter";
|
|
260
|
+
status: "error";
|
|
261
|
+
provider: TrackingProvider;
|
|
262
|
+
event: AnalyticsBrowserEvent;
|
|
263
|
+
error: Error;
|
|
264
|
+
} | {
|
|
265
|
+
target: "consent_bridge";
|
|
266
|
+
status: "success";
|
|
267
|
+
provider: TrackingProvider;
|
|
268
|
+
consent: AnalyticsConsentUpdate;
|
|
269
|
+
} | {
|
|
270
|
+
target: "consent_bridge";
|
|
271
|
+
status: "skipped";
|
|
272
|
+
provider: TrackingProvider;
|
|
273
|
+
consent: AnalyticsConsentUpdate;
|
|
274
|
+
reason: "runtime_unavailable";
|
|
275
|
+
} | {
|
|
276
|
+
target: "consent_bridge";
|
|
277
|
+
status: "error";
|
|
278
|
+
provider: TrackingProvider;
|
|
279
|
+
consent: AnalyticsConsentUpdate;
|
|
280
|
+
error: Error;
|
|
281
|
+
} | {
|
|
282
|
+
target: "consent";
|
|
283
|
+
status: "error";
|
|
284
|
+
error: Error;
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Optional browser analytics runtime hooks passed to `createStorefrontClient()`.
|
|
288
|
+
*/
|
|
289
|
+
interface StorefrontTrackingRuntimeConfig {
|
|
290
|
+
dispatchOnUnknownConsent?: AnalyticsDispatchOnUnknownConsent;
|
|
291
|
+
resolveConsentState?: () => AnalyticsConsentState | Promise<AnalyticsConsentState>;
|
|
292
|
+
adapters?: AnalyticsBrowserAdapter[];
|
|
293
|
+
onDiagnostic?: (diagnostic: AnalyticsDiagnostic) => void;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Re-export generated GraphQL types once codegen runs
|
|
298
|
+
* For now, define placeholder types that will be replaced
|
|
299
|
+
*/
|
|
300
|
+
interface StorageAdapter {
|
|
301
|
+
get(key: string): string | null;
|
|
302
|
+
set(key: string, value: string): void;
|
|
303
|
+
remove(key: string): void;
|
|
304
|
+
}
|
|
305
|
+
interface StorefrontClientConfig {
|
|
306
|
+
endpoint: string;
|
|
307
|
+
apiKey: string;
|
|
308
|
+
storage?: StorageAdapter;
|
|
309
|
+
cacheTTL?: number;
|
|
310
|
+
/**
|
|
311
|
+
* How long stored landing attribution remains valid, in milliseconds.
|
|
312
|
+
* Defaults to 30 days.
|
|
313
|
+
*/
|
|
314
|
+
trackingAttributionTTL?: number;
|
|
315
|
+
/**
|
|
316
|
+
* Deprecated. Pass runtime analytics hooks to `client.init({ analytics: ... })`.
|
|
317
|
+
*/
|
|
318
|
+
tracking?: StorefrontTrackingRuntimeConfig;
|
|
319
|
+
}
|
|
320
|
+
interface StorefrontAnalyticsInitConfig extends StorefrontTrackingRuntimeConfig {
|
|
321
|
+
stripUrl?: boolean;
|
|
322
|
+
}
|
|
323
|
+
interface StorefrontInitOptions {
|
|
324
|
+
analytics?: StorefrontAnalyticsInitConfig;
|
|
325
|
+
}
|
|
326
|
+
interface ResolvedStorefrontAnalyticsConfig {
|
|
327
|
+
enabled: boolean;
|
|
328
|
+
dispatchOnUnknownConsent: boolean;
|
|
329
|
+
gtm: {
|
|
330
|
+
enabled: boolean;
|
|
331
|
+
containerId: string | null;
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
interface ResolvedStorefrontInitConfig {
|
|
335
|
+
analytics: ResolvedStorefrontAnalyticsConfig;
|
|
336
|
+
}
|
|
337
|
+
interface PageInfo {
|
|
338
|
+
hasNextPage: boolean;
|
|
339
|
+
hasPreviousPage: boolean;
|
|
340
|
+
startCursor: string | null;
|
|
341
|
+
endCursor: string | null;
|
|
342
|
+
}
|
|
343
|
+
interface PaginatedResult<T> {
|
|
344
|
+
items: T[];
|
|
345
|
+
pageInfo: PageInfo;
|
|
346
|
+
}
|
|
347
|
+
type StorefrontResult<T> = Result<T, StorefrontError>;
|
|
348
|
+
type WeightUnit = "g" | "kg" | "lb" | "oz";
|
|
349
|
+
interface ProductOptionValue {
|
|
350
|
+
id: string;
|
|
351
|
+
value: string;
|
|
352
|
+
position: number;
|
|
353
|
+
}
|
|
354
|
+
interface ProductOption {
|
|
355
|
+
id: string;
|
|
356
|
+
name: string;
|
|
357
|
+
position: number;
|
|
358
|
+
values: ProductOptionValue[];
|
|
359
|
+
}
|
|
360
|
+
interface ProductImage {
|
|
361
|
+
id: string;
|
|
362
|
+
url: string;
|
|
363
|
+
altText: string | null;
|
|
364
|
+
position: number;
|
|
365
|
+
}
|
|
366
|
+
interface QuantityPricingTier {
|
|
367
|
+
minQuantity: number;
|
|
368
|
+
price: number;
|
|
369
|
+
}
|
|
370
|
+
interface ProductVariant {
|
|
371
|
+
id: string;
|
|
372
|
+
title: string;
|
|
373
|
+
sku: string | null;
|
|
374
|
+
price: number;
|
|
375
|
+
compareAtPrice: number | null;
|
|
376
|
+
weight: number | null;
|
|
377
|
+
weightUnit: WeightUnit;
|
|
378
|
+
requiresShipping: boolean;
|
|
379
|
+
availableForSale: boolean;
|
|
380
|
+
quantity: number;
|
|
381
|
+
selectedOptions: ProductOptionValue[];
|
|
382
|
+
image: ProductImage | null;
|
|
383
|
+
isOnSale: boolean;
|
|
384
|
+
quantityPricing: QuantityPricingTier[];
|
|
385
|
+
}
|
|
386
|
+
interface Category {
|
|
387
|
+
id: string;
|
|
388
|
+
name: string;
|
|
389
|
+
handle: string;
|
|
390
|
+
description: string | null;
|
|
391
|
+
metaTitle: string | null;
|
|
392
|
+
metaDescription: string | null;
|
|
393
|
+
imageAsset: {
|
|
394
|
+
url: string;
|
|
395
|
+
altText: string | null;
|
|
396
|
+
width: number | null;
|
|
397
|
+
height: number | null;
|
|
398
|
+
} | null;
|
|
399
|
+
parent: Category | null;
|
|
400
|
+
children: Category[];
|
|
401
|
+
ancestors: Category[];
|
|
402
|
+
productCount: number;
|
|
403
|
+
}
|
|
404
|
+
interface FlatCategory {
|
|
405
|
+
id: string;
|
|
406
|
+
name: string;
|
|
407
|
+
handle: string;
|
|
408
|
+
description: string | null;
|
|
409
|
+
metaTitle: string | null;
|
|
410
|
+
metaDescription: string | null;
|
|
411
|
+
imageUrl: string | null;
|
|
412
|
+
parentId: string | null;
|
|
413
|
+
depth: number;
|
|
414
|
+
hasChildren: boolean;
|
|
415
|
+
productCount: number;
|
|
416
|
+
}
|
|
417
|
+
interface Tag {
|
|
418
|
+
id: string;
|
|
419
|
+
name: string;
|
|
420
|
+
}
|
|
421
|
+
type SectionType = "RICH_TEXT" | "BULLET_LIST" | "TABLE";
|
|
422
|
+
type DisplayIntent = "ACCORDION" | "SPECIFICATIONS" | "BOTH";
|
|
423
|
+
interface DetailSectionBase {
|
|
424
|
+
id: string;
|
|
425
|
+
title: string;
|
|
426
|
+
displayIntent: DisplayIntent;
|
|
427
|
+
position: number;
|
|
428
|
+
}
|
|
429
|
+
interface RichTextDetailSection extends DetailSectionBase {
|
|
430
|
+
sectionType: "RICH_TEXT";
|
|
431
|
+
content: {
|
|
432
|
+
html: string;
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
interface BulletListDetailSection extends DetailSectionBase {
|
|
436
|
+
sectionType: "BULLET_LIST";
|
|
437
|
+
content: {
|
|
438
|
+
items: string[];
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
interface TableDetailSection extends DetailSectionBase {
|
|
442
|
+
sectionType: "TABLE";
|
|
443
|
+
content: {
|
|
444
|
+
rows: [string, string][];
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
type DetailSection = RichTextDetailSection | BulletListDetailSection | TableDetailSection;
|
|
448
|
+
interface Product {
|
|
449
|
+
id: string;
|
|
450
|
+
handle: string;
|
|
451
|
+
title: string;
|
|
452
|
+
description: string | null;
|
|
453
|
+
vendor: string | null;
|
|
454
|
+
productType: string | null;
|
|
455
|
+
metaTitle: string | null;
|
|
456
|
+
metaDescription: string | null;
|
|
457
|
+
publishedAt: string | null;
|
|
458
|
+
createdAt: string;
|
|
459
|
+
availableForSale: boolean;
|
|
460
|
+
media: ProductImage[];
|
|
461
|
+
options: ProductOption[];
|
|
462
|
+
variants: ProductVariant[];
|
|
463
|
+
categories: Category[];
|
|
464
|
+
primaryCategory: Category | null;
|
|
465
|
+
tags: Tag[];
|
|
466
|
+
detailSections: DetailSection[];
|
|
467
|
+
}
|
|
468
|
+
type ProductSortKey = "CREATED_AT" | "TITLE" | "PRICE_ASC" | "PRICE_DESC" | "BEST_SELLING";
|
|
469
|
+
interface ProductFilter {
|
|
470
|
+
search?: string | null;
|
|
471
|
+
categoryHandle?: string | null;
|
|
472
|
+
categoryId?: string | null;
|
|
473
|
+
includeDescendants?: boolean | null;
|
|
474
|
+
collectionHandle?: string | null;
|
|
475
|
+
collectionId?: string | null;
|
|
476
|
+
tags?: string[] | null;
|
|
477
|
+
vendor?: string | null;
|
|
478
|
+
productType?: string | null;
|
|
479
|
+
minPrice?: number | null;
|
|
480
|
+
maxPrice?: number | null;
|
|
481
|
+
availableForSale?: boolean | null;
|
|
482
|
+
}
|
|
483
|
+
type CollectionType = "manual" | "intelligent";
|
|
484
|
+
type CollectionSortOrder = "manual" | "best_selling" | "newest" | "price_asc" | "price_desc";
|
|
485
|
+
interface Collection {
|
|
486
|
+
id: string;
|
|
487
|
+
handle: string;
|
|
488
|
+
title: string;
|
|
489
|
+
description: string | null;
|
|
490
|
+
type: CollectionType;
|
|
491
|
+
sortOrder: CollectionSortOrder;
|
|
492
|
+
metaTitle: string | null;
|
|
493
|
+
metaDescription: string | null;
|
|
494
|
+
productCount: number;
|
|
495
|
+
imageAsset: {
|
|
496
|
+
url: string;
|
|
497
|
+
altText: string | null;
|
|
498
|
+
width: number | null;
|
|
499
|
+
height: number | null;
|
|
500
|
+
} | null;
|
|
501
|
+
}
|
|
502
|
+
interface CartItem {
|
|
503
|
+
id: string;
|
|
504
|
+
variantId: string;
|
|
505
|
+
quantity: number;
|
|
506
|
+
priceAtAdd: number;
|
|
507
|
+
effectiveUnitPrice: number;
|
|
508
|
+
lineTotal: number;
|
|
509
|
+
taxAmount: number;
|
|
510
|
+
variant: ProductVariant | null;
|
|
511
|
+
}
|
|
512
|
+
type CartStatus = "active" | "checkout" | "converted" | "expired";
|
|
513
|
+
interface AppliedPromoCode {
|
|
514
|
+
code: string;
|
|
515
|
+
discountType: string;
|
|
516
|
+
discountAmount: number;
|
|
517
|
+
description: string;
|
|
518
|
+
}
|
|
519
|
+
interface AppliedDiscount {
|
|
520
|
+
promotionId: string;
|
|
521
|
+
discountClass: string;
|
|
522
|
+
discountType: string;
|
|
523
|
+
discountAmount: number;
|
|
524
|
+
description: string;
|
|
525
|
+
isAutomatic: boolean;
|
|
526
|
+
}
|
|
527
|
+
interface Cart {
|
|
528
|
+
id: string;
|
|
529
|
+
token: string;
|
|
530
|
+
status: CartStatus;
|
|
531
|
+
items: CartItem[];
|
|
532
|
+
totalItems: number;
|
|
533
|
+
totalPrice: number;
|
|
534
|
+
taxTotal: number;
|
|
535
|
+
shippingTotal: number;
|
|
536
|
+
total: number;
|
|
537
|
+
discountTotal: number;
|
|
538
|
+
appliedPromoCode: AppliedPromoCode | null;
|
|
539
|
+
appliedDiscounts: AppliedDiscount[];
|
|
540
|
+
customerEmail: string | null;
|
|
541
|
+
customerPhone: string | null;
|
|
542
|
+
shippingAddress: Address | null;
|
|
543
|
+
billingAddress: Address | null;
|
|
544
|
+
notes: string | null;
|
|
545
|
+
paymentMethod: string | null;
|
|
546
|
+
shippingRateId: string | null;
|
|
547
|
+
checkoutStartedAt?: string | null;
|
|
548
|
+
checkoutExpiresAt?: string | null;
|
|
549
|
+
createdAt: string;
|
|
550
|
+
updatedAt: string;
|
|
551
|
+
}
|
|
552
|
+
interface Address {
|
|
553
|
+
firstName: string | null;
|
|
554
|
+
lastName: string | null;
|
|
555
|
+
company: string | null;
|
|
556
|
+
addressLine1: string;
|
|
557
|
+
addressLine2: string | null;
|
|
558
|
+
city: string;
|
|
559
|
+
province: string | null;
|
|
560
|
+
provinceCode: string | null;
|
|
561
|
+
country: string;
|
|
562
|
+
countryCode: string;
|
|
563
|
+
zip: string;
|
|
564
|
+
phone: string | null;
|
|
565
|
+
}
|
|
566
|
+
interface CheckoutData {
|
|
567
|
+
email?: string;
|
|
568
|
+
phone?: string;
|
|
569
|
+
shippingAddress?: Address;
|
|
570
|
+
billingAddress?: Address;
|
|
571
|
+
notes?: string;
|
|
572
|
+
emailMarketingConsent?: boolean | null;
|
|
573
|
+
paymentMethod?: string;
|
|
574
|
+
shippingRateId?: string;
|
|
575
|
+
}
|
|
576
|
+
interface ShippingRate {
|
|
577
|
+
id: string;
|
|
578
|
+
name: string;
|
|
579
|
+
price: number;
|
|
580
|
+
minOrderAmount: number | null;
|
|
581
|
+
estimatedDaysMin: number | null;
|
|
582
|
+
estimatedDaysMax: number | null;
|
|
583
|
+
isFree: boolean;
|
|
584
|
+
}
|
|
585
|
+
interface AvailablePaymentMethod {
|
|
586
|
+
method: string;
|
|
587
|
+
displayName: string;
|
|
588
|
+
additionalFee: number;
|
|
589
|
+
}
|
|
590
|
+
interface SocialLinks {
|
|
591
|
+
instagram?: string;
|
|
592
|
+
facebook?: string;
|
|
593
|
+
tiktok?: string;
|
|
594
|
+
twitter?: string;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Public GTM settings returned by the storefront `store` query.
|
|
598
|
+
*/
|
|
599
|
+
interface GtmBrowserTrackingConfig {
|
|
600
|
+
enabled: boolean;
|
|
601
|
+
containerId: string | null;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Browser-side tracking configuration returned by the storefront `store` query.
|
|
605
|
+
*/
|
|
606
|
+
interface BrowserTrackingConfig {
|
|
607
|
+
gtm: GtmBrowserTrackingConfig;
|
|
608
|
+
}
|
|
609
|
+
interface StoreAnalyticsConfig {
|
|
610
|
+
enabled: boolean;
|
|
611
|
+
dispatchOnUnknownConsent: boolean;
|
|
612
|
+
gtm: GtmBrowserTrackingConfig;
|
|
613
|
+
}
|
|
614
|
+
interface Store {
|
|
615
|
+
id: string;
|
|
616
|
+
name: string;
|
|
617
|
+
slug: string;
|
|
618
|
+
description: string | null;
|
|
619
|
+
currency: string;
|
|
620
|
+
timezone: string;
|
|
621
|
+
logoUrl: string | null;
|
|
622
|
+
contactEmail: string | null;
|
|
623
|
+
contactPhone: string | null;
|
|
624
|
+
trackingDispatchOnUnknownConsent: boolean;
|
|
625
|
+
browserTrackingConfig: BrowserTrackingConfig;
|
|
626
|
+
analytics: StoreAnalyticsConfig;
|
|
627
|
+
socialLinks: SocialLinks;
|
|
628
|
+
}
|
|
629
|
+
interface PaymentInstructions {
|
|
630
|
+
bankAccount: string;
|
|
631
|
+
recipientName: string;
|
|
632
|
+
referenceNumber: string;
|
|
633
|
+
ipsQrCodeBase64: string;
|
|
634
|
+
expiresAt: string;
|
|
635
|
+
}
|
|
636
|
+
interface OrderItem {
|
|
637
|
+
id: string;
|
|
638
|
+
productTitle: string;
|
|
639
|
+
variantTitle: string | null;
|
|
640
|
+
sku: string | null;
|
|
641
|
+
quantity: number;
|
|
642
|
+
unitPrice: number;
|
|
643
|
+
totalPrice: number;
|
|
644
|
+
}
|
|
645
|
+
interface Order {
|
|
646
|
+
id: string;
|
|
647
|
+
orderNumber: string;
|
|
648
|
+
email: string | null;
|
|
649
|
+
phone: string | null;
|
|
650
|
+
status: string;
|
|
651
|
+
shippingAddress: Address | null;
|
|
652
|
+
subtotal: number;
|
|
653
|
+
total: number;
|
|
654
|
+
note: string | null;
|
|
655
|
+
items: OrderItem[];
|
|
656
|
+
paymentInstructions: PaymentInstructions | null;
|
|
657
|
+
createdAt: string;
|
|
658
|
+
}
|
|
659
|
+
interface Customer {
|
|
660
|
+
id: string;
|
|
661
|
+
name: string | null;
|
|
662
|
+
email: string;
|
|
663
|
+
emailVerified: boolean;
|
|
664
|
+
}
|
|
665
|
+
interface CustomerAddress {
|
|
666
|
+
id: string;
|
|
667
|
+
label: string | null;
|
|
668
|
+
firstName: string | null;
|
|
669
|
+
lastName: string | null;
|
|
670
|
+
addressLine1: string;
|
|
671
|
+
addressLine2: string | null;
|
|
672
|
+
city: string;
|
|
673
|
+
zip: string | null;
|
|
674
|
+
phone: string | null;
|
|
675
|
+
isDefault: boolean;
|
|
676
|
+
createdAt: string;
|
|
677
|
+
}
|
|
678
|
+
interface CustomerAddressInput {
|
|
679
|
+
label?: string;
|
|
680
|
+
firstName?: string;
|
|
681
|
+
lastName?: string;
|
|
682
|
+
addressLine1: string;
|
|
683
|
+
addressLine2?: string;
|
|
684
|
+
city: string;
|
|
685
|
+
zip?: string;
|
|
686
|
+
phone?: string;
|
|
687
|
+
isDefault?: boolean;
|
|
688
|
+
}
|
|
689
|
+
interface CustomerAddressUpdateInput {
|
|
690
|
+
label?: string;
|
|
691
|
+
firstName?: string;
|
|
692
|
+
lastName?: string;
|
|
693
|
+
addressLine1?: string;
|
|
694
|
+
addressLine2?: string;
|
|
695
|
+
city?: string;
|
|
696
|
+
zip?: string;
|
|
697
|
+
phone?: string;
|
|
698
|
+
isDefault?: boolean;
|
|
699
|
+
}
|
|
700
|
+
interface CustomerUpdateInput {
|
|
701
|
+
name?: string;
|
|
702
|
+
email?: string;
|
|
703
|
+
currentPassword?: string;
|
|
704
|
+
newPassword?: string;
|
|
705
|
+
}
|
|
706
|
+
interface CustomerOrderItem {
|
|
707
|
+
id: string;
|
|
708
|
+
productTitle: string;
|
|
709
|
+
variantTitle: string | null;
|
|
710
|
+
sku: string | null;
|
|
711
|
+
quantity: number;
|
|
712
|
+
unitPrice: number;
|
|
713
|
+
totalPrice: number;
|
|
714
|
+
}
|
|
715
|
+
interface CustomerOrder {
|
|
716
|
+
id: string;
|
|
717
|
+
orderNumber: string;
|
|
718
|
+
status: string;
|
|
719
|
+
email: string;
|
|
720
|
+
phone: string | null;
|
|
721
|
+
subtotal: number;
|
|
722
|
+
total: number;
|
|
723
|
+
note: string | null;
|
|
724
|
+
items: CustomerOrderItem[];
|
|
725
|
+
createdAt: string;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
interface AccountOperations {
|
|
729
|
+
/**
|
|
730
|
+
* Fetch paginated orders for the authenticated customer.
|
|
731
|
+
*
|
|
732
|
+
* @param args - Forward or backward pagination options.
|
|
733
|
+
* @returns Paginated customer orders.
|
|
734
|
+
*/
|
|
735
|
+
orders(args?: {
|
|
736
|
+
first?: number;
|
|
737
|
+
after?: string;
|
|
738
|
+
last?: number;
|
|
739
|
+
before?: string;
|
|
740
|
+
}): Promise<Result<PaginatedResult<CustomerOrder>, StorefrontError>>;
|
|
741
|
+
/**
|
|
742
|
+
* Fetch saved addresses for the authenticated customer.
|
|
743
|
+
*
|
|
744
|
+
* @returns Customer addresses.
|
|
745
|
+
*/
|
|
746
|
+
addresses(): Promise<Result<CustomerAddress[], StorefrontError>>;
|
|
747
|
+
/**
|
|
748
|
+
* Create a saved customer address.
|
|
749
|
+
*
|
|
750
|
+
* @param input - Address fields to create.
|
|
751
|
+
* @returns The created address.
|
|
752
|
+
*/
|
|
753
|
+
createAddress(input: CustomerAddressInput): Promise<Result<CustomerAddress, StorefrontError>>;
|
|
754
|
+
/**
|
|
755
|
+
* Update a saved customer address.
|
|
756
|
+
*
|
|
757
|
+
* @param addressId - Address identifier to update.
|
|
758
|
+
* @param input - Address fields to change.
|
|
759
|
+
* @returns The updated address.
|
|
760
|
+
*/
|
|
761
|
+
updateAddress(addressId: string, input: CustomerAddressUpdateInput): Promise<Result<CustomerAddress, StorefrontError>>;
|
|
762
|
+
/**
|
|
763
|
+
* Delete a saved customer address.
|
|
764
|
+
*
|
|
765
|
+
* @param addressId - Address identifier to delete.
|
|
766
|
+
* @returns The deleted address identifier.
|
|
767
|
+
*/
|
|
768
|
+
deleteAddress(addressId: string): Promise<Result<string, StorefrontError>>;
|
|
769
|
+
/**
|
|
770
|
+
* Update the authenticated customer's profile fields.
|
|
771
|
+
*
|
|
772
|
+
* @param input - Customer fields to update.
|
|
773
|
+
* @returns The updated customer profile.
|
|
774
|
+
*/
|
|
775
|
+
update(input: CustomerUpdateInput): Promise<Result<Customer, StorefrontError>>;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
interface AuthOperations {
|
|
779
|
+
/**
|
|
780
|
+
* Register a customer account and store the returned auth token.
|
|
781
|
+
*
|
|
782
|
+
* @param input - Registration credentials and optional name.
|
|
783
|
+
* @returns The authenticated customer and token.
|
|
784
|
+
*/
|
|
785
|
+
register(input: {
|
|
786
|
+
email: string;
|
|
787
|
+
password: string;
|
|
788
|
+
name?: string;
|
|
789
|
+
}): Promise<Result<{
|
|
790
|
+
customer: Customer;
|
|
791
|
+
token: string;
|
|
792
|
+
}, StorefrontError>>;
|
|
793
|
+
/**
|
|
794
|
+
* Log in an existing customer and store the returned auth token.
|
|
795
|
+
*
|
|
796
|
+
* @param input - Customer login credentials.
|
|
797
|
+
* @returns The authenticated customer and token.
|
|
798
|
+
*/
|
|
799
|
+
login(input: {
|
|
800
|
+
email: string;
|
|
801
|
+
password: string;
|
|
802
|
+
}): Promise<Result<{
|
|
803
|
+
customer: Customer;
|
|
804
|
+
token: string;
|
|
805
|
+
}, StorefrontError>>;
|
|
806
|
+
/**
|
|
807
|
+
* Remove the stored customer auth token.
|
|
808
|
+
*/
|
|
809
|
+
logout(): void;
|
|
810
|
+
/**
|
|
811
|
+
* Request a password reset email for a customer account.
|
|
812
|
+
*
|
|
813
|
+
* @param email - Customer email address.
|
|
814
|
+
* @returns Reset request success state.
|
|
815
|
+
*/
|
|
816
|
+
requestPasswordReset(email: string): Promise<Result<{
|
|
817
|
+
success: boolean;
|
|
818
|
+
}, StorefrontError>>;
|
|
819
|
+
/**
|
|
820
|
+
* Reset a customer password with a reset token.
|
|
821
|
+
*
|
|
822
|
+
* @param input - Reset token and new password.
|
|
823
|
+
* @returns Reset success state.
|
|
824
|
+
*/
|
|
825
|
+
resetPassword(input: {
|
|
826
|
+
token: string;
|
|
827
|
+
newPassword: string;
|
|
828
|
+
}): Promise<Result<{
|
|
829
|
+
success: boolean;
|
|
830
|
+
}, StorefrontError>>;
|
|
831
|
+
/**
|
|
832
|
+
* Verify a customer email address with a verification token.
|
|
833
|
+
*
|
|
834
|
+
* @param token - Verification token from email.
|
|
835
|
+
* @returns The verified customer.
|
|
836
|
+
*/
|
|
837
|
+
verifyEmail(token: string): Promise<Result<Customer, StorefrontError>>;
|
|
838
|
+
/**
|
|
839
|
+
* Fetch the currently authenticated customer.
|
|
840
|
+
*
|
|
841
|
+
* @returns The signed-in customer, or `null` when unauthenticated.
|
|
842
|
+
*/
|
|
843
|
+
me(): Promise<Result<Customer | null, StorefrontError>>;
|
|
844
|
+
/**
|
|
845
|
+
* Check whether a customer token is currently stored.
|
|
846
|
+
*
|
|
847
|
+
* @returns `true` when a customer session exists.
|
|
848
|
+
*/
|
|
849
|
+
isLoggedIn(): boolean;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
interface CartOperations {
|
|
853
|
+
/**
|
|
854
|
+
* Load the current cart from the stored cart token.
|
|
855
|
+
*
|
|
856
|
+
* @returns The current cart, or `null` when no cart exists.
|
|
857
|
+
*/
|
|
858
|
+
get(): Promise<Result<Cart | null, StorefrontError>>;
|
|
859
|
+
/**
|
|
860
|
+
* Create a new active cart and persist its token.
|
|
861
|
+
*
|
|
862
|
+
* @returns The newly created cart.
|
|
863
|
+
*/
|
|
864
|
+
create(): Promise<Result<Cart, StorefrontError>>;
|
|
865
|
+
/**
|
|
866
|
+
* Add a product variant to the active cart.
|
|
867
|
+
*
|
|
868
|
+
* @param variantId - Product variant GID (global ID).
|
|
869
|
+
* @param quantity - Quantity to add.
|
|
870
|
+
* @returns The updated cart.
|
|
871
|
+
*/
|
|
872
|
+
addItem(variantId: string, quantity: number): Promise<Result<Cart, StorefrontError>>;
|
|
873
|
+
/**
|
|
874
|
+
* Update the quantity of an existing cart item.
|
|
875
|
+
*
|
|
876
|
+
* @param variantId - Product variant GID (global ID).
|
|
877
|
+
* @param quantity - New quantity for the item.
|
|
878
|
+
* @returns The updated cart.
|
|
879
|
+
*/
|
|
880
|
+
updateItem(variantId: string, quantity: number): Promise<Result<Cart, StorefrontError>>;
|
|
881
|
+
/**
|
|
882
|
+
* Remove a product variant from the cart.
|
|
883
|
+
*
|
|
884
|
+
* @param variantId - Product variant GID (global ID).
|
|
885
|
+
* @returns The updated cart.
|
|
886
|
+
*/
|
|
887
|
+
removeItem(variantId: string): Promise<Result<Cart, StorefrontError>>;
|
|
888
|
+
/**
|
|
889
|
+
* Remove all items from the active cart.
|
|
890
|
+
*
|
|
891
|
+
* @returns The emptied cart.
|
|
892
|
+
*/
|
|
893
|
+
clear(): Promise<Result<Cart, StorefrontError>>;
|
|
894
|
+
/**
|
|
895
|
+
* Apply a promo code to the active cart.
|
|
896
|
+
*
|
|
897
|
+
* @param code - Promo code to validate and apply.
|
|
898
|
+
* @returns The updated cart with discount data.
|
|
899
|
+
*/
|
|
900
|
+
applyPromoCode(code: string): Promise<Result<Cart, StorefrontError>>;
|
|
901
|
+
/**
|
|
902
|
+
* Remove the currently applied promo code from the cart.
|
|
903
|
+
*
|
|
904
|
+
* @returns The updated cart.
|
|
905
|
+
*/
|
|
906
|
+
removePromoCode(): Promise<Result<Cart, StorefrontError>>;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
interface CheckoutOperations {
|
|
910
|
+
/**
|
|
911
|
+
* Start checkout for the current active cart.
|
|
912
|
+
*
|
|
913
|
+
* @returns The cart in checkout state.
|
|
914
|
+
*/
|
|
915
|
+
start(): Promise<Result<Cart, StorefrontError>>;
|
|
916
|
+
/**
|
|
917
|
+
* Update checkout customer, shipping, and payment details.
|
|
918
|
+
*
|
|
919
|
+
* @param data - Checkout fields to update.
|
|
920
|
+
* @returns The updated checkout cart.
|
|
921
|
+
*/
|
|
922
|
+
update(data: CheckoutData): Promise<Result<Cart, StorefrontError>>;
|
|
923
|
+
/**
|
|
924
|
+
* Complete checkout and convert the cart into an order.
|
|
925
|
+
*
|
|
926
|
+
* @returns The created order.
|
|
927
|
+
*/
|
|
928
|
+
complete(): Promise<Result<Order, StorefrontError>>;
|
|
929
|
+
/**
|
|
930
|
+
* Abandon checkout and return the cart to an active state.
|
|
931
|
+
*
|
|
932
|
+
* @returns The reactivated cart.
|
|
933
|
+
*/
|
|
934
|
+
abandon(): Promise<Result<Cart, StorefrontError>>;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
interface CollectionsListOptions {
|
|
938
|
+
first?: number;
|
|
939
|
+
after?: string;
|
|
940
|
+
search?: string;
|
|
941
|
+
}
|
|
942
|
+
type CollectionProductSort = "manual" | "best_selling" | "newest" | "price_asc" | "price_desc";
|
|
943
|
+
interface CollectionProductsOptions {
|
|
944
|
+
first?: number;
|
|
945
|
+
after?: string;
|
|
946
|
+
sort?: CollectionProductSort;
|
|
947
|
+
}
|
|
948
|
+
interface CollectionsOperations {
|
|
949
|
+
/**
|
|
950
|
+
* List collections with cursor pagination and optional search.
|
|
951
|
+
*
|
|
952
|
+
* @param options - Pagination and search options.
|
|
953
|
+
* @returns Paginated storefront collections.
|
|
954
|
+
*/
|
|
955
|
+
list(options?: CollectionsListOptions): Promise<Result<PaginatedResult<Collection>, StorefrontError>>;
|
|
956
|
+
/**
|
|
957
|
+
* Fetch a single collection by GID or handle.
|
|
958
|
+
*
|
|
959
|
+
* @param idOrHandle - Collection GID or handle.
|
|
960
|
+
* @returns The matching collection.
|
|
961
|
+
*/
|
|
962
|
+
get(idOrHandle: string): Promise<Result<Collection, StorefrontError>>;
|
|
963
|
+
/**
|
|
964
|
+
* Fetch products that belong to a collection.
|
|
965
|
+
*
|
|
966
|
+
* @param idOrHandle - Collection GID or handle.
|
|
967
|
+
* @param options - Pagination and collection product options.
|
|
968
|
+
* @returns Paginated products for the collection.
|
|
969
|
+
*/
|
|
970
|
+
getProducts(idOrHandle: string, options?: CollectionProductsOptions): Promise<Result<PaginatedResult<Product>, StorefrontError>>;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
interface GraphQLRequest {
|
|
974
|
+
query: string;
|
|
975
|
+
variables?: Record<string, unknown>;
|
|
976
|
+
operationName?: string;
|
|
977
|
+
}
|
|
978
|
+
interface GraphQLResponse<T = unknown> {
|
|
979
|
+
data?: T;
|
|
980
|
+
errors?: Array<{
|
|
981
|
+
message: string;
|
|
982
|
+
path?: readonly (string | number)[];
|
|
983
|
+
}>;
|
|
984
|
+
}
|
|
985
|
+
interface GraphQLClient {
|
|
986
|
+
query<T>(request: GraphQLRequest, options?: {
|
|
987
|
+
cache?: boolean;
|
|
988
|
+
}): Promise<Result<T, StorefrontError>>;
|
|
989
|
+
mutate<T>(request: GraphQLRequest): Promise<Result<T, StorefrontError>>;
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Extract userErrors from mutation result and convert to ValidationError if present
|
|
993
|
+
*/
|
|
994
|
+
declare function extractUserErrors<T extends {
|
|
995
|
+
userErrors?: Array<{
|
|
996
|
+
field: string | null;
|
|
997
|
+
message: string;
|
|
998
|
+
}>;
|
|
999
|
+
}>(data: T, fieldName: keyof T): Result<Exclude<T[keyof T], undefined>, ValidationError>;
|
|
1000
|
+
|
|
1001
|
+
interface PaymentsOperations {
|
|
1002
|
+
/**
|
|
1003
|
+
* Fetch payment methods currently available for checkout.
|
|
1004
|
+
*
|
|
1005
|
+
* @returns Available storefront payment methods.
|
|
1006
|
+
*/
|
|
1007
|
+
getAvailableMethods(): Promise<Result<AvailablePaymentMethod[], StorefrontError>>;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
interface ProductsListOptions {
|
|
1011
|
+
first?: number;
|
|
1012
|
+
after?: string;
|
|
1013
|
+
filter?: ProductFilter;
|
|
1014
|
+
sort?: ProductSortKey;
|
|
1015
|
+
}
|
|
1016
|
+
interface ProductsOperations {
|
|
1017
|
+
/**
|
|
1018
|
+
* List products with cursor pagination and optional filters.
|
|
1019
|
+
*
|
|
1020
|
+
* @param options - Pagination, search, and sort options.
|
|
1021
|
+
* @returns Paginated storefront products.
|
|
1022
|
+
*/
|
|
1023
|
+
list(options?: ProductsListOptions): Promise<Result<PaginatedResult<Product>, StorefrontError>>;
|
|
1024
|
+
/**
|
|
1025
|
+
* Fetch a single product by GID or handle.
|
|
1026
|
+
*
|
|
1027
|
+
* @param idOrHandle - Product GID or handle.
|
|
1028
|
+
* @returns The matching product.
|
|
1029
|
+
*/
|
|
1030
|
+
get(idOrHandle: string): Promise<Result<Product, StorefrontError>>;
|
|
1031
|
+
/**
|
|
1032
|
+
* Fetch multiple products by handle in request order.
|
|
1033
|
+
*
|
|
1034
|
+
* @param handles - Product handles to resolve.
|
|
1035
|
+
* @returns Products for each requested handle, with `null` for missing entries.
|
|
1036
|
+
*/
|
|
1037
|
+
getByHandles(handles: string[]): Promise<Result<(Product | null)[], StorefrontError>>;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
interface AnalyticsInitOptions {
|
|
1041
|
+
stripUrl?: boolean;
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Checkout step identifiers for `checkout_step_completed` analytics events.
|
|
1045
|
+
*/
|
|
1046
|
+
type CheckoutStep = "contact" | "shipping" | "payment" | "review";
|
|
1047
|
+
/**
|
|
1048
|
+
* Canonical analytics event type values accepted by the storefront ingest endpoint.
|
|
1049
|
+
*/
|
|
1050
|
+
type AnalyticsEventType = TrackingPolicyEventType;
|
|
1051
|
+
/**
|
|
1052
|
+
* Supported preset event names accepted by `track()`.
|
|
1053
|
+
*/
|
|
1054
|
+
type AnalyticsPresetEventName = "page_view" | "product_view" | "collection_view" | "search_performed" | "add_to_cart" | "remove_from_cart" | "checkout_started" | "checkout_step_completed" | "checkout_completed";
|
|
1055
|
+
/**
|
|
1056
|
+
* Event name accepted by `track()`.
|
|
1057
|
+
* Preset names (e.g. `product_view`) are normalized to `analytics.*` types.
|
|
1058
|
+
* Unknown names are sent as `analytics.custom` with `{ eventName: <name> }`.
|
|
1059
|
+
*/
|
|
1060
|
+
type AnalyticsTrackEventName = AnalyticsPresetEventName | AnalyticsEventType;
|
|
1061
|
+
type PresetEventProperties = {
|
|
1062
|
+
page_view: Record<string, never>;
|
|
1063
|
+
product_view: {
|
|
1064
|
+
productId: string;
|
|
1065
|
+
variantId?: string | null;
|
|
1066
|
+
};
|
|
1067
|
+
collection_view: {
|
|
1068
|
+
collectionId: string;
|
|
1069
|
+
};
|
|
1070
|
+
search_performed: {
|
|
1071
|
+
query: string;
|
|
1072
|
+
resultsCount: number;
|
|
1073
|
+
};
|
|
1074
|
+
add_to_cart: {
|
|
1075
|
+
cartId: string;
|
|
1076
|
+
quantity: number;
|
|
1077
|
+
itemsCount: number;
|
|
1078
|
+
cartValue: number;
|
|
1079
|
+
};
|
|
1080
|
+
remove_from_cart: {
|
|
1081
|
+
cartId: string;
|
|
1082
|
+
quantity: number;
|
|
1083
|
+
itemsCount: number;
|
|
1084
|
+
cartValue: number;
|
|
1085
|
+
};
|
|
1086
|
+
checkout_started: {
|
|
1087
|
+
cartId: string;
|
|
1088
|
+
};
|
|
1089
|
+
checkout_step_completed: {
|
|
1090
|
+
cartId: string;
|
|
1091
|
+
step: CheckoutStep;
|
|
1092
|
+
};
|
|
1093
|
+
checkout_completed: {
|
|
1094
|
+
orderId: string;
|
|
1095
|
+
cartId: string;
|
|
1096
|
+
orderTotal: number;
|
|
1097
|
+
};
|
|
1098
|
+
};
|
|
1099
|
+
type PresetPropertiesByName<T extends AnalyticsPresetEventName> = PresetEventProperties[T];
|
|
1100
|
+
/**
|
|
1101
|
+
* Optional context overrides for a tracking call.
|
|
1102
|
+
*/
|
|
1103
|
+
interface AnalyticsContext {
|
|
1104
|
+
path?: string;
|
|
1105
|
+
referrer?: string | null;
|
|
1106
|
+
occurredAt?: Date | string;
|
|
1107
|
+
sessionId?: string;
|
|
1108
|
+
visitorId?: string;
|
|
1109
|
+
customerId?: string | null;
|
|
1110
|
+
utmSource?: string | null;
|
|
1111
|
+
utmMedium?: string | null;
|
|
1112
|
+
utmCampaign?: string | null;
|
|
1113
|
+
utmTerm?: string | null;
|
|
1114
|
+
utmContent?: string | null;
|
|
1115
|
+
consentState?: AnalyticsConsentState;
|
|
1116
|
+
clickIds?: Partial<Omit<AnalyticsClickIds, "schemaVersion">>;
|
|
1117
|
+
deviceType?: string;
|
|
1118
|
+
deviceOs?: string | null;
|
|
1119
|
+
deviceBrowser?: string | null;
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* Error detail for a single ingest payload item.
|
|
1123
|
+
*/
|
|
1124
|
+
interface AnalyticsErrorItem {
|
|
1125
|
+
/**
|
|
1126
|
+
* Index of the event in the request `events` array.
|
|
1127
|
+
*/
|
|
1128
|
+
index: number;
|
|
1129
|
+
/**
|
|
1130
|
+
* Server-assigned identifier for the event, if available.
|
|
1131
|
+
*/
|
|
1132
|
+
eventId: string | null;
|
|
1133
|
+
/**
|
|
1134
|
+
* Validation or processing error code.
|
|
1135
|
+
*/
|
|
1136
|
+
code: string;
|
|
1137
|
+
/**
|
|
1138
|
+
* Human-readable description of the failure.
|
|
1139
|
+
*/
|
|
1140
|
+
message: string;
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* Response summary from the analytics ingest endpoint.
|
|
1144
|
+
*/
|
|
1145
|
+
interface AnalyticsIngestResponse {
|
|
1146
|
+
/**
|
|
1147
|
+
* Number of events accepted and persisted.
|
|
1148
|
+
*/
|
|
1149
|
+
acceptedCount: number;
|
|
1150
|
+
/**
|
|
1151
|
+
* Number of events recognized as duplicates.
|
|
1152
|
+
*/
|
|
1153
|
+
duplicateCount: number;
|
|
1154
|
+
/**
|
|
1155
|
+
* Number of events rejected by validation or storage.
|
|
1156
|
+
*/
|
|
1157
|
+
rejectedCount: number;
|
|
1158
|
+
/**
|
|
1159
|
+
* Per-item errors, aligned by event index.
|
|
1160
|
+
*/
|
|
1161
|
+
errors: AnalyticsErrorItem[];
|
|
1162
|
+
}
|
|
1163
|
+
interface AnalyticsOperations {
|
|
1164
|
+
/**
|
|
1165
|
+
* Track an analytics event.
|
|
1166
|
+
*
|
|
1167
|
+
* Supports preset event names (`page_view`, `product_view`, `add_to_cart`, etc.),
|
|
1168
|
+
* canonical names (`analytics.page_view`, ...), and custom events.
|
|
1169
|
+
*
|
|
1170
|
+
* Custom event names are sent as `analytics.custom` with `eventName` included in `properties`.
|
|
1171
|
+
*
|
|
1172
|
+
* @param eventName - Preset/event-name to track.
|
|
1173
|
+
* @param context - Optional per-call context overrides.
|
|
1174
|
+
* @returns Tracking result with ingest summary, or network/validation error.
|
|
1175
|
+
*/
|
|
1176
|
+
track(eventName: "page_view", context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
1177
|
+
/**
|
|
1178
|
+
* Track a product page view.
|
|
1179
|
+
*/
|
|
1180
|
+
track(eventName: "product_view", input: PresetPropertiesByName<"product_view">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
1181
|
+
/**
|
|
1182
|
+
* Track a collection page view.
|
|
1183
|
+
*/
|
|
1184
|
+
track(eventName: "collection_view", input: PresetPropertiesByName<"collection_view">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
1185
|
+
/**
|
|
1186
|
+
* Track search execution.
|
|
1187
|
+
*/
|
|
1188
|
+
track(eventName: "search_performed", input: PresetPropertiesByName<"search_performed">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
1189
|
+
/**
|
|
1190
|
+
* Track adding items to cart.
|
|
1191
|
+
*/
|
|
1192
|
+
track(eventName: "add_to_cart", input: PresetPropertiesByName<"add_to_cart">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
1193
|
+
/**
|
|
1194
|
+
* Track removing items from cart.
|
|
1195
|
+
*/
|
|
1196
|
+
track(eventName: "remove_from_cart", input: PresetPropertiesByName<"remove_from_cart">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
1197
|
+
/**
|
|
1198
|
+
* Track checkout start.
|
|
1199
|
+
*/
|
|
1200
|
+
track(eventName: "checkout_started", input: PresetPropertiesByName<"checkout_started">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
1201
|
+
/**
|
|
1202
|
+
* Track checkout step completion.
|
|
1203
|
+
*/
|
|
1204
|
+
track(eventName: "checkout_step_completed", input: PresetPropertiesByName<"checkout_step_completed">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
1205
|
+
/**
|
|
1206
|
+
* Track successful checkout completion.
|
|
1207
|
+
*/
|
|
1208
|
+
track(eventName: "checkout_completed", input: PresetPropertiesByName<"checkout_completed">, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
1209
|
+
/**
|
|
1210
|
+
* Track a custom analytics event.
|
|
1211
|
+
*
|
|
1212
|
+
* Example:
|
|
1213
|
+
* `client.analytics.track("homepage.hero_clicked", { section: "hero", position: 1 })`
|
|
1214
|
+
*/
|
|
1215
|
+
track(eventName: string, properties: AnalyticsProperties, context?: AnalyticsContext): Promise<Result<AnalyticsIngestResponse, StorefrontError>>;
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
interface ShippingOperations {
|
|
1219
|
+
/**
|
|
1220
|
+
* Fetch shipping rates currently available for checkout.
|
|
1221
|
+
*
|
|
1222
|
+
* @returns Available shipping rates.
|
|
1223
|
+
*/
|
|
1224
|
+
getAvailableRates(): Promise<Result<ShippingRate[], StorefrontError>>;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
/**
|
|
1228
|
+
* Store-level read operations exposed by the storefront SDK.
|
|
1229
|
+
*/
|
|
1230
|
+
interface StoreOperations {
|
|
1231
|
+
get(options?: {
|
|
1232
|
+
cache?: boolean;
|
|
1233
|
+
}): Promise<StorefrontResult<Store>>;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
interface CacheHelpers {
|
|
1237
|
+
/**
|
|
1238
|
+
* Clear all cached query results for this client instance.
|
|
1239
|
+
*/
|
|
1240
|
+
clear(): void;
|
|
1241
|
+
}
|
|
1242
|
+
interface StorefrontClient {
|
|
1243
|
+
readonly config: StorefrontClientConfig;
|
|
1244
|
+
readonly cache: CacheHelpers;
|
|
1245
|
+
readonly products: ProductsOperations;
|
|
1246
|
+
readonly store: StoreOperations;
|
|
1247
|
+
readonly collections: CollectionsOperations;
|
|
1248
|
+
readonly categories: CategoriesOperations;
|
|
1249
|
+
readonly cart: CartOperations;
|
|
1250
|
+
readonly checkout: CheckoutOperations;
|
|
1251
|
+
readonly payments: PaymentsOperations;
|
|
1252
|
+
readonly auth: AuthOperations;
|
|
1253
|
+
readonly account: AccountOperations;
|
|
1254
|
+
readonly shipping: ShippingOperations;
|
|
1255
|
+
readonly analytics: AnalyticsOperations;
|
|
1256
|
+
init(options?: StorefrontInitOptions): Promise<Result<ResolvedStorefrontInitConfig, StorefrontError>>;
|
|
1257
|
+
/**
|
|
1258
|
+
* Execute a GraphQL query with optional caching
|
|
1259
|
+
*/
|
|
1260
|
+
query<T>(request: GraphQLRequest, options?: {
|
|
1261
|
+
cache?: boolean;
|
|
1262
|
+
}): Promise<Result<T, StorefrontError>>;
|
|
1263
|
+
/**
|
|
1264
|
+
* Execute a GraphQL mutation (never cached)
|
|
1265
|
+
*/
|
|
1266
|
+
mutate<T>(request: GraphQLRequest): Promise<Result<T, StorefrontError>>;
|
|
1267
|
+
/**
|
|
1268
|
+
* Get the current cart token from storage
|
|
1269
|
+
*/
|
|
1270
|
+
getCartToken(): string | null;
|
|
1271
|
+
/**
|
|
1272
|
+
* Set the cart token in storage
|
|
1273
|
+
*/
|
|
1274
|
+
setCartToken(token: string): void;
|
|
1275
|
+
/**
|
|
1276
|
+
* Clear the cart token from storage
|
|
1277
|
+
*/
|
|
1278
|
+
clearCartToken(): void;
|
|
1279
|
+
/**
|
|
1280
|
+
* Get the current customer JWT token from storage
|
|
1281
|
+
*/
|
|
1282
|
+
getCustomerToken(): string | null;
|
|
1283
|
+
/**
|
|
1284
|
+
* Set the customer JWT token in storage
|
|
1285
|
+
*/
|
|
1286
|
+
setCustomerToken(token: string): void;
|
|
1287
|
+
/**
|
|
1288
|
+
* Clear the customer JWT token from storage
|
|
1289
|
+
*/
|
|
1290
|
+
clearCustomerToken(): void;
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
/**
|
|
1294
|
+
* Create a new Storefront SDK client
|
|
1295
|
+
*
|
|
1296
|
+
* @param config - Client configuration including endpoint, API key, and optional storage adapter
|
|
1297
|
+
* @returns A configured StorefrontClient instance
|
|
1298
|
+
*
|
|
1299
|
+
* @example
|
|
1300
|
+
* ```typescript
|
|
1301
|
+
* import { createStorefrontClient } from "@ekomerc/storefront";
|
|
1302
|
+
*
|
|
1303
|
+
* const client = createStorefrontClient({
|
|
1304
|
+
* endpoint: "https://api.mystore.com/storefront",
|
|
1305
|
+
* apiKey: "sfk_abc123...",
|
|
1306
|
+
* });
|
|
1307
|
+
*
|
|
1308
|
+
* // Query products
|
|
1309
|
+
* const result = await client.query({
|
|
1310
|
+
* query: `query { products { edges { node { id title } } } }`,
|
|
1311
|
+
* });
|
|
1312
|
+
*
|
|
1313
|
+
* if (result.isOk()) {
|
|
1314
|
+
* console.log(result.value);
|
|
1315
|
+
* } else {
|
|
1316
|
+
* console.error(result.error);
|
|
1317
|
+
* }
|
|
1318
|
+
* ```
|
|
1319
|
+
*/
|
|
1320
|
+
declare function createStorefrontClient(config: StorefrontClientConfig): StorefrontClient;
|
|
1321
|
+
|
|
1322
|
+
interface CategoryProductsOptions {
|
|
1323
|
+
first?: number;
|
|
1324
|
+
after?: string;
|
|
1325
|
+
includeDescendants?: boolean;
|
|
1326
|
+
}
|
|
1327
|
+
interface CategoriesOperations {
|
|
1328
|
+
/**
|
|
1329
|
+
* Fetch the nested storefront category tree.
|
|
1330
|
+
*
|
|
1331
|
+
* @returns Categories with their child hierarchy.
|
|
1332
|
+
*/
|
|
1333
|
+
tree(): Promise<Result<Category[], StorefrontError>>;
|
|
1334
|
+
/**
|
|
1335
|
+
* Fetch categories flattened into a parent-aware list.
|
|
1336
|
+
*
|
|
1337
|
+
* @returns Flat categories with depth and parent metadata.
|
|
1338
|
+
*/
|
|
1339
|
+
flat(): Promise<Result<FlatCategory[], StorefrontError>>;
|
|
1340
|
+
/**
|
|
1341
|
+
* Fetch a single category by GID or handle.
|
|
1342
|
+
*
|
|
1343
|
+
* @param idOrHandle - Category GID or handle.
|
|
1344
|
+
* @returns The matching category.
|
|
1345
|
+
*/
|
|
1346
|
+
get(idOrHandle: string): Promise<Result<Category, StorefrontError>>;
|
|
1347
|
+
/**
|
|
1348
|
+
* Fetch products assigned to a category.
|
|
1349
|
+
*
|
|
1350
|
+
* @param idOrHandle - Category GID or handle.
|
|
1351
|
+
* @param options - Pagination and descendant-inclusion options.
|
|
1352
|
+
* @returns Paginated products for the category.
|
|
1353
|
+
*/
|
|
1354
|
+
getProducts(idOrHandle: string, options?: CategoryProductsOptions): Promise<Result<PaginatedResult<Product>, StorefrontError>>;
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
/**
|
|
1358
|
+
* Namespaced GTM event names emitted by the storefront adapter.
|
|
1359
|
+
*/
|
|
1360
|
+
type GtmNamespacedEventName = `ekomerc.${GtmStandardEventName}`;
|
|
1361
|
+
/**
|
|
1362
|
+
* GTM ecommerce item payload derived from storefront analytics properties.
|
|
1363
|
+
*/
|
|
1364
|
+
interface GtmItem {
|
|
1365
|
+
product_id: string;
|
|
1366
|
+
variant_id?: string;
|
|
1367
|
+
quantity: number;
|
|
1368
|
+
unit_price: number;
|
|
1369
|
+
line_total: number;
|
|
1370
|
+
currency: string;
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* GTM attribution payload copied from captured UTM and click ID data.
|
|
1374
|
+
*/
|
|
1375
|
+
interface GtmAttributionPayload {
|
|
1376
|
+
utm_source: string | null;
|
|
1377
|
+
utm_medium: string | null;
|
|
1378
|
+
utm_campaign: string | null;
|
|
1379
|
+
utm_term: string | null;
|
|
1380
|
+
utm_content: string | null;
|
|
1381
|
+
gclid: string | null;
|
|
1382
|
+
gbraid: string | null;
|
|
1383
|
+
wbraid: string | null;
|
|
1384
|
+
fbclid: string | null;
|
|
1385
|
+
ttclid: string | null;
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* GTM page context payload copied from the storefront analytics event.
|
|
1389
|
+
*/
|
|
1390
|
+
interface GtmContextPayload {
|
|
1391
|
+
path: string;
|
|
1392
|
+
referrer: string | null;
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* GTM `ekomerc` payload pushed alongside each `dataLayer` event.
|
|
1396
|
+
*/
|
|
1397
|
+
interface GtmEcommercePayload {
|
|
1398
|
+
event_name: GtmNamespacedEventName;
|
|
1399
|
+
event_id: string;
|
|
1400
|
+
consent_state: AnalyticsConsentState;
|
|
1401
|
+
context: GtmContextPayload;
|
|
1402
|
+
attribution: GtmAttributionPayload;
|
|
1403
|
+
currency?: string;
|
|
1404
|
+
value?: number;
|
|
1405
|
+
order_id?: string;
|
|
1406
|
+
cart_id?: string;
|
|
1407
|
+
quantity?: number;
|
|
1408
|
+
items_count?: number;
|
|
1409
|
+
search_term?: string;
|
|
1410
|
+
results_count?: number;
|
|
1411
|
+
items?: GtmItem[];
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
* Full object pushed to the configured GTM data layer.
|
|
1415
|
+
*/
|
|
1416
|
+
interface GtmDataLayerEvent {
|
|
1417
|
+
event: GtmNamespacedEventName;
|
|
1418
|
+
ekomerc: GtmEcommercePayload;
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* GTM consent-mode update payload derived from storefront consent state.
|
|
1422
|
+
*/
|
|
1423
|
+
interface GtmConsentModeUpdate {
|
|
1424
|
+
analytics_storage: "granted" | "denied";
|
|
1425
|
+
ad_storage: "granted" | "denied";
|
|
1426
|
+
ad_user_data: "granted" | "denied";
|
|
1427
|
+
ad_personalization: "granted" | "denied";
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Optional runtime overrides for the GTM browser adapter.
|
|
1431
|
+
*/
|
|
1432
|
+
interface GtmBrowserAdapterOptions {
|
|
1433
|
+
dataLayerName?: string;
|
|
1434
|
+
getWindow?: () => object | null;
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* Maps a storefront analytics event to a GTM `dataLayer.push()` payload.
|
|
1438
|
+
*/
|
|
1439
|
+
declare function buildGtmDataLayerEvent(input: AnalyticsAdapterDispatchInput): GtmDataLayerEvent | null;
|
|
1440
|
+
/**
|
|
1441
|
+
* Converts storefront consent state into a GTM consent-mode update payload.
|
|
1442
|
+
*/
|
|
1443
|
+
declare function buildGtmConsentModeUpdate({ consentState }: AnalyticsConsentUpdate): GtmConsentModeUpdate;
|
|
1444
|
+
/**
|
|
1445
|
+
* Creates a GTM browser adapter that pushes storefront analytics events into `window.dataLayer`.
|
|
1446
|
+
*/
|
|
1447
|
+
declare function createGtmBrowserAdapter(config: GtmBrowserTrackingConfig, options?: GtmBrowserAdapterOptions): AnalyticsBrowserAdapter | null;
|
|
1448
|
+
|
|
1449
|
+
declare const CART_TOKEN_KEY = "ekomerc_cart_token";
|
|
1450
|
+
declare const CUSTOMER_TOKEN_KEY = "ekomerc_customer_token";
|
|
1451
|
+
/**
|
|
1452
|
+
* localStorage adapter for browser environments
|
|
1453
|
+
*/
|
|
1454
|
+
declare function createLocalStorageAdapter(): StorageAdapter;
|
|
1455
|
+
/**
|
|
1456
|
+
* In-memory adapter for SSR or testing
|
|
1457
|
+
*/
|
|
1458
|
+
declare function createMemoryAdapter(): StorageAdapter;
|
|
1459
|
+
/**
|
|
1460
|
+
* Detect environment and create appropriate default adapter
|
|
1461
|
+
*/
|
|
1462
|
+
declare function createDefaultAdapter(): StorageAdapter;
|
|
1463
|
+
|
|
1464
|
+
declare const TRACKING_ATTRIBUTION_QUERY_PARAM_KEYS: readonly ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "gclid", "gbraid", "wbraid", "ttclid", "fbclid"];
|
|
1465
|
+
interface TrackingUtmSnapshot {
|
|
1466
|
+
schemaVersion: 1;
|
|
1467
|
+
source: string | null;
|
|
1468
|
+
medium: string | null;
|
|
1469
|
+
campaign: string | null;
|
|
1470
|
+
term: string | null;
|
|
1471
|
+
content: string | null;
|
|
1472
|
+
}
|
|
1473
|
+
interface TrackingClickIdsSnapshot {
|
|
1474
|
+
schemaVersion: 1;
|
|
1475
|
+
capturedAt: string | null;
|
|
1476
|
+
gclid: string | null;
|
|
1477
|
+
gbraid: string | null;
|
|
1478
|
+
wbraid: string | null;
|
|
1479
|
+
ttclid: string | null;
|
|
1480
|
+
fbclid: string | null;
|
|
1481
|
+
}
|
|
1482
|
+
interface TrackingAttributionSnapshot {
|
|
1483
|
+
schemaVersion: 1;
|
|
1484
|
+
capturedAt: string;
|
|
1485
|
+
utm: TrackingUtmSnapshot;
|
|
1486
|
+
clickIds: TrackingClickIdsSnapshot;
|
|
1487
|
+
}
|
|
1488
|
+
interface TrackingAttributionOptions {
|
|
1489
|
+
ttlMs?: number;
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
export { AuthError, CART_TOKEN_KEY, CUSTOMER_TOKEN_KEY, GraphQLError, NetworkError, NotFoundError, StateError, StorefrontError, TRACKING_ATTRIBUTION_QUERY_PARAM_KEYS, ValidationError, buildGtmConsentModeUpdate, buildGtmDataLayerEvent, createDefaultAdapter, createGtmBrowserAdapter, createLocalStorageAdapter, createMemoryAdapter, createQueryCache, createStorefrontClient, extractUserErrors };
|
|
1493
|
+
export type { AccountOperations, Address, AnalyticsAdapterDispatchInput, AnalyticsAdapterOperationResult, AnalyticsAdapterOperationSkippedResult, AnalyticsAdapterSkipReason, AnalyticsBrowserAdapter, AnalyticsBrowserEvent, AnalyticsBrowserEventDevice, AnalyticsClickIds, AnalyticsConsentState, AnalyticsConsentUpdate, AnalyticsContext, AnalyticsDiagnostic, AnalyticsDispatchOnUnknownConsent, AnalyticsErrorItem, AnalyticsEventContextPayload, AnalyticsEventType, AnalyticsIngestResponse, AnalyticsInitOptions, AnalyticsJsonPrimitive, AnalyticsJsonValue, AnalyticsOperations, AnalyticsPresetEventName, AnalyticsProperties, AnalyticsTrackEventName, AnalyticsUtm, AppliedDiscount, AppliedPromoCode, AuthOperations, AvailablePaymentMethod, BrowserTrackingConfig, BulletListDetailSection, CacheHelpers, Cart, CartItem, CartOperations, CartStatus, CategoriesOperations, Category, CategoryProductsOptions, CheckoutData, CheckoutOperations, CheckoutStep, Collection, CollectionProductSort, CollectionProductsOptions, CollectionSortOrder, CollectionType, CollectionsListOptions, CollectionsOperations, Customer, CustomerAddress, CustomerAddressInput, CustomerAddressUpdateInput, CustomerOrder, CustomerOrderItem, CustomerUpdateInput, DetailSection, DisplayIntent, FlatCategory, GraphQLClient, GraphQLRequest, GraphQLResponse, GtmAttributionPayload, GtmBrowserAdapterOptions, GtmBrowserTrackingConfig, GtmConsentModeUpdate, GtmContextPayload, GtmDataLayerEvent, GtmEcommercePayload, GtmItem, GtmNamespacedEventName, Order, OrderItem, PageInfo, PaginatedResult, PaymentInstructions, PaymentsOperations, Product, ProductFilter, ProductImage, ProductOption, ProductOptionValue, ProductSortKey, ProductVariant, ProductsListOptions, ProductsOperations, QuantityPricingTier, QueryCache, ResolvedStorefrontAnalyticsConfig, ResolvedStorefrontInitConfig, RichTextDetailSection, SectionType, ShippingOperations, ShippingRate, SocialLinks, StorageAdapter, Store, StoreAnalyticsConfig, StoreOperations, StorefrontAnalyticsInitConfig, StorefrontClient, StorefrontClientConfig, StorefrontInitOptions, StorefrontResult, StorefrontTrackingRuntimeConfig, TableDetailSection, Tag, TrackingAttributionOptions, TrackingAttributionSnapshot, WeightUnit };
|