scorm-again 2.4.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +23 -23
  2. package/dist/aicc.js +676 -493
  3. package/dist/aicc.js.map +1 -1
  4. package/dist/aicc.min.js +1 -1
  5. package/dist/aicc.min.js.map +1 -1
  6. package/dist/esm/aicc.js +692 -496
  7. package/dist/esm/aicc.js.map +1 -1
  8. package/dist/esm/aicc.min.js +1 -1
  9. package/dist/esm/aicc.min.js.map +1 -1
  10. package/dist/esm/scorm-again.js +1151 -743
  11. package/dist/esm/scorm-again.js.map +1 -1
  12. package/dist/esm/scorm-again.min.js +1 -1
  13. package/dist/esm/scorm-again.min.js.map +1 -1
  14. package/dist/esm/scorm12.js +534 -401
  15. package/dist/esm/scorm12.js.map +1 -1
  16. package/dist/esm/scorm12.min.js +1 -1
  17. package/dist/esm/scorm12.min.js.map +1 -1
  18. package/dist/esm/scorm2004.js +712 -465
  19. package/dist/esm/scorm2004.js.map +1 -1
  20. package/dist/esm/scorm2004.min.js +1 -1
  21. package/dist/esm/scorm2004.min.js.map +1 -1
  22. package/dist/scorm-again.js +1127 -731
  23. package/dist/scorm-again.js.map +1 -1
  24. package/dist/scorm-again.min.js +1 -1
  25. package/dist/scorm-again.min.js.map +1 -1
  26. package/dist/scorm12.js +521 -400
  27. package/dist/scorm12.js.map +1 -1
  28. package/dist/scorm12.min.js +1 -1
  29. package/dist/scorm12.min.js.map +1 -1
  30. package/dist/scorm2004.js +698 -464
  31. package/dist/scorm2004.js.map +1 -1
  32. package/dist/scorm2004.min.js +1 -1
  33. package/dist/scorm2004.min.js.map +1 -1
  34. package/package.json +15 -15
  35. package/src/AICC.ts +3 -0
  36. package/src/BaseAPI.ts +60 -95
  37. package/src/Scorm12API.ts +14 -14
  38. package/src/Scorm2004API.ts +107 -37
  39. package/src/cmi/aicc/attempts.ts +22 -12
  40. package/src/cmi/aicc/cmi.ts +2 -2
  41. package/src/cmi/aicc/core.ts +44 -26
  42. package/src/cmi/aicc/evaluation.ts +31 -12
  43. package/src/cmi/aicc/paths.ts +29 -15
  44. package/src/cmi/aicc/student_data.ts +14 -5
  45. package/src/cmi/aicc/student_demographics.ts +31 -24
  46. package/src/cmi/aicc/student_preferences.ts +11 -11
  47. package/src/cmi/aicc/tries.ts +24 -14
  48. package/src/cmi/aicc/validation.ts +3 -4
  49. package/src/cmi/common/array.ts +17 -5
  50. package/src/cmi/common/base_cmi.ts +3 -1
  51. package/src/cmi/common/score.ts +16 -13
  52. package/src/cmi/scorm12/cmi.ts +25 -10
  53. package/src/cmi/scorm12/interactions.ts +62 -28
  54. package/src/cmi/scorm12/nav.ts +13 -5
  55. package/src/cmi/scorm12/objectives.ts +28 -18
  56. package/src/cmi/scorm12/student_data.ts +15 -8
  57. package/src/cmi/scorm12/student_preference.ts +20 -13
  58. package/src/cmi/scorm12/validation.ts +7 -7
  59. package/src/cmi/scorm2004/adl.ts +141 -25
  60. package/src/cmi/scorm2004/cmi.ts +50 -55
  61. package/src/cmi/scorm2004/comments.ts +21 -20
  62. package/src/cmi/scorm2004/interactions.ts +73 -32
  63. package/src/cmi/scorm2004/learner_preference.ts +20 -13
  64. package/src/cmi/scorm2004/objectives.ts +41 -16
  65. package/src/cmi/scorm2004/score.ts +22 -11
  66. package/src/cmi/scorm2004/validation.ts +4 -4
  67. package/src/constants/api_constants.ts +8 -29
  68. package/src/constants/default_settings.ts +26 -12
  69. package/src/constants/enums.ts +9 -0
  70. package/src/constants/error_codes.ts +5 -12
  71. package/src/constants/regex.ts +5 -11
  72. package/src/constants/response_constants.ts +1 -2
  73. package/src/exceptions/aicc_exceptions.ts +29 -0
  74. package/src/exceptions/scorm12_exceptions.ts +29 -0
  75. package/src/exceptions/scorm2004_exceptions.ts +29 -0
  76. package/src/exceptions.ts +1 -86
  77. package/src/types/api_types.ts +29 -5
  78. package/test/AICC.spec.ts +114 -43
  79. package/test/Scorm12API.spec.ts +37 -39
  80. package/test/Scorm2004API.spec.ts +165 -80
  81. package/test/cmi/aicc_cmi.spec.ts +6 -9
  82. package/test/cmi/scorm12_cmi.spec.ts +8 -8
  83. package/test/cmi/scorm2004_cmi.spec.ts +8 -9
  84. package/test/exceptions.spec.ts +11 -9
  85. package/test/types/api_types.spec.ts +40 -47
  86. package/test/utilities.spec.ts +1 -4
  87. package/webpack.config.js +4 -0
@@ -1,6 +1,6 @@
1
1
  import { describe, it } from "mocha";
2
- import APIConstants from "../../src/constants/api_constants";
3
- import ErrorCodes from "../../src/constants/error_codes";
2
+ import { aicc_constants } from "../../src/constants/api_constants";
3
+ import { scorm12_errors } from "../../src/constants/error_codes";
4
4
  import { CMI } from "../../src/cmi/aicc/cmi";
5
5
  import * as h from "../cmi_helpers";
6
6
  import { expect } from "expect";
@@ -13,13 +13,10 @@ import { NAV } from "../../src/cmi/scorm12/nav";
13
13
  import { CMIPathsObject } from "../../src/cmi/aicc/paths";
14
14
  import { CMIStudentDemographics } from "../../src/cmi/aicc/student_demographics";
15
15
 
16
- const aicc_constants = APIConstants.aicc;
17
- const scorm12_error_codes = ErrorCodes.scorm12;
18
-
19
- const invalid_set = scorm12_error_codes.INVALID_SET_VALUE;
20
- const type_mismatch = scorm12_error_codes.TYPE_MISMATCH;
21
- const write_only = scorm12_error_codes.WRITE_ONLY_ELEMENT;
22
- const read_only = scorm12_error_codes.READ_ONLY_ELEMENT;
16
+ const invalid_set = scorm12_errors.INVALID_SET_VALUE;
17
+ const type_mismatch = scorm12_errors.TYPE_MISMATCH;
18
+ const write_only = scorm12_errors.WRITE_ONLY_ELEMENT;
19
+ const read_only = scorm12_errors.READ_ONLY_ELEMENT;
23
20
 
24
21
  describe("AICC CMI Tests", () => {
25
22
  describe("CMI Spec Tests", () => {
@@ -1,7 +1,7 @@
1
1
  import { expect } from "expect";
2
2
  import { describe, it } from "mocha";
3
- import APIConstants from "../../src/constants/api_constants";
4
- import ErrorCodes from "../../src/constants/error_codes";
3
+ import { scorm12_constants } from "../../src/constants/api_constants";
4
+ import { scorm12_errors } from "../../src/constants/error_codes";
5
5
  import { CMI } from "../../src/cmi/scorm12/cmi";
6
6
  import * as h from "../cmi_helpers";
7
7
  import { scorm12Values } from "../field_values";
@@ -12,13 +12,13 @@ import {
12
12
  CMIInteractionsObjectivesObject,
13
13
  } from "../../src/cmi/scorm12/interactions";
14
14
 
15
- const scorm12 = APIConstants.scorm12;
16
- const scorm12_error_codes = ErrorCodes.scorm12;
15
+ const scorm12 = scorm12_constants;
16
+ const scorm12_error_codes = scorm12;
17
17
 
18
- const invalid_set = scorm12_error_codes.INVALID_SET_VALUE;
19
- const type_mismatch = scorm12_error_codes.TYPE_MISMATCH;
20
- const write_only = scorm12_error_codes.WRITE_ONLY_ELEMENT;
21
- const read_only = scorm12_error_codes.READ_ONLY_ELEMENT;
18
+ const invalid_set = scorm12_errors.INVALID_SET_VALUE;
19
+ const type_mismatch = scorm12_errors.TYPE_MISMATCH;
20
+ const write_only = scorm12_errors.WRITE_ONLY_ELEMENT;
21
+ const read_only = scorm12_errors.READ_ONLY_ELEMENT;
22
22
 
23
23
  const cmi = () => {
24
24
  return new CMI();
@@ -1,6 +1,6 @@
1
1
  import { describe, it } from "mocha";
2
- import ErrorCodes from "../../src/constants/error_codes";
3
- import APIConstants from "../../src/constants/api_constants";
2
+ import { scorm2004_errors } from "../../src/constants/error_codes";
3
+ import { scorm2004_constants } from "../../src/constants/api_constants";
4
4
  import { CMI } from "../../src/cmi/scorm2004/cmi";
5
5
  import * as h from "../cmi_helpers";
6
6
  import { expect } from "expect";
@@ -14,12 +14,9 @@ import { CMICommentsObject } from "../../src/cmi/scorm2004/comments";
14
14
  import { CMIObjectivesObject } from "../../src/cmi/scorm2004/objectives";
15
15
  import { ADL } from "../../src/cmi/scorm2004/adl";
16
16
 
17
- const scorm2004_constants = APIConstants.scorm2004;
18
- const scorm2004_error_codes = ErrorCodes.scorm2004;
19
-
20
- const read_only = scorm2004_error_codes.READ_ONLY_ELEMENT;
21
- const write_only = scorm2004_error_codes.WRITE_ONLY_ELEMENT;
22
- const type_mismatch = scorm2004_error_codes.TYPE_MISMATCH;
17
+ const read_only = scorm2004_errors.READ_ONLY_ELEMENT;
18
+ const write_only = scorm2004_errors.WRITE_ONLY_ELEMENT;
19
+ const type_mismatch = scorm2004_errors.TYPE_MISMATCH;
23
20
 
24
21
  const cmi = () => {
25
22
  return new CMI();
@@ -1023,7 +1020,9 @@ describe("SCORM 2004 CMI Tests", () => {
1023
1020
 
1024
1021
  it("should export JSON", () => {
1025
1022
  const cmi = adl();
1026
- expect(JSON.stringify(cmi)).toEqual('{"nav":{"request":"_none_"}}');
1023
+ expect(JSON.stringify(cmi)).toEqual(
1024
+ '{"nav":{"request":"_none_"},"data":{}}',
1025
+ );
1027
1026
  });
1028
1027
  });
1029
1028
  });
@@ -1,16 +1,18 @@
1
1
  import { describe, it } from "mocha";
2
2
  import { expect } from "expect";
3
+ import { ValidationError } from "../src/exceptions";
3
4
  import {
4
- ValidationError,
5
- AICCValidationError,
6
- Scorm12ValidationError,
7
- Scorm2004ValidationError,
8
- } from "../src/exceptions";
9
- import APIConstants from "../src/constants/api_constants";
5
+ aicc_constants,
6
+ scorm12_constants,
7
+ scorm2004_constants,
8
+ } from "../src/constants/api_constants";
9
+ import { AICCValidationError } from "../src/exceptions/aicc_exceptions";
10
+ import { Scorm12ValidationError } from "../src/exceptions/scorm12_exceptions";
11
+ import { Scorm2004ValidationError } from "../src/exceptions/scorm2004_exceptions";
10
12
 
11
- const scorm12_errors = APIConstants.scorm12.error_descriptions;
12
- const aicc_errors = APIConstants.aicc.error_descriptions;
13
- const scorm2004_errors = APIConstants.scorm2004.error_descriptions;
13
+ const scorm12_errors = scorm12_constants.error_descriptions;
14
+ const aicc_errors = aicc_constants.error_descriptions;
15
+ const scorm2004_errors = scorm2004_constants.error_descriptions;
14
16
 
15
17
  type CheckValidationMessage = {
16
18
  errorClass: any;
@@ -1,7 +1,10 @@
1
1
  import { expect } from "expect";
2
2
  import * as sinon from "sinon";
3
- import { ResultObject, Settings } from "../../src/types/api_types";
4
- import APIConstants from "../../src/constants/api_constants";
3
+ import { SinonStub } from "sinon";
4
+ import { LogLevel, ResultObject, Settings } from "../../src/types/api_types";
5
+ import { global_constants } from "../../src/constants/api_constants";
6
+ import { LogLevelEnum } from "../../src/constants/enums";
7
+ import { DefaultSettings } from "../../src/constants/default_settings";
5
8
 
6
9
  describe("Settings Type", () => {
7
10
  const defaultSettings: Settings = {
@@ -13,7 +16,7 @@ describe("Settings Type", () => {
13
16
  dataCommitFormat: "json",
14
17
  commitRequestDataType: "application/json;charset=UTF-8",
15
18
  autoProgress: false,
16
- logLevel: APIConstants.global.LOG_LEVEL_ERROR,
19
+ logLevel: LogLevelEnum.ERROR,
17
20
  selfReportSessionTime: false,
18
21
  alwaysSendTotalTime: false,
19
22
  strict_errors: true,
@@ -22,32 +25,13 @@ describe("Settings Type", () => {
22
25
  responseHandler: async (response: Response): Promise<ResultObject> => {
23
26
  const httpResult = JSON.parse(await response.text());
24
27
  return {
25
- result: httpResult.result || APIConstants.global.SCORM_FALSE,
28
+ result: httpResult.result || global_constants.SCORM_FALSE,
26
29
  errorCode:
27
30
  httpResult.errorCode !== undefined ? httpResult.errorCode : 101,
28
31
  };
29
32
  },
30
33
  requestHandler: (commitObject: any) => commitObject,
31
- onLogMessage: (messageLevel: number, logMessage: string) => {
32
- switch (messageLevel) {
33
- case APIConstants.global.LOG_LEVEL_ERROR:
34
- console.error(logMessage);
35
- break;
36
- case APIConstants.global.LOG_LEVEL_WARNING:
37
- console.warn(logMessage);
38
- break;
39
- case APIConstants.global.LOG_LEVEL_INFO:
40
- console.info(logMessage);
41
- break;
42
- case APIConstants.global.LOG_LEVEL_DEBUG:
43
- if (console.debug) {
44
- console.debug(logMessage);
45
- } else {
46
- console.log(logMessage);
47
- }
48
- break;
49
- }
50
- },
34
+ onLogMessage: DefaultSettings.onLogMessage,
51
35
  };
52
36
 
53
37
  it("should have correct default values", () => {
@@ -61,9 +45,7 @@ describe("Settings Type", () => {
61
45
  "application/json;charset=UTF-8",
62
46
  );
63
47
  expect(defaultSettings.autoProgress).toBe(false);
64
- expect(defaultSettings.logLevel).toEqual(
65
- APIConstants.global.LOG_LEVEL_ERROR,
66
- );
48
+ expect(defaultSettings.logLevel).toEqual(LogLevelEnum.ERROR);
67
49
  expect(defaultSettings.selfReportSessionTime).toBe(false);
68
50
  expect(defaultSettings.alwaysSendTotalTime).toBe(false);
69
51
  expect(defaultSettings.strict_errors).toBe(true);
@@ -93,29 +75,40 @@ describe("Settings Type", () => {
93
75
  const consoleDebugStub = sinon.stub(console, "debug");
94
76
  const consoleLogStub = sinon.stub(console, "log");
95
77
 
96
- defaultSettings.onLogMessage(
97
- APIConstants.global.LOG_LEVEL_ERROR,
98
- "Error message",
99
- );
100
- expect(consoleErrorStub.calledWith("Error message")).toBe(true);
78
+ const testLog = function (
79
+ stub: SinonStub,
80
+ level: LogLevel,
81
+ shouldBeLogged = true,
82
+ ) {
83
+ const message = `${level} message - ${typeof level}`;
84
+ defaultSettings.onLogMessage(level, message);
85
+ expect(stub.calledWith(message)).toBe(shouldBeLogged);
86
+ };
101
87
 
102
- defaultSettings.onLogMessage(
103
- APIConstants.global.LOG_LEVEL_WARNING,
104
- "Warning message",
105
- );
106
- expect(consoleWarnStub.calledWith("Warning message")).toBe(true);
88
+ testLog(consoleErrorStub, LogLevelEnum.ERROR);
89
+ testLog(consoleErrorStub, 4);
90
+ testLog(consoleErrorStub, "4");
91
+ testLog(consoleErrorStub, "ERROR");
107
92
 
108
- defaultSettings.onLogMessage(
109
- APIConstants.global.LOG_LEVEL_INFO,
110
- "Info message",
111
- );
112
- expect(consoleInfoStub.calledWith("Info message")).toBe(true);
93
+ testLog(consoleWarnStub, LogLevelEnum.WARN);
94
+ testLog(consoleWarnStub, 3);
95
+ testLog(consoleWarnStub, "3");
96
+ testLog(consoleWarnStub, "WARN");
113
97
 
114
- defaultSettings.onLogMessage(
115
- APIConstants.global.LOG_LEVEL_DEBUG,
116
- "Debug message",
117
- );
118
- expect(consoleDebugStub.calledWith("Debug message")).toBe(true);
98
+ testLog(consoleInfoStub, LogLevelEnum.INFO);
99
+ testLog(consoleInfoStub, 2);
100
+ testLog(consoleInfoStub, "2");
101
+ testLog(consoleInfoStub, "INFO");
102
+
103
+ testLog(consoleDebugStub, LogLevelEnum.DEBUG);
104
+ testLog(consoleDebugStub, 1);
105
+ testLog(consoleDebugStub, "1");
106
+ testLog(consoleDebugStub, "DEBUG");
107
+
108
+ testLog(consoleLogStub, LogLevelEnum.NONE, false);
109
+ testLog(consoleLogStub, 5, false);
110
+ testLog(consoleLogStub, "5", false);
111
+ testLog(consoleLogStub, "NONE", false);
119
112
 
120
113
  consoleErrorStub.restore();
121
114
  consoleWarnStub.restore();
@@ -1,10 +1,7 @@
1
1
  import { expect } from "expect";
2
2
  import { describe, it } from "mocha";
3
3
  import * as Utilities from "../src/utilities";
4
- import Regex from "../src/constants/regex";
5
-
6
- const scorm12_regex = Regex.scorm12;
7
- const scorm2004_regex = Regex.scorm2004;
4
+ import { scorm12_regex, scorm2004_regex } from "../src/constants/regex";
8
5
 
9
6
  describe("Utility Tests", () => {
10
7
  describe("getSecondsAsHHMMSS()", () => {
package/webpack.config.js CHANGED
@@ -32,6 +32,7 @@ const commonConfig = {
32
32
  rules: [TSLoader],
33
33
  },
34
34
  optimization: {
35
+ usedExports: false,
35
36
  minimize: true,
36
37
  minimizer: [
37
38
  new TerserPlugin({
@@ -41,6 +42,9 @@ const commonConfig = {
41
42
  output: {
42
43
  comments: false,
43
44
  },
45
+ compress: {
46
+ passes: 3,
47
+ },
44
48
  },
45
49
  }),
46
50
  ],