From 9ef2642486b82f0d179fd5df9a42b64908752822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Camith-skyflow=E2=80=9D?= <“amit@skyflow.com”> Date: Thu, 24 Oct 2024 15:07:48 +0530 Subject: [PATCH] SK-1621: add samples --- samples/package.json | 2 +- ....ts => scoped-token-generation-example.ts} | 0 ....ts => signed-token-generation-example.ts} | 0 ...Example.ts => token-generation-example.ts} | 0 ... token-generation-with-context-example.ts} | 0 samples/vault-api/.env | 1 + samples/vault-api/Delete.ts | 101 ++++++++------- samples/vault-api/Detokenize.ts | 66 ---------- samples/vault-api/Get.ts | 111 ++++++++--------- samples/vault-api/GetById.ts | 56 --------- samples/vault-api/Insert.ts | 115 +++++++++--------- .../vault-api/InsertWithContinueOnError.ts | 72 ----------- samples/vault-api/InvokeConnection.ts | 57 --------- samples/vault-api/Update.ts | 104 ++++++++-------- samples/vault-api/UpsertSupport.ts | 69 ----------- samples/vault-api/client-operations.ts | 68 +++++++++++ samples/vault-api/data-residency.ts | 78 ++++++++++++ samples/vault-api/detokenzie.ts | 59 +++++++++ samples/vault-api/file-upload.ts | 48 ++++++++ samples/vault-api/get-column-values.ts | 57 +++++++++ samples/vault-api/invoke.ts | 64 ++++++++++ samples/vault-api/query.ts | 47 +++++++ samples/vault-api/tokenize.ts | 52 ++++++++ 23 files changed, 684 insertions(+), 543 deletions(-) rename samples/service-account/{ScopedTokenGenerationExample.ts => scoped-token-generation-example.ts} (100%) rename samples/service-account/{SignedTokenGenerationExample.ts => signed-token-generation-example.ts} (100%) rename samples/service-account/{TokenGenerationExample.ts => token-generation-example.ts} (100%) rename samples/service-account/{TokenGenerationWithContextExample.ts => token-generation-with-context-example.ts} (100%) create mode 100644 samples/vault-api/.env delete mode 100644 samples/vault-api/Detokenize.ts delete mode 100644 samples/vault-api/GetById.ts delete mode 100644 samples/vault-api/InsertWithContinueOnError.ts delete mode 100644 samples/vault-api/InvokeConnection.ts delete mode 100644 samples/vault-api/UpsertSupport.ts create mode 100644 samples/vault-api/client-operations.ts create mode 100644 samples/vault-api/data-residency.ts create mode 100644 samples/vault-api/detokenzie.ts create mode 100644 samples/vault-api/file-upload.ts create mode 100644 samples/vault-api/get-column-values.ts create mode 100644 samples/vault-api/invoke.ts create mode 100644 samples/vault-api/query.ts create mode 100644 samples/vault-api/tokenize.ts diff --git a/samples/package.json b/samples/package.json index f796ac2..3dd8ce0 100644 --- a/samples/package.json +++ b/samples/package.json @@ -9,6 +9,6 @@ "author": "", "license": "ISC", "dependencies": { - "skyflow-node": "^1.13.0" + "skyflow-node": "1.14.0-dev.c0f4b46" } } diff --git a/samples/service-account/ScopedTokenGenerationExample.ts b/samples/service-account/scoped-token-generation-example.ts similarity index 100% rename from samples/service-account/ScopedTokenGenerationExample.ts rename to samples/service-account/scoped-token-generation-example.ts diff --git a/samples/service-account/SignedTokenGenerationExample.ts b/samples/service-account/signed-token-generation-example.ts similarity index 100% rename from samples/service-account/SignedTokenGenerationExample.ts rename to samples/service-account/signed-token-generation-example.ts diff --git a/samples/service-account/TokenGenerationExample.ts b/samples/service-account/token-generation-example.ts similarity index 100% rename from samples/service-account/TokenGenerationExample.ts rename to samples/service-account/token-generation-example.ts diff --git a/samples/service-account/TokenGenerationWithContextExample.ts b/samples/service-account/token-generation-with-context-example.ts similarity index 100% rename from samples/service-account/TokenGenerationWithContextExample.ts rename to samples/service-account/token-generation-with-context-example.ts diff --git a/samples/vault-api/.env b/samples/vault-api/.env new file mode 100644 index 0000000..fd8598f --- /dev/null +++ b/samples/vault-api/.env @@ -0,0 +1 @@ +SKYFLOW_CREDENTIALS={ clientID: '', clientName: '', keyID: '', tokenURI: '', privateKey: '', } \ No newline at end of file diff --git a/samples/vault-api/Delete.ts b/samples/vault-api/Delete.ts index 2d6068f..1b2073f 100644 --- a/samples/vault-api/Delete.ts +++ b/samples/vault-api/Delete.ts @@ -1,58 +1,53 @@ -/* - Copyright (c) 2023 Skyflow, Inc. -*/ -import { - Skyflow, - generateBearerToken, - isExpired, - setLogLevel, - LogLevel, -} from "skyflow-node"; +import { DeleteRequest, Env, LogLevel, Skyflow } from "skyflow-node"; -const filePath = ""; -setLogLevel(LogLevel.INFO); -let bearerToken = ""; +// To generate Bearer Token from credentials string. +const cred = { + clientID: '', + clientName: '', + keyID: '', + tokenURI: '', + privateKey: '', +}; -const skyflow = Skyflow.init({ - vaultID: "", - vaultURL: "", - getBearerToken: () => { - return new Promise((resolve, reject) => { - if (!isExpired(bearerToken)) { - resolve(bearerToken); - } else { - generateBearerToken(filePath) - .then((response) => { - bearerToken = response.accessToken; - resolve(bearerToken); - }) - .catch((err) => { - reject(err); - }); - } - }); - }, -}); +// please pass one of apiKey, token, credentialsString & path +const skyflowCredentials = { + credentialsString: JSON.stringify(cred) +} + +// please pass one of apiKey, token, credentialsString & path +const credentials = { + apiKey: "API_KEY", // Api Key +} -const result = skyflow.delete({ - records: [ - { - id: "", - table: "", - table: " { - console.log("delete result:"); - console.log(JSON.stringify(response)); - }) - .catch((error) => { - console.log("delete error: "); - console.log(JSON.stringify(error)); - }); +const deleteIds = [ + 'SKYFLOW_ID1', + 'SKYFLOW_ID2', + 'SKYFLOW_ID3', +] + +const deleteRequest = new DeleteRequest( + "TABLE_NAME", // TABLE_NAME + deleteIds +); + +// will return first Vault ID +skyflow_client.vault().delete( + deleteRequest +).then(resp=>{ + console.log(resp); +}).catch(err=>{ + console.log(JSON.stringify(err)); +}); \ No newline at end of file diff --git a/samples/vault-api/Detokenize.ts b/samples/vault-api/Detokenize.ts deleted file mode 100644 index b9328b5..0000000 --- a/samples/vault-api/Detokenize.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* - Copyright (c) 2022 Skyflow, Inc. -*/ -import { - Skyflow, - generateBearerToken, - isExpired, - setLogLevel, - LogLevel, -} from 'skyflow-node'; - -const filePath = ''; -setLogLevel(LogLevel.INFO); -let bearerToken = ''; - -const skyflow = Skyflow.init({ - vaultID: '', - vaultURL: '', - getBearerToken: () => { - return new Promise((resolve, reject) => { - if (!isExpired(bearerToken)) { - resolve(bearerToken); - } else { - generateBearerToken(filePath) - .then(response => { - bearerToken = response.accessToken; - resolve(bearerToken); - }) - .catch(error => { - reject(error); - }); - } - }); - }, -}); - -const result = skyflow.detokenize({ - records: [ - { - token: '', - redaction: Skyflow.RedactionType.DEFAULT // optional - }, - { - token: '', - redaction: Skyflow.RedactionType.MASKED // optional - }, - { - token: '', - redaction: Skyflow.RedactionType.REDACTED // optional - }, - { - token: '', - }, - ], -}); - -result - .then(response => { - console.log('detokenize result: '); - console.log(JSON.stringify(response)); - }) - .catch(error => { - console.log('detokenize error:'); - console.log(JSON.stringify(error)); - }); - \ No newline at end of file diff --git a/samples/vault-api/Get.ts b/samples/vault-api/Get.ts index c3cb346..312a71b 100644 --- a/samples/vault-api/Get.ts +++ b/samples/vault-api/Get.ts @@ -1,63 +1,56 @@ -/* - Copyright (c) 2022 Skyflow, Inc. -*/ -import { - Skyflow, - generateBearerToken, - isExpired, - setLogLevel, - LogLevel, -} from 'skyflow-node'; - -const filePath = ''; -setLogLevel(LogLevel.INFO); -let bearerToken = ''; - -const skyflow = Skyflow.init({ - vaultID: '', - vaultURL: '', - getBearerToken: () => { - return new Promise((resolve, reject) => { - if (!isExpired(bearerToken)) { - resolve(bearerToken); - } else { - generateBearerToken(filePath) - .then(response => { - bearerToken = response.accessToken; - resolve(bearerToken); - }) - .catch(err => { - reject(err); - }); - } - }); - }, -}); +import { Env, GetOptions, GetRequest, LogLevel, Skyflow } from "skyflow-node"; + +// To generate Bearer Token from credentials string. +const cred = { + clientID: '', + clientName: '', + keyID: '', + tokenURI: '', + privateKey: '', +}; + +// please pass one of apiKey, token, credentialsString & path +const skyflowCredentials = { + credentialsString: JSON.stringify(cred), +} + +// please pass one of apiKey, token, credentialsString & path +const credentials = { + path: "PATH_TO_CREDENTIALS_JSON", // bearer token +} -const result = skyflow.get({ - records: [ - // To to get records using skyflow_ids. - { - ids: ['', ''], - redaction: Skyflow.RedactionType.PLAIN_TEXT, - table: 'cards', - }, - // To get records using unique column name and values. - { - redaction : Skyflow.RedactionType.PLAIN_TEXT, - table: 'persons', - columnName: 'card_id', - columnValues: ['123', '456'], - } - ], +const skyflow_client = new Skyflow({ + vaultConfigs: [ + { + vaultId: "VAULT_ID", // primary vault + clusterId: "CLUSTER_ID", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + env: Env.PROD, // Env by deault it is set to PROD + credentials: credentials // indiviudal credentails + } + ], + skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed + logLevel:LogLevel.ERROR // set loglevel by deault it is set to PROD }); -result - .then(response => { - console.log('get result:'); - console.log(JSON.stringify(response)); - }) - .catch(error => { - console.log('get error: '); +const getIds = [ + 'SKYFLOW_ID1', + 'SKYFLOW_ID2', +] + +const getRequest = new GetRequest( + "TABLE_NAME", + getIds +) + +const getOptions = new GetOptions() +//use setters of setting options refer to skyflow docs for more options +getOptions.setReturnTokens(true); + +skyflow_client.vault("VAULT_ID").get( + getRequest, + getOptions +).then(response => { + console.log(response); +}).catch(error => { console.log(JSON.stringify(error)); - }); +}); diff --git a/samples/vault-api/GetById.ts b/samples/vault-api/GetById.ts deleted file mode 100644 index 1fd97d4..0000000 --- a/samples/vault-api/GetById.ts +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright (c) 2022 Skyflow, Inc. -*/ -import { - Skyflow, - generateBearerToken, - isExpired, - setLogLevel, - LogLevel, -} from 'skyflow-node'; - -const filePath = ''; -setLogLevel(LogLevel.INFO); -let bearerToken = ''; - -const skyflow = Skyflow.init({ - vaultID: '', - vaultURL: '', - getBearerToken: () => { - return new Promise((resolve, reject) => { - if (!isExpired(bearerToken)) { - resolve(bearerToken); - } else { - generateBearerToken(filePath) - .then(response => { - bearerToken = response.accessToken; - resolve(bearerToken); - }) - .catch(err => { - reject(err); - }); - } - }); - }, -}); - -const result = skyflow.getById({ - records: [ - // To to get records using skyflow_ids. - { - ids: ['', ''], - redaction: Skyflow.RedactionType.PLAIN_TEXT, - table: 'cards', - }, - ], -}); - -result - .then(response => { - console.log('getByID result:'); - console.log(JSON.stringify(response)); - }) - .catch(error => { - console.log('getByID error: '); - console.log(JSON.stringify(error)); - }); \ No newline at end of file diff --git a/samples/vault-api/Insert.ts b/samples/vault-api/Insert.ts index 0d4c84c..ebaf497 100644 --- a/samples/vault-api/Insert.ts +++ b/samples/vault-api/Insert.ts @@ -1,61 +1,58 @@ -/* - Copyright (c) 2022 Skyflow, Inc. -*/ -import { - Skyflow, - generateBearerToken, - isExpired, - setLogLevel, - LogLevel, -} from 'skyflow-node'; - -const filePath = ''; -setLogLevel(LogLevel.INFO); -let bearerToken = ''; - -const skyflow = Skyflow.init({ - vaultID: '', - vaultURL: '', - getBearerToken: () => { - return new Promise((resolve, reject) => { - if (!isExpired(bearerToken)) { - resolve(bearerToken); - } else { - generateBearerToken(filePath) - .then(response => { - bearerToken = response.accessToken; - resolve(bearerToken); - }) - .catch(error => { - reject(error); - }); - } - }); - }, -}); +import { Env, InsertOptions, InsertRequest, LogLevel, Skyflow } from "skyflow-node"; + +// To generate Bearer Token from credentials string. +const cred = { + clientID: '', + clientName: '', + keyID: '', + tokenURI: '', + privateKey: '', +}; + +// please pass one of apiKey, token, credentialsString & path +const skyflowCredentials = { + credentialsString: JSON.stringify(cred), +} -const result = skyflow.insert( - { - records: [ - { - fields: { - card_number: '411111111111111', - expiry_date: '11/22', - fullname: 'firstNameTest', - }, - table: 'cards', - }, +// please pass one of apiKey, token, credentialsString & path +const credentials = { + apiKey: "API_KEY", // bearer token +} + +const skyflow_client = new Skyflow({ + vaultConfigs: [ + { + vaultId: "VAULT_ID", // primary vault + clusterId: "CLUSTER_ID", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + env: Env.PROD, // Env by deault it is set to PROD + credentials: credentials // indiviudal credentails + } ], - }, - {tokens: true} -); - -result - .then(response => { - console.log('insert result:'); - console.log(JSON.stringify(response)); - }) - .catch(error => { - console.log('insert error:'); - console.log(JSON.stringify(error)); - }); + skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed + logLevel:LogLevel.ERROR // set loglevel by deault it is set to PROD +}); + +//sample data +const insertData = [ + { cardumber: '4111111111111111', cvv: '1234' }, + { cardumber: '42424242424242424', cvv: '321' }, +] + +const insertReq = new InsertRequest( + "TABLE_NAME", + insertData +) + +const 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 + +skyflow_client.vault("VAULT_ID").insert( + insertReq, + insertOptions +).then(resp=>{ + console.log(resp); +}).catch(err=>{ + console.log(JSON.stringify(err)); +}); \ No newline at end of file diff --git a/samples/vault-api/InsertWithContinueOnError.ts b/samples/vault-api/InsertWithContinueOnError.ts deleted file mode 100644 index 0dc2ac3..0000000 --- a/samples/vault-api/InsertWithContinueOnError.ts +++ /dev/null @@ -1,72 +0,0 @@ -/* - Copyright (c) 2024 Skyflow, Inc. -*/ -import { - Skyflow, - generateBearerToken, - isExpired, - setLogLevel, - LogLevel, -} from "skyflow-node"; - -setLogLevel(LogLevel.DEBUG); -let bearerToken = ""; -const filePath = ""; - -const skyflow = Skyflow.init({ - vaultID: "", - vaultURL: "", - getBearerToken: () => { - return new Promise((resolve, reject) => { - if (!isExpired(bearerToken)) { - resolve(bearerToken); - } else { - generateBearerToken(filePath) - .then((response) => { - bearerToken = response.accessToken; - resolve(bearerToken); - }) - .catch((error) => { - reject(error); - }); - } - }); - }, -}); - -const result = skyflow.insert( - { - records: [ - { - fields: { - expiry_date: "12/2026", - card_number: "411111111111111", - namee: "john doe", - }, - table: "cards", - }, - { - fields: { - expiry_date: "12/2027", - card_number: "411111111111111", - name: "jane doe", - }, - table: "cards", - }, - ], - }, - { - tokens: true, - continueOnError: true, - } -); - -result - .then((response) => { - console.log("insert result:"); - console.log(JSON.stringify(response)); - }) - .catch((error) => { - console.log("insert error:"); - console.log(JSON.stringify(error)); - }); diff --git a/samples/vault-api/InvokeConnection.ts b/samples/vault-api/InvokeConnection.ts deleted file mode 100644 index 53097c1..0000000 --- a/samples/vault-api/InvokeConnection.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* - Copyright (c) 2022 Skyflow, Inc. -*/ -import { - Skyflow, - generateBearerToken, - isExpired, - setLogLevel, - LogLevel, -} from 'skyflow-node'; - -const filePath = ''; -setLogLevel(LogLevel.INFO); -let bearerToken = ''; - -const skyflow = Skyflow.init({ - vaultID: '', - vaultURL: '', - getBearerToken: () => { - return new Promise((resolve, reject) => { - if (!isExpired(bearerToken)) { - resolve(bearerToken); - } else { - generateBearerToken(filePath) - .then(response => { - bearerToken = response.accessToken; - resolve(bearerToken); - }) - .catch(err => { - reject(err); - }); - } - }); - }, -}); - -const result = skyflow.invokeConnection({ - connectionURL: '', - methodName: Skyflow.RequestMethod.POST, - requestHeader: { - Authorization: '', - }, - requestBody: { - expirationDate: { - mm: '01', - yy: '46', - }, - }, -}); - -result - .then(response => { - console.log(JSON.stringify(response)); - }) - .catch(error => { - console.log(JSON.stringify(error)); - }); diff --git a/samples/vault-api/Update.ts b/samples/vault-api/Update.ts index 26ebb6b..1c6a7b2 100644 --- a/samples/vault-api/Update.ts +++ b/samples/vault-api/Update.ts @@ -1,55 +1,57 @@ -/* - Copyright (c) 2022 Skyflow, Inc. -*/ -import {Skyflow, generateBearerToken, isExpired, setLogLevel, LogLevel} from 'skyflow-node'; -var filePath = ''; -setLogLevel(LogLevel.INFO) -var bearerToken = '' - -const skyflow = Skyflow.init({ - vaultID: '', - vaultURL: '', - getBearerToken: () => { - return new Promise((resolve, reject) => { - if(!isExpired(bearerToken)) { - resolve(bearerToken) - } - else { - generateBearerToken(filePath) - .then((res) => { - bearerToken = res.accessToken - resolve(bearerToken); - }) - .catch((err) => { - reject(err); - }); - } - }) - } -}); +import { Env, Skyflow, UpdateRequest, UpdateOptions, LogLevel } from "skyflow-node"; + +// To generate Bearer Token from credentials string. +const cred = { + clientID: '', + clientName: '', + keyID: '', + tokenURI: '', + privateKey: '', +}; + +// please pass one of apiKey, token, credentialsString & path +const skyflowCredentials = { + credentialsString: JSON.stringify(cred), +} +// please pass one of apiKey, token, credentialsString & path +const credentials = { + apiKey: "API_KEY", // bearer token +} -const result = skyflow.update( - { - records: [ - { - id : '', - table: '', - 'fields': { - '': '' +const skyflow_client = new Skyflow({ + vaultConfigs: [ + { + vaultId: "VAULT_ID", // primary vault + clusterId: "CLUSTER_ID", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + env: Env.PROD, // Env by deault it is set to PROD + credentials: credentials // indiviudal credentails } - } ], - }, - { - tokens: true, - } -); - -result.then((response)=>{ - console.log('Update result:'); - console.log(JSON.stringify(response)); -}).catch((error)=>{ - console.log('Update error:'); - console.log(JSON.stringify(error)); -}) \ No newline at end of file + skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed + logLevel:LogLevel.ERROR // set loglevel by deault it is set to PROD +}); + +// sample data +const updateData = { card_number: '12333333333333444444' }; + +const skyflowId = "SKYFLOW_ID"; + +const updateReq = new UpdateRequest( + "TABLE_NAME", + skyflowId, + updateData +) + +const updateOptions = new UpdateOptions() + +updateOptions.setReturnTokens(true); + +skyflow_client.vault("e796617671d742c6aeb69f5cc62acf26").update( + updateReq, + updateOptions +).then(resp=>{ + console.log(resp); +}).catch(err=>{ + console.log(JSON.stringify(err)); +}); \ No newline at end of file diff --git a/samples/vault-api/UpsertSupport.ts b/samples/vault-api/UpsertSupport.ts deleted file mode 100644 index f40bc1e..0000000 --- a/samples/vault-api/UpsertSupport.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* - Copyright (c) 2022 Skyflow, Inc. -*/ -import { - Skyflow, - generateBearerToken, - isExpired, - setLogLevel, - LogLevel, -} from 'skyflow-node'; - -const filePath = ''; -setLogLevel(LogLevel.INFO); -let bearerToken = ''; - -const skyflow = Skyflow.init({ - vaultID: '', - vaultURL: '', - getBearerToken: () => { - return new Promise((resolve, reject) => { - if (!isExpired(bearerToken)) { - resolve(bearerToken); - } else { - generateBearerToken(filePath) - .then(response => { - bearerToken = response.accessToken; - resolve(bearerToken); - }) - .catch(err => { - reject(err); - }); - } - }); - }, -}); - -const result = skyflow.insert( - { - records: [ - { - fields: { - card_number: '411111111111111', - expiry_date: '11/22', - fullname: 'firstNameTest', - }, - table: 'cards', - }, - ], - }, - { - tokens: true, - upsert: [ - { - table: 'cards', // Table. - column: 'card_number', // Unique column in the table. - }, - ], - } -); - -result - .then(response => { - console.log('insert result:'); - console.log(JSON.stringify(response)); - }) - .catch(error => { - console.log('insert error:'); - console.log(JSON.stringify(error)); - }); diff --git a/samples/vault-api/client-operations.ts b/samples/vault-api/client-operations.ts new file mode 100644 index 0000000..9215b91 --- /dev/null +++ b/samples/vault-api/client-operations.ts @@ -0,0 +1,68 @@ +import { DeleteRequest, Env, LogLevel, Skyflow } from "skyflow-node"; + +// To generate Bearer Token from credentials string. +const cred = { + clientID: '', + clientName: '', + keyID: '', + tokenURI: '', + privateKey: '', +}; + +// please pass one of apiKey, token, credentialsString & path +const skyflowCredentials = { + credentialsString: JSON.stringify(cred), +} + +// please pass one of apiKey, token, credentialsString & path +const credentials = { + token: "BEARER_TOKEN", // bearer token +} + +const skyflow_client = new Skyflow({ + vaultConfigs: [ + { + vaultId: "VAULT_ID1", // primary vault + clusterId: "CLUSTER_ID1", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + env: Env.PROD, // Env by deault it is set to PROD + credentials: credentials // indiviudal credentails + } + ], + skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed + logLevel:LogLevel.ERROR // set loglevel by deault it is set to PROD +}); + +//add vault config on the go +skyflow_client.addVaultConfig( + { + vaultId: "VAULT_ID2", // secondary vault + clusterId: "CLUSTER_ID2", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + env: Env.PROD, // Env by deault it is set to PROD + // if you dont specify individual creds, skyflow creds will be used + } +); + +//add vault config on the go +skyflow_client.updateVaultConfig( + { + 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 + } +); + +//perform operations +const deleteIds = [ + "SKYLFOW_ID1", + "SKYLFOW_ID1" +] + +const deleteRequest = new DeleteRequest( + "TABLE_NAME", + deleteIds +); + +//perform delete call if you dont specify valut() it will return the first valid vault +skyflow_client.vault("VALUT_ID2").delete(deleteRequest); + +skyflow_client.removeVaultConfig("VAULT_ID"); \ No newline at end of file diff --git a/samples/vault-api/data-residency.ts b/samples/vault-api/data-residency.ts new file mode 100644 index 0000000..2f1fc25 --- /dev/null +++ b/samples/vault-api/data-residency.ts @@ -0,0 +1,78 @@ +import { Env, GetRequest, GetResponse, InsertRequest, LogLevel, Skyflow } from "skyflow-node"; + +// To generate Bearer Token from credentials string. +const cred = { + clientID: '', + clientName: '', + keyID: '', + tokenURI: '', + privateKey: '', +}; + +// please pass one of apiKey, token, credentialsString & path +const skyflowCredentials = { + credentialsString: JSON.stringify(cred), +} + +// please pass one of apiKey, token, credentialsString & path +const credentials = { + token: "BEARER_TOKEN", // bearer token +} + +const skyflow_client = new Skyflow({ + vaultConfigs: [ + { + vaultId: "VAULT_ID1", // primary vault + clusterId: "CLUSTER_ID1", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + env: Env.PROD, // Env by deault it is set to PROD + credentials: credentials // indiviudal credentails + } + ], + skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed + logLevel:LogLevel.ERROR // set loglevel by deault it is set to PROD +}); + +//add vault config from Sandbox env +skyflow_client.addVaultConfig( + { + vaultId: "VAULT_ID2", // secondary vault + clusterId: "CLUSTER_ID2", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + env: Env.SANDBOX, // Env by deault it is set to PROD + // if you dont specify individual creds, skyflow creds will be used + } +); + +//perform operations +const getIds = [ + "SKYLFOW_ID1", + "SKYLFOW_ID1" +] + +const getRequest = new GetRequest( + "TABLE_NAME", + getIds +); + +//perform delete call if you dont specify valut() it will return the first valid vault +skyflow_client.vault("VALUT_ID1").get(getRequest) +.then(response=>{ + // + const getResponse: GetResponse = response as GetResponse; + console.log(getResponse.data); + + //get data from prod vault and insert data to SANDBOX vault + const insertRequest = new InsertRequest( + "TABLE_NAME", + getResponse.data!, + ); + skyflow_client.vault("VAULT_ID2").insert( + insertRequest + ).then(resp=>{ + console.log(resp); + }).catch(err=>{ + console.log(JSON.stringify(err)); + }); +}) +.catch(err=>{ + console.log(JSON.stringify(err)); +}); diff --git a/samples/vault-api/detokenzie.ts b/samples/vault-api/detokenzie.ts new file mode 100644 index 0000000..688b861 --- /dev/null +++ b/samples/vault-api/detokenzie.ts @@ -0,0 +1,59 @@ +import { DetokenizeOptions, DetokenizeRequest, Env, LogLevel, RedactionType, Skyflow } from "skyflow-node"; + +// To generate Bearer Token from credentials string. +const cred = { + clientID: '', + clientName: '', + keyID: '', + tokenURI: '', + privateKey: '', +}; + +// please pass one of apiKey, token, credentialsString & path +const skyflowCredentials = { + credentialsString: JSON.stringify(cred) +} + +// please pass one of apiKey, token, credentialsString & path +const credentials = { + token: "TOKEN", // bearer token +} + +const skyflow_client = new Skyflow({ + vaultConfigs: [ + { + vaultId: "VAULT_ID", // primary vault + clusterId: "CLUSTER_ID", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + env: Env.PROD, // Env by deault it is set to PROD + credentials: credentials // indiviudal credentails + } + ], + skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed + logLevel:LogLevel.ERROR // set loglevel by deault it is set to PROD +}); + +const detokenizeData = [ + 'TOKEN1', + 'TOKEN2', + 'TOKEN3' +] + +const detokenizeRequest = new DetokenizeRequest( + detokenizeData, + RedactionType.REDACTED +) + +const detokenizeOptions = new DetokenizeOptions() +// options can be set using setters +detokenizeOptions.setContinueOnError(true); + +detokenizeOptions.setDownloadURL(false); + +skyflow_client.vault("VAULT_ID").detokenize( + detokenizeRequest, + detokenizeOptions +).then(response=>{ + console.log(response); +}).catch(error=>{ + console.log(JSON.stringify(error)); +}) diff --git a/samples/vault-api/file-upload.ts b/samples/vault-api/file-upload.ts new file mode 100644 index 0000000..79c0938 --- /dev/null +++ b/samples/vault-api/file-upload.ts @@ -0,0 +1,48 @@ +import { Env, FileUploadRequest, LogLevel, Skyflow } from "skyflow-node"; + +// To generate Bearer Token from credentials string. +const cred = { + clientID: '', + clientName: '', + keyID: '', + tokenURI: '', + privateKey: '', +}; + +// please pass one of apiKey, token, credentialsString & path +const skyflowCredentials = { + credentialsString: JSON.stringify(cred), +} + +// please pass one of apiKey, token, credentialsString & path +const credentials = { + path: "PATH_TO_CREDENTIALS_JSON", // bearer token +} + +const skyflow_client = new Skyflow({ + vaultConfigs: [ + { + vaultId: "VAULT_ID", // primary vault + clusterId: "CLUSTER_ID", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + env: Env.PROD, // Env by deault it is set to PROD + credentials: credentials // indiviudal credentails + } + ], + skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed + logLevel:LogLevel.ERROR // set loglevel by deault it is set to PROD +}); + +const uploadReq = new FileUploadRequest( + "TABLE_NAME", + "SKYFLOW_ID", + "COLUMN_NAME", + "FILE_PATH" +); + +skyflow_client.vault("VAULT_ID").uploadFile( + uploadReq +).then(response=>{ + console.log(response); +}).catch(error=>{ + console.log(JSON.stringify(error)); +}); \ No newline at end of file diff --git a/samples/vault-api/get-column-values.ts b/samples/vault-api/get-column-values.ts new file mode 100644 index 0000000..f0d9651 --- /dev/null +++ b/samples/vault-api/get-column-values.ts @@ -0,0 +1,57 @@ +import { Env, GetOptions, LogLevel, Skyflow, GetColumnRequest } from "skyflow-node"; + +// To generate Bearer Token from credentials string. +const cred = { + clientID: '', + clientName: '', + keyID: '', + tokenURI: '', + privateKey: '', +}; + +// please pass one of apiKey, token, credentialsString & path +const skyflowCredentials = { + credentialsString: JSON.stringify(cred), +} + +// please pass one of apiKey, token, credentialsString & path +const credentials = { + path: "PATH_TO_CREDENTIALS_JSON", // bearer token +} + +const skyflow_client = new Skyflow({ + vaultConfigs: [ + { + vaultId: "VAULT_ID", // primary vault + clusterId: "CLUSTER_ID", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + env: Env.PROD, // Env by deault it is set to PROD + credentials: credentials // indiviudal credentails + } + ], + skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed + logLevel:LogLevel.ERROR // set loglevel by deault it is set to PROD +}); + +const columnValues = [ + 'VALUE1', + 'VALUE2', +] + +const getRequest = new GetColumnRequest( + "TABLE_NAME", + "COLUMN_NAME", //Name of the column. It must be configured as unique in the schema. + columnValues //Column values of the records to return +) + +const getOptions = new GetOptions() +//use setters of setting options refer to skyflow docs for more options +getOptions.setReturnTokens(true); + +skyflow_client.vault("VAULT_ID").get( + getRequest, + getOptions +).then(response => { + console.log(response); +}).catch(error => { + console.log(JSON.stringify(error)); +}); diff --git a/samples/vault-api/invoke.ts b/samples/vault-api/invoke.ts new file mode 100644 index 0000000..644280d --- /dev/null +++ b/samples/vault-api/invoke.ts @@ -0,0 +1,64 @@ +import { Env, Skyflow, InvokeConnectionRequest, METHOD, LogLevel } from "skyflow-node"; + +// To generate Bearer Token from credentials string. +const cred = { + clientID: '', + clientName: '', + keyID: '', + tokenURI: '', + privateKey: '', +}; + +// please pass one of apiKey, token, credentialsString & path +const skyflowCredentials = { + credentialsString: JSON.stringify(cred), +} + +// please pass one of apiKey, token, credentialsString & path +const credentials = { + apiKey: "API_KEY", // bearer token +} + +const skyflow_client = new Skyflow({ + vaultConfigs: [ + { + vaultId: "VAULT_ID", // primary vault ( NOTE : One vault is nessary) + clusterId: "CLUSTER_ID", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + env: Env.PROD, // Env by deault it is set to PROD + credentials: credentials // indiviudal credentails + } + ], + connectionConfigs: [ + { + 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 + } + ], + skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed + logLevel:LogLevel.ERROR // set loglevel by deault it is set to PROD +}); + +const body = { + "KEY1": "VALUE1", + "KEY2": "VALUE2", +}; + +const headers = { + 'Content-Type': 'application/json', +}; + +const invokeReq = new InvokeConnectionRequest( + METHOD.POST, + body, + headers +); + +//will return the first connection +skyflow_client.connection().invoke( + invokeReq +).then(resp=>{ + console.log(resp); +}).catch(err=>{ + console.log(JSON.stringify(err)); +}) \ No newline at end of file diff --git a/samples/vault-api/query.ts b/samples/vault-api/query.ts new file mode 100644 index 0000000..d7d28a0 --- /dev/null +++ b/samples/vault-api/query.ts @@ -0,0 +1,47 @@ +import { Env, LogLevel, QueryRequest, Skyflow } from "skyflow-node"; + +// To generate Bearer Token from credentials string. +const cred = { + clientID: '', + clientName: '', + keyID: '', + tokenURI: '', + privateKey: '', +}; + +// please pass one of apiKey, token, credentialsString & path +const skyflowCredentials = { + credentialsString: JSON.stringify(cred), +} + +// please pass one of apiKey, token, credentialsString & path +const credentials = { + apiKey: "API_KEY", // bearer token +} + +const skyflow_client = new Skyflow({ + vaultConfigs: [ + { + vaultId: "VAULT_ID", // primary vault + clusterId: "CLUSTER_ID", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + env: Env.PROD, // Env by deault it is set to PROD + credentials: credentials // indiviudal credentails + } + ], + skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed + logLevel:LogLevel.ERROR // set loglevel by deault it is set to PROD +}); +//sample query +const query = "select * from TABLE_NAME limit 1"; + +const queryReq = new QueryRequest( + query +); + +skyflow_client.vault("VAULT_ID").query( + queryReq, +).then(resp=>{ + console.log(resp); +}).catch(err=>{ + console.log(JSON.stringify(err)); +}); \ No newline at end of file diff --git a/samples/vault-api/tokenize.ts b/samples/vault-api/tokenize.ts new file mode 100644 index 0000000..8699cd4 --- /dev/null +++ b/samples/vault-api/tokenize.ts @@ -0,0 +1,52 @@ +import { Env, LogLevel, Skyflow, TokenizeRequest } from "skyflow-node"; + +// To generate Bearer Token from credentials string. +const cred = { + clientID: '', + clientName: '', + keyID: '', + tokenURI: '', + privateKey: '', +}; + +// please pass one of apiKey, token, credentialsString & path +const skyflowCredentials = { + credentialsString: JSON.stringify(cred), +} + +// please pass one of apiKey, token, credentialsString & path +const credentials = { + apiKey: "API_KEY", // bearer token +} + +const skyflow_client = new Skyflow({ + vaultConfigs: [ + { + vaultId: "VAULT_ID", // primary vault + clusterId: "CLUSTER_ID", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + env: Env.PROD, // Env by deault it is set to PROD + credentials: credentials // indiviudal credentails + } + ], + skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed + logLevel:LogLevel.ERROR // set loglevel by deault it is set to PROD +}); + +// tokenize only supports value and columngroup +// sample data +const tokenizeValues = [ + {value: '4111111111111111',columnGroup: 'card_number_cg'}, + {value:'42424242424242424',columnGroup: 'card_number_cg'} +]; + +const tokenReq = new TokenizeRequest( + tokenizeValues +); + +skyflow_client.vault("VAULT_ID").tokenize( + tokenReq, +).then(resp=>{ + console.log(resp); +}).catch(err=>{ + console.log(JSON.stringify(err)); +}); \ No newline at end of file