From b2f62dd562f15c9c9aec302c24d8fc337a636fed Mon Sep 17 00:00:00 2001 From: Jorge Cortes Date: Wed, 6 Mar 2024 15:56:17 -0500 Subject: [PATCH 1/2] anonyflow init --- .../protect-sensitive-data.mjs | 26 ++++++++++ .../unprotect-sensitive-data.mjs | 27 ++++++++++ components/anonyflow/anonyflow.app.mjs | 51 ++++++++++++++++++- components/anonyflow/package.json | 2 +- 4 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 components/anonyflow/actions/protect-sensitive-data/protect-sensitive-data.mjs create mode 100644 components/anonyflow/actions/unprotect-sensitive-data/unprotect-sensitive-data.mjs diff --git a/components/anonyflow/actions/protect-sensitive-data/protect-sensitive-data.mjs b/components/anonyflow/actions/protect-sensitive-data/protect-sensitive-data.mjs new file mode 100644 index 0000000000000..5922470181f40 --- /dev/null +++ b/components/anonyflow/actions/protect-sensitive-data/protect-sensitive-data.mjs @@ -0,0 +1,26 @@ +import anonyflow from "../../anonyflow.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "anonyflow-protect-sensitive-data", + name: "Protect Sensitive Data", + description: "Encrypts sensitive data using AnonyFlow encryption service with a unique private key managed by AnonyFlow. [See the documentation](https://anonyflow.com/api)", + version: "0.0.{{ts}}", + type: "action", + props: { + anonyflow, + sensitiveData: { + propDefinition: [ + anonyflow, + "sensitiveData", + ], + }, + }, + async run({ $ }) { + const encryptedResponse = await this.anonyflow.encryptData({ + sensitiveData: this.sensitiveData, + }); + $.export("$summary", "Sensitive data encrypted successfully"); + return encryptedResponse; + }, +}; diff --git a/components/anonyflow/actions/unprotect-sensitive-data/unprotect-sensitive-data.mjs b/components/anonyflow/actions/unprotect-sensitive-data/unprotect-sensitive-data.mjs new file mode 100644 index 0000000000000..1f17989276b3e --- /dev/null +++ b/components/anonyflow/actions/unprotect-sensitive-data/unprotect-sensitive-data.mjs @@ -0,0 +1,27 @@ +import anonyflow from "../../anonyflow.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "anonyflow-unprotect-sensitive-data", + name: "Unprotect Sensitive Data", + description: "Decrypts protected data using AnonyFlow decryption service with a unique private key, managed by AnonyFlow. [See the documentation](https://anonyflow.com/api)", + version: "0.0.{{ts}}", + type: "action", + props: { + anonyflow, + encryptedData: { + propDefinition: [ + anonyflow, + "encryptedData", + ], + }, + }, + async run({ $ }) { + const response = await this.anonyflow.decryptData({ + encryptedData: this.encryptedData, + }); + + $.export("$summary", "Successfully decrypted the data"); + return response; + }, +}; diff --git a/components/anonyflow/anonyflow.app.mjs b/components/anonyflow/anonyflow.app.mjs index 9c484b78bd69e..cc9356362fed9 100644 --- a/components/anonyflow/anonyflow.app.mjs +++ b/components/anonyflow/anonyflow.app.mjs @@ -1,11 +1,58 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "anonyflow", - propDefinitions: {}, + propDefinitions: { + encryptedData: { + type: "string", + label: "Encrypted Data", + description: "The data to be decrypted", + }, + sensitiveData: { + type: "string", + label: "Sensitive Data", + description: "The sensitive data to be encrypted", + }, + }, methods: { - // this.$auth contains connected account data authKeys() { console.log(Object.keys(this.$auth)); }, + _baseUrl() { + return "https://api.anonyflow.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, method = "POST", path, data, headers, ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + method, + url: this._baseUrl() + path, + headers: { + ...headers, + "Content-Type": "application/json", + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + }, + data, + }); + }, + async encryptData({ sensitiveData }) { + return this._makeRequest({ + path: "/anony-value", + data: { + value: sensitiveData, + }, + }); + }, + async decryptData({ encryptedData }) { + return this._makeRequest({ + path: "/deanony-value", + data: { + value: encryptedData, + }, + }); + }, }, }; diff --git a/components/anonyflow/package.json b/components/anonyflow/package.json index 917055117d608..93a5fdc700a0e 100644 --- a/components/anonyflow/package.json +++ b/components/anonyflow/package.json @@ -12,4 +12,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} From b25a56d23503c8db9a91e53f42cd2aacf89aaf77 Mon Sep 17 00:00:00 2001 From: Jorge Cortes Date: Wed, 6 Mar 2024 20:18:11 -0500 Subject: [PATCH 2/2] Tested components --- .../protect-sensitive-data.mjs | 46 ++++++++++--- .../unprotect-sensitive-data.mjs | 45 +++++++++--- components/anonyflow/anonyflow.app.mjs | 69 ++++++++----------- components/anonyflow/common/utils.mjs | 25 +++++++ components/anonyflow/package.json | 5 +- pnpm-lock.yaml | 24 ++----- 6 files changed, 134 insertions(+), 80 deletions(-) create mode 100644 components/anonyflow/common/utils.mjs diff --git a/components/anonyflow/actions/protect-sensitive-data/protect-sensitive-data.mjs b/components/anonyflow/actions/protect-sensitive-data/protect-sensitive-data.mjs index 5922470181f40..304cc66f45b54 100644 --- a/components/anonyflow/actions/protect-sensitive-data/protect-sensitive-data.mjs +++ b/components/anonyflow/actions/protect-sensitive-data/protect-sensitive-data.mjs @@ -1,26 +1,50 @@ -import anonyflow from "../../anonyflow.app.mjs"; -import { axios } from "@pipedream/platform"; +import app from "../../anonyflow.app.mjs"; +import utils from "../../common/utils.mjs"; export default { key: "anonyflow-protect-sensitive-data", name: "Protect Sensitive Data", description: "Encrypts sensitive data using AnonyFlow encryption service with a unique private key managed by AnonyFlow. [See the documentation](https://anonyflow.com/api)", - version: "0.0.{{ts}}", + version: "0.0.1", type: "action", props: { - anonyflow, - sensitiveData: { + app, + data: { propDefinition: [ - anonyflow, - "sensitiveData", + app, + "data", + ], + }, + keys: { + propDefinition: [ + app, + "keys", ], }, }, + methods: { + anonyPacket(args = {}) { + return this.app.post({ + path: "/anony-packet", + ...args, + }); + }, + }, async run({ $ }) { - const encryptedResponse = await this.anonyflow.encryptData({ - sensitiveData: this.sensitiveData, + const { + anonyPacket, + data, + keys, + } = this; + + const response = await anonyPacket({ + $, + data: { + data: utils.valueToObject(data), + keys, + }, }); - $.export("$summary", "Sensitive data encrypted successfully"); - return encryptedResponse; + $.export("$summary", `Successfully protected the data with status \`${response.status}\``); + return response; }, }; diff --git a/components/anonyflow/actions/unprotect-sensitive-data/unprotect-sensitive-data.mjs b/components/anonyflow/actions/unprotect-sensitive-data/unprotect-sensitive-data.mjs index 1f17989276b3e..2c5bd050d564f 100644 --- a/components/anonyflow/actions/unprotect-sensitive-data/unprotect-sensitive-data.mjs +++ b/components/anonyflow/actions/unprotect-sensitive-data/unprotect-sensitive-data.mjs @@ -1,27 +1,50 @@ -import anonyflow from "../../anonyflow.app.mjs"; -import { axios } from "@pipedream/platform"; +import app from "../../anonyflow.app.mjs"; +import utils from "../../common/utils.mjs"; export default { key: "anonyflow-unprotect-sensitive-data", name: "Unprotect Sensitive Data", description: "Decrypts protected data using AnonyFlow decryption service with a unique private key, managed by AnonyFlow. [See the documentation](https://anonyflow.com/api)", - version: "0.0.{{ts}}", + version: "0.0.1", type: "action", props: { - anonyflow, - encryptedData: { + app, + data: { propDefinition: [ - anonyflow, - "encryptedData", + app, + "data", + ], + }, + keys: { + propDefinition: [ + app, + "keys", ], }, }, + methods: { + deanonyPacket(args = {}) { + return this.app.post({ + path: "/deanony-packet", + ...args, + }); + }, + }, async run({ $ }) { - const response = await this.anonyflow.decryptData({ - encryptedData: this.encryptedData, - }); + const { + deanonyPacket, + data, + keys, + } = this; - $.export("$summary", "Successfully decrypted the data"); + const response = await deanonyPacket({ + $, + data: { + data: utils.valueToObject(data), + keys, + }, + }); + $.export("$summary", `Successfully unprotected the data with status \`${response.status}\``); return response; }, }; diff --git a/components/anonyflow/anonyflow.app.mjs b/components/anonyflow/anonyflow.app.mjs index cc9356362fed9..33a61bdbb59b1 100644 --- a/components/anonyflow/anonyflow.app.mjs +++ b/components/anonyflow/anonyflow.app.mjs @@ -4,54 +4,43 @@ export default { type: "app", app: "anonyflow", propDefinitions: { - encryptedData: { - type: "string", - label: "Encrypted Data", - description: "The data to be decrypted", + data: { + type: "object", + label: "Data", + description: "Data packet to be Anonymized or Deanonymized. Note that **only JSON Object is accepted**", }, - sensitiveData: { - type: "string", - label: "Sensitive Data", - description: "The sensitive data to be encrypted", + keys: { + type: "string[]", + label: "Keys", + description: "Provided keys to be used for Anonymization or Deanonymization", }, }, methods: { - authKeys() { - console.log(Object.keys(this.$auth)); + getUrl(path) { + return `https://api.anonyflow.com${path}`; }, - _baseUrl() { - return "https://api.anonyflow.com"; + getHeaders(headers) { + return { + ...headers, + "Accept": "application/json", + "Content-Type": "application/json", + "x-api-key": this.$auth.api_key, + }; }, - async _makeRequest(opts = {}) { - const { - $ = this, method = "POST", path, data, headers, ...otherOpts - } = opts; - return axios($, { - ...otherOpts, - method, - url: this._baseUrl() + path, - headers: { - ...headers, - "Content-Type": "application/json", - "Authorization": `Bearer ${this.$auth.oauth_access_token}`, - }, - data, - }); - }, - async encryptData({ sensitiveData }) { - return this._makeRequest({ - path: "/anony-value", - data: { - value: sensitiveData, - }, - }); + _makeRequest({ + $ = this, path, headers, ...args + } = {}) { + const config = { + ...args, + url: this.getUrl(path), + headers: this.getHeaders(headers), + }; + return axios($, config); }, - async decryptData({ encryptedData }) { + post(args = {}) { return this._makeRequest({ - path: "/deanony-value", - data: { - value: encryptedData, - }, + method: "post", + ...args, }); }, }, diff --git a/components/anonyflow/common/utils.mjs b/components/anonyflow/common/utils.mjs new file mode 100644 index 0000000000000..1c285647cbdda --- /dev/null +++ b/components/anonyflow/common/utils.mjs @@ -0,0 +1,25 @@ +function isJson(value) { + if (typeof(value) !== "string") { + return false; + } + + let parsedValue; + try { + parsedValue = JSON.parse(value); + } catch (e) { + return false; + } + + return typeof(parsedValue) === "object" && parsedValue !== null; +} + +function valueToObject(value) { + if (!isJson(value)) { + return value; + } + return JSON.parse(value); +} + +export default { + valueToObject, +}; diff --git a/components/anonyflow/package.json b/components/anonyflow/package.json index 93a5fdc700a0e..de1e56f6a201f 100644 --- a/components/anonyflow/package.json +++ b/components/anonyflow/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/anonyflow", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream AnonyFlow Components", "main": "anonyflow.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^1.6.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c38c2f4895b37..8a82a0ff692b9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -350,6 +350,9 @@ importers: dependencies: '@pipedream/platform': 1.6.0 + components/amazon_polly: + specifiers: {} + components/amazon_ses: specifiers: '@aws-sdk/client-ec2': ^3.89.0 @@ -413,7 +416,10 @@ importers: specifiers: {} components/anonyflow: - specifiers: {} + specifiers: + '@pipedream/platform': ^1.6.0 + dependencies: + '@pipedream/platform': 1.6.0 components/anthropic: specifiers: {} @@ -4747,9 +4753,6 @@ importers: components/mozilla_observatory: specifiers: {} - components/mtest: - specifiers: {} - components/mumara: specifiers: {} @@ -7773,19 +7776,6 @@ importers: components/tmetric: specifiers: {} - components/tmp/postgresql_test: - specifiers: - dtslint: ^4.2.1 - pg: ^8.7.1 - pg-format: ^1.0.4 - typescript: ^4.6.4 - dependencies: - pg: 8.11.3 - pg-format: 1.0.4 - typescript: 4.9.5 - devDependencies: - dtslint: 4.2.1_typescript@4.9.5 - components/todoist: specifiers: '@pipedream/platform': ^1.2.1