scorm-again 2.6.0 → 2.6.2
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 +172 -166
- 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 +173 -167
- 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 +194 -184
- 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 +171 -165
- 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 +65 -51
- 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 +195 -185
- 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 +170 -164
- 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 +64 -50
- 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/AICC.d.ts +13 -0
- package/dist/types/BaseAPI.d.ts +71 -0
- package/dist/types/Scorm12API.d.ts +39 -0
- package/dist/types/Scorm2004API.d.ts +52 -0
- package/dist/types/ScormAgain.d.ts +4 -0
- package/dist/types/cmi/aicc/attempts.d.ts +19 -0
- package/dist/types/cmi/aicc/cmi.d.ts +34 -0
- package/dist/types/cmi/aicc/core.d.ts +57 -0
- package/dist/types/cmi/aicc/evaluation.d.ts +33 -0
- package/dist/types/cmi/aicc/paths.d.ts +35 -0
- package/dist/types/cmi/aicc/student_data.d.ts +20 -0
- package/dist/types/cmi/aicc/student_demographics.d.ts +61 -0
- package/dist/types/cmi/aicc/student_preferences.d.ts +34 -0
- package/dist/types/cmi/aicc/tries.d.ts +23 -0
- package/dist/types/cmi/aicc/validation.d.ts +1 -0
- package/dist/types/cmi/common/array.d.ts +19 -0
- package/dist/types/cmi/common/base_cmi.d.ts +13 -0
- package/dist/types/cmi/common/score.d.ts +38 -0
- package/dist/types/cmi/common/validation.d.ts +3 -0
- package/dist/types/cmi/scorm12/cmi.d.ts +45 -0
- package/dist/types/cmi/scorm12/interactions.d.ts +64 -0
- package/dist/types/cmi/scorm12/nav.d.ts +11 -0
- package/dist/types/cmi/scorm12/objectives.d.ts +22 -0
- package/dist/types/cmi/scorm12/student_data.d.ts +22 -0
- package/dist/types/cmi/scorm12/student_preference.d.ts +26 -0
- package/dist/types/cmi/scorm12/validation.d.ts +2 -0
- package/dist/types/cmi/scorm2004/adl.d.ts +71 -0
- package/dist/types/cmi/scorm2004/cmi.d.ts +103 -0
- package/dist/types/cmi/scorm2004/comments.d.ts +27 -0
- package/dist/types/cmi/scorm2004/interactions.d.ts +68 -0
- package/dist/types/cmi/scorm2004/learner_preference.d.ts +26 -0
- package/dist/types/cmi/scorm2004/objectives.d.ts +38 -0
- package/dist/types/cmi/scorm2004/score.d.ts +14 -0
- package/dist/types/cmi/scorm2004/validation.d.ts +2 -0
- package/dist/types/constants/api_constants.d.ts +49 -0
- package/dist/types/constants/default_settings.d.ts +2 -0
- package/dist/types/constants/enums.d.ts +23 -0
- package/dist/types/constants/error_codes.d.ts +6 -0
- package/dist/types/constants/language_constants.d.ts +2 -0
- package/dist/types/constants/regex.d.ts +82 -0
- package/dist/types/constants/response_constants.d.ts +16 -0
- package/dist/types/exceptions/aicc_exceptions.d.ts +4 -0
- package/dist/types/exceptions/scorm12_exceptions.d.ts +4 -0
- package/dist/types/exceptions/scorm2004_exceptions.d.ts +4 -0
- package/dist/types/exceptions.d.ts +18 -0
- package/dist/types/helpers/scheduled_commit.d.ts +10 -0
- package/dist/types/interfaces/IBaseAPI.d.ts +22 -0
- package/dist/types/types/api_types.d.ts +73 -0
- package/dist/types/utilities.d.ts +19 -0
- package/dist_test.html +208 -0
- package/package.json +3 -2
- package/src/AICC.ts +3 -3
- package/src/BaseAPI.ts +32 -22
- package/src/Scorm12API.ts +4 -12
- package/src/Scorm2004API.ts +18 -23
- package/src/ScormAgain.ts +3 -7
- package/src/constants/default_settings.ts +2 -2
- package/src/types/api_types.ts +27 -2
- package/test/AICC.spec.ts +2 -2
- package/test/Scorm12API.spec.ts +26 -3
- package/test/Scorm2004API.spec.ts +20 -20
- package/tsconfig.json +19 -6
- package/webpack.config.js +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const LearnerResponses: Responses;
|
|
2
|
+
export declare const CorrectResponses: Responses;
|
|
3
|
+
export type ResponseType = {
|
|
4
|
+
format: string;
|
|
5
|
+
max: number;
|
|
6
|
+
delimiter: string;
|
|
7
|
+
unique: boolean;
|
|
8
|
+
duplicate?: boolean;
|
|
9
|
+
format2?: string;
|
|
10
|
+
delimiter2?: string;
|
|
11
|
+
limit?: number;
|
|
12
|
+
delimiter3?: string;
|
|
13
|
+
};
|
|
14
|
+
export type Responses = {
|
|
15
|
+
[key: string]: ResponseType;
|
|
16
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type APIError = {
|
|
2
|
+
errorCode: number;
|
|
3
|
+
errorMessage: string;
|
|
4
|
+
detailedMessage: string;
|
|
5
|
+
};
|
|
6
|
+
export declare class BaseScormValidationError extends Error {
|
|
7
|
+
constructor(errorCode: number);
|
|
8
|
+
private readonly _errorCode;
|
|
9
|
+
get errorCode(): number;
|
|
10
|
+
}
|
|
11
|
+
export declare class ValidationError extends BaseScormValidationError implements APIError {
|
|
12
|
+
constructor(errorCode: number, errorMessage: string, detailedMessage?: string);
|
|
13
|
+
private readonly _errorMessage;
|
|
14
|
+
private readonly _detailedMessage;
|
|
15
|
+
get errorMessage(): string;
|
|
16
|
+
get detailedMessage(): string;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import BaseAPI from "../BaseAPI";
|
|
2
|
+
export declare class ScheduledCommit {
|
|
3
|
+
private _API;
|
|
4
|
+
private _cancelled;
|
|
5
|
+
private readonly _timeout;
|
|
6
|
+
private readonly _callback;
|
|
7
|
+
constructor(API: BaseAPI, when: number, callback: string);
|
|
8
|
+
cancel(): void;
|
|
9
|
+
wrapper(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RefObject, ResultObject } from "../types/api_types";
|
|
2
|
+
import { BaseCMI } from "../cmi/common/base_cmi";
|
|
3
|
+
export interface IBaseAPI {
|
|
4
|
+
cmi: BaseCMI;
|
|
5
|
+
startingData?: RefObject;
|
|
6
|
+
initialize(callbackName: string, initializeMessage?: string, terminationMessage?: string): string;
|
|
7
|
+
lmsInitialize(): string;
|
|
8
|
+
lmsFinish(): string;
|
|
9
|
+
lmsGetValue(CMIElement: string): string;
|
|
10
|
+
lmsSetValue(CMIElement: string, value: any): string;
|
|
11
|
+
lmsCommit(): string;
|
|
12
|
+
lmsGetLastError(): string;
|
|
13
|
+
lmsGetErrorString(CMIErrorCode: string | number): string;
|
|
14
|
+
lmsGetDiagnostic(CMIErrorCode: string | number): string;
|
|
15
|
+
storeData(_calculateTotalTime: boolean): Promise<ResultObject>;
|
|
16
|
+
renderCommitCMI(_terminateCommit: boolean): RefObject | Array<any>;
|
|
17
|
+
getLmsErrorMessageDetails(_errorNumber: string | number, _detail?: boolean): string;
|
|
18
|
+
getCMIValue(_CMIElement: string): string;
|
|
19
|
+
setCMIValue(_CMIElement: string, _value: any): string;
|
|
20
|
+
validateCorrectResponse(_CMIElement: string, _value: any): void;
|
|
21
|
+
getChildElement(_CMIElement: string, _value: any, _foundFirstIndex: boolean): BaseCMI | null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { CompletionStatus, LogLevelEnum, SuccessStatus } from "../constants/enums";
|
|
2
|
+
export type Settings = {
|
|
3
|
+
autocommit?: boolean;
|
|
4
|
+
autocommitSeconds?: number;
|
|
5
|
+
asyncCommit?: boolean;
|
|
6
|
+
sendFullCommit?: boolean;
|
|
7
|
+
lmsCommitUrl?: boolean | string;
|
|
8
|
+
dataCommitFormat?: string;
|
|
9
|
+
commitRequestDataType?: string;
|
|
10
|
+
autoProgress?: boolean;
|
|
11
|
+
logLevel?: LogLevel;
|
|
12
|
+
selfReportSessionTime?: boolean;
|
|
13
|
+
alwaysSendTotalTime?: boolean;
|
|
14
|
+
strict_errors?: boolean;
|
|
15
|
+
xhrHeaders?: RefObject;
|
|
16
|
+
xhrWithCredentials?: boolean;
|
|
17
|
+
fetchMode?: "cors" | "no-cors" | "same-origin" | "navigate";
|
|
18
|
+
responseHandler?: (response: Response) => Promise<ResultObject>;
|
|
19
|
+
requestHandler?: (commitObject: any) => any;
|
|
20
|
+
onLogMessage?: (messageLevel: LogLevel, logMessage: string) => void;
|
|
21
|
+
mastery_override?: boolean;
|
|
22
|
+
renderCommonCommitFields?: boolean;
|
|
23
|
+
scoItemIds?: string[];
|
|
24
|
+
scoItemIdValidator?: false | ((scoItemId: string) => boolean);
|
|
25
|
+
globalObjectiveIds?: string[];
|
|
26
|
+
};
|
|
27
|
+
export type InternalSettings = {
|
|
28
|
+
autocommit: boolean;
|
|
29
|
+
autocommitSeconds: number;
|
|
30
|
+
asyncCommit: boolean;
|
|
31
|
+
sendFullCommit: boolean;
|
|
32
|
+
lmsCommitUrl: boolean | string;
|
|
33
|
+
dataCommitFormat: string;
|
|
34
|
+
commitRequestDataType: string;
|
|
35
|
+
autoProgress: boolean;
|
|
36
|
+
logLevel: LogLevel;
|
|
37
|
+
selfReportSessionTime: boolean;
|
|
38
|
+
renderCommonCommitFields?: boolean;
|
|
39
|
+
scoItemIds?: string[];
|
|
40
|
+
scoItemIdValidator?: false | ((scoItemId: string) => boolean);
|
|
41
|
+
globalObjectiveIds?: string[];
|
|
42
|
+
alwaysSendTotalTime: boolean;
|
|
43
|
+
strict_errors: boolean;
|
|
44
|
+
xhrHeaders: RefObject;
|
|
45
|
+
xhrWithCredentials: boolean;
|
|
46
|
+
mastery_override?: boolean;
|
|
47
|
+
fetchMode: "cors" | "no-cors" | "same-origin" | "navigate";
|
|
48
|
+
responseHandler: (response: Response) => Promise<ResultObject>;
|
|
49
|
+
requestHandler: (commitObject: any) => any;
|
|
50
|
+
onLogMessage: (messageLevel: LogLevel, logMessage: string) => void;
|
|
51
|
+
};
|
|
52
|
+
export type RefObject = {
|
|
53
|
+
[key: string]: any;
|
|
54
|
+
};
|
|
55
|
+
export type ResultObject = {
|
|
56
|
+
result: string;
|
|
57
|
+
errorCode: number;
|
|
58
|
+
navRequest?: string;
|
|
59
|
+
};
|
|
60
|
+
export type ScoreObject = {
|
|
61
|
+
raw?: number;
|
|
62
|
+
min?: number;
|
|
63
|
+
max?: number;
|
|
64
|
+
scaled?: number;
|
|
65
|
+
};
|
|
66
|
+
export type CommitObject = {
|
|
67
|
+
successStatus: SuccessStatus;
|
|
68
|
+
completionStatus: CompletionStatus;
|
|
69
|
+
totalTimeSeconds: number;
|
|
70
|
+
runtimeData: RefObject;
|
|
71
|
+
score?: ScoreObject;
|
|
72
|
+
};
|
|
73
|
+
export type LogLevel = 1 | 2 | 3 | 4 | 5 | "1" | "2" | "3" | "4" | "5" | "DEBUG" | "INFO" | "WARN" | "ERROR" | "NONE" | LogLevelEnum;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const SECONDS_PER_SECOND = 1;
|
|
2
|
+
export declare const SECONDS_PER_MINUTE = 60;
|
|
3
|
+
export declare const SECONDS_PER_HOUR: number;
|
|
4
|
+
export declare const SECONDS_PER_DAY: number;
|
|
5
|
+
type StringKeyMap = {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
export declare function getSecondsAsHHMMSS(totalSeconds: number | null): string;
|
|
9
|
+
export declare function getSecondsAsISODuration(seconds: number | null): string;
|
|
10
|
+
export declare function getTimeAsSeconds(timeString: string | number | boolean | null, timeRegex: RegExp | string): number;
|
|
11
|
+
export declare function getDurationAsSeconds(duration: string | null, durationRegex: RegExp | string): number;
|
|
12
|
+
export declare function addTwoDurations(first: string, second: string, durationRegex: RegExp | string): string;
|
|
13
|
+
export declare function addHHMMSSTimeStrings(first: string, second: string, timeRegex: RegExp | string): string;
|
|
14
|
+
export declare function flatten(data: StringKeyMap): object;
|
|
15
|
+
export declare function unflatten(data: StringKeyMap): object;
|
|
16
|
+
export declare function countDecimals(num: number): number;
|
|
17
|
+
export declare function formatMessage(functionName: string, message: string, CMIElement?: string): string;
|
|
18
|
+
export declare function stringMatches(str: string, tester: string): boolean;
|
|
19
|
+
export {};
|
package/dist_test.html
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>SCORM-Again Distribution Test</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: Arial, sans-serif;
|
|
10
|
+
margin: 20px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
h1 {
|
|
14
|
+
color: #333;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.test-container {
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-wrap: wrap;
|
|
20
|
+
gap: 20px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.test-frame {
|
|
24
|
+
border: 1px solid #ccc;
|
|
25
|
+
padding: 15px;
|
|
26
|
+
width: 300px;
|
|
27
|
+
margin-bottom: 20px;
|
|
28
|
+
border-radius: 5px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.test-frame h3 {
|
|
32
|
+
margin-top: 0;
|
|
33
|
+
border-bottom: 1px solid #eee;
|
|
34
|
+
padding-bottom: 10px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.success {
|
|
38
|
+
background-color: #d4edda;
|
|
39
|
+
color: #155724;
|
|
40
|
+
padding: 10px;
|
|
41
|
+
border-radius: 4px;
|
|
42
|
+
margin-top: 10px;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.error {
|
|
46
|
+
background-color: #f8d7da;
|
|
47
|
+
color: #721c24;
|
|
48
|
+
padding: 10px;
|
|
49
|
+
border-radius: 4px;
|
|
50
|
+
margin-top: 10px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.section {
|
|
54
|
+
margin-bottom: 30px;
|
|
55
|
+
}
|
|
56
|
+
</style>
|
|
57
|
+
</head>
|
|
58
|
+
<body>
|
|
59
|
+
<h1>SCORM-Again Distribution Test</h1>
|
|
60
|
+
|
|
61
|
+
<div class="section">
|
|
62
|
+
<h2>Regular JavaScript Files</h2>
|
|
63
|
+
<div class="test-container" id="regular-container"></div>
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
<div class="section">
|
|
67
|
+
<h2>ESM Module Files</h2>
|
|
68
|
+
<div class="test-container" id="esm-container"></div>
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<script>
|
|
72
|
+
const dists = [
|
|
73
|
+
{
|
|
74
|
+
file: 'aicc.js',
|
|
75
|
+
api: ['AICC']
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
file: 'aicc.min.js',
|
|
79
|
+
api: ['AICC']
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
file: 'scorm12.js',
|
|
83
|
+
api: ['Scorm12API']
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
file: 'scorm12.min.js',
|
|
87
|
+
api: ['Scorm12API']
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
file: 'scorm2004.js',
|
|
91
|
+
api: ['Scorm2004API']
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
file: 'scorm2004.min.js',
|
|
95
|
+
api: ['Scorm2004API']
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
file: 'scorm-again.js',
|
|
99
|
+
api: ['Scorm12API', 'Scorm2004API', 'AICC']
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
file: 'scorm-again.min.js',
|
|
103
|
+
api: ['Scorm12API', 'Scorm2004API', 'AICC']
|
|
104
|
+
}
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
// Create test frames for regular JS files
|
|
108
|
+
const regularContainer = document.getElementById('regular-container');
|
|
109
|
+
dists.forEach(dist => {
|
|
110
|
+
const frame = document.createElement('div');
|
|
111
|
+
frame.className = 'test-frame';
|
|
112
|
+
frame.innerHTML = `
|
|
113
|
+
<h3>${dist.file}</h3>
|
|
114
|
+
<div id="dist-${dist.file.replace(/\//g, '-').replace(/\./g, '-')}-result"></div>
|
|
115
|
+
`;
|
|
116
|
+
regularContainer.appendChild(frame);
|
|
117
|
+
|
|
118
|
+
// Create iframe to load the script
|
|
119
|
+
const iframe = document.createElement('iframe');
|
|
120
|
+
iframe.style.display = 'none';
|
|
121
|
+
document.body.appendChild(iframe);
|
|
122
|
+
|
|
123
|
+
// Create HTML content for the iframe with script
|
|
124
|
+
const html = `
|
|
125
|
+
<!DOCTYPE html>
|
|
126
|
+
<html>
|
|
127
|
+
<head>
|
|
128
|
+
<script src="dist/${dist.file}"><\/script>
|
|
129
|
+
<script>
|
|
130
|
+
try {
|
|
131
|
+
window.parent.postMessage({
|
|
132
|
+
file: "dist-${dist.file}",
|
|
133
|
+
success: !!(${dist.api.map(api => `window.${api}`).join(' || ')})
|
|
134
|
+
}, "*");
|
|
135
|
+
} catch (error) {
|
|
136
|
+
window.parent.postMessage({
|
|
137
|
+
file: "dist-${dist.file}",
|
|
138
|
+
success: false,
|
|
139
|
+
error: error.message
|
|
140
|
+
}, "*");
|
|
141
|
+
}
|
|
142
|
+
<\/script>
|
|
143
|
+
</head>
|
|
144
|
+
<body></body>
|
|
145
|
+
</html>
|
|
146
|
+
`;
|
|
147
|
+
|
|
148
|
+
iframe.srcdoc = html;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Create test frames for ESM module files
|
|
152
|
+
const esmContainer = document.getElementById('esm-container');
|
|
153
|
+
dists.forEach(dist => {
|
|
154
|
+
const frame = document.createElement('div');
|
|
155
|
+
frame.className = 'test-frame';
|
|
156
|
+
frame.innerHTML = `
|
|
157
|
+
<h3>${dist.file}</h3>
|
|
158
|
+
<div id="dist-esm-${dist.file.replace(/\//g, '-').replace(/\./g, '-')}-result"></div>
|
|
159
|
+
`;
|
|
160
|
+
esmContainer.appendChild(frame);
|
|
161
|
+
|
|
162
|
+
// Create iframe to load the module
|
|
163
|
+
const iframe = document.createElement('iframe');
|
|
164
|
+
iframe.style.display = 'none';
|
|
165
|
+
document.body.appendChild(iframe);
|
|
166
|
+
|
|
167
|
+
// Create HTML content for the iframe with module import
|
|
168
|
+
const html = `
|
|
169
|
+
<!DOCTYPE html>
|
|
170
|
+
<html>
|
|
171
|
+
<head>
|
|
172
|
+
<script type="module">
|
|
173
|
+
try {
|
|
174
|
+
const module = await import('/dist/esm/${dist.file}');
|
|
175
|
+
window.parent.postMessage({
|
|
176
|
+
file: "dist-esm-${dist.file}",
|
|
177
|
+
success: !!(${dist.api.map(api => `module.${api}`).join(' || ')})
|
|
178
|
+
}, "*");
|
|
179
|
+
} catch (error) {
|
|
180
|
+
window.parent.postMessage({
|
|
181
|
+
file: "dist-esm-${dist.file}",
|
|
182
|
+
success: false,
|
|
183
|
+
error: error.message
|
|
184
|
+
}, "*");
|
|
185
|
+
}
|
|
186
|
+
<\/script>
|
|
187
|
+
</head>
|
|
188
|
+
<body></body>
|
|
189
|
+
</html>
|
|
190
|
+
`;
|
|
191
|
+
|
|
192
|
+
iframe.srcdoc = html;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Listen for messages from iframes
|
|
196
|
+
window.addEventListener('message', (event) => {
|
|
197
|
+
const {file, success, error} = event.data;
|
|
198
|
+
const resultElement = document.getElementById(`${file.replace(/\//g, '-').replace(/\./g, '-')}-result`);
|
|
199
|
+
|
|
200
|
+
if (success) {
|
|
201
|
+
resultElement.innerHTML = `<div class="success">Successfully loaded</div>`;
|
|
202
|
+
} else {
|
|
203
|
+
resultElement.innerHTML = `<div class="error">Failed to load: ${error || 'Library objects not found'}</div>`;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
</script>
|
|
207
|
+
</body>
|
|
208
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scorm-again",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
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",
|
|
@@ -65,10 +65,11 @@
|
|
|
65
65
|
"webpack": "^5.97.1",
|
|
66
66
|
"webpack-cli": "^5.1.4"
|
|
67
67
|
},
|
|
68
|
+
"sideEffects": false,
|
|
68
69
|
"scripts": {
|
|
69
70
|
"test": "./node_modules/.bin/mocha --import=tsx --bdd --recursive --reporter list",
|
|
70
71
|
"test:coverage": "./node_modules/.bin/c8 ./node_modules/.bin/mocha --import=tsx --recursive --timeout=10000 --exit --reporter json --reporter-option output=test-results.json",
|
|
71
|
-
"compile": "./node_modules/.bin/webpack --bail --config webpack.config.js --mode production",
|
|
72
|
+
"compile": "./node_modules/.bin/webpack --bail --config webpack.config.js --mode production && tsc --emitDeclarationOnly --declaration --outDir dist/types",
|
|
72
73
|
"fix": "./node_modules/.bin/eslint ./src --fix",
|
|
73
74
|
"prettier": "./node_modules/.bin/prettier --write src/**/*.ts test/**/*.ts src/*.ts test/*.ts"
|
|
74
75
|
},
|
package/src/AICC.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Scorm12API } from "./Scorm12API";
|
|
2
2
|
import { CMI } from "./cmi/aicc/cmi";
|
|
3
3
|
|
|
4
4
|
import { BaseCMI } from "./cmi/common/base_cmi";
|
|
@@ -13,7 +13,7 @@ import { stringMatches } from "./utilities";
|
|
|
13
13
|
/**
|
|
14
14
|
* The AICC API class
|
|
15
15
|
*/
|
|
16
|
-
class AICCImpl extends
|
|
16
|
+
class AICCImpl extends Scorm12API {
|
|
17
17
|
/**
|
|
18
18
|
* Constructor to create AICC API object
|
|
19
19
|
* @param {Settings} settings
|
|
@@ -74,4 +74,4 @@ class AICCImpl extends Scorm12Impl {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
export { AICCImpl };
|
|
77
|
+
export { AICCImpl as AICC };
|
package/src/BaseAPI.ts
CHANGED
|
@@ -4,13 +4,7 @@ import { ErrorCode } from "./constants/error_codes";
|
|
|
4
4
|
import { global_constants } from "./constants/api_constants";
|
|
5
5
|
import { formatMessage, stringMatches, unflatten } from "./utilities";
|
|
6
6
|
import { BaseCMI } from "./cmi/common/base_cmi";
|
|
7
|
-
import {
|
|
8
|
-
CommitObject,
|
|
9
|
-
LogLevel,
|
|
10
|
-
RefObject,
|
|
11
|
-
ResultObject,
|
|
12
|
-
Settings,
|
|
13
|
-
} from "./types/api_types";
|
|
7
|
+
import { CommitObject, InternalSettings, LogLevel, RefObject, ResultObject, Settings } from "./types/api_types";
|
|
14
8
|
import { DefaultSettings } from "./constants/default_settings";
|
|
15
9
|
import { IBaseAPI } from "./interfaces/IBaseAPI";
|
|
16
10
|
import { ScheduledCommit } from "./helpers/scheduled_commit";
|
|
@@ -21,9 +15,9 @@ import { LogLevelEnum } from "./constants/enums";
|
|
|
21
15
|
* abstract, and never initialized on its own.
|
|
22
16
|
*/
|
|
23
17
|
export default abstract class BaseAPI implements IBaseAPI {
|
|
24
|
-
private _timeout?: ScheduledCommit;
|
|
18
|
+
private _timeout?: ScheduledCommit | undefined;
|
|
25
19
|
private readonly _error_codes: ErrorCode;
|
|
26
|
-
private _settings:
|
|
20
|
+
private _settings: InternalSettings = DefaultSettings;
|
|
27
21
|
|
|
28
22
|
/**
|
|
29
23
|
* Constructor for Base API class. Sets some shared API fields, as well as
|
|
@@ -42,14 +36,13 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
42
36
|
this._error_codes = error_codes;
|
|
43
37
|
|
|
44
38
|
if (settings) {
|
|
45
|
-
this.settings =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (this.apiLogLevel === undefined) {
|
|
51
|
-
this.apiLogLevel = LogLevelEnum.NONE;
|
|
39
|
+
this.settings = {
|
|
40
|
+
...DefaultSettings,
|
|
41
|
+
...settings,
|
|
42
|
+
} as InternalSettings;
|
|
52
43
|
}
|
|
44
|
+
this.apiLogLevel = this.settings.logLevel ?? LogLevelEnum.ERROR;
|
|
45
|
+
this.selfReportSessionTime = this.settings.selfReportSessionTime ?? false;
|
|
53
46
|
}
|
|
54
47
|
|
|
55
48
|
public abstract cmi: BaseCMI;
|
|
@@ -77,7 +70,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
77
70
|
this.currentState = global_constants.STATE_NOT_INITIALIZED;
|
|
78
71
|
this.lastErrorCode = "0";
|
|
79
72
|
this.listenerArray = [];
|
|
80
|
-
this.startingData =
|
|
73
|
+
this.startingData = {};
|
|
81
74
|
}
|
|
82
75
|
|
|
83
76
|
/**
|
|
@@ -215,7 +208,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
215
208
|
* Getter for _settings
|
|
216
209
|
* @return {Settings}
|
|
217
210
|
*/
|
|
218
|
-
get settings():
|
|
211
|
+
get settings(): InternalSettings {
|
|
219
212
|
return this._settings;
|
|
220
213
|
}
|
|
221
214
|
|
|
@@ -1048,6 +1041,15 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1048
1041
|
* @param {string} CMIElement
|
|
1049
1042
|
*/
|
|
1050
1043
|
loadFromJSON(json: RefObject, CMIElement: string = "") {
|
|
1044
|
+
if (
|
|
1045
|
+
(!CMIElement || CMIElement === "") &&
|
|
1046
|
+
!Object.hasOwnProperty.call(json, "cmi") &&
|
|
1047
|
+
!Object.hasOwnProperty.call(json, "adl")
|
|
1048
|
+
) {
|
|
1049
|
+
// providing a backward compatibility for the old v1 API
|
|
1050
|
+
CMIElement = "cmi";
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1051
1053
|
if (!this.isNotInitialized()) {
|
|
1052
1054
|
console.error(
|
|
1053
1055
|
"loadFromJSON can only be called before the call to lmsInitialize.",
|
|
@@ -1136,7 +1138,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1136
1138
|
const process = async (
|
|
1137
1139
|
url: string,
|
|
1138
1140
|
params: CommitObject | RefObject | Array<any>,
|
|
1139
|
-
settings:
|
|
1141
|
+
settings: InternalSettings,
|
|
1140
1142
|
): Promise<ResultObject> => {
|
|
1141
1143
|
try {
|
|
1142
1144
|
params = settings.requestHandler(params);
|
|
@@ -1255,7 +1257,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1255
1257
|
url: string,
|
|
1256
1258
|
params: RefObject | Array<any>,
|
|
1257
1259
|
): Promise<Response> {
|
|
1258
|
-
|
|
1260
|
+
let init = {
|
|
1259
1261
|
method: "POST",
|
|
1260
1262
|
mode: this.settings.fetchMode,
|
|
1261
1263
|
body: params instanceof Array ? params.join("&") : JSON.stringify(params),
|
|
@@ -1263,9 +1265,17 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1263
1265
|
...this.settings.xhrHeaders,
|
|
1264
1266
|
"Content-Type": this.settings.commitRequestDataType,
|
|
1265
1267
|
},
|
|
1266
|
-
credentials: this.settings.xhrWithCredentials ? "include" : undefined,
|
|
1267
1268
|
keepalive: true,
|
|
1268
|
-
}
|
|
1269
|
+
} as RequestInit;
|
|
1270
|
+
|
|
1271
|
+
if (this.settings.xhrWithCredentials) {
|
|
1272
|
+
init = {
|
|
1273
|
+
...init,
|
|
1274
|
+
credentials: "include",
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
return fetch(url, init);
|
|
1269
1279
|
}
|
|
1270
1280
|
|
|
1271
1281
|
/**
|
package/src/Scorm12API.ts
CHANGED
|
@@ -9,16 +9,10 @@ import { CMIObjectivesObject } from "./cmi/scorm12/objectives";
|
|
|
9
9
|
import {
|
|
10
10
|
CMIInteractionsCorrectResponsesObject,
|
|
11
11
|
CMIInteractionsObject,
|
|
12
|
-
CMIInteractionsObjectivesObject
|
|
12
|
+
CMIInteractionsObjectivesObject
|
|
13
13
|
} from "./cmi/scorm12/interactions";
|
|
14
14
|
import { NAV } from "./cmi/scorm12/nav";
|
|
15
|
-
import {
|
|
16
|
-
CommitObject,
|
|
17
|
-
RefObject,
|
|
18
|
-
ResultObject,
|
|
19
|
-
ScoreObject,
|
|
20
|
-
Settings,
|
|
21
|
-
} from "./types/api_types";
|
|
15
|
+
import { CommitObject, RefObject, ResultObject, ScoreObject, Settings } from "./types/api_types";
|
|
22
16
|
import { CompletionStatus, SuccessStatus } from "./constants/enums";
|
|
23
17
|
import BaseAPI from "./BaseAPI";
|
|
24
18
|
import { scorm12_regex } from "./constants/regex";
|
|
@@ -360,10 +354,8 @@ class Scorm12Impl extends BaseAPI {
|
|
|
360
354
|
}
|
|
361
355
|
|
|
362
356
|
const score = this.cmi.core.score;
|
|
363
|
-
|
|
357
|
+
const scoreObject: ScoreObject = {};
|
|
364
358
|
if (score) {
|
|
365
|
-
scoreObject = {};
|
|
366
|
-
|
|
367
359
|
if (!Number.isNaN(Number.parseFloat(score.raw))) {
|
|
368
360
|
scoreObject.raw = Number.parseFloat(score.raw);
|
|
369
361
|
}
|
|
@@ -444,4 +436,4 @@ class Scorm12Impl extends BaseAPI {
|
|
|
444
436
|
}
|
|
445
437
|
}
|
|
446
438
|
|
|
447
|
-
export { Scorm12Impl };
|
|
439
|
+
export { Scorm12Impl as Scorm12API };
|
package/src/Scorm2004API.ts
CHANGED
|
@@ -2,10 +2,7 @@ import BaseAPI from "./BaseAPI";
|
|
|
2
2
|
import { CMI } from "./cmi/scorm2004/cmi";
|
|
3
3
|
import * as Utilities from "./utilities";
|
|
4
4
|
import { stringMatches } from "./utilities";
|
|
5
|
-
import {
|
|
6
|
-
global_constants,
|
|
7
|
-
scorm2004_constants,
|
|
8
|
-
} from "./constants/api_constants";
|
|
5
|
+
import { global_constants, scorm2004_constants } from "./constants/api_constants";
|
|
9
6
|
import { scorm2004_errors } from "./constants/error_codes";
|
|
10
7
|
import { CorrectResponses, ResponseType } from "./constants/response_constants";
|
|
11
8
|
import ValidLanguages from "./constants/language_constants";
|
|
@@ -14,18 +11,12 @@ import { BaseCMI } from "./cmi/common/base_cmi";
|
|
|
14
11
|
import {
|
|
15
12
|
CMIInteractionsCorrectResponsesObject,
|
|
16
13
|
CMIInteractionsObject,
|
|
17
|
-
CMIInteractionsObjectivesObject
|
|
14
|
+
CMIInteractionsObjectivesObject
|
|
18
15
|
} from "./cmi/scorm2004/interactions";
|
|
19
16
|
import { CMICommentsObject } from "./cmi/scorm2004/comments";
|
|
20
17
|
import { CMIObjectivesObject } from "./cmi/scorm2004/objectives";
|
|
21
18
|
import { ADL, ADLDataObject } from "./cmi/scorm2004/adl";
|
|
22
|
-
import {
|
|
23
|
-
CommitObject,
|
|
24
|
-
RefObject,
|
|
25
|
-
ResultObject,
|
|
26
|
-
ScoreObject,
|
|
27
|
-
Settings,
|
|
28
|
-
} from "./types/api_types";
|
|
19
|
+
import { CommitObject, RefObject, ResultObject, ScoreObject, Settings } from "./types/api_types";
|
|
29
20
|
import { CompletionStatus, SuccessStatus } from "./constants/enums";
|
|
30
21
|
import { scorm2004_regex } from "./constants/regex";
|
|
31
22
|
|
|
@@ -168,13 +159,18 @@ class Scorm2004Impl extends BaseAPI {
|
|
|
168
159
|
"^adl\\.nav\\.request_valid\\.(choice|jump)\\.{target=\\S{0,}([a-zA-Z0-9-_]+)}$";
|
|
169
160
|
if (stringMatches(CMIElement, adlNavRequestRegex)) {
|
|
170
161
|
const matches = CMIElement.match(adlNavRequestRegex);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (
|
|
175
|
-
|
|
162
|
+
if (matches) {
|
|
163
|
+
const request = matches[1];
|
|
164
|
+
const target = matches[2].replace("{target=", "").replace("}", "");
|
|
165
|
+
if (request === "choice" || request === "jump") {
|
|
166
|
+
if (this.settings.scoItemIdValidator) {
|
|
167
|
+
return String(this.settings.scoItemIdValidator(target));
|
|
168
|
+
}
|
|
169
|
+
if (this.settings.scoItemIds) {
|
|
170
|
+
return String(this.settings.scoItemIds?.includes(target));
|
|
171
|
+
}
|
|
172
|
+
return String(request);
|
|
176
173
|
}
|
|
177
|
-
return String(this.settings.scoItemIds.includes(target));
|
|
178
174
|
}
|
|
179
175
|
}
|
|
180
176
|
return this.getValue("GetValue", true, CMIElement);
|
|
@@ -266,7 +262,8 @@ class Scorm2004Impl extends BaseAPI {
|
|
|
266
262
|
|
|
267
263
|
// Check if the objective ID matches a global objective
|
|
268
264
|
const is_global =
|
|
269
|
-
objective_id &&
|
|
265
|
+
objective_id &&
|
|
266
|
+
this.settings.globalObjectiveIds?.includes(objective_id);
|
|
270
267
|
|
|
271
268
|
if (is_global) {
|
|
272
269
|
// Locate or create an entry in _globalObjectives for the global objective
|
|
@@ -726,10 +723,8 @@ class Scorm2004Impl extends BaseAPI {
|
|
|
726
723
|
}
|
|
727
724
|
|
|
728
725
|
const score = this.cmi.score;
|
|
729
|
-
|
|
726
|
+
const scoreObject: ScoreObject = {};
|
|
730
727
|
if (score) {
|
|
731
|
-
scoreObject = {};
|
|
732
|
-
|
|
733
728
|
if (!Number.isNaN(Number.parseFloat(score.raw))) {
|
|
734
729
|
scoreObject.raw = Number.parseFloat(score.raw);
|
|
735
730
|
}
|
|
@@ -820,4 +815,4 @@ class Scorm2004Impl extends BaseAPI {
|
|
|
820
815
|
}
|
|
821
816
|
}
|
|
822
817
|
|
|
823
|
-
export { Scorm2004Impl };
|
|
818
|
+
export { Scorm2004Impl as Scorm2004API };
|