Skyflow SDK for Node.js
npm install skyflow-nodeSDK for the Skyflow Data Privacy Vault.



- Skyflow Node.js SDK
- Table of contents
- Overview
- Install
- Requirements
- Import / Require
- Require
- ES modules
- All imports
- Migrate from v1 to v2
- Authentication options
- Initializing the client
- Request & response structure
- Request options
- Error structure
- Quickstart
- Authenticate
- Initialize the client
- Insert data into the vault
- Vault
- Insert data into the vault
- Detokenize
- Tokenize
- Get
- Get by skyflow IDs
- Get tokens
- Get by column name and column values
- Redaction types
- Update
- Delete
- Invoke Connection
- Query
- Detect
- Deidentify Text
- Reidentify Text
- Deidentify File
- Get Run
- Connections
- Invoke a connection
- Authenticate with bearer tokens
- Generate a bearer token
- Generate bearer tokens with context
- Generate scoped bearer tokens
- Generate signed data tokens
- Bearer token expiry edge case
- Logging
- Reporting a vulnerability
- Authenticate using a Skyflow service account and generate bearer tokens for secure access.
- Perform Vault API operations such as inserting, retrieving, and tokenizing sensitive data with ease.
- Invoke connections to third-party APIs without directly handling sensitive data, ensuring compliance and data protection.
#### Requirements
- Node 12.22.12 and above
``sh`
npm install skyflow-node
#### Import / Require
Depending on your project setup, you may use either the require method (common in Node.js projects) or the import statement (common in projects using ES modules).
##### Require
`typescript`
const { Skyflow } = require('skyflow-node');
##### ES modules
`typescript`
import { Skyflow } from 'skyflow-node';
##### All imports
`typescript`
import {
Skyflow, // Vault client
isExpired, // JWT auth helpers
LogLevel, // logging options
} from 'skyflow-node'
This guide outlines the steps required to migrate the Node SDK from version 1 (V1) to version 2 (V2).
---
In V2, multiple authentication options have been introduced. You can now provide credentials in the following ways:
- API Key
- Environment Variable (SKYFLOW_CREDENTIALS) (Recommended)
- Path to Credentials JSON File
- Stringified JSON of Credentials
- Bearer Token
These options allow you to choose the authentication method that best suits your use case.
#### V1 (Old): Passing the auth function below as a parameter to the getBearerToken key.
`javascript`
// sample function to retrieve a bearer token from an environment variable
// customize this according to your environment and security posture
const auth = function () {
return new Promise((resolve, reject) => {
resolve(process.env.VAULT_BEARER_TOKEN);
});
};
#### V2 (New): Passing one of the following:
`javascript
// Option 1: API Key (Recommended)
const credentials = { apiKey: "
// Option 2: Environment Variables (Recommended)
// Set SKYFLOW_CREDENTIALS in your environment
// Option 3: Credentials File
const credentials = { path: "
// Option 4: Stringified JSON
const credentials = { credentialsString: JSON.stringify(process.env.SKYFLOW_CREDENTIALS) };
// Option 5: Bearer Token
const credentials = { token: "
`
---
V2 introduces TypeScript support and multi-vault support, allowing you to configure multiple vaults during client initialization.
In V2, the log level is tied to each individual client instance.
During client initialization, you can pass the following parameters:
- vaultId and clusterId: These values are derived from the vault ID & vault URL.
- env: Specify the environment (e.g., SANDBOX or PROD).
- credentials: The necessary authentication credentials.
#### V1 (Old)
`javascript
// Initialize the Skyflow Vault client
const vault = Skyflow.init({
// Id of the vault that the client should connect to.
vaultID: 'string',
// URL of the vault that the client should connect to.
vaultURL: 'string',
// Helper function generates a Skyflow bearer token.
getBearerToken: auth,
});
`
#### V2 (New)
`javascript
// Step 1: Configure Bearer Token Credentials
const credentials: Credentials = { apiKey: '
// Step 2: Configure Vault
const primaryVaultConfig: VaultConfig = {
vaultId: '
clusterId: '
env: Env.PROD, // Deployment environment (PROD by default)
credentials: credentials, // Authentication method
};
// Step 3: Configure Skyflow Client
const skyflowConfig: SkyflowConfig = {
vaultConfigs: [primaryVaultConfig],
skyflowCredentials: credentials, // Skyflow credentials will be used if no individual credentials are passed
logLevel: LogLevel.INFO, // Recommended to use LogLevel.ERROR in production environment.
};
// Initialize Skyflow Client
const skyflowClient: Skyflow = new Skyflow(skyflowConfig);
`
replaced with clusterId.
- Added environment specification (env).
- Instance-specific log levels.
- TypeScript support with type definitions---
$3
In V2, with the introduction of TypeScript support, you can now pass an InsertRequest of type InsertRequest. This request need
-
tableName: The name of the table.
- insertData: An array of objects containing the data to be inserted
The response will be of type InsertResponse, which contains insertedFields and errors.#### V1 (Old) - Request Building
`javascript
const result = skyflow.insert({
records: [
{
fields: {
card_number: '411111111111111',
expiry_date: '11/22',
fullname: 'firstNameTest',
},
table: 'cards',
},
],
});
`#### V2 (New) - Request Building
`typescript
// Prepare Insertion Data
const insertData: Record[] = [
{ card_number: '4111111111111112' } // Example sensitive data
];// Create Insert Request
const insertReq: InsertRequest = new InsertRequest(
'', // Replace with your actual table name
insertData
);
// Perform Secure Insertion
const response: InsertResponse = await skyflowClient
.vault("")
.insert(insertReq);
`#### V1 (Old) - Response Structure
`json
{
"records": [
{
"table": "cards",
"fields": {
"card_number": "f37186-e7e2-466f-91e5-48e2bcbc1",
"expiry_date": "1989cb56-63a-4482-adf-1f74cd1a5"
}
}
]
}
`#### V2 (New) - Response Structure
`javascript
InsertResponse(
insertedFields : [
{
skyflowId : "ID1",
"": "", // removed tokens key
"": ""
},
{
skyflowId : "ID2",
"": "",
"": ""
}
],
errors: null
);
`---
$3
In V2, we have introduced inbuilt InsertOptions classes. These allow you to use setters to configure options instead of passing a plain object with key-value pairs.
#### V1 (Old)
`javascript
const options = {
tokens: true,
// other options
};
`#### V2 (New)
`javascript
const insertOptions: InsertOptions = new InsertOptions();
insertOptions.setReturnTokens(true); // Optional: Get tokens for inserted data
insertOptions.setContinueOnError(true); // Optional: Continue on partial errors
`---
$3
In V2, we have enriched the error details to provide better debugging capabilities.
The error response now includes:
- http_status: The HTTP status code. .
- grpc_code: The gRPC code associated with the error.
- details & message: A detailed description of the error.
- request_ID: A unique request identifier for easier debugging.
#### V1 (Old) - Error Structure
`javascript
{
code: string | number,
description: string
}
`#### V2 (New) - Error Structure
`javascript
{
http_status?: string | number | null,
grpc_code?: string | number | null,
http_code: string | number | null,
message: string,
request_ID?: string | null,
details?: Array | null,
}
`Quickstart
Get started quickly with the essential steps: authenticate, initialize the client, and perform a basic vault operation. This section provides a minimal setup to help you integrate the SDK efficiently.$3
You can use an API key to authenticate and authorize requests to an API. For authenticating via bearer tokens and different supported bearer token types, refer to the Authenticate with bearer tokens section. `javascript
// create a new credentials object
const credentials = { apiKey: "" }; //add your API key in credentials
`$3
To get started, you must first initialize the skyflow client. While initializing the skyflow client, you can specify different types of credentials.
1. API keys
A unique identifier used to authenticate and authorize requests to an API.
2. Bearer tokens
A temporary access token used to authenticate API requests, typically included in the
Authorization header.
3. Service account credentials file path
The file path pointing to a JSON file containing credentials for a service account, used
for secure API access.
4. Service account credentials string
JSON-formatted string containing service account credentials, often used as an alternative to a file for programmatic authentication.
Note: Only one type of credential can be used at a time. If multiple credentials are provided, the last one added will take precedence.
`javascript
import {
Credentials,
Env,
LogLevel,
Skyflow,
VaultConfig,
SkyflowConfig,
} from 'skyflow-node';/*
Example program to initialize the Skyflow client with various configurations.
The Skyflow client facilitates secure interactions with the Skyflow vault,
such as securely managing sensitive data.
*/
// Step 1: Define the primary credentials for authentication.
// Note: Only one type of credential can be used at a time. You can choose between:
// - API key
// - Bearer token
// - A credentials string (JSON-formatted)
// - A file path to a credentials file.
// Initialize primary credentials using a Bearer token for authentication.
const primaryCredentials: Credentials = { /////////////////
token: '', // Replace with your actual authentication token.
};
// Step 2: Configure the primary vault details.
// VaultConfig stores all necessary details to connect to a specific Skyflow vault.
const primaryVaultConfig: VaultConfig = {
vaultId: '', // Replace with your primary vault ID
clusterId: '', // Replace with the cluster ID (part of the vault URL, e.g., https://{clusterId}.vault.skyflowapis.com).
env: Env.PROD, // Set the environment (PROD, SANDBOX, STAGE, DEV).
credentials: primaryCredentials // Attach the primary credentials to this vault configuration.
};
// Step 3: Create credentials as a JSON object (if a Bearer Token is not provided).
// Demonstrates an alternate approach to authenticate with Skyflow using a credentials object.
const skyflowCredentials: object = {
clientID: '', // Replace with your Client ID.
clientName: '', // Replace with your Client Name.
tokenURI: '', // Replace with the Token URI.
keyID: '', // Replace with your Key ID.
privateKey: '' // Replace with your Private Key.
}
// Step 4: Convert the JSON object to a string and use it as credentials.
// This approach allows the use of dynamically generated or pre-configured credentials.
const credentialsString: JSON.stringify(skyflowCredentials), // Converts JSON object to string for use as credentials.
// Step 5: Define secondary credentials (API key-based authentication as an example).
// Demonstrates a different type of authentication mechanism for Skyflow vaults.
const secondaryCredentials: Credentials = {
apiKey: '', // Replace with your API Key for authentication.
}
// Step 6: Configure the secondary vault details.
// A secondary vault configuration can be used for operations involving multiple vaults.
const secondaryVaultConfig: VaultConfig = {
vaultId: '', // Replace with your secondary vault's ID.
clusterId: '', // Replace with the corresponding cluster ID.
env: Env.PROD, // Set the environment for this vault.
credentials: secondaryCredentials // Attach the secondary credentials to this configuration.
}
// Step 7: Define tertiary credentials using a path to a credentials JSON file.
// This method demonstrates an alternative authentication method.
const tertiaryCredentials: Credentials = {
path: '' // Replace with the path to your credentials file.
}
// Step 8: Configure the tertiary vault details.
const tertiaryVaultConfig: VaultConfig = {
vaultId: '', // Replace with the tertiary vault ID.
clusterId: '', // Replace with the corresponding cluster ID.
env: Env.PROD, // Set the environment for this vault.
credentials: tertiaryCredentials // Attach the tertiary credentials.
}
// Step 9: Build and initialize the Skyflow client after creating Skyflow Config
// Skyflow client is configured with multiple vaults and credentials.
const skyflowConfig: SkyflowConfig = {
vaultConfigs: [primaryVaultConfig, secondaryVaultConfig, tertiaryVaultConfig], // Add the primary, secondary and tertiary vault configurations.
skyflowCredentials: skyflowCredentials, // Add JSON-formatted credentials if applicable.
logLevel: LogLevel.INFO // Recommended to use LogLevel.ERROR in production environment.
};
// Step 10: Initialize Skyflow Client
const skyflowClient: Skyflow = new Skyflow(skyflowConfig);
// The Skyflow client is now fully initialized.
// Use the
skyflowClient object to perform secure operations such as:
// - Inserting data
// - Retrieving data
// - Deleting data
// within the configured Skyflow vaults.`Notes
- If both Skyflow common credentials and individual credentials at the configuration level are specified, the individual credentials at the configuration level will take precedence.
- If neither Skyflow common credentials nor individual configuration-level credentials are provided, the SDK attempts to retrieve credentials from the
`SKYFLOW_CREDENTIALS` environment variable.
- All Vault operations require a client instance.$3
To insert data into your vault, use the insert method. The InsertRequest class creates an insert request, which includes the values to be inserted as a list of records. Below is a simple example to get started. For advanced options, check out Insert data into the vault section.`javascript
import {
InsertOptions,
InsertRequest,
SkyflowError,
InsertResponse
} from 'skyflow-node';/*
* This example demonstrates how to insert sensitive data (e.g., card information) into a Skyflow vault using the Skyflow client.
*
* 1. Initializes the Skyflow client.
* 2. Prepares a record with sensitive data (e.g., card number and cardholder name).
* 3. Creates an insert request for inserting the data into the Skyflow vault.
* 4. Prints the response of the insert operation.
*/
try{
// Step 1: Initialize data to be inserted into the Skyflow vault
const insertData: Record[] = [
{
card_number: '4111111111111112', // Replace with actual card number (sensitive data)
cardholder_name: 'John Doe', // Replace with actual cardholder name (sensitive data)
}
];
// Step 2: Create Insert Request
const insertReq: InsertRequest = new InsertRequest(
'table1', // Specify the table in the vault where the data should be inserted
insertData, // Attach the data (records) to be inserted
);
// Step 3: Configure Insertion Options
const insertOptions: InsertOptions = new InsertOptions();
insertOptions.setReturnTokens(true); // Optional: Specify if tokens should be returned upon successful insertion
insertOptions.setContinueOnError(true); // Optional: Continue on partial errors
// Step 4: Perform the insert operation using the Skyflow client
const insertResponse: InsertResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.insert(insertReq, insertOptions);
// Step 5: Print the response from the insert operation
console.log('Insert response: ', insertResponse);
} catch(error) {
// Step 6: 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);
}
}
`
Skyflow returns tokens for the record that was just inserted.`javascript
InsertResponse {
insertedFields: {
skyflowId: 'a8f3ed5d-55eb-4f32-bf7e-2dbf4b9d9097',
card_number: '5484-7829-1702-9110',
cardholder_name: 'b2308e2a-c1f5-469b-97b7-1f193159399b'
},
errors: null
}
`---
Vault
The Vault performs operations on the vault such as inserting records, detokenizing tokens, retrieving tokens for list of skyflow_id's and to invoke the Connection.$3
Apart from using the
insert method to insert data into your vault covered in Quickstart, you can also pass options to insert method, such as returning tokenized data, upserting records, or continuing the operation in case of errors.#### Construct an insert request
`typescript
import {
InsertOptions,
InsertRequest,
SkyflowError,
InsertResponse
} from 'skyflow-node';// Example program to demonstrate inserting data into a Skyflow vault,
// along with corresponding InsertRequest schema.
try {
// Initialize Skyflow client
// Step 1: Prepare the data to be inserted into the Skyflow vault
const insertData: Record[] = [
{
: '', // Replace with actual field name and value
: '', // Replace with actual field name and value
},
{
: '', // Replace with actual field name and value
: '', // Replace with actual field name and value
},
]
// Step 2: Build an InsertRequest object with the table name and the data to insert
const insertReq: InsertRequest = new InsertRequest(
'table1', // Specify the table in the vault where the data will be inserted
insertData, // Attach the data (records) to be inserted
);
// Step 3: Perform the insert operation using the Skyflow client
const insertResponse: InsertResponse = await skyflowClient
.vault('')
.insert(insertReq, insertOptions);
// Replace with your actual vault ID
// Step 4: Print the response from the insert operation
console.log('Insert response: ', insertResponse);
} catch(error) {
// Step 5: 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);
}
}
`#### Insert call example with
continueOnError option
The continueOnError flag is a boolean that determines whether insert operation should proceed despite encountering partial errors. Set to true to allow the process to continue even if some errors occur.`typescript
import {
InsertOptions,
InsertRequest,
SkyflowError,
InsertResponse
} from 'skyflow-node';/*
This example demonstrates how to insert sensitive data (e.g., card information) into a Skyflow vault using the Skyflow client.
1. Initializes the Skyflow client.
2. Prepares a record with sensitive data (e.g., card number and cardholder name).
3. Creates an insert request for inserting the data into the Skyflow vault.
4. Specifies options to continue on error and return tokens.
5. Prints the response of the insert operation.
*/
try {
// Initialize Skyflow client
// Step 1: Initialize a list to hold the data records to be inserted into the vault
const insertData: Record[] = [
// Step 2: Create the first record with card number and cardholder name
{
card_number: '4111111111111111', // Replace with actual card number (sensitive data)
cardholder_name: 'John Doe', // Replace with actual cardholder name (sensitive data)
},
//Step 3: Create the second record with card number and cardholder name
{
card_numbe: '4111111111111111', // Replace with actual card number (sensitive data)
cardholder_name: 'John Doe', // Replace with actual cardholder name (sensitive data)
}
];
// Step 4: Create Insert Request
const insertReq: InsertRequest = new InsertRequest(
'table1', // Specify the table in the vault where the data should be inserted
insertData, // Attach the data (records) to be inserted
);
// Step 5: Configure Insertion Options
const insertOptions: InsertOptions = new InsertOptions();
insertOptions.setReturnTokens(true); // Optional: Specify if tokens should be returned upon successful insertion
insertOptions.setContinueOnError(true); // Optional: Specify to continue inserting records even if an error occurs for some records partial errors
// Step 6: Perform the insert operation using the Skyflow client
const insertResponse: InsertResponse = await skyflowClient
.vault('9f27764a10f7946fe56b3258e117')
.insert(insertReq, insertOptions);
// Replace the vault ID "9f27764a10f7946fe56b3258e117" with your actual Skyflow vault ID
// Step 7: Print the response from the insert operation
console.log('Insert response: ', insertResponse);
} catch(error) {
// Step 8: 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);
}
}
`Sample Response
`typescript
InsertResponse {
insertedFields: {
[
{
card_number: '5484-7829-1702-9110',
requestIndex: 0,
skyflowId: '9fac9201-7b8a-4446-93f8-5244e1213bd1',
cardholder_name: 'b2308e2a-c1f5-469b-97b7-1f193159399'
}
],
errors: [
{
requestIndex: 1,
error: 'Insert failed. Column card_numbe is invalid. Specify a valid column.'
}
]
}
}
`Insert call example with
upsert option
An upsert operation checks for a record based on a unique column's value. If a match exists, the record is updated; otherwise, a new record is inserted.`typescript
import {
InsertOptions,
InsertRequest,
SkyflowError,
InsertResponse
} from 'skyflow-node';/*
This example demonstrates how to insert sensitive data (e.g., card information) into a Skyflow vault using the Skyflow client.
1. Initializes the Skyflow client.
2. Prepares a record with sensitive data (e.g., card number and cardholder name).
3. Creates an insert request for inserting the data into the Skyflow vault.
4. Specifies the field (cardholder_name) for upsert operations.
5. Prints the response of the insert operation.
*/
try {
// Initialize Skyflow client
// Step 1: Initialize a list to hold the data records for the insert/upsert operation
const insertData: Record[] = [
// Step 2: Create a record with the field 'cardholder_name' to insert or upsert
{
cardholder_name: 'John Doe', // Replace with actual cardholder name
}
]
// Step 3: Create Insert Request
const insertReq: InsertRequest = new InsertRequest(
'table1', // Specify the table in the vault where the data will be inserted
insertData, // Attach the data (records) to be inserted
);
// Step 4: Set upsert column by configuring the insertion options
const insertOptions: InsertOptions = new InsertOptions();
insertOptions.setReturnTokens(true); // Optional: Specify if tokens should be returned upon successful insertion
insertOptions.setUpsertColumn('cardholder_name');
// Step 5: Perform the insert/upsert operation using the Skyflow client
const insertResponse: InsertResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.insert(insertReq, insertOptions);
// Step 6: Print the response from the insert operation
console.log('Insert response: ', insertResponse);
} 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);
}
}
`Skyflow returns tokens, with
upsert support, for the record you just inserted.`typescript
InsertResponse {
insertedFields: [
{
skyflowId: "9fac9201-7b8a-4446-93f8-5244e1213bd1",
cardholder_name: "73ce45ce-20fd-490e-9310-c1d4f603ee83"
}
],
errors: null
}
`$3
To retrieve tokens from your vault, use the
detokenize method. The DetokenizeRequest class requires a list of detokenization data as input. Additionally, you can provide optional parameters, such as the redaction type and the option to continue on error.#### Construct a detokenize request
`typescript
import {
DetokenizeOptions,
DetokenizeRequest,
DetokenizeResponse,
DetokenizeData,
SkyflowError,
} from 'skyflow-node';/*
This example demonstrates how to detokenize sensitive data from tokens stored in a Skyflow vault, along with corresponding DetokenizeRequest schema.
*/
try {
// Step 1: Prepare Detokenization Data
const detokenizeData: DetokenizeData[] = [
{
token: "token1", // Token to be detokenized
redactionType: RedactionType.PLAIN_TEXT, // Redaction type
},
{
token: "token2", // Token to be detokenized
redactionType: RedactionType.PLAIN_TEXT, // Redaction type
},
];
// Step 2: Create the DetokenizeRequest object with the tokens data
const detokenizeRequest: DetokenizeRequest = new DetokenizeRequest(
detokenizeData
);
// Step 3: Configure Detokenize Options
const detokenizeOptions: DetokenizeOptions = new DetokenizeOptions();
detokenizeOptions.setContinueOnError(true); // Continue processing on errors
detokenizeOptions.setDownloadURL(false); // Disable download URL generation
// Step 4: Perform Detokenization
const response: DetokenizeResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.detokenize(detokenizeRequest, detokenizeOptions);
// Handle Successful Response
console.log('Detokenization 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:', error);
}
}
`Notes:
-
redactionType defaults to RedactionType.PLAIN_TEXT.
- continueOnError default value is False.#### An example of a detokenize call
`typescript
import {
DetokenizeOptions,
DetokenizeRequest,
DetokenizeResponse,
DetokenizeData,
SkyflowError,
} from 'skyflow-node';/*
1. Initializes the Skyflow client.
2. Creates a list of tokens (e.g., credit card tokens) that represent the sensitive data.
3. Builds a detokenization request using the provided tokens and specifies how the redacted data should be returned.
4. Calls the Skyflow vault to detokenize the tokens and retrieves the detokenized data.
5. Prints the detokenization response, which contains the detokenized values or errors.
*/
try {
// Step 1: Prepare Detokenization Data
const detokenizeData: DetokenizeData[] = [
{
token: "9738-1683-0486-1480", // Replace with your actual token value
redactionType: RedactionType.PLAIN_TEXT, // Redaction type
},
{
token: "6184-6357-8409-6668", // Replace with your actual token value
redactionType: RedactionType.PLAIN_TEXT, // Redaction type
},
];
// Step 2: Create the DetokenizeRequest object with the tokens data
const detokenizeRequest: DetokenizeRequest = new DetokenizeRequest(
detokenizeData
);
// Step 3: Configure Detokenize Options
const detokenizeOptions: DetokenizeOptions = new DetokenizeOptions();
detokenizeOptions.setContinueOnError(false); // Stop the process if any token cannot be detokenized
// Step 4: Perform Detokenization
const response: DetokenizeResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.detokenize(detokenizeRequest, detokenizeOptions);
// Handle Successful Response
console.log('Detokenization 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:', error);
}
}
`Sample response:
`typescript
DetokenizeResponse {
detokenizedFields: [
{token: '9738-1683-0486-1480', value: '4111111111111115', type: 'STRING'},
{token: '6184-6357-8409-6668', value: '4111111111111119', type: 'STRING'},
],
errors: null
}
`#### An example of a detokenize call with
continueOnError option:`typescript
import {
DetokenizeOptions,
DetokenizeRequest,
DetokenizeResponse,
DetokenizeData,
SkyflowError,
} from 'skyflow-node';/*
1. Initializes the Skyflow client.
2. Creates a list of tokens (e.g., credit card tokens) that represent the sensitive data.
3. Builds a detokenization request using the provided tokens and specifies how the redacted data should be returned.
4. Calls the Skyflow vault to detokenize the tokens and retrieves the detokenized data.
5. Prints the detokenization response, which contains the detokenized values or errors.
*/
try {
// Step 1: Prepare Detokenization Data
const detokenizeData: DetokenizeData[] = [
{
token: "9738-1683-0486-1480", // Replace with your actual token value
redactionType: RedactionType.PLAIN_TEXT, // Redaction type
},
{
token: "6184-6357-8409-6668", // Replace with your actual token value
redactionType: RedactionType.PLAIN_TEXT, // Redaction type
},
{
token: "4914-9088-2814-3840", // Replace with your actual token value
redactionType: RedactionType.PLAIN_TEXT, // Redaction type
},
];
// Step 2: Create the DetokenizeRequest object with the tokens and redaction type
const detokenizeRequest: DetokenizeRequest = new DetokenizeRequest(
detokenizeData,
redactionType
);
// Step 3: Configure Detokenize Options
const detokenizeOptions: DetokenizeOptions = new DetokenizeOptions();
detokenizeOptions.setContinueOnError(true); // Continue even if some tokens cannot be detokenized
// Step 5: Perform Detokenization
const response: DetokenizeResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.detokenize(detokenizeRequest, detokenizeOptions);
// Handle Successful Response
console.log('Detokenization 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:', error);
}
}
`Sample response:
`typescript
DetokenizeResponse {
detokenizedFields: [
{token: '9738-1683-0486-1480', value: '4111111111111115', type: 'STRING'},
{token: '6184-6357-8409-6668', value: '4111111111111119', type: 'STRING'}
],
errors: [
{
token: '4914-9088-2814-3840',
error: 'Token Not Found'
}
]
}
`$3
Tokenization replaces sensitive data with unique identifier tokens. This approach protects sensitive information by securely storing the original data while allowing the use of tokens within your application.
To tokenize data, use the
tokenize method. The TokenizeRequest class creates a tokenize request. In this request, you specify the values parameter, which is a list of column values objects. Each column value contains two properties: value and columnGroup.#### Construct a tokenize request
`typescript
import {
TokenizeRequest,
TokenizeResponse,
SkyflowError,
TokenizeRequestType
} from 'skyflow-node';try {
// Initialize Skyflow Client
// Step 1: Prepare Tokenization Data
const columnvalues: Array = [
{ value: "", columnGroup: "" }, // Replace and with actual data
{ value: "", columnGroup: "" } // Replace and with actual data
];
// Step 2: Build the TokenizeRequest with the column value2
const tokenReq: TokenizeRequest = new TokenizeRequest(columnvalues);
// Step 3: Call the Skyflow vault to tokenize the sensitive data
const response: TokenizeResponse = await skyflowClient
.vault("")
.tokenize(tokenReq);
// Replace with your actual Skyflow vault ID
// Step 4: Print the tokenization response, which contains the generated tokens or errors
console.log('Tokenization Result:', response);
} catch(error) {
// Step 5: Handle any errors that occur during the tokenization process
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);
}
}
`#### An example of Tokenize call
`typescript
import {
TokenizeRequest,
TokenizeResponse,
SkyflowError,
TokenizeRequestType
} from 'skyflow-node';/*
This example demonstrates how to tokenize sensitive data (e.g., credit card information) using the Skyflow client.
1. Initializes the Skyflow client.
2. Creates a column value for sensitive data (e.g., credit card number).
3. Builds a tokenize request with the column value to be tokenized.
4. Sends the request to the Skyflow vault for tokenization.
5. Prints the tokenization response, which includes the token or errors.
*/
try {
// Initialize Skyflow Client
// Step 1: Prepare Tokenization Data
const columnvalues: Array = [
{ value: "4111111111111111", columnGroup: "card_number_cg" }
];
// Step 2: Build the TokenizeRequest with the column value2
const tokenReq: TokenizeRequest = new TokenizeRequest(columnvalues);
// Step 3: Call the Skyflow vault to tokenize the sensitive data
const response: TokenizeResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.tokenize(tokenReq);
// Replace primaryVaultConfig.vaultId with your actual Skyflow vault ID
// Step 4: Print the tokenization response, which contains the generated tokens or errors
console.log('Tokenization Result:', response);
} catch(error) {
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);
}
}
`Sample response:
`typescript
TokenizeResponse {
tokens: [
{
token: '5479-4229-4622-1393'
}
],
errors: null
}
`$3
To retrieve data using Skyflow IDs or unique column values, use the get method. The
GetRequest class creates a get request, where you specify parameters such as the table name, redaction type, Skyflow IDs, column names, column values. If you specify Skyflow IDs, you can't use column names and column values, and the inverse is true—if you specify column names and column values, you can't use Skyflow IDs. And GetOptions class creates a get options object through which you specify whether to return tokens or not.#### Construct a get request
`typescript
import {
GetOptions,
GetRequest,
GetColumnRequest,
SkyflowError,
GetResponse
} from 'skyflow-node';try {
// Initialize Skyflow client
// Step 1: Initialize a list of Skyflow IDs to retrieve records (replace with actual Skyflow IDs)
const getIds: Array = ['', ''];
// Step 2: Create a GetRequest to retrieve records by Skyflow ID
const getRequest: GetRequest = new GetRequest(
'table1', // Replace with your actual table name
getIds
);
// Step 3: Configure Get Options and specify not to return tokens
const getOptions: GetOptions = new GetOptions();
getOptions.setReturnTokens(false); // Optional: Set to false to avoid returning tokens
// Step 4: Send the request to the Skyflow vault and retrieve the records
const getResponse: GetResponse = await skyflowClient
.vault('')
.get(getRequest, getOptions);
// Replace with your actual Skyflow vault ID
console.log('Data retrieval successful:', getResponse);
// Step 5: Create another GetRequest to retrieve records by Skyflow ID with tokenized values
const getTokensRequest: GetRequest = new GetRequest(
'table1', // Replace with your actual table name
getIds
);
// Step 6: Configure Get Options and specify to return tokens
const getOptions: GetOptions = new GetOptions();
getOptions.setReturnTokens(true); // Optional: Set to True to return tokenized values
// Step 7: Send the request to the Skyflow vault and retrieve the tokenized records
const getTokensResponse: GetResponse = await skyflowClient
.vault('')
.get(getRequest, getOptions);
// Replace with your actual Skyflow vault ID
console.log('Data retrieval successful:', getTokensResponse);
// Prepare Column-Based Retrieval Data
const columnValues: Array = [
'', // Example Unique Column value 1
'', // Example Unique Column value 2
];
const tableName: string = 'table-name'; // Replace with your actual table name
const columnName: string = 'column-name'; // Column name configured as unique in the schema
const getRequest: GetColumnRequest = new GetColumnRequest(
tableName,
columnName,
columnValues // Column values of the records to return
);
// Step 8: Configure Get Options and specify to return tokens
const getOptions: GetOptions = new GetOptions();
getOptions.setReturnTokens(true); // Optional: Set to True to return tokenized values
// Send the request to the Skyflow vault and retrieve the filtered records
const response: GetResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.get(getRequest, getOptions);
console.log('Column-based retrieval successful:', response);
} catch(error) {
// Handle any errors that occur during the retrieval process
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);
}
}
`#### Get by skyflow IDs
Retrieve specific records using skyflow
ids. Ideal for fetching exact records when IDs are known.`typescript
import {
GetOptions,
GetRequest,
SkyflowError,
GetResponse,
RedactionType
} from 'skyflow-node';/*
This example demonstrates how to retrieve data from the Skyflow vault using a list of Skyflow IDs.
1. Initializes the Skyflow client with a given vault ID.
2. Creates a request to retrieve records based on Skyflow IDs.
3. Specifies that the response should not return tokens.
4. Uses plain text redaction type for the retrieved records.
5. Prints the response to display the retrieved records.
*/
try {
// Initialize Skyflow client
// Step 1: Initialize a list of Skyflow IDs to retrieve records (replace with actual Skyflow IDs)
const getIds: Array = ['a581d205-1969-4350-acbe-a2a13eb871a6', '5ff887c3-b334-4294-9acc-70e78ae5164a'];
// Step 2: Create a GetRequest to retrieve records by Skyflow ID
const getRequest: GetRequest = new GetRequest(
'table1', // Replace with your actual table name
getIds
);
// Step 3: Configure Get Options and specify not to return tokens and redaction type
const getOptions: GetOptions = new GetOptions();
getOptions.setReturnTokens(false); // Optional: Set to false to avoid returning tokens
getOptions.setRedactionType(RedactionType.PLAIN_TEXT);
// Step 4: Send the request to the Skyflow vault and retrieve the records
const getResponse: GetResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.get(getRequest, getOptions);
// Replace with your actual Skyflow vault ID
console.log('Data retrieval successful:', getResponse);
} catch(error) {
// Step 5: Handle any errors that occur during the retrieval process
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);
}
}
`Sample response:
`typescript
GetResponse {
data: [
{
card_number: '4555555555555553',
email: 'john.doe@gmail.com',
name: 'john doe',
skyflow_id: 'a581d205-1969-4350-acbe-a2a13eb871a6'
},
{
card_number: '4555555555555559',
email: 'jane.doe@gmail.com',
name: 'jane doe',
skyflow_id: '5ff887c3-b334-4294-9acc-70e78ae5164a'
}
],
errors: null
}
`#### Get tokens
Return tokens for records. Ideal for securely processing sensitive data while maintaining data privacy.
#### An example of get call to retrieve tokens using Skyflow IDs:
`typescript
import {
GetOptions,
GetRequest,
SkyflowError,
GetResponse,
RedactionType
} from 'skyflow-node';/*
This example demonstrates how to retrieve data from the Skyflow vault and return tokens along with the records.
1. Initializes the Skyflow client with a given vault ID.
2. Creates a request to retrieve records based on Skyflow IDs and ensures tokens are returned.
3. Prints the response to display the retrieved records along with the tokens.
*/
try {
// Initialize Skyflow client
// Step 1: Initialize a list of Skyflow IDs to retrieve records (replace with actual Skyflow IDs)
const getIds: Array = ['a581d205-1969-4350-acbe-a2a13eb871a6', '5ff887c3-b334-4294-9acc-70e78ae5164a'];
// Step 2: Create a GetRequest to retrieve records by Skyflow ID
const getRequest: GetRequest = new GetRequest(
'table1', // Replace with your actual table name
getIds
);
// Step 3: Configure Get Options and specify not to return tokens and redaction type
const getOptions: GetOptions = new GetOptions();
getOptions.setReturnTokens(false); // Optional: Set to true to get tokens
// Step 4: Send the request to the Skyflow vault and retrieve the records
const getResponse: GetResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.get(getRequest, getOptions);
// Replace with your actual Skyflow vault ID
console.log('Data retrieval successful:', getResponse);
} catch(error) {
// Step 5: Handle any errors that occur during the retrieval process
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);
}
}
`Sample response:
`typescript
GetResponse {
data: [
{
card_number: '3998-2139-0328-0697',
email: 'c9a6c9555060@82c092e7.bd52',
name: '82c092e7-74c0-4e60-bd52-c9a6c9555060',
skyflow_id: 'a581d205-1969-4350-acbe-a2a13eb871a6'
},
{
card_number: '3562-0140-8820-7499',
email: '6174366e2bc6@59f82e89.93fc',
name: '59f82e89-138e-4f9b-93fc-6174366e2bc6',
skyflow_id: '5ff887c3-b334-4294-9acc-70e78ae5164a'
}
],
errors: null
}
`#### Get by column name and column values
Retrieve records by unique column values. Ideal for querying data without knowing Skyflow IDs, using alternate unique identifiers.
#### An example of get call to retrieve data using column name and column values:
`typescript
import {
GetOptions,
GetRequest,
SkyflowError,
GetResponse,
RedactionType,
GetColumnRequest
} from 'skyflow-node';/*
This example demonstrates how to retrieve data from the Skyflow vault based on column values.
1. Initializes the Skyflow client with a given vault ID.
2. Creates a request to retrieve records based on specific column values (e.g., email addresses).
3. Prints the response to display the retrieved records after redacting sensitive data based on the specified redaction type.
*/
try {
// Initialize Skyflow client
// Step 1: Initialize a list of column values (email addresses in this case)
const columnValues: Array = [
'john.doe@gmail.com', // Example email address
'jane.doe@gmail.com' , // Example email address
];
const tableName: string = 'table1'; // Replace with your actual table name
const columnName: string = 'email'; // Column name configured as unique in the schema
// Step 2: Create a GetRequest to retrieve records based on column values
const getRequest: GetColumnRequest = new GetColumnRequest(
tableName,
columnName,
columnValues // Column values of the records to return
);
// Step 3: Configure Get Options and specify redaction type
const getOptions: GetOptions = new GetOptions();
getOptions.setRedactionType(RedactionType.PLAIN_TEXT); // Optional: Set the redaction type (e.g., PLAIN_TEXT)
// Step 4: Send the request to the Skyflow vault and retrieve the filtered records
const response: GetResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.get(getRequest, getOptions);
console.log('Column-based retrieval successful:', response);
} catch(error) {
// Step 5: Handle any errors that occur during the retrieval process
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);
}
}
`Sample response:
`typescript
GetResponse {
data: [
{
card_number: '4555555555555553',
email: 'john.doe@gmail.com',
name: 'john doe',
skyflow_id: 'a581d205-1969-4350-acbe-a2a13eb871a6'
},
{
card_number: '4555555555555559',
email: 'jane.doe@gmail.com',
name: 'jane doe',
skyflow_id: '5ff887c3-b334-4294-9acc-70e78ae5164a'
}
],
errors: null
}
`#### Redaction Types
Redaction types determine how sensitive data is displayed when retrieved from the vault.
Available Redaction Types
-
DEFAULT: Applies the vault-configured default redaction setting.
- REDACTED: Completely removes sensitive data from view.
- MASKED: Partially obscures sensitive information.
- PLAIN_TEXT: Displays the full, unmasked data.Choosing the Right Redaction Type
- Use
REDACTED for scenarios requiring maximum data protection to prevent exposure of sensitive information.
- Use MASKED to provide partial visibility of sensitive data for less critical use cases.
- Use PLAIN_TEXT for internal, authorized access where full data visibility is necessary.$3
To update data in your vault, use the
update method. The UpdateRequest class is used to create an update request, where you specify parameters such as the table name, data (as a dictionary). The UpdateOptions class is used to configure update options to returnTokens, tokens, and tokenMode. If returnTokens is set to True, Skyflow returns tokens for the updated records. If returnTokens is set to False, Skyflow returns IDs for the updated records.#### Construct an update request
`typescript
import {
UpdateRequest,
UpdateOptions,
UpdateResponse,
SkyflowError,
TokenMode
} from 'skyflow-node';// This example demonstrates how to update records in the Skyflow vault by providing new data and/or tokenized values, along with the corresponding UpdateRequest schema.
try {
// Initialize Skyflow client
// Step 1: Prepare the data to update in the vault
// Use a dictionary to store the data that will be updated in the specified table
const updateData: Record = {
skyflowId: 'your-skyflow-id', // Skyflow ID for identifying the record to update
COLUMN_NAME1: '' //Example of a column name and its value to update
COLUMN_NAME2: ''// Another example of a column name and its value to update
};
// Step 2: Prepare the tokens (if necessary) for certain columns that require tokenization
const tokens: Record = {
COLUMN_NAME_2: '' // Example of a column name that should be tokenized
}
// Step 3: Create an UpdateRequest to specify the update operation
const updateReq: UpdateRequest = new UpdateRequest(
'sensitive_data_table', // Replace with your actual table name
updateData
);
// Step 4: Configure Update Options
const updateOptions: UpdateOptions = new UpdateOptions();
updateOptions.setReturnTokens(true); // Specify whether to return tokens in the response
updateOptions.setTokens(tokens); // The tokens associated with specific columns
updateOptions.setTokenMode(TokenMode.ENABLE); // Specifies the tokenization mode (ENABLE means tokenization is applied)
// Step 5: Send the request to the Skyflow vault and update the record
const response: UpdateResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.update(updateReq, updateOptions);
// Step 6: Print the response to confirm the update result
console.log('Update successful:', response);
} catch(error) {
// Step 7: Handle any errors that occur during the update operation
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);
}
}
`#### An example of update call
`typescript
import {
UpdateRequest,
UpdateOptions,
UpdateResponse,
SkyflowError,
TokenMode
} from 'skyflow-node';/*
This example demonstrates how to update a record in the Skyflow vault with specified data and tokens.
1. Initializes the Skyflow client with a given vault ID.
2. Constructs an update request with data to modify and tokens to include.
3. Sends the request to update the record in the vault.
4. Prints the response to confirm the success or failure of the update operation.
*/
try {
// Initialize Skyflow client
// Step 1: Prepare the data to update in the vault
// Use a dictionary to store the data that will be updated in the specified table
const updateData: Record = {
skyflowId: '5b699e2c-4301-4f9f-bcff-0a8fd3057413', // Skyflow ID for identifying the record to update
name: 'john doe' //Example of a column name and its value to update
card_number: '4111111111111115'// Another example of a column name and its value to update
};
// Step 2: Prepare the tokens (if necessary) for certain columns that require tokenization
const tokens: Record = {
name: '72b8ffe3-c8d3-4b4f-8052-38b2a7405b5a' // Example of a column name that should be tokenized
}
// Step 3: Create an UpdateRequest to specify the update operation
const updateReq: UpdateRequest = new UpdateRequest(
'table1', // Replace with your actual table name
updateData
);
// Step 4: Configure Update Options
const updateOptions: UpdateOptions = new UpdateOptions();
updateOptions.setTokens(tokens); // The tokens associated with specific columns
updateOptions.setTokenMode(TokenMode.ENABLE); // Specifies the tokenization mode (ENABLE means tokenization is applied)
// Step 5: Send the request to the Skyflow vault and update the record
const response: UpdateResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.update(updateReq, updateOptions);
// Step 6: Print the response to confirm the update result
console.log('Update successful:', response);
} catch(error) {
// Step 7: Handle any errors that occur during the update operation
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);
}
}
`Sample response:
- When
returnTokens is set to True
`typescript
UpdateResponse {
updatedField: {
skyflowId: '5b699e2c-4301-4f9f-bcff-0a8fd3057413',
name: '72b8ffe3-c8d3-4b4f-8052-38b2a7405b5a',
card_number: '4131-1751-0217-8491'
},
errors: null
}
`- When
returnTokens is set to False
`typescript
UpdateResponse {
updatedField: {
skyflowId: '5b699e2c-4301-4f9f-bcff-0a8fd3057413',
},
errors: null
}
`$3
To delete records using Skyflow IDs, use the
delete method. The DeleteRequest class accepts a list of Skyflow IDs that you want to delete, as shown below:#### Construct a delete request
`typescript
import {
DeleteRequest,
DeleteResponse,
SkyflowError
} from 'skyflow-node';/*
This example demonstrates how to delete records from a Skyflow vault using specified Skyflow IDs, along with corresponding DeleteRequest schema.
*/
try {
// Initialize Skyflow client
// Step 1: Prepare a list of Skyflow IDs for the records to delete
// The list stores the Skyflow IDs of the records that need to be deleted from the vault
const deleteIds: Array = ['', '', '']; // Replace with actual Skyflow IDs
const tableName: string = ''; // Replace with the actual table name from which to delete
// Step 2: Create a DeleteRequest to define the delete operation
const deleteRequest: DeleteRequest = new DeleteRequest(
tableName,
deleteIds
);
// Step 3: Send the delete request to the Skyflow vault
const response: DeleteResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.delete(deleteRequest);
// Print the response to confirm the delete result
console.log('Deletion successful:', response);
} catch(error) {
// Step 4: Handle any exceptions that occur during the delete operation
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);
}
}
`
#### An example of delete call`typescript
import {
DeleteRequest,
DeleteResponse,
SkyflowError
} from 'skyflow-node';/*
This example demonstrates how to delete records from a Skyflow vault using specified Skyflow IDs.
1. Initializes the Skyflow client with a given Vault ID.
2. Constructs a delete request by specifying the IDs of the records to delete.
3. Sends the delete request to the Skyflow vault to delete the specified records.
4. Prints the response to confirm the success or failure of the delete operation.
*/
try {
// Initialize Skyflow client
// Step 1: Prepare a list of Skyflow IDs for the records to delete
// The list stores the Skyflow IDs of the records that need to be deleted from the vault
const deleteIds: Array = ['9cbf66df-6357-48f3-b77b-0f1acbb69280', 'ea74bef4-f27e-46fe-b6a0-a28e91b4477b', '47700796-6d3b-4b54-9153-3973e281cafb']; // Replace with actual Skyflow IDs
const tableName: string = 'table1'; // Replace with the actual table name from which to delete
// Step 2: Create a DeleteRequest to define the delete operation
const deleteRequest: DeleteRequest = new DeleteRequest(
tableName,
deleteIds
);
// Step 3: Send the delete request to the Skyflow vault
const response: DeleteResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.delete(deleteRequest);
// Print the response to confirm the delete result
console.log('Deletion successful:', response);
} catch(error) {
// Step 4: Handle any exceptions that occur during the delete operation
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);
}
}
`Sample response:
`typescript
DeleteResponse {
deletedIds: [
'9cbf66df-6357-48f3-b77b-0f1acbb69280',
'ea74bef4-f27e-46fe-b6a0-a28e91b4477b',
'47700796-6d3b-4b54-9153-3973e281cafb'
],
errors: null
}
`$3
To retrieve data with SQL queries, use the
query method. QueryRequest is class that takes the query parameter as follows:#### Construct a query request
Refer to Query your data and Execute Query for guidelines and restrictions on supported SQL statements, operators, and keywords.
`typescript
import {
QueryRequest,
QueryResponse,
SkyflowError,
} from 'skyflow-node';/*
This example demonstrates how to execute a custom SQL query on a Skyflow vault, along with QueryRequest schema.
*/
try {
// Initialize Skyflow client
// Step 1: Define the SQL query to execute on the Skyflow vault
// Replace "" with the actual SQL query you want to run
const query: string = ""; // Example: "SELECT * FROM table1 WHERE column1 = 'value'"
// Step 2: Create a QueryRequest with the specified SQL query
const queryRequest: QueryRequest = new QueryRequest(query);
// Step 3: Execute the query request on the specified Skyflow vault
const response: QueryResponse = await skyflowClient
.vault('') // Replace with your actual Vault ID
.query(queryRequest);
// Step 4: Print the response containing the query results
console.log('Query Result:', response);
} catch(error) {
// Step 5: Handle any exceptions that occur during the query execution
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);
}
}
`#### An example of query call
`typescript
import {
QueryRequest,
QueryResponse,
SkyflowError,
} from 'skyflow-node';/*
This example demonstrates how to execute a SQL query on a Skyflow vault to retrieve data.
1. Initializes the Skyflow client with the Vault ID.
2. Constructs a query request with a specified SQL query.
3. Executes the query against the Skyflow vault.
4. Prints the response from the query execution.
*/
try {
// Initialize Skyflow client
// Step 1: Define the SQL query to execute on the Skyflow vault
// Example query: Retrieve all records from the "cards" table with a specific skyflow_id
const query: string = "SELECT * FROM cards WHERE skyflow_id='3ea3861-x107-40w8-la98-106sp08ea83f'";
// Step 2: Create a QueryRequest with the specified SQL query
const queryRequest: QueryRequest = new QueryRequest(query);
// Step 3: Execute the query request on the specified Skyflow vault
const response: QueryResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId) // Replace with actual Vault ID
.query(queryRequest);
// Step 4: Print the response containing the query results
console.log('Query Result:', response);
} catch(error) {
// Step 5: Handle any exceptions that occur during the query execution
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);
}
}
`Sample Response:
`typescript
QueryResponse {
fields: [
{
card_number: 'XXXXXXXXXXXX1112',
name: 'S*ar',
skyflow_id: '3ea3861-x107-40w8-la98-106sp08ea83f',
tokenizedData: {}
}
],
errors: null,
}
`$3
To upload files to a Skyflow vault, use the
uploadFile method. The FileUploadRequest class accepts parameters such as the table name, column name and skyflow ID. And FileUploadOptions class accepts the file object as shown below:``typescript