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..6973788 --- /dev/null +++ b/samples/vault-api/data-residency.ts @@ -0,0 +1,79 @@ +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); + const insertData = getResponse.data; + //parse insertData to remove skyflow_id + //get data from prod vault and insert data to SANDBOX vault + const insertRequest = new InsertRequest( + "TABLE_NAME", + insertData!, + ); + 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 diff --git a/src/error/messages/index.ts b/src/error/messages/index.ts index 3e3dca6..8ad9e30 100644 --- a/src/error/messages/index.ts +++ b/src/error/messages/index.ts @@ -157,9 +157,9 @@ const errorMessages = { INVALID_INVOKE_CONNECTION_REQUEST: `${errorPrefix} Validation error. Invalid invoke connection request. Specify a valid get invoke connection request.`, ERROR_OCCURRED: `${errorPrefix} API error. Error occurred.`, - EMPTY_INSERT_TOKEN: `${errorPrefix} Validation error. Token cannot be empty. Specify a valid token at index %s1.`, - INVALID_INSERT_TOKEN: `${errorPrefix} Validation error. Invalid token. Specify a valid token at index %s1.`, - INVALID_INSERT_TOKENS: `${errorPrefix} Validation error. Invalid tokens. Specify valid tokens as string array.`, + EMPTY_INSERT_TOKEN: `${errorPrefix} Validation error. Tokens object cannot be empty. Specify a valid tokens object at index %s1.`, + INVALID_INSERT_TOKEN: `${errorPrefix} Validation error. Invalid tokens object. Specify a valid tokens object at index %s1.`, + INVALID_INSERT_TOKENS: `${errorPrefix} Validation error. Invalid tokens. Specify valid tokens as object array.`, INVALID_TOKEN_MODE: `${errorPrefix} Validation error. The token mode key has a value of type %s1. Specify token as BYOT.`, INVALID_HOMOGENEOUS: `${errorPrefix} Validation error. The homogeneous key has a value of type %s1. Specify homogeneous as boolean.`, INVALID_TOKEN_STRICT: `${errorPrefix} Validation error. The tokenStrict key has a value of type %s1. Specify tokenStrict as boolean.`, diff --git a/src/index.ts b/src/index.ts index f0a2805..3149be8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import Skyflow from './vault/skyflow'; -import { LogLevel, Env, RedactionType, METHOD } from './utils'; +import { LogLevel, Env, RedactionType, METHOD, OrderByEnum, BYOT } from './utils'; import InsertRequest from './vault/model/request/insert'; import InsertOptions from './vault/model/options/insert'; import GetRequest from './vault/model/request/get'; @@ -39,6 +39,8 @@ export { isExpired, Credentials, RedactionType, + OrderByEnum, + BYOT, InsertRequest, InsertOptions, InsertResponse, diff --git a/src/utils/validations/index.ts b/src/utils/validations/index.ts index d94580e..53a1084 100644 --- a/src/utils/validations/index.ts +++ b/src/utils/validations/index.ts @@ -373,7 +373,7 @@ export const validateInsertOptions = (insertOptions?: InsertOptions) => { if (!token) { throw new SkyflowError(SKYFLOW_ERROR_CODE.EMPTY_INSERT_TOKEN, [index]); } - if (typeof token !== 'string' || token.trim().length === 0) { + if (typeof token !== 'object') { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_INSERT_TOKEN, [index]); } }); diff --git a/src/vault/controller/vault/index.ts b/src/vault/controller/vault/index.ts index 8e8705a..19caf3f 100644 --- a/src/vault/controller/vault/index.ts +++ b/src/vault/controller/vault/index.ts @@ -163,13 +163,17 @@ class VaultController { }); } + private getTokens(index:number, tokens?: Array) : object | undefined { + if(tokens && tokens.length !== 0 && tokens.length > index ) return tokens[index]; + } + private buildBatchInsertBody(request: InsertRequest, options?: InsertOptions): RecordServiceBatchOperationBody { - const records = request.data.map(record => ({ + const records = request.data.map((record, index) => ({ fields: record, tableName: request.tableName, tokenization: options?.getReturnTokens() || false, method: BatchRecordMethod.Post, - tokens: options?.getTokens(), + tokens: this.getTokens(index, options?.getTokens()), upsert: options?.getUpsert(), })); return { @@ -180,7 +184,10 @@ class VaultController { } private buildBulkInsertBody(request: InsertRequest, options?: InsertOptions): RecordServiceInsertRecordBody { - const records = request.data.map(record => ({ fields: record })) as Array; + const records = request.data.map((record, index) => ({ + fields: record, + tokens: this.getTokens(index, options?.getTokens()), + })) as Array; return { records, tokenization: options?.getReturnTokens(), diff --git a/src/vault/model/options/insert/index.ts b/src/vault/model/options/insert/index.ts index 2efb1ad..b9f18f4 100644 --- a/src/vault/model/options/insert/index.ts +++ b/src/vault/model/options/insert/index.ts @@ -5,7 +5,7 @@ class InsertOptions { // Fields private returnTokens?: boolean; private upsert?: string; - private tokens?: Array; + private tokens?: Array; private homogeneous?: boolean; private tokenMode?: BYOT; private tokenStrict?: boolean; @@ -23,7 +23,7 @@ class InsertOptions { this.upsert = upsert; } - setTokens(tokens: Array) { + setTokens(tokens: Array) { this.tokens = tokens; } @@ -52,7 +52,7 @@ class InsertOptions { return this.upsert; } - getTokens(): Array | undefined { + getTokens(): Array | undefined { return this.tokens; } diff --git a/test/vault/controller/vault.test.js b/test/vault/controller/vault.test.js index 495b775..c4d86f8 100644 --- a/test/vault/controller/vault.test.js +++ b/test/vault/controller/vault.test.js @@ -153,7 +153,8 @@ describe('VaultController insert method', () => { getReturnTokens: jest.fn().mockReturnValue(true), getUpsert: jest.fn().mockReturnValue(''), getHomogeneous: jest.fn().mockReturnValue(false), - getTokenMode: jest.fn().mockReturnValue('') + getTokenMode: jest.fn().mockReturnValue(''), + getTokens: jest.fn().mockReturnValue([{}]) }; const mockResponseData = { records: [{ skyflow_id: 'id123', tokens: {} }] }; @@ -181,7 +182,8 @@ describe('VaultController insert method', () => { getReturnTokens: jest.fn().mockReturnValue(true), getUpsert: jest.fn().mockReturnValue(''), getHomogeneous: jest.fn().mockReturnValue(false), - getTokenMode: jest.fn().mockReturnValue('') + getTokenMode: jest.fn().mockReturnValue(''), + getTokens: jest.fn().mockReturnValue([{}]) }; const mockResponseData = { records: [{ skyflow_id: 'id123', tokens: {} }] }; @@ -209,7 +211,8 @@ describe('VaultController insert method', () => { getReturnTokens: jest.fn().mockReturnValue(true), getUpsert: jest.fn().mockReturnValue(''), getHomogeneous: jest.fn().mockReturnValue(false), - getTokenMode: jest.fn().mockReturnValue('') + getTokenMode: jest.fn().mockReturnValue(''), + getTokens: jest.fn().mockReturnValue([{}]) }; const mockResponseData = { skyflow_id: 'id123', tokens: {} };