-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathreidentify-text.ts
More file actions
86 lines (74 loc) · 2.45 KB
/
reidentify-text.ts
File metadata and controls
86 lines (74 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import {
Credentials,
Env,
LogLevel,
Skyflow,
SkyflowConfig,
VaultConfig,
ReidentifyTextRequest,
ReidentifyTextOptions,
DetectEntities,
SkyflowError,
ReidentifyTextResponse
} from 'skyflow-node';
/**
* Skyflow Reidentify Text Example
*
* This example demonstrates how to:
* 1. Configure credentials
* 2. Set up vault configuration
* 3. Create a reidentify text request
* 4. Use all available options for re-identification
* 5. Handle response and errors
*/
async function performReidentifyText() {
try {
// Step 1: Configure Credentials
const credentials: Credentials = {
path: 'path-to-credentials-json', // Path to credentials file
};
// Step 2: Configure Vault
const primaryVaultConfig: VaultConfig = {
vaultId: '<VAULT_ID>',
clusterId: '<CLUSTER_ID>',
env: Env.PROD,
credentials: credentials
};
// Step 3: Configure Skyflow Client
const skyflowConfig: SkyflowConfig = {
vaultConfigs: [primaryVaultConfig],
logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment.
};
// Initialize Skyflow Client
const skyflowClient: Skyflow = new Skyflow(skyflowConfig);
// Step 4: Prepare Reidentify Text Request
const reidentifyRequest = new ReidentifyTextRequest(
'<REDACTED_TEXT_TO_REIDENTIFY>' // The redacted text to reidentify
);
// Step 5: Configure ReidentifyTextOptions
const options = new ReidentifyTextOptions();
// Specify which entities to reidentify as redacted, masked, or plain text
options.setRedactedEntities([DetectEntities.NAME, DetectEntities.SSN]);
options.setMaskedEntities([DetectEntities.DOB]);
options.setPlainTextEntities([DetectEntities.PHONE_NUMBER]);
// Step 6: Call reidentifyText
const response: ReidentifyTextResponse = await skyflowClient
.detect(primaryVaultConfig.vaultId)
.reidentifyText(reidentifyRequest, options);
// Step 7: Handle response
console.log('Re-identified Text Response:', response);
} catch (error) {
// Comprehensive Error Handling
if (error instanceof SkyflowError) {
console.error('Skyflow Specific Error:', {
code: error.error?.http_code,
message: error.message,
details: error.error?.details,
});
} else {
console.error('Unexpected Error:', JSON.stringify(error));
}
}
}
// Invoke the reidentify text function
performReidentifyText();