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
@@ -1,161 +0,0 @@
1
- import {describe, it} from 'mocha';
2
- import {expect} from 'chai';
3
-
4
- export const checkFieldConstraintSize = (
5
- {
6
- cmi,
7
- fieldName,
8
- limit,
9
- expectedValue = '',
10
- expectedError,
11
- }) => {
12
- describe(`Field: ${fieldName}`, () => {
13
- it(`Should be able to read from ${fieldName}`, () => {
14
- expect(eval(`${fieldName}`)).to.equal(expectedValue);
15
- });
16
-
17
- it(`Should be able to write upto ${limit} characters to ${fieldName}`,
18
- () => {
19
- expect(() => eval(`${fieldName} = 'x'.repeat(${limit})`)).
20
- to.not.throw();
21
- });
22
-
23
- it(`Should fail to write more than ${limit} characters to ${fieldName}`,
24
- () => {
25
- expect(() => eval(`${fieldName} = 'x'.repeat(${limit + 1})`)).
26
- to.throw().with.property('errorCode', expectedError);
27
- });
28
- });
29
- };
30
-
31
- export const checkReadOnly = (
32
- {
33
- cmi,
34
- fieldName,
35
- expectedValue = '',
36
- expectedError,
37
- }) => {
38
- describe(`Field: ${fieldName}`, () => {
39
- it(`Should be able to read from ${fieldName}`, () => {
40
- expect(eval(`${fieldName}`)).to.equal(expectedValue);
41
- });
42
-
43
- it(`Should fail to write to ${fieldName}`, () => {
44
- expect(() => eval(`${fieldName} = 'xxx'`)).
45
- to.throw().with.property('errorCode', expectedError);
46
- });
47
- });
48
- };
49
-
50
- export const checkRead = (
51
- {
52
- cmi,
53
- fieldName,
54
- expectedValue = '',
55
- }) => {
56
- describe(`Field: ${fieldName}`, () => {
57
- it(`Should be able to read from ${fieldName}`, () => {
58
- expect(eval(`${fieldName}`)).to.equal(expectedValue);
59
- });
60
- });
61
- };
62
-
63
- export const checkReadAndWrite = (
64
- {
65
- cmi,
66
- fieldName,
67
- expectedValue = '',
68
- valueToTest = 'xxx',
69
- }) => {
70
- describe(`Field: ${fieldName}`, () => {
71
- it(`Should be able to read from ${fieldName}`, () => {
72
- expect(eval(`${fieldName}`)).to.equal(expectedValue);
73
- });
74
-
75
- it(`Should successfully write to ${fieldName}`, () => {
76
- expect(() => eval(`${fieldName} = '${valueToTest}'`)).
77
- to.not.throw();
78
- });
79
- });
80
- };
81
-
82
- export const checkWriteOnly = (
83
- {
84
- cmi,
85
- fieldName,
86
- valueToTest = 'xxx',
87
- expectedError,
88
- }) => {
89
- describe(`Field: ${fieldName}`, () => {
90
- it(`Should fail to read from ${fieldName}`, () => {
91
- expect(() => eval(`${fieldName}`)).
92
- to.throw().with.property('errorCode', expectedError);
93
- });
94
-
95
- it(`Should successfully write to ${fieldName}`, () => {
96
- expect(() => eval(`${fieldName} = '${valueToTest}'`)).to.not.throw();
97
- });
98
- });
99
- };
100
-
101
- export const checkWrite = (
102
- {
103
- cmi,
104
- fieldName,
105
- valueToTest = 'xxx',
106
- }) => {
107
- describe(`Field: ${fieldName}`, () => {
108
- it(`Should successfully write to ${fieldName}`, () => {
109
- expect(() => eval(`${fieldName} = '${valueToTest}'`)).to.not.throw();
110
- });
111
- });
112
- };
113
-
114
- export const checkValidValues = (
115
- {
116
- cmi,
117
- fieldName,
118
- validValues,
119
- invalidValues,
120
- }) => {
121
- describe(`Field: ${fieldName}`, () => {
122
- for (const idx in validValues) {
123
- if ({}.hasOwnProperty.call(validValues, idx)) {
124
- it(`Should successfully write '${validValues[idx]}' to ${fieldName}`,
125
- () => {
126
- expect(() => eval(`${fieldName} = '${validValues[idx]}'`)).
127
- to.not.throw();
128
- });
129
- }
130
- }
131
-
132
- for (const idx in invalidValues) {
133
- if ({}.hasOwnProperty.call(invalidValues, idx)) {
134
- it(`Should fail to write '${invalidValues[idx]}' to ${fieldName}`,
135
- () => {
136
- expect(() => eval(`${fieldName} = '${invalidValues[idx]}'`)).
137
- to.throw();
138
- });
139
- }
140
- }
141
- });
142
- };
143
-
144
- export const checkGetCurrentTotalTime = (
145
- {
146
- cmi: cmi,
147
- totalFieldName,
148
- sessionFieldName,
149
- startingTotal,
150
- sessionTime,
151
- expectedTotal,
152
- }) => {
153
- it(`Should return ${expectedTotal} with a starting time of ${startingTotal} and a session time of ${sessionTime}`,
154
- () => {
155
- eval(`${totalFieldName} = '${startingTotal}'`);
156
- eval(`${sessionFieldName} = '${sessionTime}'`);
157
- expect(
158
- cmi.getCurrentTotalTime(),
159
- ).to.equal(expectedTotal);
160
- });
161
- };
@@ -1,71 +0,0 @@
1
- import {describe, it} from 'mocha';
2
- import {expect} from 'chai';
3
- import {ValidationError, AICCValidationError, Scorm12ValidationError, Scorm2004ValidationError} from '../src/exceptions';
4
- import APIConstants from '../src/constants/api_constants';
5
-
6
- const scorm12_errors = APIConstants.scorm12.error_descriptions;
7
- const aicc_errors = APIConstants.aicc.error_descriptions;
8
- const scorm2004_errors = APIConstants.scorm2004.error_descriptions;
9
-
10
- const checkValidationMessage = (
11
- {
12
- errorClass,
13
- errorCodes,
14
- error_messages,
15
- }
16
- ) => {
17
- describe(`ValidationError: ${typeof errorClass}`, () => {
18
- it(`${typeof errorClass} should return general errorCode number when not recognized`, () => {
19
- expect(
20
- new errorClass.prototype.constructor(53).errorCode,
21
- ).to.equal(101);
22
- });
23
- it(`${typeof errorClass} should return general message when not recognized`, () => {
24
- expect(
25
- new errorClass.prototype.constructor(53).message,
26
- ).to.equal(error_messages['101'].basicMessage);
27
- });
28
-
29
- for (let i = 0; i < errorCodes.length; i++) {
30
- const errorCode = errorCodes[i];
31
- it(`${typeof errorClass} should return proper errorCode number when recognized`, () => {
32
- expect(
33
- new errorClass.prototype.constructor(errorCode).errorCode,
34
- ).to.equal(errorCode);
35
- });
36
- it(`${typeof errorClass} should return proper ${errorCode} message`, () => {
37
- expect(
38
- new errorClass.prototype.constructor(errorCode).message,
39
- ).to.equal(error_messages[String(errorCode)].basicMessage);
40
- });
41
- }
42
- });
43
- };
44
-
45
- describe('Exception Tests', () => {
46
- it('ValidationException should return message string', () => {
47
- expect(
48
- new ValidationError(0, 'Error Message').message,
49
- ).to.equal('Error Message');
50
- });
51
- it('ValidationException should return errorCode number', () => {
52
- expect(
53
- new ValidationError(0, 'Error Message').errorCode,
54
- ).to.equal(0);
55
- });
56
- checkValidationMessage({
57
- errorClass: AICCValidationError,
58
- errorCodes: [101, 201, 202, 203, 301, 401, 402, 403, 404, 405, 407, 408],
59
- error_messages: aicc_errors,
60
- });
61
- checkValidationMessage({
62
- errorClass: Scorm12ValidationError,
63
- errorCodes: [101, 201, 202, 203, 301, 401, 402, 403, 404, 405, 407, 408],
64
- error_messages: scorm12_errors,
65
- });
66
- checkValidationMessage({
67
- errorClass: Scorm2004ValidationError,
68
- errorCodes: [0, 101, 102, 103, 104, 111, 112, 113, 122, 123, 132, 133, 142, 143, 201, 301, 351, 391, 401, 402, 403, 404, 405, 406, 407, 408],
69
- error_messages: scorm2004_errors,
70
- });
71
- });
@@ -1,353 +0,0 @@
1
- const common_values = {
2
- valid0To1Range: [
3
- '0.0',
4
- '0.25',
5
- '0.5',
6
- '1.0',
7
- ],
8
- invalid0To1Range: [
9
- '-1',
10
- '-0.1',
11
- '1.1',
12
- '.25',
13
- ],
14
-
15
- valid0To100Range: [
16
- '1',
17
- '50',
18
- '100',
19
- ],
20
- invalid0To100Range: [
21
- 'invalid',
22
- 'a100',
23
- '-1',
24
- ],
25
-
26
- validScaledRange: [
27
- '1',
28
- '0.5',
29
- '0',
30
- '-0.5',
31
- '-1',
32
- ],
33
- invalidScaledRange: [
34
- '-101',
35
- '25.1',
36
- '50.5',
37
- '75',
38
- '100',
39
- ],
40
-
41
- validIntegerScaledRange: [
42
- '1',
43
- '0',
44
- '-1',
45
- ],
46
- invalidIntegerScaledRange: [
47
- '-101',
48
- '-0.5',
49
- '0.5',
50
- '25.1',
51
- '50.5',
52
- '75',
53
- '100',
54
- ],
55
- };
56
-
57
- export const scorm12_values = {
58
- ...common_values, ...{
59
- validResult: [
60
- 'correct',
61
- 'wrong',
62
- 'unanticipated',
63
- 'neutral',
64
- ],
65
- invalidResult: [
66
- '-10000',
67
- '10000',
68
- 'invalid',
69
- 'incorrect',
70
- ],
71
- validLessonStatus: [
72
- 'passed',
73
- 'completed',
74
- 'failed',
75
- 'incomplete',
76
- 'browsed',
77
- ],
78
- invalidLessonStatus: [
79
- 'Passed',
80
- 'P',
81
- 'F',
82
- 'p',
83
- 'true',
84
- 'false',
85
- 'complete',
86
- ],
87
-
88
- validExit: [
89
- 'time-out',
90
- 'suspend',
91
- 'logout',
92
- '',
93
- ],
94
- invalidExit: [
95
- 'close',
96
- 'exit',
97
- 'crash',
98
- ],
99
-
100
- validType: [
101
- 'true-false',
102
- 'choice',
103
- 'fill-in',
104
- 'matching',
105
- 'performance',
106
- 'sequencing',
107
- 'likert',
108
- 'numeric',
109
- ],
110
- invalidType: [
111
- 'correct',
112
- 'wrong',
113
- 'logout',
114
- ],
115
-
116
- validSpeedRange: [
117
- '1',
118
- '50',
119
- '100',
120
- '-1',
121
- '-50',
122
- '-100',
123
- ],
124
- invalidSpeedRange: [
125
- 'invalid',
126
- 'a100',
127
- '-101',
128
- '101',
129
- '-100000',
130
- '100000',
131
- ],
132
-
133
- validScoreRange: [
134
- '1',
135
- '50.25',
136
- '70',
137
- '100',
138
- 1,
139
- 50.25,
140
- 70,
141
- 100,
142
- ],
143
- invalidScoreRange: [
144
- 'invalid',
145
- 'a100',
146
- '-1',
147
- '101',
148
- '-100000',
149
- '100000',
150
- ],
151
- invalid0To100Range: [
152
- 'invalid',
153
- 'a100',
154
- '-2',
155
- ],
156
-
157
- validTime: [
158
- '10:06:57',
159
- '23:59:59',
160
- '00:00:00',
161
- ],
162
- invalidTime: [
163
- '47:59:59',
164
- '00:00:01.56',
165
- '06:5:13',
166
- '23:59:59.123',
167
- 'P1DT23H59M59S',
168
- ],
169
-
170
- validTimespan: [
171
- '10:06:57',
172
- '00:00:01.56',
173
- '23:59:59',
174
- '47:59:59',
175
- ],
176
- invalidTimespan: [
177
- '06:5:13',
178
- '23:59:59.123',
179
- 'P1DT23H59M59S',
180
- ],
181
- },
182
- };
183
-
184
- export const scorm2004_values = {
185
- ...common_values, ...{
186
- // valid field values
187
- validResult: [
188
- 'correct',
189
- 'incorrect',
190
- 'unanticipated',
191
- 'neutral',
192
- ],
193
- invalidResult: [
194
- '-10000',
195
- '10000',
196
- 'invalid',
197
- 'wrong',
198
- ],
199
- validTimestamps: [
200
- '2019-06-25',
201
- '2019-06-25T23:59',
202
- '2019-06-25T23:59:59.99',
203
- '1970-01-01',
204
- ],
205
- invalidTimestamps: [
206
- '2019-06-25T',
207
- '2019-06-25T23:59:59.999',
208
- '2019-06-25T25:59:59.99',
209
- '2019-13-31',
210
- '1969-12-31',
211
- '-00:00:30',
212
- '0:50:30',
213
- '23:00:30.',
214
- ],
215
-
216
- validCStatus: [
217
- 'completed',
218
- 'incomplete',
219
- 'not attempted',
220
- 'unknown',
221
- ],
222
- invalidCStatus: [
223
- 'complete',
224
- 'passed',
225
- 'failed',
226
- ],
227
-
228
- validSStatus: [
229
- 'passed',
230
- 'failed',
231
- 'unknown',
232
- ],
233
- invalidSStatus: [
234
- 'complete',
235
- 'incomplete',
236
- 'P',
237
- 'f',
238
- ],
239
-
240
- validExit: [
241
- 'time-out',
242
- 'suspend',
243
- 'logout',
244
- 'normal',
245
- '',
246
- ],
247
- invalidExit: [
248
- 'close',
249
- 'exit',
250
- 'crash',
251
- ],
252
-
253
- validType: [
254
- 'true-false',
255
- 'choice',
256
- 'fill-in',
257
- 'long-fill-in',
258
- 'matching',
259
- 'performance',
260
- 'sequencing',
261
- 'likert',
262
- 'numeric',
263
- 'other',
264
- ],
265
- invalidType: [
266
- 'correct',
267
- 'wrong',
268
- 'logout',
269
- ],
270
-
271
- validScoreRange: [
272
- '1',
273
- '50',
274
- '100',
275
- '-10000',
276
- '-1',
277
- '10000',
278
- ],
279
- invalidScoreRange: [
280
- 'invalid',
281
- 'a100',
282
- '-100000',
283
- '100000',
284
- ],
285
-
286
- validISO8601Durations: [
287
- 'P1Y34DT23H45M15S',
288
- 'PT1M45S',
289
- 'P0S',
290
- 'PT75M',
291
- ],
292
- invalidISO8601Durations: [
293
- '00:08:45',
294
- '-P1H',
295
- '1y45D',
296
- '0',
297
- ],
298
-
299
- validComment: [
300
- '{lang=en-98} learner comment',
301
- '{lang=eng-98-9} learner comment',
302
- '{lang=eng-98-9fhgj}' + 'x'.repeat(4000),
303
- 'learner comment',
304
- 'learner comment}',
305
- '{lang=i-xx}',
306
- '{lang=i}',
307
- '',
308
- ],
309
- invalidComment: [
310
- '{lang=i-}',
311
- '{lang=i-x}',
312
- '{lang=eng-98-9fhgj}{ learner comment',
313
- '{learner comment',
314
- '{lang=eng-98-9fhgj}' + 'x'.repeat(4001),
315
- '{lang=eng-98-9fhgj}{' + 'x'.repeat(3999),
316
- ],
317
-
318
- validDescription: [
319
- '{lang=en-98} learner comment',
320
- '{lang=eng-98-9} learner comment',
321
- '{lang=eng-98-9fhgj}' + 'x'.repeat(250),
322
- 'learner comment',
323
- 'learner comment}',
324
- '{lang=i-xx}',
325
- '{lang=i}',
326
- '',
327
- ],
328
- invalidDescription: [
329
- '{lang=i-}',
330
- '{lang=i-x}',
331
- '{lang=eng-98-9fhgj}{ learner comment',
332
- '{learner comment',
333
- '{lang=eng-98-9fhgj}' + 'x'.repeat(251),
334
- '{lang=eng-98-9fhgj}{' + 'x'.repeat(249),
335
- ],
336
-
337
- validNavRequest: [
338
- 'previous',
339
- 'continue',
340
- 'exit',
341
- 'exitAll',
342
- 'abandon',
343
- 'abandonAll',
344
- 'suspendAll',
345
- ],
346
- invalidNavRequest: [
347
- 'close',
348
- 'quit',
349
- 'next',
350
- 'before',
351
- ],
352
- },
353
- };