scorm-again 2.5.0 → 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 (85) hide show
  1. package/dist/aicc.js +648 -485
  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 +664 -488
  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 +1111 -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 +506 -393
  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 +672 -451
  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 +1087 -717
  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 +493 -392
  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 +658 -450
  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/package.json +14 -14
  34. package/src/AICC.ts +3 -0
  35. package/src/BaseAPI.ts +33 -30
  36. package/src/Scorm12API.ts +14 -14
  37. package/src/Scorm2004API.ts +99 -33
  38. package/src/cmi/aicc/attempts.ts +22 -12
  39. package/src/cmi/aicc/cmi.ts +2 -2
  40. package/src/cmi/aicc/core.ts +44 -26
  41. package/src/cmi/aicc/evaluation.ts +31 -12
  42. package/src/cmi/aicc/paths.ts +29 -15
  43. package/src/cmi/aicc/student_data.ts +14 -5
  44. package/src/cmi/aicc/student_demographics.ts +31 -24
  45. package/src/cmi/aicc/student_preferences.ts +11 -11
  46. package/src/cmi/aicc/tries.ts +24 -14
  47. package/src/cmi/aicc/validation.ts +3 -4
  48. package/src/cmi/common/array.ts +17 -5
  49. package/src/cmi/common/base_cmi.ts +3 -1
  50. package/src/cmi/common/score.ts +16 -13
  51. package/src/cmi/scorm12/cmi.ts +25 -10
  52. package/src/cmi/scorm12/interactions.ts +62 -28
  53. package/src/cmi/scorm12/nav.ts +13 -5
  54. package/src/cmi/scorm12/objectives.ts +28 -18
  55. package/src/cmi/scorm12/student_data.ts +15 -8
  56. package/src/cmi/scorm12/student_preference.ts +20 -13
  57. package/src/cmi/scorm12/validation.ts +7 -7
  58. package/src/cmi/scorm2004/adl.ts +141 -25
  59. package/src/cmi/scorm2004/cmi.ts +50 -55
  60. package/src/cmi/scorm2004/comments.ts +21 -20
  61. package/src/cmi/scorm2004/interactions.ts +73 -32
  62. package/src/cmi/scorm2004/learner_preference.ts +20 -13
  63. package/src/cmi/scorm2004/objectives.ts +41 -16
  64. package/src/cmi/scorm2004/score.ts +22 -11
  65. package/src/cmi/scorm2004/validation.ts +4 -4
  66. package/src/constants/api_constants.ts +8 -19
  67. package/src/constants/default_settings.ts +6 -5
  68. package/src/constants/error_codes.ts +5 -12
  69. package/src/constants/regex.ts +4 -10
  70. package/src/constants/response_constants.ts +1 -2
  71. package/src/exceptions/aicc_exceptions.ts +29 -0
  72. package/src/exceptions/scorm12_exceptions.ts +29 -0
  73. package/src/exceptions/scorm2004_exceptions.ts +29 -0
  74. package/src/exceptions.ts +0 -81
  75. package/src/types/api_types.ts +3 -2
  76. package/test/AICC.spec.ts +114 -43
  77. package/test/Scorm12API.spec.ts +37 -39
  78. package/test/Scorm2004API.spec.ts +165 -80
  79. package/test/cmi/aicc_cmi.spec.ts +6 -9
  80. package/test/cmi/scorm12_cmi.spec.ts +8 -8
  81. package/test/cmi/scorm2004_cmi.spec.ts +8 -9
  82. package/test/exceptions.spec.ts +11 -9
  83. package/test/types/api_types.spec.ts +3 -3
  84. package/test/utilities.spec.ts +1 -4
  85. package/webpack.config.js +4 -0
@@ -1,6 +1,6 @@
1
- import {checkValidFormat, checkValidRange} from "../common/validation";
2
- import ErrorCodes from "../../constants/error_codes";
3
- import {Scorm12ValidationError} from "../../exceptions";
1
+ import { checkValidFormat, checkValidRange } from "../common/validation";
2
+ import { scorm12_errors } from "../../constants/error_codes";
3
+ import { Scorm12ValidationError } from "../../exceptions/scorm12_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 check12ValidFormat(
17
17
  return checkValidFormat(
18
18
  value,
19
19
  regexPattern,
20
- ErrorCodes.scorm12.TYPE_MISMATCH,
20
+ scorm12_errors.TYPE_MISMATCH,
21
21
  Scorm12ValidationError,
22
22
  allowEmptyString,
23
23
  );
@@ -36,13 +36,13 @@ export function check12ValidRange(
36
36
  allowEmptyString?: boolean,
37
37
  ): boolean {
38
38
  if (!allowEmptyString && value === "") {
39
- throw new Scorm12ValidationError(ErrorCodes.scorm12.VALUE_OUT_OF_RANGE);
39
+ throw new Scorm12ValidationError(scorm12_errors.VALUE_OUT_OF_RANGE);
40
40
  }
41
41
 
42
42
  return checkValidRange(
43
43
  value,
44
44
  rangePattern,
45
- ErrorCodes.scorm12.VALUE_OUT_OF_RANGE,
45
+ scorm12_errors.VALUE_OUT_OF_RANGE,
46
46
  Scorm12ValidationError,
47
47
  );
48
- }
48
+ }
@@ -1,9 +1,11 @@
1
1
  import { BaseCMI } from "../common/base_cmi";
2
- import { Scorm2004ValidationError } from "../../exceptions";
3
- import ErrorCodes from "../../constants/error_codes";
2
+ import { Scorm2004ValidationError } from "../../exceptions/scorm2004_exceptions";
4
3
  import { check2004ValidFormat } from "./validation";
5
- import Regex from "../../constants/regex";
4
+ import { scorm2004_regex } from "../../constants/regex";
6
5
  import { NAVBoolean } from "../../constants/enums";
6
+ import { CMIArray } from "../common/array";
7
+ import { scorm2004_constants } from "../../constants/api_constants";
8
+ import { scorm2004_errors } from "../../constants/error_codes";
7
9
 
8
10
  /**
9
11
  * Class representing SCORM 2004's adl object
@@ -15,9 +17,11 @@ export class ADL extends BaseCMI {
15
17
  constructor() {
16
18
  super();
17
19
  this.nav = new ADLNav();
20
+ this.data = new ADLData();
18
21
  }
19
22
 
20
23
  public nav: ADLNav;
24
+ public data = new ADLData();
21
25
 
22
26
  /**
23
27
  * Called when the API has been initialized after the CMI has been created
@@ -27,20 +31,31 @@ export class ADL extends BaseCMI {
27
31
  this.nav?.initialize();
28
32
  }
29
33
 
34
+ /**
35
+ * Called when the API needs to be reset
36
+ */
37
+ reset() {
38
+ this._initialized = false;
39
+ this.nav?.reset();
40
+ }
41
+
30
42
  /**
31
43
  * toJSON for adl
32
44
  * @return {
33
45
  * {
34
- * nav: ADLNav
46
+ * nav: ADLNav,
47
+ * data: ADLData
35
48
  * }
36
49
  * }
37
50
  */
38
51
  toJSON(): {
39
52
  nav: ADLNav;
53
+ data: ADLData;
40
54
  } {
41
55
  this.jsonString = true;
42
56
  const result = {
43
57
  nav: this.nav,
58
+ data: this.data,
44
59
  };
45
60
  delete this.jsonString;
46
61
  return result;
@@ -72,6 +87,15 @@ export class ADLNav extends BaseCMI {
72
87
  this.request_valid?.initialize();
73
88
  }
74
89
 
90
+ /**
91
+ * Called when the API needs to be reset
92
+ */
93
+ reset() {
94
+ this._initialized = false;
95
+ this._request = "_none_";
96
+ this.request_valid?.reset();
97
+ }
98
+
75
99
  /**
76
100
  * Getter for _request
77
101
  * @return {string}
@@ -85,7 +109,7 @@ export class ADLNav extends BaseCMI {
85
109
  * @param {string} request
86
110
  */
87
111
  set request(request: string) {
88
- if (check2004ValidFormat(request, Regex.scorm2004.NAVEvent)) {
112
+ if (check2004ValidFormat(request, scorm2004_regex.NAVEvent)) {
89
113
  this._request = request;
90
114
  }
91
115
  }
@@ -111,6 +135,97 @@ export class ADLNav extends BaseCMI {
111
135
  }
112
136
  }
113
137
 
138
+ /**
139
+ * Class representing SCORM 2004's `adl.data` object
140
+ */
141
+ export class ADLData extends CMIArray {
142
+ constructor() {
143
+ super({
144
+ children: scorm2004_constants.adl_data_children,
145
+ errorCode: scorm2004_errors.READ_ONLY_ELEMENT,
146
+ errorClass: Scorm2004ValidationError,
147
+ });
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Class for SCORM 2004's adl.data.n object
153
+ */
154
+ export class ADLDataObject extends BaseCMI {
155
+ private _id = "";
156
+ private _store = "";
157
+
158
+ constructor() {
159
+ super();
160
+ }
161
+
162
+ /**
163
+ * Called when the API has been reset
164
+ */
165
+ reset() {
166
+ this._initialized = false;
167
+ }
168
+
169
+ /**
170
+ * Getter for _id
171
+ * @return {string}
172
+ */
173
+ get id(): string {
174
+ return this._id;
175
+ }
176
+
177
+ /**
178
+ * Setter for _id
179
+ * @param {string} id
180
+ */
181
+ set id(id: string) {
182
+ if (check2004ValidFormat(id, scorm2004_regex.CMILongIdentifier)) {
183
+ this._id = id;
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Getter for _store
189
+ * @return {string}
190
+ */
191
+ get store(): string {
192
+ return this._store;
193
+ }
194
+
195
+ /**
196
+ * Setter for _store
197
+ * @param {string} store
198
+ */
199
+ set store(store: string) {
200
+ if (check2004ValidFormat(store, scorm2004_regex.CMILangString4000)) {
201
+ this._store = store;
202
+ }
203
+ }
204
+
205
+ /**
206
+ * toJSON for adl.data.n
207
+ *
208
+ * @return {
209
+ * {
210
+ * id: string,
211
+ * store: string
212
+ * }
213
+ * }
214
+ */
215
+ toJSON(): {
216
+ id: string;
217
+ store: string;
218
+ } {
219
+ this.jsonString = true;
220
+ const result = {
221
+ id: this._id,
222
+ store: this._store,
223
+ };
224
+ delete this.jsonString;
225
+ return result;
226
+ }
227
+ }
228
+
114
229
  /**
115
230
  * Class representing SCORM 2004's adl.nav.request_valid object
116
231
  */
@@ -132,6 +247,15 @@ export class ADLNavRequestValid extends BaseCMI {
132
247
  super();
133
248
  }
134
249
 
250
+ /**
251
+ * Called when the API has been reset
252
+ */
253
+ override reset() {
254
+ this._initialized = false;
255
+ this._continue = "unknown";
256
+ this._previous = "unknown";
257
+ }
258
+
135
259
  /**
136
260
  * Getter for _continue
137
261
  * @return {string}
@@ -146,11 +270,9 @@ export class ADLNavRequestValid extends BaseCMI {
146
270
  */
147
271
  set continue(_continue: string) {
148
272
  if (this.initialized) {
149
- throw new Scorm2004ValidationError(
150
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
151
- );
273
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
152
274
  }
153
- if (check2004ValidFormat(_continue, Regex.scorm2004.NAVBoolean)) {
275
+ if (check2004ValidFormat(_continue, scorm2004_regex.NAVBoolean)) {
154
276
  this._continue = _continue;
155
277
  }
156
278
  }
@@ -169,11 +291,9 @@ export class ADLNavRequestValid extends BaseCMI {
169
291
  */
170
292
  set previous(_previous: string) {
171
293
  if (this.initialized) {
172
- throw new Scorm2004ValidationError(
173
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
174
- );
294
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
175
295
  }
176
- if (check2004ValidFormat(_previous, Regex.scorm2004.NAVBoolean)) {
296
+ if (check2004ValidFormat(_previous, scorm2004_regex.NAVBoolean)) {
177
297
  this._previous = _previous;
178
298
  }
179
299
  }
@@ -192,18 +312,16 @@ export class ADLNavRequestValid extends BaseCMI {
192
312
  */
193
313
  set choice(choice: { [key: string]: string }) {
194
314
  if (this.initialized) {
195
- throw new Scorm2004ValidationError(
196
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
197
- );
315
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
198
316
  }
199
317
  if (typeof choice !== "object") {
200
- throw new Scorm2004ValidationError(ErrorCodes.scorm2004.TYPE_MISMATCH);
318
+ throw new Scorm2004ValidationError(scorm2004_errors.TYPE_MISMATCH);
201
319
  }
202
320
  for (const key in choice) {
203
321
  if ({}.hasOwnProperty.call(choice, key)) {
204
322
  if (
205
- check2004ValidFormat(choice[key], Regex.scorm2004.NAVBoolean) &&
206
- check2004ValidFormat(key, Regex.scorm2004.NAVTarget)
323
+ check2004ValidFormat(choice[key], scorm2004_regex.NAVBoolean) &&
324
+ check2004ValidFormat(key, scorm2004_regex.NAVTarget)
207
325
  ) {
208
326
  this._choice[key] =
209
327
  NAVBoolean[choice[key] as keyof typeof NAVBoolean];
@@ -226,18 +344,16 @@ export class ADLNavRequestValid extends BaseCMI {
226
344
  */
227
345
  set jump(jump: { [key: string]: string }) {
228
346
  if (this.initialized) {
229
- throw new Scorm2004ValidationError(
230
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
231
- );
347
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
232
348
  }
233
349
  if (typeof jump !== "object") {
234
- throw new Scorm2004ValidationError(ErrorCodes.scorm2004.TYPE_MISMATCH);
350
+ throw new Scorm2004ValidationError(scorm2004_errors.TYPE_MISMATCH);
235
351
  }
236
352
  for (const key in jump) {
237
353
  if ({}.hasOwnProperty.call(jump, key)) {
238
354
  if (
239
- check2004ValidFormat(jump[key], Regex.scorm2004.NAVBoolean) &&
240
- check2004ValidFormat(key, Regex.scorm2004.NAVTarget)
355
+ check2004ValidFormat(jump[key], scorm2004_regex.NAVBoolean) &&
356
+ check2004ValidFormat(key, scorm2004_regex.NAVTarget)
241
357
  ) {
242
358
  this._jump[key] = NAVBoolean[jump[key] as keyof typeof NAVBoolean];
243
359
  }
@@ -1,7 +1,7 @@
1
- import APIConstants from "../../constants/api_constants";
2
- import Regex from "../../constants/regex";
3
- import ErrorCodes from "../../constants/error_codes";
4
- import { Scorm2004ValidationError } from "../../exceptions";
1
+ import { scorm2004_constants } from "../../constants/api_constants";
2
+ import { scorm2004_regex } from "../../constants/regex";
3
+ import { scorm2004_errors } from "../../constants/error_codes";
4
+ import { Scorm2004ValidationError } from "../../exceptions/scorm2004_exceptions";
5
5
  import * as Util from "../../utilities";
6
6
  import { BaseRootCMI } from "../common/base_cmi";
7
7
  import { check2004ValidFormat, check2004ValidRange } from "./validation";
@@ -38,7 +38,7 @@ export class CMI extends BaseRootCMI {
38
38
  public objectives: CMIObjectives;
39
39
 
40
40
  private __version = "1.0";
41
- private __children = APIConstants.scorm2004.cmi_children;
41
+ private __children = scorm2004_constants.cmi_children;
42
42
  private _completion_status = "unknown";
43
43
  private _completion_threshold = "";
44
44
  private _credit = "credit";
@@ -71,6 +71,27 @@ export class CMI extends BaseRootCMI {
71
71
  this.objectives?.initialize();
72
72
  }
73
73
 
74
+ /**
75
+ * Called when API is moving to another SCO
76
+ */
77
+ reset() {
78
+ this._initialized = false;
79
+
80
+ this._completion_status = "incomplete";
81
+ this._exit = "";
82
+ this._session_time = "PT0H0M0S";
83
+ this._progress_measure = "";
84
+ this._location = "";
85
+
86
+ this.objectives?.reset(false);
87
+ this.interactions?.reset(true);
88
+
89
+ this.score?.reset();
90
+ this.comments_from_learner?.reset();
91
+ this.comments_from_lms?.reset();
92
+ this.learner_preference?.reset();
93
+ }
94
+
74
95
  /**
75
96
  * Getter for __version
76
97
  * @return {string}
@@ -86,7 +107,7 @@ export class CMI extends BaseRootCMI {
86
107
  * @private
87
108
  */
88
109
  set _version(_version: string) {
89
- throw new Scorm2004ValidationError(ErrorCodes.scorm2004.READ_ONLY_ELEMENT);
110
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
90
111
  }
91
112
 
92
113
  /**
@@ -104,7 +125,7 @@ export class CMI extends BaseRootCMI {
104
125
  * @private
105
126
  */
106
127
  set _children(_children: number) {
107
- throw new Scorm2004ValidationError(ErrorCodes.scorm2004.READ_ONLY_ELEMENT);
128
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
108
129
  }
109
130
 
110
131
  /**
@@ -120,7 +141,7 @@ export class CMI extends BaseRootCMI {
120
141
  * @param {string} completion_status
121
142
  */
122
143
  set completion_status(completion_status: string) {
123
- if (check2004ValidFormat(completion_status, Regex.scorm2004.CMICStatus)) {
144
+ if (check2004ValidFormat(completion_status, scorm2004_regex.CMICStatus)) {
124
145
  this._completion_status = completion_status;
125
146
  }
126
147
  }
@@ -139,9 +160,7 @@ export class CMI extends BaseRootCMI {
139
160
  */
140
161
  set completion_threshold(completion_threshold: string) {
141
162
  if (this.initialized) {
142
- throw new Scorm2004ValidationError(
143
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
144
- );
163
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
145
164
  } else {
146
165
  this._completion_threshold = completion_threshold;
147
166
  }
@@ -161,9 +180,7 @@ export class CMI extends BaseRootCMI {
161
180
  */
162
181
  set credit(credit: string) {
163
182
  if (this.initialized) {
164
- throw new Scorm2004ValidationError(
165
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
166
- );
183
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
167
184
  } else {
168
185
  this._credit = credit;
169
186
  }
@@ -183,9 +200,7 @@ export class CMI extends BaseRootCMI {
183
200
  */
184
201
  set entry(entry: string) {
185
202
  if (this.initialized) {
186
- throw new Scorm2004ValidationError(
187
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
188
- );
203
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
189
204
  } else {
190
205
  this._entry = entry;
191
206
  }
@@ -197,9 +212,7 @@ export class CMI extends BaseRootCMI {
197
212
  */
198
213
  get exit(): string {
199
214
  if (!this.jsonString) {
200
- throw new Scorm2004ValidationError(
201
- ErrorCodes.scorm2004.WRITE_ONLY_ELEMENT,
202
- );
215
+ throw new Scorm2004ValidationError(scorm2004_errors.WRITE_ONLY_ELEMENT);
203
216
  }
204
217
  return this._exit;
205
218
  }
@@ -209,7 +222,7 @@ export class CMI extends BaseRootCMI {
209
222
  * @param {string} exit
210
223
  */
211
224
  set exit(exit: string) {
212
- if (check2004ValidFormat(exit, Regex.scorm2004.CMIExit, true)) {
225
+ if (check2004ValidFormat(exit, scorm2004_regex.CMIExit, true)) {
213
226
  this._exit = exit;
214
227
  }
215
228
  }
@@ -228,9 +241,7 @@ export class CMI extends BaseRootCMI {
228
241
  */
229
242
  set launch_data(launch_data: string) {
230
243
  if (this.initialized) {
231
- throw new Scorm2004ValidationError(
232
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
233
- );
244
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
234
245
  } else {
235
246
  this._launch_data = launch_data;
236
247
  }
@@ -250,9 +261,7 @@ export class CMI extends BaseRootCMI {
250
261
  */
251
262
  set learner_id(learner_id: string) {
252
263
  if (this.initialized) {
253
- throw new Scorm2004ValidationError(
254
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
255
- );
264
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
256
265
  } else {
257
266
  this._learner_id = learner_id;
258
267
  }
@@ -272,9 +281,7 @@ export class CMI extends BaseRootCMI {
272
281
  */
273
282
  set learner_name(learner_name: string) {
274
283
  if (this.initialized) {
275
- throw new Scorm2004ValidationError(
276
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
277
- );
284
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
278
285
  } else {
279
286
  this._learner_name = learner_name;
280
287
  }
@@ -293,7 +300,7 @@ export class CMI extends BaseRootCMI {
293
300
  * @param {string} location
294
301
  */
295
302
  set location(location: string) {
296
- if (check2004ValidFormat(location, Regex.scorm2004.CMIString1000)) {
303
+ if (check2004ValidFormat(location, scorm2004_regex.CMIString1000)) {
297
304
  this._location = location;
298
305
  }
299
306
  }
@@ -312,9 +319,7 @@ export class CMI extends BaseRootCMI {
312
319
  */
313
320
  set max_time_allowed(max_time_allowed: string) {
314
321
  if (this.initialized) {
315
- throw new Scorm2004ValidationError(
316
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
317
- );
322
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
318
323
  } else {
319
324
  this._max_time_allowed = max_time_allowed;
320
325
  }
@@ -334,9 +339,7 @@ export class CMI extends BaseRootCMI {
334
339
  */
335
340
  set mode(mode: string) {
336
341
  if (this.initialized) {
337
- throw new Scorm2004ValidationError(
338
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
339
- );
342
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
340
343
  } else {
341
344
  this._mode = mode;
342
345
  }
@@ -356,8 +359,8 @@ export class CMI extends BaseRootCMI {
356
359
  */
357
360
  set progress_measure(progress_measure: string) {
358
361
  if (
359
- check2004ValidFormat(progress_measure, Regex.scorm2004.CMIDecimal) &&
360
- check2004ValidRange(progress_measure, Regex.scorm2004.progress_range)
362
+ check2004ValidFormat(progress_measure, scorm2004_regex.CMIDecimal) &&
363
+ check2004ValidRange(progress_measure, scorm2004_regex.progress_range)
361
364
  ) {
362
365
  this._progress_measure = progress_measure;
363
366
  }
@@ -377,9 +380,7 @@ export class CMI extends BaseRootCMI {
377
380
  */
378
381
  set scaled_passing_score(scaled_passing_score: string) {
379
382
  if (this.initialized) {
380
- throw new Scorm2004ValidationError(
381
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
382
- );
383
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
383
384
  } else {
384
385
  this._scaled_passing_score = scaled_passing_score;
385
386
  }
@@ -391,9 +392,7 @@ export class CMI extends BaseRootCMI {
391
392
  */
392
393
  get session_time(): string {
393
394
  if (!this.jsonString) {
394
- throw new Scorm2004ValidationError(
395
- ErrorCodes.scorm2004.WRITE_ONLY_ELEMENT,
396
- );
395
+ throw new Scorm2004ValidationError(scorm2004_errors.WRITE_ONLY_ELEMENT);
397
396
  }
398
397
  return this._session_time;
399
398
  }
@@ -403,7 +402,7 @@ export class CMI extends BaseRootCMI {
403
402
  * @param {string} session_time
404
403
  */
405
404
  set session_time(session_time: string) {
406
- if (check2004ValidFormat(session_time, Regex.scorm2004.CMITimespan)) {
405
+ if (check2004ValidFormat(session_time, scorm2004_regex.CMITimespan)) {
407
406
  this._session_time = session_time;
408
407
  }
409
408
  }
@@ -421,7 +420,7 @@ export class CMI extends BaseRootCMI {
421
420
  * @param {string} success_status
422
421
  */
423
422
  set success_status(success_status: string) {
424
- if (check2004ValidFormat(success_status, Regex.scorm2004.CMISStatus)) {
423
+ if (check2004ValidFormat(success_status, scorm2004_regex.CMISStatus)) {
425
424
  this._success_status = success_status;
426
425
  }
427
426
  }
@@ -440,7 +439,7 @@ export class CMI extends BaseRootCMI {
440
439
  */
441
440
  set suspend_data(suspend_data: string) {
442
441
  if (
443
- check2004ValidFormat(suspend_data, Regex.scorm2004.CMIString64000, true)
442
+ check2004ValidFormat(suspend_data, scorm2004_regex.CMIString64000, true)
444
443
  ) {
445
444
  this._suspend_data = suspend_data;
446
445
  }
@@ -460,9 +459,7 @@ export class CMI extends BaseRootCMI {
460
459
  */
461
460
  set time_limit_action(time_limit_action: string) {
462
461
  if (this.initialized) {
463
- throw new Scorm2004ValidationError(
464
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
465
- );
462
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
466
463
  } else {
467
464
  this._time_limit_action = time_limit_action;
468
465
  }
@@ -482,9 +479,7 @@ export class CMI extends BaseRootCMI {
482
479
  */
483
480
  set total_time(total_time: string) {
484
481
  if (this.initialized) {
485
- throw new Scorm2004ValidationError(
486
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
487
- );
482
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
488
483
  } else {
489
484
  this._total_time = total_time;
490
485
  }
@@ -507,7 +502,7 @@ export class CMI extends BaseRootCMI {
507
502
  return Util.addTwoDurations(
508
503
  this._total_time,
509
504
  sessionTime,
510
- Regex.scorm2004.CMITimespan,
505
+ scorm2004_regex.CMITimespan,
511
506
  );
512
507
  }
513
508
 
@@ -1,10 +1,10 @@
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_constants } from "../../constants/api_constants";
3
+ import { scorm2004_errors } from "../../constants/error_codes";
4
+ import { Scorm2004ValidationError } from "../../exceptions/scorm2004_exceptions";
5
5
  import { BaseCMI } from "../common/base_cmi";
6
6
  import { check2004ValidFormat } from "./validation";
7
- import Regex from "../../constants/regex";
7
+ import { scorm2004_regex } from "../../constants/regex";
8
8
 
9
9
  /**
10
10
  * Class representing SCORM 2004's cmi.comments_from_lms object
@@ -16,8 +16,8 @@ export class CMICommentsFromLMS extends CMIArray {
16
16
  */
17
17
  constructor() {
18
18
  super({
19
- children: APIConstants.scorm2004.comments_children,
20
- errorCode: ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
19
+ children: scorm2004_constants.comments_children,
20
+ errorCode: scorm2004_errors.READ_ONLY_ELEMENT,
21
21
  errorClass: Scorm2004ValidationError,
22
22
  });
23
23
  }
@@ -33,8 +33,8 @@ export class CMICommentsFromLearner extends CMIArray {
33
33
  */
34
34
  constructor() {
35
35
  super({
36
- children: APIConstants.scorm2004.comments_children,
37
- errorCode: ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
36
+ children: scorm2004_constants.comments_children,
37
+ errorCode: scorm2004_errors.READ_ONLY_ELEMENT,
38
38
  errorClass: Scorm2004ValidationError,
39
39
  });
40
40
  }
@@ -62,6 +62,13 @@ export class CMICommentsObject extends BaseCMI {
62
62
  this._readOnlyAfterInit = readOnlyAfterInit;
63
63
  }
64
64
 
65
+ /**
66
+ * Called when the API has been reset
67
+ */
68
+ reset(): void {
69
+ this._initialized = false;
70
+ }
71
+
65
72
  /**
66
73
  * Getter for _comment
67
74
  * @return {string}
@@ -76,12 +83,10 @@ export class CMICommentsObject extends BaseCMI {
76
83
  */
77
84
  set comment(comment: string) {
78
85
  if (this.initialized && this._readOnlyAfterInit) {
79
- throw new Scorm2004ValidationError(
80
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
81
- );
86
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
82
87
  } else {
83
88
  if (
84
- check2004ValidFormat(comment, Regex.scorm2004.CMILangString4000, true)
89
+ check2004ValidFormat(comment, scorm2004_regex.CMILangString4000, true)
85
90
  ) {
86
91
  this._comment = comment;
87
92
  }
@@ -102,11 +107,9 @@ export class CMICommentsObject extends BaseCMI {
102
107
  */
103
108
  set location(location: string) {
104
109
  if (this.initialized && this._readOnlyAfterInit) {
105
- throw new Scorm2004ValidationError(
106
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
107
- );
110
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
108
111
  } else {
109
- if (check2004ValidFormat(location, Regex.scorm2004.CMIString250)) {
112
+ if (check2004ValidFormat(location, scorm2004_regex.CMIString250)) {
110
113
  this._location = location;
111
114
  }
112
115
  }
@@ -126,11 +129,9 @@ export class CMICommentsObject extends BaseCMI {
126
129
  */
127
130
  set timestamp(timestamp: string) {
128
131
  if (this.initialized && this._readOnlyAfterInit) {
129
- throw new Scorm2004ValidationError(
130
- ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
131
- );
132
+ throw new Scorm2004ValidationError(scorm2004_errors.READ_ONLY_ELEMENT);
132
133
  } else {
133
- if (check2004ValidFormat(timestamp, Regex.scorm2004.CMITime)) {
134
+ if (check2004ValidFormat(timestamp, scorm2004_regex.CMITime)) {
134
135
  this._timestamp = timestamp;
135
136
  }
136
137
  }