scorm-again 2.5.0 → 2.6.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.
Files changed (87) hide show
  1. package/dist/aicc.js +657 -489
  2. package/dist/aicc.js.map +1 -1
  3. package/dist/aicc.min.js +1 -1
  4. package/dist/aicc.min.js.map +1 -1
  5. package/dist/esm/aicc.js +670 -489
  6. package/dist/esm/aicc.js.map +1 -1
  7. package/dist/esm/aicc.min.js +1 -1
  8. package/dist/esm/aicc.min.js.map +1 -1
  9. package/dist/esm/scorm-again.js +1113 -729
  10. package/dist/esm/scorm-again.js.map +1 -1
  11. package/dist/esm/scorm-again.min.js +1 -1
  12. package/dist/esm/scorm-again.min.js.map +1 -1
  13. package/dist/esm/scorm12.js +512 -394
  14. package/dist/esm/scorm12.js.map +1 -1
  15. package/dist/esm/scorm12.min.js +1 -1
  16. package/dist/esm/scorm12.min.js.map +1 -1
  17. package/dist/esm/scorm2004.js +678 -452
  18. package/dist/esm/scorm2004.js.map +1 -1
  19. package/dist/esm/scorm2004.min.js +1 -1
  20. package/dist/esm/scorm2004.min.js.map +1 -1
  21. package/dist/scorm-again.js +1100 -728
  22. package/dist/scorm-again.js.map +1 -1
  23. package/dist/scorm-again.min.js +1 -1
  24. package/dist/scorm-again.min.js.map +1 -1
  25. package/dist/scorm12.js +500 -394
  26. package/dist/scorm12.js.map +1 -1
  27. package/dist/scorm12.min.js +1 -1
  28. package/dist/scorm12.min.js.map +1 -1
  29. package/dist/scorm2004.js +665 -452
  30. package/dist/scorm2004.js.map +1 -1
  31. package/dist/scorm2004.min.js +1 -1
  32. package/dist/scorm2004.min.js.map +1 -1
  33. package/dist_test.html +208 -0
  34. package/package.json +14 -14
  35. package/src/AICC.ts +6 -3
  36. package/src/BaseAPI.ts +43 -37
  37. package/src/Scorm12API.ts +17 -23
  38. package/src/Scorm2004API.ts +99 -42
  39. package/src/ScormAgain.ts +3 -7
  40. package/src/cmi/aicc/attempts.ts +22 -12
  41. package/src/cmi/aicc/cmi.ts +2 -2
  42. package/src/cmi/aicc/core.ts +44 -26
  43. package/src/cmi/aicc/evaluation.ts +31 -12
  44. package/src/cmi/aicc/paths.ts +29 -15
  45. package/src/cmi/aicc/student_data.ts +14 -5
  46. package/src/cmi/aicc/student_demographics.ts +31 -24
  47. package/src/cmi/aicc/student_preferences.ts +11 -11
  48. package/src/cmi/aicc/tries.ts +24 -14
  49. package/src/cmi/aicc/validation.ts +3 -4
  50. package/src/cmi/common/array.ts +17 -5
  51. package/src/cmi/common/base_cmi.ts +3 -1
  52. package/src/cmi/common/score.ts +16 -13
  53. package/src/cmi/scorm12/cmi.ts +25 -10
  54. package/src/cmi/scorm12/interactions.ts +62 -28
  55. package/src/cmi/scorm12/nav.ts +13 -5
  56. package/src/cmi/scorm12/objectives.ts +28 -18
  57. package/src/cmi/scorm12/student_data.ts +15 -8
  58. package/src/cmi/scorm12/student_preference.ts +20 -13
  59. package/src/cmi/scorm12/validation.ts +7 -7
  60. package/src/cmi/scorm2004/adl.ts +141 -25
  61. package/src/cmi/scorm2004/cmi.ts +50 -55
  62. package/src/cmi/scorm2004/comments.ts +21 -20
  63. package/src/cmi/scorm2004/interactions.ts +73 -32
  64. package/src/cmi/scorm2004/learner_preference.ts +20 -13
  65. package/src/cmi/scorm2004/objectives.ts +41 -16
  66. package/src/cmi/scorm2004/score.ts +22 -11
  67. package/src/cmi/scorm2004/validation.ts +4 -4
  68. package/src/constants/api_constants.ts +8 -19
  69. package/src/constants/default_settings.ts +6 -5
  70. package/src/constants/error_codes.ts +5 -12
  71. package/src/constants/regex.ts +4 -10
  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 +0 -81
  77. package/src/types/api_types.ts +3 -2
  78. package/test/AICC.spec.ts +114 -43
  79. package/test/Scorm12API.spec.ts +60 -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 +3 -3
  86. package/test/utilities.spec.ts +1 -4
  87. package/webpack.config.js +5 -1
@@ -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
 
@@ -47,14 +48,7 @@ interface GlobalConstants {
47
48
  STATE_TERMINATED: number;
48
49
  }
49
50
 
50
- interface APIConstants {
51
- global: GlobalConstants;
52
- scorm12: ScormConstants;
53
- aicc: AiccConstants;
54
- scorm2004: Scorm2004Constants;
55
- }
56
-
57
- const global: GlobalConstants = {
51
+ export const global_constants: GlobalConstants = {
58
52
  SCORM_TRUE: "true",
59
53
  SCORM_FALSE: "false",
60
54
  STATE_NOT_INITIALIZED: 0,
@@ -62,7 +56,7 @@ const global: GlobalConstants = {
62
56
  STATE_TERMINATED: 2,
63
57
  };
64
58
 
65
- const scorm12: ScormConstants = {
59
+ export const scorm12_constants: ScormConstants = {
66
60
  // Children lists
67
61
  cmi_children:
68
62
  "core,suspend_data,launch_data,comments,objectives,student_data,student_preference,interactions",
@@ -139,8 +133,8 @@ const scorm12: ScormConstants = {
139
133
  },
140
134
  },
141
135
  };
142
- const aicc: AiccConstants = {
143
- ...scorm12,
136
+ export const aicc_constants: AiccConstants = {
137
+ ...scorm12_constants,
144
138
  ...{
145
139
  cmi_children:
146
140
  "core,suspend_data,launch_data,comments,objectives,student_data,student_preference,interactions,evaluation",
@@ -155,7 +149,8 @@ const aicc: AiccConstants = {
155
149
  paths_children: "location_id,date,time,status,why_left,time_in_element",
156
150
  },
157
151
  };
158
- const scorm2004: Scorm2004Constants = {
152
+
153
+ export const scorm2004_constants: Scorm2004Constants = {
159
154
  // Children lists
160
155
  cmi_children:
161
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",
@@ -169,6 +164,7 @@ const scorm2004: Scorm2004Constants = {
169
164
  "audio_level,audio_captioning,delivery_speed,language",
170
165
  interactions_children:
171
166
  "id,type,objectives,timestamp,correct_responses,weighting,learner_response,result,latency,description",
167
+ adl_data_children: "id,store",
172
168
  error_descriptions: {
173
169
  "0": {
174
170
  basicMessage: "No Error",
@@ -299,10 +295,3 @@ const scorm2004: Scorm2004Constants = {
299
295
  },
300
296
  },
301
297
  };
302
- const APIConstants: APIConstants = {
303
- global: global,
304
- scorm12: scorm12,
305
- aicc: aicc,
306
- scorm2004: scorm2004,
307
- };
308
- export default APIConstants;
@@ -1,5 +1,5 @@
1
1
  import { LogLevel, ResultObject, Settings } from "../types/api_types";
2
- import APIConstants from "./api_constants";
2
+ import { global_constants } from "./api_constants";
3
3
  import { LogLevelEnum } from "./enums";
4
4
 
5
5
  /**
@@ -35,12 +35,12 @@ export const DefaultSettings: Settings = {
35
35
  ) {
36
36
  if (response.status === 200) {
37
37
  return {
38
- result: APIConstants.global.SCORM_TRUE,
38
+ result: global_constants.SCORM_TRUE,
39
39
  errorCode: 0,
40
40
  };
41
41
  } else {
42
42
  return {
43
- result: APIConstants.global.SCORM_FALSE,
43
+ result: global_constants.SCORM_FALSE,
44
44
  errorCode: 101,
45
45
  };
46
46
  }
@@ -49,14 +49,14 @@ export const DefaultSettings: Settings = {
49
49
  result: httpResult.result,
50
50
  errorCode: httpResult.errorCode
51
51
  ? httpResult.errorCode
52
- : httpResult.result === APIConstants.global.SCORM_TRUE
52
+ : httpResult.result === global_constants.SCORM_TRUE
53
53
  ? 0
54
54
  : 101,
55
55
  };
56
56
  }
57
57
  }
58
58
  return {
59
- result: APIConstants.global.SCORM_FALSE,
59
+ result: global_constants.SCORM_FALSE,
60
60
  errorCode: 101,
61
61
  };
62
62
  },
@@ -97,4 +97,5 @@ export const DefaultSettings: Settings = {
97
97
  },
98
98
  scoItemIds: [],
99
99
  scoItemIdValidator: false,
100
+ globalObjectiveIds: [],
100
101
  };