@eldrajs/sdk 0.2.2 → 0.2.3

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/CHANGELOG.md CHANGED
@@ -9,6 +9,10 @@ platform repository.
9
9
 
10
10
  ## Unreleased
11
11
 
12
+ - `EldraHttpError.errorId` carries the problem's specific reason, such as `CART_NOT_FOUND` or
13
+ `CART_INSUFFICIENT_STOCK`. The docs told you to branch on `code` for these, but the gateway puts
14
+ them in `errorId`; `code` is only the category (`NOT_FOUND`, `CONFLICT`) and is unchanged.
15
+
12
16
  - Restore `previewToken` on the SDK client and Vite generator after the move from
13
17
  `vue-ui-components`. Accepts a string or callback and sends `X-Preview-Token`; the generator
14
18
  forwards it to both type endpoints without embedding it in generated files.
package/README.md CHANGED
@@ -54,6 +54,7 @@ precedence.
54
54
  | `inventory` | `availability` |
55
55
  | `features` | `getOrganization`, `list`, `isEnabled`, `getCapabilities` |
56
56
 
57
- Every failed request throws `EldraHttpError` with `status` and the gateway's problem `code`.
57
+ Every failed request throws `EldraHttpError` with `status`, the problem's category `code` (such as
58
+ `NOT_FOUND`) and its specific `errorId` (such as `CART_NOT_FOUND`); branch on `errorId`.
58
59
  `createCartSession` and `createOrderAccessTokens` persist the cart id and order tokens without
59
60
  throwing where storage is unavailable.
@@ -19,21 +19,24 @@ var EldraHttpError = class extends Error {
19
19
  status;
20
20
  statusText;
21
21
  body;
22
- /** The gateway's problem `code`, such as `INSUFFICIENT_STOCK`, when the body carried one. */
22
+ /** The problem's category, such as `NOT_FOUND` or `CONFLICT`, when the body carried one. */
23
23
  code;
24
+ /** The problem's specific reason, such as `CART_NOT_FOUND`, when the body carried one. */
25
+ errorId;
24
26
  constructor(response, body) {
25
27
  super(`Web Studio request failed with ${response.status} ${response.statusText}`);
26
28
  this.name = "EldraHttpError";
27
29
  this.status = response.status;
28
30
  this.statusText = response.statusText;
29
31
  this.body = body;
30
- this.code = problemCode(body);
32
+ this.code = problemField(body, "code");
33
+ this.errorId = problemField(body, "errorId");
31
34
  }
32
35
  };
33
- function problemCode(body) {
34
- if (body && typeof body === "object" && "code" in body) {
35
- const code = body.code;
36
- return typeof code === "string" ? code : void 0;
36
+ function problemField(body, field) {
37
+ if (body && typeof body === "object" && field in body) {
38
+ const value = body[field];
39
+ return typeof value === "string" ? value : void 0;
37
40
  }
38
41
  }
39
42
  function initEldraClient(options) {
package/dist/index.d.ts CHANGED
@@ -5,8 +5,10 @@ export declare class EldraHttpError extends Error {
5
5
  readonly status: number;
6
6
  readonly statusText: string;
7
7
  readonly body: unknown;
8
- /** The gateway's problem `code`, such as `INSUFFICIENT_STOCK`, when the body carried one. */
8
+ /** The problem's category, such as `NOT_FOUND` or `CONFLICT`, when the body carried one. */
9
9
  readonly code: string | undefined;
10
+ /** The problem's specific reason, such as `CART_NOT_FOUND`, when the body carried one. */
11
+ readonly errorId: string | undefined;
10
12
  constructor(response: Response, body: unknown);
11
13
  }
12
14
  export declare function initEldraClient(options: EldraClientOptions): EldraClient;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as initEldraClient, i as getEldraClient, n as EldraHttpError, r as createEldraClient, t as DEFAULT_ELDRA_API_BASE_URL } from "./client-CfkktZmj.js";
1
+ import { a as initEldraClient, i as getEldraClient, n as EldraHttpError, r as createEldraClient, t as DEFAULT_ELDRA_API_BASE_URL } from "./client-bg68WrsC.js";
2
2
  //#region src/storage.ts
3
3
  const DEFAULT_CART_KEY = "eldra.cartId";
4
4
  const DEFAULT_ORDER_TOKEN_PREFIX = "eldra.orderAccessToken.";
package/dist/vite.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./client-CfkktZmj.js";
1
+ import "./client-bg68WrsC.js";
2
2
  import { access, mkdir, writeFile } from "node:fs/promises";
3
3
  import { dirname, resolve } from "node:path";
4
4
  import openapiTS, { astToString } from "openapi-typescript";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/sdk",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Framework-free client for the Eldra Web Studio public storefront API: CMS, catalog, cart, checkout handoff, orders, inventory. Types generated from your gateway's OpenAPI document and CMS schemas at build time.",
5
5
  "keywords": [
6
6
  "cms",