@konfiqo/storefront-sdk 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -183,34 +183,36 @@ with the response body or rejects with a [`StorefrontError`](#errors).
183
183
  Path arguments (slugs, ids) that are empty, `.` or `..` reject with a
184
184
  `TypeError` (`invalid_path_segment`) without a request.
185
185
 
186
- | Method | Route | Resolves with |
187
- | ----------------------------------------------------------------------------- | ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------- |
188
- | `store.get()` | `GET /v1/store` | `Store`: name, `defaultLanguage`, `currency`, `logo`/`logoUrl`, `theme` (`ThemeV1`, as stored), contact, `company`, shipping rules |
189
- | `categories.list()` | `GET /v1/categories` | `{ items: Category[] }` (active tree, sorted) |
190
- | `products.list({ category?, q?, page?, pageSize? })` | `GET /v1/products` | `{ items: Product[], pagination }` (`pageSize` 1–100, default 20) |
191
- | `products.get(slug)` | `GET /v1/products/:slug` | `Product` |
192
- | `blog.list({ page?, pageSize? })` | `GET /v1/blog` | `{ items: BlogPostSummary[], pagination }` (newest first, `pageSize` 1–50, default 12) |
193
- | `blog.get(slug)` | `GET /v1/blog/:slug` | `BlogPost`: the summary fields, `metaDescription` and the body `tree` |
194
- | `carts.create()` | `POST /v1/carts` | `Cart` |
195
- | `carts.get(cartId)` | `GET /v1/carts/:id` | `Cart` |
196
- | `carts.addLine(cartId, { variantId, quantity, personalization? })` | `POST /v1/carts/:id/lines` | `Cart` |
197
- | `carts.updateLine(cartId, lineId, { quantity })` | `PATCH /v1/carts/:id/lines/:lineId` | `Cart` |
198
- | `carts.removeLine(cartId, lineId)` | `DELETE /v1/carts/:id/lines/:lineId` | `Cart` |
199
- | `carts.setCustomer(cartId, { email, name, surname, phone, identityNumber? })` | `PUT /v1/carts/:id/customer` | `Cart` |
200
- | `carts.setAddress(cartId, { shipping, billing? })` | `PUT /v1/carts/:id/address` | `Cart` |
201
- | `carts.shippingOptions(cartId)` | `GET /v1/carts/:id/shipping-options` | `{ items: { id, priceMinor }[] }` |
202
- | `carts.setShippingOption(cartId, optionId)` | `PUT /v1/carts/:id/shipping-option` | `Cart` |
203
- | `carts.agreements(cartId)` | `POST /v1/carts/:id/agreements` | `CartAgreements` (see [Legal texts and agreements](#legal-texts-and-agreements)) |
204
- | `carts.checkout(cartId, { agreementsHash, turnstileToken? })` | `POST /v1/carts/:id/checkout` | `CheckoutResult` (see [Checkout challenge](#checkout-challenge)) |
205
- | `orders.get(orderId, token)` | `GET /v1/orders/:id?token=` | `Order` |
206
- | `carts.recover(token)` | `POST /v1/carts/recover` | `{ cartId }`: a **new** cart with the abandoned cart's lines (see [Accounts](#accounts-and-cart-recovery)) |
207
- | `account.requestCode(email, { turnstileToken? })` | `POST /v1/account/code` | nothing (202 for any address) |
208
- | `account.signIn(email, code)` | `POST /v1/account/session` | `{ customer: { email } }`; sets the session cookie |
209
- | `account.signOut()` | `DELETE /v1/account/session` | nothing |
210
- | `account.get(page?)` | `GET /v1/account` | `Account`: profile, `savedAddresses`, one page of `orders` (20, newest first) |
211
- | `account.updateProfile({ name, surname, phone })` | `PUT /v1/account/profile` | nothing |
212
- | `account.saveAddresses(list)` | `PUT /v1/account/addresses` | `SavedAddress[]` as stored (max 5, one default) |
213
- | `media.url(key)` | none | absolute image URL (synchronous) |
186
+ | Method | Route | Resolves with |
187
+ | ----------------------------------------------------------------------------- | ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
188
+ | `store.get()` | `GET /v1/store` | `Store`: name, `defaultLanguage`, `currency`, `logo`/`logoUrl`, `theme` (`ThemeV1`, as stored), contact, `company`, shipping rules |
189
+ | `categories.list()` | `GET /v1/categories` | `{ items: Category[] }` (active tree, sorted) |
190
+ | `products.list({ category?, q?, page?, pageSize? })` | `GET /v1/products` | `{ items: Product[], pagination }` (`pageSize` 1–100, default 20) |
191
+ | `products.get(slug)` | `GET /v1/products/:slug` | `Product` |
192
+ | `blog.list({ page?, pageSize? })` | `GET /v1/blog` | `{ items: BlogPostSummary[], pagination }` (newest first, `pageSize` 1–50, default 12) |
193
+ | `blog.get(slug)` | `GET /v1/blog/:slug` | `BlogPost`: the summary fields, `metaDescription` and the body `tree` |
194
+ | `carts.create()` | `POST /v1/carts` | `Cart` |
195
+ | `carts.get(cartId)` | `GET /v1/carts/:id` | `Cart` |
196
+ | `carts.addLine(cartId, { variantId, quantity, personalization? })` | `POST /v1/carts/:id/lines` | `Cart` |
197
+ | `carts.updateLine(cartId, lineId, { quantity })` | `PATCH /v1/carts/:id/lines/:lineId` | `Cart` |
198
+ | `carts.removeLine(cartId, lineId)` | `DELETE /v1/carts/:id/lines/:lineId` | `Cart` |
199
+ | `carts.setCustomer(cartId, { email, name, surname, phone, identityNumber? })` | `PUT /v1/carts/:id/customer` | `Cart` |
200
+ | `carts.setAddress(cartId, { shipping, billing? })` | `PUT /v1/carts/:id/address` | `Cart` |
201
+ | `carts.shippingOptions(cartId)` | `GET /v1/carts/:id/shipping-options` | `{ items: { id, priceMinor }[] }` |
202
+ | `carts.setShippingOption(cartId, optionId)` | `PUT /v1/carts/:id/shipping-option` | `Cart` |
203
+ | `carts.agreements(cartId)` | `POST /v1/carts/:id/agreements` | `CartAgreements` (see [Legal texts and agreements](#legal-texts-and-agreements)) |
204
+ | `carts.checkout(cartId, { agreementsHash, turnstileToken? })` | `POST /v1/carts/:id/checkout` | `CheckoutResult` (see [Checkout challenge](#checkout-challenge)) |
205
+ | `orders.get(orderId, token)` | `GET /v1/orders/:id?token=` | `Order` |
206
+ | `orders.createReturn(orderId, token, { lines, note? })` | `POST /v1/orders/:id/returns` | `OrderReturn` (see [Returns](#returns)); the token goes in the body |
207
+ | `orders.cancelReturn(orderId, returnId, token)` | `POST /v1/orders/:id/returns/:returnId/cancel` | `OrderReturn`, now `cancelled` |
208
+ | `carts.recover(token)` | `POST /v1/carts/recover` | `{ cartId }`: a **new** cart with the abandoned cart's lines (see [Accounts](#accounts-and-cart-recovery)) |
209
+ | `account.requestCode(email, { turnstileToken? })` | `POST /v1/account/code` | nothing (202 for any address) |
210
+ | `account.signIn(email, code)` | `POST /v1/account/session` | `{ customer: { email } }`; sets the session cookie |
211
+ | `account.signOut()` | `DELETE /v1/account/session` | nothing |
212
+ | `account.get(page?)` | `GET /v1/account` | `Account`: profile, `savedAddresses`, one page of `orders` (20, newest first) |
213
+ | `account.updateProfile({ name, surname, phone })` | `PUT /v1/account/profile` | nothing |
214
+ | `account.saveAddresses(list)` | `PUT /v1/account/addresses` | `SavedAddress[]` as stored (max 5, one default) |
215
+ | `media.url(key)` | none | absolute image URL (synchronous) |
214
216
 
215
217
  ### Accounts and cart recovery
216
218
 
@@ -286,6 +288,36 @@ API that returns them; an older server omits them, and against one treat `id`
286
288
  as `variantId`, `personalization` as null and `personalizationValid` as true.
287
289
  Order lines carry `personalization?: string | null`.
288
290
 
291
+ ### Returns
292
+
293
+ `order.returnable` says whether the buyer can open a return now:
294
+ `{ eligible, reason, deadline }`. `deadline` is 14 days after the latest
295
+ delivery, or null when no delivery date is known. Show the return form only
296
+ when `eligible` is true. Each order line has an `id` (the `lineId` to send) and
297
+ `returnableQuantity` (units still open for return). Lines with a
298
+ personalization text cannot be returned.
299
+
300
+ ```ts
301
+ const returned = await client.orders.createReturn(order.id, token, {
302
+ lines: [{ lineId: order.lines[0].id, quantity: 1, reason: 'defective' }],
303
+ note: 'The lid is cracked.',
304
+ });
305
+ ```
306
+
307
+ `order.returns` lists the returns, oldest first. A return starts as
308
+ `requested`. The store may approve it at once or leave that to the seller.
309
+ From `approved` on, the return carries `carrier`, `returnCode` and
310
+ `instructions` for sending the parcel back. Later statuses are `received`,
311
+ `refunded`, `rejected` (see `rejectionReason`) and `cancelled`. The buyer can
312
+ cancel while a return is `requested` or `approved`.
313
+
314
+ Errors: `invalid_return` (400) for a line that is not of this order, a repeated
315
+ line or too many units. `return_not_allowed` (409) when the order takes no
316
+ return now; `details.reason` is one of `unpaid`, `refunded`, `cancelled`,
317
+ `window_closed`, `open_return`, `too_many_returns` or `nothing_left`, and it is
318
+ absent when a cancel is refused because the return is no longer open.
319
+ `return_not_found` (404) for a return of another order.
320
+
289
321
  **Customer.** `phone` must be a Turkish mobile number (`05XX…`, `5XX…`,
290
322
  `+90…`, `0090…`; spaces, dashes, parentheses allowed); it comes back as
291
323
  `90XXXXXXXXXX`. Addresses use `{ name?, phone?, email?, address | line1 +
package/dist/index.cjs CHANGED
@@ -95,6 +95,9 @@ var API_CODES = /* @__PURE__ */ new Set([
95
95
  "too_many_code_requests",
96
96
  "invalid_recovery_token",
97
97
  "cart_not_recoverable",
98
+ "invalid_return",
99
+ "return_not_allowed",
100
+ "return_not_found",
98
101
  "unavailable"
99
102
  ]);
100
103
  var ERROR_BRAND = /* @__PURE__ */ Symbol.for("@konfiqo/storefront-sdk/error");
@@ -209,6 +212,13 @@ function apiError(code, status, message, b) {
209
212
  return new StorefrontError(code, status, message, {
210
213
  status: b.status === "ordered" ? "ordered" : "expired"
211
214
  });
215
+ case "return_not_allowed":
216
+ return new StorefrontError(
217
+ code,
218
+ status,
219
+ message,
220
+ typeof b.reason === "string" ? { reason: b.reason } : {}
221
+ );
212
222
  default:
213
223
  return new StorefrontError(
214
224
  code,
@@ -482,6 +492,22 @@ function createStorefrontClient(options) {
482
492
  get: (orderId, token, o) => get(
483
493
  () => `/v1/orders/${seg(orderId)}?token=${encodeURIComponent(token)}`,
484
494
  o
495
+ ),
496
+ createReturn: (orderId, token, input, o) => request(
497
+ "POST",
498
+ () => `/v1/orders/${seg(orderId)}/returns`,
499
+ {
500
+ token,
501
+ lines: input.lines,
502
+ ...input.note !== void 0 && { note: input.note }
503
+ },
504
+ o
505
+ ),
506
+ cancelReturn: (orderId, returnId, token, o) => request(
507
+ "POST",
508
+ () => `/v1/orders/${seg(orderId)}/returns/${seg(returnId)}/cancel`,
509
+ { token },
510
+ o
485
511
  )
486
512
  },
487
513
  account: {
@@ -823,7 +849,7 @@ async function renderTurnstile(element, siteKey, options) {
823
849
  }
824
850
 
825
851
  // src/index.ts
826
- var SDK_VERSION = "0.8.0";
852
+ var SDK_VERSION = "0.9.0";
827
853
  // Annotate the CommonJS export names for ESM import in node:
828
854
  0 && (module.exports = {
829
855
  BUYER_IP_HEADER,