@eldrajs/sdk 0.2.9 → 0.3.0

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,36 @@ platform repository.
9
9
 
10
10
  ## Unreleased
11
11
 
12
+ - **`EldraFormDefinition.consentText` (WS-386, contract 4.13.0).** A form that subscribes the
13
+ visitor now publishes the consent sentence per locale, with the shop name already filled in
14
+ (`consentText?: EldraFormLocalized`, present only when `kinds` contains `subscribe`). Show it
15
+ beside the submit button as escaped plain text; the platform records it as the proof of consent
16
+ (followed by the labels of any ticked `consent` fields). No new submit field and no checkbox.
17
+
18
+ - **Forms are gated by the `FORMS` feature, and mailed links go to the web gateway (WS-386,
19
+ contract 4.12.0).** `client.forms` no longer needs `PAGE_BUILDER`: the organisation's new `FORMS`
20
+ feature switches on form reads and submissions, so a headless app with no theme or page builder
21
+ can use them (its origin must be a registered storefront origin). The confirm and unsubscribe
22
+ links in form mails now point at the web gateway's own page rather than the storefront's domain;
23
+ nothing changes for `confirm(token)` and `unsubscribe(token)`. No SDK code change.
24
+
25
+ - **`EldraFormFieldType` gains `number` and `url` (WS-386, contract 4.11.0).** The two types Core
26
+ accepts besides the earlier set from contract 4.11.0 on; both carry text the platform validates
27
+ (a finite number, with a decimal comma stored as a point, and an absolute http(s) URL).
28
+
29
+ - **`client.forms.confirm(token)` and `unsubscribe(token)` POST (WS-386, contract 4.10.0).** The
30
+ emailed confirm and unsubscribe links no longer act on a `GET`: Core answers a `GET` with a small
31
+ HTML page whose button posts the token back, so a mail scanner that prefetches the link confirms
32
+ and unsubscribes nobody. The two methods now `POST` the same paths with the token in the query and
33
+ still resolve `{ status }`; confirming or unsubscribing twice is a success. Needs a gateway at
34
+ contract 4.10.0 or later (the `GET` JSON answer of 4.7.0 to 4.9.0, never released, is gone).
35
+ - **`client.forms`: the site-forms API (WS-386).** `get(key)` reads a form definition,
36
+ `submit(key, { values, locale, pagePath, turnstileToken?, hp? })` posts a submission and
37
+ `confirm(token)` / `unsubscribe(token)` finish a subscriber's emailed links. A `422` resolves as
38
+ `{ status: 'invalid', errors, form }` (field-keyed, ready for `apiErrors`) rather than throwing;
39
+ `404`, `413` and `429` reject with `EldraHttpError`. New types `EldraFormDefinition`,
40
+ `EldraFormField`, `EldraFormSubmitInput`, `EldraFormSubmitResult` and friends, hand-written like
41
+ `EldraPlatformConfig`. Needs a gateway at contract 4.4.0 or later.
12
42
  - **Icelandic formatting that prints the same on every runtime: `@eldrajs/sdk/format`.**
13
43
  `numberFormat`, `formatPrice` and `comparator`/`compareIcelandic`, plus `./format/date`,
14
44
  `./format/list`, `./format/relative-time` and `./format/display-names`. Icelandic and English come
package/README.md CHANGED
@@ -94,6 +94,34 @@ Import only the entries you use; each carries its own data. The rules and what i
94
94
  | `inventory` | `availability` |
95
95
  | `features` | `getOrganization`, `list`, `isEnabled`, `getCapabilities`, `getCommerce` |
96
96
  | `platform` | `config` |
97
+ | `forms` | `get`, `submit`, `confirm`, `unsubscribe` |
98
+
99
+ `forms` is the site-forms API: `get(key)` reads a form's definition (fields with a label per locale,
100
+ the honeypot field's name, the Turnstile site key, the success message), and `submit(key, { values,
101
+ locale, pagePath, turnstileToken?, hp? })` posts a submission. A `422` is an answer, not a failure:
102
+ `submit` resolves `{ status: 'invalid', errors, form }` with the field-keyed messages a form shows
103
+ inline (`errors` is the shape `@eldrajs/ui`'s `apiErrors` takes), and `{ status: 'ok', pending }` on
104
+ success, where `pending` means a double opt-in email is on its way. A `404` (unknown form), `413`
105
+ (oversize) and `429` (rate limited) reject with `EldraHttpError`. `confirm(token)` and
106
+ `unsubscribe(token)` finish the subscriber's emailed links; those links point at the web gateway's
107
+ own page, so an app needs no route of its own for them. Forms need the organisation's `FORMS`
108
+ feature (not `PAGE_BUILDER`) and work with no theme: the app's origin must be registered as a
109
+ storefront origin in Studio, and when the definition has a Turnstile site key the app renders the
110
+ widget itself and sends the token as `turnstileToken`. The form types are hand-written, like
111
+ `EldraPlatformConfig`: the SDK ships no response types.
112
+
113
+ **Proof of consent.** For a form that subscribes the visitor, the platform records what they agreed
114
+ to, and that wording is always real: the definition's `consentText` (a sentence per locale, with the
115
+ shop name already filled in; present only when `kinds` contains `subscribe`). Show it next to the
116
+ submit button as escaped plain text; submitting is the consent, so there is no extra checkbox and
117
+ nothing extra to send. The platform stores the sentence in the visitor's `locale`, followed by the
118
+ label of each `consent` field they ticked, taken from the form definition on the server, never from
119
+ the client. `pagePath` is stored as the page the submission came from, so send the real
120
+ `location.pathname`; it is client-supplied and informational. IP addresses and user agents are not
121
+ stored.
122
+
123
+ Subscribers and this record are owned by the platform's marketing service; `confirm` and
124
+ `unsubscribe` keep calling the same `/site/v1/forms/subscriptions/*` paths, so nothing changes in an app.
97
125
 
98
126
  `checkout.url({ cartId, locale })` is where a storefront sends the shopper. The platform hosts the
99
127
  checkout page, so the client asks the platform where (`platform.config()`, a public read cached per
@@ -439,6 +439,41 @@ function createEldraClient(options) {
439
439
  })
440
440
  },
441
441
  platform: { config: (readOptions) => readPlatformConfig(readOptions) },
442
+ forms: {
443
+ get: (key, context) => request({
444
+ ...context,
445
+ path: `/site/v1/forms/${encodeURIComponent(key)}`
446
+ }),
447
+ submit: async (key, input, context) => {
448
+ try {
449
+ const answer = await request({
450
+ ...context,
451
+ method: "POST",
452
+ path: `/site/v1/forms/${encodeURIComponent(key)}/submissions`,
453
+ body: input
454
+ });
455
+ return {
456
+ status: "ok",
457
+ pending: typeof answer === "object" && answer !== null && "pending" in answer ? answer.pending === true : false
458
+ };
459
+ } catch (error) {
460
+ if (error instanceof EldraHttpError && error.status === 422) return toFormInvalid(error.body);
461
+ throw error;
462
+ }
463
+ },
464
+ confirm: (token, context) => request({
465
+ ...context,
466
+ method: "POST",
467
+ path: "/site/v1/forms/subscriptions/confirm",
468
+ query: { token }
469
+ }),
470
+ unsubscribe: (token, context) => request({
471
+ ...context,
472
+ method: "POST",
473
+ path: "/site/v1/forms/subscriptions/unsubscribe",
474
+ query: { token }
475
+ })
476
+ },
442
477
  checkout: { url: async (handoff, readOptions) => {
443
478
  let checkoutUrl = null;
444
479
  let cause;
@@ -579,6 +614,26 @@ function resolveEntryListBody(entryList) {
579
614
  pageSize: entryList.pageSize
580
615
  };
581
616
  }
617
+ /**
618
+ * A `422` body, narrowed to the field-keyed shape. Anything that is not a string array under a key
619
+ * is dropped rather than guessed at, so a malformed body still reads as "invalid" with no messages
620
+ * (the caller shows its own generic line) instead of throwing a TypeError at the visitor.
621
+ */
622
+ function toFormInvalid(body) {
623
+ const record = typeof body === "object" && body !== null ? body : {};
624
+ const strings = (value) => Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
625
+ const errors = {};
626
+ const rawErrors = record.errors;
627
+ if (typeof rawErrors === "object" && rawErrors !== null && !Array.isArray(rawErrors)) for (const [field, messages] of Object.entries(rawErrors)) {
628
+ const list = strings(messages);
629
+ if (list.length > 0) errors[field] = list;
630
+ }
631
+ return {
632
+ status: "invalid",
633
+ errors,
634
+ form: strings(record.form)
635
+ };
636
+ }
582
637
  function createHttpRequest(clientOptions, requestOptions) {
583
638
  const method = requestOptions.method ?? (requestOptions.body === void 0 ? "GET" : "POST");
584
639
  const headers = mergeHeaders(resolveRuntimeValue(clientOptions.headers), requestOptions.headers);
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
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";
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";
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 {
@@ -149,4 +149,4 @@ interface EldraResponsiveImage {
149
149
  */
150
150
  export declare function responsiveImage(source: EldraImageSource, options: EldraResponsiveImageOptions): EldraResponsiveImage | undefined;
151
151
  //#endregion
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 };
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, EldraFormActionKind, EldraFormDefinition, EldraFormField, EldraFormFieldOption, EldraFormFieldType, EldraFormLocalized, EldraFormSubmitInput, EldraFormSubmitResult, EldraFormTokenResult, EldraFormsClient, 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 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";
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";
2
2
  //#region src/storage.ts
3
3
  const DEFAULT_CART_KEY = "eldra.cartId";
4
4
  const DEFAULT_ORDER_TOKEN_PREFIX = "eldra.orderAccessToken.";
@@ -281,6 +281,7 @@ interface EldraClient {
281
281
  cart: EldraCartClient;
282
282
  orders: EldraOrdersClient;
283
283
  platform: EldraPlatformClient;
284
+ forms: EldraFormsClient;
284
285
  checkout: EldraCheckoutClient;
285
286
  inventory: EldraInventoryClient;
286
287
  }
@@ -379,5 +380,105 @@ interface EldraPlatformClient {
379
380
  interface EldraInventoryClient {
380
381
  availability(items: EldraStockAvailabilityInput[], context?: EldraRequestContext): Promise<EldraStockAvailability>;
381
382
  }
383
+ /**
384
+ * A localized string as the forms API publishes it: one entry per locale tag the merchant wrote
385
+ * (`en-US`, `is-IS`). A caller resolves its own locale and falls back; the API never guesses.
386
+ */
387
+ type EldraFormLocalized = Record<string, string>;
388
+ /**
389
+ * The field types a form definition can carry. `checkbox` and `consent` both carry a boolean;
390
+ * `required` on a `consent` field means it must be checked. `number` and `url` carry text the
391
+ * platform validates (a finite number, an absolute http(s) URL).
392
+ */
393
+ type EldraFormFieldType = 'text' | 'email' | 'phone' | 'textarea' | 'select' | 'checkbox' | 'consent' | 'number' | 'url';
394
+ interface EldraFormFieldOption {
395
+ value: string;
396
+ label: EldraFormLocalized;
397
+ }
398
+ interface EldraFormField {
399
+ /** Stable id: the key of the field in a submission's `values` and in a 422's `errors`. */
400
+ id: string;
401
+ type: EldraFormFieldType;
402
+ required: boolean;
403
+ label: EldraFormLocalized;
404
+ placeholder?: EldraFormLocalized;
405
+ options?: EldraFormFieldOption[];
406
+ validation?: {
407
+ minLength?: number;
408
+ maxLength?: number;
409
+ pattern?: string;
410
+ };
411
+ }
412
+ /** The actions a submission triggers; the merchant's notify/confirm targets are never published. */
413
+ type EldraFormActionKind = 'store' | 'notify' | 'confirm' | 'subscribe';
414
+ /**
415
+ * A form definition exactly as `GET /site/v1/forms/{key}` answers it. Hand-written rather than
416
+ * contract-derived (the SDK ships no response types): the shape is the platform's documented wire
417
+ * contract, and `@eldrajs/theme-nuxt` validates a build-time read of it before baking it.
418
+ */
419
+ interface EldraFormDefinition {
420
+ key: string;
421
+ name: string;
422
+ fields: EldraFormField[];
423
+ /** The name of a field that must stay empty: render it hidden from people, send it as `hp`. */
424
+ honeypotField: string;
425
+ /** Cloudflare Turnstile site key, or `null` when the merchant has not enabled it. */
426
+ turnstileSiteKey: string | null;
427
+ success: {
428
+ message: EldraFormLocalized;
429
+ redirect?: EldraFormLocalized;
430
+ };
431
+ kinds: EldraFormActionKind[];
432
+ /**
433
+ * The consent sentence per locale, with the shop name already filled in for `{shop}`. Present
434
+ * only when `kinds` contains `subscribe`. Show it next to the submit button (escaped, plain
435
+ * text): submitting the form is the visitor's consent to exactly this wording, and the platform
436
+ * stores it as the proof. There is no extra checkbox and no extra submit field.
437
+ */
438
+ consentText?: EldraFormLocalized;
439
+ }
440
+ interface EldraFormSubmitInput {
441
+ /** `fieldId` to the entered value; a checkbox is a boolean, everything else a string. */
442
+ values: Record<string, string | boolean>;
443
+ locale: string;
444
+ pagePath: string;
445
+ turnstileToken?: string;
446
+ /** The honeypot field's value, which a person never fills. */
447
+ hp?: string;
448
+ }
449
+ /**
450
+ * What a submission resolves to. A `422` is an answer, not a failure — it carries the field-keyed
451
+ * messages a form shows inline — so it resolves as `status: 'invalid'`. Every other non-2xx
452
+ * (`404` unknown form, `413` oversize, `429` rate limited) rejects with `EldraHttpError`.
453
+ */
454
+ type EldraFormSubmitResult = {
455
+ status: 'ok';
456
+ /** `true` when the form subscribes the visitor and a confirmation email is on its way. */
457
+ pending: boolean;
458
+ } | {
459
+ status: 'invalid';
460
+ /** `fieldId` to messages, the shape `@eldrajs/ui`'s `apiErrors` expects. */
461
+ errors: Record<string, string[]>;
462
+ /** Messages about the form as a whole. */
463
+ form: string[];
464
+ };
465
+ interface EldraFormTokenResult {
466
+ status: 'confirmed' | 'unsubscribed';
467
+ }
468
+ /**
469
+ * The site-forms API. Needs the organisation's `FORMS` feature (not `PAGE_BUILDER`) and a registered
470
+ * storefront origin in a browser; works with no theme. The mailed confirm and unsubscribe links point
471
+ * at the web gateway's own page, not the storefront.
472
+ */
473
+ interface EldraFormsClient {
474
+ /** `GET /site/v1/forms/{key}`. Rejects with `EldraHttpError` (`404`) for an unknown key. */
475
+ get(key: string, context?: EldraRequestContext): Promise<EldraFormDefinition>;
476
+ /** `POST /site/v1/forms/{key}/submissions`. See `EldraFormSubmitResult`. */
477
+ submit(key: string, input: EldraFormSubmitInput, context?: EldraRequestContext): Promise<EldraFormSubmitResult>;
478
+ /** Double opt-in: `POST /site/v1/forms/subscriptions/confirm?token=` (a GET of the link is only a page). */
479
+ confirm(token: string, context?: EldraRequestContext): Promise<EldraFormTokenResult>;
480
+ /** `POST /site/v1/forms/subscriptions/unsubscribe?token=` (a GET of the link is only a page). */
481
+ unsubscribe(token: string, context?: EldraRequestContext): Promise<EldraFormTokenResult>;
482
+ }
382
483
  //#endregion
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 };
484
+ export { EldraOrganizationFeature as $, EldraFeature as A, EldraContractMethod as At, EldraFormSubmitResult as B, EldraCmsResolveEntryListResponse as C, EldraStockAvailabilityInput as Ct, EldraCollectionListOptions as D, EldraContract as Dt, EldraCollectionList as E, RuntimeValue as Et, EldraFormField as F, EldraContractResponse as Ft, EldraInventoryClient as G, EldraFormsClient as H, EldraFormFieldOption as I, EldraOrderLine as J, EldraLocaleOptions as K, EldraFormFieldType as L, EldraFeatureClient as M, EldraContractPaths as Mt, EldraFormActionKind as N, EldraContractProp as Nt, EldraCollectionProductsOptions as O, EldraContractBody as Ot, EldraFormDefinition as P, EldraContractQuery as Pt, EldraOrganizationDetails as Q, EldraFormLocalized as R, EldraCmsResolveEntryListOptions as S, EldraStockAvailability as St, EldraCollection as T, RuntimeEnv as Tt, EldraHttpClient as U, EldraFormTokenResult as V, EldraHttpRequest as W, EldraOrdersClient as X, EldraOrderReadOptions as Y, EldraOrganizationCommerce as Z, EldraCmsEntryListEntry as _, EldraRequestContext as _t, EldraCartTotals as a, EldraPlatformConfig as at, EldraCmsGetOptions as b, EldraSearchOptions as bt, EldraCatalogListProductsOptions as c, EldraProductList as ct, EldraCheckoutUrlOptions as d, EldraProductOption as dt, EldraOrganizationLocales as et, EldraClient as f, EldraProductOptionValue as ft, EldraCmsEntryListDisplayMode as g, EldraRecoveredBasketItem as gt, EldraCmsEntryList as h, EldraRecoveredBasket as ht, EldraCartItem as i, EldraPlatformClient as it, EldraFeatureCapabilities as j, EldraContractPath as jt, EldraDiscountResult as k, EldraContractItem as kt, EldraCategory as l, EldraProductListItem as lt, EldraCmsClient as m, EldraProductVariant as mt, EldraCart as n, EldraPageMeta as nt, EldraCatalogClient as o, EldraPlatformReadOptions as ot, EldraClientOptions as p, EldraProductThumbnail as pt, EldraOrder as q, EldraCartClient as r, EldraPaginated as rt, EldraCatalogGetProductOptions as s, EldraProductDetails as st, EldraAddCartItemInput as t, EldraOrganizationOptions as tt, EldraCheckoutClient as u, EldraProductMediaLink as ut, EldraCmsEntryListFilterCriterion as v, EldraRequestOptions as vt, EldraCmsResolvedEntryList as w, EldraStockAvailabilityItem as wt, EldraCmsListOptions as x, EldraSearchResponse as xt, EldraCmsGetEntryByUniqueFieldOptions as y, EldraRetryOptions as yt, EldraFormSubmitInput as z };
package/dist/vite.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { gt as RuntimeValue, ht as RuntimeEnv } from "./types-B40H01uK.js";
1
+ import { Et as RuntimeValue, Tt as RuntimeEnv } from "./types-Cs5t0rx7.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-t66vCzJf.js";
1
+ import "./client-COQ5N834.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.9",
3
+ "version": "0.3.0",
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",