scorm-again 2.6.1 → 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 (91) hide show
  1. package/dist/aicc.js +163 -162
  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 +163 -162
  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 +185 -177
  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 +163 -162
  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 +57 -48
  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 +185 -177
  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 +163 -162
  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 +57 -48
  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/package.json +3 -2
  83. package/src/BaseAPI.ts +23 -16
  84. package/src/Scorm12API.ts +1 -3
  85. package/src/Scorm2004API.ts +14 -10
  86. package/src/constants/default_settings.ts +2 -2
  87. package/src/types/api_types.ts +27 -2
  88. package/test/AICC.spec.ts +2 -2
  89. package/test/Scorm12API.spec.ts +3 -3
  90. package/test/Scorm2004API.spec.ts +20 -20
  91. package/tsconfig.json +19 -6
@@ -0,0 +1,16 @@
1
+ export declare const LearnerResponses: Responses;
2
+ export declare const CorrectResponses: Responses;
3
+ export type ResponseType = {
4
+ format: string;
5
+ max: number;
6
+ delimiter: string;
7
+ unique: boolean;
8
+ duplicate?: boolean;
9
+ format2?: string;
10
+ delimiter2?: string;
11
+ limit?: number;
12
+ delimiter3?: string;
13
+ };
14
+ export type Responses = {
15
+ [key: string]: ResponseType;
16
+ };
@@ -0,0 +1,4 @@
1
+ import { ValidationError } from "../exceptions";
2
+ export declare class AICCValidationError extends ValidationError {
3
+ constructor(errorCode: number);
4
+ }
@@ -0,0 +1,4 @@
1
+ import { ValidationError } from "../exceptions";
2
+ export declare class Scorm12ValidationError extends ValidationError {
3
+ constructor(errorCode: number);
4
+ }
@@ -0,0 +1,4 @@
1
+ import { ValidationError } from "../exceptions";
2
+ export declare class Scorm2004ValidationError extends ValidationError {
3
+ constructor(errorCode: number);
4
+ }
@@ -0,0 +1,18 @@
1
+ type APIError = {
2
+ errorCode: number;
3
+ errorMessage: string;
4
+ detailedMessage: string;
5
+ };
6
+ export declare class BaseScormValidationError extends Error {
7
+ constructor(errorCode: number);
8
+ private readonly _errorCode;
9
+ get errorCode(): number;
10
+ }
11
+ export declare class ValidationError extends BaseScormValidationError implements APIError {
12
+ constructor(errorCode: number, errorMessage: string, detailedMessage?: string);
13
+ private readonly _errorMessage;
14
+ private readonly _detailedMessage;
15
+ get errorMessage(): string;
16
+ get detailedMessage(): string;
17
+ }
18
+ export {};
@@ -0,0 +1,10 @@
1
+ import BaseAPI from "../BaseAPI";
2
+ export declare class ScheduledCommit {
3
+ private _API;
4
+ private _cancelled;
5
+ private readonly _timeout;
6
+ private readonly _callback;
7
+ constructor(API: BaseAPI, when: number, callback: string);
8
+ cancel(): void;
9
+ wrapper(): void;
10
+ }
@@ -0,0 +1,22 @@
1
+ import { RefObject, ResultObject } from "../types/api_types";
2
+ import { BaseCMI } from "../cmi/common/base_cmi";
3
+ export interface IBaseAPI {
4
+ cmi: BaseCMI;
5
+ startingData?: RefObject;
6
+ initialize(callbackName: string, initializeMessage?: string, terminationMessage?: string): string;
7
+ lmsInitialize(): string;
8
+ lmsFinish(): string;
9
+ lmsGetValue(CMIElement: string): string;
10
+ lmsSetValue(CMIElement: string, value: any): string;
11
+ lmsCommit(): string;
12
+ lmsGetLastError(): string;
13
+ lmsGetErrorString(CMIErrorCode: string | number): string;
14
+ lmsGetDiagnostic(CMIErrorCode: string | number): string;
15
+ storeData(_calculateTotalTime: boolean): Promise<ResultObject>;
16
+ renderCommitCMI(_terminateCommit: boolean): RefObject | Array<any>;
17
+ getLmsErrorMessageDetails(_errorNumber: string | number, _detail?: boolean): string;
18
+ getCMIValue(_CMIElement: string): string;
19
+ setCMIValue(_CMIElement: string, _value: any): string;
20
+ validateCorrectResponse(_CMIElement: string, _value: any): void;
21
+ getChildElement(_CMIElement: string, _value: any, _foundFirstIndex: boolean): BaseCMI | null;
22
+ }
@@ -0,0 +1,73 @@
1
+ import { CompletionStatus, LogLevelEnum, SuccessStatus } from "../constants/enums";
2
+ export type Settings = {
3
+ autocommit?: boolean;
4
+ autocommitSeconds?: number;
5
+ asyncCommit?: boolean;
6
+ sendFullCommit?: boolean;
7
+ lmsCommitUrl?: boolean | string;
8
+ dataCommitFormat?: string;
9
+ commitRequestDataType?: string;
10
+ autoProgress?: boolean;
11
+ logLevel?: LogLevel;
12
+ selfReportSessionTime?: boolean;
13
+ alwaysSendTotalTime?: boolean;
14
+ strict_errors?: boolean;
15
+ xhrHeaders?: RefObject;
16
+ xhrWithCredentials?: boolean;
17
+ fetchMode?: "cors" | "no-cors" | "same-origin" | "navigate";
18
+ responseHandler?: (response: Response) => Promise<ResultObject>;
19
+ requestHandler?: (commitObject: any) => any;
20
+ onLogMessage?: (messageLevel: LogLevel, logMessage: string) => void;
21
+ mastery_override?: boolean;
22
+ renderCommonCommitFields?: boolean;
23
+ scoItemIds?: string[];
24
+ scoItemIdValidator?: false | ((scoItemId: string) => boolean);
25
+ globalObjectiveIds?: string[];
26
+ };
27
+ export type InternalSettings = {
28
+ autocommit: boolean;
29
+ autocommitSeconds: number;
30
+ asyncCommit: boolean;
31
+ sendFullCommit: boolean;
32
+ lmsCommitUrl: boolean | string;
33
+ dataCommitFormat: string;
34
+ commitRequestDataType: string;
35
+ autoProgress: boolean;
36
+ logLevel: LogLevel;
37
+ selfReportSessionTime: boolean;
38
+ renderCommonCommitFields?: boolean;
39
+ scoItemIds?: string[];
40
+ scoItemIdValidator?: false | ((scoItemId: string) => boolean);
41
+ globalObjectiveIds?: string[];
42
+ alwaysSendTotalTime: boolean;
43
+ strict_errors: boolean;
44
+ xhrHeaders: RefObject;
45
+ xhrWithCredentials: boolean;
46
+ mastery_override?: boolean;
47
+ fetchMode: "cors" | "no-cors" | "same-origin" | "navigate";
48
+ responseHandler: (response: Response) => Promise<ResultObject>;
49
+ requestHandler: (commitObject: any) => any;
50
+ onLogMessage: (messageLevel: LogLevel, logMessage: string) => void;
51
+ };
52
+ export type RefObject = {
53
+ [key: string]: any;
54
+ };
55
+ export type ResultObject = {
56
+ result: string;
57
+ errorCode: number;
58
+ navRequest?: string;
59
+ };
60
+ export type ScoreObject = {
61
+ raw?: number;
62
+ min?: number;
63
+ max?: number;
64
+ scaled?: number;
65
+ };
66
+ export type CommitObject = {
67
+ successStatus: SuccessStatus;
68
+ completionStatus: CompletionStatus;
69
+ totalTimeSeconds: number;
70
+ runtimeData: RefObject;
71
+ score?: ScoreObject;
72
+ };
73
+ export type LogLevel = 1 | 2 | 3 | 4 | 5 | "1" | "2" | "3" | "4" | "5" | "DEBUG" | "INFO" | "WARN" | "ERROR" | "NONE" | LogLevelEnum;
@@ -0,0 +1,19 @@
1
+ export declare const SECONDS_PER_SECOND = 1;
2
+ export declare const SECONDS_PER_MINUTE = 60;
3
+ export declare const SECONDS_PER_HOUR: number;
4
+ export declare const SECONDS_PER_DAY: number;
5
+ type StringKeyMap = {
6
+ [key: string]: any;
7
+ };
8
+ export declare function getSecondsAsHHMMSS(totalSeconds: number | null): string;
9
+ export declare function getSecondsAsISODuration(seconds: number | null): string;
10
+ export declare function getTimeAsSeconds(timeString: string | number | boolean | null, timeRegex: RegExp | string): number;
11
+ export declare function getDurationAsSeconds(duration: string | null, durationRegex: RegExp | string): number;
12
+ export declare function addTwoDurations(first: string, second: string, durationRegex: RegExp | string): string;
13
+ export declare function addHHMMSSTimeStrings(first: string, second: string, timeRegex: RegExp | string): string;
14
+ export declare function flatten(data: StringKeyMap): object;
15
+ export declare function unflatten(data: StringKeyMap): object;
16
+ export declare function countDecimals(num: number): number;
17
+ export declare function formatMessage(functionName: string, message: string, CMIElement?: string): string;
18
+ export declare function stringMatches(str: string, tester: string): boolean;
19
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scorm-again",
3
- "version": "2.6.1",
3
+ "version": "2.6.2",
4
4
  "description": "A modern SCORM JavaScript run-time library for AICC, SCORM 1.2, and SCORM 2004",
5
5
  "main": "dist/scorm-again.js",
6
6
  "types": "index.d.ts",
@@ -65,10 +65,11 @@
65
65
  "webpack": "^5.97.1",
66
66
  "webpack-cli": "^5.1.4"
67
67
  },
68
+ "sideEffects": false,
68
69
  "scripts": {
69
70
  "test": "./node_modules/.bin/mocha --import=tsx --bdd --recursive --reporter list",
70
71
  "test:coverage": "./node_modules/.bin/c8 ./node_modules/.bin/mocha --import=tsx --recursive --timeout=10000 --exit --reporter json --reporter-option output=test-results.json",
71
- "compile": "./node_modules/.bin/webpack --bail --config webpack.config.js --mode production",
72
+ "compile": "./node_modules/.bin/webpack --bail --config webpack.config.js --mode production && tsc --emitDeclarationOnly --declaration --outDir dist/types",
72
73
  "fix": "./node_modules/.bin/eslint ./src --fix",
73
74
  "prettier": "./node_modules/.bin/prettier --write src/**/*.ts test/**/*.ts src/*.ts test/*.ts"
74
75
  },
package/src/BaseAPI.ts CHANGED
@@ -4,7 +4,7 @@ import { ErrorCode } from "./constants/error_codes";
4
4
  import { global_constants } from "./constants/api_constants";
5
5
  import { formatMessage, stringMatches, unflatten } from "./utilities";
6
6
  import { BaseCMI } from "./cmi/common/base_cmi";
7
- import { CommitObject, LogLevel, RefObject, ResultObject, Settings } from "./types/api_types";
7
+ import { CommitObject, InternalSettings, LogLevel, RefObject, ResultObject, Settings } from "./types/api_types";
8
8
  import { DefaultSettings } from "./constants/default_settings";
9
9
  import { IBaseAPI } from "./interfaces/IBaseAPI";
10
10
  import { ScheduledCommit } from "./helpers/scheduled_commit";
@@ -15,9 +15,9 @@ import { LogLevelEnum } from "./constants/enums";
15
15
  * abstract, and never initialized on its own.
16
16
  */
17
17
  export default abstract class BaseAPI implements IBaseAPI {
18
- private _timeout?: ScheduledCommit;
18
+ private _timeout?: ScheduledCommit | undefined;
19
19
  private readonly _error_codes: ErrorCode;
20
- private _settings: Settings = DefaultSettings;
20
+ private _settings: InternalSettings = DefaultSettings;
21
21
 
22
22
  /**
23
23
  * Constructor for Base API class. Sets some shared API fields, as well as
@@ -36,14 +36,13 @@ export default abstract class BaseAPI implements IBaseAPI {
36
36
  this._error_codes = error_codes;
37
37
 
38
38
  if (settings) {
39
- this.settings = settings;
40
- }
41
- this.apiLogLevel = this.settings.logLevel;
42
- this.selfReportSessionTime = this.settings.selfReportSessionTime;
43
-
44
- if (this.apiLogLevel === undefined) {
45
- this.apiLogLevel = LogLevelEnum.NONE;
39
+ this.settings = {
40
+ ...DefaultSettings,
41
+ ...settings,
42
+ } as InternalSettings;
46
43
  }
44
+ this.apiLogLevel = this.settings.logLevel ?? LogLevelEnum.ERROR;
45
+ this.selfReportSessionTime = this.settings.selfReportSessionTime ?? false;
47
46
  }
48
47
 
49
48
  public abstract cmi: BaseCMI;
@@ -71,7 +70,7 @@ export default abstract class BaseAPI implements IBaseAPI {
71
70
  this.currentState = global_constants.STATE_NOT_INITIALIZED;
72
71
  this.lastErrorCode = "0";
73
72
  this.listenerArray = [];
74
- this.startingData = undefined;
73
+ this.startingData = {};
75
74
  }
76
75
 
77
76
  /**
@@ -209,7 +208,7 @@ export default abstract class BaseAPI implements IBaseAPI {
209
208
  * Getter for _settings
210
209
  * @return {Settings}
211
210
  */
212
- get settings(): Settings {
211
+ get settings(): InternalSettings {
213
212
  return this._settings;
214
213
  }
215
214
 
@@ -1139,7 +1138,7 @@ export default abstract class BaseAPI implements IBaseAPI {
1139
1138
  const process = async (
1140
1139
  url: string,
1141
1140
  params: CommitObject | RefObject | Array<any>,
1142
- settings: Settings,
1141
+ settings: InternalSettings,
1143
1142
  ): Promise<ResultObject> => {
1144
1143
  try {
1145
1144
  params = settings.requestHandler(params);
@@ -1258,7 +1257,7 @@ export default abstract class BaseAPI implements IBaseAPI {
1258
1257
  url: string,
1259
1258
  params: RefObject | Array<any>,
1260
1259
  ): Promise<Response> {
1261
- return fetch(url, {
1260
+ let init = {
1262
1261
  method: "POST",
1263
1262
  mode: this.settings.fetchMode,
1264
1263
  body: params instanceof Array ? params.join("&") : JSON.stringify(params),
@@ -1266,9 +1265,17 @@ export default abstract class BaseAPI implements IBaseAPI {
1266
1265
  ...this.settings.xhrHeaders,
1267
1266
  "Content-Type": this.settings.commitRequestDataType,
1268
1267
  },
1269
- credentials: this.settings.xhrWithCredentials ? "include" : undefined,
1270
1268
  keepalive: true,
1271
- });
1269
+ } as RequestInit;
1270
+
1271
+ if (this.settings.xhrWithCredentials) {
1272
+ init = {
1273
+ ...init,
1274
+ credentials: "include",
1275
+ };
1276
+ }
1277
+
1278
+ return fetch(url, init);
1272
1279
  }
1273
1280
 
1274
1281
  /**
package/src/Scorm12API.ts CHANGED
@@ -354,10 +354,8 @@ class Scorm12Impl extends BaseAPI {
354
354
  }
355
355
 
356
356
  const score = this.cmi.core.score;
357
- let scoreObject: ScoreObject = null;
357
+ const scoreObject: ScoreObject = {};
358
358
  if (score) {
359
- scoreObject = {};
360
-
361
359
  if (!Number.isNaN(Number.parseFloat(score.raw))) {
362
360
  scoreObject.raw = Number.parseFloat(score.raw);
363
361
  }
@@ -159,13 +159,18 @@ class Scorm2004Impl extends BaseAPI {
159
159
  "^adl\\.nav\\.request_valid\\.(choice|jump)\\.{target=\\S{0,}([a-zA-Z0-9-_]+)}$";
160
160
  if (stringMatches(CMIElement, adlNavRequestRegex)) {
161
161
  const matches = CMIElement.match(adlNavRequestRegex);
162
- const request = matches[1];
163
- const target = matches[2].replace("{target=", "").replace("}", "");
164
- if (request === "choice" || request === "jump") {
165
- if (this.settings.scoItemIdValidator) {
166
- return String(this.settings.scoItemIdValidator(target));
162
+ if (matches) {
163
+ const request = matches[1];
164
+ const target = matches[2].replace("{target=", "").replace("}", "");
165
+ if (request === "choice" || request === "jump") {
166
+ if (this.settings.scoItemIdValidator) {
167
+ return String(this.settings.scoItemIdValidator(target));
168
+ }
169
+ if (this.settings.scoItemIds) {
170
+ return String(this.settings.scoItemIds?.includes(target));
171
+ }
172
+ return String(request);
167
173
  }
168
- return String(this.settings.scoItemIds.includes(target));
169
174
  }
170
175
  }
171
176
  return this.getValue("GetValue", true, CMIElement);
@@ -257,7 +262,8 @@ class Scorm2004Impl extends BaseAPI {
257
262
 
258
263
  // Check if the objective ID matches a global objective
259
264
  const is_global =
260
- objective_id && this.settings.globalObjectiveIds.includes(objective_id);
265
+ objective_id &&
266
+ this.settings.globalObjectiveIds?.includes(objective_id);
261
267
 
262
268
  if (is_global) {
263
269
  // Locate or create an entry in _globalObjectives for the global objective
@@ -717,10 +723,8 @@ class Scorm2004Impl extends BaseAPI {
717
723
  }
718
724
 
719
725
  const score = this.cmi.score;
720
- let scoreObject: ScoreObject = null;
726
+ const scoreObject: ScoreObject = {};
721
727
  if (score) {
722
- scoreObject = {};
723
-
724
728
  if (!Number.isNaN(Number.parseFloat(score.raw))) {
725
729
  scoreObject.raw = Number.parseFloat(score.raw);
726
730
  }
@@ -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;
@@ -538,7 +538,7 @@ describe("SCORM 1.2 API Tests", () => {
538
538
  expect(commitObject.totalTimeSeconds).toEqual(
539
539
  12 * 3600 + 34 * 60 + 56 + (23 * 3600 + 59 * 60 + 59),
540
540
  );
541
- expect(commitObject.score.max).toEqual(100);
541
+ expect(commitObject?.score?.max).toEqual(100);
542
542
  });
543
543
 
544
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
+ }