@oway/sdk 0.1.1 → 0.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 +24 -12
- package/dist/index.d.mts +2880 -878
- package/dist/index.d.ts +2880 -878
- package/dist/index.js +141 -189
- package/dist/index.mjs +141 -189
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -179,32 +179,44 @@ const oway = new Oway({
|
|
|
179
179
|
|
|
180
180
|
| Environment | Constant | URL |
|
|
181
181
|
|-------------|----------|-----|
|
|
182
|
-
| Sandbox | `OwayEnvironments.SANDBOX` | `https://
|
|
183
|
-
| Production | `OwayEnvironments.PRODUCTION` | `https://
|
|
182
|
+
| Sandbox | `OwayEnvironments.SANDBOX` | `https://api.sandbox.oway.io` |
|
|
183
|
+
| Production | `OwayEnvironments.PRODUCTION` | `https://api.oway.io` |
|
|
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:
|
|
@@ -216,7 +228,7 @@ import type { Quote, Shipment, Tracking, Invoice, QuoteRequest, ShipmentRequest,
|
|
|
216
228
|
## Support
|
|
217
229
|
|
|
218
230
|
- **Documentation**: [docs.shipoway.com](https://docs.shipoway.com)
|
|
219
|
-
- **API Reference**: [
|
|
231
|
+
- **API Reference**: [api.oway.io/api-docs](https://api.oway.io/api-docs)
|
|
220
232
|
- **Email**: support@oway.io
|
|
221
233
|
|
|
222
234
|
## License
|