@oway/sdk 0.1.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 ADDED
@@ -0,0 +1,224 @@
1
+ # @oway/sdk
2
+
3
+ Official Oway SDK for JavaScript and TypeScript.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@oway/sdk.svg)](https://www.npmjs.com/package/@oway/sdk)
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @oway/sdk
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import Oway, { OwayEnvironments } from '@oway/sdk';
17
+
18
+ // 1. Initialize with M2M credentials
19
+ const oway = new Oway({
20
+ clientId: process.env.OWAY_M2M_CLIENT_ID!,
21
+ clientSecret: process.env.OWAY_M2M_CLIENT_SECRET!,
22
+ apiKey: process.env.OWAY_API_KEY, // Optional: default company API key
23
+ baseUrl: OwayEnvironments.SANDBOX,
24
+ });
25
+
26
+ // 2. Get a shipping quote
27
+ const quote = await oway.quotes.create({
28
+ pickupAddress: {
29
+ name: 'Warehouse LA',
30
+ address1: '123 Warehouse Rd',
31
+ city: 'Los Angeles',
32
+ state: 'CA',
33
+ zipCode: '90210',
34
+ phoneNumber: '+15550123456',
35
+ contactPerson: 'John Doe',
36
+ },
37
+ deliveryAddress: {
38
+ name: 'Distribution NYC',
39
+ address1: '456 Distribution Ave',
40
+ city: 'New York',
41
+ state: 'NY',
42
+ zipCode: '10001',
43
+ phoneNumber: '+15555678901',
44
+ contactPerson: 'Jane Smith',
45
+ },
46
+ orderComponents: [
47
+ { palletCount: 2, poundsWeight: 1000, palletDimensions: [48, 40, 48] },
48
+ ],
49
+ });
50
+
51
+ console.log(`Quote: $${(quote.quotedPriceInCents ?? 0) / 100}`);
52
+
53
+ // 3. Create a shipment from the quote
54
+ const shipment = await oway.shipments.create({
55
+ quoteId: quote.id,
56
+ pickupAddress: { /* same as above */ },
57
+ deliveryAddress: { /* same as above */ },
58
+ orderComponents: [
59
+ { palletCount: 2, poundsWeight: 1000, palletDimensions: [48, 40, 48] },
60
+ ],
61
+ description: 'Electronics - fragile',
62
+ });
63
+
64
+ console.log(`Order: ${shipment.orderNumber} (${shipment.orderStatus})`);
65
+
66
+ // 4. Confirm and track
67
+ await oway.shipments.confirm(shipment.orderNumber!);
68
+ const tracking = await oway.shipments.tracking(shipment.orderNumber!);
69
+ console.log(`Status: ${tracking.orderStatus}`);
70
+ ```
71
+
72
+ ## Getting Credentials
73
+
74
+ ### M2M Credentials (Required)
75
+ Contact Oway Sales Engineering (support@oway.io) to obtain a `clientId` and `clientSecret`.
76
+
77
+ ### Company API Key (Optional)
78
+ Self-service at [app.oway.io/settings/api](https://app.oway.io/settings/api).
79
+ - Shipper keys: `oway_sk_test_...` (test) / `oway_sk_live_...` (production)
80
+ - Carrier keys: `oway_ck_...`
81
+
82
+ ## Authentication
83
+
84
+ The SDK handles authentication automatically:
85
+ - **M2M Token** (`Authorization: Bearer`) - Auto-refreshed JWT from clientId/clientSecret
86
+ - **API Key** (`x-oway-api-key`) - Company-specific key for authorization
87
+
88
+ You provide credentials once at initialization - token management is automatic.
89
+
90
+ ## API Reference
91
+
92
+ ### Quotes
93
+
94
+ ```typescript
95
+ // Request a quote
96
+ const quote = await oway.quotes.create({
97
+ pickupAddress: { name, address1, city, state, zipCode, phoneNumber, contactPerson },
98
+ deliveryAddress: { name, address1, city, state, zipCode, phoneNumber, contactPerson },
99
+ orderComponents: [{ palletCount: 2, poundsWeight: 1000, palletDimensions: [48, 40, 48] }],
100
+ });
101
+
102
+ // Retrieve a quote by ID
103
+ const quote = await oway.quotes.retrieve('507f1f77bcf86cd799439011');
104
+ ```
105
+
106
+ ### Shipments
107
+
108
+ ```typescript
109
+ // Create a shipment (optionally from a quote)
110
+ const shipment = await oway.shipments.create({
111
+ quoteId: quote.id, // Optional: lock in quoted price
112
+ pickupAddress: { ... },
113
+ deliveryAddress: { ... },
114
+ orderComponents: [{ palletCount: 2, poundsWeight: 1000, palletDimensions: [48, 40, 48] }],
115
+ description: 'Palletized freight',
116
+ poNumber: 'PO-2024-12345', // Optional
117
+ });
118
+
119
+ // Retrieve a shipment
120
+ const shipment = await oway.shipments.retrieve('ZKYQ5');
121
+
122
+ // Confirm a shipment
123
+ await oway.shipments.confirm('ZKYQ5');
124
+
125
+ // Cancel a shipment
126
+ await oway.shipments.cancel('ZKYQ5');
127
+ ```
128
+
129
+ ### Tracking
130
+
131
+ ```typescript
132
+ const tracking = await oway.shipments.tracking('ZKYQ5');
133
+ console.log(tracking.orderStatus); // 'IN_TRANSIT', 'DELIVERED', etc.
134
+ console.log(tracking.estimatedDeliveryDate);
135
+ console.log(tracking.actualDeliveryDate);
136
+ ```
137
+
138
+ ### Invoices
139
+
140
+ ```typescript
141
+ const invoice = await oway.shipments.invoice('ZKYQ5');
142
+ console.log(`Total: $${(invoice.totalChargesInCents ?? 0) / 100}`);
143
+ console.log(`Line items: ${invoice.lineItems?.length}`);
144
+ ```
145
+
146
+ ### Documents
147
+
148
+ ```typescript
149
+ const { url } = await oway.shipments.document('ZKYQ5', 'BILL_OF_LADING');
150
+ // Available types: 'BILL_OF_LADING', 'INVOICE', 'SHIPPING_LABEL'
151
+ ```
152
+
153
+ ### Multi-Tenant (Per-Request API Key)
154
+
155
+ All methods accept an optional `companyApiKey` as the last argument:
156
+
157
+ ```typescript
158
+ const shipment = await oway.shipments.create(request, 'oway_sk_...');
159
+ const tracking = await oway.shipments.tracking('ZKYQ5', 'oway_sk_...');
160
+ const invoice = await oway.shipments.invoice('ZKYQ5', 'oway_sk_...');
161
+ ```
162
+
163
+ ## Configuration
164
+
165
+ ```typescript
166
+ const oway = new Oway({
167
+ clientId: string, // Required: M2M client ID
168
+ clientSecret: string, // Required: M2M client secret
169
+ apiKey?: string, // Optional: Default company API key
170
+ baseUrl?: string, // Optional: Defaults to sandbox
171
+ tokenUrl?: string, // Optional: Custom token endpoint
172
+ maxRetries?: number, // Optional: Default 3
173
+ timeout?: number, // Optional: Default 30000ms
174
+ debug?: boolean, // Optional: Enable debug logging
175
+ });
176
+ ```
177
+
178
+ ## Environments
179
+
180
+ | Environment | Constant | URL |
181
+ |-------------|----------|-----|
182
+ | Sandbox | `OwayEnvironments.SANDBOX` | `https://rest-api.sandbox.oway.io` |
183
+ | Production | `OwayEnvironments.PRODUCTION` | `https://rest-api.oway.io` |
184
+
185
+ ## Error Handling
186
+
187
+ ```typescript
188
+ import { OwayError } from '@oway/sdk';
189
+
190
+ try {
191
+ const quote = await oway.quotes.create({ ... });
192
+ } catch (error) {
193
+ 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
+ });
200
+
201
+ if (error.isRetryable()) {
202
+ // Retry logic - SDK retries automatically up to maxRetries
203
+ }
204
+ }
205
+ }
206
+ ```
207
+
208
+ ## TypeScript Support
209
+
210
+ Full type definitions included:
211
+
212
+ ```typescript
213
+ import type { Quote, Shipment, Tracking, Invoice, QuoteRequest, ShipmentRequest, Address } from '@oway/sdk';
214
+ ```
215
+
216
+ ## Support
217
+
218
+ - **Documentation**: [docs.shipoway.com](https://docs.shipoway.com)
219
+ - **API Reference**: [rest-api.oway.io/api-docs](https://rest-api.oway.io/api-docs)
220
+ - **Email**: support@oway.io
221
+
222
+ ## License
223
+
224
+ MIT