scorm-again 3.0.5 → 3.1.1
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/README.md +77 -1
- package/dist/cross-frame-api.js +579 -320
- package/dist/cross-frame-api.js.map +1 -1
- package/dist/cross-frame-api.min.js +1 -1
- package/dist/cross-frame-api.min.js.map +1 -1
- package/dist/cross-frame-lms.js +226 -163
- package/dist/cross-frame-lms.js.map +1 -1
- package/dist/cross-frame-lms.min.js +1 -1
- package/dist/cross-frame-lms.min.js.map +1 -1
- package/dist/esm/cross-frame-api.js.map +1 -1
- package/dist/esm/scorm-again.js +391 -86
- package/dist/esm/scorm-again.js.map +1 -1
- package/dist/esm/scorm-again.min.js +1 -1
- package/dist/esm/scorm-again.min.js.map +1 -1
- package/dist/esm/scorm12.js +323 -76
- package/dist/esm/scorm12.js.map +1 -1
- package/dist/esm/scorm12.min.js +1 -1
- package/dist/esm/scorm12.min.js.map +1 -1
- package/dist/esm/scorm2004.js +373 -72
- package/dist/esm/scorm2004.js.map +1 -1
- package/dist/esm/scorm2004.min.js +1 -1
- package/dist/esm/scorm2004.min.js.map +1 -1
- package/dist/scorm-again.js +32522 -19996
- package/dist/scorm-again.js.map +1 -1
- package/dist/scorm-again.min.js +1 -1
- package/dist/scorm-again.min.js.map +1 -1
- package/dist/scorm12.js +9130 -5031
- package/dist/scorm12.js.map +1 -1
- package/dist/scorm12.min.js +1 -1
- package/dist/scorm12.min.js.map +1 -1
- package/dist/scorm2004.js +30040 -18419
- package/dist/scorm2004.js.map +1 -1
- package/dist/scorm2004.min.js +1 -1
- package/dist/scorm2004.min.js.map +1 -1
- package/dist/types/BaseAPI.d.ts +15 -5
- package/dist/types/Scorm12API.d.ts +2 -2
- package/dist/types/Scorm2004API.d.ts +3 -2
- package/dist/types/cmi/common/score.d.ts +2 -0
- package/dist/types/interfaces/services.d.ts +8 -4
- package/dist/types/services/AsynchronousHttpService.d.ts +3 -2
- package/dist/types/services/EventService.d.ts +2 -2
- package/dist/types/services/OfflineStorageService.d.ts +6 -1
- package/dist/types/services/SynchronousHttpService.d.ts +2 -2
- package/dist/types/services/ValidationService.d.ts +1 -1
- package/dist/types/types/api_types.d.ts +22 -2
- package/dist/types/utilities/index.d.ts +1 -0
- package/dist/types/utilities/url.d.ts +2 -0
- package/package.json +27 -27
package/README.md
CHANGED
|
@@ -378,6 +378,9 @@ The APIs include several settings to customize the functionality of each API:
|
|
|
378
378
|
| `commitRequestDataType` | 'application/json;charset=UTF-8' | string | This setting is provided in case your LMS expects a different content type or character set. |
|
|
379
379
|
| `renderCommonCommitFields` | false | true/false | Determines whether the API should render the common fields in the commit object. Common fields are `successStatus`, `completionStatus`, `totalTimeSeconds`, `score`, and `runtimeData`. The `runtimeData` field contains the render CMI object. This allows for easier processing on the LMS. |
|
|
380
380
|
| `autoCompleteLessonStatus` | false | true/false | Controls termination behaviour for SCOs that never set `cmi.core.lesson_status`. When false (default), the API leaves the status as `incomplete`; when true, it restores the legacy behaviour of auto-upgrading to `completed`. |
|
|
381
|
+
| `terminateCommitParam` | undefined | string | When set, the terminate-time commit's URL gets `?<name>=true` appended (or `&<name>=true` if `lmsCommitUrl` already has a query string), letting the server distinguish the final commit from heartbeat commits. Applies to normal terminate commits, sendBeacon terminate commits, and offline replays of a terminate commit. |
|
|
382
|
+
| `terminateCommitPayloadField` | undefined | string | When set, the terminate-time commit's payload gets `<name>: true` added (object formats) or `<name>=true` appended (`params` format). Independent of `terminateCommitParam`; either or both may be used. |
|
|
383
|
+
| `includeCommitSequence` | false | true/false | When enabled, every commit payload includes a `commitSequence` field with a monotonically increasing number assigned when the commit is captured. Offline-replayed commits keep their original sequence, so servers can reject stale, out-of-order commits. |
|
|
381
384
|
| `autoProgress` | false | true/false | In case Sequencing is being used, you can tell the API to automatically throw the `SequenceNext` event. |
|
|
382
385
|
| `logLevel` | 4 | number \| string \| LogLevelEnum<br><br>`1` => DEBUG<br>`2` => INFO<br>`3` => WARN<br>`4` => ERROR<br>`5` => NONE | By default, the APIs only log error messages. |
|
|
383
386
|
| `mastery_override` | false | true/false | (SCORM 1.2) Used to override a module's `cmi.core.lesson_status` so that a pass/fail is determined based on a mastery score and the user's raw score, rather than using whatever status is provided by the module. An example of this would be if a module is published using a `Complete/Incomplete` final status, but the LMS always wants to receive a `Passed/Failed` for quizzes, then we can use this setting to override the given final status. |
|
|
@@ -390,7 +393,7 @@ The APIs include several settings to customize the functionality of each API:
|
|
|
390
393
|
| `httpService` | null | IHttpService | Advanced: Inject custom HTTP service implementation. Overrides `useAsynchronousCommits`. |
|
|
391
394
|
| `xhrResponseHandler` | function | function(xhr) => ResultObject | Custom response handler for synchronous XMLHttpRequest responses. Called when `useAsynchronousCommits=false`. |
|
|
392
395
|
| `responseHandler` | function | async function(response) => Promise<ResultObject> | Custom response handler for async fetch Response objects. Called when `useAsynchronousCommits=true`. The APIs expect the result from the LMS to be in the following format (errorCode is optional): `{ "result": true, "errorCode": 0 }` |
|
|
393
|
-
| `requestHandler` | function | | A function to transform the commit object before sending it to `lmsCommitUrl`. By default it's the identity function (no transformation). |
|
|
396
|
+
| `requestHandler` | function | | A function to transform the commit object before sending it to `lmsCommitUrl`. Receives an optional second `CommitMetadata` argument (`{ isTerminateCommit, trigger, sequence }`); existing one-argument handlers keep working unchanged. By default it's the identity function (no transformation). |
|
|
394
397
|
| `onLogMessage` | function | | A function to be called whenever a message is logged. Defaults to console.{error,warn,info,debug,log} |
|
|
395
398
|
| `scoItemIds` | [] | string[] | A list of valid SCO IDs to be used for choice/jump sequence validation. If a `sequencing` configuration is provided with an activity tree, this list will be automatically populated with all activity IDs from the tree. |
|
|
396
399
|
| `scoItemIdValidator` | false | false / function | A function to be called during choice/jump sequence checks to determine if a SCO ID is valid. Could be used to call an API to check validity. |
|
|
@@ -433,6 +436,64 @@ var settings = {
|
|
|
433
436
|
};
|
|
434
437
|
```
|
|
435
438
|
|
|
439
|
+
The handler also receives an optional second argument describing the commit, so a single
|
|
440
|
+
handler can react to terminate-time commits or offline replays:
|
|
441
|
+
|
|
442
|
+
```javascript
|
|
443
|
+
var settings = {
|
|
444
|
+
requestHandler: function (commitObject, metadata) {
|
|
445
|
+
// metadata = { isTerminateCommit, trigger, sequence }
|
|
446
|
+
// trigger is "manual" | "autocommit" | "terminate" | "offline-replay"
|
|
447
|
+
if (metadata && metadata.isTerminateCommit) {
|
|
448
|
+
commitObject.final = true;
|
|
449
|
+
}
|
|
450
|
+
return commitObject;
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
## Commit Lifecycle Observability
|
|
456
|
+
|
|
457
|
+
Every commit sent through the API is tracked while it is in flight. This is aimed at LMS
|
|
458
|
+
player pages that need a reliable teardown sequence — for example, draining pending
|
|
459
|
+
autocommits before calling Terminate, then waiting for the final commit to resolve before
|
|
460
|
+
navigating away or logging the learner out.
|
|
461
|
+
|
|
462
|
+
```javascript
|
|
463
|
+
// Number of commits currently in flight. Always 0 with the default synchronous
|
|
464
|
+
// HTTP service, which blocks until the LMS responds.
|
|
465
|
+
api.pendingCommitCount;
|
|
466
|
+
|
|
467
|
+
// Resolves once all in-flight commits have settled. If timeoutMs elapses first,
|
|
468
|
+
// the promise resolves anyway (best-effort drain) — check pendingCommitCount
|
|
469
|
+
// afterward to detect that case.
|
|
470
|
+
await api.whenCommitsSettled({ timeoutMs: 4000 });
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
`CommitSuccess` and `CommitError` listeners receive a context object describing the commit.
|
|
474
|
+
These events are fired by the asynchronous HTTP service (`useAsynchronousCommits: true`);
|
|
475
|
+
the default synchronous service returns results directly to the SCO instead.
|
|
476
|
+
|
|
477
|
+
```javascript
|
|
478
|
+
api.on("CommitSuccess", function (context) {
|
|
479
|
+
// context = { url, trigger, isTerminateCommit, sequence }
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
api.on("CommitError", function (errorCode, context) {
|
|
483
|
+
// errorCode stays the first argument for backward compatibility
|
|
484
|
+
});
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
A typical teardown for a player using asynchronous commits:
|
|
488
|
+
|
|
489
|
+
```javascript
|
|
490
|
+
// Force the terminate commit through fetch so its result is observable
|
|
491
|
+
api.settings.asyncModeBeaconBehavior = "never";
|
|
492
|
+
await api.whenCommitsSettled({ timeoutMs: 1000 }); // drain heartbeat commits
|
|
493
|
+
api.Terminate(""); // fires the final commit
|
|
494
|
+
await api.whenCommitsSettled({ timeoutMs: 4000 }); // wait for it to resolve
|
|
495
|
+
```
|
|
496
|
+
|
|
436
497
|
### onLogMessage
|
|
437
498
|
|
|
438
499
|
The onLogMessage function is used to log messages. By default, it logs messages to the console.
|
|
@@ -815,6 +876,21 @@ When implementing scorm-again, consider these security best practices:
|
|
|
815
876
|
- Use HTTPS for all LMS communications to prevent data interception
|
|
816
877
|
- Review the `xhrHeaders` and `responseHandler` settings for potential security implications
|
|
817
878
|
|
|
879
|
+
### Network Access & Data Flow
|
|
880
|
+
|
|
881
|
+
Supply-chain scanners (e.g. Socket) flag scorm-again as having "network access" because it
|
|
882
|
+
references `fetch` and `XMLHttpRequest`. This is expected: committing learner tracking data to an
|
|
883
|
+
LMS is the library's core function. To be clear about what that access does and does not include:
|
|
884
|
+
|
|
885
|
+
- **No hardcoded endpoints.** scorm-again never contacts any server of its own. Data is only ever
|
|
886
|
+
sent to the URL you provide via the `lmsCommitUrl` setting.
|
|
887
|
+
- **Silent by default.** `lmsCommitUrl` defaults to `false`. With no commit URL configured, the
|
|
888
|
+
library makes no network requests at all.
|
|
889
|
+
- **You control the payload and headers.** Outgoing requests can be inspected and rewritten via
|
|
890
|
+
`requestHandler`, and `xhrHeaders` / `xhrWithCredentials` govern what is attached to them.
|
|
891
|
+
- **No telemetry or analytics.** The library does not phone home, collect usage data, or contact
|
|
892
|
+
any third party.
|
|
893
|
+
|
|
818
894
|
## Performance Considerations
|
|
819
895
|
|
|
820
896
|
For optimal performance:
|