Skip to content

Commit

Permalink
New Components - anyflow (#10816)
Browse files Browse the repository at this point in the history
* anonyflow init

* Tested components
  • Loading branch information
jcortes committed Mar 11, 2024
1 parent 57252e6 commit 96cdb30
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
},
};
Original file line number Diff line number Diff line change
@@ -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;
},
};
44 changes: 40 additions & 4 deletions components/anonyflow/anonyflow.app.mjs
Original file line number Diff line number Diff line change
@@ -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,
});
},
},
};
25 changes: 25 additions & 0 deletions components/anonyflow/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -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,
};
7 changes: 5 additions & 2 deletions components/anonyflow/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/anonyflow",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream AnonyFlow Components",
"main": "anonyflow.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.0"
}
}
}
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 96cdb30

Please sign in to comment.