@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.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
  }
@@ -528,6 +528,10 @@ var ShippingResource = class {
528
528
  * a label may exist: both throw a `FlexOpsError` whose `data` is the `MultiPackageShipmentResponse`.
529
529
  * After `OutcomeUnknown`, check the order before buying again.
530
530
  *
531
+ * `maximumPostageAmount` is required: the most the whole shipment may cost in USD. The Gateway refuses to buy
532
+ * any box that would take the total above it (that box reports `PriceCeilingExceeded`; boxes after the
533
+ * ceiling is used up report `PriceCeilingReached`), and a request without a valid one is 400 `ApprovalRequired`.
534
+ *
531
535
  * `hazmatClassification` accepts only `HazmatClassification.None` or nothing. Pass a stable
532
536
  * `idempotencyKey` to retry safely across processes; otherwise one is generated for this call.
533
537
  */
@@ -670,19 +674,27 @@ var CarriersResource = class {
670
674
  /**
671
675
  * Cancel a domestic label.
672
676
  *
677
+ * @param trackingNumber The label's tracking number.
673
678
  * @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
674
679
  * `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
675
680
  * cover this.
676
681
  */
677
- cancelDomesticLabel: () => this.http.delete(this.proxy("api/v3/Shipping/cancelUspsDomesticShipmentLabel")),
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
+ },
678
686
  /**
679
687
  * Cancel an international label.
680
688
  *
689
+ * @param internationalTrackingNumber The label's international tracking number.
681
690
  * @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
682
691
  * `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
683
692
  * cover this.
684
693
  */
685
- cancelInternationalLabel: () => this.http.delete(this.proxy("api/v3/Shipping/cancelUspsInternationalShipmentLabel")),
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
+ },
686
698
  /** Get tracking summary. */
687
699
  trackSummary: (params) => this.http.get(this.proxy("api/v3/Tracking/getUspsTrackingSummaryInformation"), params),
688
700
  /** Get detailed tracking info. */
@@ -698,11 +710,15 @@ var CarriersResource = class {
698
710
  /**
699
711
  * Cancel a pickup.
700
712
  *
713
+ * @param confirmationNumber The pickup's confirmation number.
701
714
  * @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
702
715
  * `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
703
716
  * cover this.
704
717
  */
705
- cancelPickup: () => this.http.delete(this.proxy("api/v3/CarrierPickup/cancelUspsCarrierPickupSchedule")),
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
+ },
706
722
  /**
707
723
  * Create a scan form.
708
724
  *
@@ -1047,14 +1063,23 @@ var WebhooksResource = class {
1047
1063
  if (!id) throw new Error("workspaceId is required.");
1048
1064
  return `/api/workspaces/${id}/webhooks${suffix ? `/${suffix}` : ""}`;
1049
1065
  }
1050
- /** List all webhook subscriptions for the workspace. */
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
+ */
1051
1073
  async list() {
1052
1074
  return this.http.get(this.wsPath(""));
1053
1075
  }
1054
1076
  /**
1055
1077
  * Create a webhook subscription. `events` is sent as the Gateway's comma-separated `eventTypes`;
1056
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.
1057
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.
1058
1083
  */
1059
1084
  async create(request) {
1060
1085
  const body = await this.http.post(this.wsPath(""), toWireRequest(request));
@@ -1062,24 +1087,48 @@ var WebhooksResource = class {
1062
1087
  }
1063
1088
  /**
1064
1089
  * Update a webhook subscription. `events`, when given, replaces the subscribed events.
1090
+ *
1091
+ * Needs a signed-in user's access token.
1065
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.
1066
1094
  */
1067
1095
  async update(webhookId, data) {
1068
1096
  return this.http.put(this.wsPath(webhookId), toWireRequest(data));
1069
1097
  }
1070
- /** Delete a webhook subscription. The Gateway answers 204 No Content, so there is no result. */
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
+ */
1071
1104
  async delete(webhookId) {
1072
1105
  await this.http.delete(this.wsPath(webhookId));
1073
1106
  }
1074
- /** Rotate the signing secret for a webhook. */
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
+ */
1075
1113
  async rotateSecret(webhookId) {
1076
1114
  return this.http.post(this.wsPath(`${webhookId}/rotate-secret`));
1077
1115
  }
1078
- /** List delivery logs for a webhook. */
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
+ */
1079
1123
  async listDeliveryLogs(webhookId) {
1080
1124
  return this.http.get(this.wsPath(`${webhookId}/deliveries`));
1081
1125
  }
1082
- /** Send a test event to a webhook's endpoint. */
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
+ */
1083
1132
  async test(webhookId) {
1084
1133
  return this.http.post(this.wsPath(`${webhookId}/test`));
1085
1134
  }
@@ -1283,63 +1332,63 @@ var AnalyticsResource = class {
1283
1332
  path(endpoint) {
1284
1333
  return `/api/ApiProxy/api/v4/Analytics/${endpoint}`;
1285
1334
  }
1286
- /** Shipments trend over time. */
1335
+ /** Shipments trend over time. With an API key, requires `shipping:read`. */
1287
1336
  async shipmentsTrend(params) {
1288
1337
  return this.http.get(this.path("ShipmentsTrend"), params);
1289
1338
  }
1290
- /** Carrier usage summary. */
1339
+ /** Carrier usage summary. With an API key, requires `shipping:read`. */
1291
1340
  async carrierSummary(params) {
1292
1341
  return this.http.get(this.path("CarrierSummary"), params);
1293
1342
  }
1294
- /** Top shipping destinations. */
1343
+ /** Top shipping destinations. With an API key, requires `shipping:read`. */
1295
1344
  async topDestinations(params) {
1296
1345
  return this.http.get(this.path("TopDestinations"), params);
1297
1346
  }
1298
- /** Inventory metrics (stock levels, low-stock alerts). */
1347
+ /** Inventory metrics (stock levels, low-stock alerts). With an API key, requires `inventory:read`. */
1299
1348
  async inventoryMetrics() {
1300
1349
  return this.http.get(this.path("InventoryMetrics"));
1301
1350
  }
1302
- /** Stock levels by warehouse. */
1351
+ /** Stock levels by warehouse. With an API key, requires `inventory:read`. */
1303
1352
  async stockByWarehouse() {
1304
1353
  return this.http.get(this.path("StockByWarehouse"));
1305
1354
  }
1306
- /** Order metrics (volume, revenue). */
1355
+ /** Order metrics (volume, revenue). With an API key, requires `orders:read`. */
1307
1356
  async orderMetrics(params) {
1308
1357
  return this.http.get(this.path("OrderMetrics"), params);
1309
1358
  }
1310
- /** Order trend over time. */
1359
+ /** Order trend over time. With an API key, requires `orders:read`. */
1311
1360
  async orderTrend(params) {
1312
1361
  return this.http.get(this.path("OrderTrend"), params);
1313
1362
  }
1314
- /** Top selling products. */
1363
+ /** Top selling products. With an API key, requires `orders:read`. */
1315
1364
  async topSellingProducts(params) {
1316
1365
  return this.http.get(this.path("TopSellingProducts"), params);
1317
1366
  }
1318
- /** Returns metrics. */
1367
+ /** Returns metrics. With an API key, requires `returns:read`. */
1319
1368
  async returnsMetrics(params) {
1320
1369
  return this.http.get(this.path("ReturnsMetrics"), params);
1321
1370
  }
1322
- /** Returns trend over time. */
1371
+ /** Returns trend over time. With an API key, requires `returns:read`. */
1323
1372
  async returnsTrend(params) {
1324
1373
  return this.http.get(this.path("ReturnsTrend"), params);
1325
1374
  }
1326
- /** Return reasons breakdown. */
1375
+ /** Return reasons breakdown. With an API key, requires `returns:read`. */
1327
1376
  async returnReasons(params) {
1328
1377
  return this.http.get(this.path("ReturnReasons"), params);
1329
1378
  }
1330
- /** Fulfillment performance metrics. */
1379
+ /** Fulfillment performance metrics. With an API key, requires `shipping:read`. */
1331
1380
  async performanceMetrics(params) {
1332
1381
  return this.http.get(this.path("PerformanceMetrics"), params);
1333
1382
  }
1334
- /** Carrier delivery performance. */
1383
+ /** Carrier delivery performance. With an API key, requires `shipping:read`. */
1335
1384
  async carrierPerformance(params) {
1336
1385
  return this.http.get(this.path("CarrierPerformance"), params);
1337
1386
  }
1338
- /** Shipping cost analytics. */
1387
+ /** Shipping cost analytics. With an API key, requires `shipping:read`. */
1339
1388
  async shippingCostAnalytics(params) {
1340
1389
  return this.http.get(this.path("ShippingCostAnalytics"), params);
1341
1390
  }
1342
- /** Delivery performance (on-time %). */
1391
+ /** Delivery performance (on-time %). With an API key, requires `shipping:read`. */
1343
1392
  async deliveryPerformance(params) {
1344
1393
  return this.http.get(this.path("DeliveryPerformance"), params);
1345
1394
  }
@@ -1429,7 +1478,7 @@ var PickupsResource = class {
1429
1478
  if (!id) throw new Error("workspaceId is required.");
1430
1479
  return `/api/workspaces/${id}/pickups${suffix ? `/${suffix}` : ""}`;
1431
1480
  }
1432
- /** Schedule a carrier pickup. */
1481
+ /** Schedule a carrier pickup. API keys need `shipping:write`; the public demo keys are refused. */
1433
1482
  async schedule(request) {
1434
1483
  return this.http.post(this.wsPath(""), request);
1435
1484
  }
@@ -1441,7 +1490,7 @@ var PickupsResource = class {
1441
1490
  async get(pickupId, carrierCode) {
1442
1491
  return this.http.get(this.wsPath(pickupId), { carrierCode });
1443
1492
  }
1444
- /** Cancel a scheduled pickup. */
1493
+ /** Cancel a scheduled pickup. API keys need `shipping:write`; the public demo keys are refused. */
1445
1494
  async cancel(pickupId) {
1446
1495
  return this.http.delete(this.wsPath(pickupId));
1447
1496
  }
@@ -1460,19 +1509,42 @@ var ScanFormsResource = class {
1460
1509
  if (!id) throw new Error("workspaceId is required.");
1461
1510
  return `/api/workspaces/${id}/scan-forms${suffix ? `/${suffix}` : ""}`;
1462
1511
  }
1463
- /** Create a USPS scan form (SCAN/manifest). */
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
+ */
1464
1522
  async create(request) {
1465
- return this.http.post(this.wsPath(""), request);
1523
+ const response = await this.http.post(
1524
+ this.wsPath(""),
1525
+ { ...request, requestId: request.requestId ?? randomUuid() }
1526
+ );
1527
+ return withAliases(response);
1466
1528
  }
1467
- /** List scan forms. */
1529
+ /** List the workspace's saved scan forms, newest mailing date first, including any whose outcome is unknown. */
1468
1530
  async list() {
1469
- return this.http.get(this.wsPath(""));
1531
+ return withAliases(await this.http.get(this.wsPath("")));
1470
1532
  }
1471
- /** Get a scan form by ID. */
1533
+ /** Get a saved scan form by its `scanFormId`. A form that does not exist rejects with a 404 {@link FlexOpsError}. */
1472
1534
  async get(scanFormId) {
1473
- return this.http.get(this.wsPath(scanFormId));
1535
+ return withAliases(await this.http.get(this.wsPath(scanFormId)));
1474
1536
  }
1475
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
+ }
1476
1548
 
1477
1549
  // src/resources/rules.ts
1478
1550
  var RulesResource = class {
@@ -1495,25 +1567,34 @@ var RulesResource = class {
1495
1567
  async get(ruleId) {
1496
1568
  return this.http.get(this.wsPath(ruleId));
1497
1569
  }
1498
- /** Create a shipping rule. */
1570
+ /** Create a shipping rule. Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes. */
1499
1571
  async create(rule) {
1500
1572
  return this.http.post(this.wsPath(""), rule);
1501
1573
  }
1502
- /** Replace a shipping rule. */
1574
+ /** Replace a shipping rule. Signed-in users only: API keys get 403 `SIGNED_IN_USER_REQUIRED`, whatever their scopes. */
1503
1575
  async update(ruleId, rule) {
1504
1576
  return this.http.put(this.wsPath(ruleId), rule);
1505
1577
  }
1506
- /** Delete a shipping rule. The Gateway answers 204 No Content, so there is no result. */
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
+ */
1507
1582
  async delete(ruleId) {
1508
1583
  await this.http.delete(this.wsPath(ruleId));
1509
1584
  }
1510
- /** Reorder rules: each listed rule gets its position in `ruleIds` as its priority (0 first). */
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
+ */
1511
1589
  async reorder(ruleIds) {
1512
1590
  return this.http.post(this.wsPath("reorder"), {
1513
1591
  rules: ruleIds.map((ruleId, priority) => ({ ruleId, priority }))
1514
1592
  });
1515
1593
  }
1516
- /** Dry-run the workspace's rules against a sample shipment, without changing anything. */
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
+ */
1517
1598
  async test(request) {
1518
1599
  return this.http.post(this.wsPath("test"), { tags: [], ...request });
1519
1600
  }
@@ -1727,6 +1808,7 @@ var FlexOps = class {
1727
1808
  workspaces;
1728
1809
  shipping;
1729
1810
  carriers;
1811
+ /** Webhook subscriptions. Needs a signed-in user's access token; API keys get `403` `SIGNED_IN_USER_REQUIRED`. */
1730
1812
  webhooks;
1731
1813
  wallet;
1732
1814
  insurance;