Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { ConfigurationError } from "@pipedream/platform";
import fs from "fs";
import mime from "mime";
import {
checkTmp,
throwError,
} from "../../common/utils.mjs";
import jigsawstack from "../../jigsawstack.app.mjs";

export default {
key: "jigsawstack-object-detection",
name: "Object Detection",
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)",
version: "0.0.1",
type: "action",
props: {
jigsawstack,
url: {
type: "string",
label: "Image URL",
description: "The URL of the image to process.",
optional: true,
},
fileStoreKey: {
type: "string",
label: "File Store Key",
description: "The key used to store the image on Jigsawstack file [Storage](https://docs.jigsawstack.com/api-reference/store/file/add).",
optional: true,
},
imageFile: {
type: "string",
label: "Image File",
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).",
optional: true,
},
},
async run({ $ }) {
const {
jigsawstack,
...data
} = this;

if (Object.keys(data).length > 1) {
throw new ConfigurationError("You must provide only one option, either the **Image URL**, the **Image File**, or the **File Storage Key**.");
}

if (data.fileStoreKey) data.file_store_key = data.fileStoreKey;

if (data.imageFile) {
const filePath = checkTmp(data.imageFile);
const file = fs.readFileSync(filePath);
const { key } = await jigsawstack.uploadFile({
headers: {
"Content-Type": mime.getType(filePath),
},
data: file,
});
data.file_store_key = key;
}

try {
const response = await jigsawstack.detectObjectsInImage({
$,
data,
});
$.export("$summary", "Successfully detected objects in the image");
return response;

} catch (e) {
return throwError(e);
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { throwError } from "../../common/utils.mjs";
import jigsawstack from "../../jigsawstack.app.mjs";

export default {
key: "jigsawstack-sentiment-analysis",
name: "Sentiment Analysis",
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)",
version: "0.0.1",
type: "action",
props: {
jigsawstack,
text: {
type: "string",
label: "Text",
description: "The text to analyze for sentiment.",
},
},
async run({ $ }) {
try {
const response = await this.jigsawstack.analyzeSentiment({
$,
data: {
text: this.text,
},
});

$.export("$summary", `Successfully analyzed sentiment with emotion: ${response.sentiment.emotion} and sentiment: ${response.sentiment.sentiment}`);
return response;
} catch (e) {
return throwError(e);
}
},
};
33 changes: 33 additions & 0 deletions components/jigsawstack/actions/verify-email/verify-email.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { throwError } from "../../common/utils.mjs";
import jigsawstack from "../../jigsawstack.app.mjs";

export default {
key: "jigsawstack-verify-email",
name: "Verify Email",
description: "Validate any email address and determine deliverability as well as disposable status. [See the documentation](https://docs.jigsawstack.com/api-reference/validate/email)",
version: "0.0.1",
type: "action",
props: {
jigsawstack,
email: {
type: "string",
label: "Email Address",
description: "The email address to validate.",
},
},
async run({ $ }) {
try {
const response = await this.jigsawstack.validateEmail({
$,
params: {
email: this.email,
},
});

$.export("$summary", `Successfully validated email: ${this.email}`);
return response;
} catch (e) {
return throwError(e);
}
},
};
13 changes: 13 additions & 0 deletions components/jigsawstack/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ConfigurationError } from "@pipedream/platform";

export const throwError = ({ message }) => {
const errorMessage = JSON.parse(message).message;
throw new ConfigurationError(errorMessage);
};

export const checkTmp = (filename) => {
if (!filename.startsWith("/tmp")) {
return `/tmp/${filename}`;
}
return filename;
};
53 changes: 48 additions & 5 deletions components/jigsawstack/jigsawstack.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "jigsawstack",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.jigsawstack.com/v1";
},
_headers(headers = {}) {
return {
"x-api-key": this.$auth.api_key,
...headers,
};
},
_makeRequest({
$ = this, path, headers, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(headers),
...opts,
});
},
validateEmail(opts = {}) {
return this._makeRequest({
method: "GET",
path: "/validate/email",
...opts,
});
},
detectObjectsInImage(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/ai/object_detection",
...opts,
});
},
analyzeSentiment(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/ai/sentiment",
...opts,
});
},
uploadFile(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/store/file",
...opts,
});
},
},
};
};
9 changes: 7 additions & 2 deletions components/jigsawstack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/jigsawstack",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream JigsawStack Components",
"main": "jigsawstack.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,10 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.1",
"form-data": "^4.0.0",
"mime": "^4.0.4"
}
}
}
15 changes: 14 additions & 1 deletion pnpm-lock.yaml

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