@oway/sdk 0.1.2 → 0.2.1
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 +25 -13
- package/dist/index.d.mts +2769 -834
- package/dist/index.d.ts +2769 -834
- package/dist/index.js +139 -187
- package/dist/index.mjs +139 -187
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ const quote = await oway.quotes.create({
|
|
|
44
44
|
contactPerson: 'Jane Smith',
|
|
45
45
|
},
|
|
46
46
|
orderComponents: [
|
|
47
|
-
{ palletCount: 2, poundsWeight: 1000,
|
|
47
|
+
{ palletCount: 2, poundsWeight: 1000, dimensions: { length: 48, width: 40, height: 48 } },
|
|
48
48
|
],
|
|
49
49
|
});
|
|
50
50
|
|
|
@@ -56,7 +56,7 @@ const shipment = await oway.shipments.create({
|
|
|
56
56
|
pickupAddress: { /* same as above */ },
|
|
57
57
|
deliveryAddress: { /* same as above */ },
|
|
58
58
|
orderComponents: [
|
|
59
|
-
{ palletCount: 2, poundsWeight: 1000,
|
|
59
|
+
{ palletCount: 2, poundsWeight: 1000, dimensions: { length: 48, width: 40, height: 48 } },
|
|
60
60
|
],
|
|
61
61
|
description: 'Electronics - fragile',
|
|
62
62
|
});
|
|
@@ -96,7 +96,7 @@ You provide credentials once at initialization - token management is automatic.
|
|
|
96
96
|
const quote = await oway.quotes.create({
|
|
97
97
|
pickupAddress: { name, address1, city, state, zipCode, phoneNumber, contactPerson },
|
|
98
98
|
deliveryAddress: { name, address1, city, state, zipCode, phoneNumber, contactPerson },
|
|
99
|
-
orderComponents: [{ palletCount: 2, poundsWeight: 1000,
|
|
99
|
+
orderComponents: [{ palletCount: 2, poundsWeight: 1000, dimensions: { length: 48, width: 40, height: 48 } }],
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
// Retrieve a quote by ID
|
|
@@ -111,7 +111,7 @@ const shipment = await oway.shipments.create({
|
|
|
111
111
|
quoteId: quote.id, // Optional: lock in quoted price
|
|
112
112
|
pickupAddress: { ... },
|
|
113
113
|
deliveryAddress: { ... },
|
|
114
|
-
orderComponents: [{ palletCount: 2, poundsWeight: 1000,
|
|
114
|
+
orderComponents: [{ palletCount: 2, poundsWeight: 1000, dimensions: { length: 48, width: 40, height: 48 } }],
|
|
115
115
|
description: 'Palletized freight',
|
|
116
116
|
poNumber: 'PO-2024-12345', // Optional
|
|
117
117
|
});
|
|
@@ -184,27 +184,39 @@ const oway = new Oway({
|
|
|
184
184
|
|
|
185
185
|
## Error Handling
|
|
186
186
|
|
|
187
|
+
Every method throws `OwayError` on a non-2xx response. The error carries the parsed RFC 9457 `ProblemDetail`, the server-issued request id, and per-field validation failures when present.
|
|
188
|
+
|
|
187
189
|
```typescript
|
|
188
190
|
import { OwayError } from '@oway/sdk';
|
|
189
191
|
|
|
190
192
|
try {
|
|
191
|
-
const
|
|
193
|
+
const shipment = await oway.shipments.create({ ... });
|
|
192
194
|
} catch (error) {
|
|
193
195
|
if (error instanceof OwayError) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
196
|
+
// Programmatic branching:
|
|
197
|
+
switch (error.code) {
|
|
198
|
+
case 'no_coverage': /* lane not in coverage */ break;
|
|
199
|
+
case 'account_restriction': /* service not enabled */ break;
|
|
200
|
+
case 'daily_trip_limit': /* trip cap hit */ break;
|
|
201
|
+
}
|
|
200
202
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
+
// Per-field validation failures (when present):
|
|
204
|
+
for (const v of error.violations) {
|
|
205
|
+
console.error(` ${v.field}: ${v.reason}`);
|
|
203
206
|
}
|
|
207
|
+
|
|
208
|
+
console.error({
|
|
209
|
+
message: error.message, // server detail or title
|
|
210
|
+
statusCode: error.statusCode, // HTTP status
|
|
211
|
+
code: error.code, // machine-readable reason
|
|
212
|
+
requestId: error.requestId, // quote when reporting an issue
|
|
213
|
+
});
|
|
204
214
|
}
|
|
205
215
|
}
|
|
206
216
|
```
|
|
207
217
|
|
|
218
|
+
`OwayError.isRetryable()` is true for 408, 429, 500, 502, 503, and 504. The SDK retries those automatically with full-jitter exponential backoff (capped at 30 s); the helper is exposed so callers can decide how to surface failures.
|
|
219
|
+
|
|
208
220
|
## TypeScript Support
|
|
209
221
|
|
|
210
222
|
Full type definitions included:
|