Skip to content

Commit 87adfb3

Browse files
authored
New Components - jigsawstack (#13929)
* jigsawstack init * [Components] jigsawstack #13924 Actions - Verify Email - Object Detection - Sentiment Analysis * pnpm update
1 parent fdbfaaf commit 87adfb3

File tree

7 files changed

+221
-8
lines changed

7 files changed

+221
-8
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import fs from "fs";
3+
import mime from "mime";
4+
import {
5+
checkTmp,
6+
throwError,
7+
} from "../../common/utils.mjs";
8+
import jigsawstack from "../../jigsawstack.app.mjs";
9+
10+
export default {
11+
key: "jigsawstack-object-detection",
12+
name: "Object Detection",
13+
description: "Recognize objects within a provided image and retrieve it with great accuracy. [See the documentation](https://docs.jigsawstack.com/api-reference/ai/object-detection)",
14+
version: "0.0.1",
15+
type: "action",
16+
props: {
17+
jigsawstack,
18+
url: {
19+
type: "string",
20+
label: "Image URL",
21+
description: "The URL of the image to process.",
22+
optional: true,
23+
},
24+
fileStoreKey: {
25+
type: "string",
26+
label: "File Store Key",
27+
description: "The key used to store the image on Jigsawstack file [Storage](https://docs.jigsawstack.com/api-reference/store/file/add).",
28+
optional: true,
29+
},
30+
imageFile: {
31+
type: "string",
32+
label: "Image File",
33+
description: "The path to a file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp).",
34+
optional: true,
35+
},
36+
},
37+
async run({ $ }) {
38+
const {
39+
jigsawstack,
40+
...data
41+
} = this;
42+
43+
if (Object.keys(data).length > 1) {
44+
throw new ConfigurationError("You must provide only one option, either the **Image URL**, the **Image File**, or the **File Storage Key**.");
45+
}
46+
47+
if (data.fileStoreKey) data.file_store_key = data.fileStoreKey;
48+
49+
if (data.imageFile) {
50+
const filePath = checkTmp(data.imageFile);
51+
const file = fs.readFileSync(filePath);
52+
const { key } = await jigsawstack.uploadFile({
53+
headers: {
54+
"Content-Type": mime.getType(filePath),
55+
},
56+
data: file,
57+
});
58+
data.file_store_key = key;
59+
}
60+
61+
try {
62+
const response = await jigsawstack.detectObjectsInImage({
63+
$,
64+
data,
65+
});
66+
$.export("$summary", "Successfully detected objects in the image");
67+
return response;
68+
69+
} catch (e) {
70+
return throwError(e);
71+
}
72+
},
73+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { throwError } from "../../common/utils.mjs";
2+
import jigsawstack from "../../jigsawstack.app.mjs";
3+
4+
export default {
5+
key: "jigsawstack-sentiment-analysis",
6+
name: "Sentiment Analysis",
7+
description: "Assess sentiment of a provided text. Vibes can be positive, negative, or neutral. [See the documentation](https://docs.jigsawstack.com/api-reference/ai/sentiment)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
jigsawstack,
12+
text: {
13+
type: "string",
14+
label: "Text",
15+
description: "The text to analyze for sentiment.",
16+
},
17+
},
18+
async run({ $ }) {
19+
try {
20+
const response = await this.jigsawstack.analyzeSentiment({
21+
$,
22+
data: {
23+
text: this.text,
24+
},
25+
});
26+
27+
$.export("$summary", `Successfully analyzed sentiment with emotion: ${response.sentiment.emotion} and sentiment: ${response.sentiment.sentiment}`);
28+
return response;
29+
} catch (e) {
30+
return throwError(e);
31+
}
32+
},
33+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { throwError } from "../../common/utils.mjs";
2+
import jigsawstack from "../../jigsawstack.app.mjs";
3+
4+
export default {
5+
key: "jigsawstack-verify-email",
6+
name: "Verify Email",
7+
description: "Validate any email address and determine deliverability as well as disposable status. [See the documentation](https://docs.jigsawstack.com/api-reference/validate/email)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
jigsawstack,
12+
email: {
13+
type: "string",
14+
label: "Email Address",
15+
description: "The email address to validate.",
16+
},
17+
},
18+
async run({ $ }) {
19+
try {
20+
const response = await this.jigsawstack.validateEmail({
21+
$,
22+
params: {
23+
email: this.email,
24+
},
25+
});
26+
27+
$.export("$summary", `Successfully validated email: ${this.email}`);
28+
return response;
29+
} catch (e) {
30+
return throwError(e);
31+
}
32+
},
33+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
3+
export const throwError = ({ message }) => {
4+
const errorMessage = JSON.parse(message).message;
5+
throw new ConfigurationError(errorMessage);
6+
};
7+
8+
export const checkTmp = (filename) => {
9+
if (!filename.startsWith("/tmp")) {
10+
return `/tmp/${filename}`;
11+
}
12+
return filename;
13+
};
Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,54 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "jigsawstack",
4-
propDefinitions: {},
56
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
7+
_baseUrl() {
8+
return "https://api.jigsawstack.com/v1";
9+
},
10+
_headers(headers = {}) {
11+
return {
12+
"x-api-key": this.$auth.api_key,
13+
...headers,
14+
};
15+
},
16+
_makeRequest({
17+
$ = this, path, headers, ...opts
18+
}) {
19+
return axios($, {
20+
url: this._baseUrl() + path,
21+
headers: this._headers(headers),
22+
...opts,
23+
});
24+
},
25+
validateEmail(opts = {}) {
26+
return this._makeRequest({
27+
method: "GET",
28+
path: "/validate/email",
29+
...opts,
30+
});
31+
},
32+
detectObjectsInImage(opts = {}) {
33+
return this._makeRequest({
34+
method: "POST",
35+
path: "/ai/object_detection",
36+
...opts,
37+
});
38+
},
39+
analyzeSentiment(opts = {}) {
40+
return this._makeRequest({
41+
method: "POST",
42+
path: "/ai/sentiment",
43+
...opts,
44+
});
45+
},
46+
uploadFile(opts = {}) {
47+
return this._makeRequest({
48+
method: "POST",
49+
path: "/store/file",
50+
...opts,
51+
});
952
},
1053
},
11-
};
54+
};

components/jigsawstack/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/jigsawstack",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream JigsawStack Components",
55
"main": "jigsawstack.app.mjs",
66
"keywords": [
@@ -11,5 +11,10 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.1",
17+
"form-data": "^4.0.0",
18+
"mime": "^4.0.4"
1419
}
15-
}
20+
}

pnpm-lock.yaml

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)