scorm-again 2.6.6 → 2.6.8
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/.claude/settings.local.json +94 -2
- package/dist/aicc.js +3095 -3070
- 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 +3088 -3069
- 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 +5616 -5591
- 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 +2837 -2812
- 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 +1955 -1936
- 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 +5616 -5591
- 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 +2832 -2807
- 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 +1798 -1773
- package/dist/scorm2004.js.map +1 -1
- package/dist/scorm2004.min.js +1 -1
- package/dist/scorm2004.min.js.map +1 -1
- package/dist/types/types/api_types.d.ts +1 -1
- package/examples/react-native-offline/.claude/settings.local.json +31 -0
- package/index.d.ts +24 -81
- package/package.json +25 -1
- package/src/BaseAPI.ts +70 -63
- package/src/Scorm2004API.ts +2 -2
- package/src/constants/default_settings.ts +12 -12
- package/src/types/api_types.ts +2 -6
- package/tsconfig.json +1 -2
- package/.claude/.claude/settings.local.json +0 -13
package/src/BaseAPI.ts
CHANGED
|
@@ -4,7 +4,14 @@ 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 {
|
|
7
|
+
import {
|
|
8
|
+
CommitObject,
|
|
9
|
+
InternalSettings,
|
|
10
|
+
LogLevel,
|
|
11
|
+
RefObject,
|
|
12
|
+
ResultObject,
|
|
13
|
+
Settings
|
|
14
|
+
} from "./types/api_types";
|
|
8
15
|
import { DefaultSettings } from "./constants/default_settings";
|
|
9
16
|
import { IBaseAPI } from "./interfaces/IBaseAPI";
|
|
10
17
|
import { ScheduledCommit } from "./helpers/scheduled_commit";
|
|
@@ -38,7 +45,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
38
45
|
if (settings) {
|
|
39
46
|
this.settings = {
|
|
40
47
|
...DefaultSettings,
|
|
41
|
-
...settings
|
|
48
|
+
...settings
|
|
42
49
|
} as InternalSettings;
|
|
43
50
|
}
|
|
44
51
|
this.apiLogLevel = this.settings.logLevel ?? LogLevelEnum.ERROR;
|
|
@@ -83,19 +90,19 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
83
90
|
initialize(
|
|
84
91
|
callbackName: string,
|
|
85
92
|
initializeMessage?: string,
|
|
86
|
-
terminationMessage?: string
|
|
93
|
+
terminationMessage?: string
|
|
87
94
|
): string {
|
|
88
95
|
let returnValue = global_constants.SCORM_FALSE;
|
|
89
96
|
|
|
90
97
|
if (this.isInitialized()) {
|
|
91
98
|
this.throwSCORMError(
|
|
92
99
|
this._error_codes.INITIALIZED as number,
|
|
93
|
-
initializeMessage
|
|
100
|
+
initializeMessage
|
|
94
101
|
);
|
|
95
102
|
} else if (this.isTerminated()) {
|
|
96
103
|
this.throwSCORMError(
|
|
97
104
|
this._error_codes.TERMINATED as number,
|
|
98
|
-
terminationMessage
|
|
105
|
+
terminationMessage
|
|
99
106
|
);
|
|
100
107
|
} else {
|
|
101
108
|
if (this.selfReportSessionTime) {
|
|
@@ -151,7 +158,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
151
158
|
abstract getChildElement(
|
|
152
159
|
_CMIElement: string,
|
|
153
160
|
_value: any,
|
|
154
|
-
_foundFirstIndex: boolean
|
|
161
|
+
_foundFirstIndex: boolean
|
|
155
162
|
): BaseCMI | null;
|
|
156
163
|
|
|
157
164
|
/**
|
|
@@ -193,7 +200,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
193
200
|
functionName: string,
|
|
194
201
|
logMessage: string,
|
|
195
202
|
messageLevel: LogLevel,
|
|
196
|
-
CMIElement?: string
|
|
203
|
+
CMIElement?: string
|
|
197
204
|
) {
|
|
198
205
|
logMessage = formatMessage(functionName, logMessage, CMIElement);
|
|
199
206
|
|
|
@@ -234,7 +241,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
234
241
|
*/
|
|
235
242
|
async terminate(
|
|
236
243
|
callbackName: string,
|
|
237
|
-
checkTerminated: boolean
|
|
244
|
+
checkTerminated: boolean
|
|
238
245
|
): Promise<string> {
|
|
239
246
|
let returnValue = global_constants.SCORM_FALSE;
|
|
240
247
|
|
|
@@ -242,7 +249,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
242
249
|
this.checkState(
|
|
243
250
|
checkTerminated,
|
|
244
251
|
this._error_codes.TERMINATION_BEFORE_INIT as number,
|
|
245
|
-
this._error_codes.MULTIPLE_TERMINATION as number
|
|
252
|
+
this._error_codes.MULTIPLE_TERMINATION as number
|
|
246
253
|
)
|
|
247
254
|
) {
|
|
248
255
|
this.currentState = global_constants.STATE_TERMINATED;
|
|
@@ -252,8 +259,8 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
252
259
|
this.throwSCORMError(result.errorCode);
|
|
253
260
|
}
|
|
254
261
|
returnValue =
|
|
255
|
-
typeof result !== "undefined" && result.result
|
|
256
|
-
?
|
|
262
|
+
typeof result !== "undefined" && (result.result === true || result.result === global_constants.SCORM_TRUE)
|
|
263
|
+
? global_constants.SCORM_TRUE
|
|
257
264
|
: global_constants.SCORM_FALSE;
|
|
258
265
|
|
|
259
266
|
if (checkTerminated) this.lastErrorCode = "0";
|
|
@@ -279,7 +286,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
279
286
|
getValue(
|
|
280
287
|
callbackName: string,
|
|
281
288
|
checkTerminated: boolean,
|
|
282
|
-
CMIElement: string
|
|
289
|
+
CMIElement: string
|
|
283
290
|
): string {
|
|
284
291
|
let returnValue: string = "";
|
|
285
292
|
|
|
@@ -287,7 +294,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
287
294
|
this.checkState(
|
|
288
295
|
checkTerminated,
|
|
289
296
|
this._error_codes.RETRIEVE_BEFORE_INIT as number,
|
|
290
|
-
this._error_codes.RETRIEVE_AFTER_TERM as number
|
|
297
|
+
this._error_codes.RETRIEVE_AFTER_TERM as number
|
|
291
298
|
)
|
|
292
299
|
) {
|
|
293
300
|
if (checkTerminated) this.lastErrorCode = "0";
|
|
@@ -303,7 +310,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
303
310
|
callbackName,
|
|
304
311
|
": returned: " + returnValue,
|
|
305
312
|
LogLevelEnum.INFO,
|
|
306
|
-
CMIElement
|
|
313
|
+
CMIElement
|
|
307
314
|
);
|
|
308
315
|
|
|
309
316
|
if (returnValue === undefined) {
|
|
@@ -330,7 +337,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
330
337
|
commitCallback: string,
|
|
331
338
|
checkTerminated: boolean,
|
|
332
339
|
CMIElement: string,
|
|
333
|
-
value: any
|
|
340
|
+
value: any
|
|
334
341
|
): string {
|
|
335
342
|
if (value !== undefined) {
|
|
336
343
|
value = String(value);
|
|
@@ -341,7 +348,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
341
348
|
this.checkState(
|
|
342
349
|
checkTerminated,
|
|
343
350
|
this._error_codes.STORE_BEFORE_INIT as number,
|
|
344
|
-
this._error_codes.STORE_AFTER_TERM as number
|
|
351
|
+
this._error_codes.STORE_AFTER_TERM as number
|
|
345
352
|
)
|
|
346
353
|
) {
|
|
347
354
|
if (checkTerminated) this.lastErrorCode = "0";
|
|
@@ -363,7 +370,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
363
370
|
if (this.settings.autocommit) {
|
|
364
371
|
this.scheduleCommit(
|
|
365
372
|
this.settings.autocommitSeconds * 1000,
|
|
366
|
-
commitCallback
|
|
373
|
+
commitCallback
|
|
367
374
|
);
|
|
368
375
|
}
|
|
369
376
|
}
|
|
@@ -372,7 +379,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
372
379
|
callbackName,
|
|
373
380
|
": " + value + ": result: " + returnValue,
|
|
374
381
|
LogLevelEnum.INFO,
|
|
375
|
-
CMIElement
|
|
382
|
+
CMIElement
|
|
376
383
|
);
|
|
377
384
|
this.clearSCORMError(returnValue);
|
|
378
385
|
|
|
@@ -387,17 +394,17 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
387
394
|
*/
|
|
388
395
|
async commit(
|
|
389
396
|
callbackName: string,
|
|
390
|
-
checkTerminated: boolean = false
|
|
397
|
+
checkTerminated: boolean = false
|
|
391
398
|
): Promise<string> {
|
|
392
399
|
this.clearScheduledCommit();
|
|
393
400
|
|
|
394
|
-
let returnValue = global_constants.SCORM_FALSE;
|
|
401
|
+
let returnValue: string = global_constants.SCORM_FALSE;
|
|
395
402
|
|
|
396
403
|
if (
|
|
397
404
|
this.checkState(
|
|
398
405
|
checkTerminated,
|
|
399
406
|
this._error_codes.COMMIT_BEFORE_INIT as number,
|
|
400
|
-
this._error_codes.COMMIT_AFTER_TERM as number
|
|
407
|
+
this._error_codes.COMMIT_AFTER_TERM as number
|
|
401
408
|
)
|
|
402
409
|
) {
|
|
403
410
|
const result = await this.storeData(false);
|
|
@@ -405,15 +412,15 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
405
412
|
this.throwSCORMError(result.errorCode);
|
|
406
413
|
}
|
|
407
414
|
returnValue =
|
|
408
|
-
typeof result !== "undefined" && result.result
|
|
409
|
-
?
|
|
415
|
+
typeof result !== "undefined" && (result.result === true || result.result === global_constants.SCORM_TRUE)
|
|
416
|
+
? global_constants.SCORM_TRUE
|
|
410
417
|
: global_constants.SCORM_FALSE;
|
|
411
418
|
|
|
412
419
|
this.apiLog(
|
|
413
420
|
callbackName,
|
|
414
421
|
" Result: " + returnValue,
|
|
415
422
|
LogLevelEnum.DEBUG,
|
|
416
|
-
"HttpRequest"
|
|
423
|
+
"HttpRequest"
|
|
417
424
|
);
|
|
418
425
|
|
|
419
426
|
if (checkTerminated) this.lastErrorCode = "0";
|
|
@@ -493,7 +500,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
493
500
|
checkState(
|
|
494
501
|
checkTerminated: boolean,
|
|
495
502
|
beforeInitError: number,
|
|
496
|
-
afterTermError: number
|
|
503
|
+
afterTermError: number
|
|
497
504
|
): boolean {
|
|
498
505
|
if (this.isNotInitialized()) {
|
|
499
506
|
this.throwSCORMError(beforeInitError);
|
|
@@ -517,10 +524,10 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
517
524
|
*/
|
|
518
525
|
getLmsErrorMessageDetails(
|
|
519
526
|
_errorNumber: string | number,
|
|
520
|
-
_detail: boolean = false
|
|
527
|
+
_detail: boolean = false
|
|
521
528
|
): string {
|
|
522
529
|
throw new Error(
|
|
523
|
-
"The getLmsErrorMessageDetails method has not been implemented"
|
|
530
|
+
"The getLmsErrorMessageDetails method has not been implemented"
|
|
524
531
|
);
|
|
525
532
|
}
|
|
526
533
|
|
|
@@ -562,7 +569,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
562
569
|
methodName: string,
|
|
563
570
|
scorm2004: boolean,
|
|
564
571
|
CMIElement: string,
|
|
565
|
-
value: any
|
|
572
|
+
value: any
|
|
566
573
|
): string {
|
|
567
574
|
if (!CMIElement || CMIElement === "") {
|
|
568
575
|
return global_constants.SCORM_FALSE;
|
|
@@ -592,7 +599,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
592
599
|
} else {
|
|
593
600
|
refObject = {
|
|
594
601
|
...refObject,
|
|
595
|
-
attribute: value
|
|
602
|
+
attribute: value
|
|
596
603
|
};
|
|
597
604
|
}
|
|
598
605
|
} else if (!this._checkObjectHasProperty(refObject, attribute)) {
|
|
@@ -631,14 +638,14 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
631
638
|
const newChild = this.getChildElement(
|
|
632
639
|
CMIElement,
|
|
633
640
|
value,
|
|
634
|
-
foundFirstIndex
|
|
641
|
+
foundFirstIndex
|
|
635
642
|
);
|
|
636
643
|
foundFirstIndex = true;
|
|
637
644
|
|
|
638
645
|
if (!newChild) {
|
|
639
646
|
this.throwSCORMError(
|
|
640
647
|
invalidErrorCode as number,
|
|
641
|
-
invalidErrorMessage
|
|
648
|
+
invalidErrorMessage
|
|
642
649
|
);
|
|
643
650
|
} else {
|
|
644
651
|
if (refObject.initialized) newChild.initialize();
|
|
@@ -659,7 +666,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
659
666
|
this.apiLog(
|
|
660
667
|
methodName,
|
|
661
668
|
`There was an error setting the value for: ${CMIElement}, value of: ${value}`,
|
|
662
|
-
LogLevelEnum.WARN
|
|
669
|
+
LogLevelEnum.WARN
|
|
663
670
|
);
|
|
664
671
|
}
|
|
665
672
|
|
|
@@ -677,7 +684,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
677
684
|
_commonGetCMIValue(
|
|
678
685
|
methodName: string,
|
|
679
686
|
scorm2004: boolean,
|
|
680
|
-
CMIElement: string
|
|
687
|
+
CMIElement: string
|
|
681
688
|
): any {
|
|
682
689
|
if (!CMIElement || CMIElement === "") {
|
|
683
690
|
return "";
|
|
@@ -706,7 +713,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
706
713
|
if (!this._checkObjectHasProperty(refObject, attribute)) {
|
|
707
714
|
this.throwSCORMError(
|
|
708
715
|
invalidErrorCode as number,
|
|
709
|
-
invalidErrorMessage
|
|
716
|
+
invalidErrorMessage
|
|
710
717
|
);
|
|
711
718
|
return;
|
|
712
719
|
}
|
|
@@ -718,7 +725,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
718
725
|
) {
|
|
719
726
|
const target = String(attribute).substring(
|
|
720
727
|
8,
|
|
721
|
-
String(attribute).length - 9
|
|
728
|
+
String(attribute).length - 9
|
|
722
729
|
);
|
|
723
730
|
return refObject._isTargetValid(target);
|
|
724
731
|
} else if (!this._checkObjectHasProperty(refObject, attribute)) {
|
|
@@ -745,7 +752,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
745
752
|
} else {
|
|
746
753
|
this.throwSCORMError(
|
|
747
754
|
this._error_codes.VALUE_NOT_INITIALIZED as number,
|
|
748
|
-
uninitializedErrorMessage
|
|
755
|
+
uninitializedErrorMessage
|
|
749
756
|
);
|
|
750
757
|
break;
|
|
751
758
|
}
|
|
@@ -820,14 +827,14 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
820
827
|
this.listenerArray.push({
|
|
821
828
|
functionName: functionName,
|
|
822
829
|
CMIElement: CMIElement,
|
|
823
|
-
callback: callback
|
|
830
|
+
callback: callback
|
|
824
831
|
});
|
|
825
832
|
|
|
826
833
|
this.apiLog(
|
|
827
834
|
"on",
|
|
828
835
|
`Added event listener: ${this.listenerArray.length}`,
|
|
829
836
|
LogLevelEnum.INFO,
|
|
830
|
-
functionName
|
|
837
|
+
functionName
|
|
831
838
|
);
|
|
832
839
|
}
|
|
833
840
|
}
|
|
@@ -857,7 +864,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
857
864
|
(obj) =>
|
|
858
865
|
obj.functionName === functionName &&
|
|
859
866
|
obj.CMIElement === CMIElement &&
|
|
860
|
-
obj.callback === callback
|
|
867
|
+
obj.callback === callback
|
|
861
868
|
);
|
|
862
869
|
if (removeIndex !== -1) {
|
|
863
870
|
this.listenerArray.splice(removeIndex, 1);
|
|
@@ -865,7 +872,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
865
872
|
"off",
|
|
866
873
|
`Removed event listener: ${this.listenerArray.length}`,
|
|
867
874
|
LogLevelEnum.INFO,
|
|
868
|
-
functionName
|
|
875
|
+
functionName
|
|
869
876
|
);
|
|
870
877
|
}
|
|
871
878
|
}
|
|
@@ -891,7 +898,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
891
898
|
|
|
892
899
|
this.listenerArray = this.listenerArray.filter(
|
|
893
900
|
(obj) =>
|
|
894
|
-
obj.functionName !== functionName && obj.CMIElement !== CMIElement
|
|
901
|
+
obj.functionName !== functionName && obj.CMIElement !== CMIElement
|
|
895
902
|
);
|
|
896
903
|
}
|
|
897
904
|
}
|
|
@@ -917,7 +924,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
917
924
|
) {
|
|
918
925
|
CMIElementsMatch =
|
|
919
926
|
CMIElement.indexOf(
|
|
920
|
-
listener.CMIElement.substring(0, listener.CMIElement.length - 1)
|
|
927
|
+
listener.CMIElement.substring(0, listener.CMIElement.length - 1)
|
|
921
928
|
) === 0;
|
|
922
929
|
} else {
|
|
923
930
|
CMIElementsMatch = listener.CMIElement === CMIElement;
|
|
@@ -928,7 +935,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
928
935
|
"processListeners",
|
|
929
936
|
`Processing listener: ${listener.functionName}`,
|
|
930
937
|
LogLevelEnum.INFO,
|
|
931
|
-
CMIElement
|
|
938
|
+
CMIElement
|
|
932
939
|
);
|
|
933
940
|
listener.callback(CMIElement, value);
|
|
934
941
|
}
|
|
@@ -949,7 +956,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
949
956
|
this.apiLog(
|
|
950
957
|
"throwSCORMError",
|
|
951
958
|
errorNumber + ": " + message,
|
|
952
|
-
LogLevelEnum.ERROR
|
|
959
|
+
LogLevelEnum.ERROR
|
|
953
960
|
);
|
|
954
961
|
|
|
955
962
|
this.lastErrorCode = String(errorNumber);
|
|
@@ -978,7 +985,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
978
985
|
}
|
|
979
986
|
if (!this.isNotInitialized()) {
|
|
980
987
|
console.error(
|
|
981
|
-
"loadFromFlattenedJSON can only be called before the call to lmsInitialize."
|
|
988
|
+
"loadFromFlattenedJSON can only be called before the call to lmsInitialize."
|
|
982
989
|
);
|
|
983
990
|
return;
|
|
984
991
|
}
|
|
@@ -994,7 +1001,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
994
1001
|
function testPattern(
|
|
995
1002
|
a: string,
|
|
996
1003
|
c: string,
|
|
997
|
-
a_pattern: RegExp
|
|
1004
|
+
a_pattern: RegExp
|
|
998
1005
|
): number | null {
|
|
999
1006
|
const a_match = a.match(a_pattern);
|
|
1000
1007
|
|
|
@@ -1024,12 +1031,12 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1024
1031
|
const int_pattern = /^(cmi\.interactions\.)(\d+)\.(.*)$/;
|
|
1025
1032
|
const obj_pattern = /^(cmi\.objectives\.)(\d+)\.(.*)$/;
|
|
1026
1033
|
|
|
1027
|
-
const result = Object.keys(json).map(function
|
|
1034
|
+
const result = Object.keys(json).map(function(key) {
|
|
1028
1035
|
return [String(key), json[key]];
|
|
1029
1036
|
});
|
|
1030
1037
|
|
|
1031
1038
|
// CMI interactions need to have id and type loaded before any other fields
|
|
1032
|
-
result.sort(function
|
|
1039
|
+
result.sort(function([a, _b], [c, _d]) {
|
|
1033
1040
|
let test;
|
|
1034
1041
|
if ((test = testPattern(a, c, int_pattern)) !== null) {
|
|
1035
1042
|
return test;
|
|
@@ -1073,7 +1080,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1073
1080
|
|
|
1074
1081
|
if (!this.isNotInitialized()) {
|
|
1075
1082
|
console.error(
|
|
1076
|
-
"loadFromJSON can only be called before the call to lmsInitialize."
|
|
1083
|
+
"loadFromJSON can only be called before the call to lmsInitialize."
|
|
1077
1084
|
);
|
|
1078
1085
|
return;
|
|
1079
1086
|
}
|
|
@@ -1092,7 +1099,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1092
1099
|
for (let i = 0; i < value["childArray"].length; i++) {
|
|
1093
1100
|
this.loadFromJSON(
|
|
1094
1101
|
value["childArray"][i],
|
|
1095
|
-
currentCMIElement + "." + i
|
|
1102
|
+
currentCMIElement + "." + i
|
|
1096
1103
|
);
|
|
1097
1104
|
}
|
|
1098
1105
|
} else if (value.constructor === Object) {
|
|
@@ -1136,12 +1143,12 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1136
1143
|
async processHttpRequest(
|
|
1137
1144
|
url: string,
|
|
1138
1145
|
params: CommitObject | RefObject | Array<any>,
|
|
1139
|
-
immediate: boolean = false
|
|
1146
|
+
immediate: boolean = false
|
|
1140
1147
|
): Promise<ResultObject> {
|
|
1141
1148
|
const api = this;
|
|
1142
1149
|
const genericError: ResultObject = {
|
|
1143
1150
|
result: global_constants.SCORM_FALSE,
|
|
1144
|
-
errorCode: this.error_codes.GENERAL as number
|
|
1151
|
+
errorCode: this.error_codes.GENERAL as number
|
|
1145
1152
|
};
|
|
1146
1153
|
|
|
1147
1154
|
// if we are terminating the module or closing the browser window/tab, we need to make this fetch ASAP.
|
|
@@ -1154,14 +1161,14 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1154
1161
|
});
|
|
1155
1162
|
return {
|
|
1156
1163
|
result: global_constants.SCORM_TRUE,
|
|
1157
|
-
errorCode: 0
|
|
1164
|
+
errorCode: 0
|
|
1158
1165
|
};
|
|
1159
1166
|
}
|
|
1160
1167
|
|
|
1161
1168
|
const process = async (
|
|
1162
1169
|
url: string,
|
|
1163
1170
|
params: CommitObject | RefObject | Array<any>,
|
|
1164
|
-
settings: InternalSettings
|
|
1171
|
+
settings: InternalSettings
|
|
1165
1172
|
): Promise<ResultObject> => {
|
|
1166
1173
|
try {
|
|
1167
1174
|
params = settings.requestHandler(params);
|
|
@@ -1212,13 +1219,13 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1212
1219
|
*/
|
|
1213
1220
|
private _checkObjectHasProperty(
|
|
1214
1221
|
refObject: RefObject,
|
|
1215
|
-
attribute: string
|
|
1222
|
+
attribute: string
|
|
1216
1223
|
): boolean {
|
|
1217
1224
|
return (
|
|
1218
1225
|
Object.hasOwnProperty.call(refObject, attribute) ||
|
|
1219
1226
|
Object.getOwnPropertyDescriptor(
|
|
1220
1227
|
Object.getPrototypeOf(refObject),
|
|
1221
|
-
attribute
|
|
1228
|
+
attribute
|
|
1222
1229
|
) != null ||
|
|
1223
1230
|
attribute in refObject
|
|
1224
1231
|
);
|
|
@@ -1253,7 +1260,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1253
1260
|
* @private
|
|
1254
1261
|
*/
|
|
1255
1262
|
protected getCommitObject(
|
|
1256
|
-
terminateCommit: boolean
|
|
1263
|
+
terminateCommit: boolean
|
|
1257
1264
|
): CommitObject | RefObject | Array<any> {
|
|
1258
1265
|
const shouldTerminateCommit =
|
|
1259
1266
|
terminateCommit || this.settings.alwaysSendTotalTime;
|
|
@@ -1263,7 +1270,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1263
1270
|
|
|
1264
1271
|
if ([LogLevelEnum.DEBUG, "1", 1, "DEBUG"].includes(this.apiLogLevel)) {
|
|
1265
1272
|
console.debug(
|
|
1266
|
-
"Commit (terminated: " + (terminateCommit ? "yes" : "no") + "): "
|
|
1273
|
+
"Commit (terminated: " + (terminateCommit ? "yes" : "no") + "): "
|
|
1267
1274
|
);
|
|
1268
1275
|
console.debug(commitObject);
|
|
1269
1276
|
}
|
|
@@ -1279,7 +1286,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1279
1286
|
*/
|
|
1280
1287
|
private async performFetch(
|
|
1281
1288
|
url: string,
|
|
1282
|
-
params: RefObject | Array<any
|
|
1289
|
+
params: RefObject | Array<any>
|
|
1283
1290
|
): Promise<Response> {
|
|
1284
1291
|
let init = {
|
|
1285
1292
|
method: "POST",
|
|
@@ -1287,15 +1294,15 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1287
1294
|
body: params instanceof Array ? params.join("&") : JSON.stringify(params),
|
|
1288
1295
|
headers: {
|
|
1289
1296
|
...this.settings.xhrHeaders,
|
|
1290
|
-
"Content-Type": this.settings.commitRequestDataType
|
|
1297
|
+
"Content-Type": this.settings.commitRequestDataType
|
|
1291
1298
|
},
|
|
1292
|
-
keepalive: true
|
|
1299
|
+
keepalive: true
|
|
1293
1300
|
} as RequestInit;
|
|
1294
1301
|
|
|
1295
1302
|
if (this.settings.xhrWithCredentials) {
|
|
1296
1303
|
init = {
|
|
1297
1304
|
...init,
|
|
1298
|
-
credentials: "include"
|
|
1305
|
+
credentials: "include"
|
|
1299
1306
|
};
|
|
1300
1307
|
}
|
|
1301
1308
|
|
|
@@ -1309,7 +1316,7 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1309
1316
|
* @private
|
|
1310
1317
|
*/
|
|
1311
1318
|
private async transformResponse(response: Response): Promise<ResultObject> {
|
|
1312
|
-
const result =
|
|
1319
|
+
const result: ResultObject =
|
|
1313
1320
|
typeof this.settings.responseHandler === "function"
|
|
1314
1321
|
? await this.settings.responseHandler(response)
|
|
1315
1322
|
: await response.json();
|
package/src/Scorm2004API.ts
CHANGED
|
@@ -193,10 +193,10 @@ class Scorm2004Impl extends BaseAPI {
|
|
|
193
193
|
*/
|
|
194
194
|
lmsCommit(): string {
|
|
195
195
|
if (this.settings.asyncCommit) {
|
|
196
|
-
this.scheduleCommit(500, "
|
|
196
|
+
this.scheduleCommit(500, "Commit");
|
|
197
197
|
} else {
|
|
198
198
|
(async () => {
|
|
199
|
-
await this.commit("
|
|
199
|
+
await this.commit("Commit", false);
|
|
200
200
|
})();
|
|
201
201
|
}
|
|
202
202
|
return global_constants.SCORM_TRUE;
|
|
@@ -22,12 +22,12 @@ export const DefaultSettings: InternalSettings = {
|
|
|
22
22
|
xhrHeaders: {},
|
|
23
23
|
xhrWithCredentials: false,
|
|
24
24
|
fetchMode: "cors",
|
|
25
|
-
responseHandler: async function
|
|
25
|
+
responseHandler: async function(response: Response): Promise<ResultObject> {
|
|
26
26
|
if (typeof response !== "undefined") {
|
|
27
27
|
const responseText = await response.text();
|
|
28
|
-
let httpResult = null;
|
|
28
|
+
let httpResult: any = null;
|
|
29
29
|
if (responseText) {
|
|
30
|
-
httpResult = JSON.parse(responseText);
|
|
30
|
+
httpResult = JSON.parse(responseText) as any;
|
|
31
31
|
}
|
|
32
32
|
if (
|
|
33
33
|
httpResult === null ||
|
|
@@ -36,34 +36,34 @@ export const DefaultSettings: InternalSettings = {
|
|
|
36
36
|
if (response.status === 200) {
|
|
37
37
|
return {
|
|
38
38
|
result: global_constants.SCORM_TRUE,
|
|
39
|
-
errorCode: 0
|
|
39
|
+
errorCode: 0
|
|
40
40
|
};
|
|
41
41
|
} else {
|
|
42
42
|
return {
|
|
43
43
|
result: global_constants.SCORM_FALSE,
|
|
44
|
-
errorCode: 101
|
|
44
|
+
errorCode: 101
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
} else {
|
|
48
48
|
return {
|
|
49
49
|
result: httpResult.result,
|
|
50
|
-
errorCode: httpResult.errorCode
|
|
50
|
+
errorCode: typeof httpResult.errorCode === "number"
|
|
51
51
|
? httpResult.errorCode
|
|
52
|
-
: httpResult.result === global_constants.SCORM_TRUE
|
|
52
|
+
: httpResult.result === true || httpResult.result === global_constants.SCORM_TRUE
|
|
53
53
|
? 0
|
|
54
|
-
: 101
|
|
54
|
+
: 101
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
return {
|
|
59
59
|
result: global_constants.SCORM_FALSE,
|
|
60
|
-
errorCode: 101
|
|
60
|
+
errorCode: 101
|
|
61
61
|
};
|
|
62
62
|
},
|
|
63
|
-
requestHandler: function
|
|
63
|
+
requestHandler: function(commitObject) {
|
|
64
64
|
return commitObject;
|
|
65
65
|
},
|
|
66
|
-
onLogMessage: function
|
|
66
|
+
onLogMessage: function(messageLevel: LogLevel, logMessage) {
|
|
67
67
|
switch (messageLevel) {
|
|
68
68
|
case "4":
|
|
69
69
|
case 4:
|
|
@@ -97,5 +97,5 @@ export const DefaultSettings: InternalSettings = {
|
|
|
97
97
|
},
|
|
98
98
|
scoItemIds: [],
|
|
99
99
|
scoItemIdValidator: false,
|
|
100
|
-
globalObjectiveIds: []
|
|
100
|
+
globalObjectiveIds: []
|
|
101
101
|
};
|
package/src/types/api_types.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CompletionStatus,
|
|
3
|
-
LogLevelEnum,
|
|
4
|
-
SuccessStatus,
|
|
5
|
-
} from "../constants/enums";
|
|
1
|
+
import { CompletionStatus, LogLevelEnum, SuccessStatus } from "../constants/enums";
|
|
6
2
|
|
|
7
3
|
export type Settings = {
|
|
8
4
|
autocommit?: boolean;
|
|
@@ -61,7 +57,7 @@ export type RefObject = {
|
|
|
61
57
|
};
|
|
62
58
|
|
|
63
59
|
export type ResultObject = {
|
|
64
|
-
result: string;
|
|
60
|
+
result: string | boolean;
|
|
65
61
|
errorCode: number;
|
|
66
62
|
navRequest?: string;
|
|
67
63
|
};
|
package/tsconfig.json
CHANGED
|
@@ -22,9 +22,8 @@
|
|
|
22
22
|
"importHelpers": true,
|
|
23
23
|
"forceConsistentCasingInFileNames": true,
|
|
24
24
|
"exactOptionalPropertyTypes": true,
|
|
25
|
-
"strictNullChecks": true,
|
|
26
|
-
"useUnknownInCatchVariables": true,
|
|
27
25
|
"strict": true,
|
|
26
|
+
"strictNullChecks": true,
|
|
28
27
|
},
|
|
29
28
|
"include": [
|
|
30
29
|
"src/**/*"
|