scorm-again 2.1.0 → 2.2.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/README.md CHANGED
@@ -35,6 +35,7 @@ not supported by IE11, you will need to provide your own polyfill for this funct
35
35
  To begin with, you include either the `scorm-again.js` or `scorm-again.min.js` file on your launching page:
36
36
 
37
37
  ```html
38
+
38
39
  <script type="text/javascript" src="/dist/scorm-again.js"></script>
39
40
  ```
40
41
 
@@ -42,6 +43,7 @@ Or, if you would like to only pull in one API, you include either the `aicc.js`,
42
43
  their minified versions on your launching page:
43
44
 
44
45
  ```html
46
+
45
47
  <script type="text/javascript" src="/dist/scorm2004.js"></script>
46
48
  ```
47
49
 
@@ -60,7 +62,7 @@ yarn add scorm-again
60
62
  You would then initialize the APIs using the following JS statements:
61
63
 
62
64
  ```javascript
63
- import { AICC, Scorm12API, Scorm2004API } from 'scorm-again'; // you only do this if you're using the package manager
65
+ import {AICC, Scorm12API, Scorm2004API} from 'scorm-again'; // you only do this if you're using the package manager
64
66
 
65
67
  var settings = {};
66
68
 
@@ -75,33 +77,40 @@ window.API_1484_11 = new Scorm2004API(settings);
75
77
  ```
76
78
 
77
79
  ### A Note About API Discovery
78
- Before creating a ticket about your module not being able to communicate with the LMS, please make sure you've looked over my examples in the `gh-pages` branch, as well as reading the [SCORM API Discovery Algorithms](https://scorm.com/scorm-explained/technical-scorm/run-time/api-discovery-algorithms/) page. I get that some of this stuff can be hard to implement at first, but I can't give an example for every possible way this library can be loaded into your application. The main thing to remember is that it should always be attached to the `window` object, because that's where modules are supposed to look.
80
+
81
+ Before creating a ticket about your module not being able to communicate with the LMS, please make sure you've looked
82
+ over my examples in the `gh-pages` branch, as well as reading
83
+ the [SCORM API Discovery Algorithms](https://scorm.com/scorm-explained/technical-scorm/run-time/api-discovery-algorithms/)
84
+ page. I get that some of this stuff can be hard to implement at first, but I can't give an example for every possible
85
+ way this library can be loaded into your application. The main thing to remember is that it should always be attached to
86
+ the `window` object, because that's where modules are supposed to look.
79
87
 
80
88
  ### Available Settings
81
89
 
82
90
  The APIs include several settings to customize the functionality of each API:
83
91
 
84
- | Setting | Default | Values | Description |
85
- |-------------------------|:--------------------------------:|:--------------------------------------------------------------------------:|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
86
- | `autocommit` | false | true/false | Determines whether the API schedules an autocommit to the LMS after setting a value. |
87
- | `autocommitSeconds` | 60 | int | Number of seconds to wait before autocommiting. Timer is restarted if another value is set. |
88
- | `asyncCommit` | false | true/false | Determines whether the API should send the request to the `lmsCommitUrl` asynchronously. |
89
- | `sendFullCommit` | true | true/false | Determines whether the API sends the full CMI object as part of the commit, or of it only sends the fields that actually contains values. |
90
- | `lmsCommitUrl` | false | url | The URL endpoint of the LMS where data should be sent upon commit. If no value is provided, modules will run as usual, but all method calls will be logged to the console. |
91
- | `dataCommitFormat` | `json` | `json`, `flattened`, `params` | `json` will send a JSON object to the lmsCommitUrl in the format of <br>`{'cmi': {'core': {...}}`<br><br> `flattened` will send the data in the format <br>`{'cmi.core.exit': 'suspend', 'cmi.core.mode': 'normal'...}`<br><br> `params` will send the data as <br>`?cmi.core.exit=suspend&cmi.core.mode=normal...` |
92
- | `commitRequestDataType` | 'application/json;charset=UTF-8' | string | This setting is provided in case your LMS expects a different content type or character set. |
93
- | `autoProgress` | false | true/false | In case Sequencing is being used, you can tell the API to automatically throw the `SequenceNext` event. |
94
- | `logLevel` | 4 | int<br><br>1 => DEBUG<br>2 => INFO<br>3 => WARN<br>4 => ERROR<br>5 => NONE | By default, the APIs only log error messages. |
95
- | `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. |
96
- | `selfReportSessionTime` | false | true/false | Should the API override the default `session_time` reported by the module? Useful when modules don't properly report time. |
97
- | `alwaysSendTotalTime` | false | true/false | Should the API always send `total_time` when committing to the LMS |
98
- | `xhrWithCredentials` | false | true/false | Sets the withCredentials flag on the request to the LMS |
99
- | `xhrHeaders` | {} | Object | This allows setting of additional headers on the request to the LMS where the key should be the header name and the value is the value of the header you want to send |
100
- | `responseHandler` | function | | A function to properly tranform the response from the LMS to the correct format. The APIs expect the result from the LMS to be in the following format (errorCode is optional): `{ "result": true, "errorCode": 0 }` |
101
- | `requestHandler` | function | | A function to transform the commit object before sending it to `lmsCommitUrl`. By default it's the identity function (no transformation). |
102
- | `onLogMessage` | function | | A function to be called whenever a message is logged. Defaults to console.{error,warn,info,debug,log} |
103
- | `scoItemIds` | [] | string[] | A list of valid SCO IDs to be used for choice/jump sequence validation. |
104
- | `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. |
92
+ | Setting | Default | Values | Description |
93
+ |----------------------------|:--------------------------------:|:--------------------------------------------------------------------------:|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
94
+ | `autocommit` | false | true/false | Determines whether the API schedules an autocommit to the LMS after setting a value. |
95
+ | `autocommitSeconds` | 60 | int | Number of seconds to wait before autocommiting. Timer is restarted if another value is set. |
96
+ | `asyncCommit` | false | true/false | Determines whether the API should send the request to the `lmsCommitUrl` asynchronously. |
97
+ | `sendFullCommit` | true | true/false | Determines whether the API sends the full CMI object as part of the commit, or of it only sends the fields that actually contains values. |
98
+ | `lmsCommitUrl` | false | url | The URL endpoint of the LMS where data should be sent upon commit. If no value is provided, modules will run as usual, but all method calls will be logged to the console. |
99
+ | `dataCommitFormat` | `json` | `json`, `flattened`, `params` | `json` will send a JSON object to the lmsCommitUrl in the format of <br>`{'cmi': {'core': {...}}`<br><br> `flattened` will send the data in the format <br>`{'cmi.core.exit': 'suspend', 'cmi.core.mode': 'normal'...}`<br><br> `params` will send the data as <br>`?cmi.core.exit=suspend&cmi.core.mode=normal...` |
100
+ | `commitRequestDataType` | 'application/json;charset=UTF-8' | string | This setting is provided in case your LMS expects a different content type or character set. |
101
+ | `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. |
102
+ | `autoProgress` | false | true/false | In case Sequencing is being used, you can tell the API to automatically throw the `SequenceNext` event. |
103
+ | `logLevel` | 4 | int<br><br>1 => DEBUG<br>2 => INFO<br>3 => WARN<br>4 => ERROR<br>5 => NONE | By default, the APIs only log error messages. |
104
+ | `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. |
105
+ | `selfReportSessionTime` | false | true/false | Should the API override the default `session_time` reported by the module? Useful when modules don't properly report time. |
106
+ | `alwaysSendTotalTime` | false | true/false | Should the API always send `total_time` when committing to the LMS |
107
+ | `xhrWithCredentials` | false | true/false | Sets the withCredentials flag on the request to the LMS |
108
+ | `xhrHeaders` | {} | Object | This allows setting of additional headers on the request to the LMS where the key should be the header name and the value is the value of the header you want to send |
109
+ | `responseHandler` | function | | A function to properly tranform the response from the LMS to the correct format. The APIs expect the result from the LMS to be in the following format (errorCode is optional): `{ "result": true, "errorCode": 0 }` |
110
+ | `requestHandler` | function | | A function to transform the commit object before sending it to `lmsCommitUrl`. By default it's the identity function (no transformation). |
111
+ | `onLogMessage` | function | | A function to be called whenever a message is logged. Defaults to console.{error,warn,info,debug,log} |
112
+ | `scoItemIds` | [] | string[] | A list of valid SCO IDs to be used for choice/jump sequence validation. |
113
+ | `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. |
105
114
 
106
115
  ## Settings Function Examples
107
116
 
package/dist/aicc.js CHANGED
@@ -1044,6 +1044,7 @@ var DefaultSettings = {
1044
1044
  logLevel: api_constants.global.LOG_LEVEL_ERROR,
1045
1045
  selfReportSessionTime: false,
1046
1046
  alwaysSendTotalTime: false,
1047
+ renderCommonCommitFields: false,
1047
1048
  strict_errors: true,
1048
1049
  xhrHeaders: {},
1049
1050
  xhrWithCredentials: false,
@@ -3017,6 +3018,26 @@ var NAV = (function (_super) {
3017
3018
  }(BaseCMI));
3018
3019
 
3019
3020
 
3021
+ ;// ./src/constants/enums.ts
3022
+ var NAVBoolean;
3023
+ (function (NAVBoolean) {
3024
+ NAVBoolean["unknown"] = "unknown";
3025
+ NAVBoolean["true"] = "true";
3026
+ NAVBoolean["false"] = "false";
3027
+ })(NAVBoolean || (NAVBoolean = {}));
3028
+ var SuccessStatus;
3029
+ (function (SuccessStatus) {
3030
+ SuccessStatus["passed"] = "passed";
3031
+ SuccessStatus["failed"] = "failed";
3032
+ SuccessStatus["unknown"] = "unknown";
3033
+ })(SuccessStatus || (SuccessStatus = {}));
3034
+ var CompletionStatus;
3035
+ (function (CompletionStatus) {
3036
+ CompletionStatus["completed"] = "completed";
3037
+ CompletionStatus["incomplete"] = "incomplete";
3038
+ CompletionStatus["unknown"] = "unknown";
3039
+ })(CompletionStatus || (CompletionStatus = {}));
3040
+
3020
3041
  ;// ./src/Scorm12API.ts
3021
3042
 
3022
3043
 
@@ -3028,6 +3049,8 @@ var NAV = (function (_super) {
3028
3049
 
3029
3050
 
3030
3051
 
3052
+
3053
+
3031
3054
  var Scorm12API = (function (_super) {
3032
3055
  __extends(Scorm12API, _super);
3033
3056
  function Scorm12API(settings) {
@@ -3201,9 +3224,53 @@ var Scorm12API = (function (_super) {
3201
3224
  return cmiExport;
3202
3225
  }
3203
3226
  };
3227
+ Scorm12API.prototype.renderCommitObject = function (terminateCommit) {
3228
+ var cmiExport = this.renderCommitCMI(terminateCommit);
3229
+ var totalTimeHHMMSS = this.cmi.getCurrentTotalTime();
3230
+ var totalTimeSeconds = getTimeAsSeconds(totalTimeHHMMSS, regex.scorm12.CMITimespan);
3231
+ var lessonStatus = this.cmi.core.lesson_status;
3232
+ var completionStatus = CompletionStatus.unknown;
3233
+ var successStatus = SuccessStatus.unknown;
3234
+ if (lessonStatus) {
3235
+ completionStatus =
3236
+ lessonStatus === "completed" || lessonStatus === "passed"
3237
+ ? CompletionStatus.completed
3238
+ : CompletionStatus.incomplete;
3239
+ if (lessonStatus === "passed") {
3240
+ successStatus = SuccessStatus.passed;
3241
+ }
3242
+ else if (lessonStatus === "failed") {
3243
+ successStatus = SuccessStatus.failed;
3244
+ }
3245
+ }
3246
+ var score = this.cmi.core.score;
3247
+ var scoreObject = null;
3248
+ if (score) {
3249
+ scoreObject = {};
3250
+ if (!Number.isNaN(Number.parseFloat(score.raw))) {
3251
+ scoreObject.raw = Number.parseFloat(score.raw);
3252
+ }
3253
+ if (!Number.isNaN(Number.parseFloat(score.min))) {
3254
+ scoreObject.min = Number.parseFloat(score.min);
3255
+ }
3256
+ if (!Number.isNaN(Number.parseFloat(score.max))) {
3257
+ scoreObject.max = Number.parseFloat(score.max);
3258
+ }
3259
+ }
3260
+ var commitObject = {
3261
+ successStatus: successStatus,
3262
+ completionStatus: completionStatus,
3263
+ runtimeData: cmiExport,
3264
+ totalTimeSeconds: totalTimeSeconds,
3265
+ };
3266
+ if (scoreObject) {
3267
+ commitObject.score = scoreObject;
3268
+ }
3269
+ return commitObject;
3270
+ };
3204
3271
  Scorm12API.prototype.storeData = function (terminateCommit) {
3205
3272
  return __awaiter(this, void 0, void 0, function () {
3206
- var originalStatus, commitObject;
3273
+ var originalStatus, shouldTerminateCommit, commitObject;
3207
3274
  var _a, _b, _c;
3208
3275
  return __generator(this, function (_d) {
3209
3276
  switch (_d.label) {
@@ -3235,7 +3302,10 @@ var Scorm12API = (function (_super) {
3235
3302
  }
3236
3303
  }
3237
3304
  }
3238
- commitObject = this.renderCommitCMI(terminateCommit || this.settings.alwaysSendTotalTime);
3305
+ shouldTerminateCommit = terminateCommit || this.settings.alwaysSendTotalTime;
3306
+ commitObject = this.settings.renderCommonCommitFields
3307
+ ? this.renderCommitObject(shouldTerminateCommit)
3308
+ : this.renderCommitCMI(shouldTerminateCommit);
3239
3309
  if (this.apiLogLevel === api_constants.global.LOG_LEVEL_DEBUG) {
3240
3310
  console.debug("Commit (terminated: " + (terminateCommit ? "yes" : "no") + "): ");
3241
3311
  console.debug(commitObject);