adapt-authoring-server 2.3.1 → 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.
@@ -1,13 +1,13 @@
1
- # Calls the org-level reusable workflow to add PRs to the TODO Board
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
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
@@ -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.expressRouter.get('/', (req, res) => res.json(this.api?.map))
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 `${relFrom.route}_`
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.1",
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",
@@ -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: [],