@flexops/sdk 3.3.0 → 3.4.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/README.md +22 -2
- package/dist/index.d.mts +201 -42
- package/dist/index.d.ts +201 -42
- package/dist/index.js +119 -41
- package/dist/index.mjs +119 -41
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -220,8 +220,8 @@ var HttpClient = class {
|
|
|
220
220
|
async patch(path, body) {
|
|
221
221
|
return this.request("PATCH", path, { body });
|
|
222
222
|
}
|
|
223
|
-
async delete(path) {
|
|
224
|
-
return this.request("DELETE", path);
|
|
223
|
+
async delete(path, query) {
|
|
224
|
+
return this.request("DELETE", path, { query });
|
|
225
225
|
}
|
|
226
226
|
buildUrl(path, query) {
|
|
227
227
|
const url = new URL(path.startsWith("/") ? path : `/${path}`, this.baseUrl);
|
|
@@ -337,15 +337,15 @@ var WorkspacesResource = class {
|
|
|
337
337
|
async listMembers() {
|
|
338
338
|
return this.http.get(this.wsPath("members"));
|
|
339
339
|
}
|
|
340
|
-
/** Invite a user to the workspace. */
|
|
340
|
+
/** Invite a user to the workspace. Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes. */
|
|
341
341
|
async inviteMember(email, role = WorkspaceRole.Member) {
|
|
342
342
|
return this.http.post(this.wsPath("members/invite"), { email, role });
|
|
343
343
|
}
|
|
344
|
-
/** Remove a member from the workspace. */
|
|
344
|
+
/** Remove a member from the workspace. Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes. */
|
|
345
345
|
async removeMember(userId) {
|
|
346
346
|
return this.http.delete(this.wsPath(`members/${userId}`));
|
|
347
347
|
}
|
|
348
|
-
/** Change a member's role. */
|
|
348
|
+
/** Change a member's role. Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes. */
|
|
349
349
|
async updateMemberRole(userId, role) {
|
|
350
350
|
return this.http.put(this.wsPath(`members/${userId}/role`), { newRole: role });
|
|
351
351
|
}
|
|
@@ -626,19 +626,27 @@ var CarriersResource = class {
|
|
|
626
626
|
/**
|
|
627
627
|
* Cancel a domestic label.
|
|
628
628
|
*
|
|
629
|
+
* @param trackingNumber The label's tracking number.
|
|
629
630
|
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
630
631
|
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
631
632
|
* cover this.
|
|
632
633
|
*/
|
|
633
|
-
cancelDomesticLabel: () =>
|
|
634
|
+
cancelDomesticLabel: (trackingNumber) => {
|
|
635
|
+
if (!trackingNumber?.trim()) throw new Error("trackingNumber is required.");
|
|
636
|
+
return this.http.delete(this.proxy("api/v3/Shipping/cancelUspsDomesticShipmentLabel"), { trackingNumber });
|
|
637
|
+
},
|
|
634
638
|
/**
|
|
635
639
|
* Cancel an international label.
|
|
636
640
|
*
|
|
641
|
+
* @param internationalTrackingNumber The label's international tracking number.
|
|
637
642
|
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
638
643
|
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
639
644
|
* cover this.
|
|
640
645
|
*/
|
|
641
|
-
cancelInternationalLabel: () =>
|
|
646
|
+
cancelInternationalLabel: (internationalTrackingNumber) => {
|
|
647
|
+
if (!internationalTrackingNumber?.trim()) throw new Error("internationalTrackingNumber is required.");
|
|
648
|
+
return this.http.delete(this.proxy("api/v3/Shipping/cancelUspsInternationalShipmentLabel"), { internationalTrackingNumber });
|
|
649
|
+
},
|
|
642
650
|
/** Get tracking summary. */
|
|
643
651
|
trackSummary: (params) => this.http.get(this.proxy("api/v3/Tracking/getUspsTrackingSummaryInformation"), params),
|
|
644
652
|
/** Get detailed tracking info. */
|
|
@@ -654,11 +662,15 @@ var CarriersResource = class {
|
|
|
654
662
|
/**
|
|
655
663
|
* Cancel a pickup.
|
|
656
664
|
*
|
|
665
|
+
* @param confirmationNumber The pickup's confirmation number.
|
|
657
666
|
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
658
667
|
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
659
668
|
* cover this.
|
|
660
669
|
*/
|
|
661
|
-
cancelPickup: () =>
|
|
670
|
+
cancelPickup: (confirmationNumber) => {
|
|
671
|
+
if (!confirmationNumber?.trim()) throw new Error("confirmationNumber is required.");
|
|
672
|
+
return this.http.delete(this.proxy("api/v3/CarrierPickup/cancelUspsCarrierPickupSchedule"), { confirmationNumber });
|
|
673
|
+
},
|
|
662
674
|
/**
|
|
663
675
|
* Create a scan form.
|
|
664
676
|
*
|
|
@@ -1003,14 +1015,23 @@ var WebhooksResource = class {
|
|
|
1003
1015
|
if (!id) throw new Error("workspaceId is required.");
|
|
1004
1016
|
return `/api/workspaces/${id}/webhooks${suffix ? `/${suffix}` : ""}`;
|
|
1005
1017
|
}
|
|
1006
|
-
/**
|
|
1018
|
+
/**
|
|
1019
|
+
* List all webhook subscriptions for the workspace.
|
|
1020
|
+
*
|
|
1021
|
+
* Needs a signed-in user's access token. Reads are signed-in only, like the writes, because webhook
|
|
1022
|
+
* delivery logs carry each delivery's payload (order and customer data).
|
|
1023
|
+
* @throws FlexOpsError (`403`, `SIGNED_IN_USER_REQUIRED`) when the client authenticates with an API key.
|
|
1024
|
+
*/
|
|
1007
1025
|
async list() {
|
|
1008
1026
|
return this.http.get(this.wsPath(""));
|
|
1009
1027
|
}
|
|
1010
1028
|
/**
|
|
1011
1029
|
* Create a webhook subscription. `events` is sent as the Gateway's comma-separated `eventTypes`;
|
|
1012
1030
|
* omit it to receive every event. The result's `data.secret` is the signing secret, returned only here.
|
|
1031
|
+
*
|
|
1032
|
+
* Needs a signed-in user's access token.
|
|
1013
1033
|
* @throws FlexOpsError (`UnknownWebhookEvent`) when `events` is empty or names an event FlexOps does not send.
|
|
1034
|
+
* @throws FlexOpsError (`403`, `SIGNED_IN_USER_REQUIRED`) when the client authenticates with an API key.
|
|
1014
1035
|
*/
|
|
1015
1036
|
async create(request) {
|
|
1016
1037
|
const body = await this.http.post(this.wsPath(""), toWireRequest(request));
|
|
@@ -1018,24 +1039,48 @@ var WebhooksResource = class {
|
|
|
1018
1039
|
}
|
|
1019
1040
|
/**
|
|
1020
1041
|
* Update a webhook subscription. `events`, when given, replaces the subscribed events.
|
|
1042
|
+
*
|
|
1043
|
+
* Needs a signed-in user's access token.
|
|
1021
1044
|
* @throws FlexOpsError (`UnknownWebhookEvent`) when `events` is empty or names an event FlexOps does not send.
|
|
1045
|
+
* @throws FlexOpsError (`403`, `SIGNED_IN_USER_REQUIRED`) when the client authenticates with an API key.
|
|
1022
1046
|
*/
|
|
1023
1047
|
async update(webhookId, data) {
|
|
1024
1048
|
return this.http.put(this.wsPath(webhookId), toWireRequest(data));
|
|
1025
1049
|
}
|
|
1026
|
-
/**
|
|
1050
|
+
/**
|
|
1051
|
+
* Delete a webhook subscription. The Gateway answers 204 No Content, so there is no result.
|
|
1052
|
+
*
|
|
1053
|
+
* Needs a signed-in user's access token.
|
|
1054
|
+
* @throws FlexOpsError (`403`, `SIGNED_IN_USER_REQUIRED`) when the client authenticates with an API key.
|
|
1055
|
+
*/
|
|
1027
1056
|
async delete(webhookId) {
|
|
1028
1057
|
await this.http.delete(this.wsPath(webhookId));
|
|
1029
1058
|
}
|
|
1030
|
-
/**
|
|
1059
|
+
/**
|
|
1060
|
+
* Rotate the signing secret for a webhook.
|
|
1061
|
+
*
|
|
1062
|
+
* Needs a signed-in user's access token.
|
|
1063
|
+
* @throws FlexOpsError (`403`, `SIGNED_IN_USER_REQUIRED`) when the client authenticates with an API key.
|
|
1064
|
+
*/
|
|
1031
1065
|
async rotateSecret(webhookId) {
|
|
1032
1066
|
return this.http.post(this.wsPath(`${webhookId}/rotate-secret`));
|
|
1033
1067
|
}
|
|
1034
|
-
/**
|
|
1068
|
+
/**
|
|
1069
|
+
* List delivery logs for a webhook.
|
|
1070
|
+
*
|
|
1071
|
+
* Needs a signed-in user's access token. Reads are signed-in only, like the writes, because webhook
|
|
1072
|
+
* delivery logs carry each delivery's payload (order and customer data).
|
|
1073
|
+
* @throws FlexOpsError (`403`, `SIGNED_IN_USER_REQUIRED`) when the client authenticates with an API key.
|
|
1074
|
+
*/
|
|
1035
1075
|
async listDeliveryLogs(webhookId) {
|
|
1036
1076
|
return this.http.get(this.wsPath(`${webhookId}/deliveries`));
|
|
1037
1077
|
}
|
|
1038
|
-
/**
|
|
1078
|
+
/**
|
|
1079
|
+
* Send a test event to a webhook's endpoint.
|
|
1080
|
+
*
|
|
1081
|
+
* Needs a signed-in user's access token.
|
|
1082
|
+
* @throws FlexOpsError (`403`, `SIGNED_IN_USER_REQUIRED`) when the client authenticates with an API key.
|
|
1083
|
+
*/
|
|
1039
1084
|
async test(webhookId) {
|
|
1040
1085
|
return this.http.post(this.wsPath(`${webhookId}/test`));
|
|
1041
1086
|
}
|
|
@@ -1239,63 +1284,63 @@ var AnalyticsResource = class {
|
|
|
1239
1284
|
path(endpoint) {
|
|
1240
1285
|
return `/api/ApiProxy/api/v4/Analytics/${endpoint}`;
|
|
1241
1286
|
}
|
|
1242
|
-
/** Shipments trend over time. */
|
|
1287
|
+
/** Shipments trend over time. With an API key, requires `shipping:read`. */
|
|
1243
1288
|
async shipmentsTrend(params) {
|
|
1244
1289
|
return this.http.get(this.path("ShipmentsTrend"), params);
|
|
1245
1290
|
}
|
|
1246
|
-
/** Carrier usage summary. */
|
|
1291
|
+
/** Carrier usage summary. With an API key, requires `shipping:read`. */
|
|
1247
1292
|
async carrierSummary(params) {
|
|
1248
1293
|
return this.http.get(this.path("CarrierSummary"), params);
|
|
1249
1294
|
}
|
|
1250
|
-
/** Top shipping destinations. */
|
|
1295
|
+
/** Top shipping destinations. With an API key, requires `shipping:read`. */
|
|
1251
1296
|
async topDestinations(params) {
|
|
1252
1297
|
return this.http.get(this.path("TopDestinations"), params);
|
|
1253
1298
|
}
|
|
1254
|
-
/** Inventory metrics (stock levels, low-stock alerts). */
|
|
1299
|
+
/** Inventory metrics (stock levels, low-stock alerts). With an API key, requires `inventory:read`. */
|
|
1255
1300
|
async inventoryMetrics() {
|
|
1256
1301
|
return this.http.get(this.path("InventoryMetrics"));
|
|
1257
1302
|
}
|
|
1258
|
-
/** Stock levels by warehouse. */
|
|
1303
|
+
/** Stock levels by warehouse. With an API key, requires `inventory:read`. */
|
|
1259
1304
|
async stockByWarehouse() {
|
|
1260
1305
|
return this.http.get(this.path("StockByWarehouse"));
|
|
1261
1306
|
}
|
|
1262
|
-
/** Order metrics (volume, revenue). */
|
|
1307
|
+
/** Order metrics (volume, revenue). With an API key, requires `orders:read`. */
|
|
1263
1308
|
async orderMetrics(params) {
|
|
1264
1309
|
return this.http.get(this.path("OrderMetrics"), params);
|
|
1265
1310
|
}
|
|
1266
|
-
/** Order trend over time. */
|
|
1311
|
+
/** Order trend over time. With an API key, requires `orders:read`. */
|
|
1267
1312
|
async orderTrend(params) {
|
|
1268
1313
|
return this.http.get(this.path("OrderTrend"), params);
|
|
1269
1314
|
}
|
|
1270
|
-
/** Top selling products. */
|
|
1315
|
+
/** Top selling products. With an API key, requires `orders:read`. */
|
|
1271
1316
|
async topSellingProducts(params) {
|
|
1272
1317
|
return this.http.get(this.path("TopSellingProducts"), params);
|
|
1273
1318
|
}
|
|
1274
|
-
/** Returns metrics. */
|
|
1319
|
+
/** Returns metrics. With an API key, requires `returns:read`. */
|
|
1275
1320
|
async returnsMetrics(params) {
|
|
1276
1321
|
return this.http.get(this.path("ReturnsMetrics"), params);
|
|
1277
1322
|
}
|
|
1278
|
-
/** Returns trend over time. */
|
|
1323
|
+
/** Returns trend over time. With an API key, requires `returns:read`. */
|
|
1279
1324
|
async returnsTrend(params) {
|
|
1280
1325
|
return this.http.get(this.path("ReturnsTrend"), params);
|
|
1281
1326
|
}
|
|
1282
|
-
/** Return reasons breakdown. */
|
|
1327
|
+
/** Return reasons breakdown. With an API key, requires `returns:read`. */
|
|
1283
1328
|
async returnReasons(params) {
|
|
1284
1329
|
return this.http.get(this.path("ReturnReasons"), params);
|
|
1285
1330
|
}
|
|
1286
|
-
/** Fulfillment performance metrics. */
|
|
1331
|
+
/** Fulfillment performance metrics. With an API key, requires `shipping:read`. */
|
|
1287
1332
|
async performanceMetrics(params) {
|
|
1288
1333
|
return this.http.get(this.path("PerformanceMetrics"), params);
|
|
1289
1334
|
}
|
|
1290
|
-
/** Carrier delivery performance. */
|
|
1335
|
+
/** Carrier delivery performance. With an API key, requires `shipping:read`. */
|
|
1291
1336
|
async carrierPerformance(params) {
|
|
1292
1337
|
return this.http.get(this.path("CarrierPerformance"), params);
|
|
1293
1338
|
}
|
|
1294
|
-
/** Shipping cost analytics. */
|
|
1339
|
+
/** Shipping cost analytics. With an API key, requires `shipping:read`. */
|
|
1295
1340
|
async shippingCostAnalytics(params) {
|
|
1296
1341
|
return this.http.get(this.path("ShippingCostAnalytics"), params);
|
|
1297
1342
|
}
|
|
1298
|
-
/** Delivery performance (on-time %). */
|
|
1343
|
+
/** Delivery performance (on-time %). With an API key, requires `shipping:read`. */
|
|
1299
1344
|
async deliveryPerformance(params) {
|
|
1300
1345
|
return this.http.get(this.path("DeliveryPerformance"), params);
|
|
1301
1346
|
}
|
|
@@ -1385,7 +1430,7 @@ var PickupsResource = class {
|
|
|
1385
1430
|
if (!id) throw new Error("workspaceId is required.");
|
|
1386
1431
|
return `/api/workspaces/${id}/pickups${suffix ? `/${suffix}` : ""}`;
|
|
1387
1432
|
}
|
|
1388
|
-
/** Schedule a carrier pickup. */
|
|
1433
|
+
/** Schedule a carrier pickup. API keys need `shipping:write`; the public demo keys are refused. */
|
|
1389
1434
|
async schedule(request) {
|
|
1390
1435
|
return this.http.post(this.wsPath(""), request);
|
|
1391
1436
|
}
|
|
@@ -1397,7 +1442,7 @@ var PickupsResource = class {
|
|
|
1397
1442
|
async get(pickupId, carrierCode) {
|
|
1398
1443
|
return this.http.get(this.wsPath(pickupId), { carrierCode });
|
|
1399
1444
|
}
|
|
1400
|
-
/** Cancel a scheduled pickup. */
|
|
1445
|
+
/** Cancel a scheduled pickup. API keys need `shipping:write`; the public demo keys are refused. */
|
|
1401
1446
|
async cancel(pickupId) {
|
|
1402
1447
|
return this.http.delete(this.wsPath(pickupId));
|
|
1403
1448
|
}
|
|
@@ -1416,19 +1461,42 @@ var ScanFormsResource = class {
|
|
|
1416
1461
|
if (!id) throw new Error("workspaceId is required.");
|
|
1417
1462
|
return `/api/workspaces/${id}/scan-forms${suffix ? `/${suffix}` : ""}`;
|
|
1418
1463
|
}
|
|
1419
|
-
/**
|
|
1464
|
+
/**
|
|
1465
|
+
* Create a USPS scan form (SCAN/manifest). API keys need `shipping:write`; the public demo keys are refused.
|
|
1466
|
+
* Sends `request.requestId`, or a UUID generated for this call, on every attempt, so a retried call replays
|
|
1467
|
+
* the same operation instead of creating a second form.
|
|
1468
|
+
*
|
|
1469
|
+
* Resolves with the created form (200), also when the same `requestId` and inputs are sent again. Rejects with a
|
|
1470
|
+
* 409 {@link FlexOpsError} when the `requestId` was used with different inputs, when the packages already belong
|
|
1471
|
+
* to a manifest, or when this or an earlier operation needs review (its message names the operation; do not
|
|
1472
|
+
* resubmit those packages). 400 means the request or package selection was refused.
|
|
1473
|
+
*/
|
|
1420
1474
|
async create(request) {
|
|
1421
|
-
|
|
1475
|
+
const response = await this.http.post(
|
|
1476
|
+
this.wsPath(""),
|
|
1477
|
+
{ ...request, requestId: request.requestId ?? randomUuid() }
|
|
1478
|
+
);
|
|
1479
|
+
return withAliases(response);
|
|
1422
1480
|
}
|
|
1423
|
-
/** List scan forms. */
|
|
1481
|
+
/** List the workspace's saved scan forms, newest mailing date first, including any whose outcome is unknown. */
|
|
1424
1482
|
async list() {
|
|
1425
|
-
return this.http.get(this.wsPath(""));
|
|
1483
|
+
return withAliases(await this.http.get(this.wsPath("")));
|
|
1426
1484
|
}
|
|
1427
|
-
/** Get a scan form by
|
|
1485
|
+
/** Get a saved scan form by its `scanFormId`. A form that does not exist rejects with a 404 {@link FlexOpsError}. */
|
|
1428
1486
|
async get(scanFormId) {
|
|
1429
|
-
return this.http.get(this.wsPath(scanFormId));
|
|
1487
|
+
return withAliases(await this.http.get(this.wsPath(scanFormId)));
|
|
1430
1488
|
}
|
|
1431
1489
|
};
|
|
1490
|
+
function withAliases(response) {
|
|
1491
|
+
const forms = Array.isArray(response?.data) ? response.data : response?.data ? [response.data] : [];
|
|
1492
|
+
for (const form of forms) {
|
|
1493
|
+
if (form && typeof form === "object") {
|
|
1494
|
+
if (form.formData === void 0 && typeof form.scanFormImage === "string") form.formData = form.scanFormImage;
|
|
1495
|
+
if (form.createdAt === void 0 && typeof form.createdAtUtc === "string") form.createdAt = form.createdAtUtc;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
return response;
|
|
1499
|
+
}
|
|
1432
1500
|
|
|
1433
1501
|
// src/resources/rules.ts
|
|
1434
1502
|
var RulesResource = class {
|
|
@@ -1451,25 +1519,34 @@ var RulesResource = class {
|
|
|
1451
1519
|
async get(ruleId) {
|
|
1452
1520
|
return this.http.get(this.wsPath(ruleId));
|
|
1453
1521
|
}
|
|
1454
|
-
/** Create a shipping rule. */
|
|
1522
|
+
/** Create a shipping rule. Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes. */
|
|
1455
1523
|
async create(rule) {
|
|
1456
1524
|
return this.http.post(this.wsPath(""), rule);
|
|
1457
1525
|
}
|
|
1458
|
-
/** Replace a shipping rule. */
|
|
1526
|
+
/** Replace a shipping rule. Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes. */
|
|
1459
1527
|
async update(ruleId, rule) {
|
|
1460
1528
|
return this.http.put(this.wsPath(ruleId), rule);
|
|
1461
1529
|
}
|
|
1462
|
-
/**
|
|
1530
|
+
/**
|
|
1531
|
+
* Delete a shipping rule. The Gateway answers 204 No Content, so there is no result.
|
|
1532
|
+
* Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes.
|
|
1533
|
+
*/
|
|
1463
1534
|
async delete(ruleId) {
|
|
1464
1535
|
await this.http.delete(this.wsPath(ruleId));
|
|
1465
1536
|
}
|
|
1466
|
-
/**
|
|
1537
|
+
/**
|
|
1538
|
+
* Reorder rules: each listed rule gets its position in `ruleIds` as its priority (0 first).
|
|
1539
|
+
* Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes.
|
|
1540
|
+
*/
|
|
1467
1541
|
async reorder(ruleIds) {
|
|
1468
1542
|
return this.http.post(this.wsPath("reorder"), {
|
|
1469
1543
|
rules: ruleIds.map((ruleId, priority) => ({ ruleId, priority }))
|
|
1470
1544
|
});
|
|
1471
1545
|
}
|
|
1472
|
-
/**
|
|
1546
|
+
/**
|
|
1547
|
+
* Dry-run the workspace's rules against a sample shipment, without changing anything.
|
|
1548
|
+
* API keys need `shipping:read`; the public demo keys are refused.
|
|
1549
|
+
*/
|
|
1473
1550
|
async test(request) {
|
|
1474
1551
|
return this.http.post(this.wsPath("test"), { tags: [], ...request });
|
|
1475
1552
|
}
|
|
@@ -1683,6 +1760,7 @@ var FlexOps = class {
|
|
|
1683
1760
|
workspaces;
|
|
1684
1761
|
shipping;
|
|
1685
1762
|
carriers;
|
|
1763
|
+
/** Webhook subscriptions. Needs a signed-in user's access token; API keys get `403` `SIGNED_IN_USER_REQUIRED`. */
|
|
1686
1764
|
webhooks;
|
|
1687
1765
|
wallet;
|
|
1688
1766
|
insurance;
|
package/package.json
CHANGED