scorm-again 2.4.1 → 2.5.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.
- package/README.md +23 -23
- package/dist/aicc.js +55 -35
- package/dist/aicc.js.map +1 -1
- package/dist/aicc.min.js +1 -1
- package/dist/aicc.min.js.map +1 -1
- package/dist/esm/aicc.js +55 -35
- package/dist/esm/aicc.js.map +1 -1
- package/dist/esm/aicc.min.js +1 -1
- package/dist/esm/aicc.min.js.map +1 -1
- package/dist/esm/scorm-again.js +68 -42
- package/dist/esm/scorm-again.js.map +1 -1
- package/dist/esm/scorm-again.min.js +1 -1
- package/dist/esm/scorm-again.min.js.map +1 -1
- package/dist/esm/scorm12.js +55 -35
- package/dist/esm/scorm12.js.map +1 -1
- package/dist/esm/scorm12.min.js +1 -1
- package/dist/esm/scorm12.min.js.map +1 -1
- package/dist/esm/scorm2004.js +68 -42
- package/dist/esm/scorm2004.js.map +1 -1
- package/dist/esm/scorm2004.min.js +1 -1
- package/dist/esm/scorm2004.min.js.map +1 -1
- package/dist/scorm-again.js +68 -42
- package/dist/scorm-again.js.map +1 -1
- package/dist/scorm-again.min.js +1 -1
- package/dist/scorm-again.min.js.map +1 -1
- package/dist/scorm12.js +55 -35
- package/dist/scorm12.js.map +1 -1
- package/dist/scorm12.min.js +1 -1
- package/dist/scorm12.min.js.map +1 -1
- package/dist/scorm2004.js +68 -42
- package/dist/scorm2004.js.map +1 -1
- package/dist/scorm2004.min.js +1 -1
- package/dist/scorm2004.min.js.map +1 -1
- package/package.json +4 -4
- package/src/BaseAPI.ts +27 -65
- package/src/Scorm2004API.ts +8 -4
- package/src/constants/api_constants.ts +0 -10
- package/src/constants/default_settings.ts +20 -7
- package/src/constants/enums.ts +9 -0
- package/src/constants/regex.ts +1 -1
- package/src/exceptions.ts +1 -5
- package/src/types/api_types.ts +26 -3
- package/test/types/api_types.spec.ts +38 -45
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scorm-again",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
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",
|
|
@@ -52,16 +52,16 @@
|
|
|
52
52
|
"jsdoc-babel": "^0.5.0",
|
|
53
53
|
"minimist": "^1.2.8",
|
|
54
54
|
"miragejs": "^0.2.0-alpha.3",
|
|
55
|
-
"mocha": "^10.
|
|
55
|
+
"mocha": "^10.8.2",
|
|
56
56
|
"mocha-junit-reporter": "^2.2.1",
|
|
57
57
|
"mochawesome": "^7.1.3",
|
|
58
58
|
"prettier": "^3.3.3",
|
|
59
59
|
"sinon": "^19.0.2",
|
|
60
60
|
"terser-webpack-plugin": "^5.3.10",
|
|
61
61
|
"ts-loader": "^9.5.1",
|
|
62
|
-
"tsx": "^4.19.
|
|
62
|
+
"tsx": "^4.19.2",
|
|
63
63
|
"typescript": "^5.6.3",
|
|
64
|
-
"typescript-eslint": "^8.
|
|
64
|
+
"typescript-eslint": "^8.12.2",
|
|
65
65
|
"webpack": "^5.91.0",
|
|
66
66
|
"webpack-cli": "^5.1.4"
|
|
67
67
|
},
|
package/src/BaseAPI.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { formatMessage, stringMatches, unflatten } from "./utilities";
|
|
|
6
6
|
import { BaseCMI } from "./cmi/common/base_cmi";
|
|
7
7
|
import {
|
|
8
8
|
CommitObject,
|
|
9
|
+
LogLevel,
|
|
9
10
|
RefObject,
|
|
10
11
|
ResultObject,
|
|
11
12
|
Settings,
|
|
@@ -13,6 +14,7 @@ import {
|
|
|
13
14
|
import { DefaultSettings } from "./constants/default_settings";
|
|
14
15
|
import { IBaseAPI } from "./interfaces/IBaseAPI";
|
|
15
16
|
import { ScheduledCommit } from "./helpers/scheduled_commit";
|
|
17
|
+
import { LogLevelEnum } from "./constants/enums";
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* Base API class for AICC, SCORM 1.2, and SCORM 2004. Should be considered
|
|
@@ -44,6 +46,10 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
44
46
|
}
|
|
45
47
|
this.apiLogLevel = this.settings.logLevel;
|
|
46
48
|
this.selfReportSessionTime = this.settings.selfReportSessionTime;
|
|
49
|
+
|
|
50
|
+
if (this.apiLogLevel === undefined) {
|
|
51
|
+
this.apiLogLevel = LogLevelEnum.NONE;
|
|
52
|
+
}
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
public abstract cmi: BaseCMI;
|
|
@@ -52,7 +58,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
52
58
|
public currentState: number;
|
|
53
59
|
public lastErrorCode: string;
|
|
54
60
|
public listenerArray: any[];
|
|
55
|
-
public apiLogLevel:
|
|
61
|
+
public apiLogLevel: LogLevel;
|
|
56
62
|
public selfReportSessionTime: boolean;
|
|
57
63
|
|
|
58
64
|
abstract reset(settings?: Settings): void;
|
|
@@ -99,11 +105,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
99
105
|
this.processListeners(callbackName);
|
|
100
106
|
}
|
|
101
107
|
|
|
102
|
-
this.apiLog(
|
|
103
|
-
callbackName,
|
|
104
|
-
"returned: " + returnValue,
|
|
105
|
-
APIConstants.global.LOG_LEVEL_INFO,
|
|
106
|
-
);
|
|
108
|
+
this.apiLog(callbackName, "returned: " + returnValue, LogLevelEnum.INFO);
|
|
107
109
|
this.clearSCORMError(returnValue);
|
|
108
110
|
|
|
109
111
|
return returnValue;
|
|
@@ -187,7 +189,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
187
189
|
apiLog(
|
|
188
190
|
functionName: string,
|
|
189
191
|
logMessage: string,
|
|
190
|
-
messageLevel:
|
|
192
|
+
messageLevel: LogLevel,
|
|
191
193
|
CMIElement?: string,
|
|
192
194
|
) {
|
|
193
195
|
logMessage = formatMessage(functionName, logMessage, CMIElement);
|
|
@@ -257,11 +259,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
257
259
|
this.processListeners(callbackName);
|
|
258
260
|
}
|
|
259
261
|
|
|
260
|
-
this.apiLog(
|
|
261
|
-
callbackName,
|
|
262
|
-
"returned: " + returnValue,
|
|
263
|
-
APIConstants.global.LOG_LEVEL_INFO,
|
|
264
|
-
);
|
|
262
|
+
this.apiLog(callbackName, "returned: " + returnValue, LogLevelEnum.INFO);
|
|
265
263
|
this.clearSCORMError(returnValue);
|
|
266
264
|
|
|
267
265
|
return returnValue;
|
|
@@ -301,7 +299,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
301
299
|
this.apiLog(
|
|
302
300
|
callbackName,
|
|
303
301
|
": returned: " + returnValue,
|
|
304
|
-
|
|
302
|
+
LogLevelEnum.INFO,
|
|
305
303
|
CMIElement,
|
|
306
304
|
);
|
|
307
305
|
|
|
@@ -370,7 +368,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
370
368
|
this.apiLog(
|
|
371
369
|
callbackName,
|
|
372
370
|
": " + value + ": result: " + returnValue,
|
|
373
|
-
|
|
371
|
+
LogLevelEnum.INFO,
|
|
374
372
|
CMIElement,
|
|
375
373
|
);
|
|
376
374
|
this.clearSCORMError(returnValue);
|
|
@@ -388,7 +386,6 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
388
386
|
callbackName: string,
|
|
389
387
|
checkTerminated: boolean = false,
|
|
390
388
|
): Promise<string> {
|
|
391
|
-
console.log("commit");
|
|
392
389
|
this.clearScheduledCommit();
|
|
393
390
|
|
|
394
391
|
let returnValue = APIConstants.global.SCORM_FALSE;
|
|
@@ -412,7 +409,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
412
409
|
this.apiLog(
|
|
413
410
|
callbackName,
|
|
414
411
|
" Result: " + returnValue,
|
|
415
|
-
|
|
412
|
+
LogLevelEnum.DEBUG,
|
|
416
413
|
"HttpRequest",
|
|
417
414
|
);
|
|
418
415
|
|
|
@@ -421,11 +418,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
421
418
|
this.processListeners(callbackName);
|
|
422
419
|
}
|
|
423
420
|
|
|
424
|
-
this.apiLog(
|
|
425
|
-
callbackName,
|
|
426
|
-
"returned: " + returnValue,
|
|
427
|
-
APIConstants.global.LOG_LEVEL_INFO,
|
|
428
|
-
);
|
|
421
|
+
this.apiLog(callbackName, "returned: " + returnValue, LogLevelEnum.INFO);
|
|
429
422
|
this.clearSCORMError(returnValue);
|
|
430
423
|
|
|
431
424
|
return returnValue;
|
|
@@ -441,11 +434,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
441
434
|
|
|
442
435
|
this.processListeners(callbackName);
|
|
443
436
|
|
|
444
|
-
this.apiLog(
|
|
445
|
-
callbackName,
|
|
446
|
-
"returned: " + returnValue,
|
|
447
|
-
APIConstants.global.LOG_LEVEL_INFO,
|
|
448
|
-
);
|
|
437
|
+
this.apiLog(callbackName, "returned: " + returnValue, LogLevelEnum.INFO);
|
|
449
438
|
|
|
450
439
|
return returnValue;
|
|
451
440
|
}
|
|
@@ -465,11 +454,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
465
454
|
this.processListeners(callbackName);
|
|
466
455
|
}
|
|
467
456
|
|
|
468
|
-
this.apiLog(
|
|
469
|
-
callbackName,
|
|
470
|
-
"returned: " + returnValue,
|
|
471
|
-
APIConstants.global.LOG_LEVEL_INFO,
|
|
472
|
-
);
|
|
457
|
+
this.apiLog(callbackName, "returned: " + returnValue, LogLevelEnum.INFO);
|
|
473
458
|
|
|
474
459
|
return returnValue;
|
|
475
460
|
}
|
|
@@ -489,11 +474,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
489
474
|
this.processListeners(callbackName);
|
|
490
475
|
}
|
|
491
476
|
|
|
492
|
-
this.apiLog(
|
|
493
|
-
callbackName,
|
|
494
|
-
"returned: " + returnValue,
|
|
495
|
-
APIConstants.global.LOG_LEVEL_INFO,
|
|
496
|
-
);
|
|
477
|
+
this.apiLog(callbackName, "returned: " + returnValue, LogLevelEnum.INFO);
|
|
497
478
|
|
|
498
479
|
return returnValue;
|
|
499
480
|
}
|
|
@@ -668,7 +649,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
668
649
|
this.apiLog(
|
|
669
650
|
methodName,
|
|
670
651
|
`There was an error setting the value for: ${CMIElement}, value of: ${value}`,
|
|
671
|
-
|
|
652
|
+
LogLevelEnum.WARN,
|
|
672
653
|
);
|
|
673
654
|
}
|
|
674
655
|
|
|
@@ -827,7 +808,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
827
808
|
this.apiLog(
|
|
828
809
|
"on",
|
|
829
810
|
`Added event listener: ${this.listenerArray.length}`,
|
|
830
|
-
|
|
811
|
+
LogLevelEnum.INFO,
|
|
831
812
|
functionName,
|
|
832
813
|
);
|
|
833
814
|
}
|
|
@@ -865,7 +846,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
865
846
|
this.apiLog(
|
|
866
847
|
"off",
|
|
867
848
|
`Removed event listener: ${this.listenerArray.length}`,
|
|
868
|
-
|
|
849
|
+
LogLevelEnum.INFO,
|
|
869
850
|
functionName,
|
|
870
851
|
);
|
|
871
852
|
}
|
|
@@ -905,12 +886,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
905
886
|
* @param {any} value
|
|
906
887
|
*/
|
|
907
888
|
processListeners(functionName: string, CMIElement?: string, value?: any) {
|
|
908
|
-
this.apiLog(
|
|
909
|
-
functionName,
|
|
910
|
-
value,
|
|
911
|
-
APIConstants.global.LOG_LEVEL_INFO,
|
|
912
|
-
CMIElement,
|
|
913
|
-
);
|
|
889
|
+
this.apiLog(functionName, value, LogLevelEnum.INFO, CMIElement);
|
|
914
890
|
for (let i = 0; i < this.listenerArray.length; i++) {
|
|
915
891
|
const listener = this.listenerArray[i];
|
|
916
892
|
const functionsMatch = listener.functionName === functionName;
|
|
@@ -933,7 +909,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
933
909
|
this.apiLog(
|
|
934
910
|
"processListeners",
|
|
935
911
|
`Processing listener: ${listener.functionName}`,
|
|
936
|
-
|
|
912
|
+
LogLevelEnum.INFO,
|
|
937
913
|
CMIElement,
|
|
938
914
|
);
|
|
939
915
|
listener.callback(CMIElement, value);
|
|
@@ -955,7 +931,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
955
931
|
this.apiLog(
|
|
956
932
|
"throwSCORMError",
|
|
957
933
|
errorNumber + ": " + message,
|
|
958
|
-
|
|
934
|
+
LogLevelEnum.ERROR,
|
|
959
935
|
);
|
|
960
936
|
|
|
961
937
|
this.lastErrorCode = String(errorNumber);
|
|
@@ -1164,11 +1140,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1164
1140
|
|
|
1165
1141
|
return this.transformResponse(response);
|
|
1166
1142
|
} catch (e) {
|
|
1167
|
-
this.apiLog(
|
|
1168
|
-
"processHttpRequest",
|
|
1169
|
-
e,
|
|
1170
|
-
APIConstants.global.LOG_LEVEL_ERROR,
|
|
1171
|
-
);
|
|
1143
|
+
this.apiLog("processHttpRequest", e, LogLevelEnum.ERROR);
|
|
1172
1144
|
api.processListeners("CommitError");
|
|
1173
1145
|
return genericError;
|
|
1174
1146
|
}
|
|
@@ -1186,12 +1158,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1186
1158
|
scheduleCommit(when: number, callback: string) {
|
|
1187
1159
|
if (!this._timeout) {
|
|
1188
1160
|
this._timeout = new ScheduledCommit(this, when, callback);
|
|
1189
|
-
this.apiLog(
|
|
1190
|
-
"scheduleCommit",
|
|
1191
|
-
"scheduled",
|
|
1192
|
-
APIConstants.global.LOG_LEVEL_DEBUG,
|
|
1193
|
-
"",
|
|
1194
|
-
);
|
|
1161
|
+
this.apiLog("scheduleCommit", "scheduled", LogLevelEnum.DEBUG, "");
|
|
1195
1162
|
}
|
|
1196
1163
|
}
|
|
1197
1164
|
|
|
@@ -1202,12 +1169,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1202
1169
|
if (this._timeout) {
|
|
1203
1170
|
this._timeout.cancel();
|
|
1204
1171
|
this._timeout = undefined;
|
|
1205
|
-
this.apiLog(
|
|
1206
|
-
"clearScheduledCommit",
|
|
1207
|
-
"cleared",
|
|
1208
|
-
APIConstants.global.LOG_LEVEL_DEBUG,
|
|
1209
|
-
"",
|
|
1210
|
-
);
|
|
1172
|
+
this.apiLog("clearScheduledCommit", "cleared", LogLevelEnum.DEBUG, "");
|
|
1211
1173
|
}
|
|
1212
1174
|
}
|
|
1213
1175
|
|
|
@@ -1269,7 +1231,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1269
1231
|
? this.renderCommitObject(shouldTerminateCommit)
|
|
1270
1232
|
: this.renderCommitCMI(shouldTerminateCommit);
|
|
1271
1233
|
|
|
1272
|
-
if (
|
|
1234
|
+
if ([LogLevelEnum.DEBUG, "1", 1, "DEBUG"].includes(this.apiLogLevel)) {
|
|
1273
1235
|
console.debug(
|
|
1274
1236
|
"Commit (terminated: " + (terminateCommit ? "yes" : "no") + "): ",
|
|
1275
1237
|
);
|
package/src/Scorm2004API.ts
CHANGED
|
@@ -128,9 +128,14 @@ class Scorm2004Impl extends BaseAPI {
|
|
|
128
128
|
const choiceJumpRegex = new RegExp(regex.scorm2004.NAVEvent);
|
|
129
129
|
const matches = request.match(choiceJumpRegex);
|
|
130
130
|
let target = "";
|
|
131
|
-
if (matches
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
if (matches) {
|
|
132
|
+
if (matches.groups?.choice_target) {
|
|
133
|
+
target = matches.groups?.choice_target;
|
|
134
|
+
request = "choice";
|
|
135
|
+
} else if (matches.groups?.jump_target) {
|
|
136
|
+
target = matches.groups?.jump_target;
|
|
137
|
+
request = "jump";
|
|
138
|
+
}
|
|
134
139
|
}
|
|
135
140
|
const action = navActions[request];
|
|
136
141
|
if (action) {
|
|
@@ -718,7 +723,6 @@ class Scorm2004Impl extends BaseAPI {
|
|
|
718
723
|
this.adl.nav.request !== this.startingData?.adl?.nav?.request &&
|
|
719
724
|
this.adl.nav.request !== "_none_"
|
|
720
725
|
) {
|
|
721
|
-
this.adl.nav.request = encodeURIComponent(this.adl.nav.request);
|
|
722
726
|
navRequest = true;
|
|
723
727
|
}
|
|
724
728
|
|
|
@@ -45,11 +45,6 @@ interface GlobalConstants {
|
|
|
45
45
|
STATE_NOT_INITIALIZED: number;
|
|
46
46
|
STATE_INITIALIZED: number;
|
|
47
47
|
STATE_TERMINATED: number;
|
|
48
|
-
LOG_LEVEL_DEBUG: number;
|
|
49
|
-
LOG_LEVEL_INFO: number;
|
|
50
|
-
LOG_LEVEL_WARNING: number;
|
|
51
|
-
LOG_LEVEL_ERROR: number;
|
|
52
|
-
LOG_LEVEL_NONE: number;
|
|
53
48
|
}
|
|
54
49
|
|
|
55
50
|
interface APIConstants {
|
|
@@ -65,11 +60,6 @@ const global: GlobalConstants = {
|
|
|
65
60
|
STATE_NOT_INITIALIZED: 0,
|
|
66
61
|
STATE_INITIALIZED: 1,
|
|
67
62
|
STATE_TERMINATED: 2,
|
|
68
|
-
LOG_LEVEL_DEBUG: 1,
|
|
69
|
-
LOG_LEVEL_INFO: 2,
|
|
70
|
-
LOG_LEVEL_WARNING: 3,
|
|
71
|
-
LOG_LEVEL_ERROR: 4,
|
|
72
|
-
LOG_LEVEL_NONE: 5,
|
|
73
63
|
};
|
|
74
64
|
|
|
75
65
|
const scorm12: ScormConstants = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ResultObject, Settings } from "../types/api_types";
|
|
1
|
+
import { LogLevel, ResultObject, Settings } from "../types/api_types";
|
|
2
2
|
import APIConstants from "./api_constants";
|
|
3
|
+
import { LogLevelEnum } from "./enums";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Default settings for the SCORM API
|
|
@@ -13,7 +14,7 @@ export const DefaultSettings: Settings = {
|
|
|
13
14
|
dataCommitFormat: "json",
|
|
14
15
|
commitRequestDataType: "application/json;charset=UTF-8",
|
|
15
16
|
autoProgress: false,
|
|
16
|
-
logLevel:
|
|
17
|
+
logLevel: LogLevelEnum.ERROR,
|
|
17
18
|
selfReportSessionTime: false,
|
|
18
19
|
alwaysSendTotalTime: false,
|
|
19
20
|
renderCommonCommitFields: false,
|
|
@@ -62,18 +63,30 @@ export const DefaultSettings: Settings = {
|
|
|
62
63
|
requestHandler: function (commitObject) {
|
|
63
64
|
return commitObject;
|
|
64
65
|
},
|
|
65
|
-
onLogMessage: function (messageLevel, logMessage) {
|
|
66
|
+
onLogMessage: function (messageLevel: LogLevel, logMessage) {
|
|
66
67
|
switch (messageLevel) {
|
|
67
|
-
case
|
|
68
|
+
case "4":
|
|
69
|
+
case 4:
|
|
70
|
+
case "ERROR":
|
|
71
|
+
case LogLevelEnum.ERROR:
|
|
68
72
|
console.error(logMessage);
|
|
69
73
|
break;
|
|
70
|
-
case
|
|
74
|
+
case "3":
|
|
75
|
+
case 3:
|
|
76
|
+
case "WARN":
|
|
77
|
+
case LogLevelEnum.WARN:
|
|
71
78
|
console.warn(logMessage);
|
|
72
79
|
break;
|
|
73
|
-
case
|
|
80
|
+
case "2":
|
|
81
|
+
case 2:
|
|
82
|
+
case "INFO":
|
|
83
|
+
case LogLevelEnum.INFO:
|
|
74
84
|
console.info(logMessage);
|
|
75
85
|
break;
|
|
76
|
-
case
|
|
86
|
+
case "1":
|
|
87
|
+
case 1:
|
|
88
|
+
case "DEBUG":
|
|
89
|
+
case LogLevelEnum.DEBUG:
|
|
77
90
|
if (console.debug) {
|
|
78
91
|
console.debug(logMessage);
|
|
79
92
|
} else {
|
package/src/constants/enums.ts
CHANGED
package/src/constants/regex.ts
CHANGED
|
@@ -78,7 +78,7 @@ const scorm2004 = {
|
|
|
78
78
|
CMIResult:
|
|
79
79
|
"^(correct|incorrect|unanticipated|neutral|-?([0-9]{1,4})(\\.[0-9]{1,18})?)$",
|
|
80
80
|
NAVEvent:
|
|
81
|
-
"^(previous|continue|exit|exitAll|abandon|abandonAll|suspendAll|_none_|(\\{target
|
|
81
|
+
"^(previous|continue|exit|exitAll|abandon|abandonAll|suspendAll|_none_|(\\{target=(?<choice_target>\\S{0,}[a-zA-Z0-9-_]+)})?choice|(\\{target=(?<jump_target>\\S{0,}[a-zA-Z0-9-_]+)})?jump)$",
|
|
82
82
|
|
|
83
83
|
NAVBoolean: "^(unknown|true|false$)",
|
|
84
84
|
NAVTarget: "^{target=\\S{0,}[a-zA-Z0-9-_]+}$",
|
package/src/exceptions.ts
CHANGED
|
@@ -26,10 +26,6 @@ export class BaseScormValidationError extends Error {
|
|
|
26
26
|
get errorCode(): number {
|
|
27
27
|
return this._errorCode;
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
setMessage(message: string) {
|
|
31
|
-
this.message = message;
|
|
32
|
-
}
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
/**
|
|
@@ -51,7 +47,7 @@ export class ValidationError
|
|
|
51
47
|
detailedMessage?: string,
|
|
52
48
|
) {
|
|
53
49
|
super(errorCode);
|
|
54
|
-
this.
|
|
50
|
+
this.message = errorMessage;
|
|
55
51
|
this._errorMessage = errorMessage;
|
|
56
52
|
if (detailedMessage) {
|
|
57
53
|
this._detailedMessage = detailedMessage;
|
package/src/types/api_types.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
CompletionStatus,
|
|
3
|
+
LogLevelEnum,
|
|
4
|
+
SuccessStatus,
|
|
5
|
+
} from "../constants/enums";
|
|
2
6
|
|
|
3
7
|
export type Settings = {
|
|
4
8
|
autocommit?: boolean;
|
|
@@ -9,7 +13,7 @@ export type Settings = {
|
|
|
9
13
|
dataCommitFormat?: string;
|
|
10
14
|
commitRequestDataType?: string;
|
|
11
15
|
autoProgress?: boolean;
|
|
12
|
-
logLevel?:
|
|
16
|
+
logLevel?: LogLevel;
|
|
13
17
|
selfReportSessionTime?: boolean;
|
|
14
18
|
alwaysSendTotalTime?: boolean;
|
|
15
19
|
strict_errors?: boolean;
|
|
@@ -18,7 +22,7 @@ export type Settings = {
|
|
|
18
22
|
fetchMode?: "cors" | "no-cors" | "same-origin" | "navigate";
|
|
19
23
|
responseHandler?: (response: Response) => Promise<ResultObject>;
|
|
20
24
|
requestHandler?: (commitObject: any) => any;
|
|
21
|
-
onLogMessage?: (messageLevel:
|
|
25
|
+
onLogMessage?: (messageLevel: LogLevel, logMessage: string) => void;
|
|
22
26
|
scoItemIds?: string[];
|
|
23
27
|
scoItemIdValidator?: false | ((scoItemId: string) => boolean);
|
|
24
28
|
mastery_override?: boolean;
|
|
@@ -49,3 +53,22 @@ export type CommitObject = {
|
|
|
49
53
|
runtimeData: RefObject;
|
|
50
54
|
score?: ScoreObject;
|
|
51
55
|
};
|
|
56
|
+
|
|
57
|
+
export type LogLevel =
|
|
58
|
+
| 1
|
|
59
|
+
| 2
|
|
60
|
+
| 3
|
|
61
|
+
| 4
|
|
62
|
+
| 5
|
|
63
|
+
| "1"
|
|
64
|
+
| "2"
|
|
65
|
+
| "3"
|
|
66
|
+
| "4"
|
|
67
|
+
| "5"
|
|
68
|
+
| "DEBUG"
|
|
69
|
+
| "INFO"
|
|
70
|
+
| "WARN"
|
|
71
|
+
| "ERROR"
|
|
72
|
+
| "NONE"
|
|
73
|
+
| LogLevelEnum
|
|
74
|
+
| undefined;
|
|
@@ -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";
|
|
3
|
+
import { LogLevel, ResultObject, Settings } from "../../src/types/api_types";
|
|
4
4
|
import APIConstants from "../../src/constants/api_constants";
|
|
5
|
+
import { LogLevelEnum } from "../../src/constants/enums";
|
|
6
|
+
import { DefaultSettings } from "../../src/constants/default_settings";
|
|
7
|
+
import { SinonStub } from "sinon";
|
|
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:
|
|
19
|
+
logLevel: LogLevelEnum.ERROR,
|
|
17
20
|
selfReportSessionTime: false,
|
|
18
21
|
alwaysSendTotalTime: false,
|
|
19
22
|
strict_errors: true,
|
|
@@ -28,26 +31,7 @@ describe("Settings Type", () => {
|
|
|
28
31
|
};
|
|
29
32
|
},
|
|
30
33
|
requestHandler: (commitObject: any) => commitObject,
|
|
31
|
-
onLogMessage:
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
);
|
|
118
|
-
|
|
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();
|