@formio/appserver 1.1.6 → 1.1.8

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.
@@ -0,0 +1,5 @@
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
+ }
@@ -0,0 +1,70 @@
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;
@@ -0,0 +1,3 @@
1
+ import { Database } from '@formio/appserver-db-mongodb';
2
+ import { Auth } from '@formio/appserver-auth-jwt';
3
+ export { Database, Auth };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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; } });
6
+ const appserver_auth_jwt_1 = require("@formio/appserver-auth-jwt");
7
+ Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return appserver_auth_jwt_1.Auth; } });
package/lib/server.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /// <reference types="express" />
2
2
  import { Server as CoreServer } from '@formio/appserver-core';
3
- import { Auth } from "./auth";
4
- import { Database } from "./db";
3
+ import { Database, Auth } from "./modules";
5
4
  import Actions from "./actions";
6
5
  import { Processor } from "./process";
7
6
  import { Prepper } from './prepare';
package/lib/server.js CHANGED
@@ -14,14 +14,12 @@ if (!licenseKey) {
14
14
  }
15
15
  catch (err) {
16
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.');
17
- process.exit();
18
17
  }
19
18
  }
20
19
  const appserver_core_1 = require("@formio/appserver-core");
21
- const auth_1 = require("./auth");
22
- Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return auth_1.Auth; } });
23
- const db_1 = require("./db");
24
- Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return db_1.Database; } });
20
+ const modules_1 = require("./modules");
21
+ Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return modules_1.Database; } });
22
+ Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return modules_1.Auth; } });
25
23
  const actions_1 = __importDefault(require("./actions"));
26
24
  exports.Actions = actions_1.default;
27
25
  const process_1 = require("./process");
@@ -35,8 +33,8 @@ const packageJson = require('../package.json');
35
33
  const appCorePackage = require('@formio/appserver-core/package.json');
36
34
  const corePackage = require('@formio/core');
37
35
  exports.Modules = {
38
- db: db_1.Database,
39
- auth: auth_1.Auth,
36
+ db: modules_1.Database,
37
+ auth: modules_1.Auth,
40
38
  processor: process_1.Processor,
41
39
  prepper: prepare_1.Prepper,
42
40
  actions: actions_1.default
@@ -54,7 +52,7 @@ class Server extends appserver_core_1.Server {
54
52
  }
55
53
  super({
56
54
  db: config.db || new exports.Modules.db({
57
- url: (0, get_1.default)(process.env, 'MONGO', "mongodb://localhost:27017/subserver"),
55
+ url: (0, get_1.default)(process.env, 'MONGO', "mongodb://localhost:27017/appserver"),
58
56
  config: (0, get_1.default)(process.env, 'MONGO_CONFIG', "{}")
59
57
  }),
60
58
  processor: exports.Modules.processor,
@@ -1,5 +1,6 @@
1
1
  import { FormScope } from "./form";
2
2
  import { PrepScope, ProcessScope } from "./submission";
3
+ import { OfflineLicenseStruct } from '@formio/license';
3
4
  export interface ProjectConfig {
4
5
  url: string;
5
6
  key: string;
@@ -37,6 +38,8 @@ export interface ServerConfig {
37
38
  }
38
39
  export interface DBConfig {
39
40
  url: string;
41
+ ttl?: number;
42
+ dropOnConnect?: boolean;
40
43
  config: any;
41
44
  }
42
45
  export interface ServerDB {
@@ -60,12 +63,6 @@ export interface AuthModule {
60
63
  token: (user: AuthToken, secret: string, expire: number) => Promise<string>;
61
64
  user: (token: string, secret: string) => Promise<AuthToken | null>;
62
65
  }
63
- export interface LicenseTerms {
64
- serverless: string[];
65
- }
66
- export interface LicenseKey {
67
- terms: LicenseTerms;
68
- }
69
66
  export interface Processor {
70
67
  processors: Array<(scope: ProcessScope) => Promise<any[]>>;
71
68
  process: (scope: ProcessScope) => Promise<any>;
@@ -91,7 +88,7 @@ export interface ServerScope {
91
88
  utils?: any;
92
89
  util?: any;
93
90
  hook?: (name: string, ...args: any[]) => void;
94
- licenseKey?: LicenseKey;
91
+ licenseKey?: OfflineLicenseStruct;
95
92
  }
96
93
  export interface AppServerScope {
97
94
  config?: ServerConfig;
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@formio/appserver",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "A highly performant and extensible Application Server for Form.io Multi-Tenant Deployments.",
5
5
  "main": "server.js",
6
6
  "scripts": {
7
- "build": "cd src/types && npm run build && cd ../.. && tsc",
7
+ "build:types": "cd src/types && npm run build && cd ../..",
8
+ "build:db": "cd src/modules/db && npm run build && cd ../../..",
9
+ "build:auth": "cd src/modules/auth && npm run build && cd ../../..",
10
+ "build:modules": "npm run build:db && npm run build:auth",
11
+ "build": "npm run build:types && npm run build:modules && tsc",
8
12
  "test": "mocha -r ts-node/register 'src/**/*.spec.ts'",
9
13
  "prepack": "npm run build"
10
14
  },
@@ -25,16 +29,17 @@
25
29
  ],
26
30
  "homepage": "https://github.com/formio/appserver#readme",
27
31
  "dependencies": {
28
- "@formio/appserver-core": "^1.3.5",
29
- "@formio/appserver-types": "^1.2.3",
32
+ "@formio/appserver-auth-jwt": "^1.0.1",
33
+ "@formio/appserver-core": "^1.3.7",
34
+ "@formio/appserver-db-mongodb": "^1.0.4",
35
+ "@formio/appserver-types": "^1.2.5",
30
36
  "async": "^3.2.4",
31
37
  "bcryptjs": "^2.4.3",
32
38
  "debug": "^4.3.4",
33
39
  "dotenv": "^16.0.3",
34
40
  "express": "^4.18.2",
35
41
  "jsonwebtoken": "^9.0.0",
36
- "lodash": "^4.17.21",
37
- "mongodb": "^5.4.0"
42
+ "lodash": "^4.17.21"
38
43
  },
39
44
  "devDependencies": {
40
45
  "@types/async": "^3.2.20",