@formio/appserver 2.0.0-rc.8 → 2.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/lib/actions/index.d.ts +3 -156
- package/lib/actions/login/LoginAction.d.ts +2 -109
- 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 +2 -4
- package/lib/modules/mongodb/db.d.ts +31 -32
- package/lib/modules/mongodb/db.js +220 -94
- package/lib/server.d.ts +5 -171
- package/lib/server.js +59 -66
- package/package.json +18 -20
- package/lib/actions/login/LoginAction.spec.d.ts +0 -1
- package/lib/actions/login/LoginAction.spec.js +0 -15
- package/lib/actions/role/RoleAction.spec.d.ts +0 -1
- package/lib/actions/role/RoleAction.spec.js +0 -15
- package/lib/actions/save/SaveAction.spec.d.ts +0 -1
- package/lib/actions/save/SaveAction.spec.js +0 -15
- package/lib/modules/auth/auth.d.ts +0 -5
- package/lib/modules/auth/auth.js +0 -70
- package/lib/modules/auth/auth.spec.d.ts +0 -1
- package/lib/modules/auth/auth.spec.js +0 -93
- package/lib/modules/mongodb/db.spec.d.ts +0 -1
- package/lib/modules/mongodb/db.spec.js +0 -714
- package/server.js +0 -1
package/lib/server.d.ts
CHANGED
|
@@ -1,173 +1,7 @@
|
|
|
1
|
-
import { Server as CoreServer } from '@formio/appserver-core';
|
|
2
|
-
|
|
3
|
-
import Actions from "./actions";
|
|
4
|
-
import { AppServerScope, AppServerProcessors } from '@formio/appserver-types';
|
|
5
|
-
export declare const Modules: {
|
|
6
|
-
db: typeof Database;
|
|
7
|
-
auth: typeof Auth;
|
|
8
|
-
processors: AppServerProcessors;
|
|
9
|
-
actions: {
|
|
10
|
-
save: {
|
|
11
|
-
readonly info: {
|
|
12
|
-
name: string;
|
|
13
|
-
title: string;
|
|
14
|
-
description: string;
|
|
15
|
-
priority: number;
|
|
16
|
-
defaults: {
|
|
17
|
-
handler: string[];
|
|
18
|
-
method: string[];
|
|
19
|
-
};
|
|
20
|
-
access: {
|
|
21
|
-
handler: boolean;
|
|
22
|
-
method: boolean;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
mappingComponents(scope: import("@formio/appserver-types").ActionScope): Promise<any>;
|
|
26
|
-
settingsForm(scope: import("@formio/appserver-types").ActionScope): Promise<any>;
|
|
27
|
-
saveToForm(scope: import("@formio/appserver-types").ActionScope, resource: string): undefined;
|
|
28
|
-
childSubmission(scope: import("@formio/appserver-types").ActionScope, req: import("@formio/appserver-types").SubmissionRequest, res: import("@formio/appserver-types").SubmissionResponse, submission: any): any;
|
|
29
|
-
childResponse(scope: import("@formio/appserver-types").ActionScope, req: import("@formio/appserver-types").SubmissionRequest, res: import("@formio/appserver-types").SubmissionResponse): void;
|
|
30
|
-
executor(scope: import("@formio/appserver-types").ActionScope): Promise<(req: import("@formio/appserver-types").SubmissionRequest, res: import("@formio/appserver-types").SubmissionResponse, next: import("express").NextFunction) => Promise<void>>;
|
|
31
|
-
};
|
|
32
|
-
login: {
|
|
33
|
-
readonly info: {
|
|
34
|
-
name: string;
|
|
35
|
-
title: string;
|
|
36
|
-
description: string;
|
|
37
|
-
priority: number;
|
|
38
|
-
defaults: {
|
|
39
|
-
handler: string[];
|
|
40
|
-
method: string[];
|
|
41
|
-
};
|
|
42
|
-
access: {
|
|
43
|
-
handler: boolean;
|
|
44
|
-
method: boolean;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
settingsForm(scope: import("@formio/appserver-types").ActionScope): Promise<({
|
|
48
|
-
type: string;
|
|
49
|
-
label: string;
|
|
50
|
-
key: string;
|
|
51
|
-
placeholder: string;
|
|
52
|
-
dataSrc: string;
|
|
53
|
-
valueProperty: string;
|
|
54
|
-
data: {
|
|
55
|
-
json: any;
|
|
56
|
-
};
|
|
57
|
-
multiple: boolean;
|
|
58
|
-
validate: {
|
|
59
|
-
required: boolean;
|
|
60
|
-
};
|
|
61
|
-
input?: undefined;
|
|
62
|
-
description?: undefined;
|
|
63
|
-
defaultValue?: undefined;
|
|
64
|
-
suffix?: undefined;
|
|
65
|
-
} | {
|
|
66
|
-
type: string;
|
|
67
|
-
input: boolean;
|
|
68
|
-
label: string;
|
|
69
|
-
key: string;
|
|
70
|
-
placeholder: string;
|
|
71
|
-
dataSrc: string;
|
|
72
|
-
valueProperty: string;
|
|
73
|
-
data: {
|
|
74
|
-
json: any;
|
|
75
|
-
};
|
|
76
|
-
multiple: boolean;
|
|
77
|
-
validate: {
|
|
78
|
-
required: boolean;
|
|
79
|
-
};
|
|
80
|
-
description?: undefined;
|
|
81
|
-
defaultValue?: undefined;
|
|
82
|
-
suffix?: undefined;
|
|
83
|
-
} | {
|
|
84
|
-
type: string;
|
|
85
|
-
key: string;
|
|
86
|
-
input: boolean;
|
|
87
|
-
label: string;
|
|
88
|
-
description: string;
|
|
89
|
-
defaultValue: string;
|
|
90
|
-
placeholder?: undefined;
|
|
91
|
-
dataSrc?: undefined;
|
|
92
|
-
valueProperty?: undefined;
|
|
93
|
-
data?: undefined;
|
|
94
|
-
multiple?: undefined;
|
|
95
|
-
validate?: undefined;
|
|
96
|
-
suffix?: undefined;
|
|
97
|
-
} | {
|
|
98
|
-
type: string;
|
|
99
|
-
key: string;
|
|
100
|
-
input: boolean;
|
|
101
|
-
label: string;
|
|
102
|
-
description: string;
|
|
103
|
-
defaultValue: string;
|
|
104
|
-
suffix: string;
|
|
105
|
-
placeholder?: undefined;
|
|
106
|
-
dataSrc?: undefined;
|
|
107
|
-
valueProperty?: undefined;
|
|
108
|
-
data?: undefined;
|
|
109
|
-
multiple?: undefined;
|
|
110
|
-
validate?: undefined;
|
|
111
|
-
})[]>;
|
|
112
|
-
waitText(time: number): string;
|
|
113
|
-
checkAttempts(scope: import("@formio/appserver-types").ActionScope, error: any, user: import("@formio/core").Submission): Promise<any>;
|
|
114
|
-
executor(scope: import("@formio/appserver-types").ActionScope): Promise<(req: import("@formio/appserver-types").SubmissionRequest, res: import("@formio/appserver-types").SubmissionResponse, next: import("express").NextFunction) => Promise<void>>;
|
|
115
|
-
};
|
|
116
|
-
role: {
|
|
117
|
-
readonly info: {
|
|
118
|
-
name: string;
|
|
119
|
-
title: string;
|
|
120
|
-
description: string;
|
|
121
|
-
priority: number;
|
|
122
|
-
defaults: {
|
|
123
|
-
handler: string[];
|
|
124
|
-
method: string[];
|
|
125
|
-
};
|
|
126
|
-
access: {
|
|
127
|
-
handler: boolean;
|
|
128
|
-
method: boolean;
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
settingsForm(scope: import("@formio/appserver-types").ActionScope): Promise<({
|
|
132
|
-
type: string;
|
|
133
|
-
input: boolean;
|
|
134
|
-
label: string;
|
|
135
|
-
key: string;
|
|
136
|
-
placeholder: string;
|
|
137
|
-
template: string;
|
|
138
|
-
dataSrc: string;
|
|
139
|
-
data: {
|
|
140
|
-
json: string;
|
|
141
|
-
};
|
|
142
|
-
valueProperty: string;
|
|
143
|
-
multiple: boolean;
|
|
144
|
-
validate: {
|
|
145
|
-
required: boolean;
|
|
146
|
-
};
|
|
147
|
-
} | {
|
|
148
|
-
type: string;
|
|
149
|
-
input: boolean;
|
|
150
|
-
label: string;
|
|
151
|
-
key: string;
|
|
152
|
-
placeholder: string;
|
|
153
|
-
template: string;
|
|
154
|
-
dataSrc: string;
|
|
155
|
-
data: {
|
|
156
|
-
json: unknown[];
|
|
157
|
-
};
|
|
158
|
-
valueProperty: string;
|
|
159
|
-
multiple: boolean;
|
|
160
|
-
validate: {
|
|
161
|
-
required: boolean;
|
|
162
|
-
};
|
|
163
|
-
})[]>;
|
|
164
|
-
executor(scope: import("@formio/appserver-types").ActionScope): Promise<(req: import("@formio/appserver-types").SubmissionRequest, res: import("@formio/appserver-types").SubmissionResponse, next: import("express").NextFunction) => Promise<void | import("@formio/appserver-types").SubmissionResponse>>;
|
|
165
|
-
};
|
|
166
|
-
};
|
|
167
|
-
};
|
|
1
|
+
import { Server as CoreServer, ServerConfig } from '@formio/appserver-core';
|
|
2
|
+
export * from '@formio/appserver-core';
|
|
168
3
|
export declare class Server extends CoreServer {
|
|
169
|
-
constructor(config?:
|
|
4
|
+
constructor(config?: ServerConfig);
|
|
170
5
|
}
|
|
171
|
-
export
|
|
172
|
-
export
|
|
173
|
-
export { Actions };
|
|
6
|
+
export * from './modules';
|
|
7
|
+
export * from './actions';
|
package/lib/server.js
CHANGED
|
@@ -1,83 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
18
|
};
|
|
5
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
20
|
+
exports.Server = void 0;
|
|
7
21
|
// Load the license key.
|
|
8
|
-
const
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const get_1 = __importDefault(require("lodash/get"));
|
|
11
|
-
const process_1 = require("process");
|
|
12
|
-
let licenseKey = (0, get_1.default)(process.env, 'APPSERVER_LICENSE', (0, get_1.default)(process.env, 'LICENSE_KEY', ''));
|
|
13
|
-
if (!licenseKey) {
|
|
14
|
-
try {
|
|
15
|
-
licenseKey = fs_1.default.readFileSync(path_1.default.join((0, process_1.cwd)(), 'license.txt'), 'utf8');
|
|
16
|
-
}
|
|
17
|
-
catch (err) {
|
|
18
|
-
console.log('No license key found. Please set the APPSERVER_LICENSE environment variable or create a license.txt file in the root of the project.');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
22
|
+
const lodash_1 = require("lodash");
|
|
21
23
|
const appserver_core_1 = require("@formio/appserver-core");
|
|
22
24
|
const modules_1 = require("./modules");
|
|
23
|
-
Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return modules_1.Database; } });
|
|
24
|
-
Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return modules_1.Auth; } });
|
|
25
25
|
const actions_1 = __importDefault(require("./actions"));
|
|
26
|
-
exports.Actions = actions_1.default;
|
|
27
26
|
const defaultsDeep_1 = __importDefault(require("lodash/defaultsDeep"));
|
|
27
|
+
``;
|
|
28
28
|
const packageJson = require('../package.json');
|
|
29
29
|
const appCorePackage = require('@formio/appserver-core/package.json');
|
|
30
|
-
|
|
31
|
-
exports.Modules = {
|
|
32
|
-
db: modules_1.Database,
|
|
33
|
-
auth: modules_1.Auth,
|
|
34
|
-
processors: {
|
|
35
|
-
read: [],
|
|
36
|
-
submission: []
|
|
37
|
-
},
|
|
38
|
-
actions: actions_1.default
|
|
39
|
-
};
|
|
30
|
+
__exportStar(require("@formio/appserver-core"), exports);
|
|
40
31
|
class Server extends appserver_core_1.Server {
|
|
41
|
-
constructor(config
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
'@formio/appserver': packageJson.version,
|
|
66
|
-
'@formio/appserver-core': appCorePackage.version,
|
|
67
|
-
'@formio/core': corePackage.version
|
|
68
|
-
},
|
|
69
|
-
auth: {
|
|
70
|
-
portal: (0, get_1.default)(process.env, 'PORTAL_SECRET', ''),
|
|
71
|
-
secret: (0, get_1.default)(process.env, 'JWT_SECRET', ''),
|
|
72
|
-
expire: (0, get_1.default)(process.env, 'JWT_EXPIRE_TIME', 240)
|
|
73
|
-
},
|
|
74
|
-
project: {
|
|
75
|
-
url: (0, get_1.default)(process.env, 'PROJECT_ENDPOINT', ''),
|
|
76
|
-
key: (0, get_1.default)(process.env, 'PROJECT_KEY', '')
|
|
32
|
+
constructor(config) {
|
|
33
|
+
super((0, defaultsDeep_1.default)(config || {}, {
|
|
34
|
+
cors: (0, lodash_1.get)(process.env, 'CORS', true).toString(),
|
|
35
|
+
license: (0, lodash_1.get)(process.env, 'APPSERVER_LICENSE', (0, lodash_1.get)(process.env, 'LICENSE_KEY', '')),
|
|
36
|
+
cache: ((0, lodash_1.get)(process.env, 'PROJECT_CACHE', true).toString() === 'true'),
|
|
37
|
+
status: {
|
|
38
|
+
version: '8.0.0',
|
|
39
|
+
'@formio/appserver': packageJson.version,
|
|
40
|
+
'@formio/appserver-core': appCorePackage.version
|
|
41
|
+
},
|
|
42
|
+
auth: {
|
|
43
|
+
portal: (0, lodash_1.get)(process.env, 'PORTAL_SECRET', ''),
|
|
44
|
+
adminKey: (0, lodash_1.get)(process.env, 'ADMIN_KEY', ''),
|
|
45
|
+
projectKey: (0, lodash_1.get)(process.env, 'PROJECT_KEY', ''),
|
|
46
|
+
secret: (0, lodash_1.get)(process.env, 'JWT_SECRET', ''),
|
|
47
|
+
expire: parseInt((0, lodash_1.get)(process.env, 'JWT_EXPIRE_TIME', 3600).toString(), 10),
|
|
48
|
+
loginForm: (0, lodash_1.get)(process.env, 'LOGIN_FORM', ''),
|
|
49
|
+
oidc: {
|
|
50
|
+
issuer: (0, lodash_1.get)(process.env, 'OIDC_ISSUER', ''),
|
|
51
|
+
clientId: (0, lodash_1.get)(process.env, 'OIDC_CLIENT_ID', ''),
|
|
52
|
+
clientSecret: (0, lodash_1.get)(process.env, 'OIDC_CLIENT_SECRET', ''),
|
|
53
|
+
scope: (0, lodash_1.get)(process.env, 'OIDC_SCOPE', 'openid profile email'),
|
|
54
|
+
responseType: (0, lodash_1.get)(process.env, 'OIDC_RESPONSE_TYPE', 'code'),
|
|
55
|
+
responseMode: (0, lodash_1.get)(process.env, 'OIDC_RESPONSE_MODE', 'query')
|
|
77
56
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
57
|
+
},
|
|
58
|
+
project: (0, lodash_1.get)(process.env, 'PROJECT', ''),
|
|
59
|
+
submissionProxy: (0, lodash_1.get)(process.env, 'SUBMISSION_PROXY', '').toString(),
|
|
60
|
+
projects: (0, lodash_1.get)(process.env, 'PROJECTS', '').split(',').filter((p) => !!p),
|
|
61
|
+
maxBodySize: (0, lodash_1.get)(process.env, 'MAX_BODY_SIZE', '100mb')
|
|
62
|
+
}));
|
|
63
|
+
// Default the actions.
|
|
64
|
+
this.addActions(actions_1.default);
|
|
65
|
+
// Add a default database.
|
|
66
|
+
if (!this.config.db) {
|
|
67
|
+
const mongo = (0, lodash_1.get)(process.env, 'MONGO', '');
|
|
68
|
+
if (mongo) {
|
|
69
|
+
this.db = new modules_1.Database({ url: mongo, config: (0, lodash_1.get)(process.env, 'MONGO_CONFIG', '') });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
81
72
|
}
|
|
82
73
|
}
|
|
83
74
|
exports.Server = Server;
|
|
75
|
+
__exportStar(require("./modules"), exports);
|
|
76
|
+
__exportStar(require("./actions"), exports);
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formio/appserver",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A highly performant and extensible Application Server for Form.io Multi-Tenant Deployments.",
|
|
5
|
-
"main": "server.js",
|
|
5
|
+
"main": "lib/server.js",
|
|
6
|
+
"types": "lib/server.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"build
|
|
9
|
-
"build:modules": "npm run build:db && npm run build:auth",
|
|
10
|
-
"build": "npm run build:modules && tsc",
|
|
8
|
+
"clean": "rm -rf lib",
|
|
9
|
+
"build": "npm run clean && tsc",
|
|
11
10
|
"test": "mocha",
|
|
12
11
|
"prepack": "npm run build"
|
|
13
12
|
},
|
|
@@ -28,33 +27,32 @@
|
|
|
28
27
|
],
|
|
29
28
|
"homepage": "https://github.com/formio/appserver#readme",
|
|
30
29
|
"dependencies": {
|
|
31
|
-
"@formio/appserver-
|
|
32
|
-
"@formio/
|
|
33
|
-
"@formio/appserver-db-mongodb": "^2.0.0-rc.3",
|
|
34
|
-
"@formio/appserver-types": "^2.0.0-rc.4",
|
|
35
|
-
"@formio/core": "2.4.0-dev.286.23ccfc3",
|
|
36
|
-
"@formio/license": "2.0.1",
|
|
30
|
+
"@formio/appserver-core": "2.0.0",
|
|
31
|
+
"@formio/core": "2.5.1-dev.291.98f47af",
|
|
37
32
|
"async": "^3.2.6",
|
|
38
33
|
"bcryptjs": "^3.0.2",
|
|
39
|
-
"debug": "^4.4.
|
|
40
|
-
"dotenv": "^17.2.
|
|
34
|
+
"debug": "^4.4.3",
|
|
35
|
+
"dotenv": "^17.2.3",
|
|
41
36
|
"express": "^5.1.0",
|
|
42
37
|
"jsonwebtoken": "^9.0.2",
|
|
43
|
-
"lodash": "^4.17.21"
|
|
38
|
+
"lodash": "^4.17.21",
|
|
39
|
+
"mongodb": "^6.19.0"
|
|
44
40
|
},
|
|
45
41
|
"devDependencies": {
|
|
46
|
-
"@formio/js": "^5.2.0",
|
|
47
42
|
"@types/async": "^3.2.25",
|
|
48
43
|
"@types/bcryptjs": "^3.0.0",
|
|
44
|
+
"@types/chai": "^5.2.2",
|
|
49
45
|
"@types/express": "^5.0.3",
|
|
50
46
|
"@types/jsonwebtoken": "^9.0.10",
|
|
51
47
|
"@types/lodash": "^4.17.20",
|
|
52
48
|
"@types/mocha": "^10.0.10",
|
|
53
|
-
"@types/node": "^24.
|
|
54
|
-
"
|
|
55
|
-
"
|
|
49
|
+
"@types/node": "^24.7.1",
|
|
50
|
+
"chai": "^6.0.1",
|
|
51
|
+
"cross-env": "^10.1.0",
|
|
52
|
+
"mocha": "^11.7.4",
|
|
53
|
+
"mongodb-memory-server": "^10.2.3",
|
|
56
54
|
"ts-node": "^10.9.2",
|
|
57
55
|
"tsconfig-paths": "^4.2.0",
|
|
58
|
-
"typescript": "^5.9.
|
|
56
|
+
"typescript": "^5.9.3"
|
|
59
57
|
}
|
|
60
58
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const LoginAction_1 = require("./LoginAction");
|
|
7
|
-
const assert_1 = __importDefault(require("assert"));
|
|
8
|
-
describe('LoginAction', () => {
|
|
9
|
-
it('Validate the LoginAction information', () => {
|
|
10
|
-
const info = LoginAction_1.LoginAction.info;
|
|
11
|
-
assert_1.default.equal(info.name, 'login');
|
|
12
|
-
assert_1.default.equal(info.title, 'Login');
|
|
13
|
-
});
|
|
14
|
-
it('TO-DO: Write tests for LoginAction');
|
|
15
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const RoleAction_1 = require("./RoleAction");
|
|
7
|
-
const assert_1 = __importDefault(require("assert"));
|
|
8
|
-
describe('RoleAction', () => {
|
|
9
|
-
it('Validate the RoleAction information', () => {
|
|
10
|
-
const info = RoleAction_1.RoleAction.info;
|
|
11
|
-
assert_1.default.equal(info.name, 'role');
|
|
12
|
-
assert_1.default.equal(info.title, 'Role Assignment');
|
|
13
|
-
});
|
|
14
|
-
it('TO-DO: Write tests for RoleAction');
|
|
15
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const SaveAction_1 = require("./SaveAction");
|
|
7
|
-
const assert_1 = __importDefault(require("assert"));
|
|
8
|
-
describe('SaveAction', () => {
|
|
9
|
-
it('Validate the SaveAction information', () => {
|
|
10
|
-
const info = SaveAction_1.SaveAction.info;
|
|
11
|
-
assert_1.default.equal(info.name, 'save');
|
|
12
|
-
assert_1.default.equal(info.title, 'Save Submission');
|
|
13
|
-
});
|
|
14
|
-
it('TO-DO: Write tests for SaveAction');
|
|
15
|
-
});
|
package/lib/modules/auth/auth.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
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.Auth = void 0;
|
|
16
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
17
|
-
const debug = require('debug')('formio:auth');
|
|
18
|
-
const error = require('debug')('formio:error');
|
|
19
|
-
class Auth {
|
|
20
|
-
token(user_1, secret_1) {
|
|
21
|
-
return __awaiter(this, arguments, void 0, function* (user, secret, expire = 240) {
|
|
22
|
-
user = Object.assign({}, user);
|
|
23
|
-
delete user.iat;
|
|
24
|
-
delete user.exp;
|
|
25
|
-
return new Promise((resolve, reject) => {
|
|
26
|
-
if (!secret) {
|
|
27
|
-
return reject(new Error('You cannot generate a token without a secret!'));
|
|
28
|
-
}
|
|
29
|
-
debug('auth.token()', user);
|
|
30
|
-
jsonwebtoken_1.default.sign(user, secret, {
|
|
31
|
-
expiresIn: expire * 60,
|
|
32
|
-
}, (err, signed) => {
|
|
33
|
-
if (err) {
|
|
34
|
-
error(err);
|
|
35
|
-
return reject(err);
|
|
36
|
-
}
|
|
37
|
-
resolve(signed || '');
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
user(token, secret) {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
if (!token) {
|
|
45
|
-
return Promise.resolve(null);
|
|
46
|
-
}
|
|
47
|
-
return new Promise((resolve, reject) => {
|
|
48
|
-
if (!secret) {
|
|
49
|
-
return reject('You cannot authenticate without a JWT Secret!');
|
|
50
|
-
}
|
|
51
|
-
debug('auth.verify()', token);
|
|
52
|
-
jsonwebtoken_1.default.verify(token, secret, (err, payload) => {
|
|
53
|
-
if (err) {
|
|
54
|
-
error(err);
|
|
55
|
-
if (err.name === 'JsonWebTokenError') {
|
|
56
|
-
return reject({ message: 'Bad Token' });
|
|
57
|
-
}
|
|
58
|
-
if (err.name === 'TokenExpiredError') {
|
|
59
|
-
return reject({ message: 'Token Expired' });
|
|
60
|
-
}
|
|
61
|
-
return reject(err);
|
|
62
|
-
}
|
|
63
|
-
debug('auth.user()', payload);
|
|
64
|
-
resolve(payload);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.Auth = Auth;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,93 +0,0 @@
|
|
|
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 auth_1 = require("./auth");
|
|
16
|
-
const assert_1 = __importDefault(require("assert"));
|
|
17
|
-
describe('Auth', () => {
|
|
18
|
-
const user = {
|
|
19
|
-
user: {
|
|
20
|
-
_id: 'test',
|
|
21
|
-
data: {
|
|
22
|
-
firstName: 'Joe',
|
|
23
|
-
lastName: 'Smith',
|
|
24
|
-
email: 'joe@example.com'
|
|
25
|
-
},
|
|
26
|
-
roles: [
|
|
27
|
-
'1234',
|
|
28
|
-
'2468'
|
|
29
|
-
],
|
|
30
|
-
form: '234234243234234234',
|
|
31
|
-
project: '213312131213212334'
|
|
32
|
-
},
|
|
33
|
-
form: {
|
|
34
|
-
_id: '234234243234234234'
|
|
35
|
-
},
|
|
36
|
-
project: {
|
|
37
|
-
_id: '213312131213212334'
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
let token = '';
|
|
41
|
-
it('Should return a valid auth token for a valid user', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
const auth = new auth_1.Auth();
|
|
43
|
-
token = yield auth.token(user, 'test', 240);
|
|
44
|
-
(0, assert_1.default)(token, 'It must generate a valid token');
|
|
45
|
-
}));
|
|
46
|
-
it('Should validate that the token is valid', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
-
const auth = new auth_1.Auth();
|
|
48
|
-
const tokenUser = yield auth.user(token, 'test');
|
|
49
|
-
(0, assert_1.default)(tokenUser === null || tokenUser === void 0 ? void 0 : tokenUser.iat, 'It must have an iat');
|
|
50
|
-
(0, assert_1.default)(tokenUser === null || tokenUser === void 0 ? void 0 : tokenUser.exp, 'It must have an exp');
|
|
51
|
-
tokenUser === null || tokenUser === void 0 ? true : delete tokenUser.iat;
|
|
52
|
-
tokenUser === null || tokenUser === void 0 ? true : delete tokenUser.exp;
|
|
53
|
-
assert_1.default.deepEqual(tokenUser, user);
|
|
54
|
-
}));
|
|
55
|
-
it('Should throw an error with "Bad Token" for an invalid token', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
-
const auth = new auth_1.Auth();
|
|
57
|
-
try {
|
|
58
|
-
yield auth.user('invalid', 'test');
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
assert_1.default.equal(err.message, 'Bad Token');
|
|
62
|
-
}
|
|
63
|
-
}));
|
|
64
|
-
it('Should throw an error with "Token Expired" for an expired token', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
-
const auth = new auth_1.Auth();
|
|
66
|
-
token = yield auth.token(user, 'test', 0);
|
|
67
|
-
try {
|
|
68
|
-
yield auth.user(token, 'test');
|
|
69
|
-
}
|
|
70
|
-
catch (err) {
|
|
71
|
-
assert_1.default.equal(err.message, 'Token Expired');
|
|
72
|
-
}
|
|
73
|
-
}));
|
|
74
|
-
it('Should throw an error for a token without a secret', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
-
const auth = new auth_1.Auth();
|
|
76
|
-
try {
|
|
77
|
-
yield auth.token(user, '');
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
assert_1.default.equal(err.message, 'You cannot generate a token without a secret!');
|
|
81
|
-
}
|
|
82
|
-
}));
|
|
83
|
-
it('Should throw an error for a token with the wrong secret', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
-
const auth = new auth_1.Auth();
|
|
85
|
-
token = yield auth.token(user, 'test', 0);
|
|
86
|
-
try {
|
|
87
|
-
yield auth.user(token, '1234');
|
|
88
|
-
}
|
|
89
|
-
catch (err) {
|
|
90
|
-
assert_1.default.equal(err.message, 'Bad Token');
|
|
91
|
-
}
|
|
92
|
-
}));
|
|
93
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|