@eldrajs/sdk 0.4.3 → 0.5.1
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 +90 -4
- package/dist/{client-DCs3cAQK.js → client-cO8GCJK9.js} +104 -4
- package/dist/index.d.ts +117 -6
- package/dist/index.js +130 -2
- package/dist/{types-D71CuE-g.d.ts → types-BrQEYrD5.d.ts} +110 -13
- 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,12 @@ platform repository.
|
|
|
9
9
|
|
|
10
10
|
## Unreleased
|
|
11
11
|
|
|
12
|
+
- **Removed: the checkout summary types.** `EldraOrderPreview`, `EldraOrderPreviewGiftCard` and
|
|
13
|
+
`EldraOrderPreviewDiscountCode` are no longer exported. They typed `POST /order/v1/preview`, which the SDK
|
|
14
|
+
never had a method for: delivery choice, the order summary, order creation and payment belong to the hosted
|
|
15
|
+
checkout, and the SDK stops at the cart and the handoff to it (`checkout.url`). A storefront reads a cart with
|
|
16
|
+
its codes and cards applied from `cart.get` (`discountCodes`, `giftCards`, `totals`, `amountDue`). If you
|
|
17
|
+
imported one of these types, declare the shape you read locally.
|
|
12
18
|
- **Several discount codes on one cart (contract 6.9.0).** `applyDiscount` and `applyCode` (as `DISCOUNT`) now add
|
|
13
19
|
a code after the cart's codes instead of replacing it; each applies to what the codes before it left. Three new
|
|
14
20
|
409 refusals leave the cart as it was: `CART_DISCOUNT_NOT_COMBINABLE` (the code and one on the cart cannot be
|
|
@@ -17,8 +23,8 @@ platform repository.
|
|
|
17
23
|
body carries one. The cart carries `discountCodes` (`{code, amount}` in the order added; the type is
|
|
18
24
|
`EldraCartDiscountCodeEntry`); `cart.removeDiscountEntry(cartId, code, options?)` removes one code and
|
|
19
25
|
`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
|
|
21
|
-
|
|
26
|
+
`discountCode` from an older gateway), so a second code reports `true`. The order read
|
|
27
|
+
carries `discountCodes` (`EldraOrderDiscountCode`). The cart's and the order's
|
|
22
28
|
`discountCode` are deprecated in the contract: it answers them for one more version. The contract fixtures are
|
|
23
29
|
regenerated from 6.9.0.
|
|
24
30
|
- **Several gift cards on one cart (contract 6.8.0).** A cart holds any number of gift cards beside its discount
|
|
@@ -26,8 +32,7 @@ platform repository.
|
|
|
26
32
|
again is 409 `CART_GIFT_CARD_ALREADY_APPLIED`. The cart carries `giftCards` (`{entryId, last4, balance, applied,
|
|
27
33
|
amountDue}` in the order applied; the type is `EldraCartGiftCardEntry`) and the cart-wide `amountDue`.
|
|
28
34
|
`cart.removeGiftCardEntry(cartId, entryId, options?)` removes one card; `removeGiftCard` now removes every card.
|
|
29
|
-
The
|
|
30
|
-
amount}`). The cart's `giftCard` and `EldraCartGiftCard` are deprecated: the contract answers them for one more
|
|
35
|
+
The cart's `giftCard` and `EldraCartGiftCard` are deprecated: the contract answers them for one more
|
|
31
36
|
version. The contract fixtures are regenerated from 6.8.0.
|
|
32
37
|
- **One code field (contract 6.7.0).** `cart.applyCode(cartId, code, options?)` applies a gift card or a discount
|
|
33
38
|
code from one input and answers the cart with `appliedAs` (`GIFT_CARD` or `DISCOUNT`); the type is
|
|
@@ -75,6 +80,74 @@ platform repository.
|
|
|
75
80
|
`clearCampaignAttribution()`, the `EldraCampaignAttribution` type and the client option
|
|
76
81
|
`campaignAttribution` (`{ storage }`, or `false` to send none). Nothing clears it automatically.
|
|
77
82
|
|
|
83
|
+
Business customers (B2B), for the next release after 0.4.3. Every entry below needs a gateway
|
|
84
|
+
serving public contract 6.15.0 (core merged main's 6.14.0 first).
|
|
85
|
+
|
|
86
|
+
- Contract 6.15.0. Business login: `shopIssuer`, `ELDRA_SHOP_CLIENT_ID`, `createPkcePair`,
|
|
87
|
+
`pkceChallenge`, `buildAuthorizeUrl`, `exchangeAuthorizationCode`, `refreshTokens` and
|
|
88
|
+
`buildLogoutUrl` (OIDC authorization code with PKCE against the shop realm, `EldraOidcError` on
|
|
89
|
+
failure), `bearer(accessToken)`, and `customer.me(context)` for the signed-in business customer
|
|
90
|
+
and their company memberships (`GET /customer/v1/me`). The token is passed
|
|
91
|
+
per call in `context.headers`. `EldraCustomerMe`, `EldraShopUser` and `EldraCustomerMembership`
|
|
92
|
+
are derived from the generated contract like every other response type. `refreshExpiresAt` is
|
|
93
|
+
`undefined` when the server sends no `refresh_expires_in`. See `docs/business-login.md`.
|
|
94
|
+
- `buildAuthorizeUrl` takes an optional `uiLocales` (a BCP 47 tag or a list, most preferred
|
|
95
|
+
first), sent as the OIDC `ui_locales` parameter so the shop login pages use the storefront's
|
|
96
|
+
language. No contract change.
|
|
97
|
+
- Customer prices (contract 6.15.0): catalog product, list and collection-product reads and cart
|
|
98
|
+
writes accept a signed-in token and `X-Customer-Id` per call in `context.headers`. Priced
|
|
99
|
+
variants carry `listPrice`, list items carry the customer's `minPrice` and `maxPrice`, and priced
|
|
100
|
+
responses have no `compareAtPrice`. `customerHeaders(accessToken, customerId?)` builds the
|
|
101
|
+
headers. Priced responses are `Cache-Control: private, no-store`. See `docs/customer-prices.md`.
|
|
102
|
+
- Customer carts (contract 6.15.0): cart and order error ids `CART_CUSTOMER_MISMATCH` (also on a
|
|
103
|
+
signed-in read), `CART_SIGN_IN_REQUIRED` (a guest may still remove a line),
|
|
104
|
+
`CART_CUSTOMER_PRICES_OFF`, `ORDER_CUSTOMER_PRICES_OFF`, `CART_DISCOUNT_NOT_FOR_CUSTOMER_PRICES`,
|
|
105
|
+
`CART_PRICES_UNAVAILABLE`. Every cart answer is `private, no-store`; binding drops the discount
|
|
106
|
+
code; list items carry `listPrice`. The docs explain tracking the binding and moving the cart.
|
|
107
|
+
- Customer carts (contract 6.15.0): an archived or unknown company answers 409
|
|
108
|
+
`CART_CUSTOMER_UNAVAILABLE` on cart writes and 409 `ORDER_CUSTOMER_UNAVAILABLE` on order create and
|
|
109
|
+
preview; treat them like `*_CUSTOMER_PRICES_OFF`. A bound
|
|
110
|
+
cart shows the prices stored when lines were added, and the order re-prices, so show the order
|
|
111
|
+
preview total before payment. No change to the generated contract.
|
|
112
|
+
- Sales orders and delivery locations (contract 6.15.0) for a signed-in business customer's active
|
|
113
|
+
company: `customer.locations(context)` (`GET /customer/v1/locations`, answered as the `{ data }`
|
|
114
|
+
envelope like every other list, the default first, `data` `[]` for none), `salesOrders.preview(input, context)`, `salesOrders.create(input, { idempotencyKey },
|
|
115
|
+
context)`, `salesOrders.list(options, context)` and `salesOrders.get(id, context)`. `create`
|
|
116
|
+
requires the idempotency key (1 to 255 printable ASCII characters, no spaces) and rejects with
|
|
117
|
+
`EldraIdempotencyKeyError` (a `TypeError`) without a usable one, sending nothing. Catch that class,
|
|
118
|
+
not every `TypeError`: a lost connection is a `TypeError` too and is retried with the key. Keep the key across
|
|
119
|
+
retries (a 502, a 503 or a timeout may follow a placed order, and the same key replays it) and
|
|
120
|
+
mint a new one when the cart or the form changes. Types derived from the contract:
|
|
121
|
+
`EldraCustomerLocationList`, `EldraCustomerLocation`, `EldraSalesOrderPreview`, `EldraSalesOrderPreviewLine`,
|
|
122
|
+
`EldraSalesOrderCredit`, `EldraSalesOrder`, `EldraSalesOrderLine`, `EldraSalesOrderWarning`,
|
|
123
|
+
`EldraSalesOrderDelivery`, `EldraSalesOrderStatus`, `EldraSalesOrderList`,
|
|
124
|
+
`EldraSalesOrderListItem`, `EldraSalesOrderListOptions`, `EldraSalesOrderPreviewInput`,
|
|
125
|
+
`EldraCreateSalesOrderInput`. `EldraSalesOrderCredit` carries `creditCurrency` when the company's
|
|
126
|
+
credit is kept in another currency than the order's. Warnings on create:
|
|
127
|
+
`SALES_ORDER_STOCK_NOT_SET_ASIDE`, `SALES_ORDER_PAYMENT_NOT_RECORDED` (the order stands). See
|
|
128
|
+
`docs/sales-orders.md`.
|
|
129
|
+
- Error ids are typed: `EldraHttpError.errorId` is `EldraErrorId`, the known `EldraShopErrorId` and
|
|
130
|
+
`EldraSalesOrderErrorId` values or any other string. New with sales orders: `CUSTOMER_BLOCKED`,
|
|
131
|
+
`SALES_ORDER_CREDIT_LIMIT_EXCEEDED`, `SALES_ORDER_CREDIT_CURRENCY_MISMATCH` (the supplier blocks
|
|
132
|
+
over-limit orders and keeps the credit in another currency; do not retry),
|
|
133
|
+
`SALES_ORDER_CREDIT_CHECK_UNAVAILABLE`,
|
|
134
|
+
`SALES_ORDER_CART_NOT_BOUND`, `SALES_ORDER_CART_EMPTY`, `SALES_ORDER_TOO_MANY_LINES`,
|
|
135
|
+
`SALES_ORDER_LINE_INVALID`, `SALES_ORDER_CART_ALREADY_ORDERED`, `SALES_ORDER_LOCATION_UNKNOWN`,
|
|
136
|
+
`SALES_ORDER_TERMS_UNAVAILABLE`, `SALES_ORDER_CART_UNAVAILABLE`,
|
|
137
|
+
`SALES_ORDER_IDEMPOTENCY_KEY_REQUIRED`, `SALES_ORDER_NOT_FOUND`, `SALES_ORDER_UPSTREAM_REFUSED`
|
|
138
|
+
(502: the supplier's order service refused the platform; never sign the person out over it), and
|
|
139
|
+
the reused `ORDER_CUSTOMER_UNAVAILABLE`, `ORDER_CUSTOMER_PRICES_OFF`, `ORDER_PRODUCT_UNAVAILABLE`,
|
|
140
|
+
`ORDER_PRICES_UNAVAILABLE`, `ORDER_IDEMPOTENCY_CONFLICT`. `EldraHttpError.errors` carries the
|
|
141
|
+
problem's details, such as `salesOrderId` on `SALES_ORDER_CART_ALREADY_ORDERED` and `variantId`
|
|
142
|
+
on `SALES_ORDER_LINE_INVALID`. `isEldraError(error, id)` narrows an unknown error to one refusal
|
|
143
|
+
and types its `errors` from `EldraProblemErrors` (`SALES_ORDER_CART_ALREADY_ORDERED`,
|
|
144
|
+
`SALES_ORDER_LINE_INVALID`, `ORDER_PRODUCT_UNAVAILABLE`, `SHIPPING_CART_NOT_EXPORTABLE`).
|
|
145
|
+
- New required interface members: `EldraClient.salesOrders` and `EldraCustomerClient.locations`. Code
|
|
146
|
+
that only calls the client is unaffected; code that implements these interfaces itself (a mock or a
|
|
147
|
+
wrapper) must add them.
|
|
148
|
+
|
|
149
|
+
## 0.3.2 — 2026-10-22
|
|
150
|
+
|
|
78
151
|
- **Images use the size the API gives them (contract 4.14.0).** `EldraImageSource` accepts the
|
|
79
152
|
`width` and `height` an image object now carries (its pixels as displayed). `imageSrcset` stops at
|
|
80
153
|
that width unless `originalWidth` is passed, and `responsiveImage` sets `width`/`height` to the
|
|
@@ -89,12 +162,16 @@ platform repository.
|
|
|
89
162
|
which most browsers cannot show as uploaded. A narrower original still ends the list at its own
|
|
90
163
|
width.
|
|
91
164
|
|
|
165
|
+
## 0.3.1 — 2026-10-19
|
|
166
|
+
|
|
92
167
|
- **`buildToken` client option (WS-403).** When set (a string or a function returning one), every
|
|
93
168
|
request carries `X-Eldra-Build-Token`, a read-only build token (`eldra_bld_…`, created in Studio → Settings → Developers → Build tokens),
|
|
94
169
|
so the gateway can give a theme build's reads their own rate-limit bucket. Server and build only;
|
|
95
170
|
omitted or empty sends no header. Never pass the site deploy token. Pass it from server-side code
|
|
96
171
|
only; an SSR server that sends it on every visitor request shares the organisation's build budget.
|
|
97
172
|
|
|
173
|
+
## 0.3.0 — 2026-10-18
|
|
174
|
+
|
|
98
175
|
- **`EldraFormDefinition.consentText` (WS-386, contract 4.13.0).** A form that subscribes the
|
|
99
176
|
visitor now publishes the consent sentence per locale, with the shop name already filled in
|
|
100
177
|
(`consentText?: EldraFormLocalized`, present only when `kinds` contains `subscribe`). Show it
|
|
@@ -118,6 +195,7 @@ platform repository.
|
|
|
118
195
|
and unsubscribes nobody. The two methods now `POST` the same paths with the token in the query and
|
|
119
196
|
still resolve `{ status }`; confirming or unsubscribing twice is a success. Needs a gateway at
|
|
120
197
|
contract 4.10.0 or later (the `GET` JSON answer of 4.7.0 to 4.9.0, never released, is gone).
|
|
198
|
+
|
|
121
199
|
- **`client.forms`: the site-forms API (WS-386).** `get(key)` reads a form definition,
|
|
122
200
|
`submit(key, { values, locale, pagePath, turnstileToken?, hp? })` posts a submission and
|
|
123
201
|
`confirm(token)` / `unsubscribe(token)` finish a subscriber's emailed links. A `422` resolves as
|
|
@@ -125,12 +203,18 @@ platform repository.
|
|
|
125
203
|
`404`, `413` and `429` reject with `EldraHttpError`. New types `EldraFormDefinition`,
|
|
126
204
|
`EldraFormField`, `EldraFormSubmitInput`, `EldraFormSubmitResult` and friends, hand-written like
|
|
127
205
|
`EldraPlatformConfig`. Needs a gateway at contract 4.4.0 or later.
|
|
206
|
+
|
|
207
|
+
## 0.2.9 — 2026-10-12
|
|
208
|
+
|
|
128
209
|
- **Icelandic formatting that prints the same on every runtime: `@eldrajs/sdk/format`.**
|
|
129
210
|
`numberFormat`, `formatPrice` and `comparator`/`compareIcelandic`, plus `./format/date`,
|
|
130
211
|
`./format/list`, `./format/relative-time` and `./format/display-names`. Icelandic and English come
|
|
131
212
|
from the package's own CLDR 48.2 data, so Chrome and Cloudflare Workers, which lack it, print what
|
|
132
213
|
Node and Safari do; every other locale goes to the runtime's `Intl`. Dates are UTC. No new
|
|
133
214
|
runtime dependency: the formatjs code is bundled.
|
|
215
|
+
|
|
216
|
+
## 0.2.8 — 2026-10-10
|
|
217
|
+
|
|
134
218
|
- **A request that answered `429` or `503` is retried instead of failing.** The gateway rate-limits a
|
|
135
219
|
client by requests per minute, which a static build of a real catalogue meets routinely. The
|
|
136
220
|
default `fetch` transport now repeats an **idempotent** request (`GET`/`HEAD`/`OPTIONS` — never a
|
|
@@ -148,6 +232,8 @@ platform repository.
|
|
|
148
232
|
the same way. **This is a minor**: the behaviour is a repair, but `retry` is a new public option
|
|
149
233
|
and `EldraRetryOptions` a new exported type.
|
|
150
234
|
|
|
235
|
+
## 0.2.7 — 2026-10-09
|
|
236
|
+
|
|
151
237
|
- `analyticsTrackerScript`'s documentation no longer says events always reach the gateway; with
|
|
152
238
|
`eventOrigin` set they go to that first-party proxy.
|
|
153
239
|
|
|
@@ -391,9 +391,11 @@ var EldraHttpError = class extends Error {
|
|
|
391
391
|
errorId;
|
|
392
392
|
/**
|
|
393
393
|
* The gateway's problem `errors` — the refusal's detail, when the body carried it as an object.
|
|
394
|
-
*
|
|
395
|
-
* `
|
|
396
|
-
*
|
|
394
|
+
* For example `salesOrderId` on `SALES_ORDER_CART_ALREADY_ORDERED` or `variantId` on
|
|
395
|
+
* `SALES_ORDER_LINE_INVALID`; a refused discount code names what blocked it here:
|
|
396
|
+
* `errors.blockingCode` on `CART_DISCOUNT_NOT_COMBINABLE`, `errors.limit` on
|
|
397
|
+
* `CART_DISCOUNT_CODES_LIMIT_REACHED`. Its members depend on the `errorId`, so read each as
|
|
398
|
+
* unknown and check its type (or narrow with `isEldraError`).
|
|
397
399
|
*/
|
|
398
400
|
errors;
|
|
399
401
|
constructor(response, body) {
|
|
@@ -407,6 +409,27 @@ var EldraHttpError = class extends Error {
|
|
|
407
409
|
this.errors = problemErrors(body);
|
|
408
410
|
}
|
|
409
411
|
};
|
|
412
|
+
/**
|
|
413
|
+
* Thrown by `salesOrders.create`, before anything is sent, when the idempotency key is missing or not
|
|
414
|
+
* 1 to 255 printable ASCII characters without spaces. A bug in the calling code: fix it, never retry.
|
|
415
|
+
* Catch this class, not every `TypeError`: `fetch` reports a lost connection as a `TypeError` too,
|
|
416
|
+
* and that one may follow a placed order, so it is retried with the same key.
|
|
417
|
+
*/
|
|
418
|
+
var EldraIdempotencyKeyError = class extends TypeError {
|
|
419
|
+
name = "EldraIdempotencyKeyError";
|
|
420
|
+
};
|
|
421
|
+
const idempotencyKeyPattern = /^[\x21-\x7e]{1,255}$/;
|
|
422
|
+
function checkIdempotencyKey(key) {
|
|
423
|
+
if (typeof key !== "string" || !idempotencyKeyPattern.test(key)) throw new EldraIdempotencyKeyError("salesOrders.create needs an idempotency key of 1 to 255 printable ASCII characters");
|
|
424
|
+
return key;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Narrows an unknown error to an `EldraHttpError` with the given `errorId`. For an id in
|
|
428
|
+
* `EldraProblemErrors` its `errors` is typed (each field optional: it is as the gateway sent it).
|
|
429
|
+
*/
|
|
430
|
+
function isEldraError(error, errorId) {
|
|
431
|
+
return error instanceof EldraHttpError && error.errorId === errorId;
|
|
432
|
+
}
|
|
410
433
|
/** One field of an RFC 9457 problem body, when the body is an object that carries it as a string. */
|
|
411
434
|
function problemString(body, key) {
|
|
412
435
|
if (body && typeof body === "object" && key in body) {
|
|
@@ -532,11 +555,21 @@ function createEldraClient(options) {
|
|
|
532
555
|
}
|
|
533
556
|
},
|
|
534
557
|
catalog: {
|
|
558
|
+
/**
|
|
559
|
+
* Lists products. Pass `customerHeaders(token, customerId)` as `context.headers` to get a
|
|
560
|
+
* signed-in business customer's prices (`listPrice` is the list price). Server-side only;
|
|
561
|
+
* never cache the result. See docs/customer-prices.md.
|
|
562
|
+
*/
|
|
535
563
|
listProducts: (listOptions, context) => request({
|
|
536
564
|
...context,
|
|
537
565
|
path: "/catalog/v1/products/list",
|
|
538
566
|
query: listOptions
|
|
539
567
|
}),
|
|
568
|
+
/**
|
|
569
|
+
* Reads one product. Pass `customerHeaders(token, customerId)` as `context.headers` to get a
|
|
570
|
+
* signed-in business customer's prices (`listPrice` is the list price). Server-side only;
|
|
571
|
+
* never cache the result. See docs/customer-prices.md.
|
|
572
|
+
*/
|
|
540
573
|
getProduct: (productId, getOptions, context) => request({
|
|
541
574
|
...context,
|
|
542
575
|
path: `/catalog/v1/products/${encodeURIComponent(productId)}`,
|
|
@@ -557,6 +590,11 @@ function createEldraClient(options) {
|
|
|
557
590
|
path: `/catalog/v1/collections/${encodeURIComponent(slug)}`,
|
|
558
591
|
query: localeOptions
|
|
559
592
|
}),
|
|
593
|
+
/**
|
|
594
|
+
* Lists a collection's products. Pass `customerHeaders(token, customerId)` as `context.headers` to get a
|
|
595
|
+
* signed-in business customer's prices (`listPrice` is the list price). Server-side only;
|
|
596
|
+
* never cache the result. See docs/customer-prices.md.
|
|
597
|
+
*/
|
|
560
598
|
listCollectionProducts: (slug, listOptions, context) => request({
|
|
561
599
|
...context,
|
|
562
600
|
path: `/catalog/v1/collections/${encodeURIComponent(slug)}/products`,
|
|
@@ -572,6 +610,7 @@ function createEldraClient(options) {
|
|
|
572
610
|
path: `/catalog/v1/brands/${encodeURIComponent(slug)}`,
|
|
573
611
|
query: localeOptions
|
|
574
612
|
}),
|
|
613
|
+
/** Search results carry list prices, never customer prices. */
|
|
575
614
|
search: (query, searchOptions, context) => request({
|
|
576
615
|
...context,
|
|
577
616
|
path: "/search/v1",
|
|
@@ -582,6 +621,11 @@ function createEldraClient(options) {
|
|
|
582
621
|
})
|
|
583
622
|
},
|
|
584
623
|
cart: {
|
|
624
|
+
/**
|
|
625
|
+
* Adds a line. A signed-in token in `context.headers` binds the cart to that customer and
|
|
626
|
+
* prices its lines for them. Errors: 409 CART_CUSTOMER_MISMATCH, CART_SIGN_IN_REQUIRED;
|
|
627
|
+
* 503 CART_PRICES_UNAVAILABLE. See docs/customer-prices.md.
|
|
628
|
+
*/
|
|
585
629
|
addItem: (input, context) => {
|
|
586
630
|
const attribution = options.campaignAttribution === false || "attribution" in input ? null : readCampaignAttribution(options.campaignAttribution);
|
|
587
631
|
return request({
|
|
@@ -594,22 +638,38 @@ function createEldraClient(options) {
|
|
|
594
638
|
}
|
|
595
639
|
});
|
|
596
640
|
},
|
|
641
|
+
/**
|
|
642
|
+
* Reads a cart by id. Reads stay open for a cart bound to a customer (hosted checkout).
|
|
643
|
+
*/
|
|
597
644
|
get: (cartId, localeOptions, context) => request({
|
|
598
645
|
...context,
|
|
599
646
|
path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}`,
|
|
600
647
|
query: localeOptions
|
|
601
648
|
}),
|
|
649
|
+
/**
|
|
650
|
+
* Changes a line's quantity. A signed-in token in `context.headers` binds the cart to that customer and
|
|
651
|
+
* prices its lines for them. Errors: 409 CART_CUSTOMER_MISMATCH, CART_SIGN_IN_REQUIRED;
|
|
652
|
+
* 503 CART_PRICES_UNAVAILABLE. See docs/customer-prices.md.
|
|
653
|
+
*/
|
|
602
654
|
updateItem: (cartId, itemId, input, context) => request({
|
|
603
655
|
...context,
|
|
604
656
|
method: "PATCH",
|
|
605
657
|
path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}/items/${encodeURIComponent(itemId)}`,
|
|
606
658
|
body: input
|
|
607
659
|
}),
|
|
660
|
+
/**
|
|
661
|
+
* Removes a line. A guest may remove a line from a bound cart; a signed-in token binds the
|
|
662
|
+
* cart to that customer. Errors: 409 CART_CUSTOMER_MISMATCH; 503 CART_PRICES_UNAVAILABLE. See docs/customer-prices.md.
|
|
663
|
+
*/
|
|
608
664
|
removeItem: (cartId, itemId, context) => request({
|
|
609
665
|
...context,
|
|
610
666
|
method: "DELETE",
|
|
611
667
|
path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}/items/${encodeURIComponent(itemId)}`
|
|
612
668
|
}),
|
|
669
|
+
/**
|
|
670
|
+
* Applies a discount code. On a cart bound to a customer this is 409
|
|
671
|
+
* CART_DISCOUNT_NOT_FOR_CUSTOMER_PRICES: codes do not combine with customer prices.
|
|
672
|
+
*/
|
|
613
673
|
applyDiscount: async (cartId, code, localeOptions, context) => {
|
|
614
674
|
const trimmed = code.trim();
|
|
615
675
|
const cart = await request({
|
|
@@ -624,6 +684,9 @@ function createEldraClient(options) {
|
|
|
624
684
|
applied: cartHoldsDiscountCode(cart, trimmed)
|
|
625
685
|
};
|
|
626
686
|
},
|
|
687
|
+
/**
|
|
688
|
+
* Removes the discount code. A guest write to a bound cart is 409 CART_SIGN_IN_REQUIRED.
|
|
689
|
+
*/
|
|
627
690
|
removeDiscount: (cartId, localeOptions, context) => request({
|
|
628
691
|
...context,
|
|
629
692
|
method: "DELETE",
|
|
@@ -723,6 +786,43 @@ function createEldraClient(options) {
|
|
|
723
786
|
if (!checkoutUrl) throw cause === void 0 ? /* @__PURE__ */ new Error("The platform did not publish a checkout URL (GET /platform/v1/config).") : new Error(`Could not read the platform checkout URL (GET /platform/v1/config): ${describeCause(cause)}`, { cause });
|
|
724
787
|
return buildCheckoutUrl(checkoutUrl, handoff, options);
|
|
725
788
|
} },
|
|
789
|
+
customer: {
|
|
790
|
+
me: (context) => request({
|
|
791
|
+
...context,
|
|
792
|
+
path: "/customer/v1/me"
|
|
793
|
+
}),
|
|
794
|
+
locations: (context) => request({
|
|
795
|
+
...context,
|
|
796
|
+
path: "/customer/v1/locations"
|
|
797
|
+
})
|
|
798
|
+
},
|
|
799
|
+
salesOrders: {
|
|
800
|
+
preview: (input, context) => request({
|
|
801
|
+
...context,
|
|
802
|
+
method: "POST",
|
|
803
|
+
path: "/sales-order/v1/preview",
|
|
804
|
+
body: input
|
|
805
|
+
}),
|
|
806
|
+
create: async (input, createOptions, context) => {
|
|
807
|
+
const idempotencyKey = checkIdempotencyKey(createOptions?.idempotencyKey);
|
|
808
|
+
return request({
|
|
809
|
+
...context,
|
|
810
|
+
method: "POST",
|
|
811
|
+
path: "/sales-order/v1",
|
|
812
|
+
headers: mergeHeaders(context?.headers, { "Idempotency-Key": idempotencyKey }),
|
|
813
|
+
body: input
|
|
814
|
+
});
|
|
815
|
+
},
|
|
816
|
+
list: (listOptions, context) => request({
|
|
817
|
+
...context,
|
|
818
|
+
path: "/sales-order/v1",
|
|
819
|
+
query: listOptions
|
|
820
|
+
}),
|
|
821
|
+
get: (salesOrderId, context) => request({
|
|
822
|
+
...context,
|
|
823
|
+
path: `/sales-order/v1/${encodeURIComponent(salesOrderId)}`
|
|
824
|
+
})
|
|
825
|
+
},
|
|
726
826
|
inventory: { availability: (items, context) => request({
|
|
727
827
|
...context,
|
|
728
828
|
method: "POST",
|
|
@@ -985,4 +1085,4 @@ function appendQueryValue(searchParams, key, value) {
|
|
|
985
1085
|
function isRawBody(body) {
|
|
986
1086
|
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;
|
|
987
1087
|
}
|
|
988
|
-
export {
|
|
1088
|
+
export { getEldraClient as a, resolveApiBaseUrl as c, clearCampaignAttribution as d, grantCampaignAttributionConsent as f, createOrderAccessTokens 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
|
|
1
|
+
import { $ as EldraFormSubmitResult, $t as EldraShopUser, A as EldraCollection, At as EldraProductVariant, B as EldraCustomerMembership, Bt as EldraSalesOrderLine, C as EldraCmsEntryListFilterCriterion, Cn as EldraKeyValueStorage, Ct as EldraProductExtensions, D as EldraCmsResolveEntryListOptions, Dn as createOrderAccessTokens, Dt as EldraProductOption, E as EldraCmsListOptions, En as createCartSession, 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, 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 EldraOrderAccessTokens, 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, 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 EldraOrderAccessTokenOptions, 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-BrQEYrD5.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;
|
|
@@ -14,19 +14,130 @@ export declare class EldraHttpError extends Error {
|
|
|
14
14
|
* telling it apart from any other conflict is what lets a storefront say "out of stock" rather
|
|
15
15
|
* than "something went wrong".
|
|
16
16
|
*/
|
|
17
|
-
readonly errorId:
|
|
17
|
+
readonly errorId: EldraErrorId | undefined;
|
|
18
18
|
/**
|
|
19
19
|
* The gateway's problem `errors` — the refusal's detail, when the body carried it as an object.
|
|
20
|
-
*
|
|
21
|
-
* `
|
|
22
|
-
*
|
|
20
|
+
* For example `salesOrderId` on `SALES_ORDER_CART_ALREADY_ORDERED` or `variantId` on
|
|
21
|
+
* `SALES_ORDER_LINE_INVALID`; a refused discount code names what blocked it here:
|
|
22
|
+
* `errors.blockingCode` on `CART_DISCOUNT_NOT_COMBINABLE`, `errors.limit` on
|
|
23
|
+
* `CART_DISCOUNT_CODES_LIMIT_REACHED`. Its members depend on the `errorId`, so read each as
|
|
24
|
+
* unknown and check its type (or narrow with `isEldraError`).
|
|
23
25
|
*/
|
|
24
26
|
readonly errors: Readonly<Record<string, unknown>> | undefined;
|
|
25
27
|
constructor(response: Response, body: unknown);
|
|
26
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Thrown by `salesOrders.create`, before anything is sent, when the idempotency key is missing or not
|
|
31
|
+
* 1 to 255 printable ASCII characters without spaces. A bug in the calling code: fix it, never retry.
|
|
32
|
+
* Catch this class, not every `TypeError`: `fetch` reports a lost connection as a `TypeError` too,
|
|
33
|
+
* and that one may follow a placed order, so it is retried with the same key.
|
|
34
|
+
*/
|
|
35
|
+
export declare class EldraIdempotencyKeyError extends TypeError {
|
|
36
|
+
name: string;
|
|
37
|
+
}
|
|
38
|
+
/** An `EldraHttpError` whose `errorId` is `Id`, with that refusal's `errors` typed. */
|
|
39
|
+
type EldraHttpErrorWith<Id extends EldraErrorId> = EldraHttpError & {
|
|
40
|
+
readonly errorId: Id;
|
|
41
|
+
readonly errors: (Id extends keyof EldraProblemErrors ? Readonly<Partial<EldraProblemErrors[Id]>> : Readonly<Record<string, unknown>>) | undefined;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Narrows an unknown error to an `EldraHttpError` with the given `errorId`. For an id in
|
|
45
|
+
* `EldraProblemErrors` its `errors` is typed (each field optional: it is as the gateway sent it).
|
|
46
|
+
*/
|
|
47
|
+
export declare function isEldraError<Id extends EldraErrorId>(error: unknown, errorId: Id): error is EldraHttpErrorWith<Id>;
|
|
27
48
|
export declare function initEldraClient(options: EldraClientOptions): EldraClient;
|
|
28
49
|
export declare function getEldraClient(): EldraClient;
|
|
29
50
|
export declare function createEldraClient(options: EldraClientOptions): EldraClient;
|
|
51
|
+
/**
|
|
52
|
+
* OpenID Connect helpers for business-customer login. Framework-free and free of Node-only APIs:
|
|
53
|
+
* URL builders, PKCE through WebCrypto, and the two token-endpoint calls over `fetch`.
|
|
54
|
+
*
|
|
55
|
+
* The token endpoint calls take the storefront client's secret. Make them on a server only; see
|
|
56
|
+
* `docs/business-login.md`.
|
|
57
|
+
*/
|
|
58
|
+
interface EldraOidcTokens {
|
|
59
|
+
accessToken: string;
|
|
60
|
+
refreshToken: string;
|
|
61
|
+
idToken: string;
|
|
62
|
+
/** Epoch milliseconds when the access token expires. */
|
|
63
|
+
expiresAt: number;
|
|
64
|
+
/** Epoch milliseconds when the refresh token expires; undefined when the server sent no `refresh_expires_in`. */
|
|
65
|
+
refreshExpiresAt: number | undefined;
|
|
66
|
+
}
|
|
67
|
+
export declare class EldraOidcError extends Error {
|
|
68
|
+
readonly status: number;
|
|
69
|
+
/** The OAuth `error` code, such as `invalid_grant`. */
|
|
70
|
+
readonly error: string;
|
|
71
|
+
readonly errorDescription: string | undefined;
|
|
72
|
+
constructor(status: number, error: string, errorDescription?: string);
|
|
73
|
+
}
|
|
74
|
+
interface EldraPkcePair {
|
|
75
|
+
codeVerifier: string;
|
|
76
|
+
codeChallenge: string;
|
|
77
|
+
codeChallengeMethod: 'S256';
|
|
78
|
+
}
|
|
79
|
+
interface EldraAuthorizeUrlOptions {
|
|
80
|
+
issuer: string;
|
|
81
|
+
clientId: string;
|
|
82
|
+
redirectUri: string;
|
|
83
|
+
state: string;
|
|
84
|
+
codeChallenge: string;
|
|
85
|
+
scope?: string;
|
|
86
|
+
prompt?: string;
|
|
87
|
+
/**
|
|
88
|
+
* The language(s) the login pages should use, most preferred first, as BCP 47 tags (`is`,
|
|
89
|
+
* `en`). Sent as the OIDC `ui_locales` parameter (space-separated); omitted when empty.
|
|
90
|
+
*/
|
|
91
|
+
uiLocales?: string | readonly string[];
|
|
92
|
+
}
|
|
93
|
+
interface EldraTokenClientOptions {
|
|
94
|
+
issuer: string;
|
|
95
|
+
clientId: string;
|
|
96
|
+
/** Sent as `client_secret` in the form body (client_secret_post). Server-side only. */
|
|
97
|
+
clientSecret?: string;
|
|
98
|
+
fetch?: typeof fetch;
|
|
99
|
+
}
|
|
100
|
+
interface EldraExchangeCodeOptions extends EldraTokenClientOptions {
|
|
101
|
+
code: string;
|
|
102
|
+
redirectUri: string;
|
|
103
|
+
codeVerifier: string;
|
|
104
|
+
}
|
|
105
|
+
interface EldraRefreshTokensOptions extends EldraTokenClientOptions {
|
|
106
|
+
refreshToken: string;
|
|
107
|
+
}
|
|
108
|
+
interface EldraLogoutUrlOptions {
|
|
109
|
+
issuer: string;
|
|
110
|
+
clientId: string;
|
|
111
|
+
postLogoutRedirectUri: string;
|
|
112
|
+
idTokenHint?: string;
|
|
113
|
+
}
|
|
114
|
+
/** The default client id of the storefront client in every shop realm. */
|
|
115
|
+
export declare const ELDRA_SHOP_CLIENT_ID = "storefront";
|
|
116
|
+
/** The issuer of an organization's shop realm. */
|
|
117
|
+
export declare function shopIssuer(options: {
|
|
118
|
+
keycloakBaseUrl: string;
|
|
119
|
+
orgId: string;
|
|
120
|
+
}): string;
|
|
121
|
+
/** Headers carrying an access token, for `context.headers` of `customer.me()`. */
|
|
122
|
+
export declare function bearer(accessToken: string): {
|
|
123
|
+
Authorization: string;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Headers for a priced catalog read or a cart write: the access token plus, when the person
|
|
127
|
+
* belongs to more than one company, the active company as `X-Customer-Id`. Server-side only.
|
|
128
|
+
*/
|
|
129
|
+
export declare function customerHeaders(accessToken: string, customerId?: string): {
|
|
130
|
+
Authorization: string;
|
|
131
|
+
'X-Customer-Id'?: string;
|
|
132
|
+
};
|
|
133
|
+
/** The S256 code challenge for a verifier. */
|
|
134
|
+
export declare function pkceChallenge(codeVerifier: string): Promise<string>;
|
|
135
|
+
/** A fresh PKCE verifier (43 characters of base64url) with its S256 challenge. */
|
|
136
|
+
export declare function createPkcePair(): Promise<EldraPkcePair>;
|
|
137
|
+
export declare function buildAuthorizeUrl(options: EldraAuthorizeUrlOptions): string;
|
|
138
|
+
export declare function buildLogoutUrl(options: EldraLogoutUrlOptions): string;
|
|
139
|
+
export declare function exchangeAuthorizationCode(options: EldraExchangeCodeOptions): Promise<EldraOidcTokens>;
|
|
140
|
+
export declare function refreshTokens(options: EldraRefreshTokensOptions): Promise<EldraOidcTokens>;
|
|
30
141
|
interface EldraTrackerScriptOptions extends Pick<EldraClientOptions, 'apiBaseUrl' | 'orgId' | 'env'> {
|
|
31
142
|
/** Origin that receives events when the script is served through a first-party proxy. */
|
|
32
143
|
eventOrigin?: string;
|
|
@@ -121,4 +232,4 @@ interface EldraResponsiveImage {
|
|
|
121
232
|
* as `src` and no `srcset`. Returns `undefined` when there is no URL to render.
|
|
122
233
|
*/
|
|
123
234
|
export declare function responsiveImage(source: EldraImageSource, options: EldraResponsiveImageOptions): EldraResponsiveImage | undefined;
|
|
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
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,132 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as getEldraClient, c as resolveApiBaseUrl, d as clearCampaignAttribution, f as grantCampaignAttributionConsent, g as createOrderAccessTokens, 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-cO8GCJK9.js";
|
|
2
|
+
// src/oidc.ts
|
|
3
|
+
var EldraOidcError = class extends Error {
|
|
4
|
+
status;
|
|
5
|
+
/** The OAuth `error` code, such as `invalid_grant`. */
|
|
6
|
+
error;
|
|
7
|
+
errorDescription;
|
|
8
|
+
constructor(status, error, errorDescription) {
|
|
9
|
+
super(`Token request failed with ${status} ${error}${errorDescription ? `: ${errorDescription}` : ""}`);
|
|
10
|
+
this.name = "EldraOidcError";
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.error = error;
|
|
13
|
+
this.errorDescription = errorDescription;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
function trimTrailingSlashes(url) {
|
|
17
|
+
let end = url.length;
|
|
18
|
+
while (end > 0 && url[end - 1] === "/") end--;
|
|
19
|
+
return url.slice(0, end);
|
|
20
|
+
}
|
|
21
|
+
function oidcUrl(issuer, endpoint) {
|
|
22
|
+
return new URL(`${trimTrailingSlashes(issuer)}/protocol/openid-connect/${endpoint}`);
|
|
23
|
+
}
|
|
24
|
+
/** The default client id of the storefront client in every shop realm. */
|
|
25
|
+
const ELDRA_SHOP_CLIENT_ID = "storefront";
|
|
26
|
+
/** The issuer of an organization's shop realm. */
|
|
27
|
+
function shopIssuer(options) {
|
|
28
|
+
return `${trimTrailingSlashes(options.keycloakBaseUrl)}/realms/shop-${encodeURIComponent(options.orgId)}`;
|
|
29
|
+
}
|
|
30
|
+
/** Headers carrying an access token, for `context.headers` of `customer.me()`. */
|
|
31
|
+
function bearer(accessToken) {
|
|
32
|
+
return { Authorization: `Bearer ${accessToken}` };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Headers for a priced catalog read or a cart write: the access token plus, when the person
|
|
36
|
+
* belongs to more than one company, the active company as `X-Customer-Id`. Server-side only.
|
|
37
|
+
*/
|
|
38
|
+
function customerHeaders(accessToken, customerId) {
|
|
39
|
+
return customerId ? {
|
|
40
|
+
...bearer(accessToken),
|
|
41
|
+
"X-Customer-Id": customerId
|
|
42
|
+
} : bearer(accessToken);
|
|
43
|
+
}
|
|
44
|
+
function base64Url(bytes) {
|
|
45
|
+
let binary = "";
|
|
46
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
47
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
48
|
+
}
|
|
49
|
+
/** The S256 code challenge for a verifier. */
|
|
50
|
+
async function pkceChallenge(codeVerifier) {
|
|
51
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(codeVerifier));
|
|
52
|
+
return base64Url(new Uint8Array(digest));
|
|
53
|
+
}
|
|
54
|
+
/** A fresh PKCE verifier (43 characters of base64url) with its S256 challenge. */
|
|
55
|
+
async function createPkcePair() {
|
|
56
|
+
const codeVerifier = base64Url(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)));
|
|
57
|
+
return {
|
|
58
|
+
codeVerifier,
|
|
59
|
+
codeChallenge: await pkceChallenge(codeVerifier),
|
|
60
|
+
codeChallengeMethod: "S256"
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function buildAuthorizeUrl(options) {
|
|
64
|
+
const url = oidcUrl(options.issuer, "auth");
|
|
65
|
+
url.searchParams.set("client_id", options.clientId);
|
|
66
|
+
url.searchParams.set("redirect_uri", options.redirectUri);
|
|
67
|
+
url.searchParams.set("response_type", "code");
|
|
68
|
+
url.searchParams.set("scope", options.scope ?? "openid");
|
|
69
|
+
url.searchParams.set("state", options.state);
|
|
70
|
+
url.searchParams.set("code_challenge", options.codeChallenge);
|
|
71
|
+
url.searchParams.set("code_challenge_method", "S256");
|
|
72
|
+
if (options.prompt) url.searchParams.set("prompt", options.prompt);
|
|
73
|
+
const uiLocales = (typeof options.uiLocales === "string" ? options.uiLocales.split(" ") : options.uiLocales ?? []).map((tag) => tag.trim()).filter(Boolean).join(" ");
|
|
74
|
+
if (uiLocales) url.searchParams.set("ui_locales", uiLocales);
|
|
75
|
+
return url.toString();
|
|
76
|
+
}
|
|
77
|
+
function buildLogoutUrl(options) {
|
|
78
|
+
const url = oidcUrl(options.issuer, "logout");
|
|
79
|
+
url.searchParams.set("client_id", options.clientId);
|
|
80
|
+
url.searchParams.set("post_logout_redirect_uri", options.postLogoutRedirectUri);
|
|
81
|
+
if (options.idTokenHint) url.searchParams.set("id_token_hint", options.idTokenHint);
|
|
82
|
+
return url.toString();
|
|
83
|
+
}
|
|
84
|
+
async function tokenRequest(options, params) {
|
|
85
|
+
const form = new URLSearchParams({
|
|
86
|
+
...params,
|
|
87
|
+
client_id: options.clientId
|
|
88
|
+
});
|
|
89
|
+
if (options.clientSecret) form.set("client_secret", options.clientSecret);
|
|
90
|
+
const requestedAt = Date.now();
|
|
91
|
+
const response = await (options.fetch ?? globalThis.fetch)(oidcUrl(options.issuer, "token").toString(), {
|
|
92
|
+
method: "POST",
|
|
93
|
+
headers: {
|
|
94
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
95
|
+
Accept: "application/json"
|
|
96
|
+
},
|
|
97
|
+
body: form.toString()
|
|
98
|
+
});
|
|
99
|
+
const body = await response.json().catch(() => void 0);
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
const error = typeof body?.error === "string" ? body.error : "server_error";
|
|
102
|
+
const description = typeof body?.error_description === "string" ? body.error_description : void 0;
|
|
103
|
+
throw new EldraOidcError(response.status, error, description);
|
|
104
|
+
}
|
|
105
|
+
if (typeof body?.access_token !== "string" || !body.access_token) throw new EldraOidcError(response.status, "invalid_response", "Token response has no access_token");
|
|
106
|
+
const text = (key) => typeof body?.[key] === "string" ? body[key] : "";
|
|
107
|
+
const seconds = (key) => typeof body?.[key] === "number" ? body[key] : 0;
|
|
108
|
+
return {
|
|
109
|
+
accessToken: text("access_token"),
|
|
110
|
+
refreshToken: text("refresh_token"),
|
|
111
|
+
idToken: text("id_token"),
|
|
112
|
+
expiresAt: requestedAt + seconds("expires_in") * 1e3,
|
|
113
|
+
refreshExpiresAt: typeof body.refresh_expires_in === "number" ? requestedAt + body.refresh_expires_in * 1e3 : void 0
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function exchangeAuthorizationCode(options) {
|
|
117
|
+
return tokenRequest(options, {
|
|
118
|
+
grant_type: "authorization_code",
|
|
119
|
+
code: options.code,
|
|
120
|
+
redirect_uri: options.redirectUri,
|
|
121
|
+
code_verifier: options.codeVerifier
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function refreshTokens(options) {
|
|
125
|
+
return tokenRequest(options, {
|
|
126
|
+
grant_type: "refresh_token",
|
|
127
|
+
refresh_token: options.refreshToken
|
|
128
|
+
});
|
|
129
|
+
}
|
|
2
130
|
// src/tracker.ts
|
|
3
131
|
/**
|
|
4
132
|
* Builds the tracker `<script>` attributes from the same configuration the client uses, so the
|
|
@@ -129,4 +257,4 @@ function responsiveImage(source, options) {
|
|
|
129
257
|
}
|
|
130
258
|
return image;
|
|
131
259
|
}
|
|
132
|
-
export { DEFAULT_ELDRA_API_BASE_URL, ELDRA_IMAGE_VARIANT_WIDTHS, EldraHttpError, analyticsTrackerScript, captureCampaignAttribution, clearCampaignAttribution, createCartSession, createEldraClient, createOrderAccessTokens, getEldraClient, grantCampaignAttributionConsent, imageSrcset, imageUrl, imageVariantFor, initEldraClient, isEldraImage, readCampaignAttribution, responsiveImage, withdrawCampaignAttributionConsent };
|
|
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 };
|
|
@@ -358,6 +358,8 @@ interface EldraClient {
|
|
|
358
358
|
forms: EldraFormsClient;
|
|
359
359
|
checkout: EldraCheckoutClient;
|
|
360
360
|
inventory: EldraInventoryClient;
|
|
361
|
+
customer: EldraCustomerClient;
|
|
362
|
+
salesOrders: EldraSalesOrdersClient;
|
|
361
363
|
}
|
|
362
364
|
interface EldraLocaleOptions {
|
|
363
365
|
locale?: string;
|
|
@@ -419,18 +421,6 @@ type EldraOrderLine = EldraContractItem<EldraContractProp<EldraOrder, 'orderLine
|
|
|
419
421
|
type EldraOrderDiscountCode = EldraContractItem<EldraContractProp<EldraOrder, 'discountCodes'>>;
|
|
420
422
|
type EldraRecoveredBasket = EldraContractResponse<'/order/v1/recover', 'post'>;
|
|
421
423
|
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'>>;
|
|
434
424
|
interface EldraOrderReadOptions {
|
|
435
425
|
/** The one-time token returned when the order was created. Required unless the caller owns the order. */
|
|
436
426
|
accessToken?: string;
|
|
@@ -564,6 +554,113 @@ interface EldraPlatformClient {
|
|
|
564
554
|
*/
|
|
565
555
|
config(readOptions?: EldraPlatformReadOptions): Promise<EldraPlatformConfig>;
|
|
566
556
|
}
|
|
557
|
+
type EldraCustomerMe = EldraContractResponse<'/customer/v1/me', 'get'>;
|
|
558
|
+
type EldraShopUser = EldraContractProp<EldraCustomerMe, 'shopUser'>;
|
|
559
|
+
type EldraCustomerMembership = EldraContractItem<EldraContractProp<EldraCustomerMe, 'memberships'>>;
|
|
560
|
+
interface EldraCustomerClient {
|
|
561
|
+
/**
|
|
562
|
+
* The signed-in business customer and their company memberships. Pass the shop-realm access
|
|
563
|
+
* token in `context.headers`, for example `bearer(accessToken)`. Rejects with `EldraHttpError`,
|
|
564
|
+
* branch on `errorId`:
|
|
565
|
+
* - 401 `SHOP_TOKEN_INVALID`: the token is missing, expired or not from this shop realm; refresh
|
|
566
|
+
* or sign in again.
|
|
567
|
+
* - 403 `SHOP_NO_MEMBERSHIP`: the login buys for no customer company.
|
|
568
|
+
* - 403 `FEATURE_DISABLED`: the organisation has business sales turned off.
|
|
569
|
+
* - 503 `SHOP_LOGIN_UNAVAILABLE`: the login service is unreachable; try again.
|
|
570
|
+
*/
|
|
571
|
+
me(context?: EldraRequestContext): Promise<EldraCustomerMe>;
|
|
572
|
+
/**
|
|
573
|
+
* The active company's delivery locations as `{ data }`, the default first; `data` is `[]` for a
|
|
574
|
+
* company with none.
|
|
575
|
+
* Pass `customerHeaders(accessToken, customerId)` as `context.headers`. Server-side only. Refusals
|
|
576
|
+
* are the sign-in's: 401 `SHOP_TOKEN_INVALID`, 403 `SHOP_NO_MEMBERSHIP`, `FEATURE_DISABLED`,
|
|
577
|
+
* `SHOP_CUSTOMER_NOT_MEMBER`, 409 `SHOP_CUSTOMER_REQUIRED`, 503 `SHOP_LOGIN_UNAVAILABLE`.
|
|
578
|
+
*/
|
|
579
|
+
locations(context?: EldraRequestContext): Promise<EldraCustomerLocationList>;
|
|
580
|
+
}
|
|
581
|
+
type EldraCustomerLocationList = EldraContractResponse<'/customer/v1/locations', 'get'>;
|
|
582
|
+
type EldraCustomerLocation = EldraContractItem<EldraContractProp<EldraCustomerLocationList, 'data'>>;
|
|
583
|
+
type EldraSalesOrderPreviewInput = EldraContractBody<'/sales-order/v1/preview', 'post'>;
|
|
584
|
+
type EldraSalesOrderPreview = EldraContractResponse<'/sales-order/v1/preview', 'post'>;
|
|
585
|
+
type EldraSalesOrderPreviewLine = EldraContractItem<EldraContractProp<EldraSalesOrderPreview, 'lines'>>;
|
|
586
|
+
type EldraSalesOrderCredit = EldraContractProp<EldraSalesOrderPreview, 'credit'>;
|
|
587
|
+
type EldraCreateSalesOrderInput = EldraContractBody<'/sales-order/v1', 'post'>;
|
|
588
|
+
type EldraSalesOrder = EldraContractResponse<'/sales-order/v1/{salesOrderId}', 'get'>;
|
|
589
|
+
type EldraSalesOrderLine = EldraContractItem<EldraContractProp<EldraSalesOrder, 'lines'>>;
|
|
590
|
+
type EldraSalesOrderWarning = EldraContractItem<EldraContractProp<EldraSalesOrder, 'warnings'>>;
|
|
591
|
+
type EldraSalesOrderDelivery = EldraContractProp<EldraSalesOrder, 'delivery'>;
|
|
592
|
+
type EldraSalesOrderStatus = EldraContractProp<EldraSalesOrder, 'salesStatus'>;
|
|
593
|
+
type EldraSalesOrderList = EldraContractResponse<'/sales-order/v1', 'get'>;
|
|
594
|
+
type EldraSalesOrderListItem = EldraContractItem<EldraContractProp<EldraSalesOrderList, 'data'>>;
|
|
595
|
+
type EldraSalesOrderListOptions = EldraContractQuery<'/sales-order/v1', 'get'>;
|
|
596
|
+
interface EldraCreateSalesOrderOptions {
|
|
597
|
+
/**
|
|
598
|
+
* Required. Mint one per attempt to place the order (a random UUID), keep it across retries of
|
|
599
|
+
* that attempt, and mint a new one when the cart or the form changes. The same key replays the
|
|
600
|
+
* first order rather than placing a second; a different body under it is 409
|
|
601
|
+
* `ORDER_IDEMPOTENCY_CONFLICT`.
|
|
602
|
+
*/
|
|
603
|
+
idempotencyKey: string;
|
|
604
|
+
}
|
|
605
|
+
/** Error ids of the business sign-in, on every route that takes a shop token. */
|
|
606
|
+
type EldraShopErrorId = 'SHOP_TOKEN_INVALID' | 'SHOP_NO_MEMBERSHIP' | 'SHOP_CUSTOMER_NOT_MEMBER' | 'SHOP_CUSTOMER_REQUIRED' | 'SHOP_LOGIN_UNAVAILABLE' | 'FEATURE_DISABLED';
|
|
607
|
+
/**
|
|
608
|
+
* Error ids of the sales-order routes (contract 6.15.0). `SALES_ORDER_CART_ALREADY_ORDERED`
|
|
609
|
+
* carries `errors.salesOrderId`, `SALES_ORDER_LINE_INVALID` `errors.variantId` and
|
|
610
|
+
* `ORDER_PRODUCT_UNAVAILABLE` `errors.variantIds` on `EldraHttpError.errors`.
|
|
611
|
+
*/
|
|
612
|
+
type EldraSalesOrderErrorId = 'SALES_ORDER_IDEMPOTENCY_KEY_REQUIRED' | 'SALES_ORDER_CART_EMPTY' | 'SALES_ORDER_TOO_MANY_LINES' | 'SALES_ORDER_LINE_INVALID' | 'SALES_ORDER_CART_NOT_BOUND' | 'SALES_ORDER_CART_ALREADY_ORDERED' | 'SALES_ORDER_LOCATION_UNKNOWN' | 'SALES_ORDER_CREDIT_LIMIT_EXCEEDED' | 'SALES_ORDER_CREDIT_CURRENCY_MISMATCH' | 'SALES_ORDER_CREDIT_CHECK_UNAVAILABLE' | 'SALES_ORDER_TERMS_UNAVAILABLE' | 'SALES_ORDER_CART_UNAVAILABLE' | 'SALES_ORDER_UPSTREAM_REFUSED' | 'SALES_ORDER_NOT_FOUND' | 'CUSTOMER_BLOCKED' | 'CART_NOT_FOUND' | 'ORDER_CUSTOMER_UNAVAILABLE' | 'ORDER_CUSTOMER_PRICES_OFF' | 'ORDER_PRODUCT_UNAVAILABLE' | 'ORDER_PRICES_UNAVAILABLE' | 'ORDER_IDEMPOTENCY_CONFLICT' | 'ORIGIN_NOT_REGISTERED';
|
|
613
|
+
/**
|
|
614
|
+
* The `errors` object each refusal carries, by `errorId`, as the gateway documents it. Read it through
|
|
615
|
+
* `isEldraError(error, id)`. `ORDER_PRODUCT_UNAVAILABLE` names `variantIds` on a sales order and the
|
|
616
|
+
* cart's `itemIds` on a web order.
|
|
617
|
+
*/
|
|
618
|
+
interface EldraProblemErrors {
|
|
619
|
+
SALES_ORDER_CART_ALREADY_ORDERED: {
|
|
620
|
+
salesOrderId: string;
|
|
621
|
+
};
|
|
622
|
+
SALES_ORDER_LINE_INVALID: {
|
|
623
|
+
variantId: string;
|
|
624
|
+
};
|
|
625
|
+
ORDER_PRODUCT_UNAVAILABLE: {
|
|
626
|
+
variantIds: string[];
|
|
627
|
+
itemIds: string[];
|
|
628
|
+
};
|
|
629
|
+
SHIPPING_CART_NOT_EXPORTABLE: {
|
|
630
|
+
itemIds: string[];
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
/** A problem's `errorId`: the ids above, or any other the gateway answers. */
|
|
634
|
+
type EldraErrorId = EldraShopErrorId | EldraSalesOrderErrorId | keyof EldraProblemErrors | (string & {});
|
|
635
|
+
/**
|
|
636
|
+
* Orders on account for a signed-in business customer's active company (contract 6.15.0).
|
|
637
|
+
* Server-side only: pass `customerHeaders(accessToken, customerId)` as `context.headers` on every
|
|
638
|
+
* call. Every answer is `Cache-Control: private, no-store`; never cache one. See
|
|
639
|
+
* docs/sales-orders.md.
|
|
640
|
+
*
|
|
641
|
+
* Only 401 `SHOP_TOKEN_INVALID` means sign in again. 502 `SALES_ORDER_UPSTREAM_REFUSED` is the
|
|
642
|
+
* supplier's order service refusing the platform, not the person: try again later and never sign
|
|
643
|
+
* the person out over it.
|
|
644
|
+
*/
|
|
645
|
+
interface EldraSalesOrdersClient {
|
|
646
|
+
/**
|
|
647
|
+
* Prices the company's bound cart exactly as placing it would, and writes nothing. No credit
|
|
648
|
+
* limit or balance is answered: `credit.wouldBlock` says placing would be refused for credit.
|
|
649
|
+
*/
|
|
650
|
+
preview(input: EldraSalesOrderPreviewInput, context?: EldraRequestContext): Promise<EldraSalesOrderPreview>;
|
|
651
|
+
/**
|
|
652
|
+
* Places the order from the cart (201) and the cart is removed. `options.idempotencyKey` is
|
|
653
|
+
* required (1 to 255 printable ASCII characters, no spaces): without a usable one the call rejects
|
|
654
|
+
* with an `EldraIdempotencyKeyError`, a programming error, and sends nothing. **A 502, a 503 or a timeout may
|
|
655
|
+
* follow an order that was placed**: retry with the same key, which replays that order rather
|
|
656
|
+
* than placing a second. `warnings` name steps the supplier finishes later; the order stands.
|
|
657
|
+
*/
|
|
658
|
+
create(input: EldraCreateSalesOrderInput, options: EldraCreateSalesOrderOptions, context?: EldraRequestContext): Promise<EldraSalesOrder>;
|
|
659
|
+
/** The company's sales orders, newest first; `pageSize` 1–50 (default 50). */
|
|
660
|
+
list(options?: EldraSalesOrderListOptions, context?: EldraRequestContext): Promise<EldraSalesOrderList>;
|
|
661
|
+
/** One sales order; another company's is 404 `SALES_ORDER_NOT_FOUND`. `warnings` is `[]`. */
|
|
662
|
+
get(salesOrderId: string, context?: EldraRequestContext): Promise<EldraSalesOrder>;
|
|
663
|
+
}
|
|
567
664
|
interface EldraInventoryClient {
|
|
568
665
|
availability(items: EldraStockAvailabilityInput[], context?: EldraRequestContext): Promise<EldraStockAvailability>;
|
|
569
666
|
}
|
|
@@ -667,4 +764,4 @@ interface EldraFormsClient {
|
|
|
667
764
|
/** `POST /site/v1/forms/subscriptions/unsubscribe?token=` (a GET of the link is only a page). */
|
|
668
765
|
unsubscribe(token: string, context?: EldraRequestContext): Promise<EldraFormTokenResult>;
|
|
669
766
|
}
|
|
670
|
-
export {
|
|
767
|
+
export { EldraFormSubmitResult as $, EldraShopUser as $t, EldraCollection as A, EldraProductVariant as At, EldraCustomerMembership as B, EldraSalesOrderLine as Bt, EldraCmsEntryListFilterCriterion as C, EldraKeyValueStorage as Cn, EldraProductExtensions as Ct, EldraCmsResolveEntryListOptions as D, createOrderAccessTokens as Dn, EldraProductOption as Dt, EldraCmsListOptions as E, createCartSession 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, 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, EldraOrderAccessTokens 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, 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, EldraOrderAccessTokenOptions 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.
|
|
3
|
+
"version": "0.5.1",
|
|
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",
|