Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

Skyflow Node SDK with Deno

This project demonstrates how to use the Skyflow Node SDK in a Deno project using Deno's native NPM support.

Table of Contents

🧰 Prerequisites

Required Dependencies

  • Deno version 2.3.5 or higher
  • A Skyflow account (Sign up at Try Skyflow)
  • React 17.x or above

Installing Deno

Choose one of these installation methods:

Using npm (requires Node.js):

npm install -g deno

Using Shell (macOS and Linux):

curl -fsSL https://deno.land/x/install/install.sh | sh

Using Homebrew (macOS):

brew install deno

Using PowerShell (Windows):

irm https://deno.land/install.ps1 | iex

Verify Installation:

deno --version

Upgrading Deno:

deno upgrade

Create the vault

  1. In a browser, navigate to Skyflow Studio.
  2. Create a vault by clicking Add Vault > Start With a Template > Quickstart vault.
  3. Once the vault is created, click the gear icon and select Vault Details.
  4. Note your Vault URL and Vault ID values. You'll need these later.

Create a service account

  1. In the side navigation click, Access > Service Accounts > Add Service Account.
  2. For Name, enter "SDK Samples". For Roles, choose Vault Editor.
  3. Click Create. Your browser downloads a credentials.json file. Keep this file secure. You'll need it for each of the samples.

🚀 Getting Started

1. Create a new Deno project

deno init skyflow-deno
cd skyflow-deno

2. Configure deno.json

Update 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"
  }
}

3. Install Skyflow SDK

Use Deno’s built-in NPM support to add the SDK:

deno add npm:skyflow-node

4. Configure environment variables

  • 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

5. Create main.ts

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();

6. Run the Project

deno task start

Or directly:

deno run --allow-net main.ts

📦 Resources

About

This project demonstrates how to use the Skyflow Node SDK in a Deno project using Deno's native NPM support.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors