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
110 changes: 110 additions & 0 deletions components/goformz/actions/create-form/create-form.mjs
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;
},
};
25 changes: 25 additions & 0 deletions components/goformz/common/utils.mjs
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;
};
131 changes: 127 additions & 4 deletions components/goformz/goformz.app.mjs
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,
})) || [];
},
},
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,
});
},
},
};
7 changes: 5 additions & 2 deletions components/goformz/package.json
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": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
}
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);
},
};
Loading
Loading