-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - goformz #17378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - goformz #17378
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| })) || []; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| 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, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.1.0" | ||
| } | ||
| } | ||
| } | ||
68 changes: 68 additions & 0 deletions
68
components/goformz/sources/new-form-completed/new-form-completed.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| }, | ||
| }; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.