@eldrajs/sdk 0.2.3 → 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,11 @@ 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
+
12
17
  - `EldraHttpError.errorId` carries the problem's specific reason, such as `CART_NOT_FOUND` or
13
18
  `CART_INSUFFICIENT_STOCK`. The docs told you to branch on `code` for these, but the gateway puts
14
19
  them in `errorId`; `code` is only the category (`NOT_FOUND`, `CONFLICT`) and is unchanged.
@@ -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",
@@ -207,8 +215,8 @@ function createEldraClient(options) {
207
215
  })
208
216
  },
209
217
  checkout: { handoffUrl: (handoff) => {
210
- const checkoutUrl = handoff.checkoutUrl ?? resolveRuntimeValue(options.checkoutUrl);
211
- 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.`);
212
220
  const orgId = handoff.orgId ?? resolveOrgId(options);
213
221
  if (!orgId) throw new Error("Missing Web Studio organization ID.");
214
222
  const url = new URL(`${checkoutUrl.replace(/\/$/, "")}/checkout/${encodeURIComponent(orgId)}/${encodeURIComponent(handoff.cartId)}`);
@@ -296,6 +304,9 @@ function readResponseBody(response) {
296
304
  function resolveApiBaseUrl(options) {
297
305
  return resolveRuntimeValue(options.apiBaseUrl) ?? readFirstEnvValue(resolveRuntimeValue(options.env), apiBaseUrlEnvKeys) ?? "https://web.eldra.app/api";
298
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
+ }
299
310
  function resolveOrgId(options) {
300
311
  return resolveRuntimeValue(options.orgId) ?? readFirstEnvValue(resolveRuntimeValue(options.env), orgIdEnvKeys);
301
312
  }
@@ -333,4 +344,4 @@ function isRawBody(body) {
333
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;
334
345
  }
335
346
  //#endregion
336
- 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,6 +1,7 @@
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;
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-bg68WrsC.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-bg68WrsC.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.3",
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",