@flexops/sdk 3.1.0 → 3.2.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 +51 -11
- package/dist/index.d.mts +176 -14
- package/dist/index.d.ts +176 -14
- package/dist/index.js +46 -7
- package/dist/index.mjs +46 -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,37 @@ 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.
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { FlexOpsError, HazmatClassification } from '@flexops/sdk';
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
const shipment = await client.shipping.createMultiPackage(
|
|
169
|
+
{
|
|
170
|
+
orderId: 12345,
|
|
171
|
+
carrierCode: 'USPS',
|
|
172
|
+
serviceCode: 'PRIORITY',
|
|
173
|
+
hazmatClassification: HazmatClassification.None,
|
|
174
|
+
packages: [
|
|
175
|
+
{ weightInOunces: 16, lengthInInches: 10, widthInInches: 8, heightInInches: 4, packageReference: 'Box 1 of 2' },
|
|
176
|
+
{ weightInOunces: 8, lengthInInches: 6, widthInInches: 6, heightInInches: 6, packageReference: 'Box 2 of 2' },
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
'order-12345-boxes', // optional Idempotency-Key, reuse it when you retry
|
|
180
|
+
);
|
|
181
|
+
// At least one label was bought; check each box
|
|
182
|
+
for (const box of shipment.data!.labels) console.log(box.packageIndex, box.success, box.trackingNumber ?? box.errorMessage);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
// No label was bought: 422 AllPackagesFailed, or 409 OutcomeUnknown when a label may exist (check the order first).
|
|
185
|
+
if (error instanceof FlexOpsError) console.log(error.code, error.data);
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
158
189
|
## Carrier-Specific Calls
|
|
159
190
|
|
|
160
191
|
Rates, labels, voids, pickups and scan forms go through `client.shipping`, `client.pickups` and
|
|
@@ -268,7 +299,7 @@ Every SDK method is a thin wrapper around the FlexOps REST API. If you want to v
|
|
|
268
299
|
```bash
|
|
269
300
|
# Shop rates across all connected carriers
|
|
270
301
|
curl -X POST https://gateway.flexops.io/api/shipping/rates \
|
|
271
|
-
-H "X-API-Key:
|
|
302
|
+
-H "X-API-Key: live_..." \
|
|
272
303
|
-H "Content-Type: application/json" \
|
|
273
304
|
-d '{
|
|
274
305
|
"origin": {"addressLine1": "123 Main St", "city": "New York", "stateProvince": "NY", "postalCode": "10001", "countryCode": "US"},
|
|
@@ -278,7 +309,7 @@ curl -X POST https://gateway.flexops.io/api/shipping/rates \
|
|
|
278
309
|
|
|
279
310
|
# Create a label (hazmatClassification 0 = not hazardous; required when there is no orderId)
|
|
280
311
|
curl -X POST https://gateway.flexops.io/api/shipping/labels \
|
|
281
|
-
-H "X-API-Key:
|
|
312
|
+
-H "X-API-Key: live_..." \
|
|
282
313
|
-H "Content-Type: application/json" \
|
|
283
314
|
-d '{
|
|
284
315
|
"carrierCode": "USPS",
|
|
@@ -291,14 +322,14 @@ curl -X POST https://gateway.flexops.io/api/shipping/labels \
|
|
|
291
322
|
|
|
292
323
|
# Track a shipment
|
|
293
324
|
curl https://gateway.flexops.io/api/shipping/track/9400111899223456789012 \
|
|
294
|
-
-H "X-API-Key:
|
|
325
|
+
-H "X-API-Key: live_..."
|
|
295
326
|
|
|
296
327
|
# Cancel (void) a label
|
|
297
328
|
curl -X DELETE "https://gateway.flexops.io/api/shipping/labels/{labelId}?carrierCode=usps" \
|
|
298
|
-
-H "X-API-Key:
|
|
329
|
+
-H "X-API-Key: live_..."
|
|
299
330
|
```
|
|
300
331
|
|
|
301
|
-
Use
|
|
332
|
+
Use a `test_...` key instead of `live_...` to hit the sandbox environment; mock carriers respond, no real charges, no real labels.
|
|
302
333
|
|
|
303
334
|
## Wallet
|
|
304
335
|
|
|
@@ -348,22 +379,31 @@ const rma = await client.returns.create({
|
|
|
348
379
|
reason: 'Defective product',
|
|
349
380
|
items: [{ sku: 'WIDGET-001', quantity: 1 }],
|
|
350
381
|
});
|
|
382
|
+
const { rmaNumber, rmaId } = rma.data!;
|
|
383
|
+
|
|
384
|
+
// Read it back by RMA number, or page through all RMAs
|
|
385
|
+
const current = await client.returns.getRma(rmaNumber);
|
|
386
|
+
const rmas = await client.returns.listRmas({ page: 1, pageSize: 25 });
|
|
351
387
|
|
|
352
388
|
// Generate the return label. Send the package weight and size. Anything left out comes from the
|
|
353
389
|
// workspace's default shipping preset; with no preset the API answers 400 PackageMeasurementsRequired.
|
|
354
|
-
await client.returns.generateLabel(
|
|
390
|
+
await client.returns.generateLabel(rmaNumber, {
|
|
355
391
|
weightOz: 16,
|
|
356
392
|
lengthIn: 10,
|
|
357
393
|
widthIn: 8,
|
|
358
394
|
heightIn: 4,
|
|
359
395
|
});
|
|
360
396
|
|
|
361
|
-
// Record the inspected items at a warehouse (disposition 0 restock, 1
|
|
397
|
+
// Record the inspected items at a warehouse (disposition 0 restock, 1 dispose, 2 forward)
|
|
362
398
|
await client.returns.markReceived(rmaId, {
|
|
363
|
-
rmaNumber
|
|
399
|
+
rmaNumber,
|
|
364
400
|
warehouseId: 1,
|
|
365
|
-
inspectedItems: [{ partNumber: 'WIDGET-001', quantity: 1, disposition:
|
|
401
|
+
inspectedItems: [{ partNumber: 'WIDGET-001', quantity: 1, disposition: 0 }],
|
|
366
402
|
});
|
|
403
|
+
|
|
404
|
+
// Received returns: list them, then read one by its numeric return id
|
|
405
|
+
const received = await client.returns.list({ startDate: '2026-10-01' });
|
|
406
|
+
const detail = await client.returns.get(received.data![0].returnId);
|
|
367
407
|
```
|
|
368
408
|
|
|
369
409
|
Approving, rejecting, cancelling and refunding returns are done in the FlexOps portal.
|
|
@@ -465,7 +505,7 @@ try {
|
|
|
465
505
|
```typescript
|
|
466
506
|
const client = new FlexOps({
|
|
467
507
|
baseUrl: 'https://gateway.flexops.io', // Default
|
|
468
|
-
apiKey: '
|
|
508
|
+
apiKey: 'live_...',
|
|
469
509
|
workspaceId: 'ws-abc123',
|
|
470
510
|
timeout: 30000, // 30s default
|
|
471
511
|
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,143 @@ 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
|
+
/** 1 to 99 boxes. */
|
|
705
|
+
packages: MultiPackageDetail[];
|
|
706
|
+
}
|
|
707
|
+
/** One box's outcome in a multi-package shipment (the Gateway `PackageLabelResult`). */
|
|
708
|
+
interface MultiPackageLabelResult {
|
|
709
|
+
/** Index of the box in the request, from 0. */
|
|
710
|
+
packageIndex: number;
|
|
711
|
+
packageReference?: string | null;
|
|
712
|
+
trackingNumber?: string | null;
|
|
713
|
+
rate?: number | null;
|
|
714
|
+
success: boolean;
|
|
715
|
+
errorMessage?: string | null;
|
|
716
|
+
/** Stable refusal code when the box failed. `OutcomeUnknown` means a label may exist: check before retrying. */
|
|
717
|
+
errorCode?: string | null;
|
|
718
|
+
}
|
|
719
|
+
/** The Gateway `MultiPackageShipmentResponse`. */
|
|
720
|
+
interface MultiPackageShipmentResponse {
|
|
721
|
+
orderId: number;
|
|
722
|
+
carrierCode: string;
|
|
723
|
+
totalPackages: number;
|
|
724
|
+
successfulPackages: number;
|
|
725
|
+
failedPackages: number;
|
|
726
|
+
totalCost: number;
|
|
727
|
+
labels: MultiPackageLabelResult[];
|
|
728
|
+
}
|
|
598
729
|
interface ShipmentsTrend {
|
|
599
730
|
date: string;
|
|
600
731
|
count: number;
|
|
@@ -983,7 +1114,11 @@ declare class FlexOpsError extends Error {
|
|
|
983
1114
|
readonly status: number;
|
|
984
1115
|
readonly code?: string | undefined;
|
|
985
1116
|
readonly errors?: string[] | undefined;
|
|
986
|
-
|
|
1117
|
+
/** The envelope's `data` on an error reply, when the Gateway sends one (for example a multi-package 409 or 422). */
|
|
1118
|
+
readonly data?: unknown | undefined;
|
|
1119
|
+
constructor(message: string, status: number, code?: string | undefined, errors?: string[] | undefined,
|
|
1120
|
+
/** The envelope's `data` on an error reply, when the Gateway sends one (for example a multi-package 409 or 422). */
|
|
1121
|
+
data?: unknown | undefined);
|
|
987
1122
|
}
|
|
988
1123
|
declare class FlexOpsRateLimitError extends FlexOpsError {
|
|
989
1124
|
readonly retryAfter?: number | undefined;
|
|
@@ -1110,6 +1245,20 @@ declare class ShippingResource {
|
|
|
1110
1245
|
getBatchStatus(jobId: string): Promise<ApiResponse<BatchLabelJob>>;
|
|
1111
1246
|
/** Download a label from a batch job. */
|
|
1112
1247
|
downloadBatchLabel(jobId: string, itemId: string): Promise<Response>;
|
|
1248
|
+
/**
|
|
1249
|
+
* Buy labels for one order shipped in several boxes (1 to 99) with the same carrier and service.
|
|
1250
|
+
* Every box's label slot is reserved before any label is bought; a box that fails does not stop the
|
|
1251
|
+
* others, and each box reports its own `success`, `errorMessage` and `errorCode`.
|
|
1252
|
+
*
|
|
1253
|
+
* Resolves when at least one label was bought (check `failedPackages`). When none was, the Gateway
|
|
1254
|
+
* answers 422 `AllPackagesFailed`, or 409 `OutcomeUnknown` when a box's carrier outcome is unknown and
|
|
1255
|
+
* a label may exist: both throw a `FlexOpsError` whose `data` is the `MultiPackageShipmentResponse`.
|
|
1256
|
+
* After `OutcomeUnknown`, check the order before buying again.
|
|
1257
|
+
*
|
|
1258
|
+
* `hazmatClassification` accepts only `HazmatClassification.None` or nothing. Pass a stable
|
|
1259
|
+
* `idempotencyKey` to retry safely across processes; otherwise one is generated for this call.
|
|
1260
|
+
*/
|
|
1261
|
+
createMultiPackage(request: MultiPackageShipmentRequest, idempotencyKey?: string): Promise<ApiResponse<MultiPackageShipmentResponse>>;
|
|
1113
1262
|
/** List available carriers and their services. */
|
|
1114
1263
|
getCarriers(): Promise<unknown>;
|
|
1115
1264
|
/** Get AI-ranked carrier recommendations for a lane, scored by cost, speed, and reliability. */
|
|
@@ -1636,17 +1785,30 @@ declare class ReturnsResource {
|
|
|
1636
1785
|
private readonly getWorkspaceId;
|
|
1637
1786
|
constructor(http: HttpClient, getWorkspaceId: () => string | undefined);
|
|
1638
1787
|
private wsPath;
|
|
1639
|
-
/**
|
|
1788
|
+
/**
|
|
1789
|
+
* List received returns, optionally between `startDate` and `endDate` (ISO 8601). The Gateway
|
|
1790
|
+
* defaults to the last 30 days. To list return authorizations, use `listRmas()`.
|
|
1791
|
+
*/
|
|
1640
1792
|
list(query?: {
|
|
1641
1793
|
startDate?: string;
|
|
1642
1794
|
endDate?: string;
|
|
1643
1795
|
page?: number;
|
|
1644
1796
|
pageSize?: number;
|
|
1645
|
-
}): Promise<ApiResponse<
|
|
1646
|
-
/**
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1797
|
+
}): Promise<ApiResponse<ReturnSummary[]>>;
|
|
1798
|
+
/**
|
|
1799
|
+
* Get a received return by its numeric return id (`ReturnSummary.returnId` or `Rma.returnId`).
|
|
1800
|
+
* An RMA number is not a return id: the Gateway has no route for it here. Use `getRma()`.
|
|
1801
|
+
*/
|
|
1802
|
+
get(returnId: number | string): Promise<ApiResponse<ReturnDetail>>;
|
|
1803
|
+
/** List return authorizations (RMAs), one page at a time. */
|
|
1804
|
+
listRmas(query?: {
|
|
1805
|
+
page?: number;
|
|
1806
|
+
pageSize?: number;
|
|
1807
|
+
}): Promise<ApiResponse<Rma[]>>;
|
|
1808
|
+
/** Get a return authorization by its RMA number, for example `RMA-1001`. */
|
|
1809
|
+
getRma(rmaNumber: string): Promise<ApiResponse<Rma>>;
|
|
1810
|
+
/** Create a return authorization (RMA) for an order. The Gateway answers 201 with the RMA. */
|
|
1811
|
+
create(request: ReturnRequest): Promise<ApiResponse<Rma>>;
|
|
1650
1812
|
/**
|
|
1651
1813
|
* Generate a return label for an approved RMA.
|
|
1652
1814
|
*
|
|
@@ -1655,9 +1817,9 @@ declare class ReturnsResource {
|
|
|
1655
1817
|
* shipping preset has nothing else to take the package from and the call fails with a 400 that
|
|
1656
1818
|
* names the missing fields.
|
|
1657
1819
|
*/
|
|
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>>;
|
|
1820
|
+
generateLabel(rmaNumber: string, request?: ReturnLabelRequest): Promise<ApiResponse<ReturnLabel>>;
|
|
1821
|
+
/** Record the inspected items of a returned package at a warehouse. `rmaId` is the numeric `Rma.rmaId`. */
|
|
1822
|
+
markReceived(rmaId: number | string, request: ReceiveReturnRequest): Promise<ApiResponse<unknown>>;
|
|
1661
1823
|
}
|
|
1662
1824
|
|
|
1663
1825
|
type DateRange = {
|
|
@@ -1932,8 +2094,8 @@ declare class HsCodesResource {
|
|
|
1932
2094
|
* import { FlexOps } from '@flexops/sdk';
|
|
1933
2095
|
*
|
|
1934
2096
|
* const client = new FlexOps({
|
|
1935
|
-
* apiKey: '
|
|
1936
|
-
* workspaceId: '
|
|
2097
|
+
* apiKey: 'live_...',
|
|
2098
|
+
* workspaceId: 'your-workspace-id',
|
|
1937
2099
|
* });
|
|
1938
2100
|
*
|
|
1939
2101
|
* // Get shipping rates
|
|
@@ -1999,4 +2161,4 @@ declare class FlexOps {
|
|
|
1999
2161
|
}
|
|
2000
2162
|
|
|
2001
2163
|
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 };
|
|
2164
|
+
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,143 @@ 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
|
+
/** 1 to 99 boxes. */
|
|
705
|
+
packages: MultiPackageDetail[];
|
|
706
|
+
}
|
|
707
|
+
/** One box's outcome in a multi-package shipment (the Gateway `PackageLabelResult`). */
|
|
708
|
+
interface MultiPackageLabelResult {
|
|
709
|
+
/** Index of the box in the request, from 0. */
|
|
710
|
+
packageIndex: number;
|
|
711
|
+
packageReference?: string | null;
|
|
712
|
+
trackingNumber?: string | null;
|
|
713
|
+
rate?: number | null;
|
|
714
|
+
success: boolean;
|
|
715
|
+
errorMessage?: string | null;
|
|
716
|
+
/** Stable refusal code when the box failed. `OutcomeUnknown` means a label may exist: check before retrying. */
|
|
717
|
+
errorCode?: string | null;
|
|
718
|
+
}
|
|
719
|
+
/** The Gateway `MultiPackageShipmentResponse`. */
|
|
720
|
+
interface MultiPackageShipmentResponse {
|
|
721
|
+
orderId: number;
|
|
722
|
+
carrierCode: string;
|
|
723
|
+
totalPackages: number;
|
|
724
|
+
successfulPackages: number;
|
|
725
|
+
failedPackages: number;
|
|
726
|
+
totalCost: number;
|
|
727
|
+
labels: MultiPackageLabelResult[];
|
|
728
|
+
}
|
|
598
729
|
interface ShipmentsTrend {
|
|
599
730
|
date: string;
|
|
600
731
|
count: number;
|
|
@@ -983,7 +1114,11 @@ declare class FlexOpsError extends Error {
|
|
|
983
1114
|
readonly status: number;
|
|
984
1115
|
readonly code?: string | undefined;
|
|
985
1116
|
readonly errors?: string[] | undefined;
|
|
986
|
-
|
|
1117
|
+
/** The envelope's `data` on an error reply, when the Gateway sends one (for example a multi-package 409 or 422). */
|
|
1118
|
+
readonly data?: unknown | undefined;
|
|
1119
|
+
constructor(message: string, status: number, code?: string | undefined, errors?: string[] | undefined,
|
|
1120
|
+
/** The envelope's `data` on an error reply, when the Gateway sends one (for example a multi-package 409 or 422). */
|
|
1121
|
+
data?: unknown | undefined);
|
|
987
1122
|
}
|
|
988
1123
|
declare class FlexOpsRateLimitError extends FlexOpsError {
|
|
989
1124
|
readonly retryAfter?: number | undefined;
|
|
@@ -1110,6 +1245,20 @@ declare class ShippingResource {
|
|
|
1110
1245
|
getBatchStatus(jobId: string): Promise<ApiResponse<BatchLabelJob>>;
|
|
1111
1246
|
/** Download a label from a batch job. */
|
|
1112
1247
|
downloadBatchLabel(jobId: string, itemId: string): Promise<Response>;
|
|
1248
|
+
/**
|
|
1249
|
+
* Buy labels for one order shipped in several boxes (1 to 99) with the same carrier and service.
|
|
1250
|
+
* Every box's label slot is reserved before any label is bought; a box that fails does not stop the
|
|
1251
|
+
* others, and each box reports its own `success`, `errorMessage` and `errorCode`.
|
|
1252
|
+
*
|
|
1253
|
+
* Resolves when at least one label was bought (check `failedPackages`). When none was, the Gateway
|
|
1254
|
+
* answers 422 `AllPackagesFailed`, or 409 `OutcomeUnknown` when a box's carrier outcome is unknown and
|
|
1255
|
+
* a label may exist: both throw a `FlexOpsError` whose `data` is the `MultiPackageShipmentResponse`.
|
|
1256
|
+
* After `OutcomeUnknown`, check the order before buying again.
|
|
1257
|
+
*
|
|
1258
|
+
* `hazmatClassification` accepts only `HazmatClassification.None` or nothing. Pass a stable
|
|
1259
|
+
* `idempotencyKey` to retry safely across processes; otherwise one is generated for this call.
|
|
1260
|
+
*/
|
|
1261
|
+
createMultiPackage(request: MultiPackageShipmentRequest, idempotencyKey?: string): Promise<ApiResponse<MultiPackageShipmentResponse>>;
|
|
1113
1262
|
/** List available carriers and their services. */
|
|
1114
1263
|
getCarriers(): Promise<unknown>;
|
|
1115
1264
|
/** Get AI-ranked carrier recommendations for a lane, scored by cost, speed, and reliability. */
|
|
@@ -1636,17 +1785,30 @@ declare class ReturnsResource {
|
|
|
1636
1785
|
private readonly getWorkspaceId;
|
|
1637
1786
|
constructor(http: HttpClient, getWorkspaceId: () => string | undefined);
|
|
1638
1787
|
private wsPath;
|
|
1639
|
-
/**
|
|
1788
|
+
/**
|
|
1789
|
+
* List received returns, optionally between `startDate` and `endDate` (ISO 8601). The Gateway
|
|
1790
|
+
* defaults to the last 30 days. To list return authorizations, use `listRmas()`.
|
|
1791
|
+
*/
|
|
1640
1792
|
list(query?: {
|
|
1641
1793
|
startDate?: string;
|
|
1642
1794
|
endDate?: string;
|
|
1643
1795
|
page?: number;
|
|
1644
1796
|
pageSize?: number;
|
|
1645
|
-
}): Promise<ApiResponse<
|
|
1646
|
-
/**
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1797
|
+
}): Promise<ApiResponse<ReturnSummary[]>>;
|
|
1798
|
+
/**
|
|
1799
|
+
* Get a received return by its numeric return id (`ReturnSummary.returnId` or `Rma.returnId`).
|
|
1800
|
+
* An RMA number is not a return id: the Gateway has no route for it here. Use `getRma()`.
|
|
1801
|
+
*/
|
|
1802
|
+
get(returnId: number | string): Promise<ApiResponse<ReturnDetail>>;
|
|
1803
|
+
/** List return authorizations (RMAs), one page at a time. */
|
|
1804
|
+
listRmas(query?: {
|
|
1805
|
+
page?: number;
|
|
1806
|
+
pageSize?: number;
|
|
1807
|
+
}): Promise<ApiResponse<Rma[]>>;
|
|
1808
|
+
/** Get a return authorization by its RMA number, for example `RMA-1001`. */
|
|
1809
|
+
getRma(rmaNumber: string): Promise<ApiResponse<Rma>>;
|
|
1810
|
+
/** Create a return authorization (RMA) for an order. The Gateway answers 201 with the RMA. */
|
|
1811
|
+
create(request: ReturnRequest): Promise<ApiResponse<Rma>>;
|
|
1650
1812
|
/**
|
|
1651
1813
|
* Generate a return label for an approved RMA.
|
|
1652
1814
|
*
|
|
@@ -1655,9 +1817,9 @@ declare class ReturnsResource {
|
|
|
1655
1817
|
* shipping preset has nothing else to take the package from and the call fails with a 400 that
|
|
1656
1818
|
* names the missing fields.
|
|
1657
1819
|
*/
|
|
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>>;
|
|
1820
|
+
generateLabel(rmaNumber: string, request?: ReturnLabelRequest): Promise<ApiResponse<ReturnLabel>>;
|
|
1821
|
+
/** Record the inspected items of a returned package at a warehouse. `rmaId` is the numeric `Rma.rmaId`. */
|
|
1822
|
+
markReceived(rmaId: number | string, request: ReceiveReturnRequest): Promise<ApiResponse<unknown>>;
|
|
1661
1823
|
}
|
|
1662
1824
|
|
|
1663
1825
|
type DateRange = {
|
|
@@ -1932,8 +2094,8 @@ declare class HsCodesResource {
|
|
|
1932
2094
|
* import { FlexOps } from '@flexops/sdk';
|
|
1933
2095
|
*
|
|
1934
2096
|
* const client = new FlexOps({
|
|
1935
|
-
* apiKey: '
|
|
1936
|
-
* workspaceId: '
|
|
2097
|
+
* apiKey: 'live_...',
|
|
2098
|
+
* workspaceId: 'your-workspace-id',
|
|
1937
2099
|
* });
|
|
1938
2100
|
*
|
|
1939
2101
|
* // Get shipping rates
|
|
@@ -1999,4 +2161,4 @@ declare class FlexOps {
|
|
|
1999
2161
|
}
|
|
2000
2162
|
|
|
2001
2163
|
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 };
|
|
2164
|
+
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,28 @@ 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
|
+
* `hazmatClassification` accepts only `HazmatClassification.None` or nothing. Pass a stable
|
|
532
|
+
* `idempotencyKey` to retry safely across processes; otherwise one is generated for this call.
|
|
533
|
+
*/
|
|
534
|
+
async createMultiPackage(request, idempotencyKey) {
|
|
535
|
+
return this.http.request("POST", "/api/shipping/multi-package", {
|
|
536
|
+
body: request,
|
|
537
|
+
...idempotencyKey ? { headers: { "Idempotency-Key": idempotencyKey } } : {}
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
// -----------------------------------------------------------------------
|
|
516
541
|
// Carriers
|
|
517
542
|
// -----------------------------------------------------------------------
|
|
518
543
|
/** List available carriers and their services. */
|
|
@@ -1203,18 +1228,32 @@ var ReturnsResource = class {
|
|
|
1203
1228
|
if (!id) throw new Error("workspaceId is required.");
|
|
1204
1229
|
return `/api/workspaces/${id}/returns${suffix ? `/${suffix}` : ""}`;
|
|
1205
1230
|
}
|
|
1206
|
-
/**
|
|
1231
|
+
/**
|
|
1232
|
+
* List received returns, optionally between `startDate` and `endDate` (ISO 8601). The Gateway
|
|
1233
|
+
* defaults to the last 30 days. To list return authorizations, use `listRmas()`.
|
|
1234
|
+
*/
|
|
1207
1235
|
async list(query) {
|
|
1208
1236
|
return this.http.get(
|
|
1209
1237
|
this.wsPath(""),
|
|
1210
1238
|
query
|
|
1211
1239
|
);
|
|
1212
1240
|
}
|
|
1213
|
-
/**
|
|
1241
|
+
/**
|
|
1242
|
+
* Get a received return by its numeric return id (`ReturnSummary.returnId` or `Rma.returnId`).
|
|
1243
|
+
* An RMA number is not a return id: the Gateway has no route for it here. Use `getRma()`.
|
|
1244
|
+
*/
|
|
1214
1245
|
async get(returnId) {
|
|
1215
|
-
return this.http.get(this.wsPath(returnId));
|
|
1246
|
+
return this.http.get(this.wsPath(String(returnId)));
|
|
1247
|
+
}
|
|
1248
|
+
/** List return authorizations (RMAs), one page at a time. */
|
|
1249
|
+
async listRmas(query) {
|
|
1250
|
+
return this.http.get(this.wsPath("rma"), query);
|
|
1251
|
+
}
|
|
1252
|
+
/** Get a return authorization by its RMA number, for example `RMA-1001`. */
|
|
1253
|
+
async getRma(rmaNumber) {
|
|
1254
|
+
return this.http.get(this.wsPath(`rma/${encodeURIComponent(rmaNumber)}`));
|
|
1216
1255
|
}
|
|
1217
|
-
/** Create a return authorization (RMA) for an order. */
|
|
1256
|
+
/** Create a return authorization (RMA) for an order. The Gateway answers 201 with the RMA. */
|
|
1218
1257
|
async create(request) {
|
|
1219
1258
|
return this.http.post(this.wsPath("rma"), request);
|
|
1220
1259
|
}
|
|
@@ -1229,7 +1268,7 @@ var ReturnsResource = class {
|
|
|
1229
1268
|
async generateLabel(rmaNumber, request = {}) {
|
|
1230
1269
|
return this.http.post(this.wsPath(`${rmaNumber}/label`), request);
|
|
1231
1270
|
}
|
|
1232
|
-
/** Record the inspected items of a returned package at a warehouse. */
|
|
1271
|
+
/** Record the inspected items of a returned package at a warehouse. `rmaId` is the numeric `Rma.rmaId`. */
|
|
1233
1272
|
async markReceived(rmaId, request) {
|
|
1234
1273
|
return this.http.post(this.wsPath(`${rmaId}/receive`), request);
|
|
1235
1274
|
}
|
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,28 @@ 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
|
+
* `hazmatClassification` accepts only `HazmatClassification.None` or nothing. Pass a stable
|
|
484
|
+
* `idempotencyKey` to retry safely across processes; otherwise one is generated for this call.
|
|
485
|
+
*/
|
|
486
|
+
async createMultiPackage(request, idempotencyKey) {
|
|
487
|
+
return this.http.request("POST", "/api/shipping/multi-package", {
|
|
488
|
+
body: request,
|
|
489
|
+
...idempotencyKey ? { headers: { "Idempotency-Key": idempotencyKey } } : {}
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
// -----------------------------------------------------------------------
|
|
468
493
|
// Carriers
|
|
469
494
|
// -----------------------------------------------------------------------
|
|
470
495
|
/** List available carriers and their services. */
|
|
@@ -1155,18 +1180,32 @@ var ReturnsResource = class {
|
|
|
1155
1180
|
if (!id) throw new Error("workspaceId is required.");
|
|
1156
1181
|
return `/api/workspaces/${id}/returns${suffix ? `/${suffix}` : ""}`;
|
|
1157
1182
|
}
|
|
1158
|
-
/**
|
|
1183
|
+
/**
|
|
1184
|
+
* List received returns, optionally between `startDate` and `endDate` (ISO 8601). The Gateway
|
|
1185
|
+
* defaults to the last 30 days. To list return authorizations, use `listRmas()`.
|
|
1186
|
+
*/
|
|
1159
1187
|
async list(query) {
|
|
1160
1188
|
return this.http.get(
|
|
1161
1189
|
this.wsPath(""),
|
|
1162
1190
|
query
|
|
1163
1191
|
);
|
|
1164
1192
|
}
|
|
1165
|
-
/**
|
|
1193
|
+
/**
|
|
1194
|
+
* Get a received return by its numeric return id (`ReturnSummary.returnId` or `Rma.returnId`).
|
|
1195
|
+
* An RMA number is not a return id: the Gateway has no route for it here. Use `getRma()`.
|
|
1196
|
+
*/
|
|
1166
1197
|
async get(returnId) {
|
|
1167
|
-
return this.http.get(this.wsPath(returnId));
|
|
1198
|
+
return this.http.get(this.wsPath(String(returnId)));
|
|
1199
|
+
}
|
|
1200
|
+
/** List return authorizations (RMAs), one page at a time. */
|
|
1201
|
+
async listRmas(query) {
|
|
1202
|
+
return this.http.get(this.wsPath("rma"), query);
|
|
1203
|
+
}
|
|
1204
|
+
/** Get a return authorization by its RMA number, for example `RMA-1001`. */
|
|
1205
|
+
async getRma(rmaNumber) {
|
|
1206
|
+
return this.http.get(this.wsPath(`rma/${encodeURIComponent(rmaNumber)}`));
|
|
1168
1207
|
}
|
|
1169
|
-
/** Create a return authorization (RMA) for an order. */
|
|
1208
|
+
/** Create a return authorization (RMA) for an order. The Gateway answers 201 with the RMA. */
|
|
1170
1209
|
async create(request) {
|
|
1171
1210
|
return this.http.post(this.wsPath("rma"), request);
|
|
1172
1211
|
}
|
|
@@ -1181,7 +1220,7 @@ var ReturnsResource = class {
|
|
|
1181
1220
|
async generateLabel(rmaNumber, request = {}) {
|
|
1182
1221
|
return this.http.post(this.wsPath(`${rmaNumber}/label`), request);
|
|
1183
1222
|
}
|
|
1184
|
-
/** Record the inspected items of a returned package at a warehouse. */
|
|
1223
|
+
/** Record the inspected items of a returned package at a warehouse. `rmaId` is the numeric `Rma.rmaId`. */
|
|
1185
1224
|
async markReceived(rmaId, request) {
|
|
1186
1225
|
return this.http.post(this.wsPath(`${rmaId}/receive`), request);
|
|
1187
1226
|
}
|
package/package.json
CHANGED