@viu/emporix-sdk 4.0.1 → 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 +65 -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-QQMLN76U.js → chunk-2OTFVTG6.js} +7 -4
- package/dist/chunk-2OTFVTG6.js.map +1 -0
- package/dist/{chunk-CSYXGTOH.js → chunk-5MPL4XBD.js} +68 -4
- package/dist/chunk-5MPL4XBD.js.map +1 -0
- package/dist/{chunk-P3RANRGB.js → chunk-IYNT5BQW.js} +16 -2
- package/dist/chunk-IYNT5BQW.js.map +1 -0
- package/dist/{chunk-ZOFGDNSX.js → chunk-K4KXT6NX.js} +12 -6
- package/dist/chunk-K4KXT6NX.js.map +1 -0
- package/dist/{chunk-XJJDCK2Z.js → chunk-N2CE3J4M.js} +12 -7
- package/dist/chunk-N2CE3J4M.js.map +1 -0
- package/dist/{chunk-YVZ6GOLE.js → chunk-S2ERKGYL.js} +48 -3
- package/dist/chunk-S2ERKGYL.js.map +1 -0
- package/dist/{chunk-5XZ6MSXW.js → chunk-VXORPTMP.js} +19 -2
- package/dist/chunk-VXORPTMP.js.map +1 -0
- package/dist/chunk-ZWJUDXTK.js +15 -0
- package/dist/chunk-ZWJUDXTK.js.map +1 -0
- package/dist/companies.cjs +15 -2
- package/dist/companies.cjs.map +1 -1
- package/dist/companies.d.cts +5 -3
- package/dist/companies.d.ts +5 -3
- package/dist/companies.js +2 -1
- package/dist/customer-groups.cjs +17 -0
- package/dist/customer-groups.cjs.map +1 -1
- package/dist/customer-groups.js +1 -1
- package/dist/index.cjs +259 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +150 -28
- package/dist/index.d.ts +150 -28
- package/dist/index.js +99 -59
- package/dist/index.js.map +1 -1
- package/dist/media.cjs +66 -2
- package/dist/media.cjs.map +1 -1
- package/dist/media.d.cts +184 -5
- package/dist/media.d.ts +184 -5
- package/dist/media.js +1 -1
- package/dist/orders.cjs +14 -0
- package/dist/orders.cjs.map +1 -1
- package/dist/orders.d.cts +6 -0
- package/dist/orders.d.ts +6 -0
- package/dist/orders.js +1 -1
- package/dist/price.cjs +20 -4
- package/dist/price.cjs.map +1 -1
- package/dist/price.d.cts +12 -4
- package/dist/price.d.ts +12 -4
- package/dist/price.js +2 -1
- package/dist/search-DU6tE356.d.cts +15 -0
- package/dist/search-DU6tE356.d.ts +15 -0
- package/dist/segment.cjs +21 -5
- package/dist/segment.cjs.map +1 -1
- package/dist/segment.d.cts +16 -6
- package/dist/segment.d.ts +16 -6
- package/dist/segment.js +2 -1
- package/package.json +1 -1
- package/dist/chunk-5XZ6MSXW.js.map +0 -1
- package/dist/chunk-CSYXGTOH.js.map +0 -1
- package/dist/chunk-P3RANRGB.js.map +0 -1
- package/dist/chunk-QQMLN76U.js.map +0 -1
- package/dist/chunk-XJJDCK2Z.js.map +0 -1
- package/dist/chunk-YVZ6GOLE.js.map +0 -1
- package/dist/chunk-ZOFGDNSX.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,3 +1,5 @@
|
|
|
1
|
+
import { splitQuery, SEARCH_PAGING } from './chunk-ZWJUDXTK.js';
|
|
2
|
+
|
|
1
3
|
// src/services/companies.ts
|
|
2
4
|
var CompaniesService = class {
|
|
3
5
|
constructor(ctx) {
|
|
@@ -57,14 +59,15 @@ var CompaniesService = class {
|
|
|
57
59
|
}
|
|
58
60
|
/**
|
|
59
61
|
* Searches legal entities via `POST /legal-entities/search` with an Emporix
|
|
60
|
-
* `q`-syntax filter body
|
|
62
|
+
* `q`-syntax filter body; paging, sort and fields go in the query string.
|
|
63
|
+
* Requires the same read scope as {@link listMine}.
|
|
61
64
|
*/
|
|
62
65
|
async search(query, auth) {
|
|
63
66
|
return this.ctx.http.request({
|
|
64
67
|
method: "POST",
|
|
65
68
|
path: `${this.base()}/search`,
|
|
66
69
|
auth,
|
|
67
|
-
|
|
70
|
+
...splitQuery(query, SEARCH_PAGING),
|
|
68
71
|
idempotent: true
|
|
69
72
|
// pure read over POST — safe to replay on 5xx/429
|
|
70
73
|
});
|
|
@@ -83,5 +86,5 @@ var CompaniesService = class {
|
|
|
83
86
|
};
|
|
84
87
|
|
|
85
88
|
export { CompaniesService };
|
|
86
|
-
//# sourceMappingURL=chunk-
|
|
87
|
-
//# sourceMappingURL=chunk-
|
|
89
|
+
//# sourceMappingURL=chunk-2OTFVTG6.js.map
|
|
90
|
+
//# sourceMappingURL=chunk-2OTFVTG6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/companies.ts"],"names":[],"mappings":";;;AAoBO,IAAM,mBAAN,MAAuB;AAAA,EAE5B,YAA6B,GAAA,EAAoB;AAApB,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAA,EAAqB;AAAA,EAArB,GAAA;AAAA,EAD7B,OAAgB,OAAA,GAAU,qBAAA;AAAA,EAGlB,IAAA,GAAe;AACrB,IAAA,OAAO,CAAA,qBAAA,EAAwB,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,eAAA,CAAA;AAAA,EAChD;AAAA;AAAA,EAGA,MAAM,SAAS,IAAA,EAA2C;AACxD,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAuB;AAAA,MAC1C,MAAA,EAAQ,KAAA;AAAA,MACR,IAAA,EAAM,KAAK,IAAA,EAAK;AAAA,MAChB;AAAA,KACD,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,MAAM,GAAA,CAAI,aAAA,EAAuB,IAAA,EAAyC;AAC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I,IAAA,CAAK,OAAA,CAAuB;AAAA,MAC1C,MAAA,EAAQ,MAAA;AAAA,MACR,IAAA,EAAM,CAAA,EAAG,IAAA,CAAK,IAAA,EAAM,CAAA,OAAA,CAAA;AAAA,MACpB,IAAA;AAAA,MACA,GAAG,UAAA,CAAW,KAAA,EAAO,aAAa,CAAA;AAAA,MAClC,UAAA,EAAY;AAAA;AAAA,KACb,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,eAAA,CAAgB,aAAA,EAAuB,IAAA,EAA2C;AACtF,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAuB;AAAA,MAC1C,MAAA,EAAQ,KAAA;AAAA,MACR,MAAM,CAAA,EAAG,IAAA,CAAK,IAAA,EAAM,IAAI,aAAa,CAAA,iBAAA,CAAA;AAAA,MACrC;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"chunk-2OTFVTG6.js","sourcesContent":["import type { ClientContext } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport { SEARCH_PAGING, splitQuery, type SearchPaging } from \"../core/search\";\nimport type {\n LegalEntity,\n LegalEntityCreate,\n LegalEntityUpdate,\n} from \"../generated/customer-management\";\n\n/** Input for `companies.search`: an Emporix `q`-syntax filter (body) plus {@link SearchPaging} (query). */\nexport type LegalEntitySearchInput = { q?: string } & SearchPaging;\n\n/**\n * Storefront-customer access to Legal Entities.\n *\n * `listMine`/`get` require `customermanagement.legalentity_read_own` on the\n * customer token. `create`/`update`/`delete` require the corresponding\n * `_manage` scopes — typically only granted to Admin-group customers; a 403\n * surfaces as `EmporixInsufficientScopeError`.\n */\nexport class CompaniesService {\n static readonly channel = \"customer-management\" as const;\n constructor(private readonly ctx: ClientContext) {}\n\n private base(): string {\n return `/customer-management/${this.ctx.tenant}/legal-entities`;\n }\n\n /** Lists the legal entities the calling customer is assigned to. */\n async listMine(auth: AuthContext): Promise<LegalEntity[]> {\n return this.ctx.http.request<LegalEntity[]>({\n method: \"GET\",\n path: this.base(),\n auth,\n });\n }\n\n /** Fetches a single legal entity by id. */\n async get(legalEntityId: string, auth: AuthContext): Promise<LegalEntity> {\n return this.ctx.http.request<LegalEntity>({\n method: \"GET\",\n path: `${this.base()}/${legalEntityId}`,\n auth,\n });\n }\n\n /** Creates a legal entity. Requires `customermanagement.legalentity_manage`. */\n async create(input: LegalEntityCreate, auth: AuthContext): Promise<{ id: string }> {\n return this.ctx.http.request<{ id: string }>({\n method: \"POST\",\n path: this.base(),\n auth,\n body: input,\n });\n }\n\n /**\n * Updates a legal entity via `PUT …/legal-entities/{id}` (upsert / full\n * replace). The live API rejects `PATCH` on this path with 405; send the\n * complete entity, as the server replaces the resource. The body stays typed\n * as a partial of `LegalEntityUpdate` for backward compatibility.\n */\n async update(\n legalEntityId: string,\n patch: Partial<LegalEntityUpdate>,\n auth: AuthContext,\n ): Promise<LegalEntity> {\n return this.ctx.http.request<LegalEntity>({\n method: \"PUT\",\n path: `${this.base()}/${legalEntityId}`,\n auth,\n body: patch,\n });\n }\n\n /** Deletes a legal entity (async cascade on the server). */\n async delete(legalEntityId: string, auth: AuthContext): Promise<void> {\n await this.ctx.http.request<void>({\n method: \"DELETE\",\n path: `${this.base()}/${legalEntityId}`,\n auth,\n });\n }\n\n /**\n * Searches legal entities via `POST /legal-entities/search` with an Emporix\n * `q`-syntax filter body; paging, sort and fields go in the query string.\n * Requires the same read scope as {@link listMine}.\n */\n async search(query: LegalEntitySearchInput, auth: AuthContext): Promise<LegalEntity[]> {\n return this.ctx.http.request<LegalEntity[]>({\n method: \"POST\",\n path: `${this.base()}/search`,\n auth,\n ...splitQuery(query, SEARCH_PAGING),\n idempotent: true, // pure read over POST — safe to replay on 5xx/429\n });\n }\n\n /**\n * Retrieves a legal entity's chain of parent entities\n * (`GET /legal-entities/{id}/parent-hierarchy`).\n */\n async parentHierarchy(legalEntityId: string, auth: AuthContext): Promise<LegalEntity[]> {\n return this.ctx.http.request<LegalEntity[]>({\n method: \"GET\",\n path: `${this.base()}/${legalEntityId}/parent-hierarchy`,\n auth,\n });\n }\n}\n"]}
|
|
@@ -15,7 +15,10 @@ var MediaService = class {
|
|
|
15
15
|
base() {
|
|
16
16
|
return `/media/${this.ctx.tenant}/assets`;
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Create an asset. BLOB uploads via multipart (max 30 MB); LINK via JSON.
|
|
20
|
+
* {@link startUploadSession} sends the file straight to storage instead.
|
|
21
|
+
*/
|
|
19
22
|
async create(input, auth = SERVICE) {
|
|
20
23
|
if (input.kind === "blob") {
|
|
21
24
|
const fd = new FormData();
|
|
@@ -73,7 +76,7 @@ var MediaService = class {
|
|
|
73
76
|
* Sends `application/json`. Used for `refIds`, `details`, `metadata`,
|
|
74
77
|
* or `url` changes.
|
|
75
78
|
* - `{ kind: "blob", file, body }` — replaces the BLOB file content
|
|
76
|
-
* (max
|
|
79
|
+
* (max 30 MB) AND patches metadata in the same request. Sends
|
|
77
80
|
* `multipart/form-data`.
|
|
78
81
|
*
|
|
79
82
|
* `type` and `access` are immutable per Emporix — they must match the
|
|
@@ -147,6 +150,12 @@ var MediaService = class {
|
|
|
147
150
|
* an `ArrayBuffer` transparently; binary Content-Types are passed
|
|
148
151
|
* through verbatim.
|
|
149
152
|
*
|
|
153
|
+
* Emporix recommends {@link getDownloadUrl} for every download: here the file
|
|
154
|
+
* passes through the Media API. A `413` means the asset's known size exceeds
|
|
155
|
+
* the streaming limit (30 MB by default) — only {@link getDownloadUrl} can
|
|
156
|
+
* serve it. A `409` means the asset is still `PENDING` from a direct upload
|
|
157
|
+
* whose file has not reached storage.
|
|
158
|
+
*
|
|
150
159
|
* Implementation note: uses `redirect: "manual"` so the redirect-location
|
|
151
160
|
* is observable. In Node.js this works; in a browser the redirect Location
|
|
152
161
|
* is intentionally hidden by fetch — there, `PUBLIC` downloads will
|
|
@@ -202,6 +211,61 @@ var MediaService = class {
|
|
|
202
211
|
}
|
|
203
212
|
throw errorFromResponse(res.status, `GET ${path} \u2192 ${res.status}`, parsed);
|
|
204
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Get a URL that serves the stored file straight from storage
|
|
216
|
+
* (`GET /assets/{assetId}/download-url`). Emporix recommends it for every
|
|
217
|
+
* download: the file never passes through the Media API, there is no size
|
|
218
|
+
* limit, and the URL can be handed to a browser as it is.
|
|
219
|
+
*
|
|
220
|
+
* - `PRIVATE` BLOB → `provider: "GCS"`, a signed Google Cloud Storage URL that
|
|
221
|
+
* works without an Emporix token until `expiresAt` (15 minutes by default).
|
|
222
|
+
* - `PUBLIC` BLOB → `provider: "CLOUDINARY"`, the permanent URL.
|
|
223
|
+
* - `LINK` → `provider: "LINK"`, the stored URL.
|
|
224
|
+
*
|
|
225
|
+
* `disposition` (`attachment` by default, or `inline`) affects private URLs
|
|
226
|
+
* only. Unlike {@link startUploadSession}, this works whether or not direct
|
|
227
|
+
* upload is enabled for the tenant. A `409` means a direct upload is still
|
|
228
|
+
* `PENDING` and its file has not reached storage; once it has, this call
|
|
229
|
+
* completes the asset before answering.
|
|
230
|
+
*/
|
|
231
|
+
async getDownloadUrl(assetId, query = {}, auth = SERVICE) {
|
|
232
|
+
return this.ctx.http.request({
|
|
233
|
+
method: "GET",
|
|
234
|
+
path: `${this.base()}/${encodeURIComponent(assetId)}/download-url`,
|
|
235
|
+
auth,
|
|
236
|
+
query: { ...query }
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Start a direct upload of a `BLOB` asset (`POST /assets/upload-session`,
|
|
241
|
+
* `201`). Emporix creates the asset as `PENDING` — `id` is its id — and
|
|
242
|
+
* returns where to send the file. **This method does not send it**:
|
|
243
|
+
*
|
|
244
|
+
* - `upload.method === "PUT"` (a `PRIVATE` asset, `uploadType: "put"` or
|
|
245
|
+
* omitted): `PUT` the file to `upload.url` with every `upload.headers` entry.
|
|
246
|
+
* - `upload.method === "POST"` (every `PUBLIC` asset, or `uploadType: "form"`):
|
|
247
|
+
* a multipart `POST` to `upload.url` with every `upload.fields` entry
|
|
248
|
+
* unchanged and the file part last.
|
|
249
|
+
*
|
|
250
|
+
* That request goes to Google Cloud Storage or Cloudinary, not to Emporix, so
|
|
251
|
+
* it must not carry the Emporix token — which is also why a browser can make
|
|
252
|
+
* it. The asset turns `READY` once storage confirms; until then, calls that
|
|
253
|
+
* need the file answer `409`. The instruction is valid for 15 minutes (GCS) or
|
|
254
|
+
* an hour (Cloudinary), and an unused session expires at `expiresAt`.
|
|
255
|
+
*
|
|
256
|
+
* Direct upload is enabled per tenant by Emporix Support. Without it the call
|
|
257
|
+
* throws an `EmporixForbiddenError` whose `body.message` is `direct upload is
|
|
258
|
+
* not enabled for this tenant`, and nothing is created — the same status as a
|
|
259
|
+
* missing scope, so read the message.
|
|
260
|
+
*/
|
|
261
|
+
async startUploadSession(input, auth = SERVICE) {
|
|
262
|
+
return this.ctx.http.request({
|
|
263
|
+
method: "POST",
|
|
264
|
+
path: `${this.base()}/upload-session`,
|
|
265
|
+
auth,
|
|
266
|
+
body: input
|
|
267
|
+
});
|
|
268
|
+
}
|
|
205
269
|
/** Multipart upload sugar: builds `AssetCreateBlob` from input. */
|
|
206
270
|
async uploadFile(input, auth = SERVICE) {
|
|
207
271
|
const body = {
|
|
@@ -274,5 +338,5 @@ var MediaService = class {
|
|
|
274
338
|
var _internalMedia = { isProductRef };
|
|
275
339
|
|
|
276
340
|
export { MediaService, _internalMedia };
|
|
277
|
-
//# sourceMappingURL=chunk-
|
|
278
|
-
//# sourceMappingURL=chunk-
|
|
341
|
+
//# sourceMappingURL=chunk-5MPL4XBD.js.map
|
|
342
|
+
//# sourceMappingURL=chunk-5MPL4XBD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/media.ts"],"names":["text"],"mappings":";;;;AA6EA,IAAM,OAAA,GAAuB,EAAE,IAAA,EAAM,SAAA,EAAU;AAE/C,SAAS,YAAA,CAAa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AAA;AACtC,IAAA,MAAM,MAAA,GAAuB,CAAA,CAAE,MAAA,IAAU,EAAC;AAC1C,IAAA,MAAM,IAAA,GAAO,OAAO,MAAA,CAAO,CAAC,MAAM,CAAC,YAAA,CAAa,CAAA,EAAG,SAAS,CAAC,CAAA;AAC7D,IAAA,IAAI,IAAA,CAAK,MAAA,KAAW,MAAA,CAAO,MAAA,EAAQ,OAAO,CAAA;AAC1C,IAAA,MAAM,QAAQ,EAAE,IAAA,EAAM,CAAA,CAAE,IAAA,EAAM,QAAQ,IAAA,EAAK;AAC3C,IAAA,OAAO,IAAA,CAAK,OAAO,OAAA,EAAS,EAAE,MAAM,MAAA,EAAQ,IAAA,EAAM,KAAA,EAAM,EAAG,IAAI,CAAA;AAAA,EACjE;AAAA;AAAA,EAGA,MAAM,cAAA,CACJ,SAAA,EACA,IAAA,GAAoB,OAAA,EACY;AAChC,IAAA,OAAO,KAAK,IAAA,CAAK,EAAE,WAAA,EAAa,SAAA,IAAa,IAAI,CAAA;AAAA,EACnD;AACF;AAIO,IAAM,cAAA,GAAiB,EAAE,YAAA","file":"chunk-5MPL4XBD.js","sourcesContent":["import type { ClientContext, PaginatedItems } from \"../core/context\";\nimport { requestPage } from \"../core/paged\";\nimport type { AuthContext } from \"../core/auth\";\nimport { EmporixError, errorFromResponse } from \"../core/errors\";\nimport type {\n AssetCreateBlob,\n AssetCreateLink,\n AssetUpdateBlob,\n AssetUpdateLink,\n DownloadUrl,\n GetAsset,\n GetMediaRetrieveDownloadUrlData,\n PatchOperation,\n RefId,\n UploadSession,\n UploadSessionRequest,\n} from \"../generated/media\";\n\n/** Generated media types (caller sends the exact wire shape). */\nexport type AssetCreateBlobInput = AssetCreateBlob;\nexport type AssetCreateLinkInput = AssetCreateLink;\nexport type AssetUpdateBlobInput = AssetUpdateBlob;\nexport type AssetUpdateLinkInput = AssetUpdateLink;\nexport type AssetUpdateInput = AssetUpdateBlob | AssetUpdateLink;\nexport type Asset = GetAsset;\nexport type AssetRefId = RefId;\n/** Partial-update body (`PATCH /assets/{id}`) — an RFC-6902 JSON-Patch op-array. */\nexport type AssetPatch = PatchOperation[];\n/** Result of {@link MediaService.getDownloadUrl} — `{ provider, url, expiresAt? }`. */\nexport type AssetDownloadUrl = DownloadUrl;\n/** Query for {@link MediaService.getDownloadUrl} — `{ disposition? }`. */\nexport type AssetDownloadUrlQuery = NonNullable<GetMediaRetrieveDownloadUrlData[\"query\"]>;\n/** Body for {@link MediaService.startUploadSession}: a BLOB create payload plus `uploadType`. */\nexport type AssetUploadSessionInput = UploadSessionRequest;\n/** The storage instruction {@link MediaService.startUploadSession} returns. */\nexport type AssetUploadSession = UploadSession;\n\n/**\n * Filter / pagination options for {@link MediaService.list}. The explicit\n * fields are typed for autocomplete; the index signature stays open so\n * Emporix `q`-syntax filters like `\"refIds.id\"` can be passed verbatim.\n */\nexport interface ListAssetsQuery {\n pageNumber?: number;\n pageSize?: number;\n /** Emporix sort syntax, e.g. `\"name,metadata.createdAt:desc\"`. */\n sort?: string;\n /** Emporix `q`-syntax filter, e.g. `\"name:hero\"`. */\n q?: string;\n /**\n * Ask for `X-Total-Count`. An SDK-side flag, not an Emporix query parameter:\n * it becomes a request header.\n */\n totalCount?: boolean;\n [key: string]: string | number | boolean | undefined;\n}\n\n/**\n * Result of {@link MediaService.download}. The endpoint's behaviour depends\n * on the asset's `access`:\n * - `PUBLIC` assets respond with a 30x redirect whose `Location` header\n * carries the externally-cacheable storage URL — useful when the\n * storefront wants to send the user there directly.\n * - `PRIVATE` assets respond with the raw bytes (plus an `ETag` header\n * for caching). The file lives in Google Cloud Storage and is reachable\n * without the service token only through a signed URL from\n * {@link MediaService.getDownloadUrl}.\n */\nexport type DownloadResult =\n | { kind: \"redirect\"; url: string }\n | {\n kind: \"bytes\";\n data: ArrayBuffer;\n etag?: string;\n contentType?: string;\n };\n\nconst SERVICE: AuthContext = { kind: \"service\" };\n\nfunction isProductRef(r: AssetRefId, productId: string): boolean {\n return r.type === \"PRODUCT\" && r.id === productId;\n}\n\n/**\n * Media assets (BLOB/LINK). All endpoints require a backend-only scope\n * (`media.asset_manage` / `media.asset_read`) — default auth: service.\n */\nexport class MediaService {\n static readonly channel = \"media\" as const;\n constructor(private readonly ctx: ClientContext) {}\n\n private base(): string {\n return `/media/${this.ctx.tenant}/assets`;\n }\n\n /**\n * Create an asset. BLOB uploads via multipart (max 30 MB); LINK via JSON.\n * {@link startUploadSession} sends the file straight to storage instead.\n */\n async create(\n input:\n | { kind: \"blob\"; file: Blob; body: AssetCreateBlobInput }\n | { kind: \"link\"; body: AssetCreateLinkInput },\n auth: AuthContext = SERVICE,\n ): Promise<{ id: string }> {\n if (input.kind === \"blob\") {\n const fd = new FormData();\n fd.set(\"file\", input.file);\n fd.set(\"body\", JSON.stringify(input.body));\n return this.ctx.http.request<{ id: string }>({\n method: \"POST\",\n path: this.base(),\n auth,\n body: fd,\n });\n }\n return this.ctx.http.request<{ id: string }>({\n method: \"POST\",\n path: this.base(),\n auth,\n body: input.body,\n });\n }\n\n /**\n * List assets, wrapped in the shared {@link PaginatedItems} envelope so\n * callers can iterate over pages consistently with the rest of the SDK.\n * `hasNextPage` is the standard SDK heuristic: `true` when the returned\n * page is full (`items.length === requested pageSize`). Pagination\n * defaults match Emporix's server defaults (`pageNumber: 1`,\n * `pageSize: 60`) so an empty `query` produces stable expectations.\n */\n async list(\n query: ListAssetsQuery = {},\n auth: AuthContext = SERVICE,\n ): Promise<PaginatedItems<Asset>> {\n const pageNumber = query.pageNumber ?? 1;\n const pageSize = query.pageSize ?? 60;\n // Destructured out because the rest of `query` is spread into the query\n // string: `totalCount` is an SDK-side flag that becomes a request header,\n // and would otherwise ride along as a stray `?totalCount=true`.\n const { totalCount, ...rest } = query;\n return requestPage<Asset>(\n this.ctx.http,\n {\n method: \"GET\",\n path: this.base(),\n auth,\n query: { ...rest, pageNumber, pageSize },\n },\n { pageNumber, pageSize, ...(totalCount === undefined ? {} : { totalCount }) },\n );\n }\n\n /** Fetch an asset by id. */\n async get(assetId: string, auth: AuthContext = SERVICE): Promise<Asset> {\n return this.ctx.http.request<Asset>({\n method: \"GET\",\n path: `${this.base()}/${assetId}`,\n auth,\n });\n }\n\n /**\n * Update an asset. The input is a discriminated union mirroring\n * {@link create}:\n * - `{ kind: \"json\", body }` — metadata-only patch (BLOB or LINK).\n * Sends `application/json`. Used for `refIds`, `details`, `metadata`,\n * or `url` changes.\n * - `{ kind: \"blob\", file, body }` — replaces the BLOB file content\n * (max 30 MB) AND patches metadata in the same request. Sends\n * `multipart/form-data`.\n *\n * `type` and `access` are immutable per Emporix — they must match the\n * existing asset's values. Optimistic-locking is via `body.metadata.version`;\n * the server returns 409 Conflict on a stale version.\n */\n async update(\n assetId: string,\n input:\n | { kind: \"json\"; body: AssetUpdateInput }\n | { kind: \"blob\"; file: Blob; body: AssetUpdateBlobInput },\n auth: AuthContext = SERVICE,\n ): Promise<Asset> {\n if (input.kind === \"blob\") {\n const fd = new FormData();\n fd.set(\"file\", input.file);\n fd.set(\"body\", JSON.stringify(input.body));\n return this.ctx.http.request<Asset>({\n method: \"PUT\",\n path: `${this.base()}/${assetId}`,\n auth,\n body: fd,\n });\n }\n return this.ctx.http.request<Asset>({\n method: \"PUT\",\n path: `${this.base()}/${assetId}`,\n auth,\n body: input.body,\n });\n }\n\n /**\n * Partially update an asset with an RFC-6902 JSON-Patch op-array\n * (`PATCH /assets/{id}`, HTTP 204 — nothing is returned).\n *\n * This is the way to change one field without resending the whole asset, and\n * the only way to touch a `BLOB` asset's metadata **without re-uploading the\n * file** — {@link update} in `blob` mode always replaces the bytes.\n *\n * Append to an array with a path ending in `/-`, which preserves the existing\n * entries:\n *\n * ```ts\n * await client.media.patch(assetId, [\n * { op: \"add\", path: \"/refIds/-\", value: { id: \"product1\", type: \"PRODUCT\" } },\n * ]);\n * ```\n *\n * `type` and `access` are immutable here too, as with {@link update}. Only\n * `add`, `remove` and `replace` are accepted, and optimistic locking still\n * applies — a stale `metadata.version` gets a 409.\n */\n async patch(assetId: string, ops: AssetPatch, auth: AuthContext = SERVICE): Promise<void> {\n await this.ctx.http.request<void>({\n method: \"PATCH\",\n path: `${this.base()}/${encodeURIComponent(assetId)}`,\n auth,\n body: ops,\n });\n }\n\n /** Remove an asset. */\n async remove(assetId: string, auth: AuthContext = SERVICE): Promise<void> {\n await this.ctx.http.request<void>({\n method: \"DELETE\",\n path: `${this.base()}/${assetId}`,\n auth,\n });\n }\n\n /**\n * Download an asset by id. Returns a discriminated union:\n * - `{ kind: \"redirect\", url }` for `PUBLIC` assets (server-side 30x with\n * the storage URL in `Location`).\n * - `{ kind: \"bytes\", data }` for `PRIVATE` assets (server-side 200 with\n * the asset bytes; `etag` + `contentType` headers are exposed for\n * caching). When the server reports `text/plain` Content-Type (the\n * OpenAPI-documented format), the SDK decodes the base64 stream into\n * an `ArrayBuffer` transparently; binary Content-Types are passed\n * through verbatim.\n *\n * Emporix recommends {@link getDownloadUrl} for every download: here the file\n * passes through the Media API. A `413` means the asset's known size exceeds\n * the streaming limit (30 MB by default) — only {@link getDownloadUrl} can\n * serve it. A `409` means the asset is still `PENDING` from a direct upload\n * whose file has not reached storage.\n *\n * Implementation note: uses `redirect: \"manual\"` so the redirect-location\n * is observable. In Node.js this works; in a browser the redirect Location\n * is intentionally hidden by fetch — there, `PUBLIC` downloads will\n * surface as an opaque-redirect and the SDK throws. Browser code should\n * use the asset's `url` field from `get()` for `LINK` assets, or the\n * direct storage URL for `PUBLIC` `BLOB` assets (typically delivered via\n * an `<img>` tag rather than `download()`).\n */\n async download(\n assetId: string,\n auth: AuthContext = SERVICE,\n ): Promise<DownloadResult> {\n const path = `${this.base()}/${assetId}/download`;\n const res = await this.ctx.http.requestRaw(\n { method: \"GET\", path, auth },\n { redirect: \"manual\" },\n );\n\n // PUBLIC: server-side redirect — capture Location.\n if (res.status >= 300 && res.status < 400) {\n const url = res.headers.get(\"location\");\n if (!url) {\n throw new EmporixError(\n `media.download: ${res.status} response without a Location header`,\n res.status,\n );\n }\n return { kind: \"redirect\", url };\n }\n\n // PRIVATE: bytes.\n if (res.ok) {\n const etag = res.headers.get(\"etag\") ?? undefined;\n const contentType = res.headers.get(\"content-type\") ?? undefined;\n let data: ArrayBuffer;\n if (contentType?.startsWith(\"text/plain\")) {\n // Per OpenAPI spec the server returns the byte stream as a\n // base64-encoded text/plain body. Decode once into raw bytes\n // so callers always see an ArrayBuffer.\n const text = await res.text();\n const bin = atob(text);\n const arr = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) arr[i] = bin.charCodeAt(i);\n data = arr.buffer;\n } else {\n data = await res.arrayBuffer();\n }\n return {\n kind: \"bytes\",\n data,\n ...(etag !== undefined ? { etag } : {}),\n ...(contentType !== undefined ? { contentType } : {}),\n };\n }\n\n // Error: surface via the standard EmporixError hierarchy.\n const text = await res.text();\n let parsed: unknown = undefined;\n if (text) {\n try {\n parsed = JSON.parse(text);\n } catch {\n parsed = text;\n }\n }\n throw errorFromResponse(res.status, `GET ${path} → ${res.status}`, parsed);\n }\n\n /**\n * Get a URL that serves the stored file straight from storage\n * (`GET /assets/{assetId}/download-url`). Emporix recommends it for every\n * download: the file never passes through the Media API, there is no size\n * limit, and the URL can be handed to a browser as it is.\n *\n * - `PRIVATE` BLOB → `provider: \"GCS\"`, a signed Google Cloud Storage URL that\n * works without an Emporix token until `expiresAt` (15 minutes by default).\n * - `PUBLIC` BLOB → `provider: \"CLOUDINARY\"`, the permanent URL.\n * - `LINK` → `provider: \"LINK\"`, the stored URL.\n *\n * `disposition` (`attachment` by default, or `inline`) affects private URLs\n * only. Unlike {@link startUploadSession}, this works whether or not direct\n * upload is enabled for the tenant. A `409` means a direct upload is still\n * `PENDING` and its file has not reached storage; once it has, this call\n * completes the asset before answering.\n */\n async getDownloadUrl(\n assetId: string,\n query: AssetDownloadUrlQuery = {},\n auth: AuthContext = SERVICE,\n ): Promise<AssetDownloadUrl> {\n return this.ctx.http.request<AssetDownloadUrl>({\n method: \"GET\",\n path: `${this.base()}/${encodeURIComponent(assetId)}/download-url`,\n auth,\n query: { ...query },\n });\n }\n\n /**\n * Start a direct upload of a `BLOB` asset (`POST /assets/upload-session`,\n * `201`). Emporix creates the asset as `PENDING` — `id` is its id — and\n * returns where to send the file. **This method does not send it**:\n *\n * - `upload.method === \"PUT\"` (a `PRIVATE` asset, `uploadType: \"put\"` or\n * omitted): `PUT` the file to `upload.url` with every `upload.headers` entry.\n * - `upload.method === \"POST\"` (every `PUBLIC` asset, or `uploadType: \"form\"`):\n * a multipart `POST` to `upload.url` with every `upload.fields` entry\n * unchanged and the file part last.\n *\n * That request goes to Google Cloud Storage or Cloudinary, not to Emporix, so\n * it must not carry the Emporix token — which is also why a browser can make\n * it. The asset turns `READY` once storage confirms; until then, calls that\n * need the file answer `409`. The instruction is valid for 15 minutes (GCS) or\n * an hour (Cloudinary), and an unused session expires at `expiresAt`.\n *\n * Direct upload is enabled per tenant by Emporix Support. Without it the call\n * throws an `EmporixForbiddenError` whose `body.message` is `direct upload is\n * not enabled for this tenant`, and nothing is created — the same status as a\n * missing scope, so read the message.\n */\n async startUploadSession(\n input: AssetUploadSessionInput,\n auth: AuthContext = SERVICE,\n ): Promise<AssetUploadSession> {\n return this.ctx.http.request<AssetUploadSession>({\n method: \"POST\",\n path: `${this.base()}/upload-session`,\n auth,\n body: input,\n });\n }\n\n /** Multipart upload sugar: builds `AssetCreateBlob` from input. */\n async uploadFile(\n input: {\n file: Blob;\n productId?: string;\n filename?: string;\n mimeType?: string;\n access?: \"PUBLIC\" | \"PRIVATE\";\n },\n auth: AuthContext = SERVICE,\n ): Promise<{ id: string }> {\n const body: AssetCreateBlobInput = {\n type: \"BLOB\",\n access: input.access ?? \"PUBLIC\",\n ...(input.productId\n ? { refIds: [{ type: \"PRODUCT\", id: input.productId }] }\n : {}),\n ...(input.filename || input.mimeType\n ? {\n details: {\n ...(input.filename ? { filename: input.filename } : {}),\n ...(input.mimeType ? { mimeType: input.mimeType } : {}),\n },\n }\n : {}),\n };\n return this.create({ kind: \"blob\", file: input.file, body }, auth);\n }\n\n /**\n * Replace the file content of an existing BLOB asset. Sugar over\n * {@link update} with `kind: \"blob\"`. `access` is required because the\n * field is immutable and the server validates that the patch matches.\n * Pass `version` from `asset.metadata.version` if you want optimistic\n * locking (recommended when concurrent writers are possible).\n */\n async replaceFile(\n assetId: string,\n input: {\n file: Blob;\n access: \"PUBLIC\" | \"PRIVATE\";\n filename?: string;\n mimeType?: string;\n version?: number;\n },\n auth: AuthContext = SERVICE,\n ): Promise<Asset> {\n const body: AssetUpdateBlobInput = {\n type: \"BLOB\",\n access: input.access,\n ...(input.filename || input.mimeType\n ? {\n details: {\n ...(input.filename ? { filename: input.filename } : {}),\n ...(input.mimeType ? { mimeType: input.mimeType } : {}),\n },\n }\n : {}),\n ...(input.version !== undefined\n ? { metadata: { version: input.version } }\n : {}),\n };\n return this.update(assetId, { kind: \"blob\", file: input.file, body }, auth);\n }\n\n /** External-URL sugar: builds `AssetCreateLink`. */\n async link(\n input: { url: string; productId?: string; access?: \"PUBLIC\" | \"PRIVATE\" },\n auth: AuthContext = SERVICE,\n ): Promise<{ id: string }> {\n const body: AssetCreateLinkInput = {\n type: \"LINK\",\n access: input.access ?? \"PUBLIC\",\n url: input.url,\n ...(input.productId\n ? { refIds: [{ type: \"PRODUCT\", id: input.productId }] }\n : {}),\n };\n return this.create({ kind: \"link\", body }, auth);\n }\n\n /** Idempotently add a PRODUCT refId to an asset. */\n async attachToProduct(\n assetId: string,\n productId: string,\n auth: AuthContext = SERVICE,\n ): Promise<Asset> {\n const a = await this.get(assetId, auth);\n const refIds: AssetRefId[] = a.refIds ?? [];\n if (refIds.some((r) => isProductRef(r, productId))) return a;\n const next: AssetRefId[] = [...refIds, { type: \"PRODUCT\", id: productId }];\n // Preserve the asset's type discriminator so the update body satisfies\n // the AssetUpdateBlob | AssetUpdateLink union.\n const patch = { type: a.type, refIds: next } as unknown as AssetUpdateInput;\n return this.update(assetId, { kind: \"json\", body: patch }, auth);\n }\n\n /** Remove a PRODUCT refId from an asset (no-op if absent). */\n async detachFromProduct(\n assetId: string,\n productId: string,\n auth: AuthContext = SERVICE,\n ): Promise<Asset> {\n const a = await this.get(assetId, auth);\n const refIds: AssetRefId[] = a.refIds ?? [];\n const next = refIds.filter((r) => !isProductRef(r, productId));\n if (next.length === refIds.length) return a;\n const patch = { type: a.type, refIds: next } as unknown as AssetUpdateInput;\n return this.update(assetId, { kind: \"json\", body: patch }, auth);\n }\n\n /** Convenience: list assets attached to a product (server-side filter). */\n async listForProduct(\n productId: string,\n auth: AuthContext = SERVICE,\n ): Promise<PaginatedItems<Asset>> {\n return this.list({ \"refIds.id\": productId }, auth);\n }\n}\n\n// Re-export so consumers can `import { isProductRef } from \"@viu/emporix-sdk/media\"`?\n// Internal helper — kept module-private; convenience methods in Task 4 use it.\nexport const _internalMedia = { isProductRef };\n"]}
|
|
@@ -60,6 +60,20 @@ var OrdersService = class {
|
|
|
60
60
|
...headers ? { headers } : {}
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* The status transitions the customer may trigger on one of their orders
|
|
65
|
+
* (`GET /orders/{orderId}/transitions`) — for example whether it can still be
|
|
66
|
+
* cancelled, before offering {@link cancel}.
|
|
67
|
+
*/
|
|
68
|
+
async listTransitions(orderId, auth, opts = {}) {
|
|
69
|
+
const headers = this.saasHeader(opts.saasToken);
|
|
70
|
+
return this.ctx.http.request({
|
|
71
|
+
method: "GET",
|
|
72
|
+
path: `${this.base()}/${encodeURIComponent(orderId)}/transitions`,
|
|
73
|
+
auth,
|
|
74
|
+
...headers ? { headers } : {}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
63
77
|
/** Transitions an order to a new status. Server enforces legal transitions. */
|
|
64
78
|
async transition(orderId, status, auth, opts = {}) {
|
|
65
79
|
const body = { status };
|
|
@@ -282,5 +296,5 @@ var SalesOrdersService = class {
|
|
|
282
296
|
};
|
|
283
297
|
|
|
284
298
|
export { OrdersService, SalesOrdersService };
|
|
285
|
-
//# sourceMappingURL=chunk-
|
|
286
|
-
//# sourceMappingURL=chunk-
|
|
299
|
+
//# sourceMappingURL=chunk-IYNT5BQW.js.map
|
|
300
|
+
//# sourceMappingURL=chunk-IYNT5BQW.js.map
|