@viu/emporix-sdk 4.1.0 → 4.2.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 +29 -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 +46 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +78 -7
- package/dist/index.d.ts +78 -7
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-YVZ6GOLE.js.map +0 -1
package/dist/cart.d.ts
CHANGED
|
@@ -739,6 +739,54 @@ type CreatedCart = {
|
|
|
739
739
|
cartId: string;
|
|
740
740
|
yrn: Yrn;
|
|
741
741
|
};
|
|
742
|
+
type Discount = {
|
|
743
|
+
/**
|
|
744
|
+
* Discount unique identifier.
|
|
745
|
+
*/
|
|
746
|
+
id?: string;
|
|
747
|
+
couponYrn?: Yrn;
|
|
748
|
+
/**
|
|
749
|
+
* Discount code generated when a discount coupon is created through the Coupon Service.
|
|
750
|
+
*/
|
|
751
|
+
code: string;
|
|
752
|
+
/**
|
|
753
|
+
* Three-letter currency code, compliant with the ISO 4217 standard.
|
|
754
|
+
*/
|
|
755
|
+
currency?: string;
|
|
756
|
+
/**
|
|
757
|
+
* Discount expressed as fixed amount.
|
|
758
|
+
*/
|
|
759
|
+
amount?: number;
|
|
760
|
+
/**
|
|
761
|
+
* Discount displayed name.
|
|
762
|
+
*/
|
|
763
|
+
name?: string;
|
|
764
|
+
/**
|
|
765
|
+
* Discount expressed as a percentage of the price.
|
|
766
|
+
*/
|
|
767
|
+
discountRate?: number;
|
|
768
|
+
/**
|
|
769
|
+
* Determines whether the coupon is applied to the total or subtotal value of the order.
|
|
770
|
+
*/
|
|
771
|
+
discountCalculationType?: 'SUBTOTAL' | 'TOTAL';
|
|
772
|
+
/**
|
|
773
|
+
* Links to Coupon Service endpoints used to validate and redeem the discount.
|
|
774
|
+
*/
|
|
775
|
+
links?: Array<Link>;
|
|
776
|
+
/**
|
|
777
|
+
* Calculation type specifies how the discount should be calculated. It can be set to one of the following:
|
|
778
|
+
* * `ApplyDiscountBeforeTax`
|
|
779
|
+
* * `ApplyDiscountAfterTax`
|
|
780
|
+
*
|
|
781
|
+
* The field is **deprecated** and is not used in calculatedPrice fields. The calculated price takes into account site's settings
|
|
782
|
+
* where:
|
|
783
|
+
* * `includesTax=true` results in `ApplyDiscountAfterTax`
|
|
784
|
+
* * `includesTax=false` results in `ApplyDiscountBeforeTax`
|
|
785
|
+
*
|
|
786
|
+
* @deprecated
|
|
787
|
+
*/
|
|
788
|
+
calculationType?: 'ApplyDiscountBeforeTax' | 'ApplyDiscountAfterTax';
|
|
789
|
+
};
|
|
742
790
|
/**
|
|
743
791
|
* Discount details.
|
|
744
792
|
*/
|
|
@@ -1287,6 +1335,186 @@ type CartItemsBatchUpdateRequest = Array<CartItemRequest & {
|
|
|
1287
1335
|
[key: string]: unknown;
|
|
1288
1336
|
}>;
|
|
1289
1337
|
type BatchResponse = Array<SingleBatchResponse>;
|
|
1338
|
+
/**
|
|
1339
|
+
* Body of `POST /cart/{tenant}/carts/{cartId}/execute`. Between 1 and 10 commands.
|
|
1340
|
+
*/
|
|
1341
|
+
type ExecuteRequest = {
|
|
1342
|
+
/**
|
|
1343
|
+
* Commands to run sequentially. Maximum 10. Request duration is approximately the sum of the chained commands.
|
|
1344
|
+
*
|
|
1345
|
+
* Each item needs `type`. `data` is the REST request body and is omitted for commands that have no body. The cart id is the path parameter. `options` holds remaining path and query equivalents (`itemId`, `partial`, `expandCalculation`, `zipCode`, `countryCode`, `resourceVersion`, `codes`, `discountIndex`).
|
|
1346
|
+
*
|
|
1347
|
+
*/
|
|
1348
|
+
commands: Array<ExecuteCommand>;
|
|
1349
|
+
};
|
|
1350
|
+
/**
|
|
1351
|
+
* One operation in the execute chain. `type` selects the REST equivalent. `data` is that endpoint’s request body. The cart id is the execute path parameter. `options` fields are remaining path and query equivalents (`itemId`, `partial`, `expandCalculation`, `zipCode`, `countryCode`, `resourceVersion`, `codes`, `discountIndex`).
|
|
1352
|
+
*
|
|
1353
|
+
* Session and legal-entity identity are request headers, not command fields.
|
|
1354
|
+
*
|
|
1355
|
+
*/
|
|
1356
|
+
type ExecuteCommand = {
|
|
1357
|
+
/**
|
|
1358
|
+
* Operation to run.
|
|
1359
|
+
*
|
|
1360
|
+
* Possible values:
|
|
1361
|
+
* * `AddCartItem`
|
|
1362
|
+
* * `UpdateCartItem`
|
|
1363
|
+
* * `DeleteCartItem`
|
|
1364
|
+
* * `DeleteCartItems`
|
|
1365
|
+
* * `GetCart`
|
|
1366
|
+
* * `AddCartItemsBatch`
|
|
1367
|
+
* * `UpdateCartItemsBatch`
|
|
1368
|
+
* * `UpdateCart`
|
|
1369
|
+
* * `ApplyCartDiscount`
|
|
1370
|
+
* * `GetCartDiscounts`
|
|
1371
|
+
* * `DeleteCartDiscounts`
|
|
1372
|
+
* * `DeleteCartDiscount`
|
|
1373
|
+
* * `RefreshCart`
|
|
1374
|
+
* * `ValidateCart`
|
|
1375
|
+
*
|
|
1376
|
+
*/
|
|
1377
|
+
type: 'AddCartItem' | 'UpdateCartItem' | 'DeleteCartItem' | 'DeleteCartItems' | 'GetCart' | 'AddCartItemsBatch' | 'UpdateCartItemsBatch' | 'UpdateCart' | 'ApplyCartDiscount' | 'GetCartDiscounts' | 'DeleteCartDiscounts' | 'DeleteCartDiscount' | 'RefreshCart' | 'ValidateCart';
|
|
1378
|
+
/**
|
|
1379
|
+
* Request body of the equivalent REST operation.
|
|
1380
|
+
*
|
|
1381
|
+
* * `AddCartItem` – cart item body
|
|
1382
|
+
* * `UpdateCartItem` – cart item update body
|
|
1383
|
+
* * `AddCartItemsBatch` – list of cart item bodies
|
|
1384
|
+
* * `UpdateCartItemsBatch` – list of cart item updates (maximum 50)
|
|
1385
|
+
* * `UpdateCart` – cart update body
|
|
1386
|
+
* * `ApplyCartDiscount` – discount body
|
|
1387
|
+
*
|
|
1388
|
+
* Omit `data` for `GetCart`, `RefreshCart`, `ValidateCart`, deletes, `GetCartDiscounts`, `DeleteCartDiscounts`, and `DeleteCartDiscount`.
|
|
1389
|
+
*
|
|
1390
|
+
* The service selects the body type from `type`. A single item body is an object. Batch commands send an array.
|
|
1391
|
+
*
|
|
1392
|
+
*/
|
|
1393
|
+
data?: {
|
|
1394
|
+
[key: string]: unknown;
|
|
1395
|
+
} | Array<{
|
|
1396
|
+
[key: string]: unknown;
|
|
1397
|
+
}>;
|
|
1398
|
+
options?: ExecuteCommandOptions;
|
|
1399
|
+
};
|
|
1400
|
+
/**
|
|
1401
|
+
* Remaining path and query equivalents for the command. Required fields depend on `type`. The cart id is the execute path parameter, not an option.
|
|
1402
|
+
*/
|
|
1403
|
+
type ExecuteCommandOptions = {
|
|
1404
|
+
/**
|
|
1405
|
+
* Cart item unique identifier generated when the product is added to the cart.
|
|
1406
|
+
*
|
|
1407
|
+
* Required for `UpdateCartItem` and `DeleteCartItem`.
|
|
1408
|
+
*
|
|
1409
|
+
*/
|
|
1410
|
+
itemId?: string;
|
|
1411
|
+
/**
|
|
1412
|
+
* When `true`, only the provided item or batch fields are updated. Same default as the REST `partial` query parameter (`false`).
|
|
1413
|
+
*
|
|
1414
|
+
* Used by `UpdateCartItem` and `UpdateCartItemsBatch`.
|
|
1415
|
+
*
|
|
1416
|
+
*/
|
|
1417
|
+
partial?: boolean;
|
|
1418
|
+
/**
|
|
1419
|
+
* When `true`, `GetCart` returns a fully calculated cart. Same default as the REST `expandCalculation` query parameter (`true`).
|
|
1420
|
+
*
|
|
1421
|
+
* Used by `GetCart`.
|
|
1422
|
+
*
|
|
1423
|
+
*/
|
|
1424
|
+
expandCalculation?: boolean;
|
|
1425
|
+
/**
|
|
1426
|
+
* Zip code of the shipping address, used for tax calculations, shipping cost estimations, and pricing. Provide together with `countryCode` if either is specified.
|
|
1427
|
+
*
|
|
1428
|
+
* Used by `GetCart`.
|
|
1429
|
+
*
|
|
1430
|
+
*/
|
|
1431
|
+
zipCode?: string;
|
|
1432
|
+
/**
|
|
1433
|
+
* Two-letter country code of the shipping address. Provide together with `zipCode` if either is specified.
|
|
1434
|
+
*
|
|
1435
|
+
* Used by `GetCart`.
|
|
1436
|
+
*
|
|
1437
|
+
*/
|
|
1438
|
+
countryCode?: string;
|
|
1439
|
+
/**
|
|
1440
|
+
* Cart resource version used as If-Match for participating writes (`AddCartItem`, `UpdateCartItem`, `UpdateCart`, `ApplyCartDiscount`).
|
|
1441
|
+
*
|
|
1442
|
+
* * `versioning=skip` – ignored
|
|
1443
|
+
* * `versioning=explicit` – required on every participating command (whole-request preflight)
|
|
1444
|
+
* * `versioning=follow` – required to seed the first participating write; omit on later writes
|
|
1445
|
+
*
|
|
1446
|
+
* Extra `resourceVersion` on `GetCart`, `ValidateCart`, `RefreshCart`, deletes, and itemsBatch is ignored.
|
|
1447
|
+
*
|
|
1448
|
+
*/
|
|
1449
|
+
resourceVersion?: number;
|
|
1450
|
+
/**
|
|
1451
|
+
* Discount codes to remove. If omitted, `DeleteCartDiscounts` removes all discounts. Same meaning as the REST `codes` query parameter.
|
|
1452
|
+
*
|
|
1453
|
+
* Used by `DeleteCartDiscounts`.
|
|
1454
|
+
*
|
|
1455
|
+
*/
|
|
1456
|
+
codes?: Array<string>;
|
|
1457
|
+
/**
|
|
1458
|
+
* Index of the discount in the cart discounts array.
|
|
1459
|
+
*
|
|
1460
|
+
* Required for `DeleteCartDiscount`.
|
|
1461
|
+
*
|
|
1462
|
+
*/
|
|
1463
|
+
discountIndex?: string;
|
|
1464
|
+
};
|
|
1465
|
+
/**
|
|
1466
|
+
* Body of a 207 execute response. Present only when the chain was accepted and executed.
|
|
1467
|
+
*/
|
|
1468
|
+
type ExecuteResponse = {
|
|
1469
|
+
/**
|
|
1470
|
+
* Ordered results for commands that ran. With `onError=fail`, the array stops after the first non-2xx command.
|
|
1471
|
+
*
|
|
1472
|
+
*/
|
|
1473
|
+
results: Array<ExecuteCommandResult>;
|
|
1474
|
+
};
|
|
1475
|
+
/**
|
|
1476
|
+
* Result of one command in the execute chain. `data` matches the REST response body for that command.
|
|
1477
|
+
*/
|
|
1478
|
+
type ExecuteCommandResult = {
|
|
1479
|
+
/**
|
|
1480
|
+
* Zero-based index of the command in the request `commands` array.
|
|
1481
|
+
*/
|
|
1482
|
+
index: number;
|
|
1483
|
+
/**
|
|
1484
|
+
* Command type that produced this result.
|
|
1485
|
+
*/
|
|
1486
|
+
type: string;
|
|
1487
|
+
/**
|
|
1488
|
+
* HTTP status code of the equivalent REST operation.
|
|
1489
|
+
*/
|
|
1490
|
+
code: number;
|
|
1491
|
+
/**
|
|
1492
|
+
* HTTP reason phrase that matches `code`.
|
|
1493
|
+
*/
|
|
1494
|
+
status: string;
|
|
1495
|
+
/**
|
|
1496
|
+
* Response body of the equivalent REST operation. Omitted when that endpoint returns 204.
|
|
1497
|
+
*
|
|
1498
|
+
* A single-object body (`AddCartItem`, `GetCart`, `ApplyCartDiscount`, `ValidateCart`, or an error) is an object. `GetCartDiscounts`, `AddCartItemsBatch`, and `UpdateCartItemsBatch` return an array. Failures use the same error shape as REST (`code`, `status`, `message`).
|
|
1499
|
+
*
|
|
1500
|
+
*/
|
|
1501
|
+
data?: {
|
|
1502
|
+
[key: string]: unknown;
|
|
1503
|
+
} | Array<{
|
|
1504
|
+
[key: string]: unknown;
|
|
1505
|
+
}> | null;
|
|
1506
|
+
/**
|
|
1507
|
+
* Response headers for this command.
|
|
1508
|
+
*
|
|
1509
|
+
* When a participating write applied If-Match, this object contains `hybris-resource-version` set to the version after the write. `versioning=skip` does not send If-Match, so the header is absent.
|
|
1510
|
+
*
|
|
1511
|
+
* `AddCartItemsBatch` does not use this object for item locations. Each created item's `data[].headers.location` uses the same location as REST `POST .../itemsBatch`.
|
|
1512
|
+
*
|
|
1513
|
+
*/
|
|
1514
|
+
headers?: {
|
|
1515
|
+
[key: string]: string;
|
|
1516
|
+
};
|
|
1517
|
+
};
|
|
1290
1518
|
/**
|
|
1291
1519
|
* YRN
|
|
1292
1520
|
*
|
|
@@ -1916,6 +2144,60 @@ type ValidationError = {
|
|
|
1916
2144
|
*/
|
|
1917
2145
|
field?: string;
|
|
1918
2146
|
};
|
|
2147
|
+
type PostCartExecuteData = {
|
|
2148
|
+
body: ExecuteRequest;
|
|
2149
|
+
headers?: {
|
|
2150
|
+
/**
|
|
2151
|
+
* Anonymous customer unique session identifier. Shared by every command in the chain. Commands cannot override this header.
|
|
2152
|
+
*
|
|
2153
|
+
*/
|
|
2154
|
+
'session-id'?: string;
|
|
2155
|
+
/**
|
|
2156
|
+
* Legal entity of the shopper context. Shared by every command in the chain. Commands cannot override this header. To act as a different legal entity, send another request.
|
|
2157
|
+
*
|
|
2158
|
+
*/
|
|
2159
|
+
'legal-entity-id'?: string;
|
|
2160
|
+
};
|
|
2161
|
+
path: {
|
|
2162
|
+
/**
|
|
2163
|
+
* Cart unique identifier generated when a cart is created.
|
|
2164
|
+
*/
|
|
2165
|
+
cartId: string;
|
|
2166
|
+
/**
|
|
2167
|
+
* Your Emporix tenant name.
|
|
2168
|
+
*
|
|
2169
|
+
* **Note**: The tenant should always be written in lowercase.
|
|
2170
|
+
*
|
|
2171
|
+
*/
|
|
2172
|
+
tenant: string;
|
|
2173
|
+
};
|
|
2174
|
+
query?: {
|
|
2175
|
+
/**
|
|
2176
|
+
* Controls whether the chain stops after the first non-2xx command.
|
|
2177
|
+
*
|
|
2178
|
+
* Possible values:
|
|
2179
|
+
* * `fail` – Stop after the first non-2xx command. `results` contains only the commands that ran, including the failed one.
|
|
2180
|
+
* * `resume` – Run every command. Later commands still see earlier successful mutations.
|
|
2181
|
+
*
|
|
2182
|
+
* An invalid value returns **400** for the whole request before any command runs.
|
|
2183
|
+
*
|
|
2184
|
+
*/
|
|
2185
|
+
onError?: 'fail' | 'resume';
|
|
2186
|
+
/**
|
|
2187
|
+
* If-Match strategy for participating writes (`AddCartItem`, `UpdateCartItem`, `UpdateCart`, `ApplyCartDiscount`).
|
|
2188
|
+
*
|
|
2189
|
+
* Possible values:
|
|
2190
|
+
* * `skip` – Never pass a version. Ignore `options.resourceVersion` if present.
|
|
2191
|
+
* * `explicit` – Every participating command must send `options.resourceVersion`. Missing version on any participating write returns **400** for the whole request (preflight). This is not `skip`.
|
|
2192
|
+
* * `follow` – Seed from the first participating write, then use that cursor for later writes. After the cursor exists, a successful `RefreshCart`, delete, or itemsBatch also bumps it.
|
|
2193
|
+
*
|
|
2194
|
+
* An invalid value returns **400** for the whole request before any command runs.
|
|
2195
|
+
*
|
|
2196
|
+
*/
|
|
2197
|
+
versioning?: 'skip' | 'explicit' | 'follow';
|
|
2198
|
+
};
|
|
2199
|
+
url: '/cart/{tenant}/carts/{cartId}/execute';
|
|
2200
|
+
};
|
|
1919
2201
|
|
|
1920
2202
|
/** A cart as returned by the Cart service (all generated fields). */
|
|
1921
2203
|
type Cart = Cart$1;
|
|
@@ -1949,6 +2231,50 @@ type CartUpdateInput = UpdateCart;
|
|
|
1949
2231
|
type CartDiscount = DiscountResponse;
|
|
1950
2232
|
/** Lead-time and non-delivery-time restrictions for a cart (`GET …/dtRestrictions`). */
|
|
1951
2233
|
type CartDeliveryRestrictions = CartDtRestrictions;
|
|
2234
|
+
/** Body for applying a discount (`POST /carts/{id}/discounts`, generated). */
|
|
2235
|
+
type CartDiscountInput = Discount;
|
|
2236
|
+
/**
|
|
2237
|
+
* Request body per command type of {@link CartService.execute}. The spec states
|
|
2238
|
+
* this only in prose — its `data` is an untyped object — so it is the one
|
|
2239
|
+
* hand-written piece. A command type missing here (one Emporix adds after this
|
|
2240
|
+
* was written) keeps the spec's untyped `data` and still works.
|
|
2241
|
+
*/
|
|
2242
|
+
interface CartCommandBodies {
|
|
2243
|
+
AddCartItem: CartItemInput;
|
|
2244
|
+
UpdateCartItem: CartItemUpdate;
|
|
2245
|
+
AddCartItemsBatch: CartItemInput[];
|
|
2246
|
+
UpdateCartItemsBatch: CartItemsBatchUpdateInput;
|
|
2247
|
+
UpdateCart: CartUpdateInput;
|
|
2248
|
+
ApplyCartDiscount: CartDiscountInput;
|
|
2249
|
+
}
|
|
2250
|
+
/**
|
|
2251
|
+
* One command of a {@link CartService.execute} chain: `type` picks the REST
|
|
2252
|
+
* operation, `data` is that operation's request body, `options` holds its
|
|
2253
|
+
* remaining path and query parameters (`itemId`, `partial`, `expandCalculation`,
|
|
2254
|
+
* `zipCode`, `countryCode`, `resourceVersion`, `codes`, `discountIndex`). The
|
|
2255
|
+
* cart id is the `execute` path parameter, never a command field.
|
|
2256
|
+
*
|
|
2257
|
+
* `options` is the generated type, where every field is optional: `itemId`
|
|
2258
|
+
* (`UpdateCartItem`, `DeleteCartItem`) and `discountIndex` (`DeleteCartDiscount`)
|
|
2259
|
+
* are required by the server, which reports a missing one on that command.
|
|
2260
|
+
*/
|
|
2261
|
+
type CartCommand = {
|
|
2262
|
+
[T in ExecuteCommand["type"]]: Omit<ExecuteCommand, "type" | "data"> & {
|
|
2263
|
+
type: T;
|
|
2264
|
+
} & (T extends keyof CartCommandBodies ? {
|
|
2265
|
+
data: CartCommandBodies[T];
|
|
2266
|
+
} : Pick<ExecuteCommand, "data">);
|
|
2267
|
+
}[ExecuteCommand["type"]];
|
|
2268
|
+
/** `onError` and `versioning` of {@link CartService.execute} — both query parameters (generated). */
|
|
2269
|
+
type CartExecuteOptions = NonNullable<PostCartExecuteData["query"]>;
|
|
2270
|
+
/** The `207` body of {@link CartService.execute}: one result per command that ran, in order (generated). */
|
|
2271
|
+
type CartExecuteResult = ExecuteResponse;
|
|
2272
|
+
/**
|
|
2273
|
+
* One entry of {@link CartExecuteResult}`.results`: `code`/`status` of the
|
|
2274
|
+
* equivalent REST call, and as `data` its response body — or its error body
|
|
2275
|
+
* when `code` is not 2xx; absent for a 204 (generated).
|
|
2276
|
+
*/
|
|
2277
|
+
type CartCommandResult = ExecuteCommandResult;
|
|
1952
2278
|
/** Cart operations. Every method requires an explicit customer/anonymous context. */
|
|
1953
2279
|
declare class CartService {
|
|
1954
2280
|
private readonly ctx;
|
|
@@ -2116,6 +2442,31 @@ declare class CartService {
|
|
|
2116
2442
|
removeDiscountByIndex(cartId: string, discountIndex: string, auth: AuthContext): Promise<Cart>;
|
|
2117
2443
|
/** Retrieves the cart's lead-time and non-delivery-time restrictions (`GET /carts/{cartId}/dtRestrictions`). */
|
|
2118
2444
|
getDeliveryRestrictions(cartId: string, auth: AuthContext): Promise<CartDeliveryRestrictions>;
|
|
2445
|
+
/**
|
|
2446
|
+
* Runs up to 10 cart commands on this cart in one request, in order
|
|
2447
|
+
* (`POST /carts/{cartId}/execute`). The typical chain is `AddCartItem` then
|
|
2448
|
+
* `GetCart`: the calculated cart comes back without a second round trip.
|
|
2449
|
+
*
|
|
2450
|
+
* - `onError: "fail"` (default) stops at the first command that does not
|
|
2451
|
+
* answer 2xx and **throws the error that command's REST call would have
|
|
2452
|
+
* thrown** — an `EmporixNotFoundError` for a 404, … — with the command's
|
|
2453
|
+
* error body. The commands before it **have already been applied**.
|
|
2454
|
+
* - `onError: "resume"` runs every command and resolves with all results;
|
|
2455
|
+
* check each `code`.
|
|
2456
|
+
* - A `400` for the whole request (no commands or more than 10, an unknown
|
|
2457
|
+
* type, `versioning: "explicit"` without a `resourceVersion`) means no
|
|
2458
|
+
* command ran.
|
|
2459
|
+
*
|
|
2460
|
+
* The request takes about as long as its commands together — size the
|
|
2461
|
+
* client's `timeouts.readMs` for long chains. It is never retried: a replay
|
|
2462
|
+
* would apply the writes twice.
|
|
2463
|
+
*
|
|
2464
|
+
* `auth` is forwarded unguarded: a customer or anonymous token works on the
|
|
2465
|
+
* shopper's own cart; a service token needs `cart.cart_manage`, plus
|
|
2466
|
+
* `cart.cart_manage_external_prices` when a command carries an external
|
|
2467
|
+
* price, product, fee or discount.
|
|
2468
|
+
*/
|
|
2469
|
+
execute(cartId: string, commands: CartCommand[], auth: AuthContext, opts?: CartExecuteOptions): Promise<CartExecuteResult>;
|
|
2119
2470
|
}
|
|
2120
2471
|
|
|
2121
|
-
export { type Cart, type CartAddress, type CartCreated, type CartDeliveryRestrictions, type CartDiscount, type CartItem, type CartItemBatchEntry, type CartItemInput, type CartItemUpdate, type CartItemsBatchResponse, type CartItemsBatchUpdateInput, type CartItemsBatchUpdateResult, type CartSearchInput, CartService, type CartSummary, type CartUpdateInput, type CartValidationResult, type CreateCartInput };
|
|
2472
|
+
export { type Cart, type CartAddress, type CartCommand, type CartCommandBodies, type CartCommandResult, type CartCreated, type CartDeliveryRestrictions, type CartDiscount, type CartDiscountInput, type CartExecuteOptions, type CartExecuteResult, type CartItem, type CartItemBatchEntry, type CartItemInput, type CartItemUpdate, type CartItemsBatchResponse, type CartItemsBatchUpdateInput, type CartItemsBatchUpdateResult, type CartSearchInput, CartService, type CartSummary, type CartUpdateInput, type CartValidationResult, type CreateCartInput };
|
package/dist/cart.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmporixNotFoundError, EmporixValidationError } from './chunk-UWGGF4MC.js';
|
|
1
|
+
import { EmporixNotFoundError, errorFromResponse, EmporixValidationError } from './chunk-UWGGF4MC.js';
|
|
2
2
|
|
|
3
3
|
// src/services/cart.ts
|
|
4
4
|
function requireCartAuth(auth) {
|
|
@@ -392,8 +392,53 @@ var CartService = class {
|
|
|
392
392
|
auth: requireCartAuth(auth)
|
|
393
393
|
});
|
|
394
394
|
}
|
|
395
|
+
/**
|
|
396
|
+
* Runs up to 10 cart commands on this cart in one request, in order
|
|
397
|
+
* (`POST /carts/{cartId}/execute`). The typical chain is `AddCartItem` then
|
|
398
|
+
* `GetCart`: the calculated cart comes back without a second round trip.
|
|
399
|
+
*
|
|
400
|
+
* - `onError: "fail"` (default) stops at the first command that does not
|
|
401
|
+
* answer 2xx and **throws the error that command's REST call would have
|
|
402
|
+
* thrown** — an `EmporixNotFoundError` for a 404, … — with the command's
|
|
403
|
+
* error body. The commands before it **have already been applied**.
|
|
404
|
+
* - `onError: "resume"` runs every command and resolves with all results;
|
|
405
|
+
* check each `code`.
|
|
406
|
+
* - A `400` for the whole request (no commands or more than 10, an unknown
|
|
407
|
+
* type, `versioning: "explicit"` without a `resourceVersion`) means no
|
|
408
|
+
* command ran.
|
|
409
|
+
*
|
|
410
|
+
* The request takes about as long as its commands together — size the
|
|
411
|
+
* client's `timeouts.readMs` for long chains. It is never retried: a replay
|
|
412
|
+
* would apply the writes twice.
|
|
413
|
+
*
|
|
414
|
+
* `auth` is forwarded unguarded: a customer or anonymous token works on the
|
|
415
|
+
* shopper's own cart; a service token needs `cart.cart_manage`, plus
|
|
416
|
+
* `cart.cart_manage_external_prices` when a command carries an external
|
|
417
|
+
* price, product, fee or discount.
|
|
418
|
+
*/
|
|
419
|
+
async execute(cartId, commands, auth, opts = {}) {
|
|
420
|
+
const path = `${this.base()}/${encodeURIComponent(cartId)}/execute`;
|
|
421
|
+
const res = await this.ctx.http.request({
|
|
422
|
+
method: "POST",
|
|
423
|
+
path,
|
|
424
|
+
auth,
|
|
425
|
+
query: { ...opts },
|
|
426
|
+
body: { commands }
|
|
427
|
+
});
|
|
428
|
+
if (opts.onError !== "resume") {
|
|
429
|
+
const failed = res.results.find((r) => r.code < 200 || r.code > 299);
|
|
430
|
+
if (failed) {
|
|
431
|
+
throw errorFromResponse(
|
|
432
|
+
failed.code,
|
|
433
|
+
`POST ${path} \u2192 command ${failed.index} (${failed.type}) \u2192 ${failed.code}`,
|
|
434
|
+
failed.data
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return res;
|
|
439
|
+
}
|
|
395
440
|
};
|
|
396
441
|
|
|
397
442
|
export { CartService };
|
|
398
|
-
//# sourceMappingURL=chunk-
|
|
399
|
-
//# sourceMappingURL=chunk-
|
|
443
|
+
//# sourceMapping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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0BA,MAAM,OAAA,CACJ,MAAA,EACA,UACA,IAAA,EACA,IAAA,GAA2B,EAAC,EACA;AAC5B,IAAA,MAAM,IAAA,GAAO,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":"chunk-S2ERKGYL.js","sourcesContent":["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"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1242,7 +1242,7 @@ var HttpClient = class {
|
|
|
1242
1242
|
};
|
|
1243
1243
|
|
|
1244
1244
|
// package.json
|
|
1245
|
-
var version = "4.
|
|
1245
|
+
var version = "4.2.0";
|
|
1246
1246
|
|
|
1247
1247
|
// src/version.ts
|
|
1248
1248
|
var SDK_VERSION = version;
|
|
@@ -2865,6 +2865,51 @@ var CartService = class {
|
|
|
2865
2865
|
auth: requireCartAuth(auth2)
|
|
2866
2866
|
});
|
|
2867
2867
|
}
|
|
2868
|
+
/**
|
|
2869
|
+
* Runs up to 10 cart commands on this cart in one request, in order
|
|
2870
|
+
* (`POST /carts/{cartId}/execute`). The typical chain is `AddCartItem` then
|
|
2871
|
+
* `GetCart`: the calculated cart comes back without a second round trip.
|
|
2872
|
+
*
|
|
2873
|
+
* - `onError: "fail"` (default) stops at the first command that does not
|
|
2874
|
+
* answer 2xx and **throws the error that command's REST call would have
|
|
2875
|
+
* thrown** — an `EmporixNotFoundError` for a 404, … — with the command's
|
|
2876
|
+
* error body. The commands before it **have already been applied**.
|
|
2877
|
+
* - `onError: "resume"` runs every command and resolves with all results;
|
|
2878
|
+
* check each `code`.
|
|
2879
|
+
* - A `400` for the whole request (no commands or more than 10, an unknown
|
|
2880
|
+
* type, `versioning: "explicit"` without a `resourceVersion`) means no
|
|
2881
|
+
* command ran.
|
|
2882
|
+
*
|
|
2883
|
+
* The request takes about as long as its commands together — size the
|
|
2884
|
+
* client's `timeouts.readMs` for long chains. It is never retried: a replay
|
|
2885
|
+
* would apply the writes twice.
|
|
2886
|
+
*
|
|
2887
|
+
* `auth` is forwarded unguarded: a customer or anonymous token works on the
|
|
2888
|
+
* shopper's own cart; a service token needs `cart.cart_manage`, plus
|
|
2889
|
+
* `cart.cart_manage_external_prices` when a command carries an external
|
|
2890
|
+
* price, product, fee or discount.
|
|
2891
|
+
*/
|
|
2892
|
+
async execute(cartId, commands, auth2, opts = {}) {
|
|
2893
|
+
const path = `${this.base()}/${encodeURIComponent(cartId)}/execute`;
|
|
2894
|
+
const res = await this.ctx.http.request({
|
|
2895
|
+
method: "POST",
|
|
2896
|
+
path,
|
|
2897
|
+
auth: auth2,
|
|
2898
|
+
query: { ...opts },
|
|
2899
|
+
body: { commands }
|
|
2900
|
+
});
|
|
2901
|
+
if (opts.onError !== "resume") {
|
|
2902
|
+
const failed = res.results.find((r) => r.code < 200 || r.code > 299);
|
|
2903
|
+
if (failed) {
|
|
2904
|
+
throw errorFromResponse(
|
|
2905
|
+
failed.code,
|
|
2906
|
+
`POST ${path} \u2192 command ${failed.index} (${failed.type}) \u2192 ${failed.code}`,
|
|
2907
|
+
failed.data
|
|
2908
|
+
);
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
return res;
|
|
2912
|
+
}
|
|
2868
2913
|
};
|
|
2869
2914
|
|
|
2870
2915
|
// src/services/checkout.ts
|