@learnosity/lib-qti-converter 0.12.7 → 0.13.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.
- package/docs/GETTING_STARTED.md +71 -18
- package/docs/LEARNOSITY_BUNDLE_FORMAT.md +23 -7
- package/package.json +8 -8
- package/packages/cli/dist/{batchProcessors-DU1HwpHY.js → batchProcessors-DgiDpfpP.js} +271 -77
- package/packages/cli/dist/batchProcessors-DgiDpfpP.js.map +1 -0
- package/packages/cli/dist/batchWorker.js +1 -1
- package/packages/cli/dist/{create-prompt-DU9wLVhI.js → create-prompt-DyNnKXYU.js} +63 -53
- package/packages/cli/dist/create-prompt-DyNnKXYU.js.map +1 -0
- package/packages/cli/dist/{dist-DjpU2mIj.js → dist-D3v6G5F8.js} +6 -6
- package/packages/cli/dist/{dist-DjpU2mIj.js.map → dist-D3v6G5F8.js.map} +1 -1
- package/packages/cli/dist/{learnosityToQti-BSbH3jyx.js → learnosityToQti-CIj5603P.js} +4 -4
- package/packages/cli/dist/{learnosityToQti-BSbH3jyx.js.map → learnosityToQti-CIj5603P.js.map} +1 -1
- package/packages/cli/dist/{learnosityToQtiPackage-B0xRzYmy.js → learnosityToQtiPackage-n6nGGr32.js} +7 -7
- package/packages/cli/dist/{learnosityToQtiPackage-B0xRzYmy.js.map → learnosityToQtiPackage-n6nGGr32.js.map} +1 -1
- package/packages/cli/dist/main.js +5 -5
- package/packages/cli/dist/{nodeFileAccess-BkzSHCOh.js → nodeFileAccess-BhCoGDOi.js} +6 -3
- package/packages/cli/dist/{nodeFileAccess-BkzSHCOh.js.map → nodeFileAccess-BhCoGDOi.js.map} +1 -1
- package/packages/cli/dist/{pathUtils-B9yPTlVF.js → pathUtils-mTQZ0wYS.js} +36 -20
- package/packages/cli/dist/pathUtils-mTQZ0wYS.js.map +1 -0
- package/packages/cli/dist/{qtiPackageToLearnosity-C7JaaUDU.js → qtiPackageToLearnosity-B4cD8jUw.js} +13 -7
- package/packages/cli/dist/qtiPackageToLearnosity-B4cD8jUw.js.map +1 -0
- package/packages/cli/dist/{qtiToLearnosity-CYoG2aIX.js → qtiToLearnosity-DDjcpShJ.js} +7 -6
- package/packages/cli/dist/qtiToLearnosity-DDjcpShJ.js.map +1 -0
- package/packages/cli/dist/{resolveOptions-CW80R2EQ.js → resolveOptions-Czapkfc1.js} +22 -8
- package/packages/cli/dist/resolveOptions-Czapkfc1.js.map +1 -0
- package/packages/cli/dist/{table-DjOn2Tsk.js → table-DTSv0atR.js} +619 -236
- package/packages/cli/dist/table-DTSv0atR.js.map +1 -0
- package/packages/core/dist/index.d.ts +197 -184
- package/packages/core/dist/index.js +858 -303
- package/packages/core/dist/node.d.ts +211 -196
- package/packages/core/dist/node.js +889 -310
- package/packages/cli/dist/batchProcessors-DU1HwpHY.js.map +0 -1
- package/packages/cli/dist/create-prompt-DU9wLVhI.js.map +0 -1
- package/packages/cli/dist/pathUtils-B9yPTlVF.js.map +0 -1
- package/packages/cli/dist/qtiPackageToLearnosity-C7JaaUDU.js.map +0 -1
- package/packages/cli/dist/qtiToLearnosity-CYoG2aIX.js.map +0 -1
- package/packages/cli/dist/resolveOptions-CW80R2EQ.js.map +0 -1
- package/packages/cli/dist/table-DjOn2Tsk.js.map +0 -1
package/docs/GETTING_STARTED.md
CHANGED
|
@@ -231,11 +231,23 @@ This produces URLs like:
|
|
|
231
231
|
/>
|
|
232
232
|
```
|
|
233
233
|
|
|
234
|
+
### QTI → Learnosity asset filenames
|
|
235
|
+
|
|
236
|
+
QTI → Learnosity conversion uses deterministic, item-scoped asset filenames by default. For each package-local asset, the final Learnosity item reference and the canonical full QTI href are serialized as the ordered JSON tuple `JSON.stringify([finalItemReference, canonicalQtiAssetHref])`. The generated filename is:
|
|
237
|
+
|
|
238
|
+
```text
|
|
239
|
+
md5hex(JSON.stringify([finalItemReference, canonicalQtiAssetHref])) + sourceExtension
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
`md5hex` is the existing lowercase hexadecimal MD5 helper. `canonicalQtiAssetHref` converts backslashes to `/`, removes leading `./`, resolves safe `.`/`..` segments, and removes query strings and fragments while preserving the complete relative path and case. The original final extension is retained once. Thus, `images/intro/logo.png` and `images/outro/logo.png` produce different `.png` filenames, and the same item reference plus canonical href is repeatable across directory and ZIP inputs.
|
|
243
|
+
|
|
244
|
+
The selected filename is used in both generated Learnosity URLs and package bundle paths (`assets/<selected filename>`). Item JSON filenames remain controlled separately by `itemFilenameSource`. These generated QTI → Learnosity names are distinct from pre-existing Learnosity bundle/Data API names such as `<md5_hash>_<original_filename>`; this option does not rename assets during Learnosity → QTI conversion.
|
|
245
|
+
|
|
234
246
|
### `--custom-asset-url`
|
|
235
247
|
|
|
236
248
|
_Available for: `qti-to-learnosity`, `qti-package-to-learnosity`, `learnosity-to-qti`, `learnosity-to-qti-package`_
|
|
237
249
|
|
|
238
|
-
Specify a custom base URL/prefix for asset references (images, audio, video).
|
|
250
|
+
Specify a custom base URL/prefix for asset references (images, audio, video). For QTI → Learnosity, the value replaces the CDN base while the converter-generated deterministic asset filename is preserved. For Learnosity → QTI, the value replaces the reference prefix up to the existing asset filename.
|
|
239
251
|
|
|
240
252
|
**QTI → Learnosity** (`qti-to-learnosity`, `qti-package-to-learnosity`) — use a custom base instead of the default Learnosity CDN:
|
|
241
253
|
|
|
@@ -243,13 +255,29 @@ Specify a custom base URL/prefix for asset references (images, audio, video). Th
|
|
|
243
255
|
lcon qti-to-learnosity --in item.xml --out item.json --organisation_id 12345 --custom-asset-url "https://my-cdn.example.com/assets"
|
|
244
256
|
```
|
|
245
257
|
|
|
246
|
-
This produces
|
|
258
|
+
This produces a URL with your custom prefix and the deterministic generated asset filename:
|
|
247
259
|
|
|
248
260
|
```html
|
|
249
|
-
<img
|
|
261
|
+
<img
|
|
262
|
+
src="https://my-cdn.example.com/assets/<md5hex(JSON.stringify([itemReference, canonicalQtiAssetHref]))>.png"
|
|
263
|
+
/>
|
|
250
264
|
```
|
|
251
265
|
|
|
252
|
-
|
|
266
|
+
The hash input is the ordered JSON tuple `[finalItemReference, canonicalQtiAssetHref]`, where the asset href retains its full package-relative path after canonicalization. The original basename is not used by itself, so `images/intro/logo.png` and `images/outro/logo.png` cannot collide merely because both are named `logo.png`.
|
|
267
|
+
|
|
268
|
+
**Note:** In this direction, when `--custom-asset-url` is provided it overrides both the default Learnosity CDN and the `--mediavault` flag, but it does not change the generated filename or the physical bundle path.
|
|
269
|
+
|
|
270
|
+
By default, QTI → Learnosity uses the deterministic hashed filename above. To opt out for compatibility with existing basename-based CDN uploads, pass:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
lcon qti-to-learnosity \
|
|
274
|
+
--in item.xml \
|
|
275
|
+
--out item.json \
|
|
276
|
+
--organisation_id 12345 \
|
|
277
|
+
--preserve-asset-filenames
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
The library equivalent is `{ preserveAssetFilenames: true }`. The `--preserve-asset-filenames` flag is available on both `qti-to-learnosity` and `qti-package-to-learnosity`; the API option applies to both corresponding library conversions. This restores the original final QTI basename, such as `logo.png`, in both JSON URLs and bundle paths. It is compatibility behavior: if different QTI assets request the same basename, conversion reports a collision instead of silently overwriting an asset.
|
|
253
281
|
|
|
254
282
|
**Learnosity → QTI** (`learnosity-to-qti`, `learnosity-to-qti-package`) — rewrite the asset prefix in the generated QTI. When omitted, the default prefix is `./assets`, so a reference resolves to `./assets/<filename>` (matching the packaged `assets/` folder):
|
|
255
283
|
|
|
@@ -265,6 +293,30 @@ Given an input reference of `/vendor/learnosity/itembank/assets/abc123_photo.png
|
|
|
265
293
|
|
|
266
294
|
**Note:** In the Learnosity → QTI direction, `--custom-asset-url` only rewrites the reference strings in the generated XML — it does not relocate or rename the physical asset files copied into the package (those remain under `assets/`). Remote (`http(s)://`), protocol-relative (`//`) and `data:` URIs, and converter-internal references (such as the `lrn-normalize.css` stylesheet) are left untouched.
|
|
267
295
|
|
|
296
|
+
### `--preserve-asset-filenames`
|
|
297
|
+
|
|
298
|
+
_Available for: `qti-to-learnosity`, `qti-package-to-learnosity`_
|
|
299
|
+
|
|
300
|
+
Opt out of deterministic hashed asset filenames and preserve the original final QTI basename. The default is hashed naming based on the item reference and canonical QTI asset path; use this option only when existing CDN uploads require the original names.
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
lcon qti-package-to-learnosity \
|
|
304
|
+
--in ./qti-package \
|
|
305
|
+
--out ./output \
|
|
306
|
+
--organisation_id 12345 \
|
|
307
|
+
--preserve-asset-filenames
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
The library equivalent is:
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
{
|
|
314
|
+
preserveAssetFilenames: true;
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
The selected basename is used consistently in generated JSON URLs and physical bundle paths. If different item assets use the same basename, conversion reports a collision instead of silently overwriting either asset.
|
|
319
|
+
|
|
268
320
|
### `--item-reference-source`
|
|
269
321
|
|
|
270
322
|
_Available for: `qti-to-learnosity`, `qti-package-to-learnosity`_
|
|
@@ -526,20 +578,21 @@ Create `lrn-converter.config.json` in your working directory to set default opti
|
|
|
526
578
|
|
|
527
579
|
All options are optional. CLI flags override config file values.
|
|
528
580
|
|
|
529
|
-
| Option
|
|
530
|
-
|
|
|
531
|
-
| `qtiVersion`
|
|
532
|
-
| `outputFormat`
|
|
533
|
-
| `diagnostics`
|
|
534
|
-
| `pretty`
|
|
535
|
-
| `verbose`
|
|
536
|
-
| `output`
|
|
537
|
-
| `organisationId`
|
|
538
|
-
| `mediaVault`
|
|
539
|
-
| `customAssetUrl`
|
|
540
|
-
| `
|
|
541
|
-
| `
|
|
542
|
-
| `
|
|
581
|
+
| Option | Type | Default | Description |
|
|
582
|
+
| ------------------------ | ---------------------------------------------- | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
583
|
+
| `qtiVersion` | `"2.1"` \| `"2.2"` | `"2.2"` | QTI version to use for conversion |
|
|
584
|
+
| `outputFormat` | `"dir"` \| `"zip"` \| `"stdout"` | `"dir"` | Output format (auto-detected based on output path) |
|
|
585
|
+
| `diagnostics` | `"stderr"` \| `"file"` \| `"both"` \| `"none"` | `"file"` | Where to write diagnostic messages |
|
|
586
|
+
| `pretty` | `boolean` | `false` | Pretty-print JSON/XML output |
|
|
587
|
+
| `verbose` | `boolean` | `false` | Show detailed progress information |
|
|
588
|
+
| `output` | `string` | `"-"` | Default output directory for interactive mode |
|
|
589
|
+
| `organisationId` | `number` | - | Organisation ID for Learnosity CDN asset URLs |
|
|
590
|
+
| `mediaVault` | `boolean` | `false` | Use `media-vault` subdomain instead of `assets` for CDN URLs |
|
|
591
|
+
| `customAssetUrl` | `string` | - | Custom base URL/prefix for assets. QTI → Learnosity: overrides the default Learnosity CDN and `mediaVault`. Learnosity → QTI: replaces the asset prefix up to the filename (default `./assets`) |
|
|
592
|
+
| `preserveAssetFilenames` | `boolean` | `false` | QTI → Learnosity only: opt out of deterministic hashed asset names and preserve the original final QTI basename; collisions remain errors |
|
|
593
|
+
| `truncateTags` | `boolean` | `false` | Truncate tag types and names to 255 characters instead of failing |
|
|
594
|
+
| `itemReferenceSource` | `"sourceFilename"` \| `"qti"` \| `"uuid"` | `"sourceFilename"` | How to generate item references (QTI → Learnosity only) |
|
|
595
|
+
| `itemFilenameSource` | `"sourceFilename"` \| `"qti"` | Same as `itemReferenceSource` | How to name output JSON files. Defaults to the resolved `itemReferenceSource` value if omitted |
|
|
543
596
|
|
|
544
597
|
### Config File Usage
|
|
545
598
|
|
|
@@ -106,9 +106,7 @@ The converter emits a **flat** activity object (no `data` wrapper):
|
|
|
106
106
|
{
|
|
107
107
|
"reference": "ACTIVITY_REFERENCE",
|
|
108
108
|
"rendering_type": "assess",
|
|
109
|
-
"items": [
|
|
110
|
-
{ "reference": "<item_reference>", "id": "<item_reference>" }
|
|
111
|
-
],
|
|
109
|
+
"items": [{ "reference": "<item_reference>", "id": "<item_reference>" }],
|
|
112
110
|
"config": {
|
|
113
111
|
"navigation": {
|
|
114
112
|
"show_intro": true,
|
|
@@ -237,12 +235,28 @@ Common feature types in `features[].data.type`:
|
|
|
237
235
|
|
|
238
236
|
## assets/ Folder
|
|
239
237
|
|
|
240
|
-
Contains binary media files referenced by items and activities.
|
|
238
|
+
Contains binary media files referenced by items and activities. Existing Learnosity/Data API bundles may use the legacy pattern:
|
|
241
239
|
|
|
242
240
|
```
|
|
243
241
|
<md5_hash>_<original_filename>
|
|
244
242
|
```
|
|
245
243
|
|
|
244
|
+
### QTI → Learnosity generated asset names
|
|
245
|
+
|
|
246
|
+
When QTI is converted to Learnosity JSON, local asset filenames use an item-scoped deterministic hash so that equal basenames from different QTI paths or items cannot overwrite one another on the CDN. The generated filename is:
|
|
247
|
+
|
|
248
|
+
```text
|
|
249
|
+
md5hex(JSON.stringify([finalItemReference, canonicalQtiAssetHref])) + sourceExtension
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
`canonicalQtiAssetHref` is the full package-relative QTI href after converting separators to `/`, removing leading `./`, resolving safe `.`/`..` segments, and removing query strings/fragments. Bare filenames such as `745852.gif` are resolved relative to the item XML directory; explicit paths such as `assets/image.png` remain package-root-relative for compatibility. The source extension is retained; the original basename and directories are represented by the hash input, not copied into the output filename.
|
|
253
|
+
|
|
254
|
+
For example, `images/intro/logo.png` and `images/outro/logo.png` produce different deterministic `.png` filenames even when they belong to the same item. Only assets referenced by converted item XML or resolved passage HTML are emitted; manifest-only `<file>` entries such as recording controls are ignored when no item content references them. When the same source asset is referenced by multiple items, each item receives a different deterministic filename containing a cloned copy of the same bytes. The same item reference and canonical href always produce the same filename on repeat conversion. `customAssetUrl` changes only the URL base; it does not change the hash, selected filename, or physical file below `assets/`.
|
|
255
|
+
|
|
256
|
+
The bundle writer stores the selected key relative to the `assets/` root and adds that prefix exactly once, so the invariant is `generated URL basename == bundle path relative to assets/`. This generated QTI→Learnosity naming contract is distinct from pre-existing Learnosity bundle/Data API files that use `<md5_hash>_<original_filename>`; those existing names are read as-is for Learnosity → QTI conversion and are not renamed by this option.
|
|
257
|
+
|
|
258
|
+
For compatibility with existing basename-based CDN uploads, QTI → Learnosity conversion accepts `preserveAssetFilenames: true` in the library API or `--preserve-asset-filenames` in the CLI. That opt-out uses the original final QTI basename in both the generated URL and the physical `assets/` path. It is not collision-safe: when two different asset identities request the same basename, conversion reports an error rather than overwriting either file. The default hashed mode should be used for new conversions.
|
|
259
|
+
|
|
246
260
|
### Asset Types
|
|
247
261
|
|
|
248
262
|
| Extension | Description |
|
|
@@ -258,14 +272,16 @@ Contains binary media files referenced by items and activities. File names follo
|
|
|
258
272
|
Assets are referenced in HTML content using local paths:
|
|
259
273
|
|
|
260
274
|
```html
|
|
261
|
-
<!-- Image -->
|
|
262
|
-
<img
|
|
275
|
+
<!-- Image: generated QTI → Learnosity asset filename -->
|
|
276
|
+
<img
|
|
277
|
+
src="/vendor/learnosity/itembank/assets/<md5hex(JSON.stringify([itemReference, canonicalQtiAssetHref]))>.png"
|
|
278
|
+
/>
|
|
263
279
|
|
|
264
280
|
<!-- Audio player -->
|
|
265
281
|
<span
|
|
266
282
|
class="learnosity-feature"
|
|
267
283
|
data-type="audioplayer"
|
|
268
|
-
data-src="/vendor/learnosity/itembank/assets
|
|
284
|
+
data-src="/vendor/learnosity/itembank/assets/<md5_hash>_m157700"
|
|
269
285
|
>
|
|
270
286
|
</span>
|
|
271
287
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@learnosity/lib-qti-converter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "QTI ↔ Learnosity JSON converter",
|
|
6
6
|
"license": "MIT",
|
|
@@ -73,18 +73,18 @@
|
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
76
|
-
"@types/node": "^26.
|
|
77
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
78
|
-
"@typescript-eslint/parser": "^8.
|
|
76
|
+
"@types/node": "^26.6.2",
|
|
77
|
+
"@typescript-eslint/eslint-plugin": "^8.70.0",
|
|
78
|
+
"@typescript-eslint/parser": "^8.70.0",
|
|
79
79
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
80
80
|
"@vitest/coverage-v8": "^4.1.11",
|
|
81
|
-
"eslint": "^10.
|
|
81
|
+
"eslint": "^10.11.0",
|
|
82
82
|
"glob": "^13.0.6",
|
|
83
83
|
"publint": "^0.3.24",
|
|
84
|
-
"tsdown": "^0.
|
|
85
|
-
"tsx": "^4.23.
|
|
84
|
+
"tsdown": "^0.23.0",
|
|
85
|
+
"tsx": "^4.23.15",
|
|
86
86
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
87
|
-
"vite": "^8.
|
|
87
|
+
"vite": "^8.3.0",
|
|
88
88
|
"vitest": "^4.1.11"
|
|
89
89
|
},
|
|
90
90
|
"engines": {
|