This repository contains a sample project demonstrating how to use the Skyflow Node SDK within a Cloudflare Worker. The project includes functionality for deidentifying sensitive information in files and text, as well as uploading files to a Skyflow vault.
- Prerequisites
- Installation
- Create the vault
- Configuration
- Running the Project
- API Endpoints
- Samples
- Resources
Before you begin, ensure you have met the following requirements:
- Node.js (version 14 or later)
- Skyflow account with access to the Skyflow Node SDK
-
Clone the repository:
git clone https://github.com/SkyflowFoundry/cloudflare_worker_samples.git cd cloudflare_worker_samples -
Install the dependencies:
npm install
- 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.
- Add your environment variables in the
wrangler.jsoncfile under theenvsection. These will store yourVAULT_ID,CLUSTER_IDandCREDENTIALS. For example:
{
"name": "cloudflare-worker-sample", // Environment-specific configurations
"env": {
"dev": { // Development environment configuration
"vars": {
"VAULT_ID": "<VAULT_ID>", // Replace with your actual Skyflow Vault ID for development
"CLUSTER_ID": "<CLUSTER_ID>", // Replace with your actual Skyflow Cluster ID (e.g., "us1", "in1", etc.)
"CREDENTIALS": {} // Replace with your development service account credentials JSON object
}
},
"prod": { // Production environment configuration
"vars": {
"VAULT_ID": "<VAULT_ID>", // Replace with your actual Skyflow Vault ID for production
"CLUSTER_ID": "<CLUSTER_ID>", // Replace with your actual Skyflow Cluster ID
"CREDENTIALS": {} // Replace with your production service account credentials JSON object
}
}
}
}- Open the
index.tsfile located in thesrcdirectory. - Vault configuration initialisation:
const credentials: Credentials = {
credentialsString: JSON.stringify(env.CREDENTIALS), // Update the CREDENTIALS env variable in wrangler.jsonc
};
// Configure Vault
const primaryVaultConfig: VaultConfig = {
vaultId: env.VAULT_ID, // update the VAULT_ID env variable in wrangler.jsonc
clusterId: env.CLUSTER_ID, // update the CLUSTER_ID env variable in wrangler.jsonc
env: Env.DEV, // Deployment environment
credentials: credentials // Authentication method
};To run the Cloudflare Worker locally, follow these steps:
-
Install the Cloudflare Workers CLI (Wrangler):
npm install -g wrangler
-
You can test the worker locally using:
npm run dev
The following API endpoints are available in the Cloudflare Worker:
-
POST /saveFile: Uploads a file to the Skyflow vault.
- Request body: FormData containing the file.
-
POST /detectFile: Deidentifies sensitive information in a file.
- Request body: FormData containing the file.
-
POST /detectText: Deidentifies sensitive information in text.
- Request body: FormData containing the text.
- Refer to the below links for more working examples: