-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathupdate-record.ts
More file actions
87 lines (76 loc) · 2.75 KB
/
update-record.ts
File metadata and controls
87 lines (76 loc) · 2.75 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
87
import {
Credentials,
Env,
LogLevel,
Skyflow,
VaultConfig,
SkyflowConfig,
UpdateRequest,
UpdateOptions,
UpdateResponse,
SkyflowError
} from 'skyflow-node';
/**
* Skyflow Secure Data Update Example
*
* This example demonstrates how to:
* 1. Configure credentials
* 2. Set up vault configuration
* 3. Create an update request
* 4. Handle response and errors
*/
async function performSecureDataUpdate() {
try {
// Step 1: Configure Credentials
const credentials: Credentials = {
// Using API Key authentication
apiKey: 'your-skyflow-api-key',
};
// Step 2: Configure Vault
const primaryVaultConfig: VaultConfig = {
vaultId: 'your-vault-id', // Unique vault identifier
clusterId: 'your-cluster-id', // From vault URL
env: Env.PROD, // Deployment environment
credentials: credentials // Authentication method
};
// Step 3: Configure Skyflow Client
const skyflowConfig: SkyflowConfig = {
vaultConfigs: [primaryVaultConfig],
logLevel: LogLevel.INFO // Logging verbosity
};
// Initialize Skyflow Client
const skyflowClient: Skyflow = new Skyflow(skyflowConfig);
// Step 4: Prepare Update Data
const updateData: Record<string, unknown> = {
skyflowId: 'your-skyflow-id', // Skyflow ID of the record to update
card_number: '1234567890123456' // Updated sensitive data
};
// Step 5: Create Update Request
const updateReq: UpdateRequest = new UpdateRequest(
'sensitive_data_table', // Replace with your actual table name
updateData
);
// Step 6: Configure Update Options
const updateOptions: UpdateOptions = new UpdateOptions();
updateOptions.setReturnTokens(true); // Optional: Get tokens for updated data
// Step 7: Perform Secure Update
const response: UpdateResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.update(updateReq, updateOptions);
// Handle Successful Response
console.log('Update successful:', 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:', error);
}
}
}
// Invoke the secure data update function
performSecureDataUpdate();