adapt-authoring-config 1.4.4 → 1.5.0

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,4 +1,4 @@
1
- name: Standard.js formatting check
1
+ name: Lint
2
2
  on: push
3
3
  jobs:
4
4
  default:
@@ -9,4 +9,4 @@ jobs:
9
9
  with:
10
10
  node-version: 'lts/*'
11
11
  - run: npm install
12
- - run: npx standard
12
+ - run: npx standard
@@ -50,4 +50,29 @@ $ NODE_ENV=dev npm start
50
50
  > set NODE_ENV=dev | npm start
51
51
  ```
52
52
 
53
- Please see the documentation for your own operating system for instructions on how to save environment variables in a more permanent way.
53
+ Please see the documentation for your own operating system for instructions on how to save environment variables in a more permanent way.
54
+
55
+ ## Using environment variables for configuration
56
+
57
+ As an alternative to config files, any configuration option can be set via an environment variable using the following naming convention:
58
+
59
+ ```
60
+ ADAPT_AUTHORING_<MODULE>__<property>
61
+ ```
62
+
63
+ - The module name is converted to uppercase with underscores replacing hyphens (e.g. `adapt-authoring-server` becomes `ADAPT_AUTHORING_SERVER`)
64
+ - A double underscore (`__`) separates the module name from the property name
65
+ - The property name is kept in its original camelCase format
66
+
67
+ For example:
68
+
69
+ | Environment variable | Config equivalent |
70
+ | --- | --- |
71
+ | `ADAPT_AUTHORING_SERVER__host` | `adapt-authoring-server.host` |
72
+ | `ADAPT_AUTHORING_SERVER__port` | `adapt-authoring-server.port` |
73
+ | `ADAPT_AUTHORING_MONGODB__connectionUri` | `adapt-authoring-mongodb.connectionUri` |
74
+ | `ADAPT_AUTHORING_AUTH_LOCAL__saltRounds` | `adapt-authoring-auth-local.saltRounds` |
75
+
76
+ Values are parsed as JSON where possible, so non-string types like numbers and booleans can be set directly (e.g. `ADAPT_AUTHORING_SERVER__port=5678`).
77
+
78
+ Any environment variables that do not start with `ADAPT_AUTHORING_` are available under the `env` namespace (e.g. `NODE_ENV` becomes `env.NODE_ENV`).
@@ -1,5 +1,5 @@
1
1
  # Configuration reference
2
- This page lists all configuration options supported by the [core bundle](coremodules) of Adapt authoring modules.
2
+ This page lists all configuration options supported by the [core bundle](coremodules) of Adapt authoring modules. For details on how to set up your configuration, including using environment variables, see [Configuring your environment](configure-environment).
3
3
 
4
4
  {{{TABLE_OF_CONTENTS}}}
5
5
 
@@ -128,21 +128,21 @@ class ConfigModule extends AbstractModule {
128
128
  return a.name.localeCompare(b.name)
129
129
  })
130
130
  const coreDep = deps.find(d => isCore(d))
131
- if (coreDep) await this.processModuleSchema(coreDep, jsonschema)
131
+ if (coreDep) this.processModuleSchema(coreDep, jsonschema)
132
132
 
133
- const promises = deps.filter(d => !isCore(d)).map(d => this.processModuleSchema(d, jsonschema))
134
- let hasErrored = false;
135
-
136
- (await Promise.allSettled(promises)).forEach(r => {
137
- if (r.status === 'rejected') {
133
+ let hasErrored = false
134
+ for (const d of deps.filter(d => !isCore(d))) {
135
+ try {
136
+ this.processModuleSchema(d, jsonschema)
137
+ } catch (e) {
138
138
  hasErrored = true
139
- if (r.reason?.data?.errors) {
140
- console.log(`${r.reason.modName}: ${r.reason.data.errors}`)
139
+ if (e?.data?.errors) {
140
+ console.log(`${e.modName}: ${e.data.errors}`)
141
141
  } else {
142
- console.log(r.reason)
142
+ console.log(e)
143
143
  }
144
144
  }
145
- })
145
+ }
146
146
  if (hasErrored) throw new Error()
147
147
  }
148
148
 
@@ -150,15 +150,14 @@ class ConfigModule extends AbstractModule {
150
150
  * Processes and validates a single module config schema (checks the user config specifies any required fields, and that they are the expected type)
151
151
  * @param {Object} pkg Package.json data
152
152
  * @param {JsonSchemaModule} jsonschema Module instance for validation
153
- * @return {Promise}
154
153
  */
155
- async processModuleSchema (pkg, jsonschema) {
154
+ processModuleSchema (pkg, jsonschema) {
156
155
  if (!pkg.name || !pkg.rootDir) return
157
156
 
158
157
  const schemaPath = path.resolve(pkg.rootDir, 'conf/config.schema.json')
159
158
  let schema
160
159
  try {
161
- schema = await (await jsonschema.createSchema(schemaPath)).build()
160
+ schema = jsonschema.createSchema(schemaPath).build()
162
161
  } catch (e) {
163
162
  return
164
163
  }
@@ -168,7 +167,7 @@ class ConfigModule extends AbstractModule {
168
167
  return { ...m, [k]: this.get(`${pkg.name}.${k}`) }
169
168
  }, {})
170
169
  try {
171
- data = await schema.validate(data)
170
+ data = schema.validate(data)
172
171
  } catch (e) {
173
172
  e.modName = pkg.name
174
173
  throw e
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-config",
3
- "version": "1.4.4",
3
+ "version": "1.5.0",
4
4
  "description": "A configuration module for the Adapt authoring tool.",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-config",
6
6
  "license": "GPL-3.0",