@formio/appserver 1.0.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/README.md +61 -0
- package/lib/actions/index.d.ts +160 -0
- package/lib/actions/index.js +10 -0
- package/lib/actions/login/LoginAction.d.ts +110 -0
- package/lib/actions/login/LoginAction.js +288 -0
- package/lib/actions/role/RoleAction.d.ts +62 -0
- package/lib/actions/role/RoleAction.js +171 -0
- package/lib/actions/save/SaveAction.d.ts +29 -0
- package/lib/actions/save/SaveAction.js +307 -0
- package/lib/auth.d.ts +5 -0
- package/lib/auth.js +70 -0
- package/lib/db.d.ts +76 -0
- package/lib/db.js +384 -0
- package/lib/index.d.ts +167 -0
- package/lib/index.js +18 -0
- package/lib/prepare/access.d.ts +3 -0
- package/lib/prepare/access.js +62 -0
- package/lib/prepare/bcrypt.d.ts +3 -0
- package/lib/prepare/bcrypt.js +25 -0
- package/lib/prepare/index.d.ts +10 -0
- package/lib/prepare/index.js +54 -0
- package/lib/prepare/password.d.ts +3 -0
- package/lib/prepare/password.js +28 -0
- package/lib/prepare/persist.d.ts +3 -0
- package/lib/prepare/persist.js +24 -0
- package/lib/prepare/protect.d.ts +3 -0
- package/lib/prepare/protect.js +28 -0
- package/lib/process/calculate.d.ts +3 -0
- package/lib/process/calculate.js +23 -0
- package/lib/process/conditions.d.ts +3 -0
- package/lib/process/conditions.js +54 -0
- package/lib/process/fetch.d.ts +3 -0
- package/lib/process/fetch.js +61 -0
- package/lib/process/index.d.ts +9 -0
- package/lib/process/index.js +56 -0
- package/lib/process/validate.d.ts +3 -0
- package/lib/process/validate.js +14 -0
- package/lib/types/action.d.ts +7 -0
- package/lib/types/action.js +2 -0
- package/lib/types/form.d.ts +4 -0
- package/lib/types/form.js +2 -0
- package/lib/types/project.d.ts +4 -0
- package/lib/types/project.js +2 -0
- package/lib/types/server.d.ts +75 -0
- package/lib/types/server.js +2 -0
- package/lib/types/submission.d.ts +38 -0
- package/lib/types/submission.js +2 -0
- package/package.json +48 -0
- package/server.js +3 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Prepper = exports.MethodPreppers = exports.Preppers = void 0;
|
|
16
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
17
|
+
const bcrypt_1 = __importDefault(require("./bcrypt"));
|
|
18
|
+
const access_1 = __importDefault(require("./access"));
|
|
19
|
+
const persist_1 = __importDefault(require("./persist"));
|
|
20
|
+
const protect_1 = __importDefault(require("./protect"));
|
|
21
|
+
const password_1 = __importDefault(require("./password"));
|
|
22
|
+
exports.Preppers = {
|
|
23
|
+
bcrypt: bcrypt_1.default,
|
|
24
|
+
access: access_1.default,
|
|
25
|
+
persist: persist_1.default,
|
|
26
|
+
protect: protect_1.default,
|
|
27
|
+
password: password_1.default
|
|
28
|
+
};
|
|
29
|
+
exports.MethodPreppers = {
|
|
30
|
+
save: [exports.Preppers.persist, exports.Preppers.access, exports.Preppers.password, exports.Preppers.bcrypt],
|
|
31
|
+
read: [exports.Preppers.protect]
|
|
32
|
+
};
|
|
33
|
+
const debug = require('debug')('formio:prepare');
|
|
34
|
+
const error = require('debug')('formio:error');
|
|
35
|
+
const Prepper = (scope) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
let data = {};
|
|
37
|
+
const { type, form, submission } = scope;
|
|
38
|
+
try {
|
|
39
|
+
debug(`Preparing data for ${form.name}...`);
|
|
40
|
+
yield scope.utils.eachComponentData(form.components, submission.data, (component, row, path) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
for (let i = 0; i < exports.MethodPreppers[type].length; i++) {
|
|
42
|
+
yield exports.MethodPreppers[type][i](Object.assign(Object.assign({}, scope), { component,
|
|
43
|
+
row,
|
|
44
|
+
data, value: (0, get_1.default)(row, component.key), path }));
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
error(err);
|
|
50
|
+
data = {};
|
|
51
|
+
}
|
|
52
|
+
return data;
|
|
53
|
+
});
|
|
54
|
+
exports.Prepper = Prepper;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
16
|
+
const set_1 = __importDefault(require("lodash/set"));
|
|
17
|
+
const has_1 = __importDefault(require("lodash/has"));
|
|
18
|
+
exports.default = (scope) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
// Check if they do not provide a password in the save, but one exists in the current record.
|
|
20
|
+
// Do not allow them to wipe out their password by saving data that does not include one.
|
|
21
|
+
const { type, component, row, current, path, data } = scope;
|
|
22
|
+
if (component.type === 'password' &&
|
|
23
|
+
type === 'save' &&
|
|
24
|
+
!(0, has_1.default)(row, component.key) &&
|
|
25
|
+
(0, has_1.default)(current, `data.${path}`)) {
|
|
26
|
+
(0, set_1.default)(data, path, (0, get_1.default)(current.data, path));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const set_1 = __importDefault(require("lodash/set"));
|
|
16
|
+
exports.default = (scope) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const { component, data, value, path } = scope;
|
|
18
|
+
if (!value) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (!component.hasOwnProperty('persistent') || component.persistent === 'server' || component.persistent === true) {
|
|
22
|
+
(0, set_1.default)(data, path, value);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const set_1 = __importDefault(require("lodash/set"));
|
|
16
|
+
exports.default = (scope) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const { component, data, value, path } = scope;
|
|
18
|
+
if (!value) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (!component.hasOwnProperty('protected') ||
|
|
22
|
+
!component.protected) {
|
|
23
|
+
// Passwords are always protected.
|
|
24
|
+
if (component.type !== 'password') {
|
|
25
|
+
(0, set_1.default)(data, path, value);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const set_1 = __importDefault(require("lodash/set"));
|
|
16
|
+
exports.default = (scope) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const { component, row } = scope;
|
|
18
|
+
if (!component.calculateValue || !component.calculateServer) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
(0, set_1.default)(row, component.key, scope.utils.evaluate(component.calculateValue, scope, 'value'));
|
|
22
|
+
return [];
|
|
23
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const unset_1 = __importDefault(require("lodash/unset"));
|
|
16
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
17
|
+
const has_1 = __importDefault(require("lodash/has"));
|
|
18
|
+
const isArray_1 = __importDefault(require("lodash/isArray"));
|
|
19
|
+
const shouldUnset = (scope) => {
|
|
20
|
+
const { form, data, component } = scope;
|
|
21
|
+
const { conditional, customConditional } = component;
|
|
22
|
+
if (customConditional) {
|
|
23
|
+
return !scope.utils.evaluate(customConditional, scope, 'show');
|
|
24
|
+
}
|
|
25
|
+
if (conditional && conditional.json) {
|
|
26
|
+
return !scope.utils.jsonLogic.apply(conditional.json, scope);
|
|
27
|
+
}
|
|
28
|
+
if (conditional && conditional.when) {
|
|
29
|
+
const compData = scope.utils.getComponentData(form.components, data, conditional.when);
|
|
30
|
+
if (compData.component) {
|
|
31
|
+
const compValue = (0, get_1.default)(compData.data, compData.component.key);
|
|
32
|
+
const eq = String(conditional.eq);
|
|
33
|
+
const show = String(conditional.show);
|
|
34
|
+
if (compValue && (0, has_1.default)(compValue, eq)) {
|
|
35
|
+
return String(compValue[eq]) === show;
|
|
36
|
+
}
|
|
37
|
+
if ((0, isArray_1.default)(compValue) && compValue.map(String).includes(eq)) {
|
|
38
|
+
return show === 'true';
|
|
39
|
+
}
|
|
40
|
+
return (String(compValue) === eq) === (show === 'true');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
};
|
|
45
|
+
exports.default = (scope) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const { component, row } = scope;
|
|
47
|
+
if (!component.clearOnHide) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
if (shouldUnset(scope)) {
|
|
51
|
+
(0, unset_1.default)(row, component.key);
|
|
52
|
+
}
|
|
53
|
+
return [];
|
|
54
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
16
|
+
const set_1 = __importDefault(require("lodash/set"));
|
|
17
|
+
exports.default = (scope) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
// Perform a fetch for data source components.
|
|
19
|
+
const { component, row } = scope;
|
|
20
|
+
if (component.type !== 'datasource' || !(0, get_1.default)(component, 'trigger.server', false)) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
const url = scope.utils.interpolateString((0, get_1.default)(component, 'fetch.url', ''), scope);
|
|
24
|
+
if (!url) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
const request = {
|
|
28
|
+
method: (0, get_1.default)(component, 'fetch.method', 'get').toUpperCase(),
|
|
29
|
+
headers: {}
|
|
30
|
+
};
|
|
31
|
+
(0, get_1.default)(component, 'fetch.headers', []).map((header) => {
|
|
32
|
+
header.value = scope.utils.interpolateString(header.value, scope);
|
|
33
|
+
if (header.value && header.key) {
|
|
34
|
+
request.headers[header.key] = header.value;
|
|
35
|
+
}
|
|
36
|
+
return header;
|
|
37
|
+
});
|
|
38
|
+
if ((0, get_1.default)(component, 'fetch.authenticate', false)) {
|
|
39
|
+
if (scope.req.headers['x-jwt-token']) {
|
|
40
|
+
request.headers['x-jwt-token'] = scope.req.headers['x-jwt-token'];
|
|
41
|
+
}
|
|
42
|
+
if (scope.req.headers['x-remote-token']) {
|
|
43
|
+
request.headers['x-remote-token'] = scope.req.headers['x-remote-token'];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const body = (0, get_1.default)(component, 'fetch.specifyBody', '');
|
|
47
|
+
if (request.method === 'POST') {
|
|
48
|
+
request.body = JSON.stringify(scope.utils.evaluate(body, scope, 'body'));
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
// Perform the fetch.
|
|
52
|
+
const result = yield (yield scope.utils.fetch(url, request)).json();
|
|
53
|
+
const mapFunction = (0, get_1.default)(component, 'fetch.mapFunction');
|
|
54
|
+
// Set the row data of the fetched value.
|
|
55
|
+
(0, set_1.default)(row, component.key, mapFunction ? scope.utils.evaluate(mapFunction, Object.assign(Object.assign({}, scope), { responseData: result }), 'value') : result);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
console.log(err.message);
|
|
59
|
+
}
|
|
60
|
+
return [];
|
|
61
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ProcessScope } from '../types/submission';
|
|
2
|
+
export declare const Proccessors: {
|
|
3
|
+
fetch: (scope: ProcessScope) => Promise<never[]>;
|
|
4
|
+
calculate: (scope: ProcessScope) => Promise<never[]>;
|
|
5
|
+
conditions: (scope: ProcessScope) => Promise<never[]>;
|
|
6
|
+
validate: (scope: ProcessScope) => Promise<never[]>;
|
|
7
|
+
};
|
|
8
|
+
export declare const PreProccessors: ((scope: ProcessScope) => Promise<never[]>)[];
|
|
9
|
+
export declare const Processor: (scope: ProcessScope) => Promise<any>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Processor = exports.PreProccessors = exports.Proccessors = void 0;
|
|
16
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
17
|
+
const fetch_1 = __importDefault(require("./fetch"));
|
|
18
|
+
const calculate_1 = __importDefault(require("./calculate"));
|
|
19
|
+
const conditions_1 = __importDefault(require("./conditions"));
|
|
20
|
+
const validate_1 = __importDefault(require("./validate"));
|
|
21
|
+
exports.Proccessors = {
|
|
22
|
+
fetch: fetch_1.default,
|
|
23
|
+
calculate: calculate_1.default,
|
|
24
|
+
conditions: conditions_1.default,
|
|
25
|
+
validate: validate_1.default
|
|
26
|
+
};
|
|
27
|
+
exports.PreProccessors = [
|
|
28
|
+
exports.Proccessors.fetch,
|
|
29
|
+
exports.Proccessors.calculate,
|
|
30
|
+
exports.Proccessors.conditions,
|
|
31
|
+
exports.Proccessors.validate
|
|
32
|
+
];
|
|
33
|
+
const debug = require('debug')('formio:process');
|
|
34
|
+
const error = require('debug')('formio:error');
|
|
35
|
+
const Processor = (scope) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
let errors = [];
|
|
37
|
+
const { form, submission } = scope;
|
|
38
|
+
try {
|
|
39
|
+
debug(`Processing data for ${form.name}...`);
|
|
40
|
+
yield scope.utils.eachComponentData(form.components, submission.data, (component, row, path) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
const value = (0, get_1.default)(row, component.key);
|
|
42
|
+
const processScope = Object.assign(Object.assign({}, scope), { row, component, value, path });
|
|
43
|
+
for (let i = 0; i < exports.PreProccessors.length; i++) {
|
|
44
|
+
yield exports.PreProccessors[i](processScope);
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
error(err);
|
|
50
|
+
errors = [
|
|
51
|
+
{ message: err.message }
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
return errors;
|
|
55
|
+
});
|
|
56
|
+
exports.Processor = Processor;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.default = (scope) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
return [];
|
|
14
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { FormScope } from "./form";
|
|
2
|
+
export interface ProjectConfig {
|
|
3
|
+
url: string;
|
|
4
|
+
key: string;
|
|
5
|
+
}
|
|
6
|
+
export interface User {
|
|
7
|
+
_id: string;
|
|
8
|
+
data: any;
|
|
9
|
+
roles: string[];
|
|
10
|
+
form: string;
|
|
11
|
+
project: string;
|
|
12
|
+
metadata: any;
|
|
13
|
+
}
|
|
14
|
+
export interface AuthToken {
|
|
15
|
+
iat?: number;
|
|
16
|
+
exp?: number;
|
|
17
|
+
user: User;
|
|
18
|
+
form: {
|
|
19
|
+
_id: string;
|
|
20
|
+
};
|
|
21
|
+
project: {
|
|
22
|
+
_id: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface AuthConfig {
|
|
26
|
+
portal: string;
|
|
27
|
+
secret: string;
|
|
28
|
+
expire: number;
|
|
29
|
+
}
|
|
30
|
+
export interface ServerConfig {
|
|
31
|
+
project: ProjectConfig;
|
|
32
|
+
auth: AuthConfig;
|
|
33
|
+
license: string;
|
|
34
|
+
status: any;
|
|
35
|
+
}
|
|
36
|
+
export interface DBConfig {
|
|
37
|
+
url: string;
|
|
38
|
+
name: string;
|
|
39
|
+
config: any;
|
|
40
|
+
}
|
|
41
|
+
export interface ServerDB {
|
|
42
|
+
config: DBConfig;
|
|
43
|
+
connect: () => Promise<void>;
|
|
44
|
+
save: (collection: string, doc: any) => Promise<any>;
|
|
45
|
+
load: (collection: string) => Promise<any>;
|
|
46
|
+
index: (scope: FormScope, query: any) => Promise<any>;
|
|
47
|
+
create: (scope: FormScope, doc: any, allowFields?: string[]) => Promise<any>;
|
|
48
|
+
read: (scope: FormScope, id: string) => Promise<any>;
|
|
49
|
+
update: (scope: FormScope, id: string, doc: any, allowFields?: string[]) => Promise<any>;
|
|
50
|
+
delete: (scope: FormScope, id: string) => Promise<any>;
|
|
51
|
+
find: (scope: FormScope, query: any) => Promise<any>;
|
|
52
|
+
findOne: (scope: FormScope, query: any) => Promise<any>;
|
|
53
|
+
}
|
|
54
|
+
export interface AuthModule {
|
|
55
|
+
token: (user: AuthToken, secret: string, expire: number) => Promise<string>;
|
|
56
|
+
user: (token: string, secret: string) => Promise<AuthToken | null>;
|
|
57
|
+
}
|
|
58
|
+
export interface LicenseTerms {
|
|
59
|
+
serverless: string[];
|
|
60
|
+
}
|
|
61
|
+
export interface LicenseKey {
|
|
62
|
+
terms: LicenseTerms;
|
|
63
|
+
}
|
|
64
|
+
export interface ServerScope {
|
|
65
|
+
licenseKey: LicenseKey;
|
|
66
|
+
config: ServerConfig;
|
|
67
|
+
db: ServerDB;
|
|
68
|
+
auth: AuthModule;
|
|
69
|
+
access: any;
|
|
70
|
+
hooks: any;
|
|
71
|
+
template: any;
|
|
72
|
+
utils: any;
|
|
73
|
+
util: any;
|
|
74
|
+
hook: (name: string, ...args: any[]) => void;
|
|
75
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
import { FormScope } from './form';
|
|
3
|
+
export interface SubmissionResponse extends Response {
|
|
4
|
+
resource?: any;
|
|
5
|
+
proxyRes: (res: any) => void;
|
|
6
|
+
}
|
|
7
|
+
export interface SubmissionRequest extends Request {
|
|
8
|
+
user: any;
|
|
9
|
+
token: any;
|
|
10
|
+
scope: any;
|
|
11
|
+
admin: any;
|
|
12
|
+
headers: any;
|
|
13
|
+
childRequests: number;
|
|
14
|
+
skipSave: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface SubmissionScope extends FormScope {
|
|
17
|
+
submission: any;
|
|
18
|
+
}
|
|
19
|
+
export interface ProcessScope extends SubmissionScope {
|
|
20
|
+
component: any;
|
|
21
|
+
row: any;
|
|
22
|
+
value: any;
|
|
23
|
+
data: any;
|
|
24
|
+
req: SubmissionRequest;
|
|
25
|
+
res: SubmissionResponse;
|
|
26
|
+
}
|
|
27
|
+
export interface PrepScope extends ProcessScope {
|
|
28
|
+
type: string;
|
|
29
|
+
path: string;
|
|
30
|
+
current: any;
|
|
31
|
+
}
|
|
32
|
+
export interface Mail {
|
|
33
|
+
to: string;
|
|
34
|
+
from: string;
|
|
35
|
+
subject: string;
|
|
36
|
+
text: string;
|
|
37
|
+
html: string;
|
|
38
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@formio/appserver",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A highly performant and extensible Application Server for Form.io Multi-Tenant Deployments.",
|
|
5
|
+
"main": "server.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"test": "mocha -r ts-node/register 'src/**/*.spec.ts'"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/formio/appserver.git"
|
|
13
|
+
},
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "OSL-3.0",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/formio/appserver/issues"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib",
|
|
21
|
+
"server.js",
|
|
22
|
+
"package.json",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"homepage": "https://github.com/formio/appserver#readme",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@formio/appserver-core": "^1.1.3",
|
|
28
|
+
"async": "^3.2.4",
|
|
29
|
+
"bcryptjs": "^2.4.3",
|
|
30
|
+
"debug": "^4.3.4",
|
|
31
|
+
"express": "^4.18.2",
|
|
32
|
+
"jsonwebtoken": "^9.0.0",
|
|
33
|
+
"lodash": "^4.17.21",
|
|
34
|
+
"mongodb": "^5.3.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/async": "^3.2.19",
|
|
38
|
+
"@types/bcryptjs": "^2.4.2",
|
|
39
|
+
"@types/express": "^4.17.17",
|
|
40
|
+
"@types/jsonwebtoken": "^9.0.1",
|
|
41
|
+
"@types/lodash": "^4.14.194",
|
|
42
|
+
"@types/mocha": "^10.0.1",
|
|
43
|
+
"@types/node": "^18.16.1",
|
|
44
|
+
"mocha": "^10.2.0",
|
|
45
|
+
"ts-node": "^10.9.1",
|
|
46
|
+
"typescript": "^5.0.4"
|
|
47
|
+
}
|
|
48
|
+
}
|
package/server.js
ADDED