@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.js
CHANGED
|
@@ -268,8 +268,8 @@ var HttpClient = class {
|
|
|
268
268
|
async patch(path, body) {
|
|
269
269
|
return this.request("PATCH", path, { body });
|
|
270
270
|
}
|
|
271
|
-
async delete(path) {
|
|
272
|
-
return this.request("DELETE", path);
|
|
271
|
+
async delete(path, query) {
|
|
272
|
+
return this.request("DELETE", path, { query });
|
|
273
273
|
}
|
|
274
274
|
buildUrl(path, query) {
|
|
275
275
|
const url = new URL(path.startsWith("/") ? path : `/${path}`, this.baseUrl);
|
|
@@ -385,15 +385,15 @@ var WorkspacesResource = class {
|
|
|
385
385
|
async listMembers() {
|
|
386
386
|
return this.http.get(this.wsPath("members"));
|
|
387
387
|
}
|
|
388
|
-
/** Invite a user to the workspace. */
|
|
388
|
+
/** Invite a user to the workspace. Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes. */
|
|
389
389
|
async inviteMember(email, role = WorkspaceRole.Member) {
|
|
390
390
|
return this.http.post(this.wsPath("members/invite"), { email, role });
|
|
391
391
|
}
|
|
392
|
-
/** Remove a member from the workspace. */
|
|
392
|
+
/** Remove a member from the workspace. Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes. */
|
|
393
393
|
async removeMember(userId) {
|
|
394
394
|
return this.http.delete(this.wsPath(`members/${userId}`));
|
|
395
395
|
}
|
|
396
|
-
/** Change a member's role. */
|
|
396
|
+
/** Change a member's role. Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes. */
|
|
397
397
|
async updateMemberRole(userId, role) {
|
|
398
398
|
return this.http.put(this.wsPath(`members/${userId}/role`), { newRole: role });
|
|
399
399
|
}
|
|
@@ -674,19 +674,27 @@ var CarriersResource = class {
|
|
|
674
674
|
/**
|
|
675
675
|
* Cancel a domestic label.
|
|
676
676
|
*
|
|
677
|
+
* @param trackingNumber The label's tracking number.
|
|
677
678
|
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
678
679
|
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
679
680
|
* cover this.
|
|
680
681
|
*/
|
|
681
|
-
cancelDomesticLabel: () =>
|
|
682
|
+
cancelDomesticLabel: (trackingNumber) => {
|
|
683
|
+
if (!trackingNumber?.trim()) throw new Error("trackingNumber is required.");
|
|
684
|
+
return this.http.delete(this.proxy("api/v3/Shipping/cancelUspsDomesticShipmentLabel"), { trackingNumber });
|
|
685
|
+
},
|
|
682
686
|
/**
|
|
683
687
|
* Cancel an international label.
|
|
684
688
|
*
|
|
689
|
+
* @param internationalTrackingNumber The label's international tracking number.
|
|
685
690
|
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
686
691
|
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
687
692
|
* cover this.
|
|
688
693
|
*/
|
|
689
|
-
cancelInternationalLabel: () =>
|
|
694
|
+
cancelInternationalLabel: (internationalTrackingNumber) => {
|
|
695
|
+
if (!internationalTrackingNumber?.trim()) throw new Error("internationalTrackingNumber is required.");
|
|
696
|
+
return this.http.delete(this.proxy("api/v3/Shipping/cancelUspsInternationalShipmentLabel"), { internationalTrackingNumber });
|
|
697
|
+
},
|
|
690
698
|
/** Get tracking summary. */
|
|
691
699
|
trackSummary: (params) => this.http.get(this.proxy("api/v3/Tracking/getUspsTrackingSummaryInformation"), params),
|
|
692
700
|
/** Get detailed tracking info. */
|
|
@@ -702,11 +710,15 @@ var CarriersResource = class {
|
|
|
702
710
|
/**
|
|
703
711
|
* Cancel a pickup.
|
|
704
712
|
*
|
|
713
|
+
* @param confirmationNumber The pickup's confirmation number.
|
|
705
714
|
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
706
715
|
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
707
716
|
* cover this.
|
|
708
717
|
*/
|
|
709
|
-
cancelPickup: () =>
|
|
718
|
+
cancelPickup: (confirmationNumber) => {
|
|
719
|
+
if (!confirmationNumber?.trim()) throw new Error("confirmationNumber is required.");
|
|
720
|
+
return this.http.delete(this.proxy("api/v3/CarrierPickup/cancelUspsCarrierPickupSchedule"), { confirmationNumber });
|
|
721
|
+
},
|
|
710
722
|
/**
|
|
711
723
|
* Create a scan form.
|
|
712
724
|
*
|
|
@@ -1051,14 +1063,23 @@ var WebhooksResource = class {
|
|
|
1051
1063
|
if (!id) throw new Error("workspaceId is required.");
|
|
1052
1064
|
return `/api/workspaces/${id}/webhooks${suffix ? `/${suffix}` : ""}`;
|
|
1053
1065
|
}
|
|
1054
|
-
/**
|
|
1066
|
+
/**
|
|
1067
|
+
* List all webhook subscriptions for the workspace.
|
|
1068
|
+
*
|
|
1069
|
+
* Needs a signed-in user's access token. Reads are signed-in only, like the writes, because webhook
|
|
1070
|
+
* delivery logs carry each delivery's payload (order and customer data).
|
|
1071
|
+
* @throws FlexOpsError (`403`, `SIGNED_IN_USER_REQUIRED`) when the client authenticates with an API key.
|
|
1072
|
+
*/
|
|
1055
1073
|
async list() {
|
|
1056
1074
|
return this.http.get(this.wsPath(""));
|
|
1057
1075
|
}
|
|
1058
1076
|
/**
|
|
1059
1077
|
* Create a webhook subscription. `events` is sent as the Gateway's comma-separated `eventTypes`;
|
|
1060
1078
|
* omit it to receive every event. The result's `data.secret` is the signing secret, returned only here.
|
|
1079
|
+
*
|
|
1080
|
+
* Needs a signed-in user's access token.
|
|
1061
1081
|
* @throws FlexOpsError (`UnknownWebhookEvent`) when `events` is empty or names an event FlexOps does not send.
|
|
1082
|
+
* @throws FlexOpsError (`403`, `SIGNED_IN_USER_REQUIRED`) when the client authenticates with an API key.
|
|
1062
1083
|
*/
|
|
1063
1084
|
async create(request) {
|
|
1064
1085
|
const body = await this.http.post(this.wsPath(""), toWireRequest(request));
|
|
@@ -1066,24 +1087,48 @@ var WebhooksResource = class {
|
|
|
1066
1087
|
}
|
|
1067
1088
|
/**
|
|
1068
1089
|
* Update a webhook subscription. `events`, when given, replaces the subscribed events.
|
|
1090
|
+
*
|
|
1091
|
+
* Needs a signed-in user's access token.
|
|
1069
1092
|
* @throws FlexOpsError (`UnknownWebhookEvent`) when `events` is empty or names an event FlexOps does not send.
|
|
1093
|
+
* @throws FlexOpsError (`403`, `SIGNED_IN_USER_REQUIRED`) when the client authenticates with an API key.
|
|
1070
1094
|
*/
|
|
1071
1095
|
async update(webhookId, data) {
|
|
1072
1096
|
return this.http.put(this.wsPath(webhookId), toWireRequest(data));
|
|
1073
1097
|
}
|
|
1074
|
-
/**
|
|
1098
|
+
/**
|
|
1099
|
+
* Delete a webhook subscription. The Gateway answers 204 No Content, so there is no result.
|
|
1100
|
+
*
|
|
1101
|
+
* Needs a signed-in user's access token.
|
|
1102
|
+
* @throws FlexOpsError (`403`, `SIGNED_IN_USER_REQUIRED`) when the client authenticates with an API key.
|
|
1103
|
+
*/
|
|
1075
1104
|
async delete(webhookId) {
|
|
1076
1105
|
await this.http.delete(this.wsPath(webhookId));
|
|
1077
1106
|
}
|
|
1078
|
-
/**
|
|
1107
|
+
/**
|
|
1108
|
+
* Rotate the signing secret for a webhook.
|
|
1109
|
+
*
|
|
1110
|
+
* Needs a signed-in user's access token.
|
|
1111
|
+
* @throws FlexOpsError (`403`, `SIGNED_IN_USER_REQUIRED`) when the client authenticates with an API key.
|
|
1112
|
+
*/
|
|
1079
1113
|
async rotateSecret(webhookId) {
|
|
1080
1114
|
return this.http.post(this.wsPath(`${webhookId}/rotate-secret`));
|
|
1081
1115
|
}
|
|
1082
|
-
/**
|
|
1116
|
+
/**
|
|
1117
|
+
* List delivery logs for a webhook.
|
|
1118
|
+
*
|
|
1119
|
+
* Needs a signed-in user's access token. Reads are signed-in only, like the writes, because webhook
|
|
1120
|
+
* delivery logs carry each delivery's payload (order and customer data).
|
|
1121
|
+
* @throws FlexOpsError (`403`, `SIGNED_IN_USER_REQUIRED`) when the client authenticates with an API key.
|
|
1122
|
+
*/
|
|
1083
1123
|
async listDeliveryLogs(webhookId) {
|
|
1084
1124
|
return this.http.get(this.wsPath(`${webhookId}/deliveries`));
|
|
1085
1125
|
}
|
|
1086
|
-
/**
|
|
1126
|
+
/**
|
|
1127
|
+
* Send a test event to a webhook's endpoint.
|
|
1128
|
+
*
|
|
1129
|
+
* Needs a signed-in user's access token.
|
|
1130
|
+
* @throws FlexOpsError (`403`, `SIGNED_IN_USER_REQUIRED`) when the client authenticates with an API key.
|
|
1131
|
+
*/
|
|
1087
1132
|
async test(webhookId) {
|
|
1088
1133
|
return this.http.post(this.wsPath(`${webhookId}/test`));
|
|
1089
1134
|
}
|
|
@@ -1287,63 +1332,63 @@ var AnalyticsResource = class {
|
|
|
1287
1332
|
path(endpoint) {
|
|
1288
1333
|
return `/api/ApiProxy/api/v4/Analytics/${endpoint}`;
|
|
1289
1334
|
}
|
|
1290
|
-
/** Shipments trend over time. */
|
|
1335
|
+
/** Shipments trend over time. With an API key, requires `shipping:read`. */
|
|
1291
1336
|
async shipmentsTrend(params) {
|
|
1292
1337
|
return this.http.get(this.path("ShipmentsTrend"), params);
|
|
1293
1338
|
}
|
|
1294
|
-
/** Carrier usage summary. */
|
|
1339
|
+
/** Carrier usage summary. With an API key, requires `shipping:read`. */
|
|
1295
1340
|
async carrierSummary(params) {
|
|
1296
1341
|
return this.http.get(this.path("CarrierSummary"), params);
|
|
1297
1342
|
}
|
|
1298
|
-
/** Top shipping destinations. */
|
|
1343
|
+
/** Top shipping destinations. With an API key, requires `shipping:read`. */
|
|
1299
1344
|
async topDestinations(params) {
|
|
1300
1345
|
return this.http.get(this.path("TopDestinations"), params);
|
|
1301
1346
|
}
|
|
1302
|
-
/** Inventory metrics (stock levels, low-stock alerts). */
|
|
1347
|
+
/** Inventory metrics (stock levels, low-stock alerts). With an API key, requires `inventory:read`. */
|
|
1303
1348
|
async inventoryMetrics() {
|
|
1304
1349
|
return this.http.get(this.path("InventoryMetrics"));
|
|
1305
1350
|
}
|
|
1306
|
-
/** Stock levels by warehouse. */
|
|
1351
|
+
/** Stock levels by warehouse. With an API key, requires `inventory:read`. */
|
|
1307
1352
|
async stockByWarehouse() {
|
|
1308
1353
|
return this.http.get(this.path("StockByWarehouse"));
|
|
1309
1354
|
}
|
|
1310
|
-
/** Order metrics (volume, revenue). */
|
|
1355
|
+
/** Order metrics (volume, revenue). With an API key, requires `orders:read`. */
|
|
1311
1356
|
async orderMetrics(params) {
|
|
1312
1357
|
return this.http.get(this.path("OrderMetrics"), params);
|
|
1313
1358
|
}
|
|
1314
|
-
/** Order trend over time. */
|
|
1359
|
+
/** Order trend over time. With an API key, requires `orders:read`. */
|
|
1315
1360
|
async orderTrend(params) {
|
|
1316
1361
|
return this.http.get(this.path("OrderTrend"), params);
|
|
1317
1362
|
}
|
|
1318
|
-
/** Top selling products. */
|
|
1363
|
+
/** Top selling products. With an API key, requires `orders:read`. */
|
|
1319
1364
|
async topSellingProducts(params) {
|
|
1320
1365
|
return this.http.get(this.path("TopSellingProducts"), params);
|
|
1321
1366
|
}
|
|
1322
|
-
/** Returns metrics. */
|
|
1367
|
+
/** Returns metrics. With an API key, requires `returns:read`. */
|
|
1323
1368
|
async returnsMetrics(params) {
|
|
1324
1369
|
return this.http.get(this.path("ReturnsMetrics"), params);
|
|
1325
1370
|
}
|
|
1326
|
-
/** Returns trend over time. */
|
|
1371
|
+
/** Returns trend over time. With an API key, requires `returns:read`. */
|
|
1327
1372
|
async returnsTrend(params) {
|
|
1328
1373
|
return this.http.get(this.path("ReturnsTrend"), params);
|
|
1329
1374
|
}
|
|
1330
|
-
/** Return reasons breakdown. */
|
|
1375
|
+
/** Return reasons breakdown. With an API key, requires `returns:read`. */
|
|
1331
1376
|
async returnReasons(params) {
|
|
1332
1377
|
return this.http.get(this.path("ReturnReasons"), params);
|
|
1333
1378
|
}
|
|
1334
|
-
/** Fulfillment performance metrics. */
|
|
1379
|
+
/** Fulfillment performance metrics. With an API key, requires `shipping:read`. */
|
|
1335
1380
|
async performanceMetrics(params) {
|
|
1336
1381
|
return this.http.get(this.path("PerformanceMetrics"), params);
|
|
1337
1382
|
}
|
|
1338
|
-
/** Carrier delivery performance. */
|
|
1383
|
+
/** Carrier delivery performance. With an API key, requires `shipping:read`. */
|
|
1339
1384
|
async carrierPerformance(params) {
|
|
1340
1385
|
return this.http.get(this.path("CarrierPerformance"), params);
|
|
1341
1386
|
}
|
|
1342
|
-
/** Shipping cost analytics. */
|
|
1387
|
+
/** Shipping cost analytics. With an API key, requires `shipping:read`. */
|
|
1343
1388
|
async shippingCostAnalytics(params) {
|
|
1344
1389
|
return this.http.get(this.path("ShippingCostAnalytics"), params);
|
|
1345
1390
|
}
|
|
1346
|
-
/** Delivery performance (on-time %). */
|
|
1391
|
+
/** Delivery performance (on-time %). With an API key, requires `shipping:read`. */
|
|
1347
1392
|
async deliveryPerformance(params) {
|
|
1348
1393
|
return this.http.get(this.path("DeliveryPerformance"), params);
|
|
1349
1394
|
}
|
|
@@ -1433,7 +1478,7 @@ var PickupsResource = class {
|
|
|
1433
1478
|
if (!id) throw new Error("workspaceId is required.");
|
|
1434
1479
|
return `/api/workspaces/${id}/pickups${suffix ? `/${suffix}` : ""}`;
|
|
1435
1480
|
}
|
|
1436
|
-
/** Schedule a carrier pickup. */
|
|
1481
|
+
/** Schedule a carrier pickup. API keys need `shipping:write`; the public demo keys are refused. */
|
|
1437
1482
|
async schedule(request) {
|
|
1438
1483
|
return this.http.post(this.wsPath(""), request);
|
|
1439
1484
|
}
|
|
@@ -1445,7 +1490,7 @@ var PickupsResource = class {
|
|
|
1445
1490
|
async get(pickupId, carrierCode) {
|
|
1446
1491
|
return this.http.get(this.wsPath(pickupId), { carrierCode });
|
|
1447
1492
|
}
|
|
1448
|
-
/** Cancel a scheduled pickup. */
|
|
1493
|
+
/** Cancel a scheduled pickup. API keys need `shipping:write`; the public demo keys are refused. */
|
|
1449
1494
|
async cancel(pickupId) {
|
|
1450
1495
|
return this.http.delete(this.wsPath(pickupId));
|
|
1451
1496
|
}
|
|
@@ -1464,19 +1509,42 @@ var ScanFormsResource = class {
|
|
|
1464
1509
|
if (!id) throw new Error("workspaceId is required.");
|
|
1465
1510
|
return `/api/workspaces/${id}/scan-forms${suffix ? `/${suffix}` : ""}`;
|
|
1466
1511
|
}
|
|
1467
|
-
/**
|
|
1512
|
+
/**
|
|
1513
|
+
* Create a USPS scan form (SCAN/manifest). API keys need `shipping:write`; the public demo keys are refused.
|
|
1514
|
+
* Sends `request.requestId`, or a UUID generated for this call, on every attempt, so a retried call replays
|
|
1515
|
+
* the same operation instead of creating a second form.
|
|
1516
|
+
*
|
|
1517
|
+
* Resolves with the created form (200), also when the same `requestId` and inputs are sent again. Rejects with a
|
|
1518
|
+
* 409 {@link FlexOpsError} when the `requestId` was used with different inputs, when the packages already belong
|
|
1519
|
+
* to a manifest, or when this or an earlier operation needs review (its message names the operation; do not
|
|
1520
|
+
* resubmit those packages). 400 means the request or package selection was refused.
|
|
1521
|
+
*/
|
|
1468
1522
|
async create(request) {
|
|
1469
|
-
|
|
1523
|
+
const response = await this.http.post(
|
|
1524
|
+
this.wsPath(""),
|
|
1525
|
+
{ ...request, requestId: request.requestId ?? randomUuid() }
|
|
1526
|
+
);
|
|
1527
|
+
return withAliases(response);
|
|
1470
1528
|
}
|
|
1471
|
-
/** List scan forms. */
|
|
1529
|
+
/** List the workspace's saved scan forms, newest mailing date first, including any whose outcome is unknown. */
|
|
1472
1530
|
async list() {
|
|
1473
|
-
return this.http.get(this.wsPath(""));
|
|
1531
|
+
return withAliases(await this.http.get(this.wsPath("")));
|
|
1474
1532
|
}
|
|
1475
|
-
/** Get a scan form by
|
|
1533
|
+
/** Get a saved scan form by its `scanFormId`. A form that does not exist rejects with a 404 {@link FlexOpsError}. */
|
|
1476
1534
|
async get(scanFormId) {
|
|
1477
|
-
return this.http.get(this.wsPath(scanFormId));
|
|
1535
|
+
return withAliases(await this.http.get(this.wsPath(scanFormId)));
|
|
1478
1536
|
}
|
|
1479
1537
|
};
|
|
1538
|
+
function withAliases(response) {
|
|
1539
|
+
const forms = Array.isArray(response?.data) ? response.data : response?.data ? [response.data] : [];
|
|
1540
|
+
for (const form of forms) {
|
|
1541
|
+
if (form && typeof form === "object") {
|
|
1542
|
+
if (form.formData === void 0 && typeof form.scanFormImage === "string") form.formData = form.scanFormImage;
|
|
1543
|
+
if (form.createdAt === void 0 && typeof form.createdAtUtc === "string") form.createdAt = form.createdAtUtc;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
return response;
|
|
1547
|
+
}
|
|
1480
1548
|
|
|
1481
1549
|
// src/resources/rules.ts
|
|
1482
1550
|
var RulesResource = class {
|
|
@@ -1499,25 +1567,34 @@ var RulesResource = class {
|
|
|
1499
1567
|
async get(ruleId) {
|
|
1500
1568
|
return this.http.get(this.wsPath(ruleId));
|
|
1501
1569
|
}
|
|
1502
|
-
/** Create a shipping rule. */
|
|
1570
|
+
/** Create a shipping rule. Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes. */
|
|
1503
1571
|
async create(rule) {
|
|
1504
1572
|
return this.http.post(this.wsPath(""), rule);
|
|
1505
1573
|
}
|
|
1506
|
-
/** Replace a shipping rule. */
|
|
1574
|
+
/** Replace a shipping rule. Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes. */
|
|
1507
1575
|
async update(ruleId, rule) {
|
|
1508
1576
|
return this.http.put(this.wsPath(ruleId), rule);
|
|
1509
1577
|
}
|
|
1510
|
-
/**
|
|
1578
|
+
/**
|
|
1579
|
+
* Delete a shipping rule. The Gateway answers 204 No Content, so there is no result.
|
|
1580
|
+
* Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes.
|
|
1581
|
+
*/
|
|
1511
1582
|
async delete(ruleId) {
|
|
1512
1583
|
await this.http.delete(this.wsPath(ruleId));
|
|
1513
1584
|
}
|
|
1514
|
-
/**
|
|
1585
|
+
/**
|
|
1586
|
+
* Reorder rules: each listed rule gets its position in `ruleIds` as its priority (0 first).
|
|
1587
|
+
* Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes.
|
|
1588
|
+
*/
|
|
1515
1589
|
async reorder(ruleIds) {
|
|
1516
1590
|
return this.http.post(this.wsPath("reorder"), {
|
|
1517
1591
|
rules: ruleIds.map((ruleId, priority) => ({ ruleId, priority }))
|
|
1518
1592
|
});
|
|
1519
1593
|
}
|
|
1520
|
-
/**
|
|
1594
|
+
/**
|
|
1595
|
+
* Dry-run the workspace's rules against a sample shipment, without changing anything.
|
|
1596
|
+
* API keys need `shipping:read`; the public demo keys are refused.
|
|
1597
|
+
*/
|
|
1521
1598
|
async test(request) {
|
|
1522
1599
|
return this.http.post(this.wsPath("test"), { tags: [], ...request });
|
|
1523
1600
|
}
|
|
@@ -1731,6 +1808,7 @@ var FlexOps = class {
|
|
|
1731
1808
|
workspaces;
|
|
1732
1809
|
shipping;
|
|
1733
1810
|
carriers;
|
|
1811
|
+
/** Webhook subscriptions. Needs a signed-in user's access token; API keys get `403` `SIGNED_IN_USER_REQUIRED`. */
|
|
1734
1812
|
webhooks;
|
|
1735
1813
|
wallet;
|
|
1736
1814
|
insurance;
|