@flexops/sdk 3.2.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/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
  }
@@ -480,6 +480,10 @@ var ShippingResource = class {
480
480
  * a label may exist: both throw a `FlexOpsError` whose `data` is the `MultiPackageShipmentResponse`.
481
481
  * After `OutcomeUnknown`, check the order before buying again.
482
482
  *
483
+ * `maximumPostageAmount` is required: the most the whole shipment may cost in USD. The Gateway refuses to buy
484
+ * any box that would take the total above it (that box reports `PriceCeilingExceeded`; boxes after the
485
+ * ceiling is used up report `PriceCeilingReached`), and a request without a valid one is 400 `ApprovalRequired`.
486
+ *
483
487
  * `hazmatClassification` accepts only `HazmatClassification.None` or nothing. Pass a stable
484
488
  * `idempotencyKey` to retry safely across processes; otherwise one is generated for this call.
485
489
  */
@@ -622,19 +626,27 @@ var CarriersResource = class {
622
626
  /**
623
627
  * Cancel a domestic label.
624
628
  *
629
+ * @param trackingNumber The label's tracking number.
625
630
  * @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
626
631
  * `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
627
632
  * cover this.
628
633
  */
629
- cancelDomesticLabel: () => this.http.delete(this.proxy("api/v3/Shipping/cancelUspsDomesticShipmentLabel")),
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
+ },
630
638
  /**
631
639
  * Cancel an international label.
632
640
  *
641
+ * @param internationalTrackingNumber The label's international tracking number.
633
642
  * @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
634
643
  * `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
635
644
  * cover this.
636
645
  */
637
- cancelInternationalLabel: () => this.http.delete(this.proxy("api/v3/Shipping/cancelUspsInternationalShipmentLabel")),
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
+ },
638
650
  /** Get tracking summary. */
639
651
  trackSummary: (params) => this.http.get(this.proxy("api/v3/Tracking/getUspsTrackingSummaryInformation"), params),
640
652
  /** Get detailed tracking info. */
@@ -650,11 +662,15 @@ var CarriersResource = class {
650
662
  /**
651
663
  * Cancel a pickup.
652
664
  *
665
+ * @param confirmationNumber The pickup's confirmation number.
653
666
  * @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
654
667
  * `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
655
668
  * cover this.
656
669
  */
657
- cancelPickup: () => this.http.delete(this.proxy("api/v3/CarrierPickup/cancelUspsCarrierPickupSchedule")),
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
+ },
658
674
  /**
659
675
  * Create a scan form.
660
676
  *
@@ -999,14 +1015,23 @@ var WebhooksResource = class {
999
1015
  if (!id) throw new Error("workspaceId is required.");
1000
1016
  return `/api/workspaces/${id}/webhooks${suffix ? `/${suffix}` : ""}`;
1001
1017
  }
1002
- /** List all webhook subscriptions for the workspace. */
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
+ */
1003
1025
  async list() {
1004
1026
  return this.http.get(this.wsPath(""));
1005
1027
  }
1006
1028
  /**
1007
1029
  * Create a webhook subscription. `events` is sent as the Gateway's comma-separated `eventTypes`;
1008
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.
1009
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.
1010
1035
  */
1011
1036
  async create(request) {
1012
1037
  const body = await this.http.post(this.wsPath(""), toWireRequest(request));
@@ -1014,24 +1039,48 @@ var WebhooksResource = class {
1014
1039
  }
1015
1040
  /**
1016
1041
  * Update a webhook subscription. `events`, when given, replaces the subscribed events.
1042
+ *
1043
+ * Needs a signed-in user's access token.
1017
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.
1018
1046
  */
1019
1047
  async update(webhookId, data) {
1020
1048
  return this.http.put(this.wsPath(webhookId), toWireRequest(data));
1021
1049
  }
1022
- /** Delete a webhook subscription. The Gateway answers 204 No Content, so there is no result. */
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
+ */
1023
1056
  async delete(webhookId) {
1024
1057
  await this.http.delete(this.wsPath(webhookId));
1025
1058
  }
1026
- /** Rotate the signing secret for a webhook. */
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
+ */
1027
1065
  async rotateSecret(webhookId) {
1028
1066
  return this.http.post(this.wsPath(`${webhookId}/rotate-secret`));
1029
1067
  }
1030
- /** List delivery logs for a webhook. */
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
+ */
1031
1075
  async listDeliveryLogs(webhookId) {
1032
1076
  return this.http.get(this.wsPath(`${webhookId}/deliveries`));
1033
1077
  }
1034
- /** Send a test event to a webhook's endpoint. */
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
+ */
1035
1084
  async test(webhookId) {
1036
1085
  return this.http.post(this.wsPath(`${webhookId}/test`));
1037
1086
  }
@@ -1235,63 +1284,63 @@ var AnalyticsResource = class {
1235
1284
  path(endpoint) {
1236
1285
  return `/api/ApiProxy/api/v4/Analytics/${endpoint}`;
1237
1286
  }
1238
- /** Shipments trend over time. */
1287
+ /** Shipments trend over time. With an API key, requires `shipping:read`. */
1239
1288
  async shipmentsTrend(params) {
1240
1289
  return this.http.get(this.path("ShipmentsTrend"), params);
1241
1290
  }
1242
- /** Carrier usage summary. */
1291
+ /** Carrier usage summary. With an API key, requires `shipping:read`. */
1243
1292
  async carrierSummary(params) {
1244
1293
  return this.http.get(this.path("CarrierSummary"), params);
1245
1294
  }
1246
- /** Top shipping destinations. */
1295
+ /** Top shipping destinations. With an API key, requires `shipping:read`. */
1247
1296
  async topDestinations(params) {
1248
1297
  return this.http.get(this.path("TopDestinations"), params);
1249
1298
  }
1250
- /** Inventory metrics (stock levels, low-stock alerts). */
1299
+ /** Inventory metrics (stock levels, low-stock alerts). With an API key, requires `inventory:read`. */
1251
1300
  async inventoryMetrics() {
1252
1301
  return this.http.get(this.path("InventoryMetrics"));
1253
1302
  }
1254
- /** Stock levels by warehouse. */
1303
+ /** Stock levels by warehouse. With an API key, requires `inventory:read`. */
1255
1304
  async stockByWarehouse() {
1256
1305
  return this.http.get(this.path("StockByWarehouse"));
1257
1306
  }
1258
- /** Order metrics (volume, revenue). */
1307
+ /** Order metrics (volume, revenue). With an API key, requires `orders:read`. */
1259
1308
  async orderMetrics(params) {
1260
1309
  return this.http.get(this.path("OrderMetrics"), params);
1261
1310
  }
1262
- /** Order trend over time. */
1311
+ /** Order trend over time. With an API key, requires `orders:read`. */
1263
1312
  async orderTrend(params) {
1264
1313
  return this.http.get(this.path("OrderTrend"), params);
1265
1314
  }
1266
- /** Top selling products. */
1315
+ /** Top selling products. With an API key, requires `orders:read`. */
1267
1316
  async topSellingProducts(params) {
1268
1317
  return this.http.get(this.path("TopSellingProducts"), params);
1269
1318
  }
1270
- /** Returns metrics. */
1319
+ /** Returns metrics. With an API key, requires `returns:read`. */
1271
1320
  async returnsMetrics(params) {
1272
1321
  return this.http.get(this.path("ReturnsMetrics"), params);
1273
1322
  }
1274
- /** Returns trend over time. */
1323
+ /** Returns trend over time. With an API key, requires `returns:read`. */
1275
1324
  async returnsTrend(params) {
1276
1325
  return this.http.get(this.path("ReturnsTrend"), params);
1277
1326
  }
1278
- /** Return reasons breakdown. */
1327
+ /** Return reasons breakdown. With an API key, requires `returns:read`. */
1279
1328
  async returnReasons(params) {
1280
1329
  return this.http.get(this.path("ReturnReasons"), params);
1281
1330
  }
1282
- /** Fulfillment performance metrics. */
1331
+ /** Fulfillment performance metrics. With an API key, requires `shipping:read`. */
1283
1332
  async performanceMetrics(params) {
1284
1333
  return this.http.get(this.path("PerformanceMetrics"), params);
1285
1334
  }
1286
- /** Carrier delivery performance. */
1335
+ /** Carrier delivery performance. With an API key, requires `shipping:read`. */
1287
1336
  async carrierPerformance(params) {
1288
1337
  return this.http.get(this.path("CarrierPerformance"), params);
1289
1338
  }
1290
- /** Shipping cost analytics. */
1339
+ /** Shipping cost analytics. With an API key, requires `shipping:read`. */
1291
1340
  async shippingCostAnalytics(params) {
1292
1341
  return this.http.get(this.path("ShippingCostAnalytics"), params);
1293
1342
  }
1294
- /** Delivery performance (on-time %). */
1343
+ /** Delivery performance (on-time %). With an API key, requires `shipping:read`. */
1295
1344
  async deliveryPerformance(params) {
1296
1345
  return this.http.get(this.path("DeliveryPerformance"), params);
1297
1346
  }
@@ -1381,7 +1430,7 @@ var PickupsResource = class {
1381
1430
  if (!id) throw new Error("workspaceId is required.");
1382
1431
  return `/api/workspaces/${id}/pickups${suffix ? `/${suffix}` : ""}`;
1383
1432
  }
1384
- /** Schedule a carrier pickup. */
1433
+ /** Schedule a carrier pickup. API keys need `shipping:write`; the public demo keys are refused. */
1385
1434
  async schedule(request) {
1386
1435
  return this.http.post(this.wsPath(""), request);
1387
1436
  }
@@ -1393,7 +1442,7 @@ var PickupsResource = class {
1393
1442
  async get(pickupId, carrierCode) {
1394
1443
  return this.http.get(this.wsPath(pickupId), { carrierCode });
1395
1444
  }
1396
- /** Cancel a scheduled pickup. */
1445
+ /** Cancel a scheduled pickup. API keys need `shipping:write`; the public demo keys are refused. */
1397
1446
  async cancel(pickupId) {
1398
1447
  return this.http.delete(this.wsPath(pickupId));
1399
1448
  }
@@ -1412,19 +1461,42 @@ var ScanFormsResource = class {
1412
1461
  if (!id) throw new Error("workspaceId is required.");
1413
1462
  return `/api/workspaces/${id}/scan-forms${suffix ? `/${suffix}` : ""}`;
1414
1463
  }
1415
- /** Create a USPS scan form (SCAN/manifest). */
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
+ */
1416
1474
  async create(request) {
1417
- return this.http.post(this.wsPath(""), request);
1475
+ const response = await this.http.post(
1476
+ this.wsPath(""),
1477
+ { ...request, requestId: request.requestId ?? randomUuid() }
1478
+ );
1479
+ return withAliases(response);
1418
1480
  }
1419
- /** List scan forms. */
1481
+ /** List the workspace's saved scan forms, newest mailing date first, including any whose outcome is unknown. */
1420
1482
  async list() {
1421
- return this.http.get(this.wsPath(""));
1483
+ return withAliases(await this.http.get(this.wsPath("")));
1422
1484
  }
1423
- /** Get a scan form by ID. */
1485
+ /** Get a saved scan form by its `scanFormId`. A form that does not exist rejects with a 404 {@link FlexOpsError}. */
1424
1486
  async get(scanFormId) {
1425
- return this.http.get(this.wsPath(scanFormId));
1487
+ return withAliases(await this.http.get(this.wsPath(scanFormId)));
1426
1488
  }
1427
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
+ }
1428
1500
 
1429
1501
  // src/resources/rules.ts
1430
1502
  var RulesResource = class {
@@ -1447,25 +1519,34 @@ var RulesResource = class {
1447
1519
  async get(ruleId) {
1448
1520
  return this.http.get(this.wsPath(ruleId));
1449
1521
  }
1450
- /** Create a shipping rule. */
1522
+ /** Create a shipping rule. Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes. */
1451
1523
  async create(rule) {
1452
1524
  return this.http.post(this.wsPath(""), rule);
1453
1525
  }
1454
- /** Replace a shipping rule. */
1526
+ /** Replace a shipping rule. Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes. */
1455
1527
  async update(ruleId, rule) {
1456
1528
  return this.http.put(this.wsPath(ruleId), rule);
1457
1529
  }
1458
- /** Delete a shipping rule. The Gateway answers 204 No Content, so there is no result. */
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
+ */
1459
1534
  async delete(ruleId) {
1460
1535
  await this.http.delete(this.wsPath(ruleId));
1461
1536
  }
1462
- /** Reorder rules: each listed rule gets its position in `ruleIds` as its priority (0 first). */
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
+ */
1463
1541
  async reorder(ruleIds) {
1464
1542
  return this.http.post(this.wsPath("reorder"), {
1465
1543
  rules: ruleIds.map((ruleId, priority) => ({ ruleId, priority }))
1466
1544
  });
1467
1545
  }
1468
- /** Dry-run the workspace's rules against a sample shipment, without changing anything. */
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
+ */
1469
1550
  async test(request) {
1470
1551
  return this.http.post(this.wsPath("test"), { tags: [], ...request });
1471
1552
  }
@@ -1679,6 +1760,7 @@ var FlexOps = class {
1679
1760
  workspaces;
1680
1761
  shipping;
1681
1762
  carriers;
1763
+ /** Webhook subscriptions. Needs a signed-in user's access token; API keys get `403` `SIGNED_IN_USER_REQUIRED`. */
1682
1764
  webhooks;
1683
1765
  wallet;
1684
1766
  insurance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexops/sdk",
3
- "version": "3.2.0",
3
+ "version": "3.4.0",
4
4
  "description": "Official FlexOps Platform Node.js/TypeScript SDK — multi-carrier shipping, order management, and logistics API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",