sct-client 0.1.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 ADDED
@@ -0,0 +1,185 @@
1
+ # @sct/client
2
+
3
+ Official Node.js/TypeScript SDK for the **SCT (Secure Compact Tokenization)** API — pseudonymize PII, restore pseudonymized data, detect PII in free text, and optimize LLM token usage, all through one typed client.
4
+
5
+ ## Requirements
6
+
7
+ - Node.js `>=18` (uses the global `fetch` API)
8
+ - An SCT API key ([get one here](https://sct.simosphereai.com))
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @sct/client
14
+ ```
15
+
16
+ ## Quick Start
17
+
18
+ ```ts
19
+ import { SCTClient } from '@sct/client';
20
+
21
+ const client = new SCTClient({
22
+ apiKey: process.env.SCT_API_KEY!,
23
+ // baseUrl defaults to 'https://sct.simosphereai.com/api/v1'
24
+ });
25
+
26
+ const result = await client.pseudonymize(
27
+ JSON.stringify({
28
+ name: 'Max Mustermann',
29
+ email: 'max@example.com',
30
+ iban: 'DE89370400440532013000',
31
+ }),
32
+ { format: 'json', autoDetectPii: true },
33
+ );
34
+
35
+ console.log(result.pseudonymized_data);
36
+ console.log(result.encryption_key);
37
+ ```
38
+
39
+ ## Configuration
40
+
41
+ ```ts
42
+ const client = new SCTClient({
43
+ apiKey: 'sct_your_api_key',
44
+ baseUrl: 'https://sct.simosphereai.com/api/v1', // optional
45
+ timeoutMs: 10_000, // optional, aborts the request after this duration
46
+ });
47
+ ```
48
+
49
+ ## API
50
+
51
+ ### `pseudonymize(data, options?)`
52
+
53
+ Replace PII in structured or free-text data with reversible pseudonyms.
54
+
55
+ ```ts
56
+ const result = await client.pseudonymize(csvData, {
57
+ format: 'csv',
58
+ method: 'aes-256-gcm', // 'aes-256-gcm' | 'fpe-ff1'
59
+ fields: ['name', 'email'], // only pseudonymize these fields
60
+ // excludeFields: ['amount', 'currency'], // ...or exclude these instead
61
+ autoDetectPii: true, // NLP-based PII detection
62
+ });
63
+
64
+ // result.pseudonymized_data
65
+ // result.encryption_key
66
+ // result.fields_encrypted
67
+ // result.detected_entities
68
+ // result.record_count
69
+ ```
70
+
71
+ ### `dePseudonymize(data, encryptionKey, options?)`
72
+
73
+ Restore data that was previously pseudonymized, using the key returned by `pseudonymize`.
74
+
75
+ ```ts
76
+ const restored = await client.dePseudonymize(result.pseudonymized_data, result.encryption_key, {
77
+ format: 'json',
78
+ });
79
+
80
+ console.log(restored.original_data);
81
+ ```
82
+
83
+ ### `detectPii(text)`
84
+
85
+ Scan free text for PII entities (names, emails, phone numbers, IBANs, addresses, IDs, IP addresses) without pseudonymizing it.
86
+
87
+ ```ts
88
+ const detection = await client.detectPii('Contact Max Mustermann at max@example.com.');
89
+
90
+ for (const entity of detection.entities) {
91
+ console.log(`${entity.entity_type}: ${entity.value} (confidence ${entity.confidence})`);
92
+ }
93
+ ```
94
+
95
+ ### `optimizeTokens(text, targetModel?, targetReduction?)`
96
+
97
+ Reduce LLM token consumption for a piece of text while preserving its meaning.
98
+
99
+ ```ts
100
+ const optimized = await client.optimizeTokens(
101
+ 'Your verbose text content that could be optimized...',
102
+ 'gpt-4o', // 'gpt-4' | 'gpt-4o' | 'claude-3' | 'custom'
103
+ 0.3, // target reduction ratio, 0.0–0.9
104
+ );
105
+
106
+ console.log(optimized.optimized_text);
107
+ console.log(`${optimized.reduction_percent}% smaller (${optimized.tokens_saved} tokens saved)`);
108
+ ```
109
+
110
+ ### `countTokens(text, model?)`
111
+
112
+ Count tokens for a text/model pair without modifying the content.
113
+
114
+ ```ts
115
+ const { token_count } = await client.countTokens('Your text content here...', 'gpt-4o');
116
+ ```
117
+
118
+ ## Error Handling
119
+
120
+ All methods reject with an `SCTError` on non-2xx responses, network failures, or timeouts.
121
+
122
+ ```ts
123
+ import { SCTClient, SCTError } from '@sct/client';
124
+
125
+ try {
126
+ await client.pseudonymize(invalidPayload);
127
+ } catch (error) {
128
+ if (error instanceof SCTError) {
129
+ console.error(`SCT API error (${error.statusCode}): ${error.message}`);
130
+ // error.statusCode is 0 for network/timeout failures
131
+ } else {
132
+ throw error;
133
+ }
134
+ }
135
+ ```
136
+
137
+ ## Full Example: PII-Safe LLM Round-Trip
138
+
139
+ ```ts
140
+ import { SCTClient } from '@sct/client';
141
+
142
+ const client = new SCTClient({ apiKey: process.env.SCT_API_KEY! });
143
+
144
+ const prompt = 'Please draft a follow-up email to Max Mustermann (max@example.com).';
145
+
146
+ // 1. Pseudonymize before sending to an LLM provider
147
+ const { pseudonymized_data, encryption_key } = await client.pseudonymize(prompt, {
148
+ format: 'text',
149
+ autoDetectPii: true,
150
+ });
151
+
152
+ // 2. ... send pseudonymized_data to your LLM provider, get llmResponse back ...
153
+
154
+ // 3. Restore the original PII in the LLM's response
155
+ const { original_data } = await client.dePseudonymize(llmResponse, encryption_key, {
156
+ format: 'text',
157
+ });
158
+
159
+ console.log(original_data);
160
+ ```
161
+
162
+ ## TypeScript
163
+
164
+ This package ships its own type declarations — no `@types` package needed. All response and option types are exported from the package root:
165
+
166
+ ```ts
167
+ import type {
168
+ SCTClientOptions,
169
+ PseudonymizeOptions,
170
+ PseudonymizeResult,
171
+ DePseudonymizeOptions,
172
+ DePseudonymizeResult,
173
+ DetectPIIResult,
174
+ DetectedEntity,
175
+ OptimizeResult,
176
+ TokenCountResult,
177
+ DataFormat,
178
+ EncryptionMethod,
179
+ TokenizerModel,
180
+ } from '@sct/client';
181
+ ```
182
+
183
+ ## License
184
+
185
+ UNLICENSED — SIMO GmbH internal / commercial use only.
@@ -0,0 +1,68 @@
1
+ import type { DataFormat, DePseudonymizeOptions, DePseudonymizeResult, DetectPIIResult, EncryptionMethod, OptimizeResult, PseudonymizeOptions, PseudonymizeResult, SCTClientOptions, TokenCountResult, TokenizerModel } from './types.js';
2
+ /** Error thrown for any non-2xx response or network/transport failure. */
3
+ export declare class SCTError extends Error {
4
+ /** HTTP status code, or 0 when the request never reached the server. */
5
+ readonly statusCode: number;
6
+ /** Raw error payload returned by the API, when available. */
7
+ readonly details?: unknown;
8
+ constructor(message: string, statusCode: number, details?: unknown);
9
+ }
10
+ /**
11
+ * Client for the SCT (Secure Compact Tokenization) API.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const client = new SCTClient({ apiKey: process.env.SCT_API_KEY! });
16
+ * const result = await client.pseudonymize(
17
+ * JSON.stringify({ name: 'Max Mustermann', email: 'max@example.com' }),
18
+ * { format: 'json', autoDetectPii: true },
19
+ * );
20
+ * console.log(result.pseudonymized_data);
21
+ * ```
22
+ */
23
+ export declare class SCTClient {
24
+ private readonly baseUrl;
25
+ private readonly apiKey;
26
+ private readonly timeoutMs?;
27
+ constructor(options: SCTClientOptions);
28
+ /**
29
+ * Pseudonymize PII within structured or free-text data.
30
+ *
31
+ * @param data - The raw data to pseudonymize (JSON string, CSV, XML, or plain text).
32
+ * @param options - Format, encryption, and field-selection options.
33
+ */
34
+ pseudonymize(data: string, options?: PseudonymizeOptions): Promise<PseudonymizeResult>;
35
+ /**
36
+ * Restore data that was previously pseudonymized.
37
+ *
38
+ * @param data - The pseudonymized data to restore.
39
+ * @param encryptionKey - The encryption key returned by {@link pseudonymize}.
40
+ * @param options - Format, encryption, and field-selection options.
41
+ */
42
+ dePseudonymize(data: string, encryptionKey: string, options?: DePseudonymizeOptions): Promise<DePseudonymizeResult>;
43
+ /**
44
+ * Detect PII entities within free text without pseudonymizing it.
45
+ *
46
+ * @param text - The text to scan for PII.
47
+ */
48
+ detectPii(text: string): Promise<DetectPIIResult>;
49
+ /**
50
+ * Optimize text to reduce LLM token consumption while preserving meaning.
51
+ *
52
+ * @param text - The text to optimize.
53
+ * @param targetModel - The target model to optimize token usage for. @default 'gpt-4o'
54
+ * @param targetReduction - Desired reduction ratio, between 0 and 0.9. @default 0.3
55
+ */
56
+ optimizeTokens(text: string, targetModel?: TokenizerModel, targetReduction?: number): Promise<OptimizeResult>;
57
+ /**
58
+ * Count tokens for a given text and model without modifying the content.
59
+ *
60
+ * @param text - The text to count tokens for.
61
+ * @param model - The target model to count tokens for. @default 'gpt-4o'
62
+ */
63
+ countTokens(text: string, model?: TokenizerModel): Promise<TokenCountResult>;
64
+ /** Performs a POST request against the SCT API and parses the JSON response. */
65
+ private request;
66
+ }
67
+ export type { DataFormat, EncryptionMethod, TokenizerModel };
68
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAEhB,gBAAgB,EAChB,cAAc,EACf,MAAM,YAAY,CAAC;AAOpB,0EAA0E;AAC1E,qBAAa,QAAS,SAAQ,KAAK;IACjC,wEAAwE;IACxE,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,6DAA6D;IAC7D,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEtB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAOnE;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;gBAExB,OAAO,EAAE,gBAAgB;IASrC;;;;;OAKG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAYhG;;;;;;OAMG;IACG,cAAc,CAClB,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,oBAAoB,CAAC;IAWhC;;;;OAIG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAIvD;;;;;;OAMG;IACG,cAAc,CAClB,IAAI,EAAE,MAAM,EACZ,WAAW,GAAE,cAAwC,EACrD,eAAe,GAAE,MAAiC,GACjD,OAAO,CAAC,cAAc,CAAC;IAQ1B;;;;;OAKG;IACG,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,cAAwC,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAI3G,gFAAgF;YAClE,OAAO;CAgCtB;AAWD,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,CAAC"}
package/dist/client.js ADDED
@@ -0,0 +1,149 @@
1
+ const DEFAULT_BASE_URL = 'https://sct.simosphereai.com/api/v1';
2
+ const DEFAULT_ENCRYPTION_METHOD = 'aes-256-gcm';
3
+ const DEFAULT_TOKENIZER_MODEL = 'gpt-4o';
4
+ const DEFAULT_TARGET_REDUCTION = 0.3;
5
+ /** Error thrown for any non-2xx response or network/transport failure. */
6
+ export class SCTError extends Error {
7
+ /** HTTP status code, or 0 when the request never reached the server. */
8
+ statusCode;
9
+ /** Raw error payload returned by the API, when available. */
10
+ details;
11
+ constructor(message, statusCode, details) {
12
+ super(message);
13
+ this.name = 'SCTError';
14
+ this.statusCode = statusCode;
15
+ this.details = details;
16
+ Object.setPrototypeOf(this, SCTError.prototype);
17
+ }
18
+ }
19
+ /**
20
+ * Client for the SCT (Secure Compact Tokenization) API.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const client = new SCTClient({ apiKey: process.env.SCT_API_KEY! });
25
+ * const result = await client.pseudonymize(
26
+ * JSON.stringify({ name: 'Max Mustermann', email: 'max@example.com' }),
27
+ * { format: 'json', autoDetectPii: true },
28
+ * );
29
+ * console.log(result.pseudonymized_data);
30
+ * ```
31
+ */
32
+ export class SCTClient {
33
+ baseUrl;
34
+ apiKey;
35
+ timeoutMs;
36
+ constructor(options) {
37
+ if (!options?.apiKey) {
38
+ throw new Error('SCTClient: "apiKey" is required.');
39
+ }
40
+ this.apiKey = options.apiKey;
41
+ this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
42
+ this.timeoutMs = options.timeoutMs;
43
+ }
44
+ /**
45
+ * Pseudonymize PII within structured or free-text data.
46
+ *
47
+ * @param data - The raw data to pseudonymize (JSON string, CSV, XML, or plain text).
48
+ * @param options - Format, encryption, and field-selection options.
49
+ */
50
+ async pseudonymize(data, options = {}) {
51
+ return this.request('/pseudonymize', {
52
+ data,
53
+ format: options.format,
54
+ encryption_method: options.method ?? DEFAULT_ENCRYPTION_METHOD,
55
+ fields: options.fields,
56
+ exclude_fields: options.excludeFields,
57
+ auto_detect_pii: options.autoDetectPii ?? false,
58
+ encryption_key: options.encryptionKey,
59
+ });
60
+ }
61
+ /**
62
+ * Restore data that was previously pseudonymized.
63
+ *
64
+ * @param data - The pseudonymized data to restore.
65
+ * @param encryptionKey - The encryption key returned by {@link pseudonymize}.
66
+ * @param options - Format, encryption, and field-selection options.
67
+ */
68
+ async dePseudonymize(data, encryptionKey, options = {}) {
69
+ return this.request('/de-pseudonymize', {
70
+ data,
71
+ encryption_key: encryptionKey,
72
+ format: options.format,
73
+ encryption_method: options.method ?? DEFAULT_ENCRYPTION_METHOD,
74
+ fields: options.fields,
75
+ exclude_fields: options.excludeFields,
76
+ });
77
+ }
78
+ /**
79
+ * Detect PII entities within free text without pseudonymizing it.
80
+ *
81
+ * @param text - The text to scan for PII.
82
+ */
83
+ async detectPii(text) {
84
+ return this.request('/detect-pii', { text });
85
+ }
86
+ /**
87
+ * Optimize text to reduce LLM token consumption while preserving meaning.
88
+ *
89
+ * @param text - The text to optimize.
90
+ * @param targetModel - The target model to optimize token usage for. @default 'gpt-4o'
91
+ * @param targetReduction - Desired reduction ratio, between 0 and 0.9. @default 0.3
92
+ */
93
+ async optimizeTokens(text, targetModel = DEFAULT_TOKENIZER_MODEL, targetReduction = DEFAULT_TARGET_REDUCTION) {
94
+ return this.request('/tokenizer/optimize', {
95
+ text,
96
+ model: targetModel,
97
+ target_reduction: targetReduction,
98
+ });
99
+ }
100
+ /**
101
+ * Count tokens for a given text and model without modifying the content.
102
+ *
103
+ * @param text - The text to count tokens for.
104
+ * @param model - The target model to count tokens for. @default 'gpt-4o'
105
+ */
106
+ async countTokens(text, model = DEFAULT_TOKENIZER_MODEL) {
107
+ return this.request('/tokenizer/count', { text, model });
108
+ }
109
+ /** Performs a POST request against the SCT API and parses the JSON response. */
110
+ async request(path, body) {
111
+ const controller = this.timeoutMs !== undefined ? new AbortController() : undefined;
112
+ const timer = controller && this.timeoutMs !== undefined ? setTimeout(() => controller.abort(), this.timeoutMs) : undefined;
113
+ let response;
114
+ try {
115
+ response = await fetch(this.baseUrl + path, {
116
+ method: 'POST',
117
+ headers: {
118
+ Authorization: `Bearer ${this.apiKey}`,
119
+ 'Content-Type': 'application/json',
120
+ },
121
+ body: JSON.stringify(stripUndefined(body)),
122
+ signal: controller?.signal,
123
+ });
124
+ }
125
+ catch (cause) {
126
+ if (controller?.signal.aborted) {
127
+ throw new SCTError(`Request to ${path} timed out after ${this.timeoutMs}ms`, 0);
128
+ }
129
+ throw new SCTError(`Network error while requesting ${path}: ${errorMessage(cause)}`, 0);
130
+ }
131
+ finally {
132
+ if (timer !== undefined)
133
+ clearTimeout(timer);
134
+ }
135
+ if (!response.ok) {
136
+ const payload = await response.json().catch(() => ({ detail: 'Request failed' }));
137
+ throw new SCTError(payload.detail ?? payload.error ?? 'Unknown error', response.status, payload.details);
138
+ }
139
+ return response.json();
140
+ }
141
+ }
142
+ /** Removes `undefined` values so they are omitted from the JSON payload entirely. */
143
+ function stripUndefined(input) {
144
+ return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined));
145
+ }
146
+ function errorMessage(error) {
147
+ return error instanceof Error ? error.message : String(error);
148
+ }
149
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mapp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E,CAAC,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC;YACnG,MAAM,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,KAAK,IAAI,eAAe,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3G,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAgB,CAAC;IACvC,CAAC;CACF;AAED,qFAAqF;AACrF,SAAS,cAAc,CAAC,KAA8B;IACpD,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC;AAC9F,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { SCTClient, SCTError } from './client.js';
2
+ export type { SCTClientOptions, PseudonymizeOptions, PseudonymizeResult, DePseudonymizeOptions, DePseudonymizeResult, DetectPIIResult, DetectedEntity, OptimizeResult, TokenCountResult, DataFormat, EncryptionMethod, TokenizerModel, SCTErrorPayload, } from './types.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClD,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,eAAe,GAChB,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { SCTClient, SCTError } from './client.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Type definitions for the SCT (Secure Compact Tokenization) API.
3
+ *
4
+ * These types mirror the response/request shapes produced by the
5
+ * api-gateway routes (`pseudonymize.ts`, `tokenizer.ts`) which proxy
6
+ * `sct-core` (pseudonymization) and the tokenizer service verbatim.
7
+ */
8
+ /** Options for constructing an {@link SCTClient}. */
9
+ export interface SCTClientOptions {
10
+ /** SCT API key, sent as a Bearer token. */
11
+ apiKey: string;
12
+ /**
13
+ * Base URL of the SCT API, including version prefix.
14
+ * @default 'https://sct.simosphereai.com/api/v1'
15
+ */
16
+ baseUrl?: string;
17
+ /**
18
+ * Request timeout in milliseconds. When set, requests are aborted
19
+ * after this duration and rejected with an {@link SCTError}.
20
+ */
21
+ timeoutMs?: number;
22
+ }
23
+ /** Supported structured data formats for pseudonymization. */
24
+ export type DataFormat = 'json' | 'csv' | 'xml' | 'text';
25
+ /** Supported encryption methods. */
26
+ export type EncryptionMethod = 'aes-256-gcm' | 'fpe-ff1';
27
+ /** Supported tokenizer target models. */
28
+ export type TokenizerModel = 'gpt-4' | 'gpt-4o' | 'claude-3' | 'custom';
29
+ /** A single PII entity detected within text or structured data. */
30
+ export interface DetectedEntity {
31
+ /** Entity category, e.g. "PERSON", "EMAIL", "IBAN", "PHONE". */
32
+ entity_type: string;
33
+ /** The raw matched value. */
34
+ value: string;
35
+ /** Start offset (character index) of the match within the source text. */
36
+ start: number;
37
+ /** End offset (character index, exclusive) of the match within the source text. */
38
+ end: number;
39
+ /** Detection confidence, between 0 and 1. */
40
+ confidence: number;
41
+ /** Detection source, e.g. "regex", "ner". */
42
+ source: string;
43
+ }
44
+ /** Options accepted by {@link SCTClient.pseudonymize}. */
45
+ export interface PseudonymizeOptions {
46
+ /** Data format; auto-detected by the server when omitted. */
47
+ format?: DataFormat;
48
+ /** Encryption method to use. @default 'aes-256-gcm' */
49
+ method?: EncryptionMethod;
50
+ /** Restrict pseudonymization to these fields only. */
51
+ fields?: string[];
52
+ /** Exclude these fields from pseudonymization. */
53
+ excludeFields?: string[];
54
+ /** Auto-detect PII fields via NLP entity recognition. @default false */
55
+ autoDetectPii?: boolean;
56
+ /** Bring-your-own encryption key instead of letting the server generate one. */
57
+ encryptionKey?: string;
58
+ }
59
+ /** Response returned by `POST /pseudonymize`. */
60
+ export interface PseudonymizeResult {
61
+ /** The pseudonymized data, in the same format as the input. */
62
+ pseudonymized_data: string;
63
+ /** Encryption key generated (or echoed back) for later de-pseudonymization. */
64
+ encryption_key: string;
65
+ /** Data format that was processed. */
66
+ format: DataFormat;
67
+ /** Encryption method that was used. */
68
+ encryption_method: EncryptionMethod;
69
+ /** Number of records processed (1 for text/JSON objects, N for CSV rows etc.). */
70
+ record_count: number;
71
+ /** Field names that were pseudonymized. */
72
+ fields_encrypted: string[];
73
+ /** PII entities detected, populated when `auto_detect_pii` was true. */
74
+ detected_entities: DetectedEntity[];
75
+ /** Server-side processing duration in milliseconds. */
76
+ duration_ms: number;
77
+ /** Size of the original payload in bytes. */
78
+ original_size_bytes: number;
79
+ /** Size of the pseudonymized payload in bytes. */
80
+ pseudonymized_size_bytes: number;
81
+ }
82
+ /** Options accepted by {@link SCTClient.dePseudonymize}. */
83
+ export interface DePseudonymizeOptions {
84
+ /** Data format; auto-detected by the server when omitted. */
85
+ format?: DataFormat;
86
+ /** Encryption method that was used to pseudonymize the data. @default 'aes-256-gcm' */
87
+ method?: EncryptionMethod;
88
+ /** Restrict decryption to these fields only. */
89
+ fields?: string[];
90
+ /** Exclude these fields from decryption. */
91
+ excludeFields?: string[];
92
+ }
93
+ /** Response returned by `POST /de-pseudonymize`. */
94
+ export interface DePseudonymizeResult {
95
+ /** The restored original data. */
96
+ original_data: string;
97
+ /** Data format that was processed. */
98
+ format: DataFormat;
99
+ /** Number of records processed. */
100
+ record_count: number;
101
+ /** Server-side processing duration in milliseconds. */
102
+ duration_ms: number;
103
+ }
104
+ /** Response returned by `POST /detect-pii`. */
105
+ export interface DetectPIIResult {
106
+ /** PII entities detected in the given text. */
107
+ entities: DetectedEntity[];
108
+ /** Server-side processing duration in milliseconds. */
109
+ duration_ms: number;
110
+ }
111
+ /** Response returned by `POST /tokenizer/optimize`. */
112
+ export interface OptimizeResult {
113
+ /** The optimized text, semantically equivalent but with fewer tokens. */
114
+ optimized_text: string;
115
+ /** Token count of the original text. */
116
+ original_tokens: number;
117
+ /** Token count of the optimized text. */
118
+ optimized_tokens: number;
119
+ /** Number of tokens saved (original_tokens - optimized_tokens). */
120
+ tokens_saved: number;
121
+ /** Reduction percentage, e.g. 30.9 for a ~31% reduction. */
122
+ reduction_percent: number;
123
+ /** Target model the token count was computed against. */
124
+ model: TokenizerModel;
125
+ }
126
+ /** Response returned by `POST /tokenizer/count`. */
127
+ export interface TokenCountResult {
128
+ /** Number of tokens in the given text for the given model. */
129
+ token_count: number;
130
+ /** Target model the token count was computed against. */
131
+ model: TokenizerModel;
132
+ }
133
+ /** Shape of an error payload returned by the SCT API. */
134
+ export interface SCTErrorPayload {
135
+ error?: string;
136
+ detail?: string;
137
+ details?: unknown;
138
+ }
139
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,qDAAqD;AACrD,MAAM,WAAW,gBAAgB;IAC/B,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;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gBAAgB;IAC/B,8DAA8D;IAC9D,WAAW,EAAE,MAAM,CAAC;IACpB,yDAAyD;IACzD,KAAK,EAAE,cAAc,CAAC;CACvB;AAED,yDAAyD;AACzD,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Type definitions for the SCT (Secure Compact Tokenization) API.
3
+ *
4
+ * These types mirror the response/request shapes produced by the
5
+ * api-gateway routes (`pseudonymize.ts`, `tokenizer.ts`) which proxy
6
+ * `sct-core` (pseudonymization) and the tokenizer service verbatim.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "sct-client",
3
+ "version": "0.1.0",
4
+ "description": "Official Node.js/TypeScript SDK for the SCT (Secure Compact Tokenization) API \u2014 pseudonymize PII, stream encrypted data, and optimize LLM tokens.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "engines": {
20
+ "node": ">=18"
21
+ },
22
+ "scripts": {
23
+ "build": "tsc",
24
+ "dev": "tsc --watch",
25
+ "clean": "rm -rf dist",
26
+ "prepublishOnly": "npm run clean && npm run build",
27
+ "typecheck": "tsc --noEmit"
28
+ },
29
+ "keywords": [
30
+ "sct",
31
+ "pseudonymization",
32
+ "pii",
33
+ "tokenizer",
34
+ "encryption",
35
+ "gdpr",
36
+ "dsgvo",
37
+ "llm"
38
+ ],
39
+ "author": "SIMO GmbH",
40
+ "license": "UNLICENSED",
41
+ "homepage": "https://sct.simosphereai.com",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://gitlab.simo-online.com/simosphereos/secure-compact-tokenization.git",
45
+ "directory": "sdks/node"
46
+ },
47
+ "bugs": {
48
+ "url": "https://gitlab.simo-online.com/simosphereos/secure-compact-tokenization/-/issues"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "devDependencies": {
54
+ "typescript": "^5.8.3"
55
+ }
56
+ }