scorm-again 1.7.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/.babelrc +18 -7
  2. package/.github/dependabot.yml +5 -0
  3. package/.github/workflows/main.yml +79 -0
  4. package/.github/workflows/stale.yml +14 -0
  5. package/.jsdoc.json +4 -5
  6. package/.mocharc.json +8 -0
  7. package/.run/{Mocha Unit Tests.run.xml → Mocha Unit Tests (watch).run.xml } +6 -3
  8. package/.run/Template Mocha.run.xml +17 -0
  9. package/CONTRIBUTING.md +1 -1
  10. package/README.md +183 -71
  11. package/dist/aicc.js +3822 -7030
  12. package/dist/aicc.js.map +1 -1
  13. package/dist/aicc.min.js +2 -40
  14. package/dist/aicc.min.js.map +1 -0
  15. package/dist/scorm-again.js +5965 -10498
  16. package/dist/scorm-again.js.map +1 -1
  17. package/dist/scorm-again.min.js +2 -52
  18. package/dist/scorm-again.min.js.map +1 -0
  19. package/dist/scorm12.js +3028 -5373
  20. package/dist/scorm12.js.map +1 -1
  21. package/dist/scorm12.min.js +2 -34
  22. package/dist/scorm12.min.js.map +1 -0
  23. package/dist/scorm2004.js +4054 -6693
  24. package/dist/scorm2004.js.map +1 -1
  25. package/dist/scorm2004.min.js +2 -40
  26. package/dist/scorm2004.min.js.map +1 -0
  27. package/eslint.config.js +21 -0
  28. package/package.json +76 -34
  29. package/results.json +34254 -0
  30. package/src/AICC.ts +72 -0
  31. package/src/BaseAPI.ts +1300 -0
  32. package/src/Scorm12API.ts +387 -0
  33. package/src/Scorm2004API.ts +688 -0
  34. package/src/cmi/aicc/attempts.ts +94 -0
  35. package/src/cmi/aicc/cmi.ts +100 -0
  36. package/src/cmi/aicc/core.ts +360 -0
  37. package/src/cmi/aicc/evaluation.ts +157 -0
  38. package/src/cmi/aicc/paths.ts +180 -0
  39. package/src/cmi/aicc/student_data.ts +86 -0
  40. package/src/cmi/aicc/student_demographics.ts +367 -0
  41. package/src/cmi/aicc/student_preferences.ts +176 -0
  42. package/src/cmi/aicc/tries.ts +116 -0
  43. package/src/cmi/aicc/validation.ts +25 -0
  44. package/src/cmi/common/array.ts +77 -0
  45. package/src/cmi/common/base_cmi.ts +46 -0
  46. package/src/cmi/common/score.ts +203 -0
  47. package/src/cmi/common/validation.ts +60 -0
  48. package/src/cmi/scorm12/cmi.ts +224 -0
  49. package/src/cmi/scorm12/interactions.ts +368 -0
  50. package/src/cmi/scorm12/nav.ts +54 -0
  51. package/src/cmi/scorm12/objectives.ts +112 -0
  52. package/src/cmi/scorm12/student_data.ts +130 -0
  53. package/src/cmi/scorm12/student_preference.ts +158 -0
  54. package/src/cmi/scorm12/validation.ts +48 -0
  55. package/src/cmi/scorm2004/adl.ts +272 -0
  56. package/src/cmi/scorm2004/cmi.ts +599 -0
  57. package/src/cmi/scorm2004/comments.ts +163 -0
  58. package/src/cmi/scorm2004/interactions.ts +466 -0
  59. package/src/cmi/scorm2004/learner_preference.ts +152 -0
  60. package/src/cmi/scorm2004/objectives.ts +212 -0
  61. package/src/cmi/scorm2004/score.ts +78 -0
  62. package/src/cmi/scorm2004/validation.ts +42 -0
  63. package/src/constants/api_constants.ts +318 -0
  64. package/src/constants/default_settings.ts +81 -0
  65. package/src/constants/enums.ts +5 -0
  66. package/src/constants/error_codes.ts +88 -0
  67. package/src/constants/language_constants.ts +394 -0
  68. package/src/constants/regex.ts +97 -0
  69. package/src/constants/{response_constants.js → response_constants.ts} +69 -62
  70. package/src/exceptions.ts +154 -0
  71. package/src/exports/aicc.js +1 -1
  72. package/src/exports/scorm-again.js +3 -3
  73. package/src/exports/scorm12.js +1 -1
  74. package/src/exports/scorm2004.js +1 -1
  75. package/src/helpers/scheduled_commit.ts +42 -0
  76. package/src/interfaces/IBaseAPI.ts +35 -0
  77. package/src/types/api_types.ts +32 -0
  78. package/src/utilities/debounce.ts +31 -0
  79. package/src/utilities.ts +338 -0
  80. package/tea.yaml +6 -0
  81. package/test/{AICC.spec.js → AICC.spec.ts} +79 -71
  82. package/test/Scorm12API.spec.ts +833 -0
  83. package/test/Scorm2004API.spec.ts +1298 -0
  84. package/test/api_helpers.ts +176 -0
  85. package/test/cmi/aicc_cmi.spec.ts +845 -0
  86. package/test/cmi/{scorm12_cmi.spec.js → scorm12_cmi.spec.ts} +253 -271
  87. package/test/cmi/scorm2004_cmi.spec.ts +1031 -0
  88. package/test/cmi_helpers.ts +207 -0
  89. package/test/exceptions.spec.ts +79 -0
  90. package/test/field_values.ts +202 -0
  91. package/test/types/api_types.spec.ts +126 -0
  92. package/test/utilities/debounce.spec.ts +56 -0
  93. package/test/utilities.spec.ts +322 -0
  94. package/tsconfig.json +18 -0
  95. package/webpack.config.js +65 -0
  96. package/.circleci/config.yml +0 -99
  97. package/.codeclimate.yml +0 -7
  98. package/.eslintrc.js +0 -36
  99. package/src/.flowconfig +0 -11
  100. package/src/AICC.js +0 -68
  101. package/src/BaseAPI.js +0 -1275
  102. package/src/Scorm12API.js +0 -308
  103. package/src/Scorm2004API.js +0 -572
  104. package/src/cmi/aicc_cmi.js +0 -1141
  105. package/src/cmi/common.js +0 -328
  106. package/src/cmi/scorm12_cmi.js +0 -1312
  107. package/src/cmi/scorm2004_cmi.js +0 -1692
  108. package/src/constants/api_constants.js +0 -218
  109. package/src/constants/error_codes.js +0 -87
  110. package/src/constants/language_constants.js +0 -76
  111. package/src/constants/regex.js +0 -84
  112. package/src/exceptions.js +0 -104
  113. package/src/utilities.js +0 -242
  114. package/test/Scorm12API.spec.js +0 -528
  115. package/test/Scorm2004API.spec.js +0 -775
  116. package/test/abstract_classes.spec.js +0 -17
  117. package/test/api_helpers.js +0 -128
  118. package/test/cmi/aicc_cmi.spec.js +0 -684
  119. package/test/cmi/scorm2004_cmi.spec.js +0 -1066
  120. package/test/cmi_helpers.js +0 -161
  121. package/test/exceptions.spec.js +0 -71
  122. package/test/field_values.js +0 -353
  123. package/test/utilities.spec.js +0 -339
  124. package/webpack.js +0 -78
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Class for SCORM 2004's cmi.learner_preference object
3
+ */
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";
8
+ import { check2004ValidFormat, check2004ValidRange } from "./validation";
9
+ import Regex from "../../constants/regex";
10
+
11
+ export class CMILearnerPreference extends BaseCMI {
12
+ private __children = APIConstants.scorm2004.student_preference_children;
13
+ private _audio_level = "1";
14
+ private _language = "";
15
+ private _delivery_speed = "1";
16
+ private _audio_captioning = "0";
17
+
18
+ /**
19
+ * Constructor for cmi.learner_preference
20
+ */
21
+ constructor() {
22
+ super();
23
+ }
24
+
25
+ /**
26
+ * Getter for __children
27
+ * @return {string}
28
+ * @private
29
+ */
30
+ get _children(): string {
31
+ return this.__children;
32
+ }
33
+
34
+ /**
35
+ * Setter for __children. Just throws an error.
36
+ * @param {string} _children
37
+ * @private
38
+ */
39
+ set _children(_children: string) {
40
+ throw new Scorm2004ValidationError(ErrorCodes.scorm2004.READ_ONLY_ELEMENT);
41
+ }
42
+
43
+ /**
44
+ * Getter for _audio_level
45
+ * @return {string}
46
+ */
47
+ get audio_level(): string {
48
+ return this._audio_level;
49
+ }
50
+
51
+ /**
52
+ * Setter for _audio_level
53
+ * @param {string} audio_level
54
+ */
55
+ set audio_level(audio_level: string) {
56
+ if (
57
+ check2004ValidFormat(audio_level, Regex.scorm2004.CMIDecimal) &&
58
+ check2004ValidRange(audio_level, Regex.scorm2004.audio_range)
59
+ ) {
60
+ this._audio_level = audio_level;
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Getter for _language
66
+ * @return {string}
67
+ */
68
+ get language(): string {
69
+ return this._language;
70
+ }
71
+
72
+ /**
73
+ * Setter for _language
74
+ * @param {string} language
75
+ */
76
+ set language(language: string) {
77
+ if (check2004ValidFormat(language, Regex.scorm2004.CMILang)) {
78
+ this._language = language;
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Getter for _delivery_speed
84
+ * @return {string}
85
+ */
86
+ get delivery_speed(): string {
87
+ return this._delivery_speed;
88
+ }
89
+
90
+ /**
91
+ * Setter for _delivery_speed
92
+ * @param {string} delivery_speed
93
+ */
94
+ set delivery_speed(delivery_speed: string) {
95
+ if (
96
+ check2004ValidFormat(delivery_speed, Regex.scorm2004.CMIDecimal) &&
97
+ check2004ValidRange(delivery_speed, Regex.scorm2004.speed_range)
98
+ ) {
99
+ this._delivery_speed = delivery_speed;
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Getter for _audio_captioning
105
+ * @return {string}
106
+ */
107
+ get audio_captioning(): string {
108
+ return this._audio_captioning;
109
+ }
110
+
111
+ /**
112
+ * Setter for _audio_captioning
113
+ * @param {string} audio_captioning
114
+ */
115
+ set audio_captioning(audio_captioning: string) {
116
+ if (
117
+ check2004ValidFormat(audio_captioning, Regex.scorm2004.CMISInteger) &&
118
+ check2004ValidRange(audio_captioning, Regex.scorm2004.text_range)
119
+ ) {
120
+ this._audio_captioning = audio_captioning;
121
+ }
122
+ }
123
+
124
+ /**
125
+ * toJSON for cmi.learner_preference
126
+ *
127
+ * @return {
128
+ * {
129
+ * audio_level: string,
130
+ * language: string,
131
+ * delivery_speed: string,
132
+ * audio_captioning: string
133
+ * }
134
+ * }
135
+ */
136
+ toJSON(): {
137
+ audio_level: string;
138
+ language: string;
139
+ delivery_speed: string;
140
+ audio_captioning: string;
141
+ } {
142
+ this.jsonString = true;
143
+ const result = {
144
+ audio_level: this.audio_level,
145
+ language: this.language,
146
+ delivery_speed: this.delivery_speed,
147
+ audio_captioning: this.audio_captioning,
148
+ };
149
+ delete this.jsonString;
150
+ return result;
151
+ }
152
+ }
@@ -0,0 +1,212 @@
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";
5
+ import { BaseCMI } from "../common/base_cmi";
6
+ import { Scorm2004CMIScore } from "./score";
7
+ import { check2004ValidFormat, check2004ValidRange } from "./validation";
8
+ import Regex from "../../constants/regex";
9
+
10
+ /**
11
+ * Class representing SCORM 2004's `cmi.objectives` object
12
+ * @extends CMIArray
13
+ */
14
+ export class CMIObjectives extends CMIArray {
15
+ /**
16
+ * Constructor for `cmi.objectives` Array
17
+ */
18
+ constructor() {
19
+ super({
20
+ children: APIConstants.scorm2004.objectives_children,
21
+ errorCode: ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
22
+ errorClass: Scorm2004ValidationError,
23
+ });
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Class for SCORM 2004's cmi.objectives.n object
29
+ */
30
+ export class CMIObjectivesObject extends BaseCMI {
31
+ private _id = "";
32
+ private _success_status = "unknown";
33
+ private _completion_status = "unknown";
34
+ private _progress_measure = "";
35
+ private _description = "";
36
+
37
+ /**
38
+ * Constructor for cmi.objectives.n
39
+ */
40
+ constructor() {
41
+ super();
42
+ this.score = new Scorm2004CMIScore();
43
+ }
44
+
45
+ public score: Scorm2004CMIScore;
46
+
47
+ /**
48
+ * Called when the API has been initialized after the CMI has been created
49
+ */
50
+ initialize() {
51
+ super.initialize();
52
+ this.score?.initialize();
53
+ }
54
+
55
+ /**
56
+ * Getter for _id
57
+ * @return {string}
58
+ */
59
+ get id(): string {
60
+ return this._id;
61
+ }
62
+
63
+ /**
64
+ * Setter for _id
65
+ * @param {string} id
66
+ */
67
+ set id(id: string) {
68
+ if (check2004ValidFormat(id, Regex.scorm2004.CMILongIdentifier)) {
69
+ this._id = id;
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Getter for _success_status
75
+ * @return {string}
76
+ */
77
+ get success_status(): string {
78
+ return this._success_status;
79
+ }
80
+
81
+ /**
82
+ * Setter for _success_status
83
+ * @param {string} success_status
84
+ */
85
+ set success_status(success_status: string) {
86
+ if (this.initialized && this._id === "") {
87
+ throw new Scorm2004ValidationError(
88
+ ErrorCodes.scorm2004.DEPENDENCY_NOT_ESTABLISHED,
89
+ );
90
+ } else {
91
+ if (check2004ValidFormat(success_status, Regex.scorm2004.CMISStatus)) {
92
+ this._success_status = success_status;
93
+ }
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Getter for _completion_status
99
+ * @return {string}
100
+ */
101
+ get completion_status(): string {
102
+ return this._completion_status;
103
+ }
104
+
105
+ /**
106
+ * Setter for _completion_status
107
+ * @param {string} completion_status
108
+ */
109
+ set completion_status(completion_status: string) {
110
+ if (this.initialized && this._id === "") {
111
+ throw new Scorm2004ValidationError(
112
+ ErrorCodes.scorm2004.DEPENDENCY_NOT_ESTABLISHED,
113
+ );
114
+ } else {
115
+ if (check2004ValidFormat(completion_status, Regex.scorm2004.CMICStatus)) {
116
+ this._completion_status = completion_status;
117
+ }
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Getter for _progress_measure
123
+ * @return {string}
124
+ */
125
+ get progress_measure(): string {
126
+ return this._progress_measure;
127
+ }
128
+
129
+ /**
130
+ * Setter for _progress_measure
131
+ * @param {string} progress_measure
132
+ */
133
+ set progress_measure(progress_measure: string) {
134
+ if (this.initialized && this._id === "") {
135
+ throw new Scorm2004ValidationError(
136
+ ErrorCodes.scorm2004.DEPENDENCY_NOT_ESTABLISHED,
137
+ );
138
+ } else {
139
+ if (
140
+ check2004ValidFormat(progress_measure, Regex.scorm2004.CMIDecimal) &&
141
+ check2004ValidRange(progress_measure, Regex.scorm2004.progress_range)
142
+ ) {
143
+ this._progress_measure = progress_measure;
144
+ }
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Getter for _description
150
+ * @return {string}
151
+ */
152
+ get description(): string {
153
+ return this._description;
154
+ }
155
+
156
+ /**
157
+ * Setter for _description
158
+ * @param {string} description
159
+ */
160
+ set description(description: string) {
161
+ if (this.initialized && this._id === "") {
162
+ throw new Scorm2004ValidationError(
163
+ ErrorCodes.scorm2004.DEPENDENCY_NOT_ESTABLISHED,
164
+ );
165
+ } else {
166
+ if (
167
+ check2004ValidFormat(
168
+ description,
169
+ Regex.scorm2004.CMILangString250,
170
+ true,
171
+ )
172
+ ) {
173
+ this._description = description;
174
+ }
175
+ }
176
+ }
177
+
178
+ /**
179
+ * toJSON for cmi.objectives.n
180
+ *
181
+ * @return {
182
+ * {
183
+ * id: string,
184
+ * success_status: string,
185
+ * completion_status: string,
186
+ * progress_measure: string,
187
+ * description: string,
188
+ * score: Scorm2004CMIScore
189
+ * }
190
+ * }
191
+ */
192
+ toJSON(): {
193
+ id: string;
194
+ success_status: string;
195
+ completion_status: string;
196
+ progress_measure: string;
197
+ description: string;
198
+ score: Scorm2004CMIScore;
199
+ } {
200
+ this.jsonString = true;
201
+ const result = {
202
+ id: this.id,
203
+ success_status: this.success_status,
204
+ completion_status: this.completion_status,
205
+ progress_measure: this.progress_measure,
206
+ description: this.description,
207
+ score: this.score,
208
+ };
209
+ delete this.jsonString;
210
+ return result;
211
+ }
212
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Class for SCORM 2004's cmi *.score object
3
+ */
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";
9
+ import { check2004ValidFormat, check2004ValidRange } from "./validation";
10
+
11
+ export class Scorm2004CMIScore extends CMIScore {
12
+ private _scaled = "";
13
+
14
+ /**
15
+ * Constructor for cmi *.score
16
+ */
17
+ constructor() {
18
+ super({
19
+ score_children: APIConstants.scorm2004.score_children,
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,
25
+ errorClass: Scorm2004ValidationError,
26
+ });
27
+ }
28
+
29
+ /**
30
+ * Getter for _scaled
31
+ * @return {string}
32
+ */
33
+ get scaled(): string {
34
+ return this._scaled;
35
+ }
36
+
37
+ /**
38
+ * Setter for _scaled
39
+ * @param {string} scaled
40
+ */
41
+ set scaled(scaled: string) {
42
+ if (
43
+ check2004ValidFormat(scaled, Regex.scorm2004.CMIDecimal) &&
44
+ check2004ValidRange(scaled, Regex.scorm2004.scaled_range)
45
+ ) {
46
+ this._scaled = scaled;
47
+ }
48
+ }
49
+
50
+ /**
51
+ * toJSON for cmi *.score
52
+ *
53
+ * @return {
54
+ * {
55
+ * scaled: string,
56
+ * raw: string,
57
+ * min: string,
58
+ * max: string
59
+ * }
60
+ * }
61
+ */
62
+ toJSON(): {
63
+ scaled: string;
64
+ raw: string;
65
+ min: string;
66
+ max: string;
67
+ } {
68
+ this.jsonString = true;
69
+ const result = {
70
+ scaled: this.scaled,
71
+ raw: this.raw,
72
+ min: this.min,
73
+ max: this.max,
74
+ };
75
+ delete this.jsonString;
76
+ return result;
77
+ }
78
+ }
@@ -0,0 +1,42 @@
1
+ import { checkValidFormat, checkValidRange } from "../common/validation";
2
+ import ErrorCodes from "../../constants/error_codes";
3
+ import { Scorm2004ValidationError } from "../../exceptions";
4
+
5
+ /**
6
+ * Helper method, no reason to have to pass the same error codes every time
7
+ * @param {string} value
8
+ * @param {string} regexPattern
9
+ * @param {boolean} allowEmptyString
10
+ * @return {boolean}
11
+ */
12
+ export function check2004ValidFormat(
13
+ value: string,
14
+ regexPattern: string,
15
+ allowEmptyString?: boolean,
16
+ ): boolean {
17
+ return checkValidFormat(
18
+ value,
19
+ regexPattern,
20
+ ErrorCodes.scorm2004.TYPE_MISMATCH,
21
+ Scorm2004ValidationError,
22
+ allowEmptyString,
23
+ );
24
+ }
25
+
26
+ /**
27
+ * Helper method, no reason to have to pass the same error codes every time
28
+ * @param {string} value
29
+ * @param {string} rangePattern
30
+ * @return {boolean}
31
+ */
32
+ export function check2004ValidRange(
33
+ value: string,
34
+ rangePattern: string,
35
+ ): boolean {
36
+ return checkValidRange(
37
+ value,
38
+ rangePattern,
39
+ ErrorCodes.scorm2004.VALUE_OUT_OF_RANGE,
40
+ Scorm2004ValidationError,
41
+ );
42
+ }