@privacyscrubber/sdk 2.2.0 → 2.2.2
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 +178 -6
- package/cli.js +166 -19
- package/index.d.ts +122 -0
- package/index.js +626 -17
- package/package.json +1 -1
- package/ps-license-manager.js +1 -1
- package/ps-pii-engine.cjs +1 -1
- package/scrubber-core.cjs +1 -21
package/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export type PiiProfile =
|
|
|
34
34
|
| 'Insurance'
|
|
35
35
|
| 'Accounting'
|
|
36
36
|
| 'Pharma'
|
|
37
|
+
| 'Biotech'
|
|
37
38
|
| 'Underwriting'
|
|
38
39
|
| 'Crypto'
|
|
39
40
|
| 'Cloud'
|
|
@@ -69,12 +70,15 @@ export interface SanitizeOptions {
|
|
|
69
70
|
generateReceipt?: boolean;
|
|
70
71
|
/** Throw PrivacyScrubberLicenseError when free tier limits are reached (Default: true). */
|
|
71
72
|
throwOnLimit?: boolean;
|
|
73
|
+
/** Strategy when free tier limit is exceeded: 'throw' (default) or 'truncate' (soft limit with notification). */
|
|
74
|
+
onLimit?: 'throw' | 'truncate';
|
|
72
75
|
}
|
|
73
76
|
|
|
74
77
|
export interface LicenseMetadata {
|
|
75
78
|
isPro: boolean;
|
|
76
79
|
tier: 'PRO' | 'TEAMS' | 'SDK' | 'ENTERPRISE' | 'OEM' | 'FREE';
|
|
77
80
|
limit: number;
|
|
81
|
+
wasTruncated?: boolean;
|
|
78
82
|
upgradeUrl?: string;
|
|
79
83
|
recommendation?: string;
|
|
80
84
|
}
|
|
@@ -132,6 +136,24 @@ export function validateLicenseKey(key: string): 'PRO' | 'TEAMS' | 'SDK' | 'ENTE
|
|
|
132
136
|
export function buildAuditTelemetry(currentTokenMap?: Record<string, string> | string[]): AuditTelemetry;
|
|
133
137
|
export function formatAuditReceipt(telemetry: AuditTelemetry): string;
|
|
134
138
|
|
|
139
|
+
export interface ProcurementMemoOptions {
|
|
140
|
+
/** Target application or pipeline name (Default: 'Internal AI Applications & LLM Pipelines'). */
|
|
141
|
+
appName?: string;
|
|
142
|
+
/** Team or developer name (Default: 'Engineering / AI Platform Team'). */
|
|
143
|
+
developer?: string;
|
|
144
|
+
/** Output format: 'markdown' or 'text' (Default: 'markdown'). */
|
|
145
|
+
format?: 'markdown' | 'text';
|
|
146
|
+
/** Number of engineers on the team (Default: 10). */
|
|
147
|
+
teamSize?: number;
|
|
148
|
+
/** Estimated monthly prompt volume (Default: '50M - 500M characters/month'). */
|
|
149
|
+
estimatedVolume?: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Generates an executive CISO & Legal Procurement Memo for enterprise approval of @privacyscrubber/sdk.
|
|
154
|
+
*/
|
|
155
|
+
export function generateProcurementMemo(options?: ProcurementMemoOptions): string;
|
|
156
|
+
|
|
135
157
|
/**
|
|
136
158
|
* Sanitizes input text, masking all PII and secrets with zero network requests.
|
|
137
159
|
*/
|
|
@@ -163,6 +185,8 @@ export class PrivacyScrubberEngine {
|
|
|
163
185
|
sanitize(text: string, options?: SanitizeOptions & { persistSession?: boolean }): SanitizeResult;
|
|
164
186
|
restore(aiResponse: string, tokenMap?: Record<string, string> | null): RestoreResult;
|
|
165
187
|
resetSession(): void;
|
|
188
|
+
createStreamRestorer(tokenMap?: Record<string, string> | null, options?: any): StreamTokenRestorer;
|
|
189
|
+
wrapStream<T = any>(stream: AsyncIterable<T>, tokenMap?: Record<string, string> | null, options?: any): AsyncGenerator<any, void, unknown>;
|
|
166
190
|
}
|
|
167
191
|
|
|
168
192
|
/**
|
|
@@ -287,6 +311,94 @@ export function restoreToFile(filePath: string, content: string, tokenMapOrOptio
|
|
|
287
311
|
*/
|
|
288
312
|
export function createGuardedTools(engineOrOptions?: PrivacyScrubberEngine | SanitizeOptions, toolConfig?: { cwd?: string; profile?: PiiProfile }): GuardedTools;
|
|
289
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Stream token restorer interface for zero-latency SSE chunk processing.
|
|
316
|
+
*/
|
|
317
|
+
export interface StreamTokenRestorer {
|
|
318
|
+
/** Pushes an incoming streaming chunk and returns immediately rehydrated text. */
|
|
319
|
+
push(chunk: string | Uint8Array | any): string;
|
|
320
|
+
/** Feeds an incoming chunk and returns de-tokenized text. */
|
|
321
|
+
feed(chunk: string | Uint8Array | any): string;
|
|
322
|
+
/** Alias for feed. */
|
|
323
|
+
process(chunk: string | Uint8Array | any): string;
|
|
324
|
+
/** Flushes any buffered incomplete tokens at the end of the stream. */
|
|
325
|
+
flush(): string;
|
|
326
|
+
/** Wraps an async iterable LLM stream yielding de-tokenized chunks in real-time. */
|
|
327
|
+
wrapStream<T = any>(asyncIterable: AsyncIterable<T>): AsyncGenerator<any, void, unknown>;
|
|
328
|
+
/** Converts to a native Node.js Transform stream for .pipe() or stream.pipeline(). */
|
|
329
|
+
toNodeTransform(): any;
|
|
330
|
+
/** Underlying StreamingDetokenizer instance. */
|
|
331
|
+
detokenizer: StreamingDetokenizer;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* High-performance streaming de-tokenization engine with sliding-window chunk boundary buffering.
|
|
336
|
+
*/
|
|
337
|
+
export class StreamingDetokenizer {
|
|
338
|
+
constructor(tokenMap?: Record<string, string>, options?: any);
|
|
339
|
+
feed(chunk: string | Uint8Array | any): string;
|
|
340
|
+
process(chunk: string | Uint8Array | any): string;
|
|
341
|
+
flush(): string;
|
|
342
|
+
toNodeTransform(): any;
|
|
343
|
+
wrapStream<T = any>(asyncIterable: AsyncIterable<T>): AsyncGenerator<any, void, unknown>;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Builds an ultra-fast streaming token replacement function preserving all whitespace.
|
|
348
|
+
*/
|
|
349
|
+
export function buildStreamReplacer(tokenMap?: Record<string, string>): (text: string) => string;
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Ergonomic 1-liner: string-in, sanitized string-out without metadata ceremonies.
|
|
353
|
+
* @param text - Plaintext prompt containing potential PII/secrets.
|
|
354
|
+
* @param profile - Compliance profile (Default: 'General').
|
|
355
|
+
* @returns Scrubbed string ready to send to LLM.
|
|
356
|
+
*/
|
|
357
|
+
export function clean(text: string, profile?: PiiProfile): string;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Creates a stream token restorer that rehydrates masked tokens across chunk boundaries in real-time.
|
|
361
|
+
* @param tokenMap - Map of token bindings returned from sanitize().
|
|
362
|
+
* @param options - Optional configuration.
|
|
363
|
+
*/
|
|
364
|
+
export function createStreamTokenRestorer(tokenMap?: Record<string, string>, options?: any): StreamTokenRestorer;
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Creates a Node.js native Transform stream for backend streaming pipelines (stream.pipeline / .pipe()).
|
|
368
|
+
* @param tokenMap - Map of token bindings returned from sanitize().
|
|
369
|
+
* @param options - Optional configuration.
|
|
370
|
+
*/
|
|
371
|
+
export function createNodeStreamTokenRestorer(tokenMap?: Record<string, string>, options?: any): any;
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Wraps an AI streaming response (e.g. OpenAI stream, Vercel AI SDK textStream)
|
|
375
|
+
* and yields real-time plain chunks with all tokens restored on the fly.
|
|
376
|
+
* @param stream - AsyncIterable or ReadableStream of string chunks or delta objects.
|
|
377
|
+
* @param tokenMap - Map of token bindings returned from sanitize().
|
|
378
|
+
*/
|
|
379
|
+
export function wrapAiStream<T = any>(
|
|
380
|
+
stream: AsyncIterable<T> | any,
|
|
381
|
+
tokenMap?: Record<string, string>
|
|
382
|
+
): AsyncGenerator<any, void, unknown>;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Zero-Trust wrapper for Next.js App Router Route Handlers (route.js / route.ts).
|
|
386
|
+
* Automatically intercepts incoming Request JSON body, sanitizes PII in RAM,
|
|
387
|
+
* and passes scrubbed body along with tokenMap and stream restorer factory.
|
|
388
|
+
*/
|
|
389
|
+
export function withPrivacyScrubber(
|
|
390
|
+
handler: (req: Request, context?: any, psContext?: { tokenMap: Record<string, string>; telemetry: AuditTelemetry; createStreamRestorer: () => StreamTokenRestorer }) => any,
|
|
391
|
+
options?: SanitizeOptions
|
|
392
|
+
): (req: Request, context?: any) => Promise<any>;
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Express.js / Connect middleware for automatic zero-trust PII sanitization.
|
|
396
|
+
* Sanitizes req.body in local RAM and attaches req.psTokenMap, req.restore(), and req.createStreamRestorer().
|
|
397
|
+
*/
|
|
398
|
+
export function createExpressMiddleware(
|
|
399
|
+
options?: SanitizeOptions
|
|
400
|
+
): (req: any, res: any, next: (err?: any) => void) => void;
|
|
401
|
+
|
|
290
402
|
// Legacy exports
|
|
291
403
|
export function scrubText(
|
|
292
404
|
text: string,
|
|
@@ -311,14 +423,23 @@ export function unscrubText(
|
|
|
311
423
|
};
|
|
312
424
|
|
|
313
425
|
declare const defaultExport: {
|
|
426
|
+
clean: typeof clean;
|
|
314
427
|
sanitize: typeof sanitize;
|
|
315
428
|
scrub: typeof scrub;
|
|
316
429
|
restore: typeof restore;
|
|
317
430
|
unscrub: typeof unscrub;
|
|
431
|
+
StreamingDetokenizer: typeof StreamingDetokenizer;
|
|
432
|
+
createStreamTokenRestorer: typeof createStreamTokenRestorer;
|
|
433
|
+
createNodeStreamTokenRestorer: typeof createNodeStreamTokenRestorer;
|
|
434
|
+
buildStreamReplacer: typeof buildStreamReplacer;
|
|
435
|
+
wrapAiStream: typeof wrapAiStream;
|
|
436
|
+
withPrivacyScrubber: typeof withPrivacyScrubber;
|
|
437
|
+
createExpressMiddleware: typeof createExpressMiddleware;
|
|
318
438
|
validateLicense: typeof validateLicense;
|
|
319
439
|
validateLicenseKey: typeof validateLicenseKey;
|
|
320
440
|
buildAuditTelemetry: typeof buildAuditTelemetry;
|
|
321
441
|
formatAuditReceipt: typeof formatAuditReceipt;
|
|
442
|
+
generateProcurementMemo: typeof generateProcurementMemo;
|
|
322
443
|
PrivacyScrubberEngine: typeof PrivacyScrubberEngine;
|
|
323
444
|
PrivacyScrubberLicenseError: typeof PrivacyScrubberLicenseError;
|
|
324
445
|
wrapOpenAI: typeof wrapOpenAI;
|
|
@@ -332,3 +453,4 @@ declare const defaultExport: {
|
|
|
332
453
|
};
|
|
333
454
|
|
|
334
455
|
export default defaultExport;
|
|
456
|
+
|