@learnosity/lib-qti-converter 0.10.4

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.
@@ -0,0 +1,471 @@
1
+ # QTI ↔ Learnosity Converter - Getting Started
2
+
3
+ Quick guide to installing and using the QTI ↔ Learnosity Converter. You can use it as a **CLI tool** or as a **library** imported into your own Node.js/TypeScript project.
4
+
5
+ ## Prerequisites
6
+
7
+ - Node.js >= 22.0.0
8
+ - Python 3 (optional, only required if you want to validate QTI output using the included validation script)
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @learnosity/lib-qti-converter
14
+ ```
15
+
16
+ This single install gives you both the CLI tool (`lcon`) and the importable library. All dependencies are bundled — there's nothing else to install.
17
+
18
+ ### For Contributors (from source)
19
+
20
+ ```bash
21
+ git clone <repository-url>
22
+ cd lib-qti-converter
23
+ pnpm install
24
+ pnpm run build
25
+ ```
26
+
27
+ ## Quick Start — CLI
28
+
29
+ ### Convert a Single QTI Item to Learnosity
30
+
31
+ ```bash
32
+ npx lcon qti-to-learnosity \
33
+ --in path/to/item.xml \
34
+ --out path/to/output.json \
35
+ --pretty
36
+ ```
37
+
38
+ ### Convert a Learnosity Item to QTI
39
+
40
+ ```bash
41
+ npx lcon learnosity-to-qti \
42
+ --in path/to/item.json \
43
+ --out path/to/output.xml \
44
+ --qti-version 2.2
45
+ ```
46
+
47
+ ### Interactive Mode
48
+
49
+ If you prefer prompts for options:
50
+
51
+ ```bash
52
+ npx lcon qti-to-learnosity --interactive
53
+ # or
54
+ npx lcon -i
55
+ ```
56
+
57
+ Interactive mode will prompt you for:
58
+
59
+ - Input path
60
+ - Output path
61
+ - QTI version
62
+ - Output format
63
+ - Organisation ID (for Learnosity CDN asset URLs)
64
+ - Other options
65
+
66
+ ## Quick Start — Library
67
+
68
+ Import the converter directly into your Node.js or TypeScript project:
69
+
70
+ ```typescript
71
+ import { convertQtiToLearnosity, convertLearnosityToQti } from '@learnosity/lib-qti-converter';
72
+ ```
73
+
74
+ ### Convert QTI XML to Learnosity JSON
75
+
76
+ ```typescript
77
+ const qtiXml = '<assessmentItem ...>...</assessmentItem>';
78
+
79
+ const result = await convertQtiToLearnosity(qtiXml, {
80
+ qtiVersion: '2.2',
81
+ pretty: true,
82
+ });
83
+
84
+ console.log(result.output); // Converted Learnosity JSON (or undefined on failure)
85
+ console.log(result.diagnostics); // Array of Diagnostic objects
86
+ ```
87
+
88
+ ### Convert Learnosity JSON to QTI XML
89
+
90
+ ```typescript
91
+ const learnosityItem = {
92
+ reference: 'item-001',
93
+ content: '<span class="learnosity-response question-q-001"></span>',
94
+ definition: {
95
+ widgets: [{ reference: 'q-001', widget_type: 'response' }],
96
+ },
97
+ questions: [
98
+ {
99
+ reference: 'q-001',
100
+ data: {
101
+ type: 'mcq',
102
+ stimulus: '<p>Pick a color</p>',
103
+ options: [
104
+ { label: 'Red', value: '0' },
105
+ { label: 'Blue', value: '1' },
106
+ ],
107
+ },
108
+ },
109
+ ],
110
+ features: [],
111
+ };
112
+
113
+ const result = await convertLearnosityToQti(learnosityItem, {
114
+ qtiVersion: '2.2',
115
+ pretty: true,
116
+ });
117
+
118
+ console.log(result.output); // Converted QTI XML string
119
+ console.log(result.diagnostics); // Array of Diagnostic objects
120
+ ```
121
+
122
+ See [Examples](./EXAMPLES.md#library-usage) for more programmatic usage scenarios including package conversion and handling diagnostics.
123
+
124
+ ## CLI Options
125
+
126
+ ### `--interactive` / `-i`
127
+
128
+ Enable interactive mode with prompts for all options.
129
+
130
+ ```bash
131
+ lcon qti-to-learnosity --interactive
132
+ ```
133
+
134
+ ### `--verbose`
135
+
136
+ Show detailed output including INFO-level diagnostics (hidden by default).
137
+
138
+ ```bash
139
+ lcon qti-to-learnosity --in item.xml --out item.json --verbose
140
+ ```
141
+
142
+ ### `--organisation_id` / `--org_id`
143
+
144
+ Specify organisation ID for transforming asset URLs to Learnosity CDN format.
145
+
146
+ ```bash
147
+ lcon qti-to-learnosity --in item.xml --out item.json --organisation_id 12345
148
+ # or use shorter alias
149
+ lcon qti-to-learnosity --in item.xml --out item.json --org_id 12345
150
+ ```
151
+
152
+ When specified, asset URLs in QTI content like:
153
+
154
+ ```html
155
+ <img src="images/diagram.png" />
156
+ ```
157
+
158
+ Are transformed to Learnosity CDN format:
159
+
160
+ ```html
161
+ <img src="https://assets.learnosity.com/organisations/12345/images/diagram.png" />
162
+ ```
163
+
164
+ ### `--mediavault`
165
+
166
+ _Available for: `qti-to-learnosity`, `qti-package-to-learnosity`_
167
+
168
+ Use the `media-vault` subdomain instead of `assets` for Learnosity CDN URLs.
169
+
170
+ ```bash
171
+ lcon qti-to-learnosity --in item.xml --out item.json --organisation_id 12345 --mediavault
172
+ ```
173
+
174
+ This produces URLs like:
175
+
176
+ ```html
177
+ <img
178
+ src="https://media-vault.learnosity.com/organisations/12345/997a17a4-010b-4a95-9e70-1176f327d30b.png"
179
+ />
180
+ ```
181
+
182
+ ### `--custom-asset-url`
183
+
184
+ _Available for: `qti-to-learnosity`, `qti-package-to-learnosity`_
185
+
186
+ Specify a custom base URL for asset references instead of using the default Learnosity CDN.
187
+
188
+ ```bash
189
+ lcon qti-to-learnosity --in item.xml --out item.json --organisation_id 12345 --custom-asset-url "https://my-cdn.example.com/assets"
190
+ ```
191
+
192
+ This produces URLs with your custom prefix:
193
+
194
+ ```html
195
+ <img src="https://my-cdn.example.com/assets/997a17a4-010b-4a95-9e70-1176f327d30b.png" />
196
+ ```
197
+
198
+ **Note:** When `--custom-asset-url` is provided, it overrides both the default Learnosity CDN and the `--mediavault` flag.
199
+
200
+ ### `--item-reference-source`
201
+
202
+ _Available for: `qti-to-learnosity`, `qti-package-to-learnosity`_
203
+
204
+ Control how item references are generated. Options: `sourceFilename` (default) or `qti`.
205
+
206
+ **Default (`sourceFilename`)**: Uses the source filename without the .xml extension for human-readable references.
207
+
208
+ ```bash
209
+ lcon qti-to-learnosity --in Items/my-item.xml --out item.json
210
+ # Item reference will be: "my-item"
211
+ ```
212
+
213
+ **QTI mode (`--item-reference-source qti`)**: Uses the QTI identifier attribute from the XML (ignores the filename).
214
+
215
+ ```bash
216
+ lcon qti-to-learnosity --in Items/my-item.xml --out item.json --item-reference-source qti
217
+ # If the XML has identifier="item-001", item reference will be: "item-001"
218
+ ```
219
+
220
+ Use QTI mode when:
221
+
222
+ - You want item references to match the QTI identifier attribute in the XML
223
+ - The QTI identifiers are more meaningful than the filenames
224
+ - You're migrating from an older version of the converter
225
+
226
+ ### `--item-filename-source`
227
+
228
+ _Available for: `qti-package-to-learnosity`_
229
+
230
+ Control how output JSON files are named, independently from the item reference. Values: `sourceFilename` or `qti`.
231
+
232
+ **Default:** When omitted, output filenames match the item reference (i.e. whatever `--item-reference-source` produces). The option only has an effect when its value differs from `--item-reference-source`.
233
+
234
+ | Value | Behavior |
235
+ | ---------------- | -------------------------------------------------------------------------- |
236
+ | `sourceFilename` | Name output files after the source XML filename (without `.xml` extension) |
237
+ | `qti` | Name output files after the QTI `identifier` attribute from the XML |
238
+
239
+ This is useful when you want the `item.reference` inside the JSON to use one naming strategy, but the output filename on disk to use another.
240
+
241
+ **Example: QTI identifiers as references, source filenames as output files:**
242
+
243
+ ```bash
244
+ lcon qti-package-to-learnosity \
245
+ --in ./qti-package \
246
+ --out ./output \
247
+ --item-reference-source qti \
248
+ --item-filename-source sourceFilename
249
+ ```
250
+
251
+ If `items/3b34d853.xml` contains `identifier="MY_ITEM_001"`, the output will be:
252
+
253
+ - File: `items/3b34d853.json`
254
+ - Item reference inside JSON: `"MY_ITEM_001"`
255
+
256
+ **Example: Source filenames as references, QTI identifiers as output files:**
257
+
258
+ ```bash
259
+ lcon qti-package-to-learnosity \
260
+ --in ./qti-package \
261
+ --out ./output \
262
+ --item-reference-source sourceFilename \
263
+ --item-filename-source qti
264
+ ```
265
+
266
+ ### `--pretty`
267
+
268
+ Pretty-print JSON output with indentation.
269
+
270
+ ```bash
271
+ lcon qti-to-learnosity --in item.xml --out item.json --pretty
272
+ ```
273
+
274
+ ### `--quiet` / `-q`
275
+
276
+ Suppress non-essential output (banners, progress indicators).
277
+
278
+ ```bash
279
+ lcon qti-to-learnosity --in item.xml --out item.json --quiet
280
+ ```
281
+
282
+ ### `--include-learnosity-source`
283
+
284
+ _Available for: `learnosity-to-qti`, `learnosity-to-qti-package`_
285
+
286
+ Include the original Learnosity source files in the output. This is useful for round-trip conversions or debugging.
287
+
288
+ For `learnosity-to-qti`:
289
+
290
+ ```bash
291
+ lcon learnosity-to-qti \
292
+ --in item.json \
293
+ --out output.xml \
294
+ --include-learnosity-source
295
+ ```
296
+
297
+ This copies the input JSON file to a `source/` folder alongside the output XML file.
298
+
299
+ For `learnosity-to-qti-package`:
300
+
301
+ ```bash
302
+ lcon learnosity-to-qti-package \
303
+ --in bundle/ \
304
+ --out package.zip \
305
+ --include-learnosity-source
306
+ ```
307
+
308
+ This recursively copies the entire input bundle directory to a `source/` folder inside the output package.
309
+
310
+ ### `--recursive`
311
+
312
+ _Available for: `qti-package-to-learnosity`, `learnosity-to-qti-package`_
313
+
314
+ Process multiple packages in subdirectories with a single command. The output folder structure will mirror the input structure.
315
+
316
+ **Convert multiple QTI packages:**
317
+
318
+ ```bash
319
+ lcon qti-package-to-learnosity \
320
+ --in ./qti-packages \
321
+ --out ./learnosity-bundles \
322
+ --organisation_id 12345 \
323
+ --recursive
324
+ ```
325
+
326
+ **Convert multiple Learnosity bundles:**
327
+
328
+ ```bash
329
+ lcon learnosity-to-qti-package \
330
+ --in ./learnosity-bundles \
331
+ --out ./qti-packages \
332
+ --qti-version 2.2 \
333
+ --recursive
334
+ ```
335
+
336
+ **How it works:**
337
+
338
+ - Scans the input directory for immediate subdirectories (not nested)
339
+ - Auto-detects package type (QTI packages have `imsmanifest.xml`, Learnosity bundles have `manifest.json`)
340
+ - Converts each package independently
341
+ - Creates matching output folder structure
342
+ - Shows progress and summary report
343
+
344
+ **Limitations:**
345
+
346
+ - Only processes immediate subdirectories (depth = 1)
347
+ - Cannot be used with ZIP input (directory input only)
348
+ - Files in the root directory are ignored
349
+
350
+ See [Examples - Batch Processing](EXAMPLES.md#8-batch-processing-with-recursive-flag) for detailed examples.
351
+
352
+ ## Basic Workflow
353
+
354
+ ### 1. Prepare Your Input
355
+
356
+ **For QTI → Learnosity:**
357
+
358
+ - Single QTI XML file, or
359
+ - QTI Content Package (ZIP with imsmanifest.xml)
360
+
361
+ **For Learnosity → QTI:**
362
+
363
+ - Single Learnosity JSON item, or
364
+ - Learnosity bundle directory (from [Learnosity Data API](https://help.learnosity.com/hc/en-us/articles/26076363707421-Local-device-assessment-Endpoints-Data-API))
365
+
366
+ ### 2. Run Conversion
367
+
368
+ ```bash
369
+ # Single file conversion
370
+ lcon qti-to-learnosity --in input.xml --out output.json
371
+
372
+ # Package conversion
373
+ lcon qti-package-to-learnosity --in package.zip --out output.json
374
+ ```
375
+
376
+ **Note:** When converting QTI packages to Learnosity bundles, a `diagnostics` section is automatically added to the `manifest.json` file. This section includes:
377
+
378
+ - Converter version and timestamp
379
+ - All configuration options used (organisation ID, asset URL settings, item reference source)
380
+
381
+ See [Learnosity Bundle Format](LEARNOSITY_BUNDLE_FORMAT.md#diagnostics-section) for details.
382
+
383
+ ### 3. Review Diagnostics
384
+
385
+ Diagnostics are displayed after conversion:
386
+
387
+ ```
388
+ ┌─────────┬──────────────────┬─────────────────────────────┬──────┐
389
+ │ Level │ Code │ Message │ Path │
390
+ ├─────────┼──────────────────┼─────────────────────────────┼──────┤
391
+ │ INFO │ CONTENT_WRAPPED │ Content wrapped in <p> │ ... │
392
+ └─────────┴──────────────────┴─────────────────────────────┴──────┘
393
+ ```
394
+
395
+ - **INFO**: Informational, conversion succeeded
396
+ - **WARNING**: Potential issues, review recommended
397
+ - **ERROR**: Conversion failed or produced invalid output
398
+
399
+ ## Configuration File (Optional)
400
+
401
+ Create `lrn-converter.config.json` in your working directory to set default options:
402
+
403
+ ```json
404
+ {
405
+ "qtiVersion": "2.2",
406
+ "outputFormat": "dir",
407
+ "diagnostics": "both",
408
+ "pretty": true,
409
+ "verbose": false,
410
+ "output": "./output",
411
+ "organisationId": 12345,
412
+ "mediaVault": false,
413
+ "customAssetUrl": "https://my-cdn.example.com/assets",
414
+ "itemReferenceSource": "sourceFilename",
415
+ "itemFilenameSource": "qti"
416
+ }
417
+ ```
418
+
419
+ ### Available Config Options
420
+
421
+ All options are optional. CLI flags override config file values.
422
+
423
+ | Option | Type | Default | Description |
424
+ | --------------------- | ---------------------------------------------- | ----------------------------- | ---------------------------------------------------------------------------------------------- |
425
+ | `qtiVersion` | `"2.1"` \| `"2.2"` | `"2.2"` | QTI version to use for conversion |
426
+ | `outputFormat` | `"dir"` \| `"zip"` \| `"stdout"` | `"dir"` | Output format (auto-detected based on output path) |
427
+ | `diagnostics` | `"stderr"` \| `"file"` \| `"both"` \| `"none"` | `"file"` | Where to write diagnostic messages |
428
+ | `pretty` | `boolean` | `false` | Pretty-print JSON/XML output |
429
+ | `verbose` | `boolean` | `false` | Show detailed progress information |
430
+ | `output` | `string` | `"-"` | Default output directory for interactive mode |
431
+ | `organisationId` | `number` | - | Organisation ID for Learnosity CDN asset URLs |
432
+ | `mediaVault` | `boolean` | `false` | Use `media-vault` subdomain instead of `assets` for CDN URLs |
433
+ | `customAssetUrl` | `string` | - | Custom base URL for assets (overrides default Learnosity CDN) |
434
+ | `itemReferenceSource` | `"sourceFilename"` \| `"qti"` \| `"uuid"` | `"sourceFilename"` | How to generate item references (QTI → Learnosity only) |
435
+ | `itemFilenameSource` | `"sourceFilename"` \| `"qti"` | Same as `itemReferenceSource` | How to name output JSON files. Defaults to the resolved `itemReferenceSource` value if omitted |
436
+
437
+ ### Config File Usage
438
+
439
+ **Default location:**
440
+ The CLI automatically looks for `lrn-converter.config.json` in your current working directory.
441
+
442
+ **Custom config path:**
443
+
444
+ ```bash
445
+ lcon qti-to-learnosity --in input.xml --out output.json --config /path/to/custom-config.json
446
+ ```
447
+
448
+ **Disable config loading:**
449
+
450
+ ```bash
451
+ lcon qti-to-learnosity --in input.xml --out output.json --no-config
452
+ ```
453
+
454
+ **Precedence order:**
455
+
456
+ 1. CLI flags (highest priority)
457
+ 2. Config file
458
+ 3. Built-in defaults (lowest priority)
459
+
460
+ ## Next Steps
461
+
462
+ - See [Examples](https://learnosity.github.io/lib-qti-converter/#/EXAMPLES) for common conversion scenarios
463
+ - Check [FAQ](https://learnosity.github.io/lib-qti-converter/#/FAQ) for troubleshooting
464
+
465
+ ## Testing Your Setup
466
+
467
+ Run the test suite to verify everything works:
468
+
469
+ ```bash
470
+ pnpm test
471
+ ```