Skip to content

Commit

Permalink
Merge pull request #95 from skyflowapi/release/23.1.2.1
Browse files Browse the repository at this point in the history
Release/23.1.2.1
  • Loading branch information
yaswanth-pula-skyflow authored Jan 11, 2023
2 parents 184f864 + 340f922 commit 4a2f4e5
Show file tree
Hide file tree
Showing 12 changed files with 439 additions and 208 deletions.
113 changes: 100 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ skyflow-node is the Node.js version of Skyflow SDK for the JavaScript programmin
- [Insert](#insert)
- [Detokenize](#detokenize)
- [Get By Id](#get-by-id)
- [Get](#get)
- [Update](#update)
- [Invoke Connection](#invoke-connection)
- [Logging](#logging)
Expand Down Expand Up @@ -613,9 +614,102 @@ Sample response:
],
}
```

#### Get By Id
To retrieve data from your vault using SkyflowIDs or unique column values, use the getById(records) method. The `records` parameter takes a JSONObject that should contain either an array of SkyflowIDs or a unique column name and values to fetch the records, as shown below:
In order to retrieve data from your vault using SkyflowIDs, use the `getById(records)` method. The records parameter takes a JSONObject that should contain an array of SkyflowIDs to be fetched, as shown below:

```javascript
data = {
records: [{
// List of skyflow_ids for the records to be fetched
ids: ['id1', 'id2'],
// Name of table holding the above skyflow_ids
table: 'NAME_OF_SKYFLOW_TABLE',
// Redaction to be applied to retrieved data
redaction: Skyflow.RedactionType,
}]
};
```
`Skyflow.RedactionTypes` accept four values:
* `PLAIN_TEXT`
* `MASKED`
* `REDACTED`
* `DEFAULT`

You must apply a redaction type to retrieve data

An [example](https://github.com/skyflowapi/skyflow-node/blob/master/samples/vault-api/GetById.ts) of `getById` call:
```javascript
let skyflowIds = [
'f8622-b557-4c6b-a12c-c0b0bfd9',
'da26de53-95d5-4db-99db-8d35ff9'
];

let record = {
ids: skyflowIds,
table: 'cards',
redaction: RedactionType.PLAIN_TEXT
};

let invalidIds = ['invalid Skyflow ID'];
let badRecord = {
ids: invalidIds,
table: 'cards',
'redaction': RedactionType.PLAIN_TEXT
};

let records = {
records: [record, badRecord]
};

const result = client.getById(records);
result.then(
(res) => {
console.log(JSON.stringify(res));
}).catch((err) => {
console.log(JSON.stringify(err));
});
```

Sample response:

```json
{
"records": [
{
"fields": {
"card_number": "4111111111111111",
"expiry_date": "11/35",
"fullname": "myname",
"skyflow_id": "f8d2-b557-4c6b-a12c-c5ebfd9"
},
"table": "cards"
},
{
"fields": {
"card_number": "4111111111111111",
"expiry_date": "10/23",
"fullname": "sam",
"skyflow_id": "da53-95d5-4bdb-99db-8d8c5ff9"
},
"table": "cards"
}
],
"errors": [
{
"error": {
"code": "404",
"description": "No Records Found"
},
"skyflow_ids": [
"invalid Skyflow ID"
]
}
]
}
```

#### Get
To retrieve data from your vault using SkyflowIDs or unique column values, use the get(records) method. The `records` parameter takes a JSONObject that should contain either an array of SkyflowIDs or a unique column name and values to fetch the records, as shown below:

```javascript
data = {
Expand All @@ -635,17 +729,10 @@ data = {
],
};
```
`Skyflow.RedactionTypes` accept four values:
* `PLAIN_TEXT`
* `MASKED`
* `REDACTED`
* `DEFAULT`

You must apply a redaction type to retrieve data

Note: You cannot pass an array of skyflow_ids and unique column details together. Using column name and column value with `skyflow_ids` will return an error message.

[Example](https://github.com/skyflowapi/skyflow-node/blob/master/samples/vault-api/GetById.ts) to get records using skyflow_ids:
[Example](https://github.com/skyflowapi/skyflow-node/blob/master/samples/vault-api/Get.ts) to get records using skyflow_ids:
```javascript
let skyflowIds = [
'f8622-b557-4c6b-a12c-c0b0bfd9',
Expand All @@ -662,7 +749,7 @@ let records = {
records: [record],
};

const result = client.getById(records);
const result = client.get(records);
result
.then((res) => {
console.log(JSON.stringify(res));
Expand Down Expand Up @@ -698,7 +785,7 @@ Response:
]
}
```
[Example](https://github.com/skyflowapi/skyflow-node/blob/master/samples/vault-api/GetById.ts) to get records using unique column names and values:
[Example](https://github.com/skyflowapi/skyflow-node/blob/master/samples/vault-api/Get.ts) to get records using unique column names and values:

```javascript
let record = {
Expand All @@ -712,7 +799,7 @@ let records = {
records: [record],
};

const result = client.getById(records);
const result = client.get(records);
result
.then((res) => {
console.log(JSON.stringify(res));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "skyflow-node",
"version": "1.9.0",
"version": "1.9.0-dev.7943e1b",
"description": "Skyflow SDK for Node.js",
"main": "./lib/index.js",
"module": "./lib/index.js",
Expand Down
4 changes: 2 additions & 2 deletions samples/vault-api/Get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ const result = skyflow.get({

result
.then(response => {
console.log('getByID result:');
console.log('get result:');
console.log(JSON.stringify(response));
})
.catch(error => {
console.log('getByID error: ');
console.log('get error: ');
console.log(JSON.stringify(error));
});
56 changes: 56 additions & 0 deletions samples/vault-api/GetById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +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);
});
}
});
},
});

const result = skyflow.getById({
records: [
// To to get records using skyflow_ids.
{
ids: ['<ID1>', '<ID2>'],
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));
});
Loading

0 comments on commit 4a2f4e5

Please sign in to comment.