scorm-again 1.7.1 → 2.1.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/.babelrc +18 -7
- package/.github/dependabot.yml +5 -0
- package/.github/workflows/main.yml +79 -0
- package/.github/workflows/stale.yml +14 -0
- package/.jsdoc.json +4 -5
- package/.mocharc.json +8 -0
- package/.run/{Mocha Unit Tests.run.xml → Mocha Unit Tests (watch).run.xml } +6 -3
- package/.run/Template Mocha.run.xml +17 -0
- package/CONTRIBUTING.md +1 -1
- package/README.md +183 -71
- package/dist/aicc.js +3822 -7030
- package/dist/aicc.js.map +1 -1
- package/dist/aicc.min.js +2 -40
- package/dist/aicc.min.js.map +1 -0
- package/dist/scorm-again.js +5965 -10498
- package/dist/scorm-again.js.map +1 -1
- package/dist/scorm-again.min.js +2 -52
- package/dist/scorm-again.min.js.map +1 -0
- package/dist/scorm12.js +3028 -5373
- package/dist/scorm12.js.map +1 -1
- package/dist/scorm12.min.js +2 -34
- package/dist/scorm12.min.js.map +1 -0
- package/dist/scorm2004.js +4054 -6693
- package/dist/scorm2004.js.map +1 -1
- package/dist/scorm2004.min.js +2 -40
- package/dist/scorm2004.min.js.map +1 -0
- package/eslint.config.js +21 -0
- package/package.json +76 -34
- package/results.json +34254 -0
- package/src/AICC.ts +72 -0
- package/src/BaseAPI.ts +1300 -0
- package/src/Scorm12API.ts +387 -0
- package/src/Scorm2004API.ts +688 -0
- package/src/cmi/aicc/attempts.ts +94 -0
- package/src/cmi/aicc/cmi.ts +100 -0
- package/src/cmi/aicc/core.ts +360 -0
- package/src/cmi/aicc/evaluation.ts +157 -0
- package/src/cmi/aicc/paths.ts +180 -0
- package/src/cmi/aicc/student_data.ts +86 -0
- package/src/cmi/aicc/student_demographics.ts +367 -0
- package/src/cmi/aicc/student_preferences.ts +176 -0
- package/src/cmi/aicc/tries.ts +116 -0
- package/src/cmi/aicc/validation.ts +25 -0
- package/src/cmi/common/array.ts +77 -0
- package/src/cmi/common/base_cmi.ts +46 -0
- package/src/cmi/common/score.ts +203 -0
- package/src/cmi/common/validation.ts +60 -0
- package/src/cmi/scorm12/cmi.ts +224 -0
- package/src/cmi/scorm12/interactions.ts +368 -0
- package/src/cmi/scorm12/nav.ts +54 -0
- package/src/cmi/scorm12/objectives.ts +112 -0
- package/src/cmi/scorm12/student_data.ts +130 -0
- package/src/cmi/scorm12/student_preference.ts +158 -0
- package/src/cmi/scorm12/validation.ts +48 -0
- package/src/cmi/scorm2004/adl.ts +272 -0
- package/src/cmi/scorm2004/cmi.ts +599 -0
- package/src/cmi/scorm2004/comments.ts +163 -0
- package/src/cmi/scorm2004/interactions.ts +466 -0
- package/src/cmi/scorm2004/learner_preference.ts +152 -0
- package/src/cmi/scorm2004/objectives.ts +212 -0
- package/src/cmi/scorm2004/score.ts +78 -0
- package/src/cmi/scorm2004/validation.ts +42 -0
- package/src/constants/api_constants.ts +318 -0
- package/src/constants/default_settings.ts +81 -0
- package/src/constants/enums.ts +5 -0
- package/src/constants/error_codes.ts +88 -0
- package/src/constants/language_constants.ts +394 -0
- package/src/constants/regex.ts +97 -0
- package/src/constants/{response_constants.js → response_constants.ts} +69 -62
- package/src/exceptions.ts +154 -0
- package/src/exports/aicc.js +1 -1
- package/src/exports/scorm-again.js +3 -3
- package/src/exports/scorm12.js +1 -1
- package/src/exports/scorm2004.js +1 -1
- package/src/helpers/scheduled_commit.ts +42 -0
- package/src/interfaces/IBaseAPI.ts +35 -0
- package/src/types/api_types.ts +32 -0
- package/src/utilities/debounce.ts +31 -0
- package/src/utilities.ts +338 -0
- package/tea.yaml +6 -0
- package/test/{AICC.spec.js → AICC.spec.ts} +79 -71
- package/test/Scorm12API.spec.ts +833 -0
- package/test/Scorm2004API.spec.ts +1298 -0
- package/test/api_helpers.ts +176 -0
- package/test/cmi/aicc_cmi.spec.ts +845 -0
- package/test/cmi/{scorm12_cmi.spec.js → scorm12_cmi.spec.ts} +253 -271
- package/test/cmi/scorm2004_cmi.spec.ts +1031 -0
- package/test/cmi_helpers.ts +207 -0
- package/test/exceptions.spec.ts +79 -0
- package/test/field_values.ts +202 -0
- package/test/types/api_types.spec.ts +126 -0
- package/test/utilities/debounce.spec.ts +56 -0
- package/test/utilities.spec.ts +322 -0
- package/tsconfig.json +18 -0
- package/webpack.config.js +65 -0
- package/.circleci/config.yml +0 -99
- package/.codeclimate.yml +0 -7
- package/.eslintrc.js +0 -36
- package/src/.flowconfig +0 -11
- package/src/AICC.js +0 -68
- package/src/BaseAPI.js +0 -1275
- package/src/Scorm12API.js +0 -308
- package/src/Scorm2004API.js +0 -572
- package/src/cmi/aicc_cmi.js +0 -1141
- package/src/cmi/common.js +0 -328
- package/src/cmi/scorm12_cmi.js +0 -1312
- package/src/cmi/scorm2004_cmi.js +0 -1692
- package/src/constants/api_constants.js +0 -218
- package/src/constants/error_codes.js +0 -87
- package/src/constants/language_constants.js +0 -76
- package/src/constants/regex.js +0 -84
- package/src/exceptions.js +0 -104
- package/src/utilities.js +0 -242
- package/test/Scorm12API.spec.js +0 -528
- package/test/Scorm2004API.spec.js +0 -775
- package/test/abstract_classes.spec.js +0 -17
- package/test/api_helpers.js +0 -128
- package/test/cmi/aicc_cmi.spec.js +0 -684
- package/test/cmi/scorm2004_cmi.spec.js +0 -1066
- package/test/cmi_helpers.js +0 -161
- package/test/exceptions.spec.js +0 -71
- package/test/field_values.js +0 -353
- package/test/utilities.spec.js +0 -339
- package/webpack.js +0 -78
package/src/Scorm12API.js
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import BaseAPI from './BaseAPI';
|
|
3
|
-
import {
|
|
4
|
-
CMI,
|
|
5
|
-
CMIInteractionsCorrectResponsesObject,
|
|
6
|
-
CMIInteractionsObject,
|
|
7
|
-
CMIInteractionsObjectivesObject,
|
|
8
|
-
CMIObjectivesObject, NAV,
|
|
9
|
-
} from './cmi/scorm12_cmi';
|
|
10
|
-
import * as Utilities from './utilities';
|
|
11
|
-
import APIConstants from './constants/api_constants';
|
|
12
|
-
import ErrorCodes from './constants/error_codes';
|
|
13
|
-
|
|
14
|
-
const scorm12_constants = APIConstants.scorm12;
|
|
15
|
-
const global_constants = APIConstants.global;
|
|
16
|
-
const scorm12_error_codes = ErrorCodes.scorm12;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* API class for SCORM 1.2
|
|
20
|
-
*/
|
|
21
|
-
export default class Scorm12API extends BaseAPI {
|
|
22
|
-
/**
|
|
23
|
-
* Constructor for SCORM 1.2 API
|
|
24
|
-
* @param {object} settings
|
|
25
|
-
*/
|
|
26
|
-
constructor(settings: {}) {
|
|
27
|
-
const finalSettings = {
|
|
28
|
-
...{
|
|
29
|
-
mastery_override: false,
|
|
30
|
-
}, ...settings,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
super(scorm12_error_codes, finalSettings);
|
|
34
|
-
|
|
35
|
-
this.cmi = new CMI();
|
|
36
|
-
this.nav = new NAV();
|
|
37
|
-
|
|
38
|
-
// Rename functions to match 1.2 Spec and expose to modules
|
|
39
|
-
this.LMSInitialize = this.lmsInitialize;
|
|
40
|
-
this.LMSFinish = this.lmsFinish;
|
|
41
|
-
this.LMSGetValue = this.lmsGetValue;
|
|
42
|
-
this.LMSSetValue = this.lmsSetValue;
|
|
43
|
-
this.LMSCommit = this.lmsCommit;
|
|
44
|
-
this.LMSGetLastError = this.lmsGetLastError;
|
|
45
|
-
this.LMSGetErrorString = this.lmsGetErrorString;
|
|
46
|
-
this.LMSGetDiagnostic = this.lmsGetDiagnostic;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* lmsInitialize function from SCORM 1.2 Spec
|
|
51
|
-
*
|
|
52
|
-
* @return {string} bool
|
|
53
|
-
*/
|
|
54
|
-
lmsInitialize() {
|
|
55
|
-
this.cmi.initialize();
|
|
56
|
-
return this.initialize('LMSInitialize', 'LMS was already initialized!',
|
|
57
|
-
'LMS is already finished!');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* LMSFinish function from SCORM 1.2 Spec
|
|
62
|
-
*
|
|
63
|
-
* @return {string} bool
|
|
64
|
-
*/
|
|
65
|
-
lmsFinish() {
|
|
66
|
-
const result = this.terminate('LMSFinish', true);
|
|
67
|
-
|
|
68
|
-
if (result === global_constants.SCORM_TRUE) {
|
|
69
|
-
if (this.nav.event !== '') {
|
|
70
|
-
if (this.nav.event === 'continue') {
|
|
71
|
-
this.processListeners('SequenceNext');
|
|
72
|
-
} else {
|
|
73
|
-
this.processListeners('SequencePrevious');
|
|
74
|
-
}
|
|
75
|
-
} else if (this.settings.autoProgress) {
|
|
76
|
-
this.processListeners('SequenceNext');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* LMSGetValue function from SCORM 1.2 Spec
|
|
85
|
-
*
|
|
86
|
-
* @param {string} CMIElement
|
|
87
|
-
* @return {string}
|
|
88
|
-
*/
|
|
89
|
-
lmsGetValue(CMIElement) {
|
|
90
|
-
return this.getValue('LMSGetValue', false, CMIElement);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* LMSSetValue function from SCORM 1.2 Spec
|
|
95
|
-
*
|
|
96
|
-
* @param {string} CMIElement
|
|
97
|
-
* @param {*} value
|
|
98
|
-
* @return {string}
|
|
99
|
-
*/
|
|
100
|
-
lmsSetValue(CMIElement, value) {
|
|
101
|
-
return this.setValue('LMSSetValue', 'LMSCommit', false, CMIElement, value);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* LMSCommit function from SCORM 1.2 Spec
|
|
106
|
-
*
|
|
107
|
-
* @return {string} bool
|
|
108
|
-
*/
|
|
109
|
-
lmsCommit() {
|
|
110
|
-
return this.commit('LMSCommit', false);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* LMSGetLastError function from SCORM 1.2 Spec
|
|
115
|
-
*
|
|
116
|
-
* @return {string}
|
|
117
|
-
*/
|
|
118
|
-
lmsGetLastError() {
|
|
119
|
-
return this.getLastError('LMSGetLastError');
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* LMSGetErrorString function from SCORM 1.2 Spec
|
|
124
|
-
*
|
|
125
|
-
* @param {string} CMIErrorCode
|
|
126
|
-
* @return {string}
|
|
127
|
-
*/
|
|
128
|
-
lmsGetErrorString(CMIErrorCode) {
|
|
129
|
-
return this.getErrorString('LMSGetErrorString', CMIErrorCode);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* LMSGetDiagnostic function from SCORM 1.2 Spec
|
|
134
|
-
*
|
|
135
|
-
* @param {string} CMIErrorCode
|
|
136
|
-
* @return {string}
|
|
137
|
-
*/
|
|
138
|
-
lmsGetDiagnostic(CMIErrorCode) {
|
|
139
|
-
return this.getDiagnostic('LMSGetDiagnostic', CMIErrorCode);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Sets a value on the CMI Object
|
|
144
|
-
*
|
|
145
|
-
* @param {string} CMIElement
|
|
146
|
-
* @param {*} value
|
|
147
|
-
* @return {string}
|
|
148
|
-
*/
|
|
149
|
-
setCMIValue(CMIElement, value) {
|
|
150
|
-
return this._commonSetCMIValue('LMSSetValue', false, CMIElement, value);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Gets a value from the CMI Object
|
|
155
|
-
*
|
|
156
|
-
* @param {string} CMIElement
|
|
157
|
-
* @return {*}
|
|
158
|
-
*/
|
|
159
|
-
getCMIValue(CMIElement) {
|
|
160
|
-
return this._commonGetCMIValue('getCMIValue', false, CMIElement);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Gets or builds a new child element to add to the array.
|
|
165
|
-
*
|
|
166
|
-
* @param {string} CMIElement
|
|
167
|
-
* @param {*} value
|
|
168
|
-
* @param {boolean} foundFirstIndex
|
|
169
|
-
* @return {object}
|
|
170
|
-
*/
|
|
171
|
-
getChildElement(CMIElement, value, foundFirstIndex) {
|
|
172
|
-
let newChild;
|
|
173
|
-
|
|
174
|
-
if (this.stringMatches(CMIElement, 'cmi\\.objectives\\.\\d+')) {
|
|
175
|
-
newChild = new CMIObjectivesObject();
|
|
176
|
-
} else if (foundFirstIndex && this.stringMatches(CMIElement,
|
|
177
|
-
'cmi\\.interactions\\.\\d+\\.correct_responses\\.\\d+')) {
|
|
178
|
-
newChild = new CMIInteractionsCorrectResponsesObject();
|
|
179
|
-
} else if (foundFirstIndex && this.stringMatches(CMIElement,
|
|
180
|
-
'cmi\\.interactions\\.\\d+\\.objectives\\.\\d+')) {
|
|
181
|
-
newChild = new CMIInteractionsObjectivesObject();
|
|
182
|
-
} else if (!foundFirstIndex &&
|
|
183
|
-
this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d+')) {
|
|
184
|
-
newChild = new CMIInteractionsObject();
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return newChild;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Validates Correct Response values
|
|
192
|
-
*
|
|
193
|
-
* @param {string} CMIElement
|
|
194
|
-
* @param {*} value
|
|
195
|
-
* @return {boolean}
|
|
196
|
-
*/
|
|
197
|
-
validateCorrectResponse(CMIElement, value) {
|
|
198
|
-
return true;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Returns the message that corresponds to errorNumber.
|
|
203
|
-
*
|
|
204
|
-
* @param {*} errorNumber
|
|
205
|
-
* @param {boolean} detail
|
|
206
|
-
* @return {string}
|
|
207
|
-
*/
|
|
208
|
-
getLmsErrorMessageDetails(errorNumber, detail) {
|
|
209
|
-
let basicMessage = 'No Error';
|
|
210
|
-
let detailMessage = 'No Error';
|
|
211
|
-
|
|
212
|
-
// Set error number to string since inconsistent from modules if string or number
|
|
213
|
-
errorNumber = String(errorNumber);
|
|
214
|
-
if (scorm12_constants.error_descriptions[errorNumber]) {
|
|
215
|
-
basicMessage = scorm12_constants.error_descriptions[errorNumber].basicMessage;
|
|
216
|
-
detailMessage = scorm12_constants.error_descriptions[errorNumber].detailMessage;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return detail ? detailMessage : basicMessage;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Replace the whole API with another
|
|
224
|
-
*
|
|
225
|
-
* @param {Scorm12API} newAPI
|
|
226
|
-
*/
|
|
227
|
-
replaceWithAnotherScormAPI(newAPI) {
|
|
228
|
-
// Data Model
|
|
229
|
-
this.cmi = newAPI.cmi;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Render the cmi object to the proper format for LMS commit
|
|
234
|
-
*
|
|
235
|
-
* @param {boolean} terminateCommit
|
|
236
|
-
* @return {object|Array}
|
|
237
|
-
*/
|
|
238
|
-
renderCommitCMI(terminateCommit: boolean) {
|
|
239
|
-
const cmiExport = this.renderCMIToJSONObject();
|
|
240
|
-
|
|
241
|
-
if (terminateCommit) {
|
|
242
|
-
cmiExport.cmi.core.total_time = this.cmi.getCurrentTotalTime();
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const result = [];
|
|
246
|
-
const flattened = Utilities.flatten(cmiExport);
|
|
247
|
-
switch (this.settings.dataCommitFormat) {
|
|
248
|
-
case 'flattened':
|
|
249
|
-
return Utilities.flatten(cmiExport);
|
|
250
|
-
case 'params':
|
|
251
|
-
for (const item in flattened) {
|
|
252
|
-
if ({}.hasOwnProperty.call(flattened, item)) {
|
|
253
|
-
result.push(`${item}=${flattened[item]}`);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return result;
|
|
257
|
-
case 'json':
|
|
258
|
-
default:
|
|
259
|
-
return cmiExport;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Attempts to store the data to the LMS
|
|
265
|
-
*
|
|
266
|
-
* @param {boolean} terminateCommit
|
|
267
|
-
* @return {string}
|
|
268
|
-
*/
|
|
269
|
-
storeData(terminateCommit: boolean) {
|
|
270
|
-
if (terminateCommit) {
|
|
271
|
-
const originalStatus = this.cmi.core.lesson_status;
|
|
272
|
-
if (originalStatus === 'not attempted') {
|
|
273
|
-
this.cmi.core.lesson_status = 'completed';
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
if (this.cmi.core.lesson_mode === 'normal') {
|
|
277
|
-
if (this.cmi.core.credit === 'credit') {
|
|
278
|
-
if (this.settings.mastery_override &&
|
|
279
|
-
this.cmi.student_data.mastery_score !== '' &&
|
|
280
|
-
this.cmi.core.score.raw !== '') {
|
|
281
|
-
if (parseFloat(this.cmi.core.score.raw) >= parseFloat(this.cmi.student_data.mastery_score)) {
|
|
282
|
-
this.cmi.core.lesson_status = 'passed';
|
|
283
|
-
} else {
|
|
284
|
-
this.cmi.core.lesson_status = 'failed';
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
} else if (this.cmi.core.lesson_mode === 'browse') {
|
|
289
|
-
if ((this.startingData?.cmi?.core?.lesson_status || '') === '' && originalStatus === 'not attempted') {
|
|
290
|
-
this.cmi.core.lesson_status = 'browsed';
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
const commitObject = this.renderCommitCMI(terminateCommit ||
|
|
296
|
-
this.settings.alwaysSendTotalTime);
|
|
297
|
-
|
|
298
|
-
if (this.apiLogLevel === global_constants.LOG_LEVEL_DEBUG) {
|
|
299
|
-
console.debug('Commit (terminated: ' + (terminateCommit ? 'yes' : 'no') + '): ');
|
|
300
|
-
console.debug(commitObject);
|
|
301
|
-
}
|
|
302
|
-
if (this.settings.lmsCommitUrl) {
|
|
303
|
-
return this.processHttpRequest(this.settings.lmsCommitUrl, commitObject, terminateCommit);
|
|
304
|
-
} else {
|
|
305
|
-
return global_constants.SCORM_TRUE;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|