@konfiqo/storefront-sdk 0.4.0 → 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/README.md +87 -65
- package/dist/index.cjs +20 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +59 -8
- package/dist/index.d.ts +59 -8
- package/dist/index.js +20 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -181,31 +181,31 @@ with the response body or rejects with a [`StorefrontError`](#errors).
|
|
|
181
181
|
Path arguments (slugs, ids) that are empty, `.` or `..` reject with a
|
|
182
182
|
`TypeError` (`invalid_path_segment`) without a request.
|
|
183
183
|
|
|
184
|
-
| Method | Route
|
|
185
|
-
| ----------------------------------------------------------------------------- |
|
|
186
|
-
| `store.get()` | `GET /v1/store`
|
|
187
|
-
| `categories.list()` | `GET /v1/categories`
|
|
188
|
-
| `products.list({ category?, q?, page?, pageSize? })` | `GET /v1/products`
|
|
189
|
-
| `products.get(slug)` | `GET /v1/products/:slug`
|
|
190
|
-
| `carts.create()` | `POST /v1/carts`
|
|
191
|
-
| `carts.get(cartId)` | `GET /v1/carts/:id`
|
|
192
|
-
| `carts.addLine(cartId, { variantId, quantity })`
|
|
193
|
-
| `carts.updateLine(cartId,
|
|
194
|
-
| `carts.removeLine(cartId,
|
|
195
|
-
| `carts.setCustomer(cartId, { email, name, surname, phone, identityNumber? })` | `PUT /v1/carts/:id/customer`
|
|
196
|
-
| `carts.setAddress(cartId, { shipping, billing? })` | `PUT /v1/carts/:id/address`
|
|
197
|
-
| `carts.shippingOptions(cartId)` | `GET /v1/carts/:id/shipping-options`
|
|
198
|
-
| `carts.setShippingOption(cartId, optionId)` | `PUT /v1/carts/:id/shipping-option`
|
|
199
|
-
| `carts.checkout(cartId, { turnstileToken? })` | `POST /v1/carts/:id/checkout`
|
|
200
|
-
| `orders.get(orderId, token)` | `GET /v1/orders/:id?token=`
|
|
201
|
-
| `carts.recover(token)` | `POST /v1/carts/recover`
|
|
202
|
-
| `account.requestCode(email, { turnstileToken? })` | `POST /v1/account/code`
|
|
203
|
-
| `account.signIn(email, code)` | `POST /v1/account/session`
|
|
204
|
-
| `account.signOut()` | `DELETE /v1/account/session`
|
|
205
|
-
| `account.get(page?)` | `GET /v1/account`
|
|
206
|
-
| `account.updateProfile({ name, surname, phone })` | `PUT /v1/account/profile`
|
|
207
|
-
| `account.saveAddresses(list)` | `PUT /v1/account/addresses`
|
|
208
|
-
| `media.url(key)` | —
|
|
184
|
+
| Method | Route | Resolves with |
|
|
185
|
+
| ----------------------------------------------------------------------------- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
186
|
+
| `store.get()` | `GET /v1/store` | `Store`: name, `defaultLanguage`, `currency`, `logo`/`logoUrl`, `theme` (`ThemeV1`, as stored), contact, legal texts, shipping rules |
|
|
187
|
+
| `categories.list()` | `GET /v1/categories` | `{ items: Category[] }` (active tree, sorted) |
|
|
188
|
+
| `products.list({ category?, q?, page?, pageSize? })` | `GET /v1/products` | `{ items: Product[], pagination }` (`pageSize` 1–100, default 20) |
|
|
189
|
+
| `products.get(slug)` | `GET /v1/products/:slug` | `Product` |
|
|
190
|
+
| `carts.create()` | `POST /v1/carts` | `Cart` |
|
|
191
|
+
| `carts.get(cartId)` | `GET /v1/carts/:id` | `Cart` |
|
|
192
|
+
| `carts.addLine(cartId, { variantId, quantity, personalization? })` | `POST /v1/carts/:id/lines` | `Cart` |
|
|
193
|
+
| `carts.updateLine(cartId, lineId, { quantity })` | `PATCH /v1/carts/:id/lines/:lineId` | `Cart` |
|
|
194
|
+
| `carts.removeLine(cartId, lineId)` | `DELETE /v1/carts/:id/lines/:lineId` | `Cart` |
|
|
195
|
+
| `carts.setCustomer(cartId, { email, name, surname, phone, identityNumber? })` | `PUT /v1/carts/:id/customer` | `Cart` |
|
|
196
|
+
| `carts.setAddress(cartId, { shipping, billing? })` | `PUT /v1/carts/:id/address` | `Cart` |
|
|
197
|
+
| `carts.shippingOptions(cartId)` | `GET /v1/carts/:id/shipping-options` | `{ items: { id, priceMinor }[] }` |
|
|
198
|
+
| `carts.setShippingOption(cartId, optionId)` | `PUT /v1/carts/:id/shipping-option` | `Cart` |
|
|
199
|
+
| `carts.checkout(cartId, { turnstileToken? })` | `POST /v1/carts/:id/checkout` | `CheckoutResult` (see [Checkout challenge](#checkout-challenge)) |
|
|
200
|
+
| `orders.get(orderId, token)` | `GET /v1/orders/:id?token=` | `Order` |
|
|
201
|
+
| `carts.recover(token)` | `POST /v1/carts/recover` | `{ cartId }`: a **new** cart with the abandoned cart's lines (see [Accounts](#accounts-and-cart-recovery)) |
|
|
202
|
+
| `account.requestCode(email, { turnstileToken? })` | `POST /v1/account/code` | nothing (202 for any address) |
|
|
203
|
+
| `account.signIn(email, code)` | `POST /v1/account/session` | `{ customer: { email } }`; sets the session cookie |
|
|
204
|
+
| `account.signOut()` | `DELETE /v1/account/session` | nothing |
|
|
205
|
+
| `account.get(page?)` | `GET /v1/account` | `Account`: profile, `savedAddresses`, one page of `orders` (20, newest first) |
|
|
206
|
+
| `account.updateProfile({ name, surname, phone })` | `PUT /v1/account/profile` | nothing |
|
|
207
|
+
| `account.saveAddresses(list)` | `PUT /v1/account/addresses` | `SavedAddress[]` as stored (max 5, one default) |
|
|
208
|
+
| `media.url(key)` | — | absolute image URL (synchronous) |
|
|
209
209
|
|
|
210
210
|
### Accounts and cart recovery
|
|
211
211
|
|
|
@@ -263,6 +263,24 @@ rides in the query because `<img>` cannot send headers; it is public.
|
|
|
263
263
|
(false = fewer units left than the line asks for). Checkout refuses both:
|
|
264
264
|
show them and let the buyer remove or reduce.
|
|
265
265
|
|
|
266
|
+
**Line personalization.** A product can ask the buyer for one short text per
|
|
267
|
+
line (an engraving, a pet's name). When it does, `product.personalization` is
|
|
268
|
+
`{ label, required, minLength, maxLength }` (absent otherwise; lengths count
|
|
269
|
+
characters). Pass the text to `carts.addLine(cartId, { variantId, quantity,
|
|
270
|
+
personalization: 'Sarı' })`; a refused text rejects with
|
|
271
|
+
`invalid_personalization` (400). The same variant with a different text is a
|
|
272
|
+
separate line, so address lines by `line.id` in `updateLine` / `removeLine`:
|
|
273
|
+
it is the variant id for a line without text and `<variantId>~<12 hex>` for a
|
|
274
|
+
line with text (a variant id still matches a line without text). Each line
|
|
275
|
+
carries `personalization: string | null` and `personalizationValid`, which is
|
|
276
|
+
false when the stored text no longer satisfies the product's current rule;
|
|
277
|
+
checkout then rejects with `invalid_personalization` and `details.lineIds`:
|
|
278
|
+
remove those lines and add them again. `id`, `personalization` and
|
|
279
|
+
`personalizationValid` are required in the types and need a Konfiqo commerce
|
|
280
|
+
API that returns them; an older server omits them, and against one treat `id`
|
|
281
|
+
as `variantId`, `personalization` as null and `personalizationValid` as true.
|
|
282
|
+
Order lines carry `personalization?: string | null`.
|
|
283
|
+
|
|
266
284
|
**Customer.** `phone` must be a Turkish mobile number (`05XX…`, `5XX…`,
|
|
267
285
|
`+90…`, `0090…`; spaces, dashes, parentheses allowed); it comes back as
|
|
268
286
|
`90XXXXXXXXXX`. Addresses use `{ name?, phone?, email?, address | line1 +
|
|
@@ -293,6 +311,9 @@ try {
|
|
|
293
311
|
case 'out_of_stock':
|
|
294
312
|
markLines(e.details.variantIds);
|
|
295
313
|
break;
|
|
314
|
+
case 'invalid_personalization':
|
|
315
|
+
askAgain(e.details.lineIds ?? []);
|
|
316
|
+
break;
|
|
296
317
|
case 'checkout_incomplete':
|
|
297
318
|
ask(e.details.missing);
|
|
298
319
|
break;
|
|
@@ -312,46 +333,47 @@ try {
|
|
|
312
333
|
|
|
313
334
|
### API error codes
|
|
314
335
|
|
|
315
|
-
| Code | Status
|
|
316
|
-
| ------------------------- |
|
|
317
|
-
| `store_not_found` | 404
|
|
318
|
-
| `origin_not_allowed` | 403
|
|
319
|
-
| `invalid_request` | 400
|
|
320
|
-
| `invalid_buyer_ip` | 400
|
|
321
|
-
| `catalog_unavailable` | 503
|
|
322
|
-
| `product_not_found` | 404
|
|
323
|
-
| `cart_not_found` | 404
|
|
324
|
-
| `variant_not_found` | 404
|
|
325
|
-
| `insufficient_stock` | 409
|
|
326
|
-
| `quantity_out_of_range` | 400
|
|
327
|
-
| `too_many_lines` | 400
|
|
328
|
-
| `line_not_found` | 404
|
|
329
|
-
| `invalid_shipping_option` | 400
|
|
330
|
-
| `cart_read_only` | 409
|
|
331
|
-
| `checkout_in_progress` | 409
|
|
332
|
-
| `checkout_incomplete` | 400
|
|
333
|
-
| `cart_changed` | 409
|
|
334
|
-
| `out_of_stock` | 409
|
|
335
|
-
| `
|
|
336
|
-
| `
|
|
337
|
-
| `
|
|
338
|
-
| `
|
|
339
|
-
| `
|
|
340
|
-
| `
|
|
341
|
-
| `
|
|
342
|
-
| `
|
|
343
|
-
| `
|
|
344
|
-
| `
|
|
345
|
-
| `
|
|
346
|
-
| `
|
|
347
|
-
| `
|
|
348
|
-
| `
|
|
349
|
-
| `
|
|
350
|
-
| `
|
|
351
|
-
| `
|
|
352
|
-
| `
|
|
353
|
-
| `
|
|
354
|
-
| `
|
|
336
|
+
| Code | Status | `details` | Meaning / what to do |
|
|
337
|
+
| ------------------------- | -------- | ----------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
338
|
+
| `store_not_found` | 404 | | bad / revoked publishable key, or the store is disabled |
|
|
339
|
+
| `origin_not_allowed` | 403 | | browser `Origin` not in the store's `allowedOrigins` |
|
|
340
|
+
| `invalid_request` | 400 | `{ issues: [{ path, message }] }` | a body or query field is invalid (e.g. `path: "phone"`) |
|
|
341
|
+
| `invalid_buyer_ip` | 400 | | trusted key sent without a valid `buyerIp` |
|
|
342
|
+
| `catalog_unavailable` | 503 | | the catalog could not be read; retry later |
|
|
343
|
+
| `product_not_found` | 404 | | no sellable product with that slug |
|
|
344
|
+
| `cart_not_found` | 404 | | unknown cart (or another store's): start a new cart |
|
|
345
|
+
| `variant_not_found` | 404 | | the variant is not sold |
|
|
346
|
+
| `insufficient_stock` | 409 | `{ available }` | only `available` units can be added |
|
|
347
|
+
| `quantity_out_of_range` | 400 | | a line holds 1–99 units |
|
|
348
|
+
| `too_many_lines` | 400 | | a cart holds at most 50 lines |
|
|
349
|
+
| `line_not_found` | 404 | | no line with that id |
|
|
350
|
+
| `invalid_shipping_option` | 400 | | the option is not offered for this cart |
|
|
351
|
+
| `cart_read_only` | 409 | `{ status: 'ordered' \| 'expired' }` | the cart can no longer change: `expired` → start a new cart; `ordered` → check out again (re-opens payment) or show the order |
|
|
352
|
+
| `checkout_in_progress` | 409 | | another checkout of this cart is running: retry in a few seconds |
|
|
353
|
+
| `checkout_incomplete` | 400 | `{ missing: ('lines' \| 'customer' \| 'identityNumber' \| 'shippingAddress' \| 'shippingOption')[] }` | collect what is missing |
|
|
354
|
+
| `cart_changed` | 409 | `{ lines, subtotalMinor, shippingMinor, totalMinor, shippingOptions }` | prices or shipping changed: show the new totals, let the buyer confirm, then call checkout again. Never re-submit silently. |
|
|
355
|
+
| `out_of_stock` | 409 | `{ variantIds }` | remove / reduce those lines |
|
|
356
|
+
| `invalid_personalization` | 400, 409 | `{ lineIds? }` (409 at checkout) | 400: the text breaks the product's rule (or the product asks for none). 409: those lines' stored text is no longer valid: remove each line and add it again with a valid text |
|
|
357
|
+
| `amount_out_of_range` | 400 | | total not representable |
|
|
358
|
+
| `nothing_to_pay` | 400 | | total is zero |
|
|
359
|
+
| `invalid_buyer_details` | 422 | `{ field }` | the payment provider refused `name`, `surname`, `email`, `phone`, `identityNumber`, `shippingAddress.<f>` or `billingAddress.<f>`: let the buyer fix it, check out again |
|
|
360
|
+
| `payment_unavailable` | 502 | | payments refused or unreachable; the order was cancelled, the cart is still open |
|
|
361
|
+
| `checkout_unavailable` | 503 | | store backend unreachable; the cart is still open, retry |
|
|
362
|
+
| `order_not_found` | 404 | | unknown order or wrong token |
|
|
363
|
+
| `order_unavailable` | 503 | | order status temporarily unavailable; poll again |
|
|
364
|
+
| `media_not_found` | 404 | | (image route) key not referenced by the catalog |
|
|
365
|
+
| `media_unavailable` | 503 | | (image route) image temporarily unavailable |
|
|
366
|
+
| `challenge_required` | 400 | | the store requires a checkout challenge and no token was sent: render the widget, check out with its token |
|
|
367
|
+
| `challenge_failed` | 403 | | the token was invalid, expired or already used: `reset()` the widget, check out with the new token |
|
|
368
|
+
| `challenge_unavailable` | 503 | | the challenge could not be verified right now: retry in a moment |
|
|
369
|
+
| `too_many_open_orders` | 429 | | too many unpaid orders from this buyer: finish or wait out a pending payment |
|
|
370
|
+
| `not_signed_in` | 401 | | no valid session cookie: sign in |
|
|
371
|
+
| `invalid_code` | 401 | | wrong, spent or expired sign-in code (5 attempts per code) |
|
|
372
|
+
| `profile_required` | 409 | | save the profile before saving addresses |
|
|
373
|
+
| `too_many_code_requests` | 429 | | too many codes requested from this address: wait |
|
|
374
|
+
| `invalid_recovery_token` | 400 | | the recovery link is malformed or not for this store |
|
|
375
|
+
| `cart_not_recoverable` | 410 | | the abandoned cart was ordered, expired or deleted: start a new cart |
|
|
376
|
+
| `unavailable` | 503 | | the account could not be read or saved right now: retry |
|
|
355
377
|
|
|
356
378
|
### Codes the SDK assigns
|
|
357
379
|
|
package/dist/index.cjs
CHANGED
|
@@ -64,6 +64,7 @@ var API_CODES = /* @__PURE__ */ new Set([
|
|
|
64
64
|
"checkout_in_progress",
|
|
65
65
|
"checkout_incomplete",
|
|
66
66
|
"cart_changed",
|
|
67
|
+
"invalid_personalization",
|
|
67
68
|
"out_of_stock",
|
|
68
69
|
"amount_out_of_range",
|
|
69
70
|
"nothing_to_pay",
|
|
@@ -166,6 +167,13 @@ function apiError(code, status, message, b) {
|
|
|
166
167
|
totalMinor: n(b.totalMinor),
|
|
167
168
|
shippingOptions: arr(b.shippingOptions)
|
|
168
169
|
});
|
|
170
|
+
case "invalid_personalization":
|
|
171
|
+
return new StorefrontError(
|
|
172
|
+
code,
|
|
173
|
+
status,
|
|
174
|
+
message,
|
|
175
|
+
Array.isArray(b.lineIds) ? { lineIds: arr(b.lineIds) } : {}
|
|
176
|
+
);
|
|
169
177
|
case "out_of_stock":
|
|
170
178
|
return new StorefrontError(code, status, message, {
|
|
171
179
|
variantIds: arr(b.variantIds)
|
|
@@ -380,18 +388,24 @@ function createStorefrontClient(options) {
|
|
|
380
388
|
addLine: (cartId, input, o) => request(
|
|
381
389
|
"POST",
|
|
382
390
|
() => `${cart(cartId)}/lines`,
|
|
383
|
-
{
|
|
391
|
+
{
|
|
392
|
+
variantId: input.variantId,
|
|
393
|
+
quantity: input.quantity,
|
|
394
|
+
...input.personalization !== void 0 && {
|
|
395
|
+
personalization: input.personalization
|
|
396
|
+
}
|
|
397
|
+
},
|
|
384
398
|
o
|
|
385
399
|
),
|
|
386
|
-
updateLine: (cartId,
|
|
400
|
+
updateLine: (cartId, lineId, input, o) => request(
|
|
387
401
|
"PATCH",
|
|
388
|
-
() => `${cart(cartId)}/lines/${seg(
|
|
402
|
+
() => `${cart(cartId)}/lines/${seg(lineId)}`,
|
|
389
403
|
{ quantity: input.quantity },
|
|
390
404
|
o
|
|
391
405
|
),
|
|
392
|
-
removeLine: (cartId,
|
|
406
|
+
removeLine: (cartId, lineId, o) => request(
|
|
393
407
|
"DELETE",
|
|
394
|
-
() => `${cart(cartId)}/lines/${seg(
|
|
408
|
+
() => `${cart(cartId)}/lines/${seg(lineId)}`,
|
|
395
409
|
void 0,
|
|
396
410
|
o
|
|
397
411
|
),
|
|
@@ -730,7 +744,7 @@ async function renderTurnstile(element, siteKey, options) {
|
|
|
730
744
|
}
|
|
731
745
|
|
|
732
746
|
// src/index.ts
|
|
733
|
-
var SDK_VERSION = "0.
|
|
747
|
+
var SDK_VERSION = "0.5.0";
|
|
734
748
|
// Annotate the CommonJS export names for ESM import in node:
|
|
735
749
|
0 && (module.exports = {
|
|
736
750
|
BUYER_IP_HEADER,
|