@pipedream/form_io 0.0.2 → 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.
@@ -0,0 +1,378 @@
1
+ import {
2
+ axios, ConfigurationError,
3
+ } from "@pipedream/platform";
4
+ import {
5
+ API_KEY_HEADER,
6
+ LIMIT_MIN,
7
+ LIMIT_MAX,
8
+ FORM_TYPES,
9
+ SUBMISSION_STATES,
10
+ ACTION_HANDLERS,
11
+ ACTION_METHODS,
12
+ } from "./common/constants.mjs";
13
+
14
+ export default {
15
+ type: "app",
16
+ app: "form_io",
17
+ propDefinitions: {
18
+ formId: {
19
+ type: "string",
20
+ label: "Form ID",
21
+ description: "The `_id` of the form. Run **List Forms** first to obtain valid form IDs.",
22
+ },
23
+ submissionId: {
24
+ type: "string",
25
+ label: "Submission ID",
26
+ description: "The `_id` of the submission. Run **List Submissions** first to obtain valid submission IDs.",
27
+ },
28
+ roleId: {
29
+ type: "string",
30
+ label: "Role ID",
31
+ description: "The `_id` of the role. Run **List Roles** first to obtain valid role IDs.",
32
+ },
33
+ actionId: {
34
+ type: "string",
35
+ label: "Action ID",
36
+ description: "The `_id` of the form action. Run **List Form Actions** first to obtain valid action IDs.",
37
+ },
38
+ limit: {
39
+ type: "integer",
40
+ label: "Limit",
41
+ description: `Maximum number of records to return. Min ${LIMIT_MIN}, max ${LIMIT_MAX}.`,
42
+ optional: true,
43
+ min: LIMIT_MIN,
44
+ max: LIMIT_MAX,
45
+ },
46
+ skip: {
47
+ type: "integer",
48
+ label: "Skip",
49
+ description: "Number of records to skip (for pagination).",
50
+ optional: true,
51
+ },
52
+ sort: {
53
+ type: "string",
54
+ label: "Sort",
55
+ description: "Field name to sort by; prefix with `-` for descending (e.g. `-created`, `title`).",
56
+ optional: true,
57
+ },
58
+ // Shared record fields. Components reference these via `propDefinition` and override
59
+ // only what differs (description, optional, options) — see the per-component props.
60
+ title: {
61
+ type: "string",
62
+ label: "Title",
63
+ description: "A human-readable title.",
64
+ },
65
+ name: {
66
+ type: "string",
67
+ label: "Name",
68
+ description: "The machine name (lowercase, no spaces).",
69
+ },
70
+ path: {
71
+ type: "string",
72
+ label: "Path",
73
+ description: "The URL path.",
74
+ },
75
+ type: {
76
+ type: "string",
77
+ label: "Type",
78
+ description: "The form type. One of `form` or `resource`.",
79
+ optional: true,
80
+ options: FORM_TYPES,
81
+ },
82
+ components: {
83
+ type: "string",
84
+ label: "Components",
85
+ description: "JSON-string array of Form.io component schema objects.",
86
+ },
87
+ display: {
88
+ type: "string",
89
+ label: "Display",
90
+ description: "How the form is displayed (e.g. `form`, `wizard`, `pdf`).",
91
+ optional: true,
92
+ },
93
+ tags: {
94
+ type: "string[]",
95
+ label: "Tags",
96
+ description: "Tags to associate with the form.",
97
+ optional: true,
98
+ },
99
+ settings: {
100
+ type: "string",
101
+ label: "Settings",
102
+ description: "JSON-string object of settings. Parsed with JSON.parse() before sending.",
103
+ optional: true,
104
+ },
105
+ description: {
106
+ type: "string",
107
+ label: "Description",
108
+ description: "A description.",
109
+ optional: true,
110
+ },
111
+ data: {
112
+ type: "string",
113
+ label: "Data",
114
+ description: "JSON-string object of the submission's data payload. Example: `{\"name\":\"Jane Doe\",\"email\":\"jane@example.com\"}`. Parsed with JSON.parse() before sending.",
115
+ },
116
+ state: {
117
+ type: "string",
118
+ label: "State",
119
+ description: "Submission state. One of `submitted` or `draft`.",
120
+ optional: true,
121
+ options: SUBMISSION_STATES,
122
+ },
123
+ fields: {
124
+ type: "string[]",
125
+ label: "Fields",
126
+ description: "Return only these top-level fields from each record. Omit to return the full objects.",
127
+ optional: true,
128
+ },
129
+ handler: {
130
+ type: "string[]",
131
+ label: "Handler",
132
+ description: "When the action runs. Values: `before`, `after`.",
133
+ options: ACTION_HANDLERS,
134
+ },
135
+ method: {
136
+ type: "string[]",
137
+ label: "Method",
138
+ description: "Which operations trigger the action. Values: `create`, `update`, `read`, `delete`, `index`.",
139
+ options: ACTION_METHODS,
140
+ },
141
+ priority: {
142
+ type: "integer",
143
+ label: "Priority",
144
+ description: "Execution priority of the action.",
145
+ optional: true,
146
+ },
147
+ },
148
+ methods: {
149
+ _baseUrl() {
150
+ return `https://${this.$auth.project_id}.form.io`;
151
+ },
152
+ _headers() {
153
+ return {
154
+ [API_KEY_HEADER]: this.$auth.api_key,
155
+ };
156
+ },
157
+ // Validate + URL-encode a required path id before it goes into a request URL.
158
+ // An empty/whitespace id would otherwise build a malformed path (e.g. `/role/`),
159
+ // which Form.io answers with an opaque HTML 404 instead of a usable error.
160
+ _requireId(value, label) {
161
+ const id = value == null
162
+ ? ""
163
+ : String(value).trim();
164
+ if (!id) {
165
+ throw new ConfigurationError(`The \`${label}\` prop is required and cannot be empty.`);
166
+ }
167
+ return encodeURIComponent(id);
168
+ },
169
+ async _makeRequest({
170
+ $ = this,
171
+ path,
172
+ ...opts
173
+ }) {
174
+ const url = `${this._baseUrl()}${path}`;
175
+ return axios($, {
176
+ url,
177
+ headers: this._headers(),
178
+ ...opts,
179
+ });
180
+ },
181
+ // Forms
182
+ async createForm({
183
+ $, data,
184
+ } = {}) {
185
+ return this._makeRequest({
186
+ $,
187
+ method: "POST",
188
+ path: "/form",
189
+ data,
190
+ });
191
+ },
192
+ async getForm({
193
+ $, formId,
194
+ } = {}) {
195
+ return this._makeRequest({
196
+ $,
197
+ method: "GET",
198
+ path: `/form/${this._requireId(formId, "formId")}`,
199
+ });
200
+ },
201
+ async updateForm({
202
+ $, formId, data,
203
+ } = {}) {
204
+ return this._makeRequest({
205
+ $,
206
+ method: "PUT",
207
+ path: `/form/${this._requireId(formId, "formId")}`,
208
+ data,
209
+ });
210
+ },
211
+ async deleteForm({
212
+ $, formId,
213
+ } = {}) {
214
+ return this._makeRequest({
215
+ $,
216
+ method: "DELETE",
217
+ path: `/form/${this._requireId(formId, "formId")}`,
218
+ });
219
+ },
220
+ async listForms({
221
+ $, params,
222
+ } = {}) {
223
+ return this._makeRequest({
224
+ $,
225
+ method: "GET",
226
+ path: "/form",
227
+ params,
228
+ });
229
+ },
230
+ // Submissions
231
+ async createSubmission({
232
+ $, formId, data,
233
+ } = {}) {
234
+ return this._makeRequest({
235
+ $,
236
+ method: "POST",
237
+ path: `/form/${this._requireId(formId, "formId")}/submission`,
238
+ data,
239
+ });
240
+ },
241
+ async getSubmission({
242
+ $, formId, submissionId,
243
+ } = {}) {
244
+ return this._makeRequest({
245
+ $,
246
+ method: "GET",
247
+ path: `/form/${this._requireId(formId, "formId")}/submission/${this._requireId(submissionId, "submissionId")}`,
248
+ });
249
+ },
250
+ async updateSubmission({
251
+ $, formId, submissionId, data,
252
+ } = {}) {
253
+ return this._makeRequest({
254
+ $,
255
+ method: "PUT",
256
+ path: `/form/${this._requireId(formId, "formId")}/submission/${this._requireId(submissionId, "submissionId")}`,
257
+ data,
258
+ });
259
+ },
260
+ async deleteSubmission({
261
+ $, formId, submissionId,
262
+ } = {}) {
263
+ return this._makeRequest({
264
+ $,
265
+ method: "DELETE",
266
+ path: `/form/${this._requireId(formId, "formId")}/submission/${this._requireId(submissionId, "submissionId")}`,
267
+ });
268
+ },
269
+ async listSubmissions({
270
+ $, formId, params,
271
+ } = {}) {
272
+ return this._makeRequest({
273
+ $,
274
+ method: "GET",
275
+ path: `/form/${this._requireId(formId, "formId")}/submission`,
276
+ params,
277
+ });
278
+ },
279
+ // Roles
280
+ async createRole({
281
+ $, data,
282
+ } = {}) {
283
+ return this._makeRequest({
284
+ $,
285
+ method: "POST",
286
+ path: "/role",
287
+ data,
288
+ });
289
+ },
290
+ async getRole({
291
+ $, roleId,
292
+ } = {}) {
293
+ return this._makeRequest({
294
+ $,
295
+ method: "GET",
296
+ path: `/role/${this._requireId(roleId, "roleId")}`,
297
+ });
298
+ },
299
+ async updateRole({
300
+ $, roleId, data,
301
+ } = {}) {
302
+ return this._makeRequest({
303
+ $,
304
+ method: "PUT",
305
+ path: `/role/${this._requireId(roleId, "roleId")}`,
306
+ data,
307
+ });
308
+ },
309
+ async deleteRole({
310
+ $, roleId,
311
+ } = {}) {
312
+ return this._makeRequest({
313
+ $,
314
+ method: "DELETE",
315
+ path: `/role/${this._requireId(roleId, "roleId")}`,
316
+ });
317
+ },
318
+ async listRoles({
319
+ $, params,
320
+ } = {}) {
321
+ return this._makeRequest({
322
+ $,
323
+ method: "GET",
324
+ path: "/role",
325
+ params,
326
+ });
327
+ },
328
+ // Form Actions
329
+ async createFormAction({
330
+ $, formId, data,
331
+ } = {}) {
332
+ return this._makeRequest({
333
+ $,
334
+ method: "POST",
335
+ path: `/form/${this._requireId(formId, "formId")}/action`,
336
+ data,
337
+ });
338
+ },
339
+ async getFormAction({
340
+ $, formId, actionId,
341
+ } = {}) {
342
+ return this._makeRequest({
343
+ $,
344
+ method: "GET",
345
+ path: `/form/${this._requireId(formId, "formId")}/action/${this._requireId(actionId, "actionId")}`,
346
+ });
347
+ },
348
+ async updateFormAction({
349
+ $, formId, actionId, data,
350
+ } = {}) {
351
+ return this._makeRequest({
352
+ $,
353
+ method: "PUT",
354
+ path: `/form/${this._requireId(formId, "formId")}/action/${this._requireId(actionId, "actionId")}`,
355
+ data,
356
+ });
357
+ },
358
+ async deleteFormAction({
359
+ $, formId, actionId,
360
+ } = {}) {
361
+ return this._makeRequest({
362
+ $,
363
+ method: "DELETE",
364
+ path: `/form/${this._requireId(formId, "formId")}/action/${this._requireId(actionId, "actionId")}`,
365
+ });
366
+ },
367
+ async listFormActions({
368
+ $, formId, params,
369
+ } = {}) {
370
+ return this._makeRequest({
371
+ $,
372
+ method: "GET",
373
+ path: `/form/${this._requireId(formId, "formId")}/action`,
374
+ params,
375
+ });
376
+ },
377
+ },
378
+ };
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@pipedream/form_io",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "Pipedream Form.io Components",
5
- "main": "dist/app/form_io.app.mjs",
5
+ "main": "form_io.app.mjs",
6
6
  "keywords": [
7
7
  "pipedream",
8
8
  "form_io"
9
9
  ],
10
- "files": [
11
- "dist"
12
- ],
13
10
  "homepage": "https://pipedream.com/apps/form_io",
14
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
15
12
  "publishConfig": {
16
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^3.0.3"
17
17
  }
18
18
  }