@formio/appserver 2.0.0-rc.1 → 2.0.0-rc.3

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.
Files changed (46) hide show
  1. package/README.md +12 -6
  2. package/lib/actions/index.d.ts +11 -11
  3. package/lib/actions/login/LoginAction.d.ts +3 -2
  4. package/lib/actions/login/LoginAction.spec.d.ts +1 -0
  5. package/lib/actions/login/LoginAction.spec.js +15 -0
  6. package/lib/actions/role/RoleAction.spec.d.ts +1 -0
  7. package/lib/actions/role/RoleAction.spec.js +15 -0
  8. package/lib/actions/save/SaveAction.spec.d.ts +1 -0
  9. package/lib/actions/save/SaveAction.spec.js +15 -0
  10. package/lib/modules/auth/auth.spec.d.ts +1 -0
  11. package/lib/modules/auth/auth.spec.js +93 -0
  12. package/lib/modules/index.d.ts +1 -1
  13. package/lib/modules/index.js +2 -2
  14. package/lib/modules/mongodb/db.d.ts +128 -0
  15. package/lib/modules/mongodb/db.js +706 -0
  16. package/lib/modules/mongodb/db.spec.d.ts +1 -0
  17. package/lib/modules/mongodb/db.spec.js +714 -0
  18. package/lib/server.d.ts +3 -6
  19. package/lib/server.js +8 -12
  20. package/package.json +20 -20
  21. package/lib/prepare/access.d.ts +0 -3
  22. package/lib/prepare/access.js +0 -62
  23. package/lib/prepare/bcrypt.d.ts +0 -3
  24. package/lib/prepare/bcrypt.js +0 -25
  25. package/lib/prepare/index.d.ts +0 -11
  26. package/lib/prepare/index.js +0 -60
  27. package/lib/prepare/password.d.ts +0 -3
  28. package/lib/prepare/password.js +0 -27
  29. package/lib/prepare/persist.d.ts +0 -3
  30. package/lib/prepare/persist.js +0 -24
  31. package/lib/prepare/protect.d.ts +0 -3
  32. package/lib/prepare/protect.js +0 -28
  33. package/lib/prepare/reference.d.ts +0 -3
  34. package/lib/prepare/reference.js +0 -71
  35. package/lib/types/action.d.ts +0 -7
  36. package/lib/types/action.js +0 -2
  37. package/lib/types/form.d.ts +0 -4
  38. package/lib/types/form.js +0 -2
  39. package/lib/types/index.d.ts +0 -5
  40. package/lib/types/index.js +0 -21
  41. package/lib/types/project.d.ts +0 -4
  42. package/lib/types/project.js +0 -2
  43. package/lib/types/server.d.ts +0 -102
  44. package/lib/types/server.js +0 -2
  45. package/lib/types/submission.d.ts +0 -47
  46. package/lib/types/submission.js +0 -2
package/README.md CHANGED
@@ -170,12 +170,18 @@ const { CustomAction } = require('./actions/custom');
170
170
  *
171
171
  * The "scope" argument is a ProcessScope type. See https://github.com/formio/appserver/blob/main/src/types/submission.ts
172
172
  */
173
- processors: Processor.processors.concat([
174
- async (scope) => {
175
- console.log('Custom Processor');
176
- return [];
177
- },
178
- ])
173
+ processors: {
174
+ submission: [
175
+ (scope) => {},
176
+ (scope) => {}
177
+ ],
178
+ evaluator: [
179
+ (scope) => {}
180
+ ],
181
+ prepare: [
182
+ (scope) => {}
183
+ ]
184
+ }
179
185
  });
180
186
 
181
187
  // Initialize the server.
@@ -14,12 +14,12 @@ declare const _default: {
14
14
  method: boolean;
15
15
  };
16
16
  };
17
- mappingComponents(scope: import("src/types/lib").ActionScope): Promise<any>;
18
- settingsForm(scope: import("src/types/lib").ActionScope): Promise<any>;
19
- saveToForm(scope: import("src/types/lib").ActionScope, resource: string): undefined;
20
- childSubmission(scope: import("src/types/lib").ActionScope, req: import("src/types/lib").SubmissionRequest, res: import("src/types/lib").SubmissionResponse, submission: any): any;
21
- childResponse(scope: import("src/types/lib").ActionScope, req: import("src/types/lib").SubmissionRequest, res: import("src/types/lib").SubmissionResponse): void;
22
- executor(scope: import("src/types/lib").ActionScope): Promise<(req: import("src/types/lib").SubmissionRequest, res: import("src/types/lib").SubmissionResponse, next: import("express").NextFunction) => Promise<void>>;
17
+ mappingComponents(scope: import("@formio/appserver-types").ActionScope): Promise<any>;
18
+ settingsForm(scope: import("@formio/appserver-types").ActionScope): Promise<any>;
19
+ saveToForm(scope: import("@formio/appserver-types").ActionScope, resource: string): undefined;
20
+ childSubmission(scope: import("@formio/appserver-types").ActionScope, req: import("@formio/appserver-types").SubmissionRequest, res: import("@formio/appserver-types").SubmissionResponse, submission: any): any;
21
+ childResponse(scope: import("@formio/appserver-types").ActionScope, req: import("@formio/appserver-types").SubmissionRequest, res: import("@formio/appserver-types").SubmissionResponse): void;
22
+ 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>>;
23
23
  };
24
24
  login: {
25
25
  readonly info: {
@@ -36,7 +36,7 @@ declare const _default: {
36
36
  method: boolean;
37
37
  };
38
38
  };
39
- settingsForm(scope: import("src/types/lib").ActionScope): Promise<({
39
+ settingsForm(scope: import("@formio/appserver-types").ActionScope): Promise<({
40
40
  type: string;
41
41
  label: string;
42
42
  key: string;
@@ -102,8 +102,8 @@ declare const _default: {
102
102
  validate?: undefined;
103
103
  })[]>;
104
104
  waitText(time: number): string;
105
- checkAttempts(scope: import("src/types/lib").ActionScope, error: any, user: import("src/types/lib").User): Promise<any>;
106
- executor(scope: import("src/types/lib").ActionScope): Promise<(req: import("src/types/lib").SubmissionRequest, res: import("src/types/lib").SubmissionResponse, next: import("express").NextFunction) => Promise<void>>;
105
+ checkAttempts(scope: import("@formio/appserver-types").ActionScope, error: any, user: import("@formio/core").Submission): Promise<any>;
106
+ 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>>;
107
107
  };
108
108
  role: {
109
109
  readonly info: {
@@ -120,7 +120,7 @@ declare const _default: {
120
120
  method: boolean;
121
121
  };
122
122
  };
123
- settingsForm(scope: import("src/types/lib").ActionScope): Promise<({
123
+ settingsForm(scope: import("@formio/appserver-types").ActionScope): Promise<({
124
124
  type: string;
125
125
  input: boolean;
126
126
  label: string;
@@ -153,7 +153,7 @@ declare const _default: {
153
153
  required: boolean;
154
154
  };
155
155
  })[]>;
156
- executor(scope: import("src/types/lib").ActionScope): Promise<(req: import("src/types/lib").SubmissionRequest, res: import("src/types/lib").SubmissionResponse, next: import("express").NextFunction) => Promise<void | import("src/types/lib").SubmissionResponse>>;
156
+ 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>>;
157
157
  };
158
158
  };
159
159
  export default _default;
@@ -1,5 +1,6 @@
1
1
  import { NextFunction } from 'express';
2
- import { ActionScope, User, SubmissionRequest, SubmissionResponse } from '@formio/appserver-types';
2
+ import { ActionScope, SubmissionRequest, SubmissionResponse } from '@formio/appserver-types';
3
+ import { Submission } from '@formio/core/types';
3
4
  export declare const LoginAction: {
4
5
  readonly info: {
5
6
  name: string;
@@ -98,7 +99,7 @@ export declare const LoginAction: {
98
99
  * @param next
99
100
  * @returns {*}
100
101
  */
101
- checkAttempts(scope: ActionScope, error: any, user: User): Promise<any>;
102
+ checkAttempts(scope: ActionScope, error: any, user: Submission): Promise<any>;
102
103
  /**
103
104
  * Returns the action middleware.
104
105
  *
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
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
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
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
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
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
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,93 @@
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,3 +1,3 @@
1
- import { Database } from '@formio/appserver-db-mongodb';
1
+ import { Database } from './mongodb/db';
2
2
  import { Auth } from '@formio/appserver-auth-jwt';
3
3
  export { Database, Auth };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Auth = exports.Database = void 0;
4
- const appserver_db_mongodb_1 = require("@formio/appserver-db-mongodb");
5
- Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return appserver_db_mongodb_1.Database; } });
4
+ const db_1 = require("./mongodb/db");
5
+ Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return db_1.Database; } });
6
6
  const appserver_auth_jwt_1 = require("@formio/appserver-auth-jwt");
7
7
  Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return appserver_auth_jwt_1.Auth; } });
@@ -0,0 +1,128 @@
1
+ import { Collection, Document, Db, FindOptions, MongoClient } from 'mongodb';
2
+ import { DBConfig, ServerDB, FormScope } from '@formio/appserver-types';
3
+ import { ValidationContext } from '@formio/core/types';
4
+ export type DatabaseIndexResponse = {
5
+ items: Document[];
6
+ count: number;
7
+ skip: number;
8
+ limit: number;
9
+ };
10
+ export declare class Database implements ServerDB {
11
+ config: DBConfig;
12
+ db: Db | null;
13
+ client: MongoClient | null;
14
+ currentCollectionName: string;
15
+ currentCollection: Collection<Document> | null;
16
+ defaultCollection: Collection<Document> | null;
17
+ prefix: string;
18
+ constructor(config: DBConfig);
19
+ ObjectId(id: any): any;
20
+ collectionName(name: string): string;
21
+ /**
22
+ * Connect to the database.
23
+ * @param {*} scope
24
+ * @returns
25
+ */
26
+ connect(prefix?: string): Promise<void>;
27
+ close(): Promise<void>;
28
+ collection(name: string): Collection<Document> | null;
29
+ save(collectionName: string, item: any): Promise<import("mongodb").WithId<Document> | null>;
30
+ saveOne(collectionName: string, item: any): Promise<import("mongodb").WithId<Document> | null>;
31
+ load(collectionName: string, query?: {}): Promise<import("mongodb").WithId<Document> | null | undefined>;
32
+ remove(collectionName: string, query?: {}): Promise<number | null>;
33
+ /**
34
+ * Ensures the form collection is created an returns it.
35
+ * @param scope
36
+ * @returns
37
+ */
38
+ formCollection(scope: FormScope): Promise<Collection<Document> | null>;
39
+ /**
40
+ * Setup indexes.
41
+ */
42
+ setupIndexes(collection: Collection<Document> | null, scope?: FormScope): Promise<void>;
43
+ /**
44
+ * Add a field index
45
+ */
46
+ addIndex(collection: Collection<Document> | null, path: string): Promise<void>;
47
+ /**
48
+ * Adds new indexes to the forms submission collection.
49
+ * @param scope
50
+ * @param indexes
51
+ * @returns
52
+ */
53
+ addIndexes(scope: FormScope, 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 scope
61
+ * @param indexes
62
+ * @returns
63
+ */
64
+ removeIndexes(scope: FormScope, indexes: string[]): Promise<void>;
65
+ /**
66
+ * Fetch a list of submissions from a table/collection.
67
+ * @param {*} table
68
+ * @param {*} query
69
+ */
70
+ index(scope: FormScope, query?: any, collection?: Collection<Document> | null): Promise<DatabaseIndexResponse>;
71
+ /**
72
+ * Perform a count of the amount of documents within a collection.
73
+ * @param scope
74
+ * @param query
75
+ * @returns
76
+ */
77
+ count(scope: FormScope, query?: any, inCollection?: Collection<Document> | null, includeDeleted?: boolean): Promise<number>;
78
+ /**
79
+ * Create a new record.
80
+ */
81
+ create(scope: FormScope, record: any, allowFields?: string[]): Promise<import("mongodb").WithId<Document> | null | undefined>;
82
+ /**
83
+ * Return a query for a single mongo record.
84
+ * @param {*} form
85
+ * @param {*} id
86
+ * @returns
87
+ */
88
+ query(scope: FormScope, query?: any, includeAll?: boolean): any;
89
+ /**
90
+ * Find many records that match a query.
91
+ */
92
+ find(scope: FormScope, query?: any, limit?: number, skip?: number, sort?: any, select?: any, inCollection?: Collection<Document> | null, includeDeleted?: boolean): Promise<Document[]>;
93
+ /**
94
+ * Find a record for a provided query.
95
+ */
96
+ findOne(scope: FormScope, query?: any, options?: FindOptions<Document>): Promise<import("mongodb").WithId<Document> | null>;
97
+ /**
98
+ * Read a single submission from a form
99
+ *
100
+ * @param {*} table
101
+ * @param {*} query
102
+ */
103
+ read(scope: FormScope, id: string | undefined): Promise<import("mongodb").WithId<Document> | null>;
104
+ /**
105
+ * Update a single submission of a form.
106
+ *
107
+ * @param {*} table
108
+ * @param {*} query
109
+ */
110
+ update(scope: FormScope, id: string | undefined, update: any, allowFields?: string[]): Promise<import("mongodb").WithId<Document> | null>;
111
+ /**
112
+ * Delete a record from the database.
113
+ */
114
+ delete(scope: FormScope, id: string | undefined, hard?: boolean): Promise<boolean>;
115
+ addPathQueryParams(pathQueryParams: any, query: any, path: string): void;
116
+ /**
117
+ * Performs a unique query on the database to see if a value is unique.
118
+ * - If the value is unique, it returns true.
119
+ * - If the value is not unique, it returns the id of the non-unique submission.
120
+ * - If an error occurs, or uniqueness cannot be determined, it will throw an error.
121
+ *
122
+ * @param scope
123
+ * @param context
124
+ * @param value
125
+ * @returns
126
+ */
127
+ isUnique(scope: FormScope, context: ValidationContext, value: any): Promise<boolean | string>;
128
+ }