Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SK-1621: node sdk v2 samples #158

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"skyflow-node": "^1.13.0"
"skyflow-node": "1.14.0-dev.c0f4b46"
}
}
1 change: 1 addition & 0 deletions samples/vault-api/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SKYFLOW_CREDENTIALS={ clientID: '<YOUR_CLIENT_ID>', clientName: '<YOUR_CLIENT_NAME>', keyID: '<YOUR_KEY_ID>', tokenURI: '<YOUR_TOKEN_URI>', privateKey: '<YOUR_PEM_PRIVATE_KEY>', }
101 changes: 48 additions & 53 deletions samples/vault-api/Delete.ts
Original file line number Diff line number Diff line change
@@ -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 = "<YOUR_CREDENTIAL_FILE>";
setLogLevel(LogLevel.INFO);
let bearerToken = "";
// To generate Bearer Token from credentials string.
const cred = {
clientID: '<YOUR_CLIENT_ID>',
clientName: '<YOUR_CLIENT_NAME>',
keyID: '<YOUR_KEY_ID>',
tokenURI: '<YOUR_TOKEN_URI>',
privateKey: '<YOUR_PEM_PRIVATE_KEY>',
};

const skyflow = Skyflow.init({
vaultID: "<VAULT_ID>",
vaultURL: "<VAULT_URL>",
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: "<SKYFLOW_ID_1>",
table: "<TABLE_NAME",
},
{
id: "<SKYFLOW_ID_2>",
table: "<TABLE_NAME",
},
],
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("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));
});
66 changes: 0 additions & 66 deletions samples/vault-api/Detokenize.ts

This file was deleted.

111 changes: 52 additions & 59 deletions samples/vault-api/Get.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,56 @@
/*
Copyright (c) 2022 Skyflow, Inc.
*/
import {
Skyflow,
generateBearerToken,
isExpired,
setLogLevel,
LogLevel,
} from 'skyflow-node';

const filePath = '<YOUR_CREDENTIAL_FILE>';
setLogLevel(LogLevel.INFO);
let bearerToken = '';

const skyflow = Skyflow.init({
vaultID: '<VAULT_ID>',
vaultURL: '<VAULT_URL>',
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: '<YOUR_CLIENT_ID>',
clientName: '<YOUR_CLIENT_NAME>',
keyID: '<YOUR_KEY_ID>',
tokenURI: '<YOUR_TOKEN_URI>',
privateKey: '<YOUR_PEM_PRIVATE_KEY>',
};

// 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: ['<ID1>', '<ID2>'],
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));
});
});
56 changes: 0 additions & 56 deletions samples/vault-api/GetById.ts

This file was deleted.

Loading
Loading