@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 CHANGED
@@ -179,32 +179,44 @@ const oway = new Oway({
179
179
 
180
180
  | Environment | Constant | URL |
181
181
  |-------------|----------|-----|
182
- | Sandbox | `OwayEnvironments.SANDBOX` | `https://rest-api.sandbox.oway.io` |
183
- | Production | `OwayEnvironments.PRODUCTION` | `https://rest-api.oway.io` |
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 quote = await oway.quotes.create({ ... });
193
+ const shipment = await oway.shipments.create({ ... });
192
194
  } catch (error) {
193
195
  if (error instanceof OwayError) {
194
- console.error({
195
- message: error.message,
196
- code: error.code, // Error code
197
- statusCode: error.statusCode, // HTTP status
198
- requestId: error.requestId, // For support
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
- if (error.isRetryable()) {
202
- // Retry logic - SDK retries automatically up to maxRetries
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**: [rest-api.oway.io/api-docs](https://rest-api.oway.io/api-docs)
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