deliveryapi 0.1.4 → 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/dist/index.cjs +282 -202
- package/dist/index.d.cts +437 -461
- package/dist/index.d.ts +437 -461
- package/dist/index.js +281 -198
- package/package.json +2 -5
- package/README.md +0 -252
package/README.md
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
# deliveryapi
|
|
2
|
-
|
|
3
|
-
Official JavaScript/TypeScript SDK for the [DeliveryAPI](https://deliveryapi.co.kr) — Korea's unified courier tracking API.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install deliveryapi
|
|
9
|
-
# or
|
|
10
|
-
yarn add deliveryapi
|
|
11
|
-
# or
|
|
12
|
-
pnpm add deliveryapi
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Quick Start
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
import { DeliverySaasClient } from 'deliveryapi'
|
|
19
|
-
|
|
20
|
-
const client = new DeliverySaasClient({
|
|
21
|
-
apiKey: 'your-api-key',
|
|
22
|
-
secretKey: 'your-secret-key',
|
|
23
|
-
})
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
API keys can be issued at [deliveryapi.co.kr](https://deliveryapi.co.kr).
|
|
27
|
-
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
## Tracking
|
|
31
|
-
|
|
32
|
-
### Single tracking
|
|
33
|
-
|
|
34
|
-
```typescript
|
|
35
|
-
const result = await client.tracking.getOne('LOTTE', '1234567890')
|
|
36
|
-
|
|
37
|
-
console.log(result.results[0].status) // 'DELIVERED'
|
|
38
|
-
console.log(result.results[0].progresses) // delivery history
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### Multiple tracking at once
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
const result = await client.tracking.get([
|
|
45
|
-
{ courierCode: 'LOTTE', trackingNumber: '1234567890' },
|
|
46
|
-
{ courierCode: 'CJ', trackingNumber: '9876543210' },
|
|
47
|
-
])
|
|
48
|
-
|
|
49
|
-
for (const item of result.results) {
|
|
50
|
-
console.log(item.trackingNumber, item.status)
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Without delivery history (faster)
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
const result = await client.tracking.getOne('CJ', '1234567890', {
|
|
58
|
-
includeProgresses: false,
|
|
59
|
-
})
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
---
|
|
63
|
-
|
|
64
|
-
## Webhook Endpoints
|
|
65
|
-
|
|
66
|
-
Register a URL to receive real-time delivery status change notifications.
|
|
67
|
-
|
|
68
|
-
### Register endpoint
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
const endpoint = await client.webhooks.create({
|
|
72
|
-
url: 'https://your-server.com/webhook',
|
|
73
|
-
name: 'Production Webhook',
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
console.log(endpoint.id) // 'ep_xxxxxxxxxxxx'
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### List endpoints
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
const { endpoints } = await client.webhooks.list()
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### Test endpoint
|
|
86
|
-
|
|
87
|
-
```typescript
|
|
88
|
-
const result = await client.webhooks.test('ep_xxxxxxxxxxxx')
|
|
89
|
-
console.log(result.success) // true
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### Delete endpoint
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
await client.webhooks.delete('ep_xxxxxxxxxxxx')
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
## Tracking Subscriptions
|
|
101
|
-
|
|
102
|
-
Subscribe to a tracking number and receive webhook notifications when status changes.
|
|
103
|
-
|
|
104
|
-
### Create subscription
|
|
105
|
-
|
|
106
|
-
```typescript
|
|
107
|
-
const subscription = await client.subscriptions.create({
|
|
108
|
-
courierCode: 'LOTTE',
|
|
109
|
-
trackingNumber: '1234567890',
|
|
110
|
-
endpointId: 'ep_xxxxxxxxxxxx',
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
console.log(subscription.id) // 'sub_xxxxxxxxxxxx'
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### Subscribe to specific statuses only
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
const subscription = await client.subscriptions.create({
|
|
120
|
-
courierCode: 'CJ',
|
|
121
|
-
trackingNumber: '9876543210',
|
|
122
|
-
endpointId: 'ep_xxxxxxxxxxxx',
|
|
123
|
-
subscribedStatuses: ['IN_TRANSIT', 'DELIVERED'],
|
|
124
|
-
})
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### List subscriptions
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
130
|
-
const { subscriptions, total } = await client.subscriptions.list({
|
|
131
|
-
status: 'ACTIVE',
|
|
132
|
-
page: 1,
|
|
133
|
-
pageSize: 20,
|
|
134
|
-
})
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
### Retrieve subscription
|
|
138
|
-
|
|
139
|
-
```typescript
|
|
140
|
-
const subscription = await client.subscriptions.retrieve('sub_xxxxxxxxxxxx')
|
|
141
|
-
console.log(subscription.status) // 'ACTIVE'
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
### Cancel subscription
|
|
145
|
-
|
|
146
|
-
```typescript
|
|
147
|
-
await client.subscriptions.cancel('sub_xxxxxxxxxxxx')
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
---
|
|
151
|
-
|
|
152
|
-
## Couriers
|
|
153
|
-
|
|
154
|
-
### List supported couriers
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
const { couriers } = await client.couriers.list()
|
|
158
|
-
|
|
159
|
-
for (const courier of couriers) {
|
|
160
|
-
console.log(courier.code, courier.name) // 'LOTTE', '롯데택배'
|
|
161
|
-
}
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
---
|
|
165
|
-
|
|
166
|
-
## Webhook Payload
|
|
167
|
-
|
|
168
|
-
When a tracking status changes, your endpoint receives a POST request with the following payload:
|
|
169
|
-
|
|
170
|
-
```typescript
|
|
171
|
-
import type { WebhookPayload } from 'deliveryapi'
|
|
172
|
-
|
|
173
|
-
app.post('/webhook', (req, res) => {
|
|
174
|
-
const payload: WebhookPayload = req.body
|
|
175
|
-
|
|
176
|
-
console.log(payload.subscriptionId)
|
|
177
|
-
console.log(payload.courierCode)
|
|
178
|
-
console.log(payload.trackingNumber)
|
|
179
|
-
console.log(payload.status) // 'DELIVERED'
|
|
180
|
-
console.log(payload.changedAt) // ISO 8601 timestamp
|
|
181
|
-
|
|
182
|
-
res.sendStatus(200)
|
|
183
|
-
})
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
---
|
|
187
|
-
|
|
188
|
-
## Error Handling
|
|
189
|
-
|
|
190
|
-
```typescript
|
|
191
|
-
import {
|
|
192
|
-
DeliverySaasClient,
|
|
193
|
-
AuthenticationError,
|
|
194
|
-
RateLimitError,
|
|
195
|
-
NotFoundError,
|
|
196
|
-
DeliverySaasError,
|
|
197
|
-
} from 'deliveryapi'
|
|
198
|
-
|
|
199
|
-
try {
|
|
200
|
-
const result = await client.tracking.getOne('LOTTE', '1234567890')
|
|
201
|
-
} catch (error) {
|
|
202
|
-
if (error instanceof AuthenticationError) {
|
|
203
|
-
// Invalid API key or secret key
|
|
204
|
-
console.error('Authentication failed')
|
|
205
|
-
} else if (error instanceof RateLimitError) {
|
|
206
|
-
// Request limit exceeded
|
|
207
|
-
console.error('Rate limit exceeded, retry later')
|
|
208
|
-
} else if (error instanceof NotFoundError) {
|
|
209
|
-
// Resource not found
|
|
210
|
-
console.error('Not found')
|
|
211
|
-
} else if (error instanceof DeliverySaasError) {
|
|
212
|
-
// Other API errors
|
|
213
|
-
console.error(error.message, error.statusCode)
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
---
|
|
219
|
-
|
|
220
|
-
## TypeScript
|
|
221
|
-
|
|
222
|
-
Full TypeScript support is included out of the box.
|
|
223
|
-
|
|
224
|
-
```typescript
|
|
225
|
-
import type {
|
|
226
|
-
TrackingResponse,
|
|
227
|
-
TrackingSubscription,
|
|
228
|
-
WebhookEndpoint,
|
|
229
|
-
WebhookPayload,
|
|
230
|
-
CourierDeliveryStatus,
|
|
231
|
-
} from 'deliveryapi'
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
---
|
|
235
|
-
|
|
236
|
-
## Supported Couriers
|
|
237
|
-
|
|
238
|
-
| Code | Name |
|
|
239
|
-
|------|------|
|
|
240
|
-
| `LOTTE` | 롯데택배 |
|
|
241
|
-
| `CJ` | CJ대한통운 |
|
|
242
|
-
| `HANJIN` | 한진택배 |
|
|
243
|
-
| `POST` | 우체국택배 |
|
|
244
|
-
| `LOGEN` | 로젠택배 |
|
|
245
|
-
|
|
246
|
-
Full list available via `client.couriers.list()`.
|
|
247
|
-
|
|
248
|
-
---
|
|
249
|
-
|
|
250
|
-
## License
|
|
251
|
-
|
|
252
|
-
MIT
|