@pipedream/form_io 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions/create-form/create-form.mjs +101 -0
- package/actions/create-form-action/create-form-action.mjs +89 -0
- package/actions/create-role/create-role.mjs +49 -0
- package/actions/create-submission/create-submission.mjs +48 -0
- package/actions/delete-form/delete-form.mjs +33 -0
- package/actions/delete-form-action/delete-form-action.mjs +45 -0
- package/actions/delete-role/delete-role.mjs +33 -0
- package/actions/delete-submission/delete-submission.mjs +45 -0
- package/actions/get-form/get-form.mjs +33 -0
- package/actions/get-form-action/get-form-action.mjs +45 -0
- package/actions/get-role/get-role.mjs +33 -0
- package/actions/get-submission/get-submission.mjs +45 -0
- package/actions/list-form-actions/list-form-actions.mjs +67 -0
- package/actions/list-forms/list-forms.mjs +79 -0
- package/actions/list-roles/list-roles.mjs +59 -0
- package/actions/list-submissions/list-submissions.mjs +87 -0
- package/actions/update-form/update-form.mjs +113 -0
- package/actions/update-form-action/update-form-action.mjs +93 -0
- package/actions/update-role/update-role.mjs +76 -0
- package/actions/update-submission/update-submission.mjs +64 -0
- package/common/constants.mjs +24 -0
- package/common/utils.mjs +75 -0
- package/form_io.app.mjs +371 -4
- package/package.json +4 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import formIo from "../../form_io.app.mjs";
|
|
2
|
+
import { pluckFields } from "../../common/utils.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "form_io-list-forms",
|
|
6
|
+
name: "List Forms",
|
|
7
|
+
description: "List forms and resources in the Form.io project. Optionally filter by `type` to return only forms or only resources. Form.io returns up to `limit` records (default 10); if you receive a full page there may be more — raise `limit` (up to 1000) or page with `skip` to retrieve them all. Forms are large; pass `fields` to return only the fields you need (e.g. `_id`, `title`, `name`, `path`). [See the documentation](https://apidocs.form.io/#40baaaa1-c309-4f81-a546-6821cec14701).",
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
type: "action",
|
|
10
|
+
ai: "optimized",
|
|
11
|
+
annotations: {
|
|
12
|
+
readOnlyHint: true,
|
|
13
|
+
destructiveHint: false,
|
|
14
|
+
openWorldHint: true,
|
|
15
|
+
},
|
|
16
|
+
props: {
|
|
17
|
+
formIo,
|
|
18
|
+
type: {
|
|
19
|
+
propDefinition: [
|
|
20
|
+
formIo,
|
|
21
|
+
"type",
|
|
22
|
+
],
|
|
23
|
+
description: "Filter by form type. One of `form` or `resource`. Omit to return both.",
|
|
24
|
+
},
|
|
25
|
+
limit: {
|
|
26
|
+
propDefinition: [
|
|
27
|
+
formIo,
|
|
28
|
+
"limit",
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
skip: {
|
|
32
|
+
propDefinition: [
|
|
33
|
+
formIo,
|
|
34
|
+
"skip",
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
sort: {
|
|
38
|
+
propDefinition: [
|
|
39
|
+
formIo,
|
|
40
|
+
"sort",
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
fields: {
|
|
44
|
+
propDefinition: [
|
|
45
|
+
formIo,
|
|
46
|
+
"fields",
|
|
47
|
+
],
|
|
48
|
+
description: "Optional. Return only these top-level fields from each form (e.g. `_id`, `title`, `name`, `path`, `type`). Omit to return the full form objects, which include the large `components` and `access` arrays.",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
async run({ $ }) {
|
|
52
|
+
const {
|
|
53
|
+
type,
|
|
54
|
+
limit,
|
|
55
|
+
skip,
|
|
56
|
+
sort,
|
|
57
|
+
fields,
|
|
58
|
+
} = this;
|
|
59
|
+
|
|
60
|
+
const response = await this.formIo.listForms({
|
|
61
|
+
$,
|
|
62
|
+
params: {
|
|
63
|
+
type,
|
|
64
|
+
limit,
|
|
65
|
+
skip,
|
|
66
|
+
sort,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const forms = Array.isArray(response)
|
|
71
|
+
? response
|
|
72
|
+
: response?.data ?? [];
|
|
73
|
+
|
|
74
|
+
$.export("$summary", `Retrieved ${forms.length} form(s)`);
|
|
75
|
+
return fields?.length
|
|
76
|
+
? pluckFields(forms, fields)
|
|
77
|
+
: response;
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import formIo from "../../form_io.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
key: "form_io-list-roles",
|
|
5
|
+
name: "List Roles",
|
|
6
|
+
description: "List all roles in the Form.io project, including the built-in Administrator, Authenticated, and Anonymous roles. Form.io returns up to `limit` records (default 10); if you receive a full page there may be more — raise `limit` (up to 1000) or page with `skip` to retrieve them all. [See the documentation](https://apidocs.form.io/#8ecd0673-9088-4157-ae0d-161f93d090fb).",
|
|
7
|
+
version: "0.0.1",
|
|
8
|
+
type: "action",
|
|
9
|
+
ai: "optimized",
|
|
10
|
+
annotations: {
|
|
11
|
+
readOnlyHint: true,
|
|
12
|
+
destructiveHint: false,
|
|
13
|
+
openWorldHint: true,
|
|
14
|
+
},
|
|
15
|
+
props: {
|
|
16
|
+
formIo,
|
|
17
|
+
limit: {
|
|
18
|
+
propDefinition: [
|
|
19
|
+
formIo,
|
|
20
|
+
"limit",
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
skip: {
|
|
24
|
+
propDefinition: [
|
|
25
|
+
formIo,
|
|
26
|
+
"skip",
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
sort: {
|
|
30
|
+
propDefinition: [
|
|
31
|
+
formIo,
|
|
32
|
+
"sort",
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
async run({ $ }) {
|
|
37
|
+
const {
|
|
38
|
+
limit,
|
|
39
|
+
skip,
|
|
40
|
+
sort,
|
|
41
|
+
} = this;
|
|
42
|
+
|
|
43
|
+
const response = await this.formIo.listRoles({
|
|
44
|
+
$,
|
|
45
|
+
params: {
|
|
46
|
+
limit,
|
|
47
|
+
skip,
|
|
48
|
+
sort,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const roles = Array.isArray(response)
|
|
53
|
+
? response
|
|
54
|
+
: response?.data ?? [];
|
|
55
|
+
|
|
56
|
+
$.export("$summary", `Retrieved ${roles.length} role(s)`);
|
|
57
|
+
return response;
|
|
58
|
+
},
|
|
59
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import formIo from "../../form_io.app.mjs";
|
|
2
|
+
import { pluckFields } from "../../common/utils.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "form_io-list-submissions",
|
|
6
|
+
name: "List Submissions",
|
|
7
|
+
description: "List submissions for a Form.io form. Optionally filter by state. Use **List Forms** to find the form ID. Form.io returns up to `limit` records (default 10); if you receive a full page there may be more — raise `limit` (up to 1000) or page with `skip` to retrieve them all. Pass `fields` to return only the fields you need (e.g. `_id`, `data`, `created`). [See the documentation](https://apidocs.form.io/#1f207caa-9d04-3e81-2973-e4bf82ee5190).",
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
type: "action",
|
|
10
|
+
ai: "optimized",
|
|
11
|
+
annotations: {
|
|
12
|
+
readOnlyHint: true,
|
|
13
|
+
destructiveHint: false,
|
|
14
|
+
openWorldHint: true,
|
|
15
|
+
},
|
|
16
|
+
props: {
|
|
17
|
+
formIo,
|
|
18
|
+
formId: {
|
|
19
|
+
propDefinition: [
|
|
20
|
+
formIo,
|
|
21
|
+
"formId",
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
state: {
|
|
25
|
+
propDefinition: [
|
|
26
|
+
formIo,
|
|
27
|
+
"state",
|
|
28
|
+
],
|
|
29
|
+
description: "Filter by submission state. One of `submitted` or `draft`.",
|
|
30
|
+
},
|
|
31
|
+
sort: {
|
|
32
|
+
propDefinition: [
|
|
33
|
+
formIo,
|
|
34
|
+
"sort",
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
limit: {
|
|
38
|
+
propDefinition: [
|
|
39
|
+
formIo,
|
|
40
|
+
"limit",
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
skip: {
|
|
44
|
+
propDefinition: [
|
|
45
|
+
formIo,
|
|
46
|
+
"skip",
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
fields: {
|
|
50
|
+
propDefinition: [
|
|
51
|
+
formIo,
|
|
52
|
+
"fields",
|
|
53
|
+
],
|
|
54
|
+
description: "Optional. Return only these top-level fields from each submission (e.g. `_id`, `data`, `created`, `state`). Omit to return the full submission objects, which include access and metadata envelopes.",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
async run({ $ }) {
|
|
58
|
+
const {
|
|
59
|
+
formId,
|
|
60
|
+
state,
|
|
61
|
+
sort,
|
|
62
|
+
limit,
|
|
63
|
+
skip,
|
|
64
|
+
fields,
|
|
65
|
+
} = this;
|
|
66
|
+
|
|
67
|
+
const response = await this.formIo.listSubmissions({
|
|
68
|
+
$,
|
|
69
|
+
formId,
|
|
70
|
+
params: {
|
|
71
|
+
state,
|
|
72
|
+
sort,
|
|
73
|
+
limit,
|
|
74
|
+
skip,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const submissions = Array.isArray(response)
|
|
79
|
+
? response
|
|
80
|
+
: response?.data ?? [];
|
|
81
|
+
|
|
82
|
+
$.export("$summary", `Retrieved ${submissions.length} submission(s)`);
|
|
83
|
+
return fields?.length
|
|
84
|
+
? pluckFields(submissions, fields)
|
|
85
|
+
: response;
|
|
86
|
+
},
|
|
87
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import formIo from "../../form_io.app.mjs";
|
|
2
|
+
import { parseJson } from "../../common/utils.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "form_io-update-form",
|
|
6
|
+
name: "Update Form",
|
|
7
|
+
description: "Update a form or resource in Form.io. Only the fields you provide are changed; omitted fields keep their current values. Use **List Forms** to find the form ID. The `components` prop is a JSON-string array of Form.io component schema objects. [See the documentation](https://apidocs.form.io/#9faa123a-3183-4513-9ae5-c64553359749).",
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
type: "action",
|
|
10
|
+
ai: "optimized",
|
|
11
|
+
annotations: {
|
|
12
|
+
readOnlyHint: false,
|
|
13
|
+
destructiveHint: false,
|
|
14
|
+
openWorldHint: true,
|
|
15
|
+
},
|
|
16
|
+
props: {
|
|
17
|
+
formIo,
|
|
18
|
+
formId: {
|
|
19
|
+
propDefinition: [
|
|
20
|
+
formIo,
|
|
21
|
+
"formId",
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
title: {
|
|
25
|
+
propDefinition: [
|
|
26
|
+
formIo,
|
|
27
|
+
"title",
|
|
28
|
+
],
|
|
29
|
+
description: "Updated title of the form.",
|
|
30
|
+
optional: true,
|
|
31
|
+
},
|
|
32
|
+
name: {
|
|
33
|
+
propDefinition: [
|
|
34
|
+
formIo,
|
|
35
|
+
"name",
|
|
36
|
+
],
|
|
37
|
+
description: "Updated machine name of the form.",
|
|
38
|
+
optional: true,
|
|
39
|
+
},
|
|
40
|
+
path: {
|
|
41
|
+
propDefinition: [
|
|
42
|
+
formIo,
|
|
43
|
+
"path",
|
|
44
|
+
],
|
|
45
|
+
description: "Updated URL path for the form.",
|
|
46
|
+
optional: true,
|
|
47
|
+
},
|
|
48
|
+
type: {
|
|
49
|
+
propDefinition: [
|
|
50
|
+
formIo,
|
|
51
|
+
"type",
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
components: {
|
|
55
|
+
propDefinition: [
|
|
56
|
+
formIo,
|
|
57
|
+
"components",
|
|
58
|
+
],
|
|
59
|
+
description: "JSON-string array of Form.io component schema objects. Example: `[{\"type\":\"textfield\",\"key\":\"name\",\"label\":\"Full Name\",\"input\":true}]`. Parsed from a JSON string before sending.",
|
|
60
|
+
optional: true,
|
|
61
|
+
},
|
|
62
|
+
display: {
|
|
63
|
+
propDefinition: [
|
|
64
|
+
formIo,
|
|
65
|
+
"display",
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
tags: {
|
|
69
|
+
propDefinition: [
|
|
70
|
+
formIo,
|
|
71
|
+
"tags",
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
settings: {
|
|
75
|
+
propDefinition: [
|
|
76
|
+
formIo,
|
|
77
|
+
"settings",
|
|
78
|
+
],
|
|
79
|
+
description: "JSON-string object of form settings. Example: `{\"theme\":\"default\"}`.",
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
async run({ $ }) {
|
|
83
|
+
const {
|
|
84
|
+
formId,
|
|
85
|
+
title,
|
|
86
|
+
name,
|
|
87
|
+
path,
|
|
88
|
+
type,
|
|
89
|
+
components,
|
|
90
|
+
display,
|
|
91
|
+
tags,
|
|
92
|
+
settings,
|
|
93
|
+
} = this;
|
|
94
|
+
|
|
95
|
+
const response = await this.formIo.updateForm({
|
|
96
|
+
$,
|
|
97
|
+
formId,
|
|
98
|
+
data: {
|
|
99
|
+
title,
|
|
100
|
+
name,
|
|
101
|
+
path,
|
|
102
|
+
type,
|
|
103
|
+
components: parseJson(components, "components", "array"),
|
|
104
|
+
display,
|
|
105
|
+
tags,
|
|
106
|
+
settings: parseJson(settings, "settings", "object"),
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
$.export("$summary", `Updated form "${response.title}" (${response._id})`);
|
|
111
|
+
return response;
|
|
112
|
+
},
|
|
113
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import formIo from "../../form_io.app.mjs";
|
|
2
|
+
import { parseJson } from "../../common/utils.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "form_io-update-form-action",
|
|
6
|
+
name: "Update Form Action",
|
|
7
|
+
description: "Update an action attached to a Form.io form. Only the fields you provide are changed; omitted fields keep their current values. Use **List Form Actions** to find the action ID. The `settings` prop is a JSON-string object specific to the action type. [See the documentation](https://apidocs.form.io/#2b553c0c-f857-4bfc-8023-1ddd0fc216e9).",
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
type: "action",
|
|
10
|
+
ai: "optimized",
|
|
11
|
+
annotations: {
|
|
12
|
+
readOnlyHint: false,
|
|
13
|
+
destructiveHint: false,
|
|
14
|
+
openWorldHint: true,
|
|
15
|
+
},
|
|
16
|
+
props: {
|
|
17
|
+
formIo,
|
|
18
|
+
formId: {
|
|
19
|
+
propDefinition: [
|
|
20
|
+
formIo,
|
|
21
|
+
"formId",
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
actionId: {
|
|
25
|
+
propDefinition: [
|
|
26
|
+
formIo,
|
|
27
|
+
"actionId",
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
title: {
|
|
31
|
+
propDefinition: [
|
|
32
|
+
formIo,
|
|
33
|
+
"title",
|
|
34
|
+
],
|
|
35
|
+
description: "Updated title of the action.",
|
|
36
|
+
optional: true,
|
|
37
|
+
},
|
|
38
|
+
handler: {
|
|
39
|
+
propDefinition: [
|
|
40
|
+
formIo,
|
|
41
|
+
"handler",
|
|
42
|
+
],
|
|
43
|
+
optional: true,
|
|
44
|
+
},
|
|
45
|
+
method: {
|
|
46
|
+
propDefinition: [
|
|
47
|
+
formIo,
|
|
48
|
+
"method",
|
|
49
|
+
],
|
|
50
|
+
optional: true,
|
|
51
|
+
},
|
|
52
|
+
priority: {
|
|
53
|
+
propDefinition: [
|
|
54
|
+
formIo,
|
|
55
|
+
"priority",
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
settings: {
|
|
59
|
+
propDefinition: [
|
|
60
|
+
formIo,
|
|
61
|
+
"settings",
|
|
62
|
+
],
|
|
63
|
+
description: "JSON-string object of action-specific settings; the shape depends on the action type. Example (webhook action): `{\"method\":\"post\",\"url\":\"https://example.com/webhook\"}`. Parsed with JSON.parse() before sending.",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
async run({ $ }) {
|
|
67
|
+
const {
|
|
68
|
+
formId,
|
|
69
|
+
actionId,
|
|
70
|
+
title,
|
|
71
|
+
handler,
|
|
72
|
+
method,
|
|
73
|
+
priority,
|
|
74
|
+
settings,
|
|
75
|
+
} = this;
|
|
76
|
+
|
|
77
|
+
const response = await this.formIo.updateFormAction({
|
|
78
|
+
$,
|
|
79
|
+
formId,
|
|
80
|
+
actionId,
|
|
81
|
+
data: {
|
|
82
|
+
title,
|
|
83
|
+
handler,
|
|
84
|
+
method,
|
|
85
|
+
priority,
|
|
86
|
+
settings: parseJson(settings, "settings", "object"),
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
$.export("$summary", `Updated form action "${response.title}" (${response._id})`);
|
|
91
|
+
return response;
|
|
92
|
+
},
|
|
93
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ConfigurationError } from "@pipedream/platform";
|
|
2
|
+
import formIo from "../../form_io.app.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "form_io-update-role",
|
|
6
|
+
name: "Update Role",
|
|
7
|
+
description: "Update a role in the Form.io project. Only the fields you provide are changed; omitted fields keep their current values. Obtain the role ID from **List Roles** (it is the role's 24-character hex `_id`, e.g. `64f8a1b2c3d4e5f60718293a`). Example: for `roleId` `64f8a1b2c3d4e5f60718293a`, set description to `Read-only reviewer` → returns the updated role. [See the documentation](https://apidocs.form.io/#6ad0536d-1927-41c5-b406-956ac736f9e5).",
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
type: "action",
|
|
10
|
+
ai: "optimized",
|
|
11
|
+
annotations: {
|
|
12
|
+
readOnlyHint: false,
|
|
13
|
+
destructiveHint: false,
|
|
14
|
+
openWorldHint: true,
|
|
15
|
+
},
|
|
16
|
+
props: {
|
|
17
|
+
formIo,
|
|
18
|
+
roleId: {
|
|
19
|
+
propDefinition: [
|
|
20
|
+
formIo,
|
|
21
|
+
"roleId",
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
title: {
|
|
25
|
+
propDefinition: [
|
|
26
|
+
formIo,
|
|
27
|
+
"title",
|
|
28
|
+
],
|
|
29
|
+
description: "Updated title of the role.",
|
|
30
|
+
optional: true,
|
|
31
|
+
},
|
|
32
|
+
description: {
|
|
33
|
+
propDefinition: [
|
|
34
|
+
formIo,
|
|
35
|
+
"description",
|
|
36
|
+
],
|
|
37
|
+
description: "Updated description of the role.",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
async run({ $ }) {
|
|
41
|
+
const {
|
|
42
|
+
roleId,
|
|
43
|
+
title,
|
|
44
|
+
description,
|
|
45
|
+
} = this;
|
|
46
|
+
|
|
47
|
+
// Send only the fields the user actually provided. Form.io's role PUT merges
|
|
48
|
+
// the request body onto the existing document server-side (omitted fields keep
|
|
49
|
+
// their current values), so we deliberately do NOT read-modify-write a full
|
|
50
|
+
// snapshot: reading the whole role and PUTting it back would overwrite any
|
|
51
|
+
// field a concurrent update changed in between (a lost update). By writing only
|
|
52
|
+
// the changed fields, two concurrent updates to different fields both survive.
|
|
53
|
+
const data = {};
|
|
54
|
+
if (title !== undefined) {
|
|
55
|
+
data.title = title;
|
|
56
|
+
}
|
|
57
|
+
if (description !== undefined) {
|
|
58
|
+
data.description = description;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!Object.keys(data).length) {
|
|
62
|
+
throw new ConfigurationError(
|
|
63
|
+
"Provide at least one field to update (Title and/or Description).",
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const response = await this.formIo.updateRole({
|
|
68
|
+
$,
|
|
69
|
+
roleId,
|
|
70
|
+
data,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
$.export("$summary", `Updated role "${response.title}" (${response._id})`);
|
|
74
|
+
return response;
|
|
75
|
+
},
|
|
76
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import formIo from "../../form_io.app.mjs";
|
|
2
|
+
import { parseJson } from "../../common/utils.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "form_io-update-submission",
|
|
6
|
+
name: "Update Submission",
|
|
7
|
+
description: "Update a submission for a Form.io form. Only the fields you provide are changed; omitted fields keep their current values. Use **List Submissions** to find the submission ID. The `data` prop is a JSON-string object of field key-value pairs. [See the documentation](https://apidocs.form.io/#fa874508-bff1-1047-a504-d3831576df00).",
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
type: "action",
|
|
10
|
+
ai: "optimized",
|
|
11
|
+
annotations: {
|
|
12
|
+
readOnlyHint: false,
|
|
13
|
+
destructiveHint: false,
|
|
14
|
+
openWorldHint: true,
|
|
15
|
+
},
|
|
16
|
+
props: {
|
|
17
|
+
formIo,
|
|
18
|
+
formId: {
|
|
19
|
+
propDefinition: [
|
|
20
|
+
formIo,
|
|
21
|
+
"formId",
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
submissionId: {
|
|
25
|
+
propDefinition: [
|
|
26
|
+
formIo,
|
|
27
|
+
"submissionId",
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
data: {
|
|
31
|
+
propDefinition: [
|
|
32
|
+
formIo,
|
|
33
|
+
"data",
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
state: {
|
|
37
|
+
propDefinition: [
|
|
38
|
+
formIo,
|
|
39
|
+
"state",
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
async run({ $ }) {
|
|
44
|
+
const {
|
|
45
|
+
formId,
|
|
46
|
+
submissionId,
|
|
47
|
+
data,
|
|
48
|
+
state,
|
|
49
|
+
} = this;
|
|
50
|
+
|
|
51
|
+
const response = await this.formIo.updateSubmission({
|
|
52
|
+
$,
|
|
53
|
+
formId,
|
|
54
|
+
submissionId,
|
|
55
|
+
data: {
|
|
56
|
+
data: parseJson(data, "data", "object"),
|
|
57
|
+
state,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
$.export("$summary", `Updated submission ${response._id}`);
|
|
62
|
+
return response;
|
|
63
|
+
},
|
|
64
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Form.io project API Keys authenticate via the `x-token` header.
|
|
2
|
+
// (`x-jwt-token` is only for short-lived login JWTs, which expire in minutes.)
|
|
3
|
+
export const API_KEY_HEADER = "x-token";
|
|
4
|
+
export const FORM_TYPES = [
|
|
5
|
+
"form",
|
|
6
|
+
"resource",
|
|
7
|
+
];
|
|
8
|
+
export const SUBMISSION_STATES = [
|
|
9
|
+
"submitted",
|
|
10
|
+
"draft",
|
|
11
|
+
];
|
|
12
|
+
export const ACTION_HANDLERS = [
|
|
13
|
+
"before",
|
|
14
|
+
"after",
|
|
15
|
+
];
|
|
16
|
+
export const ACTION_METHODS = [
|
|
17
|
+
"create",
|
|
18
|
+
"update",
|
|
19
|
+
"read",
|
|
20
|
+
"delete",
|
|
21
|
+
"index",
|
|
22
|
+
];
|
|
23
|
+
export const LIMIT_MIN = 1;
|
|
24
|
+
export const LIMIT_MAX = 1000;
|
package/common/utils.mjs
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ConfigurationError } from "@pipedream/platform";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parse a JSON-string prop into a JS value, optionally validating its shape.
|
|
5
|
+
*
|
|
6
|
+
* MCP/agent-facing props like `components`, `settings`, and `data` arrive as JSON strings.
|
|
7
|
+
* This centralizes the parsing so every action reports the same clear, prop-named error on
|
|
8
|
+
* malformed input (a raw `JSON.parse` throws a bare `SyntaxError` with no prop context).
|
|
9
|
+
*
|
|
10
|
+
* - Returns `undefined` for empty input (null / undefined / ""), so optional props can be
|
|
11
|
+
* passed straight through without a caller-side ternary.
|
|
12
|
+
* - Passes an already-parsed object/array through unchanged (defensive).
|
|
13
|
+
* - When `expect` is `"object"` or `"array"`, the parsed value must match that shape, so a
|
|
14
|
+
* valid-JSON-but-wrong-shape value (e.g. an array where the API wants an object) fails here
|
|
15
|
+
* with a prop-named message instead of as an opaque 400 from the API.
|
|
16
|
+
*
|
|
17
|
+
* @param {string|object|null|undefined} value - the raw prop value
|
|
18
|
+
* @param {string} propLabel - the prop name, used in the error message
|
|
19
|
+
* @param {"object"|"array"} [expect] - required shape of the parsed value
|
|
20
|
+
* @returns {*} the parsed value, or `undefined` when `value` is empty
|
|
21
|
+
* @throws {ConfigurationError} when `value` is not valid JSON, or does not match `expect`
|
|
22
|
+
*/
|
|
23
|
+
export function parseJson(value, propLabel = "value", expect) {
|
|
24
|
+
if (value === undefined || value === null || value === "") {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
let parsed;
|
|
28
|
+
if (typeof value === "object") {
|
|
29
|
+
parsed = value;
|
|
30
|
+
} else {
|
|
31
|
+
try {
|
|
32
|
+
parsed = JSON.parse(value);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
throw new ConfigurationError(
|
|
35
|
+
`The \`${propLabel}\` prop must be a valid JSON string. ${err.message}`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (expect === "object"
|
|
40
|
+
&& (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))) {
|
|
41
|
+
throw new ConfigurationError(
|
|
42
|
+
`The \`${propLabel}\` prop must be a JSON object (e.g. \`{ ... }\`).`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
if (expect === "array" && !Array.isArray(parsed)) {
|
|
46
|
+
throw new ConfigurationError(
|
|
47
|
+
`The \`${propLabel}\` prop must be a JSON array (e.g. \`[ { ... } ]\`).`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return parsed;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Reduce each record in an array to only the named top-level fields.
|
|
55
|
+
*
|
|
56
|
+
* Optional response-shaping for list actions that return large objects (Form.io forms carry
|
|
57
|
+
* big `components`/`access` arrays). When `fields` is empty/undefined the records are returned
|
|
58
|
+
* unchanged, so this is always additive — omitting the `fields` prop reproduces the raw output.
|
|
59
|
+
*
|
|
60
|
+
* @param {Array} records - the array of record objects
|
|
61
|
+
* @param {string[]|undefined} fields - top-level field names to keep
|
|
62
|
+
* @returns {Array} the records, each narrowed to `fields` (or unchanged when `fields` is empty)
|
|
63
|
+
*/
|
|
64
|
+
export function pluckFields(records, fields) {
|
|
65
|
+
if (!Array.isArray(records) || !fields?.length) {
|
|
66
|
+
return records;
|
|
67
|
+
}
|
|
68
|
+
return records.map((r) => (
|
|
69
|
+
r && typeof r === "object" && !Array.isArray(r)
|
|
70
|
+
? Object.fromEntries(Object.entries(r).filter(([
|
|
71
|
+
k,
|
|
72
|
+
]) => fields.includes(k)))
|
|
73
|
+
: r
|
|
74
|
+
));
|
|
75
|
+
}
|