This project demonstrates how to use the Skyflow Node SDK in a Deno project using Deno's native NPM support.
- Deno version 2.3.5 or higher
- A Skyflow account (Sign up at Try Skyflow)
- React 17.x or above
Choose one of these installation methods:
npm install -g denocurl -fsSL https://deno.land/x/install/install.sh | shbrew install denoirm https://deno.land/install.ps1 | iexdeno --versiondeno upgrade- In a browser, navigate to Skyflow Studio.
- Create a vault by clicking Add Vault > Start With a Template > Quickstart vault.
- Once the vault is created, click the gear icon and select Vault Details.
- Note your Vault URL and Vault ID values. You'll need these later.
- In the side navigation click, Access > Service Accounts > Add Service Account.
- For Name, enter "SDK Samples". For Roles, choose Vault Editor.
- Click Create. Your browser downloads a credentials.json file. Keep this file secure. You'll need it for each of the samples.
deno init skyflow-deno
cd skyflow-denoUpdate deno.json to enable npm support and add the skyflow-node import map:
{
"compilerOptions": {
"lib": ["deno.ns", "deno.unstable"]
},
"imports": {
"skyflow": "npm:skyflow-node"
},
"tasks": {
"start": "deno run --allow-net main.ts"
}
}Use Deno’s built-in NPM support to add the SDK:
deno add npm:skyflow-node- Create .env if doesn't exist in project directory
touch .env
- Update the environment variables:
- Replace
<VAULT_ID>,<CLUSTER_ID>, and<SKYFLOW_API_KEY>with the actual values.
echo VAULT_ID=<VAULT_ID> CLUSTER_ID=<CLUSTER_ID> SKYFLOW_API_KEY=<SKYFLOW_API_KEY> >.env
- Replace
You can create your own file or copy a sample from the Skyflow Node SDK samples folder, such as insert-record.js, and adapt it for Deno.
Example:
import {
Credentials,
Env,
InsertOptions,
InsertRequest,
LogLevel,
Skyflow,
VaultConfig,
SkyflowConfig,
SkyflowError,
InsertResponse,
ApiKeyCredentials,
InsertResponseType
} from 'skyflow-node';
// Skyflow Secure Data Insertion Example
async function performSecureDataInsertion() {
try {
// Step 1: Configure Credentials
const credentials: Credentials = {
// Using API Key authentication
apiKey: process.env.SKYFLOW_API_KEY || '',
};
// Step 2: Configure Vault
const primaryVaultConfig: VaultConfig = {
vaultId: process.env.VAULT_ID || '', // Unique vault identifier
clusterId: process.env.CLUSTER_ID || '', // From vault URL
env: Env.PROD, // Deployment environment
credentials: credentials // Authentication method
};
// Step 3: Configure Skyflow Client
const skyflowConfig: SkyflowConfig = {
vaultConfigs: [primaryVaultConfig],
logLevel: LogLevel.INFO // Logging verbosity
};
// Initialize Skyflow Client
const skyflowClient: Skyflow = new Skyflow(skyflowConfig);
// Step 4: Prepare Insertion Data
const insertData: Record<string, unknown>[] = [
{ card_number: '4111111111111112' } // Example sensitive data
];
// Step 5: Create Insert Request
const insertReq: InsertRequest = new InsertRequest(
'sensitive_data_table', // Replace with your actual table name
insertData
);
// Step 6: Configure Insertion Options
const insertOptions: 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: InsertResponse = await skyflowClient
.vault(primaryVaultConfig.vaultId)
.insert(insertReq, insertOptions);
// Handle Successful Response
if(response.insertedFields!=null) {
for(let i = 0; i < response.insertedFields.length; i++) {
const field: InsertResponseType = response.insertedFields[i];
console.log('Inserted Field: ',field);
// Handle filed
}
}
} 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();deno task startOr directly:
deno run --allow-net main.ts