diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ba980f..430e5b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. +## [1.13.0] - 2024-01-12 +### Added +- Removed get call from batch Insert. +- Continue on error support for batch Insert. + ## [1.12.0] - 2023-10-20 ### Added - `tokens` option in `get` interface. diff --git a/README.md b/README.md index e8f7025..3121cb8 100644 --- a/README.md +++ b/README.md @@ -573,6 +573,73 @@ response.then( }); ``` +Insert call [example](https://github.com/skyflowapi/skyflow-node/blob/master/samples/vault-api/InsertWithContinueOnError.ts) with contiueOnError support: + +```javascript +const response = client.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, +}); + +response.then( + (res) => { + console.log(JSON.stringify(res)); + }, + (err) => { + console.log(JSON.stringify(err)); + } +).catch((err) => { + console.log(JSON.stringify(err)); +}); +``` + +Sample Response: +```json +{ + "records": [ + { + "table": "cards", + "fields": { + "skyflow_id": "16419435-aa63-4823-aae7-19c6a2d6a19f", + "card_number": "f3907186-e7e2-466f-91e5-48e12c2bcbc1", + "expiry_date": "1989cb56-63da-4482-a2df-1f74cd0dd1a5", + "name": "245d3a0f-a2d3-443b-8a20-8c17de86e186", + }, + "request_index": 1, + } + ], + "errors": [ + { + "error": { + "code":400, + "description":"Invalid field present in JSON namee - requestId: 87fb2e32-6287-4e61-8304-9268df12bfe8", + "request_index": 0, + } + } + ] +} +``` + #### Detokenize In order to retrieve data from your vault using tokens that you have previously generated for that data, you can use the `detokenize(records)` method. The first parameter must have a records key that takes an array of tokens to be fetched from the vault, as shown below. diff --git a/samples/package.json b/samples/package.json index 49f65a0..f796ac2 100644 --- a/samples/package.json +++ b/samples/package.json @@ -9,6 +9,6 @@ "author": "", "license": "ISC", "dependencies": { - "skyflow-node": "^1.11.0" + "skyflow-node": "^1.13.0" } } diff --git a/samples/vault-api/InsertWithContinueOnError.ts b/samples/vault-api/InsertWithContinueOnError.ts new file mode 100644 index 0000000..0dc2ac3 --- /dev/null +++ b/samples/vault-api/InsertWithContinueOnError.ts @@ -0,0 +1,72 @@ +/* + 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)); + });