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..304cc66f45b54 --- /dev/null +++ b/components/anonyflow/actions/protect-sensitive-data/protect-sensitive-data.mjs @@ -0,0 +1,50 @@ +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.1", + type: "action", + props: { + app, + data: { + propDefinition: [ + app, + "data", + ], + }, + keys: { + propDefinition: [ + app, + "keys", + ], + }, + }, + methods: { + anonyPacket(args = {}) { + return this.app.post({ + path: "/anony-packet", + ...args, + }); + }, + }, + async run({ $ }) { + const { + anonyPacket, + data, + keys, + } = this; + + const response = await anonyPacket({ + $, + data: { + data: utils.valueToObject(data), + keys, + }, + }); + $.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 new file mode 100644 index 0000000000000..2c5bd050d564f --- /dev/null +++ b/components/anonyflow/actions/unprotect-sensitive-data/unprotect-sensitive-data.mjs @@ -0,0 +1,50 @@ +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.1", + type: "action", + props: { + app, + data: { + propDefinition: [ + app, + "data", + ], + }, + keys: { + propDefinition: [ + app, + "keys", + ], + }, + }, + methods: { + deanonyPacket(args = {}) { + return this.app.post({ + path: "/deanony-packet", + ...args, + }); + }, + }, + async run({ $ }) { + const { + deanonyPacket, + data, + keys, + } = this; + + 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 9c484b78bd69e..33a61bdbb59b1 100644 --- a/components/anonyflow/anonyflow.app.mjs +++ b/components/anonyflow/anonyflow.app.mjs @@ -1,11 +1,47 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "anonyflow", - propDefinitions: {}, + propDefinitions: { + data: { + type: "object", + label: "Data", + description: "Data packet to be Anonymized or Deanonymized. Note that **only JSON Object is accepted**", + }, + keys: { + type: "string[]", + label: "Keys", + description: "Provided keys to be used for Anonymization or Deanonymization", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + getUrl(path) { + return `https://api.anonyflow.com${path}`; + }, + getHeaders(headers) { + return { + ...headers, + "Accept": "application/json", + "Content-Type": "application/json", + "x-api-key": this.$auth.api_key, + }; + }, + _makeRequest({ + $ = this, path, headers, ...args + } = {}) { + const config = { + ...args, + url: this.getUrl(path), + headers: this.getHeaders(headers), + }; + return axios($, config); + }, + post(args = {}) { + return this._makeRequest({ + 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 917055117d608..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" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e27ac8a1860d4..102fb537996f5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -416,7 +416,10 @@ importers: specifiers: {} components/anonyflow: - specifiers: {} + specifiers: + '@pipedream/platform': ^1.6.0 + dependencies: + '@pipedream/platform': 1.6.0 components/anthropic: specifiers: {}