@viu/emporix-sdk 4.1.0 → 4.2.2
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 +37 -0
- package/README.md +1 -0
- package/dist/cart.cjs +85 -0
- package/dist/cart.cjs.map +1 -1
- package/dist/cart.d.cts +352 -1
- package/dist/cart.d.ts +352 -1
- package/dist/cart.js +1 -1
- package/dist/{chunk-YVZ6GOLE.js → chunk-S2ERKGYL.js} +48 -3
- package/dist/chunk-S2ERKGYL.js.map +1 -0
- package/dist/index.cjs +61 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +113 -11
- package/dist/index.d.ts +113 -11
- package/dist/index.js +18 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-YVZ6GOLE.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @viu/emporix-sdk
|
|
2
2
|
|
|
3
|
+
## 4.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#372](https://github.com/viuteam/emporix-sdk/pull/372) [`b89a81a`](https://github.com/viuteam/emporix-sdk/commit/b89a81a9eed1cdbf781757d5e5f09820f6cb04af) Thanks [@amnael1](https://github.com/amnael1)! - docs(sdk): document published mappings and aborted import runs
|
|
8
|
+
|
|
9
|
+
The import types and `triggerRun` / `retryRun` now describe the Import Service change of 2026-09-28, which the types already carried: a run executes each stream's published mappings, a dry run checks the drafts with `mappings: "draft"`, and runs report `mappingVersions` and `dryRunPublished`. They also name the trap that came with it — a run refused for never-published mappings still resolves with `200` and only then finishes `ABORTED`, so read the run back before treating it as started.
|
|
10
|
+
|
|
11
|
+
## 4.2.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [#361](https://github.com/viuteam/emporix-sdk/pull/361) [`2d33114`](https://github.com/viuteam/emporix-sdk/commit/2d33114f8f7177e1d2178d46633ff3ac976ba3b4) Thanks [@amnael1](https://github.com/amnael1)! - feat(cart): add carts.execute for cart command chains
|
|
16
|
+
|
|
17
|
+
`client.carts.execute(cartId, commands, auth, { onError, versioning })` wraps
|
|
18
|
+
Emporix's new `POST /cart/{tenant}/carts/{cartId}/execute`: up to ten cart
|
|
19
|
+
operations on one cart in a single request, typically `AddCartItem` followed by
|
|
20
|
+
`GetCart`, so the calculated cart comes back with the write. `CartCommand` types
|
|
21
|
+
each command's `data` from its REST operation. With the default
|
|
22
|
+
`onError: "fail"`, a failed command throws the error its REST call would have
|
|
23
|
+
thrown — the commands before it are already applied; `onError: "resume"`
|
|
24
|
+
returns every result. See `docs/cart.md`.
|
|
25
|
+
|
|
26
|
+
React: `useCartCommands(cartId?)` runs a chain on the active cart and adopts a
|
|
27
|
+
trailing `GetCart` straight into the `useCart` cache — an add-to-cart costs one
|
|
28
|
+
request instead of the write plus a refetch. Any other chain, and any failure,
|
|
29
|
+
invalidates the cart.
|
|
30
|
+
|
|
31
|
+
Angular: `injectCartMutations().execute(commands, opts?)` runs a chain and
|
|
32
|
+
invalidates the cart after success and after a failure.
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- [#356](https://github.com/viuteam/emporix-sdk/pull/356) [`bde9867`](https://github.com/viuteam/emporix-sdk/commit/bde986759fd0b0869058d3e975a563fa761ec5a6) Thanks [@viu-release-bot](https://github.com/apps/viu-release-bot)! - chore(sdk): sync generated types with upstream Emporix API specs
|
|
37
|
+
|
|
38
|
+
Updated services: cart
|
|
39
|
+
|
|
3
40
|
## 4.1.0
|
|
4
41
|
|
|
5
42
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -126,6 +126,7 @@ anonymous browsing, both when you need both.
|
|
|
126
126
|
| `products.*` / `categories.*` (reads) | `anonymous` | — (pass `customer` for personalized pricing) |
|
|
127
127
|
| `carts.*` | — | explicit `customer` or `anonymous` |
|
|
128
128
|
| `carts.merge` | — | `customer` |
|
|
129
|
+
| `carts.execute` ([command chains](../../docs/cart.md)) | — | `customer`, `anonymous`, or `service` with `cart.cart_manage` |
|
|
129
130
|
| `companies.*` / `contacts.*` / `locations.*` / `customerGroups.*` (B2B) | — | `customer` (reads need `*_read_own`; mutations need `*_manage`) |
|
|
130
131
|
| `media.*` (Asset CRUD + download) | `service` | `service` — server-only (`media.asset_read` / `media.asset_manage`); never call from the browser |
|
|
131
132
|
|
package/dist/cart.cjs
CHANGED
|
@@ -38,10 +38,50 @@ var EmporixError = class extends Error {
|
|
|
38
38
|
return { name: this.name, message: this.message, status: this.status, body: scrub(this.body) };
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
|
+
var EmporixAuthError = class extends EmporixError {
|
|
42
|
+
};
|
|
43
|
+
var EmporixForbiddenError = class extends EmporixError {
|
|
44
|
+
};
|
|
41
45
|
var EmporixNotFoundError = class extends EmporixError {
|
|
42
46
|
};
|
|
43
47
|
var EmporixValidationError = class extends EmporixError {
|
|
44
48
|
};
|
|
49
|
+
var EmporixServerError = class extends EmporixError {
|
|
50
|
+
};
|
|
51
|
+
var EmporixInsufficientScopeError = class extends EmporixForbiddenError {
|
|
52
|
+
requiredScope;
|
|
53
|
+
constructor(message, status, body, requiredScope) {
|
|
54
|
+
super(message, status, body);
|
|
55
|
+
this.requiredScope = requiredScope;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var SCOPE_HINT_RE = /missing scope[: ]+([a-z0-9._-]+)/i;
|
|
59
|
+
function extractRequiredScope(body) {
|
|
60
|
+
if (body && typeof body === "object" && "details" in body) {
|
|
61
|
+
const details = body.details;
|
|
62
|
+
if (Array.isArray(details)) {
|
|
63
|
+
for (const d of details) {
|
|
64
|
+
if (typeof d === "string") {
|
|
65
|
+
const m = d.match(SCOPE_HINT_RE);
|
|
66
|
+
if (m) return m[1];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
function errorFromResponse(status, message, body) {
|
|
74
|
+
if (status === 401) return new EmporixAuthError(message, status, body);
|
|
75
|
+
if (status === 403) {
|
|
76
|
+
const scope = extractRequiredScope(body);
|
|
77
|
+
if (scope) return new EmporixInsufficientScopeError(message, status, body, scope);
|
|
78
|
+
return new EmporixForbiddenError(message, status, body);
|
|
79
|
+
}
|
|
80
|
+
if (status === 404) return new EmporixNotFoundError(message, status, body);
|
|
81
|
+
if (status === 400 || status === 422) return new EmporixValidationError(message, status, body);
|
|
82
|
+
if (status >= 500) return new EmporixServerError(message, status, body);
|
|
83
|
+
return new EmporixError(message, status, body);
|
|
84
|
+
}
|
|
45
85
|
|
|
46
86
|
// src/services/cart.ts
|
|
47
87
|
function requireCartAuth(auth) {
|
|
@@ -435,6 +475,51 @@ var CartService = class {
|
|
|
435
475
|
auth: requireCartAuth(auth)
|
|
436
476
|
});
|
|
437
477
|
}
|
|
478
|
+
/**
|
|
479
|
+
* Runs up to 10 cart commands on this cart in one request, in order
|
|
480
|
+
* (`POST /carts/{cartId}/execute`). The typical chain is `AddCartItem` then
|
|
481
|
+
* `GetCart`: the calculated cart comes back without a second round trip.
|
|
482
|
+
*
|
|
483
|
+
* - `onError: "fail"` (default) stops at the first command that does not
|
|
484
|
+
* answer 2xx and **throws the error that command's REST call would have
|
|
485
|
+
* thrown** — an `EmporixNotFoundError` for a 404, … — with the command's
|
|
486
|
+
* error body. The commands before it **have already been applied**.
|
|
487
|
+
* - `onError: "resume"` runs every command and resolves with all results;
|
|
488
|
+
* check each `code`.
|
|
489
|
+
* - A `400` for the whole request (no commands or more than 10, an unknown
|
|
490
|
+
* type, `versioning: "explicit"` without a `resourceVersion`) means no
|
|
491
|
+
* command ran.
|
|
492
|
+
*
|
|
493
|
+
* The request takes about as long as its commands together — size the
|
|
494
|
+
* client's `timeouts.readMs` for long chains. It is never retried: a replay
|
|
495
|
+
* would apply the writes twice.
|
|
496
|
+
*
|
|
497
|
+
* `auth` is forwarded unguarded: a customer or anonymous token works on the
|
|
498
|
+
* shopper's own cart; a service token needs `cart.cart_manage`, plus
|
|
499
|
+
* `cart.cart_manage_external_prices` when a command carries an external
|
|
500
|
+
* price, product, fee or discount.
|
|
501
|
+
*/
|
|
502
|
+
async execute(cartId, commands, auth, opts = {}) {
|
|
503
|
+
const path = `${this.base()}/${encodeURIComponent(cartId)}/execute`;
|
|
504
|
+
const res = await this.ctx.http.request({
|
|
505
|
+
method: "POST",
|
|
506
|
+
path,
|
|
507
|
+
auth,
|
|
508
|
+
query: { ...opts },
|
|
509
|
+
body: { commands }
|
|
510
|
+
});
|
|
511
|
+
if (opts.onError !== "resume") {
|
|
512
|
+
const failed = res.results.find((r) => r.code < 200 || r.code > 299);
|
|
513
|
+
if (failed) {
|
|
514
|
+
throw errorFromResponse(
|
|
515
|
+
failed.code,
|
|
516
|
+
`POST ${path} \u2192 command ${failed.index} (${failed.type}) \u2192 ${failed.code}`,
|
|
517
|
+
failed.data
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return res;
|
|
522
|
+
}
|
|
438
523
|
};
|
|
439
524
|
|
|
440
525
|
exports.CartService = CartService;
|
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,OAAO,IAAA,KAAS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A;AAAA,MAC9B,IAAA,EAAM;AAAA,KACP,CAAA;AACD,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,MAAA,EAAQ,QAAQ,CAAA;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,qBAAA,CAAsB,MAAA,EAAgB,aAAA,EAAuB,IAAA,EAAkC;AACnG,IAAA,MAAM,QAAA,GAAW,gBAAgB,IAAI,CAAA;AACrC,IAAA,MAAM,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAc;AAAA,MAChC,MAAA,EAAQ,QAAA;AAAA,MACR,IAAA,EAAM,GAAG,IAAA,CAAK,IAAA,EAAM,CAAA,CAAA,EAAI,MAAM,cAAc,aAAa,CAAA,CAAA;AAAA,MACzD,IAAA,EAAM;AAAA,KACP,CAAA;AACD,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,MAAA,EAAQ,QAAQ,CAAA;AAAA,EAClC;AAAA;AAAA,EAGA,MAAM,uBAAA,CAAwB,MAAA,EAAgB,IAAA,EAAsD;AAClG,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAkC;AAAA,MACrD,MAAA,EAAQ,KAAA;AAAA,MACR,MAAM,CAAA,EAAG,IAAA,CAAK,IAAA,EAAM,IAAI,MAAM,CAAA,eAAA,CAAA;AAAA,MAC9B,IAAA,EAAM,gBAAgB,IAAI;AAAA,KAC3B,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 Search,\n CartGetAll,\n UpdateCart,\n DiscountResponse,\n CartDtRestrictions,\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\n/** Body for searching carts (`POST /carts/search`) — a `q` filter. */\nexport type CartSearchInput = Search;\n\n/** A cart summary as returned by `POST /carts/search`. */\nexport type CartSummary = CartGetAll;\n\n/** Body for a full cart update (`PUT /carts/{id}`). */\nexport type CartUpdateInput = UpdateCart;\n\n/** A discount entry as returned by `GET /carts/{id}/discounts`. */\nexport type CartDiscount = DiscountResponse;\n\n/** Lead-time and non-delivery-time restrictions for a cart (`GET …/dtRestrictions`). */\nexport type CartDeliveryRestrictions = CartDtRestrictions;\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 /**\n * Sets the cart's shipping address, preserving the billing address.\n *\n * The API has no per-type address endpoint: addresses live in the cart's\n * `addresses` array, written via `PUT /carts/{cartId}`. That array is a **full\n * replace** — sending only one type leaves the other as an empty stub — so\n * this method reads the cart, merges, writes, and re-fetches. Use\n * {@link setAddresses} to set both in a single request.\n */\n async setShippingAddress(\n cartId: string,\n address: CartAddress,\n auth: AuthContext,\n ): Promise<Cart> {\n return this.mergeAddress(cartId, address, \"SHIPPING\", requireCartAuth(auth));\n }\n\n /**\n * Sets the cart's billing address, preserving the shipping address. See\n * {@link setShippingAddress} for why this reads before writing.\n */\n async setBillingAddress(\n cartId: string,\n address: CartAddress,\n auth: AuthContext,\n ): Promise<Cart> {\n return this.mergeAddress(cartId, address, \"BILLING\", requireCartAuth(auth));\n }\n\n /**\n * Sets both cart addresses in one request (`PUT /carts/{cartId}`), skipping\n * the read that {@link setShippingAddress} needs.\n *\n * **This replaces the cart's address set**: a type you omit is cleared, and\n * `{}` clears both. Use it when you already hold both addresses (a checkout\n * form submitting them together); use the per-type setters to change one and\n * keep the other.\n */\n async setAddresses(\n cartId: string,\n addresses: { shipping?: CartAddress; billing?: CartAddress },\n auth: AuthContext,\n ): Promise<Cart> {\n const cartAuth = requireCartAuth(auth);\n const next: CartAddress[] = [];\n if (addresses.shipping) next.push({ ...addresses.shipping, type: \"SHIPPING\" });\n if (addresses.billing) next.push({ ...addresses.billing, type: \"BILLING\" });\n await this.ctx.http.request<void>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}`,\n auth: cartAuth,\n body: { addresses: next },\n });\n return this.get(cartId, cartAuth);\n }\n\n /**\n * Reads the cart, replaces the entry of `type` with `address` (keeping every\n * other type verbatim — resending it unchanged is what stops the server from\n * wiping it), writes, and returns the re-fetched cart.\n */\n private async mergeAddress(\n cartId: string,\n address: CartAddress,\n type: \"SHIPPING\" | \"BILLING\",\n cartAuth: AuthContext,\n ): Promise<Cart> {\n const current = await this.get(cartId, cartAuth);\n const others = (current.addresses ?? []).filter((a) => a.type !== type);\n await this.ctx.http.request<void>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}`,\n auth: cartAuth,\n body: { addresses: [...others, { ...address, type }] },\n });\n return this.get(cartId, cartAuth);\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 /**\n * Searches carts tenant-wide (`POST /carts/search`, body `{ q }`). This is a\n * backend/admin operation — a customer token cannot scan other customers'\n * carts, so `auth` is forwarded unguarded (pass a service token for admin\n * use). The server enforces scope (403 on insufficient).\n */\n async search(\n query: CartSearchInput,\n auth: AuthContext,\n params: { pageNumber?: number; pageSize?: number; sort?: string; fields?: string } = {},\n ): Promise<CartSummary[]> {\n return this.ctx.http.request<CartSummary[]>({\n method: \"POST\",\n path: `${this.base()}/search`,\n query: {\n ...(params.pageNumber === undefined ? {} : { pageNumber: params.pageNumber }),\n ...(params.pageSize === undefined ? {} : { pageSize: params.pageSize }),\n ...(params.sort === undefined ? {} : { sort: params.sort }),\n ...(params.fields === undefined ? {} : { fields: params.fields }),\n },\n body: query,\n idempotent: true, // pure read over POST — safe to replay on 5xx/429\n auth,\n });\n }\n\n /**\n * Deletes a cart (`DELETE /carts/{cartId}`). Backend/admin or owner\n * operation — `auth` is forwarded unguarded (service or customer). Returns\n * nothing; the cart no longer exists.\n */\n async delete(cartId: string, auth: AuthContext): Promise<void> {\n await this.ctx.http.request<void>({\n method: \"DELETE\",\n path: `${this.base()}/${cartId}`,\n auth,\n });\n }\n\n /**\n * Full-updates a cart (`PUT /carts/{cartId}`, body `UpdateCart`). Backend or\n * owner operation — `auth` is forwarded unguarded. The endpoint returns 204,\n * so the cart is re-fetched with the same `auth` (via a direct GET, not\n * `get()`, so a service token is not rejected by the cart-auth guard) and\n * returned.\n */\n async update(cartId: string, input: CartUpdateInput, auth: AuthContext): Promise<Cart> {\n await this.ctx.http.request<void>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}`,\n auth,\n body: input,\n });\n return this.ctx.http.request<Cart>({\n method: \"GET\",\n path: `${this.base()}/${cartId}`,\n auth,\n });\n }\n\n /** Fetches a single cart item's details (`GET /carts/{cartId}/items/{itemId}`). */\n async getItem(cartId: string, itemId: string, auth: AuthContext): Promise<CartItem> {\n return this.ctx.http.request<CartItem>({\n method: \"GET\",\n path: `${this.base()}/${cartId}/items/${itemId}`,\n auth: requireCartAuth(auth),\n });\n }\n\n /** Lists the discounts applied to a cart (`GET /carts/{cartId}/discounts`). */\n async listDiscounts(cartId: string, auth: AuthContext): Promise<CartDiscount[]> {\n return this.ctx.http.request<CartDiscount[]>({\n method: \"GET\",\n path: `${this.base()}/${cartId}/discounts`,\n auth: requireCartAuth(auth),\n });\n }\n\n /**\n * Removes all discounts from a cart (`DELETE /carts/{cartId}/discounts` with\n * no `codes` filter), then re-fetches and returns the updated cart. Use\n * `removeCoupon(code)` to remove a specific coupon by code.\n */\n async removeAllDiscounts(cartId: 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 auth: cartAuth,\n });\n return this.get(cartId, cartAuth);\n }\n\n /**\n * Removes a single discount by its index (`DELETE\n * /carts/{cartId}/discounts/{discountIndex}`), then re-fetches and returns\n * the updated cart.\n */\n async removeDiscountByIndex(cartId: string, discountIndex: 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/${discountIndex}`,\n auth: cartAuth,\n });\n return this.get(cartId, cartAuth);\n }\n\n /** Retrieves the cart's lead-time and non-delivery-time restrictions (`GET /carts/{cartId}/dtRestrictions`). */\n async getDeliveryRestrictions(cartId: string, auth: AuthContext): Promise<CartDeliveryRestrictions> {\n return this.ctx.http.request<CartDeliveryRestrictions>({\n method: \"GET\",\n path: `${this.base()}/${cartId}/dtRestrictions`,\n auth: requireCartAuth(auth),\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,CAAC,CAAA,EAAG,CAAC,KAAK,MAAA,CAAO,OAAA,CAAQ,IAA+B,CAAA,EAAG;AACpE,MAAA,GAAA,CAAI,CAAC,CAAA,GAAI,kBAAA,CAAmB,GAAA,CAAI,CAAA,CAAE,aAAa,CAAA,GAAI,gBAAA,GAAmB,KAAA,CAAM,CAAC,CAAA;AAAA,IAC/E;AACA,IAAA,OAAO,GAAA;AAAA,EACT;AACA,EAAA,OAAO,IAAA;AACT;AAGO,IAAM,YAAA,GAAN,cAA2B,KAAA,CAAM;AAAA,EAC7B,MAAA;AAAA,EACA,IAAA;AAAA,EACT,WAAA,CAAY,OAAA,EAAiB,MAAA,EAAiB,IAAA,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GAAG,IAAA,CAAK,IAAA,EAAM,CAAA,CAAA,EAAI,kBAAA,CAAmB,MAAM,CAAC,CAAA,QAAA,CAAA;AACzD,IAAA,MAAM,GAAA,GAAM,MAAM,IAAA,CAAK,GAAA,CAAI,KAAK,OAAA,CAA2B;AAAA,MACzD,MAAA,EAAQ,MAAA;AAAA,MACR,IAAA;AAAA,MACA,IAAA;AAAA,MACA,KAAA,EAAO,EAAE,GAAG,IAAA,EAAK;AAAA,MACjB,IAAA,EAAM,EAAE,QAAA;AAAS,KAClB,CAAA;AACD,IAAA,IAAI,IAAA,CAAK,YAAY,QAAA,EAAU;AAC7B,MAAA,MAAM,MAAA,GAAS,GAAA,CAAI,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,IAAA,GAAO,GAAA,IAAO,CAAA,CAAE,IAAA,GAAO,GAAG,CAAA;AACnE,MAAA,IAAI,MAAA,EAAQ;AACV,QAAA,MAAM,iBAAA;AAAA,UACJ,MAAA,CAAO,IAAA;AAAA,UACP,CAAA,KAAA,EAAQ,IAAI,CAAA,gBAAA,EAAc,MAAA,CAAO,KAAK,KAAK,MAAA,CAAO,IAAI,CAAA,SAAA,EAAO,MAAA,CAAO,IAAI,CAAA,CAAA;AAAA,UACxE,MAAA,CAAO;AAAA,SACT;AAAA,MACF;AAAA,IACF;AACA,IAAA,OAAO,GAAA;AAAA,EACT;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, errorFromResponse } 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 Search,\n CartGetAll,\n UpdateCart,\n DiscountResponse,\n CartDtRestrictions,\n Discount,\n ExecuteCommand,\n ExecuteCommandResult,\n ExecuteResponse,\n PostCartExecuteData,\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\n/** Body for searching carts (`POST /carts/search`) — a `q` filter. */\nexport type CartSearchInput = Search;\n\n/** A cart summary as returned by `POST /carts/search`. */\nexport type CartSummary = CartGetAll;\n\n/** Body for a full cart update (`PUT /carts/{id}`). */\nexport type CartUpdateInput = UpdateCart;\n\n/** A discount entry as returned by `GET /carts/{id}/discounts`. */\nexport type CartDiscount = DiscountResponse;\n\n/** Lead-time and non-delivery-time restrictions for a cart (`GET …/dtRestrictions`). */\nexport type CartDeliveryRestrictions = CartDtRestrictions;\n\n/** Body for applying a discount (`POST /carts/{id}/discounts`, generated). */\nexport type CartDiscountInput = Discount;\n\n/**\n * Request body per command type of {@link CartService.execute}. The spec states\n * this only in prose — its `data` is an untyped object — so it is the one\n * hand-written piece. A command type missing here (one Emporix adds after this\n * was written) keeps the spec's untyped `data` and still works.\n */\nexport interface CartCommandBodies {\n AddCartItem: CartItemInput;\n UpdateCartItem: CartItemUpdate;\n AddCartItemsBatch: CartItemInput[];\n UpdateCartItemsBatch: CartItemsBatchUpdateInput;\n UpdateCart: CartUpdateInput;\n ApplyCartDiscount: CartDiscountInput;\n}\n\n/**\n * One command of a {@link CartService.execute} chain: `type` picks the REST\n * operation, `data` is that operation's request body, `options` holds its\n * remaining path and query parameters (`itemId`, `partial`, `expandCalculation`,\n * `zipCode`, `countryCode`, `resourceVersion`, `codes`, `discountIndex`). The\n * cart id is the `execute` path parameter, never a command field.\n *\n * `options` is the generated type, where every field is optional: `itemId`\n * (`UpdateCartItem`, `DeleteCartItem`) and `discountIndex` (`DeleteCartDiscount`)\n * are required by the server, which reports a missing one on that command.\n */\nexport type CartCommand = {\n [T in ExecuteCommand[\"type\"]]: Omit<ExecuteCommand, \"type\" | \"data\"> & { type: T } &\n (T extends keyof CartCommandBodies ? { data: CartCommandBodies[T] } : Pick<ExecuteCommand, \"data\">);\n}[ExecuteCommand[\"type\"]];\n\n/** `onError` and `versioning` of {@link CartService.execute} — both query parameters (generated). */\nexport type CartExecuteOptions = NonNullable<PostCartExecuteData[\"query\"]>;\n\n/** The `207` body of {@link CartService.execute}: one result per command that ran, in order (generated). */\nexport type CartExecuteResult = ExecuteResponse;\n\n/**\n * One entry of {@link CartExecuteResult}`.results`: `code`/`status` of the\n * equivalent REST call, and as `data` its response body — or its error body\n * when `code` is not 2xx; absent for a 204 (generated).\n */\nexport type CartCommandResult = ExecuteCommandResult;\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 /**\n * Sets the cart's shipping address, preserving the billing address.\n *\n * The API has no per-type address endpoint: addresses live in the cart's\n * `addresses` array, written via `PUT /carts/{cartId}`. That array is a **full\n * replace** — sending only one type leaves the other as an empty stub — so\n * this method reads the cart, merges, writes, and re-fetches. Use\n * {@link setAddresses} to set both in a single request.\n */\n async setShippingAddress(\n cartId: string,\n address: CartAddress,\n auth: AuthContext,\n ): Promise<Cart> {\n return this.mergeAddress(cartId, address, \"SHIPPING\", requireCartAuth(auth));\n }\n\n /**\n * Sets the cart's billing address, preserving the shipping address. See\n * {@link setShippingAddress} for why this reads before writing.\n */\n async setBillingAddress(\n cartId: string,\n address: CartAddress,\n auth: AuthContext,\n ): Promise<Cart> {\n return this.mergeAddress(cartId, address, \"BILLING\", requireCartAuth(auth));\n }\n\n /**\n * Sets both cart addresses in one request (`PUT /carts/{cartId}`), skipping\n * the read that {@link setShippingAddress} needs.\n *\n * **This replaces the cart's address set**: a type you omit is cleared, and\n * `{}` clears both. Use it when you already hold both addresses (a checkout\n * form submitting them together); use the per-type setters to change one and\n * keep the other.\n */\n async setAddresses(\n cartId: string,\n addresses: { shipping?: CartAddress; billing?: CartAddress },\n auth: AuthContext,\n ): Promise<Cart> {\n const cartAuth = requireCartAuth(auth);\n const next: CartAddress[] = [];\n if (addresses.shipping) next.push({ ...addresses.shipping, type: \"SHIPPING\" });\n if (addresses.billing) next.push({ ...addresses.billing, type: \"BILLING\" });\n await this.ctx.http.request<void>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}`,\n auth: cartAuth,\n body: { addresses: next },\n });\n return this.get(cartId, cartAuth);\n }\n\n /**\n * Reads the cart, replaces the entry of `type` with `address` (keeping every\n * other type verbatim — resending it unchanged is what stops the server from\n * wiping it), writes, and returns the re-fetched cart.\n */\n private async mergeAddress(\n cartId: string,\n address: CartAddress,\n type: \"SHIPPING\" | \"BILLING\",\n cartAuth: AuthContext,\n ): Promise<Cart> {\n const current = await this.get(cartId, cartAuth);\n const others = (current.addresses ?? []).filter((a) => a.type !== type);\n await this.ctx.http.request<void>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}`,\n auth: cartAuth,\n body: { addresses: [...others, { ...address, type }] },\n });\n return this.get(cartId, cartAuth);\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 /**\n * Searches carts tenant-wide (`POST /carts/search`, body `{ q }`). This is a\n * backend/admin operation — a customer token cannot scan other customers'\n * carts, so `auth` is forwarded unguarded (pass a service token for admin\n * use). The server enforces scope (403 on insufficient).\n */\n async search(\n query: CartSearchInput,\n auth: AuthContext,\n params: { pageNumber?: number; pageSize?: number; sort?: string; fields?: string } = {},\n ): Promise<CartSummary[]> {\n return this.ctx.http.request<CartSummary[]>({\n method: \"POST\",\n path: `${this.base()}/search`,\n query: {\n ...(params.pageNumber === undefined ? {} : { pageNumber: params.pageNumber }),\n ...(params.pageSize === undefined ? {} : { pageSize: params.pageSize }),\n ...(params.sort === undefined ? {} : { sort: params.sort }),\n ...(params.fields === undefined ? {} : { fields: params.fields }),\n },\n body: query,\n idempotent: true, // pure read over POST — safe to replay on 5xx/429\n auth,\n });\n }\n\n /**\n * Deletes a cart (`DELETE /carts/{cartId}`). Backend/admin or owner\n * operation — `auth` is forwarded unguarded (service or customer). Returns\n * nothing; the cart no longer exists.\n */\n async delete(cartId: string, auth: AuthContext): Promise<void> {\n await this.ctx.http.request<void>({\n method: \"DELETE\",\n path: `${this.base()}/${cartId}`,\n auth,\n });\n }\n\n /**\n * Full-updates a cart (`PUT /carts/{cartId}`, body `UpdateCart`). Backend or\n * owner operation — `auth` is forwarded unguarded. The endpoint returns 204,\n * so the cart is re-fetched with the same `auth` (via a direct GET, not\n * `get()`, so a service token is not rejected by the cart-auth guard) and\n * returned.\n */\n async update(cartId: string, input: CartUpdateInput, auth: AuthContext): Promise<Cart> {\n await this.ctx.http.request<void>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}`,\n auth,\n body: input,\n });\n return this.ctx.http.request<Cart>({\n method: \"GET\",\n path: `${this.base()}/${cartId}`,\n auth,\n });\n }\n\n /** Fetches a single cart item's details (`GET /carts/{cartId}/items/{itemId}`). */\n async getItem(cartId: string, itemId: string, auth: AuthContext): Promise<CartItem> {\n return this.ctx.http.request<CartItem>({\n method: \"GET\",\n path: `${this.base()}/${cartId}/items/${itemId}`,\n auth: requireCartAuth(auth),\n });\n }\n\n /** Lists the discounts applied to a cart (`GET /carts/{cartId}/discounts`). */\n async listDiscounts(cartId: string, auth: AuthContext): Promise<CartDiscount[]> {\n return this.ctx.http.request<CartDiscount[]>({\n method: \"GET\",\n path: `${this.base()}/${cartId}/discounts`,\n auth: requireCartAuth(auth),\n });\n }\n\n /**\n * Removes all discounts from a cart (`DELETE /carts/{cartId}/discounts` with\n * no `codes` filter), then re-fetches and returns the updated cart. Use\n * `removeCoupon(code)` to remove a specific coupon by code.\n */\n async removeAllDiscounts(cartId: 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 auth: cartAuth,\n });\n return this.get(cartId, cartAuth);\n }\n\n /**\n * Removes a single discount by its index (`DELETE\n * /carts/{cartId}/discounts/{discountIndex}`), then re-fetches and returns\n * the updated cart.\n */\n async removeDiscountByIndex(cartId: string, discountIndex: 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/${discountIndex}`,\n auth: cartAuth,\n });\n return this.get(cartId, cartAuth);\n }\n\n /** Retrieves the cart's lead-time and non-delivery-time restrictions (`GET /carts/{cartId}/dtRestrictions`). */\n async getDeliveryRestrictions(cartId: string, auth: AuthContext): Promise<CartDeliveryRestrictions> {\n return this.ctx.http.request<CartDeliveryRestrictions>({\n method: \"GET\",\n path: `${this.base()}/${cartId}/dtRestrictions`,\n auth: requireCartAuth(auth),\n });\n }\n\n /**\n * Runs up to 10 cart commands on this cart in one request, in order\n * (`POST /carts/{cartId}/execute`). The typical chain is `AddCartItem` then\n * `GetCart`: the calculated cart comes back without a second round trip.\n *\n * - `onError: \"fail\"` (default) stops at the first command that does not\n * answer 2xx and **throws the error that command's REST call would have\n * thrown** — an `EmporixNotFoundError` for a 404, … — with the command's\n * error body. The commands before it **have already been applied**.\n * - `onError: \"resume\"` runs every command and resolves with all results;\n * check each `code`.\n * - A `400` for the whole request (no commands or more than 10, an unknown\n * type, `versioning: \"explicit\"` without a `resourceVersion`) means no\n * command ran.\n *\n * The request takes about as long as its commands together — size the\n * client's `timeouts.readMs` for long chains. It is never retried: a replay\n * would apply the writes twice.\n *\n * `auth` is forwarded unguarded: a customer or anonymous token works on the\n * shopper's own cart; a service token needs `cart.cart_manage`, plus\n * `cart.cart_manage_external_prices` when a command carries an external\n * price, product, fee or discount.\n */\n async execute(\n cartId: string,\n commands: CartCommand[],\n auth: AuthContext,\n opts: CartExecuteOptions = {},\n ): Promise<CartExecuteResult> {\n const path = `${this.base()}/${encodeURIComponent(cartId)}/execute`;\n const res = await this.ctx.http.request<CartExecuteResult>({\n method: \"POST\",\n path,\n auth,\n query: { ...opts },\n body: { commands },\n });\n if (opts.onError !== \"resume\") {\n const failed = res.results.find((r) => r.code < 200 || r.code > 299);\n if (failed) {\n throw errorFromResponse(\n failed.code,\n `POST ${path} → command ${failed.index} (${failed.type}) → ${failed.code}`,\n failed.data,\n );\n }\n }\n return res;\n }\n}\n"]}
|