@eldrajs/sdk 0.2.3 → 0.2.5
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,11 @@ platform repository.
|
|
|
9
9
|
|
|
10
10
|
## Unreleased
|
|
11
11
|
|
|
12
|
+
- `checkout.handoffUrl` defaults to the hosted checkout at `https://checkout.eldra.app` (exported
|
|
13
|
+
as `DEFAULT_ELDRA_CHECKOUT_URL`) when the client uses the default API base URL, so a production
|
|
14
|
+
storefront no longer needs a checkout URL setting. `checkoutUrl` and the `ELDRA_CHECKOUT_URL` env
|
|
15
|
+
keys still override it; a client on any other gateway must still name its checkout.
|
|
16
|
+
|
|
12
17
|
- `EldraHttpError.errorId` carries the problem's specific reason, such as `CART_NOT_FOUND` or
|
|
13
18
|
`CART_INSUFFICIENT_STOCK`. The docs told you to branch on `code` for these, but the gateway puts
|
|
14
19
|
them in `errorId`; `code` is only the category (`NOT_FOUND`, `CONFLICT`) and is unchanged.
|
|
@@ -7,6 +7,14 @@ const apiBaseUrlEnvKeys = [
|
|
|
7
7
|
"PUBLIC_ELDRA_API_BASE_URL"
|
|
8
8
|
];
|
|
9
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";
|
|
10
18
|
const orgIdEnvKeys = [
|
|
11
19
|
"ELDRA_ORG_ID",
|
|
12
20
|
"VITE_ELDRA_ORG_ID",
|
|
@@ -207,8 +215,8 @@ function createEldraClient(options) {
|
|
|
207
215
|
})
|
|
208
216
|
},
|
|
209
217
|
checkout: { handoffUrl: (handoff) => {
|
|
210
|
-
const checkoutUrl = handoff.checkoutUrl ??
|
|
211
|
-
if (!checkoutUrl) throw new Error(
|
|
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.`);
|
|
212
220
|
const orgId = handoff.orgId ?? resolveOrgId(options);
|
|
213
221
|
if (!orgId) throw new Error("Missing Web Studio organization ID.");
|
|
214
222
|
const url = new URL(`${checkoutUrl.replace(/\/$/, "")}/checkout/${encodeURIComponent(orgId)}/${encodeURIComponent(handoff.cartId)}`);
|
|
@@ -296,6 +304,9 @@ function readResponseBody(response) {
|
|
|
296
304
|
function resolveApiBaseUrl(options) {
|
|
297
305
|
return resolveRuntimeValue(options.apiBaseUrl) ?? readFirstEnvValue(resolveRuntimeValue(options.env), apiBaseUrlEnvKeys) ?? "https://web.eldra.app/api";
|
|
298
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
|
+
}
|
|
299
310
|
function resolveOrgId(options) {
|
|
300
311
|
return resolveRuntimeValue(options.orgId) ?? readFirstEnvValue(resolveRuntimeValue(options.env), orgIdEnvKeys);
|
|
301
312
|
}
|
|
@@ -333,4 +344,4 @@ function isRawBody(body) {
|
|
|
333
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;
|
|
334
345
|
}
|
|
335
346
|
//#endregion
|
|
336
|
-
export {
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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-C0yabGuL.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";
|
|
4
5
|
export declare class EldraHttpError extends Error {
|
|
5
6
|
readonly status: number;
|
|
6
7
|
readonly statusText: string;
|
|
@@ -46,4 +47,24 @@ export declare function createCartSession(options?: EldraCartSessionOptions): El
|
|
|
46
47
|
*/
|
|
47
48
|
export declare function createOrderAccessTokens(options?: EldraOrderAccessTokenOptions): EldraOrderAccessTokens;
|
|
48
49
|
//#endregion
|
|
49
|
-
|
|
50
|
+
//#region src/tracker.d.ts
|
|
51
|
+
interface EldraTrackerScriptOptions extends Pick<EldraClientOptions, 'apiBaseUrl' | 'orgId' | 'env'> {
|
|
52
|
+
/** Origin that receives events when the script is served through a first-party proxy. */
|
|
53
|
+
eventOrigin?: string;
|
|
54
|
+
}
|
|
55
|
+
/** Attributes of the `<script>` tag that loads the Eldra analytics tracker. */
|
|
56
|
+
interface EldraTrackerScript {
|
|
57
|
+
src: string;
|
|
58
|
+
defer: true;
|
|
59
|
+
crossorigin: 'anonymous';
|
|
60
|
+
'data-org': string;
|
|
61
|
+
'data-api'?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Builds the tracker `<script>` attributes from the same configuration the client uses, so the
|
|
65
|
+
* tracker always reports to the gateway the site reads from. Returns `undefined` when no
|
|
66
|
+
* organisation id is configured, which is the case in builds that should not report at all.
|
|
67
|
+
*/
|
|
68
|
+
export declare function analyticsTrackerScript(options?: EldraTrackerScriptOptions): EldraTrackerScript | undefined;
|
|
69
|
+
//#endregion
|
|
70
|
+
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, 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, EldraSearchOptions, EldraSearchResponse, EldraStockAvailability, EldraStockAvailabilityInput, EldraStockAvailabilityItem, EldraTrackerScript, EldraTrackerScriptOptions, RuntimeEnv, RuntimeValue };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
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";
|
|
2
2
|
//#region src/storage.ts
|
|
3
3
|
const DEFAULT_CART_KEY = "eldra.cartId";
|
|
4
4
|
const DEFAULT_ORDER_TOKEN_PREFIX = "eldra.orderAccessToken.";
|
|
@@ -47,4 +47,23 @@ function createOrderAccessTokens(options = {}) {
|
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
//#endregion
|
|
50
|
-
|
|
50
|
+
//#region src/tracker.ts
|
|
51
|
+
/**
|
|
52
|
+
* Builds the tracker `<script>` attributes from the same configuration the client uses, so the
|
|
53
|
+
* tracker always reports to the gateway the site reads from. Returns `undefined` when no
|
|
54
|
+
* organisation id is configured, which is the case in builds that should not report at all.
|
|
55
|
+
*/
|
|
56
|
+
function analyticsTrackerScript(options = {}) {
|
|
57
|
+
const orgId = resolveOrgId(options);
|
|
58
|
+
if (!orgId) return;
|
|
59
|
+
const script = {
|
|
60
|
+
src: `${new URL(resolveApiBaseUrl(options)).origin}/js/script.js`,
|
|
61
|
+
defer: true,
|
|
62
|
+
crossorigin: "anonymous",
|
|
63
|
+
"data-org": orgId
|
|
64
|
+
};
|
|
65
|
+
if (options.eventOrigin) script["data-api"] = options.eventOrigin;
|
|
66
|
+
return script;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { DEFAULT_ELDRA_API_BASE_URL, DEFAULT_ELDRA_CHECKOUT_URL, EldraHttpError, analyticsTrackerScript, createCartSession, createEldraClient, createOrderAccessTokens, getEldraClient, initEldraClient };
|
|
@@ -63,7 +63,10 @@ interface EldraClientOptions {
|
|
|
63
63
|
headers?: RuntimeValue<HeadersInit>;
|
|
64
64
|
httpClient?: EldraHttpClient;
|
|
65
65
|
fetch?: typeof fetch;
|
|
66
|
-
/**
|
|
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
|
+
*/
|
|
67
70
|
checkoutUrl?: RuntimeValue<string>;
|
|
68
71
|
}
|
|
69
72
|
interface EldraPaginationOptions {
|
package/dist/vite.d.ts
CHANGED
package/dist/vite.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eldrajs/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
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",
|