scorm-again 2.6.1 → 2.6.3

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 (93) hide show
  1. package/dist/aicc.js +167 -165
  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 +167 -165
  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 +189 -180
  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 +167 -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 +61 -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 +189 -180
  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 +167 -165
  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 +61 -51
  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/index.d.ts +24 -3
  83. package/package.json +3 -2
  84. package/src/BaseAPI.ts +26 -18
  85. package/src/Scorm12API.ts +1 -3
  86. package/src/Scorm2004API.ts +14 -10
  87. package/src/constants/default_settings.ts +2 -2
  88. package/src/constants/regex.ts +8 -1
  89. package/src/types/api_types.ts +27 -2
  90. package/test/AICC.spec.ts +2 -2
  91. package/test/Scorm12API.spec.ts +3 -3
  92. package/test/Scorm2004API.spec.ts +20 -20
  93. 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/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { Scorm12Impl } from "./src/Scorm12API";
1
+ import { Scorm12API as Scorm12Impl } from "./src/Scorm12API";
2
2
  import { CMI as Scorm12CMI } from "./src/cmi/scorm12/cmi";
3
3
  import { NAV as Scorm12NAV } from "./src/cmi/scorm12/nav";
4
4
  import { CMI as Scorm2004CMI } from "./src/cmi/scorm2004/cmi";
5
5
  import { ADL as Scorm2004ADL } from "./src/cmi/scorm2004/adl";
6
6
  import { Settings } from "./src/types/api_types";
7
- import { Scorm2004Impl } from "./src/Scorm2004API";
8
- import { AICCImpl } from "./src/AICC";
7
+ import { Scorm2004API as Scorm2004Impl } from "./src/Scorm2004API";
8
+ import { AICC as AICCImpl } from "./src/AICC";
9
9
 
10
10
  declare class Scorm12API extends Scorm12Impl {
11
11
  constructor(settings?: Settings);
@@ -21,6 +21,13 @@ declare class Scorm12API extends Scorm12Impl {
21
21
  LMSGetErrorString: (CMIErrorCode: string) => string;
22
22
  LMSGetDiagnostic: (CMIErrorCode: string) => string;
23
23
 
24
+ loadFromJSON: (json: any, CMIElement?: string) => void;
25
+ loadFromFlattenedJSON: (json: any, CMIElement?: string) => void;
26
+ on: (listenerName: string, callback: Function) => void;
27
+ off: (listenerName: string, callback: Function) => void;
28
+ clear: (listenerName: string) => void;
29
+
30
+
24
31
  /**
25
32
  * Called when the API needs to be reset
26
33
  */
@@ -41,6 +48,13 @@ declare class Scorm2004API extends Scorm2004Impl {
41
48
  GetErrorString: (CMIErrorCode: string) => string;
42
49
  GetDiagnostic: (CMIErrorCode: string) => string;
43
50
 
51
+ loadFromJSON: (json: any, CMIElement?: string) => void;
52
+ loadFromFlattenedJSON: (json: any, CMIElement?: string) => void;
53
+ on: (listenerName: string, callback: Function) => void;
54
+ off: (listenerName: string, callback: Function) => void;
55
+ clear: (listenerName: string) => void;
56
+
57
+
44
58
  /**
45
59
  * Called when the API needs to be reset
46
60
  */
@@ -61,6 +75,13 @@ declare class AICC extends AICCImpl {
61
75
  LMSGetErrorString: (CMIErrorCode: string) => string;
62
76
  LMSGetDiagnostic: (CMIErrorCode: string) => string;
63
77
 
78
+ loadFromJSON: (json: any, CMIElement?: string) => void;
79
+ loadFromFlattenedJSON: (json: any, CMIElement?: string) => void;
80
+ on: (listenerName: string, callback: Function) => void;
81
+ off: (listenerName: string, callback: Function) => void;
82
+ clear: (listenerName: string) => void;
83
+
84
+
64
85
  /**
65
86
  * Called when the API needs to be reset
66
87
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scorm-again",
3
- "version": "2.6.1",
3
+ "version": "2.6.3",
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,15 +1138,16 @@ 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);
1146
1145
  const response = await this.performFetch(url, params);
1147
1146
 
1148
1147
  return this.transformResponse(response);
1149
- } catch (e) {
1150
- this.apiLog("processHttpRequest", e, LogLevelEnum.ERROR);
1148
+ } catch (e: unknown) {
1149
+ const message = e instanceof Error ? e.message : String(e);
1150
+ this.apiLog("processHttpRequest", message, LogLevelEnum.ERROR);
1151
1151
  api.processListeners("CommitError");
1152
1152
  return genericError;
1153
1153
  }
@@ -1258,7 +1258,7 @@ export default abstract class BaseAPI implements IBaseAPI {
1258
1258
  url: string,
1259
1259
  params: RefObject | Array<any>,
1260
1260
  ): Promise<Response> {
1261
- return fetch(url, {
1261
+ let init = {
1262
1262
  method: "POST",
1263
1263
  mode: this.settings.fetchMode,
1264
1264
  body: params instanceof Array ? params.join("&") : JSON.stringify(params),
@@ -1266,9 +1266,17 @@ export default abstract class BaseAPI implements IBaseAPI {
1266
1266
  ...this.settings.xhrHeaders,
1267
1267
  "Content-Type": this.settings.commitRequestDataType,
1268
1268
  },
1269
- credentials: this.settings.xhrWithCredentials ? "include" : undefined,
1270
1269
  keepalive: true,
1271
- });
1270
+ } as RequestInit;
1271
+
1272
+ if (this.settings.xhrWithCredentials) {
1273
+ init = {
1274
+ ...init,
1275
+ credentials: "include",
1276
+ };
1277
+ }
1278
+
1279
+ return fetch(url, init);
1272
1280
  }
1273
1281
 
1274
1282
  /**
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,
@@ -9,7 +9,14 @@ export const scorm12_regex = {
9
9
  CMIDecimal: "^-?([0-9]{0,3})(.[0-9]*)?$",
10
10
 
11
11
  CMIIdentifier: "^[\\u0021-\\u007E\\s]{0,255}$",
12
- CMIFeedback: "^.{0,255}$",
12
+ // Allow storing larger responses for interactions
13
+ // Some content packages may exceed the 255 character limit
14
+ // defined in the SCORM 1.2 specification. The previous
15
+ // expression truncated these values which resulted in
16
+ // a "101: General Exception" being thrown when long
17
+ // answers were supplied. To support these packages we
18
+ // relax the limitation and accept any length string.
19
+ CMIFeedback: "^.*$",
13
20
  // This must be redefined
14
21
  CMIIndex: "[._](\\d+).",
15
22
  // Vocabulary Data Type Definition
@@ -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", () => {