adapt-authoring-server 2.3.0 → 2.3.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.
- package/.github/workflows/new.yml +5 -5
- package/.github/workflows/releases.yml +2 -1
- package/README.md +9 -0
- package/lib/ServerModule.js +16 -1
- package/lib/utils/generateRouterMap.js +1 -1
- package/package.json +2 -2
- package/tests/ServerUtils.spec.js +6 -7
- package/tests/utils-generateRouterMap.spec.js +1 -3
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
name: Add PR to Project
|
|
4
|
-
|
|
1
|
+
name: Add to project
|
|
5
2
|
on:
|
|
3
|
+
issues:
|
|
4
|
+
types:
|
|
5
|
+
- opened
|
|
6
|
+
- reopened
|
|
6
7
|
pull_request:
|
|
7
8
|
types:
|
|
8
9
|
- opened
|
|
9
10
|
- reopened
|
|
10
|
-
|
|
11
11
|
jobs:
|
|
12
12
|
add-to-project:
|
|
13
13
|
uses: adapt-security/.github/.github/workflows/new.yml@main
|
|
@@ -10,7 +10,8 @@ permissions:
|
|
|
10
10
|
issues: write
|
|
11
11
|
pull-requests: write
|
|
12
12
|
id-token: write
|
|
13
|
+
packages: write
|
|
13
14
|
|
|
14
15
|
jobs:
|
|
15
16
|
release:
|
|
16
|
-
uses: adaptlearning/semantic-release-config/.github/workflows/release.yml@master
|
|
17
|
+
uses: adaptlearning/semantic-release-config/.github/workflows/release.yml@master
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# adapt-authoring-server
|
|
2
|
+
|
|
3
|
+
Provides the Express application that fronts the Adapt authoring tool — routing, the middleware stack and the static/API serving other modules attach their routers to.
|
|
4
|
+
|
|
5
|
+
Extends `AbstractModule` from [adapt-authoring-core](../adapt-authoring-core).
|
|
6
|
+
|
|
7
|
+
## Documentation
|
|
8
|
+
|
|
9
|
+
- [Server requests](docs/server-requests.md) — the request/response lifecycle and routing
|
package/lib/ServerModule.js
CHANGED
|
@@ -2,6 +2,7 @@ import express from 'express'
|
|
|
2
2
|
import { AbstractModule, Hook } from 'adapt-authoring-core'
|
|
3
3
|
import Router from './Router.js'
|
|
4
4
|
import ServerUtils from './ServerUtils.js'
|
|
5
|
+
import { mapHandler } from './utils/mapHandler.js'
|
|
5
6
|
/**
|
|
6
7
|
* Adds an Express server to the authoring tool
|
|
7
8
|
* @memberof server
|
|
@@ -20,7 +21,21 @@ class ServerModule extends AbstractModule {
|
|
|
20
21
|
* @type {Router}
|
|
21
22
|
*/
|
|
22
23
|
this.api = new Router('/api', this.expressApp, [], [ServerUtils.debugRequestTime])
|
|
23
|
-
this.api.
|
|
24
|
+
this.api.addRoute({
|
|
25
|
+
route: '/',
|
|
26
|
+
handlers: { get: mapHandler(this.api) },
|
|
27
|
+
meta: {
|
|
28
|
+
get: {
|
|
29
|
+
summary: 'Retrieve a map of the available API endpoints',
|
|
30
|
+
responses: {
|
|
31
|
+
200: {
|
|
32
|
+
description: 'The API endpoint map',
|
|
33
|
+
content: { 'application/json': { schema: { type: 'object' } } }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
})
|
|
24
39
|
/**
|
|
25
40
|
* The default/'root' router for the application
|
|
26
41
|
* @type {Router}
|
|
@@ -32,7 +32,7 @@ function getEndpoints (r) {
|
|
|
32
32
|
/** @ignore */
|
|
33
33
|
function getRelativeRoute (relFrom, relTo) {
|
|
34
34
|
if (relFrom === relTo) {
|
|
35
|
-
return
|
|
35
|
+
return 'general_'
|
|
36
36
|
}
|
|
37
37
|
let route = ''
|
|
38
38
|
for (let r = relTo; r !== relFrom; r = r.parentRouter) route = `${r.root}_${route}`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adapt-authoring-server",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.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",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"test": "node --test tests/**/*.spec.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"adapt-authoring-core": "^
|
|
14
|
+
"adapt-authoring-core": "^3.0.0",
|
|
15
15
|
"express": "^5.1.0",
|
|
16
16
|
"hbs": "^4.2.0",
|
|
17
17
|
"lodash": "^4.17.21"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, it, before } from 'node:test'
|
|
1
|
+
import { describe, it, before, beforeEach } from 'node:test'
|
|
2
2
|
import assert from 'node:assert/strict'
|
|
3
3
|
import { App } from 'adapt-authoring-core'
|
|
4
4
|
|
|
@@ -16,6 +16,11 @@ describe('ServerUtils', () => {
|
|
|
16
16
|
ServerUtils = (await import('../lib/ServerUtils.js')).default
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
// real errors expose registered codes as non-configurable getters, so stub with a plain object
|
|
21
|
+
App.instance.errors = {}
|
|
22
|
+
})
|
|
23
|
+
|
|
19
24
|
describe('#addErrorHandler()', () => {
|
|
20
25
|
/** Set up a res with addErrorHandler + status/json capture */
|
|
21
26
|
function createSendErrorSetup (reqOverrides = {}) {
|
|
@@ -57,7 +62,6 @@ describe('ServerUtils', () => {
|
|
|
57
62
|
})
|
|
58
63
|
|
|
59
64
|
it('sendError should fall back to SERVER_ERROR for unknown errors', () => {
|
|
60
|
-
App.instance.errors = App.instance.errors || {}
|
|
61
65
|
App.instance.errors.SERVER_ERROR = {
|
|
62
66
|
constructor: { name: 'AdaptError' },
|
|
63
67
|
statusCode: 500,
|
|
@@ -74,7 +78,6 @@ describe('ServerUtils', () => {
|
|
|
74
78
|
})
|
|
75
79
|
|
|
76
80
|
it('sendError should look up known error codes on non-AdaptError', () => {
|
|
77
|
-
App.instance.errors = App.instance.errors || {}
|
|
78
81
|
App.instance.errors.CUSTOM_CODE = {
|
|
79
82
|
statusCode: 422,
|
|
80
83
|
code: 'CUSTOM_CODE',
|
|
@@ -92,7 +95,6 @@ describe('ServerUtils', () => {
|
|
|
92
95
|
})
|
|
93
96
|
|
|
94
97
|
it('sendError should copy data from non-AdaptError to looked-up error', () => {
|
|
95
|
-
App.instance.errors = App.instance.errors || {}
|
|
96
98
|
App.instance.errors.VALIDATION_FAILED = {
|
|
97
99
|
statusCode: 400,
|
|
98
100
|
code: 'VALIDATION_FAILED',
|
|
@@ -190,7 +192,6 @@ describe('ServerUtils', () => {
|
|
|
190
192
|
|
|
191
193
|
it('should call next with METHOD_NOT_ALLOWED when path exists but method does not match', () => {
|
|
192
194
|
const mockError = { code: 'METHOD_NOT_ALLOWED' }
|
|
193
|
-
App.instance.errors = App.instance.errors || {}
|
|
194
195
|
App.instance.errors.METHOD_NOT_ALLOWED = { setData: () => mockError }
|
|
195
196
|
|
|
196
197
|
const mockRouter = {
|
|
@@ -215,7 +216,6 @@ describe('ServerUtils', () => {
|
|
|
215
216
|
|
|
216
217
|
describe('#rootNotFoundHandler()', () => {
|
|
217
218
|
it('should respond with NOT_FOUND status code', () => {
|
|
218
|
-
App.instance.errors = App.instance.errors || {}
|
|
219
219
|
App.instance.errors.NOT_FOUND = { statusCode: 404 }
|
|
220
220
|
|
|
221
221
|
let statusCode
|
|
@@ -235,7 +235,6 @@ describe('ServerUtils', () => {
|
|
|
235
235
|
describe('#apiNotFoundHandler()', () => {
|
|
236
236
|
it('should call next with ENDPOINT_NOT_FOUND error', () => {
|
|
237
237
|
const mockError = { code: 'ENDPOINT_NOT_FOUND' }
|
|
238
|
-
App.instance.errors = App.instance.errors || {}
|
|
239
238
|
App.instance.errors.ENDPOINT_NOT_FOUND = { setData: () => mockError }
|
|
240
239
|
|
|
241
240
|
let nextArg
|
|
@@ -42,7 +42,6 @@ describe('generateRouterMap()', () => {
|
|
|
42
42
|
it('should include endpoint URLs and accepted methods', () => {
|
|
43
43
|
const mockRouter = {
|
|
44
44
|
root: 'api',
|
|
45
|
-
route: '/api',
|
|
46
45
|
path: '/api',
|
|
47
46
|
url: 'http://localhost:5000/api',
|
|
48
47
|
routes: [
|
|
@@ -59,6 +58,7 @@ describe('generateRouterMap()', () => {
|
|
|
59
58
|
const keys = Object.keys(map)
|
|
60
59
|
|
|
61
60
|
assert.ok(keys.length > 0)
|
|
61
|
+
assert.equal(keys[0], 'general_endpoints')
|
|
62
62
|
const endpoints = map[keys[0]]
|
|
63
63
|
assert.ok(Array.isArray(endpoints))
|
|
64
64
|
assert.equal(endpoints[0].url, 'http://localhost:5000/api/users')
|
|
@@ -81,7 +81,6 @@ describe('generateRouterMap()', () => {
|
|
|
81
81
|
}
|
|
82
82
|
const mockRouter = {
|
|
83
83
|
root: 'api',
|
|
84
|
-
route: '/api',
|
|
85
84
|
path: '/api',
|
|
86
85
|
url: 'http://localhost:5000/api',
|
|
87
86
|
routes: [],
|
|
@@ -117,7 +116,6 @@ describe('generateRouterMap()', () => {
|
|
|
117
116
|
}
|
|
118
117
|
const mockRouter = {
|
|
119
118
|
root: 'api',
|
|
120
|
-
route: '/api',
|
|
121
119
|
path: '/api',
|
|
122
120
|
url: 'http://localhost:5000/api',
|
|
123
121
|
routes: [],
|