Appearance
Core SDK (Vanilla TypeScript)
For non-React applications, use the core SDK directly.
Installation
bash
pnpm add @waspada/sdk @waspada/typesQuick Example
typescript
import { WaspadaSDK } from '@waspada/sdk';
import type { WaspadaSdkConfig } from '@waspada/types';
const config: WaspadaSdkConfig = {
source_platform: 'YOUR_PARTNER_ID',
signPayload: async (data: string) => {
// Your backend RS256 signing
const res = await fetch('/api/sign', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ data }),
});
return (await res.json()).signature;
},
ocr_languages: ['eng', 'msa'], // Optional, these are the defaults
};
const sdk = new WaspadaSDK(config);Lifecycle
1. Initialize
typescript
const status = await sdk.initAndCache();
console.log(status.ready); // true
console.log(status.storage_backend); // 'OPFS' or 'IndexedDB'
console.log(status.ocr_languages_cached); // ['eng', 'msa']
console.log(status.ner_model_cached); // true (after async download)Background Loading
initAndCache() downloads OCR language packs and the NER model in the background. Regex extraction (Tier 1) is available immediately. NER (Tier 2) becomes available once the model finishes downloading.
2. Process Evidence
typescript
const fileInput = document.querySelector<HTMLInputElement>('#file-input');
const file = fileInput.files[0];
const result = await sdk.processEvidence(file);3. Read Results
typescript
if (result.success) {
console.log('Extraction Tier:', result.extraction_tier);
// 'REGEX_ONLY' | 'NER_ENCODER' | 'HYBRID'
console.log('Confidence:', result.confidence);
// 0.0 - 1.0
console.log('Indicators:', result.indicators);
// { mule_bank_bic, mule_account_number, scammer_alias, malicious_urls }
}
if (result.warnings.length > 0) {
console.warn('Warnings:', result.warnings);
}4. Submit Telemetry
typescript
await sdk.submitTelemetry(result);
// Sends PII-stripped payload to Waspada Gateway5. Cleanup
typescript
await sdk.terminate();
// Releases OCR workers, NER pipeline, and storage handlesConfiguration Reference
| Property | Type | Default | Description |
|---|---|---|---|
source_platform | string | — | Your registered partner ID |
signPayload | (data: string) => Promise<string> | — | RS256 signing callback |
ocr_languages | OcrLanguage[] | ['eng', 'msa'] | OCR language packs to pre-cache |
gateway_url | string | https://api.waspada.ai | Gateway endpoint |
storage_key | string | 'waspada_store' | OPFS/IndexedDB storage key |
Supported File Types
| Type | Extension | Strategy |
|---|---|---|
| PDF (digital) | .pdf | Text layer extraction (~10ms/page) |
| PDF (scanned) | .pdf | OCR fallback (~2-5s/page) |
| PNG | .png | OCR with Otsu's binarization |
| JPEG | .jpg, .jpeg | OCR with Otsu's binarization |
| WebP | .webp | OCR with Otsu's binarization |
| BMP | .bmp | OCR with Otsu's binarization |