@eldrajs/sdk 0.5.1 → 0.5.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 +5 -0
- package/README.md +2 -2
- package/dist/{client-cO8GCJK9.js → client-Bh_8g5xj.js} +18 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +9 -7
- package/dist/{types-BrQEYrD5.d.ts → types-COJLLz9z.d.ts} +25 -2
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,11 @@ platform repository.
|
|
|
9
9
|
|
|
10
10
|
## Unreleased
|
|
11
11
|
|
|
12
|
+
- **Selling in more than one currency (WS-1391; contracts 6.19.0, 6.20.0, 6.21.0).** `createCurrencyPreference()` keeps the currency a visitor picked (`read`, `remember`, `forget`; `localStorage` `eldra.currency`); `cart.setCurrency(cartId, currency)` changes a cart's currency (`PUT /shopping-cart/v1/cart/{cartID}/currency`); `catalog.getProduct` takes `currency`; `EldraOrganizationCommerce` carries `currencies` (what the storefront may offer, the store currency first); `paymentProviders` on the organisation is typed as `EldraOrganizationPaymentProvider[]`, each with the `currencies` it takes (missing means ISK only).
|
|
13
|
+
- **A 3840 px image variant, `uhd`.** A full-width image on a high-density screen wants about 3840 px, and
|
|
14
|
+
`full` stops at 2560. `imageSrcset` now lists `…/uhd 3840w` after `full`, `imageVariantFor` falls back to
|
|
15
|
+
`uhd` instead of `full`, and the original is listed only when it is wider than 3840 px.
|
|
16
|
+
`ELDRA_IMAGE_VARIANT_WIDTHS` and `EldraImageVariant` carry it. It needs the media host that serves `uhd`.
|
|
12
17
|
- **Removed: the checkout summary types.** `EldraOrderPreview`, `EldraOrderPreviewGiftCard` and
|
|
13
18
|
`EldraOrderPreviewDiscountCode` are no longer exported. They typed `POST /order/v1/preview`, which the SDK
|
|
14
19
|
never had a method for: delivery choice, the order summary, order creation and payment belong to the hosted
|
package/README.md
CHANGED
|
@@ -276,5 +276,5 @@ Every failed request throws `EldraHttpError` with `status`, the problem's catego
|
|
|
276
276
|
that says more carries it in `errors`, the problem's `errors` object: a discount code refused with
|
|
277
277
|
`CART_DISCOUNT_NOT_COMBINABLE` names the code on the cart that blocks it in `errors.blockingCode`,
|
|
278
278
|
and `CART_DISCOUNT_CODES_LIMIT_REACHED` the limit (6) in `errors.limit`.
|
|
279
|
-
`createCartSession` and `createOrderAccessTokens` persist the cart id
|
|
280
|
-
throwing where storage is unavailable.
|
|
279
|
+
`createCartSession`, `createCurrencyPreference` and `createOrderAccessTokens` persist the cart id,
|
|
280
|
+
the visitor's chosen currency and order tokens without throwing where storage is unavailable.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/storage.ts
|
|
2
2
|
const DEFAULT_CART_KEY = "eldra.cartId";
|
|
3
|
+
const DEFAULT_CURRENCY_KEY = "eldra.currency";
|
|
3
4
|
const DEFAULT_ORDER_TOKEN_PREFIX = "eldra.orderAccessToken.";
|
|
4
5
|
function browserStorage(name) {
|
|
5
6
|
try {
|
|
@@ -35,6 +36,16 @@ function createCartSession(options = {}) {
|
|
|
35
36
|
* The one-time order access token, kept in sessionStorage rather than the return URL so it
|
|
36
37
|
* survives the payment provider's redirect without landing in a URL, a log or a Referer.
|
|
37
38
|
*/
|
|
39
|
+
/** The currency a visitor picked, kept for their next visit (`localStorage` `eldra.currency`). */
|
|
40
|
+
function createCurrencyPreference(options = {}) {
|
|
41
|
+
const storage = options.storage === void 0 ? browserStorage("localStorage") : options.storage;
|
|
42
|
+
const key = options.key ?? DEFAULT_CURRENCY_KEY;
|
|
43
|
+
return {
|
|
44
|
+
read: () => safeRead(storage, key),
|
|
45
|
+
remember: (currency) => safeWrite(storage, key, currency),
|
|
46
|
+
forget: () => safeWrite(storage, key, null)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
38
49
|
function createOrderAccessTokens(options = {}) {
|
|
39
50
|
const storage = options.storage === void 0 ? browserStorage("sessionStorage") : options.storage;
|
|
40
51
|
const prefix = options.keyPrefix ?? DEFAULT_ORDER_TOKEN_PREFIX;
|
|
@@ -666,6 +677,12 @@ function createEldraClient(options) {
|
|
|
666
677
|
method: "DELETE",
|
|
667
678
|
path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}/items/${encodeURIComponent(itemId)}`
|
|
668
679
|
}),
|
|
680
|
+
setCurrency: (cartId, currency, context) => request({
|
|
681
|
+
...context,
|
|
682
|
+
method: "PUT",
|
|
683
|
+
path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}/currency`,
|
|
684
|
+
body: { currency }
|
|
685
|
+
}),
|
|
669
686
|
/**
|
|
670
687
|
* Applies a discount code. On a cart bound to a customer this is 409
|
|
671
688
|
* CART_DISCOUNT_NOT_FOR_CUSTOMER_PRICES: codes do not combine with customer prices.
|
|
@@ -1085,4 +1102,4 @@ function appendQueryValue(searchParams, key, value) {
|
|
|
1085
1102
|
function isRawBody(body) {
|
|
1086
1103
|
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;
|
|
1087
1104
|
}
|
|
1088
|
-
export { getEldraClient as a, resolveApiBaseUrl as c, clearCampaignAttribution as d, grantCampaignAttributionConsent as f,
|
|
1105
|
+
export { createOrderAccessTokens as _, getEldraClient as a, resolveApiBaseUrl as c, clearCampaignAttribution as d, grantCampaignAttributionConsent as f, createCurrencyPreference as g, createCartSession as h, createEldraClient as i, resolveOrgId as l, withdrawCampaignAttributionConsent as m, EldraHttpError as n, initEldraClient as o, readCampaignAttribution as p, EldraIdempotencyKeyError as r, isEldraError as s, DEFAULT_ELDRA_API_BASE_URL as t, captureCampaignAttribution as u };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as EldraFormSubmitResult, $t as EldraShopUser, A as EldraCollection, At as EldraProductVariant, B as EldraCustomerMembership, Bt as EldraSalesOrderLine, C as EldraCmsEntryListFilterCriterion, Cn as
|
|
1
|
+
import { $ as EldraFormSubmitResult, $t as EldraShopUser, A as EldraCollection, At as EldraProductVariant, B as EldraCustomerMembership, Bt as EldraSalesOrderLine, C as EldraCmsEntryListFilterCriterion, Cn as EldraCurrencyPreference, Ct as EldraProductExtensions, D as EldraCmsResolveEntryListOptions, Dn as createCartSession, Dt as EldraProductOption, E as EldraCmsListOptions, En as EldraOrderAccessTokens, Et as EldraProductMediaLink, F as EldraCreateSalesOrderOptions, Ft as EldraRetryOptions, G as EldraFeatureClient, Gt as EldraSalesOrderPreviewInput, H as EldraErrorId, Ht as EldraSalesOrderListItem, I as EldraCustomerClient, It as EldraSalesOrder, J as EldraFormField, Jt as EldraSalesOrderWarning, K as EldraFormActionKind, Kt as EldraSalesOrderPreviewLine, L as EldraCustomerLocation, Lt as EldraSalesOrderCredit, M as EldraCollectionListOptions, Mt as EldraRecoveredBasketItem, N as EldraCollectionProductsOptions, Nt as EldraRequestContext, O as EldraCmsResolveEntryListResponse, On as createCurrencyPreference, Ot as EldraProductOptionValue, P as EldraCreateSalesOrderInput, Pt as EldraRequestOptions, Q as EldraFormSubmitInput, Qt as EldraShopErrorId, R as EldraCustomerLocationList, Rt as EldraSalesOrderDelivery, S as EldraCmsEntryListEntry, Sn as EldraCartSessionOptions, St as EldraProductDetails, T as EldraCmsGetOptions, Tn as EldraOrderAccessTokenOptions, Tt as EldraProductListItem, U as EldraFeature, Ut as EldraSalesOrderListOptions, V as EldraDiscountResult, Vt as EldraSalesOrderList, W as EldraFeatureCapabilities, Wt as EldraSalesOrderPreview, X as EldraFormFieldType, Xt as EldraSearchOptions, Y as EldraFormFieldOption, Yt as EldraSalesOrdersClient, Z as EldraFormLocalized, Zt as EldraSearchResponse, _ as EldraClient, _n as clearCampaignAttribution, _t as EldraPaginated, a as EldraCartClient, an as EldraContract, at as EldraLocaleOptions, b as EldraCmsEntryList, bn as withdrawCampaignAttributionConsent, bt as EldraPlatformReadOptions, c as EldraCartGiftCardEntry, cn as EldraContractMethod, ct as EldraOrderLine, d as EldraCatalogClient, dn as EldraContractProp, dt as EldraOrganizationCommerce, en as EldraStockAvailability, et as EldraFormTokenResult, f as EldraCatalogGetProductOptions, fn as EldraContractQuery, ft as EldraOrganizationDetails, g as EldraCheckoutUrlOptions, gn as captureCampaignAttribution, gt as EldraPageMeta, h as EldraCheckoutClient, hn as EldraCampaignAttributionOptions, ht as EldraOrganizationOptions, i as EldraCartAppliedCode, in as RuntimeValue, it as EldraInventoryClient, j as EldraCollectionList, jt as EldraRecoveredBasket, k as EldraCmsResolvedEntryList, kn as createOrderAccessTokens, kt as EldraProductThumbnail, l as EldraCartItem, ln as EldraContractPath, lt as EldraOrderReadOptions, m as EldraCategory, mn as EldraCampaignAttribution, mt as EldraOrganizationLocales, n as EldraBrand, nn as EldraStockAvailabilityItem, nt as EldraHttpClient, o as EldraCartDiscountCodeEntry, on as EldraContractBody, ot as EldraOrder, p as EldraCatalogListProductsOptions, pn as EldraContractResponse, pt as EldraOrganizationFeature, q as EldraFormDefinition, qt as EldraSalesOrderStatus, r as EldraCart, rn as RuntimeEnv, rt as EldraHttpRequest, s as EldraCartGiftCard, sn as EldraContractItem, st as EldraOrderDiscountCode, t as EldraAddCartItemInput, tn as EldraStockAvailabilityInput, tt as EldraFormsClient, u as EldraCartTotals, un as EldraContractPaths, ut as EldraOrdersClient, v as EldraClientOptions, vn as grantCampaignAttributionConsent, vt as EldraPlatformClient, w as EldraCmsGetEntryByUniqueFieldOptions, wn as EldraKeyValueStorage, wt as EldraProductList, x as EldraCmsEntryListDisplayMode, xn as EldraCartSession, xt as EldraProblemErrors, y as EldraCmsClient, yn as readCampaignAttribution, yt as EldraPlatformConfig, z as EldraCustomerMe, zt as EldraSalesOrderErrorId } from "./types-COJLLz9z.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;
|
|
@@ -158,7 +158,7 @@ interface EldraTrackerScript {
|
|
|
158
158
|
*/
|
|
159
159
|
export declare function analyticsTrackerScript(options?: EldraTrackerScriptOptions): EldraTrackerScript | undefined;
|
|
160
160
|
/** A size the media host serves by path suffix; `original` is the uploaded file, untransformed. */
|
|
161
|
-
type EldraImageVariant = 'sm' | 'md' | 'lg' | 'xl' | 'full' | 'original';
|
|
161
|
+
type EldraImageVariant = 'sm' | 'md' | 'lg' | 'xl' | 'full' | 'uhd' | 'original';
|
|
162
162
|
/** The variants the media host resizes, narrowest first. */
|
|
163
163
|
type EldraSizedImageVariant = Exclude<EldraImageVariant, 'original'>;
|
|
164
164
|
/**
|
|
@@ -186,14 +186,14 @@ export declare function isEldraImage(source: EldraImageSource): boolean;
|
|
|
186
186
|
export declare function imageUrl(source: string, variant: EldraImageVariant): string;
|
|
187
187
|
export declare function imageUrl(source: EldraImageSource, variant: EldraImageVariant): string | undefined;
|
|
188
188
|
/**
|
|
189
|
-
* The narrowest variant at least `width` CSS pixels wide at the given pixel density, or `
|
|
189
|
+
* The narrowest variant at least `width` CSS pixels wide at the given pixel density, or `uhd`
|
|
190
190
|
* when nothing is that wide.
|
|
191
191
|
*/
|
|
192
192
|
export declare function imageVariantFor(width: number, density?: number): EldraSizedImageVariant;
|
|
193
193
|
interface EldraImageSrcsetOptions {
|
|
194
194
|
/**
|
|
195
195
|
* The original's width in pixels, by default the source's `width`. Wider variants are dropped and
|
|
196
|
-
* the last is described at its true width; an original wider than `
|
|
196
|
+
* the last is described at its true width; an original wider than `uhd` is listed itself, last.
|
|
197
197
|
*/
|
|
198
198
|
originalWidth?: number;
|
|
199
199
|
}
|
|
@@ -232,4 +232,4 @@ interface EldraResponsiveImage {
|
|
|
232
232
|
* as `src` and no `srcset`. Returns `undefined` when there is no URL to render.
|
|
233
233
|
*/
|
|
234
234
|
export declare function responsiveImage(source: EldraImageSource, options: EldraResponsiveImageOptions): EldraResponsiveImage | undefined;
|
|
235
|
-
export { type EldraAddCartItemInput, type EldraAuthorizeUrlOptions, type EldraBrand, type EldraCampaignAttribution, type EldraCampaignAttributionOptions, type EldraCart, type EldraCartAppliedCode, type EldraCartClient, type EldraCartDiscountCodeEntry, type EldraCartGiftCard, type EldraCartGiftCardEntry, 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 EldraCreateSalesOrderInput, type EldraCreateSalesOrderOptions, type EldraCustomerClient, type EldraCustomerLocation, type EldraCustomerLocationList, type EldraCustomerMe, type EldraCustomerMembership, type EldraDiscountResult, type EldraErrorId, type EldraExchangeCodeOptions, 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 EldraHttpErrorWith, type EldraHttpRequest, type EldraImageSource, type EldraImageSrcsetOptions, type EldraImageVariant, type EldraInventoryClient, type EldraKeyValueStorage, type EldraLocaleOptions, type EldraLogoutUrlOptions, type EldraOidcTokens, type EldraOrder, type EldraOrderAccessTokenOptions, type EldraOrderAccessTokens, type EldraOrderDiscountCode, type EldraOrderLine, type EldraOrderReadOptions, type EldraOrdersClient, type EldraOrganizationCommerce, type EldraOrganizationDetails, type EldraOrganizationFeature, type EldraOrganizationLocales, type EldraOrganizationOptions, type EldraPageMeta, type EldraPaginated, type EldraPkcePair, type EldraPlatformClient, type EldraPlatformConfig, type EldraPlatformReadOptions, type EldraProblemErrors, type EldraProductDetails, type EldraProductExtensions, type EldraProductList, type EldraProductListItem, type EldraProductMediaLink, type EldraProductOption, type EldraProductOptionValue, type EldraProductThumbnail, type EldraProductVariant, type EldraRecoveredBasket, type EldraRecoveredBasketItem, type EldraRefreshTokensOptions, type EldraRequestContext, type EldraRequestOptions, type EldraResponsiveImage, type EldraResponsiveImageOptions, type EldraRetryOptions, type EldraSalesOrder, type EldraSalesOrderCredit, type EldraSalesOrderDelivery, type EldraSalesOrderErrorId, type EldraSalesOrderLine, type EldraSalesOrderList, type EldraSalesOrderListItem, type EldraSalesOrderListOptions, type EldraSalesOrderPreview, type EldraSalesOrderPreviewInput, type EldraSalesOrderPreviewLine, type EldraSalesOrderStatus, type EldraSalesOrderWarning, type EldraSalesOrdersClient, type EldraSearchOptions, type EldraSearchResponse, type EldraShopErrorId, type EldraShopUser, type EldraSizedImageVariant, type EldraStockAvailability, type EldraStockAvailabilityInput, type EldraStockAvailabilityItem, type EldraTokenClientOptions, type EldraTrackerScript, type EldraTrackerScriptOptions, type RuntimeEnv, type RuntimeValue, captureCampaignAttribution, clearCampaignAttribution, createCartSession, createOrderAccessTokens, grantCampaignAttributionConsent, readCampaignAttribution, withdrawCampaignAttributionConsent };
|
|
235
|
+
export { type EldraAddCartItemInput, type EldraAuthorizeUrlOptions, type EldraBrand, type EldraCampaignAttribution, type EldraCampaignAttributionOptions, type EldraCart, type EldraCartAppliedCode, type EldraCartClient, type EldraCartDiscountCodeEntry, type EldraCartGiftCard, type EldraCartGiftCardEntry, 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 EldraCreateSalesOrderInput, type EldraCreateSalesOrderOptions, type EldraCurrencyPreference, type EldraCustomerClient, type EldraCustomerLocation, type EldraCustomerLocationList, type EldraCustomerMe, type EldraCustomerMembership, type EldraDiscountResult, type EldraErrorId, type EldraExchangeCodeOptions, 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 EldraHttpErrorWith, type EldraHttpRequest, type EldraImageSource, type EldraImageSrcsetOptions, type EldraImageVariant, type EldraInventoryClient, type EldraKeyValueStorage, type EldraLocaleOptions, type EldraLogoutUrlOptions, type EldraOidcTokens, type EldraOrder, type EldraOrderAccessTokenOptions, type EldraOrderAccessTokens, type EldraOrderDiscountCode, type EldraOrderLine, type EldraOrderReadOptions, type EldraOrdersClient, type EldraOrganizationCommerce, type EldraOrganizationDetails, type EldraOrganizationFeature, type EldraOrganizationLocales, type EldraOrganizationOptions, type EldraPageMeta, type EldraPaginated, type EldraPkcePair, type EldraPlatformClient, type EldraPlatformConfig, type EldraPlatformReadOptions, type EldraProblemErrors, type EldraProductDetails, type EldraProductExtensions, type EldraProductList, type EldraProductListItem, type EldraProductMediaLink, type EldraProductOption, type EldraProductOptionValue, type EldraProductThumbnail, type EldraProductVariant, type EldraRecoveredBasket, type EldraRecoveredBasketItem, type EldraRefreshTokensOptions, type EldraRequestContext, type EldraRequestOptions, type EldraResponsiveImage, type EldraResponsiveImageOptions, type EldraRetryOptions, type EldraSalesOrder, type EldraSalesOrderCredit, type EldraSalesOrderDelivery, type EldraSalesOrderErrorId, type EldraSalesOrderLine, type EldraSalesOrderList, type EldraSalesOrderListItem, type EldraSalesOrderListOptions, type EldraSalesOrderPreview, type EldraSalesOrderPreviewInput, type EldraSalesOrderPreviewLine, type EldraSalesOrderStatus, type EldraSalesOrderWarning, type EldraSalesOrdersClient, type EldraSearchOptions, type EldraSearchResponse, type EldraShopErrorId, type EldraShopUser, type EldraSizedImageVariant, type EldraStockAvailability, type EldraStockAvailabilityInput, type EldraStockAvailabilityItem, type EldraTokenClientOptions, type EldraTrackerScript, type EldraTrackerScriptOptions, type RuntimeEnv, type RuntimeValue, captureCampaignAttribution, clearCampaignAttribution, createCartSession, createCurrencyPreference, createOrderAccessTokens, grantCampaignAttributionConsent, readCampaignAttribution, withdrawCampaignAttributionConsent };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as getEldraClient, c as resolveApiBaseUrl, d as clearCampaignAttribution, f as grantCampaignAttributionConsent, g as
|
|
1
|
+
import { _ as createOrderAccessTokens, a as getEldraClient, c as resolveApiBaseUrl, d as clearCampaignAttribution, f as grantCampaignAttributionConsent, g as createCurrencyPreference, h as createCartSession, i as createEldraClient, l as resolveOrgId, m as withdrawCampaignAttributionConsent, n as EldraHttpError, o as initEldraClient, p as readCampaignAttribution, r as EldraIdempotencyKeyError, s as isEldraError, t as DEFAULT_ELDRA_API_BASE_URL, u as captureCampaignAttribution } from "./client-Bh_8g5xj.js";
|
|
2
2
|
// src/oidc.ts
|
|
3
3
|
var EldraOidcError = class extends Error {
|
|
4
4
|
status;
|
|
@@ -156,11 +156,13 @@ const ELDRA_IMAGE_VARIANT_WIDTHS = {
|
|
|
156
156
|
md: 800,
|
|
157
157
|
lg: 1200,
|
|
158
158
|
xl: 1920,
|
|
159
|
-
full: 2560
|
|
159
|
+
full: 2560,
|
|
160
|
+
uhd: 3840
|
|
160
161
|
};
|
|
161
162
|
const SIZED_VARIANTS = Object.keys(ELDRA_IMAGE_VARIANT_WIDTHS);
|
|
163
|
+
const WIDEST = "uhd";
|
|
162
164
|
const UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
163
|
-
const ELDRA_ASSET_URL = new RegExp(`^((?:(?:https?:)?//[^/\\s,?#]+)?(?:/[^\\s,?#]*)?/public/${UUID}/assets/${UUID})(?:/(?:sm|md|lg|xl|full|original))?/?$`, "i");
|
|
165
|
+
const ELDRA_ASSET_URL = new RegExp(`^((?:(?:https?:)?//[^/\\s,?#]+)?(?:/[^\\s,?#]*)?/public/${UUID}/assets/${UUID})(?:/(?:sm|md|lg|xl|full|uhd|original))?/?$`, "i");
|
|
164
166
|
const RESIZABLE_CONTENT_TYPES = /* @__PURE__ */ new Set([
|
|
165
167
|
"image/jpeg",
|
|
166
168
|
"image/png",
|
|
@@ -198,13 +200,13 @@ function imageUrl(source, variant) {
|
|
|
198
200
|
return base ? `${base}/${variant}` : sourceUrl(source);
|
|
199
201
|
}
|
|
200
202
|
/**
|
|
201
|
-
* The narrowest variant at least `width` CSS pixels wide at the given pixel density, or `
|
|
203
|
+
* The narrowest variant at least `width` CSS pixels wide at the given pixel density, or `uhd`
|
|
202
204
|
* when nothing is that wide.
|
|
203
205
|
*/
|
|
204
206
|
function imageVariantFor(width, density = 1) {
|
|
205
207
|
const needed = width * density;
|
|
206
208
|
if (!Number.isFinite(needed) || needed <= 0) throw new RangeError(`imageVariantFor needs a positive width, got ${width} at ${density}x`);
|
|
207
|
-
return SIZED_VARIANTS.find((variant) => ELDRA_IMAGE_VARIANT_WIDTHS[variant] >= needed) ??
|
|
209
|
+
return SIZED_VARIANTS.find((variant) => ELDRA_IMAGE_VARIANT_WIDTHS[variant] >= needed) ?? WIDEST;
|
|
208
210
|
}
|
|
209
211
|
function originalDisplays(source) {
|
|
210
212
|
const contentType = typeof source === "object" ? source?.contentType?.toLowerCase() : void 0;
|
|
@@ -227,7 +229,7 @@ function imageSrcset(source, options = {}) {
|
|
|
227
229
|
}
|
|
228
230
|
candidates.push(`${base}/${variant} ${width}w`);
|
|
229
231
|
}
|
|
230
|
-
if (isSide(originalWidth) && Math.round(originalWidth) > ELDRA_IMAGE_VARIANT_WIDTHS
|
|
232
|
+
if (isSide(originalWidth) && Math.round(originalWidth) > ELDRA_IMAGE_VARIANT_WIDTHS[WIDEST] && originalDisplays(source)) candidates.push(`${base}/original ${Math.round(originalWidth)}w`);
|
|
231
233
|
return candidates.join(", ");
|
|
232
234
|
}
|
|
233
235
|
/**
|
|
@@ -257,4 +259,4 @@ function responsiveImage(source, options) {
|
|
|
257
259
|
}
|
|
258
260
|
return image;
|
|
259
261
|
}
|
|
260
|
-
export { DEFAULT_ELDRA_API_BASE_URL, ELDRA_IMAGE_VARIANT_WIDTHS, ELDRA_SHOP_CLIENT_ID, EldraHttpError, EldraIdempotencyKeyError, EldraOidcError, analyticsTrackerScript, bearer, buildAuthorizeUrl, buildLogoutUrl, captureCampaignAttribution, clearCampaignAttribution, createCartSession, createEldraClient, createOrderAccessTokens, createPkcePair, customerHeaders, exchangeAuthorizationCode, getEldraClient, grantCampaignAttributionConsent, imageSrcset, imageUrl, imageVariantFor, initEldraClient, isEldraError, isEldraImage, pkceChallenge, readCampaignAttribution, refreshTokens, responsiveImage, shopIssuer, withdrawCampaignAttributionConsent };
|
|
262
|
+
export { DEFAULT_ELDRA_API_BASE_URL, ELDRA_IMAGE_VARIANT_WIDTHS, ELDRA_SHOP_CLIENT_ID, EldraHttpError, EldraIdempotencyKeyError, EldraOidcError, analyticsTrackerScript, bearer, buildAuthorizeUrl, buildLogoutUrl, captureCampaignAttribution, clearCampaignAttribution, createCartSession, createCurrencyPreference, createEldraClient, createOrderAccessTokens, createPkcePair, customerHeaders, exchangeAuthorizationCode, getEldraClient, grantCampaignAttributionConsent, imageSrcset, imageUrl, imageVariantFor, initEldraClient, isEldraError, isEldraImage, pkceChallenge, readCampaignAttribution, refreshTokens, responsiveImage, shopIssuer, withdrawCampaignAttributionConsent };
|
|
@@ -8,6 +8,11 @@ interface EldraCartSession {
|
|
|
8
8
|
remember(cartId: string): void;
|
|
9
9
|
forget(): void;
|
|
10
10
|
}
|
|
11
|
+
interface EldraCurrencyPreference {
|
|
12
|
+
read(): string | null;
|
|
13
|
+
remember(currency: string): void;
|
|
14
|
+
forget(): void;
|
|
15
|
+
}
|
|
11
16
|
interface EldraOrderAccessTokens {
|
|
12
17
|
remember(orderId: string, token: string | undefined): void;
|
|
13
18
|
read(orderId: string): string | null;
|
|
@@ -26,6 +31,8 @@ declare function createCartSession(options?: EldraCartSessionOptions): EldraCart
|
|
|
26
31
|
* The one-time order access token, kept in sessionStorage rather than the return URL so it
|
|
27
32
|
* survives the payment provider's redirect without landing in a URL, a log or a Referer.
|
|
28
33
|
*/
|
|
34
|
+
/** The currency a visitor picked, kept for their next visit (`localStorage` `eldra.currency`). */
|
|
35
|
+
declare function createCurrencyPreference(options?: EldraCartSessionOptions): EldraCurrencyPreference;
|
|
29
36
|
declare function createOrderAccessTokens(options?: EldraOrderAccessTokenOptions): EldraOrderAccessTokens;
|
|
30
37
|
/** The campaign a visit landed from: campaign-level tags only, nothing about the visitor. */
|
|
31
38
|
interface EldraCampaignAttribution {
|
|
@@ -226,6 +233,8 @@ interface EldraCmsResolveEntryListOptions {
|
|
|
226
233
|
type EldraCatalogListProductsOptions = EldraContractQuery<'/catalog/v1/products/list', 'get'>;
|
|
227
234
|
interface EldraCatalogGetProductOptions {
|
|
228
235
|
locale?: string;
|
|
236
|
+
/** Contract 6.19.0: price the variants in this selling currency. */
|
|
237
|
+
currency?: string;
|
|
229
238
|
}
|
|
230
239
|
type EldraFeature = 'CMS' | 'ECOMMERCE';
|
|
231
240
|
interface EldraOrganizationFeature {
|
|
@@ -249,6 +258,18 @@ interface EldraOrganizationCommerce {
|
|
|
249
258
|
taxInclusivePricing: boolean;
|
|
250
259
|
/** Fraction, e.g. `0.24` — applies to shipping and to products without their own rate. */
|
|
251
260
|
defaultTaxRate: number;
|
|
261
|
+
/** Contract 6.21.0: the currencies the storefront may offer, `currency` first. */
|
|
262
|
+
currencies?: string[];
|
|
263
|
+
}
|
|
264
|
+
/** One of the organisation's payment providers (contract 6.20.0). */
|
|
265
|
+
interface EldraOrganizationPaymentProvider {
|
|
266
|
+
type: string;
|
|
267
|
+
name: string;
|
|
268
|
+
status: string;
|
|
269
|
+
/** The selling currencies it takes. Missing: ISK only. */
|
|
270
|
+
currencies?: string[] | null;
|
|
271
|
+
paymentMethods?: string[] | null;
|
|
272
|
+
logos?: unknown;
|
|
252
273
|
}
|
|
253
274
|
/**
|
|
254
275
|
* The organisation's configured **content** locales, as the public organisation read publishes
|
|
@@ -279,7 +300,7 @@ interface EldraOrganizationDetails {
|
|
|
279
300
|
commerce?: EldraOrganizationCommerce | null;
|
|
280
301
|
/** See `EldraOrganizationLocales`: absent, or `null`, until the organisation configures any. */
|
|
281
302
|
locales?: EldraOrganizationLocales | null;
|
|
282
|
-
paymentProviders?:
|
|
303
|
+
paymentProviders?: EldraOrganizationPaymentProvider[];
|
|
283
304
|
createdAt?: string;
|
|
284
305
|
updatedAt?: string;
|
|
285
306
|
}
|
|
@@ -465,6 +486,8 @@ interface EldraCartClient {
|
|
|
465
486
|
quantity: number;
|
|
466
487
|
}, context?: EldraRequestContext): Promise<EldraCart>;
|
|
467
488
|
removeItem(cartId: string, itemId: string, context?: EldraRequestContext): Promise<EldraCart>;
|
|
489
|
+
/** Moves the cart to `currency` and reprices it (6.21.0); errors 400 CART_CURRENCY_NOT_SOLD, 409 CART_CURRENCY_CUSTOMER_ISK_ONLY. */
|
|
490
|
+
setCurrency(cartId: string, currency: string, context?: EldraRequestContext): Promise<EldraCart>;
|
|
468
491
|
/**
|
|
469
492
|
* Applies a discount code and answers the cart with `applied` (see {@link EldraDiscountResult}).
|
|
470
493
|
* Since contract 6.9.0 a discount code is **added** after the cart's codes instead of replacing
|
|
@@ -764,4 +787,4 @@ interface EldraFormsClient {
|
|
|
764
787
|
/** `POST /site/v1/forms/subscriptions/unsubscribe?token=` (a GET of the link is only a page). */
|
|
765
788
|
unsubscribe(token: string, context?: EldraRequestContext): Promise<EldraFormTokenResult>;
|
|
766
789
|
}
|
|
767
|
-
export { EldraFormSubmitResult as $, EldraShopUser as $t, EldraCollection as A, EldraProductVariant as At, EldraCustomerMembership as B, EldraSalesOrderLine as Bt, EldraCmsEntryListFilterCriterion as C,
|
|
790
|
+
export { EldraFormSubmitResult as $, EldraShopUser as $t, EldraCollection as A, EldraProductVariant as At, EldraCustomerMembership as B, EldraSalesOrderLine as Bt, EldraCmsEntryListFilterCriterion as C, EldraCurrencyPreference as Cn, EldraProductExtensions as Ct, EldraCmsResolveEntryListOptions as D, createCartSession as Dn, EldraProductOption as Dt, EldraCmsListOptions as E, EldraOrderAccessTokens as En, EldraProductMediaLink as Et, EldraCreateSalesOrderOptions as F, EldraRetryOptions as Ft, EldraFeatureClient as G, EldraSalesOrderPreviewInput as Gt, EldraErrorId as H, EldraSalesOrderListItem as Ht, EldraCustomerClient as I, EldraSalesOrder as It, EldraFormField as J, EldraSalesOrderWarning as Jt, EldraFormActionKind as K, EldraSalesOrderPreviewLine as Kt, EldraCustomerLocation as L, EldraSalesOrderCredit as Lt, EldraCollectionListOptions as M, EldraRecoveredBasketItem as Mt, EldraCollectionProductsOptions as N, EldraRequestContext as Nt, EldraCmsResolveEntryListResponse as O, createCurrencyPreference as On, EldraProductOptionValue as Ot, EldraCreateSalesOrderInput as P, EldraRequestOptions as Pt, EldraFormSubmitInput as Q, EldraShopErrorId as Qt, EldraCustomerLocationList as R, EldraSalesOrderDelivery as Rt, EldraCmsEntryListEntry as S, EldraCartSessionOptions as Sn, EldraProductDetails as St, EldraCmsGetOptions as T, EldraOrderAccessTokenOptions as Tn, EldraProductListItem as Tt, EldraFeature as U, EldraSalesOrderListOptions as Ut, EldraDiscountResult as V, EldraSalesOrderList as Vt, EldraFeatureCapabilities as W, EldraSalesOrderPreview as Wt, EldraFormFieldType as X, EldraSearchOptions as Xt, EldraFormFieldOption as Y, EldraSalesOrdersClient as Yt, EldraFormLocalized as Z, EldraSearchResponse as Zt, EldraClient as _, clearCampaignAttribution as _n, EldraPaginated as _t, EldraCartClient as a, EldraContract as an, EldraLocaleOptions as at, EldraCmsEntryList as b, withdrawCampaignAttributionConsent as bn, EldraPlatformReadOptions as bt, EldraCartGiftCardEntry as c, EldraContractMethod as cn, EldraOrderLine as ct, EldraCatalogClient as d, EldraContractProp as dn, EldraOrganizationCommerce as dt, EldraStockAvailability as en, EldraFormTokenResult as et, EldraCatalogGetProductOptions as f, EldraContractQuery as fn, EldraOrganizationDetails as ft, EldraCheckoutUrlOptions as g, captureCampaignAttribution as gn, EldraPageMeta as gt, EldraCheckoutClient as h, EldraCampaignAttributionOptions as hn, EldraOrganizationOptions as ht, EldraCartAppliedCode as i, RuntimeValue as in, EldraInventoryClient as it, EldraCollectionList as j, EldraRecoveredBasket as jt, EldraCmsResolvedEntryList as k, createOrderAccessTokens as kn, EldraProductThumbnail as kt, EldraCartItem as l, EldraContractPath as ln, EldraOrderReadOptions as lt, EldraCategory as m, EldraCampaignAttribution as mn, EldraOrganizationLocales as mt, EldraBrand as n, EldraStockAvailabilityItem as nn, EldraHttpClient as nt, EldraCartDiscountCodeEntry as o, EldraContractBody as on, EldraOrder as ot, EldraCatalogListProductsOptions as p, EldraContractResponse as pn, EldraOrganizationFeature as pt, EldraFormDefinition as q, EldraSalesOrderStatus as qt, EldraCart as r, RuntimeEnv as rn, EldraHttpRequest as rt, EldraCartGiftCard as s, EldraContractItem as sn, EldraOrderDiscountCode as st, EldraAddCartItemInput as t, EldraStockAvailabilityInput as tn, EldraFormsClient as tt, EldraCartTotals as u, EldraContractPaths as un, EldraOrdersClient as ut, EldraClientOptions as v, grantCampaignAttributionConsent as vn, EldraPlatformClient as vt, EldraCmsGetEntryByUniqueFieldOptions as w, EldraKeyValueStorage as wn, EldraProductList as wt, EldraCmsEntryListDisplayMode as x, EldraCartSession as xn, EldraProblemErrors as xt, EldraCmsClient as y, readCampaignAttribution as yn, EldraPlatformConfig as yt, EldraCustomerMe as z, EldraSalesOrderErrorId as zt };
|
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.5.
|
|
3
|
+
"version": "0.5.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",
|