@flexops/sdk 3.1.0 → 3.3.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 +55 -11
- package/dist/index.d.mts +188 -14
- package/dist/index.d.ts +188 -14
- package/dist/index.js +50 -7
- package/dist/index.mjs +50 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ npm install @flexops/sdk
|
|
|
28
28
|
import { FlexOps, HazmatClassification } from '@flexops/sdk';
|
|
29
29
|
|
|
30
30
|
const client = new FlexOps({
|
|
31
|
-
apiKey: '
|
|
31
|
+
apiKey: 'live_...',
|
|
32
32
|
workspaceId: 'your-workspace-id',
|
|
33
33
|
});
|
|
34
34
|
```
|
|
@@ -155,6 +155,41 @@ const batch = await client.shipping.createBatch(request);
|
|
|
155
155
|
const status = await client.shipping.getBatchStatus(batch.data!.jobId);
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
+
### Multi-Package Labels
|
|
159
|
+
|
|
160
|
+
One order shipped in several boxes with the same carrier and service. Each box gets its own label;
|
|
161
|
+
a box that fails does not stop the others. Multi-package labels cannot carry HAZMAT: send
|
|
162
|
+
`HazmatClassification.None` or leave `hazmatClassification` out. `maximumPostageAmount` is required: the most the
|
|
163
|
+
whole shipment may cost in USD (positive, at most two decimals). The Gateway refuses to buy a box that would take the
|
|
164
|
+
total above it (`PriceCeilingExceeded`; once the amount is used up the remaining boxes report `PriceCeilingReached`),
|
|
165
|
+
and a request without a valid ceiling is 400 `ApprovalRequired`.
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { FlexOpsError, HazmatClassification } from '@flexops/sdk';
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
const shipment = await client.shipping.createMultiPackage(
|
|
172
|
+
{
|
|
173
|
+
orderId: 12345,
|
|
174
|
+
carrierCode: 'USPS',
|
|
175
|
+
serviceCode: 'PRIORITY',
|
|
176
|
+
hazmatClassification: HazmatClassification.None,
|
|
177
|
+
maximumPostageAmount: 25, // required: the most the whole shipment may cost, in USD
|
|
178
|
+
packages: [
|
|
179
|
+
{ weightInOunces: 16, lengthInInches: 10, widthInInches: 8, heightInInches: 4, packageReference: 'Box 1 of 2' },
|
|
180
|
+
{ weightInOunces: 8, lengthInInches: 6, widthInInches: 6, heightInInches: 6, packageReference: 'Box 2 of 2' },
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
'order-12345-boxes', // optional Idempotency-Key, reuse it when you retry
|
|
184
|
+
);
|
|
185
|
+
// At least one label was bought; check each box
|
|
186
|
+
for (const box of shipment.data!.labels) console.log(box.packageIndex, box.success, box.trackingNumber ?? box.errorMessage);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
// No label was bought: 422 AllPackagesFailed, or 409 OutcomeUnknown when a label may exist (check the order first).
|
|
189
|
+
if (error instanceof FlexOpsError) console.log(error.code, error.data);
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
158
193
|
## Carrier-Specific Calls
|
|
159
194
|
|
|
160
195
|
Rates, labels, voids, pickups and scan forms go through `client.shipping`, `client.pickups` and
|
|
@@ -268,7 +303,7 @@ Every SDK method is a thin wrapper around the FlexOps REST API. If you want to v
|
|
|
268
303
|
```bash
|
|
269
304
|
# Shop rates across all connected carriers
|
|
270
305
|
curl -X POST https://gateway.flexops.io/api/shipping/rates \
|
|
271
|
-
-H "X-API-Key:
|
|
306
|
+
-H "X-API-Key: live_..." \
|
|
272
307
|
-H "Content-Type: application/json" \
|
|
273
308
|
-d '{
|
|
274
309
|
"origin": {"addressLine1": "123 Main St", "city": "New York", "stateProvince": "NY", "postalCode": "10001", "countryCode": "US"},
|
|
@@ -278,7 +313,7 @@ curl -X POST https://gateway.flexops.io/api/shipping/rates \
|
|
|
278
313
|
|
|
279
314
|
# Create a label (hazmatClassification 0 = not hazardous; required when there is no orderId)
|
|
280
315
|
curl -X POST https://gateway.flexops.io/api/shipping/labels \
|
|
281
|
-
-H "X-API-Key:
|
|
316
|
+
-H "X-API-Key: live_..." \
|
|
282
317
|
-H "Content-Type: application/json" \
|
|
283
318
|
-d '{
|
|
284
319
|
"carrierCode": "USPS",
|
|
@@ -291,14 +326,14 @@ curl -X POST https://gateway.flexops.io/api/shipping/labels \
|
|
|
291
326
|
|
|
292
327
|
# Track a shipment
|
|
293
328
|
curl https://gateway.flexops.io/api/shipping/track/9400111899223456789012 \
|
|
294
|
-
-H "X-API-Key:
|
|
329
|
+
-H "X-API-Key: live_..."
|
|
295
330
|
|
|
296
331
|
# Cancel (void) a label
|
|
297
332
|
curl -X DELETE "https://gateway.flexops.io/api/shipping/labels/{labelId}?carrierCode=usps" \
|
|
298
|
-
-H "X-API-Key:
|
|
333
|
+
-H "X-API-Key: live_..."
|
|
299
334
|
```
|
|
300
335
|
|
|
301
|
-
Use
|
|
336
|
+
Use a `test_...` key instead of `live_...` to hit the sandbox environment; mock carriers respond, no real charges, no real labels.
|
|
302
337
|
|
|
303
338
|
## Wallet
|
|
304
339
|
|
|
@@ -348,22 +383,31 @@ const rma = await client.returns.create({
|
|
|
348
383
|
reason: 'Defective product',
|
|
349
384
|
items: [{ sku: 'WIDGET-001', quantity: 1 }],
|
|
350
385
|
});
|
|
386
|
+
const { rmaNumber, rmaId } = rma.data!;
|
|
387
|
+
|
|
388
|
+
// Read it back by RMA number, or page through all RMAs
|
|
389
|
+
const current = await client.returns.getRma(rmaNumber);
|
|
390
|
+
const rmas = await client.returns.listRmas({ page: 1, pageSize: 25 });
|
|
351
391
|
|
|
352
392
|
// Generate the return label. Send the package weight and size. Anything left out comes from the
|
|
353
393
|
// workspace's default shipping preset; with no preset the API answers 400 PackageMeasurementsRequired.
|
|
354
|
-
await client.returns.generateLabel(
|
|
394
|
+
await client.returns.generateLabel(rmaNumber, {
|
|
355
395
|
weightOz: 16,
|
|
356
396
|
lengthIn: 10,
|
|
357
397
|
widthIn: 8,
|
|
358
398
|
heightIn: 4,
|
|
359
399
|
});
|
|
360
400
|
|
|
361
|
-
// Record the inspected items at a warehouse (disposition 0 restock, 1
|
|
401
|
+
// Record the inspected items at a warehouse (disposition 0 restock, 1 dispose, 2 forward)
|
|
362
402
|
await client.returns.markReceived(rmaId, {
|
|
363
|
-
rmaNumber
|
|
403
|
+
rmaNumber,
|
|
364
404
|
warehouseId: 1,
|
|
365
|
-
inspectedItems: [{ partNumber: 'WIDGET-001', quantity: 1, disposition:
|
|
405
|
+
inspectedItems: [{ partNumber: 'WIDGET-001', quantity: 1, disposition: 0 }],
|
|
366
406
|
});
|
|
407
|
+
|
|
408
|
+
// Received returns: list them, then read one by its numeric return id
|
|
409
|
+
const received = await client.returns.list({ startDate: '2026-10-01' });
|
|
410
|
+
const detail = await client.returns.get(received.data![0].returnId);
|
|
367
411
|
```
|
|
368
412
|
|
|
369
413
|
Approving, rejecting, cancelling and refunding returns are done in the FlexOps portal.
|
|
@@ -465,7 +509,7 @@ try {
|
|
|
465
509
|
```typescript
|
|
466
510
|
const client = new FlexOps({
|
|
467
511
|
baseUrl: 'https://gateway.flexops.io', // Default
|
|
468
|
-
apiKey: '
|
|
512
|
+
apiKey: 'live_...',
|
|
469
513
|
workspaceId: 'ws-abc123',
|
|
470
514
|
timeout: 30000, // 30s default
|
|
471
515
|
retry: {
|
package/dist/index.d.mts
CHANGED
|
@@ -575,7 +575,7 @@ interface ReturnLabelRequest {
|
|
|
575
575
|
/** USPS rate indicator for the return label's price tier. */
|
|
576
576
|
rateIndicator?: string;
|
|
577
577
|
}
|
|
578
|
-
/** How a received item is dispositioned: 0 restock, 1
|
|
578
|
+
/** How a received item is dispositioned: 0 restock, 1 dispose, 2 forward. */
|
|
579
579
|
type ReturnDisposition = 0 | 1 | 2;
|
|
580
580
|
/** Body of `POST /api/workspaces/{workspaceId}/returns/{rmaId}/receive`. */
|
|
581
581
|
interface ReceiveReturnRequest {
|
|
@@ -589,12 +589,151 @@ interface ReceiveReturnRequest {
|
|
|
589
589
|
inspectionNotes?: string;
|
|
590
590
|
}[];
|
|
591
591
|
}
|
|
592
|
+
/**
|
|
593
|
+
* @deprecated No Gateway route returns this shape. `returns.create()` and `returns.getRma()` return an
|
|
594
|
+
* `Rma`, `returns.list()` returns `ReturnSummary` rows and `returns.get()` returns a `ReturnDetail`.
|
|
595
|
+
*/
|
|
592
596
|
interface ReturnAuthorization {
|
|
593
597
|
rmaId: string;
|
|
594
598
|
status: string;
|
|
595
599
|
returnLabel?: Label;
|
|
596
600
|
createdAt: string;
|
|
597
601
|
}
|
|
602
|
+
/** One item on an RMA or a received return. */
|
|
603
|
+
interface RmaItem {
|
|
604
|
+
sku: string;
|
|
605
|
+
description?: string | null;
|
|
606
|
+
quantity: number;
|
|
607
|
+
unitPrice?: number;
|
|
608
|
+
extendedPrice?: number;
|
|
609
|
+
reason?: string | null;
|
|
610
|
+
}
|
|
611
|
+
/** A return authorization (the Gateway `RmaDto`). `rmaNumber` names it in the label and RMA routes. */
|
|
612
|
+
interface Rma {
|
|
613
|
+
rmaNumber: string;
|
|
614
|
+
/** Numeric RMA id, used by `returns.markReceived()`. */
|
|
615
|
+
rmaId: number;
|
|
616
|
+
orderId: number;
|
|
617
|
+
orderNumber?: string | null;
|
|
618
|
+
customerEmail?: string | null;
|
|
619
|
+
status: string;
|
|
620
|
+
reason?: string | null;
|
|
621
|
+
createdAt: string;
|
|
622
|
+
items: RmaItem[];
|
|
623
|
+
itemCount: number;
|
|
624
|
+
returnLabelTrackingNumber?: string | null;
|
|
625
|
+
notes?: string | null;
|
|
626
|
+
/** Numeric return id once the RMA has been received, used by `returns.get()`. */
|
|
627
|
+
returnId?: number | null;
|
|
628
|
+
dispositionStatus?: string | null;
|
|
629
|
+
appliedRuleId?: string | null;
|
|
630
|
+
appliedRuleName?: string | null;
|
|
631
|
+
requirePhotos?: boolean;
|
|
632
|
+
keepItem?: boolean;
|
|
633
|
+
appliedFeeCents?: number;
|
|
634
|
+
}
|
|
635
|
+
/** A received return (the Gateway `ReturnDto`), as `returns.list()` lists it. */
|
|
636
|
+
interface ReturnSummary {
|
|
637
|
+
returnId: number;
|
|
638
|
+
rmaNumber?: string | null;
|
|
639
|
+
orderId: number;
|
|
640
|
+
status: string;
|
|
641
|
+
returnDate: string;
|
|
642
|
+
dispositionType?: string | null;
|
|
643
|
+
}
|
|
644
|
+
/** A received return with its items (the Gateway `ReturnDetailDto`), from `returns.get()`. */
|
|
645
|
+
interface ReturnDetail extends ReturnSummary {
|
|
646
|
+
items: RmaItem[];
|
|
647
|
+
reason?: string | null;
|
|
648
|
+
notes?: string | null;
|
|
649
|
+
trackingNumber?: string | null;
|
|
650
|
+
carrierCode?: string | null;
|
|
651
|
+
}
|
|
652
|
+
/** A return label (the Gateway `ReturnLabelDto`), from `returns.generateLabel()`. */
|
|
653
|
+
interface ReturnLabel {
|
|
654
|
+
trackingNumber?: string | null;
|
|
655
|
+
/** The label image, base64 encoded. */
|
|
656
|
+
labelData?: string | null;
|
|
657
|
+
carrierCode: string;
|
|
658
|
+
rate?: number | null;
|
|
659
|
+
success: boolean;
|
|
660
|
+
errorMessage?: string | null;
|
|
661
|
+
costPolicy?: number;
|
|
662
|
+
deductedFromRefundCents?: number | null;
|
|
663
|
+
customerPaymentRequired?: boolean;
|
|
664
|
+
}
|
|
665
|
+
/** One box in a multi-package shipment (the Gateway `PackageDetail`). */
|
|
666
|
+
interface MultiPackageDetail {
|
|
667
|
+
/** Weight in ounces, 0.1 to 999999. */
|
|
668
|
+
weightInOunces: number;
|
|
669
|
+
/** Length in inches, 0.1 to 999. */
|
|
670
|
+
lengthInInches: number;
|
|
671
|
+
/** Width in inches, 0.1 to 999. */
|
|
672
|
+
widthInInches: number;
|
|
673
|
+
/** Height in inches, 0.1 to 999. */
|
|
674
|
+
heightInInches: number;
|
|
675
|
+
deliveryConfirmationRequired?: boolean;
|
|
676
|
+
signatureConfirmationRequired?: boolean;
|
|
677
|
+
insuranceCoverageRequested?: boolean;
|
|
678
|
+
/** Coverage in USD. Needs `insuranceCoverageRequested: true`; left out, the order value is insured. */
|
|
679
|
+
insuredValue?: number;
|
|
680
|
+
/** Your label for the box, up to 100 characters (for example `Box 1 of 3`). */
|
|
681
|
+
packageReference?: string;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Body of `POST /api/shipping/multi-package` (the Gateway `MultiPackageShipmentRequest`): one order
|
|
685
|
+
* shipped in several boxes with the same carrier and service. Addresses come from the order.
|
|
686
|
+
*/
|
|
687
|
+
interface MultiPackageShipmentRequest {
|
|
688
|
+
/** The order to ship. Required and positive. */
|
|
689
|
+
orderId: number;
|
|
690
|
+
/** Carrier for every box. */
|
|
691
|
+
carrierCode: string;
|
|
692
|
+
/** Service for every box. */
|
|
693
|
+
serviceCode?: string;
|
|
694
|
+
/** Defaults to `PDF` on the Gateway. */
|
|
695
|
+
labelFormat?: 'PDF' | 'PNG' | 'ZPL';
|
|
696
|
+
/** ISO 8601 date; defaults to today. */
|
|
697
|
+
shipDate?: string;
|
|
698
|
+
/**
|
|
699
|
+
* What the shipment holds. Multi-package labels cannot carry HAZMAT yet: send `HazmatClassification.None`
|
|
700
|
+
* (0) for no dangerous goods or leave it out for no answer. The Gateway refuses any other class
|
|
701
|
+
* (400 `HazmatNotSupported`); buy those labels one at a time with `shipping.createLabel`.
|
|
702
|
+
*/
|
|
703
|
+
hazmatClassification?: typeof HazmatClassification.None;
|
|
704
|
+
/**
|
|
705
|
+
* The most the whole shipment may cost, in USD: required, positive, with at most two decimals. It covers the
|
|
706
|
+
* postage of every box. The Gateway refuses to buy a box that would take the total above it, so you never pay
|
|
707
|
+
* more: a box priced above what is left reports `PriceCeilingExceeded`, and once the amount is used up the
|
|
708
|
+
* remaining boxes report `PriceCeilingReached` and are not bought. Boxes already bought stay bought. A missing
|
|
709
|
+
* or invalid value is 400 `ApprovalRequired`. It is part of the request the `Idempotency-Key` identifies.
|
|
710
|
+
*/
|
|
711
|
+
maximumPostageAmount: number;
|
|
712
|
+
/** 1 to 99 boxes. */
|
|
713
|
+
packages: MultiPackageDetail[];
|
|
714
|
+
}
|
|
715
|
+
/** One box's outcome in a multi-package shipment (the Gateway `PackageLabelResult`). */
|
|
716
|
+
interface MultiPackageLabelResult {
|
|
717
|
+
/** Index of the box in the request, from 0. */
|
|
718
|
+
packageIndex: number;
|
|
719
|
+
packageReference?: string | null;
|
|
720
|
+
trackingNumber?: string | null;
|
|
721
|
+
rate?: number | null;
|
|
722
|
+
success: boolean;
|
|
723
|
+
errorMessage?: string | null;
|
|
724
|
+
/** Stable refusal code when the box failed. `OutcomeUnknown` means a label may exist: check before retrying. */
|
|
725
|
+
errorCode?: string | null;
|
|
726
|
+
}
|
|
727
|
+
/** The Gateway `MultiPackageShipmentResponse`. */
|
|
728
|
+
interface MultiPackageShipmentResponse {
|
|
729
|
+
orderId: number;
|
|
730
|
+
carrierCode: string;
|
|
731
|
+
totalPackages: number;
|
|
732
|
+
successfulPackages: number;
|
|
733
|
+
failedPackages: number;
|
|
734
|
+
totalCost: number;
|
|
735
|
+
labels: MultiPackageLabelResult[];
|
|
736
|
+
}
|
|
598
737
|
interface ShipmentsTrend {
|
|
599
738
|
date: string;
|
|
600
739
|
count: number;
|
|
@@ -983,7 +1122,11 @@ declare class FlexOpsError extends Error {
|
|
|
983
1122
|
readonly status: number;
|
|
984
1123
|
readonly code?: string | undefined;
|
|
985
1124
|
readonly errors?: string[] | undefined;
|
|
986
|
-
|
|
1125
|
+
/** The envelope's `data` on an error reply, when the Gateway sends one (for example a multi-package 409 or 422). */
|
|
1126
|
+
readonly data?: unknown | undefined;
|
|
1127
|
+
constructor(message: string, status: number, code?: string | undefined, errors?: string[] | undefined,
|
|
1128
|
+
/** The envelope's `data` on an error reply, when the Gateway sends one (for example a multi-package 409 or 422). */
|
|
1129
|
+
data?: unknown | undefined);
|
|
987
1130
|
}
|
|
988
1131
|
declare class FlexOpsRateLimitError extends FlexOpsError {
|
|
989
1132
|
readonly retryAfter?: number | undefined;
|
|
@@ -1110,6 +1253,24 @@ declare class ShippingResource {
|
|
|
1110
1253
|
getBatchStatus(jobId: string): Promise<ApiResponse<BatchLabelJob>>;
|
|
1111
1254
|
/** Download a label from a batch job. */
|
|
1112
1255
|
downloadBatchLabel(jobId: string, itemId: string): Promise<Response>;
|
|
1256
|
+
/**
|
|
1257
|
+
* Buy labels for one order shipped in several boxes (1 to 99) with the same carrier and service.
|
|
1258
|
+
* Every box's label slot is reserved before any label is bought; a box that fails does not stop the
|
|
1259
|
+
* others, and each box reports its own `success`, `errorMessage` and `errorCode`.
|
|
1260
|
+
*
|
|
1261
|
+
* Resolves when at least one label was bought (check `failedPackages`). When none was, the Gateway
|
|
1262
|
+
* answers 422 `AllPackagesFailed`, or 409 `OutcomeUnknown` when a box's carrier outcome is unknown and
|
|
1263
|
+
* a label may exist: both throw a `FlexOpsError` whose `data` is the `MultiPackageShipmentResponse`.
|
|
1264
|
+
* After `OutcomeUnknown`, check the order before buying again.
|
|
1265
|
+
*
|
|
1266
|
+
* `maximumPostageAmount` is required: the most the whole shipment may cost in USD. The Gateway refuses to buy
|
|
1267
|
+
* any box that would take the total above it (that box reports `PriceCeilingExceeded`; boxes after the
|
|
1268
|
+
* ceiling is used up report `PriceCeilingReached`), and a request without a valid one is 400 `ApprovalRequired`.
|
|
1269
|
+
*
|
|
1270
|
+
* `hazmatClassification` accepts only `HazmatClassification.None` or nothing. Pass a stable
|
|
1271
|
+
* `idempotencyKey` to retry safely across processes; otherwise one is generated for this call.
|
|
1272
|
+
*/
|
|
1273
|
+
createMultiPackage(request: MultiPackageShipmentRequest, idempotencyKey?: string): Promise<ApiResponse<MultiPackageShipmentResponse>>;
|
|
1113
1274
|
/** List available carriers and their services. */
|
|
1114
1275
|
getCarriers(): Promise<unknown>;
|
|
1115
1276
|
/** Get AI-ranked carrier recommendations for a lane, scored by cost, speed, and reliability. */
|
|
@@ -1636,17 +1797,30 @@ declare class ReturnsResource {
|
|
|
1636
1797
|
private readonly getWorkspaceId;
|
|
1637
1798
|
constructor(http: HttpClient, getWorkspaceId: () => string | undefined);
|
|
1638
1799
|
private wsPath;
|
|
1639
|
-
/**
|
|
1800
|
+
/**
|
|
1801
|
+
* List received returns, optionally between `startDate` and `endDate` (ISO 8601). The Gateway
|
|
1802
|
+
* defaults to the last 30 days. To list return authorizations, use `listRmas()`.
|
|
1803
|
+
*/
|
|
1640
1804
|
list(query?: {
|
|
1641
1805
|
startDate?: string;
|
|
1642
1806
|
endDate?: string;
|
|
1643
1807
|
page?: number;
|
|
1644
1808
|
pageSize?: number;
|
|
1645
|
-
}): Promise<ApiResponse<
|
|
1646
|
-
/**
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1809
|
+
}): Promise<ApiResponse<ReturnSummary[]>>;
|
|
1810
|
+
/**
|
|
1811
|
+
* Get a received return by its numeric return id (`ReturnSummary.returnId` or `Rma.returnId`).
|
|
1812
|
+
* An RMA number is not a return id: the Gateway has no route for it here. Use `getRma()`.
|
|
1813
|
+
*/
|
|
1814
|
+
get(returnId: number | string): Promise<ApiResponse<ReturnDetail>>;
|
|
1815
|
+
/** List return authorizations (RMAs), one page at a time. */
|
|
1816
|
+
listRmas(query?: {
|
|
1817
|
+
page?: number;
|
|
1818
|
+
pageSize?: number;
|
|
1819
|
+
}): Promise<ApiResponse<Rma[]>>;
|
|
1820
|
+
/** Get a return authorization by its RMA number, for example `RMA-1001`. */
|
|
1821
|
+
getRma(rmaNumber: string): Promise<ApiResponse<Rma>>;
|
|
1822
|
+
/** Create a return authorization (RMA) for an order. The Gateway answers 201 with the RMA. */
|
|
1823
|
+
create(request: ReturnRequest): Promise<ApiResponse<Rma>>;
|
|
1650
1824
|
/**
|
|
1651
1825
|
* Generate a return label for an approved RMA.
|
|
1652
1826
|
*
|
|
@@ -1655,9 +1829,9 @@ declare class ReturnsResource {
|
|
|
1655
1829
|
* shipping preset has nothing else to take the package from and the call fails with a 400 that
|
|
1656
1830
|
* names the missing fields.
|
|
1657
1831
|
*/
|
|
1658
|
-
generateLabel(rmaNumber: string, request?: ReturnLabelRequest): Promise<ApiResponse<
|
|
1659
|
-
/** Record the inspected items of a returned package at a warehouse. */
|
|
1660
|
-
markReceived(rmaId: string, request: ReceiveReturnRequest): Promise<ApiResponse<unknown>>;
|
|
1832
|
+
generateLabel(rmaNumber: string, request?: ReturnLabelRequest): Promise<ApiResponse<ReturnLabel>>;
|
|
1833
|
+
/** Record the inspected items of a returned package at a warehouse. `rmaId` is the numeric `Rma.rmaId`. */
|
|
1834
|
+
markReceived(rmaId: number | string, request: ReceiveReturnRequest): Promise<ApiResponse<unknown>>;
|
|
1661
1835
|
}
|
|
1662
1836
|
|
|
1663
1837
|
type DateRange = {
|
|
@@ -1932,8 +2106,8 @@ declare class HsCodesResource {
|
|
|
1932
2106
|
* import { FlexOps } from '@flexops/sdk';
|
|
1933
2107
|
*
|
|
1934
2108
|
* const client = new FlexOps({
|
|
1935
|
-
* apiKey: '
|
|
1936
|
-
* workspaceId: '
|
|
2109
|
+
* apiKey: 'live_...',
|
|
2110
|
+
* workspaceId: 'your-workspace-id',
|
|
1937
2111
|
* });
|
|
1938
2112
|
*
|
|
1939
2113
|
* // Get shipping rates
|
|
@@ -1999,4 +2173,4 @@ declare class FlexOps {
|
|
|
1999
2173
|
}
|
|
2000
2174
|
|
|
2001
2175
|
export { AnalyticsResource, AuthResource, CarbonOffsetsResource, CarriersResource, EmailTemplatesResource, FlexOps, FlexOpsAuthError, FlexOpsError, FlexOpsRateLimitError, HazmatClassification, HsCodesResource, InsuranceResource, InventoryResource, OrdersResource, PickupsResource, RecurrenceInterval, RecurringShipmentsResource, ReportFormat, ReportFrequency, ReportSchedulesResource, ReturnsResource, RulesResource, ScanFormsResource, ShippingResource, TrackingEmailEvent, WalletResource, WebhookEventType, WebhooksResource, WorkspaceRole, WorkspacesResource };
|
|
2002
|
-
export type { Address, AddressValidationResult, ApiResponse, BatchLabelItem, BatchLabelItemResult, BatchLabelJob, BatchLabelRequest, CanonicalLabelRequest, CanonicalRateRequest, CarbonOffset, CarbonOffsetPurchaseRequest, CarbonOffsetQuote, CarbonOffsetQuoteRequest, CarbonOffsetSettings, CarbonOffsetSummary, CarrierRecommendation, CarrierRecommendationRequest, CarrierRecommendationResponse, CarrierSummary, CostSavingsSummary, CreateBatchLabelRequest, CreateLabelRequest, CreateRecurringShipmentRequest, CreateReportScheduleRequest, CreateWebhookRequest, CustomsItem, DeliveryPredictionRequest, DeliveryPredictionResponse, EmailTemplate, EmailTemplatePreview, EmailTemplatePreviewRequest, FileClaimRequest, FlexOpsConfig, HsCodeResult, InsuranceClaim, InsurancePolicy, InsuranceQuote, InsuranceQuoteRequest, Label, LabelPurchaseApproval, LabelPurchasePreview, LandedCostEstimate, LandedCostRequest, LaneSavingsOpportunity, LegacyRateRequest, LoginRequest, LoginResponse, Order, OrderItem, PaginatedResponse, Parcel, PendingInvite, PickupConfirmation, PickupRequest, PurchaseInsuranceRequest, RateRequest, ReceiveReturnRequest, RecurringShipment, ReportSchedule, RetryConfig, ReturnAuthorization, ReturnDisposition, ReturnItem, ReturnLabelRequest, ReturnRequest, RuleAction, RuleCondition, ScanForm, ScanFormRequest, ShipmentsTrend, ShippingAddress, ShippingPackage, ShippingRate, ShippingRule, ShippingRuleInput, ShippingRuleTestRequest, SuggestedAddress, TrackingEvent, TrackingInfo, UpdateRecurringShipmentRequest, UpdateReportScheduleRequest, UpdateWebhookRequest, UpsertEmailTemplateRequest, VerifySignatureOptions, WalletBalance, WebhookSubscription, Workspace, WorkspaceDetail, WorkspaceMember, WorkspaceMemberList };
|
|
2176
|
+
export type { Address, AddressValidationResult, ApiResponse, BatchLabelItem, BatchLabelItemResult, BatchLabelJob, BatchLabelRequest, CanonicalLabelRequest, CanonicalRateRequest, CarbonOffset, CarbonOffsetPurchaseRequest, CarbonOffsetQuote, CarbonOffsetQuoteRequest, CarbonOffsetSettings, CarbonOffsetSummary, CarrierRecommendation, CarrierRecommendationRequest, CarrierRecommendationResponse, CarrierSummary, CostSavingsSummary, CreateBatchLabelRequest, CreateLabelRequest, CreateRecurringShipmentRequest, CreateReportScheduleRequest, CreateWebhookRequest, CustomsItem, DeliveryPredictionRequest, DeliveryPredictionResponse, EmailTemplate, EmailTemplatePreview, EmailTemplatePreviewRequest, FileClaimRequest, FlexOpsConfig, HsCodeResult, InsuranceClaim, InsurancePolicy, InsuranceQuote, InsuranceQuoteRequest, Label, LabelPurchaseApproval, LabelPurchasePreview, LandedCostEstimate, LandedCostRequest, LaneSavingsOpportunity, LegacyRateRequest, LoginRequest, LoginResponse, MultiPackageDetail, MultiPackageLabelResult, MultiPackageShipmentRequest, MultiPackageShipmentResponse, Order, OrderItem, PaginatedResponse, Parcel, PendingInvite, PickupConfirmation, PickupRequest, PurchaseInsuranceRequest, RateRequest, ReceiveReturnRequest, RecurringShipment, ReportSchedule, RetryConfig, ReturnAuthorization, ReturnDetail, ReturnDisposition, ReturnItem, ReturnLabel, ReturnLabelRequest, ReturnRequest, ReturnSummary, Rma, RmaItem, RuleAction, RuleCondition, ScanForm, ScanFormRequest, ShipmentsTrend, ShippingAddress, ShippingPackage, ShippingRate, ShippingRule, ShippingRuleInput, ShippingRuleTestRequest, SuggestedAddress, TrackingEvent, TrackingInfo, UpdateRecurringShipmentRequest, UpdateReportScheduleRequest, UpdateWebhookRequest, UpsertEmailTemplateRequest, VerifySignatureOptions, WalletBalance, WebhookSubscription, Workspace, WorkspaceDetail, WorkspaceMember, WorkspaceMemberList };
|
package/dist/index.d.ts
CHANGED
|
@@ -575,7 +575,7 @@ interface ReturnLabelRequest {
|
|
|
575
575
|
/** USPS rate indicator for the return label's price tier. */
|
|
576
576
|
rateIndicator?: string;
|
|
577
577
|
}
|
|
578
|
-
/** How a received item is dispositioned: 0 restock, 1
|
|
578
|
+
/** How a received item is dispositioned: 0 restock, 1 dispose, 2 forward. */
|
|
579
579
|
type ReturnDisposition = 0 | 1 | 2;
|
|
580
580
|
/** Body of `POST /api/workspaces/{workspaceId}/returns/{rmaId}/receive`. */
|
|
581
581
|
interface ReceiveReturnRequest {
|
|
@@ -589,12 +589,151 @@ interface ReceiveReturnRequest {
|
|
|
589
589
|
inspectionNotes?: string;
|
|
590
590
|
}[];
|
|
591
591
|
}
|
|
592
|
+
/**
|
|
593
|
+
* @deprecated No Gateway route returns this shape. `returns.create()` and `returns.getRma()` return an
|
|
594
|
+
* `Rma`, `returns.list()` returns `ReturnSummary` rows and `returns.get()` returns a `ReturnDetail`.
|
|
595
|
+
*/
|
|
592
596
|
interface ReturnAuthorization {
|
|
593
597
|
rmaId: string;
|
|
594
598
|
status: string;
|
|
595
599
|
returnLabel?: Label;
|
|
596
600
|
createdAt: string;
|
|
597
601
|
}
|
|
602
|
+
/** One item on an RMA or a received return. */
|
|
603
|
+
interface RmaItem {
|
|
604
|
+
sku: string;
|
|
605
|
+
description?: string | null;
|
|
606
|
+
quantity: number;
|
|
607
|
+
unitPrice?: number;
|
|
608
|
+
extendedPrice?: number;
|
|
609
|
+
reason?: string | null;
|
|
610
|
+
}
|
|
611
|
+
/** A return authorization (the Gateway `RmaDto`). `rmaNumber` names it in the label and RMA routes. */
|
|
612
|
+
interface Rma {
|
|
613
|
+
rmaNumber: string;
|
|
614
|
+
/** Numeric RMA id, used by `returns.markReceived()`. */
|
|
615
|
+
rmaId: number;
|
|
616
|
+
orderId: number;
|
|
617
|
+
orderNumber?: string | null;
|
|
618
|
+
customerEmail?: string | null;
|
|
619
|
+
status: string;
|
|
620
|
+
reason?: string | null;
|
|
621
|
+
createdAt: string;
|
|
622
|
+
items: RmaItem[];
|
|
623
|
+
itemCount: number;
|
|
624
|
+
returnLabelTrackingNumber?: string | null;
|
|
625
|
+
notes?: string | null;
|
|
626
|
+
/** Numeric return id once the RMA has been received, used by `returns.get()`. */
|
|
627
|
+
returnId?: number | null;
|
|
628
|
+
dispositionStatus?: string | null;
|
|
629
|
+
appliedRuleId?: string | null;
|
|
630
|
+
appliedRuleName?: string | null;
|
|
631
|
+
requirePhotos?: boolean;
|
|
632
|
+
keepItem?: boolean;
|
|
633
|
+
appliedFeeCents?: number;
|
|
634
|
+
}
|
|
635
|
+
/** A received return (the Gateway `ReturnDto`), as `returns.list()` lists it. */
|
|
636
|
+
interface ReturnSummary {
|
|
637
|
+
returnId: number;
|
|
638
|
+
rmaNumber?: string | null;
|
|
639
|
+
orderId: number;
|
|
640
|
+
status: string;
|
|
641
|
+
returnDate: string;
|
|
642
|
+
dispositionType?: string | null;
|
|
643
|
+
}
|
|
644
|
+
/** A received return with its items (the Gateway `ReturnDetailDto`), from `returns.get()`. */
|
|
645
|
+
interface ReturnDetail extends ReturnSummary {
|
|
646
|
+
items: RmaItem[];
|
|
647
|
+
reason?: string | null;
|
|
648
|
+
notes?: string | null;
|
|
649
|
+
trackingNumber?: string | null;
|
|
650
|
+
carrierCode?: string | null;
|
|
651
|
+
}
|
|
652
|
+
/** A return label (the Gateway `ReturnLabelDto`), from `returns.generateLabel()`. */
|
|
653
|
+
interface ReturnLabel {
|
|
654
|
+
trackingNumber?: string | null;
|
|
655
|
+
/** The label image, base64 encoded. */
|
|
656
|
+
labelData?: string | null;
|
|
657
|
+
carrierCode: string;
|
|
658
|
+
rate?: number | null;
|
|
659
|
+
success: boolean;
|
|
660
|
+
errorMessage?: string | null;
|
|
661
|
+
costPolicy?: number;
|
|
662
|
+
deductedFromRefundCents?: number | null;
|
|
663
|
+
customerPaymentRequired?: boolean;
|
|
664
|
+
}
|
|
665
|
+
/** One box in a multi-package shipment (the Gateway `PackageDetail`). */
|
|
666
|
+
interface MultiPackageDetail {
|
|
667
|
+
/** Weight in ounces, 0.1 to 999999. */
|
|
668
|
+
weightInOunces: number;
|
|
669
|
+
/** Length in inches, 0.1 to 999. */
|
|
670
|
+
lengthInInches: number;
|
|
671
|
+
/** Width in inches, 0.1 to 999. */
|
|
672
|
+
widthInInches: number;
|
|
673
|
+
/** Height in inches, 0.1 to 999. */
|
|
674
|
+
heightInInches: number;
|
|
675
|
+
deliveryConfirmationRequired?: boolean;
|
|
676
|
+
signatureConfirmationRequired?: boolean;
|
|
677
|
+
insuranceCoverageRequested?: boolean;
|
|
678
|
+
/** Coverage in USD. Needs `insuranceCoverageRequested: true`; left out, the order value is insured. */
|
|
679
|
+
insuredValue?: number;
|
|
680
|
+
/** Your label for the box, up to 100 characters (for example `Box 1 of 3`). */
|
|
681
|
+
packageReference?: string;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Body of `POST /api/shipping/multi-package` (the Gateway `MultiPackageShipmentRequest`): one order
|
|
685
|
+
* shipped in several boxes with the same carrier and service. Addresses come from the order.
|
|
686
|
+
*/
|
|
687
|
+
interface MultiPackageShipmentRequest {
|
|
688
|
+
/** The order to ship. Required and positive. */
|
|
689
|
+
orderId: number;
|
|
690
|
+
/** Carrier for every box. */
|
|
691
|
+
carrierCode: string;
|
|
692
|
+
/** Service for every box. */
|
|
693
|
+
serviceCode?: string;
|
|
694
|
+
/** Defaults to `PDF` on the Gateway. */
|
|
695
|
+
labelFormat?: 'PDF' | 'PNG' | 'ZPL';
|
|
696
|
+
/** ISO 8601 date; defaults to today. */
|
|
697
|
+
shipDate?: string;
|
|
698
|
+
/**
|
|
699
|
+
* What the shipment holds. Multi-package labels cannot carry HAZMAT yet: send `HazmatClassification.None`
|
|
700
|
+
* (0) for no dangerous goods or leave it out for no answer. The Gateway refuses any other class
|
|
701
|
+
* (400 `HazmatNotSupported`); buy those labels one at a time with `shipping.createLabel`.
|
|
702
|
+
*/
|
|
703
|
+
hazmatClassification?: typeof HazmatClassification.None;
|
|
704
|
+
/**
|
|
705
|
+
* The most the whole shipment may cost, in USD: required, positive, with at most two decimals. It covers the
|
|
706
|
+
* postage of every box. The Gateway refuses to buy a box that would take the total above it, so you never pay
|
|
707
|
+
* more: a box priced above what is left reports `PriceCeilingExceeded`, and once the amount is used up the
|
|
708
|
+
* remaining boxes report `PriceCeilingReached` and are not bought. Boxes already bought stay bought. A missing
|
|
709
|
+
* or invalid value is 400 `ApprovalRequired`. It is part of the request the `Idempotency-Key` identifies.
|
|
710
|
+
*/
|
|
711
|
+
maximumPostageAmount: number;
|
|
712
|
+
/** 1 to 99 boxes. */
|
|
713
|
+
packages: MultiPackageDetail[];
|
|
714
|
+
}
|
|
715
|
+
/** One box's outcome in a multi-package shipment (the Gateway `PackageLabelResult`). */
|
|
716
|
+
interface MultiPackageLabelResult {
|
|
717
|
+
/** Index of the box in the request, from 0. */
|
|
718
|
+
packageIndex: number;
|
|
719
|
+
packageReference?: string | null;
|
|
720
|
+
trackingNumber?: string | null;
|
|
721
|
+
rate?: number | null;
|
|
722
|
+
success: boolean;
|
|
723
|
+
errorMessage?: string | null;
|
|
724
|
+
/** Stable refusal code when the box failed. `OutcomeUnknown` means a label may exist: check before retrying. */
|
|
725
|
+
errorCode?: string | null;
|
|
726
|
+
}
|
|
727
|
+
/** The Gateway `MultiPackageShipmentResponse`. */
|
|
728
|
+
interface MultiPackageShipmentResponse {
|
|
729
|
+
orderId: number;
|
|
730
|
+
carrierCode: string;
|
|
731
|
+
totalPackages: number;
|
|
732
|
+
successfulPackages: number;
|
|
733
|
+
failedPackages: number;
|
|
734
|
+
totalCost: number;
|
|
735
|
+
labels: MultiPackageLabelResult[];
|
|
736
|
+
}
|
|
598
737
|
interface ShipmentsTrend {
|
|
599
738
|
date: string;
|
|
600
739
|
count: number;
|
|
@@ -983,7 +1122,11 @@ declare class FlexOpsError extends Error {
|
|
|
983
1122
|
readonly status: number;
|
|
984
1123
|
readonly code?: string | undefined;
|
|
985
1124
|
readonly errors?: string[] | undefined;
|
|
986
|
-
|
|
1125
|
+
/** The envelope's `data` on an error reply, when the Gateway sends one (for example a multi-package 409 or 422). */
|
|
1126
|
+
readonly data?: unknown | undefined;
|
|
1127
|
+
constructor(message: string, status: number, code?: string | undefined, errors?: string[] | undefined,
|
|
1128
|
+
/** The envelope's `data` on an error reply, when the Gateway sends one (for example a multi-package 409 or 422). */
|
|
1129
|
+
data?: unknown | undefined);
|
|
987
1130
|
}
|
|
988
1131
|
declare class FlexOpsRateLimitError extends FlexOpsError {
|
|
989
1132
|
readonly retryAfter?: number | undefined;
|
|
@@ -1110,6 +1253,24 @@ declare class ShippingResource {
|
|
|
1110
1253
|
getBatchStatus(jobId: string): Promise<ApiResponse<BatchLabelJob>>;
|
|
1111
1254
|
/** Download a label from a batch job. */
|
|
1112
1255
|
downloadBatchLabel(jobId: string, itemId: string): Promise<Response>;
|
|
1256
|
+
/**
|
|
1257
|
+
* Buy labels for one order shipped in several boxes (1 to 99) with the same carrier and service.
|
|
1258
|
+
* Every box's label slot is reserved before any label is bought; a box that fails does not stop the
|
|
1259
|
+
* others, and each box reports its own `success`, `errorMessage` and `errorCode`.
|
|
1260
|
+
*
|
|
1261
|
+
* Resolves when at least one label was bought (check `failedPackages`). When none was, the Gateway
|
|
1262
|
+
* answers 422 `AllPackagesFailed`, or 409 `OutcomeUnknown` when a box's carrier outcome is unknown and
|
|
1263
|
+
* a label may exist: both throw a `FlexOpsError` whose `data` is the `MultiPackageShipmentResponse`.
|
|
1264
|
+
* After `OutcomeUnknown`, check the order before buying again.
|
|
1265
|
+
*
|
|
1266
|
+
* `maximumPostageAmount` is required: the most the whole shipment may cost in USD. The Gateway refuses to buy
|
|
1267
|
+
* any box that would take the total above it (that box reports `PriceCeilingExceeded`; boxes after the
|
|
1268
|
+
* ceiling is used up report `PriceCeilingReached`), and a request without a valid one is 400 `ApprovalRequired`.
|
|
1269
|
+
*
|
|
1270
|
+
* `hazmatClassification` accepts only `HazmatClassification.None` or nothing. Pass a stable
|
|
1271
|
+
* `idempotencyKey` to retry safely across processes; otherwise one is generated for this call.
|
|
1272
|
+
*/
|
|
1273
|
+
createMultiPackage(request: MultiPackageShipmentRequest, idempotencyKey?: string): Promise<ApiResponse<MultiPackageShipmentResponse>>;
|
|
1113
1274
|
/** List available carriers and their services. */
|
|
1114
1275
|
getCarriers(): Promise<unknown>;
|
|
1115
1276
|
/** Get AI-ranked carrier recommendations for a lane, scored by cost, speed, and reliability. */
|
|
@@ -1636,17 +1797,30 @@ declare class ReturnsResource {
|
|
|
1636
1797
|
private readonly getWorkspaceId;
|
|
1637
1798
|
constructor(http: HttpClient, getWorkspaceId: () => string | undefined);
|
|
1638
1799
|
private wsPath;
|
|
1639
|
-
/**
|
|
1800
|
+
/**
|
|
1801
|
+
* List received returns, optionally between `startDate` and `endDate` (ISO 8601). The Gateway
|
|
1802
|
+
* defaults to the last 30 days. To list return authorizations, use `listRmas()`.
|
|
1803
|
+
*/
|
|
1640
1804
|
list(query?: {
|
|
1641
1805
|
startDate?: string;
|
|
1642
1806
|
endDate?: string;
|
|
1643
1807
|
page?: number;
|
|
1644
1808
|
pageSize?: number;
|
|
1645
|
-
}): Promise<ApiResponse<
|
|
1646
|
-
/**
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1809
|
+
}): Promise<ApiResponse<ReturnSummary[]>>;
|
|
1810
|
+
/**
|
|
1811
|
+
* Get a received return by its numeric return id (`ReturnSummary.returnId` or `Rma.returnId`).
|
|
1812
|
+
* An RMA number is not a return id: the Gateway has no route for it here. Use `getRma()`.
|
|
1813
|
+
*/
|
|
1814
|
+
get(returnId: number | string): Promise<ApiResponse<ReturnDetail>>;
|
|
1815
|
+
/** List return authorizations (RMAs), one page at a time. */
|
|
1816
|
+
listRmas(query?: {
|
|
1817
|
+
page?: number;
|
|
1818
|
+
pageSize?: number;
|
|
1819
|
+
}): Promise<ApiResponse<Rma[]>>;
|
|
1820
|
+
/** Get a return authorization by its RMA number, for example `RMA-1001`. */
|
|
1821
|
+
getRma(rmaNumber: string): Promise<ApiResponse<Rma>>;
|
|
1822
|
+
/** Create a return authorization (RMA) for an order. The Gateway answers 201 with the RMA. */
|
|
1823
|
+
create(request: ReturnRequest): Promise<ApiResponse<Rma>>;
|
|
1650
1824
|
/**
|
|
1651
1825
|
* Generate a return label for an approved RMA.
|
|
1652
1826
|
*
|
|
@@ -1655,9 +1829,9 @@ declare class ReturnsResource {
|
|
|
1655
1829
|
* shipping preset has nothing else to take the package from and the call fails with a 400 that
|
|
1656
1830
|
* names the missing fields.
|
|
1657
1831
|
*/
|
|
1658
|
-
generateLabel(rmaNumber: string, request?: ReturnLabelRequest): Promise<ApiResponse<
|
|
1659
|
-
/** Record the inspected items of a returned package at a warehouse. */
|
|
1660
|
-
markReceived(rmaId: string, request: ReceiveReturnRequest): Promise<ApiResponse<unknown>>;
|
|
1832
|
+
generateLabel(rmaNumber: string, request?: ReturnLabelRequest): Promise<ApiResponse<ReturnLabel>>;
|
|
1833
|
+
/** Record the inspected items of a returned package at a warehouse. `rmaId` is the numeric `Rma.rmaId`. */
|
|
1834
|
+
markReceived(rmaId: number | string, request: ReceiveReturnRequest): Promise<ApiResponse<unknown>>;
|
|
1661
1835
|
}
|
|
1662
1836
|
|
|
1663
1837
|
type DateRange = {
|
|
@@ -1932,8 +2106,8 @@ declare class HsCodesResource {
|
|
|
1932
2106
|
* import { FlexOps } from '@flexops/sdk';
|
|
1933
2107
|
*
|
|
1934
2108
|
* const client = new FlexOps({
|
|
1935
|
-
* apiKey: '
|
|
1936
|
-
* workspaceId: '
|
|
2109
|
+
* apiKey: 'live_...',
|
|
2110
|
+
* workspaceId: 'your-workspace-id',
|
|
1937
2111
|
* });
|
|
1938
2112
|
*
|
|
1939
2113
|
* // Get shipping rates
|
|
@@ -1999,4 +2173,4 @@ declare class FlexOps {
|
|
|
1999
2173
|
}
|
|
2000
2174
|
|
|
2001
2175
|
export { AnalyticsResource, AuthResource, CarbonOffsetsResource, CarriersResource, EmailTemplatesResource, FlexOps, FlexOpsAuthError, FlexOpsError, FlexOpsRateLimitError, HazmatClassification, HsCodesResource, InsuranceResource, InventoryResource, OrdersResource, PickupsResource, RecurrenceInterval, RecurringShipmentsResource, ReportFormat, ReportFrequency, ReportSchedulesResource, ReturnsResource, RulesResource, ScanFormsResource, ShippingResource, TrackingEmailEvent, WalletResource, WebhookEventType, WebhooksResource, WorkspaceRole, WorkspacesResource };
|
|
2002
|
-
export type { Address, AddressValidationResult, ApiResponse, BatchLabelItem, BatchLabelItemResult, BatchLabelJob, BatchLabelRequest, CanonicalLabelRequest, CanonicalRateRequest, CarbonOffset, CarbonOffsetPurchaseRequest, CarbonOffsetQuote, CarbonOffsetQuoteRequest, CarbonOffsetSettings, CarbonOffsetSummary, CarrierRecommendation, CarrierRecommendationRequest, CarrierRecommendationResponse, CarrierSummary, CostSavingsSummary, CreateBatchLabelRequest, CreateLabelRequest, CreateRecurringShipmentRequest, CreateReportScheduleRequest, CreateWebhookRequest, CustomsItem, DeliveryPredictionRequest, DeliveryPredictionResponse, EmailTemplate, EmailTemplatePreview, EmailTemplatePreviewRequest, FileClaimRequest, FlexOpsConfig, HsCodeResult, InsuranceClaim, InsurancePolicy, InsuranceQuote, InsuranceQuoteRequest, Label, LabelPurchaseApproval, LabelPurchasePreview, LandedCostEstimate, LandedCostRequest, LaneSavingsOpportunity, LegacyRateRequest, LoginRequest, LoginResponse, Order, OrderItem, PaginatedResponse, Parcel, PendingInvite, PickupConfirmation, PickupRequest, PurchaseInsuranceRequest, RateRequest, ReceiveReturnRequest, RecurringShipment, ReportSchedule, RetryConfig, ReturnAuthorization, ReturnDisposition, ReturnItem, ReturnLabelRequest, ReturnRequest, RuleAction, RuleCondition, ScanForm, ScanFormRequest, ShipmentsTrend, ShippingAddress, ShippingPackage, ShippingRate, ShippingRule, ShippingRuleInput, ShippingRuleTestRequest, SuggestedAddress, TrackingEvent, TrackingInfo, UpdateRecurringShipmentRequest, UpdateReportScheduleRequest, UpdateWebhookRequest, UpsertEmailTemplateRequest, VerifySignatureOptions, WalletBalance, WebhookSubscription, Workspace, WorkspaceDetail, WorkspaceMember, WorkspaceMemberList };
|
|
2176
|
+
export type { Address, AddressValidationResult, ApiResponse, BatchLabelItem, BatchLabelItemResult, BatchLabelJob, BatchLabelRequest, CanonicalLabelRequest, CanonicalRateRequest, CarbonOffset, CarbonOffsetPurchaseRequest, CarbonOffsetQuote, CarbonOffsetQuoteRequest, CarbonOffsetSettings, CarbonOffsetSummary, CarrierRecommendation, CarrierRecommendationRequest, CarrierRecommendationResponse, CarrierSummary, CostSavingsSummary, CreateBatchLabelRequest, CreateLabelRequest, CreateRecurringShipmentRequest, CreateReportScheduleRequest, CreateWebhookRequest, CustomsItem, DeliveryPredictionRequest, DeliveryPredictionResponse, EmailTemplate, EmailTemplatePreview, EmailTemplatePreviewRequest, FileClaimRequest, FlexOpsConfig, HsCodeResult, InsuranceClaim, InsurancePolicy, InsuranceQuote, InsuranceQuoteRequest, Label, LabelPurchaseApproval, LabelPurchasePreview, LandedCostEstimate, LandedCostRequest, LaneSavingsOpportunity, LegacyRateRequest, LoginRequest, LoginResponse, MultiPackageDetail, MultiPackageLabelResult, MultiPackageShipmentRequest, MultiPackageShipmentResponse, Order, OrderItem, PaginatedResponse, Parcel, PendingInvite, PickupConfirmation, PickupRequest, PurchaseInsuranceRequest, RateRequest, ReceiveReturnRequest, RecurringShipment, ReportSchedule, RetryConfig, ReturnAuthorization, ReturnDetail, ReturnDisposition, ReturnItem, ReturnLabel, ReturnLabelRequest, ReturnRequest, ReturnSummary, Rma, RmaItem, RuleAction, RuleCondition, ScanForm, ScanFormRequest, ShipmentsTrend, ShippingAddress, ShippingPackage, ShippingRate, ShippingRule, ShippingRuleInput, ShippingRuleTestRequest, SuggestedAddress, TrackingEvent, TrackingInfo, UpdateRecurringShipmentRequest, UpdateReportScheduleRequest, UpdateWebhookRequest, UpsertEmailTemplateRequest, VerifySignatureOptions, WalletBalance, WebhookSubscription, Workspace, WorkspaceDetail, WorkspaceMember, WorkspaceMemberList };
|
package/dist/index.js
CHANGED
|
@@ -101,16 +101,18 @@ var TrackingEmailEvent = {
|
|
|
101
101
|
ReturnToSender: 5
|
|
102
102
|
};
|
|
103
103
|
var FlexOpsError = class extends Error {
|
|
104
|
-
constructor(message, status, code, errors) {
|
|
104
|
+
constructor(message, status, code, errors, data) {
|
|
105
105
|
super(message);
|
|
106
106
|
this.status = status;
|
|
107
107
|
this.code = code;
|
|
108
108
|
this.errors = errors;
|
|
109
|
+
this.data = data;
|
|
109
110
|
this.name = "FlexOpsError";
|
|
110
111
|
}
|
|
111
112
|
status;
|
|
112
113
|
code;
|
|
113
114
|
errors;
|
|
115
|
+
data;
|
|
114
116
|
};
|
|
115
117
|
var FlexOpsRateLimitError = class extends FlexOpsError {
|
|
116
118
|
constructor(message, retryAfter) {
|
|
@@ -243,7 +245,8 @@ var HttpClient = class {
|
|
|
243
245
|
errorBody.message ?? `HTTP ${response.status}: ${response.statusText}`,
|
|
244
246
|
response.status,
|
|
245
247
|
code ?? (response.status === 403 ? "FORBIDDEN" : void 0),
|
|
246
|
-
errorBody.errors
|
|
248
|
+
errorBody.errors,
|
|
249
|
+
errorBody.data ?? void 0
|
|
247
250
|
);
|
|
248
251
|
if (this.isRetryable(verb, response.status, code)) {
|
|
249
252
|
lastError = error;
|
|
@@ -513,6 +516,32 @@ var ShippingResource = class {
|
|
|
513
516
|
return this.http.get(this.wsPath(`labels/batch/${jobId}/items/${itemId}/label`));
|
|
514
517
|
}
|
|
515
518
|
// -----------------------------------------------------------------------
|
|
519
|
+
// Multi-Package Labels
|
|
520
|
+
// -----------------------------------------------------------------------
|
|
521
|
+
/**
|
|
522
|
+
* Buy labels for one order shipped in several boxes (1 to 99) with the same carrier and service.
|
|
523
|
+
* Every box's label slot is reserved before any label is bought; a box that fails does not stop the
|
|
524
|
+
* others, and each box reports its own `success`, `errorMessage` and `errorCode`.
|
|
525
|
+
*
|
|
526
|
+
* Resolves when at least one label was bought (check `failedPackages`). When none was, the Gateway
|
|
527
|
+
* answers 422 `AllPackagesFailed`, or 409 `OutcomeUnknown` when a box's carrier outcome is unknown and
|
|
528
|
+
* a label may exist: both throw a `FlexOpsError` whose `data` is the `MultiPackageShipmentResponse`.
|
|
529
|
+
* After `OutcomeUnknown`, check the order before buying again.
|
|
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
|
+
*
|
|
535
|
+
* `hazmatClassification` accepts only `HazmatClassification.None` or nothing. Pass a stable
|
|
536
|
+
* `idempotencyKey` to retry safely across processes; otherwise one is generated for this call.
|
|
537
|
+
*/
|
|
538
|
+
async createMultiPackage(request, idempotencyKey) {
|
|
539
|
+
return this.http.request("POST", "/api/shipping/multi-package", {
|
|
540
|
+
body: request,
|
|
541
|
+
...idempotencyKey ? { headers: { "Idempotency-Key": idempotencyKey } } : {}
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
// -----------------------------------------------------------------------
|
|
516
545
|
// Carriers
|
|
517
546
|
// -----------------------------------------------------------------------
|
|
518
547
|
/** List available carriers and their services. */
|
|
@@ -1203,18 +1232,32 @@ var ReturnsResource = class {
|
|
|
1203
1232
|
if (!id) throw new Error("workspaceId is required.");
|
|
1204
1233
|
return `/api/workspaces/${id}/returns${suffix ? `/${suffix}` : ""}`;
|
|
1205
1234
|
}
|
|
1206
|
-
/**
|
|
1235
|
+
/**
|
|
1236
|
+
* List received returns, optionally between `startDate` and `endDate` (ISO 8601). The Gateway
|
|
1237
|
+
* defaults to the last 30 days. To list return authorizations, use `listRmas()`.
|
|
1238
|
+
*/
|
|
1207
1239
|
async list(query) {
|
|
1208
1240
|
return this.http.get(
|
|
1209
1241
|
this.wsPath(""),
|
|
1210
1242
|
query
|
|
1211
1243
|
);
|
|
1212
1244
|
}
|
|
1213
|
-
/**
|
|
1245
|
+
/**
|
|
1246
|
+
* Get a received return by its numeric return id (`ReturnSummary.returnId` or `Rma.returnId`).
|
|
1247
|
+
* An RMA number is not a return id: the Gateway has no route for it here. Use `getRma()`.
|
|
1248
|
+
*/
|
|
1214
1249
|
async get(returnId) {
|
|
1215
|
-
return this.http.get(this.wsPath(returnId));
|
|
1250
|
+
return this.http.get(this.wsPath(String(returnId)));
|
|
1251
|
+
}
|
|
1252
|
+
/** List return authorizations (RMAs), one page at a time. */
|
|
1253
|
+
async listRmas(query) {
|
|
1254
|
+
return this.http.get(this.wsPath("rma"), query);
|
|
1255
|
+
}
|
|
1256
|
+
/** Get a return authorization by its RMA number, for example `RMA-1001`. */
|
|
1257
|
+
async getRma(rmaNumber) {
|
|
1258
|
+
return this.http.get(this.wsPath(`rma/${encodeURIComponent(rmaNumber)}`));
|
|
1216
1259
|
}
|
|
1217
|
-
/** Create a return authorization (RMA) for an order. */
|
|
1260
|
+
/** Create a return authorization (RMA) for an order. The Gateway answers 201 with the RMA. */
|
|
1218
1261
|
async create(request) {
|
|
1219
1262
|
return this.http.post(this.wsPath("rma"), request);
|
|
1220
1263
|
}
|
|
@@ -1229,7 +1272,7 @@ var ReturnsResource = class {
|
|
|
1229
1272
|
async generateLabel(rmaNumber, request = {}) {
|
|
1230
1273
|
return this.http.post(this.wsPath(`${rmaNumber}/label`), request);
|
|
1231
1274
|
}
|
|
1232
|
-
/** Record the inspected items of a returned package at a warehouse. */
|
|
1275
|
+
/** Record the inspected items of a returned package at a warehouse. `rmaId` is the numeric `Rma.rmaId`. */
|
|
1233
1276
|
async markReceived(rmaId, request) {
|
|
1234
1277
|
return this.http.post(this.wsPath(`${rmaId}/receive`), request);
|
|
1235
1278
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -53,16 +53,18 @@ var TrackingEmailEvent = {
|
|
|
53
53
|
ReturnToSender: 5
|
|
54
54
|
};
|
|
55
55
|
var FlexOpsError = class extends Error {
|
|
56
|
-
constructor(message, status, code, errors) {
|
|
56
|
+
constructor(message, status, code, errors, data) {
|
|
57
57
|
super(message);
|
|
58
58
|
this.status = status;
|
|
59
59
|
this.code = code;
|
|
60
60
|
this.errors = errors;
|
|
61
|
+
this.data = data;
|
|
61
62
|
this.name = "FlexOpsError";
|
|
62
63
|
}
|
|
63
64
|
status;
|
|
64
65
|
code;
|
|
65
66
|
errors;
|
|
67
|
+
data;
|
|
66
68
|
};
|
|
67
69
|
var FlexOpsRateLimitError = class extends FlexOpsError {
|
|
68
70
|
constructor(message, retryAfter) {
|
|
@@ -195,7 +197,8 @@ var HttpClient = class {
|
|
|
195
197
|
errorBody.message ?? `HTTP ${response.status}: ${response.statusText}`,
|
|
196
198
|
response.status,
|
|
197
199
|
code ?? (response.status === 403 ? "FORBIDDEN" : void 0),
|
|
198
|
-
errorBody.errors
|
|
200
|
+
errorBody.errors,
|
|
201
|
+
errorBody.data ?? void 0
|
|
199
202
|
);
|
|
200
203
|
if (this.isRetryable(verb, response.status, code)) {
|
|
201
204
|
lastError = error;
|
|
@@ -465,6 +468,32 @@ var ShippingResource = class {
|
|
|
465
468
|
return this.http.get(this.wsPath(`labels/batch/${jobId}/items/${itemId}/label`));
|
|
466
469
|
}
|
|
467
470
|
// -----------------------------------------------------------------------
|
|
471
|
+
// Multi-Package Labels
|
|
472
|
+
// -----------------------------------------------------------------------
|
|
473
|
+
/**
|
|
474
|
+
* Buy labels for one order shipped in several boxes (1 to 99) with the same carrier and service.
|
|
475
|
+
* Every box's label slot is reserved before any label is bought; a box that fails does not stop the
|
|
476
|
+
* others, and each box reports its own `success`, `errorMessage` and `errorCode`.
|
|
477
|
+
*
|
|
478
|
+
* Resolves when at least one label was bought (check `failedPackages`). When none was, the Gateway
|
|
479
|
+
* answers 422 `AllPackagesFailed`, or 409 `OutcomeUnknown` when a box's carrier outcome is unknown and
|
|
480
|
+
* a label may exist: both throw a `FlexOpsError` whose `data` is the `MultiPackageShipmentResponse`.
|
|
481
|
+
* After `OutcomeUnknown`, check the order before buying again.
|
|
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
|
+
*
|
|
487
|
+
* `hazmatClassification` accepts only `HazmatClassification.None` or nothing. Pass a stable
|
|
488
|
+
* `idempotencyKey` to retry safely across processes; otherwise one is generated for this call.
|
|
489
|
+
*/
|
|
490
|
+
async createMultiPackage(request, idempotencyKey) {
|
|
491
|
+
return this.http.request("POST", "/api/shipping/multi-package", {
|
|
492
|
+
body: request,
|
|
493
|
+
...idempotencyKey ? { headers: { "Idempotency-Key": idempotencyKey } } : {}
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
// -----------------------------------------------------------------------
|
|
468
497
|
// Carriers
|
|
469
498
|
// -----------------------------------------------------------------------
|
|
470
499
|
/** List available carriers and their services. */
|
|
@@ -1155,18 +1184,32 @@ var ReturnsResource = class {
|
|
|
1155
1184
|
if (!id) throw new Error("workspaceId is required.");
|
|
1156
1185
|
return `/api/workspaces/${id}/returns${suffix ? `/${suffix}` : ""}`;
|
|
1157
1186
|
}
|
|
1158
|
-
/**
|
|
1187
|
+
/**
|
|
1188
|
+
* List received returns, optionally between `startDate` and `endDate` (ISO 8601). The Gateway
|
|
1189
|
+
* defaults to the last 30 days. To list return authorizations, use `listRmas()`.
|
|
1190
|
+
*/
|
|
1159
1191
|
async list(query) {
|
|
1160
1192
|
return this.http.get(
|
|
1161
1193
|
this.wsPath(""),
|
|
1162
1194
|
query
|
|
1163
1195
|
);
|
|
1164
1196
|
}
|
|
1165
|
-
/**
|
|
1197
|
+
/**
|
|
1198
|
+
* Get a received return by its numeric return id (`ReturnSummary.returnId` or `Rma.returnId`).
|
|
1199
|
+
* An RMA number is not a return id: the Gateway has no route for it here. Use `getRma()`.
|
|
1200
|
+
*/
|
|
1166
1201
|
async get(returnId) {
|
|
1167
|
-
return this.http.get(this.wsPath(returnId));
|
|
1202
|
+
return this.http.get(this.wsPath(String(returnId)));
|
|
1203
|
+
}
|
|
1204
|
+
/** List return authorizations (RMAs), one page at a time. */
|
|
1205
|
+
async listRmas(query) {
|
|
1206
|
+
return this.http.get(this.wsPath("rma"), query);
|
|
1207
|
+
}
|
|
1208
|
+
/** Get a return authorization by its RMA number, for example `RMA-1001`. */
|
|
1209
|
+
async getRma(rmaNumber) {
|
|
1210
|
+
return this.http.get(this.wsPath(`rma/${encodeURIComponent(rmaNumber)}`));
|
|
1168
1211
|
}
|
|
1169
|
-
/** Create a return authorization (RMA) for an order. */
|
|
1212
|
+
/** Create a return authorization (RMA) for an order. The Gateway answers 201 with the RMA. */
|
|
1170
1213
|
async create(request) {
|
|
1171
1214
|
return this.http.post(this.wsPath("rma"), request);
|
|
1172
1215
|
}
|
|
@@ -1181,7 +1224,7 @@ var ReturnsResource = class {
|
|
|
1181
1224
|
async generateLabel(rmaNumber, request = {}) {
|
|
1182
1225
|
return this.http.post(this.wsPath(`${rmaNumber}/label`), request);
|
|
1183
1226
|
}
|
|
1184
|
-
/** Record the inspected items of a returned package at a warehouse. */
|
|
1227
|
+
/** Record the inspected items of a returned package at a warehouse. `rmaId` is the numeric `Rma.rmaId`. */
|
|
1185
1228
|
async markReceived(rmaId, request) {
|
|
1186
1229
|
return this.http.post(this.wsPath(`${rmaId}/receive`), request);
|
|
1187
1230
|
}
|
package/package.json
CHANGED