@eldrajs/sdk 0.2.1 → 0.2.3
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 +8 -0
- package/README.md +9 -1
- package/dist/{client-BREAy8rQ.js → client-bg68WrsC.js} +11 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/dist/{types-Bq1jUVcz.d.ts → types-CPUs_QPj.d.ts} +2 -0
- package/dist/vite.d.ts +3 -1
- package/dist/vite.js +5 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,14 @@ platform repository.
|
|
|
9
9
|
|
|
10
10
|
## Unreleased
|
|
11
11
|
|
|
12
|
+
- `EldraHttpError.errorId` carries the problem's specific reason, such as `CART_NOT_FOUND` or
|
|
13
|
+
`CART_INSUFFICIENT_STOCK`. The docs told you to branch on `code` for these, but the gateway puts
|
|
14
|
+
them in `errorId`; `code` is only the category (`NOT_FOUND`, `CONFLICT`) and is unchanged.
|
|
15
|
+
|
|
16
|
+
- Restore `previewToken` on the SDK client and Vite generator after the move from
|
|
17
|
+
`vue-ui-components`. Accepts a string or callback and sends `X-Preview-Token`; the generator
|
|
18
|
+
forwards it to both type endpoints without embedding it in generated files.
|
|
19
|
+
|
|
12
20
|
- The Vite plugin writes `.eldra/web-studio/` beside the nearest `package.json` instead of Vite's
|
|
13
21
|
root; on Nuxt 4 the root is `app/`, and the folder landed there. A relative `outDir` is resolved
|
|
14
22
|
the same way.
|
package/README.md
CHANGED
|
@@ -35,6 +35,13 @@ call site.
|
|
|
35
35
|
|
|
36
36
|
The full walkthrough is [docs/getting-started.md](../../docs/getting-started.md).
|
|
37
37
|
|
|
38
|
+
## Preview mode
|
|
39
|
+
|
|
40
|
+
Both `createEldraClient` and the Vite plugin accept `previewToken` as a string or callback and send
|
|
41
|
+
it as `X-Preview-Token`. Configure each separately; the generator never embeds the token in its
|
|
42
|
+
output. See [preview mode](../../docs/getting-started.md#preview-mode) for examples and header
|
|
43
|
+
precedence.
|
|
44
|
+
|
|
38
45
|
## What is in the client
|
|
39
46
|
|
|
40
47
|
| Group | Methods |
|
|
@@ -47,6 +54,7 @@ The full walkthrough is [docs/getting-started.md](../../docs/getting-started.md)
|
|
|
47
54
|
| `inventory` | `availability` |
|
|
48
55
|
| `features` | `getOrganization`, `list`, `isEnabled`, `getCapabilities` |
|
|
49
56
|
|
|
50
|
-
Every failed request throws `EldraHttpError` with `status
|
|
57
|
+
Every failed request throws `EldraHttpError` with `status`, the problem's category `code` (such as
|
|
58
|
+
`NOT_FOUND`) and its specific `errorId` (such as `CART_NOT_FOUND`); branch on `errorId`.
|
|
51
59
|
`createCartSession` and `createOrderAccessTokens` persist the cart id and order tokens without
|
|
52
60
|
throwing where storage is unavailable.
|
|
@@ -19,21 +19,24 @@ var EldraHttpError = class extends Error {
|
|
|
19
19
|
status;
|
|
20
20
|
statusText;
|
|
21
21
|
body;
|
|
22
|
-
/** The
|
|
22
|
+
/** The problem's category, such as `NOT_FOUND` or `CONFLICT`, when the body carried one. */
|
|
23
23
|
code;
|
|
24
|
+
/** The problem's specific reason, such as `CART_NOT_FOUND`, when the body carried one. */
|
|
25
|
+
errorId;
|
|
24
26
|
constructor(response, body) {
|
|
25
27
|
super(`Web Studio request failed with ${response.status} ${response.statusText}`);
|
|
26
28
|
this.name = "EldraHttpError";
|
|
27
29
|
this.status = response.status;
|
|
28
30
|
this.statusText = response.statusText;
|
|
29
31
|
this.body = body;
|
|
30
|
-
this.code =
|
|
32
|
+
this.code = problemField(body, "code");
|
|
33
|
+
this.errorId = problemField(body, "errorId");
|
|
31
34
|
}
|
|
32
35
|
};
|
|
33
|
-
function
|
|
34
|
-
if (body && typeof body === "object" &&
|
|
35
|
-
const
|
|
36
|
-
return typeof
|
|
36
|
+
function problemField(body, field) {
|
|
37
|
+
if (body && typeof body === "object" && field in body) {
|
|
38
|
+
const value = body[field];
|
|
39
|
+
return typeof value === "string" ? value : void 0;
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
function initEldraClient(options) {
|
|
@@ -254,6 +257,8 @@ function createHttpRequest(clientOptions, requestOptions) {
|
|
|
254
257
|
const headers = mergeHeaders(resolveRuntimeValue(clientOptions.headers), requestOptions.headers);
|
|
255
258
|
const orgId = requestOptions.orgId ?? resolveOrgId(clientOptions);
|
|
256
259
|
if (orgId) headers.set("X-Org-Id", orgId);
|
|
260
|
+
const previewToken = resolveRuntimeValue(clientOptions.previewToken);
|
|
261
|
+
if (previewToken) headers.set("X-Preview-Token", previewToken);
|
|
257
262
|
let body;
|
|
258
263
|
if (requestOptions.body !== void 0) {
|
|
259
264
|
headers.set("Content-Type", headers.get("Content-Type") ?? "application/json");
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
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-
|
|
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";
|
|
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 {
|
|
5
5
|
readonly status: number;
|
|
6
6
|
readonly statusText: string;
|
|
7
7
|
readonly body: unknown;
|
|
8
|
-
/** The
|
|
8
|
+
/** The problem's category, such as `NOT_FOUND` or `CONFLICT`, when the body carried one. */
|
|
9
9
|
readonly code: string | undefined;
|
|
10
|
+
/** The problem's specific reason, such as `CART_NOT_FOUND`, when the body carried one. */
|
|
11
|
+
readonly errorId: string | undefined;
|
|
10
12
|
constructor(response: Response, body: unknown);
|
|
11
13
|
}
|
|
12
14
|
export declare function initEldraClient(options: EldraClientOptions): EldraClient;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as initEldraClient, i as getEldraClient, n as EldraHttpError, r as createEldraClient, t as DEFAULT_ELDRA_API_BASE_URL } from "./client-
|
|
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";
|
|
2
2
|
//#region src/storage.ts
|
|
3
3
|
const DEFAULT_CART_KEY = "eldra.cartId";
|
|
4
4
|
const DEFAULT_ORDER_TOKEN_PREFIX = "eldra.orderAccessToken.";
|
|
@@ -57,6 +57,8 @@ type EldraHttpClient = <T = unknown>(request: EldraHttpRequest) => Promise<T>;
|
|
|
57
57
|
interface EldraClientOptions {
|
|
58
58
|
apiBaseUrl?: RuntimeValue<string>;
|
|
59
59
|
orgId?: RuntimeValue<string>;
|
|
60
|
+
/** Sends X-Preview-Token on requests, overriding the same header in headers/context. */
|
|
61
|
+
previewToken?: RuntimeValue<string>;
|
|
60
62
|
env?: RuntimeValue<RuntimeEnv>;
|
|
61
63
|
headers?: RuntimeValue<HeadersInit>;
|
|
62
64
|
httpClient?: EldraHttpClient;
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { lt as RuntimeEnv, ut as RuntimeValue } from "./types-
|
|
1
|
+
import { lt as RuntimeEnv, ut as RuntimeValue } from "./types-CPUs_QPj.js";
|
|
2
2
|
import { Plugin } from "vite";
|
|
3
3
|
//#region src/vite-plugin.d.ts
|
|
4
4
|
export interface EldraVitePluginOptions {
|
|
5
5
|
apiBaseUrl?: RuntimeValue<string>;
|
|
6
6
|
orgId?: RuntimeValue<string>;
|
|
7
|
+
/** Sends X-Preview-Token when fetching types/contracts; never embedded in generated files. */
|
|
8
|
+
previewToken?: RuntimeValue<string>;
|
|
7
9
|
env?: RuntimeValue<RuntimeEnv>;
|
|
8
10
|
headers?: RuntimeValue<HeadersInit>;
|
|
9
11
|
schemas?: string[];
|
package/dist/vite.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./client-
|
|
1
|
+
import "./client-bg68WrsC.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";
|
|
@@ -65,9 +65,12 @@ async function generateEldraFiles(root, options, mode = process.env.NODE_ENV ??
|
|
|
65
65
|
const contractFileName = options.contractFileName ?? defaultContractFileName;
|
|
66
66
|
const clientFileName = options.clientFileName ?? defaultClientFileName;
|
|
67
67
|
const indexFileName = options.indexFileName ?? defaultIndexFileName;
|
|
68
|
+
const headers = new Headers(resolveRuntimeValue(options.headers));
|
|
69
|
+
const previewToken = resolveRuntimeValue(options.previewToken);
|
|
70
|
+
if (previewToken) headers.set("X-Preview-Token", previewToken);
|
|
68
71
|
const fetchOptions = {
|
|
69
72
|
fetch: options.fetch,
|
|
70
|
-
headers
|
|
73
|
+
headers
|
|
71
74
|
};
|
|
72
75
|
const result = {
|
|
73
76
|
written: [],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eldrajs/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
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",
|