diff --git a/components/retool/.gitignore b/components/retool/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/retool/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/retool/actions/create-organization-user-attribute/create-organization-user-attribute.mjs b/components/retool/actions/create-organization-user-attribute/create-organization-user-attribute.mjs new file mode 100644 index 0000000000000..72b8fa7c2604e --- /dev/null +++ b/components/retool/actions/create-organization-user-attribute/create-organization-user-attribute.mjs @@ -0,0 +1,67 @@ +import app from "../../retool.app.mjs"; + +export default { + key: "retool-create-organization-user-attribute", + name: "Create Organization User Attribute", + description: "Create a new user attribute for the organization. [See the documentation](https://docs.retool.com/reference/api/v2#tag/User-Attributes/paths/~1user_attributes/post).", + version: "0.0.1", + type: "action", + props: { + app, + name: { + type: "string", + label: "Attribute Name", + description: "The name of the user attribute. Must be alphanumeric and without spaces.", + }, + label: { + type: "string", + label: "Attribute Label", + description: "A short description of the user attribute", + }, + dataType: { + type: "string", + label: "Data Type", + description: "The data type of the attribute", + options: [ + "string", + "json", + "number", + ], + }, + defaultValue: { + type: "string", + label: "Default Value", + description: "A default value to apply to users that don't have an attribute set", + optional: true, + }, + }, + methods: { + createOrgUserAttribute(args = {}) { + return this.app.post({ + path: "/user_attributes", + ...args, + }); + }, + }, + async run({ $ }) { + const { + createOrgUserAttribute, + name, + label, + dataType, + defaultValue, + } = this; + + const response = await createOrgUserAttribute({ + $, + data: { + name, + label, + dataType, + defaultValue, + }, + }); + $.export("$summary", `Successfully created organization user attribute with ID \`${response.data.id}\``); + return response; + }, +}; diff --git a/components/retool/actions/create-user/create-user.mjs b/components/retool/actions/create-user/create-user.mjs new file mode 100644 index 0000000000000..bde596f706340 --- /dev/null +++ b/components/retool/actions/create-user/create-user.mjs @@ -0,0 +1,86 @@ +import app from "../../retool.app.mjs"; +import constants from "../../common/constants.mjs"; + +export default { + key: "retool-create-user", + name: "Create User", + description: "Creates a new user. [See the documentation](https://docs.retool.com/reference/api/v2#tag/Users/paths/~1users/post).", + version: "0.0.1", + type: "action", + props: { + app, + email: { + type: "string", + label: "Email", + description: "The email of the user to be created.", + }, + firstName: { + type: "string", + label: "First Name", + description: "The first name of the user.", + }, + lastName: { + type: "string", + label: "Last Name", + description: "The last name of the user.", + }, + active: { + type: "boolean", + label: "Active", + description: "Whether the user should be active. Defaults to `true` if not provided.", + optional: true, + }, + metadata: { + type: "object", + label: "Metadata", + description: "Additional metadata to associate with the user.", + optional: true, + }, + userType: { + type: "string", + label: "User Type", + description: "The type of the user.", + optional: true, + options: [ + "default", + "mobile", + "embed", + ], + }, + }, + methods: { + createUser(args = {}) { + return this.app.post({ + versionPath: constants.VERSION_PATH.V2, + path: "/users", + ...args, + }); + }, + }, + async run({ $ }) { + const { + createUser, + email, + firstName, + lastName, + active, + metadata, + userType, + } = this; + + const response = await createUser({ + $, + data: { + email, + first_name: firstName, + last_name: lastName, + active, + metadata, + user_type: userType, + }, + }); + + $.export("$summary", `Successfully created user with ID \`${response.data.id}\`.`); + return response; + }, +}; diff --git a/components/retool/actions/trigger-workflow/trigger-workflow.mjs b/components/retool/actions/trigger-workflow/trigger-workflow.mjs new file mode 100644 index 0000000000000..9b3357db70a0a --- /dev/null +++ b/components/retool/actions/trigger-workflow/trigger-workflow.mjs @@ -0,0 +1,61 @@ +import app from "../../retool.app.mjs"; +import constants from "../../common/constants.mjs"; + +export default { + key: "retool-trigger-workflow", + name: "Trigger Workflow", + description: "Trigger a workflow. [See the documentation](https://docs.retool.com/workflows/guides/webhooks#send-a-webhook-event).", + version: "0.0.1", + type: "action", + props: { + app, + workflowId: { + type: "string", + label: "Workflow ID", + description: "The unique identifier for the workflow you want to trigger.", + }, + apiKey: { + type: "string", + label: "API Key", + description: "The API key of the workflow you want to trigger. You can find it in the webhook settings of the workflow.", + }, + data: { + type: "object", + label: "Input Parameters", + description: "The input parameters to pass to the workflow, if any.", + optional: true, + }, + }, + methods: { + triggerWorkflow({ + workflowId, apiKey, ...args + }) { + return this.app.post({ + versionPath: constants.VERSION_PATH.V2, + path: `/workflows/${workflowId}/startTrigger`, + headers: { + "Content-Type": "application/json", + "X-Workflow-Api-Key": apiKey, + }, + ...args, + }); + }, + }, + async run({ $ }) { + const { + triggerWorkflow, + workflowId, + apiKey, + data, + } = this; + + const response = await triggerWorkflow({ + $, + workflowId, + apiKey, + data, + }); + $.export("$summary", "Successfully triggered workflow"); + return response; + }, +}; diff --git a/components/retool/app/retool.app.ts b/components/retool/app/retool.app.ts deleted file mode 100644 index 90ebcff256942..0000000000000 --- a/components/retool/app/retool.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "retool", - 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/retool/common/constants.mjs b/components/retool/common/constants.mjs new file mode 100644 index 0000000000000..5b1046db661b5 --- /dev/null +++ b/components/retool/common/constants.mjs @@ -0,0 +1,10 @@ +const BASE_URL = "https://api.retool.com"; +const VERSION_PATH = { + V1: "/v1", + V2: "/api/v2", +}; + +export default { + BASE_URL, + VERSION_PATH, +}; diff --git a/components/retool/package.json b/components/retool/package.json index 96ac5d3393259..16fae1623c9c0 100644 --- a/components/retool/package.json +++ b/components/retool/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/retool", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Retool Components", "main": "dist/app/retool.app.mjs", "keywords": [ diff --git a/components/retool/retool.app.mjs b/components/retool/retool.app.mjs new file mode 100644 index 0000000000000..2401f6e1a338d --- /dev/null +++ b/components/retool/retool.app.mjs @@ -0,0 +1,35 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + +export default { + type: "app", + app: "retool", + methods: { + getUrl(path, versionPath = constants.VERSION_PATH.V2) { + return `${constants.BASE_URL}${versionPath}${path}`; + }, + getHeaders(headers) { + return { + Authorization: `Bearer ${this.$auth.access_token}`, + Accept: "application/json", + ...headers, + }; + }, + _makeRequest({ + $ = this, path, headers, versionPath, ...args + } = {}) { + return axios($, { + ...args, + debug: true, + url: this.getUrl(path, versionPath), + headers: this.getHeaders(headers), + }); + }, + post(args = {}) { + return this._makeRequest({ + method: "POST", + ...args, + }); + }, + }, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 24eeae7eebb45..6bc5b49bed04b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35757,8 +35757,6 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) - transitivePeerDependencies: - - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: