From 3e9bdd18990232279375db879510c567fa08effb Mon Sep 17 00:00:00 2001 From: Jorge Cortes Date: Wed, 6 Mar 2024 15:56:17 -0500 Subject: [PATCH] anonyflow init --- .../protect-sensitive-data.mjs | 26 +++++++++ .../unprotect-sensitive-data.mjs | 27 ++++++++++ components/anonyflow/anonyflow.app.mjs | 54 +++++++++++++++++-- components/anonyflow/package.json | 2 +- 4 files changed, 105 insertions(+), 4 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 96802b2ad5bda..bc3afdb911c11 100644 --- a/components/anonyflow/anonyflow.app.mjs +++ b/components/anonyflow/anonyflow.app.mjs @@ -1,11 +1,59 @@ +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, + }, + }); + }, }, -}; \ No newline at end of file + version: "0.0.{{ts}}", +}; 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 +}