scorm-again 2.4.0 → 2.4.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.
Files changed (54) hide show
  1. package/dist/aicc.js +10 -6
  2. package/dist/aicc.js.map +1 -1
  3. package/dist/aicc.min.js +1 -1
  4. package/dist/aicc.min.js.map +1 -1
  5. package/dist/esm/aicc.js +10 -6
  6. package/dist/esm/aicc.js.map +1 -1
  7. package/dist/esm/aicc.min.js +1 -1
  8. package/dist/esm/aicc.min.js.map +1 -1
  9. package/dist/esm/scorm-again.js +10 -6
  10. package/dist/esm/scorm-again.js.map +1 -1
  11. package/dist/esm/scorm-again.min.js +1 -1
  12. package/dist/esm/scorm-again.min.js.map +1 -1
  13. package/dist/esm/scorm12.js +10 -6
  14. package/dist/esm/scorm12.js.map +1 -1
  15. package/dist/esm/scorm12.min.js +1 -1
  16. package/dist/esm/scorm12.min.js.map +1 -1
  17. package/dist/esm/scorm2004.js +10 -6
  18. package/dist/esm/scorm2004.js.map +1 -1
  19. package/dist/esm/scorm2004.min.js +1 -1
  20. package/dist/esm/scorm2004.min.js.map +1 -1
  21. package/dist/scorm-again.js +10 -6
  22. package/dist/scorm-again.js.map +1 -1
  23. package/dist/scorm-again.min.js +1 -1
  24. package/dist/scorm-again.min.js.map +1 -1
  25. package/dist/scorm12.js +10 -6
  26. package/dist/scorm12.js.map +1 -1
  27. package/dist/scorm12.min.js +1 -1
  28. package/dist/scorm12.min.js.map +1 -1
  29. package/dist/scorm2004.js +10 -6
  30. package/dist/scorm2004.js.map +1 -1
  31. package/dist/scorm2004.min.js +1 -1
  32. package/dist/scorm2004.min.js.map +1 -1
  33. package/package.json +1 -1
  34. package/src/AICC.ts +2 -2
  35. package/src/BaseAPI.ts +1 -1
  36. package/src/Scorm12API.ts +3 -3
  37. package/src/Scorm2004API.ts +3 -3
  38. package/src/cmi/aicc/attempts.ts +7 -7
  39. package/src/cmi/aicc/cmi.ts +4 -4
  40. package/src/cmi/aicc/core.ts +1 -1
  41. package/src/cmi/aicc/evaluation.ts +1 -1
  42. package/src/cmi/aicc/student_data.ts +2 -2
  43. package/src/cmi/aicc/student_preferences.ts +2 -2
  44. package/src/cmi/aicc/tries.ts +7 -7
  45. package/src/cmi/scorm12/cmi.ts +1 -1
  46. package/src/cmi/scorm12/interactions.ts +1 -1
  47. package/src/cmi/scorm2004/adl.ts +2 -2
  48. package/src/cmi/scorm2004/cmi.ts +1 -1
  49. package/src/cmi/scorm2004/interactions.ts +1 -1
  50. package/src/cmi/scorm2004/objectives.ts +1 -1
  51. package/src/cmi/scorm2004/score.ts +1 -1
  52. package/src/constants/default_settings.ts +5 -1
  53. package/test/Scorm12API.spec.ts +101 -1
  54. package/tsconfig.json +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scorm-again",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "A modern SCORM JavaScript run-time library for AICC, SCORM 1.2, and SCORM 2004",
5
5
  "main": "dist/scorm-again.js",
6
6
  "types": "index.d.ts",
package/src/AICC.ts CHANGED
@@ -33,7 +33,7 @@ class AICCImpl extends Scorm12Impl {
33
33
  * @param {boolean} foundFirstIndex
34
34
  * @return {BaseCMI | null}
35
35
  */
36
- getChildElement(
36
+ override getChildElement(
37
37
  CMIElement: string,
38
38
  value: any,
39
39
  foundFirstIndex: boolean,
@@ -64,7 +64,7 @@ class AICCImpl extends Scorm12Impl {
64
64
  *
65
65
  * @param {AICCImpl} newAPI
66
66
  */
67
- replaceWithAnotherScormAPI(newAPI: AICCImpl) {
67
+ override replaceWithAnotherScormAPI(newAPI: AICCImpl) {
68
68
  // Data Model
69
69
  this.cmi = newAPI.cmi;
70
70
  this.nav = newAPI.nav;
package/src/BaseAPI.ts CHANGED
@@ -1067,7 +1067,7 @@ export default abstract class BaseAPI implements IBaseAPI {
1067
1067
  * @param {RefObject} json
1068
1068
  * @param {string} CMIElement
1069
1069
  */
1070
- loadFromJSON(json: RefObject, CMIElement: string) {
1070
+ loadFromJSON(json: RefObject, CMIElement: string = "") {
1071
1071
  if (!this.isNotInitialized()) {
1072
1072
  console.error(
1073
1073
  "loadFromJSON can only be called before the call to lmsInitialize.",
package/src/Scorm12API.ts CHANGED
@@ -203,7 +203,7 @@ class Scorm12Impl extends BaseAPI {
203
203
  * @param {*} value
204
204
  * @return {string}
205
205
  */
206
- setCMIValue(CMIElement: string, value: any): string {
206
+ override setCMIValue(CMIElement: string, value: any): string {
207
207
  return this._commonSetCMIValue("LMSSetValue", false, CMIElement, value);
208
208
  }
209
209
 
@@ -213,7 +213,7 @@ class Scorm12Impl extends BaseAPI {
213
213
  * @param {string} CMIElement
214
214
  * @return {*}
215
215
  */
216
- getCMIValue(CMIElement: string): any {
216
+ override getCMIValue(CMIElement: string): any {
217
217
  return this._commonGetCMIValue("getCMIValue", false, CMIElement);
218
218
  }
219
219
 
@@ -272,7 +272,7 @@ class Scorm12Impl extends BaseAPI {
272
272
  * @param {boolean} detail
273
273
  * @return {string}
274
274
  */
275
- getLmsErrorMessageDetails(
275
+ override getLmsErrorMessageDetails(
276
276
  errorNumber: number | string,
277
277
  detail: boolean,
278
278
  ): string {
@@ -226,7 +226,7 @@ class Scorm2004Impl extends BaseAPI {
226
226
  * @param {any} value
227
227
  * @return {string}
228
228
  */
229
- setCMIValue(CMIElement: string, value: any): string {
229
+ override setCMIValue(CMIElement: string, value: any): string {
230
230
  return this._commonSetCMIValue("SetValue", true, CMIElement, value);
231
231
  }
232
232
 
@@ -411,7 +411,7 @@ class Scorm2004Impl extends BaseAPI {
411
411
  * @param {string} CMIElement
412
412
  * @return {*}
413
413
  */
414
- getCMIValue(CMIElement: string): any {
414
+ override getCMIValue(CMIElement: string): any {
415
415
  return this._commonGetCMIValue("GetValue", true, CMIElement);
416
416
  }
417
417
 
@@ -422,7 +422,7 @@ class Scorm2004Impl extends BaseAPI {
422
422
  * @param {boolean} detail
423
423
  * @return {string}
424
424
  */
425
- getLmsErrorMessageDetails(
425
+ override getLmsErrorMessageDetails(
426
426
  errorNumber: string | number,
427
427
  detail: boolean,
428
428
  ): string {
@@ -1,11 +1,11 @@
1
- import {BaseCMI} from "../common/base_cmi";
2
- import {CMIScore} from "../common/score";
1
+ import { BaseCMI } from "../common/base_cmi";
2
+ import { CMIScore } from "../common/score";
3
3
  import APIConstants from "../../constants/api_constants";
4
4
  import Regex from "../../constants/regex";
5
5
  import ErrorCodes from "../../constants/error_codes";
6
- import {AICCValidationError} from "../../exceptions";
7
- import {checkAICCValidFormat} from "./validation";
8
- import {CMIArray} from "../common/array";
6
+ import { AICCValidationError } from "../../exceptions";
7
+ import { checkAICCValidFormat } from "./validation";
8
+ import { CMIArray } from "../common/array";
9
9
 
10
10
  /**
11
11
  * Class for cmi.student_data.attempt_records array
@@ -45,7 +45,7 @@ export class CMIAttemptRecordsObject extends BaseCMI {
45
45
  /**
46
46
  * Called when the API has been initialized after the CMI has been created
47
47
  */
48
- initialize() {
48
+ override initialize() {
49
49
  super.initialize();
50
50
  this.score?.initialize();
51
51
  }
@@ -91,4 +91,4 @@ export class CMIAttemptRecordsObject extends BaseCMI {
91
91
  delete this.jsonString;
92
92
  return result;
93
93
  }
94
- }
94
+ }
@@ -29,8 +29,8 @@ export class CMI extends Scorm12CMI.CMI {
29
29
  this.paths = new CMIPaths();
30
30
  }
31
31
 
32
- public student_data: AICCCMIStudentData;
33
- public student_preference: AICCStudentPreferences;
32
+ public override student_data: AICCCMIStudentData;
33
+ public override student_preference: AICCStudentPreferences;
34
34
  public student_demographics: CMIStudentDemographics;
35
35
  public evaluation: CMIEvaluation;
36
36
  public paths: CMIPaths;
@@ -38,7 +38,7 @@ export class CMI extends Scorm12CMI.CMI {
38
38
  /**
39
39
  * Called when the API has been initialized after the CMI has been created
40
40
  */
41
- initialize() {
41
+ override initialize() {
42
42
  super.initialize();
43
43
  this.student_preference?.initialize();
44
44
  this.student_data?.initialize();
@@ -65,7 +65,7 @@ export class CMI extends Scorm12CMI.CMI {
65
65
  * }
66
66
  * }
67
67
  */
68
- toJSON(): {
68
+ override toJSON(): {
69
69
  suspend_data: string;
70
70
  launch_data: string;
71
71
  comments: string;
@@ -32,7 +32,7 @@ export class CMICore extends BaseCMI {
32
32
  /**
33
33
  * Called when the API has been initialized after the CMI has been created
34
34
  */
35
- initialize() {
35
+ override initialize() {
36
36
  super.initialize();
37
37
  this.score?.initialize();
38
38
  }
@@ -23,7 +23,7 @@ export class CMIEvaluation extends BaseCMI {
23
23
  /**
24
24
  * Called when the API has been initialized after the CMI has been created
25
25
  */
26
- initialize() {
26
+ override initialize() {
27
27
  super.initialize();
28
28
  this.comments?.initialize();
29
29
  }
@@ -24,7 +24,7 @@ export class AICCCMIStudentData extends CMIStudentData {
24
24
  /**
25
25
  * Called when the API has been initialized after the CMI has been created
26
26
  */
27
- initialize() {
27
+ override initialize() {
28
28
  super.initialize();
29
29
  this.tries?.initialize();
30
30
  this.attempt_records?.initialize();
@@ -65,7 +65,7 @@ export class AICCCMIStudentData extends CMIStudentData {
65
65
  * }
66
66
  * }
67
67
  */
68
- toJSON(): {
68
+ override toJSON(): {
69
69
  mastery_score: string;
70
70
  max_time_allowed: string;
71
71
  time_limit_action: string;
@@ -27,7 +27,7 @@ export class AICCStudentPreferences extends CMIStudentPreference {
27
27
  /**
28
28
  * Called when the API has been initialized after the CMI has been created
29
29
  */
30
- initialize() {
30
+ override initialize() {
31
31
  super.initialize();
32
32
  this.windows?.initialize();
33
33
  }
@@ -145,7 +145,7 @@ export class AICCStudentPreferences extends CMIStudentPreference {
145
145
  * }
146
146
  * }
147
147
  */
148
- toJSON(): {
148
+ override toJSON(): {
149
149
  audio: string;
150
150
  language: string;
151
151
  lesson_type: string;
@@ -1,11 +1,11 @@
1
- import {CMIArray} from "../common/array";
1
+ import { CMIArray } from "../common/array";
2
2
  import APIConstants from "../../constants/api_constants";
3
- import {BaseCMI} from "../common/base_cmi";
4
- import {CMIScore} from "../common/score";
3
+ import { BaseCMI } from "../common/base_cmi";
4
+ import { CMIScore } from "../common/score";
5
5
  import Regex from "../../constants/regex";
6
6
  import ErrorCodes from "../../constants/error_codes";
7
- import {AICCValidationError} from "../../exceptions";
8
- import {checkAICCValidFormat} from "./validation";
7
+ import { AICCValidationError } from "../../exceptions";
8
+ import { checkAICCValidFormat } from "./validation";
9
9
 
10
10
  /**
11
11
  * Class representing the AICC cmi.student_data.tries object
@@ -45,7 +45,7 @@ export class CMITriesObject extends BaseCMI {
45
45
  /**
46
46
  * Called when the API has been initialized after the CMI has been created
47
47
  */
48
- initialize() {
48
+ override initialize() {
49
49
  super.initialize();
50
50
  this.score?.initialize();
51
51
  }
@@ -113,4 +113,4 @@ export class CMITriesObject extends BaseCMI {
113
113
  delete this.jsonString;
114
114
  return result;
115
115
  }
116
- }
116
+ }
@@ -52,7 +52,7 @@ export class CMI extends BaseRootCMI {
52
52
  /**
53
53
  * Called when the API has been initialized after the CMI has been created
54
54
  */
55
- initialize() {
55
+ override initialize() {
56
56
  super.initialize();
57
57
  this.core?.initialize();
58
58
  this.objectives?.initialize();
@@ -51,7 +51,7 @@ export class CMIInteractionsObject extends BaseCMI {
51
51
  /**
52
52
  * Called when the API has been initialized after the CMI has been created
53
53
  */
54
- initialize() {
54
+ override initialize() {
55
55
  super.initialize();
56
56
  this.objectives?.initialize();
57
57
  this.correct_responses?.initialize();
@@ -22,7 +22,7 @@ export class ADL extends BaseCMI {
22
22
  /**
23
23
  * Called when the API has been initialized after the CMI has been created
24
24
  */
25
- initialize() {
25
+ override initialize() {
26
26
  super.initialize();
27
27
  this.nav?.initialize();
28
28
  }
@@ -67,7 +67,7 @@ export class ADLNav extends BaseCMI {
67
67
  /**
68
68
  * Called when the API has been initialized after the CMI has been created
69
69
  */
70
- initialize() {
70
+ override initialize() {
71
71
  super.initialize();
72
72
  this.request_valid?.initialize();
73
73
  }
@@ -61,7 +61,7 @@ export class CMI extends BaseRootCMI {
61
61
  /**
62
62
  * Called when the API has been initialized after the CMI has been created
63
63
  */
64
- initialize() {
64
+ override initialize() {
65
65
  super.initialize();
66
66
  this.learner_preference?.initialize();
67
67
  this.score?.initialize();
@@ -60,7 +60,7 @@ export class CMIInteractionsObject extends BaseCMI {
60
60
  /**
61
61
  * Called when the API has been initialized after the CMI has been created
62
62
  */
63
- initialize() {
63
+ override initialize() {
64
64
  super.initialize();
65
65
  this.objectives?.initialize();
66
66
  this.correct_responses?.initialize();
@@ -47,7 +47,7 @@ export class CMIObjectivesObject extends BaseCMI {
47
47
  /**
48
48
  * Called when the API has been initialized after the CMI has been created
49
49
  */
50
- initialize() {
50
+ override initialize() {
51
51
  super.initialize();
52
52
  this.score?.initialize();
53
53
  }
@@ -59,7 +59,7 @@ export class Scorm2004CMIScore extends CMIScore {
59
59
  * }
60
60
  * }
61
61
  */
62
- toJSON(): {
62
+ override toJSON(): {
63
63
  scaled: string;
64
64
  raw: string;
65
65
  min: string;
@@ -23,7 +23,11 @@ export const DefaultSettings: Settings = {
23
23
  fetchMode: "cors",
24
24
  responseHandler: async function (response: Response): Promise<ResultObject> {
25
25
  if (typeof response !== "undefined") {
26
- const httpResult = JSON.parse(await response.text());
26
+ const responseText = await response.text();
27
+ let httpResult = null;
28
+ if (responseText) {
29
+ httpResult = JSON.parse(responseText);
30
+ }
27
31
  if (
28
32
  httpResult === null ||
29
33
  !{}.hasOwnProperty.call(httpResult, "result")
@@ -20,7 +20,7 @@ const api = (settings?: Settings, startingData: RefObject = {}) => {
20
20
  };
21
21
  const apiInitialized = (settings?: Settings, startingData: RefObject = {}) => {
22
22
  const API = api(settings);
23
- API.loadFromJSON(startingData ? startingData : {}, "");
23
+ API.loadFromJSON(startingData ? startingData : {});
24
24
  API.lmsInitialize();
25
25
  return API;
26
26
  };
@@ -51,6 +51,106 @@ describe("SCORM 1.2 API Tests", () => {
51
51
  clock.restore();
52
52
  });
53
53
 
54
+ describe("loadFromJSON()", () => {
55
+ it("should load JSON data into the CMI object", () => {
56
+ const scorm12API = api();
57
+ const jsonData = {
58
+ cmi: {
59
+ core: {
60
+ student_id: "student_1",
61
+ student_name: "John Doe",
62
+ lesson_status: "incomplete",
63
+ },
64
+ },
65
+ };
66
+
67
+ scorm12API.loadFromJSON(jsonData);
68
+ scorm12API.lmsInitialize();
69
+
70
+ expect(scorm12API.cmi.core.student_id).toEqual("student_1");
71
+ expect(scorm12API.cmi.core.student_name).toEqual("John Doe");
72
+ expect(scorm12API.cmi.core.lesson_status).toEqual("incomplete");
73
+ });
74
+
75
+ it("should load nested JSON data into the CMI object", () => {
76
+ const scorm12API = api();
77
+ const jsonData = {
78
+ cmi: {
79
+ objectives: {
80
+ "0": {
81
+ id: "obj_1",
82
+ score: {
83
+ raw: "85",
84
+ min: "0",
85
+ max: "100",
86
+ },
87
+ },
88
+ },
89
+ },
90
+ };
91
+
92
+ scorm12API.loadFromJSON(jsonData);
93
+
94
+ expect(scorm12API.cmi.objectives.childArray[0].id).toEqual("obj_1");
95
+ expect(scorm12API.cmi.objectives.childArray[0].score.raw).toEqual("85");
96
+ expect(scorm12API.cmi.objectives.childArray[0].score.min).toEqual("0");
97
+ expect(scorm12API.cmi.objectives.childArray[0].score.max).toEqual("100");
98
+ });
99
+
100
+ it("should load nested cmi JSON data into the CMI object", () => {
101
+ const scorm12API = api();
102
+ const jsonData = {
103
+ objectives: {
104
+ "0": {
105
+ id: "obj_1",
106
+ score: {
107
+ raw: "85",
108
+ min: "0",
109
+ max: "100",
110
+ },
111
+ },
112
+ },
113
+ };
114
+
115
+ scorm12API.loadFromJSON(jsonData, "cmi");
116
+
117
+ expect(scorm12API.cmi.objectives.childArray[0].id).toEqual("obj_1");
118
+ expect(scorm12API.cmi.objectives.childArray[0].score.raw).toEqual("85");
119
+ expect(scorm12API.cmi.objectives.childArray[0].score.min).toEqual("0");
120
+ expect(scorm12API.cmi.objectives.childArray[0].score.max).toEqual("100");
121
+ });
122
+
123
+ it("should handle empty JSON data", () => {
124
+ const scorm12API = api();
125
+ const jsonData = {};
126
+
127
+ scorm12API.loadFromJSON(jsonData);
128
+
129
+ expect(scorm12API.cmi.core.student_id).toBeFalsy();
130
+ expect(scorm12API.cmi.core.student_name).toBeFalsy();
131
+ expect(scorm12API.cmi.core.lesson_status).toBe("not attempted");
132
+ });
133
+
134
+ it("should not load data if API is initialized", () => {
135
+ const scorm12API = apiInitialized();
136
+ const jsonData = {
137
+ cmi: {
138
+ core: {
139
+ student_id: "student_1",
140
+ student_name: "John Doe",
141
+ lesson_status: "incomplete",
142
+ },
143
+ },
144
+ };
145
+
146
+ scorm12API.loadFromJSON(jsonData);
147
+
148
+ expect(scorm12API.cmi.core.student_id).toBeFalsy();
149
+ expect(scorm12API.cmi.core.student_name).toBeFalsy();
150
+ expect(scorm12API.cmi.core.lesson_status).toBe("not attempted");
151
+ });
152
+ });
153
+
54
154
  describe("LMSSetValue()", () => {
55
155
  h.checkValidValues({
56
156
  api: apiInitialized(),
package/tsconfig.json CHANGED
@@ -2,6 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "sourceMap": true,
4
4
  "noImplicitAny": true,
5
+ "noImplicitOverride": true,
5
6
  "declaration": false,
6
7
  "module": "es2015",
7
8
  "moduleResolution": "Node",