@eldrajs/sdk 0.2.2 → 0.2.4

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,15 @@ platform repository.
9
9
 
10
10
  ## Unreleased
11
11
 
12
+ - `checkout.handoffUrl` defaults to the hosted checkout at `https://checkout.eldra.app` (exported
13
+ as `DEFAULT_ELDRA_CHECKOUT_URL`) when the client uses the default API base URL, so a production
14
+ storefront no longer needs a checkout URL setting. `checkoutUrl` and the `ELDRA_CHECKOUT_URL` env
15
+ keys still override it; a client on any other gateway must still name its checkout.
16
+
17
+ - `EldraHttpError.errorId` carries the problem's specific reason, such as `CART_NOT_FOUND` or
18
+ `CART_INSUFFICIENT_STOCK`. The docs told you to branch on `code` for these, but the gateway puts
19
+ them in `errorId`; `code` is only the category (`NOT_FOUND`, `CONFLICT`) and is unchanged.
20
+
12
21
  - Restore `previewToken` on the SDK client and Vite generator after the move from
13
22
  `vue-ui-components`. Accepts a string or callback and sends `X-Preview-Token`; the generator
14
23
  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.
@@ -7,6 +7,14 @@ const apiBaseUrlEnvKeys = [
7
7
  "PUBLIC_ELDRA_API_BASE_URL"
8
8
  ];
9
9
  const DEFAULT_ELDRA_API_BASE_URL = "https://web.eldra.app/api";
10
+ const checkoutUrlEnvKeys = [
11
+ "ELDRA_CHECKOUT_URL",
12
+ "VITE_ELDRA_CHECKOUT_URL",
13
+ "NEXT_PUBLIC_ELDRA_CHECKOUT_URL",
14
+ "NUXT_PUBLIC_ELDRA_CHECKOUT_URL",
15
+ "PUBLIC_ELDRA_CHECKOUT_URL"
16
+ ];
17
+ const DEFAULT_ELDRA_CHECKOUT_URL = "https://checkout.eldra.app";
10
18
  const orgIdEnvKeys = [
11
19
  "ELDRA_ORG_ID",
12
20
  "VITE_ELDRA_ORG_ID",
@@ -19,21 +27,24 @@ var EldraHttpError = class extends Error {
19
27
  status;
20
28
  statusText;
21
29
  body;
22
- /** The gateway's problem `code`, such as `INSUFFICIENT_STOCK`, when the body carried one. */
30
+ /** The problem's category, such as `NOT_FOUND` or `CONFLICT`, when the body carried one. */
23
31
  code;
32
+ /** The problem's specific reason, such as `CART_NOT_FOUND`, when the body carried one. */
33
+ errorId;
24
34
  constructor(response, body) {
25
35
  super(`Web Studio request failed with ${response.status} ${response.statusText}`);
26
36
  this.name = "EldraHttpError";
27
37
  this.status = response.status;
28
38
  this.statusText = response.statusText;
29
39
  this.body = body;
30
- this.code = problemCode(body);
40
+ this.code = problemField(body, "code");
41
+ this.errorId = problemField(body, "errorId");
31
42
  }
32
43
  };
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;
44
+ function problemField(body, field) {
45
+ if (body && typeof body === "object" && field in body) {
46
+ const value = body[field];
47
+ return typeof value === "string" ? value : void 0;
37
48
  }
38
49
  }
39
50
  function initEldraClient(options) {
@@ -204,8 +215,8 @@ function createEldraClient(options) {
204
215
  })
205
216
  },
206
217
  checkout: { handoffUrl: (handoff) => {
207
- const checkoutUrl = handoff.checkoutUrl ?? resolveRuntimeValue(options.checkoutUrl);
208
- if (!checkoutUrl) throw new Error("Missing checkout URL. Pass checkoutUrl to createEldraClient() or to handoffUrl().");
218
+ const checkoutUrl = handoff.checkoutUrl ?? resolveCheckoutUrl(options);
219
+ if (!checkoutUrl) throw new Error(`Missing checkout URL. Pass checkoutUrl to createEldraClient() or to handoffUrl(); ${DEFAULT_ELDRA_CHECKOUT_URL} is only the default for the default API base URL.`);
209
220
  const orgId = handoff.orgId ?? resolveOrgId(options);
210
221
  if (!orgId) throw new Error("Missing Web Studio organization ID.");
211
222
  const url = new URL(`${checkoutUrl.replace(/\/$/, "")}/checkout/${encodeURIComponent(orgId)}/${encodeURIComponent(handoff.cartId)}`);
@@ -293,6 +304,9 @@ function readResponseBody(response) {
293
304
  function resolveApiBaseUrl(options) {
294
305
  return resolveRuntimeValue(options.apiBaseUrl) ?? readFirstEnvValue(resolveRuntimeValue(options.env), apiBaseUrlEnvKeys) ?? "https://web.eldra.app/api";
295
306
  }
307
+ function resolveCheckoutUrl(options) {
308
+ return resolveRuntimeValue(options.checkoutUrl) ?? readFirstEnvValue(resolveRuntimeValue(options.env), checkoutUrlEnvKeys) ?? (resolveApiBaseUrl(options).replace(/\/$/, "") === "https://web.eldra.app/api" ? "https://checkout.eldra.app" : void 0);
309
+ }
296
310
  function resolveOrgId(options) {
297
311
  return resolveRuntimeValue(options.orgId) ?? readFirstEnvValue(resolveRuntimeValue(options.env), orgIdEnvKeys);
298
312
  }
@@ -330,4 +344,4 @@ function isRawBody(body) {
330
344
  return typeof body === "string" || typeof FormData !== "undefined" && body instanceof FormData || typeof URLSearchParams !== "undefined" && body instanceof URLSearchParams || typeof Blob !== "undefined" && body instanceof Blob || body instanceof ArrayBuffer;
331
345
  }
332
346
  //#endregion
333
- export { initEldraClient as a, getEldraClient as i, EldraHttpError as n, createEldraClient as r, DEFAULT_ELDRA_API_BASE_URL as t };
347
+ export { getEldraClient as a, createEldraClient as i, DEFAULT_ELDRA_CHECKOUT_URL as n, initEldraClient as o, EldraHttpError as r, DEFAULT_ELDRA_API_BASE_URL as t };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,15 @@
1
- import { $ as EldraProductVariant, A as EldraFeature, B as EldraOrdersClient, C as EldraCmsResolveEntryListResponse, D as EldraCollectionListOptions, E as EldraCollectionList, F as EldraInventoryClient, G as EldraPaginated, H as EldraOrganizationFeature, I as EldraLocaleOptions, J as EldraProductListItem, K as EldraProductDetails, L as EldraOrder, M as EldraFeatureClient, N as EldraHttpClient, O as EldraCollectionProductsOptions, P as EldraHttpRequest, Q as EldraProductThumbnail, R as EldraOrderLine, S as EldraCmsResolveEntryListOptions, T as EldraCollection, U as EldraOrganizationOptions, V as EldraOrganizationDetails, W as EldraPageMeta, X as EldraProductOption, Y as EldraProductMediaLink, Z as EldraProductOptionValue, _ as EldraCmsEntryListEntry, _t as EldraContractProp, a as EldraCartTotals, at as EldraSearchResponse, b as EldraCmsGetOptions, c as EldraCatalogListProductsOptions, ct as EldraStockAvailabilityItem, d as EldraCheckoutHandoffOptions, dt as EldraContract, et as EldraRecoveredBasket, f as EldraClient, ft as EldraContractBody, g as EldraCmsEntryListDisplayMode, gt as EldraContractPaths, h as EldraCmsEntryList, ht as EldraContractPath, i as EldraCartItem, it as EldraSearchOptions, j as EldraFeatureCapabilities, k as EldraDiscountResult, l as EldraCategory, lt as RuntimeEnv, m as EldraCmsClient, mt as EldraContractMethod, n as EldraCart, nt as EldraRequestContext, o as EldraCatalogClient, ot as EldraStockAvailability, p as EldraClientOptions, pt as EldraContractItem, q as EldraProductList, r as EldraCartClient, rt as EldraRequestOptions, s as EldraCatalogGetProductOptions, st as EldraStockAvailabilityInput, t as EldraAddCartItemInput, tt as EldraRecoveredBasketItem, u as EldraCheckoutClient, ut as RuntimeValue, v as EldraCmsEntryListFilterCriterion, vt as EldraContractQuery, w as EldraCmsResolvedEntryList, x as EldraCmsListOptions, y as EldraCmsGetEntryByUniqueFieldOptions, yt as EldraContractResponse, z as EldraOrderReadOptions } from "./types-CPUs_QPj.js";
1
+ import { $ as EldraProductVariant, A as EldraFeature, B as EldraOrdersClient, C as EldraCmsResolveEntryListResponse, D as EldraCollectionListOptions, E as EldraCollectionList, F as EldraInventoryClient, G as EldraPaginated, H as EldraOrganizationFeature, I as EldraLocaleOptions, J as EldraProductListItem, K as EldraProductDetails, L as EldraOrder, M as EldraFeatureClient, N as EldraHttpClient, O as EldraCollectionProductsOptions, P as EldraHttpRequest, Q as EldraProductThumbnail, R as EldraOrderLine, S as EldraCmsResolveEntryListOptions, T as EldraCollection, U as EldraOrganizationOptions, V as EldraOrganizationDetails, W as EldraPageMeta, X as EldraProductOption, Y as EldraProductMediaLink, Z as EldraProductOptionValue, _ as EldraCmsEntryListEntry, _t as EldraContractProp, a as EldraCartTotals, at as EldraSearchResponse, b as EldraCmsGetOptions, c as EldraCatalogListProductsOptions, ct as EldraStockAvailabilityItem, d as EldraCheckoutHandoffOptions, dt as EldraContract, et as EldraRecoveredBasket, f as EldraClient, ft as EldraContractBody, g as EldraCmsEntryListDisplayMode, gt as EldraContractPaths, h as EldraCmsEntryList, ht as EldraContractPath, i as EldraCartItem, it as EldraSearchOptions, j as EldraFeatureCapabilities, k as EldraDiscountResult, l as EldraCategory, lt as RuntimeEnv, m as EldraCmsClient, mt as EldraContractMethod, n as EldraCart, nt as EldraRequestContext, o as EldraCatalogClient, ot as EldraStockAvailability, p as EldraClientOptions, pt as EldraContractItem, q as EldraProductList, r as EldraCartClient, rt as EldraRequestOptions, s as EldraCatalogGetProductOptions, st as EldraStockAvailabilityInput, t as EldraAddCartItemInput, tt as EldraRecoveredBasketItem, u as EldraCheckoutClient, ut as RuntimeValue, v as EldraCmsEntryListFilterCriterion, vt as EldraContractQuery, w as EldraCmsResolvedEntryList, x as EldraCmsListOptions, y as EldraCmsGetEntryByUniqueFieldOptions, yt as EldraContractResponse, z as EldraOrderReadOptions } from "./types-C0yabGuL.js";
2
2
  //#region src/client.d.ts
3
3
  export declare const DEFAULT_ELDRA_API_BASE_URL = "https://web.eldra.app/api";
4
+ export declare const DEFAULT_ELDRA_CHECKOUT_URL = "https://checkout.eldra.app";
4
5
  export declare class EldraHttpError extends Error {
5
6
  readonly status: number;
6
7
  readonly statusText: string;
7
8
  readonly body: unknown;
8
- /** The gateway's problem `code`, such as `INSUFFICIENT_STOCK`, when the body carried one. */
9
+ /** The problem's category, such as `NOT_FOUND` or `CONFLICT`, when the body carried one. */
9
10
  readonly code: string | undefined;
11
+ /** The problem's specific reason, such as `CART_NOT_FOUND`, when the body carried one. */
12
+ readonly errorId: string | undefined;
10
13
  constructor(response: Response, body: unknown);
11
14
  }
12
15
  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 getEldraClient, i as createEldraClient, n as DEFAULT_ELDRA_CHECKOUT_URL, o as initEldraClient, r as EldraHttpError, t as DEFAULT_ELDRA_API_BASE_URL } from "./client-DEKwEhpg.js";
2
2
  //#region src/storage.ts
3
3
  const DEFAULT_CART_KEY = "eldra.cartId";
4
4
  const DEFAULT_ORDER_TOKEN_PREFIX = "eldra.orderAccessToken.";
@@ -47,4 +47,4 @@ function createOrderAccessTokens(options = {}) {
47
47
  };
48
48
  }
49
49
  //#endregion
50
- export { DEFAULT_ELDRA_API_BASE_URL, EldraHttpError, createCartSession, createEldraClient, createOrderAccessTokens, getEldraClient, initEldraClient };
50
+ export { DEFAULT_ELDRA_API_BASE_URL, DEFAULT_ELDRA_CHECKOUT_URL, EldraHttpError, createCartSession, createEldraClient, createOrderAccessTokens, getEldraClient, initEldraClient };
@@ -63,7 +63,10 @@ interface EldraClientOptions {
63
63
  headers?: RuntimeValue<HeadersInit>;
64
64
  httpClient?: EldraHttpClient;
65
65
  fetch?: typeof fetch;
66
- /** Origin of the hosted checkout app, used by `checkout.handoffUrl`. */
66
+ /**
67
+ * Origin of the hosted checkout app, used by `checkout.handoffUrl`. Defaults to
68
+ * `https://checkout.eldra.app` when the API base URL is the default.
69
+ */
67
70
  checkoutUrl?: RuntimeValue<string>;
68
71
  }
69
72
  interface EldraPaginationOptions {
package/dist/vite.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { lt as RuntimeEnv, ut as RuntimeValue } from "./types-CPUs_QPj.js";
1
+ import { lt as RuntimeEnv, ut as RuntimeValue } from "./types-C0yabGuL.js";
2
2
  import { Plugin } from "vite";
3
3
  //#region src/vite-plugin.d.ts
4
4
  export interface EldraVitePluginOptions {
package/dist/vite.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./client-CfkktZmj.js";
1
+ import "./client-DEKwEhpg.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.4",
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",