@formio/appserver 1.2.10 → 2.0.0-dev.10

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.
@@ -1,3 +1,4 @@
1
+ /// <reference types="express" />
1
2
  declare const _default: {
2
3
  save: {
3
4
  readonly info: {
@@ -14,12 +15,12 @@ declare const _default: {
14
15
  method: boolean;
15
16
  };
16
17
  };
17
- mappingComponents(scope: import("../types/lib").ActionScope): Promise<any>;
18
- settingsForm(scope: import("../types/lib").ActionScope): Promise<any>;
19
- saveToForm(scope: import("../types/lib").ActionScope, resource: string): undefined;
20
- childSubmission(scope: import("../types/lib").ActionScope, req: import("../types/lib").SubmissionRequest, res: import("../types/lib").SubmissionResponse, submission: any): any;
21
- childResponse(scope: import("../types/lib").ActionScope, req: import("../types/lib").SubmissionRequest, res: import("../types/lib").SubmissionResponse): void;
22
- executor(scope: import("../types/lib").ActionScope): Promise<(req: import("../types/lib").SubmissionRequest, res: import("../types/lib").SubmissionResponse, next: import("express").NextFunction) => Promise<void>>;
18
+ mappingComponents(scope: import("src/types/lib").ActionScope): Promise<any>;
19
+ settingsForm(scope: import("src/types/lib").ActionScope): Promise<any>;
20
+ saveToForm(scope: import("src/types/lib").ActionScope, resource: string): undefined;
21
+ childSubmission(scope: import("src/types/lib").ActionScope, req: import("src/types/lib").SubmissionRequest, res: import("src/types/lib").SubmissionResponse, submission: any): any;
22
+ childResponse(scope: import("src/types/lib").ActionScope, req: import("src/types/lib").SubmissionRequest, res: import("src/types/lib").SubmissionResponse): void;
23
+ 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>>;
23
24
  };
24
25
  login: {
25
26
  readonly info: {
@@ -36,7 +37,7 @@ declare const _default: {
36
37
  method: boolean;
37
38
  };
38
39
  };
39
- settingsForm(scope: import("../types/lib").ActionScope): Promise<({
40
+ settingsForm(scope: import("src/types/lib").ActionScope): Promise<({
40
41
  type: string;
41
42
  label: string;
42
43
  key: string;
@@ -102,8 +103,8 @@ declare const _default: {
102
103
  validate?: undefined;
103
104
  })[]>;
104
105
  waitText(time: number): string;
105
- checkAttempts(scope: import("../types/lib").ActionScope, error: any, user: import("../types/lib").User): Promise<any>;
106
- executor(scope: import("../types/lib").ActionScope): Promise<(req: import("../types/lib").SubmissionRequest, res: import("../types/lib").SubmissionResponse, next: import("express").NextFunction) => Promise<void>>;
106
+ checkAttempts(scope: import("src/types/lib").ActionScope, error: any, user: import("src/types/lib").User): Promise<any>;
107
+ 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>>;
107
108
  };
108
109
  role: {
109
110
  readonly info: {
@@ -120,7 +121,7 @@ declare const _default: {
120
121
  method: boolean;
121
122
  };
122
123
  };
123
- settingsForm(scope: import("../types/lib").ActionScope): Promise<({
124
+ settingsForm(scope: import("src/types/lib").ActionScope): Promise<({
124
125
  type: string;
125
126
  input: boolean;
126
127
  label: string;
@@ -153,7 +154,7 @@ declare const _default: {
153
154
  required: boolean;
154
155
  };
155
156
  })[]>;
156
- executor(scope: import("../types/lib").ActionScope): Promise<(req: import("../types/lib").SubmissionRequest, res: import("../types/lib").SubmissionResponse, next: import("express").NextFunction) => Promise<void | import("../types/lib").SubmissionResponse>>;
157
+ 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>>;
157
158
  };
158
159
  };
159
160
  export default _default;
@@ -88,13 +88,13 @@ exports.SaveAction = {
88
88
  components: []
89
89
  };
90
90
  const toFields = [];
91
- yield scope.utils.eachComponent(form.components, (component) => {
91
+ yield scope.utils.eachComponentAsync(form.components, (component) => {
92
92
  if (['button'].indexOf(component.type) !== -1) {
93
93
  return;
94
94
  }
95
95
  toFields.push({ label: component.label || component.key, value: component.key });
96
96
  });
97
- yield scope.utils.eachComponent(scope.form.components, (component) => {
97
+ yield scope.utils.eachComponentAsync(scope.form.components, (component) => {
98
98
  if (['button'].indexOf(component.type) !== -1) {
99
99
  return;
100
100
  }
@@ -17,8 +17,8 @@ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
17
17
  const debug = require('debug')('formio:auth');
18
18
  const error = require('debug')('formio:error');
19
19
  class Auth {
20
- token(user, secret, expire = 240) {
21
- return __awaiter(this, void 0, void 0, function* () {
20
+ token(user_1, secret_1) {
21
+ return __awaiter(this, arguments, void 0, function* (user, secret, expire = 240) {
22
22
  user = Object.assign({}, user);
23
23
  delete user.iat;
24
24
  delete user.exp;
@@ -5,5 +5,7 @@ export declare const Preppers: {
5
5
  persist: (scope: PrepScope) => Promise<void>;
6
6
  protect: (scope: PrepScope) => Promise<void>;
7
7
  password: (scope: PrepScope) => Promise<void>;
8
+ referenceLoad: (scope: PrepScope) => Promise<void>;
9
+ referenceSave: (scope: PrepScope) => Promise<void>;
8
10
  };
9
11
  export declare const Prepper: PrepperType;
@@ -19,19 +19,23 @@ const access_1 = __importDefault(require("./access"));
19
19
  const persist_1 = __importDefault(require("./persist"));
20
20
  const protect_1 = __importDefault(require("./protect"));
21
21
  const password_1 = __importDefault(require("./password"));
22
+ const reference_1 = require("./reference");
23
+ const core_1 = require("@formio/core");
22
24
  exports.Preppers = {
23
25
  bcrypt: bcrypt_1.default,
24
26
  access: access_1.default,
25
27
  persist: persist_1.default,
26
28
  protect: protect_1.default,
27
- password: password_1.default
29
+ password: password_1.default,
30
+ referenceLoad: reference_1.referenceLoad,
31
+ referenceSave: reference_1.referenceSave
28
32
  };
29
33
  const debug = require('debug')('formio:prepare');
30
34
  const error = require('debug')('formio:error');
31
35
  exports.Prepper = {
32
36
  preppers: {
33
- save: [exports.Preppers.persist, exports.Preppers.access, exports.Preppers.password, exports.Preppers.bcrypt],
34
- read: [exports.Preppers.protect]
37
+ save: [exports.Preppers.persist, exports.Preppers.access, exports.Preppers.password, exports.Preppers.bcrypt, exports.Preppers.referenceSave],
38
+ read: [exports.Preppers.protect, exports.Preppers.referenceLoad]
35
39
  },
36
40
  prepare(scope) {
37
41
  return __awaiter(this, void 0, void 0, function* () {
@@ -39,12 +43,10 @@ exports.Prepper = {
39
43
  const { type, form, submission } = scope;
40
44
  try {
41
45
  debug(`Preparing data for ${form.name}...`);
42
- yield scope.utils.eachComponentData(form.components, submission.data, (component, row, path) => __awaiter(this, void 0, void 0, function* () {
46
+ yield scope.utils.eachComponentData(form.components, submission.data, (component, compData, compRow, compPath) => __awaiter(this, void 0, void 0, function* () {
43
47
  if (exports.Prepper.preppers.hasOwnProperty(type)) {
44
48
  for (let i = 0; i < exports.Prepper.preppers[type].length; i++) {
45
- yield exports.Prepper.preppers[type][i](Object.assign(Object.assign({}, scope), { component,
46
- row,
47
- data, value: (0, get_1.default)(row, component.key), path }));
49
+ yield exports.Prepper.preppers[type][i](Object.assign(Object.assign({}, scope), { component, row: compRow, data, value: (0, get_1.default)(compData, compPath), path: core_1.Utils.getComponentAbsolutePath(component) }));
48
50
  }
49
51
  }
50
52
  }));
@@ -14,15 +14,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const get_1 = __importDefault(require("lodash/get"));
16
16
  const set_1 = __importDefault(require("lodash/set"));
17
- const has_1 = __importDefault(require("lodash/has"));
18
17
  exports.default = (scope) => __awaiter(void 0, void 0, void 0, function* () {
19
18
  // Check if they do not provide a password in the save, but one exists in the current record.
20
19
  // Do not allow them to wipe out their password by saving data that does not include one.
21
20
  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));
21
+ if (component.type === 'password' && type === 'save') {
22
+ const currentPass = (0, get_1.default)(current, `data.${path}`);
23
+ if (!(0, get_1.default)(row, component.key) && currentPass) {
24
+ (0, set_1.default)(data, path, currentPass);
25
+ }
27
26
  }
28
27
  });
@@ -0,0 +1,3 @@
1
+ import { PrepScope } from '@formio/appserver-types';
2
+ export declare const referenceLoad: (scope: PrepScope) => Promise<void>;
3
+ export declare const referenceSave: (scope: PrepScope) => Promise<void>;
@@ -0,0 +1,71 @@
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.referenceSave = exports.referenceLoad = void 0;
16
+ const lodash_1 = require("lodash");
17
+ const protect_1 = __importDefault(require("./protect"));
18
+ const getResource = (scope) => {
19
+ var _a, _b, _c, _d, _e;
20
+ const { component } = scope;
21
+ const resourceId = (_a = component.data) === null || _a === void 0 ? void 0 : _a.resource;
22
+ let resource = (_b = scope.server) === null || _b === void 0 ? void 0 : _b.project.forms[resourceId];
23
+ if (!resource) {
24
+ for (let name in (_c = scope.server) === null || _c === void 0 ? void 0 : _c.project.forms) {
25
+ const form = (_d = scope.server) === null || _d === void 0 ? void 0 : _d.project.forms[name].clientForm;
26
+ if (form._id.toString() === resourceId) {
27
+ resource = (_e = scope.server) === null || _e === void 0 ? void 0 : _e.project.forms[name];
28
+ break;
29
+ }
30
+ }
31
+ }
32
+ return resource;
33
+ };
34
+ const referenceLoad = (scope) => __awaiter(void 0, void 0, void 0, function* () {
35
+ const { component, data, value, path } = scope;
36
+ if (!value) {
37
+ return;
38
+ }
39
+ if (component.reference) {
40
+ const resource = getResource(scope);
41
+ if (resource) {
42
+ const submission = yield resource.loadSubmission(value._id);
43
+ if (submission) {
44
+ // Make sure to protect this submission like any other submission output.
45
+ const context = Object.assign(Object.assign({}, scope), { data: {} });
46
+ yield scope.utils.eachComponentDataAsync(resource.clientForm.components, submission.data, (comp, compData, compRow, compPath) => __awaiter(void 0, void 0, void 0, function* () {
47
+ yield (0, protect_1.default)(Object.assign(Object.assign({}, context), { component: comp, row: compRow, data: compData, value: (0, lodash_1.get)(compRow, comp.key), path: compPath }));
48
+ }));
49
+ submission.data = context.data;
50
+ (0, lodash_1.set)(data, path, submission);
51
+ }
52
+ }
53
+ }
54
+ });
55
+ exports.referenceLoad = referenceLoad;
56
+ const referenceSave = (scope) => __awaiter(void 0, void 0, void 0, function* () {
57
+ const { component, data, value, path } = scope;
58
+ if (!value || !value._id) {
59
+ return;
60
+ }
61
+ if (component.reference && value._id) {
62
+ const resource = getResource(scope);
63
+ if (resource) {
64
+ (0, lodash_1.set)(data, path, {
65
+ _id: value._id,
66
+ form: resource.clientForm._id
67
+ });
68
+ }
69
+ }
70
+ });
71
+ exports.referenceSave = referenceSave;
package/lib/server.d.ts CHANGED
@@ -1,14 +1,14 @@
1
+ /// <reference types="express" />
1
2
  import { Server as CoreServer } from '@formio/appserver-core';
2
3
  import { Database, Auth } from "./modules";
3
4
  import Actions from "./actions";
4
- import { Processor } from "./process";
5
5
  import { Prepper } from './prepare';
6
- import { AppServerScope, Processor as ProcessorType, Prepper as PrepperType } from '@formio/appserver-types';
6
+ import { AppServerScope } from '@formio/appserver-types';
7
7
  export declare const Modules: {
8
8
  db: typeof Database;
9
9
  auth: typeof Auth;
10
- processor: ProcessorType;
11
- prepper: PrepperType;
10
+ processors: ProcessTarget;
11
+ prepper: import("@formio/appserver-types").Prepper;
12
12
  actions: {
13
13
  save: {
14
14
  readonly info: {
@@ -172,7 +172,6 @@ export declare class Server extends CoreServer {
172
172
  constructor(config?: AppServerScope);
173
173
  }
174
174
  export { Prepper };
175
- export { Processor };
176
175
  export { Database };
177
176
  export { Auth };
178
177
  export { Actions };
package/lib/server.js CHANGED
@@ -3,17 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Actions = exports.Auth = exports.Database = exports.Processor = exports.Prepper = exports.Server = exports.Modules = void 0;
6
+ exports.Actions = exports.Auth = exports.Database = exports.Prepper = exports.Server = exports.Modules = void 0;
7
7
  // Load the license key.
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const get_1 = __importDefault(require("lodash/get"));
10
- let licenseKey = (0, get_1.default)(process.env, 'LICENSE_KEY', '');
10
+ let licenseKey = (0, get_1.default)(process.env, 'APPSERVER_LICENSE', (0, get_1.default)(process.env, 'LICENSE_KEY', ''));
11
11
  if (!licenseKey) {
12
12
  try {
13
- licenseKey = fs_1.default.readFileSync(path_1.default.join((0, process_2.cwd)(), 'license.txt'), 'utf8');
13
+ licenseKey = fs_1.default.readFileSync(path_1.default.join((0, process_1.cwd)(), 'license.txt'), 'utf8');
14
14
  }
15
15
  catch (err) {
16
- console.log('No license key found. Please set the LICENSE_KEY environment variable or create a license.txt file in the root of the project.');
16
+ 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.');
17
17
  }
18
18
  }
19
19
  const appserver_core_1 = require("@formio/appserver-core");
@@ -22,27 +22,26 @@ Object.defineProperty(exports, "Database", { enumerable: true, get: function ()
22
22
  Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return modules_1.Auth; } });
23
23
  const actions_1 = __importDefault(require("./actions"));
24
24
  exports.Actions = actions_1.default;
25
- const process_1 = require("./process");
26
- Object.defineProperty(exports, "Processor", { enumerable: true, get: function () { return process_1.Processor; } });
27
25
  const prepare_1 = require("./prepare");
28
26
  Object.defineProperty(exports, "Prepper", { enumerable: true, get: function () { return prepare_1.Prepper; } });
29
- const process_2 = require("process");
27
+ const process_1 = require("process");
30
28
  const path_1 = __importDefault(require("path"));
31
29
  const defaultsDeep_1 = __importDefault(require("lodash/defaultsDeep"));
30
+ const core_1 = require("@formio/core");
32
31
  const packageJson = require('../package.json');
33
32
  const appCorePackage = require('@formio/appserver-core/package.json');
34
33
  const corePackage = require('@formio/core');
35
34
  exports.Modules = {
36
35
  db: modules_1.Database,
37
36
  auth: modules_1.Auth,
38
- processor: process_1.Processor,
37
+ processors: core_1.ProcessTargets,
39
38
  prepper: prepare_1.Prepper,
40
39
  actions: actions_1.default
41
40
  };
42
41
  class Server extends appserver_core_1.Server {
43
42
  constructor(config = {}) {
44
43
  if (config.processors) {
45
- exports.Modules.processor.processors = config.processors;
44
+ exports.Modules.processors = config.processors;
46
45
  }
47
46
  if (config.preppers) {
48
47
  exports.Modules.prepper.preppers = config.preppers;
@@ -55,7 +54,7 @@ class Server extends appserver_core_1.Server {
55
54
  url: (0, get_1.default)(process.env, 'MONGO', "mongodb://localhost:27017/appserver"),
56
55
  config: (0, get_1.default)(process.env, 'MONGO_CONFIG', "{}")
57
56
  }),
58
- processor: exports.Modules.processor,
57
+ processors: exports.Modules.processors,
59
58
  prepper: exports.Modules.prepper,
60
59
  auth: config.auth || new exports.Modules.auth(),
61
60
  actions: Object.assign(Object.assign({}, exports.Modules.actions), config.actions),
@@ -1,6 +1,7 @@
1
1
  import { FormScope } from "./form";
2
- import { PrepScope, ProcessScope } from "./submission";
2
+ import { PrepScope } from "./submission";
3
3
  import { OfflineLicenseStruct } from '@formio/license';
4
+ import { ValidationContext, ProcessTarget } from "@formio/core/types";
4
5
  export interface ProjectConfig {
5
6
  url: string;
6
7
  key: string;
@@ -45,9 +46,10 @@ export interface DBConfig {
45
46
  export interface ServerDB {
46
47
  config: DBConfig;
47
48
  connect: (prefix?: string) => Promise<void>;
49
+ saveOne: (collection: string, doc: any) => Promise<any>;
48
50
  save: (collection: string, doc: any) => Promise<any>;
49
- load: (collection: string) => Promise<any>;
50
- remove: (collection: string) => Promise<any>;
51
+ load: (collection: string, query?: any) => Promise<any>;
52
+ remove: (collection: string, query?: any) => Promise<any>;
51
53
  index: (scope: FormScope, query: any) => Promise<any>;
52
54
  create: (scope: FormScope, doc: any, allowFields?: string[]) => Promise<any>;
53
55
  read: (scope: FormScope, id: string) => Promise<any>;
@@ -58,15 +60,12 @@ export interface ServerDB {
58
60
  formCollection: (scope: FormScope) => Promise<any>;
59
61
  addIndexes: (scope: FormScope, indexes: string[]) => Promise<any>;
60
62
  removeIndexes: (scope: FormScope, indexes: string[]) => Promise<any>;
63
+ isUnique: (scope: FormScope, context: ValidationContext, value: any) => Promise<boolean | string>;
61
64
  }
62
65
  export interface AuthModule {
63
66
  token: (user: AuthToken, secret: string, expire: number) => Promise<string>;
64
67
  user: (token: string, secret: string) => Promise<AuthToken | null>;
65
68
  }
66
- export interface Processor {
67
- processors: Array<(scope: ProcessScope) => Promise<any[]>>;
68
- process: (scope: ProcessScope) => Promise<any>;
69
- }
70
69
  export interface Preppers {
71
70
  save: Array<(scope: PrepScope) => Promise<any>>;
72
71
  read: Array<(scope: PrepScope) => Promise<any>>;
@@ -80,13 +79,14 @@ export interface ServerScope {
80
79
  db: ServerDB;
81
80
  auth: AuthModule;
82
81
  actions: any;
83
- processor: Processor;
82
+ processors: ProcessTarget;
84
83
  prepper: Prepper;
85
84
  access?: any;
86
85
  hooks?: any;
87
86
  template?: any;
88
87
  utils?: any;
89
88
  util?: any;
89
+ server?: any;
90
90
  hook?: (name: string, ...args: any[]) => void;
91
91
  licenseKey?: OfflineLicenseStruct;
92
92
  }
@@ -94,7 +94,7 @@ export interface AppServerScope {
94
94
  config?: ServerConfig;
95
95
  db?: ServerDB;
96
96
  auth?: AuthModule;
97
- processors?: Array<(scope: ProcessScope) => Promise<any[]>>;
97
+ processors?: ProcessTarget;
98
98
  preppers?: Preppers;
99
99
  actions?: any;
100
100
  hooks?: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/appserver",
3
- "version": "1.2.10",
3
+ "version": "2.0.0-dev.10",
4
4
  "description": "A highly performant and extensible Application Server for Form.io Multi-Tenant Deployments.",
5
5
  "main": "server.js",
6
6
  "scripts": {
@@ -29,29 +29,31 @@
29
29
  ],
30
30
  "homepage": "https://github.com/formio/appserver#readme",
31
31
  "dependencies": {
32
- "@formio/appserver-auth-jwt": "^1.0.1",
33
- "@formio/appserver-core": "^1.4.10",
34
- "@formio/appserver-db-mongodb": "^1.0.5",
35
- "@formio/appserver-types": "^1.2.5",
36
- "async": "^3.2.4",
32
+ "@formio/appserver-auth-jwt": "^2.0.0-dev.7",
33
+ "@formio/appserver-core": "^2.0.0-dev.9",
34
+ "@formio/appserver-db-mongodb": "^2.0.0-dev.7",
35
+ "@formio/appserver-types": "^2.0.0-dev.8",
36
+ "@formio/core": "^2.0.0-rc.24",
37
+ "@formio/vm": "^0.0.7-rc.18",
38
+ "async": "^3.2.5",
37
39
  "bcryptjs": "^2.4.3",
38
40
  "debug": "^4.3.4",
39
- "dotenv": "^16.0.3",
40
- "express": "^4.18.2",
41
- "jsonwebtoken": "^9.0.0",
41
+ "dotenv": "^16.4.5",
42
+ "express": "^4.19.2",
43
+ "jsonwebtoken": "^9.0.2",
42
44
  "lodash": "^4.17.21"
43
45
  },
44
46
  "devDependencies": {
45
- "@types/async": "^3.2.20",
46
- "@types/bcryptjs": "^2.4.2",
47
- "@types/express": "^4.17.17",
48
- "@types/jsonwebtoken": "^9.0.2",
49
- "@types/lodash": "^4.14.194",
50
- "@types/mocha": "^10.0.1",
51
- "@types/node": "^20.1.1",
52
- "mocha": "^10.2.0",
53
- "ts-node": "^10.9.1",
47
+ "@types/async": "^3.2.24",
48
+ "@types/bcryptjs": "^2.4.6",
49
+ "@types/express": "^4.17.21",
50
+ "@types/jsonwebtoken": "^9.0.6",
51
+ "@types/lodash": "^4.17.0",
52
+ "@types/mocha": "^10.0.6",
53
+ "@types/node": "^20.12.7",
54
+ "mocha": "^10.4.0",
55
+ "ts-node": "^10.9.2",
54
56
  "tsconfig-paths": "^4.2.0",
55
- "typescript": "^5.0.4"
57
+ "typescript": "^5.4.5"
56
58
  }
57
59
  }
package/lib/auth.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { AuthModule, AuthToken } from '@formio/appserver-types';
2
- export declare class Auth implements AuthModule {
3
- token(user: AuthToken, secret: string, expire?: number): Promise<string>;
4
- user(token: string, secret: string): Promise<AuthToken | null>;
5
- }
package/lib/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, secret, expire = 240) {
21
- return __awaiter(this, void 0, void 0, function* () {
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;
package/lib/db.d.ts DELETED
@@ -1,97 +0,0 @@
1
- import { Collection, Db } from 'mongodb';
2
- import { DBConfig, ServerDB, FormScope } from '@formio/appserver-types';
3
- export declare class Database implements ServerDB {
4
- config: DBConfig;
5
- db: Db | null;
6
- currentCollectionName: string;
7
- currentCollection: Collection<Document> | null;
8
- defaultCollection: Collection<Document> | null;
9
- prefix: string;
10
- constructor(config: DBConfig);
11
- ObjectId(id: any): any;
12
- collectionName(name: string): string;
13
- /**
14
- * Connect to the database.
15
- * @param {*} scope
16
- * @returns
17
- */
18
- connect(prefix?: string): Promise<void>;
19
- save(collectionName: string, item: any): Promise<import("mongodb").WithId<import("bson").Document> | null>;
20
- load(collectionName: string): Promise<import("mongodb").WithId<import("bson").Document> | null | undefined>;
21
- remove(collectionName: string): Promise<number | null>;
22
- /**
23
- * Ensures the form collection is created an returns it.
24
- * @param scope
25
- * @returns
26
- */
27
- formCollection(scope: FormScope): Promise<Collection<Document> | null>;
28
- /**
29
- * Setup indexes.
30
- */
31
- setupIndexes(collection: Collection<Document> | null, scope?: FormScope): Promise<void>;
32
- /**
33
- * Add a field index
34
- */
35
- addIndex(collection: Collection<Document>, path: string): Promise<void>;
36
- /**
37
- * Adds new indexes to the forms submission collection.
38
- * @param scope
39
- * @param indexes
40
- * @returns
41
- */
42
- addIndexes(scope: FormScope, indexes: string[]): Promise<void>;
43
- /**
44
- * Remove a field index.
45
- */
46
- removeIndex(collection: Collection<Document>, path: string): Promise<void>;
47
- /**
48
- * Removes indexes to the forms submission collection.
49
- * @param scope
50
- * @param indexes
51
- * @returns
52
- */
53
- removeIndexes(scope: FormScope, indexes: string[]): Promise<void>;
54
- /**
55
- * Fetch a list of submissions from a table/collection.
56
- * @param {*} table
57
- * @param {*} query
58
- */
59
- index(scope: FormScope, query?: {}): Promise<import("mongodb").WithId<Document>[] | undefined>;
60
- /**
61
- * Create a new record.
62
- */
63
- create(scope: FormScope, record: any, allowFields?: string[]): Promise<import("mongodb").WithId<Document> | null | undefined>;
64
- /**
65
- * Return a query for a single mongo record.
66
- * @param {*} form
67
- * @param {*} id
68
- * @returns
69
- */
70
- query(scope: FormScope, query?: any): any;
71
- /**
72
- * Find many records that match a query.
73
- */
74
- find(scope: FormScope, query?: any): Promise<import("mongodb").WithId<Document>[]>;
75
- /**
76
- * Find a record for a provided query.
77
- */
78
- findOne(scope: FormScope, query?: any): Promise<import("mongodb").WithId<Document> | null>;
79
- /**
80
- * Read a single submission from a form
81
- *
82
- * @param {*} table
83
- * @param {*} query
84
- */
85
- read(scope: FormScope, id: string): Promise<import("mongodb").WithId<Document> | null>;
86
- /**
87
- * Update a single submission of a form.
88
- *
89
- * @param {*} table
90
- * @param {*} query
91
- */
92
- update(scope: FormScope, id: string, update: any, allowFields?: string[]): Promise<import("mongodb").WithId<Document> | null>;
93
- /**
94
- * Delete a record from the database.
95
- */
96
- delete(scope: FormScope, id: string): Promise<boolean>;
97
- }