@eldrajs/sdk 0.4.1 → 0.4.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 +48 -0
- package/README.md +31 -12
- package/dist/{client-DLMV5fcx.js → client-DCs3cAQK.js} +73 -5
- package/dist/index.d.ts +9 -2
- package/dist/index.js +1 -1
- package/dist/{types-CiA-DRIp.d.ts → types-D71CuE-g.d.ts} +129 -9
- 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,54 @@ platform repository.
|
|
|
9
9
|
|
|
10
10
|
## Unreleased
|
|
11
11
|
|
|
12
|
+
- **Several discount codes on one cart (contract 6.9.0).** `applyDiscount` and `applyCode` (as `DISCOUNT`) now add
|
|
13
|
+
a code after the cart's codes instead of replacing it; each applies to what the codes before it left. Three new
|
|
14
|
+
409 refusals leave the cart as it was: `CART_DISCOUNT_NOT_COMBINABLE` (the code and one on the cart cannot be
|
|
15
|
+
combined; `errors.blockingCode` names the one on the cart), `CART_DISCOUNT_CODES_LIMIT_REACHED` (`errors.limit`,
|
|
16
|
+
6) and `CART_DISCOUNT_ALREADY_APPLIED`. `EldraHttpError` gains `errors`, the problem's `errors` object when the
|
|
17
|
+
body carries one. The cart carries `discountCodes` (`{code, amount}` in the order added; the type is
|
|
18
|
+
`EldraCartDiscountCodeEntry`); `cart.removeDiscountEntry(cartId, code, options?)` removes one code and
|
|
19
|
+
`removeDiscount` now removes every code. `applyDiscount`'s `applied` reads `discountCodes` (falling back to
|
|
20
|
+
`discountCode` from an older gateway), so a second code reports `true`. The order read and the checkout summary
|
|
21
|
+
carry `discountCodes` (`EldraOrderDiscountCode`, `EldraOrderPreviewDiscountCode`). The cart's and the order's
|
|
22
|
+
`discountCode` are deprecated in the contract: it answers them for one more version. The contract fixtures are
|
|
23
|
+
regenerated from 6.9.0.
|
|
24
|
+
- **Several gift cards on one cart (contract 6.8.0).** A cart holds any number of gift cards beside its discount
|
|
25
|
+
code: `applyGiftCard` and `applyCode` now add a card after the others instead of replacing one, and the same card
|
|
26
|
+
again is 409 `CART_GIFT_CARD_ALREADY_APPLIED`. The cart carries `giftCards` (`{entryId, last4, balance, applied,
|
|
27
|
+
amountDue}` in the order applied; the type is `EldraCartGiftCardEntry`) and the cart-wide `amountDue`.
|
|
28
|
+
`cart.removeGiftCardEntry(cartId, entryId, options?)` removes one card; `removeGiftCard` now removes every card.
|
|
29
|
+
The checkout summary's type `EldraOrderPreview` carries `giftCards` (`EldraOrderPreviewGiftCard`, `{last4,
|
|
30
|
+
amount}`). The cart's `giftCard` and `EldraCartGiftCard` are deprecated: the contract answers them for one more
|
|
31
|
+
version. The contract fixtures are regenerated from 6.8.0.
|
|
32
|
+
- **One code field (contract 6.7.0).** `cart.applyCode(cartId, code, options?)` applies a gift card or a discount
|
|
33
|
+
code from one input and answers the cart with `appliedAs` (`GIFT_CARD` or `DISCOUNT`); the type is
|
|
34
|
+
`EldraCartAppliedCode`. A code that is neither is 404 `CART_CODE_INVALID`. `applyDiscount` and
|
|
35
|
+
`applyGiftCard` stay.
|
|
36
|
+
- **The shared SEO value on catalog reads (contract 6.6.0).** A product's, category's, collection's and brand's
|
|
37
|
+
`seo` now carries `canonicalUrl`, `ogTitle`, `ogDescription`, `imageAssetId`, `imageUrl` and `noindex` beside
|
|
38
|
+
`title` and `description`: the shape a CMS entry's `seo` field has. Types only; the contract fixtures are
|
|
39
|
+
regenerated from 6.6.0. A product card (the product list and a collection's products) carries `seo` with
|
|
40
|
+
`canonicalUrl` and `noindex` only, which the theme's sitemap reads.
|
|
41
|
+
- **Brands and gift cards (contract 6.4.0).** `catalog.listBrands(options?)` reads the shop's active brands
|
|
42
|
+
(`[]` for none) and `catalog.getBrand(slug, options?)` one of them (404 `CATALOG_BRAND_NOT_FOUND` otherwise);
|
|
43
|
+
`cart.applyGiftCard(cartId, code, options?)` and `cart.removeGiftCard(cartId, options?)` put a gift card on the
|
|
44
|
+
cart and take it off, answering the cart (its `giftCard {last4, balance, applied, amountDue}`). A refused card
|
|
45
|
+
is an `EldraHttpError` with the contract's `errorId` (`CART_GIFT_CARD_INVALID`, `CART_GIFT_CARD_EXHAUSTED`,
|
|
46
|
+
`CART_DISCOUNT_TOO_MANY_ATTEMPTS`, `CART_GIFT_CARD_UNAVAILABLE`). New types `EldraBrand` and `EldraCartGiftCard`.
|
|
47
|
+
A product's `brand` and `seo`, a variant's `regularPrice`, `priorPrice` and `discount`, a card's `priorPrice`
|
|
48
|
+
and `discountLabel`, a cart line's `salePrice` and the list filter `brandId` need nothing new: they come from
|
|
49
|
+
the generated contract. Needs a gateway on contract 6.4.0 or later.
|
|
50
|
+
|
|
51
|
+
- **Typed product extensions (WS-439, contract 6.1.0).** `EldraProductDetails.extensions` is keyed by
|
|
52
|
+
the apiId of each CMS schema that extends products, and its type is the new, initially empty
|
|
53
|
+
`EldraProductExtensions` registry. The CMS types the Vite plugin writes now fill it in (`eldra-theme types` writes the
|
|
54
|
+
same augmentation, for `@eldrajs/sdk`; both ask the gateway for it with `sdkAugmentation=true`, so any other
|
|
55
|
+
consumer of `/cms/v1/typescript-definitions` gets plain interfaces with no `declare module`), so `product.extensions?.clothing?.material` type-checks; before generation it is
|
|
56
|
+
`{}`, not `unknown`. If you set the plugin's `sdkImport`, the augmentation in `cms-types.ts` names that import;
|
|
57
|
+
`eldra-theme types` has no such option and always targets `@eldrajs/sdk` (`--no-sdk-augmentation` leaves the block out).
|
|
58
|
+
Needs a gateway on contract 6.1.0 or later to return `extensions`.
|
|
59
|
+
|
|
12
60
|
- **`installIcelandicIntl()` (new entry `@eldrajs/sdk/format/intl`)** — Icelandic for code that calls
|
|
13
61
|
`Intl` itself (date pickers, vue-i18n, chart libraries). Where the runtime has no Icelandic data,
|
|
14
62
|
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
|
|
@@ -106,17 +122,17 @@ Lists, relative times, names and sorting are not patched; use the functions abov
|
|
|
106
122
|
|
|
107
123
|
## What is in the client
|
|
108
124
|
|
|
109
|
-
| Group | Methods
|
|
110
|
-
| ----------- |
|
|
111
|
-
| `catalog` | `listProducts`, `getProduct`, `listCategories`, `listCollections`, `getCollection`, `listCollectionProducts`, `search`
|
|
112
|
-
| `cms` | `list`, `get`, `getEntryByUniqueField`, `resolveEntryList`
|
|
113
|
-
| `cart` | `addItem`, `get`, `updateItem`, `removeItem`, `applyDiscount`, `removeDiscount`
|
|
114
|
-
| `checkout` | `url`
|
|
115
|
-
| `orders` | `get`, `recover`
|
|
116
|
-
| `inventory` | `availability`
|
|
117
|
-
| `features` | `getOrganization`, `list`, `isEnabled`, `getCapabilities`, `getCommerce`
|
|
118
|
-
| `platform` | `config`
|
|
119
|
-
| `forms` | `get`, `submit`, `confirm`, `unsubscribe`
|
|
125
|
+
| Group | Methods |
|
|
126
|
+
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
127
|
+
| `catalog` | `listProducts`, `getProduct`, `listCategories`, `listCollections`, `getCollection`, `listCollectionProducts`, `listBrands`, `getBrand`, `search` |
|
|
128
|
+
| `cms` | `list`, `get`, `getEntryByUniqueField`, `resolveEntryList` |
|
|
129
|
+
| `cart` | `addItem`, `get`, `updateItem`, `removeItem`, `applyDiscount`, `removeDiscount`, `removeDiscountEntry`, `applyCode`, `applyGiftCard`, `removeGiftCard`, `removeGiftCardEntry` |
|
|
130
|
+
| `checkout` | `url` |
|
|
131
|
+
| `orders` | `get`, `recover` |
|
|
132
|
+
| `inventory` | `availability` |
|
|
133
|
+
| `features` | `getOrganization`, `list`, `isEnabled`, `getCapabilities`, `getCommerce` |
|
|
134
|
+
| `platform` | `config` |
|
|
135
|
+
| `forms` | `get`, `submit`, `confirm`, `unsubscribe` |
|
|
120
136
|
|
|
121
137
|
`forms` is the site-forms API: `get(key)` reads a form's definition (fields with a label per locale,
|
|
122
138
|
the honeypot field's name, the Turnstile site key, the success message), and `submit(key, { values,
|
|
@@ -256,6 +272,9 @@ createEldraClient({ orgId: 'your-organisation-id', retry: { attempts: 0 } });
|
|
|
256
272
|
A consumer-supplied `httpClient` replaces the transport, so the retry is that client's own.
|
|
257
273
|
|
|
258
274
|
Every failed request throws `EldraHttpError` with `status`, the problem's category `code` (such as
|
|
259
|
-
`NOT_FOUND`) and its specific `errorId` (such as `CART_NOT_FOUND`); branch on `errorId`.
|
|
275
|
+
`NOT_FOUND`) and its specific `errorId` (such as `CART_NOT_FOUND`); branch on `errorId`. A refusal
|
|
276
|
+
that says more carries it in `errors`, the problem's `errors` object: a discount code refused with
|
|
277
|
+
`CART_DISCOUNT_NOT_COMBINABLE` names the code on the cart that blocks it in `errors.blockingCode`,
|
|
278
|
+
and `CART_DISCOUNT_CODES_LIMIT_REACHED` the limit (6) in `errors.limit`.
|
|
260
279
|
`createCartSession` and `createOrderAccessTokens` persist the cart id and order tokens without
|
|
261
280
|
throwing where storage is unavailable.
|
|
@@ -389,6 +389,13 @@ var EldraHttpError = class extends Error {
|
|
|
389
389
|
* than "something went wrong".
|
|
390
390
|
*/
|
|
391
391
|
errorId;
|
|
392
|
+
/**
|
|
393
|
+
* The gateway's problem `errors` — the refusal's detail, when the body carried it as an object.
|
|
394
|
+
* A refused discount code names what blocked it here: `errors.blockingCode` on
|
|
395
|
+
* `CART_DISCOUNT_NOT_COMBINABLE`, `errors.limit` on `CART_DISCOUNT_CODES_LIMIT_REACHED`. Its
|
|
396
|
+
* members depend on the `errorId`, so read each as unknown and check its type.
|
|
397
|
+
*/
|
|
398
|
+
errors;
|
|
392
399
|
constructor(response, body) {
|
|
393
400
|
super(`Web Studio request failed with ${response.status} ${response.statusText}`);
|
|
394
401
|
this.name = "EldraHttpError";
|
|
@@ -397,6 +404,7 @@ var EldraHttpError = class extends Error {
|
|
|
397
404
|
this.body = body;
|
|
398
405
|
this.code = problemString(body, "code");
|
|
399
406
|
this.errorId = problemString(body, "errorId");
|
|
407
|
+
this.errors = problemErrors(body);
|
|
400
408
|
}
|
|
401
409
|
};
|
|
402
410
|
/** One field of an RFC 9457 problem body, when the body is an object that carries it as a string. */
|
|
@@ -406,6 +414,24 @@ function problemString(body, key) {
|
|
|
406
414
|
return typeof value === "string" ? value : void 0;
|
|
407
415
|
}
|
|
408
416
|
}
|
|
417
|
+
/** The problem's `errors` member, when the body is an object that carries it as a plain object. */
|
|
418
|
+
function problemErrors(body) {
|
|
419
|
+
if (body && typeof body === "object" && "errors" in body) {
|
|
420
|
+
const value = body.errors;
|
|
421
|
+
if (value && typeof value === "object" && !Array.isArray(value)) return value;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Whether the cart answered to an apply holds the code: in `discountCodes` (contract 6.9.0, any
|
|
426
|
+
* case), else, from an older gateway that answers only `discountCode`, when that is the code.
|
|
427
|
+
*/
|
|
428
|
+
function cartHoldsDiscountCode(cart, code) {
|
|
429
|
+
const wanted = code.toUpperCase();
|
|
430
|
+
const record = cart ?? {};
|
|
431
|
+
const same = (value) => typeof value === "string" && value.trim().toUpperCase() === wanted;
|
|
432
|
+
if (Array.isArray(record.discountCodes)) return record.discountCodes.some((entry) => !!entry && typeof entry === "object" && same(entry.code));
|
|
433
|
+
return same(record.discountCode);
|
|
434
|
+
}
|
|
409
435
|
function initEldraClient(options) {
|
|
410
436
|
defaultClient = createEldraClient(options);
|
|
411
437
|
return defaultClient;
|
|
@@ -536,6 +562,16 @@ function createEldraClient(options) {
|
|
|
536
562
|
path: `/catalog/v1/collections/${encodeURIComponent(slug)}/products`,
|
|
537
563
|
query: listOptions
|
|
538
564
|
}),
|
|
565
|
+
listBrands: async (localeOptions, context) => await request({
|
|
566
|
+
...context,
|
|
567
|
+
path: "/catalog/v1/brands",
|
|
568
|
+
query: localeOptions
|
|
569
|
+
}) ?? [],
|
|
570
|
+
getBrand: (slug, localeOptions, context) => request({
|
|
571
|
+
...context,
|
|
572
|
+
path: `/catalog/v1/brands/${encodeURIComponent(slug)}`,
|
|
573
|
+
query: localeOptions
|
|
574
|
+
}),
|
|
539
575
|
search: (query, searchOptions, context) => request({
|
|
540
576
|
...context,
|
|
541
577
|
path: "/search/v1",
|
|
@@ -583,10 +619,9 @@ function createEldraClient(options) {
|
|
|
583
619
|
query: localeOptions,
|
|
584
620
|
body: { code: trimmed }
|
|
585
621
|
});
|
|
586
|
-
const discountCode = cart.discountCode;
|
|
587
622
|
return {
|
|
588
623
|
cart,
|
|
589
|
-
applied:
|
|
624
|
+
applied: cartHoldsDiscountCode(cart, trimmed)
|
|
590
625
|
};
|
|
591
626
|
},
|
|
592
627
|
removeDiscount: (cartId, localeOptions, context) => request({
|
|
@@ -594,6 +629,38 @@ function createEldraClient(options) {
|
|
|
594
629
|
method: "DELETE",
|
|
595
630
|
path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}/discount`,
|
|
596
631
|
query: localeOptions
|
|
632
|
+
}),
|
|
633
|
+
applyGiftCard: (cartId, code, localeOptions, context) => request({
|
|
634
|
+
...context,
|
|
635
|
+
method: "PUT",
|
|
636
|
+
path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}/gift-card`,
|
|
637
|
+
query: localeOptions,
|
|
638
|
+
body: { code: code.trim() }
|
|
639
|
+
}),
|
|
640
|
+
applyCode: (cartId, code, localeOptions, context) => request({
|
|
641
|
+
...context,
|
|
642
|
+
method: "PUT",
|
|
643
|
+
path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}/code`,
|
|
644
|
+
query: localeOptions,
|
|
645
|
+
body: { code: code.trim() }
|
|
646
|
+
}),
|
|
647
|
+
removeGiftCard: (cartId, localeOptions, context) => request({
|
|
648
|
+
...context,
|
|
649
|
+
method: "DELETE",
|
|
650
|
+
path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}/gift-card`,
|
|
651
|
+
query: localeOptions
|
|
652
|
+
}),
|
|
653
|
+
removeGiftCardEntry: (cartId, entryId, localeOptions, context) => request({
|
|
654
|
+
...context,
|
|
655
|
+
method: "DELETE",
|
|
656
|
+
path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}/gift-cards/${encodeURIComponent(entryId)}`,
|
|
657
|
+
query: localeOptions
|
|
658
|
+
}),
|
|
659
|
+
removeDiscountEntry: (cartId, code, localeOptions, context) => request({
|
|
660
|
+
...context,
|
|
661
|
+
method: "DELETE",
|
|
662
|
+
path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}/discount-codes/${encodeURIComponent(code)}`,
|
|
663
|
+
query: localeOptions
|
|
597
664
|
})
|
|
598
665
|
},
|
|
599
666
|
orders: {
|
|
@@ -886,8 +953,8 @@ function buildUrl(apiBaseUrl, path, query) {
|
|
|
886
953
|
* `filter` has to be in here — a filter token is `[groupIndex:]field:op:value`
|
|
887
954
|
* whose value may itself contain commas (`slug:in:a,b`), so joining several
|
|
888
955
|
* 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
|
|
956
|
+
* is lost. The catalog product filters (`categoryId`, `collectionId`, `option`,
|
|
957
|
+
* `ext` on `GET /catalog/v1/products/list` and
|
|
891
958
|
* `GET /catalog/v1/collections/{slug}/products`) are declared the same way, and
|
|
892
959
|
* each is an OR over its values: comma-joined, `categoryId=a,b` is one id the
|
|
893
960
|
* catalogue has never heard of, so a shopper ticking two categories would see
|
|
@@ -897,7 +964,8 @@ const REPEATED_QUERY_KEYS = /* @__PURE__ */ new Set([
|
|
|
897
964
|
"filter",
|
|
898
965
|
"categoryId",
|
|
899
966
|
"collectionId",
|
|
900
|
-
"option"
|
|
967
|
+
"option",
|
|
968
|
+
"ext"
|
|
901
969
|
]);
|
|
902
970
|
function appendQueryValue(searchParams, key, value) {
|
|
903
971
|
if (value === void 0 || value === null || value === "") return;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as EldraOrderDiscountCode, $t as EldraCartSession, A as EldraCollection, At as EldraSearchOptions, B as EldraFormField, Bt as EldraContractMethod, C as EldraCmsEntryListFilterCriterion, Ct as EldraProductThumbnail, D as EldraCmsResolveEntryListOptions, Dt as EldraRequestContext, E as EldraCmsListOptions, Et as EldraRecoveredBasketItem, F as EldraFeature, Ft as RuntimeEnv, G as EldraFormSubmitResult, Gt as EldraContractResponse, H as EldraFormFieldType, Ht as EldraContractPaths, I as EldraFeatureCapabilities, It as RuntimeValue, J as EldraHttpClient, Jt as captureCampaignAttribution, K as EldraFormTokenResult, Kt as EldraCampaignAttribution, L as EldraFeatureClient, Lt as EldraContract, M as EldraCollectionListOptions, Mt as EldraStockAvailability, N as EldraCollectionProductsOptions, Nt as EldraStockAvailabilityInput, O as EldraCmsResolveEntryListResponse, Ot as EldraRequestOptions, P as EldraDiscountResult, Pt as EldraStockAvailabilityItem, Q as EldraOrder, Qt as withdrawCampaignAttributionConsent, R as EldraFormActionKind, Rt as EldraContractBody, S as EldraCmsEntryListEntry, St as EldraProductOptionValue, T as EldraCmsGetOptions, Tt as EldraRecoveredBasket, U as EldraFormLocalized, Ut as EldraContractProp, V as EldraFormFieldOption, Vt as EldraContractPath, W as EldraFormSubmitInput, Wt as EldraContractQuery, X as EldraInventoryClient, Xt as grantCampaignAttributionConsent, Y as EldraHttpRequest, Yt as clearCampaignAttribution, Z as EldraLocaleOptions, Zt as readCampaignAttribution, _ as EldraClient, _t as EldraProductExtensions, a as EldraCartClient, an as createOrderAccessTokens, at as EldraOrdersClient, b as EldraCmsEntryList, bt as EldraProductMediaLink, c as EldraCartGiftCardEntry, ct as EldraOrganizationFeature, d as EldraCatalogClient, dt as EldraPageMeta, en as EldraCartSessionOptions, et as EldraOrderLine, f as EldraCatalogGetProductOptions, ft as EldraPaginated, g as EldraCheckoutUrlOptions, gt as EldraProductDetails, h as EldraCheckoutClient, ht as EldraPlatformReadOptions, i as EldraCartAppliedCode, in as createCartSession, it as EldraOrderReadOptions, j as EldraCollectionList, jt as EldraSearchResponse, k as EldraCmsResolvedEntryList, kt as EldraRetryOptions, l as EldraCartItem, lt as EldraOrganizationLocales, m as EldraCategory, mt as EldraPlatformConfig, n as EldraBrand, nn as EldraOrderAccessTokenOptions, nt as EldraOrderPreviewDiscountCode, o as EldraCartDiscountCodeEntry, ot as EldraOrganizationCommerce, p as EldraCatalogListProductsOptions, pt as EldraPlatformClient, q as EldraFormsClient, qt as EldraCampaignAttributionOptions, r as EldraCart, rn as EldraOrderAccessTokens, rt as EldraOrderPreviewGiftCard, s as EldraCartGiftCard, st as EldraOrganizationDetails, t as EldraAddCartItemInput, tn as EldraKeyValueStorage, tt as EldraOrderPreview, u as EldraCartTotals, ut as EldraOrganizationOptions, v as EldraClientOptions, vt as EldraProductList, w as EldraCmsGetEntryByUniqueFieldOptions, wt as EldraProductVariant, x as EldraCmsEntryListDisplayMode, xt as EldraProductOption, y as EldraCmsClient, yt as EldraProductListItem, z as EldraFormDefinition, zt as EldraContractItem } from "./types-D71CuE-g.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;
|
|
@@ -15,6 +15,13 @@ export declare class EldraHttpError extends Error {
|
|
|
15
15
|
* than "something went wrong".
|
|
16
16
|
*/
|
|
17
17
|
readonly errorId: string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* The gateway's problem `errors` — the refusal's detail, when the body carried it as an object.
|
|
20
|
+
* A refused discount code names what blocked it here: `errors.blockingCode` on
|
|
21
|
+
* `CART_DISCOUNT_NOT_COMBINABLE`, `errors.limit` on `CART_DISCOUNT_CODES_LIMIT_REACHED`. Its
|
|
22
|
+
* members depend on the `errorId`, so read each as unknown and check its type.
|
|
23
|
+
*/
|
|
24
|
+
readonly errors: Readonly<Record<string, unknown>> | undefined;
|
|
18
25
|
constructor(response: Response, body: unknown);
|
|
19
26
|
}
|
|
20
27
|
export declare function initEldraClient(options: EldraClientOptions): EldraClient;
|
|
@@ -114,4 +121,4 @@ interface EldraResponsiveImage {
|
|
|
114
121
|
* as `src` and no `srcset`. Returns `undefined` when there is no URL to render.
|
|
115
122
|
*/
|
|
116
123
|
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 };
|
|
124
|
+
export { type EldraAddCartItemInput, 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 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 EldraOrderDiscountCode, type EldraOrderLine, type EldraOrderPreview, type EldraOrderPreviewDiscountCode, type EldraOrderPreviewGiftCard, 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-DCs3cAQK.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'>>;
|
|
@@ -314,6 +317,10 @@ interface EldraCatalogClient {
|
|
|
314
317
|
listCollections(options?: EldraCollectionListOptions, context?: EldraRequestContext): Promise<EldraCollectionList>;
|
|
315
318
|
getCollection(slug: string, options?: EldraLocaleOptions, context?: EldraRequestContext): Promise<EldraCollection>;
|
|
316
319
|
listCollectionProducts(slug: string, options?: EldraCollectionProductsOptions, context?: EldraRequestContext): Promise<EldraProductList>;
|
|
320
|
+
/** The shop's active brands, ordered by name; `[]` for none (contract 6.4.0). */
|
|
321
|
+
listBrands(options?: EldraLocaleOptions, context?: EldraRequestContext): Promise<EldraBrand[]>;
|
|
322
|
+
/** One active brand; 404 `CATALOG_BRAND_NOT_FOUND` for a slug that is missing or not active. */
|
|
323
|
+
getBrand(slug: string, options?: EldraLocaleOptions, context?: EldraRequestContext): Promise<EldraBrand>;
|
|
317
324
|
search(query: string, options?: EldraSearchOptions, context?: EldraRequestContext): Promise<EldraSearchResponse>;
|
|
318
325
|
}
|
|
319
326
|
interface EldraFeatureClient {
|
|
@@ -360,21 +367,70 @@ type EldraCollectionList = EldraContractResponse<'/catalog/v1/collections', 'get
|
|
|
360
367
|
type EldraCollection = EldraContractResponse<'/catalog/v1/collections/{slug}', 'get'>;
|
|
361
368
|
type EldraCollectionListOptions = EldraContractQuery<'/catalog/v1/collections', 'get'>;
|
|
362
369
|
type EldraCollectionProductsOptions = EldraContractQuery<'/catalog/v1/collections/{slug}/products', 'get'>;
|
|
370
|
+
type EldraBrand = EldraContractResponse<'/catalog/v1/brands/{slug}', 'get'>;
|
|
363
371
|
type EldraSearchOptions = Omit<EldraContractQuery<'/search/v1', 'get'>, 'q'>;
|
|
364
372
|
type EldraSearchResponse = EldraContractResponse<'/search/v1', 'get'>;
|
|
365
373
|
type EldraCart = EldraContractResponse<'/shopping-cart/v1/cart/{cartID}', 'get'>;
|
|
366
374
|
type EldraCartItem = EldraContractItem<EldraContractProp<EldraCart, 'items'>>;
|
|
367
375
|
type EldraCartTotals = EldraContractProp<EldraCart, 'totals'>;
|
|
376
|
+
/**
|
|
377
|
+
* @deprecated Contract 6.8.0: a cart holds several gift cards. The cart's `giftCard` is the first
|
|
378
|
+
* of `giftCards`, except that its `amountDue` is the cart's `amountDue` (what is due after every
|
|
379
|
+
* card); it is answered for one more contract version. Read `giftCards`
|
|
380
|
+
* ({@link EldraCartGiftCardEntry}) and the cart's `amountDue` instead.
|
|
381
|
+
*/
|
|
382
|
+
type EldraCartGiftCard = EldraContractProp<EldraCart, 'giftCard'>;
|
|
383
|
+
/**
|
|
384
|
+
* One gift card on the cart (contract 6.8.0), from `giftCards`, in the order applied:
|
|
385
|
+
* `{entryId, last4, balance, applied, amountDue}`. `applied` is what it pays after the cards
|
|
386
|
+
* before it (0 when they already cover the total; such a card stays on the cart), `amountDue`
|
|
387
|
+
* what is still due after it. `entryId` names the card on this cart for
|
|
388
|
+
* `cart.removeGiftCardEntry`; it is not the card's id or code.
|
|
389
|
+
*/
|
|
390
|
+
type EldraCartGiftCardEntry = EldraContractItem<EldraContractProp<EldraCart, 'giftCards'>>;
|
|
391
|
+
/**
|
|
392
|
+
* One discount code on the cart (contract 6.9.0), from `discountCodes`, in the order added:
|
|
393
|
+
* `{code, amount}`. Each code applies to what the codes before it left, and `amount` (major
|
|
394
|
+
* units) is what it takes now: 0 for a code that reduces nothing at the moment (nothing left to
|
|
395
|
+
* reduce, only gift-card lines, or a code the shop has since stopped letting combine); such a
|
|
396
|
+
* code stays on the cart. `code` names it for `cart.removeDiscountEntry`. The cart's deprecated
|
|
397
|
+
* `discountCode` is the first of these whose `amount` is above 0.
|
|
398
|
+
*/
|
|
399
|
+
type EldraCartDiscountCodeEntry = EldraContractItem<EldraContractProp<EldraCart, 'discountCodes'>>;
|
|
400
|
+
/** The cart after `cart.applyCode`, with `appliedAs` saying which kind the code was. */
|
|
401
|
+
type EldraCartAppliedCode = EldraContractResponse<'/shopping-cart/v1/cart/{cartID}/code', 'put'>;
|
|
368
402
|
type EldraAddCartItemInput = EldraContractBody<'/shopping-cart/v1/cart/items', 'post'>;
|
|
369
403
|
interface EldraDiscountResult {
|
|
370
404
|
cart: EldraCart;
|
|
371
|
-
/**
|
|
405
|
+
/**
|
|
406
|
+
* The server drops a code it will not honour, so the returned cart is the verdict: true when the
|
|
407
|
+
* cart's `discountCodes` holds the code (any case; since contract 6.9.0, even while it takes 0),
|
|
408
|
+
* or, from a gateway older than 6.9.0, when its single `discountCode` is the code.
|
|
409
|
+
*/
|
|
372
410
|
applied: boolean;
|
|
373
411
|
}
|
|
374
412
|
type EldraOrder = EldraContractResponse<'/order/v1/{orderId}', 'get'>;
|
|
375
413
|
type EldraOrderLine = EldraContractItem<EldraContractProp<EldraOrder, 'orderLines'>>;
|
|
414
|
+
/**
|
|
415
|
+
* One discount code of an order (contract 6.9.0), from the order's `discountCodes`: each code that
|
|
416
|
+
* reduced the order, in the order applied, as `{code, amount}`. The order's `discountCode` is
|
|
417
|
+
* deprecated (the first of these).
|
|
418
|
+
*/
|
|
419
|
+
type EldraOrderDiscountCode = EldraContractItem<EldraContractProp<EldraOrder, 'discountCodes'>>;
|
|
376
420
|
type EldraRecoveredBasket = EldraContractResponse<'/order/v1/recover', 'post'>;
|
|
377
421
|
type EldraRecoveredBasketItem = EldraContractItem<EldraContractProp<EldraRecoveredBasket, 'items'>>;
|
|
422
|
+
/** The checkout summary `POST /order/v1/preview` answers (the hosted checkout reads it). */
|
|
423
|
+
type EldraOrderPreview = EldraContractResponse<'/order/v1/preview', 'post'>;
|
|
424
|
+
/**
|
|
425
|
+
* One gift card of the checkout summary (contract 6.8.0), from `giftCards`: each card that would
|
|
426
|
+
* pay something, in the order applied, as `{last4, amount}`; they sum to `giftCardAmount`.
|
|
427
|
+
*/
|
|
428
|
+
type EldraOrderPreviewGiftCard = EldraContractItem<EldraContractProp<EldraOrderPreview, 'giftCards'>>;
|
|
429
|
+
/**
|
|
430
|
+
* One discount code of the checkout summary (contract 6.9.0), from `discountCodes`: each code that
|
|
431
|
+
* would reduce the order, in the order applied, as `{code, amount}`.
|
|
432
|
+
*/
|
|
433
|
+
type EldraOrderPreviewDiscountCode = EldraContractItem<EldraContractProp<EldraOrderPreview, 'discountCodes'>>;
|
|
378
434
|
interface EldraOrderReadOptions {
|
|
379
435
|
/** The one-time token returned when the order was created. Required unless the caller owns the order. */
|
|
380
436
|
accessToken?: string;
|
|
@@ -419,8 +475,72 @@ interface EldraCartClient {
|
|
|
419
475
|
quantity: number;
|
|
420
476
|
}, context?: EldraRequestContext): Promise<EldraCart>;
|
|
421
477
|
removeItem(cartId: string, itemId: string, context?: EldraRequestContext): Promise<EldraCart>;
|
|
478
|
+
/**
|
|
479
|
+
* Applies a discount code and answers the cart with `applied` (see {@link EldraDiscountResult}).
|
|
480
|
+
* Since contract 6.9.0 a discount code is **added** after the cart's codes instead of replacing
|
|
481
|
+
* one; each applies to what the codes before it left, at most 6 per cart, and two codes sit
|
|
482
|
+
* together only when both allow combining. Three refusals leave the cart exactly as it was, each a
|
|
483
|
+
* 409 `EldraHttpError` read from `errorId`, with its detail in `errors` (the problem's `errors`
|
|
484
|
+
* object): `CART_DISCOUNT_NOT_COMBINABLE` (the code and a code on the cart cannot both be used;
|
|
485
|
+
* `errors.blockingCode` is the code on the cart that blocks it, for "cannot be combined with
|
|
486
|
+
* SUMMER10"; remove it with `removeDiscountEntry` and apply again to change codes),
|
|
487
|
+
* `CART_DISCOUNT_CODES_LIMIT_REACHED` (the cart already holds `errors.limit` codes, 6) and
|
|
488
|
+
* `CART_DISCOUNT_ALREADY_APPLIED` (the cart already holds this code).
|
|
489
|
+
* Other refusals are unchanged: `CART_DISCOUNT_NOT_USABLE`, `CART_DISCOUNT_EXHAUSTED`,
|
|
490
|
+
* `CART_DISCOUNT_TOO_MANY_ATTEMPTS`.
|
|
491
|
+
*/
|
|
422
492
|
applyDiscount(cartId: string, code: string, options?: EldraLocaleOptions, context?: EldraRequestContext): Promise<EldraDiscountResult>;
|
|
493
|
+
/**
|
|
494
|
+
* Removes every discount code on the cart (contract 6.9.0; before it, the one code); succeeds
|
|
495
|
+
* when none is applied. To take off one code, use `removeDiscountEntry`.
|
|
496
|
+
*/
|
|
423
497
|
removeDiscount(cartId: string, options?: EldraLocaleOptions, context?: EldraRequestContext): Promise<EldraCart>;
|
|
498
|
+
/**
|
|
499
|
+
* Adds a gift card (contract 6.4.0; since 6.8.0 it adds the card after the cart's other cards
|
|
500
|
+
* instead of replacing one, with no limit, and the discount code stays). A refusal is an
|
|
501
|
+
* `EldraHttpError` whose `errorId` names it: `CART_GIFT_CARD_INVALID`, `CART_GIFT_CARD_EXHAUSTED`,
|
|
502
|
+
* `CART_GIFT_CARD_ALREADY_APPLIED` (409, the cart already holds this card),
|
|
503
|
+
* `CART_DISCOUNT_TOO_MANY_ATTEMPTS`, `CART_GIFT_CARD_UNAVAILABLE`.
|
|
504
|
+
*/
|
|
505
|
+
applyGiftCard(cartId: string, code: string, options?: EldraLocaleOptions, context?: EldraRequestContext): Promise<EldraCart>;
|
|
506
|
+
/**
|
|
507
|
+
* Applies a code from one field, as whichever it is (contract 6.7.0): a gift card or a discount
|
|
508
|
+
* code. The answer is the cart with `appliedAs` (`GIFT_CARD` or `DISCOUNT`). Since 6.8.0 a gift
|
|
509
|
+
* card is added after the cart's other cards; remove one with `removeGiftCardEntry`, or one
|
|
510
|
+
* discount code with `removeDiscountEntry`. A refusal is an `EldraHttpError` whose `errorId` names it:
|
|
511
|
+
* `CART_CODE_INVALID` (neither kind; the answer does not say which exists), `CART_CODE_REQUIRED`,
|
|
512
|
+
* `CART_GIFT_CARD_EXHAUSTED`, `CART_GIFT_CARD_ALREADY_APPLIED` (409, the cart already holds this
|
|
513
|
+
* card; the code is not then tried as a discount code), `CART_DISCOUNT_EXHAUSTED`,
|
|
514
|
+
* `CART_DISCOUNT_TOO_MANY_ATTEMPTS`, `CART_GIFT_CARD_UNAVAILABLE`.
|
|
515
|
+
*
|
|
516
|
+
* Since contract 6.9.0 a discount code is **added** after the cart's codes instead of replacing
|
|
517
|
+
* one; each applies to what the codes before it left, at most 6 per cart, and two codes sit
|
|
518
|
+
* together only when both allow combining. Three refusals leave the cart exactly as it was, each a
|
|
519
|
+
* 409 `EldraHttpError` read from `errorId`, with its detail in `errors` (the problem's `errors`
|
|
520
|
+
* object): `CART_DISCOUNT_NOT_COMBINABLE` (the code and a code on the cart cannot both be used;
|
|
521
|
+
* `errors.blockingCode` is the code on the cart that blocks it, for "cannot be combined with
|
|
522
|
+
* SUMMER10"; remove it with `removeDiscountEntry` and apply again to change codes),
|
|
523
|
+
* `CART_DISCOUNT_CODES_LIMIT_REACHED` (the cart already holds `errors.limit` codes, 6) and
|
|
524
|
+
* `CART_DISCOUNT_ALREADY_APPLIED` (the cart already holds this code).
|
|
525
|
+
*/
|
|
526
|
+
applyCode(cartId: string, code: string, options?: EldraLocaleOptions, context?: EldraRequestContext): Promise<EldraCartAppliedCode>;
|
|
527
|
+
/**
|
|
528
|
+
* Removes every gift card on the cart (contract 6.8.0; before it, the one card); succeeds when
|
|
529
|
+
* none is applied. To take off one card, use `removeGiftCardEntry`.
|
|
530
|
+
*/
|
|
531
|
+
removeGiftCard(cartId: string, options?: EldraLocaleOptions, context?: EldraRequestContext): Promise<EldraCart>;
|
|
532
|
+
/**
|
|
533
|
+
* Removes one gift card, the one whose `giftCards[].entryId` is `entryId` (contract 6.8.0), and
|
|
534
|
+
* answers the cart; the other cards keep their order. An `entryId` the cart does not hold answers
|
|
535
|
+
* the cart unchanged, so a double click does not fail.
|
|
536
|
+
*/
|
|
537
|
+
removeGiftCardEntry(cartId: string, entryId: string, options?: EldraLocaleOptions, context?: EldraRequestContext): Promise<EldraCart>;
|
|
538
|
+
/**
|
|
539
|
+
* Removes one discount code, the one whose `discountCodes[].code` is `code` (any case; contract
|
|
540
|
+
* 6.9.0), and answers the cart; the other codes keep their order. A code the cart does not hold
|
|
541
|
+
* answers the cart unchanged, so a double click does not fail.
|
|
542
|
+
*/
|
|
543
|
+
removeDiscountEntry(cartId: string, code: string, options?: EldraLocaleOptions, context?: EldraRequestContext): Promise<EldraCart>;
|
|
424
544
|
}
|
|
425
545
|
interface EldraOrdersClient {
|
|
426
546
|
get(orderId: string, options?: EldraOrderReadOptions, context?: EldraRequestContext): Promise<EldraOrder>;
|
|
@@ -547,4 +667,4 @@ interface EldraFormsClient {
|
|
|
547
667
|
/** `POST /site/v1/forms/subscriptions/unsubscribe?token=` (a GET of the link is only a page). */
|
|
548
668
|
unsubscribe(token: string, context?: EldraRequestContext): Promise<EldraFormTokenResult>;
|
|
549
669
|
}
|
|
550
|
-
export {
|
|
670
|
+
export { EldraOrderDiscountCode as $, EldraCartSession as $t, EldraCollection as A, EldraSearchOptions as At, EldraFormField as B, EldraContractMethod as Bt, EldraCmsEntryListFilterCriterion as C, EldraProductThumbnail as Ct, EldraCmsResolveEntryListOptions as D, EldraRequestContext as Dt, EldraCmsListOptions as E, EldraRecoveredBasketItem as Et, EldraFeature as F, RuntimeEnv as Ft, EldraFormSubmitResult as G, EldraContractResponse as Gt, EldraFormFieldType as H, EldraContractPaths as Ht, EldraFeatureCapabilities as I, RuntimeValue as It, EldraHttpClient as J, captureCampaignAttribution as Jt, EldraFormTokenResult as K, EldraCampaignAttribution as Kt, EldraFeatureClient as L, EldraContract as Lt, EldraCollectionListOptions as M, EldraStockAvailability as Mt, EldraCollectionProductsOptions as N, EldraStockAvailabilityInput as Nt, EldraCmsResolveEntryListResponse as O, EldraRequestOptions as Ot, EldraDiscountResult as P, EldraStockAvailabilityItem as Pt, EldraOrder as Q, withdrawCampaignAttributionConsent as Qt, EldraFormActionKind as R, EldraContractBody as Rt, EldraCmsEntryListEntry as S, EldraProductOptionValue as St, EldraCmsGetOptions as T, EldraRecoveredBasket as Tt, EldraFormLocalized as U, EldraContractProp as Ut, EldraFormFieldOption as V, EldraContractPath as Vt, EldraFormSubmitInput as W, EldraContractQuery as Wt, EldraInventoryClient as X, grantCampaignAttributionConsent as Xt, EldraHttpRequest as Y, clearCampaignAttribution as Yt, EldraLocaleOptions as Z, readCampaignAttribution as Zt, EldraClient as _, EldraProductExtensions as _t, EldraCartClient as a, createOrderAccessTokens as an, EldraOrdersClient as at, EldraCmsEntryList as b, EldraProductMediaLink as bt, EldraCartGiftCardEntry as c, EldraOrganizationFeature as ct, EldraCatalogClient as d, EldraPageMeta as dt, EldraCartSessionOptions as en, EldraOrderLine as et, EldraCatalogGetProductOptions as f, EldraPaginated as ft, EldraCheckoutUrlOptions as g, EldraProductDetails as gt, EldraCheckoutClient as h, EldraPlatformReadOptions as ht, EldraCartAppliedCode as i, createCartSession as in, EldraOrderReadOptions as it, EldraCollectionList as j, EldraSearchResponse as jt, EldraCmsResolvedEntryList as k, EldraRetryOptions as kt, EldraCartItem as l, EldraOrganizationLocales as lt, EldraCategory as m, EldraPlatformConfig as mt, EldraBrand as n, EldraOrderAccessTokenOptions as nn, EldraOrderPreviewDiscountCode as nt, EldraCartDiscountCodeEntry as o, EldraOrganizationCommerce as ot, EldraCatalogListProductsOptions as p, EldraPlatformClient as pt, EldraFormsClient as q, EldraCampaignAttributionOptions as qt, EldraCart as r, EldraOrderAccessTokens as rn, EldraOrderPreviewGiftCard as rt, EldraCartGiftCard as s, EldraOrganizationDetails as st, EldraAddCartItemInput as t, EldraKeyValueStorage as tn, EldraOrderPreview as tt, EldraCartTotals as u, EldraOrganizationOptions as ut, EldraClientOptions as v, EldraProductList as vt, EldraCmsGetEntryByUniqueFieldOptions as w, EldraProductVariant as wt, EldraCmsEntryListDisplayMode as x, EldraProductOption as xt, EldraCmsClient as y, EldraProductListItem as yt, EldraFormDefinition as z, EldraContractItem as zt };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ft as RuntimeEnv, It as RuntimeValue } from "./types-D71CuE-g.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-DCs3cAQK.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.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",
|
|
@@ -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",
|