@konfiqo/storefront-sdk 0.0.0-stage → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +616 -2
- package/dist/index.cjs +772 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1287 -0
- package/dist/index.d.ts +1287 -0
- package/dist/index.js +725 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store theme, `schemaVersion: 1` (the commerce module's "Store settings
|
|
3
|
+
* JSON"). The Storefront API passes the theme through **as stored**: it is
|
|
4
|
+
* not validated, so every field is optional and a renderer must tolerate
|
|
5
|
+
* missing values, wrong types and keys it does not know. Image fields are
|
|
6
|
+
* tenant storage keys — turn them into URLs with `client.media.url(key)`.
|
|
7
|
+
*/
|
|
8
|
+
interface ThemeV1 {
|
|
9
|
+
/** `1` for this shape. Anything else: render defaults. */
|
|
10
|
+
schemaVersion?: number;
|
|
11
|
+
/** Storage key of the logo (the same key as the store's `logo`). */
|
|
12
|
+
logo?: string | null;
|
|
13
|
+
/** Storage key of the favicon. */
|
|
14
|
+
favicon?: string | null;
|
|
15
|
+
/** Theme colors, CSS color strings (normally `#rrggbb`). */
|
|
16
|
+
colors?: ThemeColors;
|
|
17
|
+
/** One of {@link THEME_FONTS}; an unknown value means "use the default font". */
|
|
18
|
+
font?: ThemeFont | (string & {});
|
|
19
|
+
/** The homepage, as ordered sections. */
|
|
20
|
+
homepage?: ThemeHomepage;
|
|
21
|
+
/** Footer links and social profiles. */
|
|
22
|
+
footer?: ThemeFooter;
|
|
23
|
+
/** Keys this SDK version does not know are kept as stored. */
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
/** Theme colors. Each is a CSS color string; any may be missing. */
|
|
27
|
+
interface ThemeColors {
|
|
28
|
+
/** Primary brand color. */
|
|
29
|
+
primary?: string;
|
|
30
|
+
/** Accent (links, highlights). */
|
|
31
|
+
accent?: string;
|
|
32
|
+
/** Page background. */
|
|
33
|
+
background?: string;
|
|
34
|
+
/** Body text. */
|
|
35
|
+
text?: string;
|
|
36
|
+
/** Unknown color keys are kept as stored. */
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
/** The fonts a v1 theme may name. */
|
|
40
|
+
declare const THEME_FONTS: readonly ["inter", "roboto", "open-sans", "lato", "poppins"];
|
|
41
|
+
/** A font a v1 theme may name. */
|
|
42
|
+
type ThemeFont = (typeof THEME_FONTS)[number];
|
|
43
|
+
/** The homepage: sections in display order. */
|
|
44
|
+
interface ThemeHomepage {
|
|
45
|
+
/**
|
|
46
|
+
* Sections in display order. May contain section types this SDK does not
|
|
47
|
+
* know (skip them) — narrow with {@link isKnownThemeSection}.
|
|
48
|
+
*/
|
|
49
|
+
sections?: ThemeSection[];
|
|
50
|
+
/** Unknown homepage keys are kept as stored. */
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}
|
|
53
|
+
/** A call-to-action link. */
|
|
54
|
+
interface ThemeLink {
|
|
55
|
+
/** Visible text. */
|
|
56
|
+
label?: string;
|
|
57
|
+
/** Target URL or path. */
|
|
58
|
+
href?: string;
|
|
59
|
+
}
|
|
60
|
+
/** `hero`: a large banner with an optional image and call to action. */
|
|
61
|
+
interface HeroSection {
|
|
62
|
+
/** Discriminator. */
|
|
63
|
+
type: 'hero';
|
|
64
|
+
/** Storage key of the banner image. */
|
|
65
|
+
image?: string | null;
|
|
66
|
+
/** Headline. */
|
|
67
|
+
title?: string;
|
|
68
|
+
/** Sub-headline. */
|
|
69
|
+
subtitle?: string;
|
|
70
|
+
/** Optional call-to-action button. */
|
|
71
|
+
cta?: ThemeLink;
|
|
72
|
+
}
|
|
73
|
+
/** `featuredProducts`: a hand-picked list of products. */
|
|
74
|
+
interface FeaturedProductsSection {
|
|
75
|
+
/** Discriminator. */
|
|
76
|
+
type: 'featuredProducts';
|
|
77
|
+
/** Section heading. */
|
|
78
|
+
title?: string;
|
|
79
|
+
/** Product slugs, in display order. Slugs no longer sold are skipped. */
|
|
80
|
+
productSlugs?: string[];
|
|
81
|
+
}
|
|
82
|
+
/** `categoryGrid`: a grid of category tiles. */
|
|
83
|
+
interface CategoryGridSection {
|
|
84
|
+
/** Discriminator. */
|
|
85
|
+
type: 'categoryGrid';
|
|
86
|
+
/** Category slugs, in display order. Unknown slugs are skipped. */
|
|
87
|
+
categorySlugs?: string[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* `richText`: seller-written text. Render it as text or sanitized
|
|
91
|
+
* markdown — never as raw HTML.
|
|
92
|
+
*/
|
|
93
|
+
interface RichTextSection {
|
|
94
|
+
/** Discriminator. */
|
|
95
|
+
type: 'richText';
|
|
96
|
+
/** The text. */
|
|
97
|
+
content?: string;
|
|
98
|
+
}
|
|
99
|
+
/** A section type this SDK knows how to describe. */
|
|
100
|
+
type KnownThemeSection = HeroSection | FeaturedProductsSection | CategoryGridSection | RichTextSection;
|
|
101
|
+
/** A section of a type this SDK version does not know; renderers skip it. */
|
|
102
|
+
interface UnknownThemeSection {
|
|
103
|
+
/** The stored type. */
|
|
104
|
+
type: string;
|
|
105
|
+
/** Other stored keys. */
|
|
106
|
+
[key: string]: unknown;
|
|
107
|
+
}
|
|
108
|
+
/** A homepage section as stored: a known section or an unknown one. */
|
|
109
|
+
type ThemeSection = KnownThemeSection | UnknownThemeSection;
|
|
110
|
+
/**
|
|
111
|
+
* Whether a stored section is one of the known types. After this guard a
|
|
112
|
+
* `switch (section.type)` narrows to the exact section shape.
|
|
113
|
+
*/
|
|
114
|
+
declare function isKnownThemeSection(section: unknown): section is KnownThemeSection;
|
|
115
|
+
/** Social profile URLs; only filled ones are stored. */
|
|
116
|
+
interface ThemeSocial {
|
|
117
|
+
/** Instagram profile URL. */
|
|
118
|
+
instagram?: string;
|
|
119
|
+
/** Facebook page URL. */
|
|
120
|
+
facebook?: string;
|
|
121
|
+
/** X profile URL. */
|
|
122
|
+
x?: string;
|
|
123
|
+
/** TikTok profile URL. */
|
|
124
|
+
tiktok?: string;
|
|
125
|
+
/** YouTube channel URL. */
|
|
126
|
+
youtube?: string;
|
|
127
|
+
/** Unknown networks are kept as stored. */
|
|
128
|
+
[key: string]: unknown;
|
|
129
|
+
}
|
|
130
|
+
/** Footer configuration. */
|
|
131
|
+
interface ThemeFooter {
|
|
132
|
+
/** Footer links, in display order. */
|
|
133
|
+
links?: ThemeLink[];
|
|
134
|
+
/** Social profiles. */
|
|
135
|
+
social?: ThemeSocial;
|
|
136
|
+
/** Unknown footer keys are kept as stored. */
|
|
137
|
+
[key: string]: unknown;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Shipping price rules of the store (minor units). */
|
|
141
|
+
interface ShippingRules {
|
|
142
|
+
/** Price when no other rule applies; `0` = free shipping. */
|
|
143
|
+
flatMinor?: number;
|
|
144
|
+
/** A subtotal of at least this ships free. */
|
|
145
|
+
freeAboveMinor?: number;
|
|
146
|
+
/**
|
|
147
|
+
* Weight bands, ascending by `maxGrams`: the parcel pays the first band
|
|
148
|
+
* it fits; heavier than every band, it pays `flatMinor`.
|
|
149
|
+
*/
|
|
150
|
+
weightBands?: {
|
|
151
|
+
maxGrams: number;
|
|
152
|
+
priceMinor: number;
|
|
153
|
+
}[];
|
|
154
|
+
}
|
|
155
|
+
/** Store contact details. */
|
|
156
|
+
interface StoreContact {
|
|
157
|
+
/** Contact e-mail address. */
|
|
158
|
+
email: string | null;
|
|
159
|
+
/** Contact phone number. */
|
|
160
|
+
phone: string | null;
|
|
161
|
+
}
|
|
162
|
+
/** Legal texts the storefront must show. Plain text as the seller wrote it. */
|
|
163
|
+
interface StoreLegal {
|
|
164
|
+
/** KVKK (personal data) notice. */
|
|
165
|
+
kvkk: string | null;
|
|
166
|
+
/** Distance sales agreement. */
|
|
167
|
+
distanceSales: string | null;
|
|
168
|
+
/** Returns policy. */
|
|
169
|
+
returns: string | null;
|
|
170
|
+
/**
|
|
171
|
+
* Cookie policy: the seller's text, or the platform default. (Absent from
|
|
172
|
+
* API versions before cookie consent existed.)
|
|
173
|
+
*/
|
|
174
|
+
cookies?: string | null;
|
|
175
|
+
}
|
|
176
|
+
/** What a cookie is for: necessary ones need no consent. */
|
|
177
|
+
type CookieCategory = 'necessary' | 'analytics' | 'marketing';
|
|
178
|
+
/** A cookie the store uses, for the consent banner and the cookie policy. */
|
|
179
|
+
interface CookieInfo {
|
|
180
|
+
/** Cookie name. */
|
|
181
|
+
name: string;
|
|
182
|
+
category: CookieCategory;
|
|
183
|
+
/** What it is for, in the store's language. */
|
|
184
|
+
purpose: string;
|
|
185
|
+
/** How long it is kept, in days. */
|
|
186
|
+
durationDays: number;
|
|
187
|
+
/**
|
|
188
|
+
* True for a cookie its library writes to the registrable domain with no
|
|
189
|
+
* host-only option (Meta, TikTok): on a host under
|
|
190
|
+
* {@link Store.defaultDomainSuffix} that pixel does not run, so leave
|
|
191
|
+
* the cookie out of the list there. (Absent otherwise.)
|
|
192
|
+
*/
|
|
193
|
+
customDomainOnly?: boolean;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The bot challenge checkout requires: render a Cloudflare Turnstile widget
|
|
197
|
+
* with `siteKey` and pass its token to `carts.checkout`.
|
|
198
|
+
*/
|
|
199
|
+
interface CheckoutChallenge {
|
|
200
|
+
/** Challenge provider. */
|
|
201
|
+
provider: 'turnstile';
|
|
202
|
+
/** The public Turnstile site key of the store. */
|
|
203
|
+
siteKey: string;
|
|
204
|
+
}
|
|
205
|
+
/** A node of a Markdoc render tree: a string, or a tag with attributes and children. */
|
|
206
|
+
type ContentNode = string | {
|
|
207
|
+
$$mdtype: 'Tag';
|
|
208
|
+
name: string;
|
|
209
|
+
attributes: Record<string, unknown>;
|
|
210
|
+
children: ContentNode[];
|
|
211
|
+
};
|
|
212
|
+
/** `GET /v1/content/:key`: store content (Markdoc) as a renderable tree. */
|
|
213
|
+
interface StoreContent {
|
|
214
|
+
key: string;
|
|
215
|
+
title: string;
|
|
216
|
+
/** `Markdoc.transform` output (plain objects). Render with `<Content>`. */
|
|
217
|
+
tree: ContentNode;
|
|
218
|
+
}
|
|
219
|
+
/** The ad pixels a store configured (ids are validated by the API). */
|
|
220
|
+
interface AdPixels {
|
|
221
|
+
/** Meta Pixel. */
|
|
222
|
+
meta?: {
|
|
223
|
+
pixelId: string;
|
|
224
|
+
};
|
|
225
|
+
/** TikTok Pixel. */
|
|
226
|
+
tiktok?: {
|
|
227
|
+
pixelId: string;
|
|
228
|
+
};
|
|
229
|
+
/** Google tag: GA4 and/or Google Ads. */
|
|
230
|
+
google?: {
|
|
231
|
+
ga4Id?: string;
|
|
232
|
+
adsId?: string;
|
|
233
|
+
adsConversionLabel?: string;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/** `GET /v1/store`. */
|
|
237
|
+
interface Store {
|
|
238
|
+
/** Store name. */
|
|
239
|
+
name: string;
|
|
240
|
+
/** Default language (`tr`, `en`, …), or null when not set. */
|
|
241
|
+
defaultLanguage: string | null;
|
|
242
|
+
/** ISO 4217 currency of every price in this store. */
|
|
243
|
+
currency: string;
|
|
244
|
+
/** Storage key of the logo. */
|
|
245
|
+
logo: string | null;
|
|
246
|
+
/**
|
|
247
|
+
* Media URL of the logo, **relative** (`/v1/media/<key>?pk=<key>`): prefix
|
|
248
|
+
* the API origin, or use `client.media.url(store.logo)`.
|
|
249
|
+
*/
|
|
250
|
+
logoUrl: string | null;
|
|
251
|
+
/** The theme as stored (not validated); null when the store has none. */
|
|
252
|
+
theme: ThemeV1 | null;
|
|
253
|
+
/** Contact details. */
|
|
254
|
+
contact: StoreContact;
|
|
255
|
+
/** Legal texts. */
|
|
256
|
+
legal: StoreLegal;
|
|
257
|
+
/** Shipping rules, or null when the store has no shipping configured. */
|
|
258
|
+
shipping: ShippingRules | null;
|
|
259
|
+
/**
|
|
260
|
+
* The challenge checkout requires, or null when none. (Absent from API
|
|
261
|
+
* versions before the challenge existed: treat as null.)
|
|
262
|
+
*/
|
|
263
|
+
checkoutChallenge?: CheckoutChallenge | null;
|
|
264
|
+
/**
|
|
265
|
+
* The cookies the store uses; empty when it uses no optional cookie (then
|
|
266
|
+
* nothing needs consent). (Absent from older API versions: treat as [].)
|
|
267
|
+
*/
|
|
268
|
+
cookies?: CookieInfo[];
|
|
269
|
+
/**
|
|
270
|
+
* Version of the optional cookie set: a stored consent for another
|
|
271
|
+
* version is void. '' when the store uses no optional cookie.
|
|
272
|
+
*/
|
|
273
|
+
consentVersion?: string;
|
|
274
|
+
/**
|
|
275
|
+
* The store's ad pixels; load them only after the shopper granted
|
|
276
|
+
* `marketing`. (Absent from older API versions: treat as none.)
|
|
277
|
+
*/
|
|
278
|
+
adPixels?: AdPixels;
|
|
279
|
+
/**
|
|
280
|
+
* The suffix of the stores' default domains (`<slug>.<suffix>`). On a
|
|
281
|
+
* host under it Meta and TikTok are not loaded and the
|
|
282
|
+
* `customDomainOnly` cookies are not listed. (Absent from older API
|
|
283
|
+
* versions: treat every host as a custom domain.)
|
|
284
|
+
*/
|
|
285
|
+
defaultDomainSuffix?: string;
|
|
286
|
+
}
|
|
287
|
+
/** A node of the active category tree. */
|
|
288
|
+
interface Category {
|
|
289
|
+
/** Category id. */
|
|
290
|
+
id: string;
|
|
291
|
+
/** URL slug; the `category` filter of `products.list`. */
|
|
292
|
+
slug: string;
|
|
293
|
+
/** Display name. */
|
|
294
|
+
name: string;
|
|
295
|
+
/** Sort key within its parent (already applied to `children`). */
|
|
296
|
+
sortOrder: number;
|
|
297
|
+
/** Active child categories, sorted. */
|
|
298
|
+
children: Category[];
|
|
299
|
+
}
|
|
300
|
+
/** `GET /v1/categories`. */
|
|
301
|
+
interface CategoryList {
|
|
302
|
+
/** Root categories, sorted. */
|
|
303
|
+
items: Category[];
|
|
304
|
+
}
|
|
305
|
+
/** A sellable product variant. */
|
|
306
|
+
interface ProductVariant {
|
|
307
|
+
/** Variant id: what a cart line references. */
|
|
308
|
+
id: string;
|
|
309
|
+
/** Stock-keeping unit. */
|
|
310
|
+
sku: string;
|
|
311
|
+
/** Variant title (`S`, `Red / M`, …), or null for a single-variant product. */
|
|
312
|
+
title: string | null;
|
|
313
|
+
/**
|
|
314
|
+
* The variant's option values as stored (a JSON field; typically an
|
|
315
|
+
* object such as `{ "size": "M" }`), or null.
|
|
316
|
+
*/
|
|
317
|
+
optionValues: unknown;
|
|
318
|
+
/** Price, minor units. */
|
|
319
|
+
priceMinor: number;
|
|
320
|
+
/** "Was" price for display, minor units, or null. */
|
|
321
|
+
compareAtPriceMinor: number | null;
|
|
322
|
+
/** ISO 4217 currency of the prices. */
|
|
323
|
+
currency: string;
|
|
324
|
+
/** Units available now (stock minus reservations); never negative. */
|
|
325
|
+
available: number;
|
|
326
|
+
}
|
|
327
|
+
/** The text a product asks the buyer for, once per cart line. */
|
|
328
|
+
interface ProductPersonalization {
|
|
329
|
+
/** What to ask for (e.g. the label of the input). */
|
|
330
|
+
label: string;
|
|
331
|
+
/** True when the product cannot be bought without the text. */
|
|
332
|
+
required: boolean;
|
|
333
|
+
/** Shortest accepted text, in characters (Unicode code points). */
|
|
334
|
+
minLength: number;
|
|
335
|
+
/** Longest accepted text, in characters (Unicode code points). */
|
|
336
|
+
maxLength: number;
|
|
337
|
+
}
|
|
338
|
+
/** A product. Only products with at least one sellable variant are listed. */
|
|
339
|
+
interface Product {
|
|
340
|
+
/** Product id. */
|
|
341
|
+
id: string;
|
|
342
|
+
/** URL slug; the argument of `products.get`. */
|
|
343
|
+
slug: string;
|
|
344
|
+
/** Display name. */
|
|
345
|
+
name: string;
|
|
346
|
+
/** Description as the seller wrote it, or null. */
|
|
347
|
+
description: string | null;
|
|
348
|
+
/** Storage key of the product image, or null. */
|
|
349
|
+
image: string | null;
|
|
350
|
+
/**
|
|
351
|
+
* Media URL of `image`, **relative** (`/v1/media/<key>?pk=<key>`): prefix
|
|
352
|
+
* the API origin, or use `client.media.url(product.image)`.
|
|
353
|
+
*/
|
|
354
|
+
imageUrl: string | null;
|
|
355
|
+
/** SEO title override, or null (use `name`). */
|
|
356
|
+
seoTitle: string | null;
|
|
357
|
+
/** SEO description, or null. */
|
|
358
|
+
seoDescription: string | null;
|
|
359
|
+
/** The product's (live) category, or null. */
|
|
360
|
+
category: {
|
|
361
|
+
slug: string;
|
|
362
|
+
name: string;
|
|
363
|
+
} | null;
|
|
364
|
+
/** Sellable variants. */
|
|
365
|
+
variants: ProductVariant[];
|
|
366
|
+
/** The text the product asks for per cart line; present only when it asks for one. */
|
|
367
|
+
personalization?: ProductPersonalization;
|
|
368
|
+
}
|
|
369
|
+
/** Paging information of a list. */
|
|
370
|
+
interface Pagination {
|
|
371
|
+
/** 1-based page number. */
|
|
372
|
+
page: number;
|
|
373
|
+
/** Items per page. */
|
|
374
|
+
pageSize: number;
|
|
375
|
+
/** Items matching the query. */
|
|
376
|
+
totalItems: number;
|
|
377
|
+
/** Pages for the query (`0` when nothing matches). */
|
|
378
|
+
totalPages: number;
|
|
379
|
+
}
|
|
380
|
+
/** `GET /v1/products`. */
|
|
381
|
+
interface ProductPage {
|
|
382
|
+
/** The page's products, sorted by name. */
|
|
383
|
+
items: Product[];
|
|
384
|
+
/** Paging information. */
|
|
385
|
+
pagination: Pagination;
|
|
386
|
+
}
|
|
387
|
+
/** Filters and paging of `products.list`. All optional. */
|
|
388
|
+
interface ProductListQuery {
|
|
389
|
+
/** Category slug; includes the category's descendants. */
|
|
390
|
+
category?: string;
|
|
391
|
+
/** Search text (name, description, SKU), at most 200 characters. */
|
|
392
|
+
q?: string;
|
|
393
|
+
/** 1-based page (default 1, at most 10 000). */
|
|
394
|
+
page?: number;
|
|
395
|
+
/** Items per page (default 20, 1–100). */
|
|
396
|
+
pageSize?: number;
|
|
397
|
+
}
|
|
398
|
+
/** Cart status. Only an `open` cart can change. */
|
|
399
|
+
type CartStatus = 'open' | 'ordered' | 'expired';
|
|
400
|
+
/** A priced cart line. Prices are always computed server-side. */
|
|
401
|
+
interface CartLine {
|
|
402
|
+
/**
|
|
403
|
+
* Line id: the argument of `carts.updateLine` / `carts.removeLine`. The
|
|
404
|
+
* variant id for a line without text, `<variantId>~<12 hex>` for a line
|
|
405
|
+
* with text. Required: needs a commerce API that returns it (older servers
|
|
406
|
+
* omit it; there, use `variantId`).
|
|
407
|
+
*/
|
|
408
|
+
id: string;
|
|
409
|
+
/** The variant this line holds. */
|
|
410
|
+
variantId: string;
|
|
411
|
+
/** Units, 1–99. */
|
|
412
|
+
quantity: number;
|
|
413
|
+
/**
|
|
414
|
+
* The buyer's text for this line, or null. Required: older servers omit
|
|
415
|
+
* it (treat it as null there).
|
|
416
|
+
*/
|
|
417
|
+
personalization: string | null;
|
|
418
|
+
/**
|
|
419
|
+
* False when the stored text no longer satisfies the product's current
|
|
420
|
+
* rule; checkout then answers `invalid_personalization`. Required: older
|
|
421
|
+
* servers omit it (treat it as true there).
|
|
422
|
+
*/
|
|
423
|
+
personalizationValid: boolean;
|
|
424
|
+
/** False when the variant is no longer sold. Checkout refuses the cart. */
|
|
425
|
+
purchasable: boolean;
|
|
426
|
+
/** False when fewer units are available than the line asks for. Checkout refuses the cart. */
|
|
427
|
+
inStock: boolean;
|
|
428
|
+
/** Product id; null when not purchasable. */
|
|
429
|
+
productId: string | null;
|
|
430
|
+
/** Product slug; null when not purchasable. */
|
|
431
|
+
productSlug: string | null;
|
|
432
|
+
/** Product name; null when not purchasable. */
|
|
433
|
+
productName: string | null;
|
|
434
|
+
/** Variant title; null when not purchasable or untitled. */
|
|
435
|
+
variantTitle: string | null;
|
|
436
|
+
/** SKU; null when not purchasable. */
|
|
437
|
+
sku: string | null;
|
|
438
|
+
/** Unit price, minor units; null when not purchasable. */
|
|
439
|
+
unitPriceMinor: number | null;
|
|
440
|
+
/** Line total, minor units (`0` when not purchasable). */
|
|
441
|
+
lineTotalMinor: number;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* The module address shape. Either `address` or `line1` is required;
|
|
445
|
+
* `name` / `phone` / `email` fall back to the customer's. Only `TR` in 0.1.0.
|
|
446
|
+
*/
|
|
447
|
+
interface Address {
|
|
448
|
+
/** Recipient name. */
|
|
449
|
+
name?: string;
|
|
450
|
+
/** Recipient phone. */
|
|
451
|
+
phone?: string;
|
|
452
|
+
/** Recipient e-mail. */
|
|
453
|
+
email?: string;
|
|
454
|
+
/** Full street address (alternative to `line1` + `line2`). */
|
|
455
|
+
address?: string;
|
|
456
|
+
/** Street address, first line. */
|
|
457
|
+
line1?: string;
|
|
458
|
+
/** Street address, second line. */
|
|
459
|
+
line2?: string;
|
|
460
|
+
/** District (ilçe). */
|
|
461
|
+
district: string;
|
|
462
|
+
/** City (il). */
|
|
463
|
+
city: string;
|
|
464
|
+
/** Postal code (or `postalCode`). */
|
|
465
|
+
zipCode?: string;
|
|
466
|
+
/** Postal code (or `zipCode`). */
|
|
467
|
+
postalCode?: string;
|
|
468
|
+
/** Country; `TR` only. */
|
|
469
|
+
country: 'TR';
|
|
470
|
+
}
|
|
471
|
+
/** The buyer as stored on a cart. The identity number is never returned. */
|
|
472
|
+
interface CartCustomer {
|
|
473
|
+
/** E-mail address. */
|
|
474
|
+
email: string;
|
|
475
|
+
/** First name. */
|
|
476
|
+
name: string;
|
|
477
|
+
/** Surname. */
|
|
478
|
+
surname: string;
|
|
479
|
+
/** Turkish mobile number, normalised to `90XXXXXXXXXX`. */
|
|
480
|
+
phone: string;
|
|
481
|
+
/** Whether an identity number (TC kimlik no) is on file. */
|
|
482
|
+
identityNumberProvided: boolean;
|
|
483
|
+
}
|
|
484
|
+
/** The cart view every cart route answers. */
|
|
485
|
+
interface Cart {
|
|
486
|
+
/** Cart id: a bearer capability, keep it private to the buyer. */
|
|
487
|
+
id: string;
|
|
488
|
+
/** Cart status. */
|
|
489
|
+
status: CartStatus;
|
|
490
|
+
/** ISO 4217 currency. */
|
|
491
|
+
currency: string;
|
|
492
|
+
/** Priced lines. */
|
|
493
|
+
lines: CartLine[];
|
|
494
|
+
/** Sum of line totals, minor units. */
|
|
495
|
+
subtotalMinor: number;
|
|
496
|
+
/** Shipping price, minor units. */
|
|
497
|
+
shippingMinor: number;
|
|
498
|
+
/** Total to pay, minor units. */
|
|
499
|
+
totalMinor: number;
|
|
500
|
+
/** The selected shipping option id, or null when none (or no longer offered). */
|
|
501
|
+
shippingOption: string | null;
|
|
502
|
+
/** The buyer, or null before `setCustomer`. */
|
|
503
|
+
customer: CartCustomer | null;
|
|
504
|
+
/** Shipping address, or null. */
|
|
505
|
+
shippingAddress: Address | null;
|
|
506
|
+
/** Billing address, or null (= the shipping address). */
|
|
507
|
+
billingAddress: Address | null;
|
|
508
|
+
/** When the cart expires (ISO date). */
|
|
509
|
+
expiresAt: string;
|
|
510
|
+
}
|
|
511
|
+
/** Body of `carts.addLine`. */
|
|
512
|
+
interface AddLineInput {
|
|
513
|
+
/** Variant id from the catalog. */
|
|
514
|
+
variantId: string;
|
|
515
|
+
/** Units to add, 1–99 (added to an existing line of the same variant and text). */
|
|
516
|
+
quantity: number;
|
|
517
|
+
/**
|
|
518
|
+
* The buyer's text, for a product that asks for one (see
|
|
519
|
+
* `Product.personalization`). Refused with `invalid_personalization` (400)
|
|
520
|
+
* when it breaks the product's rule, or when the product asks for none.
|
|
521
|
+
*/
|
|
522
|
+
personalization?: string;
|
|
523
|
+
}
|
|
524
|
+
/** Body of `carts.updateLine`. */
|
|
525
|
+
interface UpdateLineInput {
|
|
526
|
+
/** New quantity, 1–99. */
|
|
527
|
+
quantity: number;
|
|
528
|
+
}
|
|
529
|
+
/** Body of `carts.setCustomer`. */
|
|
530
|
+
interface CustomerInput {
|
|
531
|
+
/** E-mail address. */
|
|
532
|
+
email: string;
|
|
533
|
+
/** First name. */
|
|
534
|
+
name: string;
|
|
535
|
+
/** Surname. */
|
|
536
|
+
surname: string;
|
|
537
|
+
/**
|
|
538
|
+
* A **Turkish mobile number**: `05XX…`, `5XX…`, `+90…`, `0090…` (spaces,
|
|
539
|
+
* dashes and parentheses allowed). Anything else is `invalid_request`
|
|
540
|
+
* with `path: "phone"`.
|
|
541
|
+
*/
|
|
542
|
+
phone: string;
|
|
543
|
+
/**
|
|
544
|
+
* TC kimlik no, exactly 11 digits. Sealed, never returned. Omitted, the
|
|
545
|
+
* one already on the cart is kept.
|
|
546
|
+
*/
|
|
547
|
+
identityNumber?: string;
|
|
548
|
+
}
|
|
549
|
+
/** Body of `carts.setAddress`. */
|
|
550
|
+
interface AddressInput {
|
|
551
|
+
/** Shipping address. */
|
|
552
|
+
shipping: Address;
|
|
553
|
+
/** Billing address; omitted or null = same as shipping. */
|
|
554
|
+
billing?: Address | null;
|
|
555
|
+
}
|
|
556
|
+
/** A shipping option offered for a cart. */
|
|
557
|
+
interface ShippingOption {
|
|
558
|
+
/** Option id (`standard` in 0.1.0). */
|
|
559
|
+
id: string;
|
|
560
|
+
/** Price for this cart, minor units. */
|
|
561
|
+
priceMinor: number;
|
|
562
|
+
}
|
|
563
|
+
/** `GET /v1/carts/:id/shipping-options`. */
|
|
564
|
+
interface ShippingOptionList {
|
|
565
|
+
/** The options this cart can use. */
|
|
566
|
+
items: ShippingOption[];
|
|
567
|
+
}
|
|
568
|
+
/** The known embed kinds. */
|
|
569
|
+
type CheckoutEmbedKind = 'iyzico-checkout-form';
|
|
570
|
+
/**
|
|
571
|
+
* The payment provider's checkout form, passed through from the payments
|
|
572
|
+
* service. Render it as its `kind` says; `iyzico-checkout-form` carries the
|
|
573
|
+
* provider's HTML + scripts in `content`.
|
|
574
|
+
*/
|
|
575
|
+
interface CheckoutEmbed {
|
|
576
|
+
/** How to render the form. */
|
|
577
|
+
kind: CheckoutEmbedKind | (string & {});
|
|
578
|
+
/** For `iyzico-checkout-form`: the HTML (with scripts) to inject. */
|
|
579
|
+
content?: string;
|
|
580
|
+
/** Other provider fields. */
|
|
581
|
+
[key: string]: unknown;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Why payment cannot be (re)opened: `paid` (paid or later), `cancelled`,
|
|
585
|
+
* `processing` (being finalised), or from the payments service `expired`,
|
|
586
|
+
* `failed`, `not_found`.
|
|
587
|
+
*/
|
|
588
|
+
type ClosedCheckoutPage = 'paid' | 'cancelled' | 'processing' | 'expired' | 'failed' | 'not_found' | (string & {});
|
|
589
|
+
/** Fields every checkout result has. */
|
|
590
|
+
interface CheckoutResultBase {
|
|
591
|
+
/** The order id. */
|
|
592
|
+
orderId: string;
|
|
593
|
+
/** Human-readable order number (`261115-ABCDEF`). */
|
|
594
|
+
orderNumber: string;
|
|
595
|
+
/**
|
|
596
|
+
* The buyer's order-status token, returned **once**, by the checkout that
|
|
597
|
+
* placed the order. Keep it: it is the only key to `orders.get`.
|
|
598
|
+
*/
|
|
599
|
+
token?: string;
|
|
600
|
+
/** The order's status, when the service read it (re-opened orders). */
|
|
601
|
+
orderStatus?: OrderStatus;
|
|
602
|
+
}
|
|
603
|
+
/** Render the provider's form in the page. */
|
|
604
|
+
interface EmbeddedCheckoutResult extends CheckoutResultBase {
|
|
605
|
+
/** Discriminator. */
|
|
606
|
+
presentation: 'embedded';
|
|
607
|
+
/** The form to render. */
|
|
608
|
+
embed: CheckoutEmbed;
|
|
609
|
+
}
|
|
610
|
+
/** Send the buyer's browser to `url` (top-level navigation, not an iframe). */
|
|
611
|
+
interface RedirectCheckoutResult extends CheckoutResultBase {
|
|
612
|
+
/** Discriminator. */
|
|
613
|
+
presentation: 'redirect';
|
|
614
|
+
/** The provider's payment page. */
|
|
615
|
+
url: string;
|
|
616
|
+
}
|
|
617
|
+
/** Payment cannot be (re)opened: show the order status page. */
|
|
618
|
+
interface ClosedCheckoutResult extends CheckoutResultBase {
|
|
619
|
+
/** Discriminator. */
|
|
620
|
+
presentation: 'closed';
|
|
621
|
+
/** Which state to show. */
|
|
622
|
+
page: ClosedCheckoutPage;
|
|
623
|
+
}
|
|
624
|
+
/** `POST /v1/carts/:id/checkout`, discriminated by `presentation`. */
|
|
625
|
+
type CheckoutResult = EmbeddedCheckoutResult | RedirectCheckoutResult | ClosedCheckoutResult;
|
|
626
|
+
/** Order status (the commerce module's values; future values pass through). */
|
|
627
|
+
type OrderStatus = 'pendingPayment' | 'paid' | 'fulfilling' | 'shipped' | 'delivered' | 'cancelled' | 'refunded' | 'partiallyRefunded' | (string & {});
|
|
628
|
+
/**
|
|
629
|
+
* Payment status. `processing` = the payment succeeded and the order is
|
|
630
|
+
* being updated (poll again).
|
|
631
|
+
*/
|
|
632
|
+
type PaymentStatus = 'none' | 'pending' | 'processing' | 'succeeded' | 'failed' | 'expired' | 'refunded' | 'partiallyRefunded' | (string & {});
|
|
633
|
+
/** Shipment status (the commerce module's values; future values pass through). */
|
|
634
|
+
type ShipmentStatus = 'requested' | 'created' | 'picked_up' | 'in_transit' | 'out_for_delivery' | 'delivered' | 'returned' | 'cancelled' | 'exception' | 'failed' | (string & {});
|
|
635
|
+
/** A line of a placed order. */
|
|
636
|
+
interface OrderLine {
|
|
637
|
+
/** Product id (what ad pixels and analytics use as item id). */
|
|
638
|
+
productId?: string | null;
|
|
639
|
+
/** Product name at order time. */
|
|
640
|
+
productName: string;
|
|
641
|
+
/** SKU at order time. */
|
|
642
|
+
sku: string;
|
|
643
|
+
/** Unit price, minor units. */
|
|
644
|
+
unitPriceMinor: number;
|
|
645
|
+
/** Units. */
|
|
646
|
+
quantity: number;
|
|
647
|
+
/** Line total, minor units. */
|
|
648
|
+
lineTotalMinor: number;
|
|
649
|
+
/** The buyer's text for this line; absent or null when there is none. */
|
|
650
|
+
personalization?: string | null;
|
|
651
|
+
}
|
|
652
|
+
/** A shipment of an order. */
|
|
653
|
+
interface OrderShipment {
|
|
654
|
+
/** Shipment status. */
|
|
655
|
+
status: ShipmentStatus;
|
|
656
|
+
/** Carrier name, or null. */
|
|
657
|
+
carrier: string | null;
|
|
658
|
+
/** Tracking number, or null. */
|
|
659
|
+
trackingNumber: string | null;
|
|
660
|
+
/** Carrier tracking page, or null. */
|
|
661
|
+
trackingUrl: string | null;
|
|
662
|
+
}
|
|
663
|
+
/** `GET /v1/orders/:id?token=` — what a buyer sees of an order. */
|
|
664
|
+
interface Order {
|
|
665
|
+
/** Order id. */
|
|
666
|
+
id: string;
|
|
667
|
+
/** Human-readable order number. */
|
|
668
|
+
orderNumber: string;
|
|
669
|
+
/** Order status. */
|
|
670
|
+
status: OrderStatus;
|
|
671
|
+
/** Payment status. */
|
|
672
|
+
paymentStatus: PaymentStatus;
|
|
673
|
+
/** ISO 4217 currency. */
|
|
674
|
+
currency: string;
|
|
675
|
+
/** Subtotal, minor units. */
|
|
676
|
+
subtotalMinor: number;
|
|
677
|
+
/** Shipping, minor units. */
|
|
678
|
+
shippingMinor: number;
|
|
679
|
+
/** Total, minor units. */
|
|
680
|
+
totalMinor: number;
|
|
681
|
+
/** When the order was placed (ISO date), or null. */
|
|
682
|
+
placedAt: string | null;
|
|
683
|
+
/** Shipping address as entered (string fields of the address shape). */
|
|
684
|
+
shippingAddress: Record<string, string> | null;
|
|
685
|
+
/** Billing address as entered, or null. */
|
|
686
|
+
billingAddress: Record<string, string> | null;
|
|
687
|
+
/** Order lines. */
|
|
688
|
+
lines: OrderLine[];
|
|
689
|
+
/** Shipments. */
|
|
690
|
+
shipments: OrderShipment[];
|
|
691
|
+
}
|
|
692
|
+
/** `POST /v1/account/session`: the signed-in buyer. */
|
|
693
|
+
interface AccountSession {
|
|
694
|
+
customer: {
|
|
695
|
+
email: string;
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
/** `PUT /v1/account/profile` body. */
|
|
699
|
+
interface AccountProfileInput {
|
|
700
|
+
/** First name (1-100 characters). */
|
|
701
|
+
name: string;
|
|
702
|
+
/** Surname (1-100 characters). */
|
|
703
|
+
surname: string;
|
|
704
|
+
/** Turkish mobile number in any common format; stored as `90XXXXXXXXXX`. */
|
|
705
|
+
phone: string;
|
|
706
|
+
}
|
|
707
|
+
/** A saved address as the API stores it. */
|
|
708
|
+
interface SavedAddress extends Address {
|
|
709
|
+
/** Server-assigned id. */
|
|
710
|
+
id: string;
|
|
711
|
+
/** Whether this is the default address (exactly one is, when any exist). */
|
|
712
|
+
isDefault: boolean;
|
|
713
|
+
}
|
|
714
|
+
/** A saved address to send: `id` is filled in by the server when absent. */
|
|
715
|
+
interface SavedAddressInput extends Address {
|
|
716
|
+
id?: string;
|
|
717
|
+
isDefault?: boolean;
|
|
718
|
+
}
|
|
719
|
+
/** One order in the account's order list. */
|
|
720
|
+
interface AccountOrder {
|
|
721
|
+
/** Order number shown to the buyer. */
|
|
722
|
+
number: string;
|
|
723
|
+
/** ISO time the order was placed, or null. */
|
|
724
|
+
placedAt: string | null;
|
|
725
|
+
/** Order status (see {@link OrderStatus}). */
|
|
726
|
+
status: string;
|
|
727
|
+
totalMinor: number;
|
|
728
|
+
currency: string;
|
|
729
|
+
/** Link to the order status page, or null when none exists yet. */
|
|
730
|
+
statusUrl: string | null;
|
|
731
|
+
}
|
|
732
|
+
/** `GET /v1/account`. Name, surname and phone are null until a profile is saved. */
|
|
733
|
+
interface Account {
|
|
734
|
+
email: string;
|
|
735
|
+
name: string | null;
|
|
736
|
+
surname: string | null;
|
|
737
|
+
phone: string | null;
|
|
738
|
+
savedAddresses: SavedAddress[];
|
|
739
|
+
/** One page of orders, newest first. */
|
|
740
|
+
orders: AccountOrder[];
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/** Default request timeout, milliseconds. */
|
|
744
|
+
declare const DEFAULT_TIMEOUT_MS = 15000;
|
|
745
|
+
/** Header carrying the publishable key on every request. */
|
|
746
|
+
declare const PUBLISHABLE_KEY_HEADER = "x-konfiqo-publishable-key";
|
|
747
|
+
/** Header carrying the trusted storefront key (server-side only). */
|
|
748
|
+
declare const STOREFRONT_KEY_HEADER = "x-konfiqo-storefront-key";
|
|
749
|
+
/** Header carrying the checkout challenge token (checkout only). */
|
|
750
|
+
declare const TURNSTILE_TOKEN_HEADER = "x-konfiqo-turnstile-token";
|
|
751
|
+
/** Header carrying the buyer's IP (only with a server key or the trusted storefront key). */
|
|
752
|
+
declare const BUYER_IP_HEADER = "x-konfiqo-buyer-ip";
|
|
753
|
+
/** Per-call options, accepted as the last argument of every method. */
|
|
754
|
+
interface RequestOptions {
|
|
755
|
+
/**
|
|
756
|
+
* Aborts the request: it rejects with code `aborted`. Combined with the
|
|
757
|
+
* client timeout (whichever comes first wins).
|
|
758
|
+
*/
|
|
759
|
+
signal?: AbortSignal;
|
|
760
|
+
/**
|
|
761
|
+
* **Server-side only.** A `Cookie` header to forward, so a server-rendered
|
|
762
|
+
* storefront can call the account routes as the buyer: pass the incoming
|
|
763
|
+
* request's `cookie` header (or just `konfiqo_session=<value>`). Browsers
|
|
764
|
+
* ignore a `Cookie` header set from script; there the session cookie rides
|
|
765
|
+
* along automatically (`credentials: 'include'`).
|
|
766
|
+
*/
|
|
767
|
+
cookie?: string;
|
|
768
|
+
}
|
|
769
|
+
/** Options of `account.requestCode`. */
|
|
770
|
+
interface RequestCodeOptions extends RequestOptions {
|
|
771
|
+
/**
|
|
772
|
+
* The challenge token (Cloudflare Turnstile), required when the store
|
|
773
|
+
* asks for one (`store.checkoutChallenge`). Single-use. Sent as
|
|
774
|
+
* `x-konfiqo-turnstile-token`.
|
|
775
|
+
*/
|
|
776
|
+
turnstileToken?: string;
|
|
777
|
+
}
|
|
778
|
+
/** Options of `carts.checkout`. */
|
|
779
|
+
interface CheckoutOptions extends RequestOptions {
|
|
780
|
+
/**
|
|
781
|
+
* The checkout challenge token (Cloudflare Turnstile), required when
|
|
782
|
+
* `store.checkoutChallenge` is set. Single-use: get a new one (reset the
|
|
783
|
+
* widget) for every checkout call. Sent as `x-konfiqo-turnstile-token`.
|
|
784
|
+
*/
|
|
785
|
+
turnstileToken?: string;
|
|
786
|
+
}
|
|
787
|
+
/** Options of {@link createStorefrontClient}. */
|
|
788
|
+
interface StorefrontClientOptions {
|
|
789
|
+
/**
|
|
790
|
+
* The Storefront API base: `https://<store domain>/api` (or the relative
|
|
791
|
+
* `/api` in a same-origin browser app). Requests go to `${baseUrl}/v1/...`,
|
|
792
|
+
* so do not include `/v1`.
|
|
793
|
+
*/
|
|
794
|
+
baseUrl: string;
|
|
795
|
+
/** The store's publishable key (`pk_live_…` / `pk_test_…`). Public. */
|
|
796
|
+
publishableKey: string;
|
|
797
|
+
/** A `fetch` implementation; defaults to the global `fetch`. */
|
|
798
|
+
fetch?: typeof fetch;
|
|
799
|
+
/** Per-request timeout in milliseconds (default {@link DEFAULT_TIMEOUT_MS}). */
|
|
800
|
+
timeoutMs?: number;
|
|
801
|
+
/**
|
|
802
|
+
* **Server-side only.** The shared storefront key that lets a server-side
|
|
803
|
+
* renderer report the real buyer IP (`buyerIp`), so throttling and the
|
|
804
|
+
* payment provider see the buyer instead of the server. Sent as
|
|
805
|
+
* `x-konfiqo-storefront-key`. Constructing a client with it where
|
|
806
|
+
* `window` exists throws: never ship this key to a browser.
|
|
807
|
+
*/
|
|
808
|
+
trustedStorefrontKey?: string;
|
|
809
|
+
/**
|
|
810
|
+
* **Server-side only.** The store's own server key, minted by the store
|
|
811
|
+
* operator. It lets the seller's server report the real buyer IP
|
|
812
|
+
* (`buyerIp`). Sent as `x-konfiqo-server-key` next to the publishable
|
|
813
|
+
* key. Needs `buyerIp`, cannot be combined with `trustedStorefrontKey`,
|
|
814
|
+
* and constructing a client with it in a browser throws.
|
|
815
|
+
*/
|
|
816
|
+
serverKey?: string;
|
|
817
|
+
/**
|
|
818
|
+
* The buyer's IP address, sent as `x-konfiqo-buyer-ip`. Required with
|
|
819
|
+
* `serverKey` or `trustedStorefrontKey`, ignored without one. Create one
|
|
820
|
+
* client per incoming request on the server.
|
|
821
|
+
*/
|
|
822
|
+
buyerIp?: string;
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* A typed client of the Storefront API (`/v1`).
|
|
826
|
+
*
|
|
827
|
+
* Every method returns the response body, or rejects with a
|
|
828
|
+
* {@link StorefrontError}. Nothing is retried: whether to retry is the
|
|
829
|
+
* caller's decision, because writes are not safely repeatable — in
|
|
830
|
+
* particular `carts.checkout` on a cart whose order failed places a
|
|
831
|
+
* **new** order, so a blind retry could open a second payment.
|
|
832
|
+
*/
|
|
833
|
+
interface StorefrontClient {
|
|
834
|
+
/**
|
|
835
|
+
* `GET /v1/content/:key`: a piece of store content as a renderable
|
|
836
|
+
* Markdoc tree. Rejects `content_not_found` (404) for an unknown key.
|
|
837
|
+
*/
|
|
838
|
+
getContent(key: string, options?: RequestOptions): Promise<StoreContent>;
|
|
839
|
+
/** Store information. */
|
|
840
|
+
readonly store: {
|
|
841
|
+
/** `GET /v1/store`: name, language, currency, logo, theme, contact, legal texts, shipping rules. */
|
|
842
|
+
get(options?: RequestOptions): Promise<Store>;
|
|
843
|
+
};
|
|
844
|
+
/** Categories. */
|
|
845
|
+
readonly categories: {
|
|
846
|
+
/** `GET /v1/categories`: the active category tree. */
|
|
847
|
+
list(options?: RequestOptions): Promise<CategoryList>;
|
|
848
|
+
};
|
|
849
|
+
/** Products. */
|
|
850
|
+
readonly products: {
|
|
851
|
+
/** `GET /v1/products`: a page of products, optionally filtered. */
|
|
852
|
+
list(query?: ProductListQuery, options?: RequestOptions): Promise<ProductPage>;
|
|
853
|
+
/** `GET /v1/products/:slug`. Rejects with `product_not_found`. */
|
|
854
|
+
get(slug: string, options?: RequestOptions): Promise<Product>;
|
|
855
|
+
};
|
|
856
|
+
/** Carts. Every cart write answers the updated cart. */
|
|
857
|
+
readonly carts: {
|
|
858
|
+
/** `POST /v1/carts`: a new, empty cart. */
|
|
859
|
+
create(options?: RequestOptions): Promise<Cart>;
|
|
860
|
+
/**
|
|
861
|
+
* `POST /v1/carts/recover`: turns the `t` token of an abandoned-cart
|
|
862
|
+
* e-mail link into a **new** cart with the same lines (no buyer data).
|
|
863
|
+
* Rejects `invalid_recovery_token` (400) or `cart_not_recoverable` (410:
|
|
864
|
+
* the cart was ordered, expired or deleted).
|
|
865
|
+
*/
|
|
866
|
+
recover(token: string, options?: RequestOptions): Promise<{
|
|
867
|
+
cartId: string;
|
|
868
|
+
}>;
|
|
869
|
+
/** `GET /v1/carts/:id`. Also reopens a cart whose payment failed. */
|
|
870
|
+
get(cartId: string, options?: RequestOptions): Promise<Cart>;
|
|
871
|
+
/** `POST /v1/carts/:id/lines`: adds units of a variant. */
|
|
872
|
+
addLine(cartId: string, input: AddLineInput, options?: RequestOptions): Promise<Cart>;
|
|
873
|
+
/**
|
|
874
|
+
* `PATCH /v1/carts/:id/lines/:lineId`: sets a line's quantity. `lineId`
|
|
875
|
+
* is `CartLine.id`; a variant id still matches a line without text.
|
|
876
|
+
*/
|
|
877
|
+
updateLine(cartId: string, lineId: string, input: UpdateLineInput, options?: RequestOptions): Promise<Cart>;
|
|
878
|
+
/** `DELETE /v1/carts/:id/lines/:lineId`: removes a line (`CartLine.id`). */
|
|
879
|
+
removeLine(cartId: string, lineId: string, options?: RequestOptions): Promise<Cart>;
|
|
880
|
+
/** `PUT /v1/carts/:id/customer`: sets the buyer. */
|
|
881
|
+
setCustomer(cartId: string, input: CustomerInput, options?: RequestOptions): Promise<Cart>;
|
|
882
|
+
/** `PUT /v1/carts/:id/address`: sets the shipping (and billing) address. */
|
|
883
|
+
setAddress(cartId: string, input: AddressInput, options?: RequestOptions): Promise<Cart>;
|
|
884
|
+
/** `GET /v1/carts/:id/shipping-options`: the options this cart can use. */
|
|
885
|
+
shippingOptions(cartId: string, options?: RequestOptions): Promise<ShippingOptionList>;
|
|
886
|
+
/** `PUT /v1/carts/:id/shipping-option`: selects a shipping option by id. */
|
|
887
|
+
setShippingOption(cartId: string, optionId: string, options?: RequestOptions): Promise<Cart>;
|
|
888
|
+
/**
|
|
889
|
+
* `POST /v1/carts/:id/checkout`: places the order (or re-opens payment
|
|
890
|
+
* for the cart's order) and answers how to present payment. Keep the
|
|
891
|
+
* returned `token`: it is returned only once. Not retried.
|
|
892
|
+
*
|
|
893
|
+
* Aborting (`signal`) only stops waiting: the server may still place
|
|
894
|
+
* the order. Read the cart again before showing a result.
|
|
895
|
+
*
|
|
896
|
+
* When `store.checkoutChallenge` is set, pass a fresh
|
|
897
|
+
* `turnstileToken` (see `renderTurnstile`); tokens are single-use, so
|
|
898
|
+
* reset the widget after every call. Re-opening payment on an already
|
|
899
|
+
* ordered cart needs no token.
|
|
900
|
+
*/
|
|
901
|
+
checkout(cartId: string, options?: CheckoutOptions): Promise<CheckoutResult>;
|
|
902
|
+
};
|
|
903
|
+
/** Buyer order status. */
|
|
904
|
+
readonly orders: {
|
|
905
|
+
/** `GET /v1/orders/:id?token=`: the order, for the buyer holding its token. */
|
|
906
|
+
get(orderId: string, token: string, options?: RequestOptions): Promise<Order>;
|
|
907
|
+
};
|
|
908
|
+
/**
|
|
909
|
+
* The signed-in buyer's account. Sign-in is by an e-mailed one-time code;
|
|
910
|
+
* the session is an HttpOnly cookie (`konfiqo_session`) the API sets on the
|
|
911
|
+
* store origin, so these calls send `credentials: 'include'`. On a server,
|
|
912
|
+
* forward the buyer's cookie with the `cookie` call option.
|
|
913
|
+
*/
|
|
914
|
+
readonly account: {
|
|
915
|
+
/**
|
|
916
|
+
* `POST /v1/account/code`: e-mails a 6-digit code. Resolves the same for
|
|
917
|
+
* any address (202); rejects `too_many_code_requests` (429),
|
|
918
|
+
* `challenge_required` / `challenge_failed`, `invalid_request`.
|
|
919
|
+
*/
|
|
920
|
+
requestCode(email: string, options?: RequestCodeOptions): Promise<void>;
|
|
921
|
+
/**
|
|
922
|
+
* `POST /v1/account/session`: signs in with the code. A wrong, spent or
|
|
923
|
+
* expired code rejects `invalid_code` (401).
|
|
924
|
+
*/
|
|
925
|
+
signIn(email: string, code: string, options?: RequestOptions): Promise<AccountSession>;
|
|
926
|
+
/** `DELETE /v1/account/session`: signs out (always succeeds). */
|
|
927
|
+
signOut(options?: RequestOptions): Promise<void>;
|
|
928
|
+
/**
|
|
929
|
+
* `GET /v1/account[?page=]`: profile, saved addresses and a page of
|
|
930
|
+
* orders (20 per page, newest first). Rejects `not_signed_in` (401).
|
|
931
|
+
*/
|
|
932
|
+
get(page?: number, options?: RequestOptions): Promise<Account>;
|
|
933
|
+
/**
|
|
934
|
+
* `PUT /v1/account/profile`: saves name, surname and a Turkish mobile
|
|
935
|
+
* phone. Creates the buyer's record on first save.
|
|
936
|
+
*/
|
|
937
|
+
updateProfile(profile: AccountProfileInput, options?: RequestOptions): Promise<void>;
|
|
938
|
+
/**
|
|
939
|
+
* `PUT /v1/account/addresses`: replaces the saved addresses (at most 5,
|
|
940
|
+
* at most one default). Resolves the list as stored (ids filled in).
|
|
941
|
+
* Rejects `profile_required` (409) until a profile is saved.
|
|
942
|
+
*/
|
|
943
|
+
saveAddresses(addresses: SavedAddressInput[], options?: RequestOptions): Promise<SavedAddress[]>;
|
|
944
|
+
};
|
|
945
|
+
/** Catalog images. */
|
|
946
|
+
readonly media: {
|
|
947
|
+
/**
|
|
948
|
+
* The absolute URL of a storage key (product `image`, store `logo`,
|
|
949
|
+
* theme `logo` / `favicon` / section `image`), usable in `<img src>`:
|
|
950
|
+
* `${baseUrl}/v1/media/<key, each segment encoded>?pk=<publishable key>`.
|
|
951
|
+
*
|
|
952
|
+
* @throws TypeError (`invalid_path_segment`) when a key segment is
|
|
953
|
+
* empty, `.` or `..`.
|
|
954
|
+
*/
|
|
955
|
+
url(key: string): string;
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Creates a Storefront API client.
|
|
960
|
+
*
|
|
961
|
+
* @throws TypeError when `baseUrl` or `publishableKey` is empty, when
|
|
962
|
+
* `serverKey` or `trustedStorefrontKey` is given without `buyerIp`, when
|
|
963
|
+
* both keys are given together, or when either key is given in a
|
|
964
|
+
* browser-like host (`window` or `document` defined, or a web worker).
|
|
965
|
+
* Hosts that define `window` on a server (jsdom, Electron renderers,
|
|
966
|
+
* React Native) are refused too: keep these keys in a plain server process.
|
|
967
|
+
*/
|
|
968
|
+
declare function createStorefrontClient(options: StorefrontClientOptions): StorefrontClient;
|
|
969
|
+
|
|
970
|
+
/** `checkout_incomplete`: what the cart still lacks. */
|
|
971
|
+
type CheckoutMissing = 'lines' | 'customer' | 'identityNumber' | 'shippingAddress' | 'shippingOption';
|
|
972
|
+
/**
|
|
973
|
+
* `invalid_buyer_details`: the buyer detail the payment provider refused.
|
|
974
|
+
* Address fields come as `shippingAddress.<field>` / `billingAddress.<field>`.
|
|
975
|
+
*/
|
|
976
|
+
type BuyerDetailField = 'name' | 'surname' | 'email' | 'phone' | 'identityNumber' | `shippingAddress.${string}` | `billingAddress.${string}`;
|
|
977
|
+
/** One validation problem of an `invalid_request`. */
|
|
978
|
+
interface ValidationIssue {
|
|
979
|
+
/** Dotted path of the field (`phone`, `shipping.city`, …). */
|
|
980
|
+
path: string;
|
|
981
|
+
/** What is wrong with it (never echoes the submitted value). */
|
|
982
|
+
message: string;
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* The extras each error code carries (`StorefrontError.details`). Codes
|
|
986
|
+
* not listed here carry no details (`undefined`).
|
|
987
|
+
*/
|
|
988
|
+
interface StorefrontErrorDetailsMap {
|
|
989
|
+
/** Prices or shipping changed: show the new totals, then check out again. */
|
|
990
|
+
cart_changed: {
|
|
991
|
+
lines: CartLine[];
|
|
992
|
+
subtotalMinor: number;
|
|
993
|
+
shippingMinor: number;
|
|
994
|
+
totalMinor: number;
|
|
995
|
+
shippingOptions: ShippingOption[];
|
|
996
|
+
};
|
|
997
|
+
/**
|
|
998
|
+
* A personalization text is refused (400, no details) or, at checkout
|
|
999
|
+
* (409), a line's stored text no longer satisfies the product's rule:
|
|
1000
|
+
* `lineIds` are those lines. Remove the line and add it again with a
|
|
1001
|
+
* valid text.
|
|
1002
|
+
*/
|
|
1003
|
+
invalid_personalization: {
|
|
1004
|
+
lineIds?: string[];
|
|
1005
|
+
};
|
|
1006
|
+
/** These variants cannot be bought (no longer sold, or not enough units). */
|
|
1007
|
+
out_of_stock: {
|
|
1008
|
+
variantIds: string[];
|
|
1009
|
+
};
|
|
1010
|
+
/** Collect what is missing, then check out again. */
|
|
1011
|
+
checkout_incomplete: {
|
|
1012
|
+
missing: CheckoutMissing[];
|
|
1013
|
+
};
|
|
1014
|
+
/** Let the buyer fix `field`, then check out again. */
|
|
1015
|
+
invalid_buyer_details: {
|
|
1016
|
+
field: BuyerDetailField;
|
|
1017
|
+
};
|
|
1018
|
+
/** Only `available` units can be added. */
|
|
1019
|
+
insufficient_stock: {
|
|
1020
|
+
available: number;
|
|
1021
|
+
};
|
|
1022
|
+
/** The request body or query failed validation. */
|
|
1023
|
+
invalid_request: {
|
|
1024
|
+
issues: ValidationIssue[];
|
|
1025
|
+
};
|
|
1026
|
+
/** The cart can no longer change: start a new cart. */
|
|
1027
|
+
cart_read_only: {
|
|
1028
|
+
status: 'ordered' | 'expired';
|
|
1029
|
+
};
|
|
1030
|
+
/** Throttled. `retryAfter` = seconds to wait, when the response said so. */
|
|
1031
|
+
rate_limited: {
|
|
1032
|
+
retryAfter?: number;
|
|
1033
|
+
};
|
|
1034
|
+
/** No response within `timeoutMs`. */
|
|
1035
|
+
timeout: {
|
|
1036
|
+
timeoutMs: number;
|
|
1037
|
+
};
|
|
1038
|
+
/** The server answered an error code this SDK version does not know. */
|
|
1039
|
+
unknown_error: {
|
|
1040
|
+
error: string | null;
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
/** Error codes of the Storefront API (the `error` field of an error response). */
|
|
1044
|
+
type StorefrontApiErrorCode = 'store_not_found' | 'origin_not_allowed' | 'invalid_request' | 'invalid_buyer_ip' | 'catalog_unavailable' | 'product_not_found' | 'content_not_found' | 'cart_not_found' | 'variant_not_found' | 'line_not_found' | 'insufficient_stock' | 'quantity_out_of_range' | 'too_many_lines' | 'invalid_shipping_option' | 'cart_read_only' | 'checkout_in_progress' | 'checkout_incomplete' | 'cart_changed' | 'invalid_personalization' | 'out_of_stock' | 'amount_out_of_range' | 'nothing_to_pay' | 'invalid_buyer_details' | 'payment_unavailable' | 'checkout_unavailable' | 'order_not_found' | 'order_unavailable' | 'media_not_found' | 'media_unavailable' | 'challenge_required' | 'challenge_failed' | 'challenge_unavailable' | 'too_many_open_orders' | 'not_signed_in' | 'invalid_code' | 'profile_required' | 'too_many_code_requests' | 'invalid_recovery_token' | 'cart_not_recoverable' | 'unavailable';
|
|
1045
|
+
/**
|
|
1046
|
+
* Codes the SDK assigns itself:
|
|
1047
|
+
* - `rate_limited` — HTTP 429 without a known `error` code (the throttler);
|
|
1048
|
+
* - `unauthorized` — HTTP 401 without a code (a wrong `trustedStorefrontKey`);
|
|
1049
|
+
* - `http_error` — any other non-2xx response without an `error` code;
|
|
1050
|
+
* - `unknown_error` — an `error` code this SDK version does not know (in `details.error`);
|
|
1051
|
+
* - `invalid_response` — a 2xx response that is not JSON;
|
|
1052
|
+
* - `network_error` — no readable response: the API was unreachable (DNS,
|
|
1053
|
+
* TLS, offline), or, in a browser, the origin is allowed by no store;
|
|
1054
|
+
* - `timeout` — no response within `timeoutMs`;
|
|
1055
|
+
* - `aborted` — the caller's `signal` aborted the request.
|
|
1056
|
+
*/
|
|
1057
|
+
type StorefrontClientErrorCode = 'rate_limited' | 'unauthorized' | 'http_error' | 'unknown_error' | 'invalid_response' | 'network_error' | 'timeout' | 'aborted';
|
|
1058
|
+
/** Every code a {@link StorefrontError} can have. */
|
|
1059
|
+
type StorefrontErrorCode = StorefrontApiErrorCode | StorefrontClientErrorCode;
|
|
1060
|
+
/** The `details` type of an error code (`undefined` for codes without extras). */
|
|
1061
|
+
type StorefrontErrorDetails<C extends StorefrontErrorCode> = C extends keyof StorefrontErrorDetailsMap ? StorefrontErrorDetailsMap[C] : undefined;
|
|
1062
|
+
/**
|
|
1063
|
+
* Every failure of a client call: an API error response, a throttle, a
|
|
1064
|
+
* timeout or a transport failure. Switch on `code`, never on `message`.
|
|
1065
|
+
*
|
|
1066
|
+
* To get `details` typed per code, narrow with {@link isStorefrontError}
|
|
1067
|
+
* (which yields the {@link AnyStorefrontError} union) and `switch (e.code)`,
|
|
1068
|
+
* or test one code with `e.is('cart_changed')`.
|
|
1069
|
+
*/
|
|
1070
|
+
declare class StorefrontError<C extends StorefrontErrorCode = StorefrontErrorCode> extends Error {
|
|
1071
|
+
/** The API `error` code, or one of the SDK's own codes. */
|
|
1072
|
+
readonly code: C;
|
|
1073
|
+
/** HTTP status; `0` when no response arrived (`network_error`, `timeout`). */
|
|
1074
|
+
readonly status: number;
|
|
1075
|
+
/** The code's extras (see {@link StorefrontErrorDetailsMap}). */
|
|
1076
|
+
readonly details: StorefrontErrorDetails<C>;
|
|
1077
|
+
/**
|
|
1078
|
+
* @param code - the error code
|
|
1079
|
+
* @param status - the HTTP status (`0` without a response)
|
|
1080
|
+
* @param message - a human-readable description (not for display logic)
|
|
1081
|
+
* @param details - the code's extras
|
|
1082
|
+
* @param options - `cause`: the underlying error, if any
|
|
1083
|
+
*/
|
|
1084
|
+
constructor(code: C, status: number, message: string, details: StorefrontErrorDetails<C>, options?: {
|
|
1085
|
+
cause?: unknown;
|
|
1086
|
+
});
|
|
1087
|
+
/** Whether this error has `code`; narrows `details` to that code's extras. */
|
|
1088
|
+
is<K extends StorefrontErrorCode>(code: K): this is StorefrontError<K>;
|
|
1089
|
+
}
|
|
1090
|
+
/**
|
|
1091
|
+
* The union of {@link StorefrontError} by code: after narrowing `code`
|
|
1092
|
+
* (e.g. in a `switch`), `details` has that code's type.
|
|
1093
|
+
*/
|
|
1094
|
+
type AnyStorefrontError = {
|
|
1095
|
+
[C in StorefrontErrorCode]: StorefrontError<C>;
|
|
1096
|
+
}[StorefrontErrorCode];
|
|
1097
|
+
/**
|
|
1098
|
+
* Whether `e` is a {@link StorefrontError}, as the code-discriminated union.
|
|
1099
|
+
* Also true for an error from another copy of this SDK (checked by a global
|
|
1100
|
+
* brand, not only `instanceof`).
|
|
1101
|
+
*/
|
|
1102
|
+
declare function isStorefrontError(e: unknown): e is AnyStorefrontError;
|
|
1103
|
+
|
|
1104
|
+
/**
|
|
1105
|
+
* What {@link mountPayment} renders: a checkout result, or just its
|
|
1106
|
+
* presentation part.
|
|
1107
|
+
*/
|
|
1108
|
+
type PaymentPresentation = Pick<EmbeddedCheckoutResult, 'presentation' | 'embed'> | Pick<RedirectCheckoutResult, 'presentation' | 'url'> | Pick<ClosedCheckoutResult, 'presentation' | 'page'>;
|
|
1109
|
+
/** Options of {@link mountPayment}. */
|
|
1110
|
+
interface MountPaymentOptions {
|
|
1111
|
+
/**
|
|
1112
|
+
* Called for `presentation: "closed"` with the page to show (`paid`,
|
|
1113
|
+
* `cancelled`, `processing`, …). Typically: go to the order status page.
|
|
1114
|
+
*/
|
|
1115
|
+
onClosed?: (page: ClosedCheckoutPage) => void;
|
|
1116
|
+
}
|
|
1117
|
+
/** The provider form is in the element. */
|
|
1118
|
+
interface EmbeddedPaymentMount {
|
|
1119
|
+
/** Discriminator. */
|
|
1120
|
+
kind: 'embedded';
|
|
1121
|
+
/** Removes the form from the element. */
|
|
1122
|
+
unmount(): void;
|
|
1123
|
+
}
|
|
1124
|
+
/** The browser is navigating to the provider's payment page. */
|
|
1125
|
+
interface RedirectPaymentMount {
|
|
1126
|
+
/** Discriminator. */
|
|
1127
|
+
kind: 'redirect';
|
|
1128
|
+
/** Where the browser was sent. */
|
|
1129
|
+
url: string;
|
|
1130
|
+
}
|
|
1131
|
+
/** Payment cannot be opened; `onClosed` was called. */
|
|
1132
|
+
interface ClosedPaymentMount {
|
|
1133
|
+
/** Discriminator. */
|
|
1134
|
+
kind: 'closed';
|
|
1135
|
+
/** The page to show. */
|
|
1136
|
+
page: ClosedCheckoutPage;
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* The embed has a `kind` this SDK version cannot render. Nothing was put
|
|
1140
|
+
* in the element; show a fallback (e.g. "payment unavailable").
|
|
1141
|
+
*/
|
|
1142
|
+
interface UnsupportedPaymentMount {
|
|
1143
|
+
/** Discriminator. */
|
|
1144
|
+
kind: 'unsupported';
|
|
1145
|
+
/** The embed kind that was not understood. */
|
|
1146
|
+
embedKind: string;
|
|
1147
|
+
}
|
|
1148
|
+
/** The result of {@link mountPayment}, discriminated by `kind`. */
|
|
1149
|
+
type PaymentMount = EmbeddedPaymentMount | RedirectPaymentMount | ClosedPaymentMount | UnsupportedPaymentMount;
|
|
1150
|
+
/**
|
|
1151
|
+
* Presents payment from a checkout result. Card data never touches your
|
|
1152
|
+
* page's code: the form is the provider's own, or a redirect.
|
|
1153
|
+
*
|
|
1154
|
+
* - `embedded` (`iyzico-checkout-form`): puts the provider's HTML into
|
|
1155
|
+
* `element` and re-creates every `<script>` in it so it executes
|
|
1156
|
+
* (`innerHTML` alone never runs scripts). Idempotent per element:
|
|
1157
|
+
* mounting the same content again does nothing, other content replaces
|
|
1158
|
+
* the previous form — scripts are never injected twice.
|
|
1159
|
+
* - `redirect`: top-level navigation to the provider page
|
|
1160
|
+
* (`location.assign`). Only `http:` / `https:` URLs are followed.
|
|
1161
|
+
* - `closed`: calls `onClosed(page)`.
|
|
1162
|
+
*
|
|
1163
|
+
* Browser only (needs a DOM).
|
|
1164
|
+
*
|
|
1165
|
+
* @throws TypeError for a redirect URL that is not `http(s)`.
|
|
1166
|
+
*/
|
|
1167
|
+
declare function mountPayment(element: HTMLElement, presentation: PaymentPresentation | CheckoutResult, options?: MountPaymentOptions): PaymentMount;
|
|
1168
|
+
|
|
1169
|
+
/**
|
|
1170
|
+
* Formats an integer amount of minor units (kuruş, cents, …) as a
|
|
1171
|
+
* localised currency string with `Intl.NumberFormat`, using the currency's
|
|
1172
|
+
* own number of minor digits (2 for `TRY`, 0 for `JPY`).
|
|
1173
|
+
*
|
|
1174
|
+
* @example formatMoney(14990, 'TRY', 'tr-TR') // "₺149,90"
|
|
1175
|
+
* @throws TypeError when `minor` is not a finite number; RangeError for an
|
|
1176
|
+
* unknown currency code (from `Intl`).
|
|
1177
|
+
*/
|
|
1178
|
+
declare function formatMoney(minor: number, currency: string, locale?: string | string[]): string;
|
|
1179
|
+
|
|
1180
|
+
/**
|
|
1181
|
+
* The part of the Web Storage API the cart-id helpers use; `localStorage`,
|
|
1182
|
+
* `sessionStorage` or any object with these methods (a cookie adapter, a
|
|
1183
|
+
* test double).
|
|
1184
|
+
*/
|
|
1185
|
+
interface CartIdStorage {
|
|
1186
|
+
/** Reads a value, or null. */
|
|
1187
|
+
getItem(key: string): string | null;
|
|
1188
|
+
/** Writes a value. */
|
|
1189
|
+
setItem(key: string, value: string): void;
|
|
1190
|
+
/** Deletes a value. */
|
|
1191
|
+
removeItem(key: string): void;
|
|
1192
|
+
}
|
|
1193
|
+
/** The storage key of a store's cart id. Namespaced per store. */
|
|
1194
|
+
declare function cartIdKey(storeId: string): string;
|
|
1195
|
+
/**
|
|
1196
|
+
* The saved cart id of a store, or null. Never throws: a missing storage
|
|
1197
|
+
* (SSR), a storage that throws (Safari private mode, blocked cookies) or
|
|
1198
|
+
* an empty value all read as null.
|
|
1199
|
+
*/
|
|
1200
|
+
declare function loadCartId(storage: CartIdStorage | null | undefined, storeId: string): string | null;
|
|
1201
|
+
/** Saves a store's cart id. Returns false when the storage refused. Never throws. */
|
|
1202
|
+
declare function saveCartId(storage: CartIdStorage | null | undefined, storeId: string, cartId: string): boolean;
|
|
1203
|
+
/**
|
|
1204
|
+
* Forgets a store's cart id (after `cart_not_found`, or `cart_read_only`
|
|
1205
|
+
* with `status: "expired"`). Returns false when the storage refused. Never throws.
|
|
1206
|
+
*/
|
|
1207
|
+
declare function clearCartId(storage: CartIdStorage | null | undefined, storeId: string): boolean;
|
|
1208
|
+
/** The part of `document` the cookie storage uses. */
|
|
1209
|
+
interface CookieJar {
|
|
1210
|
+
cookie: string;
|
|
1211
|
+
}
|
|
1212
|
+
/**
|
|
1213
|
+
* Cart ids in the first-party `__Host-konfiqo_cart` cookie (path
|
|
1214
|
+
* `/`, no `Domain`, `SameSite=Lax`, `Secure`). The `__Host-` prefix makes
|
|
1215
|
+
* browsers refuse a cookie of this name scoped to a parent domain, so a
|
|
1216
|
+
* sibling store subdomain cannot plant a cart; the old unprefixed
|
|
1217
|
+
* `konfiqo_cart` is never read. The value is a JSON map keyed by
|
|
1218
|
+
* {@link cartIdKey}, so a store's own frontend and the hosted checkout on the same domain share
|
|
1219
|
+
* the cart. `Secure` cookies are dropped by browsers on plain `http`
|
|
1220
|
+
* (other than `localhost`), so over http nothing is stored here; pair it
|
|
1221
|
+
* with a `localStorage` fallback. Without a document (SSR) it reads nothing and writes fail.
|
|
1222
|
+
* Never throws; a malformed or oversized cookie is ignored.
|
|
1223
|
+
*
|
|
1224
|
+
* @param doc Defaults to the global `document`; `null` disables it.
|
|
1225
|
+
*/
|
|
1226
|
+
declare function cookieCartStorage(doc?: CookieJar | null): CartIdStorage;
|
|
1227
|
+
|
|
1228
|
+
/**
|
|
1229
|
+
* Cloudflare's official Turnstile script, explicit-render mode. The only
|
|
1230
|
+
* URL {@link loadTurnstile} ever injects.
|
|
1231
|
+
*/
|
|
1232
|
+
declare const TURNSTILE_SCRIPT_URL = "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit";
|
|
1233
|
+
/** The subset of Cloudflare's `window.turnstile` API the SDK uses. */
|
|
1234
|
+
interface TurnstileApi {
|
|
1235
|
+
/** Renders a widget into `container`; returns its widget id. */
|
|
1236
|
+
render(container: HTMLElement | string, params: {
|
|
1237
|
+
sitekey: string;
|
|
1238
|
+
callback?: (token: string) => void;
|
|
1239
|
+
'expired-callback'?: () => void;
|
|
1240
|
+
'error-callback'?: (code?: string) => void;
|
|
1241
|
+
[key: string]: unknown;
|
|
1242
|
+
}): string | null | undefined;
|
|
1243
|
+
/** Resets a widget so it produces a new token. */
|
|
1244
|
+
reset(widgetId?: string): void;
|
|
1245
|
+
/** Removes a widget. */
|
|
1246
|
+
remove(widgetId?: string): void;
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Loads Cloudflare Turnstile into `document` (once: the script is injected
|
|
1250
|
+
* at most once per document, concurrent calls share one load) and resolves
|
|
1251
|
+
* with `window.turnstile`. Rejects when the script fails to load; the
|
|
1252
|
+
* failed `<script>` is removed, so calling again injects a fresh one.
|
|
1253
|
+
*/
|
|
1254
|
+
declare function loadTurnstile(document: Document): Promise<TurnstileApi>;
|
|
1255
|
+
/** Callbacks of {@link renderTurnstile}. */
|
|
1256
|
+
interface RenderTurnstileOptions {
|
|
1257
|
+
/** A token is ready: keep it for the next `carts.checkout` call. */
|
|
1258
|
+
onToken: (token: string) => void;
|
|
1259
|
+
/** The token expired unused (about 5 minutes): drop it; the widget refreshes. */
|
|
1260
|
+
onExpired?: () => void;
|
|
1261
|
+
/** The widget failed (network, unsupported browser, …). */
|
|
1262
|
+
onError?: (code?: string) => void;
|
|
1263
|
+
}
|
|
1264
|
+
/** A rendered Turnstile widget. */
|
|
1265
|
+
interface TurnstileWidget {
|
|
1266
|
+
/** The widget id. */
|
|
1267
|
+
readonly widgetId: string;
|
|
1268
|
+
/**
|
|
1269
|
+
* Gets a new token. Call it after every `carts.checkout` that used the
|
|
1270
|
+
* current token: tokens are **single-use**.
|
|
1271
|
+
*/
|
|
1272
|
+
reset(): void;
|
|
1273
|
+
/** Removes the widget. */
|
|
1274
|
+
remove(): void;
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* Renders a Turnstile widget with the store's `siteKey`
|
|
1278
|
+
* (`store.checkoutChallenge.siteKey`) into `element`, loading the script
|
|
1279
|
+
* first if needed. Pass each token from `onToken` to
|
|
1280
|
+
* `carts.checkout(id, { turnstileToken })`, then `reset()`.
|
|
1281
|
+
*/
|
|
1282
|
+
declare function renderTurnstile(element: HTMLElement, siteKey: string, options: RenderTurnstileOptions): Promise<TurnstileWidget>;
|
|
1283
|
+
|
|
1284
|
+
/** Version of the Storefront SDK package. */
|
|
1285
|
+
declare const SDK_VERSION = "0.5.0";
|
|
1286
|
+
|
|
1287
|
+
export { type Account, type AccountOrder, type AccountProfileInput, type AccountSession, type AdPixels, type AddLineInput, type Address, type AddressInput, type AnyStorefrontError, BUYER_IP_HEADER, type BuyerDetailField, type Cart, type CartCustomer, type CartIdStorage, type CartLine, type CartStatus, type Category, type CategoryGridSection, type CategoryList, type CheckoutChallenge, type CheckoutEmbed, type CheckoutEmbedKind, type CheckoutMissing, type CheckoutOptions, type CheckoutResult, type CheckoutResultBase, type ClosedCheckoutPage, type ClosedCheckoutResult, type ClosedPaymentMount, type ContentNode, type CookieCategory, type CookieInfo, type CookieJar, type CustomerInput, DEFAULT_TIMEOUT_MS, type EmbeddedCheckoutResult, type EmbeddedPaymentMount, type FeaturedProductsSection, type HeroSection, type KnownThemeSection, type MountPaymentOptions, type Order, type OrderLine, type OrderShipment, type OrderStatus, PUBLISHABLE_KEY_HEADER, type Pagination, type PaymentMount, type PaymentPresentation, type PaymentStatus, type Product, type ProductListQuery, type ProductPage, type ProductPersonalization, type ProductVariant, type RedirectCheckoutResult, type RedirectPaymentMount, type RenderTurnstileOptions, type RequestCodeOptions, type RequestOptions, type RichTextSection, SDK_VERSION, STOREFRONT_KEY_HEADER, type SavedAddress, type SavedAddressInput, type ShipmentStatus, type ShippingOption, type ShippingOptionList, type ShippingRules, type Store, type StoreContact, type StoreContent, type StoreLegal, type StorefrontApiErrorCode, type StorefrontClient, type StorefrontClientErrorCode, type StorefrontClientOptions, StorefrontError, type StorefrontErrorCode, type StorefrontErrorDetails, type StorefrontErrorDetailsMap, THEME_FONTS, TURNSTILE_SCRIPT_URL, TURNSTILE_TOKEN_HEADER, type ThemeColors, type ThemeFont, type ThemeFooter, type ThemeHomepage, type ThemeLink, type ThemeSection, type ThemeSocial, type ThemeV1, type TurnstileApi, type TurnstileWidget, type UnknownThemeSection, type UnsupportedPaymentMount, type UpdateLineInput, type ValidationIssue, cartIdKey, clearCartId, cookieCartStorage, createStorefrontClient, formatMoney, isKnownThemeSection, isStorefrontError, loadCartId, loadTurnstile, mountPayment, renderTurnstile, saveCartId };
|