@eldrajs/sdk 0.4.1 → 0.4.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 +9 -0
- package/README.md +16 -0
- package/dist/{client-DLMV5fcx.js → client-C7hMOeGA.js} +4 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{types-CiA-DRIp.d.ts → types-BN7Y-C9T.d.ts} +11 -8
- package/dist/vite.d.ts +2 -1
- package/dist/vite.js +14 -4
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,15 @@ platform repository.
|
|
|
9
9
|
|
|
10
10
|
## Unreleased
|
|
11
11
|
|
|
12
|
+
- **Typed product extensions (WS-439, contract 6.1.0).** `EldraProductDetails.extensions` is keyed by
|
|
13
|
+
the apiId of each CMS schema that extends products, and its type is the new, initially empty
|
|
14
|
+
`EldraProductExtensions` registry. The CMS types the Vite plugin writes now fill it in (`eldra-theme types` writes the
|
|
15
|
+
same augmentation, for `@eldrajs/sdk`; both ask the gateway for it with `sdkAugmentation=true`, so any other
|
|
16
|
+
consumer of `/cms/v1/typescript-definitions` gets plain interfaces with no `declare module`), so `product.extensions?.clothing?.material` type-checks; before generation it is
|
|
17
|
+
`{}`, not `unknown`. If you set the plugin's `sdkImport`, the augmentation in `cms-types.ts` names that import;
|
|
18
|
+
`eldra-theme types` has no such option and always targets `@eldrajs/sdk` (`--no-sdk-augmentation` leaves the block out).
|
|
19
|
+
Needs a gateway on contract 6.1.0 or later to return `extensions`.
|
|
20
|
+
|
|
12
21
|
- **`installIcelandicIntl()` (new entry `@eldrajs/sdk/format/intl`)** — Icelandic for code that calls
|
|
13
22
|
`Intl` itself (date pickers, vue-i18n, chart libraries). Where the runtime has no Icelandic data,
|
|
14
23
|
it patches `Intl.NumberFormat`, `Intl.DateTimeFormat`, `Number.prototype.toLocaleString` and
|
package/README.md
CHANGED
|
@@ -33,6 +33,22 @@ actually returns. Commit the folder; it is what your CI type-checks against, and
|
|
|
33
33
|
you see the API change. Without the plugin, responses are `unknown` and you name the type at the
|
|
34
34
|
call site.
|
|
35
35
|
|
|
36
|
+
### Product extensions
|
|
37
|
+
|
|
38
|
+
A CMS schema flagged "extends products" attaches its fields to every product. The generated
|
|
39
|
+
`cms-types.ts` types them by schema apiId, so for a `clothing` schema:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const product = await eldra.catalog.getProduct(id);
|
|
43
|
+
product.extensions?.clothing?.material; // string | undefined
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The Vite plugin (and `eldra-theme types`) request the `declare module '@eldrajs/sdk'` block with
|
|
47
|
+
`sdkAugmentation=true`; the endpoint omits it otherwise, so a project that does not use the SDK is never
|
|
48
|
+
handed a module it cannot resolve. `eldra-theme types --no-sdk-augmentation` leaves it out.
|
|
49
|
+
|
|
50
|
+
`extensions` is absent when a product has none. Without generated types it is `{}`: nothing to read.
|
|
51
|
+
|
|
36
52
|
The full walkthrough is [docs/getting-started.md](../../docs/getting-started.md).
|
|
37
53
|
|
|
38
54
|
## Preview mode
|
|
@@ -886,8 +886,8 @@ function buildUrl(apiBaseUrl, path, query) {
|
|
|
886
886
|
* `filter` has to be in here — a filter token is `[groupIndex:]field:op:value`
|
|
887
887
|
* whose value may itself contain commas (`slug:in:a,b`), so joining several
|
|
888
888
|
* tokens into one parameter runs them together and every token after the first
|
|
889
|
-
* is lost. The catalog product filters (`categoryId`, `collectionId`, `option
|
|
890
|
-
* on `GET /catalog/v1/products/list` and
|
|
889
|
+
* is lost. The catalog product filters (`categoryId`, `collectionId`, `option`,
|
|
890
|
+
* `ext` on `GET /catalog/v1/products/list` and
|
|
891
891
|
* `GET /catalog/v1/collections/{slug}/products`) are declared the same way, and
|
|
892
892
|
* each is an OR over its values: comma-joined, `categoryId=a,b` is one id the
|
|
893
893
|
* catalogue has never heard of, so a shopper ticking two categories would see
|
|
@@ -897,7 +897,8 @@ const REPEATED_QUERY_KEYS = /* @__PURE__ */ new Set([
|
|
|
897
897
|
"filter",
|
|
898
898
|
"categoryId",
|
|
899
899
|
"collectionId",
|
|
900
|
-
"option"
|
|
900
|
+
"option",
|
|
901
|
+
"ext"
|
|
901
902
|
]);
|
|
902
903
|
function appendQueryValue(searchParams, key, value) {
|
|
903
904
|
if (value === void 0 || value === null || value === "") return;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as EldraOrganizationFeature, A as EldraFeature, At as
|
|
1
|
+
import { $ as EldraOrganizationFeature, A as EldraFeature, At as EldraContractItem, B as EldraFormSubmitResult, Bt as clearCampaignAttribution, C as EldraCmsResolveEntryListResponse, Ct as EldraStockAvailability, D as EldraCollectionListOptions, Dt as RuntimeValue, E as EldraCollectionList, Et as RuntimeEnv, F as EldraFormField, Ft as EldraContractQuery, G as EldraInventoryClient, Gt as EldraCartSessionOptions, H as EldraFormsClient, Ht as readCampaignAttribution, I as EldraFormFieldOption, It as EldraContractResponse, J as EldraOrderLine, Jt as EldraOrderAccessTokens, K as EldraLocaleOptions, Kt as EldraKeyValueStorage, L as EldraFormFieldType, Lt as EldraCampaignAttribution, M as EldraFeatureClient, Mt as EldraContractPath, N as EldraFormActionKind, Nt as EldraContractPaths, O as EldraCollectionProductsOptions, Ot as EldraContract, P as EldraFormDefinition, Pt as EldraContractProp, Q as EldraOrganizationDetails, R as EldraFormLocalized, Rt as EldraCampaignAttributionOptions, S as EldraCmsResolveEntryListOptions, St as EldraSearchResponse, T as EldraCollection, Tt as EldraStockAvailabilityItem, U as EldraHttpClient, Ut as withdrawCampaignAttributionConsent, V as EldraFormTokenResult, Vt as grantCampaignAttributionConsent, W as EldraHttpRequest, Wt as EldraCartSession, X as EldraOrdersClient, Xt as createOrderAccessTokens, Y as EldraOrderReadOptions, Yt as createCartSession, Z as EldraOrganizationCommerce, _ as EldraCmsEntryListEntry, _t as EldraRecoveredBasketItem, a as EldraCartTotals, at as EldraPlatformConfig, b as EldraCmsGetOptions, bt as EldraRetryOptions, c as EldraCatalogListProductsOptions, ct as EldraProductExtensions, d as EldraCheckoutUrlOptions, dt as EldraProductMediaLink, et as EldraOrganizationLocales, f as EldraClient, ft as EldraProductOption, g as EldraCmsEntryListDisplayMode, gt as EldraRecoveredBasket, h as EldraCmsEntryList, ht as EldraProductVariant, i as EldraCartItem, it as EldraPlatformClient, j as EldraFeatureCapabilities, jt as EldraContractMethod, k as EldraDiscountResult, kt as EldraContractBody, l as EldraCategory, lt as EldraProductList, m as EldraCmsClient, mt as EldraProductThumbnail, n as EldraCart, nt as EldraPageMeta, o as EldraCatalogClient, ot as EldraPlatformReadOptions, p as EldraClientOptions, pt as EldraProductOptionValue, q as EldraOrder, qt as EldraOrderAccessTokenOptions, r as EldraCartClient, rt as EldraPaginated, s as EldraCatalogGetProductOptions, st as EldraProductDetails, t as EldraAddCartItemInput, tt as EldraOrganizationOptions, u as EldraCheckoutClient, ut as EldraProductListItem, v as EldraCmsEntryListFilterCriterion, vt as EldraRequestContext, w as EldraCmsResolvedEntryList, wt as EldraStockAvailabilityInput, x as EldraCmsListOptions, xt as EldraSearchOptions, y as EldraCmsGetEntryByUniqueFieldOptions, yt as EldraRequestOptions, z as EldraFormSubmitInput, zt as captureCampaignAttribution } from "./types-BN7Y-C9T.js";
|
|
2
2
|
export declare const DEFAULT_ELDRA_API_BASE_URL = "https://web.eldra.app/api";
|
|
3
3
|
export declare class EldraHttpError extends Error {
|
|
4
4
|
readonly status: number;
|
|
@@ -114,4 +114,4 @@ interface EldraResponsiveImage {
|
|
|
114
114
|
* as `src` and no `srcset`. Returns `undefined` when there is no URL to render.
|
|
115
115
|
*/
|
|
116
116
|
export declare function responsiveImage(source: EldraImageSource, options: EldraResponsiveImageOptions): EldraResponsiveImage | undefined;
|
|
117
|
-
export { type EldraAddCartItemInput, type EldraCampaignAttribution, type EldraCampaignAttributionOptions, type EldraCart, type EldraCartClient, type EldraCartItem, type EldraCartSession, type EldraCartSessionOptions, type EldraCartTotals, type EldraCatalogClient, type EldraCatalogGetProductOptions, type EldraCatalogListProductsOptions, type EldraCategory, type EldraCheckoutClient, type EldraCheckoutUrlOptions, type EldraClient, type EldraClientOptions, type EldraCmsClient, type EldraCmsEntryList, type EldraCmsEntryListDisplayMode, type EldraCmsEntryListEntry, type EldraCmsEntryListFilterCriterion, type EldraCmsGetEntryByUniqueFieldOptions, type EldraCmsGetOptions, type EldraCmsListOptions, type EldraCmsResolveEntryListOptions, type EldraCmsResolveEntryListResponse, type EldraCmsResolvedEntryList, type EldraCollection, type EldraCollectionList, type EldraCollectionListOptions, type EldraCollectionProductsOptions, type EldraContract, type EldraContractBody, type EldraContractItem, type EldraContractMethod, type EldraContractPath, type EldraContractPaths, type EldraContractProp, type EldraContractQuery, type EldraContractResponse, type EldraDiscountResult, type EldraFeature, type EldraFeatureCapabilities, type EldraFeatureClient, type EldraFormActionKind, type EldraFormDefinition, type EldraFormField, type EldraFormFieldOption, type EldraFormFieldType, type EldraFormLocalized, type EldraFormSubmitInput, type EldraFormSubmitResult, type EldraFormTokenResult, type EldraFormsClient, type EldraHttpClient, type EldraHttpRequest, type EldraImageSource, type EldraImageSrcsetOptions, type EldraImageVariant, type EldraInventoryClient, type EldraKeyValueStorage, type EldraLocaleOptions, type EldraOrder, type EldraOrderAccessTokenOptions, type EldraOrderAccessTokens, type EldraOrderLine, type EldraOrderReadOptions, type EldraOrdersClient, type EldraOrganizationCommerce, type EldraOrganizationDetails, type EldraOrganizationFeature, type EldraOrganizationLocales, type EldraOrganizationOptions, type EldraPageMeta, type EldraPaginated, type EldraPlatformClient, type EldraPlatformConfig, type EldraPlatformReadOptions, type EldraProductDetails, type EldraProductList, type EldraProductListItem, type EldraProductMediaLink, type EldraProductOption, type EldraProductOptionValue, type EldraProductThumbnail, type EldraProductVariant, type EldraRecoveredBasket, type EldraRecoveredBasketItem, type EldraRequestContext, type EldraRequestOptions, type EldraResponsiveImage, type EldraResponsiveImageOptions, type EldraRetryOptions, type EldraSearchOptions, type EldraSearchResponse, type EldraSizedImageVariant, type EldraStockAvailability, type EldraStockAvailabilityInput, type EldraStockAvailabilityItem, type EldraTrackerScript, type EldraTrackerScriptOptions, type RuntimeEnv, type RuntimeValue, captureCampaignAttribution, clearCampaignAttribution, createCartSession, createOrderAccessTokens, grantCampaignAttributionConsent, readCampaignAttribution, withdrawCampaignAttributionConsent };
|
|
117
|
+
export { type EldraAddCartItemInput, type EldraCampaignAttribution, type EldraCampaignAttributionOptions, type EldraCart, type EldraCartClient, type EldraCartItem, type EldraCartSession, type EldraCartSessionOptions, type EldraCartTotals, type EldraCatalogClient, type EldraCatalogGetProductOptions, type EldraCatalogListProductsOptions, type EldraCategory, type EldraCheckoutClient, type EldraCheckoutUrlOptions, type EldraClient, type EldraClientOptions, type EldraCmsClient, type EldraCmsEntryList, type EldraCmsEntryListDisplayMode, type EldraCmsEntryListEntry, type EldraCmsEntryListFilterCriterion, type EldraCmsGetEntryByUniqueFieldOptions, type EldraCmsGetOptions, type EldraCmsListOptions, type EldraCmsResolveEntryListOptions, type EldraCmsResolveEntryListResponse, type EldraCmsResolvedEntryList, type EldraCollection, type EldraCollectionList, type EldraCollectionListOptions, type EldraCollectionProductsOptions, type EldraContract, type EldraContractBody, type EldraContractItem, type EldraContractMethod, type EldraContractPath, type EldraContractPaths, type EldraContractProp, type EldraContractQuery, type EldraContractResponse, type EldraDiscountResult, type EldraFeature, type EldraFeatureCapabilities, type EldraFeatureClient, type EldraFormActionKind, type EldraFormDefinition, type EldraFormField, type EldraFormFieldOption, type EldraFormFieldType, type EldraFormLocalized, type EldraFormSubmitInput, type EldraFormSubmitResult, type EldraFormTokenResult, type EldraFormsClient, type EldraHttpClient, type EldraHttpRequest, type EldraImageSource, type EldraImageSrcsetOptions, type EldraImageVariant, type EldraInventoryClient, type EldraKeyValueStorage, type EldraLocaleOptions, type EldraOrder, type EldraOrderAccessTokenOptions, type EldraOrderAccessTokens, type EldraOrderLine, type EldraOrderReadOptions, type EldraOrdersClient, type EldraOrganizationCommerce, type EldraOrganizationDetails, type EldraOrganizationFeature, type EldraOrganizationLocales, type EldraOrganizationOptions, type EldraPageMeta, type EldraPaginated, type EldraPlatformClient, type EldraPlatformConfig, type EldraPlatformReadOptions, type EldraProductDetails, type EldraProductExtensions, type EldraProductList, type EldraProductListItem, type EldraProductMediaLink, type EldraProductOption, type EldraProductOptionValue, type EldraProductThumbnail, type EldraProductVariant, type EldraRecoveredBasket, type EldraRecoveredBasketItem, type EldraRequestContext, type EldraRequestOptions, type EldraResponsiveImage, type EldraResponsiveImageOptions, type EldraRetryOptions, type EldraSearchOptions, type EldraSearchResponse, type EldraSizedImageVariant, type EldraStockAvailability, type EldraStockAvailabilityInput, type EldraStockAvailabilityItem, type EldraTrackerScript, type EldraTrackerScriptOptions, type RuntimeEnv, type RuntimeValue, captureCampaignAttribution, clearCampaignAttribution, createCartSession, createOrderAccessTokens, grantCampaignAttributionConsent, readCampaignAttribution, withdrawCampaignAttributionConsent };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as initEldraClient, c as captureCampaignAttribution, d as readCampaignAttribution, f as withdrawCampaignAttributionConsent, i as getEldraClient, l as clearCampaignAttribution, m as createOrderAccessTokens, n as EldraHttpError, o as resolveApiBaseUrl, p as createCartSession, r as createEldraClient, s as resolveOrgId, t as DEFAULT_ELDRA_API_BASE_URL, u as grantCampaignAttributionConsent } from "./client-
|
|
1
|
+
import { a as initEldraClient, c as captureCampaignAttribution, d as readCampaignAttribution, f as withdrawCampaignAttributionConsent, i as getEldraClient, l as clearCampaignAttribution, m as createOrderAccessTokens, n as EldraHttpError, o as resolveApiBaseUrl, p as createCartSession, r as createEldraClient, s as resolveOrgId, t as DEFAULT_ELDRA_API_BASE_URL, u as grantCampaignAttributionConsent } from "./client-C7hMOeGA.js";
|
|
2
2
|
// src/tracker.ts
|
|
3
3
|
/**
|
|
4
4
|
* Builds the tracker `<script>` attributes from the same configuration the client uses, so the
|
|
@@ -62,10 +62,10 @@ interface EldraContract {}
|
|
|
62
62
|
type Paths = EldraContract extends {
|
|
63
63
|
paths: infer P;
|
|
64
64
|
} ? P : never;
|
|
65
|
-
type Generated = [Paths] extends [never] ? false : true;
|
|
65
|
+
type Generated$1 = [Paths] extends [never] ? false : true;
|
|
66
66
|
type EldraContractPaths = Paths;
|
|
67
|
-
type EldraContractPath = Generated extends true ? keyof Paths : string;
|
|
68
|
-
type EldraContractMethod<Path extends EldraContractPath> = Generated extends true ? keyof Paths[Path & keyof Paths] : string;
|
|
67
|
+
type EldraContractPath = Generated$1 extends true ? keyof Paths : string;
|
|
68
|
+
type EldraContractMethod<Path extends EldraContractPath> = Generated$1 extends true ? keyof Paths[Path & keyof Paths] : string;
|
|
69
69
|
type Operation<Path, Method> = Path extends keyof Paths ? Method extends keyof Paths[Path] ? Paths[Path][Method] : never : never;
|
|
70
70
|
type JsonContent<Response> = Response extends {
|
|
71
71
|
content: {
|
|
@@ -77,13 +77,13 @@ type SuccessResponse<Responses> = Responses extends {
|
|
|
77
77
|
} ? JsonContent<Response> : Responses extends {
|
|
78
78
|
201: infer Response;
|
|
79
79
|
} ? JsonContent<Response> : never;
|
|
80
|
-
type EldraContractResponse<Path extends EldraContractPath, Method extends EldraContractMethod<Path>> = Generated extends true ? Operation<Path, Method> extends {
|
|
80
|
+
type EldraContractResponse<Path extends EldraContractPath, Method extends EldraContractMethod<Path>> = Generated$1 extends true ? Operation<Path, Method> extends {
|
|
81
81
|
responses: infer Responses;
|
|
82
82
|
} ? SuccessResponse<Responses> : never : unknown;
|
|
83
|
-
type EldraContractBody<Path extends EldraContractPath, Method extends EldraContractMethod<Path>> = Generated extends true ? Operation<Path, Method> extends {
|
|
83
|
+
type EldraContractBody<Path extends EldraContractPath, Method extends EldraContractMethod<Path>> = Generated$1 extends true ? Operation<Path, Method> extends {
|
|
84
84
|
requestBody?: infer Body;
|
|
85
85
|
} ? JsonContent<NonNullable<Body>> : never : Record<string, unknown>;
|
|
86
|
-
type EldraContractQuery<Path extends EldraContractPath, Method extends EldraContractMethod<Path>> = Generated extends true ? Operation<Path, Method> extends {
|
|
86
|
+
type EldraContractQuery<Path extends EldraContractPath, Method extends EldraContractMethod<Path>> = Generated$1 extends true ? Operation<Path, Method> extends {
|
|
87
87
|
parameters: {
|
|
88
88
|
query?: infer Query;
|
|
89
89
|
};
|
|
@@ -301,7 +301,10 @@ interface EldraCmsClient {
|
|
|
301
301
|
}
|
|
302
302
|
type EldraProductList = EldraContractResponse<'/catalog/v1/products/list', 'get'>;
|
|
303
303
|
type EldraProductListItem = EldraContractItem<EldraContractProp<EldraProductList, 'data'>>;
|
|
304
|
-
|
|
304
|
+
interface EldraProductExtensions {}
|
|
305
|
+
type EldraProductDetails = EldraContractResponse<'/catalog/v1/products/{productId}', 'get'> extends (infer Generated) ? unknown extends Generated ? unknown : Omit<Generated, 'extensions'> & {
|
|
306
|
+
extensions?: EldraProductExtensions;
|
|
307
|
+
} : never;
|
|
305
308
|
type EldraProductVariant = EldraContractItem<EldraContractProp<EldraProductDetails, 'variants'>>;
|
|
306
309
|
type EldraProductOption = EldraContractItem<EldraContractProp<EldraProductDetails, 'options'>>;
|
|
307
310
|
type EldraProductOptionValue = EldraContractItem<EldraContractProp<EldraProductOption, 'values'>>;
|
|
@@ -547,4 +550,4 @@ interface EldraFormsClient {
|
|
|
547
550
|
/** `POST /site/v1/forms/subscriptions/unsubscribe?token=` (a GET of the link is only a page). */
|
|
548
551
|
unsubscribe(token: string, context?: EldraRequestContext): Promise<EldraFormTokenResult>;
|
|
549
552
|
}
|
|
550
|
-
export { EldraOrganizationFeature as $, EldraFeature as A,
|
|
553
|
+
export { EldraOrganizationFeature as $, EldraFeature as A, EldraContractItem as At, EldraFormSubmitResult as B, clearCampaignAttribution as Bt, EldraCmsResolveEntryListResponse as C, EldraStockAvailability as Ct, EldraCollectionListOptions as D, RuntimeValue as Dt, EldraCollectionList as E, RuntimeEnv as Et, EldraFormField as F, EldraContractQuery as Ft, EldraInventoryClient as G, EldraCartSessionOptions as Gt, EldraFormsClient as H, readCampaignAttribution as Ht, EldraFormFieldOption as I, EldraContractResponse as It, EldraOrderLine as J, EldraOrderAccessTokens as Jt, EldraLocaleOptions as K, EldraKeyValueStorage as Kt, EldraFormFieldType as L, EldraCampaignAttribution as Lt, EldraFeatureClient as M, EldraContractPath as Mt, EldraFormActionKind as N, EldraContractPaths as Nt, EldraCollectionProductsOptions as O, EldraContract as Ot, EldraFormDefinition as P, EldraContractProp as Pt, EldraOrganizationDetails as Q, EldraFormLocalized as R, EldraCampaignAttributionOptions as Rt, EldraCmsResolveEntryListOptions as S, EldraSearchResponse as St, EldraCollection as T, EldraStockAvailabilityItem as Tt, EldraHttpClient as U, withdrawCampaignAttributionConsent as Ut, EldraFormTokenResult as V, grantCampaignAttributionConsent as Vt, EldraHttpRequest as W, EldraCartSession as Wt, EldraOrdersClient as X, createOrderAccessTokens as Xt, EldraOrderReadOptions as Y, createCartSession as Yt, EldraOrganizationCommerce as Z, EldraCmsEntryListEntry as _, EldraRecoveredBasketItem as _t, EldraCartTotals as a, EldraPlatformConfig as at, EldraCmsGetOptions as b, EldraRetryOptions as bt, EldraCatalogListProductsOptions as c, EldraProductExtensions as ct, EldraCheckoutUrlOptions as d, EldraProductMediaLink as dt, EldraOrganizationLocales as et, EldraClient as f, EldraProductOption as ft, EldraCmsEntryListDisplayMode as g, EldraRecoveredBasket as gt, EldraCmsEntryList as h, EldraProductVariant as ht, EldraCartItem as i, EldraPlatformClient as it, EldraFeatureCapabilities as j, EldraContractMethod as jt, EldraDiscountResult as k, EldraContractBody as kt, EldraCategory as l, EldraProductList as lt, EldraCmsClient as m, EldraProductThumbnail as mt, EldraCart as n, EldraPageMeta as nt, EldraCatalogClient as o, EldraPlatformReadOptions as ot, EldraClientOptions as p, EldraProductOptionValue as pt, EldraOrder as q, EldraOrderAccessTokenOptions as qt, EldraCartClient as r, EldraPaginated as rt, EldraCatalogGetProductOptions as s, EldraProductDetails as st, EldraAddCartItemInput as t, EldraOrganizationOptions as tt, EldraCheckoutClient as u, EldraProductListItem as ut, EldraCmsEntryListFilterCriterion as v, EldraRequestContext as vt, EldraCmsResolvedEntryList as w, EldraStockAvailabilityInput as wt, EldraCmsListOptions as x, EldraSearchOptions as xt, EldraCmsGetEntryByUniqueFieldOptions as y, EldraRequestOptions as yt, EldraFormSubmitInput as z, captureCampaignAttribution as zt };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Dt as RuntimeValue, Et as RuntimeEnv } from "./types-BN7Y-C9T.js";
|
|
2
2
|
import { Plugin } from "vite";
|
|
3
3
|
export interface EldraVitePluginOptions {
|
|
4
4
|
apiBaseUrl?: RuntimeValue<string>;
|
|
@@ -32,6 +32,7 @@ export interface EldraGenerationResult {
|
|
|
32
32
|
}
|
|
33
33
|
export declare function eldra(options?: EldraVitePluginOptions): Plugin;
|
|
34
34
|
export declare function generateEldraFiles(root: string, options: EldraVitePluginOptions, mode?: string): Promise<EldraGenerationResult>;
|
|
35
|
+
export declare function retargetSdkAugmentation(source: string, sdkImport: string): string;
|
|
35
36
|
export declare function createContractSource(document: unknown, options?: {
|
|
36
37
|
sdkImport?: string;
|
|
37
38
|
source?: URL | string;
|
package/dist/vite.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./client-
|
|
1
|
+
import "./client-C7hMOeGA.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";
|
|
@@ -80,7 +80,8 @@ async function generateEldraFiles(root, options, mode = process.env.NODE_ENV ??
|
|
|
80
80
|
...fetchOptions,
|
|
81
81
|
maxDepth: options.maxDepth,
|
|
82
82
|
moduleName,
|
|
83
|
-
schemas: options.schemas
|
|
83
|
+
schemas: options.schemas,
|
|
84
|
+
sdkImport
|
|
84
85
|
}));
|
|
85
86
|
const contractSource = options.contract === false ? void 0 : await attempt("Gateway contract", result, () => fetchContract(apiBaseUrl, orgId, {
|
|
86
87
|
...fetchOptions,
|
|
@@ -110,13 +111,22 @@ async function generateEldraFiles(root, options, mode = process.env.NODE_ENV ??
|
|
|
110
111
|
async function fetchCmsTypes(apiBaseUrl, orgId, options) {
|
|
111
112
|
const url = new URL(`${trimSlash(apiBaseUrl)}/cms/v1/typescript-definitions`);
|
|
112
113
|
url.searchParams.set("moduleName", options.moduleName);
|
|
114
|
+
url.searchParams.set("sdkAugmentation", "true");
|
|
113
115
|
if (options.maxDepth !== void 0) url.searchParams.set("maxDepth", String(options.maxDepth));
|
|
114
116
|
if (options.schemas && options.schemas.length > 0) url.searchParams.set("schemas", options.schemas.join(","));
|
|
115
117
|
const body = await fetchText(url, orgId, {
|
|
116
118
|
...options,
|
|
117
119
|
accept: "text/plain"
|
|
118
120
|
});
|
|
119
|
-
return body.endsWith("\n") ? body : `${body}\n
|
|
121
|
+
return retargetSdkAugmentation(body.endsWith("\n") ? body : `${body}\n`, options.sdkImport);
|
|
122
|
+
}
|
|
123
|
+
function retargetSdkAugmentation(source, sdkImport) {
|
|
124
|
+
if (sdkImport === defaultSdkImport) return source;
|
|
125
|
+
const declaration = new RegExp(`declare\\s+module\\s+(['"])${escapeRegExp(defaultSdkImport)}\\1`, "g");
|
|
126
|
+
return source.replace(declaration, (_match, quote) => `declare module ${quote}${sdkImport}${quote}`);
|
|
127
|
+
}
|
|
128
|
+
function escapeRegExp(value) {
|
|
129
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
120
130
|
}
|
|
121
131
|
async function fetchContract(apiBaseUrl, orgId, options) {
|
|
122
132
|
const url = new URL(`${trimSlash(apiBaseUrl)}/public/openapi.json`);
|
|
@@ -243,4 +253,4 @@ function stripTSExtension(path) {
|
|
|
243
253
|
function pascalTypeName(value) {
|
|
244
254
|
return value.split(/[^A-Za-z0-9]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
245
255
|
}
|
|
246
|
-
export { createContractSource, eldra, generateEldraFiles };
|
|
256
|
+
export { createContractSource, eldra, generateEldraFiles, retargetSdkAugmentation };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eldrajs/sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
},
|
|
91
91
|
"scripts": {
|
|
92
92
|
"build": "tsdown",
|
|
93
|
-
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.generated.json",
|
|
93
|
+
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.generated.json && tsc -p tsconfig.generated-bare.json",
|
|
94
94
|
"test": "vitest run",
|
|
95
95
|
"fixture": "node scripts/fixture.mjs",
|
|
96
96
|
"format-data": "node scripts/extract-format-data.mjs",
|