adapt-authoring-jsonschema 1.1.1 → 1.1.3
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/releases.yml +9 -2
- package/.github/workflows/standardjs.yml +13 -0
- package/docs/plugins/schemas-reference.js +55 -49
- package/lib/JsonSchema.js +2 -2
- package/lib/JsonSchemaModule.js +9 -7
- package/lib/XSSDefaults.js +1 -1
- package/lib/typedefs.js +1 -1
- package/package.json +9 -10
- package/.eslintignore +0 -1
- package/.eslintrc +0 -14
|
@@ -3,10 +3,16 @@ on:
|
|
|
3
3
|
push:
|
|
4
4
|
branches:
|
|
5
5
|
- master
|
|
6
|
+
|
|
6
7
|
jobs:
|
|
7
8
|
release:
|
|
8
9
|
name: Release
|
|
9
10
|
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
contents: write # to be able to publish a GitHub release
|
|
13
|
+
issues: write # to be able to comment on released issues
|
|
14
|
+
pull-requests: write # to be able to comment on released pull requests
|
|
15
|
+
id-token: write # to enable use of OIDC for trusted publishing and npm provenance
|
|
10
16
|
steps:
|
|
11
17
|
- name: Checkout
|
|
12
18
|
uses: actions/checkout@v3
|
|
@@ -16,10 +22,11 @@ jobs:
|
|
|
16
22
|
uses: actions/setup-node@v3
|
|
17
23
|
with:
|
|
18
24
|
node-version: 'lts/*'
|
|
25
|
+
- name: Update npm
|
|
26
|
+
run: npm install -g npm@latest
|
|
19
27
|
- name: Install dependencies
|
|
20
28
|
run: npm ci
|
|
21
29
|
- name: Release
|
|
22
30
|
env:
|
|
23
31
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
24
|
-
|
|
25
|
-
run: npx semantic-release
|
|
32
|
+
run: npx semantic-release
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
name: Standard.js formatting check
|
|
2
|
+
on: push
|
|
3
|
+
jobs:
|
|
4
|
+
default:
|
|
5
|
+
runs-on: ubuntu-latest
|
|
6
|
+
steps:
|
|
7
|
+
- uses: actions/checkout@master
|
|
8
|
+
- uses: actions/setup-node@master
|
|
9
|
+
with:
|
|
10
|
+
node-version: 'lts/*'
|
|
11
|
+
cache: 'npm'
|
|
12
|
+
- run: npm ci
|
|
13
|
+
- run: npx standard
|
|
@@ -1,74 +1,80 @@
|
|
|
1
1
|
export default class SchemasReference {
|
|
2
|
-
constructor(app, config, dir, utils) {
|
|
3
|
-
this.app = app
|
|
4
|
-
this.utils = utils
|
|
2
|
+
constructor (app, config, dir, utils) {
|
|
3
|
+
this.app = app
|
|
4
|
+
this.utils = utils
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
6
|
+
|
|
7
|
+
async run () {
|
|
8
|
+
this.schemas = await this.loadSchemas()
|
|
9
|
+
this.manualFile = 'schemas-reference.md'
|
|
10
|
+
this.contents = Object.keys(this.schemas)
|
|
11
|
+
this.replace = { LIST: this.generateList() }
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
async loadSchemas () {
|
|
15
|
+
const schema = await this.app.waitForModule('jsonschema')
|
|
14
16
|
return Object.keys(schema.schemas)
|
|
15
17
|
.sort((a, b) => a.localeCompare(b))
|
|
16
|
-
.reduce((schemas, s) => Object.assign(schemas, { [s]: schema.schemas[s].raw }), {})
|
|
18
|
+
.reduce((schemas, s) => Object.assign(schemas, { [s]: schema.schemas[s].raw }), {})
|
|
17
19
|
}
|
|
18
|
-
|
|
20
|
+
|
|
21
|
+
generateList () {
|
|
19
22
|
return Object.entries(this.schemas).reduce((output, [dep, schema]) => {
|
|
20
23
|
return `${output}<h3 id="${dep.toLowerCase()}" class="dep">${dep}</h3>
|
|
21
24
|
|
|
22
25
|
${this.schemaToMd(schema)}
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
}, '')
|
|
27
|
+
`
|
|
28
|
+
}, '')
|
|
26
29
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
schemaToMd (schema) {
|
|
32
|
+
let output = ''
|
|
33
|
+
if (schema.description) {
|
|
34
|
+
output += `<div class="desc">${schema.description}</div>\n\n`
|
|
31
35
|
}
|
|
32
|
-
let s
|
|
33
|
-
if(schema.properties) {
|
|
34
|
-
s = schema
|
|
35
|
-
} else if(schema.$patch) {
|
|
36
|
-
s = schema.$patch.with
|
|
37
|
-
const ref = schema.$patch.source.$ref
|
|
38
|
-
output += `<div class="extension">Patches <a href="#/schemas-reference?id=${ref}">${ref}</a></div
|
|
39
|
-
} else if(schema.$merge) {
|
|
40
|
-
s = schema.$merge.with
|
|
41
|
-
const ref = schema.$merge?.source?.$ref
|
|
42
|
-
output += `<div class="extension">${ref ? `Merges with <a href="#/schemas-reference?id=${ref}">${ref}</a>` : 'This is a merge schema'}</div>\n\n
|
|
36
|
+
let s
|
|
37
|
+
if (schema.properties) {
|
|
38
|
+
s = schema
|
|
39
|
+
} else if (schema.$patch) {
|
|
40
|
+
s = schema.$patch.with
|
|
41
|
+
const ref = schema.$patch.source.$ref
|
|
42
|
+
output += `<div class="extension">Patches <a href="#/schemas-reference?id=${ref}">${ref}</a></div>`
|
|
43
|
+
} else if (schema.$merge) {
|
|
44
|
+
s = schema.$merge.with
|
|
45
|
+
const ref = schema.$merge?.source?.$ref
|
|
46
|
+
output += `<div class="extension">${ref ? `Merges with <a href="#/schemas-reference?id=${ref}">${ref}</a>` : 'This is a merge schema'}</div>\n\n`
|
|
43
47
|
}
|
|
44
|
-
const { properties, required } = s
|
|
48
|
+
const { properties, required } = s
|
|
45
49
|
|
|
46
|
-
if(!properties) {
|
|
47
|
-
return
|
|
50
|
+
if (!properties) {
|
|
51
|
+
return
|
|
48
52
|
}
|
|
49
|
-
if(required) {
|
|
50
|
-
output +=
|
|
53
|
+
if (required) {
|
|
54
|
+
output += '<div class="required">Fields in bold are required.</div>\n\n'
|
|
51
55
|
}
|
|
52
|
-
const table = `<tr><th>Attribute</th><th>Type</th><th>Default</th><th>Description</th></tr>${this.tableRowsFromProps(properties, required)}
|
|
53
|
-
return `${output}<table class="schema">${table}</table
|
|
56
|
+
const table = `<tr><th>Attribute</th><th>Type</th><th>Default</th><th>Description</th></tr>${this.tableRowsFromProps(properties, required)}`
|
|
57
|
+
return `${output}<table class="schema">${table}</table>`
|
|
54
58
|
}
|
|
55
|
-
|
|
59
|
+
|
|
60
|
+
tableRowsFromProps (properties, required = [], parent) {
|
|
56
61
|
return Object.entries(properties).reduce((output, [attr, config]) => {
|
|
57
|
-
const attrKey = (parent ? parent + '.' : '') + attr
|
|
58
|
-
output +=
|
|
59
|
-
output += `<td>${attrKey}</td>\n
|
|
60
|
-
output += `<td>${config.type}</td>\n
|
|
61
|
-
output += `<td>${config.default !== undefined ? this.defaultToMd(config.default) : ''}</td>\n
|
|
62
|
-
output += `<td>${config.description || ' '}</td>\n
|
|
63
|
-
output +=
|
|
64
|
-
if(config.properties) output += this.tableRowsFromProps(config.properties, config.required, attrKey)
|
|
65
|
-
return output
|
|
66
|
-
}, '')
|
|
62
|
+
const attrKey = (parent ? parent + '.' : '') + attr
|
|
63
|
+
output += `<tr class="${config.default === undefined && required && required.includes(attr) ? 'required' : ''}">\n`
|
|
64
|
+
output += `<td>${attrKey}</td>\n`
|
|
65
|
+
output += `<td>${config.type}</td>\n`
|
|
66
|
+
output += `<td>${config.default !== undefined ? this.defaultToMd(config.default) : ''}</td>\n`
|
|
67
|
+
output += `<td>${config.description || ' '}</td>\n`
|
|
68
|
+
output += '</tr>\n'
|
|
69
|
+
if (config.properties) output += this.tableRowsFromProps(config.properties, config.required, attrKey)
|
|
70
|
+
return output
|
|
71
|
+
}, '')
|
|
67
72
|
}
|
|
73
|
+
|
|
68
74
|
/**
|
|
69
75
|
* Returns a string formatted nicely for markdown
|
|
70
76
|
*/
|
|
71
|
-
defaultToMd(val) {
|
|
72
|
-
return `<pre>${JSON.stringify(val)}</pre
|
|
77
|
+
defaultToMd (val) {
|
|
78
|
+
return `<pre>${JSON.stringify(val)}</pre>`
|
|
73
79
|
}
|
|
74
80
|
}
|
package/lib/JsonSchema.js
CHANGED
|
@@ -149,7 +149,7 @@ class JsonSchema {
|
|
|
149
149
|
}))
|
|
150
150
|
}
|
|
151
151
|
this.built = built
|
|
152
|
-
if(options.compile !== false) { // don't compile when option present (e.g. when running build recursively)
|
|
152
|
+
if (options.compile !== false) { // don't compile when option present (e.g. when running build recursively)
|
|
153
153
|
this.compiled = await this.validator.compileAsync(built)
|
|
154
154
|
}
|
|
155
155
|
this.isBuilding = false
|
|
@@ -203,7 +203,7 @@ class JsonSchema {
|
|
|
203
203
|
validate (dataToValidate, options) {
|
|
204
204
|
const opts = _.defaults(options, { useDefaults: true, ignoreRequired: false })
|
|
205
205
|
const data = _.defaults(_.cloneDeep(dataToValidate), opts.useDefaults ? this.getObjectDefaults() : {})
|
|
206
|
-
if(!this.compiled) { // fallback in the case that the compiled function is missing
|
|
206
|
+
if (!this.compiled) { // fallback in the case that the compiled function is missing
|
|
207
207
|
this.log('warn', 'NO_COMPILED_FUNC', this.name)
|
|
208
208
|
this.validator.compile(this.built)
|
|
209
209
|
}
|
package/lib/JsonSchemaModule.js
CHANGED
|
@@ -32,7 +32,7 @@ class JsonSchemaModule extends AbstractModule {
|
|
|
32
32
|
* Invoked when schemas are registered
|
|
33
33
|
* @type {Hook}
|
|
34
34
|
*/
|
|
35
|
-
this.registerSchemasHook = new Hook
|
|
35
|
+
this.registerSchemasHook = new Hook()
|
|
36
36
|
/**
|
|
37
37
|
* Tags and attributes to be whitelisted by the XSS filter
|
|
38
38
|
* @type {Object}
|
|
@@ -53,9 +53,9 @@ class JsonSchemaModule extends AbstractModule {
|
|
|
53
53
|
keywords: Keywords.all
|
|
54
54
|
})
|
|
55
55
|
this.addStringFormats({
|
|
56
|
-
'date-time': /[A-za-z0-9
|
|
56
|
+
'date-time': /[A-za-z0-9:+()]+/,
|
|
57
57
|
time: /^(\d{2}):(\d{2}):(\d{2})\+(\d{2}):(\d{2})$/,
|
|
58
|
-
uri: /^(.+):\/\/(www\.)?[-a-zA-Z0-9@:%_
|
|
58
|
+
uri: /^(.+):\/\/(www\.)?[-a-zA-Z0-9@:%_+.~#?&//=]{1,256}/
|
|
59
59
|
})
|
|
60
60
|
await this.resetSchemaRegistry()
|
|
61
61
|
|
|
@@ -109,19 +109,21 @@ class JsonSchemaModule extends AbstractModule {
|
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
111
|
* Searches all Adapt dependencies for any local JSON schemas and registers them for use in the app. Schemas must be located in in a `/schema` folder, and be named appropriately: `*.schema.json`.
|
|
112
|
+
* @param options {object}
|
|
113
|
+
* @param options.quiet {Boolean} Set to true to suppress logs
|
|
112
114
|
* @return {Promise}
|
|
113
115
|
*/
|
|
114
|
-
async registerSchemas (
|
|
116
|
+
async registerSchemas (options = {}) {
|
|
115
117
|
await this.resetSchemaRegistry()
|
|
116
118
|
await Promise.all(Object.values(this.app.dependencies).map(async d => {
|
|
117
|
-
if(d.name === this.name) return
|
|
119
|
+
if (d.name === this.name) return
|
|
118
120
|
const files = await glob('schema/*.schema.json', { cwd: d.rootDir, absolute: true })
|
|
119
121
|
;(await Promise.allSettled(files.map(f => this.registerSchema(f))))
|
|
120
122
|
.filter(r => r.status === 'rejected')
|
|
121
123
|
.forEach(r => this.log('warn', r.reason))
|
|
122
124
|
}))
|
|
123
125
|
await this.registerSchemasHook.invoke()
|
|
124
|
-
if(quiet !== true) this.logSchemas()
|
|
126
|
+
if (options.quiet !== true) this.logSchemas()
|
|
125
127
|
}
|
|
126
128
|
|
|
127
129
|
/**
|
|
@@ -215,7 +217,7 @@ class JsonSchemaModule extends AbstractModule {
|
|
|
215
217
|
logSchemas () {
|
|
216
218
|
this.log('debug', 'SCHEMAS', Object.keys(this.schemas))
|
|
217
219
|
this.log('debug', 'SCHEMA_EXTENSIONS', Object.entries(this.schemas).reduce((m, [k, v]) => {
|
|
218
|
-
if(v.extensions.length) m[k] = v.extensions
|
|
220
|
+
if (v.extensions.length) m[k] = v.extensions
|
|
219
221
|
return m
|
|
220
222
|
}, {}))
|
|
221
223
|
}
|
package/lib/XSSDefaults.js
CHANGED
package/lib/typedefs.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adapt-authoring-jsonschema",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Module to add support for the JSON schema specification",
|
|
5
5
|
"homepage": "https://github.com/adapt-security/adapt-authoring-jsonschema",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -23,16 +23,15 @@
|
|
|
23
23
|
"adapt-authoring-core": "github:adapt-security/adapt-authoring-core"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"
|
|
27
|
-
"standard": "^17.1.0",
|
|
28
|
-
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
26
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
29
27
|
"@semantic-release/git": "^10.0.1",
|
|
30
|
-
"@semantic-release/github": "^
|
|
31
|
-
"@semantic-release/npm": "^
|
|
32
|
-
"@semantic-release/release-notes-generator": "^
|
|
33
|
-
"conventional-changelog-eslint": "^
|
|
34
|
-
"semantic-release": "^
|
|
35
|
-
"semantic-release-replace-plugin": "^1.2.7"
|
|
28
|
+
"@semantic-release/github": "^12.0.2",
|
|
29
|
+
"@semantic-release/npm": "^13.1.2",
|
|
30
|
+
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
31
|
+
"conventional-changelog-eslint": "^6.0.0",
|
|
32
|
+
"semantic-release": "^25.0.2",
|
|
33
|
+
"semantic-release-replace-plugin": "^1.2.7",
|
|
34
|
+
"standard": "^17.1.0"
|
|
36
35
|
},
|
|
37
36
|
"release": {
|
|
38
37
|
"plugins": [
|
package/.eslintignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
node_modules
|