adapt-authoring-config 1.1.5 → 1.2.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.
@@ -21,11 +21,6 @@ class ConfigModule extends AbstractModule {
21
21
  * @type {String}
22
22
  */
23
23
  this.configFilePath = path.join(this.app.rootDir, 'conf', `${process.env.NODE_ENV}.config.js`)
24
- /**
25
- * The keys for all attributes which can be modified during runtime
26
- * @type {Array<String>}
27
- */
28
- this.mutableAttributes = []
29
24
  /**
30
25
  * The keys for all attributes marked as public
31
26
  * @type {Array<String>}
@@ -61,7 +56,7 @@ class ConfigModule extends AbstractModule {
61
56
  const [auth, server] = await this.app.waitForModule('auth', 'server')
62
57
  const router = server.api.createChildRouter('config', [{
63
58
  route: '/',
64
- handlers: { get: (req, res) => res.json(this.getPublicConfig(req.params.mutable)) },
59
+ handlers: { get: (_req, res) => res.json(this.getPublicConfig()) },
65
60
  meta: {
66
61
  get: {
67
62
  summary: 'Retrieve public config data',
@@ -86,7 +81,7 @@ class ConfigModule extends AbstractModule {
86
81
  try { // try to parse to allow for non-string values
87
82
  val = JSON.parse(val)
88
83
  } catch {} // ignore errors
89
- this.set(this.envVarToConfigKey(key), val)
84
+ this._config[this.envVarToConfigKey(key)] = val
90
85
  })
91
86
  }
92
87
 
@@ -126,7 +121,7 @@ class ConfigModule extends AbstractModule {
126
121
  }
127
122
  Object.entries(config).forEach(([name, c]) => {
128
123
  Object.entries(c).forEach(([key, val]) => {
129
- this.set(`${name}.${key}`, val)
124
+ this._config[`${name}.${key}`] = val
130
125
  })
131
126
  })
132
127
  }
@@ -178,7 +173,6 @@ class ConfigModule extends AbstractModule {
178
173
  }
179
174
  // validate user config data
180
175
  let data = Object.entries(schema.raw.properties).reduce((m, [k, v]) => {
181
- if (v?._adapt?.isMutable) this.mutableAttributes.push(`${pkg.name}.${k}`)
182
176
  if (v?._adapt?.isPublic) this.publicAttributes.push(`${pkg.name}.${k}`)
183
177
  return { ...m, [k]: this.get(`${pkg.name}.${k}`) }
184
178
  }, {})
@@ -189,7 +183,7 @@ class ConfigModule extends AbstractModule {
189
183
  throw e
190
184
  }
191
185
  // apply validated config settings
192
- Object.entries(data).forEach(([key, val]) => this.set(`${pkg.name}.${key}`, val, { force: true }))
186
+ Object.entries(data).forEach(([key, val]) => { this._config[`${pkg.name}.${key}`] = val })
193
187
  }
194
188
 
195
189
  /**
@@ -210,30 +204,13 @@ class ConfigModule extends AbstractModule {
210
204
  return this._config[attr]
211
205
  }
212
206
 
213
- /**
214
- * Stores a value for the passed attribute
215
- * @param {String} attr Attribute key name
216
- * @param {*} val Value to set
217
- * @param {objeect} options Custom options
218
- * @param {objeect} options.force Whether to force an update
219
- */
220
- set (attr, val, options = {}) {
221
- if (this.has(attr) && !this.mutableAttributes.includes(attr) && options.force !== true) {
222
- return
223
- }
224
- this._config[attr] = val
225
- }
226
-
227
207
  /**
228
208
  * Retrieves all config options marked as 'public'
229
- * @param {Boolean} isMutable Whether options should also be mutable
230
209
  * @return {Object}
231
210
  */
232
- getPublicConfig (isMutable) {
211
+ getPublicConfig () {
233
212
  return this.publicAttributes.reduce((m, a) => {
234
- if (!isMutable || (isMutable && this.mutableAttributes.includes(a))) {
235
- m[a] = this.get(a)
236
- }
213
+ m[a] = this.get(a)
237
214
  return m
238
215
  }, {})
239
216
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-config",
3
- "version": "1.1.5",
3
+ "version": "1.2.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",
@@ -16,7 +16,7 @@
16
16
  "glob": "^13.0.0"
17
17
  },
18
18
  "peerDependencies": {
19
- "adapt-authoring-auth": "^1.0.5",
19
+ "adapt-authoring-auth": "^1.0.7",
20
20
  "adapt-authoring-errors": "^1.1.2",
21
21
  "adapt-authoring-jsonschema": "^1.2.0",
22
22
  "adapt-authoring-server": "^1.2.1"
@@ -31,14 +31,6 @@ describe('Config module', function () {
31
31
  actualValue.should.equal(expectedValue)
32
32
  })
33
33
  })
34
- describe('#set()', function () {
35
- it('should be able to set a value', function () {
36
- const newValue = 'newtestvalue'
37
- this.config.set('adapt-authoring-testing.test', newValue)
38
- const actualValue = this.config.get('adapt-authoring-testing.test')
39
- actualValue.should.equal(newValue)
40
- })
41
- })
42
34
  describe('#getPublicConfig()', function () {
43
35
  it('should be able to retrieve values marked as public', function () {
44
36
  this.config.app.dependencies = [{ name: 'adapt-authoring-testing', dir: path.join(__dirname, 'data') }]