{"_id":"@cloak-business/sdk","name":"@cloak-business/sdk","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@cloak-business/sdk","version":"1.0.0","description":"Official JavaScript/TypeScript SDK for cloak.business PII detection and anonymization API","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"build":"tsup","dev":"tsup --watch","test":"vitest run","test:watch":"vitest","lint":"eslint src --ext .ts","typecheck":"tsc --noEmit","prepublishOnly":"npm run build"},"keywords":["pii","anonymization","privacy","gdpr","data-protection","presidio","cloak","redaction","encryption"],"author":{"name":"cloak.business"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/cloak-business/sdk-js.git"},"homepage":"https://cloak.business/docs/developer/api","bugs":{"url":"https://github.com/cloak-business/sdk-js/issues"},"engines":{"node":">=18.0.0"},"devDependencies":{"@types/node":"^20.0.0","tsup":"^8.0.0","typescript":"^5.3.0","vitest":"^1.0.0"},"_id":"@cloak-business/sdk@1.0.0","gitHead":"33f4413c113dcf1bfc372b45766c961fd1f5435d","_nodeVersion":"24.7.0","_npmVersion":"11.6.0","dist":{"integrity":"sha512-5bcxQKA0cDCIrRQQBwAAqiBYuDdIBJ69nvteYs+7SD4l4SzGcY5jI9nuFdN5+41e7TD2UpxsRD+ZtFgAczpz3w==","shasum":"5899e31472abc8d6a8a1b89a38f9fad2f2150ad6","tarball":"https://registry.npmjs.org/@cloak-business/sdk/-/sdk-1.0.0.tgz","fileCount":8,"unpackedSize":250192,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDGpSA/1j8Rts84UDWgSwGZWow1cU5lF3n3MMKZJ/ZJdwIhAMWZfSTYKOgnjiSw6RYpUtbe8o0imohNG+juSetNg4zy"}]},"_npmUser":{"name":"acloakbusiness","email":"npm@cloak.business"},"directories":{},"maintainers":[{"name":"acloakbusiness","email":"npm@cloak.business"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sdk_1.0.0_1771332994909_0.7024395767459484"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-17T12:56:34.804Z","1.0.0":"2026-02-17T12:56:35.066Z","modified":"2026-02-17T12:56:35.317Z"},"maintainers":[{"name":"acloakbusiness","email":"npm@cloak.business"}],"description":"Official JavaScript/TypeScript SDK for cloak.business PII detection and anonymization API","homepage":"https://cloak.business/docs/developer/api","keywords":["pii","anonymization","privacy","gdpr","data-protection","presidio","cloak","redaction","encryption"],"repository":{"type":"git","url":"git+https://github.com/cloak-business/sdk-js.git"},"author":{"name":"cloak.business"},"bugs":{"url":"https://github.com/cloak-business/sdk-js/issues"},"license":"MIT","readme":"# @cloak-business/sdk\r\n\r\nOfficial JavaScript/TypeScript SDK for the [cloak.business](https://cloak.business) PII detection and anonymization API.\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install @cloak-business/sdk\r\n```\r\n\r\n## Quick Start\r\n\r\n```typescript\r\nimport { CloakClient } from '@cloak-business/sdk';\r\n\r\nconst client = new CloakClient({\r\n  apiKey: 'cb_your_api_key_here',\r\n});\r\n\r\n// Analyze text for PII\r\nconst analysis = await client.analyze({\r\n  text: 'Contact John Doe at john@example.com',\r\n});\r\n\r\nconsole.log(analysis.results);\r\n// [\r\n//   { entity_type: 'PERSON', start: 8, end: 16, score: 0.85 },\r\n//   { entity_type: 'EMAIL_ADDRESS', start: 20, end: 36, score: 1.0 }\r\n// ]\r\n```\r\n\r\n## Features\r\n\r\n- Full TypeScript support with comprehensive type definitions\r\n- Automatic retry with exponential backoff on network/server errors\r\n- Rate limit handling with retry-after support\r\n- Request timeout configuration\r\n- Custom fetch implementation support (for testing or special environments)\r\n\r\n## API Reference\r\n\r\n### Configuration\r\n\r\n```typescript\r\nconst client = new CloakClient({\r\n  apiKey: 'cb_your_api_key_here',  // Required: Your API key\r\n  baseUrl: 'https://cloak.business/api',  // Optional: API base URL\r\n  timeout: 30000,  // Optional: Request timeout in ms (default: 30000)\r\n  retries: 3,      // Optional: Retry count on 5xx/network errors (default: 3)\r\n});\r\n```\r\n\r\n### Text Analysis\r\n\r\n#### `analyze(request)`\r\n\r\nDetect PII entities in text.\r\n\r\n```typescript\r\nconst result = await client.analyze({\r\n  text: 'My email is john@example.com and my SSN is 123-45-6789',\r\n  language: 'en',              // Optional: ISO 639-1 language code\r\n  entities: ['EMAIL_ADDRESS', 'US_SSN'],  // Optional: Filter entity types\r\n  score_threshold: 0.5,        // Optional: Minimum confidence (0.0-1.0)\r\n});\r\n```\r\n\r\n#### `batchAnalyze(request)`\r\n\r\nAnalyze multiple texts in a single request (max 50 texts).\r\n\r\n```typescript\r\nconst result = await client.batchAnalyze({\r\n  texts: [\r\n    'Contact john@example.com',\r\n    'Call me at 555-1234',\r\n  ],\r\n  language: 'en',\r\n});\r\n```\r\n\r\n### Anonymization\r\n\r\n#### `anonymize(request)`\r\n\r\nAnonymize detected PII entities using various operators.\r\n\r\n```typescript\r\nconst result = await client.anonymize({\r\n  text: 'Contact John at john@example.com',\r\n  analyzer_results: analysis.results,\r\n  operators: {\r\n    PERSON: { type: 'replace', new_value: '[NAME]' },\r\n    EMAIL_ADDRESS: { type: 'hash', hash_type: 'sha256' },\r\n    DEFAULT: { type: 'redact' },  // Fallback for other types\r\n  },\r\n});\r\n```\r\n\r\n**Available Operators:**\r\n\r\n| Operator | Description | Options |\r\n|----------|-------------|---------|\r\n| `replace` | Replace with custom text | `new_value` |\r\n| `redact` | Remove completely | - |\r\n| `hash` | One-way hash | `hash_type`: 'sha256' or 'sha512' |\r\n| `mask` | Partial masking | `masking_char`, `chars_to_mask`, `from_end` |\r\n| `encrypt` | Reversible encryption | `key` (16/24/32 chars) |\r\n| `keep` | Leave unchanged | - |\r\n\r\n#### `deanonymize(request)`\r\n\r\nDecrypt encrypted PII entities.\r\n\r\n```typescript\r\nconst decrypted = await client.deanonymize({\r\n  text: encrypted.text,\r\n  anonymizer_results: encrypted.items,\r\n  deanonymizers: {\r\n    PERSON: { type: 'decrypt', key: 'my-32-character-secret-key!!' },\r\n    EMAIL_ADDRESS: { type: 'decrypt', key: 'my-32-character-secret-key!!' },\r\n  },\r\n});\r\n```\r\n\r\n### Image Processing\r\n\r\n#### `processImage(request)`\r\n\r\nDetect or redact PII in images.\r\n\r\n```typescript\r\n// Analyze mode - returns detected entities\r\nconst analysis = await client.processImage({\r\n  file: './document.png',  // File path, Buffer, or Blob\r\n  mode: 'analyze',\r\n  language: 'en',\r\n});\r\n\r\n// Redact mode - returns image buffer\r\nconst redactedBuffer = await client.processImage({\r\n  file: imageBuffer,\r\n  mode: 'redact',\r\n  fill_color: 'black',  // 'black', 'white', 'red', 'green', 'blue', 'gray'\r\n});\r\n```\r\n\r\n### Account Management\r\n\r\n```typescript\r\n// Get token balance\r\nconst balance = await client.getTokenBalance();\r\nconsole.log(`Tokens: ${balance.balance}`);\r\n\r\n// List encryption sessions\r\nconst sessions = await client.getSessions();\r\n\r\n// Delete a session\r\nawait client.deleteSession('session-id');\r\n```\r\n\r\n### Utility Methods\r\n\r\n```typescript\r\n// Get API limits\r\nconst limits = await client.getLimits();\r\n\r\n// Get available presets\r\nconst presets = await client.getPresets();\r\n\r\n// Get all entity types\r\nconst entities = await client.getEntities();\r\n\r\n// Health check\r\nconst health = await client.health();\r\n```\r\n\r\n## Error Handling\r\n\r\nThe SDK provides typed errors for different failure scenarios:\r\n\r\n```typescript\r\nimport {\r\n  CloakClient,\r\n  AuthenticationError,\r\n  RateLimitError,\r\n  InsufficientTokensError,\r\n  ValidationError,\r\n} from '@cloak-business/sdk';\r\n\r\ntry {\r\n  await client.analyze({ text: 'test' });\r\n} catch (error) {\r\n  if (error instanceof AuthenticationError) {\r\n    console.error('Invalid API key');\r\n  } else if (error instanceof RateLimitError) {\r\n    console.error(`Rate limited. Retry after ${error.retryAfter}s`);\r\n  } else if (error instanceof InsufficientTokensError) {\r\n    console.error('Not enough tokens');\r\n  } else if (error instanceof ValidationError) {\r\n    console.error('Invalid request:', error.details);\r\n  }\r\n}\r\n```\r\n\r\n## Requirements\r\n\r\n- Node.js 18.0.0 or higher\r\n- Browser environments with native `fetch` support\r\n\r\n## License\r\n\r\nMIT\r\n","readmeFilename":"README.md","_rev":"1-f7ff8d6363b6cd7a882fe2fdf883d805"}