@veroai/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 +291 -0
- package/dist/index.cjs +1946 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1569 -0
- package/dist/index.d.ts +1569 -0
- package/dist/index.js +1926 -0
- package/dist/index.js.map +1 -0
- package/package.json +81 -0
package/README.md
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
# @veroai/sdk
|
|
2
|
+
|
|
3
|
+
Official TypeScript/JavaScript SDK for [VeroAI](https://veroai.dev) - Unified communications API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @veroai/sdk
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @veroai/sdk
|
|
11
|
+
# or
|
|
12
|
+
yarn add @veroai/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { VeroAI } from '@veroai/sdk';
|
|
19
|
+
|
|
20
|
+
const veroai = new VeroAI({ apiKey: 'sk_live_...' });
|
|
21
|
+
|
|
22
|
+
// Send an SMS
|
|
23
|
+
const result = await veroai.messages.send({
|
|
24
|
+
channelId: 'ch_abc123',
|
|
25
|
+
to: '+15551234567',
|
|
26
|
+
content: { type: 'text', text: 'Hello from VeroAI!' }
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Send an email
|
|
30
|
+
const result = await veroai.messages.send({
|
|
31
|
+
channelId: 'ch_def456',
|
|
32
|
+
to: 'user@example.com',
|
|
33
|
+
subject: 'Welcome!',
|
|
34
|
+
content: {
|
|
35
|
+
type: 'html',
|
|
36
|
+
html: '<h1>Welcome to our platform</h1>'
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
- **Full TypeScript support** with comprehensive types
|
|
44
|
+
- **Automatic retries** with exponential backoff
|
|
45
|
+
- **Error handling** with typed error classes
|
|
46
|
+
- **Real-time events** via WebSocket subscriptions
|
|
47
|
+
- **Works everywhere** - Node.js, browsers, edge runtimes
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
### Initialize the Client
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { VeroAI } from '@veroai/sdk';
|
|
55
|
+
|
|
56
|
+
// With API key
|
|
57
|
+
const veroai = new VeroAI({ apiKey: 'sk_live_...' });
|
|
58
|
+
|
|
59
|
+
// With custom options
|
|
60
|
+
const veroai = new VeroAI({
|
|
61
|
+
apiKey: 'sk_test_...',
|
|
62
|
+
baseUrl: 'https://api.staging.veroai.dev',
|
|
63
|
+
timeout: 60000,
|
|
64
|
+
maxRetries: 5,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// From environment variables (reads VEROAI_API_KEY)
|
|
68
|
+
const veroai = VeroAI.fromEnv();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Channels
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
// List all channels
|
|
75
|
+
const { data: channels } = await veroai.channels.list();
|
|
76
|
+
|
|
77
|
+
// Create a channel
|
|
78
|
+
const { channel, oauthUrl } = await veroai.channels.create({
|
|
79
|
+
name: 'Support Email',
|
|
80
|
+
adapterType: 'gmail-oauth',
|
|
81
|
+
direction: 'bidirectional',
|
|
82
|
+
config: {},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Get channel health
|
|
86
|
+
const health = await veroai.channels.health('ch_abc123');
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Messages
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// Send a message
|
|
93
|
+
const result = await veroai.messages.send({
|
|
94
|
+
channelId: 'ch_abc123',
|
|
95
|
+
to: '+15551234567',
|
|
96
|
+
content: { type: 'text', text: 'Hello!' }
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Send to multiple recipients
|
|
100
|
+
const results = await veroai.messages.sendBatch({
|
|
101
|
+
channelId: 'ch_abc123',
|
|
102
|
+
messages: [
|
|
103
|
+
{ to: '+15551234567', content: { type: 'text', text: 'Hello!' } },
|
|
104
|
+
{ to: '+15559876543', content: { type: 'text', text: 'Hi there!' } },
|
|
105
|
+
]
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Events
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// List events
|
|
113
|
+
const { data: events } = await veroai.events.list({
|
|
114
|
+
channelId: 'ch_abc123',
|
|
115
|
+
startDate: new Date('2024-01-01'),
|
|
116
|
+
canonicalType: 'message',
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Get event statistics
|
|
120
|
+
const stats = await veroai.events.stats({ days: 7 });
|
|
121
|
+
|
|
122
|
+
// Get time series data
|
|
123
|
+
const timeseries = await veroai.events.timeseries({
|
|
124
|
+
days: 7,
|
|
125
|
+
granularity: 'hour',
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Webhooks
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
// Create a webhook
|
|
133
|
+
const { webhook, secret } = await veroai.webhooks.create({
|
|
134
|
+
name: 'My Webhook',
|
|
135
|
+
url: 'https://example.com/webhook',
|
|
136
|
+
events: ['message.received', 'message.sent'],
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Save the secret for signature verification!
|
|
140
|
+
console.log('Webhook secret:', secret);
|
|
141
|
+
|
|
142
|
+
// List delivery history
|
|
143
|
+
const { data: deliveries } = await veroai.webhooks.deliveries('wh_abc123');
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### API Keys
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
// Create an API key
|
|
150
|
+
const { apiKey, key } = await veroai.apiKeys.create({
|
|
151
|
+
name: 'Production Key',
|
|
152
|
+
environment: 'production',
|
|
153
|
+
scopes: ['channels:read', 'messages:send'],
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Save the key securely - it won't be shown again!
|
|
157
|
+
console.log('API Key:', key);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Domains
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
// Add a domain
|
|
164
|
+
const { domain, verificationRecord } = await veroai.domains.create({
|
|
165
|
+
domain: 'example.com',
|
|
166
|
+
verificationMethod: 'manual',
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Verify domain
|
|
170
|
+
const result = await veroai.domains.verify('dom_abc123');
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Real-time Events
|
|
174
|
+
|
|
175
|
+
Subscribe to real-time events via WebSocket:
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
// Connect to the WebSocket server
|
|
179
|
+
await veroai.realtime.connect();
|
|
180
|
+
|
|
181
|
+
// Listen for events
|
|
182
|
+
veroai.realtime.onEvent((event) => {
|
|
183
|
+
console.log('Received event:', event.canonicalType, event.payload);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// Listen for connection state changes
|
|
187
|
+
veroai.realtime.onStateChange((state) => {
|
|
188
|
+
console.log('Connection state:', state);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// Handle errors
|
|
192
|
+
veroai.realtime.onError((error) => {
|
|
193
|
+
console.error('WebSocket error:', error);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Subscribe to all events
|
|
197
|
+
await veroai.realtime.subscribeAll();
|
|
198
|
+
|
|
199
|
+
// Or subscribe to specific channels
|
|
200
|
+
await veroai.realtime.subscribeChannels(['ch_abc123', 'ch_def456']);
|
|
201
|
+
|
|
202
|
+
// Or subscribe to specific event types
|
|
203
|
+
await veroai.realtime.subscribeEventTypes(['message.received', 'message.sent']);
|
|
204
|
+
|
|
205
|
+
// Unsubscribe when done
|
|
206
|
+
await veroai.realtime.unsubscribeChannels(['ch_abc123']);
|
|
207
|
+
|
|
208
|
+
// Disconnect
|
|
209
|
+
veroai.realtime.disconnect();
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
The realtime client automatically reconnects on connection loss and resubscribes to all active subscriptions.
|
|
213
|
+
|
|
214
|
+
#### Realtime Configuration
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
const veroai = new VeroAI({
|
|
218
|
+
apiKey: 'sk_live_...',
|
|
219
|
+
realtime: {
|
|
220
|
+
url: 'wss://realtime.veroai.dev/ws', // Custom WebSocket URL
|
|
221
|
+
autoReconnect: true, // Auto-reconnect on disconnect
|
|
222
|
+
reconnectInterval: 1000, // Initial reconnect delay (ms)
|
|
223
|
+
maxReconnectAttempts: 10, // Max reconnection attempts (0 = infinite)
|
|
224
|
+
heartbeatInterval: 30000, // Heartbeat interval (ms)
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
#### Node.js WebSocket Support
|
|
230
|
+
|
|
231
|
+
In Node.js, install the `ws` package for WebSocket support:
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
npm install ws
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Error Handling
|
|
238
|
+
|
|
239
|
+
The SDK provides typed error classes for different scenarios:
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
import {
|
|
243
|
+
VeroAI,
|
|
244
|
+
AuthenticationError,
|
|
245
|
+
RateLimitError,
|
|
246
|
+
ValidationError,
|
|
247
|
+
NotFoundError,
|
|
248
|
+
} from '@veroai/sdk';
|
|
249
|
+
|
|
250
|
+
try {
|
|
251
|
+
await veroai.messages.send({ ... });
|
|
252
|
+
} catch (error) {
|
|
253
|
+
if (error instanceof AuthenticationError) {
|
|
254
|
+
console.log('Invalid API key');
|
|
255
|
+
} else if (error instanceof RateLimitError) {
|
|
256
|
+
console.log(`Rate limited. Retry after ${error.retryAfter}s`);
|
|
257
|
+
} else if (error instanceof ValidationError) {
|
|
258
|
+
console.log('Invalid request:', error.details);
|
|
259
|
+
} else if (error instanceof NotFoundError) {
|
|
260
|
+
console.log('Resource not found');
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## TypeScript
|
|
266
|
+
|
|
267
|
+
The SDK is written in TypeScript and provides comprehensive type definitions:
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
import type {
|
|
271
|
+
Channel,
|
|
272
|
+
ActivityEvent,
|
|
273
|
+
Webhook,
|
|
274
|
+
SendMessageParams,
|
|
275
|
+
} from '@veroai/sdk';
|
|
276
|
+
|
|
277
|
+
const params: SendMessageParams = {
|
|
278
|
+
channelId: 'ch_abc123',
|
|
279
|
+
to: '+15551234567',
|
|
280
|
+
content: { type: 'text', text: 'Hello!' }
|
|
281
|
+
};
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Requirements
|
|
285
|
+
|
|
286
|
+
- Node.js >= 18 (or a fetch polyfill)
|
|
287
|
+
- TypeScript >= 5.0 (optional, for type definitions)
|
|
288
|
+
|
|
289
|
+
## License
|
|
290
|
+
|
|
291
|
+
MIT
|