Repository navigation
Expand file tree
/
Copy pathupdate-record.ts
More file actions
102 lines (88 loc) · 3.43 KB
/
Copy pathupdate-record.ts
File metadata and controls
102 lines (88 loc) · 3.43 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import {
Credentials,
Env,
LogLevel,
Skyflow,
VaultConfig,
SkyflowConfig,
UpdateRequest,
UpdateOptions,
UpdateResponse,
TokenMode,
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();
// Return tokens for the updated fields (default: false — returns skyflowId only)
updateOptions.setReturnTokens(true);
// --- BYOT (Bring Your Own Token) options ---
// Provide pre-existing tokens to associate with the updated fields
// updateOptions.setTokens({ card_number: '<YOUR_TOKEN>' });
// Control tokenization mode when using BYOT:
// TokenMode.DISABLE — vault generates tokens (default)
// TokenMode.ENABLE — use provided tokens as-is
// TokenMode.ENABLE_STRICT — validate provided tokens before accepting
// updateOptions.setTokenMode(TokenMode.ENABLE);
// 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:', {
httpCode: error.error?.httpCode,
grpcCode: error.error?.grpcCode,
httpStatus: error.error?.httpStatus,
message: error.message,
details: error.error?.details,
});
} else {
console.error('Unexpected Error:', error);
}
}
}
// Invoke the secure data update function
performSecureDataUpdate();