From 63f0a351ba3d8208e9b9d0041ca8485e1a9a4957 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 27 Sep 2023 09:54:30 -0300 Subject: [PATCH 1/5] Added actions --- components/translate_com/.gitignore | 3 -- .../actions/translate-text/translate-text.mjs | 50 +++++++++++++++++ .../translate_com/app/translate_com.app.ts | 13 ----- components/translate_com/package.json | 5 +- .../translate_com/translate_com.app.mjs | 54 +++++++++++++++++++ pnpm-lock.yaml | 2 + 6 files changed, 108 insertions(+), 19 deletions(-) delete mode 100644 components/translate_com/.gitignore create mode 100644 components/translate_com/actions/translate-text/translate-text.mjs delete mode 100644 components/translate_com/app/translate_com.app.ts create mode 100644 components/translate_com/translate_com.app.mjs diff --git a/components/translate_com/.gitignore b/components/translate_com/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/translate_com/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/translate_com/actions/translate-text/translate-text.mjs b/components/translate_com/actions/translate-text/translate-text.mjs new file mode 100644 index 0000000000000..711cd94626448 --- /dev/null +++ b/components/translate_com/actions/translate-text/translate-text.mjs @@ -0,0 +1,50 @@ +import app from "../../translate_com.app.mjs"; + +export default { + name: "Translate Text", + version: "0.0.2", + key: "translate_com-translate-text", + description: "Translante a text using machine. [See the documentation](https://translation-api.translate.com/api/documentation?_gl=1*1qes1da*_ga*MTMwNzkzMTg3OC4xNjk1NDE3MDIy*_ga_T51KL347BB*MTY5NTQxNzAyMS4xLjAuMTY5NTQxNzAyMS42MC4wLjA.#/Machine Translation)", + type: "action", + props: { + app, + sourceLanguage: { + label: "Source language", + description: "The language of the source text", + propDefinition: [ + app, + "language", + ], + }, + translationLanguage: { + type: "string", + label: "Translation language", + description: "The translation language", + propDefinition: [ + app, + "language", + ], + }, + text: { + type: "string", + label: "Text", + description: "Text to be translated", + }, + }, + async run({ $ }) { + const response = await this.app.transateText({ + $, + data: { + source_language: this.sourceLanguage, + translation_language: this.translationLanguage, + text: this.text, + }, + }); + + if (response) { + $.export("$summary", "Successfully translated text"); + } + + return response; + }, +}; diff --git a/components/translate_com/app/translate_com.app.ts b/components/translate_com/app/translate_com.app.ts deleted file mode 100644 index ae5c1565ba146..0000000000000 --- a/components/translate_com/app/translate_com.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "translate_com", - propDefinitions: {}, - methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); - }, - }, -}); \ No newline at end of file diff --git a/components/translate_com/package.json b/components/translate_com/package.json index 08681f6771b18..ee0ba95b6b419 100644 --- a/components/translate_com/package.json +++ b/components/translate_com/package.json @@ -1,13 +1,12 @@ { "name": "@pipedream/translate_com", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Translate.com Components", - "main": "dist/app/translate_com.app.mjs", + "main": "translate_com.app.mjs", "keywords": [ "pipedream", "translate_com" ], - "files": ["dist"], "homepage": "https://pipedream.com/apps/translate_com", "author": "Pipedream (https://pipedream.com/)", "publishConfig": { diff --git a/components/translate_com/translate_com.app.mjs b/components/translate_com/translate_com.app.mjs new file mode 100644 index 0000000000000..a580468b7b4bb --- /dev/null +++ b/components/translate_com/translate_com.app.mjs @@ -0,0 +1,54 @@ +import { axios } from "@pipedream/platform"; + +export default { + type: "app", + app: "translate_com", + propDefinitions: { + language: { + type: "string", + label: "Language", + description: "A language", + async options() { + const languages = await this.getLanguages(); + + return languages.map((language) => ({ + value: language.code, + label: language.name, + })); + }, + }, + }, + methods: { + _apiKey() { + return this.$auth.api_key; + }, + _apiUrl() { + return "https://translation-api.translate.com/translate/v1"; + }, + async _makeRequest({ + $ = this, path, ...args + }) { + return axios($, { + url: `${this._apiUrl()}${path}`, + ...args, + headers: { + ...args.headers, + "x-api-key": this._apiKey(), + }, + }); + }, + async transateText(args = {}) { + return this._makeRequest({ + path: "/mt", + method: "post", + ...args, + }); + }, + async getLanguages(args = {}) { + return this._makeRequest({ + path: "/mt-langs", + ...args, + }); + }, + }, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 30d5c3efc3297..2bbd4815bca66 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3261,6 +3261,8 @@ importers: components/mode: {} + components/modeck: {} + components/mojo_helpdesk: dependencies: '@pipedream/platform': From 2d1380a7a65aa4b75b8eb72bac6fa49afc5ba458 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 27 Sep 2023 10:32:03 -0300 Subject: [PATCH 2/5] Fixed some bugs --- .../translate_com/actions/translate-text/translate-text.mjs | 2 +- components/translate_com/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/translate_com/actions/translate-text/translate-text.mjs b/components/translate_com/actions/translate-text/translate-text.mjs index 711cd94626448..e4c448945126d 100644 --- a/components/translate_com/actions/translate-text/translate-text.mjs +++ b/components/translate_com/actions/translate-text/translate-text.mjs @@ -2,7 +2,7 @@ import app from "../../translate_com.app.mjs"; export default { name: "Translate Text", - version: "0.0.2", + version: "0.0.1", key: "translate_com-translate-text", description: "Translante a text using machine. [See the documentation](https://translation-api.translate.com/api/documentation?_gl=1*1qes1da*_ga*MTMwNzkzMTg3OC4xNjk1NDE3MDIy*_ga_T51KL347BB*MTY5NTQxNzAyMS4xLjAuMTY5NTQxNzAyMS42MC4wLjA.#/Machine Translation)", type: "action", diff --git a/components/translate_com/package.json b/components/translate_com/package.json index ee0ba95b6b419..a39a86c143fc5 100644 --- a/components/translate_com/package.json +++ b/components/translate_com/package.json @@ -12,4 +12,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} From 760cd656af40235b6ac44a39612e0468cef40480 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 27 Sep 2023 11:38:23 -0300 Subject: [PATCH 3/5] Update components/translate_com/translate_com.app.mjs Co-authored-by: Jorge Cortes --- components/translate_com/translate_com.app.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/translate_com/translate_com.app.mjs b/components/translate_com/translate_com.app.mjs index a580468b7b4bb..efa24da410a04 100644 --- a/components/translate_com/translate_com.app.mjs +++ b/components/translate_com/translate_com.app.mjs @@ -37,7 +37,7 @@ export default { }, }); }, - async transateText(args = {}) { + translateText(args = {}) { return this._makeRequest({ path: "/mt", method: "post", From 5d4178b134955039a3ef8166f02be7f79f0f5179 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 27 Sep 2023 11:38:28 -0300 Subject: [PATCH 4/5] Update components/translate_com/translate_com.app.mjs Co-authored-by: Jorge Cortes --- components/translate_com/translate_com.app.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/translate_com/translate_com.app.mjs b/components/translate_com/translate_com.app.mjs index efa24da410a04..5157f5cd1838d 100644 --- a/components/translate_com/translate_com.app.mjs +++ b/components/translate_com/translate_com.app.mjs @@ -44,7 +44,7 @@ export default { ...args, }); }, - async getLanguages(args = {}) { + getLanguages(args = {}) { return this._makeRequest({ path: "/mt-langs", ...args, From 63f3f5c82d2167cd64c0d3541e0f154ef854d54d Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 27 Sep 2023 11:38:35 -0300 Subject: [PATCH 5/5] Update components/translate_com/actions/translate-text/translate-text.mjs Co-authored-by: Jorge Cortes --- .../translate_com/actions/translate-text/translate-text.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/translate_com/actions/translate-text/translate-text.mjs b/components/translate_com/actions/translate-text/translate-text.mjs index e4c448945126d..edf64b5f3424c 100644 --- a/components/translate_com/actions/translate-text/translate-text.mjs +++ b/components/translate_com/actions/translate-text/translate-text.mjs @@ -32,7 +32,7 @@ export default { }, }, async run({ $ }) { - const response = await this.app.transateText({ + const response = await this.app.translateText({ $, data: { source_language: this.sourceLanguage,