@centrali-io/centrali-sdk 2.3.0 → 2.3.1
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 +160 -0
- package/centrali-io-centrali-sdk-2.3.0.tgz +0 -0
- package/dist/index.js +601 -1
- package/index.ts +1137 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,6 +74,8 @@ const centrali = new CentraliSDK({
|
|
|
74
74
|
- ✅ **Realtime events** - Subscribe to record changes via SSE
|
|
75
75
|
- ✅ **Compute functions** - Execute serverless functions
|
|
76
76
|
- ✅ **File uploads** - Upload files to Centrali storage
|
|
77
|
+
- ✅ **Data Validation** - AI-powered typo detection, format validation, duplicate detection
|
|
78
|
+
- ✅ **Anomaly Insights** - AI-powered anomaly detection and data quality insights
|
|
77
79
|
- ✅ **Service accounts** - Automatic token refresh for server-to-server auth
|
|
78
80
|
|
|
79
81
|
## Core Operations
|
|
@@ -248,6 +250,48 @@ const subscription = centrali.realtime.subscribe({
|
|
|
248
250
|
| `record_created` | A new record was created |
|
|
249
251
|
| `record_updated` | An existing record was updated |
|
|
250
252
|
| `record_deleted` | A record was deleted |
|
|
253
|
+
| `validation_suggestion_created` | AI detected a data quality issue |
|
|
254
|
+
| `validation_batch_completed` | Batch validation scan finished |
|
|
255
|
+
| `anomaly_insight_created` | AI detected a data anomaly |
|
|
256
|
+
| `anomaly_detection_completed` | Anomaly detection scan finished |
|
|
257
|
+
|
|
258
|
+
#### Subscribing to Validation Events
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
// Subscribe to validation events for a structure
|
|
262
|
+
const subscription = centrali.realtime.subscribe({
|
|
263
|
+
structures: ['orders'], // Filter by structure
|
|
264
|
+
events: ['validation_suggestion_created', 'validation_batch_completed'],
|
|
265
|
+
onEvent: (event) => {
|
|
266
|
+
if (event.event === 'validation_suggestion_created') {
|
|
267
|
+
console.log('New suggestion:', event.data.field, event.data.issueType);
|
|
268
|
+
console.log('Confidence:', event.data.confidence);
|
|
269
|
+
} else if (event.event === 'validation_batch_completed') {
|
|
270
|
+
console.log('Scan complete:', event.data.issuesFound, 'issues found');
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
#### Subscribing to Anomaly Events
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
// Subscribe to anomaly detection events for a structure
|
|
280
|
+
const subscription = centrali.realtime.subscribe({
|
|
281
|
+
structures: ['orders'],
|
|
282
|
+
events: ['anomaly_insight_created', 'anomaly_detection_completed'],
|
|
283
|
+
onEvent: (event) => {
|
|
284
|
+
if (event.event === 'anomaly_insight_created') {
|
|
285
|
+
console.log('New anomaly:', event.data.title);
|
|
286
|
+
console.log('Severity:', event.data.severity);
|
|
287
|
+
console.log('Type:', event.data.insightType);
|
|
288
|
+
} else if (event.event === 'anomaly_detection_completed') {
|
|
289
|
+
console.log('Analysis complete:', event.data.insightsCreated, 'anomalies found');
|
|
290
|
+
console.log('Critical:', event.data.criticalCount);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
```
|
|
251
295
|
|
|
252
296
|
#### Reconnection
|
|
253
297
|
|
|
@@ -292,6 +336,122 @@ const uploadResult = await centrali.uploadFile(
|
|
|
292
336
|
console.log('File URL:', uploadResult.data);
|
|
293
337
|
```
|
|
294
338
|
|
|
339
|
+
### Data Validation
|
|
340
|
+
|
|
341
|
+
AI-powered data quality validation to detect typos, format issues, duplicates, and semantic errors:
|
|
342
|
+
|
|
343
|
+
```typescript
|
|
344
|
+
// Trigger a batch validation scan on a structure
|
|
345
|
+
const batch = await centrali.validation.triggerScan('orders');
|
|
346
|
+
console.log('Scan started:', batch.data.batchId);
|
|
347
|
+
console.log('Records to scan:', batch.data.total);
|
|
348
|
+
|
|
349
|
+
// Wait for the scan to complete (with polling)
|
|
350
|
+
const result = await centrali.validation.waitForScan(batch.data.batchId, {
|
|
351
|
+
pollInterval: 5000, // Check every 5 seconds
|
|
352
|
+
timeout: 300000 // Timeout after 5 minutes
|
|
353
|
+
});
|
|
354
|
+
console.log('Issues found:', result.data.issuesFound);
|
|
355
|
+
|
|
356
|
+
// List pending validation suggestions
|
|
357
|
+
const suggestions = await centrali.validation.listSuggestions({
|
|
358
|
+
status: 'pending',
|
|
359
|
+
issueType: 'typo' // 'format' | 'typo' | 'duplicate' | 'semantic'
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// Review a suggestion
|
|
363
|
+
for (const suggestion of suggestions.data) {
|
|
364
|
+
console.log(`Field: ${suggestion.field}`);
|
|
365
|
+
console.log(`Original: ${suggestion.originalValue}`);
|
|
366
|
+
console.log(`Suggested: ${suggestion.suggestedValue}`);
|
|
367
|
+
console.log(`Confidence: ${suggestion.confidence}`);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Accept a suggestion (applies the fix to the record)
|
|
371
|
+
const accepted = await centrali.validation.accept('suggestion-id');
|
|
372
|
+
if (accepted.data.recordUpdated) {
|
|
373
|
+
console.log('Fix applied successfully');
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Reject a suggestion
|
|
377
|
+
await centrali.validation.reject('suggestion-id');
|
|
378
|
+
|
|
379
|
+
// Bulk accept high-confidence suggestions
|
|
380
|
+
const highConfidence = suggestions.data.filter(s => s.confidence >= 0.95);
|
|
381
|
+
await centrali.validation.bulkAccept(highConfidence.map(s => s.id));
|
|
382
|
+
|
|
383
|
+
// Get validation summary
|
|
384
|
+
const summary = await centrali.validation.getSummary();
|
|
385
|
+
console.log('Pending:', summary.data.pending);
|
|
386
|
+
console.log('By type:', summary.data.byIssueType);
|
|
387
|
+
|
|
388
|
+
// Get pending count for a structure
|
|
389
|
+
const count = await centrali.validation.getPendingCount('structure-uuid');
|
|
390
|
+
console.log('Pending issues:', count.data.pendingCount);
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
#### Validation Issue Types
|
|
394
|
+
|
|
395
|
+
| Type | Description |
|
|
396
|
+
|------|-------------|
|
|
397
|
+
| `format` | Format validation (email, phone, URL patterns) |
|
|
398
|
+
| `typo` | Spelling mistakes in text fields |
|
|
399
|
+
| `duplicate` | Duplicate records detected |
|
|
400
|
+
| `semantic` | Logical inconsistencies (e.g., end date before start date) |
|
|
401
|
+
|
|
402
|
+
### Anomaly Insights
|
|
403
|
+
|
|
404
|
+
AI-powered anomaly detection to identify unusual patterns in your data:
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
// Trigger anomaly analysis for a structure
|
|
408
|
+
const result = await centrali.anomalyInsights.triggerAnalysis('orders');
|
|
409
|
+
if (result.data.success) {
|
|
410
|
+
console.log('Analysis started:', result.data.batchId);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// List all active insights
|
|
414
|
+
const insights = await centrali.anomalyInsights.list({
|
|
415
|
+
status: 'active',
|
|
416
|
+
severity: 'critical' // 'info' | 'warning' | 'critical'
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
// List insights for a specific structure
|
|
420
|
+
const orderInsights = await centrali.anomalyInsights.listByStructure('orders');
|
|
421
|
+
|
|
422
|
+
// Get a single insight
|
|
423
|
+
const insight = await centrali.anomalyInsights.get('insight-id');
|
|
424
|
+
console.log('Title:', insight.data.title);
|
|
425
|
+
console.log('Description:', insight.data.description);
|
|
426
|
+
console.log('Affected records:', insight.data.affectedRecordIds);
|
|
427
|
+
|
|
428
|
+
// Acknowledge an insight (mark as reviewed)
|
|
429
|
+
await centrali.anomalyInsights.acknowledge('insight-id');
|
|
430
|
+
|
|
431
|
+
// Dismiss an insight (mark as not relevant)
|
|
432
|
+
await centrali.anomalyInsights.dismiss('insight-id');
|
|
433
|
+
|
|
434
|
+
// Bulk acknowledge multiple insights
|
|
435
|
+
await centrali.anomalyInsights.bulkAcknowledge(['id1', 'id2', 'id3']);
|
|
436
|
+
|
|
437
|
+
// Get insights summary
|
|
438
|
+
const summary = await centrali.anomalyInsights.getSummary();
|
|
439
|
+
console.log('Active:', summary.data.active);
|
|
440
|
+
console.log('By severity:', summary.data.bySeverity);
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
#### Insight Types
|
|
444
|
+
|
|
445
|
+
| Type | Description |
|
|
446
|
+
|------|-------------|
|
|
447
|
+
| `time_series_anomaly` | Unusual patterns in time-series data |
|
|
448
|
+
| `statistical_outlier` | Values significantly outside normal ranges |
|
|
449
|
+
| `pattern_deviation` | Deviations from expected data patterns |
|
|
450
|
+
| `volume_spike` | Unusual spikes or drops in data volume |
|
|
451
|
+
| `missing_data` | Missing or null values in required fields |
|
|
452
|
+
| `orphaned_reference` | References to deleted or non-existent records |
|
|
453
|
+
| `reference_integrity` | Broken relationships between records |
|
|
454
|
+
|
|
295
455
|
## TypeScript Support
|
|
296
456
|
|
|
297
457
|
The SDK includes full TypeScript definitions for type-safe development:
|
|
Binary file
|