@kadoa/node-sdk 0.7.0 → 0.10.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
@@ -46,12 +46,30 @@ const client = new KadoaClient({
46
46
  });
47
47
  ```
48
48
 
49
+ ### Realtime Configuration
50
+
51
+ To enable WebSocket connections for realtime events, use a team API key (starting with `tk-`):
52
+
53
+ ```typescript
54
+ const client = new KadoaClient({
55
+ apiKey: 'tk-your-team-api-key', // Must be a team API key
56
+ enableRealtime: true,
57
+ realtimeConfig: {
58
+ autoConnect: true, // optional, default: true
59
+ reconnectDelay: 5000, // optional, default: 5000ms
60
+ heartbeatInterval: 10000 // optional, default: 10000ms
61
+ }
62
+ });
63
+ ```
64
+
49
65
  ### Using Environment Variables
50
66
 
51
67
  ```env
52
68
  KADOA_API_KEY=your-api-key
53
- KADOA_API_URL=https://api.kadoa.com
69
+ KADOA_TEAM_API_KEY=tk-your-team-api-key # For realtime features (optional)
70
+ KADOA_PUBLIC_API_URI=https://api.kadoa.com
54
71
  KADOA_TIMEOUT=30000
72
+ DEBUG=kadoa:* # Enable all SDK debug logs (optional)
55
73
  ```
56
74
 
57
75
  ```typescript
@@ -62,7 +80,7 @@ config();
62
80
 
63
81
  const client = new KadoaClient({
64
82
  apiKey: process.env.KADOA_API_KEY!,
65
- baseUrl: process.env.KADOA_API_URL,
83
+ baseUrl: process.env.KADOA_PUBLIC_API_URI,
66
84
  timeout: parseInt(process.env.KADOA_TIMEOUT || '30000')
67
85
  });
68
86
  ```
@@ -83,42 +101,209 @@ client.onEvent((event) => {
83
101
  // - extraction:status_changed
84
102
  // - extraction:data_available
85
103
  // - extraction:completed
104
+ // - realtime:connected (when WebSocket enabled)
105
+ // - realtime:disconnected
106
+ // - realtime:event
107
+ // - realtime:heartbeat
108
+ // - realtime:error
109
+ ```
110
+
111
+ ### Realtime Events
112
+
113
+ When realtime is enabled with a team API key:
114
+
115
+ ```typescript
116
+ const client = new KadoaClient({
117
+ apiKey: 'tk-your-team-api-key',
118
+ enableRealtime: true
119
+ });
120
+
121
+ // Listen to realtime events
122
+ client.onEvent((event) => {
123
+ if (event.type === 'realtime:event') {
124
+ console.log('Received realtime data:', event.payload.data);
125
+ }
126
+ });
127
+
128
+ // Manual connection control
129
+ const realtime = client.connectRealtime();
130
+
131
+ // Check connection status
132
+ if (client.isRealtimeConnected()) {
133
+ console.log('Connected to realtime server');
134
+ }
135
+
136
+ // Disconnect when done
137
+ client.disconnectRealtime();
86
138
  ```
87
139
 
88
- ## API Reference
89
-
90
- ### new KadoaClient(config)
91
- - `apiKey` (required): Your Kadoa API key
92
- - `baseUrl` (optional): API base URL (default: 'https://api.kadoa.com')
93
- - `timeout` (optional): Request timeout in milliseconds (default: 30000)
94
-
95
- Returns a client instance with:
96
- - `extraction`: Extraction module with `run()`, `submit()`, `fetchData()` methods
97
- - `workflow`: Workflow module with `get()`, `submit()`, `cancel()`, `wait()` methods
98
- - `onEvent()`: Subscribe to events
99
- - `offEvent()`: Unsubscribe from events
100
- - `dispose()`: Releases resources and removes all event listeners
101
-
102
- ### client.extraction.run(options)
103
- Runs extraction and waits for completion.
104
- - `urls`: Array of URLs to extract from
105
- - `name`: Workflow name
106
- - Additional options available in API documentation
107
-
108
- ### client.extraction.submit(options)
109
- Submits extraction without waiting for completion.
110
- - `urls`: Array of URLs to extract from
111
- - `name`: Workflow name
112
- - Returns: `{ workflowId: string }`
113
-
114
- ### client.workflow.get(workflowId)
115
- Gets the current status of a workflow.
116
- - `workflowId`: The workflow ID to query
117
- - Returns: Workflow status object
140
+ ## Debug Logging
141
+
142
+ The SDK uses the [debug](https://www.npmjs.com/package/debug) package for logging, which is disabled by default. Enable debug logs using the `DEBUG` environment variable:
143
+
144
+ ```bash
145
+ # Enable all Kadoa SDK logs
146
+ DEBUG=kadoa:* node app.js
147
+
148
+ # Enable specific modules
149
+ DEBUG=kadoa:client node app.js # Client operations only
150
+ DEBUG=kadoa:wss node app.js # WebSocket logs only
151
+ DEBUG=kadoa:extraction node app.js # Extraction module logs
152
+ DEBUG=kadoa:http node app.js # HTTP request/response logs
153
+ DEBUG=kadoa:workflow node app.js # Workflow operations
154
+
155
+ # Enable multiple modules
156
+ DEBUG=kadoa:client,kadoa:extraction node app.js
157
+ ```
118
158
 
119
159
  ## Examples
120
160
 
121
- See [examples directory](https://github.com/kadoa-org/kadoa-sdks/tree/main/examples/node-examples) for more usage examples.
161
+ ### Basic Extraction
162
+
163
+ ```typescript
164
+ import { KadoaClient } from '@kadoa/node-sdk';
165
+
166
+ const client = new KadoaClient({
167
+ apiKey: 'your-api-key'
168
+ });
169
+
170
+ // Run an extraction
171
+ const result = await client.extraction.run({
172
+ urls: ['https://sandbox.kadoa.com/ecommerce'],
173
+ name: 'My Extraction Workflow'
174
+ });
175
+
176
+ // Fetch paginated data
177
+ if (result.workflowId) {
178
+ const page1 = await client.extraction.fetchData({
179
+ workflowId: result.workflowId,
180
+ page: 1
181
+ });
182
+
183
+ console.log('Data:', page1.data?.slice(0, 5));
184
+ console.log('Pagination:', page1.pagination);
185
+ }
186
+ ```
187
+
188
+ ### WebSocket Events with Notifications
189
+
190
+ ```typescript
191
+ // Initialize client with team API key for realtime features
192
+ const client = new KadoaClient({
193
+ apiKey: 'tk-your-team-api-key',
194
+ enableRealtime: true,
195
+ });
196
+
197
+ // Listen to realtime events
198
+ client.realtime?.onEvent((event) => {
199
+ console.log('Event received:', event);
200
+ });
201
+
202
+ // List available notification events
203
+ const availableEvents = await client.notification.settings.listAllEvents();
204
+
205
+ // Run extraction with notifications
206
+ const result = await client.extraction.run({
207
+ urls: ['https://sandbox.kadoa.com/ecommerce'],
208
+ notifications: {
209
+ events: 'all', // or subset of availableEvents
210
+ channels: {
211
+ WEBSOCKET: true,
212
+ },
213
+ },
214
+ });
215
+ ```
216
+
217
+ ### Data Validation with Rules
218
+
219
+ ```typescript
220
+ import { KadoaClient, pollUntil } from '@kadoa/node-sdk';
221
+
222
+ const client = new KadoaClient({ apiKey: 'your-api-key' });
223
+
224
+ // 1. Run an extraction
225
+ const result = await client.extraction.run({
226
+ urls: ['https://sandbox.kadoa.com/ecommerce'],
227
+ });
228
+
229
+ // 2. Wait for automatic rule suggestions
230
+ const rulesResult = await pollUntil(
231
+ async () => await client.validation.listRules({
232
+ workflowId: result.workflowId,
233
+ }),
234
+ (result) => result.data.length > 0,
235
+ { pollIntervalMs: 1000, timeoutMs: 30000 }
236
+ );
237
+
238
+ // 3. Approve suggested rules
239
+ const approvedRules = await client.validation.bulkApproveRules({
240
+ workflowId: result.workflowId,
241
+ ruleIds: rulesResult.result.data.map(rule => rule.id),
242
+ });
243
+
244
+ // 4. Run validation check
245
+ const validation = await client.validation.scheduleValidation(
246
+ result.workflowId,
247
+ result.workflow?.jobId || ''
248
+ );
249
+
250
+ // 5. Wait for completion and check anomalies
251
+ const completed = await client.validation.waitUntilCompleted(
252
+ validation.validationId
253
+ );
254
+
255
+ const anomalies = await client.validation.getValidationAnomalies(
256
+ validation.validationId
257
+ );
258
+
259
+ console.log('Validation anomalies:', anomalies);
260
+ ```
261
+
262
+ ### Complete Example
263
+
264
+ ```typescript
265
+ import assert from 'node:assert';
266
+ import { KadoaClient } from '@kadoa/node-sdk';
267
+
268
+ async function main() {
269
+ const apiKey = process.env.KADOA_API_KEY;
270
+ assert(apiKey, 'KADOA_API_KEY is not set');
271
+
272
+ const client = new KadoaClient({ apiKey });
273
+
274
+ // Run extraction
275
+ const result = await client.extraction.run({
276
+ urls: ['https://sandbox.kadoa.com/ecommerce'],
277
+ });
278
+
279
+ // Fetch and display data
280
+ if (result.workflowId) {
281
+ const page1 = await client.extraction.fetchData({
282
+ workflowId: result.workflowId,
283
+ page: 1,
284
+ });
285
+
286
+ console.log('Page 1 Data:');
287
+ console.log('--------------------------------');
288
+ console.log(page1.data?.slice(0, 5));
289
+ console.log(page1.pagination);
290
+ console.log('--------------------------------');
291
+ }
292
+
293
+ console.log('Initial result:', result.data?.slice(0, 5));
294
+ }
295
+
296
+ main().catch(console.error);
297
+ ```
298
+
299
+ ### More Examples
300
+
301
+ See the [examples directory](https://github.com/kadoa-org/kadoa-sdks/tree/main/examples/node-examples) for additional usage examples including:
302
+ - Advanced extraction configurations
303
+ - Custom validation rules
304
+ - Error handling patterns
305
+ - Batch processing
306
+ - Integration patterns
122
307
 
123
308
  ## Requirements
124
309