scorm-again 1.7.1 → 2.0.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.
Files changed (85) hide show
  1. package/.babelrc +18 -7
  2. package/.github/dependabot.yml +5 -0
  3. package/.github/workflows/main.yml +79 -0
  4. package/.jsdoc.json +4 -5
  5. package/.mocharc.json +8 -0
  6. package/.run/Mocha Unit Tests.run.xml +5 -2
  7. package/CONTRIBUTING.md +1 -1
  8. package/README.md +14 -1
  9. package/dist/aicc.js +3661 -7170
  10. package/dist/aicc.js.map +1 -1
  11. package/dist/aicc.min.js +2 -40
  12. package/dist/aicc.min.js.map +1 -0
  13. package/dist/scorm-again.js +5671 -10695
  14. package/dist/scorm-again.js.map +1 -1
  15. package/dist/scorm-again.min.js +2 -52
  16. package/dist/scorm-again.min.js.map +1 -0
  17. package/dist/scorm12.js +2871 -5433
  18. package/dist/scorm12.js.map +1 -1
  19. package/dist/scorm12.min.js +2 -34
  20. package/dist/scorm12.min.js.map +1 -0
  21. package/dist/scorm2004.js +3868 -6797
  22. package/dist/scorm2004.js.map +1 -1
  23. package/dist/scorm2004.min.js +2 -40
  24. package/dist/scorm2004.min.js.map +1 -0
  25. package/eslint.config.js +21 -0
  26. package/package.json +72 -34
  27. package/results.json +34254 -0
  28. package/src/{AICC.js → AICC.ts} +27 -21
  29. package/src/BaseAPI.ts +1449 -0
  30. package/src/Scorm12API.ts +360 -0
  31. package/src/{Scorm2004API.js → Scorm2004API.ts} +245 -163
  32. package/src/cmi/aicc_cmi.ts +1248 -0
  33. package/src/cmi/common.ts +411 -0
  34. package/src/cmi/scorm12_cmi.ts +1426 -0
  35. package/src/cmi/scorm2004_cmi.ts +1874 -0
  36. package/src/constants/api_constants.ts +318 -0
  37. package/src/constants/error_codes.ts +88 -0
  38. package/src/constants/language_constants.ts +394 -0
  39. package/src/constants/regex.ts +97 -0
  40. package/src/constants/{response_constants.js → response_constants.ts} +67 -62
  41. package/src/exceptions.ts +133 -0
  42. package/src/exports/aicc.js +1 -1
  43. package/src/exports/scorm-again.js +3 -3
  44. package/src/exports/scorm12.js +1 -1
  45. package/src/exports/scorm2004.js +1 -1
  46. package/src/{utilities.js → utilities.ts} +114 -74
  47. package/tea.yaml +6 -0
  48. package/test/{AICC.spec.js → AICC.spec.ts} +70 -72
  49. package/test/Scorm12API.spec.ts +580 -0
  50. package/test/Scorm2004API.spec.ts +812 -0
  51. package/test/api_helpers.ts +176 -0
  52. package/test/cmi/{aicc_cmi.spec.js → aicc_cmi.spec.ts} +193 -209
  53. package/test/cmi/{scorm12_cmi.spec.js → scorm12_cmi.spec.ts} +251 -269
  54. package/test/cmi/scorm2004_cmi.spec.ts +1031 -0
  55. package/test/cmi_helpers.ts +207 -0
  56. package/test/exceptions.spec.ts +79 -0
  57. package/test/field_values.ts +202 -0
  58. package/test/utilities.spec.ts +322 -0
  59. package/tsconfig.json +18 -0
  60. package/webpack.config.js +65 -0
  61. package/.circleci/config.yml +0 -99
  62. package/.codeclimate.yml +0 -7
  63. package/.eslintrc.js +0 -36
  64. package/src/.flowconfig +0 -11
  65. package/src/BaseAPI.js +0 -1275
  66. package/src/Scorm12API.js +0 -308
  67. package/src/cmi/aicc_cmi.js +0 -1141
  68. package/src/cmi/common.js +0 -328
  69. package/src/cmi/scorm12_cmi.js +0 -1312
  70. package/src/cmi/scorm2004_cmi.js +0 -1692
  71. package/src/constants/api_constants.js +0 -218
  72. package/src/constants/error_codes.js +0 -87
  73. package/src/constants/language_constants.js +0 -76
  74. package/src/constants/regex.js +0 -84
  75. package/src/exceptions.js +0 -104
  76. package/test/Scorm12API.spec.js +0 -528
  77. package/test/Scorm2004API.spec.js +0 -775
  78. package/test/abstract_classes.spec.js +0 -17
  79. package/test/api_helpers.js +0 -128
  80. package/test/cmi/scorm2004_cmi.spec.js +0 -1066
  81. package/test/cmi_helpers.js +0 -161
  82. package/test/exceptions.spec.js +0 -71
  83. package/test/field_values.js +0 -353
  84. package/test/utilities.spec.js +0 -339
  85. 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
- }