import { Credentials, Env, GetOptions, GetRequest, LogLevel, OrderByEnum, RedactionType, Skyflow, VaultConfig, SkyflowConfig, SkyflowError, GetResponse, GetResponseData } from 'skyflow-node'; /** * Skyflow Secure Data Retrieval Example * * This example demonstrates how to: * 1. Configure credentials * 2. Set up vault configuration * 3. Create a get request * 4. Handle response and errors */ async function performSecureDataRetrieval() { 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: '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.ERROR, // Logging verbosity }; // Initialize Skyflow Client const skyflowClient: Skyflow = new Skyflow(skyflowConfig); // Step 4: Prepare Retrieval Data const getIds: Array = [ 'skyflow-id1', 'skyflow-id2', ]; // Step 5: Create Get Request const getRequest: GetRequest = new GetRequest( 'sensitive_data_table', // Replace with your actual table name getIds ); // Step 6: Configure Get Options const getOptions: GetOptions = new GetOptions(); // Return tokens instead of plain-text values (default: false) getOptions.setReturnTokens(true); // Control how sensitive data is redacted in the response // getOptions.setRedactionType(RedactionType.PLAIN_TEXT); // Limit the response to specific field names // getOptions.setFields(['card_number', 'cardholder_name']); // Pagination: skip the first N records // getOptions.setOffset('10'); // Pagination: return at most N records // getOptions.setLimit('20'); // Sort order for returned records // getOptions.setOrderBy(OrderByEnum.ASCENDING); // --- Alternative: query by column value instead of Skyflow IDs --- // (use with a GetRequest that has no IDs; setColumnName + setColumnValues together) // getOptions.setColumnName('card_number'); // getOptions.setColumnValues(['4111111111111112']); // Return a pre-signed download URL for file fields // getOptions.setDownloadUrl(true); // DEPRECATED API — still works, logs WARN: setDownloadURL (uppercase URL) // getOptions.setDownloadURL(false); // Step 7: Perform Secure Retrieval const response: GetResponse = await skyflowClient .vault(primaryVaultConfig.vaultId) .get(getRequest, getOptions); // Handle Successful Response console.log('Data retrieval successful:', response); if(response.data!=null) { for(let i=0; i