scorm-again 2.6.0 → 2.6.2

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 (95) hide show
  1. package/dist/aicc.js +172 -166
  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 +173 -167
  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 +194 -184
  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 +171 -165
  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 +65 -51
  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 +195 -185
  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 +170 -164
  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 +64 -50
  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/types/AICC.d.ts +13 -0
  34. package/dist/types/BaseAPI.d.ts +71 -0
  35. package/dist/types/Scorm12API.d.ts +39 -0
  36. package/dist/types/Scorm2004API.d.ts +52 -0
  37. package/dist/types/ScormAgain.d.ts +4 -0
  38. package/dist/types/cmi/aicc/attempts.d.ts +19 -0
  39. package/dist/types/cmi/aicc/cmi.d.ts +34 -0
  40. package/dist/types/cmi/aicc/core.d.ts +57 -0
  41. package/dist/types/cmi/aicc/evaluation.d.ts +33 -0
  42. package/dist/types/cmi/aicc/paths.d.ts +35 -0
  43. package/dist/types/cmi/aicc/student_data.d.ts +20 -0
  44. package/dist/types/cmi/aicc/student_demographics.d.ts +61 -0
  45. package/dist/types/cmi/aicc/student_preferences.d.ts +34 -0
  46. package/dist/types/cmi/aicc/tries.d.ts +23 -0
  47. package/dist/types/cmi/aicc/validation.d.ts +1 -0
  48. package/dist/types/cmi/common/array.d.ts +19 -0
  49. package/dist/types/cmi/common/base_cmi.d.ts +13 -0
  50. package/dist/types/cmi/common/score.d.ts +38 -0
  51. package/dist/types/cmi/common/validation.d.ts +3 -0
  52. package/dist/types/cmi/scorm12/cmi.d.ts +45 -0
  53. package/dist/types/cmi/scorm12/interactions.d.ts +64 -0
  54. package/dist/types/cmi/scorm12/nav.d.ts +11 -0
  55. package/dist/types/cmi/scorm12/objectives.d.ts +22 -0
  56. package/dist/types/cmi/scorm12/student_data.d.ts +22 -0
  57. package/dist/types/cmi/scorm12/student_preference.d.ts +26 -0
  58. package/dist/types/cmi/scorm12/validation.d.ts +2 -0
  59. package/dist/types/cmi/scorm2004/adl.d.ts +71 -0
  60. package/dist/types/cmi/scorm2004/cmi.d.ts +103 -0
  61. package/dist/types/cmi/scorm2004/comments.d.ts +27 -0
  62. package/dist/types/cmi/scorm2004/interactions.d.ts +68 -0
  63. package/dist/types/cmi/scorm2004/learner_preference.d.ts +26 -0
  64. package/dist/types/cmi/scorm2004/objectives.d.ts +38 -0
  65. package/dist/types/cmi/scorm2004/score.d.ts +14 -0
  66. package/dist/types/cmi/scorm2004/validation.d.ts +2 -0
  67. package/dist/types/constants/api_constants.d.ts +49 -0
  68. package/dist/types/constants/default_settings.d.ts +2 -0
  69. package/dist/types/constants/enums.d.ts +23 -0
  70. package/dist/types/constants/error_codes.d.ts +6 -0
  71. package/dist/types/constants/language_constants.d.ts +2 -0
  72. package/dist/types/constants/regex.d.ts +82 -0
  73. package/dist/types/constants/response_constants.d.ts +16 -0
  74. package/dist/types/exceptions/aicc_exceptions.d.ts +4 -0
  75. package/dist/types/exceptions/scorm12_exceptions.d.ts +4 -0
  76. package/dist/types/exceptions/scorm2004_exceptions.d.ts +4 -0
  77. package/dist/types/exceptions.d.ts +18 -0
  78. package/dist/types/helpers/scheduled_commit.d.ts +10 -0
  79. package/dist/types/interfaces/IBaseAPI.d.ts +22 -0
  80. package/dist/types/types/api_types.d.ts +73 -0
  81. package/dist/types/utilities.d.ts +19 -0
  82. package/dist_test.html +208 -0
  83. package/package.json +3 -2
  84. package/src/AICC.ts +3 -3
  85. package/src/BaseAPI.ts +32 -22
  86. package/src/Scorm12API.ts +4 -12
  87. package/src/Scorm2004API.ts +18 -23
  88. package/src/ScormAgain.ts +3 -7
  89. package/src/constants/default_settings.ts +2 -2
  90. package/src/types/api_types.ts +27 -2
  91. package/test/AICC.spec.ts +2 -2
  92. package/test/Scorm12API.spec.ts +26 -3
  93. package/test/Scorm2004API.spec.ts +20 -20
  94. package/tsconfig.json +19 -6
  95. package/webpack.config.js +1 -1
package/src/ScormAgain.ts CHANGED
@@ -1,9 +1,5 @@
1
- import { AICCImpl } from "./AICC";
2
- import { Scorm12Impl } from "./Scorm12API";
3
- import { Scorm2004Impl } from "./Scorm2004API";
4
-
5
- const Scorm12API = Scorm12Impl;
6
- const Scorm2004API = Scorm2004Impl;
7
- const AICC = AICCImpl;
1
+ import { AICC } from "./AICC";
2
+ import { Scorm12API } from "./Scorm12API";
3
+ import { Scorm2004API } from "./Scorm2004API";
8
4
 
9
5
  export { Scorm12API, Scorm2004API, AICC };
@@ -1,11 +1,11 @@
1
- import { LogLevel, ResultObject, Settings } from "../types/api_types";
1
+ import { InternalSettings, LogLevel, ResultObject } from "../types/api_types";
2
2
  import { global_constants } from "./api_constants";
3
3
  import { LogLevelEnum } from "./enums";
4
4
 
5
5
  /**
6
6
  * Default settings for the SCORM API
7
7
  */
8
- export const DefaultSettings: Settings = {
8
+ export const DefaultSettings: InternalSettings = {
9
9
  autocommit: false,
10
10
  autocommitSeconds: 10,
11
11
  asyncCommit: false,
@@ -30,6 +30,32 @@ export type Settings = {
30
30
  globalObjectiveIds?: string[];
31
31
  };
32
32
 
33
+ export type InternalSettings = {
34
+ autocommit: boolean;
35
+ autocommitSeconds: number;
36
+ asyncCommit: boolean;
37
+ sendFullCommit: boolean;
38
+ lmsCommitUrl: boolean | string;
39
+ dataCommitFormat: string;
40
+ commitRequestDataType: string;
41
+ autoProgress: boolean;
42
+ logLevel: LogLevel;
43
+ selfReportSessionTime: boolean;
44
+ renderCommonCommitFields?: boolean;
45
+ scoItemIds?: string[];
46
+ scoItemIdValidator?: false | ((scoItemId: string) => boolean);
47
+ globalObjectiveIds?: string[];
48
+ alwaysSendTotalTime: boolean;
49
+ strict_errors: boolean;
50
+ xhrHeaders: RefObject;
51
+ xhrWithCredentials: boolean;
52
+ mastery_override?: boolean;
53
+ fetchMode: "cors" | "no-cors" | "same-origin" | "navigate";
54
+ responseHandler: (response: Response) => Promise<ResultObject>;
55
+ requestHandler: (commitObject: any) => any;
56
+ onLogMessage: (messageLevel: LogLevel, logMessage: string) => void;
57
+ };
58
+
33
59
  export type RefObject = {
34
60
  [key: string]: any;
35
61
  };
@@ -71,5 +97,4 @@ export type LogLevel =
71
97
  | "WARN"
72
98
  | "ERROR"
73
99
  | "NONE"
74
- | LogLevelEnum
75
- | undefined;
100
+ | LogLevelEnum;
package/test/AICC.spec.ts CHANGED
@@ -2,7 +2,7 @@ import { expect } from "expect";
2
2
  import { describe, it } from "mocha";
3
3
  import * as h from "./api_helpers";
4
4
  import { scorm12_errors } from "../src/constants/error_codes";
5
- import { AICCImpl } from "../src/AICC";
5
+ import { AICC } from "../src/AICC";
6
6
  import { DefaultSettings } from "../src/constants/default_settings";
7
7
  import * as sinon from "sinon";
8
8
  import { CMITries } from "../src/cmi/aicc/tries";
@@ -10,7 +10,7 @@ import { CMIInteractions } from "../src/cmi/scorm12/interactions";
10
10
  import { RefObject, Settings } from "../src/types/api_types";
11
11
 
12
12
  const api = (settings?: Settings, startingData: RefObject = {}) => {
13
- const API = new AICCImpl(settings);
13
+ const API = new AICC(settings);
14
14
  API.apiLogLevel = 1;
15
15
  if (startingData) {
16
16
  API.startingData = startingData;
@@ -1,6 +1,6 @@
1
1
  import { expect } from "expect";
2
2
  import { after, before, describe, it } from "mocha";
3
- import { Scorm12Impl } from "../src/Scorm12API";
3
+ import { Scorm12API } from "../src/Scorm12API";
4
4
  import * as h from "./api_helpers";
5
5
  import { scorm12_errors } from "../src/constants/error_codes";
6
6
  import { scorm12Values } from "./field_values";
@@ -11,7 +11,7 @@ import { DefaultSettings } from "../src/constants/default_settings";
11
11
 
12
12
  let clock: sinon.SinonFakeTimers;
13
13
  const api = (settings?: Settings, startingData: RefObject = {}) => {
14
- const API = new Scorm12Impl(settings);
14
+ const API = new Scorm12API(settings);
15
15
  API.apiLogLevel = 5;
16
16
  API.startingData = startingData;
17
17
  return API;
@@ -118,6 +118,29 @@ describe("SCORM 1.2 API Tests", () => {
118
118
  expect(scorm12API.cmi.objectives.childArray[0].score.max).toEqual("100");
119
119
  });
120
120
 
121
+ it("should load nested JSON data into the CMI object in a backwards compatible way with v1", () => {
122
+ const scorm12API = api();
123
+ const jsonData = {
124
+ objectives: {
125
+ "0": {
126
+ id: "obj_1",
127
+ score: {
128
+ raw: "85",
129
+ min: "0",
130
+ max: "100",
131
+ },
132
+ },
133
+ },
134
+ };
135
+
136
+ scorm12API.loadFromJSON(jsonData);
137
+
138
+ expect(scorm12API.cmi.objectives.childArray[0].id).toEqual("obj_1");
139
+ expect(scorm12API.cmi.objectives.childArray[0].score.raw).toEqual("85");
140
+ expect(scorm12API.cmi.objectives.childArray[0].score.min).toEqual("0");
141
+ expect(scorm12API.cmi.objectives.childArray[0].score.max).toEqual("100");
142
+ });
143
+
121
144
  it("should handle empty JSON data", () => {
122
145
  const scorm12API = api();
123
146
  const jsonData = {};
@@ -515,7 +538,7 @@ describe("SCORM 1.2 API Tests", () => {
515
538
  expect(commitObject.totalTimeSeconds).toEqual(
516
539
  12 * 3600 + 34 * 60 + 56 + (23 * 3600 + 59 * 60 + 59),
517
540
  );
518
- expect(commitObject.score.max).toEqual(100);
541
+ expect(commitObject?.score?.max).toEqual(100);
519
542
  });
520
543
 
521
544
  it("should render commit object with score data", () => {
@@ -4,7 +4,7 @@ import * as sinon from "sinon";
4
4
  import * as h from "./api_helpers";
5
5
  import Pretender from "fetch-pretender";
6
6
  import { scorm2004_errors } from "../src/constants/error_codes";
7
- import { Scorm2004Impl } from "../src/Scorm2004API";
7
+ import { Scorm2004API } from "../src/Scorm2004API";
8
8
  import { scorm2004Values } from "./field_values";
9
9
  import {
10
10
  global_constants,
@@ -17,7 +17,7 @@ import { ADLNav } from "../src/cmi/scorm2004/adl";
17
17
 
18
18
  let clock: sinon.SinonFakeTimers;
19
19
  const api = (settings?: Settings, startingData: RefObject = {}) => {
20
- const API = new Scorm2004Impl(settings);
20
+ const API = new Scorm2004API(settings);
21
21
  API.apiLogLevel = 5;
22
22
  if (startingData) {
23
23
  API.startingData = startingData;
@@ -195,7 +195,7 @@ describe("SCORM 2004 API Tests", () => {
195
195
  scorm2004API.setCMIValue("cmi.objectives.1.progress_measure", "0.5");
196
196
 
197
197
  const globalObjective = scorm2004API.globalObjectives.find(
198
- (objective) => objective.id === "Objective 1",
198
+ (objective: { id: string }) => objective.id === "Objective 1",
199
199
  );
200
200
 
201
201
  expect(scorm2004API.getCMIValue("cmi.objectives.0.id")).toEqual(
@@ -229,7 +229,7 @@ describe("SCORM 2004 API Tests", () => {
229
229
  expect(globalObjective?.progress_measure).toEqual("1");
230
230
 
231
231
  const globalObjective2 = scorm2004API.globalObjectives.find(
232
- (objective) => objective.id === "Objective 2",
232
+ (objective: { id: string }) => objective.id === "Objective 2",
233
233
  );
234
234
  expect(globalObjective2).toBe(undefined);
235
235
  });
@@ -1034,7 +1034,7 @@ describe("SCORM 2004 API Tests", () => {
1034
1034
 
1035
1035
  describe("checkCorrectResponseValue()", () => {
1036
1036
  it("should properly handle the true-false response type for unknown value", () => {
1037
- const scorm2004API = new Scorm2004Impl();
1037
+ const scorm2004API = new Scorm2004API();
1038
1038
  scorm2004API.checkCorrectResponseValue("true-false", ["unknown"], "true");
1039
1039
  expect(scorm2004API.lmsGetLastError()).toEqual(
1040
1040
  String(scorm2004_errors.TYPE_MISMATCH),
@@ -1042,13 +1042,13 @@ describe("SCORM 2004 API Tests", () => {
1042
1042
  });
1043
1043
 
1044
1044
  it("should properly handle the true-false response type for correct value", () => {
1045
- const scorm2004API = new Scorm2004Impl();
1045
+ const scorm2004API = new Scorm2004API();
1046
1046
  scorm2004API.checkCorrectResponseValue("true-false", ["true"], "true");
1047
1047
  expect(scorm2004API.lmsGetLastError()).toEqual(String(0));
1048
1048
  });
1049
1049
 
1050
1050
  it("should properly handle the choice response type for value over 4000 characters", () => {
1051
- const scorm2004API = new Scorm2004Impl();
1051
+ const scorm2004API = new Scorm2004API();
1052
1052
  scorm2004API.checkCorrectResponseValue(
1053
1053
  "choice",
1054
1054
  ["x".repeat(4001)],
@@ -1060,25 +1060,25 @@ describe("SCORM 2004 API Tests", () => {
1060
1060
  });
1061
1061
 
1062
1062
  it("should properly handle the choice response type for correct value", () => {
1063
- const scorm2004API = new Scorm2004Impl();
1063
+ const scorm2004API = new Scorm2004API();
1064
1064
  scorm2004API.checkCorrectResponseValue("choice", ["true"], "true");
1065
1065
  expect(scorm2004API.lmsGetLastError()).toEqual(String(0));
1066
1066
  });
1067
1067
 
1068
1068
  it("should properly handle the fill-in response type for correct value", () => {
1069
- const scorm2004API = new Scorm2004Impl();
1069
+ const scorm2004API = new Scorm2004API();
1070
1070
  scorm2004API.checkCorrectResponseValue("fill-in", ["true"], "true");
1071
1071
  expect(scorm2004API.lmsGetLastError()).toEqual(String(0));
1072
1072
  });
1073
1073
 
1074
1074
  it("should properly handle the long-fill-in response type for correct value", () => {
1075
- const scorm2004API = new Scorm2004Impl();
1075
+ const scorm2004API = new Scorm2004API();
1076
1076
  scorm2004API.checkCorrectResponseValue("long-fill-in", ["true"], "true");
1077
1077
  expect(scorm2004API.lmsGetLastError()).toEqual(String(0));
1078
1078
  });
1079
1079
 
1080
1080
  it("should properly handle the matching response type for correct value", () => {
1081
- const scorm2004API = new Scorm2004Impl();
1081
+ const scorm2004API = new Scorm2004API();
1082
1082
  scorm2004API.checkCorrectResponseValue(
1083
1083
  "matching",
1084
1084
  ["{order_matters=true}0[.]1"],
@@ -1090,28 +1090,28 @@ describe("SCORM 2004 API Tests", () => {
1090
1090
 
1091
1091
  describe("removeCorrectResponsePrefixes()", () => {
1092
1092
  it("should remove the prefix from the string", () => {
1093
- const scorm2004API = new Scorm2004Impl();
1093
+ const scorm2004API = new Scorm2004API();
1094
1094
  const input = "{order_matters=true}correctResponse";
1095
1095
  const result = scorm2004API.removeCorrectResponsePrefixes(input);
1096
1096
  expect(result).toBe("correctResponse");
1097
1097
  });
1098
1098
 
1099
1099
  it("should return the original string if no prefix is present", () => {
1100
- const scorm2004API = new Scorm2004Impl();
1100
+ const scorm2004API = new Scorm2004API();
1101
1101
  const input = "correctResponse";
1102
1102
  const result = scorm2004API.removeCorrectResponsePrefixes(input);
1103
1103
  expect(result).toBe("correctResponse");
1104
1104
  });
1105
1105
 
1106
1106
  it("should handle empty strings correctly", () => {
1107
- const scorm2004API = new Scorm2004Impl();
1107
+ const scorm2004API = new Scorm2004API();
1108
1108
  const input = "";
1109
1109
  const result = scorm2004API.removeCorrectResponsePrefixes(input);
1110
1110
  expect(result).toBe("");
1111
1111
  });
1112
1112
 
1113
1113
  it("should handle multiple prefixes correctly", () => {
1114
- const scorm2004API = new Scorm2004Impl();
1114
+ const scorm2004API = new Scorm2004API();
1115
1115
  const input =
1116
1116
  "{lang=en}{order_matters=true}{case_matters=false}correctResponse";
1117
1117
  const result = scorm2004API.removeCorrectResponsePrefixes(input);
@@ -1119,7 +1119,7 @@ describe("SCORM 2004 API Tests", () => {
1119
1119
  });
1120
1120
 
1121
1121
  it("should throw an error for invalid order_matters value", () => {
1122
- const scorm2004API = new Scorm2004Impl();
1122
+ const scorm2004API = new Scorm2004API();
1123
1123
  const input = "{order_matters=invalid}correctResponse";
1124
1124
  scorm2004API.removeCorrectResponsePrefixes(input);
1125
1125
  expect(scorm2004API.lmsGetLastError()).toEqual(
@@ -1128,7 +1128,7 @@ describe("SCORM 2004 API Tests", () => {
1128
1128
  });
1129
1129
 
1130
1130
  it("should throw an error for invalid case_matters value", () => {
1131
- const scorm2004API = new Scorm2004Impl();
1131
+ const scorm2004API = new Scorm2004API();
1132
1132
  const input = "{case_matters=invalid}correctResponse";
1133
1133
  scorm2004API.removeCorrectResponsePrefixes(input);
1134
1134
  expect(scorm2004API.lmsGetLastError()).toEqual(
@@ -1137,14 +1137,14 @@ describe("SCORM 2004 API Tests", () => {
1137
1137
  });
1138
1138
 
1139
1139
  it("should ignore an unknown prefix", () => {
1140
- const scorm2004API = new Scorm2004Impl();
1140
+ const scorm2004API = new Scorm2004API();
1141
1141
  const input = "{unknown=true}correctResponse";
1142
1142
  const result = scorm2004API.removeCorrectResponsePrefixes(input);
1143
1143
  expect(result).toBe("{unknown=true}correctResponse");
1144
1144
  });
1145
1145
 
1146
1146
  it("should throw an error with an invalid language code", () => {
1147
- const scorm2004API = new Scorm2004Impl();
1147
+ const scorm2004API = new Scorm2004API();
1148
1148
  const input = "{lang=xyz}correctResponse";
1149
1149
  scorm2004API.removeCorrectResponsePrefixes(input);
1150
1150
  expect(scorm2004API.lmsGetLastError()).toEqual(
@@ -1174,7 +1174,7 @@ describe("SCORM 2004 API Tests", () => {
1174
1174
  });
1175
1175
 
1176
1176
  it("should call throwSCORMError with the correct arguments in createCorrectResponsesObject", () => {
1177
- const scorm2004API = new Scorm2004Impl();
1177
+ const scorm2004API = new Scorm2004API();
1178
1178
  const interaction = {
1179
1179
  id: "interaction-id-1",
1180
1180
  type: "invalid-type",
package/tsconfig.json CHANGED
@@ -4,16 +4,29 @@
4
4
  "noImplicitAny": true,
5
5
  "noImplicitOverride": true,
6
6
  "declaration": false,
7
- "module": "es2015",
7
+ "module": "es2020",
8
8
  "moduleResolution": "Node",
9
9
  "target": "es5",
10
10
  "emitDecoratorMetadata": true,
11
11
  "experimentalDecorators": true,
12
- "typeRoots": ["node_modules/@types"],
12
+ "typeRoots": [
13
+ "node_modules/@types",
14
+ "src/types"
15
+ ],
16
+ "types": [
17
+ "node"
18
+ ],
19
+ "skipLibCheck": true,
13
20
  "removeComments": true,
14
21
  "importHelpers": true,
15
- "forceConsistentCasingInFileNames": true
22
+ "forceConsistentCasingInFileNames": true,
23
+ "exactOptionalPropertyTypes": true,
24
+ "strictNullChecks": true,
16
25
  },
17
- "include": ["src/**/*"],
18
- "exclude": ["node_modules"]
19
- }
26
+ "include": [
27
+ "src/**/*"
28
+ ],
29
+ "exclude": [
30
+ "node_modules"
31
+ ]
32
+ }
package/webpack.config.js CHANGED
@@ -67,7 +67,7 @@ const cjsConfig = {
67
67
  output: {
68
68
  path: path.resolve(__dirname, "dist"),
69
69
  filename: "[name].js",
70
- libraryTarget: "this",
70
+ libraryTarget: "window",
71
71
  environment: {
72
72
  arrowFunction: false,
73
73
  },