scorm-again 2.4.1 → 2.6.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 (87) hide show
  1. package/README.md +23 -23
  2. package/dist/aicc.js +676 -493
  3. package/dist/aicc.js.map +1 -1
  4. package/dist/aicc.min.js +1 -1
  5. package/dist/aicc.min.js.map +1 -1
  6. package/dist/esm/aicc.js +692 -496
  7. package/dist/esm/aicc.js.map +1 -1
  8. package/dist/esm/aicc.min.js +1 -1
  9. package/dist/esm/aicc.min.js.map +1 -1
  10. package/dist/esm/scorm-again.js +1151 -743
  11. package/dist/esm/scorm-again.js.map +1 -1
  12. package/dist/esm/scorm-again.min.js +1 -1
  13. package/dist/esm/scorm-again.min.js.map +1 -1
  14. package/dist/esm/scorm12.js +534 -401
  15. package/dist/esm/scorm12.js.map +1 -1
  16. package/dist/esm/scorm12.min.js +1 -1
  17. package/dist/esm/scorm12.min.js.map +1 -1
  18. package/dist/esm/scorm2004.js +712 -465
  19. package/dist/esm/scorm2004.js.map +1 -1
  20. package/dist/esm/scorm2004.min.js +1 -1
  21. package/dist/esm/scorm2004.min.js.map +1 -1
  22. package/dist/scorm-again.js +1127 -731
  23. package/dist/scorm-again.js.map +1 -1
  24. package/dist/scorm-again.min.js +1 -1
  25. package/dist/scorm-again.min.js.map +1 -1
  26. package/dist/scorm12.js +521 -400
  27. package/dist/scorm12.js.map +1 -1
  28. package/dist/scorm12.min.js +1 -1
  29. package/dist/scorm12.min.js.map +1 -1
  30. package/dist/scorm2004.js +698 -464
  31. package/dist/scorm2004.js.map +1 -1
  32. package/dist/scorm2004.min.js +1 -1
  33. package/dist/scorm2004.min.js.map +1 -1
  34. package/package.json +15 -15
  35. package/src/AICC.ts +3 -0
  36. package/src/BaseAPI.ts +60 -95
  37. package/src/Scorm12API.ts +14 -14
  38. package/src/Scorm2004API.ts +107 -37
  39. package/src/cmi/aicc/attempts.ts +22 -12
  40. package/src/cmi/aicc/cmi.ts +2 -2
  41. package/src/cmi/aicc/core.ts +44 -26
  42. package/src/cmi/aicc/evaluation.ts +31 -12
  43. package/src/cmi/aicc/paths.ts +29 -15
  44. package/src/cmi/aicc/student_data.ts +14 -5
  45. package/src/cmi/aicc/student_demographics.ts +31 -24
  46. package/src/cmi/aicc/student_preferences.ts +11 -11
  47. package/src/cmi/aicc/tries.ts +24 -14
  48. package/src/cmi/aicc/validation.ts +3 -4
  49. package/src/cmi/common/array.ts +17 -5
  50. package/src/cmi/common/base_cmi.ts +3 -1
  51. package/src/cmi/common/score.ts +16 -13
  52. package/src/cmi/scorm12/cmi.ts +25 -10
  53. package/src/cmi/scorm12/interactions.ts +62 -28
  54. package/src/cmi/scorm12/nav.ts +13 -5
  55. package/src/cmi/scorm12/objectives.ts +28 -18
  56. package/src/cmi/scorm12/student_data.ts +15 -8
  57. package/src/cmi/scorm12/student_preference.ts +20 -13
  58. package/src/cmi/scorm12/validation.ts +7 -7
  59. package/src/cmi/scorm2004/adl.ts +141 -25
  60. package/src/cmi/scorm2004/cmi.ts +50 -55
  61. package/src/cmi/scorm2004/comments.ts +21 -20
  62. package/src/cmi/scorm2004/interactions.ts +73 -32
  63. package/src/cmi/scorm2004/learner_preference.ts +20 -13
  64. package/src/cmi/scorm2004/objectives.ts +41 -16
  65. package/src/cmi/scorm2004/score.ts +22 -11
  66. package/src/cmi/scorm2004/validation.ts +4 -4
  67. package/src/constants/api_constants.ts +8 -29
  68. package/src/constants/default_settings.ts +26 -12
  69. package/src/constants/enums.ts +9 -0
  70. package/src/constants/error_codes.ts +5 -12
  71. package/src/constants/regex.ts +5 -11
  72. package/src/constants/response_constants.ts +1 -2
  73. package/src/exceptions/aicc_exceptions.ts +29 -0
  74. package/src/exceptions/scorm12_exceptions.ts +29 -0
  75. package/src/exceptions/scorm2004_exceptions.ts +29 -0
  76. package/src/exceptions.ts +1 -86
  77. package/src/types/api_types.ts +29 -5
  78. package/test/AICC.spec.ts +114 -43
  79. package/test/Scorm12API.spec.ts +37 -39
  80. package/test/Scorm2004API.spec.ts +165 -80
  81. package/test/cmi/aicc_cmi.spec.ts +6 -9
  82. package/test/cmi/scorm12_cmi.spec.ts +8 -8
  83. package/test/cmi/scorm2004_cmi.spec.ts +8 -9
  84. package/test/exceptions.spec.ts +11 -9
  85. package/test/types/api_types.spec.ts +40 -47
  86. package/test/utilities.spec.ts +1 -4
  87. package/webpack.config.js +4 -0
@@ -3,11 +3,11 @@
3
3
  */
4
4
  import { BaseCMI } from "../common/base_cmi";
5
5
  import { CMIArray } from "../common/array";
6
- import ErrorCodes from "../../constants/error_codes";
7
- import { Scorm2004ValidationError } from "../../exceptions";
8
- import APIConstants from "../../constants/api_constants";
6
+ import { scorm2004_errors } from "../../constants/error_codes";
7
+ import { Scorm2004ValidationError } from "../../exceptions/scorm2004_exceptions";
8
+ import { scorm2004_constants } from "../../constants/api_constants";
9
9
  import { check2004ValidFormat } from "./validation";
10
- import Regex from "../../constants/regex";
10
+ import { scorm2004_regex } from "../../constants/regex";
11
11
  import { LearnerResponses } from "../../constants/response_constants";
12
12
 
13
13
  export class CMIInteractions extends CMIArray {
@@ -16,8 +16,8 @@ export class CMIInteractions extends CMIArray {
16
16
  */
17
17
  constructor() {
18
18
  super({
19
- children: APIConstants.scorm2004.interactions_children,
20
- errorCode: ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
19
+ children: scorm2004_constants.interactions_children,
20
+ errorCode: scorm2004_errors.READ_ONLY_ELEMENT,
21
21
  errorClass: Scorm2004ValidationError,
22
22
  });
23
23
  }
@@ -43,14 +43,14 @@ export class CMIInteractionsObject extends BaseCMI {
43
43
  constructor() {
44
44
  super();
45
45
  this.objectives = new CMIArray({
46
- errorCode: ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
46
+ errorCode: scorm2004_errors.READ_ONLY_ELEMENT,
47
47
  errorClass: Scorm2004ValidationError,
48
- children: APIConstants.scorm2004.objectives_children,
48
+ children: scorm2004_constants.objectives_children,
49
49
  });
50
50
  this.correct_responses = new CMIArray({
51
- errorCode: ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
51
+ errorCode: scorm2004_errors.READ_ONLY_ELEMENT,
52
52
  errorClass: Scorm2004ValidationError,
53
- children: APIConstants.scorm2004.correct_responses_children,
53
+ children: scorm2004_constants.correct_responses_children,
54
54
  });
55
55
  }
56
56
 
@@ -66,6 +66,31 @@ export class CMIInteractionsObject extends BaseCMI {
66
66
  this.correct_responses?.initialize();
67
67
  }
68
68
 
69
+ /**
70
+ * Called when the API has been reset
71
+ */
72
+ override reset() {
73
+ this._initialized = false;
74
+ this._id = "";
75
+ this._type = "";
76
+ this._timestamp = "";
77
+ this._weighting = "";
78
+ this._learner_response = "";
79
+ this._result = "";
80
+ this._latency = "";
81
+ this._description = "";
82
+ this.objectives = new CMIArray({
83
+ errorCode: scorm2004_errors.READ_ONLY_ELEMENT,
84
+ errorClass: Scorm2004ValidationError,
85
+ children: scorm2004_constants.objectives_children,
86
+ });
87
+ this.correct_responses = new CMIArray({
88
+ errorCode: scorm2004_errors.READ_ONLY_ELEMENT,
89
+ errorClass: Scorm2004ValidationError,
90
+ children: scorm2004_constants.correct_responses_children,
91
+ });
92
+ }
93
+
69
94
  /**
70
95
  * Getter for _id
71
96
  * @return {string}
@@ -79,7 +104,7 @@ export class CMIInteractionsObject extends BaseCMI {
79
104
  * @param {string} id
80
105
  */
81
106
  set id(id: string) {
82
- if (check2004ValidFormat(id, Regex.scorm2004.CMILongIdentifier)) {
107
+ if (check2004ValidFormat(id, scorm2004_regex.CMILongIdentifier)) {
83
108
  this._id = id;
84
109
  }
85
110
  }
@@ -99,10 +124,10 @@ export class CMIInteractionsObject extends BaseCMI {
99
124
  set type(type: string) {
100
125
  if (this.initialized && this._id === "") {
101
126
  throw new Scorm2004ValidationError(
102
- ErrorCodes.scorm2004.DEPENDENCY_NOT_ESTABLISHED,
127
+ scorm2004_errors.DEPENDENCY_NOT_ESTABLISHED,
103
128
  );
104
129
  } else {
105
- if (check2004ValidFormat(type, Regex.scorm2004.CMIType)) {
130
+ if (check2004ValidFormat(type, scorm2004_regex.CMIType)) {
106
131
  this._type = type;
107
132
  }
108
133
  }
@@ -123,10 +148,10 @@ export class CMIInteractionsObject extends BaseCMI {
123
148
  set timestamp(timestamp: string) {
124
149
  if (this.initialized && this._id === "") {
125
150
  throw new Scorm2004ValidationError(
126
- ErrorCodes.scorm2004.DEPENDENCY_NOT_ESTABLISHED,
151
+ scorm2004_errors.DEPENDENCY_NOT_ESTABLISHED,
127
152
  );
128
153
  } else {
129
- if (check2004ValidFormat(timestamp, Regex.scorm2004.CMITime)) {
154
+ if (check2004ValidFormat(timestamp, scorm2004_regex.CMITime)) {
130
155
  this._timestamp = timestamp;
131
156
  }
132
157
  }
@@ -147,10 +172,10 @@ export class CMIInteractionsObject extends BaseCMI {
147
172
  set weighting(weighting: string) {
148
173
  if (this.initialized && this._id === "") {
149
174
  throw new Scorm2004ValidationError(
150
- ErrorCodes.scorm2004.DEPENDENCY_NOT_ESTABLISHED,
175
+ scorm2004_errors.DEPENDENCY_NOT_ESTABLISHED,
151
176
  );
152
177
  } else {
153
- if (check2004ValidFormat(weighting, Regex.scorm2004.CMIDecimal)) {
178
+ if (check2004ValidFormat(weighting, scorm2004_regex.CMIDecimal)) {
154
179
  this._weighting = weighting;
155
180
  }
156
181
  }
@@ -172,7 +197,7 @@ export class CMIInteractionsObject extends BaseCMI {
172
197
  set learner_response(learner_response: string) {
173
198
  if (this.initialized && (this._type === "" || this._id === "")) {
174
199
  throw new Scorm2004ValidationError(
175
- ErrorCodes.scorm2004.DEPENDENCY_NOT_ESTABLISHED,
200
+ scorm2004_errors.DEPENDENCY_NOT_ESTABLISHED,
176
201
  );
177
202
  } else {
178
203
  let nodes = [];
@@ -195,7 +220,7 @@ export class CMIInteractionsObject extends BaseCMI {
195
220
  if (values.length === 2) {
196
221
  if (!values[0].match(formatRegex)) {
197
222
  throw new Scorm2004ValidationError(
198
- ErrorCodes.scorm2004.TYPE_MISMATCH,
223
+ scorm2004_errors.TYPE_MISMATCH,
199
224
  );
200
225
  } else {
201
226
  if (
@@ -203,26 +228,26 @@ export class CMIInteractionsObject extends BaseCMI {
203
228
  !values[1].match(new RegExp(response_type.format2))
204
229
  ) {
205
230
  throw new Scorm2004ValidationError(
206
- ErrorCodes.scorm2004.TYPE_MISMATCH,
231
+ scorm2004_errors.TYPE_MISMATCH,
207
232
  );
208
233
  }
209
234
  }
210
235
  } else {
211
236
  throw new Scorm2004ValidationError(
212
- ErrorCodes.scorm2004.TYPE_MISMATCH,
237
+ scorm2004_errors.TYPE_MISMATCH,
213
238
  );
214
239
  }
215
240
  } else {
216
241
  if (!nodes[i].match(formatRegex)) {
217
242
  throw new Scorm2004ValidationError(
218
- ErrorCodes.scorm2004.TYPE_MISMATCH,
243
+ scorm2004_errors.TYPE_MISMATCH,
219
244
  );
220
245
  } else {
221
246
  if (nodes[i] !== "" && response_type.unique) {
222
247
  for (let j = 0; j < i; j++) {
223
248
  if (nodes[i] === nodes[j]) {
224
249
  throw new Scorm2004ValidationError(
225
- ErrorCodes.scorm2004.TYPE_MISMATCH,
250
+ scorm2004_errors.TYPE_MISMATCH,
226
251
  );
227
252
  }
228
253
  }
@@ -232,13 +257,13 @@ export class CMIInteractionsObject extends BaseCMI {
232
257
  }
233
258
  } else {
234
259
  throw new Scorm2004ValidationError(
235
- ErrorCodes.scorm2004.GENERAL_SET_FAILURE,
260
+ scorm2004_errors.GENERAL_SET_FAILURE,
236
261
  );
237
262
  }
238
263
 
239
264
  this._learner_response = learner_response;
240
265
  } else {
241
- throw new Scorm2004ValidationError(ErrorCodes.scorm2004.TYPE_MISMATCH);
266
+ throw new Scorm2004ValidationError(scorm2004_errors.TYPE_MISMATCH);
242
267
  }
243
268
  }
244
269
  }
@@ -256,7 +281,7 @@ export class CMIInteractionsObject extends BaseCMI {
256
281
  * @param {string} result
257
282
  */
258
283
  set result(result: string) {
259
- if (check2004ValidFormat(result, Regex.scorm2004.CMIResult)) {
284
+ if (check2004ValidFormat(result, scorm2004_regex.CMIResult)) {
260
285
  this._result = result;
261
286
  }
262
287
  }
@@ -276,10 +301,10 @@ export class CMIInteractionsObject extends BaseCMI {
276
301
  set latency(latency: string) {
277
302
  if (this.initialized && this._id === "") {
278
303
  throw new Scorm2004ValidationError(
279
- ErrorCodes.scorm2004.DEPENDENCY_NOT_ESTABLISHED,
304
+ scorm2004_errors.DEPENDENCY_NOT_ESTABLISHED,
280
305
  );
281
306
  } else {
282
- if (check2004ValidFormat(latency, Regex.scorm2004.CMITimespan)) {
307
+ if (check2004ValidFormat(latency, scorm2004_regex.CMITimespan)) {
283
308
  this._latency = latency;
284
309
  }
285
310
  }
@@ -300,13 +325,13 @@ export class CMIInteractionsObject extends BaseCMI {
300
325
  set description(description: string) {
301
326
  if (this.initialized && this._id === "") {
302
327
  throw new Scorm2004ValidationError(
303
- ErrorCodes.scorm2004.DEPENDENCY_NOT_ESTABLISHED,
328
+ scorm2004_errors.DEPENDENCY_NOT_ESTABLISHED,
304
329
  );
305
330
  } else {
306
331
  if (
307
332
  check2004ValidFormat(
308
333
  description,
309
- Regex.scorm2004.CMILangString250,
334
+ scorm2004_regex.CMILangString250,
310
335
  true,
311
336
  )
312
337
  ) {
@@ -376,6 +401,14 @@ export class CMIInteractionsObjectivesObject extends BaseCMI {
376
401
  super();
377
402
  }
378
403
 
404
+ /**
405
+ * Called when the API has been reset
406
+ */
407
+ override reset() {
408
+ this._initialized = false;
409
+ this._id = "";
410
+ }
411
+
379
412
  /**
380
413
  * Getter for _id
381
414
  * @return {string}
@@ -389,7 +422,7 @@ export class CMIInteractionsObjectivesObject extends BaseCMI {
389
422
  * @param {string} id
390
423
  */
391
424
  set id(id: string) {
392
- if (check2004ValidFormat(id, Regex.scorm2004.CMILongIdentifier)) {
425
+ if (check2004ValidFormat(id, scorm2004_regex.CMILongIdentifier)) {
393
426
  this._id = id;
394
427
  }
395
428
  }
@@ -427,6 +460,14 @@ export class CMIInteractionsCorrectResponsesObject extends BaseCMI {
427
460
  super();
428
461
  }
429
462
 
463
+ /**
464
+ * Called when the API has been reset
465
+ */
466
+ override reset() {
467
+ this._initialized = false;
468
+ this._pattern = "";
469
+ }
470
+
430
471
  /**
431
472
  * Getter for _pattern
432
473
  * @return {string}
@@ -440,7 +481,7 @@ export class CMIInteractionsCorrectResponsesObject extends BaseCMI {
440
481
  * @param {string} pattern
441
482
  */
442
483
  set pattern(pattern: string) {
443
- if (check2004ValidFormat(pattern, Regex.scorm2004.CMIFeedback)) {
484
+ if (check2004ValidFormat(pattern, scorm2004_regex.CMIFeedback)) {
444
485
  this._pattern = pattern;
445
486
  }
446
487
  }
@@ -2,14 +2,14 @@
2
2
  * Class for SCORM 2004's cmi.learner_preference object
3
3
  */
4
4
  import { BaseCMI } from "../common/base_cmi";
5
- import APIConstants from "../../constants/api_constants";
6
- import { Scorm2004ValidationError } from "../../exceptions";
7
- import ErrorCodes from "../../constants/error_codes";
5
+ import { scorm2004_constants } from "../../constants/api_constants";
6
+ import { Scorm2004ValidationError } from "../../exceptions/scorm2004_exceptions";
7
+ import { scorm2004_errors } from "../../constants/error_codes";
8
8
  import { check2004ValidFormat, check2004ValidRange } from "./validation";
9
- import Regex from "../../constants/regex";
9
+ import { scorm2004_regex } from "../../constants/regex";
10
10
 
11
11
  export class CMILearnerPreference extends BaseCMI {
12
- private __children = APIConstants.scorm2004.student_preference_children;
12
+ private __children = scorm2004_constants.student_preference_children;
13
13
  private _audio_level = "1";
14
14
  private _language = "";
15
15
  private _delivery_speed = "1";
@@ -22,6 +22,13 @@ export class CMILearnerPreference extends BaseCMI {
22
22
  super();
23
23
  }
24
24
 
25
+ /**
26
+ * Called when the API has been reset
27
+ */
28
+ override reset() {
29
+ this._initialized = false;
30
+ }
31
+
25
32
  /**
26
33
  * Getter for __children
27
34
  * @return {string}
@@ -37,7 +44,7 @@ export class CMILearnerPreference extends BaseCMI {
37
44
  * @private
38
45
  */
39
46
  set _children(_children: string) {
40
- throw new Scorm2004ValidationError(ErrorCodes.scorm2004.READ_ONLY_ELEMENT);
47
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
41
48
  }
42
49
 
43
50
  /**
@@ -54,8 +61,8 @@ export class CMILearnerPreference extends BaseCMI {
54
61
  */
55
62
  set audio_level(audio_level: string) {
56
63
  if (
57
- check2004ValidFormat(audio_level, Regex.scorm2004.CMIDecimal) &&
58
- check2004ValidRange(audio_level, Regex.scorm2004.audio_range)
64
+ check2004ValidFormat(audio_level, scorm2004_regex.CMIDecimal) &&
65
+ check2004ValidRange(audio_level, scorm2004_regex.audio_range)
59
66
  ) {
60
67
  this._audio_level = audio_level;
61
68
  }
@@ -74,7 +81,7 @@ export class CMILearnerPreference extends BaseCMI {
74
81
  * @param {string} language
75
82
  */
76
83
  set language(language: string) {
77
- if (check2004ValidFormat(language, Regex.scorm2004.CMILang)) {
84
+ if (check2004ValidFormat(language, scorm2004_regex.CMILang)) {
78
85
  this._language = language;
79
86
  }
80
87
  }
@@ -93,8 +100,8 @@ export class CMILearnerPreference extends BaseCMI {
93
100
  */
94
101
  set delivery_speed(delivery_speed: string) {
95
102
  if (
96
- check2004ValidFormat(delivery_speed, Regex.scorm2004.CMIDecimal) &&
97
- check2004ValidRange(delivery_speed, Regex.scorm2004.speed_range)
103
+ check2004ValidFormat(delivery_speed, scorm2004_regex.CMIDecimal) &&
104
+ check2004ValidRange(delivery_speed, scorm2004_regex.speed_range)
98
105
  ) {
99
106
  this._delivery_speed = delivery_speed;
100
107
  }
@@ -114,8 +121,8 @@ export class CMILearnerPreference extends BaseCMI {
114
121
  */
115
122
  set audio_captioning(audio_captioning: string) {
116
123
  if (
117
- check2004ValidFormat(audio_captioning, Regex.scorm2004.CMISInteger) &&
118
- check2004ValidRange(audio_captioning, Regex.scorm2004.text_range)
124
+ check2004ValidFormat(audio_captioning, scorm2004_regex.CMISInteger) &&
125
+ check2004ValidRange(audio_captioning, scorm2004_regex.text_range)
119
126
  ) {
120
127
  this._audio_captioning = audio_captioning;
121
128
  }
@@ -1,11 +1,11 @@
1
1
  import { CMIArray } from "../common/array";
2
- import APIConstants from "../../constants/api_constants";
3
- import ErrorCodes from "../../constants/error_codes";
4
- import { Scorm2004ValidationError } from "../../exceptions";
2
+ import { scorm2004_errors } from "../../constants/error_codes";
3
+ import { Scorm2004ValidationError } from "../../exceptions/scorm2004_exceptions";
5
4
  import { BaseCMI } from "../common/base_cmi";
6
5
  import { Scorm2004CMIScore } from "./score";
7
6
  import { check2004ValidFormat, check2004ValidRange } from "./validation";
8
- import Regex from "../../constants/regex";
7
+ import { scorm2004_regex } from "../../constants/regex";
8
+ import { scorm2004_constants } from "../../constants/api_constants";
9
9
 
10
10
  /**
11
11
  * Class representing SCORM 2004's `cmi.objectives` object
@@ -17,11 +17,32 @@ export class CMIObjectives extends CMIArray {
17
17
  */
18
18
  constructor() {
19
19
  super({
20
- children: APIConstants.scorm2004.objectives_children,
21
- errorCode: ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
20
+ children: scorm2004_constants.objectives_children,
21
+ errorCode: scorm2004_errors.READ_ONLY_ELEMENT,
22
22
  errorClass: Scorm2004ValidationError,
23
23
  });
24
24
  }
25
+
26
+ /**
27
+ * Find an objective by its ID
28
+ */
29
+ public findObjectiveById(id: string): CMIObjectivesObject | undefined {
30
+ return this.childArray.find((objective) => objective.id === id);
31
+ }
32
+
33
+ /**
34
+ * Find objective by its index
35
+ */
36
+ public findObjectiveByIndex(index: number): CMIObjectivesObject {
37
+ return this.childArray[index];
38
+ }
39
+
40
+ /**
41
+ * Set an objective at the given index
42
+ */
43
+ public setObjectiveByIndex(index: number, objective: CMIObjectivesObject) {
44
+ this.childArray[index] = objective;
45
+ }
25
46
  }
26
47
 
27
48
  /**
@@ -42,6 +63,10 @@ export class CMIObjectivesObject extends BaseCMI {
42
63
  this.score = new Scorm2004CMIScore();
43
64
  }
44
65
 
66
+ override reset() {
67
+ this._initialized = false;
68
+ }
69
+
45
70
  public score: Scorm2004CMIScore;
46
71
 
47
72
  /**
@@ -65,7 +90,7 @@ export class CMIObjectivesObject extends BaseCMI {
65
90
  * @param {string} id
66
91
  */
67
92
  set id(id: string) {
68
- if (check2004ValidFormat(id, Regex.scorm2004.CMILongIdentifier)) {
93
+ if (check2004ValidFormat(id, scorm2004_regex.CMILongIdentifier)) {
69
94
  this._id = id;
70
95
  }
71
96
  }
@@ -85,10 +110,10 @@ export class CMIObjectivesObject extends BaseCMI {
85
110
  set success_status(success_status: string) {
86
111
  if (this.initialized && this._id === "") {
87
112
  throw new Scorm2004ValidationError(
88
- ErrorCodes.scorm2004.DEPENDENCY_NOT_ESTABLISHED,
113
+ scorm2004_errors.DEPENDENCY_NOT_ESTABLISHED,
89
114
  );
90
115
  } else {
91
- if (check2004ValidFormat(success_status, Regex.scorm2004.CMISStatus)) {
116
+ if (check2004ValidFormat(success_status, scorm2004_regex.CMISStatus)) {
92
117
  this._success_status = success_status;
93
118
  }
94
119
  }
@@ -109,10 +134,10 @@ export class CMIObjectivesObject extends BaseCMI {
109
134
  set completion_status(completion_status: string) {
110
135
  if (this.initialized && this._id === "") {
111
136
  throw new Scorm2004ValidationError(
112
- ErrorCodes.scorm2004.DEPENDENCY_NOT_ESTABLISHED,
137
+ scorm2004_errors.DEPENDENCY_NOT_ESTABLISHED,
113
138
  );
114
139
  } else {
115
- if (check2004ValidFormat(completion_status, Regex.scorm2004.CMICStatus)) {
140
+ if (check2004ValidFormat(completion_status, scorm2004_regex.CMICStatus)) {
116
141
  this._completion_status = completion_status;
117
142
  }
118
143
  }
@@ -133,12 +158,12 @@ export class CMIObjectivesObject extends BaseCMI {
133
158
  set progress_measure(progress_measure: string) {
134
159
  if (this.initialized && this._id === "") {
135
160
  throw new Scorm2004ValidationError(
136
- ErrorCodes.scorm2004.DEPENDENCY_NOT_ESTABLISHED,
161
+ scorm2004_errors.DEPENDENCY_NOT_ESTABLISHED,
137
162
  );
138
163
  } else {
139
164
  if (
140
- check2004ValidFormat(progress_measure, Regex.scorm2004.CMIDecimal) &&
141
- check2004ValidRange(progress_measure, Regex.scorm2004.progress_range)
165
+ check2004ValidFormat(progress_measure, scorm2004_regex.CMIDecimal) &&
166
+ check2004ValidRange(progress_measure, scorm2004_regex.progress_range)
142
167
  ) {
143
168
  this._progress_measure = progress_measure;
144
169
  }
@@ -160,13 +185,13 @@ export class CMIObjectivesObject extends BaseCMI {
160
185
  set description(description: string) {
161
186
  if (this.initialized && this._id === "") {
162
187
  throw new Scorm2004ValidationError(
163
- ErrorCodes.scorm2004.DEPENDENCY_NOT_ESTABLISHED,
188
+ scorm2004_errors.DEPENDENCY_NOT_ESTABLISHED,
164
189
  );
165
190
  } else {
166
191
  if (
167
192
  check2004ValidFormat(
168
193
  description,
169
- Regex.scorm2004.CMILangString250,
194
+ scorm2004_regex.CMILangString250,
170
195
  true,
171
196
  )
172
197
  ) {
@@ -2,10 +2,10 @@
2
2
  * Class for SCORM 2004's cmi *.score object
3
3
  */
4
4
  import { CMIScore } from "../common/score";
5
- import APIConstants from "../../constants/api_constants";
6
- import ErrorCodes from "../../constants/error_codes";
7
- import Regex from "../../constants/regex";
8
- import { Scorm2004ValidationError } from "../../exceptions";
5
+ import { scorm2004_constants } from "../../constants/api_constants";
6
+ import { scorm2004_errors } from "../../constants/error_codes";
7
+ import { scorm2004_regex } from "../../constants/regex";
8
+ import { Scorm2004ValidationError } from "../../exceptions/scorm2004_exceptions";
9
9
  import { check2004ValidFormat, check2004ValidRange } from "./validation";
10
10
 
11
11
  export class Scorm2004CMIScore extends CMIScore {
@@ -16,16 +16,27 @@ export class Scorm2004CMIScore extends CMIScore {
16
16
  */
17
17
  constructor() {
18
18
  super({
19
- score_children: APIConstants.scorm2004.score_children,
19
+ score_children: scorm2004_constants.score_children,
20
20
  max: "",
21
- invalidErrorCode: ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
22
- invalidTypeCode: ErrorCodes.scorm2004.TYPE_MISMATCH,
23
- invalidRangeCode: ErrorCodes.scorm2004.VALUE_OUT_OF_RANGE,
24
- decimalRegex: Regex.scorm2004.CMIDecimal,
21
+ invalidErrorCode: scorm2004_errors.READ_ONLY_ELEMENT,
22
+ invalidTypeCode: scorm2004_errors.TYPE_MISMATCH,
23
+ invalidRangeCode: scorm2004_errors.VALUE_OUT_OF_RANGE,
24
+ decimalRegex: scorm2004_regex.CMIDecimal,
25
25
  errorClass: Scorm2004ValidationError,
26
26
  });
27
27
  }
28
28
 
29
+ /**
30
+ * Called when the API has been reset
31
+ */
32
+ override reset(): void {
33
+ this._initialized = false;
34
+ this._scaled = "";
35
+ this._raw = "";
36
+ this._min = "";
37
+ this._max = "";
38
+ }
39
+
29
40
  /**
30
41
  * Getter for _scaled
31
42
  * @return {string}
@@ -40,8 +51,8 @@ export class Scorm2004CMIScore extends CMIScore {
40
51
  */
41
52
  set scaled(scaled: string) {
42
53
  if (
43
- check2004ValidFormat(scaled, Regex.scorm2004.CMIDecimal) &&
44
- check2004ValidRange(scaled, Regex.scorm2004.scaled_range)
54
+ check2004ValidFormat(scaled, scorm2004_regex.CMIDecimal) &&
55
+ check2004ValidRange(scaled, scorm2004_regex.scaled_range)
45
56
  ) {
46
57
  this._scaled = scaled;
47
58
  }
@@ -1,6 +1,6 @@
1
1
  import { checkValidFormat, checkValidRange } from "../common/validation";
2
- import ErrorCodes from "../../constants/error_codes";
3
- import { Scorm2004ValidationError } from "../../exceptions";
2
+ import { scorm2004_errors } from "../../constants/error_codes";
3
+ import { Scorm2004ValidationError } from "../../exceptions/scorm2004_exceptions";
4
4
 
5
5
  /**
6
6
  * Helper method, no reason to have to pass the same error codes every time
@@ -17,7 +17,7 @@ export function check2004ValidFormat(
17
17
  return checkValidFormat(
18
18
  value,
19
19
  regexPattern,
20
- ErrorCodes.scorm2004.TYPE_MISMATCH,
20
+ scorm2004_errors.TYPE_MISMATCH,
21
21
  Scorm2004ValidationError,
22
22
  allowEmptyString,
23
23
  );
@@ -36,7 +36,7 @@ export function check2004ValidRange(
36
36
  return checkValidRange(
37
37
  value,
38
38
  rangePattern,
39
- ErrorCodes.scorm2004.VALUE_OUT_OF_RANGE,
39
+ scorm2004_errors.VALUE_OUT_OF_RANGE,
40
40
  Scorm2004ValidationError,
41
41
  );
42
42
  }
@@ -36,6 +36,7 @@ interface Scorm2004Constants {
36
36
  student_data_children: string;
37
37
  student_preference_children: string;
38
38
  interactions_children: string;
39
+ adl_data_children: string;
39
40
  error_descriptions: ErrorDescriptions;
40
41
  }
41
42
 
@@ -45,34 +46,17 @@ interface GlobalConstants {
45
46
  STATE_NOT_INITIALIZED: number;
46
47
  STATE_INITIALIZED: number;
47
48
  STATE_TERMINATED: number;
48
- LOG_LEVEL_DEBUG: number;
49
- LOG_LEVEL_INFO: number;
50
- LOG_LEVEL_WARNING: number;
51
- LOG_LEVEL_ERROR: number;
52
- LOG_LEVEL_NONE: number;
53
49
  }
54
50
 
55
- interface APIConstants {
56
- global: GlobalConstants;
57
- scorm12: ScormConstants;
58
- aicc: AiccConstants;
59
- scorm2004: Scorm2004Constants;
60
- }
61
-
62
- const global: GlobalConstants = {
51
+ export const global_constants: GlobalConstants = {
63
52
  SCORM_TRUE: "true",
64
53
  SCORM_FALSE: "false",
65
54
  STATE_NOT_INITIALIZED: 0,
66
55
  STATE_INITIALIZED: 1,
67
56
  STATE_TERMINATED: 2,
68
- LOG_LEVEL_DEBUG: 1,
69
- LOG_LEVEL_INFO: 2,
70
- LOG_LEVEL_WARNING: 3,
71
- LOG_LEVEL_ERROR: 4,
72
- LOG_LEVEL_NONE: 5,
73
57
  };
74
58
 
75
- const scorm12: ScormConstants = {
59
+ export const scorm12_constants: ScormConstants = {
76
60
  // Children lists
77
61
  cmi_children:
78
62
  "core,suspend_data,launch_data,comments,objectives,student_data,student_preference,interactions",
@@ -149,8 +133,8 @@ const scorm12: ScormConstants = {
149
133
  },
150
134
  },
151
135
  };
152
- const aicc: AiccConstants = {
153
- ...scorm12,
136
+ export const aicc_constants: AiccConstants = {
137
+ ...scorm12_constants,
154
138
  ...{
155
139
  cmi_children:
156
140
  "core,suspend_data,launch_data,comments,objectives,student_data,student_preference,interactions,evaluation",
@@ -165,7 +149,8 @@ const aicc: AiccConstants = {
165
149
  paths_children: "location_id,date,time,status,why_left,time_in_element",
166
150
  },
167
151
  };
168
- const scorm2004: Scorm2004Constants = {
152
+
153
+ export const scorm2004_constants: Scorm2004Constants = {
169
154
  // Children lists
170
155
  cmi_children:
171
156
  "_version,comments_from_learner,comments_from_lms,completion_status,credit,entry,exit,interactions,launch_data,learner_id,learner_name,learner_preference,location,max_time_allowed,mode,objectives,progress_measure,scaled_passing_score,score,session_time,success_status,suspend_data,time_limit_action,total_time",
@@ -179,6 +164,7 @@ const scorm2004: Scorm2004Constants = {
179
164
  "audio_level,audio_captioning,delivery_speed,language",
180
165
  interactions_children:
181
166
  "id,type,objectives,timestamp,correct_responses,weighting,learner_response,result,latency,description",
167
+ adl_data_children: "id,store",
182
168
  error_descriptions: {
183
169
  "0": {
184
170
  basicMessage: "No Error",
@@ -309,10 +295,3 @@ const scorm2004: Scorm2004Constants = {
309
295
  },
310
296
  },
311
297
  };
312
- const APIConstants: APIConstants = {
313
- global: global,
314
- scorm12: scorm12,
315
- aicc: aicc,
316
- scorm2004: scorm2004,
317
- };
318
- export default APIConstants;