@konfiqo/storefront-sdk 0.0.0-stage → 0.4.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.
@@ -0,0 +1,1236 @@
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
+ /** A product. Only products with at least one sellable variant are listed. */
328
+ interface Product {
329
+ /** Product id. */
330
+ id: string;
331
+ /** URL slug; the argument of `products.get`. */
332
+ slug: string;
333
+ /** Display name. */
334
+ name: string;
335
+ /** Description as the seller wrote it, or null. */
336
+ description: string | null;
337
+ /** Storage key of the product image, or null. */
338
+ image: string | null;
339
+ /**
340
+ * Media URL of `image`, **relative** (`/v1/media/<key>?pk=<key>`): prefix
341
+ * the API origin, or use `client.media.url(product.image)`.
342
+ */
343
+ imageUrl: string | null;
344
+ /** SEO title override, or null (use `name`). */
345
+ seoTitle: string | null;
346
+ /** SEO description, or null. */
347
+ seoDescription: string | null;
348
+ /** The product's (live) category, or null. */
349
+ category: {
350
+ slug: string;
351
+ name: string;
352
+ } | null;
353
+ /** Sellable variants. */
354
+ variants: ProductVariant[];
355
+ }
356
+ /** Paging information of a list. */
357
+ interface Pagination {
358
+ /** 1-based page number. */
359
+ page: number;
360
+ /** Items per page. */
361
+ pageSize: number;
362
+ /** Items matching the query. */
363
+ totalItems: number;
364
+ /** Pages for the query (`0` when nothing matches). */
365
+ totalPages: number;
366
+ }
367
+ /** `GET /v1/products`. */
368
+ interface ProductPage {
369
+ /** The page's products, sorted by name. */
370
+ items: Product[];
371
+ /** Paging information. */
372
+ pagination: Pagination;
373
+ }
374
+ /** Filters and paging of `products.list`. All optional. */
375
+ interface ProductListQuery {
376
+ /** Category slug; includes the category's descendants. */
377
+ category?: string;
378
+ /** Search text (name, description, SKU), at most 200 characters. */
379
+ q?: string;
380
+ /** 1-based page (default 1, at most 10 000). */
381
+ page?: number;
382
+ /** Items per page (default 20, 1–100). */
383
+ pageSize?: number;
384
+ }
385
+ /** Cart status. Only an `open` cart can change. */
386
+ type CartStatus = 'open' | 'ordered' | 'expired';
387
+ /** A priced cart line. Prices are always computed server-side. */
388
+ interface CartLine {
389
+ /** The variant this line holds. */
390
+ variantId: string;
391
+ /** Units, 1–99. */
392
+ quantity: number;
393
+ /** False when the variant is no longer sold. Checkout refuses the cart. */
394
+ purchasable: boolean;
395
+ /** False when fewer units are available than the line asks for. Checkout refuses the cart. */
396
+ inStock: boolean;
397
+ /** Product id; null when not purchasable. */
398
+ productId: string | null;
399
+ /** Product slug; null when not purchasable. */
400
+ productSlug: string | null;
401
+ /** Product name; null when not purchasable. */
402
+ productName: string | null;
403
+ /** Variant title; null when not purchasable or untitled. */
404
+ variantTitle: string | null;
405
+ /** SKU; null when not purchasable. */
406
+ sku: string | null;
407
+ /** Unit price, minor units; null when not purchasable. */
408
+ unitPriceMinor: number | null;
409
+ /** Line total, minor units (`0` when not purchasable). */
410
+ lineTotalMinor: number;
411
+ }
412
+ /**
413
+ * The module address shape. Either `address` or `line1` is required;
414
+ * `name` / `phone` / `email` fall back to the customer's. Only `TR` in 0.1.0.
415
+ */
416
+ interface Address {
417
+ /** Recipient name. */
418
+ name?: string;
419
+ /** Recipient phone. */
420
+ phone?: string;
421
+ /** Recipient e-mail. */
422
+ email?: string;
423
+ /** Full street address (alternative to `line1` + `line2`). */
424
+ address?: string;
425
+ /** Street address, first line. */
426
+ line1?: string;
427
+ /** Street address, second line. */
428
+ line2?: string;
429
+ /** District (ilçe). */
430
+ district: string;
431
+ /** City (il). */
432
+ city: string;
433
+ /** Postal code (or `postalCode`). */
434
+ zipCode?: string;
435
+ /** Postal code (or `zipCode`). */
436
+ postalCode?: string;
437
+ /** Country; `TR` only. */
438
+ country: 'TR';
439
+ }
440
+ /** The buyer as stored on a cart. The identity number is never returned. */
441
+ interface CartCustomer {
442
+ /** E-mail address. */
443
+ email: string;
444
+ /** First name. */
445
+ name: string;
446
+ /** Surname. */
447
+ surname: string;
448
+ /** Turkish mobile number, normalised to `90XXXXXXXXXX`. */
449
+ phone: string;
450
+ /** Whether an identity number (TC kimlik no) is on file. */
451
+ identityNumberProvided: boolean;
452
+ }
453
+ /** The cart view every cart route answers. */
454
+ interface Cart {
455
+ /** Cart id: a bearer capability, keep it private to the buyer. */
456
+ id: string;
457
+ /** Cart status. */
458
+ status: CartStatus;
459
+ /** ISO 4217 currency. */
460
+ currency: string;
461
+ /** Priced lines. */
462
+ lines: CartLine[];
463
+ /** Sum of line totals, minor units. */
464
+ subtotalMinor: number;
465
+ /** Shipping price, minor units. */
466
+ shippingMinor: number;
467
+ /** Total to pay, minor units. */
468
+ totalMinor: number;
469
+ /** The selected shipping option id, or null when none (or no longer offered). */
470
+ shippingOption: string | null;
471
+ /** The buyer, or null before `setCustomer`. */
472
+ customer: CartCustomer | null;
473
+ /** Shipping address, or null. */
474
+ shippingAddress: Address | null;
475
+ /** Billing address, or null (= the shipping address). */
476
+ billingAddress: Address | null;
477
+ /** When the cart expires (ISO date). */
478
+ expiresAt: string;
479
+ }
480
+ /** Body of `carts.addLine`. */
481
+ interface AddLineInput {
482
+ /** Variant id from the catalog. */
483
+ variantId: string;
484
+ /** Units to add, 1–99 (added to an existing line of the same variant). */
485
+ quantity: number;
486
+ }
487
+ /** Body of `carts.updateLine`. */
488
+ interface UpdateLineInput {
489
+ /** New quantity, 1–99. */
490
+ quantity: number;
491
+ }
492
+ /** Body of `carts.setCustomer`. */
493
+ interface CustomerInput {
494
+ /** E-mail address. */
495
+ email: string;
496
+ /** First name. */
497
+ name: string;
498
+ /** Surname. */
499
+ surname: string;
500
+ /**
501
+ * A **Turkish mobile number**: `05XX…`, `5XX…`, `+90…`, `0090…` (spaces,
502
+ * dashes and parentheses allowed). Anything else is `invalid_request`
503
+ * with `path: "phone"`.
504
+ */
505
+ phone: string;
506
+ /**
507
+ * TC kimlik no, exactly 11 digits. Sealed, never returned. Omitted, the
508
+ * one already on the cart is kept.
509
+ */
510
+ identityNumber?: string;
511
+ }
512
+ /** Body of `carts.setAddress`. */
513
+ interface AddressInput {
514
+ /** Shipping address. */
515
+ shipping: Address;
516
+ /** Billing address; omitted or null = same as shipping. */
517
+ billing?: Address | null;
518
+ }
519
+ /** A shipping option offered for a cart. */
520
+ interface ShippingOption {
521
+ /** Option id (`standard` in 0.1.0). */
522
+ id: string;
523
+ /** Price for this cart, minor units. */
524
+ priceMinor: number;
525
+ }
526
+ /** `GET /v1/carts/:id/shipping-options`. */
527
+ interface ShippingOptionList {
528
+ /** The options this cart can use. */
529
+ items: ShippingOption[];
530
+ }
531
+ /** The known embed kinds. */
532
+ type CheckoutEmbedKind = 'iyzico-checkout-form';
533
+ /**
534
+ * The payment provider's checkout form, passed through from the payments
535
+ * service. Render it as its `kind` says; `iyzico-checkout-form` carries the
536
+ * provider's HTML + scripts in `content`.
537
+ */
538
+ interface CheckoutEmbed {
539
+ /** How to render the form. */
540
+ kind: CheckoutEmbedKind | (string & {});
541
+ /** For `iyzico-checkout-form`: the HTML (with scripts) to inject. */
542
+ content?: string;
543
+ /** Other provider fields. */
544
+ [key: string]: unknown;
545
+ }
546
+ /**
547
+ * Why payment cannot be (re)opened: `paid` (paid or later), `cancelled`,
548
+ * `processing` (being finalised), or from the payments service `expired`,
549
+ * `failed`, `not_found`.
550
+ */
551
+ type ClosedCheckoutPage = 'paid' | 'cancelled' | 'processing' | 'expired' | 'failed' | 'not_found' | (string & {});
552
+ /** Fields every checkout result has. */
553
+ interface CheckoutResultBase {
554
+ /** The order id. */
555
+ orderId: string;
556
+ /** Human-readable order number (`261115-ABCDEF`). */
557
+ orderNumber: string;
558
+ /**
559
+ * The buyer's order-status token, returned **once**, by the checkout that
560
+ * placed the order. Keep it: it is the only key to `orders.get`.
561
+ */
562
+ token?: string;
563
+ /** The order's status, when the service read it (re-opened orders). */
564
+ orderStatus?: OrderStatus;
565
+ }
566
+ /** Render the provider's form in the page. */
567
+ interface EmbeddedCheckoutResult extends CheckoutResultBase {
568
+ /** Discriminator. */
569
+ presentation: 'embedded';
570
+ /** The form to render. */
571
+ embed: CheckoutEmbed;
572
+ }
573
+ /** Send the buyer's browser to `url` (top-level navigation, not an iframe). */
574
+ interface RedirectCheckoutResult extends CheckoutResultBase {
575
+ /** Discriminator. */
576
+ presentation: 'redirect';
577
+ /** The provider's payment page. */
578
+ url: string;
579
+ }
580
+ /** Payment cannot be (re)opened: show the order status page. */
581
+ interface ClosedCheckoutResult extends CheckoutResultBase {
582
+ /** Discriminator. */
583
+ presentation: 'closed';
584
+ /** Which state to show. */
585
+ page: ClosedCheckoutPage;
586
+ }
587
+ /** `POST /v1/carts/:id/checkout`, discriminated by `presentation`. */
588
+ type CheckoutResult = EmbeddedCheckoutResult | RedirectCheckoutResult | ClosedCheckoutResult;
589
+ /** Order status (the commerce module's values; future values pass through). */
590
+ type OrderStatus = 'pendingPayment' | 'paid' | 'fulfilling' | 'shipped' | 'delivered' | 'cancelled' | 'refunded' | 'partiallyRefunded' | (string & {});
591
+ /**
592
+ * Payment status. `processing` = the payment succeeded and the order is
593
+ * being updated (poll again).
594
+ */
595
+ type PaymentStatus = 'none' | 'pending' | 'processing' | 'succeeded' | 'failed' | 'expired' | 'refunded' | 'partiallyRefunded' | (string & {});
596
+ /** Shipment status (the commerce module's values; future values pass through). */
597
+ type ShipmentStatus = 'requested' | 'created' | 'picked_up' | 'in_transit' | 'out_for_delivery' | 'delivered' | 'returned' | 'cancelled' | 'exception' | 'failed' | (string & {});
598
+ /** A line of a placed order. */
599
+ interface OrderLine {
600
+ /** Product id (what ad pixels and analytics use as item id). */
601
+ productId?: string | null;
602
+ /** Product name at order time. */
603
+ productName: string;
604
+ /** SKU at order time. */
605
+ sku: string;
606
+ /** Unit price, minor units. */
607
+ unitPriceMinor: number;
608
+ /** Units. */
609
+ quantity: number;
610
+ /** Line total, minor units. */
611
+ lineTotalMinor: number;
612
+ }
613
+ /** A shipment of an order. */
614
+ interface OrderShipment {
615
+ /** Shipment status. */
616
+ status: ShipmentStatus;
617
+ /** Carrier name, or null. */
618
+ carrier: string | null;
619
+ /** Tracking number, or null. */
620
+ trackingNumber: string | null;
621
+ /** Carrier tracking page, or null. */
622
+ trackingUrl: string | null;
623
+ }
624
+ /** `GET /v1/orders/:id?token=` — what a buyer sees of an order. */
625
+ interface Order {
626
+ /** Order id. */
627
+ id: string;
628
+ /** Human-readable order number. */
629
+ orderNumber: string;
630
+ /** Order status. */
631
+ status: OrderStatus;
632
+ /** Payment status. */
633
+ paymentStatus: PaymentStatus;
634
+ /** ISO 4217 currency. */
635
+ currency: string;
636
+ /** Subtotal, minor units. */
637
+ subtotalMinor: number;
638
+ /** Shipping, minor units. */
639
+ shippingMinor: number;
640
+ /** Total, minor units. */
641
+ totalMinor: number;
642
+ /** When the order was placed (ISO date), or null. */
643
+ placedAt: string | null;
644
+ /** Shipping address as entered (string fields of the address shape). */
645
+ shippingAddress: Record<string, string> | null;
646
+ /** Billing address as entered, or null. */
647
+ billingAddress: Record<string, string> | null;
648
+ /** Order lines. */
649
+ lines: OrderLine[];
650
+ /** Shipments. */
651
+ shipments: OrderShipment[];
652
+ }
653
+ /** `POST /v1/account/session`: the signed-in buyer. */
654
+ interface AccountSession {
655
+ customer: {
656
+ email: string;
657
+ };
658
+ }
659
+ /** `PUT /v1/account/profile` body. */
660
+ interface AccountProfileInput {
661
+ /** First name (1-100 characters). */
662
+ name: string;
663
+ /** Surname (1-100 characters). */
664
+ surname: string;
665
+ /** Turkish mobile number in any common format; stored as `90XXXXXXXXXX`. */
666
+ phone: string;
667
+ }
668
+ /** A saved address as the API stores it. */
669
+ interface SavedAddress extends Address {
670
+ /** Server-assigned id. */
671
+ id: string;
672
+ /** Whether this is the default address (exactly one is, when any exist). */
673
+ isDefault: boolean;
674
+ }
675
+ /** A saved address to send: `id` is filled in by the server when absent. */
676
+ interface SavedAddressInput extends Address {
677
+ id?: string;
678
+ isDefault?: boolean;
679
+ }
680
+ /** One order in the account's order list. */
681
+ interface AccountOrder {
682
+ /** Order number shown to the buyer. */
683
+ number: string;
684
+ /** ISO time the order was placed, or null. */
685
+ placedAt: string | null;
686
+ /** Order status (see {@link OrderStatus}). */
687
+ status: string;
688
+ totalMinor: number;
689
+ currency: string;
690
+ /** Link to the order status page, or null when none exists yet. */
691
+ statusUrl: string | null;
692
+ }
693
+ /** `GET /v1/account`. Name, surname and phone are null until a profile is saved. */
694
+ interface Account {
695
+ email: string;
696
+ name: string | null;
697
+ surname: string | null;
698
+ phone: string | null;
699
+ savedAddresses: SavedAddress[];
700
+ /** One page of orders, newest first. */
701
+ orders: AccountOrder[];
702
+ }
703
+
704
+ /** Default request timeout, milliseconds. */
705
+ declare const DEFAULT_TIMEOUT_MS = 15000;
706
+ /** Header carrying the publishable key on every request. */
707
+ declare const PUBLISHABLE_KEY_HEADER = "x-konfiqo-publishable-key";
708
+ /** Header carrying the trusted storefront key (server-side only). */
709
+ declare const STOREFRONT_KEY_HEADER = "x-konfiqo-storefront-key";
710
+ /** Header carrying the checkout challenge token (checkout only). */
711
+ declare const TURNSTILE_TOKEN_HEADER = "x-konfiqo-turnstile-token";
712
+ /** Header carrying the buyer's IP (only with a server key or the trusted storefront key). */
713
+ declare const BUYER_IP_HEADER = "x-konfiqo-buyer-ip";
714
+ /** Per-call options, accepted as the last argument of every method. */
715
+ interface RequestOptions {
716
+ /**
717
+ * Aborts the request: it rejects with code `aborted`. Combined with the
718
+ * client timeout (whichever comes first wins).
719
+ */
720
+ signal?: AbortSignal;
721
+ /**
722
+ * **Server-side only.** A `Cookie` header to forward, so a server-rendered
723
+ * storefront can call the account routes as the buyer: pass the incoming
724
+ * request's `cookie` header (or just `konfiqo_session=<value>`). Browsers
725
+ * ignore a `Cookie` header set from script; there the session cookie rides
726
+ * along automatically (`credentials: 'include'`).
727
+ */
728
+ cookie?: string;
729
+ }
730
+ /** Options of `account.requestCode`. */
731
+ interface RequestCodeOptions extends RequestOptions {
732
+ /**
733
+ * The challenge token (Cloudflare Turnstile), required when the store
734
+ * asks for one (`store.checkoutChallenge`). Single-use. Sent as
735
+ * `x-konfiqo-turnstile-token`.
736
+ */
737
+ turnstileToken?: string;
738
+ }
739
+ /** Options of `carts.checkout`. */
740
+ interface CheckoutOptions extends RequestOptions {
741
+ /**
742
+ * The checkout challenge token (Cloudflare Turnstile), required when
743
+ * `store.checkoutChallenge` is set. Single-use: get a new one (reset the
744
+ * widget) for every checkout call. Sent as `x-konfiqo-turnstile-token`.
745
+ */
746
+ turnstileToken?: string;
747
+ }
748
+ /** Options of {@link createStorefrontClient}. */
749
+ interface StorefrontClientOptions {
750
+ /**
751
+ * The Storefront API base: `https://<store domain>/api` (or the relative
752
+ * `/api` in a same-origin browser app). Requests go to `${baseUrl}/v1/...`,
753
+ * so do not include `/v1`.
754
+ */
755
+ baseUrl: string;
756
+ /** The store's publishable key (`pk_live_…` / `pk_test_…`). Public. */
757
+ publishableKey: string;
758
+ /** A `fetch` implementation; defaults to the global `fetch`. */
759
+ fetch?: typeof fetch;
760
+ /** Per-request timeout in milliseconds (default {@link DEFAULT_TIMEOUT_MS}). */
761
+ timeoutMs?: number;
762
+ /**
763
+ * **Server-side only.** The shared storefront key that lets a server-side
764
+ * renderer report the real buyer IP (`buyerIp`), so throttling and the
765
+ * payment provider see the buyer instead of the server. Sent as
766
+ * `x-konfiqo-storefront-key`. Constructing a client with it where
767
+ * `window` exists throws: never ship this key to a browser.
768
+ */
769
+ trustedStorefrontKey?: string;
770
+ /**
771
+ * **Server-side only.** The store's own server key, minted by the store
772
+ * operator. It lets the seller's server report the real buyer IP
773
+ * (`buyerIp`). Sent as `x-konfiqo-server-key` next to the publishable
774
+ * key. Needs `buyerIp`, cannot be combined with `trustedStorefrontKey`,
775
+ * and constructing a client with it in a browser throws.
776
+ */
777
+ serverKey?: string;
778
+ /**
779
+ * The buyer's IP address, sent as `x-konfiqo-buyer-ip`. Required with
780
+ * `serverKey` or `trustedStorefrontKey`, ignored without one. Create one
781
+ * client per incoming request on the server.
782
+ */
783
+ buyerIp?: string;
784
+ }
785
+ /**
786
+ * A typed client of the Storefront API (`/v1`).
787
+ *
788
+ * Every method returns the response body, or rejects with a
789
+ * {@link StorefrontError}. Nothing is retried: whether to retry is the
790
+ * caller's decision, because writes are not safely repeatable — in
791
+ * particular `carts.checkout` on a cart whose order failed places a
792
+ * **new** order, so a blind retry could open a second payment.
793
+ */
794
+ interface StorefrontClient {
795
+ /**
796
+ * `GET /v1/content/:key`: a piece of store content as a renderable
797
+ * Markdoc tree. Rejects `content_not_found` (404) for an unknown key.
798
+ */
799
+ getContent(key: string, options?: RequestOptions): Promise<StoreContent>;
800
+ /** Store information. */
801
+ readonly store: {
802
+ /** `GET /v1/store`: name, language, currency, logo, theme, contact, legal texts, shipping rules. */
803
+ get(options?: RequestOptions): Promise<Store>;
804
+ };
805
+ /** Categories. */
806
+ readonly categories: {
807
+ /** `GET /v1/categories`: the active category tree. */
808
+ list(options?: RequestOptions): Promise<CategoryList>;
809
+ };
810
+ /** Products. */
811
+ readonly products: {
812
+ /** `GET /v1/products`: a page of products, optionally filtered. */
813
+ list(query?: ProductListQuery, options?: RequestOptions): Promise<ProductPage>;
814
+ /** `GET /v1/products/:slug`. Rejects with `product_not_found`. */
815
+ get(slug: string, options?: RequestOptions): Promise<Product>;
816
+ };
817
+ /** Carts. Every cart write answers the updated cart. */
818
+ readonly carts: {
819
+ /** `POST /v1/carts`: a new, empty cart. */
820
+ create(options?: RequestOptions): Promise<Cart>;
821
+ /**
822
+ * `POST /v1/carts/recover`: turns the `t` token of an abandoned-cart
823
+ * e-mail link into a **new** cart with the same lines (no buyer data).
824
+ * Rejects `invalid_recovery_token` (400) or `cart_not_recoverable` (410:
825
+ * the cart was ordered, expired or deleted).
826
+ */
827
+ recover(token: string, options?: RequestOptions): Promise<{
828
+ cartId: string;
829
+ }>;
830
+ /** `GET /v1/carts/:id`. Also reopens a cart whose payment failed. */
831
+ get(cartId: string, options?: RequestOptions): Promise<Cart>;
832
+ /** `POST /v1/carts/:id/lines`: adds units of a variant. */
833
+ addLine(cartId: string, input: AddLineInput, options?: RequestOptions): Promise<Cart>;
834
+ /** `PATCH /v1/carts/:id/lines/:variantId`: sets a line's quantity. */
835
+ updateLine(cartId: string, variantId: string, input: UpdateLineInput, options?: RequestOptions): Promise<Cart>;
836
+ /** `DELETE /v1/carts/:id/lines/:variantId`: removes a line. */
837
+ removeLine(cartId: string, variantId: string, options?: RequestOptions): Promise<Cart>;
838
+ /** `PUT /v1/carts/:id/customer`: sets the buyer. */
839
+ setCustomer(cartId: string, input: CustomerInput, options?: RequestOptions): Promise<Cart>;
840
+ /** `PUT /v1/carts/:id/address`: sets the shipping (and billing) address. */
841
+ setAddress(cartId: string, input: AddressInput, options?: RequestOptions): Promise<Cart>;
842
+ /** `GET /v1/carts/:id/shipping-options`: the options this cart can use. */
843
+ shippingOptions(cartId: string, options?: RequestOptions): Promise<ShippingOptionList>;
844
+ /** `PUT /v1/carts/:id/shipping-option`: selects a shipping option by id. */
845
+ setShippingOption(cartId: string, optionId: string, options?: RequestOptions): Promise<Cart>;
846
+ /**
847
+ * `POST /v1/carts/:id/checkout`: places the order (or re-opens payment
848
+ * for the cart's order) and answers how to present payment. Keep the
849
+ * returned `token`: it is returned only once. Not retried.
850
+ *
851
+ * Aborting (`signal`) only stops waiting: the server may still place
852
+ * the order. Read the cart again before showing a result.
853
+ *
854
+ * When `store.checkoutChallenge` is set, pass a fresh
855
+ * `turnstileToken` (see `renderTurnstile`); tokens are single-use, so
856
+ * reset the widget after every call. Re-opening payment on an already
857
+ * ordered cart needs no token.
858
+ */
859
+ checkout(cartId: string, options?: CheckoutOptions): Promise<CheckoutResult>;
860
+ };
861
+ /** Buyer order status. */
862
+ readonly orders: {
863
+ /** `GET /v1/orders/:id?token=`: the order, for the buyer holding its token. */
864
+ get(orderId: string, token: string, options?: RequestOptions): Promise<Order>;
865
+ };
866
+ /**
867
+ * The signed-in buyer's account. Sign-in is by an e-mailed one-time code;
868
+ * the session is an HttpOnly cookie (`konfiqo_session`) the API sets on the
869
+ * store origin, so these calls send `credentials: 'include'`. On a server,
870
+ * forward the buyer's cookie with the `cookie` call option.
871
+ */
872
+ readonly account: {
873
+ /**
874
+ * `POST /v1/account/code`: e-mails a 6-digit code. Resolves the same for
875
+ * any address (202); rejects `too_many_code_requests` (429),
876
+ * `challenge_required` / `challenge_failed`, `invalid_request`.
877
+ */
878
+ requestCode(email: string, options?: RequestCodeOptions): Promise<void>;
879
+ /**
880
+ * `POST /v1/account/session`: signs in with the code. A wrong, spent or
881
+ * expired code rejects `invalid_code` (401).
882
+ */
883
+ signIn(email: string, code: string, options?: RequestOptions): Promise<AccountSession>;
884
+ /** `DELETE /v1/account/session`: signs out (always succeeds). */
885
+ signOut(options?: RequestOptions): Promise<void>;
886
+ /**
887
+ * `GET /v1/account[?page=]`: profile, saved addresses and a page of
888
+ * orders (20 per page, newest first). Rejects `not_signed_in` (401).
889
+ */
890
+ get(page?: number, options?: RequestOptions): Promise<Account>;
891
+ /**
892
+ * `PUT /v1/account/profile`: saves name, surname and a Turkish mobile
893
+ * phone. Creates the buyer's record on first save.
894
+ */
895
+ updateProfile(profile: AccountProfileInput, options?: RequestOptions): Promise<void>;
896
+ /**
897
+ * `PUT /v1/account/addresses`: replaces the saved addresses (at most 5,
898
+ * at most one default). Resolves the list as stored (ids filled in).
899
+ * Rejects `profile_required` (409) until a profile is saved.
900
+ */
901
+ saveAddresses(addresses: SavedAddressInput[], options?: RequestOptions): Promise<SavedAddress[]>;
902
+ };
903
+ /** Catalog images. */
904
+ readonly media: {
905
+ /**
906
+ * The absolute URL of a storage key (product `image`, store `logo`,
907
+ * theme `logo` / `favicon` / section `image`), usable in `<img src>`:
908
+ * `${baseUrl}/v1/media/<key, each segment encoded>?pk=<publishable key>`.
909
+ *
910
+ * @throws TypeError (`invalid_path_segment`) when a key segment is
911
+ * empty, `.` or `..`.
912
+ */
913
+ url(key: string): string;
914
+ };
915
+ }
916
+ /**
917
+ * Creates a Storefront API client.
918
+ *
919
+ * @throws TypeError when `baseUrl` or `publishableKey` is empty, when
920
+ * `serverKey` or `trustedStorefrontKey` is given without `buyerIp`, when
921
+ * both keys are given together, or when either key is given in a
922
+ * browser-like host (`window` or `document` defined, or a web worker).
923
+ * Hosts that define `window` on a server (jsdom, Electron renderers,
924
+ * React Native) are refused too: keep these keys in a plain server process.
925
+ */
926
+ declare function createStorefrontClient(options: StorefrontClientOptions): StorefrontClient;
927
+
928
+ /** `checkout_incomplete`: what the cart still lacks. */
929
+ type CheckoutMissing = 'lines' | 'customer' | 'identityNumber' | 'shippingAddress' | 'shippingOption';
930
+ /**
931
+ * `invalid_buyer_details`: the buyer detail the payment provider refused.
932
+ * Address fields come as `shippingAddress.<field>` / `billingAddress.<field>`.
933
+ */
934
+ type BuyerDetailField = 'name' | 'surname' | 'email' | 'phone' | 'identityNumber' | `shippingAddress.${string}` | `billingAddress.${string}`;
935
+ /** One validation problem of an `invalid_request`. */
936
+ interface ValidationIssue {
937
+ /** Dotted path of the field (`phone`, `shipping.city`, …). */
938
+ path: string;
939
+ /** What is wrong with it (never echoes the submitted value). */
940
+ message: string;
941
+ }
942
+ /**
943
+ * The extras each error code carries (`StorefrontError.details`). Codes
944
+ * not listed here carry no details (`undefined`).
945
+ */
946
+ interface StorefrontErrorDetailsMap {
947
+ /** Prices or shipping changed: show the new totals, then check out again. */
948
+ cart_changed: {
949
+ lines: CartLine[];
950
+ subtotalMinor: number;
951
+ shippingMinor: number;
952
+ totalMinor: number;
953
+ shippingOptions: ShippingOption[];
954
+ };
955
+ /** These variants cannot be bought (no longer sold, or not enough units). */
956
+ out_of_stock: {
957
+ variantIds: string[];
958
+ };
959
+ /** Collect what is missing, then check out again. */
960
+ checkout_incomplete: {
961
+ missing: CheckoutMissing[];
962
+ };
963
+ /** Let the buyer fix `field`, then check out again. */
964
+ invalid_buyer_details: {
965
+ field: BuyerDetailField;
966
+ };
967
+ /** Only `available` units can be added. */
968
+ insufficient_stock: {
969
+ available: number;
970
+ };
971
+ /** The request body or query failed validation. */
972
+ invalid_request: {
973
+ issues: ValidationIssue[];
974
+ };
975
+ /** The cart can no longer change: start a new cart. */
976
+ cart_read_only: {
977
+ status: 'ordered' | 'expired';
978
+ };
979
+ /** Throttled. `retryAfter` = seconds to wait, when the response said so. */
980
+ rate_limited: {
981
+ retryAfter?: number;
982
+ };
983
+ /** No response within `timeoutMs`. */
984
+ timeout: {
985
+ timeoutMs: number;
986
+ };
987
+ /** The server answered an error code this SDK version does not know. */
988
+ unknown_error: {
989
+ error: string | null;
990
+ };
991
+ }
992
+ /** Error codes of the Storefront API (the `error` field of an error response). */
993
+ 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' | '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';
994
+ /**
995
+ * Codes the SDK assigns itself:
996
+ * - `rate_limited` — HTTP 429 without a known `error` code (the throttler);
997
+ * - `unauthorized` — HTTP 401 without a code (a wrong `trustedStorefrontKey`);
998
+ * - `http_error` — any other non-2xx response without an `error` code;
999
+ * - `unknown_error` — an `error` code this SDK version does not know (in `details.error`);
1000
+ * - `invalid_response` — a 2xx response that is not JSON;
1001
+ * - `network_error` — no readable response: the API was unreachable (DNS,
1002
+ * TLS, offline), or, in a browser, the origin is allowed by no store;
1003
+ * - `timeout` — no response within `timeoutMs`;
1004
+ * - `aborted` — the caller's `signal` aborted the request.
1005
+ */
1006
+ type StorefrontClientErrorCode = 'rate_limited' | 'unauthorized' | 'http_error' | 'unknown_error' | 'invalid_response' | 'network_error' | 'timeout' | 'aborted';
1007
+ /** Every code a {@link StorefrontError} can have. */
1008
+ type StorefrontErrorCode = StorefrontApiErrorCode | StorefrontClientErrorCode;
1009
+ /** The `details` type of an error code (`undefined` for codes without extras). */
1010
+ type StorefrontErrorDetails<C extends StorefrontErrorCode> = C extends keyof StorefrontErrorDetailsMap ? StorefrontErrorDetailsMap[C] : undefined;
1011
+ /**
1012
+ * Every failure of a client call: an API error response, a throttle, a
1013
+ * timeout or a transport failure. Switch on `code`, never on `message`.
1014
+ *
1015
+ * To get `details` typed per code, narrow with {@link isStorefrontError}
1016
+ * (which yields the {@link AnyStorefrontError} union) and `switch (e.code)`,
1017
+ * or test one code with `e.is('cart_changed')`.
1018
+ */
1019
+ declare class StorefrontError<C extends StorefrontErrorCode = StorefrontErrorCode> extends Error {
1020
+ /** The API `error` code, or one of the SDK's own codes. */
1021
+ readonly code: C;
1022
+ /** HTTP status; `0` when no response arrived (`network_error`, `timeout`). */
1023
+ readonly status: number;
1024
+ /** The code's extras (see {@link StorefrontErrorDetailsMap}). */
1025
+ readonly details: StorefrontErrorDetails<C>;
1026
+ /**
1027
+ * @param code - the error code
1028
+ * @param status - the HTTP status (`0` without a response)
1029
+ * @param message - a human-readable description (not for display logic)
1030
+ * @param details - the code's extras
1031
+ * @param options - `cause`: the underlying error, if any
1032
+ */
1033
+ constructor(code: C, status: number, message: string, details: StorefrontErrorDetails<C>, options?: {
1034
+ cause?: unknown;
1035
+ });
1036
+ /** Whether this error has `code`; narrows `details` to that code's extras. */
1037
+ is<K extends StorefrontErrorCode>(code: K): this is StorefrontError<K>;
1038
+ }
1039
+ /**
1040
+ * The union of {@link StorefrontError} by code: after narrowing `code`
1041
+ * (e.g. in a `switch`), `details` has that code's type.
1042
+ */
1043
+ type AnyStorefrontError = {
1044
+ [C in StorefrontErrorCode]: StorefrontError<C>;
1045
+ }[StorefrontErrorCode];
1046
+ /**
1047
+ * Whether `e` is a {@link StorefrontError}, as the code-discriminated union.
1048
+ * Also true for an error from another copy of this SDK (checked by a global
1049
+ * brand, not only `instanceof`).
1050
+ */
1051
+ declare function isStorefrontError(e: unknown): e is AnyStorefrontError;
1052
+
1053
+ /**
1054
+ * What {@link mountPayment} renders: a checkout result, or just its
1055
+ * presentation part.
1056
+ */
1057
+ type PaymentPresentation = Pick<EmbeddedCheckoutResult, 'presentation' | 'embed'> | Pick<RedirectCheckoutResult, 'presentation' | 'url'> | Pick<ClosedCheckoutResult, 'presentation' | 'page'>;
1058
+ /** Options of {@link mountPayment}. */
1059
+ interface MountPaymentOptions {
1060
+ /**
1061
+ * Called for `presentation: "closed"` with the page to show (`paid`,
1062
+ * `cancelled`, `processing`, …). Typically: go to the order status page.
1063
+ */
1064
+ onClosed?: (page: ClosedCheckoutPage) => void;
1065
+ }
1066
+ /** The provider form is in the element. */
1067
+ interface EmbeddedPaymentMount {
1068
+ /** Discriminator. */
1069
+ kind: 'embedded';
1070
+ /** Removes the form from the element. */
1071
+ unmount(): void;
1072
+ }
1073
+ /** The browser is navigating to the provider's payment page. */
1074
+ interface RedirectPaymentMount {
1075
+ /** Discriminator. */
1076
+ kind: 'redirect';
1077
+ /** Where the browser was sent. */
1078
+ url: string;
1079
+ }
1080
+ /** Payment cannot be opened; `onClosed` was called. */
1081
+ interface ClosedPaymentMount {
1082
+ /** Discriminator. */
1083
+ kind: 'closed';
1084
+ /** The page to show. */
1085
+ page: ClosedCheckoutPage;
1086
+ }
1087
+ /**
1088
+ * The embed has a `kind` this SDK version cannot render. Nothing was put
1089
+ * in the element; show a fallback (e.g. "payment unavailable").
1090
+ */
1091
+ interface UnsupportedPaymentMount {
1092
+ /** Discriminator. */
1093
+ kind: 'unsupported';
1094
+ /** The embed kind that was not understood. */
1095
+ embedKind: string;
1096
+ }
1097
+ /** The result of {@link mountPayment}, discriminated by `kind`. */
1098
+ type PaymentMount = EmbeddedPaymentMount | RedirectPaymentMount | ClosedPaymentMount | UnsupportedPaymentMount;
1099
+ /**
1100
+ * Presents payment from a checkout result. Card data never touches your
1101
+ * page's code: the form is the provider's own, or a redirect.
1102
+ *
1103
+ * - `embedded` (`iyzico-checkout-form`): puts the provider's HTML into
1104
+ * `element` and re-creates every `<script>` in it so it executes
1105
+ * (`innerHTML` alone never runs scripts). Idempotent per element:
1106
+ * mounting the same content again does nothing, other content replaces
1107
+ * the previous form — scripts are never injected twice.
1108
+ * - `redirect`: top-level navigation to the provider page
1109
+ * (`location.assign`). Only `http:` / `https:` URLs are followed.
1110
+ * - `closed`: calls `onClosed(page)`.
1111
+ *
1112
+ * Browser only (needs a DOM).
1113
+ *
1114
+ * @throws TypeError for a redirect URL that is not `http(s)`.
1115
+ */
1116
+ declare function mountPayment(element: HTMLElement, presentation: PaymentPresentation | CheckoutResult, options?: MountPaymentOptions): PaymentMount;
1117
+
1118
+ /**
1119
+ * Formats an integer amount of minor units (kuruş, cents, …) as a
1120
+ * localised currency string with `Intl.NumberFormat`, using the currency's
1121
+ * own number of minor digits (2 for `TRY`, 0 for `JPY`).
1122
+ *
1123
+ * @example formatMoney(14990, 'TRY', 'tr-TR') // "₺149,90"
1124
+ * @throws TypeError when `minor` is not a finite number; RangeError for an
1125
+ * unknown currency code (from `Intl`).
1126
+ */
1127
+ declare function formatMoney(minor: number, currency: string, locale?: string | string[]): string;
1128
+
1129
+ /**
1130
+ * The part of the Web Storage API the cart-id helpers use; `localStorage`,
1131
+ * `sessionStorage` or any object with these methods (a cookie adapter, a
1132
+ * test double).
1133
+ */
1134
+ interface CartIdStorage {
1135
+ /** Reads a value, or null. */
1136
+ getItem(key: string): string | null;
1137
+ /** Writes a value. */
1138
+ setItem(key: string, value: string): void;
1139
+ /** Deletes a value. */
1140
+ removeItem(key: string): void;
1141
+ }
1142
+ /** The storage key of a store's cart id. Namespaced per store. */
1143
+ declare function cartIdKey(storeId: string): string;
1144
+ /**
1145
+ * The saved cart id of a store, or null. Never throws: a missing storage
1146
+ * (SSR), a storage that throws (Safari private mode, blocked cookies) or
1147
+ * an empty value all read as null.
1148
+ */
1149
+ declare function loadCartId(storage: CartIdStorage | null | undefined, storeId: string): string | null;
1150
+ /** Saves a store's cart id. Returns false when the storage refused. Never throws. */
1151
+ declare function saveCartId(storage: CartIdStorage | null | undefined, storeId: string, cartId: string): boolean;
1152
+ /**
1153
+ * Forgets a store's cart id (after `cart_not_found`, or `cart_read_only`
1154
+ * with `status: "expired"`). Returns false when the storage refused. Never throws.
1155
+ */
1156
+ declare function clearCartId(storage: CartIdStorage | null | undefined, storeId: string): boolean;
1157
+ /** The part of `document` the cookie storage uses. */
1158
+ interface CookieJar {
1159
+ cookie: string;
1160
+ }
1161
+ /**
1162
+ * Cart ids in the first-party `__Host-konfiqo_cart` cookie (path
1163
+ * `/`, no `Domain`, `SameSite=Lax`, `Secure`). The `__Host-` prefix makes
1164
+ * browsers refuse a cookie of this name scoped to a parent domain, so a
1165
+ * sibling store subdomain cannot plant a cart; the old unprefixed
1166
+ * `konfiqo_cart` is never read. The value is a JSON map keyed by
1167
+ * {@link cartIdKey}, so a store's own frontend and the hosted checkout on the same domain share
1168
+ * the cart. `Secure` cookies are dropped by browsers on plain `http`
1169
+ * (other than `localhost`), so over http nothing is stored here; pair it
1170
+ * with a `localStorage` fallback. Without a document (SSR) it reads nothing and writes fail.
1171
+ * Never throws; a malformed or oversized cookie is ignored.
1172
+ *
1173
+ * @param doc Defaults to the global `document`; `null` disables it.
1174
+ */
1175
+ declare function cookieCartStorage(doc?: CookieJar | null): CartIdStorage;
1176
+
1177
+ /**
1178
+ * Cloudflare's official Turnstile script, explicit-render mode. The only
1179
+ * URL {@link loadTurnstile} ever injects.
1180
+ */
1181
+ declare const TURNSTILE_SCRIPT_URL = "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit";
1182
+ /** The subset of Cloudflare's `window.turnstile` API the SDK uses. */
1183
+ interface TurnstileApi {
1184
+ /** Renders a widget into `container`; returns its widget id. */
1185
+ render(container: HTMLElement | string, params: {
1186
+ sitekey: string;
1187
+ callback?: (token: string) => void;
1188
+ 'expired-callback'?: () => void;
1189
+ 'error-callback'?: (code?: string) => void;
1190
+ [key: string]: unknown;
1191
+ }): string | null | undefined;
1192
+ /** Resets a widget so it produces a new token. */
1193
+ reset(widgetId?: string): void;
1194
+ /** Removes a widget. */
1195
+ remove(widgetId?: string): void;
1196
+ }
1197
+ /**
1198
+ * Loads Cloudflare Turnstile into `document` (once: the script is injected
1199
+ * at most once per document, concurrent calls share one load) and resolves
1200
+ * with `window.turnstile`. Rejects when the script fails to load; the
1201
+ * failed `<script>` is removed, so calling again injects a fresh one.
1202
+ */
1203
+ declare function loadTurnstile(document: Document): Promise<TurnstileApi>;
1204
+ /** Callbacks of {@link renderTurnstile}. */
1205
+ interface RenderTurnstileOptions {
1206
+ /** A token is ready: keep it for the next `carts.checkout` call. */
1207
+ onToken: (token: string) => void;
1208
+ /** The token expired unused (about 5 minutes): drop it; the widget refreshes. */
1209
+ onExpired?: () => void;
1210
+ /** The widget failed (network, unsupported browser, …). */
1211
+ onError?: (code?: string) => void;
1212
+ }
1213
+ /** A rendered Turnstile widget. */
1214
+ interface TurnstileWidget {
1215
+ /** The widget id. */
1216
+ readonly widgetId: string;
1217
+ /**
1218
+ * Gets a new token. Call it after every `carts.checkout` that used the
1219
+ * current token: tokens are **single-use**.
1220
+ */
1221
+ reset(): void;
1222
+ /** Removes the widget. */
1223
+ remove(): void;
1224
+ }
1225
+ /**
1226
+ * Renders a Turnstile widget with the store's `siteKey`
1227
+ * (`store.checkoutChallenge.siteKey`) into `element`, loading the script
1228
+ * first if needed. Pass each token from `onToken` to
1229
+ * `carts.checkout(id, { turnstileToken })`, then `reset()`.
1230
+ */
1231
+ declare function renderTurnstile(element: HTMLElement, siteKey: string, options: RenderTurnstileOptions): Promise<TurnstileWidget>;
1232
+
1233
+ /** Version of the Storefront SDK package. */
1234
+ declare const SDK_VERSION = "0.4.0";
1235
+
1236
+ 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 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 };