@konfiqo/storefront-sdk 0.6.1 → 0.8.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/dist/index.d.cts CHANGED
@@ -159,19 +159,23 @@ interface StoreContact {
159
159
  /** Contact phone number. */
160
160
  phone: string | null;
161
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;
162
+ /**
163
+ * The seller's company details, as entered in the store settings. Use them
164
+ * in an imprint or footer. Each field is null when not set.
165
+ */
166
+ interface StoreCompany {
167
+ /** Legal title of the company. */
168
+ title: string | null;
169
+ /** Registered address. */
170
+ address: string | null;
171
+ /** Tax office (vergi dairesi). */
172
+ taxOffice: string | null;
173
+ /** Tax number (10 or 11 digits). */
174
+ taxNumber: string | null;
175
+ /** MERSIS number (16 digits). */
176
+ mersisNumber: string | null;
177
+ /** KEP (registered e-mail) address. */
178
+ kepAddress: string | null;
175
179
  }
176
180
  /** What a cookie is for: necessary ones need no consent. */
177
181
  type CookieCategory = 'necessary' | 'analytics' | 'marketing';
@@ -216,6 +220,62 @@ interface StoreContent {
216
220
  /** `Markdoc.transform` output (plain objects). Render with `<Content>`. */
217
221
  tree: ContentNode;
218
222
  }
223
+ /** A blog post as listed (no body). */
224
+ interface BlogPostSummary {
225
+ /** URL slug; the argument of `blog.get`. */
226
+ slug: string;
227
+ title: string;
228
+ /** Short teaser text. */
229
+ summary: string;
230
+ /** Storage key of the cover image, or null. */
231
+ coverImage: string | null;
232
+ /**
233
+ * Media URL of `coverImage`, **relative** (`/v1/media/<key>?pk=<key>`):
234
+ * prefix the API origin, or use `client.media.url(post.coverImage)`.
235
+ */
236
+ coverImageUrl: string | null;
237
+ /** When the post went live (ISO 8601). */
238
+ publishedAt: string;
239
+ /** When the post last changed (ISO 8601). */
240
+ updatedAt: string;
241
+ }
242
+ /** A blog post with its body. */
243
+ interface BlogPost extends BlogPostSummary {
244
+ /** Description for search engines. The summary when none was written. */
245
+ metaDescription: string;
246
+ /** `Markdoc.transform` output (plain objects). Render with `<Content>`. */
247
+ tree: ContentNode;
248
+ }
249
+ /** `GET /v1/blog`: a page of posts, newest first. */
250
+ interface BlogPostList {
251
+ items: BlogPostSummary[];
252
+ pagination: {
253
+ page: number;
254
+ pageSize: number;
255
+ total: number;
256
+ totalPages: number;
257
+ };
258
+ }
259
+ /** A legal text kept with a cart or an order: the text the buyer was shown. */
260
+ interface LegalDocument {
261
+ /** Content key, one of {@link LEGAL_KEYS}. */
262
+ key: string;
263
+ title: string;
264
+ /** `Markdoc.transform` output. Render with `<Content>`. */
265
+ tree: ContentNode;
266
+ }
267
+ /**
268
+ * `POST /v1/carts/:id/agreements`: the order documents filled in for this
269
+ * cart. Show them, then pass `agreementsHash` to `carts.checkout`.
270
+ */
271
+ interface CartAgreements {
272
+ /** The order number the order will get. Already printed in the documents. */
273
+ orderNumber: string;
274
+ /** The order documents (`legal.preliminary-information`, `legal.distance-sales`). */
275
+ documents: LegalDocument[];
276
+ /** Hash of the shown texts (64 hex characters). Checkout refuses a stale one. */
277
+ agreementsHash: string;
278
+ }
219
279
  /** The ad pixels a store configured (ids are validated by the API). */
220
280
  interface AdPixels {
221
281
  /** Meta Pixel. */
@@ -252,8 +312,8 @@ interface Store {
252
312
  theme: ThemeV1 | null;
253
313
  /** Contact details. */
254
314
  contact: StoreContact;
255
- /** Legal texts. */
256
- legal: StoreLegal;
315
+ /** Company details of the seller. */
316
+ company: StoreCompany;
257
317
  /** Shipping rules, or null when the store has no shipping configured. */
258
318
  shipping: ShippingRules | null;
259
319
  /**
@@ -283,6 +343,20 @@ interface Store {
283
343
  * versions: treat every host as a custom domain.)
284
344
  */
285
345
  defaultDomainSuffix?: string;
346
+ /**
347
+ * The marketing consent text the checkout shows next to an unticked box,
348
+ * with its version (`v1-tr`, `v1-en`). Send `version` as
349
+ * `consentTextVersion` when the buyer ticks the box. Absent on older
350
+ * API versions. Treat absent or null as "show no checkbox".
351
+ */
352
+ marketingConsent?: MarketingConsentText | null;
353
+ }
354
+ /** The marketing consent text served in `Store.marketingConsent`. */
355
+ interface MarketingConsentText {
356
+ /** Version of the text; send it with a tick as `consentTextVersion`. */
357
+ version: string;
358
+ /** The text to show next to the box, in the store's language. */
359
+ text: string;
286
360
  }
287
361
  /** A node of the active category tree. */
288
362
  interface Category {
@@ -545,6 +619,20 @@ interface CustomerInput {
545
619
  * one already on the cart is kept.
546
620
  */
547
621
  identityNumber?: string;
622
+ /**
623
+ * Whether the buyer ticked the marketing consent box. Never pre-tick it:
624
+ * the box starts unticked and only the buyer's own action sets it. Omitted
625
+ * or `false` records no consent. With `true`, also send
626
+ * `consentTextVersion`.
627
+ */
628
+ marketingConsent?: boolean;
629
+ /**
630
+ * The `version` of `store.marketingConsent` that was shown next to the
631
+ * tick. Required with `marketingConsent: true`: a missing or unknown
632
+ * version is refused as `invalid_request` with
633
+ * `path: "consentTextVersion"`.
634
+ */
635
+ consentTextVersion?: string;
548
636
  }
549
637
  /** Body of `carts.setAddress`. */
550
638
  interface AddressInput {
@@ -688,6 +776,8 @@ interface Order {
688
776
  lines: OrderLine[];
689
777
  /** Shipments. */
690
778
  shipments: OrderShipment[];
779
+ /** The legal texts the buyer accepted at checkout, as placed. */
780
+ agreements: LegalDocument[];
691
781
  }
692
782
  /** `POST /v1/account/session`: the signed-in buyer. */
693
783
  interface AccountSession {
@@ -750,6 +840,8 @@ declare const STOREFRONT_KEY_HEADER = "x-konfiqo-storefront-key";
750
840
  declare const TURNSTILE_TOKEN_HEADER = "x-konfiqo-turnstile-token";
751
841
  /** Header carrying the buyer's IP (only with a server key or the trusted storefront key). */
752
842
  declare const BUYER_IP_HEADER = "x-konfiqo-buyer-ip";
843
+ /** Header carrying the buyer's user agent (only with a server key or the trusted storefront key). */
844
+ declare const BUYER_USER_AGENT_HEADER = "x-konfiqo-buyer-user-agent";
753
845
  /** Per-call options, accepted as the last argument of every method. */
754
846
  interface RequestOptions {
755
847
  /**
@@ -775,8 +867,30 @@ interface RequestCodeOptions extends RequestOptions {
775
867
  */
776
868
  turnstileToken?: string;
777
869
  }
870
+ /**
871
+ * The `agreementsHash` to send when re-opening payment on an `ordered` cart.
872
+ *
873
+ * On an `ordered` cart (the buyer already placed the order and payment is
874
+ * still pending), `carts.agreements` answers `cart_read_only`, so there is no
875
+ * fresh hash to send. Pass this value to `carts.checkout` instead: commerce
876
+ * re-opens the pending payment and does not read the hash on that path.
877
+ *
878
+ * If the old order was cancelled (for example, after a declined payment),
879
+ * commerce answers `agreements_changed` instead. Then call
880
+ * `carts.agreements` again, show the documents, ask the buyer to accept them,
881
+ * and check out with the new `agreementsHash`.
882
+ */
883
+ declare const REOPEN_AGREEMENTS_HASH: string;
778
884
  /** Options of `carts.checkout`. */
779
885
  interface CheckoutOptions extends RequestOptions {
886
+ /**
887
+ * The `agreementsHash` of the {@link CartAgreements} the buyer was
888
+ * shown (`carts.agreements`). Sent as the JSON body. Checkout refuses
889
+ * with `agreements_changed` when the cart or a legal text changed since.
890
+ * To re-open payment on an `ordered` cart, pass
891
+ * {@link REOPEN_AGREEMENTS_HASH}.
892
+ */
893
+ agreementsHash: string;
780
894
  /**
781
895
  * The checkout challenge token (Cloudflare Turnstile), required when
782
896
  * `store.checkoutChallenge` is set. Single-use: get a new one (reset the
@@ -820,6 +934,14 @@ interface StorefrontClientOptions {
820
934
  * client per incoming request on the server.
821
935
  */
822
936
  buyerIp?: string;
937
+ /**
938
+ * The buyer's browser user agent, sent as `x-konfiqo-buyer-user-agent`
939
+ * so the store can record it with the buyer's marketing consent. Optional,
940
+ * and ignored without `serverKey` or `trustedStorefrontKey` (the API
941
+ * trusts it from a keyed caller only, like `buyerIp`). Pass the
942
+ * `User-Agent` header of the incoming request.
943
+ */
944
+ buyerUserAgent?: string;
823
945
  }
824
946
  /**
825
947
  * A typed client of the Storefront API (`/v1`).
@@ -838,9 +960,22 @@ interface StorefrontClient {
838
960
  getContent(key: string, options?: RequestOptions): Promise<StoreContent>;
839
961
  /** Store information. */
840
962
  readonly store: {
841
- /** `GET /v1/store`: name, language, currency, logo, theme, contact, legal texts, shipping rules. */
963
+ /** `GET /v1/store`: name, language, currency, logo, theme, contact, company details, shipping rules. */
842
964
  get(options?: RequestOptions): Promise<Store>;
843
965
  };
966
+ /** Blog posts. Only published posts whose time has come are served. */
967
+ readonly blog: {
968
+ /**
969
+ * `GET /v1/blog`: a page of posts, newest first. `pageSize` is 1 to 50
970
+ * (default 12). A page past the end answers an empty `items`.
971
+ */
972
+ list(query?: {
973
+ page?: number;
974
+ pageSize?: number;
975
+ }, options?: RequestOptions): Promise<BlogPostList>;
976
+ /** `GET /v1/blog/:slug`. Rejects with `blog_post_not_found`. */
977
+ get(slug: string, options?: RequestOptions): Promise<BlogPost>;
978
+ };
844
979
  /** Categories. */
845
980
  readonly categories: {
846
981
  /** `GET /v1/categories`: the active category tree. */
@@ -885,6 +1020,17 @@ interface StorefrontClient {
885
1020
  shippingOptions(cartId: string, options?: RequestOptions): Promise<ShippingOptionList>;
886
1021
  /** `PUT /v1/carts/:id/shipping-option`: selects a shipping option by id. */
887
1022
  setShippingOption(cartId: string, optionId: string, options?: RequestOptions): Promise<Cart>;
1023
+ /**
1024
+ * `POST /v1/carts/:id/agreements`: the order documents (preliminary
1025
+ * information and distance sales agreement) filled in with this cart,
1026
+ * and their hash. Show the documents, ask the buyer to accept them,
1027
+ * then pass the hash to `checkout`. Call it again after any change to
1028
+ * the cart. Refuses with `legal_not_confirmed` (the store takes no
1029
+ * orders yet), `cart_incomplete`, or `cart_read_only` (the cart is
1030
+ * ordered or expired; to re-open payment on an ordered cart, see
1031
+ * {@link REOPEN_AGREEMENTS_HASH}).
1032
+ */
1033
+ agreements(cartId: string, options?: RequestOptions): Promise<CartAgreements>;
888
1034
  /**
889
1035
  * `POST /v1/carts/:id/checkout`: places the order (or re-opens payment
890
1036
  * for the cart's order) and answers how to present payment. Keep the
@@ -897,8 +1043,17 @@ interface StorefrontClient {
897
1043
  * `turnstileToken` (see `renderTurnstile`); tokens are single-use, so
898
1044
  * reset the widget after every call. Re-opening payment on an already
899
1045
  * ordered cart needs no token.
1046
+ *
1047
+ * `agreementsHash` is required: send the hash from `agreements` that
1048
+ * the buyer accepted. On `agreements_changed`, load the agreements
1049
+ * again, show them and ask the buyer to accept before checking out
1050
+ * with the new hash. This also happens after a declined payment: the
1051
+ * cart opens again and the next order gets a new number. To re-open
1052
+ * payment on an
1053
+ * `ordered` cart, where `agreements` answers `cart_read_only`, pass
1054
+ * {@link REOPEN_AGREEMENTS_HASH}.
900
1055
  */
901
- checkout(cartId: string, options?: CheckoutOptions): Promise<CheckoutResult>;
1056
+ checkout(cartId: string, options: CheckoutOptions): Promise<CheckoutResult>;
902
1057
  };
903
1058
  /** Buyer order status. */
904
1059
  readonly orders: {
@@ -967,6 +1122,15 @@ interface StorefrontClient {
967
1122
  */
968
1123
  declare function createStorefrontClient(options: StorefrontClientOptions): StorefrontClient;
969
1124
 
1125
+ /**
1126
+ * Content keys of the legal texts. A store keeps each one as content: load
1127
+ * it with `getContent(key)` and render it with `<Content>`. The `legal.`
1128
+ * prefix is reserved for these six keys.
1129
+ */
1130
+ declare const LEGAL_KEYS: readonly ["legal.kvkk", "legal.privacy", "legal.preliminary-information", "legal.distance-sales", "legal.returns", "legal.cookies"];
1131
+ /** One of {@link LEGAL_KEYS}. */
1132
+ type LegalKey = (typeof LEGAL_KEYS)[number];
1133
+
970
1134
  /** `checkout_incomplete`: what the cart still lacks. */
971
1135
  type CheckoutMissing = 'lines' | 'customer' | 'identityNumber' | 'shippingAddress' | 'shippingOption';
972
1136
  /**
@@ -1011,6 +1175,10 @@ interface StorefrontErrorDetailsMap {
1011
1175
  checkout_incomplete: {
1012
1176
  missing: CheckoutMissing[];
1013
1177
  };
1178
+ /** `carts.agreements` on a cart that lacks these parts: collect them first. */
1179
+ cart_incomplete: {
1180
+ missing: CheckoutMissing[];
1181
+ };
1014
1182
  /** Let the buyer fix `field`, then check out again. */
1015
1183
  invalid_buyer_details: {
1016
1184
  field: BuyerDetailField;
@@ -1041,7 +1209,7 @@ interface StorefrontErrorDetailsMap {
1041
1209
  };
1042
1210
  }
1043
1211
  /** 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';
1212
+ type StorefrontApiErrorCode = 'store_not_found' | 'origin_not_allowed' | 'invalid_request' | 'invalid_buyer_ip' | 'catalog_unavailable' | 'product_not_found' | 'content_not_found' | 'blog_post_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' | 'legal_not_confirmed' | 'agreements_changed' | 'cart_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
1213
  /**
1046
1214
  * Codes the SDK assigns itself:
1047
1215
  * - `rate_limited` — HTTP 429 without a known `error` code (the throttler);
@@ -1291,11 +1459,11 @@ interface TurnstileWidget {
1291
1459
  * Renders a Turnstile widget with the store's `siteKey`
1292
1460
  * (`store.checkoutChallenge.siteKey`) into `element`, loading the script
1293
1461
  * first if needed. Pass each token from `onToken` to
1294
- * `carts.checkout(id, { turnstileToken })`, then `reset()`.
1462
+ * `carts.checkout(id, { agreementsHash, turnstileToken })`, then `reset()`.
1295
1463
  */
1296
1464
  declare function renderTurnstile(element: HTMLElement, siteKey: string, options: RenderTurnstileOptions): Promise<TurnstileWidget>;
1297
1465
 
1298
1466
  /** Version of the Storefront SDK package. */
1299
- declare const SDK_VERSION = "0.6.1";
1467
+ declare const SDK_VERSION = "0.8.0";
1300
1468
 
1301
- 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, cookiesForHost, createStorefrontClient, formatMoney, isKnownThemeSection, isStorefrontError, loadCartId, loadTurnstile, mountPayment, onDefaultDomain, pixelsForHost, renderTurnstile, saveCartId };
1469
+ export { type Account, type AccountOrder, type AccountProfileInput, type AccountSession, type AdPixels, type AddLineInput, type Address, type AddressInput, type AnyStorefrontError, BUYER_IP_HEADER, BUYER_USER_AGENT_HEADER, type BlogPost, type BlogPostList, type BlogPostSummary, type BuyerDetailField, type Cart, type CartAgreements, 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, LEGAL_KEYS, type LegalDocument, type LegalKey, type MarketingConsentText, 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, REOPEN_AGREEMENTS_HASH, 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 StoreCompany, type StoreContact, type StoreContent, 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, cookiesForHost, createStorefrontClient, formatMoney, isKnownThemeSection, isStorefrontError, loadCartId, loadTurnstile, mountPayment, onDefaultDomain, pixelsForHost, renderTurnstile, saveCartId };