From 87dd5944a4f0871684f325c0deaafcf50d0caca9 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Tue, 1 Jul 2025 10:44:50 -0400 Subject: [PATCH 1/2] new components --- .../actions/create-form/create-form.mjs | 110 +++++++++++++++ components/goformz/common/utils.mjs | 25 ++++ components/goformz/goformz.app.mjs | 131 +++++++++++++++++- components/goformz/package.json | 7 +- .../new-form-completed/new-form-completed.mjs | 68 +++++++++ 5 files changed, 335 insertions(+), 6 deletions(-) create mode 100644 components/goformz/actions/create-form/create-form.mjs create mode 100644 components/goformz/common/utils.mjs create mode 100644 components/goformz/sources/new-form-completed/new-form-completed.mjs diff --git a/components/goformz/actions/create-form/create-form.mjs b/components/goformz/actions/create-form/create-form.mjs new file mode 100644 index 0000000000000..a918d621b219d --- /dev/null +++ b/components/goformz/actions/create-form/create-form.mjs @@ -0,0 +1,110 @@ +import goformz from "../../goformz.app.mjs"; +import { parseObject } from "../../common/utils.mjs"; +import { ConfigurationError } from "@pipedream/platform"; + +export default { + key: "goformz-create-form", + name: "Create Form", + description: "Create a new form in GoFormz. [See the documentation](https://developers.goformz.com/reference/create-a-form)", + version: "0.0.1", + type: "action", + props: { + goformz, + name: { + type: "string", + label: "Name", + description: "The name of the form", + }, + templateId: { + propDefinition: [ + goformz, + "templateId", + ], + reloadProps: true, + }, + userId: { + propDefinition: [ + goformz, + "userId", + ], + optional: true, + }, + groupId: { + propDefinition: [ + goformz, + "groupId", + ], + optional: true, + }, + overrideDefaultFormName: { + type: "boolean", + label: "Override Default Form Name", + description: "Set to `true` to override the automatic form name rules", + optional: true, + default: false, + }, + }, + async additionalProps() { + const props = {}; + if (!this.templateId) { + return props; + } + props["alert"] = { + type: "alert", + alertType: "info", + content: "See the [Form Field Reference](https://developers.goformz.com/reference/form-field-reference) for more information about form field types", + }; + const { fields } = await this.goformz.getTemplate({ + templateId: this.templateId, + }); + for (const field of Object.values(fields)) { + props[field.id] = { + type: "object", + label: field.name, + description: `Value for ${field.name}. Type: ${field.type}`, + optional: true, + }; + } + return props; + }, + async run({ $ }) { + if (!this.userId && !this.groupId) { + throw new ConfigurationError("Form must be assigned to a User or Group"); + } + if (this.userId && this.groupId) { + throw new ConfigurationError("Form can only be assigned to one of User or Group"); + } + + const assignment = this.userId + ? { + id: this.userId, + type: "User", + } + : { + id: this.groupId, + type: "Group", + }; + + const { fields } = await this.goformz.getTemplate({ + templateId: this.templateId, + }); + + const fieldProps = {}; + for (const field of Object.values(fields)) { + fieldProps[field.name] = parseObject(this[field.id]); + } + + const response = await this.goformz.createForm({ + $, + data: { + name: this.name, + overrideDefaultFormName: this.overrideDefaultFormName, + templateId: this.templateId, + assignment, + fields: fieldProps, + }, + }); + $.export("$summary", `Successfully created form with ID: ${response.id}`); + return response; + }, +}; diff --git a/components/goformz/common/utils.mjs b/components/goformz/common/utils.mjs new file mode 100644 index 0000000000000..e51d69347bc84 --- /dev/null +++ b/components/goformz/common/utils.mjs @@ -0,0 +1,25 @@ +export const parseObject = (obj) => { + if (!obj) { + return undefined; + } + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch (error) { + return obj; + } + } + if (Array.isArray(obj)) { + return obj.map(parseObject); + } + if (typeof obj === "object") { + return Object.fromEntries(Object.entries(obj).map(([ + key, + value, + ]) => [ + key, + parseObject(value), + ])); + } + return obj; +}; diff --git a/components/goformz/goformz.app.mjs b/components/goformz/goformz.app.mjs index e3faeb0b29de4..e61eb72a368a9 100644 --- a/components/goformz/goformz.app.mjs +++ b/components/goformz/goformz.app.mjs @@ -1,11 +1,134 @@ +import { axios } from "@pipedream/platform"; +const DEFAULT_PAGE_SIZE = 25; + export default { type: "app", app: "goformz", - propDefinitions: {}, + propDefinitions: { + templateId: { + type: "string", + label: "Template ID", + description: "The ID of the template to use for the form", + async options({ page }) { + const templates = await this.listTemplates({ + params: { + pageSize: DEFAULT_PAGE_SIZE, + pageNumber: page + 1, + }, + }); + return templates?.map((template) => ({ + label: template.name, + value: template.id, + })) || []; + }, + }, + userId: { + type: "string", + label: "User ID", + description: "The ID of the user to assign the form to", + async options({ page }) { + const users = await this.listUsers({ + params: { + pageSize: DEFAULT_PAGE_SIZE, + pageNumber: page + 1, + }, + }); + return users?.map((user) => ({ + label: user.username, + value: user.id, + })) || []; + }, + }, + groupId: { + type: "string", + label: "Group ID", + description: "The ID of the group to assign the form to", + async options({ page }) { + const groups = await this.listGroups({ + params: { + pageSize: DEFAULT_PAGE_SIZE, + pageNumber: page + 1, + }, + }); + return groups?.map((group) => ({ + label: group.name, + value: group.id, + })) || []; + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.goformz.com/v2"; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + "Content-Type": "application/json", + }, + ...opts, + }); + }, + createWebhook(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/webhooks", + ...opts, + }); + }, + deleteWebhook({ + hookId, ...opts + }) { + return this._makeRequest({ + method: "DELETE", + path: `/webhooks/${hookId}`, + ...opts, + }); + }, + getTemplate({ + templateId, ...opts + }) { + return this._makeRequest({ + path: `/templates/${templateId}`, + ...opts, + }); + }, + getForm({ + formId, ...opts + }) { + return this._makeRequest({ + path: `/formz/${formId}`, + ...opts, + }); + }, + listTemplates(opts = {}) { + return this._makeRequest({ + path: "/templates", + ...opts, + }); + }, + listUsers(opts = {}) { + return this._makeRequest({ + path: "/users", + ...opts, + }); + }, + listGroups(opts = {}) { + return this._makeRequest({ + path: "/groups", + ...opts, + }); + }, + createForm( opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/formz", + ...opts, + }); }, }, }; diff --git a/components/goformz/package.json b/components/goformz/package.json index 3eb77b622a6d7..4beb0c1fe2b67 100644 --- a/components/goformz/package.json +++ b/components/goformz/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/goformz", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream GoFormz Components", "main": "goformz.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } -} \ No newline at end of file +} diff --git a/components/goformz/sources/new-form-completed/new-form-completed.mjs b/components/goformz/sources/new-form-completed/new-form-completed.mjs new file mode 100644 index 0000000000000..5753ceae68e63 --- /dev/null +++ b/components/goformz/sources/new-form-completed/new-form-completed.mjs @@ -0,0 +1,68 @@ +import goformz from "../../goformz.app.mjs"; + +export default { + key: "goformz-new-form-completed", + name: "New Form Completed", + description: "Emit new event when a new form is completed in GoFormz", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + goformz, + db: "$.service.db", + http: "$.interface.http", + templateId: { + propDefinition: [ + goformz, + "templateId", + ], + description: "The ID of the template to watch for form completions", + }, + }, + hooks: { + async activate() { + const { id } = await this.goformz.createWebhook({ + data: { + eventType: "form.complete", + targetUrl: this.http.endpoint, + entityId: this.templateId, + }, + }); + this._setHookId(id); + }, + async deactivate() { + const hookId = this._getHookId(); + if (hookId) { + await this.goformz.deleteWebhook({ + hookId, + }); + } + }, + }, + methods: { + _getHookId() { + return this.db.get("hookId"); + }, + _setHookId(hookId) { + this.db.set("hookId", hookId); + }, + generateMeta(form) { + return { + id: form.formId, + summary: `New Form Completed: ${form.name}`, + ts: Date.now(), + }; + }, + }, + async run(event) { + const { body } = event; + if (!body) { + return; + } + const form = await this.goformz.getForm({ + formId: body.Item.Id, + }); + const meta = this.generateMeta(form); + this.$emit(form, meta); + }, +}; From a898da902efb1e8fe440fc12c36ed0f73784951b Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Tue, 1 Jul 2025 10:45:29 -0400 Subject: [PATCH 2/2] pnpm-lock.yaml --- pnpm-lock.yaml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ca0a6e13fd61f..d5695d5dc2215 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5402,7 +5402,11 @@ importers: components/godial: {} - components/goformz: {} + components/goformz: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/gohighlevel: dependencies: @@ -29612,22 +29616,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - deprecated: Please downgrade to v7.1.5 if you need IE/ActiveXObject support OR upgrade to v8.0.0 as we no longer support IE and published an incorrect patch version (see https://github.com/visionmedia/superagent/issues/1731) + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net supports-color@2.0.0: resolution: {integrity: sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==}