diff --git a/samples/vault-api/.env b/samples/vault-api/.env index fd8598f..43d37b4 100644 --- a/samples/vault-api/.env +++ b/samples/vault-api/.env @@ -1 +1 @@ -SKYFLOW_CREDENTIALS={ clientID: '', clientName: '', keyID: '', tokenURI: '', privateKey: '', } \ No newline at end of file +SKYFLOW_CREDENTIALS={ clientID: '', clientName: '', keyID: '', tokenURI: '', privateKey: '' } \ No newline at end of file diff --git a/samples/vault-api/client-operations.ts b/samples/vault-api/client-operations.ts index 0d21808..fa270c5 100644 --- a/samples/vault-api/client-operations.ts +++ b/samples/vault-api/client-operations.ts @@ -1,81 +1,105 @@ -import { Credentials, DeleteRequest, Env, LogLevel, Skyflow, VaultConfig, SkyflowConfig } from 'skyflow-node'; - -try { - // To generate Bearer Token from credentials string. - const cred: Object = { - clientID: '', - clientName: '', - keyID: '', - tokenURI: '', - privateKey: '', - }; - - // please pass one of apiKey, token, credentialsString & path as credentials - const skyflowCredentials: Credentials = { - credentialsString: JSON.stringify(cred), - }; - - // please pass one of apiKey, token, credentialsString & path as credentials - const credentials: Credentials = { - token: 'BEARER_TOKEN', // bearer token - }; - - const primaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID1', // primary vault - clusterId: 'CLUSTER_ID1', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - credentials: credentials, // individual credentials - }; - - // skyflow config - const skyflowConfig: SkyflowConfig = { - // pass array vault configs - vaultConfigs: [ - primaryVaultConfig, - ], - skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed - logLevel: LogLevel.ERROR, // set log level by default it is set to PROD - }; - - // initialize skyflow client - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - const vaultConfig: VaultConfig = { - vaultId: 'VAULT_ID2', // secondary vault - clusterId: 'CLUSTER_ID2', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - // if you don't specify individual credentials, skyflow credentials will be used - }; - - //add vault config on the fly - skyflowClient.addVaultConfig(vaultConfig); - - const updatedVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID2', // vault Id and cluster Id is unique - clusterId: 'CLUSTER_ID2', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - credentials: credentials, //update credentials - }; - //update vault config on the fly - skyflowClient.updateVaultConfig(updatedVaultConfig); - - //perform operations - const deleteIds: Array = [ - 'SKYLFOW_ID1', - 'SKYLFOW_ID2', - ] - - const tableName: string = 'TABLE_NAME'; - - const deleteRequest: DeleteRequest = new DeleteRequest( - tableName, - deleteIds, - ); - - //perform delete call if you don't specify vault() it will return the first valid vault - skyflowClient.vault('VAULT_ID2').delete(deleteRequest); - - //remove vault on the fly - skyflowClient.removeVaultConfig('VAULT_ID'); -} catch (err) { - console.log(JSON.stringify(err)); -} \ No newline at end of file +import { + Credentials, + DeleteRequest, + Env, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + SkyflowError +} from 'skyflow-node'; + +/** + * Skyflow Secure Data Deletion Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configuration + * 3. Create a delete request + * 4. Handle response and errors + */ +async function performSecureDataDeletion() { + try { + // Step 1: Configure Bearer Token Credentials + const credentials: Credentials = { + token: '', // Bearer token + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', // Primary vault + clusterId: '', // Cluster ID from your vault URL + env: Env.PROD, // Deployment environment (PROD by default) + credentials: credentials, // Authentication method + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.ERROR // Logging verbosity + }; + + // Initialize Skyflow Client + const skyflowClient = new Skyflow(skyflowConfig); + + // Step 4: Add Secondary Vault Configuration + const secondaryVaultConfig: VaultConfig = { + vaultId: '', // Secondary vault + clusterId: '', // Cluster ID from your vault URL + env: Env.PROD, // Deployment environment + // If credentials aren't specified, Skyflow credentials will be used + }; + + // Add secondary vault config on the fly + skyflowClient.addVaultConfig(secondaryVaultConfig); + + // Step 5: Update Vault Configuration + const updatedVaultConfig: VaultConfig = { + vaultId: '', // Vault ID and cluster ID are unique + clusterId: '', // Cluster ID from your vault URL + credentials: credentials, // Update credentials + }; + + // Update vault config on the fly + skyflowClient.updateVaultConfig(updatedVaultConfig); + + // Step 6: Prepare Delete Request + const deleteIds: Array = [ + 'skyflow_id1', + 'skyflow_id2', + ]; + + const tableName: string = ''; // Replace with actual table name + + const deleteRequest: DeleteRequest = new DeleteRequest( + tableName, + deleteIds, + ); + + // Step 7: Perform Secure Deletion on Secondary Vault + const response = await skyflowClient + .vault('') // Specify vault ID + .delete(deleteRequest); + + // Handle Successful Response + console.log('Deletion successful:', response); + + // Step 8: Remove Secondary Vault Configuration + skyflowClient.removeVaultConfig(''); // Remove vault configuration + + } 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 deletion function +performSecureDataDeletion(); diff --git a/samples/vault-api/credentials-options.ts b/samples/vault-api/credentials-options.ts index d51f411..c7ee92a 100644 --- a/samples/vault-api/credentials-options.ts +++ b/samples/vault-api/credentials-options.ts @@ -1,95 +1,113 @@ -import { Credentials, DeleteRequest, Env, LogLevel, Skyflow, VaultConfig, SkyflowConfig, DeleteResponse, SkyflowError } from 'skyflow-node'; - -try { - //NOTE : If you don't specify credentials at config level credentials or skyflow credentials, SDK will check SKYFLOW_CREDENTIALS key in your env - // To generate Bearer Token from credentials string. - const cred: Object = { - clientID: '', - clientName: '', - keyID: '', - tokenURI: '', - privateKey: '', - }; - - // please pass one of apiKey, token, credentialsString & path as credentials - const skyflowCredentials: Credentials = { - credentialsString: JSON.stringify(cred), - }; - - const credentials: Credentials = { - token: 'BEARER_TOKEN', // bearer token - // apiKey: 'API_KEY', //API_KEY - // path: 'PATH', //path to credentials file - // credentialsString: 'CREDENTIAL_STRING', // credentials as string - }; - - const primaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID1', // primary vault - clusterId: 'CLUSTER_ID1', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - }; - - const secondaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID2', // secondary vault - clusterId: 'CLUSTER_ID2', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - credentials: credentials, - }; - - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [ - primaryVaultConfig, - secondaryVaultConfig, - ], - skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed - logLevel: LogLevel.ERROR, // set log level by default it is set to PROD - }; - - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - const primaryDeleteIds: Array = [ - 'SKYFLOW_ID1', - 'SKYFLOW_ID2', - 'SKYFLOW_ID3', - ]; - - const primaryTableName: string = 'TABLE_NAME1'; // TABLE_NAME - - const primaryDeleteRequest: DeleteRequest = new DeleteRequest( - primaryTableName, - primaryDeleteIds, - ); - - // VAULT_ID1 will use skyflowCredentials if you don't specify individual credentials at config level - skyflowClient.vault('VAULT_ID1').delete( - primaryDeleteRequest, - ).then((resp: DeleteResponse) => { - console.log(resp); - }).catch((err: SkyflowError) => { - console.log(JSON.stringify(err)); - }); - - const secondaryDeleteIds: Array = [ - 'SKYFLOW_ID4', - 'SKYFLOW_ID5', - 'SKYFLOW_ID6', - ]; - - const secondaryTableName: string = 'TABLE_NAME2'; // TABLE_NAME - - const secondaryDeleteRequest: DeleteRequest = new DeleteRequest( - secondaryTableName, - secondaryDeleteIds, - ); - - // VAULT_ID1 will use individual credentials at config level - skyflowClient.vault('VAULT_ID2').delete( - secondaryDeleteRequest - ).then((resp: DeleteResponse) => { - console.log(resp); - }).catch((err: SkyflowError) => { - console.log(JSON.stringify(err)); - }); -} catch (err) { - console.log(JSON.stringify(err)); -} \ No newline at end of file +import { + Credentials, + DeleteRequest, + Env, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + SkyflowError +} from 'skyflow-node'; + +/** + * Skyflow Secure Data Deletion Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configurations + * 3. Create and perform delete requests + * 4. Handle response and errors + */ +async function performSecureDataDeletion() { + try { + // Step 1: Configure Bearer Token Credentials + const credentials: Credentials = { + token: '', // Bearer token + // apiKey: '', // Uncomment to use API key + // path: 'path_to_credentials_json', // Path to credentials file + // credentialsString: 'your_credentials_string', // Credentials as string + }; + + // Step 2: Configure Vaults + const primaryVaultConfig: VaultConfig = { + vaultId: '', // Primary vault + clusterId: '', // Cluster ID from your vault URL + env: Env.PROD, // Deployment environment (PROD by default) + }; + + const secondaryVaultConfig: VaultConfig = { + vaultId: '', // Secondary vault + clusterId: '', // Cluster ID from your vault URL + env: Env.PROD, // Deployment environment + credentials: credentials, // Use credentials if specified + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig, secondaryVaultConfig], // Vault configurations + logLevel: LogLevel.ERROR, // Set log level (ERROR in this case) + }; + + // Initialize Skyflow Client + const skyflowClient = new Skyflow(skyflowConfig); + + // Step 4: Prepare Delete Request for Primary Vault + const primaryDeleteIds: Array = [ + 'skyflow_id1', + 'skyflow_id2', + 'skyflow_id3', + ]; + + const primaryTableName: string = ''; // Replace with actual table name + + const primaryDeleteRequest: DeleteRequest = new DeleteRequest( + primaryTableName, + primaryDeleteIds, + ); + + // Perform Delete Operation for Primary Vault + const primaryDeleteResponse = await skyflowClient + .vault('') // Specify the primary vault ID + .delete(primaryDeleteRequest); + + // Handle Successful Response + console.log('Primary Vault Deletion Successful:', primaryDeleteResponse); + + // Step 5: Prepare Delete Request for Secondary Vault + const secondaryDeleteIds: Array = [ + 'skyflow_id4', + 'skyflow_id5', + 'skyflow_id6', + ]; + + const secondaryTableName: string = ''; // Replace with actual table name + + const secondaryDeleteRequest: DeleteRequest = new DeleteRequest( + secondaryTableName, + secondaryDeleteIds, + ); + + // Perform Delete Operation for Secondary Vault + const secondaryDeleteResponse = await skyflowClient + .vault('') // Specify the secondary vault ID + .delete(secondaryDeleteRequest); + + // Handle Successful Response + console.log('Secondary Vault Deletion Successful:', secondaryDeleteResponse); + + } 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 deletion function +performSecureDataDeletion(); diff --git a/samples/vault-api/data-residency.ts b/samples/vault-api/data-residency.ts index 46fdfcf..a6357d9 100644 --- a/samples/vault-api/data-residency.ts +++ b/samples/vault-api/data-residency.ts @@ -1,91 +1,126 @@ -import { Credentials, Env, GetRequest, GetResponse, InsertRequest, LogLevel, Skyflow, VaultConfig, SkyflowConfig, InsertResponse, SkyflowError } from 'skyflow-node'; - -try { - // To generate Bearer Token from credentials string. - const cred: Object = { - clientID: '', - clientName: '', - keyID: '', - tokenURI: '', - privateKey: '', - }; - - // please pass one of apiKey, token, credentialsString & path as credentials - const skyflowCredentials: Credentials = { - credentialsString: JSON.stringify(cred), - }; - - // please pass one of apiKey, token, credentialsString & path as credentials - const credentials: Credentials = { - token: 'BEARER_TOKEN', // bearer token - }; - - const primaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID1', // primary vault - clusterId: 'CLUSTER_ID1', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - credentials: credentials, // individual credentials - }; - - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [ - primaryVaultConfig, - ], - skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed - logLevel: LogLevel.ERROR, // set log level by default it is set to PROD - }; - - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - const secondaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID2', // secondary vault - clusterId: 'CLUSTER_ID2', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - // if you dont specify individual credentials, skyflow credentials will be used - }; - - //add vault config from prod env - skyflowClient.addVaultConfig(secondaryVaultConfig); - - //perform operations - const getIds: Array = [ - 'SKYLFOW_ID1', - 'SKYLFOW_ID2', - ]; - - const tableName: string = 'TABLE_NAME'; - - const getRequest: GetRequest = new GetRequest( - tableName, - getIds, - ); - - //perform delete call if you dont specify vault() it will return the first valid vault - skyflowClient.vault('VAULT_ID1').get(getRequest) - .then(response => { - // get response - const getResponse: GetResponse = response as GetResponse; - console.log(getResponse.data); - const insertData: Array = getResponse.data!; - - const tableName: string = 'TABLE_NAME'; - //parse insertData to remove skyflow_id - //get data from one vault and insert data to another vault - const insertRequest: InsertRequest = new InsertRequest( - tableName, - insertData, - ); - skyflowClient.vault('VAULT_ID2').insert( - insertRequest - ).then((resp: InsertResponse) => { - console.log(resp); - }).catch((err: SkyflowError) => { - console.log(JSON.stringify(err)); - }); - }) - .catch((err: SkyflowError) => { - console.log(JSON.stringify(err)); +import { + Credentials, + Env, + GetRequest, + GetResponse, + InsertRequest, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + InsertResponse, + SkyflowError +} from 'skyflow-node'; + +/** + * Skyflow Vault Data Transfer Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up primary and secondary vault configurations + * 3. Retrieve data from one vault + * 4. Insert data into another vault + * 5. Handle responses and errors + */ +async function transferDataBetweenVaults() { + try { + // Step 1: Configure Skyflow Credentials + const cred: Object = { + clientID: '', // Client identifier + clientName: '', // Client name + keyID: '', // Key identifier + tokenURI: '', // Token URI + privateKey: '' // Private key for authentication + }; + + const skyflowCredentials: Credentials = { + credentialsString: JSON.stringify(cred), // Token credentials + }; + + const credentials: Credentials = { + token: 'BEARER_TOKEN', // Bearer token for authentication + }; + + // Step 2: Configure Primary Vault + const primaryVaultConfig: VaultConfig = { + vaultId: 'vault-id-1', // Primary vault ID + clusterId: 'cluster-id-1', // Cluster ID from your vault URL + env: Env.PROD, // Environment (default: PROD) + credentials: credentials, // Authentication method for this vault + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + skyflowCredentials: skyflowCredentials, // Skyflow credentials for fallback + logLevel: LogLevel.ERROR, // Set log level to ERROR + }; + + const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + + // Step 4: Configure Secondary Vault + const secondaryVaultConfig: VaultConfig = { + vaultId: 'vault-id-2', // Secondary vault ID + clusterId: 'cluster-id-2', // Cluster ID from the secondary vault URL + env: Env.PROD, // Environment (default: PROD) + // If no individual credentials are provided, Skyflow credentials will be used + }; + + // Add Secondary Vault to Skyflow Client + skyflowClient.addVaultConfig(secondaryVaultConfig); + + // Step 5: Get Data from Primary Vault + const getIds: Array = [ + 'skyflow-id-1', + 'skyflow-id-2', + ]; + + const tableName: string = 'your-table-name'; // Replace with your table name + + const getRequest: GetRequest = new GetRequest(tableName, getIds); + + // Perform Get request on Primary Vault + const getResponse = await skyflowClient + .vault('vault-id-1') // Specify the vault ID or it defaults to the first valid vault + .get(getRequest); + + // Step 6: Handle Get Response and Insert Data into Secondary Vault + const getResponseData: GetResponse = getResponse as GetResponse; + + const insertData: Array = getResponseData.data!; + + // Remove skyflow_id from the data (if needed for re-insertion) + const sanitizedData = insertData.map(item => { + const { skyflow_id, ...rest } = item as any; // Exclude the skyflow_id field + return rest; }); -} catch (err) { - console.log(JSON.stringify(err)); -} \ No newline at end of file + + // Step 7: Insert Data into Secondary Vault + const insertRequest: InsertRequest = new InsertRequest( + tableName, // Same table name or different as needed + sanitizedData, + ); + + // Perform Insert request on Secondary Vault + const insertResponse = await skyflowClient + .vault('vault-id-2') // Specify the secondary vault ID + .insert(insertRequest); + + console.log('Data successfully inserted into secondary vault:', insertResponse); + + } 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 data transfer function +transferDataBetweenVaults(); diff --git a/samples/vault-api/delete-records.ts b/samples/vault-api/delete-records.ts index d81f0c6..e3d5071 100644 --- a/samples/vault-api/delete-records.ts +++ b/samples/vault-api/delete-records.ts @@ -1,63 +1,92 @@ -import { Credentials, DeleteRequest, DeleteResponse, Env, LogLevel, Skyflow, SkyflowConfig, VaultConfig, SkyflowError } from 'skyflow-node'; - -try { - // To generate Bearer Token from credentials string. - const cred: Object = { - clientID: '', - clientName: '', - keyID: '', - tokenURI: '', - privateKey: '', - }; - - // please pass one of apiKey, token, credentialsString & path as credentials - const skyflowCredentials: Credentials = { - credentialsString: JSON.stringify(cred), - }; - - // please pass one of apiKey, token, credentialsString & path as credentials - const credentials: Credentials = { - apiKey: 'API_KEY', // API Key - }; - - const primaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID', // primary vault - clusterId: 'CLUSTER_ID', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - credentials: credentials, // individual credentials - }; - - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [ - primaryVaultConfig, - ], - skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed - logLevel: LogLevel.ERROR, // set log level by default it is set to PROD - }; - - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - const deleteIds: Array = [ - 'SKYFLOW_ID1', - 'SKYFLOW_ID2', - 'SKYFLOW_ID3', - ]; - - const tableName: string = 'TABLE_NAME'; // TABLE_NAME - - const deleteRequest: DeleteRequest = new DeleteRequest( - tableName, - deleteIds, - ); - - // will return first Vault ID - skyflowClient.vault().delete( - deleteRequest, - ).then((resp: DeleteResponse) => { - console.log(resp); - }).catch((err: SkyflowError) => { - console.log(JSON.stringify(err)); - }); -} catch (err) { - console.log(JSON.stringify(err)); -} \ No newline at end of file +import { + Credentials, + DeleteRequest, + DeleteResponse, + Env, + LogLevel, + Skyflow, + SkyflowConfig, + VaultConfig, + SkyflowError +} from 'skyflow-node'; + +/** + * Skyflow Delete Records Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configuration + * 3. Create a delete request + * 4. Handle response and errors + */ +async function performDeletion() { + try { + // Step 1: Configure Credentials + const cred: object = { + clientID: '', // Client identifier + clientName: '', // Client name + keyID: '', // Key identifier + tokenURI: '', // Token URI + privateKey: '' // Private key for authentication + }; + + const skyflowCredentials: Credentials = { + credentialsString: JSON.stringify(cred), // Token credentials + }; + + const credentials: Credentials = { + apiKey: 'your-skyflow-api-key', // API key for authentication + }; + + // 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], + skyflowCredentials: skyflowCredentials, // Used if no individual credentials are passed + logLevel: LogLevel.ERROR, // Logging verbosity + }; + + // Initialize Skyflow Client + const skyflowClient = new Skyflow(skyflowConfig); + + // Step 4: Prepare Delete Data + const deleteIds = ['skyflow_id1', 'skyflow_id2', 'skyflow_id3']; // Record IDs to delete + const tableName = 'sensitive_data_table'; // Table name in the vault schema + + // Create Delete Request + const deleteRequest = new DeleteRequest( + tableName, + deleteIds + ); + + // Step 5: Perform Deletion + const response: DeleteResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .delete(deleteRequest); + + // Handle Successful Response + console.log('Deletion 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 deletion function +performDeletion(); diff --git a/samples/vault-api/detokenzie-records.ts b/samples/vault-api/detokenzie-records.ts index 3349a45..176bdee 100644 --- a/samples/vault-api/detokenzie-records.ts +++ b/samples/vault-api/detokenzie-records.ts @@ -1,70 +1,99 @@ -import { Credentials, DetokenizeOptions, DetokenizeRequest, DetokenizeResponse, Env, LogLevel, RedactionType, Skyflow, SkyflowError, VaultConfig, SkyflowConfig } from 'skyflow-node'; +import { + Credentials, + DetokenizeOptions, + DetokenizeRequest, + DetokenizeResponse, + Env, + LogLevel, + RedactionType, + Skyflow, + SkyflowError, + VaultConfig, + SkyflowConfig +} from 'skyflow-node'; -try { - // To generate Bearer Token from credentials string. - const cred: Object = { - clientID: '', - clientName: '', - keyID: '', - tokenURI: '', - privateKey: '', - }; +/** + * Skyflow Detokenization Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configuration + * 3. Create a detokenization request + * 4. Handle response and errors + */ +async function performDetokenization() { + try { + // Step 1: Configure Credentials + const cred: object = { + clientID: '', // Client identifier + clientName: '', // Client name + keyID: '', // Key identifier + tokenURI: '', // Token URI + privateKey: '' // Private key for authentication + }; - // please pass one of apiKey, token, credentialsString & path as credentials - const skyflowCredentials: Credentials = { - credentialsString: JSON.stringify(cred), - }; + const skyflowCredentials: Credentials = { + credentialsString: JSON.stringify(cred), // Token credentials + }; - // please pass one of apiKey, token, credentialsString & path as credentials - const credentials: Credentials = { - token: 'TOKEN', // bearer token - }; + const credentials: Credentials = { + token: 'token', // Bearer token for authentication + }; - const primaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID', // primary vault - clusterId: 'CLUSTER_ID', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - credentials: credentials, // individual credentials - }; + // 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 + }; - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [ - primaryVaultConfig, - ], - skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed - logLevel: LogLevel.ERROR, // set log level by default it is set to PROD - }; + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + skyflowCredentials: skyflowCredentials, // Used if no individual credentials are passed + logLevel: LogLevel.ERROR, // Logging verbosity + }; - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + // Initialize Skyflow Client + const skyflowClient = new Skyflow(skyflowConfig); - const detokenizeData: Array = [ - 'TOKEN1', - 'TOKEN2', - 'TOKEN3', - ]; + // Step 4: Prepare Detokenization Data + const detokenizeData = ['token1', 'token2', 'token3']; // Tokens to be detokenized + const redactionType = RedactionType.REDACTED; // Redaction type - const redactionType: RedactionType = RedactionType.REDACTED; + // Create Detokenize Request + const detokenizeRequest = new DetokenizeRequest( + detokenizeData, + redactionType + ); - const detokenizeRequest: DetokenizeRequest = new DetokenizeRequest( - detokenizeData, - redactionType, - ); + // Configure Detokenize Options + const detokenizeOptions = new DetokenizeOptions(); + detokenizeOptions.setContinueOnError(true); // Continue processing on errors + detokenizeOptions.setDownloadURL(false); // Disable download URL generation - const detokenizeOptions: DetokenizeOptions = new DetokenizeOptions(); - // options can be set using setters - detokenizeOptions.setContinueOnError(true); + // Step 5: Perform Detokenization + const response = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .detokenize(detokenizeRequest, detokenizeOptions); - detokenizeOptions.setDownloadURL(false); + // Handle Successful Response + console.log('Detokenization successful:', response); - skyflowClient.vault('VAULT_ID').detokenize( - detokenizeRequest, - detokenizeOptions - ).then((response: DetokenizeResponse) => { - console.log(response); - }).catch((error: SkyflowError) => { - console.log(JSON.stringify(error)); - }); + } 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); + } + } +} -} catch (err) { - console.log(JSON.stringify(err)); -} \ No newline at end of file +// Invoke the detokenization function +performDetokenization(); diff --git a/samples/vault-api/file-upload.ts b/samples/vault-api/file-upload.ts index a51441e..22ee7a5 100644 --- a/samples/vault-api/file-upload.ts +++ b/samples/vault-api/file-upload.ts @@ -1,62 +1,96 @@ -//please use node version 18 & above to run file upload -import { Credentials, Env, FileUploadRequest, FileUploadResponse, LogLevel, Skyflow, SkyflowConfig, VaultConfig, SkyflowError } from 'skyflow-node'; - -try { - // To generate Bearer Token from credentials string. - const cred: Object = { - clientID: '', - clientName: '', - keyID: '', - tokenURI: '', - privateKey: '', - }; - - // please pass one of apiKey, token, credentialsString & path as credentials - const skyflowCredentials: Credentials = { - credentialsString: JSON.stringify(cred), - }; - - // please pass one of apiKey, token, credentialsString & path as credentials - const credentials: Credentials = { - path: 'PATH_TO_CREDENTIALS_JSON', // path to credentials file - }; - - const primaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID', // primary vault - clusterId: 'CLUSTER_ID', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - credentials: credentials, // individual credentials - }; - - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [ - primaryVaultConfig, - ], - skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed - logLevel: LogLevel.ERROR, // set log level by default it is set to PROD - }; - - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - const tableName: string = 'TABLE_NAME'; //table name - const skyflowId: string = 'SKYFLOW_ID'; //skyflow id - const columnName: string = 'COLUMN_NAME'; //column name - const filePath: string = 'FILE_PATH'; //file path - - const uploadReq: FileUploadRequest = new FileUploadRequest( - tableName, - skyflowId, - columnName, - filePath, - ); - - skyflowClient.vault('VAULT_ID').uploadFile( - uploadReq, - ).then((response: FileUploadResponse) => { - console.log(response); - }).catch((error: SkyflowError) => { - console.log(JSON.stringify(error)); - }); -} catch (err) { - console.log(JSON.stringify(err)); -} \ No newline at end of file +// Please use Node.js version 18 & above to run file upload +import { + Credentials, + Env, + FileUploadRequest, + LogLevel, + Skyflow, + SkyflowConfig, + VaultConfig, + SkyflowError +} from 'skyflow-node'; + +/** + * Skyflow File Upload Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configuration + * 3. Create a file upload request + * 4. Handle response and errors + */ +async function performFileUpload() { + try { + // Step 1: Configure Credentials + const cred: object = { + clientID: '', // Client identifier + clientName: '', // Client name + keyID: '', // Key identifier + tokenURI: '', // Token URI + privateKey: '' // Private key for authentication + }; + + const skyflowCredentials: Credentials = { + credentialsString: JSON.stringify(cred), // Token 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], + skyflowCredentials: skyflowCredentials, // Used if no individual credentials are passed + logLevel: LogLevel.ERROR, // Logging verbosity + }; + + // Initialize Skyflow Client + const skyflowClient = new Skyflow(skyflowConfig); + + // Step 4: Prepare File Upload Data + const tableName = 'table-name'; // Table name + const skyflowId = 'skyflow-id'; // Skyflow ID of the record + const columnName = 'column-name'; // Column name to store file + const filePath = 'file-path'; // Path to the file for upload + + // Step 5: Create File Upload Request + const uploadReq = new FileUploadRequest( + tableName, + skyflowId, + columnName, + filePath + ); + + // Step 6: Perform File Upload + const response = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .uploadFile(uploadReq); + + // Handle Successful Response + console.log('File upload 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 file upload function +performFileUpload(); diff --git a/samples/vault-api/get-column-values.ts b/samples/vault-api/get-column-values.ts index 1ea9b0a..f7c982c 100644 --- a/samples/vault-api/get-column-values.ts +++ b/samples/vault-api/get-column-values.ts @@ -1,68 +1,101 @@ -import { Env, GetOptions, LogLevel, Skyflow, GetColumnRequest, Credentials, SkyflowConfig, VaultConfig, GetResponse, SkyflowError } from 'skyflow-node'; +import { + Env, + GetOptions, + LogLevel, + Skyflow, + GetColumnRequest, + Credentials, + SkyflowConfig, + VaultConfig, + SkyflowError +} from 'skyflow-node'; -try { - // To generate Bearer Token from credentials string. - const cred: Object = { - clientID: '', - clientName: '', - keyID: '', - tokenURI: '', - privateKey: '', - }; +/** + * Skyflow Secure Column-Based Retrieval Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configuration + * 3. Create a column-based get request + * 4. Handle response and errors + */ +async function performSecureColumnRetrieval() { + try { + // Step 1: Configure Credentials + const cred: object = { + clientID: '', // Client identifier + clientName: '', // Client name + keyID: '', // Key identifier + tokenURI: '', // Token URI + privateKey: '' // Private key for authentication + }; - // please pass one of apiKey, token, credentialsString & path as credentials - const skyflowCredentials: Credentials = { - credentialsString: JSON.stringify(cred), - }; + const skyflowCredentials: Credentials = { + credentialsString: JSON.stringify(cred), // Token credentials + }; - // please pass one of apiKey, token, credentialsString & path as credentials - const credentials: Credentials = { - path: 'PATH_TO_CREDENTIALS_JSON', // path to credentials file - }; + const credentials: Credentials = { + path: 'path-to-credentials-json', // Path to credentials file + }; - const primaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID', // primary vault - clusterId: 'CLUSTER_ID', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - credentials: credentials, // individual credentials - }; + // 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 + }; - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [ - primaryVaultConfig, - ], - skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed - logLevel: LogLevel.ERROR, // set log level by default it is set to PROD - }; + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + skyflowCredentials: skyflowCredentials, // Used if no individual credentials are passed + logLevel: LogLevel.ERROR, // Logging verbosity + }; - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + // Initialize Skyflow Client + const skyflowClient = new Skyflow(skyflowConfig); - const columnValues: Array = [ - 'VALUE1', - 'VALUE2', - ]; + // Step 4: Prepare Column-Based Retrieval Data + const columnValues: string[] = [ + 'value1', // Example Unique Column value 1 + 'value2', // Example Unique Column value 2 + ]; + const tableName = 'table-name'; // Replace with your actual table name + const columnName = 'column-name'; // Column name configured as unique in the schema - const tableName: string = 'TABLE_NAME'; - const columnName: string = 'COLUMN_NAME'; //Name of the column. It must be configured as unique in the schema. + // Step 5: Create Get Column Request + const getRequest = new GetColumnRequest( + tableName, + columnName, + columnValues // Column values of the records to return + ); - const getRequest: GetColumnRequest = new GetColumnRequest( - tableName, - columnName, - columnValues, //Column values of the records to return - ); + // Step 6: Configure Get Options + const getOptions = new GetOptions(); + getOptions.setReturnTokens(true); // Optional: Get tokens for retrieved data - const getOptions: GetOptions = new GetOptions(); - //use setters of setting options refer to skyflow docs for more options - getOptions.setReturnTokens(true); + // Step 7: Perform Secure Retrieval + const response = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .get(getRequest, getOptions); - skyflowClient.vault('VAULT_ID').get( - getRequest, - getOptions, - ).then((response: GetResponse) => { - console.log(response); - }).catch((error: SkyflowError) => { - console.log(JSON.stringify(error)); - }); -} catch (err) { - console.log(JSON.stringify(err)); -} \ No newline at end of file + // Handle Successful Response + console.log('Column-based retrieval 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 column retrieval function +performSecureColumnRetrieval(); diff --git a/samples/vault-api/get-records.ts b/samples/vault-api/get-records.ts index 260eafe..ec4789d 100644 --- a/samples/vault-api/get-records.ts +++ b/samples/vault-api/get-records.ts @@ -1,66 +1,98 @@ -import { Credentials, Env, GetOptions, GetRequest, GetResponse, LogLevel, Skyflow, SkyflowError, SkyflowConfig, VaultConfig } from 'skyflow-node'; +import { + Credentials, + Env, + GetOptions, + GetRequest, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + SkyflowError +} from 'skyflow-node'; -try { - // To generate Bearer Token from credentials string. - const cred: Object = { - clientID: '', - clientName: '', - keyID: '', - tokenURI: '', - privateKey: '', - }; +/** + * Skyflow Secure Data Retrieval Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client 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 cred: object = { + clientID: '', // Client identifier + clientName: '', // Client name + keyID: '', // Key identifier + tokenURI: '', // Token URI + privateKey: '' // Private key for authentication + }; - // please pass one of apiKey, token, credentialsString & path as credentials - const skyflowCredentials: Credentials = { - credentialsString: JSON.stringify(cred), - }; + const skyflowCredentials: Credentials = { + credentialsString: JSON.stringify(cred), // Token credentials + }; - // please pass one of apiKey, token, credentialsString & path as credentials - const credentials: Credentials = { - path: 'PATH_TO_CREDENTIALS_JSON', // path to credentials file - }; + const credentials: Credentials = { + path: 'path-to-credentials-json', // Path to credentials file + }; - const primaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID', // primary vault - clusterId: 'CLUSTER_ID', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - credentials: credentials, // individual credentials - }; + // 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 + }; - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [ - primaryVaultConfig, - ], - skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed - logLevel: LogLevel.ERROR, // set log level by default it is set to PROD - }; + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + skyflowCredentials: skyflowCredentials, // Used if no individual credentials are passed + logLevel: LogLevel.ERROR, // Logging verbosity + }; - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + // Initialize Skyflow Client + const skyflowClient = new Skyflow(skyflowConfig); - const getIds: Array = [ - 'SKYFLOW_ID1', - 'SKYFLOW_ID2', - ]; + // Step 4: Prepare Retrieval Data + const getIds: string[] = [ + 'skyflow-id1', + 'skyflow-id2', + ]; - const tableName: string = 'TABLE_NAME'; + // Step 5: Create Get Request + const getRequest = new GetRequest( + 'sensitive_data_table', // Replace with your actual table name + getIds + ); - const getRequest: GetRequest = new GetRequest( - tableName, - getIds, - ); + // Step 6: Configure Get Options + const getOptions = new GetOptions(); + getOptions.setReturnTokens(true); // Optional: Get tokens for retrieved data - const getOptions: GetOptions = new GetOptions(); - //use setters of setting options refer to skyflow docs for more options - getOptions.setReturnTokens(true); + // Step 7: Perform Secure Retrieval + const response = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .get(getRequest, getOptions); - skyflowClient.vault('VAULT_ID').get( - getRequest, - getOptions - ).then((response: GetResponse) => { - console.log(response); - }).catch((error: SkyflowError) => { - console.log(JSON.stringify(error)); - }); -} catch (err) { - console.log(JSON.stringify(err)); -} \ No newline at end of file + // Handle Successful Response + console.log('Data retrieval 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 retrieval function +performSecureDataRetrieval(); diff --git a/samples/vault-api/insert-byot.ts b/samples/vault-api/insert-byot.ts index a00493a..c4d472f 100644 --- a/samples/vault-api/insert-byot.ts +++ b/samples/vault-api/insert-byot.ts @@ -1,75 +1,103 @@ -import { BYOT, Credentials, Env, InsertOptions, InsertRequest, LogLevel, Skyflow, VaultConfig, SkyflowConfig, InsertResponse, SkyflowError } from 'skyflow-node'; +import { + TokenMode, + Credentials, + Env, + InsertOptions, + InsertRequest, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + InsertResponse, + SkyflowError +} from 'skyflow-node'; -try { - // To generate Bearer Token from credentials string. - const cred: Object = { - clientID: '', - clientName: '', - keyID: '', - tokenURI: '', - privateKey: '', - }; +/** + * Skyflow Insert with BYOT Example + * + * This example demonstrates: + * 1. Configuring Skyflow client credentials + * 2. Setting up vault configuration + * 3. Utilizing Bring Your Own Token (BYOT) during insertion + * 4. Handling responses and errors + */ +async function performSecureDataInsertionWithBYOT() { + try { + // Step 1: Configure Credentials + const cred: object = { + clientID: '', // Client identifier + clientName: '', // Client name + keyID: '', // Key identifier + tokenURI: '', // Token URI + privateKey: '' // Private key for authentication + }; - // please pass one of apiKey, token, credentialsString & path as credentials - const skyflowCredentials: Credentials = { - credentialsString: JSON.stringify(cred), - }; + const skyflowCredentials: Credentials = { + credentialsString: JSON.stringify(cred), // Token-based credentials + }; - // please pass one of apiKey, token, credentialsString & path as credentials - const credentials: Credentials = { - token: "BEARER", // token - }; + const credentials: Credentials = { + token: 'bearer', // Bearer token authentication + }; - const primaryVaultConfig: VaultConfig = { - vaultId: "VAULT_ID", // primary vault - clusterId: "CLUSTER_ID", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - credentials: credentials, // individual credentials - }; + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: 'your-vault-id', // Unique vault identifier + clusterId: 'your-cluster-id', // Cluster ID from vault URL + env: Env.PROD, // Deployment environment + credentials: credentials // Authentication method + }; - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [ - primaryVaultConfig, - ], - skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed - logLevel: LogLevel.INFO, // set log level by default it is set to PROD - }; + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + skyflowCredentials: skyflowCredentials, // Used if no individual credentials are passed + logLevel: LogLevel.INFO // Logging verbosity + }; - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + // Initialize Skyflow Client + const skyflowClient = new Skyflow(skyflowConfig); - //sample data - const insertData: Array = [ - { card_number: 'CARD_NUMBER1', card_cvv: 'CVV1' }, - { card_number: 'CARD_NUMBER2', card_cvv: 'CVV2' }, - ]; + // Step 4: Prepare Insertion Data + const insertData: Array = [ + { card_number: 'skyflow_id1', card_cvv: 'skyflow_id2' }, + ]; - const tableName: string = 'TABLE_NAME'; + const tableName: string = 'your-table-name'; + const insertReq: InsertRequest = new InsertRequest(tableName, insertData); - const insertReq: InsertRequest = new InsertRequest( - tableName, - insertData, - ); + // Step 5: BYOT Configuration + const tokens: Array = [ + { card_number: 'token1', card_cvv: 'token2' }, + ]; - const tokens: Array = [ - { card_number: 'TOKEN1', card_cvv: 'TOKEN2' }, - { card_number: 'TOKEN3', card_cvv: 'TOKEN4' }, - ]; + const insertOptions: InsertOptions = new InsertOptions(); + insertOptions.setReturnTokens(true); // Optionally get tokens for inserted data + insertOptions.setTokenMode(TokenMode.ENABLE); // Enable Bring Your Own Token (BYOT) + insertOptions.setTokens(tokens); // Specify tokens to use for BYOT + // insertOptions.setContinueOnError(true); // Optionally continue on partial errors - const insertOptions: InsertOptions = new InsertOptions() - //use setters for setting options - insertOptions.setReturnTokens(true); - insertOptions.setTokenMode(BYOT.ENABLE); - insertOptions.setTokens(tokens); - // insertOptions.setContinueOnError(true); // if continue on error is set true we will return requestIndex for errors + // Step 6: Perform Secure Insertion + const response: InsertResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .insert(insertReq, insertOptions); - skyflowClient.vault('VAULT_ID').insert( - insertReq, - insertOptions, - ).then((resp: InsertResponse) => { - console.log(resp); - }).catch((err: SkyflowError) => { - console.log(JSON.stringify(err)); - }); -} catch (err) { - console.log(JSON.stringify(err)); -} \ No newline at end of file + // Handle Successful Response + console.log('Insertion Successful:', response); + + } catch (error) { + // Step 7: 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 insertion function +performSecureDataInsertionWithBYOT(); diff --git a/samples/vault-api/insert-records.ts b/samples/vault-api/insert-records.ts index 03f1809..bc702ad 100644 --- a/samples/vault-api/insert-records.ts +++ b/samples/vault-api/insert-records.ts @@ -1,55 +1,86 @@ -import { Credentials, Env, InsertOptions, InsertRequest, LogLevel, Skyflow, VaultConfig, SkyflowConfig, InsertResponse, SkyflowError } from 'skyflow-node'; - -try { - // please pass one of apiKey, token, credentialsString & path as credentials - const credentials: Credentials = { - apiKey: 'API_KEY', // API Key - }; - - const logLevel: LogLevel = LogLevel.INFO; - - const primaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID', // primary vault - clusterId: 'CLUSTER_ID', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - credentials: credentials, // individual credentials - }; - - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [ - primaryVaultConfig, - ], - logLevel: logLevel, // set log level by default it is set to PROD - }; - - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - //sample data - const insertData: Array = [ - { card_number: '4111111111111111', card_cvv: '1234' }, - { card_number: '42424242424242424', card_cvv: '321' }, - ]; - - const tableName: string = 'TABLE_NAME'; - - const insertReq: InsertRequest = new InsertRequest( - tableName, - insertData, - ); - - const insertOptions: InsertOptions = new InsertOptions(); - //use setters for setting options - insertOptions.setReturnTokens(true); - // insertOptions.setContinueOnError(true); // if continue on error is set true we will return requestIndex for errors - - skyflowClient.vault('VAULT_ID').insert( - insertReq, - insertOptions - ).then((resp: InsertResponse) => { - console.log(resp); - }).catch((err: SkyflowError) => { - console.log(JSON.stringify(err)); - }); -} catch (err) { - console.log(JSON.stringify(err)); -} \ No newline at end of file +import { + Credentials, + Env, + InsertOptions, + InsertRequest, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + SkyflowError +} from 'skyflow-node'; + +/** + * Skyflow Secure Data Insertion Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configuration + * 3. Create an insert request + * 4. Handle response and errors + */ +async function performSecureDataInsertion() { + 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 = new Skyflow(skyflowConfig); + + // Step 4: Prepare Insertion Data + const insertData = [ + { card_number: '4111111111111112' } // Example sensitive data + ]; + + // Step 5: Create Insert Request + const insertReq = new InsertRequest( + 'sensitive_data_table', // Replace with your actual table name + insertData + ); + + // Step 6: Configure Insertion Options + const insertOptions = new InsertOptions(); + insertOptions.setReturnTokens(true); // Optional: Get tokens for inserted data + // insertOptions.setContinueOnError(true); // Optional: Continue on partial errors + + // Step 7: Perform Secure Insertion + const response = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .insert(insertReq, insertOptions); + + // Handle Successful Response + console.log('Insertion 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 insertion function +performSecureDataInsertion(); diff --git a/samples/vault-api/invoke-connection.ts b/samples/vault-api/invoke-connection.ts index 54f2a68..9025ac2 100644 --- a/samples/vault-api/invoke-connection.ts +++ b/samples/vault-api/invoke-connection.ts @@ -1,76 +1,98 @@ -import { Env, Skyflow, InvokeConnectionRequest, RequestMethod, LogLevel, Credentials, SkyflowConfig, VaultConfig, ConnectionConfig, InvokeConnectionResponse, SkyflowError } from 'skyflow-node'; +import { + Credentials, + Env, + InvokeConnectionRequest, + RequestMethod, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + ConnectionConfig, + SkyflowError +} from 'skyflow-node'; -try { - // To generate Bearer Token from credentials string. - const cred: Object = { - clientID: '', - clientName: '', - keyID: '', - tokenURI: '', - privateKey: '', - }; +/** + * Skyflow Connection Invocation Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault and connection configurations + * 3. Invoke a connection + * 4. Handle response and errors + */ +async function invokeSkyflowConnection() { + try { + // Step 1: Configure Credentials + const credentials: Credentials = { + // Using API Key authentication + apiKey: 'your-skyflow-api-key', + }; - // please pass one of apiKey, token, credentialsString & path as credentials - const skyflowCredentials: Credentials = { - credentialsString: JSON.stringify(cred), - }; + // 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 + }; - // please pass one of apiKey, token, credentialsString & path as credentials - const credentials: Credentials = { - apiKey: 'API_KEY', // API Key - }; + // Step 3: Configure Connection + const primaryConnectionConfig: ConnectionConfig = { + connectionId: 'your-connection-id', // Unique connection identifier + connectionUrl: 'your-connection-url', // connection url + credentials: credentials // Connection-specific credentials + }; - const primaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID', // primary vault ( NOTE : One vault is necessary) - clusterId: 'CLUSTER_ID', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - credentials: credentials, // individual credentials - }; + // Step 4: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + connectionConfigs: [primaryConnectionConfig], + logLevel: LogLevel.INFO // Logging verbosity + }; - const primaryConnectionConfig: ConnectionConfig = { - connectionId: 'CONNECTION_ID', // get connection ID from https://${clusterId}.gateway.skyflowapis.dev/v1/gateway/inboundRoutes/${connectionId}/${connection_name} - connectionUrl: 'CONNECTION_URL', // the whole URL https://${clusterId}.gateway.skyflowapis.dev/v1/gateway/inboundRoutes/${connectionId}/${connection_name} - credentials: credentials - }; + // Initialize Skyflow Client + const skyflowClient = new Skyflow(skyflowConfig); - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [ - primaryVaultConfig, - ], - connectionConfigs: [ - primaryConnectionConfig, - ], - skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed - logLevel: LogLevel.ERROR // set log level by default it is set to PROD - }; + // Step 5: Prepare Connection Request + const requestBody = { + key1: 'value1', // Replace with actual key-value pairs + key2: 'value2' + }; - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + const requestHeaders = { + 'content-type': 'application/json' + }; - const body = { - 'KEY1': 'VALUE1', - 'KEY2': 'VALUE2', - }; + const requestMethod: RequestMethod = RequestMethod.POST; - const headers = { - 'Content-Type': 'application/json', - }; + // Step 6: Create Invoke Connection Request + const invokeReq = new InvokeConnectionRequest( + requestMethod, + requestBody, + requestHeaders + ); - const method: RequestMethod = RequestMethod.POST; + // Step 7: Invoke Connection + const response = await skyflowClient + .connection() + .invoke(invokeReq); - const invokeReq: InvokeConnectionRequest = new InvokeConnectionRequest( - method, - body, - headers, - ); + // Handle Successful Response + console.log('Connection invocation successful:', response); - //will return the first connection - skyflowClient.connection().invoke( - invokeReq, - ).then((resp: InvokeConnectionResponse) => { - console.log(resp); - }).catch((err: SkyflowError) => { - console.log(JSON.stringify(err)); - }); -} catch (err) { - console.log(JSON.stringify(err)); -} \ No newline at end of file + } 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 connection function +invokeSkyflowConnection(); diff --git a/samples/vault-api/query-records.ts b/samples/vault-api/query-records.ts index 3f0736e..3efd701 100644 --- a/samples/vault-api/query-records.ts +++ b/samples/vault-api/query-records.ts @@ -1,54 +1,87 @@ -import { Credentials, Env, LogLevel, QueryRequest, QueryResponse, Skyflow, SkyflowConfig, SkyflowError, VaultConfig } from 'skyflow-node'; -try { - // To generate Bearer Token from credentials string. - const cred: Object = { - clientID: '', - clientName: '', - keyID: '', - tokenURI: '', - privateKey: '', - }; - - // please pass one of apiKey, token, credentialsString & path as credentials - const skyflowCredentials: Credentials = { - credentialsString: JSON.stringify(cred), - }; - - // please pass one of apiKey, token, credentialsString & path as credentials - const credentials: Credentials = { - apiKey: 'API_KEY', // API key - }; - - const primaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID', // primary vault - clusterId: 'CLUSTER_ID', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - credentials: credentials, // individual credentials - }; - - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [ - primaryVaultConfig, - ], - skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed - logLevel: LogLevel.ERROR, // set log level by default it is set to PROD - }; - - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - //sample query - const query: string = 'select * from TABLE_NAME limit 1'; - - const queryReq: QueryRequest = new QueryRequest( - query, - ); - - skyflowClient.vault('VAULT_ID').query( - queryReq, - ).then((resp: QueryResponse) => { - console.log(resp); - }).catch((err: SkyflowError) => { - console.log(JSON.stringify(err)); - }); -} catch (err) { - console.log(JSON.stringify(err)); -} \ No newline at end of file +import { + Credentials, + Env, + LogLevel, + QueryRequest, + QueryResponse, + Skyflow, + SkyflowConfig, + SkyflowError, + VaultConfig +} from 'skyflow-node'; + +/** + * Skyflow Query Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configuration + * 3. Execute a query on the vault + * 4. Handle response and errors + */ +async function executeQuery() { + try { + // Step 1: Configure Credentials + const cred: object = { + clientID: '', // Client identifier + clientName: '', // Client name + keyID: '', // Key identifier + tokenURI: '', // Token URI + privateKey: '' // Private key for authentication + }; + + const skyflowCredentials: Credentials = { + credentialsString: JSON.stringify(cred), // Token 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], + skyflowCredentials: skyflowCredentials, // Used if no individual credentials are passed + logLevel: LogLevel.ERROR, // Logging verbosity + }; + + // Initialize Skyflow Client + const skyflowClient = new Skyflow(skyflowConfig); + + // Step 4: Prepare Query + const query = 'select * from table_name limit 1'; // Example query + const queryRequest = new QueryRequest(query); + + // Step 5: Execute Query + const response: QueryResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .query(queryRequest); + + // Handle Successful Response + console.log('Query Result:', 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 query function +executeQuery(); diff --git a/samples/vault-api/tokenize-records.ts b/samples/vault-api/tokenize-records.ts index 82bce25..e11ed24 100644 --- a/samples/vault-api/tokenize-records.ts +++ b/samples/vault-api/tokenize-records.ts @@ -1,59 +1,91 @@ -import { Credentials, Env, LogLevel, Skyflow, SkyflowConfig, TokenizeRequest, VaultConfig, TokenizeRequestType, TokenizeResponse, SkyflowError } from 'skyflow-node'; -try { - // To generate Bearer Token from credentials string. - const cred: Object = { - clientID: '', - clientName: '', - keyID: '', - tokenURI: '', - privateKey: '', - }; - - // please pass one of apiKey, token, credentialsString & path as credentials - const skyflowCredentials: Credentials = { - credentialsString: JSON.stringify(cred), - }; - - // please pass one of apiKey, token, credentialsString & path as credentials - const credentials: Credentials = { - apiKey: 'API_KEY', // API key - }; - - const primaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID', // primary vault - clusterId: 'CLUSTER_ID', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - credentials: credentials, // individual credentials - }; - - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [ - primaryVaultConfig, - ], - skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed - logLevel: LogLevel.ERROR // set log level by default it is set to PROD - }; - - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); - - // tokenize only supports value and columngroup - // sample data - const tokenizeValues: Array = [ - { value: '4111111111111111', columnGroup: 'card_number_cg' }, - { value: '42424242424242424', columnGroup: 'card_number_cg' } - ]; - - const tokenReq: TokenizeRequest = new TokenizeRequest( - tokenizeValues, - ); - - skyflowClient.vault('VAULT_ID').tokenize( - tokenReq, - ).then((resp: TokenizeResponse) => { - console.log(resp); - }).catch((err: SkyflowError) => { - console.log(JSON.stringify(err)); - }); -} catch (err) { - console.log(JSON.stringify(err)); -} \ No newline at end of file +import { + Credentials, + Env, + LogLevel, + Skyflow, + SkyflowConfig, + TokenizeRequest, + VaultConfig, + TokenizeRequestType, + TokenizeResponse, + SkyflowError +} from 'skyflow-node'; + +/** + * Skyflow Tokenization Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configuration + * 3. Tokenize sensitive data + * 4. Handle response and errors + */ +async function executeTokenization() { + try { + // Step 1: Configure Credentials + const cred: object = { + clientID: '', // Client identifier + clientName: '', // Client name + keyID: '', // Key identifier + tokenURI: '', // Token URI + privateKey: '' // Private key for authentication + }; + + const skyflowCredentials: Credentials = { + credentialsString: JSON.stringify(cred), // Token credentials + }; + + const credentials: Credentials = { + apiKey: '', // API key for authentication + }; + + // Step 2: Configure Vault + const primaryVaultConfig: VaultConfig = { + vaultId: '', // Unique vault identifier + clusterId: '', // From vault URL + env: Env.PROD, // Deployment environment + credentials: credentials // Authentication method + }; + + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + skyflowCredentials: skyflowCredentials, // Used if no individual credentials are passed + logLevel: LogLevel.ERROR, // Logging verbosity + }; + + // Initialize Skyflow Client + const skyflowClient = new Skyflow(skyflowConfig); + + // Step 4: Prepare Tokenization Data + const tokenizeValues: Array = [ + { value: '4111111111111111', columnGroup: 'card_number_cg' }, + { value: '4242424242424242', columnGroup: 'card_number_cg' } + ]; + + const tokenReq: TokenizeRequest = new TokenizeRequest(tokenizeValues); + + // Step 5: Execute Tokenization + const response: TokenizeResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .tokenize(tokenReq); + + // Handle Successful Response + console.log('Tokenization Result:', 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 tokenization function +executeTokenization(); diff --git a/samples/vault-api/update-record.ts b/samples/vault-api/update-record.ts index f06bc6e..2dce780 100644 --- a/samples/vault-api/update-record.ts +++ b/samples/vault-api/update-record.ts @@ -1,66 +1,87 @@ -import { Env, Skyflow, UpdateRequest, UpdateOptions, LogLevel, Credentials, VaultConfig, SkyflowConfig, UpdateResponse, SkyflowError } from 'skyflow-node'; +import { + Credentials, + Env, + LogLevel, + Skyflow, + VaultConfig, + SkyflowConfig, + UpdateRequest, + UpdateOptions, + UpdateResponse, + SkyflowError +} from 'skyflow-node'; -try { - // To generate Bearer Token from credentials string. - const cred: Object = { - clientID: '', - clientName: '', - keyID: '', - tokenURI: '', - privateKey: '', - }; +/** + * Skyflow Secure Data Update Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client 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', + }; - // please pass one of apiKey, token, credentialsString & path as credentials - const skyflowCredentials: Credentials = { - credentialsString: JSON.stringify(cred), - }; + // 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 + }; - // please pass one of apiKey, token, credentialsString & path as credentials - const credentials: Credentials = { - apiKey: 'API_KEY', // API key - }; + // Step 3: Configure Skyflow Client + const skyflowConfig: SkyflowConfig = { + vaultConfigs: [primaryVaultConfig], + logLevel: LogLevel.INFO // Logging verbosity + }; - const primaryVaultConfig: VaultConfig = { - vaultId: 'VAULT_ID', // primary vault - clusterId: 'CLUSTER_ID', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - env: Env.PROD, // Env by default it is set to PROD - credentials: credentials, // individual credentials - }; + // Initialize Skyflow Client + const skyflowClient = new Skyflow(skyflowConfig); - const skyflowConfig: SkyflowConfig = { - vaultConfigs: [ - primaryVaultConfig, - ], - skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed - logLevel: LogLevel.ERROR, // set log level by default it is set to PROD - }; + // Step 4: Prepare Update Data + const updateData = { + skyflowId: 'your-skyflow-id', // Skyflow ID of the record to update + card_number: '1234567890123456' // Updated sensitive data + }; - const skyflowClient: Skyflow = new Skyflow(skyflowConfig); + // Step 5: Create Update Request + const updateReq = new UpdateRequest( + 'sensitive_data_table', // Replace with your actual table name + updateData + ); - const skyflowId: string = 'SKYFLOW_ID'; + // Step 6: Configure Update Options + const updateOptions = new UpdateOptions(); + updateOptions.setReturnTokens(true); // Optional: Get tokens for updated data - // sample data - const updateData: Object = { skyflowId, card_number: '12333333333333444444' }; + // Step 7: Perform Secure Update + const response: UpdateResponse = await skyflowClient + .vault(primaryVaultConfig.vaultId) + .update(updateReq, updateOptions); - const tableName: string = 'TABLE_NAME'; + // Handle Successful Response + console.log('Update successful:', response); - const updateReq: UpdateRequest = new UpdateRequest( - tableName, - updateData, - ); + } 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); + } + } +} - const updateOptions: UpdateOptions = new UpdateOptions(); - - updateOptions.setReturnTokens(true); - - skyflowClient.vault('VAULT_ID').update( - updateReq, - updateOptions, - ).then((resp: UpdateResponse) => { - console.log(resp); - }).catch((err: SkyflowError) => { - console.log(JSON.stringify(err)); - }); -} catch (err) { - console.log(JSON.stringify(err)); -} \ No newline at end of file +// Invoke the secure data update function +performSecureDataUpdate(); diff --git a/src/error/messages/index.ts b/src/error/messages/index.ts index 67d02da..5c102c0 100644 --- a/src/error/messages/index.ts +++ b/src/error/messages/index.ts @@ -164,7 +164,7 @@ const errorMessages = { EMPTY_INSERT_TOKEN: `${errorPrefix} Validation error. Tokens object cannot be empty. Specify a valid tokens object at index %s1.`, INVALID_INSERT_TOKEN: `${errorPrefix} Validation error. Invalid tokens object. Specify a valid tokens object at index %s1.`, INVALID_INSERT_TOKENS: `${errorPrefix} Validation error. Invalid tokens. Specify valid tokens as object array.`, - INVALID_TOKEN_MODE: `${errorPrefix} Validation error. The token mode key has a value of type %s1. Specify token as BYOT.`, + INVALID_TOKEN_MODE: `${errorPrefix} Validation error. The token mode key has a value of type %s1. Specify token as type of TokenMode.`, INVALID_HOMOGENEOUS: `${errorPrefix} Validation error. The homogeneous key has a value of type %s1. Specify homogeneous as boolean.`, INVALID_TOKEN_STRICT: `${errorPrefix} Validation error. The tokenStrict key has a value of type %s1. Specify tokenStrict as boolean.`, INVALID_CONTINUE_ON_ERROR: `${errorPrefix} Validation error. The continueOnError key has a value of type %s1. Specify continueOnError as boolean.`, diff --git a/src/index.ts b/src/index.ts index 22fcbbd..f8edec2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import Skyflow from './vault/skyflow'; -import { LogLevel, Env, RedactionType, RequestMethod, OrderByEnum, BYOT } from './utils'; +import { LogLevel, Env, RedactionType, RequestMethod, OrderByEnum, TokenMode } from './utils'; import InsertRequest from './vault/model/request/insert'; import InsertOptions from './vault/model/options/insert'; import GetRequest from './vault/model/request/get'; @@ -52,7 +52,7 @@ export { Credentials, RedactionType, OrderByEnum, - BYOT, + TokenMode, InsertRequest, InsertOptions, InsertResponse, diff --git a/src/utils/index.ts b/src/utils/index.ts index 3892b94..b75dce9 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -34,7 +34,7 @@ export const VAULT = "vault"; export const CONNECTION = "connection"; -export enum BYOT { +export enum TokenMode { DISABLE = 'DISABLE', ENABLE = 'ENABLE', ENABLE_STRICT = 'ENABLE_STRICT' diff --git a/src/vault/controller/vault/index.ts b/src/vault/controller/vault/index.ts index 64653a9..9facd08 100644 --- a/src/vault/controller/vault/index.ts +++ b/src/vault/controller/vault/index.ts @@ -256,7 +256,7 @@ class VaultController { const skyflowId = request.data[SKYFLOW_ID]; delete request.data[SKYFLOW_ID]; const record = { fields: request.data, tokens: options?.getTokens() }; - const strictMode = options?.getTokenMode() ? V1BYOT.Enable : V1BYOT.Disable; + const strictMode = options?.getTokenMode() ? options?.getTokenMode() : V1BYOT.Disable; const updateData: RecordServiceUpdateRecordBody = { record: record, tokenization: options?.getReturnTokens(), diff --git a/src/vault/model/options/insert/index.ts b/src/vault/model/options/insert/index.ts index 14b5d2c..14703bc 100644 --- a/src/vault/model/options/insert/index.ts +++ b/src/vault/model/options/insert/index.ts @@ -1,4 +1,4 @@ -import { BYOT } from "../../../../utils"; +import { TokenMode } from "../../../../utils"; //imports class InsertOptions { @@ -7,7 +7,7 @@ class InsertOptions { private upsert?: string; private tokens?: Array; private homogeneous?: boolean; - private tokenMode?: BYOT; + private tokenMode?: TokenMode; private continueOnError?: boolean; // Constructor @@ -30,7 +30,7 @@ class InsertOptions { this.homogeneous = homogeneous; } - setTokenMode(tokenMode: BYOT) { + setTokenMode(tokenMode: TokenMode) { this.tokenMode = tokenMode; } @@ -55,7 +55,7 @@ class InsertOptions { return this.homogeneous; } - getTokenMode(): BYOT | undefined { + getTokenMode(): TokenMode | undefined { return this.tokenMode; } diff --git a/src/vault/model/options/update/index.ts b/src/vault/model/options/update/index.ts index 4d779df..3485321 100644 --- a/src/vault/model/options/update/index.ts +++ b/src/vault/model/options/update/index.ts @@ -1,11 +1,11 @@ //imports -import { BYOT } from "../../../../utils"; +import { TokenMode } from "../../../../utils"; class UpdateOptions { //fields private returnTokens?: boolean; - private tokenMode?: BYOT; + private tokenMode?: TokenMode; private tokens?: object; // Constructor @@ -20,11 +20,11 @@ class UpdateOptions { this.tokens = tokens; } - setTokenMode(tokenMode: BYOT) { + setTokenMode(tokenMode: TokenMode) { this.tokenMode = tokenMode; } - getTokenMode(): BYOT | undefined { + getTokenMode(): TokenMode | undefined { return this.tokenMode; } diff --git a/test/vault/controller/vault.test.js b/test/vault/controller/vault.test.js index ce57af5..e3e9c44 100644 --- a/test/vault/controller/vault.test.js +++ b/test/vault/controller/vault.test.js @@ -1041,7 +1041,7 @@ describe('VaultController update method', () => { }; const mockOptions = { getReturnTokens: jest.fn().mockReturnValue(true), - getTokenMode: jest.fn().mockReturnValue("ENABLE"), + getTokenMode: jest.fn().mockReturnValue(""), getTokens: jest.fn().mockReturnValue({}), }; validateUpdateRequest.mockImplementation(() => {