@formio/appserver 2.0.0-rc.1 → 2.0.0-rc.31
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/README.md +12 -6
- package/lib/actions/index.d.ts +3 -156
- package/lib/actions/login/LoginAction.d.ts +2 -108
- package/lib/actions/login/LoginAction.js +124 -213
- package/lib/actions/role/RoleAction.d.ts +2 -61
- package/lib/actions/role/RoleAction.js +13 -20
- package/lib/actions/save/SaveAction.d.ts +2 -28
- package/lib/actions/save/SaveAction.js +27 -45
- package/lib/modules/index.d.ts +1 -3
- package/lib/modules/index.js +3 -5
- package/lib/modules/mongodb/db.d.ts +127 -0
- package/lib/modules/mongodb/db.js +832 -0
- package/lib/server.d.ts +5 -174
- package/lib/server.js +61 -58
- package/package.json +25 -25
- package/lib/modules/auth/auth.d.ts +0 -5
- package/lib/modules/auth/auth.js +0 -70
- package/lib/prepare/access.d.ts +0 -3
- package/lib/prepare/access.js +0 -62
- package/lib/prepare/bcrypt.d.ts +0 -3
- package/lib/prepare/bcrypt.js +0 -25
- package/lib/prepare/index.d.ts +0 -11
- package/lib/prepare/index.js +0 -60
- package/lib/prepare/password.d.ts +0 -3
- package/lib/prepare/password.js +0 -27
- package/lib/prepare/persist.d.ts +0 -3
- package/lib/prepare/persist.js +0 -24
- package/lib/prepare/protect.d.ts +0 -3
- package/lib/prepare/protect.js +0 -28
- package/lib/prepare/reference.d.ts +0 -3
- package/lib/prepare/reference.js +0 -71
- package/lib/types/action.d.ts +0 -7
- package/lib/types/action.js +0 -2
- package/lib/types/form.d.ts +0 -4
- package/lib/types/form.js +0 -2
- package/lib/types/index.d.ts +0 -5
- package/lib/types/index.js +0 -21
- package/lib/types/project.d.ts +0 -4
- package/lib/types/project.js +0 -2
- package/lib/types/server.d.ts +0 -102
- package/lib/types/server.js +0 -2
- package/lib/types/submission.d.ts +0 -47
- package/lib/types/submission.js +0 -2
- package/server.js +0 -1
|
@@ -18,6 +18,7 @@ const set_1 = __importDefault(require("lodash/set"));
|
|
|
18
18
|
const has_1 = __importDefault(require("lodash/has"));
|
|
19
19
|
const get_1 = __importDefault(require("lodash/get"));
|
|
20
20
|
const async_1 = __importDefault(require("async"));
|
|
21
|
+
const appserver_core_1 = require("@formio/appserver-core");
|
|
21
22
|
const debug = require('debug')('formio:actions:save');
|
|
22
23
|
const error = require('debug')('formio:error');
|
|
23
24
|
exports.SaveAction = {
|
|
@@ -38,8 +39,9 @@ exports.SaveAction = {
|
|
|
38
39
|
}
|
|
39
40
|
};
|
|
40
41
|
},
|
|
41
|
-
mappingComponents(
|
|
42
|
+
mappingComponents(form) {
|
|
42
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
var _a;
|
|
43
45
|
const components = [
|
|
44
46
|
{
|
|
45
47
|
type: 'select',
|
|
@@ -76,8 +78,8 @@ exports.SaveAction = {
|
|
|
76
78
|
]
|
|
77
79
|
}
|
|
78
80
|
];
|
|
79
|
-
for (let key in
|
|
80
|
-
const
|
|
81
|
+
for (let key in (_a = form.project.template) === null || _a === void 0 ? void 0 : _a.resources) {
|
|
82
|
+
const resource = form.project.template.resources[key];
|
|
81
83
|
const mappings = {
|
|
82
84
|
title: 'Simple Mappings',
|
|
83
85
|
label: 'Simple Mappings',
|
|
@@ -88,13 +90,13 @@ exports.SaveAction = {
|
|
|
88
90
|
components: []
|
|
89
91
|
};
|
|
90
92
|
const toFields = [];
|
|
91
|
-
|
|
93
|
+
appserver_core_1.Utils.eachComponent(resource.components, (component) => {
|
|
92
94
|
if (['button'].indexOf(component.type) !== -1) {
|
|
93
95
|
return;
|
|
94
96
|
}
|
|
95
97
|
toFields.push({ label: component.label || component.key, value: component.key });
|
|
96
98
|
});
|
|
97
|
-
|
|
99
|
+
appserver_core_1.Utils.eachComponent(resource.components, (component) => {
|
|
98
100
|
if (['button'].indexOf(component.type) !== -1) {
|
|
99
101
|
return;
|
|
100
102
|
}
|
|
@@ -112,16 +114,13 @@ exports.SaveAction = {
|
|
|
112
114
|
return components;
|
|
113
115
|
});
|
|
114
116
|
},
|
|
115
|
-
|
|
116
|
-
* The settings form for this action.
|
|
117
|
-
* @param {*} scope
|
|
118
|
-
*/
|
|
119
|
-
settingsForm(scope) {
|
|
117
|
+
settingsForm(form) {
|
|
120
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
var _a, _b;
|
|
121
120
|
const resources = [];
|
|
122
|
-
for (let name in
|
|
121
|
+
for (let name in (_a = form.project.template) === null || _a === void 0 ? void 0 : _a.resources) {
|
|
123
122
|
resources.push({
|
|
124
|
-
label:
|
|
123
|
+
label: (_b = form.project.template) === null || _b === void 0 ? void 0 : _b.resources[name].title,
|
|
125
124
|
value: name
|
|
126
125
|
});
|
|
127
126
|
}
|
|
@@ -168,7 +167,7 @@ exports.SaveAction = {
|
|
|
168
167
|
}
|
|
169
168
|
]
|
|
170
169
|
}
|
|
171
|
-
].concat(yield exports.SaveAction.mappingComponents(
|
|
170
|
+
].concat(yield exports.SaveAction.mappingComponents(form))
|
|
172
171
|
},
|
|
173
172
|
{
|
|
174
173
|
type: 'panel',
|
|
@@ -211,31 +210,12 @@ exports.SaveAction = {
|
|
|
211
210
|
];
|
|
212
211
|
});
|
|
213
212
|
},
|
|
214
|
-
saveToForm(scope, resource) {
|
|
215
|
-
let saveTo;
|
|
216
|
-
(0, each_1.default)(scope.template.resources, (form) => {
|
|
217
|
-
if (form.key === resource) {
|
|
218
|
-
saveTo = form;
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
if (!saveTo) {
|
|
223
|
-
(0, each_1.default)(scope.template.forms, (form) => {
|
|
224
|
-
if (form.key === resource) {
|
|
225
|
-
saveTo = form;
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
return saveTo;
|
|
231
|
-
},
|
|
232
213
|
// Create a child submission.
|
|
233
|
-
childSubmission(
|
|
234
|
-
const { action } = scope;
|
|
214
|
+
childSubmission(action, req, res, form, submission) {
|
|
235
215
|
let childSub = { data: {} };
|
|
236
216
|
if (action.settings.mapping) {
|
|
237
217
|
try {
|
|
238
|
-
childSub =
|
|
218
|
+
childSub = appserver_core_1.Utils.evaluate(action.settings.mapping, appserver_core_1.Utils.evalContext(form, req.body, req.auth, req.headers, req.findQuery), 'body');
|
|
239
219
|
}
|
|
240
220
|
catch (err) {
|
|
241
221
|
console.log(`Error in mapping transform: ${err.message}`);
|
|
@@ -254,7 +234,7 @@ exports.SaveAction = {
|
|
|
254
234
|
childSub.metadata = submission.metadata;
|
|
255
235
|
if (action.settings.transform) {
|
|
256
236
|
try {
|
|
257
|
-
childSub.data =
|
|
237
|
+
childSub.data = appserver_core_1.Utils.evaluate(action.settings.transform, appserver_core_1.Utils.evalContext(form, req.body, req.auth, req.headers, req.findQuery), 'data');
|
|
258
238
|
}
|
|
259
239
|
catch (err) {
|
|
260
240
|
console.log(`Error in submission transform: ${err.message}`);
|
|
@@ -263,9 +243,8 @@ exports.SaveAction = {
|
|
|
263
243
|
return childSub;
|
|
264
244
|
},
|
|
265
245
|
// Set the child response
|
|
266
|
-
childResponse(
|
|
246
|
+
childResponse(action, req, res, form, submission) {
|
|
267
247
|
var _a, _b;
|
|
268
|
-
const { action } = scope;
|
|
269
248
|
if ((_a = res.resource) === null || _a === void 0 ? void 0 : _a.item) {
|
|
270
249
|
// Set the action in the property.
|
|
271
250
|
if ((_b = action.settings) === null || _b === void 0 ? void 0 : _b.property) {
|
|
@@ -284,7 +263,7 @@ exports.SaveAction = {
|
|
|
284
263
|
// Allow for a response mapping.
|
|
285
264
|
if (action.settings.response) {
|
|
286
265
|
try {
|
|
287
|
-
res.resource.item =
|
|
266
|
+
res.resource.item = appserver_core_1.Utils.evaluate(action.settings.response, Object.assign(Object.assign({}, appserver_core_1.Utils.evalContext(form, req.body, req.auth, req.headers, req.findQuery)), { response: res.resource.item }), 'response');
|
|
288
267
|
}
|
|
289
268
|
catch (err) {
|
|
290
269
|
console.log(`Error in mapping transform: ${err.message}`);
|
|
@@ -292,9 +271,8 @@ exports.SaveAction = {
|
|
|
292
271
|
}
|
|
293
272
|
}
|
|
294
273
|
},
|
|
295
|
-
executor(
|
|
274
|
+
executor(form, action, handler, method) {
|
|
296
275
|
return __awaiter(this, void 0, void 0, function* () {
|
|
297
|
-
const action = scope.action;
|
|
298
276
|
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
299
277
|
var _a;
|
|
300
278
|
debug('Save Action');
|
|
@@ -305,28 +283,32 @@ exports.SaveAction = {
|
|
|
305
283
|
// If this is saving to another resource, then we need to use those handlers instead.
|
|
306
284
|
if ((_a = action.settings) === null || _a === void 0 ? void 0 : _a.resource) {
|
|
307
285
|
debug('Saving to resource: ' + action.settings.resource);
|
|
308
|
-
const saveTo =
|
|
286
|
+
const saveTo = yield form.project.getForm(action.settings.resource);
|
|
309
287
|
if (saveTo) {
|
|
310
288
|
if (!saveTo.handlers) {
|
|
311
289
|
error('Cannot find resource handlers.');
|
|
312
290
|
return next('Cannot find resource handlers.');
|
|
313
291
|
}
|
|
314
292
|
const handlers = req.method === 'PUT' ? saveTo.handlers.update : saveTo.handlers.create;
|
|
315
|
-
const childReq =
|
|
316
|
-
|
|
293
|
+
const childReq = appserver_core_1.Utils.childRequest(req);
|
|
294
|
+
if (!childReq) {
|
|
295
|
+
error('Failed to create child request');
|
|
296
|
+
return next('Failed to create child request');
|
|
297
|
+
}
|
|
298
|
+
childReq.body = exports.SaveAction.childSubmission(action, req, res, saveTo, childReq.body);
|
|
317
299
|
return async_1.default.series(handlers.map((handler) => async_1.default.apply(handler, childReq, res)), (err) => {
|
|
318
300
|
if (err) {
|
|
319
301
|
error(err);
|
|
320
302
|
return next(err);
|
|
321
303
|
}
|
|
322
304
|
// Set the child response based on the response of the subform.
|
|
323
|
-
exports.SaveAction.childResponse(
|
|
305
|
+
exports.SaveAction.childResponse(action, req, res, saveTo, childReq.body);
|
|
324
306
|
next();
|
|
325
307
|
});
|
|
326
308
|
}
|
|
327
309
|
}
|
|
328
310
|
// Save the submission.
|
|
329
|
-
req.
|
|
311
|
+
req.saveSubmission = true;
|
|
330
312
|
debug('Saving submission');
|
|
331
313
|
return next();
|
|
332
314
|
});
|
package/lib/modules/index.d.ts
CHANGED
package/lib/modules/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return
|
|
6
|
-
const appserver_auth_jwt_1 = require("@formio/appserver-auth-jwt");
|
|
7
|
-
Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return appserver_auth_jwt_1.Auth; } });
|
|
3
|
+
exports.Database = void 0;
|
|
4
|
+
var db_1 = require("./mongodb/db");
|
|
5
|
+
Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return db_1.Database; } });
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Collection, Document, Db, FindOptions, MongoClient } from 'mongodb';
|
|
2
|
+
import { Component, Submission } from '@formio/core';
|
|
3
|
+
import { ServerDB, DBConfig, AppServerForm, DatabaseIndexResponse } from '@formio/appserver-core';
|
|
4
|
+
export declare class Database implements ServerDB {
|
|
5
|
+
config: DBConfig;
|
|
6
|
+
db: Db | null;
|
|
7
|
+
client: MongoClient | null;
|
|
8
|
+
currentCollectionName: string;
|
|
9
|
+
currentCollection: Collection<Document> | null;
|
|
10
|
+
defaultCollection: Collection<Document> | null;
|
|
11
|
+
prefix: string;
|
|
12
|
+
authQuery: any;
|
|
13
|
+
constructor(config: DBConfig);
|
|
14
|
+
ObjectId(id: any): any;
|
|
15
|
+
collectionName(name: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Connect to the database.
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
connect(prefix?: string): Promise<void>;
|
|
21
|
+
close(): Promise<void>;
|
|
22
|
+
collection(name: string): Collection<Document> | null;
|
|
23
|
+
save(collectionName: string, item: any): Promise<any | null>;
|
|
24
|
+
saveOne(collectionName: string, item: any): Promise<any>;
|
|
25
|
+
load(collectionName: string, dbQuery?: {}): Promise<any | null>;
|
|
26
|
+
indexAuth(query: any): void;
|
|
27
|
+
getQueryValue(name: string, value: string, selector: string): string | boolean | Date | null;
|
|
28
|
+
/**
|
|
29
|
+
* Converts the url query to query parameters.
|
|
30
|
+
* @param query
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
dbQuery(query?: Record<string, string>): any;
|
|
34
|
+
remove(collectionName: string, dbQuery?: {}): Promise<number | null>;
|
|
35
|
+
/**
|
|
36
|
+
* Ensures the form collection is created an returns it.
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
formCollection(form: AppServerForm): Promise<Collection<Document> | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Setup indexes.
|
|
42
|
+
*/
|
|
43
|
+
setupIndexes(collection: Collection<Document> | null, form?: AppServerForm): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Add a field index
|
|
46
|
+
*/
|
|
47
|
+
addIndex(collection: Collection<Document> | null, path: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Adds new indexes to the forms submission collection.
|
|
50
|
+
* @param indexes
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
addIndexes(form: AppServerForm, indexes: string[]): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Remove a field index.
|
|
56
|
+
*/
|
|
57
|
+
removeIndex(collection: Collection<Document>, path: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Removes indexes to the forms submission collection.
|
|
60
|
+
* @param indexes
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
removeIndexes(form: AppServerForm, indexes: string[]): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Fetch a list of submissions from a table/collection.
|
|
66
|
+
* @param {*} table
|
|
67
|
+
* @param {*} query
|
|
68
|
+
*/
|
|
69
|
+
index(form: AppServerForm, urlQuery?: any, collection?: Collection<Document> | null): Promise<DatabaseIndexResponse<Submission>>;
|
|
70
|
+
/**
|
|
71
|
+
* Perform a count of the amount of documents within a collection.
|
|
72
|
+
* @param form
|
|
73
|
+
* @param query
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
count(form: AppServerForm, dbQuery?: any, inCollection?: Collection<Document> | null, includeDeleted?: boolean): Promise<number>;
|
|
77
|
+
/**
|
|
78
|
+
* Create a new record.
|
|
79
|
+
*/
|
|
80
|
+
create(form: AppServerForm, record: any, allowFields?: string[]): Promise<Submission | null>;
|
|
81
|
+
/**
|
|
82
|
+
* Return a query for a single mongo record.
|
|
83
|
+
* @param {*} form
|
|
84
|
+
* @param {*} id
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
query(form: AppServerForm, query?: any, includeAll?: boolean): any;
|
|
88
|
+
/**
|
|
89
|
+
* Find many records that match a query.
|
|
90
|
+
*/
|
|
91
|
+
find(form: AppServerForm, dbQuery?: any, limit?: number, skip?: number, sort?: any, select?: any, inCollection?: Collection<Document> | null, includeDeleted?: boolean): Promise<any | null>;
|
|
92
|
+
/**
|
|
93
|
+
* Find a record for a provided query.
|
|
94
|
+
*/
|
|
95
|
+
findOne(form: AppServerForm, dbQuery?: any, options?: FindOptions<Document>): Promise<Submission | null>;
|
|
96
|
+
/**
|
|
97
|
+
* Read a single submission from a form
|
|
98
|
+
*
|
|
99
|
+
* @param {*} table
|
|
100
|
+
* @param {*} query
|
|
101
|
+
*/
|
|
102
|
+
read(form: AppServerForm, id: string | undefined): Promise<Submission | null>;
|
|
103
|
+
/**
|
|
104
|
+
* Update a single submission of a form.
|
|
105
|
+
*
|
|
106
|
+
* @param {*} table
|
|
107
|
+
* @param {*} query
|
|
108
|
+
*/
|
|
109
|
+
update(form: AppServerForm, id: string | undefined, update: any, allowFields?: string[]): Promise<Submission | null>;
|
|
110
|
+
/**
|
|
111
|
+
* Delete a record from the database.
|
|
112
|
+
*/
|
|
113
|
+
delete(form: AppServerForm, id: string | undefined, hard?: boolean): Promise<boolean>;
|
|
114
|
+
addPathQueryParams(pathQueryParams: any, query: any, path: string): void;
|
|
115
|
+
/**
|
|
116
|
+
* Performs a unique query on the database to see if a value is unique.
|
|
117
|
+
* - If the value is unique, it returns true.
|
|
118
|
+
* - If the value is not unique, it returns the id of the non-unique submission.
|
|
119
|
+
* - If an error occurs, or uniqueness cannot be determined, it will throw an error.
|
|
120
|
+
*
|
|
121
|
+
* @param form
|
|
122
|
+
* @param context
|
|
123
|
+
* @param value
|
|
124
|
+
* @returns
|
|
125
|
+
*/
|
|
126
|
+
isUnique(form: AppServerForm, component: Component, submission: Submission, componentPath: string, value: any): Promise<boolean | string>;
|
|
127
|
+
}
|