@viu/emporix-sdk 2.20.1 → 2.22.0
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 +75 -0
- package/dist/availability.d.cts +1 -1
- package/dist/availability.d.ts +1 -1
- package/dist/cart.cjs +83 -7
- package/dist/cart.cjs.map +1 -1
- package/dist/cart.d.cts +119 -4
- package/dist/cart.d.ts +119 -4
- package/dist/cart.js +1 -1
- package/dist/category.cjs +28 -0
- package/dist/category.cjs.map +1 -1
- package/dist/category.d.cts +11 -1
- package/dist/category.d.ts +11 -1
- package/dist/category.js +1 -1
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/{chunk-BNX3JULF.js → chunk-44F52KRE.js} +7 -5
- package/dist/chunk-44F52KRE.js.map +1 -0
- package/dist/{chunk-PAT4CS36.js → chunk-5DWCYDQD.js} +85 -9
- package/dist/chunk-5DWCYDQD.js.map +1 -0
- package/dist/{chunk-ZNLHLFQM.js → chunk-DXOLWAOY.js} +30 -2
- package/dist/chunk-DXOLWAOY.js.map +1 -0
- package/dist/{chunk-EAWGUZHS.js → chunk-HD5RBCM6.js} +7 -5
- package/dist/chunk-HD5RBCM6.js.map +1 -0
- package/dist/{chunk-DUVIIWFG.js → chunk-IAOWDMTA.js} +7 -5
- package/dist/chunk-IAOWDMTA.js.map +1 -0
- package/dist/{chunk-PYLWZZC4.js → chunk-MMX5FGMI.js} +19 -2
- package/dist/chunk-MMX5FGMI.js.map +1 -0
- package/dist/{chunk-NEXUWPHW.js → chunk-PRN3T6TY.js} +66 -6
- package/dist/chunk-PRN3T6TY.js.map +1 -0
- package/dist/companies.cjs +5 -3
- package/dist/companies.cjs.map +1 -1
- package/dist/companies.d.cts +5 -3
- package/dist/companies.d.ts +5 -3
- package/dist/companies.js +1 -1
- package/dist/contacts.cjs +5 -3
- package/dist/contacts.cjs.map +1 -1
- package/dist/contacts.d.cts +5 -3
- package/dist/contacts.d.ts +5 -3
- package/dist/contacts.js +1 -1
- package/dist/{context-Dawv2AtS.d.ts → context-CfXJcYKP.d.cts} +1 -1
- package/dist/{context-Dawv2AtS.d.cts → context-CfXJcYKP.d.ts} +1 -1
- package/dist/customer-groups.d.cts +1 -1
- package/dist/customer-groups.d.ts +1 -1
- package/dist/customer.cjs +64 -4
- package/dist/customer.cjs.map +1 -1
- package/dist/customer.d.cts +49 -2
- package/dist/customer.d.ts +49 -2
- package/dist/customer.js +1 -1
- package/dist/index.cjs +870 -235
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2138 -117
- package/dist/index.d.ts +2138 -117
- package/dist/index.js +676 -230
- package/dist/index.js.map +1 -1
- package/dist/locations.cjs +5 -3
- package/dist/locations.cjs.map +1 -1
- package/dist/locations.d.cts +5 -3
- package/dist/locations.d.ts +5 -3
- package/dist/locations.js +1 -1
- package/dist/media.d.cts +1 -1
- package/dist/media.d.ts +1 -1
- package/dist/orders.d.cts +1 -1
- package/dist/orders.d.ts +1 -1
- package/dist/payment.cjs +17 -0
- package/dist/payment.cjs.map +1 -1
- package/dist/payment.d.cts +38 -2
- package/dist/payment.d.ts +38 -2
- package/dist/payment.js +1 -1
- package/dist/price.d.cts +6 -6
- package/dist/price.d.ts +6 -6
- package/dist/product.d.cts +1 -1
- package/dist/product.d.ts +1 -1
- package/dist/segment.d.cts +1 -1
- package/dist/segment.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-BNX3JULF.js.map +0 -1
- package/dist/chunk-DUVIIWFG.js.map +0 -1
- package/dist/chunk-EAWGUZHS.js.map +0 -1
- package/dist/chunk-NEXUWPHW.js.map +0 -1
- package/dist/chunk-PAT4CS36.js.map +0 -1
- package/dist/chunk-PYLWZZC4.js.map +0 -1
- package/dist/chunk-ZNLHLFQM.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,80 @@
|
|
|
1
1
|
# @viu/emporix-sdk
|
|
2
2
|
|
|
3
|
+
## 2.22.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#160](https://github.com/viuteam/emporix-sdk/pull/160) [`7a63559`](https://github.com/viuteam/emporix-sdk/commit/7a635592f7233dc35f35502538d6695d428897cf) Thanks [@amnael1](https://github.com/amnael1)! - Add storefront-facing facade methods and matching React hooks. Additive and
|
|
8
|
+
backward-compatible.
|
|
9
|
+
- **Cart** — `carts.validate`, `listItems`, `refresh`, `changeSite`,
|
|
10
|
+
`changeCurrency`, `updateItemsBatch` (state-changing ops re-fetch and return
|
|
11
|
+
the updated cart). Hooks: `useCartValidation`, `useCartItems`, and
|
|
12
|
+
`refresh`/`changeSite`/`changeCurrency`/`updateItemsBatch` on the
|
|
13
|
+
`useCartMutations` bundle.
|
|
14
|
+
- **Customer** — double opt-in (`confirmSignup`/`resendActivation`),
|
|
15
|
+
login-email change (`changeEmail`/`confirmEmailChange`), and address
|
|
16
|
+
`get`/`addTags`/`removeTags`. Hooks: `useConfirmSignup`,
|
|
17
|
+
`useResendActivation`, `useChangeEmail`, `useConfirmEmailChange`,
|
|
18
|
+
`useCustomerAddress`, `useAddAddressTags`, `useRemoveAddressTags`.
|
|
19
|
+
- **Category** — `categories.parents`, `childCategories` (dedicated
|
|
20
|
+
`/subcategories`), `getTree` (single tree by id). Hooks:
|
|
21
|
+
`useCategoryParents`, `useChildCategories`, `useCategoryTreeById`.
|
|
22
|
+
- **Payment** — `payments.getMode`, `initialize` (frontend, no scope). Hooks:
|
|
23
|
+
`usePaymentMode`, `useInitializePayment`.
|
|
24
|
+
- **Session context** — `sessionContext.addAttribute`/`removeAttribute`. Hooks:
|
|
25
|
+
`useAddSessionAttribute`, `useRemoveSessionAttribute`.
|
|
26
|
+
|
|
27
|
+
## 2.21.0
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- [#154](https://github.com/viuteam/emporix-sdk/pull/154) [`2c170d1`](https://github.com/viuteam/emporix-sdk/commit/2c170d182a2839bb39aba47a4075ee820195813a) Thanks [@amnael1](https://github.com/amnael1)! - Add full `AiService` parity with the ai-service API. New CRUD sub-resources
|
|
32
|
+
`ai.tools`, `ai.mcpServers`, `ai.tokens`, `ai.oauths` (list/search/get/upsert/patch/delete);
|
|
33
|
+
new resource groups `ai.jobs`, `ai.templates`, `ai.logs`, `ai.analytics`; and
|
|
34
|
+
new methods `ai.listModels`, `ai.listCommerceEvents`, `ai.uploadAttachment`,
|
|
35
|
+
`ai.exportAgents`, `ai.importAgents`.
|
|
36
|
+
|
|
37
|
+
- [#157](https://github.com/viuteam/emporix-sdk/pull/157) [`f7e9839`](https://github.com/viuteam/emporix-sdk/commit/f7e983928c3d91d3093c875a3fef5c15d59133c0) Thanks [@amnael1](https://github.com/amnael1)! - Add `client.invoices` (invoice-generation jobs) and `client.quotes` (B2B quotes
|
|
38
|
+
CRUD + PDF + history, with a `client.quotes.reasons` config sub-resource),
|
|
39
|
+
backed by the generated `invoice` / `quote` types. Quote-domain methods take a
|
|
40
|
+
required `auth` argument (customer or admin token — quotes are never
|
|
41
|
+
anonymous). The OAuth Service is intentionally not wrapped — its token grant is
|
|
42
|
+
owned by the SDK auth core.
|
|
43
|
+
|
|
44
|
+
- [#156](https://github.com/viuteam/emporix-sdk/pull/156) [`61df99e`](https://github.com/viuteam/emporix-sdk/commit/61df99ec09be5ff69327a3f70b82be58b7c90d34) Thanks [@amnael1](https://github.com/amnael1)! - Derive `SiteService` and `SessionContextService` public types from the
|
|
45
|
+
generated `site-settings-service` / `session-context` types. `Site` now
|
|
46
|
+
inherits every generated field (shipping/payment/tax/assistedBuying/mixins/
|
|
47
|
+
taxDeterminationBasedOn, richer address) while keeping `active`/`default`
|
|
48
|
+
required; `SessionContext.sessionId` stays required and the ergonomic flat
|
|
49
|
+
`patch({ …, version })` DX is unchanged. Note: `SessionContext.context` /
|
|
50
|
+
`SessionContextPatch.context` are now the accurate nested map type
|
|
51
|
+
(`Record<string, Record<string, unknown>>`) instead of `Record<string, unknown>`.
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- [#151](https://github.com/viuteam/emporix-sdk/pull/151) [`7aa5fc9`](https://github.com/viuteam/emporix-sdk/commit/7aa5fc93c5ef6a83f7235b76e4e5ccc9bb545d33) Thanks [@viu-release-bot](https://github.com/apps/viu-release-bot)! - chore(sdk): sync generated types with upstream Emporix API specs
|
|
56
|
+
|
|
57
|
+
Updated services: ai-service
|
|
58
|
+
|
|
59
|
+
- [#159](https://github.com/viuteam/emporix-sdk/pull/159) [`7a7c90c`](https://github.com/viuteam/emporix-sdk/commit/7a7c90c7d569988dfdce8ca84ea261d311a419e7) Thanks [@amnael1](https://github.com/amnael1)! - Fix four facade methods that targeted HTTP paths/methods the live Emporix API
|
|
60
|
+
rejects (verified against the tenant). Signatures are unchanged.
|
|
61
|
+
- `cart.applyCoupon` / `cart.removeCoupon` used `…/carts/{id}/coupons`, which
|
|
62
|
+
returns 404 "No endpoint". Coupons are applied via the cart **discounts**
|
|
63
|
+
endpoint: `applyCoupon` now `POST …/discounts` (coupon-code payload),
|
|
64
|
+
`removeCoupon` now `DELETE …/discounts?codes=<code>`. Both re-fetch and return
|
|
65
|
+
the updated cart.
|
|
66
|
+
- `customer.changePassword` used `PUT …/password` (404). Now `POST …/password/change`.
|
|
67
|
+
- `customer.confirmPasswordReset` used `POST …/password/reset/confirm` (404). Now
|
|
68
|
+
`POST …/password/reset/update`.
|
|
69
|
+
- `companies.update` / `contacts.update` / `locations.update` used `PATCH`, which
|
|
70
|
+
the customer-management API rejects with 405 Method Not Allowed. Now `PUT`
|
|
71
|
+
(upsert). Send the complete entity, as the server replaces the resource.
|
|
72
|
+
|
|
73
|
+
- [#155](https://github.com/viuteam/emporix-sdk/pull/155) [`c78ce7b`](https://github.com/viuteam/emporix-sdk/commit/c78ce7bb25c0208b02a4469904c56c38b11cc6cf) Thanks [@amnael1](https://github.com/amnael1)! - Register the five remaining Emporix OpenAPI specs that were missing from the
|
|
74
|
+
fetch registry — `oauth-service`, `site-settings-service`, `invoice`, `quote`,
|
|
75
|
+
`session-context` — so the SDK vendors and generates types for all 43 listed
|
|
76
|
+
API services. Generated types only; no new service facades.
|
|
77
|
+
|
|
3
78
|
## 2.20.1
|
|
4
79
|
|
|
5
80
|
### Patch Changes
|
package/dist/availability.d.cts
CHANGED
package/dist/availability.d.ts
CHANGED
package/dist/cart.cjs
CHANGED
|
@@ -163,23 +163,99 @@ var CartService = class {
|
|
|
163
163
|
auth: requireCartAuth(auth)
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
|
-
/**
|
|
166
|
+
/**
|
|
167
|
+
* Applies a coupon by code. Coupon application goes through the cart's
|
|
168
|
+
* `discounts` endpoint (`POST …/discounts` with a coupon-code-only payload) —
|
|
169
|
+
* the live API has no `…/coupons` path. The apply response only carries the
|
|
170
|
+
* applied-discount reference (`{ discountId, discountIndex }`), so the updated
|
|
171
|
+
* cart is re-fetched and returned to preserve the `Cart` contract.
|
|
172
|
+
*/
|
|
167
173
|
async applyCoupon(cartId, code, auth) {
|
|
168
|
-
|
|
174
|
+
const cartAuth = requireCartAuth(auth);
|
|
175
|
+
await this.ctx.http.request({
|
|
169
176
|
method: "POST",
|
|
170
|
-
path: `${this.base()}/${cartId}/
|
|
171
|
-
auth:
|
|
177
|
+
path: `${this.base()}/${cartId}/discounts`,
|
|
178
|
+
auth: cartAuth,
|
|
172
179
|
body: { code }
|
|
173
180
|
});
|
|
181
|
+
return this.get(cartId, cartAuth);
|
|
174
182
|
}
|
|
175
|
-
/**
|
|
183
|
+
/**
|
|
184
|
+
* Removes a coupon by code via `DELETE …/discounts?codes=<code>` — the live
|
|
185
|
+
* API has no `…/coupons/<code>` path. The delete responds 204 No Content, so
|
|
186
|
+
* the updated cart is re-fetched and returned.
|
|
187
|
+
*/
|
|
176
188
|
async removeCoupon(cartId, code, auth) {
|
|
177
|
-
|
|
189
|
+
const cartAuth = requireCartAuth(auth);
|
|
190
|
+
await this.ctx.http.request({
|
|
178
191
|
method: "DELETE",
|
|
179
|
-
path: `${this.base()}/${cartId}/
|
|
192
|
+
path: `${this.base()}/${cartId}/discounts`,
|
|
193
|
+
query: { codes: code },
|
|
194
|
+
auth: cartAuth
|
|
195
|
+
});
|
|
196
|
+
return this.get(cartId, cartAuth);
|
|
197
|
+
}
|
|
198
|
+
/** Validates the cart's items (pricing/consistency checks). */
|
|
199
|
+
async validate(cartId, auth) {
|
|
200
|
+
return this.ctx.http.request({
|
|
201
|
+
method: "GET",
|
|
202
|
+
path: `${this.base()}/${cartId}/validate`,
|
|
180
203
|
auth: requireCartAuth(auth)
|
|
181
204
|
});
|
|
182
205
|
}
|
|
206
|
+
/** Lists the items in a cart with calculated prices. */
|
|
207
|
+
async listItems(cartId, auth) {
|
|
208
|
+
return this.ctx.http.request({
|
|
209
|
+
method: "GET",
|
|
210
|
+
path: `${this.base()}/${cartId}/items`,
|
|
211
|
+
auth: requireCartAuth(auth)
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/** Refreshes a cart and its items (re-prices), then returns the updated cart. */
|
|
215
|
+
async refresh(cartId, auth) {
|
|
216
|
+
const cartAuth = requireCartAuth(auth);
|
|
217
|
+
await this.ctx.http.request({
|
|
218
|
+
method: "PUT",
|
|
219
|
+
path: `${this.base()}/${cartId}/refresh`,
|
|
220
|
+
auth: cartAuth
|
|
221
|
+
});
|
|
222
|
+
return this.get(cartId, cartAuth);
|
|
223
|
+
}
|
|
224
|
+
/** Changes the cart's site (re-prices to the new site's currency), then returns the updated cart. */
|
|
225
|
+
async changeSite(cartId, siteCode, auth) {
|
|
226
|
+
const cartAuth = requireCartAuth(auth);
|
|
227
|
+
await this.ctx.http.request({
|
|
228
|
+
method: "POST",
|
|
229
|
+
path: `${this.base()}/${cartId}/changeSite`,
|
|
230
|
+
auth: cartAuth,
|
|
231
|
+
body: { siteCode }
|
|
232
|
+
});
|
|
233
|
+
return this.get(cartId, cartAuth);
|
|
234
|
+
}
|
|
235
|
+
/** Changes the cart's currency (re-prices), then returns the updated cart. */
|
|
236
|
+
async changeCurrency(cartId, currency, auth) {
|
|
237
|
+
const cartAuth = requireCartAuth(auth);
|
|
238
|
+
await this.ctx.http.request({
|
|
239
|
+
method: "POST",
|
|
240
|
+
path: `${this.base()}/${cartId}/changeCurrency`,
|
|
241
|
+
auth: cartAuth,
|
|
242
|
+
body: { currency }
|
|
243
|
+
});
|
|
244
|
+
return this.get(cartId, cartAuth);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Updates multiple cart items in one request (`PUT …/itemsBatch`). Like
|
|
248
|
+
* `addItemsBatch`, the response carries a per-entry `status`; partial failures
|
|
249
|
+
* do not throw — inspect each entry.
|
|
250
|
+
*/
|
|
251
|
+
async updateItemsBatch(cartId, items, auth) {
|
|
252
|
+
return this.ctx.http.request({
|
|
253
|
+
method: "PUT",
|
|
254
|
+
path: `${this.base()}/${cartId}/itemsBatch`,
|
|
255
|
+
auth: requireCartAuth(auth),
|
|
256
|
+
body: items
|
|
257
|
+
});
|
|
258
|
+
}
|
|
183
259
|
/** Sets the shipping address. */
|
|
184
260
|
async setShippingAddress(cartId, address, auth) {
|
|
185
261
|
return this.ctx.http.request({
|
package/dist/cart.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/errors.ts","../src/services/cart.ts"],"names":[],"mappings":";;;AACA,IAAM,kBAAA,uBAAyB,GAAA,CAAI;AAAA,EACjC,cAAA;AAAA,EAAgB,eAAA;AAAA,EAAiB,OAAA;AAAA,EAAS,eAAA;AAAA,EAAiB,WAAA;AAAA,EAC3D,QAAA;AAAA,EAAU,eAAA;AAAA,EAAiB,eAAA;AAAA,EAAiB;AAC9C,CAAC,CAAA;AAED,SAAS,MAAM,IAAA,EAAwB;AACrC,EAAA,IAAI,MAAM,OAAA,CAAQ,IAAI,GAAG,OAAO,IAAA,CAAK,IAAI,KAAK,CAAA;AAC9C,EAAA,IAAI,IAAA,IAAQ,O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AM;AAAA,KACP,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,MAAM,iBAAA,CACJ,MAAA,EACA,OAAA,EACA,IAAA,EACe;AACf,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAc;AAAA,MACjC,MAAA,EAAQ,KAAA;AAAA,MACR,MAAM,CAAA,EAAG,IAAA,CAAK,IAAA,EAAM,IAAI,MAAM,CAAA,gBAAA,CAAA;AAAA,MAC9B,IAAA,EAAM,gBAAgB,IAAI,CAAA;AAAA,MAC1B,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,KAAA,CACJ,cAAA,EACA,gBAAA,EACA,IAAA,EACe;AACf,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAc;AAAA,MACjC,MAAA,EAAQ,MAAA;AAAA,MACR,MAAM,CAAA,EAAG,IAAA,CAAK,IAAA,EAAM,IAAI,cAAc,CAAA,MAAA,CAAA;AAAA,MACtC,IAAA,EAAM,oBAAoB,IAAI,CAAA;AAAA,MAC9B,IAAA,EAAM,EAAE,KAAA,EAAO,gBAAA;AAAiB,KACjC,CAAA;AAAA,EACH;AACF","file":"cart.cjs","sourcesContent":["/** Keys whose values are stripped from any serialised error body. */\nconst REDACTED_BODY_KEYS = new Set([\n \"access_token\", \"refresh_token\", \"token\", \"customertoken\", \"saastoken\",\n \"secret\", \"client_secret\", \"authorization\", \"password\",\n]);\n\nfunction scrub(body: unknown): unknown {\n if (Array.isArray(body)) return body.map(scrub);\n if (body && typeof body === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(body as Record<string, unknown>)) {\n out[k] = REDACTED_BODY_KEYS.has(k.toLowerCase()) ? \"***redacted***\" : scrub(v);\n }\n return out;\n }\n return body;\n}\n\n/** Base class for every error thrown by the SDK. */\nexport class EmporixError extends Error {\n readonly status: number | undefined;\n readonly body: unknown;\n constructor(message: string, status?: number, body?: unknown) {\n super(message);\n this.name = new.target.name;\n this.status = status;\n this.body = body;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n /** Safe serialisation — token-like body fields are redacted. */\n toJSON(): Record<string, unknown> {\n return { name: this.name, message: this.message, status: this.status, body: scrub(this.body) };\n }\n}\n\n/** 401 — authentication failed or token expired. */\nexport class EmporixAuthError extends EmporixError {}\n/** 403 — authenticated but not permitted. */\nexport class EmporixForbiddenError extends EmporixError {}\n/** 404 — resource not found. */\nexport class EmporixNotFoundError extends EmporixError {}\n/** 400/422 — request validation failed. */\nexport class EmporixValidationError extends EmporixError {}\n/** 5xx — server-side failure. */\nexport class EmporixServerError extends EmporixError {}\n/** Request aborted by the configured connect/read timeout. No HTTP status. */\nexport class EmporixTimeoutError extends EmporixError {}\n/** DNS/TLS/connection-level failure before or during the exchange. No HTTP status. */\nexport class EmporixNetworkError extends EmporixError {}\n\n/**\n * 403 with a `missing scope: <name>` hint in the body's `details` array.\n * Subclasses {@link EmporixForbiddenError} so existing 403 catches still work.\n */\nexport class EmporixInsufficientScopeError extends EmporixForbiddenError {\n readonly requiredScope: string | undefined;\n constructor(message: string, status: number, body: unknown, requiredScope?: string) {\n super(message, status, body);\n this.requiredScope = requiredScope;\n }\n}\n\nconst SCOPE_HINT_RE = /missing scope[: ]+([a-z0-9._-]+)/i;\n\nfunction extractRequiredScope(body: unknown): string | undefined {\n if (body && typeof body === \"object\" && \"details\" in body) {\n const details = (body as { details?: unknown }).details;\n if (Array.isArray(details)) {\n for (const d of details) {\n if (typeof d === \"string\") {\n const m = d.match(SCOPE_HINT_RE);\n if (m) return m[1];\n }\n }\n }\n }\n return undefined;\n}\n\n/** Maps an HTTP status to the matching {@link EmporixError} subclass. */\nexport function errorFromResponse(status: number, message: string, body: unknown): EmporixError {\n if (status === 401) return new EmporixAuthError(message, status, body);\n if (status === 403) {\n const scope = extractRequiredScope(body);\n if (scope) return new EmporixInsufficientScopeError(message, status, body, scope);\n return new EmporixForbiddenError(message, status, body);\n }\n if (status === 404) return new EmporixNotFoundError(message, status, body);\n if (status === 400 || status === 422) return new EmporixValidationError(message, status, body);\n if (status >= 500) return new EmporixServerError(message, status, body);\n return new EmporixError(message, status, body);\n}\n","import type { ClientContext } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport { EmporixNotFoundError, EmporixValidationError } from \"../core/errors\";\nimport type {\n Cart as GeneratedCart,\n CreateCart,\n CreatedCart,\n CartItemRequest,\n UpdateCartItem,\n AddressRequest,\n BatchResponse as GeneratedBatchResponse,\n SingleBatchResponse as GeneratedSingleBatchResponse,\n} from \"../generated/cart\";\n\n/** A cart as returned by the Cart service (all generated fields). */\nexport type Cart = GeneratedCart;\n\n/** The cart-create response (`{ cartId, yrn }`, generated). */\nexport type CartCreated = CreatedCart;\n\n/** Generated request bodies (caller sends the exact wire shape). */\nexport type CreateCartInput = CreateCart;\nexport type CartItemInput = CartItemRequest;\nexport type CartItemUpdate = UpdateCartItem;\n\n/** Per-entry result of `addItemsBatch`. `status` is HTTP-style per entry (e.g. 201 = added, 4xx = failed). */\nexport type CartItemBatchEntry = GeneratedSingleBatchResponse;\n/** Response shape of `addItemsBatch` — one entry per input item, matching by `index`. */\nexport type CartItemsBatchResponse = GeneratedBatchResponse;\n\n/** An address payload for cart shipping/billing (generated). */\nexport type CartAddress = AddressRequest;\n\nfunction requireCartAuth(auth: AuthContext | undefined): AuthContext {\n if (auth && (auth.kind === \"customer\" || auth.kind === \"anonymous\")) return auth;\n throw new EmporixValidationError(\n \"CartService requires an explicit { kind: 'customer' } or { kind: 'anonymous' } AuthContext\",\n );\n}\n\nfunction requireCustomerAuth(auth: AuthContext | undefined): AuthContext {\n if (auth && auth.kind === \"customer\") return auth;\n throw new EmporixValidationError(\"cart.merge requires a { kind: 'customer' } AuthContext\");\n}\n\n/** Cart operations. Every method requires an explicit customer/anonymous context. */\nexport class CartService {\n static readonly channel = \"cart\" as const;\n constructor(private readonly ctx: ClientContext) {}\n\n private base(): string {\n return `/cart/${this.ctx.tenant}/carts`;\n }\n\n /** Creates a cart. */\n async create(\n input: CreateCartInput | undefined,\n auth: AuthContext,\n ): Promise<CartCreated> {\n return this.ctx.http.request<CartCreated>({\n method: \"POST\",\n path: this.base(),\n auth: requireCartAuth(auth),\n body: input ?? {},\n });\n }\n\n /** Fetches a cart by id. */\n async get(cartId: string, auth: AuthContext): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"GET\",\n path: `${this.base()}/${cartId}`,\n auth: requireCartAuth(auth),\n });\n }\n\n /** Returns the current cart for the session, or null if none. */\n /**\n * Get the customer / anonymous cart matching the given criteria. Per Emporix:\n * uniqueness is defined by `siteCode` + `type` + `legalEntityId` +\n * (`customerId` derived from a customer token, or `sessionId` derived from an\n * anonymous token). With `create: true`, Emporix creates a new cart if none\n * matches.\n *\n * Returns `null` on 404 (no cart found and `create` was not set). All other\n * errors are propagated.\n */\n async getCurrent(\n auth: AuthContext,\n opts: { siteCode: string; type?: string; legalEntityId?: string; create?: boolean },\n ): Promise<Cart | null> {\n const query: Record<string, string | number> = { siteCode: opts.siteCode };\n if (opts.type !== undefined) query.type = opts.type;\n if (opts.legalEntityId !== undefined) query.legalEntityId = opts.legalEntityId;\n if (opts.create) query.create = \"true\";\n try {\n return await this.ctx.http.request<Cart>({\n method: \"GET\",\n path: this.base(),\n query,\n auth: requireCartAuth(auth),\n });\n } catch (e) {\n if (e instanceof EmporixNotFoundError) return null;\n throw e;\n }\n }\n\n /** Adds an item. */\n async addItem(\n cartId: string,\n item: CartItemInput,\n auth: AuthContext,\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"POST\",\n path: `${this.base()}/${cartId}/items`,\n auth: requireCartAuth(auth),\n body: item,\n });\n }\n\n /**\n * Adds multiple items in a single request via `POST /carts/{id}/itemsBatch`.\n * Server-side limit is 200 entries per call — callers handling larger sets\n * must chunk. The response carries a per-entry `status` (HTTP-style: 201\n * for added, 4xx/5xx for failed) and `index` matching the input position;\n * partial failures do **not** throw — inspect `status` per entry.\n */\n async addItemsBatch(\n cartId: string,\n items: CartItemInput[],\n auth: AuthContext,\n ): Promise<CartItemsBatchResponse> {\n return this.ctx.http.request<CartItemsBatchResponse>({\n method: \"POST\",\n path: `${this.base()}/${cartId}/itemsBatch`,\n auth: requireCartAuth(auth),\n body: items,\n });\n }\n\n /**\n * Updates an item. By default this is a **full replace** — the server expects\n * the complete item (e.g. `itemYrn` + the `price` row). Pass\n * `{ partial: true }` to send a **partial update** (`?partial=true`), e.g. a\n * quantity-only change with just `{ quantity }`.\n */\n async updateItem(\n cartId: string,\n itemId: string,\n patch: CartItemUpdate,\n auth: AuthContext,\n opts: { partial?: boolean } = {},\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}/items/${itemId}`,\n auth: requireCartAuth(auth),\n body: patch,\n ...(opts.partial ? { query: { partial: \"true\" } } : {}),\n });\n }\n\n /** Removes an item. */\n async removeItem(cartId: string, itemId: string, auth: AuthContext): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"DELETE\",\n path: `${this.base()}/${cartId}/items/${itemId}`,\n auth: requireCartAuth(auth),\n });\n }\n\n /** Empties the cart. */\n async clear(cartId: string, auth: AuthContext): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"DELETE\",\n path: `${this.base()}/${cartId}/items`,\n auth: requireCartAuth(auth),\n });\n }\n\n /** Applies a coupon. */\n async applyCoupon(cartId: string, code: string, auth: AuthContext): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"POST\",\n path: `${this.base()}/${cartId}/coupons`,\n auth: requireCartAuth(auth),\n body: { code },\n });\n }\n\n /** Removes a coupon. */\n async removeCoupon(cartId: string, code: string, auth: AuthContext): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"DELETE\",\n path: `${this.base()}/${cartId}/coupons/${code}`,\n auth: requireCartAuth(auth),\n });\n }\n\n /** Sets the shipping address. */\n async setShippingAddress(\n cartId: string,\n address: CartAddress,\n auth: AuthContext,\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}/shipping-address`,\n auth: requireCartAuth(auth),\n body: address,\n });\n }\n\n /** Sets the billing address. */\n async setBillingAddress(\n cartId: string,\n address: CartAddress,\n auth: AuthContext,\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}/billing-address`,\n auth: requireCartAuth(auth),\n body: address,\n });\n }\n\n /**\n * Merges one or more anonymous carts into the specified customer cart.\n * Per Emporix: the target cart in the path **must belong to the logged-in\n * customer**, and each id in `anonymousCartIds` must belong to an anonymous\n * customer. Anonymous carts go `CLOSED` on success.\n *\n * Requires a customer `AuthContext`.\n */\n async merge(\n customerCartId: string,\n anonymousCartIds: string[],\n auth: AuthContext,\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"POST\",\n path: `${this.base()}/${customerCartId}/merge`,\n auth: requireCustomerAuth(auth),\n body: { carts: anonymousCartIds },\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/core/errors.ts","../src/services/cart.ts"],"names":[],"mappings":";;;AACA,IAAM,kBAAA,uBAAyB,GAAA,CAAI;AAAA,EACjC,cAAA;AAAA,EAAgB,eAAA;AAAA,EAAiB,OAAA;AAAA,EAAS,eAAA;AAAA,EAAiB,WAAA;AAAA,EAC3D,QAAA;AAAA,EAAU,eAAA;AAAA,EAAiB,eAAA;AAAA,EAAiB;AAC9C,CAAC,CAAA;AAED,SAAS,MAAM,IAAA,EAAwB;AACrC,EAAA,IAAI,MAAM,OAAA,CAAQ,IAAI,GAAG,OAAO,IAAA,CAAK,IAAI,KAAK,CAAA;AAC9C,EAAA,IAAI,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAA,EAAU;AACpC,IAAA,MAAM,MAA+B,EAAC;AACtC,IAAA,KAAA,MAAW,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,CAAK,IAAA,EAAM,IAAI,MAAM,CAAA,iBAAA,CAAA;AAAA,MAC9B,IAAA,EAAM,gBAAgB,IAAI,CAAA;AAAA,MAC1B,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,MAAM,iBAAA,CACJ,MAAA,EACA,OAAA,EACA,IAAA,EACe;AACf,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAc;AAAA,MACjC,MAAA,EAAQ,KAAA;AAAA,MACR,MAAM,CAAA,EAAG,IAAA,CAAK,IAAA,EAAM,IAAI,MAAM,CAAA,gBAAA,CAAA;AAAA,MAC9B,IAAA,EAAM,gBAAgB,IAAI,CAAA;AAAA,MAC1B,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,KAAA,CACJ,cAAA,EACA,gBAAA,EACA,IAAA,EACe;AACf,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAc;AAAA,MACjC,MAAA,EAAQ,MAAA;AAAA,MACR,MAAM,CAAA,EAAG,IAAA,CAAK,IAAA,EAAM,IAAI,cAAc,CAAA,MAAA,CAAA;AAAA,MACtC,IAAA,EAAM,oBAAoB,IAAI,CAAA;AAAA,MAC9B,IAAA,EAAM,EAAE,KAAA,EAAO,gBAAA;AAAiB,KACjC,CAAA;AAAA,EACH;AACF","file":"cart.cjs","sourcesContent":["/** Keys whose values are stripped from any serialised error body. */\nconst REDACTED_BODY_KEYS = new Set([\n \"access_token\", \"refresh_token\", \"token\", \"customertoken\", \"saastoken\",\n \"secret\", \"client_secret\", \"authorization\", \"password\",\n]);\n\nfunction scrub(body: unknown): unknown {\n if (Array.isArray(body)) return body.map(scrub);\n if (body && typeof body === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(body as Record<string, unknown>)) {\n out[k] = REDACTED_BODY_KEYS.has(k.toLowerCase()) ? \"***redacted***\" : scrub(v);\n }\n return out;\n }\n return body;\n}\n\n/** Base class for every error thrown by the SDK. */\nexport class EmporixError extends Error {\n readonly status: number | undefined;\n readonly body: unknown;\n constructor(message: string, status?: number, body?: unknown) {\n super(message);\n this.name = new.target.name;\n this.status = status;\n this.body = body;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n /** Safe serialisation — token-like body fields are redacted. */\n toJSON(): Record<string, unknown> {\n return { name: this.name, message: this.message, status: this.status, body: scrub(this.body) };\n }\n}\n\n/** 401 — authentication failed or token expired. */\nexport class EmporixAuthError extends EmporixError {}\n/** 403 — authenticated but not permitted. */\nexport class EmporixForbiddenError extends EmporixError {}\n/** 404 — resource not found. */\nexport class EmporixNotFoundError extends EmporixError {}\n/** 400/422 — request validation failed. */\nexport class EmporixValidationError extends EmporixError {}\n/** 5xx — server-side failure. */\nexport class EmporixServerError extends EmporixError {}\n/** Request aborted by the configured connect/read timeout. No HTTP status. */\nexport class EmporixTimeoutError extends EmporixError {}\n/** DNS/TLS/connection-level failure before or during the exchange. No HTTP status. */\nexport class EmporixNetworkError extends EmporixError {}\n\n/**\n * 403 with a `missing scope: <name>` hint in the body's `details` array.\n * Subclasses {@link EmporixForbiddenError} so existing 403 catches still work.\n */\nexport class EmporixInsufficientScopeError extends EmporixForbiddenError {\n readonly requiredScope: string | undefined;\n constructor(message: string, status: number, body: unknown, requiredScope?: string) {\n super(message, status, body);\n this.requiredScope = requiredScope;\n }\n}\n\nconst SCOPE_HINT_RE = /missing scope[: ]+([a-z0-9._-]+)/i;\n\nfunction extractRequiredScope(body: unknown): string | undefined {\n if (body && typeof body === \"object\" && \"details\" in body) {\n const details = (body as { details?: unknown }).details;\n if (Array.isArray(details)) {\n for (const d of details) {\n if (typeof d === \"string\") {\n const m = d.match(SCOPE_HINT_RE);\n if (m) return m[1];\n }\n }\n }\n }\n return undefined;\n}\n\n/** Maps an HTTP status to the matching {@link EmporixError} subclass. */\nexport function errorFromResponse(status: number, message: string, body: unknown): EmporixError {\n if (status === 401) return new EmporixAuthError(message, status, body);\n if (status === 403) {\n const scope = extractRequiredScope(body);\n if (scope) return new EmporixInsufficientScopeError(message, status, body, scope);\n return new EmporixForbiddenError(message, status, body);\n }\n if (status === 404) return new EmporixNotFoundError(message, status, body);\n if (status === 400 || status === 422) return new EmporixValidationError(message, status, body);\n if (status >= 500) return new EmporixServerError(message, status, body);\n return new EmporixError(message, status, body);\n}\n","import type { ClientContext } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport { EmporixNotFoundError, EmporixValidationError } from \"../core/errors\";\nimport type {\n Cart as GeneratedCart,\n CreateCart,\n CreatedCart,\n CartItemRequest,\n UpdateCartItem,\n AddressRequest,\n AppliedDiscount,\n BatchResponse as GeneratedBatchResponse,\n SingleBatchResponse as GeneratedSingleBatchResponse,\n CartValidationResult as GeneratedCartValidationResult,\n CartItemResponse,\n CartItemsBatchUpdateRequest,\n CartItemsBatchUpdateResponse,\n} from \"../generated/cart\";\n\n/** A cart as returned by the Cart service (all generated fields). */\nexport type Cart = GeneratedCart;\n\n/** The cart-create response (`{ cartId, yrn }`, generated). */\nexport type CartCreated = CreatedCart;\n\n/** Generated request bodies (caller sends the exact wire shape). */\nexport type CreateCartInput = CreateCart;\nexport type CartItemInput = CartItemRequest;\nexport type CartItemUpdate = UpdateCartItem;\n\n/** Per-entry result of `addItemsBatch`. `status` is HTTP-style per entry (e.g. 201 = added, 4xx = failed). */\nexport type CartItemBatchEntry = GeneratedSingleBatchResponse;\n/** Response shape of `addItemsBatch` — one entry per input item, matching by `index`. */\nexport type CartItemsBatchResponse = GeneratedBatchResponse;\n\n/** An address payload for cart shipping/billing (generated). */\nexport type CartAddress = AddressRequest;\n\n/** Result of validating a cart's items (generated). */\nexport type CartValidationResult = GeneratedCartValidationResult;\n\n/** A single cart item as returned by the Cart service (generated). */\nexport type CartItem = CartItemResponse;\n\n/** Request body for updating multiple cart items (generated). */\nexport type CartItemsBatchUpdateInput = CartItemsBatchUpdateRequest;\n\n/** Per-entry response for a multi-item update (generated). */\nexport type CartItemsBatchUpdateResult = CartItemsBatchUpdateResponse;\n\nfunction requireCartAuth(auth: AuthContext | undefined): AuthContext {\n if (auth && (auth.kind === \"customer\" || auth.kind === \"anonymous\")) return auth;\n throw new EmporixValidationError(\n \"CartService requires an explicit { kind: 'customer' } or { kind: 'anonymous' } AuthContext\",\n );\n}\n\nfunction requireCustomerAuth(auth: AuthContext | undefined): AuthContext {\n if (auth && auth.kind === \"customer\") return auth;\n throw new EmporixValidationError(\"cart.merge requires a { kind: 'customer' } AuthContext\");\n}\n\n/** Cart operations. Every method requires an explicit customer/anonymous context. */\nexport class CartService {\n static readonly channel = \"cart\" as const;\n constructor(private readonly ctx: ClientContext) {}\n\n private base(): string {\n return `/cart/${this.ctx.tenant}/carts`;\n }\n\n /** Creates a cart. */\n async create(\n input: CreateCartInput | undefined,\n auth: AuthContext,\n ): Promise<CartCreated> {\n return this.ctx.http.request<CartCreated>({\n method: \"POST\",\n path: this.base(),\n auth: requireCartAuth(auth),\n body: input ?? {},\n });\n }\n\n /** Fetches a cart by id. */\n async get(cartId: string, auth: AuthContext): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"GET\",\n path: `${this.base()}/${cartId}`,\n auth: requireCartAuth(auth),\n });\n }\n\n /** Returns the current cart for the session, or null if none. */\n /**\n * Get the customer / anonymous cart matching the given criteria. Per Emporix:\n * uniqueness is defined by `siteCode` + `type` + `legalEntityId` +\n * (`customerId` derived from a customer token, or `sessionId` derived from an\n * anonymous token). With `create: true`, Emporix creates a new cart if none\n * matches.\n *\n * Returns `null` on 404 (no cart found and `create` was not set). All other\n * errors are propagated.\n */\n async getCurrent(\n auth: AuthContext,\n opts: { siteCode: string; type?: string; legalEntityId?: string; create?: boolean },\n ): Promise<Cart | null> {\n const query: Record<string, string | number> = { siteCode: opts.siteCode };\n if (opts.type !== undefined) query.type = opts.type;\n if (opts.legalEntityId !== undefined) query.legalEntityId = opts.legalEntityId;\n if (opts.create) query.create = \"true\";\n try {\n return await this.ctx.http.request<Cart>({\n method: \"GET\",\n path: this.base(),\n query,\n auth: requireCartAuth(auth),\n });\n } catch (e) {\n if (e instanceof EmporixNotFoundError) return null;\n throw e;\n }\n }\n\n /** Adds an item. */\n async addItem(\n cartId: string,\n item: CartItemInput,\n auth: AuthContext,\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"POST\",\n path: `${this.base()}/${cartId}/items`,\n auth: requireCartAuth(auth),\n body: item,\n });\n }\n\n /**\n * Adds multiple items in a single request via `POST /carts/{id}/itemsBatch`.\n * Server-side limit is 200 entries per call — callers handling larger sets\n * must chunk. The response carries a per-entry `status` (HTTP-style: 201\n * for added, 4xx/5xx for failed) and `index` matching the input position;\n * partial failures do **not** throw — inspect `status` per entry.\n */\n async addItemsBatch(\n cartId: string,\n items: CartItemInput[],\n auth: AuthContext,\n ): Promise<CartItemsBatchResponse> {\n return this.ctx.http.request<CartItemsBatchResponse>({\n method: \"POST\",\n path: `${this.base()}/${cartId}/itemsBatch`,\n auth: requireCartAuth(auth),\n body: items,\n });\n }\n\n /**\n * Updates an item. By default this is a **full replace** — the server expects\n * the complete item (e.g. `itemYrn` + the `price` row). Pass\n * `{ partial: true }` to send a **partial update** (`?partial=true`), e.g. a\n * quantity-only change with just `{ quantity }`.\n */\n async updateItem(\n cartId: string,\n itemId: string,\n patch: CartItemUpdate,\n auth: AuthContext,\n opts: { partial?: boolean } = {},\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}/items/${itemId}`,\n auth: requireCartAuth(auth),\n body: patch,\n ...(opts.partial ? { query: { partial: \"true\" } } : {}),\n });\n }\n\n /** Removes an item. */\n async removeItem(cartId: string, itemId: string, auth: AuthContext): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"DELETE\",\n path: `${this.base()}/${cartId}/items/${itemId}`,\n auth: requireCartAuth(auth),\n });\n }\n\n /** Empties the cart. */\n async clear(cartId: string, auth: AuthContext): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"DELETE\",\n path: `${this.base()}/${cartId}/items`,\n auth: requireCartAuth(auth),\n });\n }\n\n /**\n * Applies a coupon by code. Coupon application goes through the cart's\n * `discounts` endpoint (`POST …/discounts` with a coupon-code-only payload) —\n * the live API has no `…/coupons` path. The apply response only carries the\n * applied-discount reference (`{ discountId, discountIndex }`), so the updated\n * cart is re-fetched and returned to preserve the `Cart` contract.\n */\n async applyCoupon(cartId: string, code: string, auth: AuthContext): Promise<Cart> {\n const cartAuth = requireCartAuth(auth);\n await this.ctx.http.request<AppliedDiscount>({\n method: \"POST\",\n path: `${this.base()}/${cartId}/discounts`,\n auth: cartAuth,\n body: { code },\n });\n return this.get(cartId, cartAuth);\n }\n\n /**\n * Removes a coupon by code via `DELETE …/discounts?codes=<code>` — the live\n * API has no `…/coupons/<code>` path. The delete responds 204 No Content, so\n * the updated cart is re-fetched and returned.\n */\n async removeCoupon(cartId: string, code: string, auth: AuthContext): Promise<Cart> {\n const cartAuth = requireCartAuth(auth);\n await this.ctx.http.request<void>({\n method: \"DELETE\",\n path: `${this.base()}/${cartId}/discounts`,\n query: { codes: code },\n auth: cartAuth,\n });\n return this.get(cartId, cartAuth);\n }\n\n /** Validates the cart's items (pricing/consistency checks). */\n async validate(cartId: string, auth: AuthContext): Promise<CartValidationResult> {\n return this.ctx.http.request<CartValidationResult>({\n method: \"GET\",\n path: `${this.base()}/${cartId}/validate`,\n auth: requireCartAuth(auth),\n });\n }\n\n /** Lists the items in a cart with calculated prices. */\n async listItems(cartId: string, auth: AuthContext): Promise<CartItem[]> {\n return this.ctx.http.request<CartItem[]>({\n method: \"GET\",\n path: `${this.base()}/${cartId}/items`,\n auth: requireCartAuth(auth),\n });\n }\n\n /** Refreshes a cart and its items (re-prices), then returns the updated cart. */\n async refresh(cartId: string, auth: AuthContext): Promise<Cart> {\n const cartAuth = requireCartAuth(auth);\n await this.ctx.http.request<void>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}/refresh`,\n auth: cartAuth,\n });\n return this.get(cartId, cartAuth);\n }\n\n /** Changes the cart's site (re-prices to the new site's currency), then returns the updated cart. */\n async changeSite(cartId: string, siteCode: string, auth: AuthContext): Promise<Cart> {\n const cartAuth = requireCartAuth(auth);\n await this.ctx.http.request<void>({\n method: \"POST\",\n path: `${this.base()}/${cartId}/changeSite`,\n auth: cartAuth,\n body: { siteCode },\n });\n return this.get(cartId, cartAuth);\n }\n\n /** Changes the cart's currency (re-prices), then returns the updated cart. */\n async changeCurrency(cartId: string, currency: string, auth: AuthContext): Promise<Cart> {\n const cartAuth = requireCartAuth(auth);\n await this.ctx.http.request<void>({\n method: \"POST\",\n path: `${this.base()}/${cartId}/changeCurrency`,\n auth: cartAuth,\n body: { currency },\n });\n return this.get(cartId, cartAuth);\n }\n\n /**\n * Updates multiple cart items in one request (`PUT …/itemsBatch`). Like\n * `addItemsBatch`, the response carries a per-entry `status`; partial failures\n * do not throw — inspect each entry.\n */\n async updateItemsBatch(\n cartId: string,\n items: CartItemsBatchUpdateInput,\n auth: AuthContext,\n ): Promise<CartItemsBatchUpdateResult> {\n return this.ctx.http.request<CartItemsBatchUpdateResult>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}/itemsBatch`,\n auth: requireCartAuth(auth),\n body: items,\n });\n }\n\n /** Sets the shipping address. */\n async setShippingAddress(\n cartId: string,\n address: CartAddress,\n auth: AuthContext,\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}/shipping-address`,\n auth: requireCartAuth(auth),\n body: address,\n });\n }\n\n /** Sets the billing address. */\n async setBillingAddress(\n cartId: string,\n address: CartAddress,\n auth: AuthContext,\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}/billing-address`,\n auth: requireCartAuth(auth),\n body: address,\n });\n }\n\n /**\n * Merges one or more anonymous carts into the specified customer cart.\n * Per Emporix: the target cart in the path **must belong to the logged-in\n * customer**, and each id in `anonymousCartIds` must belong to an anonymous\n * customer. Anonymous carts go `CLOSED` on success.\n *\n * Requires a customer `AuthContext`.\n */\n async merge(\n customerCartId: string,\n anonymousCartIds: string[],\n auth: AuthContext,\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"POST\",\n path: `${this.base()}/${customerCartId}/merge`,\n auth: requireCustomerAuth(auth),\n body: { carts: anonymousCartIds },\n });\n }\n}\n"]}
|
package/dist/cart.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClientContext, b as AuthContext } from './context-
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-CfXJcYKP.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Access control identifier that determines who can view or manage the cart.
|
|
@@ -998,6 +998,40 @@ type SingleBatchResponse = {
|
|
|
998
998
|
};
|
|
999
999
|
yrn?: Yrn;
|
|
1000
1000
|
};
|
|
1001
|
+
/**
|
|
1002
|
+
* Result for a single cart item in a batch update, aligned with bulk operation entry responses.
|
|
1003
|
+
*/
|
|
1004
|
+
type UpdateCartItemsBatchEntryResponse = {
|
|
1005
|
+
/**
|
|
1006
|
+
* Index of the processed cart item, matching the position in the request body.
|
|
1007
|
+
*
|
|
1008
|
+
*/
|
|
1009
|
+
index?: number;
|
|
1010
|
+
/**
|
|
1011
|
+
* Cart item unique identifier.
|
|
1012
|
+
*/
|
|
1013
|
+
id?: string;
|
|
1014
|
+
/**
|
|
1015
|
+
* HTTP status code for this entry.
|
|
1016
|
+
*/
|
|
1017
|
+
code?: number;
|
|
1018
|
+
/**
|
|
1019
|
+
* HTTP status description for this entry.
|
|
1020
|
+
*/
|
|
1021
|
+
status?: string;
|
|
1022
|
+
/**
|
|
1023
|
+
* Message describing the outcome or error for this entry.
|
|
1024
|
+
*/
|
|
1025
|
+
message?: string;
|
|
1026
|
+
/**
|
|
1027
|
+
* Additional detail messages for this entry.
|
|
1028
|
+
*/
|
|
1029
|
+
details?: Array<string>;
|
|
1030
|
+
};
|
|
1031
|
+
/**
|
|
1032
|
+
* Per-entry results for batch cart item updates.
|
|
1033
|
+
*/
|
|
1034
|
+
type CartItemsBatchUpdateResponse = Array<UpdateCartItemsBatchEntryResponse>;
|
|
1001
1035
|
/**
|
|
1002
1036
|
* Shipping cost information.
|
|
1003
1037
|
*/
|
|
@@ -1149,6 +1183,9 @@ type UpdateProduct = {
|
|
|
1149
1183
|
[key: string]: unknown;
|
|
1150
1184
|
};
|
|
1151
1185
|
};
|
|
1186
|
+
type CartItemsBatchUpdateRequest = Array<CartItemRequest & {
|
|
1187
|
+
[key: string]: unknown;
|
|
1188
|
+
}>;
|
|
1152
1189
|
type BatchResponse = Array<SingleBatchResponse>;
|
|
1153
1190
|
/**
|
|
1154
1191
|
* A unique identifier of a global resource, which stores information about the resource, such as its type, ID or name of the tenant.
|
|
@@ -1728,6 +1765,50 @@ type CalculatedTotalDiscount = {
|
|
|
1728
1765
|
*/
|
|
1729
1766
|
appliedDiscounts?: Array<CalculatedAppliedDiscount>;
|
|
1730
1767
|
};
|
|
1768
|
+
/**
|
|
1769
|
+
* Result of cart validation showing any errors in the cart items.
|
|
1770
|
+
*/
|
|
1771
|
+
type CartValidationResult$1 = {
|
|
1772
|
+
/**
|
|
1773
|
+
* Flag indicating if the cart is valid or contains validation errors.
|
|
1774
|
+
*/
|
|
1775
|
+
isValid?: boolean;
|
|
1776
|
+
/**
|
|
1777
|
+
* Detailed list of validation errors for specific cart items.
|
|
1778
|
+
*/
|
|
1779
|
+
itemsValidationDetails?: Array<ItemValidationDetails>;
|
|
1780
|
+
};
|
|
1781
|
+
/**
|
|
1782
|
+
* Validation details for a specific cart item.
|
|
1783
|
+
*/
|
|
1784
|
+
type ItemValidationDetails = {
|
|
1785
|
+
/**
|
|
1786
|
+
* Identifier of the cart item.
|
|
1787
|
+
*/
|
|
1788
|
+
id?: string;
|
|
1789
|
+
/**
|
|
1790
|
+
* List of validation errors for this cart item.
|
|
1791
|
+
*/
|
|
1792
|
+
errors?: Array<ValidationError>;
|
|
1793
|
+
};
|
|
1794
|
+
/**
|
|
1795
|
+
* Details of a specific validation error.
|
|
1796
|
+
*/
|
|
1797
|
+
type ValidationError = {
|
|
1798
|
+
/**
|
|
1799
|
+
* Error code for the validation issue. Common codes include: - CART-ITEM-UNIT-PRICE-100001: Item's price was not found in the price match - CART-ITEM-UNIT-PRICE-100002: Duplicated prices found for the same product - CART-ITEM-EXTERNAL-DISCOUNT-100001: Invalid external discount configuration - CART-ITEM-EXTERNAL-DISCOUNT-100002: External discount amount exceeds item price
|
|
1800
|
+
*
|
|
1801
|
+
*/
|
|
1802
|
+
errorCode?: string;
|
|
1803
|
+
/**
|
|
1804
|
+
* Human-readable message describing the error.
|
|
1805
|
+
*/
|
|
1806
|
+
message?: string;
|
|
1807
|
+
/**
|
|
1808
|
+
* Field path where the error occurred.
|
|
1809
|
+
*/
|
|
1810
|
+
field?: string;
|
|
1811
|
+
};
|
|
1731
1812
|
|
|
1732
1813
|
/** A cart as returned by the Cart service (all generated fields). */
|
|
1733
1814
|
type Cart = Cart$1;
|
|
@@ -1743,6 +1824,14 @@ type CartItemBatchEntry = SingleBatchResponse;
|
|
|
1743
1824
|
type CartItemsBatchResponse = BatchResponse;
|
|
1744
1825
|
/** An address payload for cart shipping/billing (generated). */
|
|
1745
1826
|
type CartAddress = AddressRequest;
|
|
1827
|
+
/** Result of validating a cart's items (generated). */
|
|
1828
|
+
type CartValidationResult = CartValidationResult$1;
|
|
1829
|
+
/** A single cart item as returned by the Cart service (generated). */
|
|
1830
|
+
type CartItem = CartItemResponse;
|
|
1831
|
+
/** Request body for updating multiple cart items (generated). */
|
|
1832
|
+
type CartItemsBatchUpdateInput = CartItemsBatchUpdateRequest;
|
|
1833
|
+
/** Per-entry response for a multi-item update (generated). */
|
|
1834
|
+
type CartItemsBatchUpdateResult = CartItemsBatchUpdateResponse;
|
|
1746
1835
|
/** Cart operations. Every method requires an explicit customer/anonymous context. */
|
|
1747
1836
|
declare class CartService {
|
|
1748
1837
|
private readonly ctx;
|
|
@@ -1793,10 +1882,36 @@ declare class CartService {
|
|
|
1793
1882
|
removeItem(cartId: string, itemId: string, auth: AuthContext): Promise<Cart>;
|
|
1794
1883
|
/** Empties the cart. */
|
|
1795
1884
|
clear(cartId: string, auth: AuthContext): Promise<Cart>;
|
|
1796
|
-
/**
|
|
1885
|
+
/**
|
|
1886
|
+
* Applies a coupon by code. Coupon application goes through the cart's
|
|
1887
|
+
* `discounts` endpoint (`POST …/discounts` with a coupon-code-only payload) —
|
|
1888
|
+
* the live API has no `…/coupons` path. The apply response only carries the
|
|
1889
|
+
* applied-discount reference (`{ discountId, discountIndex }`), so the updated
|
|
1890
|
+
* cart is re-fetched and returned to preserve the `Cart` contract.
|
|
1891
|
+
*/
|
|
1797
1892
|
applyCoupon(cartId: string, code: string, auth: AuthContext): Promise<Cart>;
|
|
1798
|
-
/**
|
|
1893
|
+
/**
|
|
1894
|
+
* Removes a coupon by code via `DELETE …/discounts?codes=<code>` — the live
|
|
1895
|
+
* API has no `…/coupons/<code>` path. The delete responds 204 No Content, so
|
|
1896
|
+
* the updated cart is re-fetched and returned.
|
|
1897
|
+
*/
|
|
1799
1898
|
removeCoupon(cartId: string, code: string, auth: AuthContext): Promise<Cart>;
|
|
1899
|
+
/** Validates the cart's items (pricing/consistency checks). */
|
|
1900
|
+
validate(cartId: string, auth: AuthContext): Promise<CartValidationResult>;
|
|
1901
|
+
/** Lists the items in a cart with calculated prices. */
|
|
1902
|
+
listItems(cartId: string, auth: AuthContext): Promise<CartItem[]>;
|
|
1903
|
+
/** Refreshes a cart and its items (re-prices), then returns the updated cart. */
|
|
1904
|
+
refresh(cartId: string, auth: AuthContext): Promise<Cart>;
|
|
1905
|
+
/** Changes the cart's site (re-prices to the new site's currency), then returns the updated cart. */
|
|
1906
|
+
changeSite(cartId: string, siteCode: string, auth: AuthContext): Promise<Cart>;
|
|
1907
|
+
/** Changes the cart's currency (re-prices), then returns the updated cart. */
|
|
1908
|
+
changeCurrency(cartId: string, currency: string, auth: AuthContext): Promise<Cart>;
|
|
1909
|
+
/**
|
|
1910
|
+
* Updates multiple cart items in one request (`PUT …/itemsBatch`). Like
|
|
1911
|
+
* `addItemsBatch`, the response carries a per-entry `status`; partial failures
|
|
1912
|
+
* do not throw — inspect each entry.
|
|
1913
|
+
*/
|
|
1914
|
+
updateItemsBatch(cartId: string, items: CartItemsBatchUpdateInput, auth: AuthContext): Promise<CartItemsBatchUpdateResult>;
|
|
1800
1915
|
/** Sets the shipping address. */
|
|
1801
1916
|
setShippingAddress(cartId: string, address: CartAddress, auth: AuthContext): Promise<Cart>;
|
|
1802
1917
|
/** Sets the billing address. */
|
|
@@ -1812,4 +1927,4 @@ declare class CartService {
|
|
|
1812
1927
|
merge(customerCartId: string, anonymousCartIds: string[], auth: AuthContext): Promise<Cart>;
|
|
1813
1928
|
}
|
|
1814
1929
|
|
|
1815
|
-
export { type Cart, type CartAddress, type CartCreated, type CartItemBatchEntry, type CartItemInput, type CartItemUpdate, type CartItemsBatchResponse, CartService, type CreateCartInput };
|
|
1930
|
+
export { type Cart, type CartAddress, type CartCreated, type CartItem, type CartItemBatchEntry, type CartItemInput, type CartItemUpdate, type CartItemsBatchResponse, type CartItemsBatchUpdateInput, type CartItemsBatchUpdateResult, CartService, type CartValidationResult, type CreateCartInput };
|
package/dist/cart.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClientContext, b as AuthContext } from './context-
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-CfXJcYKP.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Access control identifier that determines who can view or manage the cart.
|
|
@@ -998,6 +998,40 @@ type SingleBatchResponse = {
|
|
|
998
998
|
};
|
|
999
999
|
yrn?: Yrn;
|
|
1000
1000
|
};
|
|
1001
|
+
/**
|
|
1002
|
+
* Result for a single cart item in a batch update, aligned with bulk operation entry responses.
|
|
1003
|
+
*/
|
|
1004
|
+
type UpdateCartItemsBatchEntryResponse = {
|
|
1005
|
+
/**
|
|
1006
|
+
* Index of the processed cart item, matching the position in the request body.
|
|
1007
|
+
*
|
|
1008
|
+
*/
|
|
1009
|
+
index?: number;
|
|
1010
|
+
/**
|
|
1011
|
+
* Cart item unique identifier.
|
|
1012
|
+
*/
|
|
1013
|
+
id?: string;
|
|
1014
|
+
/**
|
|
1015
|
+
* HTTP status code for this entry.
|
|
1016
|
+
*/
|
|
1017
|
+
code?: number;
|
|
1018
|
+
/**
|
|
1019
|
+
* HTTP status description for this entry.
|
|
1020
|
+
*/
|
|
1021
|
+
status?: string;
|
|
1022
|
+
/**
|
|
1023
|
+
* Message describing the outcome or error for this entry.
|
|
1024
|
+
*/
|
|
1025
|
+
message?: string;
|
|
1026
|
+
/**
|
|
1027
|
+
* Additional detail messages for this entry.
|
|
1028
|
+
*/
|
|
1029
|
+
details?: Array<string>;
|
|
1030
|
+
};
|
|
1031
|
+
/**
|
|
1032
|
+
* Per-entry results for batch cart item updates.
|
|
1033
|
+
*/
|
|
1034
|
+
type CartItemsBatchUpdateResponse = Array<UpdateCartItemsBatchEntryResponse>;
|
|
1001
1035
|
/**
|
|
1002
1036
|
* Shipping cost information.
|
|
1003
1037
|
*/
|
|
@@ -1149,6 +1183,9 @@ type UpdateProduct = {
|
|
|
1149
1183
|
[key: string]: unknown;
|
|
1150
1184
|
};
|
|
1151
1185
|
};
|
|
1186
|
+
type CartItemsBatchUpdateRequest = Array<CartItemRequest & {
|
|
1187
|
+
[key: string]: unknown;
|
|
1188
|
+
}>;
|
|
1152
1189
|
type BatchResponse = Array<SingleBatchResponse>;
|
|
1153
1190
|
/**
|
|
1154
1191
|
* A unique identifier of a global resource, which stores information about the resource, such as its type, ID or name of the tenant.
|
|
@@ -1728,6 +1765,50 @@ type CalculatedTotalDiscount = {
|
|
|
1728
1765
|
*/
|
|
1729
1766
|
appliedDiscounts?: Array<CalculatedAppliedDiscount>;
|
|
1730
1767
|
};
|
|
1768
|
+
/**
|
|
1769
|
+
* Result of cart validation showing any errors in the cart items.
|
|
1770
|
+
*/
|
|
1771
|
+
type CartValidationResult$1 = {
|
|
1772
|
+
/**
|
|
1773
|
+
* Flag indicating if the cart is valid or contains validation errors.
|
|
1774
|
+
*/
|
|
1775
|
+
isValid?: boolean;
|
|
1776
|
+
/**
|
|
1777
|
+
* Detailed list of validation errors for specific cart items.
|
|
1778
|
+
*/
|
|
1779
|
+
itemsValidationDetails?: Array<ItemValidationDetails>;
|
|
1780
|
+
};
|
|
1781
|
+
/**
|
|
1782
|
+
* Validation details for a specific cart item.
|
|
1783
|
+
*/
|
|
1784
|
+
type ItemValidationDetails = {
|
|
1785
|
+
/**
|
|
1786
|
+
* Identifier of the cart item.
|
|
1787
|
+
*/
|
|
1788
|
+
id?: string;
|
|
1789
|
+
/**
|
|
1790
|
+
* List of validation errors for this cart item.
|
|
1791
|
+
*/
|
|
1792
|
+
errors?: Array<ValidationError>;
|
|
1793
|
+
};
|
|
1794
|
+
/**
|
|
1795
|
+
* Details of a specific validation error.
|
|
1796
|
+
*/
|
|
1797
|
+
type ValidationError = {
|
|
1798
|
+
/**
|
|
1799
|
+
* Error code for the validation issue. Common codes include: - CART-ITEM-UNIT-PRICE-100001: Item's price was not found in the price match - CART-ITEM-UNIT-PRICE-100002: Duplicated prices found for the same product - CART-ITEM-EXTERNAL-DISCOUNT-100001: Invalid external discount configuration - CART-ITEM-EXTERNAL-DISCOUNT-100002: External discount amount exceeds item price
|
|
1800
|
+
*
|
|
1801
|
+
*/
|
|
1802
|
+
errorCode?: string;
|
|
1803
|
+
/**
|
|
1804
|
+
* Human-readable message describing the error.
|
|
1805
|
+
*/
|
|
1806
|
+
message?: string;
|
|
1807
|
+
/**
|
|
1808
|
+
* Field path where the error occurred.
|
|
1809
|
+
*/
|
|
1810
|
+
field?: string;
|
|
1811
|
+
};
|
|
1731
1812
|
|
|
1732
1813
|
/** A cart as returned by the Cart service (all generated fields). */
|
|
1733
1814
|
type Cart = Cart$1;
|
|
@@ -1743,6 +1824,14 @@ type CartItemBatchEntry = SingleBatchResponse;
|
|
|
1743
1824
|
type CartItemsBatchResponse = BatchResponse;
|
|
1744
1825
|
/** An address payload for cart shipping/billing (generated). */
|
|
1745
1826
|
type CartAddress = AddressRequest;
|
|
1827
|
+
/** Result of validating a cart's items (generated). */
|
|
1828
|
+
type CartValidationResult = CartValidationResult$1;
|
|
1829
|
+
/** A single cart item as returned by the Cart service (generated). */
|
|
1830
|
+
type CartItem = CartItemResponse;
|
|
1831
|
+
/** Request body for updating multiple cart items (generated). */
|
|
1832
|
+
type CartItemsBatchUpdateInput = CartItemsBatchUpdateRequest;
|
|
1833
|
+
/** Per-entry response for a multi-item update (generated). */
|
|
1834
|
+
type CartItemsBatchUpdateResult = CartItemsBatchUpdateResponse;
|
|
1746
1835
|
/** Cart operations. Every method requires an explicit customer/anonymous context. */
|
|
1747
1836
|
declare class CartService {
|
|
1748
1837
|
private readonly ctx;
|
|
@@ -1793,10 +1882,36 @@ declare class CartService {
|
|
|
1793
1882
|
removeItem(cartId: string, itemId: string, auth: AuthContext): Promise<Cart>;
|
|
1794
1883
|
/** Empties the cart. */
|
|
1795
1884
|
clear(cartId: string, auth: AuthContext): Promise<Cart>;
|
|
1796
|
-
/**
|
|
1885
|
+
/**
|
|
1886
|
+
* Applies a coupon by code. Coupon application goes through the cart's
|
|
1887
|
+
* `discounts` endpoint (`POST …/discounts` with a coupon-code-only payload) —
|
|
1888
|
+
* the live API has no `…/coupons` path. The apply response only carries the
|
|
1889
|
+
* applied-discount reference (`{ discountId, discountIndex }`), so the updated
|
|
1890
|
+
* cart is re-fetched and returned to preserve the `Cart` contract.
|
|
1891
|
+
*/
|
|
1797
1892
|
applyCoupon(cartId: string, code: string, auth: AuthContext): Promise<Cart>;
|
|
1798
|
-
/**
|
|
1893
|
+
/**
|
|
1894
|
+
* Removes a coupon by code via `DELETE …/discounts?codes=<code>` — the live
|
|
1895
|
+
* API has no `…/coupons/<code>` path. The delete responds 204 No Content, so
|
|
1896
|
+
* the updated cart is re-fetched and returned.
|
|
1897
|
+
*/
|
|
1799
1898
|
removeCoupon(cartId: string, code: string, auth: AuthContext): Promise<Cart>;
|
|
1899
|
+
/** Validates the cart's items (pricing/consistency checks). */
|
|
1900
|
+
validate(cartId: string, auth: AuthContext): Promise<CartValidationResult>;
|
|
1901
|
+
/** Lists the items in a cart with calculated prices. */
|
|
1902
|
+
listItems(cartId: string, auth: AuthContext): Promise<CartItem[]>;
|
|
1903
|
+
/** Refreshes a cart and its items (re-prices), then returns the updated cart. */
|
|
1904
|
+
refresh(cartId: string, auth: AuthContext): Promise<Cart>;
|
|
1905
|
+
/** Changes the cart's site (re-prices to the new site's currency), then returns the updated cart. */
|
|
1906
|
+
changeSite(cartId: string, siteCode: string, auth: AuthContext): Promise<Cart>;
|
|
1907
|
+
/** Changes the cart's currency (re-prices), then returns the updated cart. */
|
|
1908
|
+
changeCurrency(cartId: string, currency: string, auth: AuthContext): Promise<Cart>;
|
|
1909
|
+
/**
|
|
1910
|
+
* Updates multiple cart items in one request (`PUT …/itemsBatch`). Like
|
|
1911
|
+
* `addItemsBatch`, the response carries a per-entry `status`; partial failures
|
|
1912
|
+
* do not throw — inspect each entry.
|
|
1913
|
+
*/
|
|
1914
|
+
updateItemsBatch(cartId: string, items: CartItemsBatchUpdateInput, auth: AuthContext): Promise<CartItemsBatchUpdateResult>;
|
|
1800
1915
|
/** Sets the shipping address. */
|
|
1801
1916
|
setShippingAddress(cartId: string, address: CartAddress, auth: AuthContext): Promise<Cart>;
|
|
1802
1917
|
/** Sets the billing address. */
|
|
@@ -1812,4 +1927,4 @@ declare class CartService {
|
|
|
1812
1927
|
merge(customerCartId: string, anonymousCartIds: string[], auth: AuthContext): Promise<Cart>;
|
|
1813
1928
|
}
|
|
1814
1929
|
|
|
1815
|
-
export { type Cart, type CartAddress, type CartCreated, type CartItemBatchEntry, type CartItemInput, type CartItemUpdate, type CartItemsBatchResponse, CartService, type CreateCartInput };
|
|
1930
|
+
export { type Cart, type CartAddress, type CartCreated, type CartItem, type CartItemBatchEntry, type CartItemInput, type CartItemUpdate, type CartItemsBatchResponse, type CartItemsBatchUpdateInput, type CartItemsBatchUpdateResult, CartService, type CartValidationResult, type CreateCartInput };
|
package/dist/cart.js
CHANGED