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.
- package/dist/aicc.js +10 -6
- package/dist/aicc.js.map +1 -1
- package/dist/aicc.min.js +1 -1
- package/dist/aicc.min.js.map +1 -1
- package/dist/esm/aicc.js +10 -6
- package/dist/esm/aicc.js.map +1 -1
- package/dist/esm/aicc.min.js +1 -1
- package/dist/esm/aicc.min.js.map +1 -1
- package/dist/esm/scorm-again.js +10 -6
- 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 +10 -6
- 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 +10 -6
- 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 +10 -6
- 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 +10 -6
- 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 +10 -6
- package/dist/scorm2004.js.map +1 -1
- package/dist/scorm2004.min.js +1 -1
- package/dist/scorm2004.min.js.map +1 -1
- package/package.json +1 -1
- package/src/AICC.ts +2 -2
- package/src/BaseAPI.ts +1 -1
- package/src/Scorm12API.ts +3 -3
- package/src/Scorm2004API.ts +3 -3
- package/src/cmi/aicc/attempts.ts +7 -7
- package/src/cmi/aicc/cmi.ts +4 -4
- package/src/cmi/aicc/core.ts +1 -1
- package/src/cmi/aicc/evaluation.ts +1 -1
- package/src/cmi/aicc/student_data.ts +2 -2
- package/src/cmi/aicc/student_preferences.ts +2 -2
- package/src/cmi/aicc/tries.ts +7 -7
- package/src/cmi/scorm12/cmi.ts +1 -1
- package/src/cmi/scorm12/interactions.ts +1 -1
- package/src/cmi/scorm2004/adl.ts +2 -2
- package/src/cmi/scorm2004/cmi.ts +1 -1
- package/src/cmi/scorm2004/interactions.ts +1 -1
- package/src/cmi/scorm2004/objectives.ts +1 -1
- package/src/cmi/scorm2004/score.ts +1 -1
- package/src/constants/default_settings.ts +5 -1
- package/test/Scorm12API.spec.ts +101 -1
- package/tsconfig.json +1 -0
package/package.json
CHANGED
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 {
|
package/src/Scorm2004API.ts
CHANGED
|
@@ -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 {
|
package/src/cmi/aicc/attempts.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/cmi/aicc/cmi.ts
CHANGED
|
@@ -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;
|
package/src/cmi/aicc/core.ts
CHANGED
|
@@ -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;
|
package/src/cmi/aicc/tries.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/cmi/scorm12/cmi.ts
CHANGED
|
@@ -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();
|
package/src/cmi/scorm2004/adl.ts
CHANGED
|
@@ -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
|
}
|
package/src/cmi/scorm2004/cmi.ts
CHANGED
|
@@ -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();
|
|
@@ -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
|
|
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")
|
package/test/Scorm12API.spec.ts
CHANGED
|
@@ -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(),
|