@eldrajs/sdk 0.3.0 → 0.3.2

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,26 @@ platform repository.
9
9
 
10
10
  ## Unreleased
11
11
 
12
+ - **Images use the size the API gives them (contract 4.14.0).** `EldraImageSource` accepts the
13
+ `width` and `height` an image object now carries (its pixels as displayed). `imageSrcset` stops at
14
+ that width unless `originalWidth` is passed, and `responsiveImage` sets `width`/`height` to the
15
+ `src` variant's own size (the original scaled to the variant, never enlarged) when neither
16
+ `width`/`height` nor `aspectRatio` is given; both of those still win. An image without them
17
+ behaves as before.
18
+
19
+ - **`imageSrcset` lists the original when it is wider than `full`.** When the original's width is
20
+ known (the API's `width`, or `originalWidth`) and above 2560 px, the `srcset` ends with
21
+ `…/original <width>w`, so a zoomed crop that needs more than 2560 px is sharp. The original is
22
+ served as uploaded, so a browser picks it only when no variant is wide enough. Never for HEIC,
23
+ which most browsers cannot show as uploaded. A narrower original still ends the list at its own
24
+ width.
25
+
26
+ - **`buildToken` client option (WS-403).** When set (a string or a function returning one), every
27
+ request carries `X-Eldra-Build-Token`, a read-only build token (`eldra_bld_…`, created in Studio → Settings → Developers → Build tokens),
28
+ so the gateway can give a theme build's reads their own rate-limit bucket. Server and build only;
29
+ omitted or empty sends no header. Never pass the site deploy token. Pass it from server-side code
30
+ only; an SSR server that sends it on every visitor request shares the organisation's build budget.
31
+
12
32
  - **`EldraFormDefinition.consentText` (WS-386, contract 4.13.0).** A form that subscribes the
13
33
  visitor now publishes the consent sentence per locale, with the shop name already filled in
14
34
  (`consentText?: EldraFormLocalized`, present only when `kinds` contains `subscribe`). Show it
package/README.md CHANGED
@@ -45,7 +45,8 @@ precedence.
45
45
  ## Images
46
46
 
47
47
  A media URL from the API serves an 800 px copy. Build a `srcset` over the sizes the media host
48
- serves (400 to 2560 px) so the browser picks one that is sharp on the screen in front of it:
48
+ serves (400 to 2560 px, then the original when it is wider) so the browser picks one that is sharp
49
+ on the screen in front of it:
49
50
 
50
51
  ```ts
51
52
  import { responsiveImage } from '@eldrajs/sdk';
@@ -641,6 +641,8 @@ function createHttpRequest(clientOptions, requestOptions) {
641
641
  if (orgId) headers.set("X-Org-Id", orgId);
642
642
  const previewToken = resolveRuntimeValue(clientOptions.previewToken);
643
643
  if (previewToken) headers.set("X-Preview-Token", previewToken);
644
+ const buildToken = resolveRuntimeValue(clientOptions.buildToken);
645
+ if (buildToken) headers.set("X-Eldra-Build-Token", buildToken);
644
646
  let body;
645
647
  if (requestOptions.body !== void 0) {
646
648
  headers.set("Content-Type", headers.get("Content-Type") ?? "application/json");
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as EldraOrganizationFeature, A as EldraFeature, At as EldraContractMethod, B as EldraFormSubmitResult, C as EldraCmsResolveEntryListResponse, Ct as EldraStockAvailabilityInput, D as EldraCollectionListOptions, Dt as EldraContract, E as EldraCollectionList, Et as RuntimeValue, F as EldraFormField, Ft as EldraContractResponse, G as EldraInventoryClient, H as EldraFormsClient, I as EldraFormFieldOption, J as EldraOrderLine, K as EldraLocaleOptions, L as EldraFormFieldType, M as EldraFeatureClient, Mt as EldraContractPaths, N as EldraFormActionKind, Nt as EldraContractProp, O as EldraCollectionProductsOptions, Ot as EldraContractBody, P as EldraFormDefinition, Pt as EldraContractQuery, Q as EldraOrganizationDetails, R as EldraFormLocalized, S as EldraCmsResolveEntryListOptions, St as EldraStockAvailability, T as EldraCollection, Tt as RuntimeEnv, U as EldraHttpClient, V as EldraFormTokenResult, W as EldraHttpRequest, X as EldraOrdersClient, Y as EldraOrderReadOptions, Z as EldraOrganizationCommerce, _ as EldraCmsEntryListEntry, _t as EldraRequestContext, a as EldraCartTotals, at as EldraPlatformConfig, b as EldraCmsGetOptions, bt as EldraSearchOptions, c as EldraCatalogListProductsOptions, ct as EldraProductList, d as EldraCheckoutUrlOptions, dt as EldraProductOption, et as EldraOrganizationLocales, f as EldraClient, ft as EldraProductOptionValue, g as EldraCmsEntryListDisplayMode, gt as EldraRecoveredBasketItem, h as EldraCmsEntryList, ht as EldraRecoveredBasket, i as EldraCartItem, it as EldraPlatformClient, j as EldraFeatureCapabilities, jt as EldraContractPath, k as EldraDiscountResult, kt as EldraContractItem, l as EldraCategory, lt as EldraProductListItem, m as EldraCmsClient, mt as EldraProductVariant, n as EldraCart, nt as EldraPageMeta, o as EldraCatalogClient, ot as EldraPlatformReadOptions, p as EldraClientOptions, pt as EldraProductThumbnail, q as EldraOrder, r as EldraCartClient, rt as EldraPaginated, s as EldraCatalogGetProductOptions, st as EldraProductDetails, t as EldraAddCartItemInput, tt as EldraOrganizationOptions, u as EldraCheckoutClient, ut as EldraProductMediaLink, v as EldraCmsEntryListFilterCriterion, vt as EldraRequestOptions, w as EldraCmsResolvedEntryList, wt as EldraStockAvailabilityItem, x as EldraCmsListOptions, xt as EldraSearchResponse, y as EldraCmsGetEntryByUniqueFieldOptions, yt as EldraRetryOptions, z as EldraFormSubmitInput } from "./types-Cs5t0rx7.js";
1
+ import { $ as EldraOrganizationFeature, A as EldraFeature, At as EldraContractMethod, B as EldraFormSubmitResult, C as EldraCmsResolveEntryListResponse, Ct as EldraStockAvailabilityInput, D as EldraCollectionListOptions, Dt as EldraContract, E as EldraCollectionList, Et as RuntimeValue, F as EldraFormField, Ft as EldraContractResponse, G as EldraInventoryClient, H as EldraFormsClient, I as EldraFormFieldOption, J as EldraOrderLine, K as EldraLocaleOptions, L as EldraFormFieldType, M as EldraFeatureClient, Mt as EldraContractPaths, N as EldraFormActionKind, Nt as EldraContractProp, O as EldraCollectionProductsOptions, Ot as EldraContractBody, P as EldraFormDefinition, Pt as EldraContractQuery, Q as EldraOrganizationDetails, R as EldraFormLocalized, S as EldraCmsResolveEntryListOptions, St as EldraStockAvailability, T as EldraCollection, Tt as RuntimeEnv, U as EldraHttpClient, V as EldraFormTokenResult, W as EldraHttpRequest, X as EldraOrdersClient, Y as EldraOrderReadOptions, Z as EldraOrganizationCommerce, _ as EldraCmsEntryListEntry, _t as EldraRequestContext, a as EldraCartTotals, at as EldraPlatformConfig, b as EldraCmsGetOptions, bt as EldraSearchOptions, c as EldraCatalogListProductsOptions, ct as EldraProductList, d as EldraCheckoutUrlOptions, dt as EldraProductOption, et as EldraOrganizationLocales, f as EldraClient, ft as EldraProductOptionValue, g as EldraCmsEntryListDisplayMode, gt as EldraRecoveredBasketItem, h as EldraCmsEntryList, ht as EldraRecoveredBasket, i as EldraCartItem, it as EldraPlatformClient, j as EldraFeatureCapabilities, jt as EldraContractPath, k as EldraDiscountResult, kt as EldraContractItem, l as EldraCategory, lt as EldraProductListItem, m as EldraCmsClient, mt as EldraProductVariant, n as EldraCart, nt as EldraPageMeta, o as EldraCatalogClient, ot as EldraPlatformReadOptions, p as EldraClientOptions, pt as EldraProductThumbnail, q as EldraOrder, r as EldraCartClient, rt as EldraPaginated, s as EldraCatalogGetProductOptions, st as EldraProductDetails, t as EldraAddCartItemInput, tt as EldraOrganizationOptions, u as EldraCheckoutClient, ut as EldraProductMediaLink, v as EldraCmsEntryListFilterCriterion, vt as EldraRequestOptions, w as EldraCmsResolvedEntryList, wt as EldraStockAvailabilityItem, x as EldraCmsListOptions, xt as EldraSearchResponse, y as EldraCmsGetEntryByUniqueFieldOptions, yt as EldraRetryOptions, z as EldraFormSubmitInput } from "./types-BAYHYEat.js";
2
2
  //#region src/client.d.ts
3
3
  export declare const DEFAULT_ELDRA_API_BASE_URL = "https://web.eldra.app/api";
4
4
  export declare class EldraHttpError extends Error {
@@ -87,11 +87,13 @@ export declare const ELDRA_IMAGE_VARIANT_WIDTHS: Readonly<Record<EldraSizedImage
87
87
  /**
88
88
  * A media URL as the API returns it, or any object carrying one (`thumbnail`, `mediaLinks[]`, a
89
89
  * CMS media item). `contentType`, when present, keeps formats the host does not resize out of
90
- * `srcset`.
90
+ * `srcset`; `width` and `height`, when present, are the displayed pixel size (docs/images.md).
91
91
  */
92
92
  type EldraImageSource = string | {
93
93
  url?: string | null;
94
94
  contentType?: string | null;
95
+ width?: number | null;
96
+ height?: number | null;
95
97
  } | null | undefined;
96
98
  /** Whether the source is an Eldra media asset the host can resize. */
97
99
  export declare function isEldraImage(source: EldraImageSource): boolean;
@@ -108,14 +110,14 @@ export declare function imageUrl(source: EldraImageSource, variant: EldraImageVa
108
110
  export declare function imageVariantFor(width: number, density?: number): EldraSizedImageVariant;
109
111
  interface EldraImageSrcsetOptions {
110
112
  /**
111
- * The original's width in pixels, when you know it. Variants wider than it would be the same
112
- * pixels at a new URL, so they are dropped, and the last one is described at its true width.
113
+ * The original's width in pixels, by default the source's `width`. Wider variants are dropped and
114
+ * the last is described at its true width; an original wider than `full` is listed itself, last.
113
115
  */
114
116
  originalWidth?: number;
115
117
  }
116
118
  /**
117
- * A `srcset` over the resized variants of an Eldra media asset, each described by its width. Returns
118
- * `undefined` for anything else, so `<img :srcset>` simply drops the attribute.
119
+ * A `srcset` over the resized variants of an Eldra media asset, and the original when it is wider.
120
+ * Returns `undefined` for anything else, so `<img :srcset>` simply drops the attribute.
119
121
  */
120
122
  export declare function imageSrcset(source: EldraImageSource, options?: EldraImageSrcsetOptions): string | undefined;
121
123
  interface EldraResponsiveImageOptions extends EldraImageSrcsetOptions {
@@ -128,10 +130,10 @@ interface EldraResponsiveImageOptions extends EldraImageSrcsetOptions {
128
130
  variant?: EldraSizedImageVariant;
129
131
  /**
130
132
  * The width-to-height ratio of the box the image fills, such as `4 / 5`. It becomes `width` and
131
- * `height` attributes, which reserve the space before the image loads.
133
+ * `height` attributes, which reserve the space before the image loads, in place of the source's size.
132
134
  */
133
135
  aspectRatio?: number;
134
- /** Explicit `width` and `height` attributes; they take precedence over `aspectRatio`. */
136
+ /** Explicit `width` and `height` attributes; they take precedence over everything else. */
135
137
  width?: number;
136
138
  height?: number;
137
139
  }
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
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-COQ5N834.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-Cn3at4Zh.js";
2
2
  //#region src/storage.ts
3
3
  const DEFAULT_CART_KEY = "eldra.cartId";
4
4
  const DEFAULT_ORDER_TOKEN_PREFIX = "eldra.orderAccessToken.";
@@ -94,6 +94,15 @@ function sourceUrl(source) {
94
94
  const url = typeof source === "string" ? source : source?.url;
95
95
  return url ? url : void 0;
96
96
  }
97
+ const isSide = (n) => typeof n === "number" && n > 0 && n < Infinity;
98
+ /** The size the API gave the image, when it gave both sides. */
99
+ function sourceSize(source) {
100
+ const s = typeof source === "object" ? source : void 0;
101
+ return s && isSide(s.width) && isSide(s.height) ? {
102
+ width: s.width,
103
+ height: s.height
104
+ } : void 0;
105
+ }
97
106
  function resizableAssetBase(source) {
98
107
  const url = sourceUrl(source);
99
108
  if (!url) return void 0;
@@ -118,23 +127,28 @@ function imageVariantFor(width, density = 1) {
118
127
  if (!Number.isFinite(needed) || needed <= 0) throw new RangeError(`imageVariantFor needs a positive width, got ${width} at ${density}x`);
119
128
  return SIZED_VARIANTS.find((variant) => ELDRA_IMAGE_VARIANT_WIDTHS[variant] >= needed) ?? "full";
120
129
  }
130
+ function originalDisplays(source) {
131
+ const contentType = typeof source === "object" ? source?.contentType?.toLowerCase() : void 0;
132
+ return contentType !== "image/heic" && contentType !== "image/heif";
133
+ }
121
134
  /**
122
- * A `srcset` over the resized variants of an Eldra media asset, each described by its width. Returns
123
- * `undefined` for anything else, so `<img :srcset>` simply drops the attribute.
135
+ * A `srcset` over the resized variants of an Eldra media asset, and the original when it is wider.
136
+ * Returns `undefined` for anything else, so `<img :srcset>` simply drops the attribute.
124
137
  */
125
138
  function imageSrcset(source, options = {}) {
126
139
  const base = resizableAssetBase(source);
127
140
  if (!base) return void 0;
128
- const { originalWidth } = options;
141
+ const originalWidth = options.originalWidth ?? sourceSize(source)?.width;
129
142
  const candidates = [];
130
143
  for (const variant of SIZED_VARIANTS) {
131
144
  const width = ELDRA_IMAGE_VARIANT_WIDTHS[variant];
132
145
  if (originalWidth !== void 0 && originalWidth > 0 && width >= originalWidth) {
133
146
  candidates.push(`${base}/${variant} ${Math.round(originalWidth)}w`);
134
- break;
147
+ return candidates.join(", ");
135
148
  }
136
149
  candidates.push(`${base}/${variant} ${width}w`);
137
150
  }
151
+ if (isSide(originalWidth) && Math.round(originalWidth) > ELDRA_IMAGE_VARIANT_WIDTHS.full && originalDisplays(source)) candidates.push(`${base}/original ${Math.round(originalWidth)}w`);
138
152
  return candidates.join(", ");
139
153
  }
140
154
  /**
@@ -151,12 +165,16 @@ function responsiveImage(source, options) {
151
165
  image.srcset = srcset;
152
166
  image.sizes = options.sizes;
153
167
  }
168
+ const size = sourceSize(source);
154
169
  if (options.width !== void 0 && options.height !== void 0) {
155
170
  image.width = options.width;
156
171
  image.height = options.height;
157
172
  } else if (options.aspectRatio !== void 0 && options.aspectRatio > 0) {
158
173
  image.width = ELDRA_IMAGE_VARIANT_WIDTHS[variant];
159
174
  image.height = Math.round(image.width / options.aspectRatio);
175
+ } else if (size) {
176
+ image.width = srcset ? Math.min(ELDRA_IMAGE_VARIANT_WIDTHS[variant], size.width) : size.width;
177
+ image.height = Math.round(image.width * size.height / size.width) || 1;
160
178
  }
161
179
  return image;
162
180
  }
@@ -80,6 +80,14 @@ interface EldraClientOptions {
80
80
  orgId?: RuntimeValue<string>;
81
81
  /** Sends X-Preview-Token on requests, overriding the same header in headers/context. */
82
82
  previewToken?: RuntimeValue<string>;
83
+ /**
84
+ * Sends X-Eldra-Build-Token on every request: a read-only build token (`eldra_bld_…`, Studio → Settings → Developers → Build tokens), proving the request comes
85
+ * from a theme build so the gateway counts it against the build's own rate-limit budget instead
86
+ * of the machine's IP. **Server and build only** — never pass it from code that runs in a
87
+ * browser, and never put it in a public config. Never pass a site deploy token here.
88
+ * An SSR server that sends it on every visitor request shares the organisation's build budget. Omitted or empty sends no header.
89
+ */
90
+ buildToken?: RuntimeValue<string>;
83
91
  env?: RuntimeValue<RuntimeEnv>;
84
92
  headers?: RuntimeValue<HeadersInit>;
85
93
  httpClient?: EldraHttpClient;
package/dist/vite.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Et as RuntimeValue, Tt as RuntimeEnv } from "./types-Cs5t0rx7.js";
1
+ import { Et as RuntimeValue, Tt as RuntimeEnv } from "./types-BAYHYEat.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-COQ5N834.js";
1
+ import "./client-Cn3at4Zh.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.3.0",
3
+ "version": "0.3.2",
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",