@eldrajs/sdk 0.2.7 → 0.2.8

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/dist/index.d.ts CHANGED
@@ -1,14 +1,20 @@
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";
1
+ import { $ as EldraProductListItem, A as EldraFeature, B as EldraOrdersClient, C as EldraCmsResolveEntryListResponse, Ct as EldraContractProp, D as EldraCollectionListOptions, E as EldraCollectionList, F as EldraInventoryClient, G as EldraOrganizationOptions, H as EldraOrganizationDetails, I as EldraLocaleOptions, J as EldraPlatformClient, K as EldraPageMeta, L as EldraOrder, M as EldraFeatureClient, N as EldraHttpClient, O as EldraCollectionProductsOptions, P as EldraHttpRequest, Q as EldraProductList, R as EldraOrderLine, S as EldraCmsResolveEntryListOptions, St as EldraContractPaths, T as EldraCollection, Tt as EldraContractResponse, U as EldraOrganizationFeature, V as EldraOrganizationCommerce, W as EldraOrganizationLocales, X as EldraPlatformReadOptions, Y as EldraPlatformConfig, Z as EldraProductDetails, _ as EldraCmsEntryListEntry, _t as EldraContract, a as EldraCartTotals, at as EldraRecoveredBasket, b as EldraCmsGetOptions, bt as EldraContractMethod, c as EldraCatalogListProductsOptions, ct as EldraRequestOptions, d as EldraCheckoutUrlOptions, dt as EldraSearchResponse, et as EldraProductMediaLink, f as EldraClient, ft as EldraStockAvailability, g as EldraCmsEntryListDisplayMode, gt as RuntimeValue, h as EldraCmsEntryList, ht as RuntimeEnv, i as EldraCartItem, it as EldraProductVariant, j as EldraFeatureCapabilities, k as EldraDiscountResult, l as EldraCategory, lt as EldraRetryOptions, m as EldraCmsClient, mt as EldraStockAvailabilityItem, n as EldraCart, nt as EldraProductOptionValue, o as EldraCatalogClient, ot as EldraRecoveredBasketItem, p as EldraClientOptions, pt as EldraStockAvailabilityInput, q as EldraPaginated, r as EldraCartClient, rt as EldraProductThumbnail, s as EldraCatalogGetProductOptions, st as EldraRequestContext, t as EldraAddCartItemInput, tt as EldraProductOption, u as EldraCheckoutClient, ut as EldraSearchOptions, v as EldraCmsEntryListFilterCriterion, vt as EldraContractBody, w as EldraCmsResolvedEntryList, wt as EldraContractQuery, x as EldraCmsListOptions, xt as EldraContractPath, y as EldraCmsGetEntryByUniqueFieldOptions, yt as EldraContractItem, z as EldraOrderReadOptions } from "./types-B40H01uK.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";
5
4
  export declare class EldraHttpError extends Error {
6
5
  readonly status: number;
7
6
  readonly statusText: string;
8
7
  readonly body: unknown;
9
- /** The problem's category, such as `NOT_FOUND` or `CONFLICT`, when the body carried one. */
8
+ /** The gateway's problem `code`, such as `CONFLICT`, when the body carried one. */
10
9
  readonly code: string | undefined;
11
- /** The problem's specific reason, such as `CART_NOT_FOUND`, when the body carried one. */
10
+ /**
11
+ * The gateway's problem `errorId` — the stable identifier for *which* failure this is, such as
12
+ * `CART_INSUFFICIENT_STOCK`. `code` names the class of failure (`CONFLICT`, `VALIDATION`) and
13
+ * several unrelated refusals share one, so a caller that reacts to a specific cause has to read
14
+ * this: a 409 on an add is `{ code: 'CONFLICT', errorId: 'CART_INSUFFICIENT_STOCK' }`, and
15
+ * telling it apart from any other conflict is what lets a storefront say "out of stock" rather
16
+ * than "something went wrong".
17
+ */
12
18
  readonly errorId: string | undefined;
13
19
  constructor(response: Response, body: unknown);
14
20
  }
@@ -143,4 +149,4 @@ interface EldraResponsiveImage {
143
149
  */
144
150
  export declare function responsiveImage(source: EldraImageSource, options: EldraResponsiveImageOptions): EldraResponsiveImage | undefined;
145
151
  //#endregion
146
- export type { EldraAddCartItemInput, EldraCart, EldraCartClient, EldraCartItem, EldraCartSession, EldraCartSessionOptions, EldraCartTotals, EldraCatalogClient, EldraCatalogGetProductOptions, EldraCatalogListProductsOptions, EldraCategory, EldraCheckoutClient, EldraCheckoutHandoffOptions, EldraClient, EldraClientOptions, EldraCmsClient, EldraCmsEntryList, EldraCmsEntryListDisplayMode, EldraCmsEntryListEntry, EldraCmsEntryListFilterCriterion, EldraCmsGetEntryByUniqueFieldOptions, EldraCmsGetOptions, EldraCmsListOptions, EldraCmsResolveEntryListOptions, EldraCmsResolveEntryListResponse, EldraCmsResolvedEntryList, EldraCollection, EldraCollectionList, EldraCollectionListOptions, EldraCollectionProductsOptions, EldraContract, EldraContractBody, EldraContractItem, EldraContractMethod, EldraContractPath, EldraContractPaths, EldraContractProp, EldraContractQuery, EldraContractResponse, EldraDiscountResult, EldraFeature, EldraFeatureCapabilities, EldraFeatureClient, EldraHttpClient, EldraHttpRequest, EldraImageSource, EldraImageSrcsetOptions, EldraImageVariant, EldraInventoryClient, EldraKeyValueStorage, EldraLocaleOptions, EldraOrder, EldraOrderAccessTokenOptions, EldraOrderAccessTokens, EldraOrderLine, EldraOrderReadOptions, EldraOrdersClient, EldraOrganizationDetails, EldraOrganizationFeature, EldraOrganizationOptions, EldraPageMeta, EldraPaginated, EldraProductDetails, EldraProductList, EldraProductListItem, EldraProductMediaLink, EldraProductOption, EldraProductOptionValue, EldraProductThumbnail, EldraProductVariant, EldraRecoveredBasket, EldraRecoveredBasketItem, EldraRequestContext, EldraRequestOptions, EldraResponsiveImage, EldraResponsiveImageOptions, EldraSearchOptions, EldraSearchResponse, EldraSizedImageVariant, EldraStockAvailability, EldraStockAvailabilityInput, EldraStockAvailabilityItem, EldraTrackerScript, EldraTrackerScriptOptions, RuntimeEnv, RuntimeValue };
152
+ export type { EldraAddCartItemInput, EldraCart, EldraCartClient, EldraCartItem, EldraCartSession, EldraCartSessionOptions, EldraCartTotals, EldraCatalogClient, EldraCatalogGetProductOptions, EldraCatalogListProductsOptions, EldraCategory, EldraCheckoutClient, EldraCheckoutUrlOptions, EldraClient, EldraClientOptions, EldraCmsClient, EldraCmsEntryList, EldraCmsEntryListDisplayMode, EldraCmsEntryListEntry, EldraCmsEntryListFilterCriterion, EldraCmsGetEntryByUniqueFieldOptions, EldraCmsGetOptions, EldraCmsListOptions, EldraCmsResolveEntryListOptions, EldraCmsResolveEntryListResponse, EldraCmsResolvedEntryList, EldraCollection, EldraCollectionList, EldraCollectionListOptions, EldraCollectionProductsOptions, EldraContract, EldraContractBody, EldraContractItem, EldraContractMethod, EldraContractPath, EldraContractPaths, EldraContractProp, EldraContractQuery, EldraContractResponse, EldraDiscountResult, EldraFeature, EldraFeatureCapabilities, EldraFeatureClient, EldraHttpClient, EldraHttpRequest, EldraImageSource, EldraImageSrcsetOptions, EldraImageVariant, EldraInventoryClient, EldraKeyValueStorage, EldraLocaleOptions, EldraOrder, EldraOrderAccessTokenOptions, EldraOrderAccessTokens, EldraOrderLine, EldraOrderReadOptions, EldraOrdersClient, EldraOrganizationCommerce, EldraOrganizationDetails, EldraOrganizationFeature, EldraOrganizationLocales, EldraOrganizationOptions, EldraPageMeta, EldraPaginated, EldraPlatformClient, EldraPlatformConfig, EldraPlatformReadOptions, EldraProductDetails, EldraProductList, EldraProductListItem, EldraProductMediaLink, EldraProductOption, EldraProductOptionValue, EldraProductThumbnail, EldraProductVariant, EldraRecoveredBasket, EldraRecoveredBasketItem, EldraRequestContext, EldraRequestOptions, EldraResponsiveImage, EldraResponsiveImageOptions, EldraRetryOptions, EldraSearchOptions, EldraSearchResponse, EldraSizedImageVariant, EldraStockAvailability, EldraStockAvailabilityInput, EldraStockAvailabilityItem, EldraTrackerScript, EldraTrackerScriptOptions, RuntimeEnv, RuntimeValue };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as getEldraClient, c as resolveOrgId, i as createEldraClient, n as DEFAULT_ELDRA_CHECKOUT_URL, o as initEldraClient, r as EldraHttpError, s as resolveApiBaseUrl, t as DEFAULT_ELDRA_API_BASE_URL } from "./client-DVn7qqKo.js";
1
+ import { a as initEldraClient, i as getEldraClient, n as EldraHttpError, o as resolveApiBaseUrl, r as createEldraClient, s as resolveOrgId, t as DEFAULT_ELDRA_API_BASE_URL } from "./client-t66vCzJf.js";
2
2
  //#region src/storage.ts
3
3
  const DEFAULT_CART_KEY = "eldra.cartId";
4
4
  const DEFAULT_ORDER_TOKEN_PREFIX = "eldra.orderAccessToken.";
@@ -161,4 +161,4 @@ function responsiveImage(source, options) {
161
161
  return image;
162
162
  }
163
163
  //#endregion
164
- export { DEFAULT_ELDRA_API_BASE_URL, DEFAULT_ELDRA_CHECKOUT_URL, ELDRA_IMAGE_VARIANT_WIDTHS, EldraHttpError, analyticsTrackerScript, createCartSession, createEldraClient, createOrderAccessTokens, getEldraClient, imageSrcset, imageUrl, imageVariantFor, initEldraClient, isEldraImage, responsiveImage };
164
+ export { DEFAULT_ELDRA_API_BASE_URL, ELDRA_IMAGE_VARIANT_WIDTHS, EldraHttpError, analyticsTrackerScript, createCartSession, createEldraClient, createOrderAccessTokens, getEldraClient, imageSrcset, imageUrl, imageVariantFor, initEldraClient, isEldraImage, responsiveImage };
@@ -54,6 +54,27 @@ interface EldraHttpRequest {
54
54
  signal?: AbortSignal;
55
55
  }
56
56
  type EldraHttpClient = <T = unknown>(request: EldraHttpRequest) => Promise<T>;
57
+ /**
58
+ * How hard the client tries again when the gateway says "not now" — a `429`
59
+ * from its rate limit, a `503` while it restarts, or a dropped connection.
60
+ * Only idempotent requests are ever repeated; see `retry.ts` for the rules.
61
+ * Ignored when a consumer supplies its own `httpClient`: the retry belongs to
62
+ * the transport, and a replaced transport is the consumer's own.
63
+ */
64
+ interface EldraRetryOptions {
65
+ /**
66
+ * Total attempts per request, the first included. Default 5. `0` or `1`
67
+ * disables retrying: one request, no waiting.
68
+ */
69
+ attempts?: number;
70
+ /** First backoff window, doubling per attempt. Default 250 ms. */
71
+ baseDelayMs?: number;
72
+ /**
73
+ * Ceiling on the computed backoff. Default 5000 ms. A `Retry-After` the
74
+ * gateway sends is honoured beyond it (up to a minute).
75
+ */
76
+ maxDelayMs?: number;
77
+ }
57
78
  interface EldraClientOptions {
58
79
  apiBaseUrl?: RuntimeValue<string>;
59
80
  orgId?: RuntimeValue<string>;
@@ -63,11 +84,8 @@ interface EldraClientOptions {
63
84
  headers?: RuntimeValue<HeadersInit>;
64
85
  httpClient?: EldraHttpClient;
65
86
  fetch?: typeof fetch;
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
- */
70
- checkoutUrl?: RuntimeValue<string>;
87
+ /** See `EldraRetryOptions`; defaults documented there. */
88
+ retry?: EldraRetryOptions;
71
89
  }
72
90
  interface EldraPaginationOptions {
73
91
  page?: number;
@@ -147,11 +165,53 @@ interface EldraOrganizationFeature {
147
165
  feature: EldraFeature | string;
148
166
  enabled: boolean;
149
167
  }
168
+ /**
169
+ * The store's commerce settings, as `GET /organization/v1/{orgId}` publishes them under
170
+ * `commerce` (the gateway's `dto_OrganizationCommerce`). **Absent on a store that has not
171
+ * configured commerce**, which is why `features.getCommerce()` answers `null` rather than a
172
+ * default: a storefront that cannot know what it sells in has to say so, not guess a currency.
173
+ *
174
+ * Written by hand for the same reason `EldraOrganizationDetails` below it is: the organisation
175
+ * read backs every `features.*` method, so its shape has to resolve without the Vite plugin's
176
+ * generated `contract.ts` augmentation.
177
+ */
178
+ interface EldraOrganizationCommerce {
179
+ /** ISO 4217 code every catalog price is quoted in, e.g. `ISK`. */
180
+ currency: string;
181
+ /** Prices already contain VAT; a storefront shows them as they are. */
182
+ taxInclusivePricing: boolean;
183
+ /** Fraction, e.g. `0.24` — applies to shipping and to products without their own rate. */
184
+ defaultTaxRate: number;
185
+ }
186
+ /**
187
+ * The organisation's configured **content** locales, as the public organisation read publishes
188
+ * them: which locale a document's untagged content belongs to, and every locale its fields may
189
+ * carry a value for.
190
+ *
191
+ * Hand-written for the same reason `EldraOrganizationCommerce` above it is — the organisation read
192
+ * backs every `features.*` method and has to resolve without the Vite plugin's generated
193
+ * `contract.ts`.
194
+ *
195
+ * `supported` is default-first and always contains `default`. An organisation that has configured
196
+ * none publishes no `locales` at all, which `features.getLocales()` reports as `null`: a consumer
197
+ * can then behave exactly as it did before locales existed (one unprefixed site, the gateway's own
198
+ * default locale on every read) rather than inventing a tag nobody chose.
199
+ */
200
+ interface EldraOrganizationLocales {
201
+ /** The locale served unprefixed, e.g. `en-US`. */
202
+ default: string;
203
+ /** Every configured locale, `default` first, e.g. `["en-US", "is-IS"]`. */
204
+ supported: string[];
205
+ }
150
206
  interface EldraOrganizationDetails {
151
207
  id: string;
152
208
  name: string;
153
209
  description?: string;
154
210
  features?: EldraOrganizationFeature[];
211
+ /** See `EldraOrganizationCommerce`: absent, or `null`, until the store configures commerce. */
212
+ commerce?: EldraOrganizationCommerce | null;
213
+ /** See `EldraOrganizationLocales`: absent, or `null`, until the organisation configures any. */
214
+ locales?: EldraOrganizationLocales | null;
155
215
  paymentProviders?: unknown;
156
216
  createdAt?: string;
157
217
  updatedAt?: string;
@@ -194,6 +254,24 @@ interface EldraFeatureClient {
194
254
  list(options?: EldraOrganizationOptions, context?: EldraRequestContext): Promise<EldraOrganizationFeature[]>;
195
255
  isEnabled(feature: EldraFeature, options?: EldraOrganizationOptions, context?: EldraRequestContext): Promise<boolean>;
196
256
  getCapabilities(options?: EldraOrganizationOptions, context?: EldraRequestContext): Promise<EldraFeatureCapabilities>;
257
+ /**
258
+ * What the store sells in: the organisation's own `commerce` settings, or `null` when it
259
+ * publishes none. Reads the same organisation document the other `features` methods read, so a
260
+ * caller that already has one can take `commerce` off it instead of calling this.
261
+ */
262
+ getCommerce(options?: EldraOrganizationOptions, context?: EldraRequestContext): Promise<EldraOrganizationCommerce | null>;
263
+ /**
264
+ * Which content locales the organisation publishes: `{ default, supported }`, or `null` when it
265
+ * has configured none. Reads the same organisation document the other `features` methods read,
266
+ * so a caller that already has one can take `locales` off it instead of calling this.
267
+ *
268
+ * The answer is validated rather than passed through: a record without a non-empty string
269
+ * `default`, or whose `supported` is not an array of non-empty strings, is reported as `null` —
270
+ * the same answer as "none configured". A consumer uses this to decide which locale lives at
271
+ * which URL, and half an answer there would route real visitors to paths no content exists at.
272
+ * `default` is always first in `supported`, and duplicates are collapsed.
273
+ */
274
+ getLocales(options?: EldraOrganizationOptions, context?: EldraRequestContext): Promise<EldraOrganizationLocales | null>;
197
275
  }
198
276
  interface EldraClient {
199
277
  request<T = unknown>(options: EldraRequestOptions): Promise<T>;
@@ -202,6 +280,7 @@ interface EldraClient {
202
280
  features: EldraFeatureClient;
203
281
  cart: EldraCartClient;
204
282
  orders: EldraOrdersClient;
283
+ platform: EldraPlatformClient;
205
284
  checkout: EldraCheckoutClient;
206
285
  inventory: EldraInventoryClient;
207
286
  }
@@ -235,12 +314,36 @@ interface EldraOrderReadOptions {
235
314
  type EldraStockAvailabilityInput = EldraContractItem<EldraContractProp<EldraContractBody<'/inventory/v1/stock/availability', 'post'>, 'items'>>;
236
315
  type EldraStockAvailability = EldraContractResponse<'/inventory/v1/stock/availability', 'post'>;
237
316
  type EldraStockAvailabilityItem = EldraContractItem<EldraContractProp<EldraStockAvailability, 'items'>>;
238
- interface EldraCheckoutHandoffOptions {
317
+ interface EldraCheckoutUrlOptions {
239
318
  cartId: string;
240
319
  locale?: string;
241
- checkoutUrl?: string;
320
+ /** Overrides the client's own `orgId` — a storefront serving several organisations. */
242
321
  orgId?: string;
243
322
  }
323
+ /**
324
+ * Mirrors `GET /platform/v1/config` on the web gateway: the public, organisation-independent read
325
+ * (it takes no `X-Org-Id`, and the SDK sends none, so it answers the same thing whatever the
326
+ * browser's origin;
327
+ * `Cache-Control: public, max-age=300`) that tells a storefront where the platform hosts checkout.
328
+ * Written by hand because the generated contract does not carry the path yet; it becomes
329
+ * `EldraContractResponse<'/platform/v1/config', 'get'>` once the contract is regenerated.
330
+ */
331
+ interface EldraPlatformConfig {
332
+ /** Origin of the platform-hosted checkout app; `null` when the platform publishes none. */
333
+ checkoutUrl: string | null;
334
+ }
335
+ /**
336
+ * The only per-call option the platform reads take. There is no request context to pass: the route
337
+ * carries no organisation, no preview token and no auth, and the answer is shared by every caller of
338
+ * one client — so headers or an `orgId` per call could not mean anything.
339
+ */
340
+ interface EldraPlatformReadOptions {
341
+ /**
342
+ * Abandons **this** caller's wait. The read is shared, so it is not cancelled: aborting rejects
343
+ * the promise you are holding and leaves the request to whoever else is waiting on it.
344
+ */
345
+ signal?: AbortSignal;
346
+ }
244
347
  interface EldraCartClient {
245
348
  addItem(input: EldraAddCartItemInput, context?: EldraRequestContext): Promise<EldraCart>;
246
349
  get(cartId: string, options?: EldraLocaleOptions, context?: EldraRequestContext): Promise<EldraCart>;
@@ -256,11 +359,25 @@ interface EldraOrdersClient {
256
359
  recover(token: string, context?: EldraRequestContext): Promise<EldraRecoveredBasket>;
257
360
  }
258
361
  interface EldraCheckoutClient {
259
- /** Where a storefront sends the customer: `{checkoutUrl}/checkout/{orgId}/{cartId}`. */
260
- handoffUrl(options: EldraCheckoutHandoffOptions): string;
362
+ /**
363
+ * Where a storefront sends the customer: `{checkoutUrl}/checkout/{orgId}/{cartId}`, with the
364
+ * locale as `lang`. The base URL is the platform's — read from `platform.config()`, cached per
365
+ * client — so this is async, and it rejects when the platform published no checkout URL, when the
366
+ * read failed (with that failure as the error's `cause`), and when what the platform published is
367
+ * not an absolute `http(s)` URL. Each refusal says which it was.
368
+ */
369
+ url(options: EldraCheckoutUrlOptions, readOptions?: EldraPlatformReadOptions): Promise<string>;
370
+ }
371
+ interface EldraPlatformClient {
372
+ /**
373
+ * The platform's public configuration. Read once per client instance: concurrent callers share
374
+ * the one in-flight request — cancellable by none of them, see `EldraPlatformReadOptions` — and a
375
+ * read that failed is retried by the next call.
376
+ */
377
+ config(readOptions?: EldraPlatformReadOptions): Promise<EldraPlatformConfig>;
261
378
  }
262
379
  interface EldraInventoryClient {
263
380
  availability(items: EldraStockAvailabilityInput[], context?: EldraRequestContext): Promise<EldraStockAvailability>;
264
381
  }
265
382
  //#endregion
266
- export { EldraProductVariant as $, EldraFeature as A, EldraOrdersClient as B, EldraCmsResolveEntryListResponse as C, EldraCollectionListOptions as D, EldraCollectionList as E, EldraInventoryClient as F, EldraPaginated as G, EldraOrganizationFeature as H, EldraLocaleOptions as I, EldraProductListItem as J, EldraProductDetails as K, EldraOrder as L, EldraFeatureClient as M, EldraHttpClient as N, EldraCollectionProductsOptions as O, EldraHttpRequest as P, EldraProductThumbnail as Q, EldraOrderLine as R, EldraCmsResolveEntryListOptions as S, EldraCollection as T, EldraOrganizationOptions as U, EldraOrganizationDetails as V, EldraPageMeta as W, EldraProductOption as X, EldraProductMediaLink as Y, EldraProductOptionValue as Z, EldraCmsEntryListEntry as _, EldraContractProp as _t, EldraCartTotals as a, EldraSearchResponse as at, EldraCmsGetOptions as b, EldraCatalogListProductsOptions as c, EldraStockAvailabilityItem as ct, EldraCheckoutHandoffOptions as d, EldraContract as dt, EldraRecoveredBasket as et, EldraClient as f, EldraContractBody as ft, EldraCmsEntryListDisplayMode as g, EldraContractPaths as gt, EldraCmsEntryList as h, EldraContractPath as ht, EldraCartItem as i, EldraSearchOptions as it, EldraFeatureCapabilities as j, EldraDiscountResult as k, EldraCategory as l, RuntimeEnv as lt, EldraCmsClient as m, EldraContractMethod as mt, EldraCart as n, EldraRequestContext as nt, EldraCatalogClient as o, EldraStockAvailability as ot, EldraClientOptions as p, EldraContractItem as pt, EldraProductList as q, EldraCartClient as r, EldraRequestOptions as rt, EldraCatalogGetProductOptions as s, EldraStockAvailabilityInput as st, EldraAddCartItemInput as t, EldraRecoveredBasketItem as tt, EldraCheckoutClient as u, RuntimeValue as ut, EldraCmsEntryListFilterCriterion as v, EldraContractQuery as vt, EldraCmsResolvedEntryList as w, EldraCmsListOptions as x, EldraCmsGetEntryByUniqueFieldOptions as y, EldraContractResponse as yt, EldraOrderReadOptions as z };
383
+ export { EldraProductListItem as $, EldraFeature as A, EldraOrdersClient as B, EldraCmsResolveEntryListResponse as C, EldraContractProp as Ct, EldraCollectionListOptions as D, EldraCollectionList as E, EldraInventoryClient as F, EldraOrganizationOptions as G, EldraOrganizationDetails as H, EldraLocaleOptions as I, EldraPlatformClient as J, EldraPageMeta as K, EldraOrder as L, EldraFeatureClient as M, EldraHttpClient as N, EldraCollectionProductsOptions as O, EldraHttpRequest as P, EldraProductList as Q, EldraOrderLine as R, EldraCmsResolveEntryListOptions as S, EldraContractPaths as St, EldraCollection as T, EldraContractResponse as Tt, EldraOrganizationFeature as U, EldraOrganizationCommerce as V, EldraOrganizationLocales as W, EldraPlatformReadOptions as X, EldraPlatformConfig as Y, EldraProductDetails as Z, EldraCmsEntryListEntry as _, EldraContract as _t, EldraCartTotals as a, EldraRecoveredBasket as at, EldraCmsGetOptions as b, EldraContractMethod as bt, EldraCatalogListProductsOptions as c, EldraRequestOptions as ct, EldraCheckoutUrlOptions as d, EldraSearchResponse as dt, EldraProductMediaLink as et, EldraClient as f, EldraStockAvailability as ft, EldraCmsEntryListDisplayMode as g, RuntimeValue as gt, EldraCmsEntryList as h, RuntimeEnv as ht, EldraCartItem as i, EldraProductVariant as it, EldraFeatureCapabilities as j, EldraDiscountResult as k, EldraCategory as l, EldraRetryOptions as lt, EldraCmsClient as m, EldraStockAvailabilityItem as mt, EldraCart as n, EldraProductOptionValue as nt, EldraCatalogClient as o, EldraRecoveredBasketItem as ot, EldraClientOptions as p, EldraStockAvailabilityInput as pt, EldraPaginated as q, EldraCartClient as r, EldraProductThumbnail as rt, EldraCatalogGetProductOptions as s, EldraRequestContext as st, EldraAddCartItemInput as t, EldraProductOption as tt, EldraCheckoutClient as u, EldraSearchOptions as ut, EldraCmsEntryListFilterCriterion as v, EldraContractBody as vt, EldraCmsResolvedEntryList as w, EldraContractQuery as wt, EldraCmsListOptions as x, EldraContractPath as xt, EldraCmsGetEntryByUniqueFieldOptions as y, EldraContractItem as yt, EldraOrderReadOptions as z };
package/dist/vite.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { lt as RuntimeEnv, ut as RuntimeValue } from "./types-C0yabGuL.js";
1
+ import { gt as RuntimeValue, ht as RuntimeEnv } from "./types-B40H01uK.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-DVn7qqKo.js";
1
+ import "./client-t66vCzJf.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.7",
3
+ "version": "0.2.8",
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",
@@ -1,347 +0,0 @@
1
- //#region src/client.ts
2
- const apiBaseUrlEnvKeys = [
3
- "ELDRA_API_BASE_URL",
4
- "VITE_ELDRA_API_BASE_URL",
5
- "NEXT_PUBLIC_ELDRA_API_BASE_URL",
6
- "NUXT_PUBLIC_ELDRA_API_BASE_URL",
7
- "PUBLIC_ELDRA_API_BASE_URL"
8
- ];
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";
18
- const orgIdEnvKeys = [
19
- "ELDRA_ORG_ID",
20
- "VITE_ELDRA_ORG_ID",
21
- "NEXT_PUBLIC_ELDRA_ORG_ID",
22
- "NUXT_PUBLIC_ELDRA_ORG_ID",
23
- "PUBLIC_ELDRA_ORG_ID"
24
- ];
25
- let defaultClient;
26
- var EldraHttpError = class extends Error {
27
- status;
28
- statusText;
29
- body;
30
- /** The problem's category, such as `NOT_FOUND` or `CONFLICT`, when the body carried one. */
31
- code;
32
- /** The problem's specific reason, such as `CART_NOT_FOUND`, when the body carried one. */
33
- errorId;
34
- constructor(response, body) {
35
- super(`Web Studio request failed with ${response.status} ${response.statusText}`);
36
- this.name = "EldraHttpError";
37
- this.status = response.status;
38
- this.statusText = response.statusText;
39
- this.body = body;
40
- this.code = problemField(body, "code");
41
- this.errorId = problemField(body, "errorId");
42
- }
43
- };
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;
48
- }
49
- }
50
- function initEldraClient(options) {
51
- defaultClient = createEldraClient(options);
52
- return defaultClient;
53
- }
54
- function getEldraClient() {
55
- if (!defaultClient) throw new Error("Eldra client has not been initialized. Call initEldraClient() first.");
56
- return defaultClient;
57
- }
58
- function createEldraClient(options) {
59
- const httpClient = options.httpClient ?? createFetchHttpClient(options.fetch);
60
- const request = (requestOptions) => httpClient(createHttpRequest(options, requestOptions));
61
- const getOrganization = (organizationOptions, context) => {
62
- const orgId = resolveRequestOrgId(options, organizationOptions, context);
63
- return request({
64
- ...context,
65
- orgId,
66
- path: `/organization/v1/${encodeURIComponent(orgId)}`
67
- });
68
- };
69
- const getOrganizationFeatureMap = async (organizationOptions, context) => {
70
- return mapOrganizationFeatures((await getOrganization(organizationOptions, context)).features ?? []);
71
- };
72
- return {
73
- request,
74
- cms: {
75
- list: (schemaApiId, listOptions, context) => request({
76
- ...context,
77
- path: `/cms/v1/schema/${encodeURIComponent(schemaApiId)}/entry`,
78
- query: listOptions
79
- }),
80
- get: (schemaApiId, entryId, getOptions, context) => request({
81
- ...context,
82
- path: `/cms/v1/schema/${encodeURIComponent(schemaApiId)}/entry/${encodeURIComponent(entryId)}`,
83
- query: getOptions
84
- }),
85
- getEntryByUniqueField: (schemaApiId, fieldId, entryIdentifier, getOptions, context) => request({
86
- ...context,
87
- path: `/cms/v1/schema/${encodeURIComponent(schemaApiId)}/entry/unique/${encodeURIComponent(fieldId)}/${encodeURIComponent(entryIdentifier)}`,
88
- query: getOptions
89
- }),
90
- resolveEntryList: (entryList, resolveOptions, context) => request({
91
- ...context,
92
- method: "POST",
93
- path: "/cms/v1/entry-list/resolve",
94
- query: resolveEntryListQuery(resolveOptions),
95
- body: resolveEntryListBody(entryList)
96
- })
97
- },
98
- features: {
99
- getOrganization,
100
- list: async (organizationOptions, context) => {
101
- return (await getOrganization(organizationOptions, context)).features ?? [];
102
- },
103
- isEnabled: async (feature, organizationOptions, context) => {
104
- return (await getOrganizationFeatureMap(organizationOptions, context))[feature] === true;
105
- },
106
- getCapabilities: async (organizationOptions, context) => {
107
- const features = await getOrganizationFeatureMap(organizationOptions, context);
108
- const cms = features.CMS === true;
109
- const ecommerce = features.ECOMMERCE === true;
110
- return {
111
- cms,
112
- catalog: ecommerce,
113
- products: ecommerce,
114
- ecommerce,
115
- features
116
- };
117
- }
118
- },
119
- catalog: {
120
- listProducts: (listOptions, context) => request({
121
- ...context,
122
- path: "/catalog/v1/products/list",
123
- query: listOptions
124
- }),
125
- getProduct: (productId, getOptions, context) => request({
126
- ...context,
127
- path: `/catalog/v1/products/${encodeURIComponent(productId)}`,
128
- query: getOptions
129
- }),
130
- listCategories: async (localeOptions, context) => await request({
131
- ...context,
132
- path: "/catalog/v1/categories",
133
- query: localeOptions
134
- }) ?? [],
135
- listCollections: (listOptions, context) => request({
136
- ...context,
137
- path: "/catalog/v1/collections",
138
- query: listOptions
139
- }),
140
- getCollection: (slug, localeOptions, context) => request({
141
- ...context,
142
- path: `/catalog/v1/collections/${encodeURIComponent(slug)}`,
143
- query: localeOptions
144
- }),
145
- listCollectionProducts: (slug, listOptions, context) => request({
146
- ...context,
147
- path: `/catalog/v1/collections/${encodeURIComponent(slug)}/products`,
148
- query: listOptions
149
- }),
150
- search: (query, searchOptions, context) => request({
151
- ...context,
152
- path: "/search/v1",
153
- query: {
154
- ...searchOptions,
155
- q: query
156
- }
157
- })
158
- },
159
- cart: {
160
- addItem: (input, context) => request({
161
- ...context,
162
- method: "POST",
163
- path: "/shopping-cart/v1/cart/items",
164
- body: input
165
- }),
166
- get: (cartId, localeOptions, context) => request({
167
- ...context,
168
- path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}`,
169
- query: localeOptions
170
- }),
171
- updateItem: (cartId, itemId, input, context) => request({
172
- ...context,
173
- method: "PATCH",
174
- path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}/items/${encodeURIComponent(itemId)}`,
175
- body: input
176
- }),
177
- removeItem: (cartId, itemId, context) => request({
178
- ...context,
179
- method: "DELETE",
180
- path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}/items/${encodeURIComponent(itemId)}`
181
- }),
182
- applyDiscount: async (cartId, code, localeOptions, context) => {
183
- const trimmed = code.trim();
184
- const cart = await request({
185
- ...context,
186
- method: "PUT",
187
- path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}/discount`,
188
- query: localeOptions,
189
- body: { code: trimmed }
190
- });
191
- const discountCode = cart.discountCode;
192
- return {
193
- cart,
194
- applied: typeof discountCode === "string" && discountCode.trim().toUpperCase() === trimmed.toUpperCase()
195
- };
196
- },
197
- removeDiscount: (cartId, localeOptions, context) => request({
198
- ...context,
199
- method: "DELETE",
200
- path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}/discount`,
201
- query: localeOptions
202
- })
203
- },
204
- orders: {
205
- get: (orderId, readOptions, context) => request({
206
- ...context,
207
- path: `/order/v1/${encodeURIComponent(orderId)}`,
208
- headers: mergeHeaders(context?.headers, readOptions?.accessToken ? { "X-Order-Token": readOptions.accessToken } : void 0)
209
- }),
210
- recover: (token, context) => request({
211
- ...context,
212
- method: "POST",
213
- path: "/order/v1/recover",
214
- body: { token: token.trim() }
215
- })
216
- },
217
- checkout: { handoffUrl: (handoff) => {
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.`);
220
- const orgId = handoff.orgId ?? resolveOrgId(options);
221
- if (!orgId) throw new Error("Missing Web Studio organization ID.");
222
- const url = new URL(`${checkoutUrl.replace(/\/$/, "")}/checkout/${encodeURIComponent(orgId)}/${encodeURIComponent(handoff.cartId)}`);
223
- if (handoff.locale) url.searchParams.set("lang", handoff.locale);
224
- return url.toString();
225
- } },
226
- inventory: { availability: (items, context) => request({
227
- ...context,
228
- method: "POST",
229
- path: "/inventory/v1/stock/availability",
230
- body: { items }
231
- }) }
232
- };
233
- }
234
- function resolveRequestOrgId(clientOptions, organizationOptions, context) {
235
- const orgId = organizationOptions?.orgId ?? context?.orgId ?? resolveOrgId(clientOptions);
236
- if (!orgId) throw new Error("Missing Web Studio organization ID.");
237
- return orgId;
238
- }
239
- function mapOrganizationFeatures(features) {
240
- const mapped = {};
241
- for (const row of features) if (row.feature === "CMS" || row.feature === "ECOMMERCE") mapped[row.feature] = row.enabled;
242
- return mapped;
243
- }
244
- function resolveEntryListQuery(options) {
245
- return {
246
- locale: options?.locale,
247
- page: options?.page,
248
- pageSize: options?.pageSize,
249
- limit: options?.limit,
250
- depth: options?.depth,
251
- deep: options?.deep
252
- };
253
- }
254
- function resolveEntryListBody(entryList) {
255
- return {
256
- schemas: entryList.schemas,
257
- filters: entryList.filters,
258
- displayAs: entryList.displayAs,
259
- orderBy: entryList.orderBy,
260
- pageSize: entryList.pageSize
261
- };
262
- }
263
- function createHttpRequest(clientOptions, requestOptions) {
264
- const method = requestOptions.method ?? (requestOptions.body === void 0 ? "GET" : "POST");
265
- const headers = mergeHeaders(resolveRuntimeValue(clientOptions.headers), requestOptions.headers);
266
- const orgId = requestOptions.orgId ?? resolveOrgId(clientOptions);
267
- if (orgId) headers.set("X-Org-Id", orgId);
268
- const previewToken = resolveRuntimeValue(clientOptions.previewToken);
269
- if (previewToken) headers.set("X-Preview-Token", previewToken);
270
- let body;
271
- if (requestOptions.body !== void 0) {
272
- headers.set("Content-Type", headers.get("Content-Type") ?? "application/json");
273
- body = isRawBody(requestOptions.body) ? requestOptions.body : JSON.stringify(requestOptions.body);
274
- }
275
- return {
276
- url: buildUrl(resolveApiBaseUrl(clientOptions), requestOptions.path, requestOptions.query),
277
- method,
278
- headers,
279
- body,
280
- signal: requestOptions.signal
281
- };
282
- }
283
- function createFetchHttpClient(fetchImpl) {
284
- return async (request) => {
285
- const resolvedFetch = fetchImpl ?? globalThis.fetch;
286
- if (!resolvedFetch) throw new Error("No fetch implementation is available. Pass fetch or httpClient to createEldraClient().");
287
- const response = await resolvedFetch(request.url, {
288
- method: request.method,
289
- headers: request.headers,
290
- body: request.body,
291
- signal: request.signal
292
- });
293
- const body = await readResponseBody(response);
294
- if (!response.ok) throw new EldraHttpError(response, body);
295
- return body;
296
- };
297
- }
298
- function readResponseBody(response) {
299
- if (response.status === 204) return Promise.resolve(void 0);
300
- const contentType = response.headers.get("Content-Type") ?? "";
301
- if (contentType.includes("application/json") || contentType.includes("application/problem+json")) return response.json();
302
- return response.text();
303
- }
304
- function resolveApiBaseUrl(options) {
305
- return resolveRuntimeValue(options.apiBaseUrl) ?? readFirstEnvValue(resolveRuntimeValue(options.env), apiBaseUrlEnvKeys) ?? "https://web.eldra.app/api";
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
- }
310
- function resolveOrgId(options) {
311
- return resolveRuntimeValue(options.orgId) ?? readFirstEnvValue(resolveRuntimeValue(options.env), orgIdEnvKeys);
312
- }
313
- function readFirstEnvValue(env, keys) {
314
- for (const key of keys) {
315
- const value = env?.[key];
316
- if (typeof value === "string" && value.trim() !== "") return value;
317
- }
318
- }
319
- function resolveRuntimeValue(value) {
320
- return typeof value === "function" ? value() : value;
321
- }
322
- function mergeHeaders(...sources) {
323
- const headers = new Headers();
324
- for (const source of sources) {
325
- if (!source) continue;
326
- new Headers(source).forEach((value, key) => headers.set(key, value));
327
- }
328
- return headers;
329
- }
330
- function buildUrl(apiBaseUrl, path, query) {
331
- const url = new URL(`${apiBaseUrl.replace(/\/$/, "")}/${path.replace(/^\//, "")}`);
332
- for (const [key, value] of Object.entries(query ?? {})) appendQueryValue(url.searchParams, key, value);
333
- return url.toString();
334
- }
335
- function appendQueryValue(searchParams, key, value) {
336
- if (value === void 0 || value === null || value === "") return;
337
- if (Array.isArray(value)) {
338
- searchParams.set(key, value.map(String).join(","));
339
- return;
340
- }
341
- searchParams.set(key, String(value));
342
- }
343
- function isRawBody(body) {
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;
345
- }
346
- //#endregion
347
- export { getEldraClient as a, resolveOrgId as c, createEldraClient as i, DEFAULT_ELDRA_CHECKOUT_URL as n, initEldraClient as o, EldraHttpError as r, resolveApiBaseUrl as s, DEFAULT_ELDRA_API_BASE_URL as t };