adapt-authoring-server 1.0.0 → 1.0.2

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.
@@ -3,10 +3,16 @@ on:
3
3
  push:
4
4
  branches:
5
5
  - master
6
+
6
7
  jobs:
7
8
  release:
8
9
  name: Release
9
10
  runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: write # to be able to publish a GitHub release
13
+ issues: write # to be able to comment on released issues
14
+ pull-requests: write # to be able to comment on released pull requests
15
+ id-token: write # to enable use of OIDC for trusted publishing and npm provenance
10
16
  steps:
11
17
  - name: Checkout
12
18
  uses: actions/checkout@v3
@@ -16,10 +22,11 @@ jobs:
16
22
  uses: actions/setup-node@v3
17
23
  with:
18
24
  node-version: 'lts/*'
25
+ - name: Update npm
26
+ run: npm install -g npm@latest
19
27
  - name: Install dependencies
20
28
  run: npm ci
21
29
  - name: Release
22
30
  env:
23
31
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24
- NPM_TOKEN: ${{ secrets.AAT_NPM_TOKEN }}
25
- run: npx semantic-release
32
+ run: npx semantic-release
@@ -0,0 +1,13 @@
1
+ name: Standard.js formatting check
2
+ on: push
3
+ jobs:
4
+ default:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - uses: actions/checkout@master
8
+ - uses: actions/setup-node@master
9
+ with:
10
+ node-version: 'lts/*'
11
+ cache: 'npm'
12
+ - run: npm ci
13
+ - run: npx standard
@@ -23,11 +23,6 @@
23
23
  "type": ["number", "boolean"],
24
24
  "default": 0
25
25
  },
26
- "debugRequestTime": {
27
- "description": "Will log the execution time of each request",
28
- "type": "boolean",
29
- "default": false
30
- },
31
26
  "verboseErrorLogging": {
32
27
  "description": "Whether to log errors in their entirety",
33
28
  "type": "boolean",
package/lib/Router.js CHANGED
@@ -221,7 +221,7 @@ class Router {
221
221
  this.routes.forEach(r => {
222
222
  Object.entries(r.handlers).forEach(([method, handler]) => {
223
223
  this.expressRouter[method](r.route, ServerUtils.cacheRouteConfig(r), ...this.getHandlerMiddleware(), handler)
224
- this.log('debug', 'ADD_ROUTE', method.toUpperCase(), `${this.path !== '/' ? this.path : ''}${r.route}`)
224
+ this.log('verbose', 'ADD_ROUTE', method.toUpperCase(), `${this.path !== '/' ? this.path : ''}${r.route}`)
225
225
  })
226
226
  })
227
227
  }
@@ -120,11 +120,13 @@ class ServerModule extends AbstractModule {
120
120
  */
121
121
  listen () {
122
122
  return new Promise((resolve, reject) => {
123
- this.httpServer = this.expressApp.listen(this.port, this.host, () => {
124
- this.isListening = true
125
- this.listeningHook.invoke()
126
- resolve(this.httpServer)
127
- }).once('error', e => reject(this.app.errors.SERVER_START.setData({ error: e })))
123
+ this.httpServer = this.expressApp.listen(this.port, this.host)
124
+ .on('error', e => reject(this.app.errors.SERVER_START.setData({ error: e })))
125
+ .on('listening', () => {
126
+ this.isListening = true
127
+ this.listeningHook.invoke()
128
+ resolve(this.httpServer)
129
+ })
128
130
  })
129
131
  }
130
132
 
@@ -91,10 +91,8 @@ class ServerUtils {
91
91
  */
92
92
  static async debugRequestTime (req, res, next) {
93
93
  const server = await App.instance.waitForModule('server')
94
- if (server.getConfig('debugRequestTime')) {
95
- const start = new Date()
96
- res.on('finish', () => server.log('debug', 'REQUEST_DURATION', req.method, req.originalUrl, new Date() - start))
97
- }
94
+ const start = new Date()
95
+ res.on('finish', () => server.log('verbose', 'REQUEST_DURATION', req.method, req.originalUrl, new Date() - start, req.auth?.user?._id?.toString()))
98
96
  next()
99
97
  }
100
98
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-server",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Provides an Express application routing and more",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-server",
6
6
  "license": "GPL-3.0",
@@ -16,16 +16,15 @@
16
16
  "adapt-authoring-core": "github:adapt-security/adapt-authoring-core"
17
17
  },
18
18
  "devDependencies": {
19
- "eslint": "^9.12.0",
20
- "standard": "^17.1.0",
21
- "@semantic-release/commit-analyzer": "^9.0.2",
19
+ "@semantic-release/commit-analyzer": "^13.0.1",
22
20
  "@semantic-release/git": "^10.0.1",
23
- "@semantic-release/github": "^8.0.5",
24
- "@semantic-release/npm": "^9.0.1",
25
- "@semantic-release/release-notes-generator": "^10.0.3",
26
- "conventional-changelog-eslint": "^3.0.9",
27
- "semantic-release": "^21.0.1",
28
- "semantic-release-replace-plugin": "^1.2.7"
21
+ "@semantic-release/github": "^12.0.2",
22
+ "@semantic-release/npm": "^13.1.2",
23
+ "@semantic-release/release-notes-generator": "^14.1.0",
24
+ "conventional-changelog-eslint": "^6.0.0",
25
+ "semantic-release": "^25.0.2",
26
+ "semantic-release-replace-plugin": "^1.2.7",
27
+ "standard": "^17.1.0"
29
28
  },
30
29
  "release": {
31
30
  "plugins": [
package/.eslintignore DELETED
@@ -1 +0,0 @@
1
- node_modules
package/.eslintrc DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "env": {
3
- "browser": false,
4
- "node": true,
5
- "commonjs": false,
6
- "es2020": true
7
- },
8
- "extends": [
9
- "standard"
10
- ],
11
- "parserOptions": {
12
- "ecmaVersion": 2020
13
- }
14
- }
@@ -1,142 +0,0 @@
1
- const { App } = require('adapt-authoring-core');
2
- const express = require('express');
3
- const Router = require('../lib/Router');
4
- const should = require('should');
5
- const supertest = require('supertest');
6
-
7
- describe('Server router', function() {
8
- before(function() {
9
- this.createRouter = (r = 'test') => new Router(r, express());
10
- this.testRequest = (router, done, expectedStatus = 200) => {
11
- const l = router.parentRouter.listen(undefined, function() {
12
- supertest(router.parentRouter)
13
- .get(`${router.path}`)
14
- .expect(expectedStatus)
15
- .end((e, res) => l.close(done))
16
- });
17
- };
18
- });
19
- describe('#addRoute()', function() {
20
- const r1 = { route: 'test1', handlers: { get: () => {} } };
21
- const r2 = { route: 'test2', handlers: { get: () => {} } };
22
- const r3 = { route: 'test3', handlers: { get: () => {} } };
23
- it('should add a route function to the stack', function() {
24
- const router = this.createRouter();
25
- router.addRoute(r1);
26
- router.routes.should.containEql(r1);
27
- });
28
- it('should add multiple routes to the stack', function() {
29
- const router = this.createRouter();
30
- router.addRoute(r1, r2);
31
- router.routes.should.containEql(r2);
32
- });
33
- it('should return router reference so as to be chainable', function() {
34
- const router = this.createRouter();
35
- const r = router.addRoute(r2);
36
- r.should.equal(router);
37
- });
38
- it('should call route handler on client request', function(done) {
39
- const router = this.createRouter();
40
- router.addRoute({
41
- route: '/',
42
- handlers: { get: (req, res, next) => res.end() }
43
- });
44
- router.init();
45
- this.testRequest(router, done);
46
- });
47
- });
48
- describe('#addMiddleware()', function() {
49
- const m1 = (req, res, next) => next();
50
- const m2 = (req, res, next) => next();
51
- it('should add a middleware function to the stack', function() {
52
- const router = this.createRouter();
53
- router.addMiddleware(m1);
54
- router.middleware.should.containEql(m1);
55
- });
56
- it('should add multiple middleware functions to the stack', function() {
57
- const router = this.createRouter();
58
- router.addMiddleware(m1, m2);
59
- router.middleware.should.containEql(m2);
60
- });
61
- it('should return router reference so as to be chainable', function() {
62
- const router = this.createRouter();
63
- const r = router.addMiddleware(m2);
64
- r.should.equal(router);
65
- });
66
- it('should call custom middleware on client request', function(done) {
67
- const router = this.createRouter();
68
- router.addRoute({
69
- route: '/',
70
- handlers: { get: (req, res, next) => res.status(500).end() }
71
- });
72
- router.addMiddleware((req, res, next) => res.status(200).end());
73
- router.init();
74
- this.testRequest(router, done);
75
- });
76
- });
77
- describe('#createChildRouter()', function() {
78
- let parent, child;
79
- before(function() {
80
- parent = this.createRouter();
81
- child = parent.createChildRouter('child');
82
- });
83
- it('should return a router instance', function() {
84
- child.should.be.instanceof(Router);
85
- });
86
- it('should expose specified route', function() {
87
- child.route.should.equal('child');
88
- });
89
- it('should be added to child routers', function() {
90
- parent.childRouters.should.containEql(child);
91
- });
92
- it('should reference current router as parent', function() {
93
- child.parentRouter.should.equal(parent);
94
- });
95
- });
96
- describe('#path()', function() {
97
- it('should generate the endpoint of the router', function() {
98
- const child = new Router('child', new Router('parent', {}));
99
- child.path.should.equal('/parent/child');
100
- });
101
- });
102
- describe('#handleRequest()', function() {
103
- it('should invoke listeners to Server#requestHook', function(done) {
104
- let isDone = false;
105
- App.instance.getModule('server').requestHook.tap(() => {
106
- if(!isDone) done();
107
- isDone = true;
108
- });
109
- const router = this.createRouter();
110
- router.addRoute({
111
- route: '/',
112
- handlers: { get: (req, res, next) => {} }
113
- });
114
- router.init();
115
- this.testRequest(router, () => {}, 500);
116
- });
117
- });
118
- describe('#genericNotFoundHandler()', function() {
119
- it('should return 404 HTTP status', function(done) {
120
- const router = this.createRouter();
121
- router.addRoute({
122
- route: '/',
123
- handlers: { get: (req, res, next) => res.end() }
124
- });
125
- router.addMiddleware(router.genericNotFoundHandler);
126
- router.init();
127
- this.testRequest(router, done, 404);
128
- });
129
- });
130
- describe('#genericErrorHandler()', function() {
131
- it('should return error HTTP status', function(done) {
132
- const router = this.createRouter();
133
- router.addRoute({
134
- route: '/',
135
- handlers: { get: (req, res, next) => next(new Error('Something bad happened')) }
136
- });
137
- router.addMiddleware(router.genericErrorHandler);
138
- router.init();
139
- this.testRequest(router, done, 500);
140
- });
141
- });
142
- });
@@ -1,51 +0,0 @@
1
- const { Hook } = require('adapt-authoring-core');
2
- const Router = require('../lib/Router');
3
- const ServerModule = require('../lib/ServerModule');
4
- const should = require('should');
5
- const supertest = require('supertest');
6
-
7
- describe('Server module', function() {
8
- before(function() {
9
- this.server = new ServerModule(global.ADAPT.app, { name: require('../package.json').name });
10
- });
11
- describe('#constructor()', function() {
12
- it('should expose the Express application', function() {
13
- false.should.be.true();
14
- });
15
- it('should expose a `root` Router', function() {
16
- this.server.root.should.be.an.instanceof(Router);
17
- });
18
- it('should expose an `api` Router', function() {
19
- this.server.api.should.be.an.instanceof(Router);
20
- });
21
- it('should expose a hook to modify requests', function() {
22
- this.server.requestHook.should.be.an.instanceof(Hook);
23
- });
24
- });
25
- describe('#url()', function() {
26
- it('should return the URL of the server', function() {
27
- this.server.url.should.be.a.String();
28
- });
29
- });
30
- describe('#static()', function() {
31
- it('should expose Express#static', function() {
32
- false.should.be.true();
33
- });
34
- });
35
- describe('#listen()', function() {
36
- it('should accept requests on the specified URL/port', function(done) {
37
- supertest(this.server.expressApp)
38
- .get(`${this.server.api.path}`)
39
- .expect(200)
40
- .end(done);
41
- });
42
- it('should not accept requests on unspecified URLs/ports', function(done) {
43
- false.should.be.true();
44
- });
45
- });
46
- describe('#close()', function() {
47
- it('should stop accepting requests', function() {
48
- false.should.be.true();
49
- });
50
- });
51
- });