Skip to content

Commit

Permalink
DEX-229 resolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kamal-skyflow committed Nov 10, 2023
2 parents 486a082 + eab834e commit 0917a96
Show file tree
Hide file tree
Showing 16 changed files with 1,227 additions and 55 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## [1.12.0] - 2023-10-20
### Added
- `tokens` option in `get` interface.
- `encodeURI` option in `get` interface.

## [1.11.0] - 2023-07-19
### Added
- Added new `delete` interface.
## [1.10.0] - 2023-06-08
### Added
- `redaction` in detokenize interface.
Expand Down
75 changes: 68 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ skyflow-node is the Node.js version of Skyflow SDK for the JavaScript programmin
- [Requirements](#requirements)
- [Configuration](#configuration)
- [Usage](#usage)
- [Service Account Bearer Token Generation](#Service-Account-Bearer-Token-Generation)
- [Service Account Bearer Token Generation with Additional Context](#Service-Account-Bearer-Token-Generation-with-Additional-Context)
- [Service Account Scoped Bearer Token Generation](#Service-Account-Scoped-Bearer-Token-Generation)
- [Skyflow Signed Data Tokens Generation](#Skyflow-Signed-Data-Tokens-Generation)
- [Importing `skyflow-node`](#importing-skyflow-node)
- [Service Account Bearer Token Generation](#service-account-bearer-token-generation)
- [Service Account Bearer Token Generation with Additional Context](#service-account-bearer-token-generation-with-additional-context)
- [Service Account Scoped Bearer Token Generation](#service-account-scoped-bearer-token-generation)
- [Skyflow Signed Data Tokens Generation](#skyflow-signed-data-tokens-generation)
- [Vault APIs](#vault-apis)
- [Insert](#insert)
- [Detokenize](#detokenize)
- [Get By Id](#get-by-id)
- [Get](#get)
- [Update](#update)
- [Delete](#delete)
- [Invoke Connection](#invoke-connection)
- [Logging](#logging)
- [Reporting a Vulnerability](#reporting-a-vulnerability)
Expand Down Expand Up @@ -112,7 +114,7 @@ let bearerToken = '';
function getSkyflowBearerToken() {
return new Promise(async (resolve, reject) => {
try {
if (isExpired(bearerToken)) resolve(bearerToken);
if (!isExpired(bearerToken)) resolve(bearerToken);
else {
let response = await generateBearerTokenFromCreds(
JSON.stringify(credentials)
Expand Down Expand Up @@ -195,7 +197,7 @@ function getSkyflowBearerToken() {
const options = {
ctx: 'CONTEXT_ID',
}
if (isExpired(bearerToken)) resolve(bearerToken);
if (!isExpired(bearerToken)) resolve(bearerToken);
else {
let response = await generateBearerTokenFromCreds(
JSON.stringify(credentials),
Expand Down Expand Up @@ -279,7 +281,7 @@ function getSkyflowBearerToken() {
const options = {
roleIDs: ['ROLE_ID1', 'ROLE_ID2'],
};
if (isExpired(bearerToken)) resolve(bearerToken);
if (!isExpired(bearerToken)) resolve(bearerToken);
else {
let response = await generateBearerTokenFromCreds(
JSON.stringify(credentials),
Expand Down Expand Up @@ -909,6 +911,65 @@ Response:
]
}
```
#### Delete

To delete data from the vault, use the `delete(records, options?)` method of the Skyflow client. The `records` parameter takes an array of records to delete in the following format. The `options` parameter is optional and takes an object of deletion parameters. Currently, there are no supported deletion parameters.

Call schema:
```js
const deleteInput = {
records: [
{
id: "<SKYFLOW_ID_1>", // skyflow id of the record to delete
table: "<TABLE_NAME>" // Table from which the record is to be deleted
},
{
// ...additional records here
},
]
};

const options = {
// Optional
}
```

[Example](https://github.com/skyflowapi/skyflow-node/blob/master/samples/vault-api/Delete.ts) to delete by ID using `skyflow_ids`

```js
const deleteInput = {
records: [
{
id: "29ebda8d-5272-4063-af58-15cc674e332b",
table: "cards",
},
{
id: "d5f4b926-7b1a-41df-8fac-7950d2cbd923",
table: "cards",
}
],
};

const options = {};

const response = skyflowClient.delete(deleteInput, options);
console.log(response);
```
Response:
```json
{
"records": [
{
"skyflow_id": "29ebda8d-5272-4063-af58-15cc674e332b",
"deleted": true,
},
{
"skyflow_id": "29ebda8d-5272-4063-af58-15cc674e332b",
"deleted": true,
}
]
}
```
#### Invoke Connection

Using the InvokeConnection method, you can integrate their server-side application with third party APIs and services without directly handling sensitive data. Prior to invoking the InvokeConnection method, you must have created a connection and have a connectionURL already generated. Once you have the connectionURL, you can invoke a connection by using the `invokeConnection(config)` method. The config object must include a connectionURL and methodName. The other fields are optional.
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "skyflow-node",
"version": "1.10.0",
"version": "1.12.0",
"description": "Skyflow SDK for Node.js",
"main": "./lib/index.js",
"module": "./lib/index.js",
Expand Down Expand Up @@ -48,7 +48,7 @@
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.9.6",
"@babel/core": "^7.23.2",
"@babel/plugin-proposal-class-properties": "^7.10.1",
"@babel/plugin-proposal-decorators": "^7.10.1",
"@babel/plugin-proposal-object-rest-spread": "^7.10.1",
Expand All @@ -66,17 +66,16 @@
"@types/qs": "^6.9.7",
"babel-loader": "^8.0.0",
"chai": "^4.1.2",
"coveralls": "^3.0.1",
"crypto-browserify": "^3.12.0",
"eslint": "^8.12.0",
"eslint-plugin-sonarjs": "^0.13.0",
"expect.js": "^0.3.1",
"husky": "^1.3.1",
"istanbul": "^0.4.5",
"jest": "^27.3.1",
"jsdoc": "^3.6.3",
"jsdoc": "^4.0.2",
"json-loader": "~0.5.4",
"nodemon": "^2.0.14",
"nodemon": "^3.0.1",
"null-loader": "^0.1.1",
"nyc": "^15.1.0",
"prettier": "^1.13.7",
Expand Down
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.9.0"
"skyflow-node": "^1.11.0"
}
}
58 changes: 58 additions & 0 deletions samples/vault-api/Delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright (c) 2023 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);
});
}
});
},
});

const result = skyflow.delete({
records: [
{
id: "<SKYFLOW_ID_1>",
table: "<TABLE_NAME",
},
{
id: "<SKYFLOW_ID_2>",
table: "<TABLE_NAME",
},
],
});

result
.then((response) => {
console.log("delete result:");
console.log(JSON.stringify(response));
})
.catch((error) => {
console.log("delete error: ");
console.log(JSON.stringify(error));
});
39 changes: 35 additions & 4 deletions src/vault-api/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import Client from './client';

import {
validateConnectionConfig, validateInsertRecords, validateDetokenizeInput, validateGetByIdInput, validateInitConfig, validateUpsertOptions, validateUpdateInput, validateGetInput,
validateConnectionConfig, validateInsertRecords, validateDetokenizeInput, validateGetByIdInput, validateInitConfig, validateUpsertOptions, validateUpdateInput, validateGetInput, validateDeleteInputAndOptions
} from './utils/validators';

import {
ContentType,
IDeleteInput,
IDeleteOptions,
IGetInput,
IGetOptions,
IInsertOptions,
IUpdateInput,
IUpdateOptions,
Expand Down Expand Up @@ -40,6 +43,7 @@ import {
import { isTokenValid } from './utils/jwt-utils';
import SKYFLOW_ERROR_CODE from './utils/constants';
import SkyflowError from './libs/SkyflowError';
import { deleteRecordsBySkyflowID } from './core/Delete';

class Controller {
#client: Client;
Expand Down Expand Up @@ -148,20 +152,21 @@ class Controller {
});
}

get(getInput: IGetInput) {
get(getInput: IGetInput,options:IGetOptions={}) {
return new Promise((resolve, reject) => {
try {
validateInitConfig(this.#client.config)
printLog(logs.infoLogs.VALIDATE_GET_INPUT, MessageType.LOG);
validateGetInput(getInput);
validateGetInput(getInput,options);
printLog(parameterizedString(logs.infoLogs.EMIT_REQUEST,
TYPES.GET),
MessageType.LOG);
this.getToken().then((res) => {
fetchRecordsBySkyflowID(
getInput.records,
this.#client,
res
res,
options
).then(
(resolvedResult) => {
printLog(logs.infoLogs.GET_BY_SKYFLOWID_RESOLVED, MessageType.LOG);
Expand Down Expand Up @@ -243,6 +248,32 @@ class Controller {
});
}

delete(deleteInput: IDeleteInput, options?: IDeleteOptions) {
return new Promise((resolve, reject) => {
try {
validateInitConfig(this.#client.config);
validateDeleteInputAndOptions(deleteInput, options);
this.getToken().then((authToken) => {
deleteRecordsBySkyflowID(deleteInput.records, options = {}, this.#client, authToken)
.then((response) => {
printLog(logs.infoLogs.DELETE_REQUEST_RESOLVED, MessageType.LOG);
resolve(response);
}).catch((error) => {
printLog(logs.errorLogs.DELETE_REQUEST_REJECTED, MessageType.ERROR);
reject(error);
});
}).catch((err) => {
reject(err);
})

} catch (error) {
if (error instanceof Error)
printLog(error.message, MessageType.ERROR);
reject(error);
}
})
}

insertData(records, options) {
const requestBody = constructInsertRecordRequest(records, options);
return new Promise((rootResolve, rootReject) => {
Expand Down
48 changes: 28 additions & 20 deletions src/vault-api/Skyflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@
* @module Skyflow
*/

import Client from './client';
import { printLog } from './utils/logs-helper';
import logs from './utils/logs';
import Controller from './Controller';
import {
IRevealResponseType,
IConnectionConfig,
RequestMethod,
IInsertRecordInput,
IDetokenizeInput,
IGetByIdInput,
RedactionType,
MessageType,
IInsertOptions,
IUpdateInput,
IUpdateOptions,
IGetInput,
} from './utils/common';
import { formatVaultURL } from './utils/helpers';
import Client from './client';
import { printLog } from './utils/logs-helper';
import logs from './utils/logs';
import Controller from './Controller';
import {
IRevealResponseType,
IConnectionConfig,
RequestMethod,
IInsertRecordInput,
IDetokenizeInput,
IGetByIdInput,
RedactionType,
MessageType,
IInsertOptions,
IUpdateInput,
IUpdateOptions,
IGetInput,
IGetOptions,
IDeleteInput,
IDeleteOptions,
} from './utils/common';
import { formatVaultURL } from './utils/helpers';


/**
Expand Down Expand Up @@ -171,6 +174,11 @@
return this.#Controller.update(updateInput,options);
}

delete(deleteInput: IDeleteInput, options?: IDeleteOptions) {
printLog(logs.infoLogs.UPDATE_TRIGGERED, MessageType.LOG);
return this.#Controller.delete(deleteInput, options)
}

static get RedactionType() {
return RedactionType;
}
Expand All @@ -180,4 +188,4 @@
}
}
export default Skyflow;


Loading

0 comments on commit 0917a96

Please sign in to comment.