@dispatchtickets/sdk 0.3.0 → 0.7.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 +57 -9
- package/dist/index.cjs +708 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +979 -15
- package/dist/index.d.ts +979 -15
- package/dist/index.js +699 -67
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -44,12 +44,44 @@ const client = new DispatchTickets({
|
|
|
44
44
|
apiKey: 'sk_live_...', // Required
|
|
45
45
|
baseUrl: 'https://...', // Optional, default: production API
|
|
46
46
|
timeout: 30000, // Optional, request timeout in ms
|
|
47
|
-
maxRetries: 3, // Optional, retry count for failed requests
|
|
48
47
|
debug: false, // Optional, enable debug logging
|
|
49
48
|
fetch: customFetch, // Optional, custom fetch for testing
|
|
49
|
+
retry: { // Optional, fine-grained retry config
|
|
50
|
+
maxRetries: 3,
|
|
51
|
+
retryableStatuses: [429, 500, 502, 503, 504],
|
|
52
|
+
initialDelayMs: 1000,
|
|
53
|
+
maxDelayMs: 30000,
|
|
54
|
+
},
|
|
55
|
+
hooks: { // Optional, observability hooks
|
|
56
|
+
onRequest: (ctx) => console.log(`${ctx.method} ${ctx.url}`),
|
|
57
|
+
onResponse: (ctx) => console.log(`${ctx.status} in ${ctx.durationMs}ms`),
|
|
58
|
+
onError: (error) => Sentry.captureException(error),
|
|
59
|
+
onRetry: (ctx, error, delay) => console.log(`Retrying in ${delay}ms`),
|
|
60
|
+
},
|
|
50
61
|
});
|
|
51
62
|
```
|
|
52
63
|
|
|
64
|
+
### Request Cancellation
|
|
65
|
+
|
|
66
|
+
Cancel long-running requests with an AbortController:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
const controller = new AbortController();
|
|
70
|
+
|
|
71
|
+
// Cancel after 5 seconds
|
|
72
|
+
setTimeout(() => controller.abort(), 5000);
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const page = await client.tickets.listPage('ws_abc', {}, {
|
|
76
|
+
signal: controller.signal,
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error.message.includes('aborted')) {
|
|
80
|
+
console.log('Request was cancelled');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
53
85
|
## Resources
|
|
54
86
|
|
|
55
87
|
### Accounts
|
|
@@ -303,30 +335,36 @@ await client.fields.delete('ws_abc123', 'ticket', 'order_id');
|
|
|
303
335
|
|
|
304
336
|
## Error Handling
|
|
305
337
|
|
|
338
|
+
Use type guards for clean error handling:
|
|
339
|
+
|
|
306
340
|
```typescript
|
|
307
341
|
import {
|
|
308
342
|
DispatchTickets,
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
343
|
+
isNotFoundError,
|
|
344
|
+
isAuthenticationError,
|
|
345
|
+
isRateLimitError,
|
|
346
|
+
isValidationError,
|
|
313
347
|
} from '@dispatchtickets/sdk';
|
|
314
348
|
|
|
315
349
|
try {
|
|
316
350
|
await client.tickets.get('ws_abc123', 'tkt_invalid');
|
|
317
351
|
} catch (error) {
|
|
318
|
-
if (error
|
|
352
|
+
if (isNotFoundError(error)) {
|
|
319
353
|
console.log('Ticket not found');
|
|
320
|
-
|
|
354
|
+
console.log('Request ID:', error.requestId); // For debugging with support
|
|
355
|
+
} else if (isAuthenticationError(error)) {
|
|
321
356
|
console.log('Invalid API key');
|
|
322
|
-
} else if (error
|
|
357
|
+
} else if (isRateLimitError(error)) {
|
|
323
358
|
console.log(`Rate limited. Retry after ${error.retryAfter} seconds`);
|
|
324
|
-
|
|
359
|
+
console.log(`Limit: ${error.limit}, Remaining: ${error.remaining}`);
|
|
360
|
+
} else if (isValidationError(error)) {
|
|
325
361
|
console.log('Validation errors:', error.errors);
|
|
326
362
|
}
|
|
327
363
|
}
|
|
328
364
|
```
|
|
329
365
|
|
|
366
|
+
All errors include a `requestId` for debugging with support.
|
|
367
|
+
|
|
330
368
|
## Webhook Events
|
|
331
369
|
|
|
332
370
|
Handle webhook events with full type safety:
|
|
@@ -427,6 +465,16 @@ See the `/examples` directory for complete working examples:
|
|
|
427
465
|
- **[nextjs-api-route.ts](./examples/nextjs-api-route.ts)** - Next.js App Router webhook handler
|
|
428
466
|
- **[basic-usage.ts](./examples/basic-usage.ts)** - Common SDK operations (tickets, comments, pagination)
|
|
429
467
|
|
|
468
|
+
## API Documentation
|
|
469
|
+
|
|
470
|
+
Generate TypeDoc API documentation locally:
|
|
471
|
+
|
|
472
|
+
```bash
|
|
473
|
+
npm run docs
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
This creates a `docs/` folder with HTML documentation for all exported types and methods.
|
|
477
|
+
|
|
430
478
|
## Links
|
|
431
479
|
|
|
432
480
|
- [API Reference (Swagger)](https://dispatch-tickets-api.onrender.com/docs)
|