@eldrajs/sdk 0.2.7 → 0.2.9
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 +23 -0
- package/README.md +65 -2
- package/THIRD-PARTY-NOTICES.md +18 -0
- package/dist/client-t66vCzJf.js +693 -0
- package/dist/format/date.d.ts +4 -0
- package/dist/format/date.js +12214 -0
- package/dist/format/display-names.d.ts +4 -0
- package/dist/format/display-names.js +4905 -0
- package/dist/format/list.d.ts +4 -0
- package/dist/format/list.js +902 -0
- package/dist/format/relative-time.d.ts +4 -0
- package/dist/format/relative-time.js +1546 -0
- package/dist/format.d.ts +12 -0
- package/dist/format.js +72 -0
- package/dist/index.d.ts +11 -5
- package/dist/index.js +2 -2
- package/dist/locale-DOZdbAbY.js +4011 -0
- package/dist/number-D3Vt6TOL.js +9585 -0
- package/dist/{types-C0yabGuL.d.ts → types-B40H01uK.d.ts} +127 -10
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +1 -1
- package/package.json +32 -3
- package/dist/client-DVn7qqKo.js +0 -347
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/format/compare.d.ts
|
|
2
|
+
/** Icelandic alphabetical order (`Intl.Collator('is')`), for runtimes that ship without it. */
|
|
3
|
+
export declare function compareIcelandic(a: string, b: string): number;
|
|
4
|
+
/** A sort comparator for `locale`: Icelandic order from {@link compareIcelandic}, any other from the runtime. */
|
|
5
|
+
export declare function comparator(locale: string): (a: string, b: string) => number;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/format/number.d.ts
|
|
8
|
+
/** `new Intl.NumberFormat(locale, options)` with the same text on every runtime, Chrome and Workers included. */
|
|
9
|
+
export declare function numberFormat(locale: string, options?: Intl.NumberFormatOptions): Intl.NumberFormat;
|
|
10
|
+
/** A price in major units, the way every Eldra surface writes it: `12.900 kr.`, `ISK 12,900`. */
|
|
11
|
+
export declare function formatPrice(amount: number, currency: string, locale: string): string;
|
|
12
|
+
//#endregion
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { n as numberFormat, t as formatPrice } from "./number-D3Vt6TOL.js";
|
|
2
|
+
//#region src/format/compare.ts
|
|
3
|
+
const PUNCTUATION = " \xA0_-–—,;:!¡?¿.…·'‘’\"“”„«»()[]{}§@*/\\&#%`^°+÷×<=>|~$£€";
|
|
4
|
+
const LETTERS = "aábcdðeéfghiíjklłmnoópqrstuúvwxyýzþæöå";
|
|
5
|
+
const IGNORED = /* @__PURE__ */ new Set([
|
|
6
|
+
"",
|
|
7
|
+
"",
|
|
8
|
+
"",
|
|
9
|
+
"",
|
|
10
|
+
"",
|
|
11
|
+
""
|
|
12
|
+
]);
|
|
13
|
+
const SECONDARY_OF = {
|
|
14
|
+
ä: "æ",
|
|
15
|
+
ø: "ö",
|
|
16
|
+
đ: "d"
|
|
17
|
+
};
|
|
18
|
+
const EXPANSIONS = {
|
|
19
|
+
ß: "ss",
|
|
20
|
+
œ: "oe"
|
|
21
|
+
};
|
|
22
|
+
const DIGITS_AT = 54;
|
|
23
|
+
const LETTERS_AT = 64;
|
|
24
|
+
const OTHER_AT = 102;
|
|
25
|
+
function key(text) {
|
|
26
|
+
const result = [
|
|
27
|
+
[],
|
|
28
|
+
[],
|
|
29
|
+
[]
|
|
30
|
+
];
|
|
31
|
+
for (const char of text.normalize("NFC")) {
|
|
32
|
+
if (IGNORED.has(char)) continue;
|
|
33
|
+
const lower = char.toLowerCase();
|
|
34
|
+
const expansion = EXPANSIONS[lower];
|
|
35
|
+
const tertiary = (char === lower ? 0 : 1) + (expansion ? 2 : 0);
|
|
36
|
+
for (const unit of expansion ?? lower) {
|
|
37
|
+
const [primary, secondary] = weigh(unit);
|
|
38
|
+
result[0].push(primary);
|
|
39
|
+
result[1].push(secondary);
|
|
40
|
+
result[2].push(tertiary);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
function weigh(char) {
|
|
46
|
+
const letter = LETTERS.indexOf(char);
|
|
47
|
+
if (letter >= 0) return [LETTERS_AT + letter, 0];
|
|
48
|
+
const base = SECONDARY_OF[char] ?? char.normalize("NFD")[0] ?? char;
|
|
49
|
+
const accented = LETTERS.indexOf(base);
|
|
50
|
+
if (accented >= 0) return [LETTERS_AT + accented, char.codePointAt(0) ?? 0];
|
|
51
|
+
if (char >= "0" && char <= "9") return [DIGITS_AT + Number(char), 0];
|
|
52
|
+
const mark = PUNCTUATION.indexOf(char);
|
|
53
|
+
if (mark >= 0) return [mark, 0];
|
|
54
|
+
return [OTHER_AT + (char.codePointAt(0) ?? 0), 0];
|
|
55
|
+
}
|
|
56
|
+
function compareWeights(a, b) {
|
|
57
|
+
const length = Math.min(a.length, b.length);
|
|
58
|
+
for (let i = 0; i < length; i++) if (a[i] !== b[i]) return (a[i] ?? 0) - (b[i] ?? 0);
|
|
59
|
+
return a.length - b.length;
|
|
60
|
+
}
|
|
61
|
+
/** Icelandic alphabetical order (`Intl.Collator('is')`), for runtimes that ship without it. */
|
|
62
|
+
function compareIcelandic(a, b) {
|
|
63
|
+
const [ka, kb] = [key(a), key(b)];
|
|
64
|
+
return Math.sign(compareWeights(ka[0], kb[0]) || compareWeights(ka[1], kb[1]) || compareWeights(ka[2], kb[2]));
|
|
65
|
+
}
|
|
66
|
+
/** A sort comparator for `locale`: Icelandic order from {@link compareIcelandic}, any other from the runtime. */
|
|
67
|
+
function comparator(locale) {
|
|
68
|
+
if ((Intl.getCanonicalLocales(locale)[0] ?? locale).split("-")[0] === "is") return compareIcelandic;
|
|
69
|
+
return new Intl.Collator(locale).compare;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { comparator, compareIcelandic, formatPrice, numberFormat };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import { $ as
|
|
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";
|
|
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";
|
|
5
4
|
export declare class EldraHttpError extends Error {
|
|
6
5
|
readonly status: number;
|
|
7
6
|
readonly statusText: string;
|
|
8
7
|
readonly body: unknown;
|
|
9
|
-
/** The
|
|
8
|
+
/** The gateway's problem `code`, such as `CONFLICT`, when the body carried one. */
|
|
10
9
|
readonly code: string | undefined;
|
|
11
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The gateway's problem `errorId` — the stable identifier for *which* failure this is, such as
|
|
12
|
+
* `CART_INSUFFICIENT_STOCK`. `code` names the class of failure (`CONFLICT`, `VALIDATION`) and
|
|
13
|
+
* several unrelated refusals share one, so a caller that reacts to a specific cause has to read
|
|
14
|
+
* this: a 409 on an add is `{ code: 'CONFLICT', errorId: 'CART_INSUFFICIENT_STOCK' }`, and
|
|
15
|
+
* telling it apart from any other conflict is what lets a storefront say "out of stock" rather
|
|
16
|
+
* than "something went wrong".
|
|
17
|
+
*/
|
|
12
18
|
readonly errorId: string | undefined;
|
|
13
19
|
constructor(response: Response, body: unknown);
|
|
14
20
|
}
|
|
@@ -143,4 +149,4 @@ interface EldraResponsiveImage {
|
|
|
143
149
|
*/
|
|
144
150
|
export declare function responsiveImage(source: EldraImageSource, options: EldraResponsiveImageOptions): EldraResponsiveImage | undefined;
|
|
145
151
|
//#endregion
|
|
146
|
-
export type { EldraAddCartItemInput, EldraCart, EldraCartClient, EldraCartItem, EldraCartSession, EldraCartSessionOptions, EldraCartTotals, EldraCatalogClient, EldraCatalogGetProductOptions, EldraCatalogListProductsOptions, EldraCategory, EldraCheckoutClient,
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
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";
|
|
2
2
|
//#region src/storage.ts
|
|
3
3
|
const DEFAULT_CART_KEY = "eldra.cartId";
|
|
4
4
|
const DEFAULT_ORDER_TOKEN_PREFIX = "eldra.orderAccessToken.";
|
|
@@ -161,4 +161,4 @@ function responsiveImage(source, options) {
|
|
|
161
161
|
return image;
|
|
162
162
|
}
|
|
163
163
|
//#endregion
|
|
164
|
-
export { DEFAULT_ELDRA_API_BASE_URL,
|
|
164
|
+
export { DEFAULT_ELDRA_API_BASE_URL, ELDRA_IMAGE_VARIANT_WIDTHS, EldraHttpError, analyticsTrackerScript, createCartSession, createEldraClient, createOrderAccessTokens, getEldraClient, imageSrcset, imageUrl, imageVariantFor, initEldraClient, isEldraImage, responsiveImage };
|