adapt-authoring-adaptframework 1.9.9 → 1.10.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.
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "FW_IMPORT_CONTENT_FAILED": {
25
25
  "data": {
26
- "errors": "Accompanying errors"
26
+ "errors": "Array of accompanying errors, each with either { schemaName, id, errors } or { message }"
27
27
  },
28
28
  "description": "Import of framework content failed",
29
29
  "statusCode": 400
@@ -45,11 +45,17 @@
45
45
  },
46
46
  "FW_IMPORT_INVALID": {
47
47
  "description": "An invalid import zip has been provided",
48
- "statusCode": 400
48
+ "statusCode": 400,
49
+ "data": {
50
+ "reason": "The reason the import zip was considered invalid"
51
+ }
49
52
  },
50
53
  "FW_IMPORT_INVALID_COURSE": {
51
54
  "description": "An invalid course has been provided",
52
- "statusCode": 400
55
+ "statusCode": 400,
56
+ "data": {
57
+ "reason": "The reason the course was considered invalid"
58
+ }
53
59
  },
54
60
  "FW_IMPORT_INVALID_CONTENT": {
55
61
  "description": "An invalid content item has been found in import data",
@@ -58,6 +64,13 @@
58
64
  "item": "The invalid content item"
59
65
  }
60
66
  },
67
+ "FW_IMPORT_MIGRATION_FAILED": {
68
+ "data": {
69
+ "reason": "The reason the migration failed"
70
+ },
71
+ "description": "Migration of course content failed",
72
+ "statusCode": 500
73
+ },
61
74
  "FW_IMPORT_MISSING_PLUGINS": {
62
75
  "description": "Course for import uses plugins which are missing from the server",
63
76
  "statusCode": 400
@@ -78,10 +91,27 @@
78
91
  "description": "Plugin is incompatible",
79
92
  "statusCode": 500
80
93
  },
94
+ "FW_LATEST_VERSION_FAILED": {
95
+ "data": {
96
+ "reason": "The reason the version check failed"
97
+ },
98
+ "description": "Failed to retrieve the latest framework version",
99
+ "statusCode": 500
100
+ },
81
101
  "FW_INSTALL_FAILED": {
102
+ "data": {
103
+ "reason": "The reason the installation failed"
104
+ },
82
105
  "description": "Installation of the framework failed",
83
106
  "statusCode": 500
84
107
  },
108
+ "FW_UPDATE_FAILED": {
109
+ "data": {
110
+ "reason": "The reason the update failed"
111
+ },
112
+ "description": "Update of the framework failed",
113
+ "statusCode": 500
114
+ },
85
115
  "FW_INVALID_VERSION": {
86
116
  "data": {
87
117
  "name": "Incompatible plugin name",
@@ -374,19 +374,17 @@ class AdaptFrameworkBuild {
374
374
  Object.assign(i, JSON.parse(itemString))
375
375
  // insert expected _component values
376
376
  if (i._component) {
377
- i._component = this.enabledPlugins.find(p => p.name === i._component).targetAttribute.slice(1)
377
+ i._component = this.enabledPlugins.find(p => p.name === i._component)?.targetAttribute.slice(1) ?? i._component
378
378
  }
379
379
  })
380
380
  // move globals to a nested _extensions object as expected by the framework
381
381
  this.enabledPlugins.forEach(({ targetAttribute, type }) => {
382
382
  let key = `_${type}`
383
383
  if (type === 'component' || type === 'extension') key += 's'
384
- try {
385
- _.merge(this.courseData.course.data._globals, {
386
- [key]: { [targetAttribute]: this.courseData.course.data._globals[targetAttribute] }
387
- })
388
- delete this.courseData.course.data._globals[targetAttribute]
389
- } catch (e) {}
384
+ const globals = this.courseData.course.data._globals
385
+ if (!globals?.[targetAttribute]) return
386
+ _.merge(globals, { [key]: { [targetAttribute]: globals[targetAttribute] } })
387
+ delete globals[targetAttribute]
390
388
  })
391
389
  // map course tag values (_id -> title)
392
390
  const tags = await App.instance.waitForModule('tags')
@@ -311,7 +311,7 @@ class AdaptFrameworkImport {
311
311
  await fs.readdir(this.langPath)
312
312
  } catch (e) {
313
313
  this.framework.log('error', e)
314
- throw App.instance.errors.FW_IMPORT_INVALID_COURSE
314
+ throw (e?.statusCode ? e : App.instance.errors.FW_IMPORT_INVALID_COURSE.setData({ reason: e.message }))
315
315
  }
316
316
  FWUtils.logDir('unzipPath', this.path)
317
317
  FWUtils.logDir('coursePath', this.coursePath)
@@ -319,7 +319,7 @@ class AdaptFrameworkImport {
319
319
  try {
320
320
  /** @ignore */this.pkg = await FWUtils.readJson(`${this.path}/package.json`)
321
321
  } catch (e) {
322
- throw App.instance.errors.FW_IMPORT_INVALID
322
+ throw App.instance.errors.FW_IMPORT_INVALID.setData({ reason: e.message })
323
323
  }
324
324
  try {
325
325
  await fs.rm(`${this.path}/package-lock.json`)
@@ -517,7 +517,7 @@ class AdaptFrameworkImport {
517
517
  await fs.rm(path.join(this.framework.path, opts.captureDir), { recursive: true })
518
518
  } catch (error) {
519
519
  FWUtils.log('error', 'Migration process failed', error)
520
- throw new Error(`Migration process failed: ${error.message}`)
520
+ throw App.instance.errors.FW_IMPORT_MIGRATION_FAILED.setData({ reason: error.message })
521
521
  }
522
522
  }
523
523
 
@@ -665,11 +665,11 @@ class AdaptFrameworkImport {
665
665
  }
666
666
  this.statusReport.info.push({ code: 'INSTALL_PLUGIN', data: { name: p, version: bowerJson.version } })
667
667
  } catch (e) {
668
- if (e.code !== 'EEXIST') {
669
- FWUtils.log('error', 'PLUGIN_IMPORT_FAILED', p, e)
670
- errors.push({ plugin: p, error: e.data.errors[0] })
668
+ if (e.code === 'EEXIST') {
669
+ FWUtils.log('warn', 'PLUGIN_ALREADY_EXISTS', p)
671
670
  } else {
672
- errors.push(e)
671
+ FWUtils.log('error', 'PLUGIN_IMPORT_FAILED', p, e)
672
+ errors.push({ plugin: p, error: e.data?.errors?.[0] ?? e })
673
673
  }
674
674
  }
675
675
  }))
@@ -689,8 +689,9 @@ class AdaptFrameworkImport {
689
689
  * @return {Promise}
690
690
  */
691
691
  async importCourseData () {
692
- const stringifyError = e => {
693
- return e?.data?.schemaName ? `${e.data.schemaName} ${e.data.data._id} ${e.data.errors}` : App.instance.lang.translate(undefined, e)
692
+ const formatError = e => {
693
+ if (e?.data?.schemaName) return { schemaName: e.data.schemaName, id: e.data.data?._id, errors: e.data.errors }
694
+ return { message: App.instance.lang.translate(undefined, e) }
694
695
  }
695
696
  /**
696
697
  * Note: the execution order is important here
@@ -704,7 +705,7 @@ class AdaptFrameworkImport {
704
705
  // we need to run an update with the same data to make sure all extension schema settings are applied
705
706
  await this.importContentObject({ ...this.contentJson.course, _id: course._id }, { isUpdate: true })
706
707
  } catch (e) {
707
- throw App.instance.errors.FW_IMPORT_CONTENT_FAILED.setData({ errors: stringifyError(e) })
708
+ throw App.instance.errors.FW_IMPORT_CONTENT_FAILED.setData({ errors: [formatError(e)] })
708
709
  }
709
710
  const { sorted, hierarchy } = await this.getSortedData()
710
711
  const errors = []
@@ -718,11 +719,11 @@ class AdaptFrameworkImport {
718
719
  ...itemJson // note that JSON sort order will override the deduced one
719
720
  })
720
721
  } catch (e) {
721
- errors.push(stringifyError(e))
722
+ errors.push(formatError(e))
722
723
  }
723
724
  }
724
725
  }
725
- if (errors.length) throw App.instance.errors.FW_IMPORT_CONTENT_FAILED.setData({ errors: errors.join('; ') })
726
+ if (errors.length) throw App.instance.errors.FW_IMPORT_CONTENT_FAILED.setData({ errors })
726
727
  FWUtils.log('debug', 'imported course data successfully')
727
728
  }
728
729
 
@@ -108,7 +108,7 @@ class AdaptFrameworkModule extends AbstractModule {
108
108
  await this.runCliCommand('installFramework', { version })
109
109
  } catch (e) {
110
110
  this.log('error', `failed to install framework, ${e.message}`)
111
- throw this.app.errors.FW_INSTALL_FAILED
111
+ throw this.app.errors.FW_INSTALL_FAILED.setData({ reason: e.message })
112
112
  }
113
113
  this.log('verbose', 'INSTALL hook invoke')
114
114
  await this.postInstallHook.invoke()
@@ -123,7 +123,7 @@ class AdaptFrameworkModule extends AbstractModule {
123
123
  return semver.clean(await this.runCliCommand('getLatestFrameworkVersion'))
124
124
  } catch (e) {
125
125
  this.log('error', `failed to retrieve framework update data, ${e.message}`)
126
- throw e
126
+ throw this.app.errors.FW_LATEST_VERSION_FAILED.setData({ reason: e.message })
127
127
  }
128
128
  }
129
129
 
@@ -155,7 +155,7 @@ class AdaptFrameworkModule extends AbstractModule {
155
155
  this._version = await this.runCliCommand('getCurrentFrameworkVersion')
156
156
  } catch (e) {
157
157
  this.log('error', `failed to update framework, ${e.message}`)
158
- throw this.app.errors.FW_UPDATE_FAILED
158
+ throw this.app.errors.FW_UPDATE_FAILED.setData({ reason: e.message })
159
159
  }
160
160
  this.postUpdateHook.invoke()
161
161
  }
@@ -195,7 +195,7 @@ class AdaptFrameworkModule extends AbstractModule {
195
195
  if (data._type === 'course') {
196
196
  course = data
197
197
  } else {
198
- [course] = await content.find({ _id: data._courseId || (await content.find(data))._courseId })
198
+ course = await content.findOne({ _id: data._courseId || (await content.findOne(data, { strict: false }))?._courseId })
199
199
  }
200
200
  if (!course) {
201
201
  return
@@ -320,7 +320,7 @@ class AdaptFrameworkUtils {
320
320
  })
321
321
  res.json(importer.summary)
322
322
  } catch (e) {
323
- return next(App.instance.errors.FW_IMPORT_FAILED.setData({ error: e }))
323
+ return next(e?.statusCode ? e : App.instance.errors.FW_IMPORT_FAILED.setData({ error: e }))
324
324
  }
325
325
  }
326
326
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-adaptframework",
3
- "version": "1.9.9",
3
+ "version": "1.10.0",
4
4
  "description": "Adapt framework integration for the Adapt authoring tool",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-adaptframework",
6
6
  "license": "GPL-3.0",