scorm-again 2.0.0 → 2.2.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.
Files changed (77) hide show
  1. package/.github/workflows/stale.yml +14 -0
  2. package/.run/{Mocha Unit Tests.run.xml → Mocha Unit Tests (watch).run.xml } +1 -1
  3. package/.run/Template Mocha.run.xml +17 -0
  4. package/README.md +180 -72
  5. package/dist/aicc.js +1520 -1149
  6. package/dist/aicc.js.map +1 -1
  7. package/dist/aicc.min.js +1 -1
  8. package/dist/aicc.min.js.map +1 -1
  9. package/dist/scorm-again.js +2812 -2205
  10. package/dist/scorm-again.js.map +1 -1
  11. package/dist/scorm-again.min.js +1 -1
  12. package/dist/scorm-again.min.js.map +1 -1
  13. package/dist/scorm12.js +1129 -842
  14. package/dist/scorm12.js.map +1 -1
  15. package/dist/scorm12.min.js +1 -1
  16. package/dist/scorm12.min.js.map +1 -1
  17. package/dist/scorm2004.js +1921 -1564
  18. package/dist/scorm2004.js.map +1 -1
  19. package/dist/scorm2004.min.js +1 -1
  20. package/dist/scorm2004.min.js.map +1 -1
  21. package/package.json +20 -17
  22. package/src/AICC.ts +15 -17
  23. package/src/BaseAPI.ts +283 -420
  24. package/src/Scorm12API.ts +133 -41
  25. package/src/Scorm2004API.ts +224 -120
  26. package/src/cmi/aicc/attempts.ts +94 -0
  27. package/src/cmi/aicc/cmi.ts +100 -0
  28. package/src/cmi/aicc/core.ts +360 -0
  29. package/src/cmi/aicc/evaluation.ts +157 -0
  30. package/src/cmi/aicc/paths.ts +180 -0
  31. package/src/cmi/aicc/student_data.ts +86 -0
  32. package/src/cmi/aicc/student_demographics.ts +367 -0
  33. package/src/cmi/aicc/student_preferences.ts +176 -0
  34. package/src/cmi/aicc/tries.ts +116 -0
  35. package/src/cmi/aicc/validation.ts +25 -0
  36. package/src/cmi/common/array.ts +77 -0
  37. package/src/cmi/common/base_cmi.ts +46 -0
  38. package/src/cmi/common/score.ts +203 -0
  39. package/src/cmi/common/validation.ts +60 -0
  40. package/src/cmi/scorm12/cmi.ts +224 -0
  41. package/src/cmi/scorm12/interactions.ts +368 -0
  42. package/src/cmi/scorm12/nav.ts +54 -0
  43. package/src/cmi/scorm12/objectives.ts +112 -0
  44. package/src/cmi/scorm12/student_data.ts +130 -0
  45. package/src/cmi/scorm12/student_preference.ts +158 -0
  46. package/src/cmi/scorm12/validation.ts +48 -0
  47. package/src/cmi/scorm2004/adl.ts +272 -0
  48. package/src/cmi/scorm2004/cmi.ts +599 -0
  49. package/src/cmi/scorm2004/comments.ts +163 -0
  50. package/src/cmi/scorm2004/interactions.ts +466 -0
  51. package/src/cmi/scorm2004/learner_preference.ts +152 -0
  52. package/src/cmi/scorm2004/objectives.ts +212 -0
  53. package/src/cmi/scorm2004/score.ts +78 -0
  54. package/src/cmi/scorm2004/validation.ts +42 -0
  55. package/src/constants/default_settings.ts +82 -0
  56. package/src/constants/enums.ts +17 -0
  57. package/src/constants/regex.ts +2 -2
  58. package/src/constants/response_constants.ts +2 -0
  59. package/src/exceptions.ts +22 -1
  60. package/src/helpers/scheduled_commit.ts +42 -0
  61. package/src/interfaces/IBaseAPI.ts +35 -0
  62. package/src/types/api_types.ts +50 -0
  63. package/src/utilities/debounce.ts +31 -0
  64. package/src/utilities.ts +56 -0
  65. package/test/AICC.spec.ts +11 -1
  66. package/test/Scorm12API.spec.ts +372 -9
  67. package/test/Scorm2004API.spec.ts +558 -2
  68. package/test/cmi/aicc_cmi.spec.ts +188 -11
  69. package/test/cmi/scorm12_cmi.spec.ts +5 -5
  70. package/test/cmi/scorm2004_cmi.spec.ts +8 -8
  71. package/test/cmi_helpers.ts +1 -1
  72. package/test/types/api_types.spec.ts +126 -0
  73. package/test/utilities/debounce.spec.ts +56 -0
  74. package/src/cmi/aicc_cmi.ts +0 -1248
  75. package/src/cmi/common.ts +0 -411
  76. package/src/cmi/scorm12_cmi.ts +0 -1426
  77. package/src/cmi/scorm2004_cmi.ts +0 -1874
package/dist/scorm2004.js CHANGED
@@ -381,9 +381,88 @@ function __disposeResources(env) {
381
381
  __disposeResources,
382
382
  });
383
383
 
384
- ;// ./src/constants/api_constants.ts
384
+ ;// ./src/cmi/common/base_cmi.ts
385
+
386
+ var BaseCMI = (function () {
387
+ function BaseCMI() {
388
+ this.jsonString = false;
389
+ this._initialized = false;
390
+ }
391
+ Object.defineProperty(BaseCMI.prototype, "initialized", {
392
+ get: function () {
393
+ return this._initialized;
394
+ },
395
+ enumerable: false,
396
+ configurable: true
397
+ });
398
+ Object.defineProperty(BaseCMI.prototype, "start_time", {
399
+ get: function () {
400
+ return this._start_time;
401
+ },
402
+ enumerable: false,
403
+ configurable: true
404
+ });
405
+ BaseCMI.prototype.initialize = function () {
406
+ this._initialized = true;
407
+ };
408
+ BaseCMI.prototype.setStartTime = function () {
409
+ this._start_time = new Date().getTime();
410
+ };
411
+ return BaseCMI;
412
+ }());
413
+
414
+ var BaseRootCMI = (function (_super) {
415
+ __extends(BaseRootCMI, _super);
416
+ function BaseRootCMI() {
417
+ return _super !== null && _super.apply(this, arguments) || this;
418
+ }
419
+ return BaseRootCMI;
420
+ }(BaseCMI));
421
+
422
+
423
+ ;// ./src/constants/error_codes.ts
385
424
 
386
425
  var global = {
426
+ GENERAL: 101,
427
+ INITIALIZATION_FAILED: 101,
428
+ INITIALIZED: 101,
429
+ TERMINATED: 101,
430
+ TERMINATION_FAILURE: 101,
431
+ TERMINATION_BEFORE_INIT: 101,
432
+ MULTIPLE_TERMINATION: 101,
433
+ RETRIEVE_BEFORE_INIT: 101,
434
+ RETRIEVE_AFTER_TERM: 101,
435
+ STORE_BEFORE_INIT: 101,
436
+ STORE_AFTER_TERM: 101,
437
+ COMMIT_BEFORE_INIT: 101,
438
+ COMMIT_AFTER_TERM: 101,
439
+ ARGUMENT_ERROR: 101,
440
+ CHILDREN_ERROR: 101,
441
+ COUNT_ERROR: 101,
442
+ GENERAL_GET_FAILURE: 101,
443
+ GENERAL_SET_FAILURE: 101,
444
+ GENERAL_COMMIT_FAILURE: 101,
445
+ UNDEFINED_DATA_MODEL: 101,
446
+ UNIMPLEMENTED_ELEMENT: 101,
447
+ VALUE_NOT_INITIALIZED: 101,
448
+ INVALID_SET_VALUE: 101,
449
+ READ_ONLY_ELEMENT: 101,
450
+ WRITE_ONLY_ELEMENT: 101,
451
+ TYPE_MISMATCH: 101,
452
+ VALUE_OUT_OF_RANGE: 101,
453
+ DEPENDENCY_NOT_ESTABLISHED: 101,
454
+ };
455
+ var scorm12 = __assign(__assign({}, global), { RETRIEVE_BEFORE_INIT: 301, STORE_BEFORE_INIT: 301, COMMIT_BEFORE_INIT: 301, ARGUMENT_ERROR: 201, CHILDREN_ERROR: 202, COUNT_ERROR: 203, UNDEFINED_DATA_MODEL: 401, UNIMPLEMENTED_ELEMENT: 401, VALUE_NOT_INITIALIZED: 301, INVALID_SET_VALUE: 402, READ_ONLY_ELEMENT: 403, WRITE_ONLY_ELEMENT: 404, TYPE_MISMATCH: 405, VALUE_OUT_OF_RANGE: 407, DEPENDENCY_NOT_ESTABLISHED: 408 });
456
+ var scorm2004 = __assign(__assign({}, global), { INITIALIZATION_FAILED: 102, INITIALIZED: 103, TERMINATED: 104, TERMINATION_FAILURE: 111, TERMINATION_BEFORE_INIT: 112, MULTIPLE_TERMINATIONS: 113, RETRIEVE_BEFORE_INIT: 122, RETRIEVE_AFTER_TERM: 123, STORE_BEFORE_INIT: 132, STORE_AFTER_TERM: 133, COMMIT_BEFORE_INIT: 142, COMMIT_AFTER_TERM: 143, ARGUMENT_ERROR: 201, GENERAL_GET_FAILURE: 301, GENERAL_SET_FAILURE: 351, GENERAL_COMMIT_FAILURE: 391, UNDEFINED_DATA_MODEL: 401, UNIMPLEMENTED_ELEMENT: 402, VALUE_NOT_INITIALIZED: 403, READ_ONLY_ELEMENT: 404, WRITE_ONLY_ELEMENT: 405, TYPE_MISMATCH: 406, VALUE_OUT_OF_RANGE: 407, DEPENDENCY_NOT_ESTABLISHED: 408 });
457
+ var ErrorCodes = {
458
+ scorm12: scorm12,
459
+ scorm2004: scorm2004,
460
+ };
461
+ /* harmony default export */ var error_codes = (ErrorCodes);
462
+
463
+ ;// ./src/constants/api_constants.ts
464
+
465
+ var api_constants_global = {
387
466
  SCORM_TRUE: "true",
388
467
  SCORM_FALSE: "false",
389
468
  STATE_NOT_INITIALIZED: 0,
@@ -395,7 +474,7 @@ var global = {
395
474
  LOG_LEVEL_ERROR: 4,
396
475
  LOG_LEVEL_NONE: 5,
397
476
  };
398
- var scorm12 = {
477
+ var api_constants_scorm12 = {
399
478
  cmi_children: "core,suspend_data,launch_data,comments,objectives,student_data,student_preference,interactions",
400
479
  core_children: "student_id,student_name,lesson_location,credit,lesson_status,entry,score,total_time,lesson_mode,exit,session_time",
401
480
  score_children: "raw,min,max",
@@ -456,7 +535,7 @@ var scorm12 = {
456
535
  },
457
536
  },
458
537
  };
459
- var aicc = __assign(__assign({}, scorm12), {
538
+ var aicc = __assign(__assign({}, api_constants_scorm12), {
460
539
  cmi_children: "core,suspend_data,launch_data,comments,objectives,student_data,student_preference,interactions,evaluation",
461
540
  student_preference_children: "audio,language,lesson_type,speed,text,text_color,text_location,text_size,video,windows",
462
541
  student_data_children: "attempt_number,tries,mastery_score,max_time_allowed,time_limit_action",
@@ -465,7 +544,7 @@ var aicc = __assign(__assign({}, scorm12), {
465
544
  attempt_records_children: "score,lesson_status",
466
545
  paths_children: "location_id,date,time,status,why_left,time_in_element",
467
546
  });
468
- var scorm2004 = {
547
+ var api_constants_scorm2004 = {
469
548
  cmi_children: "_version,comments_from_learner,comments_from_lms,completion_status,credit,entry,exit,interactions,launch_data,learner_id,learner_name,learner_preference,location,max_time_allowed,mode,objectives,progress_measure,scaled_passing_score,score,session_time,success_status,suspend_data,time_limit_action,total_time",
470
549
  comments_children: "comment,timestamp,location",
471
550
  score_children: "max,raw,scaled,min",
@@ -582,132 +661,19 @@ var scorm2004 = {
582
661
  },
583
662
  };
584
663
  var APIConstants = {
585
- global: global,
586
- scorm12: scorm12,
664
+ global: api_constants_global,
665
+ scorm12: api_constants_scorm12,
587
666
  aicc: aicc,
588
- scorm2004: scorm2004,
667
+ scorm2004: api_constants_scorm2004,
589
668
  };
590
669
  /* harmony default export */ var api_constants = (APIConstants);
591
670
 
592
- ;// ./src/constants/error_codes.ts
593
-
594
- var error_codes_global = {
595
- GENERAL: 101,
596
- INITIALIZATION_FAILED: 101,
597
- INITIALIZED: 101,
598
- TERMINATED: 101,
599
- TERMINATION_FAILURE: 101,
600
- TERMINATION_BEFORE_INIT: 101,
601
- MULTIPLE_TERMINATION: 101,
602
- RETRIEVE_BEFORE_INIT: 101,
603
- RETRIEVE_AFTER_TERM: 101,
604
- STORE_BEFORE_INIT: 101,
605
- STORE_AFTER_TERM: 101,
606
- COMMIT_BEFORE_INIT: 101,
607
- COMMIT_AFTER_TERM: 101,
608
- ARGUMENT_ERROR: 101,
609
- CHILDREN_ERROR: 101,
610
- COUNT_ERROR: 101,
611
- GENERAL_GET_FAILURE: 101,
612
- GENERAL_SET_FAILURE: 101,
613
- GENERAL_COMMIT_FAILURE: 101,
614
- UNDEFINED_DATA_MODEL: 101,
615
- UNIMPLEMENTED_ELEMENT: 101,
616
- VALUE_NOT_INITIALIZED: 101,
617
- INVALID_SET_VALUE: 101,
618
- READ_ONLY_ELEMENT: 101,
619
- WRITE_ONLY_ELEMENT: 101,
620
- TYPE_MISMATCH: 101,
621
- VALUE_OUT_OF_RANGE: 101,
622
- DEPENDENCY_NOT_ESTABLISHED: 101,
623
- };
624
- var error_codes_scorm12 = __assign(__assign({}, error_codes_global), { RETRIEVE_BEFORE_INIT: 301, STORE_BEFORE_INIT: 301, COMMIT_BEFORE_INIT: 301, ARGUMENT_ERROR: 201, CHILDREN_ERROR: 202, COUNT_ERROR: 203, UNDEFINED_DATA_MODEL: 401, UNIMPLEMENTED_ELEMENT: 401, VALUE_NOT_INITIALIZED: 301, INVALID_SET_VALUE: 402, READ_ONLY_ELEMENT: 403, WRITE_ONLY_ELEMENT: 404, TYPE_MISMATCH: 405, VALUE_OUT_OF_RANGE: 407, DEPENDENCY_NOT_ESTABLISHED: 408 });
625
- var error_codes_scorm2004 = __assign(__assign({}, error_codes_global), { INITIALIZATION_FAILED: 102, INITIALIZED: 103, TERMINATED: 104, TERMINATION_FAILURE: 111, TERMINATION_BEFORE_INIT: 112, MULTIPLE_TERMINATIONS: 113, RETRIEVE_BEFORE_INIT: 122, RETRIEVE_AFTER_TERM: 123, STORE_BEFORE_INIT: 132, STORE_AFTER_TERM: 133, COMMIT_BEFORE_INIT: 142, COMMIT_AFTER_TERM: 143, ARGUMENT_ERROR: 201, GENERAL_GET_FAILURE: 301, GENERAL_SET_FAILURE: 351, GENERAL_COMMIT_FAILURE: 391, UNDEFINED_DATA_MODEL: 401, UNIMPLEMENTED_ELEMENT: 402, VALUE_NOT_INITIALIZED: 403, READ_ONLY_ELEMENT: 404, WRITE_ONLY_ELEMENT: 405, TYPE_MISMATCH: 406, VALUE_OUT_OF_RANGE: 407, DEPENDENCY_NOT_ESTABLISHED: 408 });
626
- var ErrorCodes = {
627
- scorm12: error_codes_scorm12,
628
- scorm2004: error_codes_scorm2004,
629
- };
630
- /* harmony default export */ var error_codes = (ErrorCodes);
631
-
632
- ;// ./src/constants/regex.ts
633
-
634
- var regex_scorm12 = {
635
- CMIString256: "^.{0,255}$",
636
- CMIString4096: "^.{0,4096}$",
637
- CMITime: "^(?:[01]\\d|2[0123]):(?:[012345]\\d):(?:[012345]\\d)$",
638
- CMITimespan: "^([0-9]{2,}):([0-9]{2}):([0-9]{2})(.[0-9]{1,2})?$",
639
- CMIInteger: "^\\d+$",
640
- CMISInteger: "^-?([0-9]+)$",
641
- CMIDecimal: "^-?([0-9]{0,3})(.[0-9]*)?$",
642
- CMIIdentifier: "^[\\u0021-\\u007E\\s]{0,255}$",
643
- CMIFeedback: "^.{0,255}$",
644
- CMIIndex: "[._](\\d+).",
645
- CMIStatus: "^(passed|completed|failed|incomplete|browsed)$",
646
- CMIStatus2: "^(passed|completed|failed|incomplete|browsed|not attempted)$",
647
- CMIExit: "^(time-out|suspend|logout|)$",
648
- CMIType: "^(true-false|choice|fill-in|matching|performance|sequencing|likert|numeric)$",
649
- CMIResult: "^(correct|wrong|unanticipated|neutral|([0-9]{0,3})?(\\.[0-9]*)?)$",
650
- NAVEvent: "^(previous|continue)$",
651
- score_range: "0#100",
652
- audio_range: "-1#100",
653
- speed_range: "-100#100",
654
- weighting_range: "-100#100",
655
- text_range: "-1#1",
656
- };
657
- var regex_aicc = __assign(__assign({}, regex_scorm12), {
658
- CMIIdentifier: "^\\w{1,255}$",
659
- });
660
- var regex_scorm2004 = {
661
- CMIString200: "^[\\u0000-\\uFFFF]{0,200}$",
662
- CMIString250: "^[\\u0000-\\uFFFF]{0,250}$",
663
- CMIString1000: "^[\\u0000-\\uFFFF]{0,1000}$",
664
- CMIString4000: "^[\\u0000-\\uFFFF]{0,4000}$",
665
- CMIString64000: "^[\\u0000-\\uFFFF]{0,64000}$",
666
- CMILang: "^([a-zA-Z]{2,3}|i|x)(-[a-zA-Z0-9-]{2,8})?$|^$",
667
- CMILangString250: "^({lang=([a-zA-Z]{2,3}|i|x)(-[a-zA-Z0-9-]{2,8})?})?((?!{.*$).{0,250}$)?$",
668
- CMILangcr: "^(({lang=([a-zA-Z]{2,3}|i|x)?(-[a-zA-Z0-9-]{2,8})?}))(.*?)$",
669
- CMILangString250cr: "^(({lang=([a-zA-Z]{2,3}|i|x)?(-[a-zA-Z0-9-]{2,8})?})?(.{0,250})?)?$",
670
- CMILangString4000: "^({lang=([a-zA-Z]{2,3}|i|x)(-[a-zA-Z0-9-]{2,8})?})?((?!{.*$).{0,4000}$)?$",
671
- CMITime: "^(19[7-9]{1}[0-9]{1}|20[0-2]{1}[0-9]{1}|203[0-8]{1})((-(0[1-9]{1}|1[0-2]{1}))((-(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]{1}))(T([0-1]{1}[0-9]{1}|2[0-3]{1})((:[0-5]{1}[0-9]{1})((:[0-5]{1}[0-9]{1})((\\.[0-9]{1,2})((Z|([+|-]([0-1]{1}[0-9]{1}|2[0-3]{1})))(:[0-5]{1}[0-9]{1})?)?)?)?)?)?)?)?$",
672
- CMITimespan: "^P(?:([.,\\d]+)Y)?(?:([.,\\d]+)M)?(?:([.,\\d]+)W)?(?:([.,\\d]+)D)?(?:T?(?:([.,\\d]+)H)?(?:([.,\\d]+)M)?(?:([.,\\d]+)S)?)?$",
673
- CMIInteger: "^\\d+$",
674
- CMISInteger: "^-?([0-9]+)$",
675
- CMIDecimal: "^-?([0-9]{1,5})(\\.[0-9]{1,18})?$",
676
- CMIIdentifier: "^\\S{1,250}[a-zA-Z0-9]$",
677
- CMIShortIdentifier: "^[\\w\\.\\-\\_]{1,250}$",
678
- CMILongIdentifier: "^(?:(?!urn:)\\S{1,4000}|urn:[A-Za-z0-9-]{1,31}:\\S{1,4000}|.{1,4000})$",
679
- CMIFeedback: "^.*$",
680
- CMIIndex: "[._](\\d+).",
681
- CMIIndexStore: ".N(\\d+).",
682
- CMICStatus: "^(completed|incomplete|not attempted|unknown)$",
683
- CMISStatus: "^(passed|failed|unknown)$",
684
- CMIExit: "^(time-out|suspend|logout|normal)$",
685
- CMIType: "^(true-false|choice|fill-in|long-fill-in|matching|performance|sequencing|likert|numeric|other)$",
686
- CMIResult: "^(correct|incorrect|unanticipated|neutral|-?([0-9]{1,4})(\\.[0-9]{1,18})?)$",
687
- NAVEvent: "^(previous|continue|exit|exitAll|abandon|abandonAll|suspendAll|{target=\\S{0,200}[a-zA-Z0-9]}choice|jump)$",
688
- NAVBoolean: "^(unknown|true|false$)",
689
- NAVTarget: "^(previous|continue|choice.{target=\\S{0,200}[a-zA-Z0-9]})$",
690
- scaled_range: "-1#1",
691
- audio_range: "0#*",
692
- speed_range: "0#*",
693
- text_range: "-1#1",
694
- progress_range: "0#1",
695
- };
696
- var Regex = {
697
- aicc: regex_aicc,
698
- scorm12: regex_scorm12,
699
- scorm2004: regex_scorm2004,
700
- };
701
- /* harmony default export */ var regex = (Regex);
702
-
703
- ;// ./src/cmi/common.ts
704
-
705
-
671
+ ;// ./src/exceptions.ts
706
672
 
707
673
 
708
- var scorm12_constants = api_constants.scorm12;
709
- var scorm12_regex = regex.scorm12;
710
- var scorm12_error_codes = error_codes.scorm12;
674
+ var scorm12_errors = api_constants.scorm12.error_descriptions;
675
+ var aicc_errors = api_constants.aicc.error_descriptions;
676
+ var scorm2004_errors = api_constants.scorm2004.error_descriptions;
711
677
  var BaseScormValidationError = (function (_super) {
712
678
  __extends(BaseScormValidationError, _super);
713
679
  function BaseScormValidationError(errorCode) {
@@ -729,246 +695,28 @@ var BaseScormValidationError = (function (_super) {
729
695
  return BaseScormValidationError;
730
696
  }(Error));
731
697
 
732
- var BaseScorm12ValidationError = (function (_super) {
733
- __extends(BaseScorm12ValidationError, _super);
734
- function BaseScorm12ValidationError(errorCode) {
735
- var _this = _super.call(this, errorCode) || this;
736
- _this.name = "Scorm12ValidationError";
737
- return _this;
738
- }
739
- return BaseScorm12ValidationError;
740
- }(BaseScormValidationError));
741
-
742
- var BaseScorm2004ValidationError = (function (_super) {
743
- __extends(BaseScorm2004ValidationError, _super);
744
- function BaseScorm2004ValidationError(errorCode) {
698
+ var ValidationError = (function (_super) {
699
+ __extends(ValidationError, _super);
700
+ function ValidationError(errorCode, errorMessage, detailedMessage) {
745
701
  var _this = _super.call(this, errorCode) || this;
746
- _this.name = "Scorm2004ValidationError";
747
- return _this;
748
- }
749
- return BaseScorm2004ValidationError;
750
- }(BaseScormValidationError));
751
-
752
- function checkValidFormat(value, regexPattern, errorCode, errorClass, allowEmptyString) {
753
- var formatRegex = new RegExp(regexPattern);
754
- var matches = value.match(formatRegex);
755
- if (allowEmptyString && value === "") {
756
- return true;
757
- }
758
- if (value === undefined || !matches || matches[0] === "") {
759
- throw new errorClass(errorCode);
760
- }
761
- return true;
762
- }
763
- function checkValidRange(value, rangePattern, errorCode, errorClass) {
764
- var ranges = rangePattern.split("#");
765
- value = value * 1.0;
766
- if (value >= ranges[0]) {
767
- if (ranges[1] === "*" || value <= ranges[1]) {
768
- return true;
769
- }
770
- else {
771
- throw new errorClass(errorCode);
702
+ _this._detailedMessage = "";
703
+ _this.setMessage(errorMessage);
704
+ _this._errorMessage = errorMessage;
705
+ if (detailedMessage) {
706
+ _this._detailedMessage = detailedMessage;
772
707
  }
708
+ return _this;
773
709
  }
774
- else {
775
- throw new errorClass(errorCode);
776
- }
777
- }
778
- var BaseCMI = (function () {
779
- function BaseCMI() {
780
- this.jsonString = false;
781
- this._initialized = false;
782
- }
783
- Object.defineProperty(BaseCMI.prototype, "initialized", {
710
+ Object.defineProperty(ValidationError.prototype, "errorMessage", {
784
711
  get: function () {
785
- return this._initialized;
712
+ return this._errorMessage;
786
713
  },
787
714
  enumerable: false,
788
715
  configurable: true
789
716
  });
790
- Object.defineProperty(BaseCMI.prototype, "start_time", {
717
+ Object.defineProperty(ValidationError.prototype, "detailedMessage", {
791
718
  get: function () {
792
- return this._start_time;
793
- },
794
- enumerable: false,
795
- configurable: true
796
- });
797
- BaseCMI.prototype.initialize = function () {
798
- this._initialized = true;
799
- };
800
- BaseCMI.prototype.setStartTime = function () {
801
- this._start_time = new Date().getTime();
802
- };
803
- return BaseCMI;
804
- }());
805
-
806
- var BaseRootCMI = (function (_super) {
807
- __extends(BaseRootCMI, _super);
808
- function BaseRootCMI() {
809
- return _super !== null && _super.apply(this, arguments) || this;
810
- }
811
- return BaseRootCMI;
812
- }(BaseCMI));
813
-
814
- var CMIScore = (function (_super) {
815
- __extends(CMIScore, _super);
816
- function CMIScore(params) {
817
- var _this = _super.call(this) || this;
818
- _this._raw = "";
819
- _this._min = "";
820
- _this.__children = params.score_children || scorm12_constants.score_children;
821
- _this.__score_range = !params.score_range
822
- ? false
823
- : scorm12_regex.score_range;
824
- _this._max = params.max || params.max === "" ? params.max : "100";
825
- _this.__invalid_error_code =
826
- params.invalidErrorCode || scorm12_error_codes.INVALID_SET_VALUE;
827
- _this.__invalid_type_code =
828
- params.invalidTypeCode || scorm12_error_codes.TYPE_MISMATCH;
829
- _this.__invalid_range_code =
830
- params.invalidRangeCode || scorm12_error_codes.VALUE_OUT_OF_RANGE;
831
- _this.__decimal_regex = params.decimalRegex || scorm12_regex.CMIDecimal;
832
- _this.__error_class = params.errorClass;
833
- return _this;
834
- }
835
- Object.defineProperty(CMIScore.prototype, "_children", {
836
- get: function () {
837
- return this.__children;
838
- },
839
- set: function (_children) {
840
- throw new this.__error_class(this.__invalid_error_code);
841
- },
842
- enumerable: false,
843
- configurable: true
844
- });
845
- Object.defineProperty(CMIScore.prototype, "raw", {
846
- get: function () {
847
- return this._raw;
848
- },
849
- set: function (raw) {
850
- if (checkValidFormat(raw, this.__decimal_regex, this.__invalid_type_code, this.__error_class) &&
851
- (!this.__score_range ||
852
- checkValidRange(raw, this.__score_range, this.__invalid_range_code, this.__error_class))) {
853
- this._raw = raw;
854
- }
855
- },
856
- enumerable: false,
857
- configurable: true
858
- });
859
- Object.defineProperty(CMIScore.prototype, "min", {
860
- get: function () {
861
- return this._min;
862
- },
863
- set: function (min) {
864
- if (checkValidFormat(min, this.__decimal_regex, this.__invalid_type_code, this.__error_class) &&
865
- (!this.__score_range ||
866
- checkValidRange(min, this.__score_range, this.__invalid_range_code, this.__error_class))) {
867
- this._min = min;
868
- }
869
- },
870
- enumerable: false,
871
- configurable: true
872
- });
873
- Object.defineProperty(CMIScore.prototype, "max", {
874
- get: function () {
875
- return this._max;
876
- },
877
- set: function (max) {
878
- if (checkValidFormat(max, this.__decimal_regex, this.__invalid_type_code, this.__error_class) &&
879
- (!this.__score_range ||
880
- checkValidRange(max, this.__score_range, this.__invalid_range_code, this.__error_class))) {
881
- this._max = max;
882
- }
883
- },
884
- enumerable: false,
885
- configurable: true
886
- });
887
- CMIScore.prototype.toJSON = function () {
888
- this.jsonString = true;
889
- var result = {
890
- raw: this.raw,
891
- min: this.min,
892
- max: this.max,
893
- };
894
- delete this.jsonString;
895
- return result;
896
- };
897
- return CMIScore;
898
- }(BaseCMI));
899
-
900
- var CMIArray = (function (_super) {
901
- __extends(CMIArray, _super);
902
- function CMIArray(params) {
903
- var _this = _super.call(this) || this;
904
- _this.__children = params.children;
905
- _this._errorCode = params.errorCode || scorm12_error_codes.GENERAL;
906
- _this._errorClass = params.errorClass || BaseScorm12ValidationError;
907
- _this.childArray = [];
908
- return _this;
909
- }
910
- Object.defineProperty(CMIArray.prototype, "_children", {
911
- get: function () {
912
- return this.__children;
913
- },
914
- set: function (_children) {
915
- throw new this._errorClass(this._errorCode);
916
- },
917
- enumerable: false,
918
- configurable: true
919
- });
920
- Object.defineProperty(CMIArray.prototype, "_count", {
921
- get: function () {
922
- return this.childArray.length;
923
- },
924
- set: function (_count) {
925
- throw new this._errorClass(this._errorCode);
926
- },
927
- enumerable: false,
928
- configurable: true
929
- });
930
- CMIArray.prototype.toJSON = function () {
931
- this.jsonString = true;
932
- var result = {};
933
- for (var i = 0; i < this.childArray.length; i++) {
934
- result[i + ""] = this.childArray[i];
935
- }
936
- delete this.jsonString;
937
- return result;
938
- };
939
- return CMIArray;
940
- }(BaseCMI));
941
-
942
-
943
- ;// ./src/exceptions.ts
944
-
945
-
946
-
947
- var scorm12_errors = api_constants.scorm12.error_descriptions;
948
- var aicc_errors = api_constants.aicc.error_descriptions;
949
- var scorm2004_errors = api_constants.scorm2004.error_descriptions;
950
- var ValidationError = (function (_super) {
951
- __extends(ValidationError, _super);
952
- function ValidationError(errorCode, errorMessage, detailedMessage) {
953
- var _this = _super.call(this, errorCode) || this;
954
- _this._detailedMessage = "";
955
- _this.setMessage(errorMessage);
956
- _this._errorMessage = errorMessage;
957
- if (detailedMessage) {
958
- _this._detailedMessage = detailedMessage;
959
- }
960
- return _this;
961
- }
962
- Object.defineProperty(ValidationError.prototype, "errorMessage", {
963
- get: function () {
964
- return this._errorMessage;
965
- },
966
- enumerable: false,
967
- configurable: true
968
- });
969
- Object.defineProperty(ValidationError.prototype, "detailedMessage", {
970
- get: function () {
971
- return this._detailedMessage;
719
+ return this._detailedMessage;
972
720
  },
973
721
  enumerable: false,
974
722
  configurable: true
@@ -1022,6 +770,55 @@ var Scorm2004ValidationError = (function (_super) {
1022
770
  }(ValidationError));
1023
771
 
1024
772
 
773
+ ;// ./src/cmi/common/array.ts
774
+
775
+
776
+
777
+
778
+ var scorm12_error_codes = error_codes.scorm12;
779
+ var CMIArray = (function (_super) {
780
+ __extends(CMIArray, _super);
781
+ function CMIArray(params) {
782
+ var _this = _super.call(this) || this;
783
+ _this.__children = params.children;
784
+ _this._errorCode = params.errorCode || scorm12_error_codes.GENERAL;
785
+ _this._errorClass = params.errorClass || BaseScormValidationError;
786
+ _this.childArray = [];
787
+ return _this;
788
+ }
789
+ Object.defineProperty(CMIArray.prototype, "_children", {
790
+ get: function () {
791
+ return this.__children;
792
+ },
793
+ set: function (_children) {
794
+ throw new this._errorClass(this._errorCode);
795
+ },
796
+ enumerable: false,
797
+ configurable: true
798
+ });
799
+ Object.defineProperty(CMIArray.prototype, "_count", {
800
+ get: function () {
801
+ return this.childArray.length;
802
+ },
803
+ set: function (_count) {
804
+ throw new this._errorClass(this._errorCode);
805
+ },
806
+ enumerable: false,
807
+ configurable: true
808
+ });
809
+ CMIArray.prototype.toJSON = function () {
810
+ this.jsonString = true;
811
+ var result = {};
812
+ for (var i = 0; i < this.childArray.length; i++) {
813
+ result[i + ""] = this.childArray[i];
814
+ }
815
+ delete this.jsonString;
816
+ return result;
817
+ };
818
+ return CMIArray;
819
+ }(BaseCMI));
820
+
821
+
1025
822
  ;// ./src/utilities.ts
1026
823
  var SECONDS_PER_SECOND = 1.0;
1027
824
  var SECONDS_PER_MINUTE = 60;
@@ -1182,16 +979,33 @@ function countDecimals(num) {
1182
979
  var parts = num.toString().split(".")[1];
1183
980
  return parts.length || 0;
1184
981
  }
982
+ function formatMessage(functionName, message, CMIElement) {
983
+ var baseLength = 20;
984
+ var messageString = "";
985
+ messageString += functionName;
986
+ var fillChars = baseLength - messageString.length;
987
+ for (var i = 0; i < fillChars; i++) {
988
+ messageString += " ";
989
+ }
990
+ messageString += ": ";
991
+ if (CMIElement) {
992
+ var CMIElementBaseLength = 70;
993
+ messageString += CMIElement;
994
+ fillChars = CMIElementBaseLength - messageString.length;
995
+ for (var j = 0; j < fillChars; j++) {
996
+ messageString += " ";
997
+ }
998
+ }
999
+ if (message) {
1000
+ messageString += message;
1001
+ }
1002
+ return messageString;
1003
+ }
1004
+ function stringMatches(str, tester) {
1005
+ return (str === null || str === void 0 ? void 0 : str.match(tester)) !== null;
1006
+ }
1185
1007
 
1186
- ;// ./src/BaseAPI.ts
1187
-
1188
-
1189
-
1190
-
1191
-
1192
-
1193
- var global_constants = api_constants.global;
1194
- var BaseAPI_scorm12_error_codes = error_codes.scorm12;
1008
+ ;// ./src/utilities/debounce.ts
1195
1009
  function debounce(func, wait, immediate) {
1196
1010
  if (immediate === void 0) { immediate = false; }
1197
1011
  var timeout;
@@ -1214,43 +1028,48 @@ function debounce(func, wait, immediate) {
1214
1028
  func.apply(context, args);
1215
1029
  };
1216
1030
  }
1031
+
1032
+ ;// ./src/constants/default_settings.ts
1033
+
1034
+
1217
1035
  var DefaultSettings = {
1218
1036
  autocommit: false,
1219
1037
  autocommitSeconds: 10,
1220
1038
  asyncCommit: false,
1221
- sendBeaconCommit: false,
1039
+ sendFullCommit: true,
1222
1040
  lmsCommitUrl: false,
1223
1041
  dataCommitFormat: "json",
1224
1042
  commitRequestDataType: "application/json;charset=UTF-8",
1225
1043
  autoProgress: false,
1226
- logLevel: global_constants.LOG_LEVEL_ERROR,
1044
+ logLevel: api_constants.global.LOG_LEVEL_ERROR,
1227
1045
  selfReportSessionTime: false,
1228
1046
  alwaysSendTotalTime: false,
1047
+ renderCommonCommitFields: false,
1229
1048
  strict_errors: true,
1230
1049
  xhrHeaders: {},
1231
1050
  xhrWithCredentials: false,
1232
1051
  responseHandler: function (response) {
1233
1052
  return __awaiter(this, void 0, void 0, function () {
1234
- var httpResult, _a, _c;
1235
- return __generator(this, function (_e) {
1236
- switch (_e.label) {
1053
+ var httpResult, _a, _b;
1054
+ return __generator(this, function (_c) {
1055
+ switch (_c.label) {
1237
1056
  case 0:
1238
1057
  if (!(typeof response !== "undefined")) return [3, 2];
1239
- _c = (_a = JSON).parse;
1058
+ _b = (_a = JSON).parse;
1240
1059
  return [4, response.text()];
1241
1060
  case 1:
1242
- httpResult = _c.apply(_a, [_e.sent()]);
1061
+ httpResult = _b.apply(_a, [_c.sent()]);
1243
1062
  if (httpResult === null ||
1244
1063
  !{}.hasOwnProperty.call(httpResult, "result")) {
1245
1064
  if (response.status === 200) {
1246
1065
  return [2, {
1247
- result: global_constants.SCORM_TRUE,
1066
+ result: api_constants.global.SCORM_TRUE,
1248
1067
  errorCode: 0,
1249
1068
  }];
1250
1069
  }
1251
1070
  else {
1252
1071
  return [2, {
1253
- result: global_constants.SCORM_FALSE,
1072
+ result: api_constants.global.SCORM_FALSE,
1254
1073
  errorCode: 101,
1255
1074
  }];
1256
1075
  }
@@ -1260,14 +1079,14 @@ var DefaultSettings = {
1260
1079
  result: httpResult.result,
1261
1080
  errorCode: httpResult.errorCode
1262
1081
  ? httpResult.errorCode
1263
- : httpResult.result === global_constants.SCORM_TRUE
1082
+ : httpResult.result === api_constants.global.SCORM_TRUE
1264
1083
  ? 0
1265
1084
  : 101,
1266
1085
  }];
1267
1086
  }
1268
- _e.label = 2;
1087
+ _c.label = 2;
1269
1088
  case 2: return [2, {
1270
- result: global_constants.SCORM_FALSE,
1089
+ result: api_constants.global.SCORM_FALSE,
1271
1090
  errorCode: 101,
1272
1091
  }];
1273
1092
  }
@@ -1279,16 +1098,16 @@ var DefaultSettings = {
1279
1098
  },
1280
1099
  onLogMessage: function (messageLevel, logMessage) {
1281
1100
  switch (messageLevel) {
1282
- case global_constants.LOG_LEVEL_ERROR:
1101
+ case api_constants.global.LOG_LEVEL_ERROR:
1283
1102
  console.error(logMessage);
1284
1103
  break;
1285
- case global_constants.LOG_LEVEL_WARNING:
1104
+ case api_constants.global.LOG_LEVEL_WARNING:
1286
1105
  console.warn(logMessage);
1287
1106
  break;
1288
- case global_constants.LOG_LEVEL_INFO:
1107
+ case api_constants.global.LOG_LEVEL_INFO:
1289
1108
  console.info(logMessage);
1290
1109
  break;
1291
- case global_constants.LOG_LEVEL_DEBUG:
1110
+ case api_constants.global.LOG_LEVEL_DEBUG:
1292
1111
  if (console.debug) {
1293
1112
  console.debug(logMessage);
1294
1113
  }
@@ -1298,26 +1117,75 @@ var DefaultSettings = {
1298
1117
  break;
1299
1118
  }
1300
1119
  },
1120
+ scoItemIds: [],
1121
+ scoItemIdValidator: false,
1301
1122
  };
1302
- var BaseAPI = (function () {
1303
- function BaseAPI(error_codes, settings) {
1304
- var _newTarget = this.constructor;
1305
- this._settings = DefaultSettings;
1306
- if (_newTarget === BaseAPI) {
1307
- throw new TypeError("Cannot construct BaseAPI instances directly");
1308
- }
1309
- this.currentState = global_constants.STATE_NOT_INITIALIZED;
1310
- this.lastErrorCode = "0";
1311
- this.listenerArray = [];
1312
- this._error_codes = error_codes;
1313
- if (settings) {
1314
- this.settings = settings;
1315
- }
1316
- this.apiLogLevel = this.settings.logLevel;
1317
- this.selfReportSessionTime = this.settings.selfReportSessionTime;
1123
+
1124
+ ;// ./src/helpers/scheduled_commit.ts
1125
+
1126
+ var ScheduledCommit = (function () {
1127
+ function ScheduledCommit(API, when, callback) {
1128
+ this._cancelled = false;
1129
+ this._API = API;
1130
+ this._timeout = setTimeout(this.wrapper.bind(this), when);
1131
+ this._callback = callback;
1318
1132
  }
1319
- BaseAPI.prototype.initialize = function (callbackName, initializeMessage, terminationMessage) {
1320
- var returnValue = global_constants.SCORM_FALSE;
1133
+ ScheduledCommit.prototype.cancel = function () {
1134
+ this._cancelled = true;
1135
+ if (this._timeout) {
1136
+ clearTimeout(this._timeout);
1137
+ }
1138
+ };
1139
+ ScheduledCommit.prototype.wrapper = function () {
1140
+ var _this = this;
1141
+ if (!this._cancelled) {
1142
+ (function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
1143
+ switch (_a.label) {
1144
+ case 0: return [4, this._API.commit(this._callback)];
1145
+ case 1: return [2, _a.sent()];
1146
+ }
1147
+ }); }); })();
1148
+ }
1149
+ };
1150
+ return ScheduledCommit;
1151
+ }());
1152
+
1153
+
1154
+ ;// ./src/BaseAPI.ts
1155
+
1156
+
1157
+
1158
+
1159
+
1160
+
1161
+
1162
+
1163
+
1164
+ var BaseAPI = (function () {
1165
+ function BaseAPI(error_codes, settings) {
1166
+ var _newTarget = this.constructor;
1167
+ this._settings = DefaultSettings;
1168
+ if (_newTarget === BaseAPI) {
1169
+ throw new TypeError("Cannot construct BaseAPI instances directly");
1170
+ }
1171
+ this.currentState = api_constants.global.STATE_NOT_INITIALIZED;
1172
+ this.lastErrorCode = "0";
1173
+ this.listenerArray = [];
1174
+ this._error_codes = error_codes;
1175
+ if (settings) {
1176
+ this.settings = settings;
1177
+ }
1178
+ this.apiLogLevel = this.settings.logLevel;
1179
+ this.selfReportSessionTime = this.settings.selfReportSessionTime;
1180
+ }
1181
+ BaseAPI.prototype.commonReset = function (settings) {
1182
+ this.settings = __assign(__assign({}, this.settings), settings);
1183
+ this.currentState = api_constants.global.STATE_NOT_INITIALIZED;
1184
+ this.lastErrorCode = "0";
1185
+ this.listenerArray = [];
1186
+ };
1187
+ BaseAPI.prototype.initialize = function (callbackName, initializeMessage, terminationMessage) {
1188
+ var returnValue = api_constants.global.SCORM_FALSE;
1321
1189
  if (this.isInitialized()) {
1322
1190
  this.throwSCORMError(this._error_codes.INITIALIZED, initializeMessage);
1323
1191
  }
@@ -1328,15 +1196,21 @@ var BaseAPI = (function () {
1328
1196
  if (this.selfReportSessionTime) {
1329
1197
  this.cmi.setStartTime();
1330
1198
  }
1331
- this.currentState = global_constants.STATE_INITIALIZED;
1199
+ this.currentState = api_constants.global.STATE_INITIALIZED;
1332
1200
  this.lastErrorCode = "0";
1333
- returnValue = global_constants.SCORM_TRUE;
1201
+ returnValue = api_constants.global.SCORM_TRUE;
1334
1202
  this.processListeners(callbackName);
1335
1203
  }
1336
- this.apiLog(callbackName, "returned: " + returnValue, global_constants.LOG_LEVEL_INFO);
1204
+ this.apiLog(callbackName, "returned: " + returnValue, api_constants.global.LOG_LEVEL_INFO);
1337
1205
  this.clearSCORMError(returnValue);
1338
1206
  return returnValue;
1339
1207
  };
1208
+ BaseAPI.prototype.apiLog = function (functionName, logMessage, messageLevel, CMIElement) {
1209
+ logMessage = formatMessage(functionName, logMessage, CMIElement);
1210
+ if (messageLevel >= this.apiLogLevel) {
1211
+ this.settings.onLogMessage(messageLevel, logMessage);
1212
+ }
1213
+ };
1340
1214
  Object.defineProperty(BaseAPI.prototype, "error_codes", {
1341
1215
  get: function () {
1342
1216
  return this._error_codes;
@@ -1355,25 +1229,36 @@ var BaseAPI = (function () {
1355
1229
  configurable: true
1356
1230
  });
1357
1231
  BaseAPI.prototype.terminate = function (callbackName, checkTerminated) {
1358
- var returnValue = global_constants.SCORM_FALSE;
1359
- if (this.checkState(checkTerminated, this._error_codes.TERMINATION_BEFORE_INIT, this._error_codes.MULTIPLE_TERMINATION)) {
1360
- this.currentState = global_constants.STATE_TERMINATED;
1361
- var result = this.storeData(true);
1362
- if (typeof result.errorCode !== "undefined" && result.errorCode > 0) {
1363
- this.throwSCORMError(result.errorCode);
1364
- }
1365
- returnValue =
1366
- typeof result !== "undefined" && result.result
1367
- ? result.result
1368
- : global_constants.SCORM_FALSE;
1369
- if (checkTerminated)
1370
- this.lastErrorCode = "0";
1371
- returnValue = global_constants.SCORM_TRUE;
1372
- this.processListeners(callbackName);
1373
- }
1374
- this.apiLog(callbackName, "returned: " + returnValue, global_constants.LOG_LEVEL_INFO);
1375
- this.clearSCORMError(returnValue);
1376
- return returnValue;
1232
+ return __awaiter(this, void 0, void 0, function () {
1233
+ var returnValue, result;
1234
+ return __generator(this, function (_a) {
1235
+ switch (_a.label) {
1236
+ case 0:
1237
+ returnValue = api_constants.global.SCORM_FALSE;
1238
+ if (!this.checkState(checkTerminated, this._error_codes.TERMINATION_BEFORE_INIT, this._error_codes.MULTIPLE_TERMINATION)) return [3, 2];
1239
+ this.currentState = api_constants.global.STATE_TERMINATED;
1240
+ return [4, this.storeData(true)];
1241
+ case 1:
1242
+ result = _a.sent();
1243
+ if (typeof result.errorCode !== "undefined" && result.errorCode > 0) {
1244
+ this.throwSCORMError(result.errorCode);
1245
+ }
1246
+ returnValue =
1247
+ typeof result !== "undefined" && result.result
1248
+ ? result.result
1249
+ : api_constants.global.SCORM_FALSE;
1250
+ if (checkTerminated)
1251
+ this.lastErrorCode = "0";
1252
+ returnValue = api_constants.global.SCORM_TRUE;
1253
+ this.processListeners(callbackName);
1254
+ _a.label = 2;
1255
+ case 2:
1256
+ this.apiLog(callbackName, "returned: " + returnValue, api_constants.global.LOG_LEVEL_INFO);
1257
+ this.clearSCORMError(returnValue);
1258
+ return [2, returnValue];
1259
+ }
1260
+ });
1261
+ });
1377
1262
  };
1378
1263
  BaseAPI.prototype.getValue = function (callbackName, checkTerminated, CMIElement) {
1379
1264
  var returnValue = "";
@@ -1388,7 +1273,10 @@ var BaseAPI = (function () {
1388
1273
  }
1389
1274
  this.processListeners(callbackName, CMIElement);
1390
1275
  }
1391
- this.apiLog(callbackName, ": returned: " + returnValue, global_constants.LOG_LEVEL_INFO, CMIElement);
1276
+ this.apiLog(callbackName, ": returned: " + returnValue, api_constants.global.LOG_LEVEL_INFO, CMIElement);
1277
+ if (returnValue === undefined) {
1278
+ return "";
1279
+ }
1392
1280
  this.clearSCORMError(returnValue);
1393
1281
  return returnValue;
1394
1282
  };
@@ -1396,7 +1284,7 @@ var BaseAPI = (function () {
1396
1284
  if (value !== undefined) {
1397
1285
  value = String(value);
1398
1286
  }
1399
- var returnValue = global_constants.SCORM_FALSE;
1287
+ var returnValue = api_constants.global.SCORM_FALSE;
1400
1288
  if (this.checkState(checkTerminated, this._error_codes.STORE_BEFORE_INIT, this._error_codes.STORE_AFTER_TERM)) {
1401
1289
  if (checkTerminated)
1402
1290
  this.lastErrorCode = "0";
@@ -1409,43 +1297,54 @@ var BaseAPI = (function () {
1409
1297
  this.processListeners(callbackName, CMIElement, value);
1410
1298
  }
1411
1299
  if (returnValue === undefined) {
1412
- returnValue = global_constants.SCORM_FALSE;
1300
+ returnValue = api_constants.global.SCORM_FALSE;
1413
1301
  }
1414
1302
  if (String(this.lastErrorCode) === "0") {
1415
1303
  if (this.settings.autocommit && !this._timeout) {
1416
1304
  this.scheduleCommit(this.settings.autocommitSeconds * 1000, commitCallback);
1417
1305
  }
1418
1306
  }
1419
- this.apiLog(callbackName, ": " + value + ": result: " + returnValue, global_constants.LOG_LEVEL_INFO, CMIElement);
1307
+ this.apiLog(callbackName, ": " + value + ": result: " + returnValue, api_constants.global.LOG_LEVEL_INFO, CMIElement);
1420
1308
  this.clearSCORMError(returnValue);
1421
1309
  return returnValue;
1422
1310
  };
1423
- BaseAPI.prototype.commit = function (callbackName, checkTerminated) {
1424
- if (checkTerminated === void 0) { checkTerminated = false; }
1425
- this.clearScheduledCommit();
1426
- var returnValue = global_constants.SCORM_FALSE;
1427
- if (this.checkState(checkTerminated, this._error_codes.COMMIT_BEFORE_INIT, this._error_codes.COMMIT_AFTER_TERM)) {
1428
- var result = this.storeData(false);
1429
- if (result.errorCode && result.errorCode > 0) {
1430
- this.throwSCORMError(result.errorCode);
1431
- }
1432
- returnValue =
1433
- typeof result !== "undefined" && result.result
1434
- ? result.result
1435
- : global_constants.SCORM_FALSE;
1436
- this.apiLog(callbackName, " Result: " + returnValue, global_constants.LOG_LEVEL_DEBUG, "HttpRequest");
1437
- if (checkTerminated)
1438
- this.lastErrorCode = "0";
1439
- this.processListeners(callbackName);
1440
- }
1441
- this.apiLog(callbackName, "returned: " + returnValue, global_constants.LOG_LEVEL_INFO);
1442
- this.clearSCORMError(returnValue);
1443
- return returnValue;
1311
+ BaseAPI.prototype.commit = function (callbackName_1) {
1312
+ return __awaiter(this, arguments, void 0, function (callbackName, checkTerminated) {
1313
+ var returnValue, result;
1314
+ if (checkTerminated === void 0) { checkTerminated = false; }
1315
+ return __generator(this, function (_a) {
1316
+ switch (_a.label) {
1317
+ case 0:
1318
+ this.clearScheduledCommit();
1319
+ returnValue = api_constants.global.SCORM_FALSE;
1320
+ if (!this.checkState(checkTerminated, this._error_codes.COMMIT_BEFORE_INIT, this._error_codes.COMMIT_AFTER_TERM)) return [3, 2];
1321
+ return [4, this.storeData(false)];
1322
+ case 1:
1323
+ result = _a.sent();
1324
+ if (result.errorCode && result.errorCode > 0) {
1325
+ this.throwSCORMError(result.errorCode);
1326
+ }
1327
+ returnValue =
1328
+ typeof result !== "undefined" && result.result
1329
+ ? result.result
1330
+ : api_constants.global.SCORM_FALSE;
1331
+ this.apiLog(callbackName, " Result: " + returnValue, api_constants.global.LOG_LEVEL_DEBUG, "HttpRequest");
1332
+ if (checkTerminated)
1333
+ this.lastErrorCode = "0";
1334
+ this.processListeners(callbackName);
1335
+ _a.label = 2;
1336
+ case 2:
1337
+ this.apiLog(callbackName, "returned: " + returnValue, api_constants.global.LOG_LEVEL_INFO);
1338
+ this.clearSCORMError(returnValue);
1339
+ return [2, returnValue];
1340
+ }
1341
+ });
1342
+ });
1444
1343
  };
1445
1344
  BaseAPI.prototype.getLastError = function (callbackName) {
1446
1345
  var returnValue = String(this.lastErrorCode);
1447
1346
  this.processListeners(callbackName);
1448
- this.apiLog(callbackName, "returned: " + returnValue, global_constants.LOG_LEVEL_INFO);
1347
+ this.apiLog(callbackName, "returned: " + returnValue, api_constants.global.LOG_LEVEL_INFO);
1449
1348
  return returnValue;
1450
1349
  };
1451
1350
  BaseAPI.prototype.getErrorString = function (callbackName, CMIErrorCode) {
@@ -1454,7 +1353,7 @@ var BaseAPI = (function () {
1454
1353
  returnValue = this.getLmsErrorMessageDetails(CMIErrorCode);
1455
1354
  this.processListeners(callbackName);
1456
1355
  }
1457
- this.apiLog(callbackName, "returned: " + returnValue, global_constants.LOG_LEVEL_INFO);
1356
+ this.apiLog(callbackName, "returned: " + returnValue, api_constants.global.LOG_LEVEL_INFO);
1458
1357
  return returnValue;
1459
1358
  };
1460
1359
  BaseAPI.prototype.getDiagnostic = function (callbackName, CMIErrorCode) {
@@ -1463,7 +1362,7 @@ var BaseAPI = (function () {
1463
1362
  returnValue = this.getLmsErrorMessageDetails(CMIErrorCode, true);
1464
1363
  this.processListeners(callbackName);
1465
1364
  }
1466
- this.apiLog(callbackName, "returned: " + returnValue, global_constants.LOG_LEVEL_INFO);
1365
+ this.apiLog(callbackName, "returned: " + returnValue, api_constants.global.LOG_LEVEL_INFO);
1467
1366
  return returnValue;
1468
1367
  };
1469
1368
  BaseAPI.prototype.checkState = function (checkTerminated, beforeInitError, afterTermError) {
@@ -1477,42 +1376,6 @@ var BaseAPI = (function () {
1477
1376
  }
1478
1377
  return true;
1479
1378
  };
1480
- BaseAPI.prototype.apiLog = function (functionName, logMessage, messageLevel, CMIElement) {
1481
- logMessage = this.formatMessage(functionName, logMessage, CMIElement);
1482
- if (messageLevel >= this.apiLogLevel) {
1483
- this.settings.onLogMessage(messageLevel, logMessage);
1484
- }
1485
- };
1486
- BaseAPI.prototype.formatMessage = function (functionName, message, CMIElement) {
1487
- var baseLength = 20;
1488
- var messageString = "";
1489
- messageString += functionName;
1490
- var fillChars = baseLength - messageString.length;
1491
- for (var i = 0; i < fillChars; i++) {
1492
- messageString += " ";
1493
- }
1494
- messageString += ": ";
1495
- if (CMIElement) {
1496
- var CMIElementBaseLength = 70;
1497
- messageString += CMIElement;
1498
- fillChars = CMIElementBaseLength - messageString.length;
1499
- for (var j = 0; j < fillChars; j++) {
1500
- messageString += " ";
1501
- }
1502
- }
1503
- if (message) {
1504
- messageString += message;
1505
- }
1506
- return messageString;
1507
- };
1508
- BaseAPI.prototype.stringMatches = function (str, tester) {
1509
- return (str === null || str === void 0 ? void 0 : str.match(tester)) !== null;
1510
- };
1511
- BaseAPI.prototype._checkObjectHasProperty = function (refObject, attribute) {
1512
- return (Object.hasOwnProperty.call(refObject, attribute) ||
1513
- Object.getOwnPropertyDescriptor(Object.getPrototypeOf(refObject), attribute) != null ||
1514
- attribute in refObject);
1515
- };
1516
1379
  BaseAPI.prototype.getLmsErrorMessageDetails = function (_errorNumber, _detail) {
1517
1380
  if (_detail === void 0) { _detail = false; }
1518
1381
  throw new Error("The getLmsErrorMessageDetails method has not been implemented");
@@ -1525,11 +1388,11 @@ var BaseAPI = (function () {
1525
1388
  };
1526
1389
  BaseAPI.prototype._commonSetCMIValue = function (methodName, scorm2004, CMIElement, value) {
1527
1390
  if (!CMIElement || CMIElement === "") {
1528
- return global_constants.SCORM_FALSE;
1391
+ return api_constants.global.SCORM_FALSE;
1529
1392
  }
1530
1393
  var structure = CMIElement.split(".");
1531
1394
  var refObject = this;
1532
- var returnValue = global_constants.SCORM_FALSE;
1395
+ var returnValue = api_constants.global.SCORM_FALSE;
1533
1396
  var foundFirstIndex = false;
1534
1397
  var invalidErrorMessage = "The data model element passed to ".concat(methodName, " (").concat(CMIElement, ") is not a valid SCORM data model element.");
1535
1398
  var invalidErrorCode = scorm2004
@@ -1538,22 +1401,25 @@ var BaseAPI = (function () {
1538
1401
  for (var idx = 0; idx < structure.length; idx++) {
1539
1402
  var attribute = structure[idx];
1540
1403
  if (idx === structure.length - 1) {
1541
- if (scorm2004 &&
1542
- attribute.substring(0, 8) === "{target=" &&
1543
- typeof refObject._isTargetValid == "function") {
1544
- this.throwSCORMError(this._error_codes.READ_ONLY_ELEMENT);
1404
+ if (scorm2004 && attribute.substring(0, 8) === "{target=") {
1405
+ if (this.isInitialized()) {
1406
+ this.throwSCORMError(this._error_codes.READ_ONLY_ELEMENT);
1407
+ }
1408
+ else {
1409
+ refObject = __assign(__assign({}, refObject), { attribute: value });
1410
+ }
1545
1411
  }
1546
1412
  else if (!this._checkObjectHasProperty(refObject, attribute)) {
1547
1413
  this.throwSCORMError(invalidErrorCode, invalidErrorMessage);
1548
1414
  }
1549
1415
  else {
1550
- if (this.isInitialized() &&
1551
- this.stringMatches(CMIElement, "\\.correct_responses\\.\\d+")) {
1416
+ if (stringMatches(CMIElement, "\\.correct_responses\\.\\d+") &&
1417
+ this.isInitialized()) {
1552
1418
  this.validateCorrectResponse(CMIElement, value);
1553
1419
  }
1554
1420
  if (!scorm2004 || this.lastErrorCode === "0") {
1555
1421
  refObject[attribute] = value;
1556
- returnValue = global_constants.SCORM_TRUE;
1422
+ returnValue = api_constants.global.SCORM_TRUE;
1557
1423
  }
1558
1424
  }
1559
1425
  }
@@ -1589,8 +1455,8 @@ var BaseAPI = (function () {
1589
1455
  }
1590
1456
  }
1591
1457
  }
1592
- if (returnValue === global_constants.SCORM_FALSE) {
1593
- this.apiLog(methodName, "There was an error setting the value for: ".concat(CMIElement, ", value of: ").concat(value), global_constants.LOG_LEVEL_WARNING);
1458
+ if (returnValue === api_constants.global.SCORM_FALSE) {
1459
+ this.apiLog(methodName, "There was an error setting the value for: ".concat(CMIElement, ", value of: ").concat(value), api_constants.global.LOG_LEVEL_WARNING);
1594
1460
  }
1595
1461
  return returnValue;
1596
1462
  };
@@ -1650,10 +1516,10 @@ var BaseAPI = (function () {
1650
1516
  if (refObject === null || refObject === undefined) {
1651
1517
  if (!scorm2004) {
1652
1518
  if (attribute === "_children") {
1653
- this.throwSCORMError(BaseAPI_scorm12_error_codes.CHILDREN_ERROR);
1519
+ this.throwSCORMError(error_codes.scorm12.CHILDREN_ERROR);
1654
1520
  }
1655
1521
  else if (attribute === "_count") {
1656
- this.throwSCORMError(BaseAPI_scorm12_error_codes.COUNT_ERROR);
1522
+ this.throwSCORMError(error_codes.scorm12.COUNT_ERROR);
1657
1523
  }
1658
1524
  }
1659
1525
  }
@@ -1662,13 +1528,13 @@ var BaseAPI = (function () {
1662
1528
  }
1663
1529
  };
1664
1530
  BaseAPI.prototype.isInitialized = function () {
1665
- return this.currentState === global_constants.STATE_INITIALIZED;
1531
+ return this.currentState === api_constants.global.STATE_INITIALIZED;
1666
1532
  };
1667
1533
  BaseAPI.prototype.isNotInitialized = function () {
1668
- return this.currentState === global_constants.STATE_NOT_INITIALIZED;
1534
+ return this.currentState === api_constants.global.STATE_NOT_INITIALIZED;
1669
1535
  };
1670
1536
  BaseAPI.prototype.isTerminated = function () {
1671
- return this.currentState === global_constants.STATE_TERMINATED;
1537
+ return this.currentState === api_constants.global.STATE_TERMINATED;
1672
1538
  };
1673
1539
  BaseAPI.prototype.on = function (listenerName, callback) {
1674
1540
  if (!callback)
@@ -1688,7 +1554,7 @@ var BaseAPI = (function () {
1688
1554
  CMIElement: CMIElement,
1689
1555
  callback: callback,
1690
1556
  });
1691
- this.apiLog("on", "Added event listener: ".concat(this.listenerArray.length), global_constants.LOG_LEVEL_INFO, functionName);
1557
+ this.apiLog("on", "Added event listener: ".concat(this.listenerArray.length), api_constants.global.LOG_LEVEL_INFO, functionName);
1692
1558
  }
1693
1559
  };
1694
1560
  BaseAPI.prototype.off = function (listenerName, callback) {
@@ -1711,7 +1577,7 @@ var BaseAPI = (function () {
1711
1577
  });
1712
1578
  if (removeIndex !== -1) {
1713
1579
  this_1.listenerArray.splice(removeIndex, 1);
1714
- this_1.apiLog("off", "Removed event listener: ".concat(this_1.listenerArray.length), global_constants.LOG_LEVEL_INFO, functionName);
1580
+ this_1.apiLog("off", "Removed event listener: ".concat(this_1.listenerArray.length), api_constants.global.LOG_LEVEL_INFO, functionName);
1715
1581
  }
1716
1582
  };
1717
1583
  var this_1 = this;
@@ -1744,7 +1610,7 @@ var BaseAPI = (function () {
1744
1610
  }
1745
1611
  };
1746
1612
  BaseAPI.prototype.processListeners = function (functionName, CMIElement, value) {
1747
- this.apiLog(functionName, value, global_constants.LOG_LEVEL_INFO, CMIElement);
1613
+ this.apiLog(functionName, value, api_constants.global.LOG_LEVEL_INFO, CMIElement);
1748
1614
  for (var i = 0; i < this.listenerArray.length; i++) {
1749
1615
  var listener = this.listenerArray[i];
1750
1616
  var functionsMatch = listener.functionName === functionName;
@@ -1760,7 +1626,7 @@ var BaseAPI = (function () {
1760
1626
  CMIElementsMatch = listener.CMIElement === CMIElement;
1761
1627
  }
1762
1628
  if (functionsMatch && (!listenerHasCMIElement || CMIElementsMatch)) {
1763
- this.apiLog("processListeners", "Processing listener: ".concat(listener.functionName), global_constants.LOG_LEVEL_INFO, CMIElement);
1629
+ this.apiLog("processListeners", "Processing listener: ".concat(listener.functionName), api_constants.global.LOG_LEVEL_INFO, CMIElement);
1764
1630
  listener.callback(CMIElement, value);
1765
1631
  }
1766
1632
  }
@@ -1769,16 +1635,19 @@ var BaseAPI = (function () {
1769
1635
  if (!message) {
1770
1636
  message = this.getLmsErrorMessageDetails(errorNumber);
1771
1637
  }
1772
- this.apiLog("throwSCORMError", errorNumber + ": " + message, global_constants.LOG_LEVEL_ERROR);
1638
+ this.apiLog("throwSCORMError", errorNumber + ": " + message, api_constants.global.LOG_LEVEL_ERROR);
1773
1639
  this.lastErrorCode = String(errorNumber);
1774
1640
  };
1775
1641
  BaseAPI.prototype.clearSCORMError = function (success) {
1776
- if (success !== undefined && success !== global_constants.SCORM_FALSE) {
1642
+ if (success !== undefined && success !== api_constants.global.SCORM_FALSE) {
1777
1643
  this.lastErrorCode = "0";
1778
1644
  }
1779
1645
  };
1780
1646
  BaseAPI.prototype.loadFromFlattenedJSON = function (json, CMIElement) {
1781
1647
  var _this = this;
1648
+ if (!CMIElement) {
1649
+ CMIElement = "";
1650
+ }
1782
1651
  if (!this.isNotInitialized()) {
1783
1652
  console.error("loadFromFlattenedJSON can only be called before the call to lmsInitialize.");
1784
1653
  return;
@@ -1866,87 +1735,96 @@ var BaseAPI = (function () {
1866
1735
  };
1867
1736
  BaseAPI.prototype.renderCMIToJSONString = function () {
1868
1737
  var cmi = this.cmi;
1869
- return JSON.stringify({ cmi: cmi });
1738
+ if (this.settings.sendFullCommit) {
1739
+ return JSON.stringify({ cmi: cmi });
1740
+ }
1741
+ return JSON.stringify({ cmi: cmi }, function (k, v) { return (v === undefined ? null : v); }, 2);
1870
1742
  };
1871
1743
  BaseAPI.prototype.renderCMIToJSONObject = function () {
1872
1744
  return JSON.parse(this.renderCMIToJSONString());
1873
1745
  };
1874
- BaseAPI.prototype.processHttpRequest = function (url, params, immediate) {
1875
- var _this = this;
1876
- if (immediate === void 0) { immediate = false; }
1877
- var api = this;
1878
- var genericError = {
1879
- result: global_constants.SCORM_FALSE,
1880
- errorCode: this.error_codes.GENERAL,
1881
- };
1882
- var process = function (url, params, settings) { return __awaiter(_this, void 0, void 0, function () {
1883
- var response, result, _a, e_1;
1884
- return __generator(this, function (_c) {
1885
- switch (_c.label) {
1746
+ BaseAPI.prototype.processHttpRequest = function (url_1, params_1) {
1747
+ return __awaiter(this, arguments, void 0, function (url, params, immediate) {
1748
+ var api, genericError, process, debouncedProcess;
1749
+ var _this = this;
1750
+ if (immediate === void 0) { immediate = false; }
1751
+ return __generator(this, function (_a) {
1752
+ switch (_a.label) {
1886
1753
  case 0:
1887
- _c.trys.push([0, 6, , 7]);
1888
- params = settings.requestHandler(params);
1889
- return [4, fetch(url, {
1890
- method: "POST",
1891
- body: params instanceof Array ? params.join("&") : JSON.stringify(params),
1892
- headers: __assign(__assign({}, settings.xhrHeaders), { "Content-Type": settings.commitRequestDataType }),
1893
- credentials: settings.xhrWithCredentials ? "include" : undefined,
1894
- keepalive: true,
1895
- })];
1896
- case 1:
1897
- response = _c.sent();
1898
- if (!(typeof settings.responseHandler === "function")) return [3, 3];
1899
- return [4, settings.responseHandler(response)];
1900
- case 2:
1901
- _a = _c.sent();
1902
- return [3, 5];
1903
- case 3: return [4, response.json()];
1904
- case 4:
1905
- _a = _c.sent();
1906
- _c.label = 5;
1907
- case 5:
1908
- result = _a;
1909
- if (response.status >= 200 &&
1910
- response.status <= 299 &&
1911
- (result.result === true ||
1912
- result.result === global_constants.SCORM_TRUE)) {
1913
- api.processListeners("CommitSuccess");
1914
- }
1915
- else {
1916
- api.processListeners("CommitError");
1754
+ api = this;
1755
+ genericError = {
1756
+ result: api_constants.global.SCORM_FALSE,
1757
+ errorCode: this.error_codes.GENERAL,
1758
+ };
1759
+ if (immediate) {
1760
+ this.performFetch(url, params).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
1761
+ return __generator(this, function (_a) {
1762
+ switch (_a.label) {
1763
+ case 0: return [4, this.transformResponse(response)];
1764
+ case 1:
1765
+ _a.sent();
1766
+ return [2];
1767
+ }
1768
+ });
1769
+ }); });
1770
+ return [2, {
1771
+ result: api_constants.global.SCORM_TRUE,
1772
+ errorCode: 0,
1773
+ }];
1917
1774
  }
1918
- return [2, result];
1919
- case 6:
1920
- e_1 = _c.sent();
1921
- this.apiLog("processHttpRequest", e_1, global_constants.LOG_LEVEL_ERROR);
1922
- api.processListeners("CommitError");
1923
- return [2, genericError];
1924
- case 7: return [2];
1775
+ process = function (url, params, settings) { return __awaiter(_this, void 0, void 0, function () {
1776
+ var response, e_1;
1777
+ return __generator(this, function (_a) {
1778
+ switch (_a.label) {
1779
+ case 0:
1780
+ _a.trys.push([0, 2, , 3]);
1781
+ params = settings.requestHandler(params);
1782
+ return [4, this.performFetch(url, params)];
1783
+ case 1:
1784
+ response = _a.sent();
1785
+ return [2, this.transformResponse(response)];
1786
+ case 2:
1787
+ e_1 = _a.sent();
1788
+ this.apiLog("processHttpRequest", e_1, api_constants.global.LOG_LEVEL_ERROR);
1789
+ api.processListeners("CommitError");
1790
+ return [2, genericError];
1791
+ case 3: return [2];
1792
+ }
1793
+ });
1794
+ }); };
1795
+ if (!this.settings.asyncCommit) return [3, 1];
1796
+ debouncedProcess = debounce(process, 500, immediate);
1797
+ debouncedProcess(url, params, this.settings);
1798
+ return [2, {
1799
+ result: api_constants.global.SCORM_TRUE,
1800
+ errorCode: 0,
1801
+ }];
1802
+ case 1: return [4, process(url, params, this.settings)];
1803
+ case 2: return [2, _a.sent()];
1925
1804
  }
1926
1805
  });
1927
- }); };
1928
- var debouncedProcess = debounce(process, 500, immediate);
1929
- debouncedProcess(url, params, this.settings);
1930
- return {
1931
- result: global_constants.SCORM_TRUE,
1932
- errorCode: 0,
1933
- };
1806
+ });
1934
1807
  };
1935
1808
  BaseAPI.prototype.scheduleCommit = function (when, callback) {
1936
1809
  this._timeout = new ScheduledCommit(this, when, callback);
1937
- this.apiLog("scheduleCommit", "scheduled", global_constants.LOG_LEVEL_DEBUG, "");
1810
+ this.apiLog("scheduleCommit", "scheduled", api_constants.global.LOG_LEVEL_DEBUG, "");
1938
1811
  };
1939
1812
  BaseAPI.prototype.clearScheduledCommit = function () {
1940
1813
  if (this._timeout) {
1941
1814
  this._timeout.cancel();
1942
1815
  this._timeout = undefined;
1943
- this.apiLog("clearScheduledCommit", "cleared", global_constants.LOG_LEVEL_DEBUG, "");
1816
+ this.apiLog("clearScheduledCommit", "cleared", api_constants.global.LOG_LEVEL_DEBUG, "");
1944
1817
  }
1945
1818
  };
1819
+ BaseAPI.prototype._checkObjectHasProperty = function (refObject, attribute) {
1820
+ return (Object.hasOwnProperty.call(refObject, attribute) ||
1821
+ Object.getOwnPropertyDescriptor(Object.getPrototypeOf(refObject), attribute) != null ||
1822
+ attribute in refObject);
1823
+ };
1946
1824
  BaseAPI.prototype.handleValueAccessException = function (e, returnValue) {
1947
1825
  if (e instanceof ValidationError) {
1948
1826
  this.lastErrorCode = String(e.errorCode);
1949
- returnValue = global_constants.SCORM_FALSE;
1827
+ returnValue = api_constants.global.SCORM_FALSE;
1950
1828
  }
1951
1829
  else {
1952
1830
  if (e instanceof Error && e.message) {
@@ -1959,112 +1837,344 @@ var BaseAPI = (function () {
1959
1837
  }
1960
1838
  return returnValue;
1961
1839
  };
1962
- return BaseAPI;
1963
- }());
1964
- /* harmony default export */ var src_BaseAPI = (BaseAPI);
1965
- var ScheduledCommit = (function () {
1966
- function ScheduledCommit(API, when, callback) {
1967
- this._cancelled = false;
1968
- this._API = API;
1969
- this._timeout = setTimeout(this.wrapper.bind(this), when);
1970
- this._callback = callback;
1971
- }
1972
- ScheduledCommit.prototype.cancel = function () {
1973
- this._cancelled = true;
1974
- if (this._timeout) {
1975
- clearTimeout(this._timeout);
1976
- }
1840
+ BaseAPI.prototype.performFetch = function (url, params) {
1841
+ return __awaiter(this, void 0, void 0, function () {
1842
+ return __generator(this, function (_a) {
1843
+ return [2, fetch(url, {
1844
+ method: "POST",
1845
+ body: params instanceof Array ? params.join("&") : JSON.stringify(params),
1846
+ headers: __assign(__assign({}, this.settings.xhrHeaders), { "Content-Type": this.settings.commitRequestDataType }),
1847
+ credentials: this.settings.xhrWithCredentials ? "include" : undefined,
1848
+ keepalive: true,
1849
+ })];
1850
+ });
1851
+ });
1977
1852
  };
1978
- ScheduledCommit.prototype.wrapper = function () {
1979
- if (!this._cancelled) {
1980
- this._API.commit(this._callback);
1981
- }
1853
+ BaseAPI.prototype.transformResponse = function (response) {
1854
+ return __awaiter(this, void 0, void 0, function () {
1855
+ var result, _a;
1856
+ return __generator(this, function (_c) {
1857
+ switch (_c.label) {
1858
+ case 0:
1859
+ if (!(typeof this.settings.responseHandler === "function")) return [3, 2];
1860
+ return [4, this.settings.responseHandler(response)];
1861
+ case 1:
1862
+ _a = _c.sent();
1863
+ return [3, 4];
1864
+ case 2: return [4, response.json()];
1865
+ case 3:
1866
+ _a = _c.sent();
1867
+ _c.label = 4;
1868
+ case 4:
1869
+ result = _a;
1870
+ if (response.status >= 200 &&
1871
+ response.status <= 299 &&
1872
+ (result.result === true ||
1873
+ result.result === api_constants.global.SCORM_TRUE)) {
1874
+ this.processListeners("CommitSuccess");
1875
+ }
1876
+ else {
1877
+ this.processListeners("CommitError");
1878
+ }
1879
+ return [2, result];
1880
+ }
1881
+ });
1882
+ });
1982
1883
  };
1983
- return ScheduledCommit;
1884
+ return BaseAPI;
1984
1885
  }());
1886
+ /* harmony default export */ var src_BaseAPI = (BaseAPI);
1985
1887
 
1986
- ;// ./src/constants/response_constants.ts
1888
+ ;// ./src/constants/regex.ts
1987
1889
 
1988
- var scorm2004_regex = regex.scorm2004;
1989
- var LearnerResponses = {
1990
- "true-false": {
1991
- format: "^true$|^false$",
1992
- max: 1,
1993
- delimiter: "",
1994
- unique: false,
1995
- },
1996
- choice: {
1997
- format: scorm2004_regex.CMILongIdentifier,
1998
- max: 36,
1999
- delimiter: "[,]",
2000
- unique: true,
2001
- },
2002
- "fill-in": {
2003
- format: scorm2004_regex.CMILangString250,
2004
- max: 10,
2005
- delimiter: "[,]",
2006
- unique: false,
2007
- },
2008
- "long-fill-in": {
2009
- format: scorm2004_regex.CMILangString4000,
2010
- max: 1,
2011
- delimiter: "",
2012
- unique: false,
2013
- },
2014
- matching: {
2015
- format: scorm2004_regex.CMIShortIdentifier,
2016
- format2: scorm2004_regex.CMIShortIdentifier,
2017
- max: 36,
2018
- delimiter: "[,]",
2019
- delimiter2: "[.]",
2020
- unique: false,
2021
- },
2022
- performance: {
2023
- format: "^$|" + scorm2004_regex.CMIShortIdentifier,
2024
- format2: scorm2004_regex.CMIDecimal + "|^$|" + scorm2004_regex.CMIShortIdentifier,
2025
- max: 250,
2026
- delimiter: "[,]",
2027
- delimiter2: "[.]",
2028
- unique: false,
2029
- },
2030
- sequencing: {
2031
- format: scorm2004_regex.CMIShortIdentifier,
2032
- max: 36,
2033
- delimiter: "[,]",
2034
- unique: false,
2035
- },
2036
- likert: {
2037
- format: scorm2004_regex.CMIShortIdentifier,
2038
- max: 1,
2039
- delimiter: "",
2040
- unique: false,
2041
- },
2042
- numeric: {
2043
- format: scorm2004_regex.CMIDecimal,
2044
- max: 1,
2045
- delimiter: "",
2046
- unique: false,
2047
- },
2048
- other: {
2049
- format: scorm2004_regex.CMIString4000,
2050
- max: 1,
2051
- delimiter: "",
2052
- unique: false,
2053
- },
2054
- };
2055
- var CorrectResponses = {
2056
- "true-false": {
2057
- max: 1,
2058
- delimiter: "",
2059
- unique: false,
2060
- duplicate: false,
2061
- format: "^true$|^false$",
2062
- limit: 1,
2063
- },
2064
- choice: {
2065
- max: 36,
2066
- delimiter: "[,]",
2067
- unique: true,
1890
+ var regex_scorm12 = {
1891
+ CMIString256: "^.{0,255}$",
1892
+ CMIString4096: "^.{0,4096}$",
1893
+ CMITime: "^(?:[01]\\d|2[0123]):(?:[012345]\\d):(?:[012345]\\d)$",
1894
+ CMITimespan: "^([0-9]{2,}):([0-9]{2}):([0-9]{2})(.[0-9]{1,2})?$",
1895
+ CMIInteger: "^\\d+$",
1896
+ CMISInteger: "^-?([0-9]+)$",
1897
+ CMIDecimal: "^-?([0-9]{0,3})(.[0-9]*)?$",
1898
+ CMIIdentifier: "^[\\u0021-\\u007E\\s]{0,255}$",
1899
+ CMIFeedback: "^.{0,255}$",
1900
+ CMIIndex: "[._](\\d+).",
1901
+ CMIStatus: "^(passed|completed|failed|incomplete|browsed)$",
1902
+ CMIStatus2: "^(passed|completed|failed|incomplete|browsed|not attempted)$",
1903
+ CMIExit: "^(time-out|suspend|logout|)$",
1904
+ CMIType: "^(true-false|choice|fill-in|matching|performance|sequencing|likert|numeric)$",
1905
+ CMIResult: "^(correct|wrong|unanticipated|neutral|([0-9]{0,3})?(\\.[0-9]*)?)$",
1906
+ NAVEvent: "^(previous|continue)$",
1907
+ score_range: "0#100",
1908
+ audio_range: "-1#100",
1909
+ speed_range: "-100#100",
1910
+ weighting_range: "-100#100",
1911
+ text_range: "-1#1",
1912
+ };
1913
+ var regex_aicc = __assign(__assign({}, regex_scorm12), {
1914
+ CMIIdentifier: "^\\w{1,255}$",
1915
+ });
1916
+ var regex_scorm2004 = {
1917
+ CMIString200: "^[\\u0000-\\uFFFF]{0,200}$",
1918
+ CMIString250: "^[\\u0000-\\uFFFF]{0,250}$",
1919
+ CMIString1000: "^[\\u0000-\\uFFFF]{0,1000}$",
1920
+ CMIString4000: "^[\\u0000-\\uFFFF]{0,4000}$",
1921
+ CMIString64000: "^[\\u0000-\\uFFFF]{0,64000}$",
1922
+ CMILang: "^([a-zA-Z]{2,3}|i|x)(-[a-zA-Z0-9-]{2,8})?$|^$",
1923
+ CMILangString250: "^({lang=([a-zA-Z]{2,3}|i|x)(-[a-zA-Z0-9-]{2,8})?})?((?!{.*$).{0,250}$)?$",
1924
+ CMILangcr: "^(({lang=([a-zA-Z]{2,3}|i|x)?(-[a-zA-Z0-9-]{2,8})?}))(.*?)$",
1925
+ CMILangString250cr: "^(({lang=([a-zA-Z]{2,3}|i|x)?(-[a-zA-Z0-9-]{2,8})?})?(.{0,250})?)?$",
1926
+ CMILangString4000: "^({lang=([a-zA-Z]{2,3}|i|x)(-[a-zA-Z0-9-]{2,8})?})?((?!{.*$).{0,4000}$)?$",
1927
+ CMITime: "^(19[7-9]{1}[0-9]{1}|20[0-2]{1}[0-9]{1}|203[0-8]{1})((-(0[1-9]{1}|1[0-2]{1}))((-(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]{1}))(T([0-1]{1}[0-9]{1}|2[0-3]{1})((:[0-5]{1}[0-9]{1})((:[0-5]{1}[0-9]{1})((\\.[0-9]{1,2})((Z|([+|-]([0-1]{1}[0-9]{1}|2[0-3]{1})))(:[0-5]{1}[0-9]{1})?)?)?)?)?)?)?)?$",
1928
+ CMITimespan: "^P(?:([.,\\d]+)Y)?(?:([.,\\d]+)M)?(?:([.,\\d]+)W)?(?:([.,\\d]+)D)?(?:T?(?:([.,\\d]+)H)?(?:([.,\\d]+)M)?(?:([.,\\d]+)S)?)?$",
1929
+ CMIInteger: "^\\d+$",
1930
+ CMISInteger: "^-?([0-9]+)$",
1931
+ CMIDecimal: "^-?([0-9]{1,5})(\\.[0-9]{1,18})?$",
1932
+ CMIIdentifier: "^\\S{1,250}[a-zA-Z0-9]$",
1933
+ CMIShortIdentifier: "^[\\w\\.\\-\\_]{1,250}$",
1934
+ CMILongIdentifier: "^(?:(?!urn:)\\S{1,4000}|urn:[A-Za-z0-9-]{1,31}:\\S{1,4000}|.{1,4000})$",
1935
+ CMIFeedback: "^.*$",
1936
+ CMIIndex: "[._](\\d+).",
1937
+ CMIIndexStore: ".N(\\d+).",
1938
+ CMICStatus: "^(completed|incomplete|not attempted|unknown)$",
1939
+ CMISStatus: "^(passed|failed|unknown)$",
1940
+ CMIExit: "^(time-out|suspend|logout|normal)$",
1941
+ CMIType: "^(true-false|choice|fill-in|long-fill-in|matching|performance|sequencing|likert|numeric|other)$",
1942
+ CMIResult: "^(correct|incorrect|unanticipated|neutral|-?([0-9]{1,4})(\\.[0-9]{1,18})?)$",
1943
+ NAVEvent: "^(previous|continue|exit|exitAll|abandon|abandonAll|suspendAll|_none_|(\\{target=\\S{0,}[a-zA-Z0-9-_]+})?choice|(\\{target=\\S{0,}[a-zA-Z0-9-_]+})?jump)$",
1944
+ NAVBoolean: "^(unknown|true|false$)",
1945
+ NAVTarget: "^{target=\\S{0,}[a-zA-Z0-9-_]+}$",
1946
+ scaled_range: "-1#1",
1947
+ audio_range: "0#*",
1948
+ speed_range: "0#*",
1949
+ text_range: "-1#1",
1950
+ progress_range: "0#1",
1951
+ };
1952
+ var Regex = {
1953
+ aicc: regex_aicc,
1954
+ scorm12: regex_scorm12,
1955
+ scorm2004: regex_scorm2004,
1956
+ };
1957
+ /* harmony default export */ var regex = (Regex);
1958
+
1959
+ ;// ./src/cmi/common/validation.ts
1960
+ function checkValidFormat(value, regexPattern, errorCode, errorClass, allowEmptyString) {
1961
+ if (typeof value !== "string") {
1962
+ return false;
1963
+ }
1964
+ var formatRegex = new RegExp(regexPattern);
1965
+ var matches = value.match(formatRegex);
1966
+ if (allowEmptyString && value === "") {
1967
+ return true;
1968
+ }
1969
+ if (value === undefined || !matches || matches[0] === "") {
1970
+ throw new errorClass(errorCode);
1971
+ }
1972
+ return true;
1973
+ }
1974
+ function checkValidRange(value, rangePattern, errorCode, errorClass) {
1975
+ var ranges = rangePattern.split("#");
1976
+ value = value * 1.0;
1977
+ if (value >= ranges[0]) {
1978
+ if (ranges[1] === "*" || value <= ranges[1]) {
1979
+ return true;
1980
+ }
1981
+ else {
1982
+ throw new errorClass(errorCode);
1983
+ }
1984
+ }
1985
+ else {
1986
+ throw new errorClass(errorCode);
1987
+ }
1988
+ }
1989
+
1990
+ ;// ./src/cmi/scorm2004/validation.ts
1991
+
1992
+
1993
+
1994
+ function check2004ValidFormat(value, regexPattern, allowEmptyString) {
1995
+ return checkValidFormat(value, regexPattern, error_codes.scorm2004.TYPE_MISMATCH, Scorm2004ValidationError, allowEmptyString);
1996
+ }
1997
+ function check2004ValidRange(value, rangePattern) {
1998
+ return checkValidRange(value, rangePattern, error_codes.scorm2004.VALUE_OUT_OF_RANGE, Scorm2004ValidationError);
1999
+ }
2000
+
2001
+ ;// ./src/cmi/scorm2004/learner_preference.ts
2002
+
2003
+
2004
+
2005
+
2006
+
2007
+
2008
+
2009
+ var CMILearnerPreference = (function (_super) {
2010
+ __extends(CMILearnerPreference, _super);
2011
+ function CMILearnerPreference() {
2012
+ var _this = _super.call(this) || this;
2013
+ _this.__children = api_constants.scorm2004.student_preference_children;
2014
+ _this._audio_level = "1";
2015
+ _this._language = "";
2016
+ _this._delivery_speed = "1";
2017
+ _this._audio_captioning = "0";
2018
+ return _this;
2019
+ }
2020
+ Object.defineProperty(CMILearnerPreference.prototype, "_children", {
2021
+ get: function () {
2022
+ return this.__children;
2023
+ },
2024
+ set: function (_children) {
2025
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
2026
+ },
2027
+ enumerable: false,
2028
+ configurable: true
2029
+ });
2030
+ Object.defineProperty(CMILearnerPreference.prototype, "audio_level", {
2031
+ get: function () {
2032
+ return this._audio_level;
2033
+ },
2034
+ set: function (audio_level) {
2035
+ if (check2004ValidFormat(audio_level, regex.scorm2004.CMIDecimal) &&
2036
+ check2004ValidRange(audio_level, regex.scorm2004.audio_range)) {
2037
+ this._audio_level = audio_level;
2038
+ }
2039
+ },
2040
+ enumerable: false,
2041
+ configurable: true
2042
+ });
2043
+ Object.defineProperty(CMILearnerPreference.prototype, "language", {
2044
+ get: function () {
2045
+ return this._language;
2046
+ },
2047
+ set: function (language) {
2048
+ if (check2004ValidFormat(language, regex.scorm2004.CMILang)) {
2049
+ this._language = language;
2050
+ }
2051
+ },
2052
+ enumerable: false,
2053
+ configurable: true
2054
+ });
2055
+ Object.defineProperty(CMILearnerPreference.prototype, "delivery_speed", {
2056
+ get: function () {
2057
+ return this._delivery_speed;
2058
+ },
2059
+ set: function (delivery_speed) {
2060
+ if (check2004ValidFormat(delivery_speed, regex.scorm2004.CMIDecimal) &&
2061
+ check2004ValidRange(delivery_speed, regex.scorm2004.speed_range)) {
2062
+ this._delivery_speed = delivery_speed;
2063
+ }
2064
+ },
2065
+ enumerable: false,
2066
+ configurable: true
2067
+ });
2068
+ Object.defineProperty(CMILearnerPreference.prototype, "audio_captioning", {
2069
+ get: function () {
2070
+ return this._audio_captioning;
2071
+ },
2072
+ set: function (audio_captioning) {
2073
+ if (check2004ValidFormat(audio_captioning, regex.scorm2004.CMISInteger) &&
2074
+ check2004ValidRange(audio_captioning, regex.scorm2004.text_range)) {
2075
+ this._audio_captioning = audio_captioning;
2076
+ }
2077
+ },
2078
+ enumerable: false,
2079
+ configurable: true
2080
+ });
2081
+ CMILearnerPreference.prototype.toJSON = function () {
2082
+ this.jsonString = true;
2083
+ var result = {
2084
+ audio_level: this.audio_level,
2085
+ language: this.language,
2086
+ delivery_speed: this.delivery_speed,
2087
+ audio_captioning: this.audio_captioning,
2088
+ };
2089
+ delete this.jsonString;
2090
+ return result;
2091
+ };
2092
+ return CMILearnerPreference;
2093
+ }(BaseCMI));
2094
+
2095
+
2096
+ ;// ./src/constants/response_constants.ts
2097
+
2098
+ var scorm2004_regex = regex.scorm2004;
2099
+ var LearnerResponses = {
2100
+ "true-false": {
2101
+ format: "^true$|^false$",
2102
+ max: 1,
2103
+ delimiter: "",
2104
+ unique: false,
2105
+ },
2106
+ choice: {
2107
+ format: scorm2004_regex.CMILongIdentifier,
2108
+ max: 36,
2109
+ delimiter: "[,]",
2110
+ unique: true,
2111
+ },
2112
+ "fill-in": {
2113
+ format: scorm2004_regex.CMILangString250,
2114
+ max: 10,
2115
+ delimiter: "[,]",
2116
+ unique: false,
2117
+ },
2118
+ "long-fill-in": {
2119
+ format: scorm2004_regex.CMILangString4000,
2120
+ max: 1,
2121
+ delimiter: "",
2122
+ unique: false,
2123
+ },
2124
+ matching: {
2125
+ format: scorm2004_regex.CMIShortIdentifier,
2126
+ format2: scorm2004_regex.CMIShortIdentifier,
2127
+ max: 36,
2128
+ delimiter: "[,]",
2129
+ delimiter2: "[.]",
2130
+ unique: false,
2131
+ },
2132
+ performance: {
2133
+ format: "^$|" + scorm2004_regex.CMIShortIdentifier,
2134
+ format2: scorm2004_regex.CMIDecimal + "|^$|" + scorm2004_regex.CMIShortIdentifier,
2135
+ max: 250,
2136
+ delimiter: "[,]",
2137
+ delimiter2: "[.]",
2138
+ unique: false,
2139
+ },
2140
+ sequencing: {
2141
+ format: scorm2004_regex.CMIShortIdentifier,
2142
+ max: 36,
2143
+ delimiter: "[,]",
2144
+ unique: false,
2145
+ },
2146
+ likert: {
2147
+ format: scorm2004_regex.CMIShortIdentifier,
2148
+ max: 1,
2149
+ delimiter: "",
2150
+ unique: false,
2151
+ },
2152
+ numeric: {
2153
+ format: scorm2004_regex.CMIDecimal,
2154
+ max: 1,
2155
+ delimiter: "",
2156
+ unique: false,
2157
+ },
2158
+ other: {
2159
+ format: scorm2004_regex.CMIString4000,
2160
+ max: 1,
2161
+ delimiter: "",
2162
+ unique: false,
2163
+ },
2164
+ };
2165
+ var CorrectResponses = {
2166
+ "true-false": {
2167
+ max: 1,
2168
+ delimiter: "",
2169
+ unique: false,
2170
+ duplicate: false,
2171
+ format: "^true$|^false$",
2172
+ limit: 1,
2173
+ },
2174
+ choice: {
2175
+ max: 36,
2176
+ delimiter: "[,]",
2177
+ unique: true,
2068
2178
  duplicate: false,
2069
2179
  format: scorm2004_regex.CMILongIdentifier,
2070
2180
  },
@@ -2095,6 +2205,7 @@ var CorrectResponses = {
2095
2205
  max: 250,
2096
2206
  delimiter: "[,]",
2097
2207
  delimiter2: "[.]",
2208
+ delimiter3: "[:]",
2098
2209
  unique: false,
2099
2210
  duplicate: false,
2100
2211
  format: "^$|" + scorm2004_regex.CMIShortIdentifier,
@@ -2133,7 +2244,7 @@ var CorrectResponses = {
2133
2244
  },
2134
2245
  };
2135
2246
 
2136
- ;// ./src/cmi/scorm2004_cmi.ts
2247
+ ;// ./src/cmi/scorm2004/interactions.ts
2137
2248
 
2138
2249
 
2139
2250
 
@@ -2142,734 +2253,588 @@ var CorrectResponses = {
2142
2253
 
2143
2254
 
2144
2255
 
2145
- var scorm2004_constants = api_constants.scorm2004;
2146
- var scorm2004_error_codes = error_codes.scorm2004;
2147
- var learner_responses = LearnerResponses;
2148
- var scorm2004_cmi_scorm2004_regex = regex.scorm2004;
2149
- function check2004ValidFormat(value, regexPattern, allowEmptyString) {
2150
- return checkValidFormat(value, regexPattern, scorm2004_error_codes.TYPE_MISMATCH, Scorm2004ValidationError, allowEmptyString);
2151
- }
2152
- function check2004ValidRange(value, rangePattern) {
2153
- return checkValidRange(value, rangePattern, scorm2004_error_codes.VALUE_OUT_OF_RANGE, Scorm2004ValidationError);
2154
- }
2155
- var CMI = (function (_super) {
2156
- __extends(CMI, _super);
2157
- function CMI(initialized) {
2158
- if (initialized === void 0) { initialized = false; }
2256
+
2257
+ var CMIInteractions = (function (_super) {
2258
+ __extends(CMIInteractions, _super);
2259
+ function CMIInteractions() {
2260
+ return _super.call(this, {
2261
+ children: api_constants.scorm2004.interactions_children,
2262
+ errorCode: error_codes.scorm2004.READ_ONLY_ELEMENT,
2263
+ errorClass: Scorm2004ValidationError,
2264
+ }) || this;
2265
+ }
2266
+ return CMIInteractions;
2267
+ }(CMIArray));
2268
+
2269
+ var CMIInteractionsObject = (function (_super) {
2270
+ __extends(CMIInteractionsObject, _super);
2271
+ function CMIInteractionsObject() {
2159
2272
  var _this = _super.call(this) || this;
2160
- _this.__version = "1.0";
2161
- _this.__children = scorm2004_constants.cmi_children;
2162
- _this._completion_status = "unknown";
2163
- _this._completion_threshold = "";
2164
- _this._credit = "credit";
2165
- _this._entry = "";
2166
- _this._exit = "";
2167
- _this._launch_data = "";
2168
- _this._learner_id = "";
2169
- _this._learner_name = "";
2170
- _this._location = "";
2171
- _this._max_time_allowed = "";
2172
- _this._mode = "normal";
2173
- _this._progress_measure = "";
2174
- _this._scaled_passing_score = "";
2175
- _this._session_time = "PT0H0M0S";
2176
- _this._success_status = "unknown";
2177
- _this._suspend_data = "";
2178
- _this._time_limit_action = "continue,no message";
2179
- _this._total_time = "";
2180
- _this.learner_preference = new CMILearnerPreference();
2181
- _this.score = new Scorm2004CMIScore();
2182
- _this.comments_from_learner = new CMICommentsFromLearner();
2183
- _this.comments_from_lms = new CMICommentsFromLMS();
2184
- _this.interactions = new CMIInteractions();
2185
- _this.objectives = new CMIObjectives();
2186
- if (initialized)
2187
- _this.initialize();
2273
+ _this._id = "";
2274
+ _this._type = "";
2275
+ _this._timestamp = "";
2276
+ _this._weighting = "";
2277
+ _this._learner_response = "";
2278
+ _this._result = "";
2279
+ _this._latency = "";
2280
+ _this._description = "";
2281
+ _this.objectives = new CMIArray({
2282
+ errorCode: error_codes.scorm2004.READ_ONLY_ELEMENT,
2283
+ errorClass: Scorm2004ValidationError,
2284
+ children: api_constants.scorm2004.objectives_children,
2285
+ });
2286
+ _this.correct_responses = new CMIArray({
2287
+ errorCode: error_codes.scorm2004.READ_ONLY_ELEMENT,
2288
+ errorClass: Scorm2004ValidationError,
2289
+ children: api_constants.scorm2004.correct_responses_children,
2290
+ });
2188
2291
  return _this;
2189
2292
  }
2190
- CMI.prototype.initialize = function () {
2191
- var _a, _b, _c, _d, _e, _f;
2293
+ CMIInteractionsObject.prototype.initialize = function () {
2294
+ var _a, _b;
2192
2295
  _super.prototype.initialize.call(this);
2193
- (_a = this.learner_preference) === null || _a === void 0 ? void 0 : _a.initialize();
2194
- (_b = this.score) === null || _b === void 0 ? void 0 : _b.initialize();
2195
- (_c = this.comments_from_learner) === null || _c === void 0 ? void 0 : _c.initialize();
2196
- (_d = this.comments_from_lms) === null || _d === void 0 ? void 0 : _d.initialize();
2197
- (_e = this.interactions) === null || _e === void 0 ? void 0 : _e.initialize();
2198
- (_f = this.objectives) === null || _f === void 0 ? void 0 : _f.initialize();
2296
+ (_a = this.objectives) === null || _a === void 0 ? void 0 : _a.initialize();
2297
+ (_b = this.correct_responses) === null || _b === void 0 ? void 0 : _b.initialize();
2199
2298
  };
2200
- Object.defineProperty(CMI.prototype, "_version", {
2201
- get: function () {
2202
- return this.__version;
2203
- },
2204
- set: function (_version) {
2205
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
2206
- },
2207
- enumerable: false,
2208
- configurable: true
2209
- });
2210
- Object.defineProperty(CMI.prototype, "_children", {
2211
- get: function () {
2212
- return this.__children;
2213
- },
2214
- set: function (_children) {
2215
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
2216
- },
2217
- enumerable: false,
2218
- configurable: true
2219
- });
2220
- Object.defineProperty(CMI.prototype, "completion_status", {
2221
- get: function () {
2222
- return this._completion_status;
2223
- },
2224
- set: function (completion_status) {
2225
- if (check2004ValidFormat(completion_status, scorm2004_cmi_scorm2004_regex.CMICStatus)) {
2226
- this._completion_status = completion_status;
2227
- }
2228
- },
2229
- enumerable: false,
2230
- configurable: true
2231
- });
2232
- Object.defineProperty(CMI.prototype, "completion_threshold", {
2233
- get: function () {
2234
- return this._completion_threshold;
2235
- },
2236
- set: function (completion_threshold) {
2237
- if (this.initialized) {
2238
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
2239
- }
2240
- else {
2241
- this._completion_threshold = completion_threshold;
2242
- }
2243
- },
2244
- enumerable: false,
2245
- configurable: true
2246
- });
2247
- Object.defineProperty(CMI.prototype, "credit", {
2248
- get: function () {
2249
- return this._credit;
2250
- },
2251
- set: function (credit) {
2252
- if (this.initialized) {
2253
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
2254
- }
2255
- else {
2256
- this._credit = credit;
2257
- }
2258
- },
2259
- enumerable: false,
2260
- configurable: true
2261
- });
2262
- Object.defineProperty(CMI.prototype, "entry", {
2263
- get: function () {
2264
- return this._entry;
2265
- },
2266
- set: function (entry) {
2267
- if (this.initialized) {
2268
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
2269
- }
2270
- else {
2271
- this._entry = entry;
2272
- }
2273
- },
2274
- enumerable: false,
2275
- configurable: true
2276
- });
2277
- Object.defineProperty(CMI.prototype, "exit", {
2278
- get: function () {
2279
- if (!this.jsonString) {
2280
- throw new Scorm2004ValidationError(scorm2004_error_codes.WRITE_ONLY_ELEMENT);
2281
- }
2282
- return this._exit;
2283
- },
2284
- set: function (exit) {
2285
- if (check2004ValidFormat(exit, scorm2004_cmi_scorm2004_regex.CMIExit, true)) {
2286
- this._exit = exit;
2287
- }
2288
- },
2289
- enumerable: false,
2290
- configurable: true
2291
- });
2292
- Object.defineProperty(CMI.prototype, "launch_data", {
2293
- get: function () {
2294
- return this._launch_data;
2295
- },
2296
- set: function (launch_data) {
2297
- if (this.initialized) {
2298
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
2299
- }
2300
- else {
2301
- this._launch_data = launch_data;
2302
- }
2303
- },
2304
- enumerable: false,
2305
- configurable: true
2306
- });
2307
- Object.defineProperty(CMI.prototype, "learner_id", {
2308
- get: function () {
2309
- return this._learner_id;
2310
- },
2311
- set: function (learner_id) {
2312
- if (this.initialized) {
2313
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
2314
- }
2315
- else {
2316
- this._learner_id = learner_id;
2317
- }
2318
- },
2319
- enumerable: false,
2320
- configurable: true
2321
- });
2322
- Object.defineProperty(CMI.prototype, "learner_name", {
2323
- get: function () {
2324
- return this._learner_name;
2325
- },
2326
- set: function (learner_name) {
2327
- if (this.initialized) {
2328
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
2329
- }
2330
- else {
2331
- this._learner_name = learner_name;
2332
- }
2333
- },
2334
- enumerable: false,
2335
- configurable: true
2336
- });
2337
- Object.defineProperty(CMI.prototype, "location", {
2299
+ Object.defineProperty(CMIInteractionsObject.prototype, "id", {
2338
2300
  get: function () {
2339
- return this._location;
2301
+ return this._id;
2340
2302
  },
2341
- set: function (location) {
2342
- if (check2004ValidFormat(location, scorm2004_cmi_scorm2004_regex.CMIString1000)) {
2343
- this._location = location;
2303
+ set: function (id) {
2304
+ if (check2004ValidFormat(id, regex.scorm2004.CMILongIdentifier)) {
2305
+ this._id = id;
2344
2306
  }
2345
2307
  },
2346
2308
  enumerable: false,
2347
2309
  configurable: true
2348
2310
  });
2349
- Object.defineProperty(CMI.prototype, "max_time_allowed", {
2311
+ Object.defineProperty(CMIInteractionsObject.prototype, "type", {
2350
2312
  get: function () {
2351
- return this._max_time_allowed;
2313
+ return this._type;
2352
2314
  },
2353
- set: function (max_time_allowed) {
2354
- if (this.initialized) {
2355
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
2315
+ set: function (type) {
2316
+ if (this.initialized && this._id === "") {
2317
+ throw new Scorm2004ValidationError(error_codes.scorm2004.DEPENDENCY_NOT_ESTABLISHED);
2356
2318
  }
2357
2319
  else {
2358
- this._max_time_allowed = max_time_allowed;
2320
+ if (check2004ValidFormat(type, regex.scorm2004.CMIType)) {
2321
+ this._type = type;
2322
+ }
2359
2323
  }
2360
2324
  },
2361
2325
  enumerable: false,
2362
2326
  configurable: true
2363
2327
  });
2364
- Object.defineProperty(CMI.prototype, "mode", {
2328
+ Object.defineProperty(CMIInteractionsObject.prototype, "timestamp", {
2365
2329
  get: function () {
2366
- return this._mode;
2330
+ return this._timestamp;
2367
2331
  },
2368
- set: function (mode) {
2369
- if (this.initialized) {
2370
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
2332
+ set: function (timestamp) {
2333
+ if (this.initialized && this._id === "") {
2334
+ throw new Scorm2004ValidationError(error_codes.scorm2004.DEPENDENCY_NOT_ESTABLISHED);
2371
2335
  }
2372
2336
  else {
2373
- this._mode = mode;
2337
+ if (check2004ValidFormat(timestamp, regex.scorm2004.CMITime)) {
2338
+ this._timestamp = timestamp;
2339
+ }
2374
2340
  }
2375
2341
  },
2376
2342
  enumerable: false,
2377
2343
  configurable: true
2378
2344
  });
2379
- Object.defineProperty(CMI.prototype, "progress_measure", {
2345
+ Object.defineProperty(CMIInteractionsObject.prototype, "weighting", {
2380
2346
  get: function () {
2381
- return this._progress_measure;
2347
+ return this._weighting;
2382
2348
  },
2383
- set: function (progress_measure) {
2384
- if (check2004ValidFormat(progress_measure, scorm2004_cmi_scorm2004_regex.CMIDecimal) &&
2385
- check2004ValidRange(progress_measure, scorm2004_cmi_scorm2004_regex.progress_range)) {
2386
- this._progress_measure = progress_measure;
2349
+ set: function (weighting) {
2350
+ if (this.initialized && this._id === "") {
2351
+ throw new Scorm2004ValidationError(error_codes.scorm2004.DEPENDENCY_NOT_ESTABLISHED);
2352
+ }
2353
+ else {
2354
+ if (check2004ValidFormat(weighting, regex.scorm2004.CMIDecimal)) {
2355
+ this._weighting = weighting;
2356
+ }
2387
2357
  }
2388
2358
  },
2389
2359
  enumerable: false,
2390
2360
  configurable: true
2391
2361
  });
2392
- Object.defineProperty(CMI.prototype, "scaled_passing_score", {
2362
+ Object.defineProperty(CMIInteractionsObject.prototype, "learner_response", {
2393
2363
  get: function () {
2394
- return this._scaled_passing_score;
2364
+ return this._learner_response;
2395
2365
  },
2396
- set: function (scaled_passing_score) {
2397
- if (this.initialized) {
2398
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
2366
+ set: function (learner_response) {
2367
+ if (this.initialized && (this._type === "" || this._id === "")) {
2368
+ throw new Scorm2004ValidationError(error_codes.scorm2004.DEPENDENCY_NOT_ESTABLISHED);
2399
2369
  }
2400
2370
  else {
2401
- this._scaled_passing_score = scaled_passing_score;
2371
+ var nodes = [];
2372
+ var response_type = LearnerResponses[this.type];
2373
+ if (response_type) {
2374
+ if (response_type === null || response_type === void 0 ? void 0 : response_type.delimiter) {
2375
+ nodes = learner_response.split(response_type.delimiter);
2376
+ }
2377
+ else {
2378
+ nodes[0] = learner_response;
2379
+ }
2380
+ if (nodes.length > 0 && nodes.length <= response_type.max) {
2381
+ var formatRegex = new RegExp(response_type.format);
2382
+ for (var i = 0; i < nodes.length; i++) {
2383
+ if (response_type === null || response_type === void 0 ? void 0 : response_type.delimiter2) {
2384
+ var values = nodes[i].split(response_type.delimiter2);
2385
+ if (values.length === 2) {
2386
+ if (!values[0].match(formatRegex)) {
2387
+ throw new Scorm2004ValidationError(error_codes.scorm2004.TYPE_MISMATCH);
2388
+ }
2389
+ else {
2390
+ if (!response_type.format2 ||
2391
+ !values[1].match(new RegExp(response_type.format2))) {
2392
+ throw new Scorm2004ValidationError(error_codes.scorm2004.TYPE_MISMATCH);
2393
+ }
2394
+ }
2395
+ }
2396
+ else {
2397
+ throw new Scorm2004ValidationError(error_codes.scorm2004.TYPE_MISMATCH);
2398
+ }
2399
+ }
2400
+ else {
2401
+ if (!nodes[i].match(formatRegex)) {
2402
+ throw new Scorm2004ValidationError(error_codes.scorm2004.TYPE_MISMATCH);
2403
+ }
2404
+ else {
2405
+ if (nodes[i] !== "" && response_type.unique) {
2406
+ for (var j = 0; j < i; j++) {
2407
+ if (nodes[i] === nodes[j]) {
2408
+ throw new Scorm2004ValidationError(error_codes.scorm2004.TYPE_MISMATCH);
2409
+ }
2410
+ }
2411
+ }
2412
+ }
2413
+ }
2414
+ }
2415
+ }
2416
+ else {
2417
+ throw new Scorm2004ValidationError(error_codes.scorm2004.GENERAL_SET_FAILURE);
2418
+ }
2419
+ this._learner_response = learner_response;
2420
+ }
2421
+ else {
2422
+ throw new Scorm2004ValidationError(error_codes.scorm2004.TYPE_MISMATCH);
2423
+ }
2402
2424
  }
2403
2425
  },
2404
2426
  enumerable: false,
2405
2427
  configurable: true
2406
2428
  });
2407
- Object.defineProperty(CMI.prototype, "session_time", {
2429
+ Object.defineProperty(CMIInteractionsObject.prototype, "result", {
2408
2430
  get: function () {
2409
- if (!this.jsonString) {
2410
- throw new Scorm2004ValidationError(scorm2004_error_codes.WRITE_ONLY_ELEMENT);
2411
- }
2412
- return this._session_time;
2431
+ return this._result;
2413
2432
  },
2414
- set: function (session_time) {
2415
- if (check2004ValidFormat(session_time, scorm2004_cmi_scorm2004_regex.CMITimespan)) {
2416
- this._session_time = session_time;
2433
+ set: function (result) {
2434
+ if (check2004ValidFormat(result, regex.scorm2004.CMIResult)) {
2435
+ this._result = result;
2417
2436
  }
2418
2437
  },
2419
2438
  enumerable: false,
2420
2439
  configurable: true
2421
2440
  });
2422
- Object.defineProperty(CMI.prototype, "success_status", {
2441
+ Object.defineProperty(CMIInteractionsObject.prototype, "latency", {
2423
2442
  get: function () {
2424
- return this._success_status;
2443
+ return this._latency;
2425
2444
  },
2426
- set: function (success_status) {
2427
- if (check2004ValidFormat(success_status, scorm2004_cmi_scorm2004_regex.CMISStatus)) {
2428
- this._success_status = success_status;
2445
+ set: function (latency) {
2446
+ if (this.initialized && this._id === "") {
2447
+ throw new Scorm2004ValidationError(error_codes.scorm2004.DEPENDENCY_NOT_ESTABLISHED);
2448
+ }
2449
+ else {
2450
+ if (check2004ValidFormat(latency, regex.scorm2004.CMITimespan)) {
2451
+ this._latency = latency;
2452
+ }
2429
2453
  }
2430
2454
  },
2431
2455
  enumerable: false,
2432
2456
  configurable: true
2433
2457
  });
2434
- Object.defineProperty(CMI.prototype, "suspend_data", {
2458
+ Object.defineProperty(CMIInteractionsObject.prototype, "description", {
2435
2459
  get: function () {
2436
- return this._suspend_data;
2460
+ return this._description;
2437
2461
  },
2438
- set: function (suspend_data) {
2439
- if (check2004ValidFormat(suspend_data, scorm2004_cmi_scorm2004_regex.CMIString64000, true)) {
2440
- this._suspend_data = suspend_data;
2462
+ set: function (description) {
2463
+ if (this.initialized && this._id === "") {
2464
+ throw new Scorm2004ValidationError(error_codes.scorm2004.DEPENDENCY_NOT_ESTABLISHED);
2465
+ }
2466
+ else {
2467
+ if (check2004ValidFormat(description, regex.scorm2004.CMILangString250, true)) {
2468
+ this._description = description;
2469
+ }
2441
2470
  }
2442
2471
  },
2443
2472
  enumerable: false,
2444
2473
  configurable: true
2445
2474
  });
2446
- Object.defineProperty(CMI.prototype, "time_limit_action", {
2475
+ CMIInteractionsObject.prototype.toJSON = function () {
2476
+ this.jsonString = true;
2477
+ var result = {
2478
+ id: this.id,
2479
+ type: this.type,
2480
+ objectives: this.objectives,
2481
+ timestamp: this.timestamp,
2482
+ weighting: this.weighting,
2483
+ learner_response: this.learner_response,
2484
+ result: this.result,
2485
+ latency: this.latency,
2486
+ description: this.description,
2487
+ correct_responses: this.correct_responses,
2488
+ };
2489
+ delete this.jsonString;
2490
+ return result;
2491
+ };
2492
+ return CMIInteractionsObject;
2493
+ }(BaseCMI));
2494
+
2495
+ var CMIInteractionsObjectivesObject = (function (_super) {
2496
+ __extends(CMIInteractionsObjectivesObject, _super);
2497
+ function CMIInteractionsObjectivesObject() {
2498
+ var _this = _super.call(this) || this;
2499
+ _this._id = "";
2500
+ return _this;
2501
+ }
2502
+ Object.defineProperty(CMIInteractionsObjectivesObject.prototype, "id", {
2447
2503
  get: function () {
2448
- return this._time_limit_action;
2504
+ return this._id;
2449
2505
  },
2450
- set: function (time_limit_action) {
2451
- if (this.initialized) {
2452
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
2453
- }
2454
- else {
2455
- this._time_limit_action = time_limit_action;
2506
+ set: function (id) {
2507
+ if (check2004ValidFormat(id, regex.scorm2004.CMILongIdentifier)) {
2508
+ this._id = id;
2456
2509
  }
2457
2510
  },
2458
2511
  enumerable: false,
2459
2512
  configurable: true
2460
2513
  });
2461
- Object.defineProperty(CMI.prototype, "total_time", {
2514
+ CMIInteractionsObjectivesObject.prototype.toJSON = function () {
2515
+ this.jsonString = true;
2516
+ var result = {
2517
+ id: this.id,
2518
+ };
2519
+ delete this.jsonString;
2520
+ return result;
2521
+ };
2522
+ return CMIInteractionsObjectivesObject;
2523
+ }(BaseCMI));
2524
+
2525
+ var CMIInteractionsCorrectResponsesObject = (function (_super) {
2526
+ __extends(CMIInteractionsCorrectResponsesObject, _super);
2527
+ function CMIInteractionsCorrectResponsesObject() {
2528
+ var _this = _super.call(this) || this;
2529
+ _this._pattern = "";
2530
+ return _this;
2531
+ }
2532
+ Object.defineProperty(CMIInteractionsCorrectResponsesObject.prototype, "pattern", {
2462
2533
  get: function () {
2463
- return this._total_time;
2534
+ return this._pattern;
2464
2535
  },
2465
- set: function (total_time) {
2466
- if (this.initialized) {
2467
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
2468
- }
2469
- else {
2470
- this._total_time = total_time;
2536
+ set: function (pattern) {
2537
+ if (check2004ValidFormat(pattern, regex.scorm2004.CMIFeedback)) {
2538
+ this._pattern = pattern;
2471
2539
  }
2472
2540
  },
2473
2541
  enumerable: false,
2474
2542
  configurable: true
2475
2543
  });
2476
- CMI.prototype.getCurrentTotalTime = function () {
2477
- var sessionTime = this._session_time;
2478
- var startTime = this.start_time;
2479
- if (typeof startTime !== "undefined" && startTime !== null) {
2480
- var seconds = new Date().getTime() - startTime;
2481
- sessionTime = getSecondsAsISODuration(seconds / 1000);
2482
- }
2483
- return addTwoDurations(this._total_time, sessionTime, scorm2004_cmi_scorm2004_regex.CMITimespan);
2484
- };
2485
- CMI.prototype.toJSON = function () {
2544
+ CMIInteractionsCorrectResponsesObject.prototype.toJSON = function () {
2486
2545
  this.jsonString = true;
2487
2546
  var result = {
2488
- comments_from_learner: this.comments_from_learner,
2489
- comments_from_lms: this.comments_from_lms,
2490
- completion_status: this.completion_status,
2491
- completion_threshold: this.completion_threshold,
2492
- credit: this.credit,
2493
- entry: this.entry,
2494
- exit: this.exit,
2495
- interactions: this.interactions,
2496
- launch_data: this.launch_data,
2497
- learner_id: this.learner_id,
2498
- learner_name: this.learner_name,
2499
- learner_preference: this.learner_preference,
2500
- location: this.location,
2501
- max_time_allowed: this.max_time_allowed,
2502
- mode: this.mode,
2503
- objectives: this.objectives,
2504
- progress_measure: this.progress_measure,
2505
- scaled_passing_score: this.scaled_passing_score,
2506
- score: this.score,
2507
- session_time: this.session_time,
2508
- success_status: this.success_status,
2509
- suspend_data: this.suspend_data,
2510
- time_limit_action: this.time_limit_action,
2547
+ pattern: this.pattern,
2511
2548
  };
2512
2549
  delete this.jsonString;
2513
2550
  return result;
2514
2551
  };
2515
- return CMI;
2516
- }(BaseRootCMI));
2552
+ return CMIInteractionsCorrectResponsesObject;
2553
+ }(BaseCMI));
2517
2554
 
2518
- var CMILearnerPreference = (function (_super) {
2519
- __extends(CMILearnerPreference, _super);
2520
- function CMILearnerPreference() {
2555
+
2556
+ ;// ./src/cmi/common/score.ts
2557
+
2558
+
2559
+
2560
+
2561
+
2562
+
2563
+ var scorm12_constants = api_constants.scorm12;
2564
+ var scorm12_regex = regex.scorm12;
2565
+ var score_scorm12_error_codes = error_codes.scorm12;
2566
+ var CMIScore = (function (_super) {
2567
+ __extends(CMIScore, _super);
2568
+ function CMIScore(params) {
2521
2569
  var _this = _super.call(this) || this;
2522
- _this.__children = scorm2004_constants.student_preference_children;
2523
- _this._audio_level = "1";
2524
- _this._language = "";
2525
- _this._delivery_speed = "1";
2526
- _this._audio_captioning = "0";
2570
+ _this._raw = "";
2571
+ _this._min = "";
2572
+ _this.__children = params.score_children || scorm12_constants.score_children;
2573
+ _this.__score_range = !params.score_range
2574
+ ? false
2575
+ : scorm12_regex.score_range;
2576
+ _this._max = params.max || params.max === "" ? params.max : "100";
2577
+ _this.__invalid_error_code =
2578
+ params.invalidErrorCode || score_scorm12_error_codes.INVALID_SET_VALUE;
2579
+ _this.__invalid_type_code =
2580
+ params.invalidTypeCode || score_scorm12_error_codes.TYPE_MISMATCH;
2581
+ _this.__invalid_range_code =
2582
+ params.invalidRangeCode || score_scorm12_error_codes.VALUE_OUT_OF_RANGE;
2583
+ _this.__decimal_regex = params.decimalRegex || scorm12_regex.CMIDecimal;
2584
+ _this.__error_class = params.errorClass;
2527
2585
  return _this;
2528
2586
  }
2529
- Object.defineProperty(CMILearnerPreference.prototype, "_children", {
2587
+ Object.defineProperty(CMIScore.prototype, "_children", {
2530
2588
  get: function () {
2531
2589
  return this.__children;
2532
2590
  },
2533
2591
  set: function (_children) {
2534
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
2592
+ throw new this.__error_class(this.__invalid_error_code);
2535
2593
  },
2536
2594
  enumerable: false,
2537
2595
  configurable: true
2538
2596
  });
2539
- Object.defineProperty(CMILearnerPreference.prototype, "audio_level", {
2597
+ Object.defineProperty(CMIScore.prototype, "raw", {
2540
2598
  get: function () {
2541
- return this._audio_level;
2599
+ return this._raw;
2542
2600
  },
2543
- set: function (audio_level) {
2544
- if (check2004ValidFormat(audio_level, scorm2004_cmi_scorm2004_regex.CMIDecimal) &&
2545
- check2004ValidRange(audio_level, scorm2004_cmi_scorm2004_regex.audio_range)) {
2546
- this._audio_level = audio_level;
2601
+ set: function (raw) {
2602
+ if (checkValidFormat(raw, this.__decimal_regex, this.__invalid_type_code, this.__error_class) &&
2603
+ (!this.__score_range ||
2604
+ checkValidRange(raw, this.__score_range, this.__invalid_range_code, this.__error_class))) {
2605
+ this._raw = raw;
2547
2606
  }
2548
2607
  },
2549
2608
  enumerable: false,
2550
2609
  configurable: true
2551
2610
  });
2552
- Object.defineProperty(CMILearnerPreference.prototype, "language", {
2611
+ Object.defineProperty(CMIScore.prototype, "min", {
2553
2612
  get: function () {
2554
- return this._language;
2613
+ return this._min;
2555
2614
  },
2556
- set: function (language) {
2557
- if (check2004ValidFormat(language, scorm2004_cmi_scorm2004_regex.CMILang)) {
2558
- this._language = language;
2615
+ set: function (min) {
2616
+ if (checkValidFormat(min, this.__decimal_regex, this.__invalid_type_code, this.__error_class) &&
2617
+ (!this.__score_range ||
2618
+ checkValidRange(min, this.__score_range, this.__invalid_range_code, this.__error_class))) {
2619
+ this._min = min;
2559
2620
  }
2560
2621
  },
2561
2622
  enumerable: false,
2562
2623
  configurable: true
2563
2624
  });
2564
- Object.defineProperty(CMILearnerPreference.prototype, "delivery_speed", {
2625
+ Object.defineProperty(CMIScore.prototype, "max", {
2565
2626
  get: function () {
2566
- return this._delivery_speed;
2627
+ return this._max;
2567
2628
  },
2568
- set: function (delivery_speed) {
2569
- if (check2004ValidFormat(delivery_speed, scorm2004_cmi_scorm2004_regex.CMIDecimal) &&
2570
- check2004ValidRange(delivery_speed, scorm2004_cmi_scorm2004_regex.speed_range)) {
2571
- this._delivery_speed = delivery_speed;
2629
+ set: function (max) {
2630
+ if (checkValidFormat(max, this.__decimal_regex, this.__invalid_type_code, this.__error_class) &&
2631
+ (!this.__score_range ||
2632
+ checkValidRange(max, this.__score_range, this.__invalid_range_code, this.__error_class))) {
2633
+ this._max = max;
2572
2634
  }
2573
2635
  },
2574
2636
  enumerable: false,
2575
2637
  configurable: true
2576
2638
  });
2577
- Object.defineProperty(CMILearnerPreference.prototype, "audio_captioning", {
2639
+ CMIScore.prototype.toJSON = function () {
2640
+ this.jsonString = true;
2641
+ var result = {
2642
+ raw: this.raw,
2643
+ min: this.min,
2644
+ max: this.max,
2645
+ };
2646
+ delete this.jsonString;
2647
+ return result;
2648
+ };
2649
+ return CMIScore;
2650
+ }(BaseCMI));
2651
+
2652
+
2653
+ ;// ./src/cmi/scorm2004/score.ts
2654
+
2655
+
2656
+
2657
+
2658
+
2659
+
2660
+
2661
+ var Scorm2004CMIScore = (function (_super) {
2662
+ __extends(Scorm2004CMIScore, _super);
2663
+ function Scorm2004CMIScore() {
2664
+ var _this = _super.call(this, {
2665
+ score_children: api_constants.scorm2004.score_children,
2666
+ max: "",
2667
+ invalidErrorCode: error_codes.scorm2004.READ_ONLY_ELEMENT,
2668
+ invalidTypeCode: error_codes.scorm2004.TYPE_MISMATCH,
2669
+ invalidRangeCode: error_codes.scorm2004.VALUE_OUT_OF_RANGE,
2670
+ decimalRegex: regex.scorm2004.CMIDecimal,
2671
+ errorClass: Scorm2004ValidationError,
2672
+ }) || this;
2673
+ _this._scaled = "";
2674
+ return _this;
2675
+ }
2676
+ Object.defineProperty(Scorm2004CMIScore.prototype, "scaled", {
2578
2677
  get: function () {
2579
- return this._audio_captioning;
2678
+ return this._scaled;
2580
2679
  },
2581
- set: function (audio_captioning) {
2582
- if (check2004ValidFormat(audio_captioning, scorm2004_cmi_scorm2004_regex.CMISInteger) &&
2583
- check2004ValidRange(audio_captioning, scorm2004_cmi_scorm2004_regex.text_range)) {
2584
- this._audio_captioning = audio_captioning;
2680
+ set: function (scaled) {
2681
+ if (check2004ValidFormat(scaled, regex.scorm2004.CMIDecimal) &&
2682
+ check2004ValidRange(scaled, regex.scorm2004.scaled_range)) {
2683
+ this._scaled = scaled;
2585
2684
  }
2586
2685
  },
2587
2686
  enumerable: false,
2588
2687
  configurable: true
2589
2688
  });
2590
- CMILearnerPreference.prototype.toJSON = function () {
2689
+ Scorm2004CMIScore.prototype.toJSON = function () {
2591
2690
  this.jsonString = true;
2592
2691
  var result = {
2593
- audio_level: this.audio_level,
2594
- language: this.language,
2595
- delivery_speed: this.delivery_speed,
2596
- audio_captioning: this.audio_captioning,
2692
+ scaled: this.scaled,
2693
+ raw: this.raw,
2694
+ min: this.min,
2695
+ max: this.max,
2597
2696
  };
2598
2697
  delete this.jsonString;
2599
2698
  return result;
2600
2699
  };
2601
- return CMILearnerPreference;
2602
- }(BaseCMI));
2603
- var CMIInteractions = (function (_super) {
2604
- __extends(CMIInteractions, _super);
2605
- function CMIInteractions() {
2606
- return _super.call(this, {
2607
- children: scorm2004_constants.interactions_children,
2608
- errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
2609
- errorClass: Scorm2004ValidationError,
2610
- }) || this;
2611
- }
2612
- return CMIInteractions;
2613
- }(CMIArray));
2614
- var CMIObjectives = (function (_super) {
2615
- __extends(CMIObjectives, _super);
2616
- function CMIObjectives() {
2617
- return _super.call(this, {
2618
- children: scorm2004_constants.objectives_children,
2619
- errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
2620
- errorClass: Scorm2004ValidationError,
2621
- }) || this;
2622
- }
2623
- return CMIObjectives;
2624
- }(CMIArray));
2700
+ return Scorm2004CMIScore;
2701
+ }(CMIScore));
2702
+
2703
+
2704
+ ;// ./src/cmi/scorm2004/comments.ts
2705
+
2706
+
2707
+
2708
+
2709
+
2710
+
2711
+
2712
+
2625
2713
  var CMICommentsFromLMS = (function (_super) {
2626
2714
  __extends(CMICommentsFromLMS, _super);
2627
2715
  function CMICommentsFromLMS() {
2628
2716
  return _super.call(this, {
2629
- children: scorm2004_constants.comments_children,
2630
- errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
2717
+ children: api_constants.scorm2004.comments_children,
2718
+ errorCode: error_codes.scorm2004.READ_ONLY_ELEMENT,
2631
2719
  errorClass: Scorm2004ValidationError,
2632
2720
  }) || this;
2633
2721
  }
2634
2722
  return CMICommentsFromLMS;
2635
2723
  }(CMIArray));
2724
+
2636
2725
  var CMICommentsFromLearner = (function (_super) {
2637
2726
  __extends(CMICommentsFromLearner, _super);
2638
2727
  function CMICommentsFromLearner() {
2639
2728
  return _super.call(this, {
2640
- children: scorm2004_constants.comments_children,
2641
- errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
2729
+ children: api_constants.scorm2004.comments_children,
2730
+ errorCode: error_codes.scorm2004.READ_ONLY_ELEMENT,
2642
2731
  errorClass: Scorm2004ValidationError,
2643
2732
  }) || this;
2644
2733
  }
2645
2734
  return CMICommentsFromLearner;
2646
2735
  }(CMIArray));
2647
- var CMIInteractionsObject = (function (_super) {
2648
- __extends(CMIInteractionsObject, _super);
2649
- function CMIInteractionsObject() {
2736
+
2737
+ var CMICommentsObject = (function (_super) {
2738
+ __extends(CMICommentsObject, _super);
2739
+ function CMICommentsObject(readOnlyAfterInit) {
2740
+ if (readOnlyAfterInit === void 0) { readOnlyAfterInit = false; }
2650
2741
  var _this = _super.call(this) || this;
2651
- _this._id = "";
2652
- _this._type = "";
2742
+ _this._comment = "";
2743
+ _this._location = "";
2653
2744
  _this._timestamp = "";
2654
- _this._weighting = "";
2655
- _this._learner_response = "";
2656
- _this._result = "";
2657
- _this._latency = "";
2658
- _this._description = "";
2659
- _this.objectives = new CMIArray({
2660
- errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
2661
- errorClass: Scorm2004ValidationError,
2662
- children: scorm2004_constants.objectives_children,
2663
- });
2664
- _this.correct_responses = new CMIArray({
2665
- errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
2666
- errorClass: Scorm2004ValidationError,
2667
- children: scorm2004_constants.correct_responses_children,
2668
- });
2745
+ _this._comment = "";
2746
+ _this._location = "";
2747
+ _this._timestamp = "";
2748
+ _this._readOnlyAfterInit = readOnlyAfterInit;
2669
2749
  return _this;
2670
- }
2671
- CMIInteractionsObject.prototype.initialize = function () {
2672
- var _a, _b;
2673
- _super.prototype.initialize.call(this);
2674
- (_a = this.objectives) === null || _a === void 0 ? void 0 : _a.initialize();
2675
- (_b = this.correct_responses) === null || _b === void 0 ? void 0 : _b.initialize();
2676
- };
2677
- Object.defineProperty(CMIInteractionsObject.prototype, "id", {
2678
- get: function () {
2679
- return this._id;
2680
- },
2681
- set: function (id) {
2682
- if (check2004ValidFormat(id, scorm2004_cmi_scorm2004_regex.CMILongIdentifier)) {
2683
- this._id = id;
2684
- }
2685
- },
2686
- enumerable: false,
2687
- configurable: true
2688
- });
2689
- Object.defineProperty(CMIInteractionsObject.prototype, "type", {
2690
- get: function () {
2691
- return this._type;
2692
- },
2693
- set: function (type) {
2694
- if (this.initialized && this._id === "") {
2695
- throw new Scorm2004ValidationError(scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED);
2696
- }
2697
- else {
2698
- if (check2004ValidFormat(type, scorm2004_cmi_scorm2004_regex.CMIType)) {
2699
- this._type = type;
2700
- }
2701
- }
2702
- },
2703
- enumerable: false,
2704
- configurable: true
2705
- });
2706
- Object.defineProperty(CMIInteractionsObject.prototype, "timestamp", {
2707
- get: function () {
2708
- return this._timestamp;
2709
- },
2710
- set: function (timestamp) {
2711
- if (this.initialized && this._id === "") {
2712
- throw new Scorm2004ValidationError(scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED);
2713
- }
2714
- else {
2715
- if (check2004ValidFormat(timestamp, scorm2004_cmi_scorm2004_regex.CMITime)) {
2716
- this._timestamp = timestamp;
2717
- }
2718
- }
2719
- },
2720
- enumerable: false,
2721
- configurable: true
2722
- });
2723
- Object.defineProperty(CMIInteractionsObject.prototype, "weighting", {
2724
- get: function () {
2725
- return this._weighting;
2726
- },
2727
- set: function (weighting) {
2728
- if (this.initialized && this._id === "") {
2729
- throw new Scorm2004ValidationError(scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED);
2730
- }
2731
- else {
2732
- if (check2004ValidFormat(weighting, scorm2004_cmi_scorm2004_regex.CMIDecimal)) {
2733
- this._weighting = weighting;
2734
- }
2735
- }
2736
- },
2737
- enumerable: false,
2738
- configurable: true
2739
- });
2740
- Object.defineProperty(CMIInteractionsObject.prototype, "learner_response", {
2741
- get: function () {
2742
- return this._learner_response;
2743
- },
2744
- set: function (learner_response) {
2745
- if (this.initialized && (this._type === "" || this._id === "")) {
2746
- throw new Scorm2004ValidationError(scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED);
2747
- }
2748
- else {
2749
- var nodes = [];
2750
- var response_type = learner_responses[this.type];
2751
- if (response_type) {
2752
- if (response_type === null || response_type === void 0 ? void 0 : response_type.delimiter) {
2753
- nodes = learner_response.split(response_type.delimiter);
2754
- }
2755
- else {
2756
- nodes[0] = learner_response;
2757
- }
2758
- if (nodes.length > 0 && nodes.length <= response_type.max) {
2759
- var formatRegex = new RegExp(response_type.format);
2760
- for (var i = 0; i < nodes.length; i++) {
2761
- if (response_type === null || response_type === void 0 ? void 0 : response_type.delimiter2) {
2762
- var values = nodes[i].split(response_type.delimiter2);
2763
- if (values.length === 2) {
2764
- if (!values[0].match(formatRegex)) {
2765
- throw new Scorm2004ValidationError(scorm2004_error_codes.TYPE_MISMATCH);
2766
- }
2767
- else {
2768
- if (!response_type.format2 ||
2769
- !values[1].match(new RegExp(response_type.format2))) {
2770
- throw new Scorm2004ValidationError(scorm2004_error_codes.TYPE_MISMATCH);
2771
- }
2772
- }
2773
- }
2774
- else {
2775
- throw new Scorm2004ValidationError(scorm2004_error_codes.TYPE_MISMATCH);
2776
- }
2777
- }
2778
- else {
2779
- if (!nodes[i].match(formatRegex)) {
2780
- throw new Scorm2004ValidationError(scorm2004_error_codes.TYPE_MISMATCH);
2781
- }
2782
- else {
2783
- if (nodes[i] !== "" && response_type.unique) {
2784
- for (var j = 0; j < i; j++) {
2785
- if (nodes[i] === nodes[j]) {
2786
- throw new Scorm2004ValidationError(scorm2004_error_codes.TYPE_MISMATCH);
2787
- }
2788
- }
2789
- }
2790
- }
2791
- }
2792
- }
2793
- }
2794
- else {
2795
- throw new Scorm2004ValidationError(scorm2004_error_codes.GENERAL_SET_FAILURE);
2796
- }
2797
- this._learner_response = learner_response;
2798
- }
2799
- else {
2800
- throw new Scorm2004ValidationError(scorm2004_error_codes.TYPE_MISMATCH);
2801
- }
2802
- }
2803
- },
2804
- enumerable: false,
2805
- configurable: true
2806
- });
2807
- Object.defineProperty(CMIInteractionsObject.prototype, "result", {
2750
+ }
2751
+ Object.defineProperty(CMICommentsObject.prototype, "comment", {
2808
2752
  get: function () {
2809
- return this._result;
2753
+ return this._comment;
2810
2754
  },
2811
- set: function (result) {
2812
- if (check2004ValidFormat(result, scorm2004_cmi_scorm2004_regex.CMIResult)) {
2813
- this._result = result;
2755
+ set: function (comment) {
2756
+ if (this.initialized && this._readOnlyAfterInit) {
2757
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
2758
+ }
2759
+ else {
2760
+ if (check2004ValidFormat(comment, regex.scorm2004.CMILangString4000, true)) {
2761
+ this._comment = comment;
2762
+ }
2814
2763
  }
2815
2764
  },
2816
2765
  enumerable: false,
2817
2766
  configurable: true
2818
2767
  });
2819
- Object.defineProperty(CMIInteractionsObject.prototype, "latency", {
2768
+ Object.defineProperty(CMICommentsObject.prototype, "location", {
2820
2769
  get: function () {
2821
- return this._latency;
2770
+ return this._location;
2822
2771
  },
2823
- set: function (latency) {
2824
- if (this.initialized && this._id === "") {
2825
- throw new Scorm2004ValidationError(scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED);
2772
+ set: function (location) {
2773
+ if (this.initialized && this._readOnlyAfterInit) {
2774
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
2826
2775
  }
2827
2776
  else {
2828
- if (check2004ValidFormat(latency, scorm2004_cmi_scorm2004_regex.CMITimespan)) {
2829
- this._latency = latency;
2777
+ if (check2004ValidFormat(location, regex.scorm2004.CMIString250)) {
2778
+ this._location = location;
2830
2779
  }
2831
2780
  }
2832
2781
  },
2833
2782
  enumerable: false,
2834
2783
  configurable: true
2835
2784
  });
2836
- Object.defineProperty(CMIInteractionsObject.prototype, "description", {
2785
+ Object.defineProperty(CMICommentsObject.prototype, "timestamp", {
2837
2786
  get: function () {
2838
- return this._description;
2787
+ return this._timestamp;
2839
2788
  },
2840
- set: function (description) {
2841
- if (this.initialized && this._id === "") {
2842
- throw new Scorm2004ValidationError(scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED);
2789
+ set: function (timestamp) {
2790
+ if (this.initialized && this._readOnlyAfterInit) {
2791
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
2843
2792
  }
2844
2793
  else {
2845
- if (check2004ValidFormat(description, scorm2004_cmi_scorm2004_regex.CMILangString250, true)) {
2846
- this._description = description;
2794
+ if (check2004ValidFormat(timestamp, regex.scorm2004.CMITime)) {
2795
+ this._timestamp = timestamp;
2847
2796
  }
2848
2797
  }
2849
2798
  },
2850
2799
  enumerable: false,
2851
2800
  configurable: true
2852
2801
  });
2853
- CMIInteractionsObject.prototype.toJSON = function () {
2802
+ CMICommentsObject.prototype.toJSON = function () {
2854
2803
  this.jsonString = true;
2855
2804
  var result = {
2856
- id: this.id,
2857
- type: this.type,
2858
- objectives: this.objectives,
2805
+ comment: this.comment,
2806
+ location: this.location,
2859
2807
  timestamp: this.timestamp,
2860
- weighting: this.weighting,
2861
- learner_response: this.learner_response,
2862
- result: this.result,
2863
- latency: this.latency,
2864
- description: this.description,
2865
- correct_responses: this.correct_responses,
2866
2808
  };
2867
2809
  delete this.jsonString;
2868
2810
  return result;
2869
2811
  };
2870
- return CMIInteractionsObject;
2812
+ return CMICommentsObject;
2871
2813
  }(BaseCMI));
2872
2814
 
2815
+
2816
+ ;// ./src/cmi/scorm2004/objectives.ts
2817
+
2818
+
2819
+
2820
+
2821
+
2822
+
2823
+
2824
+
2825
+
2826
+ var CMIObjectives = (function (_super) {
2827
+ __extends(CMIObjectives, _super);
2828
+ function CMIObjectives() {
2829
+ return _super.call(this, {
2830
+ children: api_constants.scorm2004.objectives_children,
2831
+ errorCode: error_codes.scorm2004.READ_ONLY_ELEMENT,
2832
+ errorClass: Scorm2004ValidationError,
2833
+ }) || this;
2834
+ }
2835
+ return CMIObjectives;
2836
+ }(CMIArray));
2837
+
2873
2838
  var CMIObjectivesObject = (function (_super) {
2874
2839
  __extends(CMIObjectivesObject, _super);
2875
2840
  function CMIObjectivesObject() {
@@ -2892,7 +2857,7 @@ var CMIObjectivesObject = (function (_super) {
2892
2857
  return this._id;
2893
2858
  },
2894
2859
  set: function (id) {
2895
- if (check2004ValidFormat(id, scorm2004_cmi_scorm2004_regex.CMILongIdentifier)) {
2860
+ if (check2004ValidFormat(id, regex.scorm2004.CMILongIdentifier)) {
2896
2861
  this._id = id;
2897
2862
  }
2898
2863
  },
@@ -2905,10 +2870,10 @@ var CMIObjectivesObject = (function (_super) {
2905
2870
  },
2906
2871
  set: function (success_status) {
2907
2872
  if (this.initialized && this._id === "") {
2908
- throw new Scorm2004ValidationError(scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED);
2873
+ throw new Scorm2004ValidationError(error_codes.scorm2004.DEPENDENCY_NOT_ESTABLISHED);
2909
2874
  }
2910
2875
  else {
2911
- if (check2004ValidFormat(success_status, scorm2004_cmi_scorm2004_regex.CMISStatus)) {
2876
+ if (check2004ValidFormat(success_status, regex.scorm2004.CMISStatus)) {
2912
2877
  this._success_status = success_status;
2913
2878
  }
2914
2879
  }
@@ -2922,10 +2887,10 @@ var CMIObjectivesObject = (function (_super) {
2922
2887
  },
2923
2888
  set: function (completion_status) {
2924
2889
  if (this.initialized && this._id === "") {
2925
- throw new Scorm2004ValidationError(scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED);
2890
+ throw new Scorm2004ValidationError(error_codes.scorm2004.DEPENDENCY_NOT_ESTABLISHED);
2926
2891
  }
2927
2892
  else {
2928
- if (check2004ValidFormat(completion_status, scorm2004_cmi_scorm2004_regex.CMICStatus)) {
2893
+ if (check2004ValidFormat(completion_status, regex.scorm2004.CMICStatus)) {
2929
2894
  this._completion_status = completion_status;
2930
2895
  }
2931
2896
  }
@@ -2939,11 +2904,11 @@ var CMIObjectivesObject = (function (_super) {
2939
2904
  },
2940
2905
  set: function (progress_measure) {
2941
2906
  if (this.initialized && this._id === "") {
2942
- throw new Scorm2004ValidationError(scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED);
2907
+ throw new Scorm2004ValidationError(error_codes.scorm2004.DEPENDENCY_NOT_ESTABLISHED);
2943
2908
  }
2944
2909
  else {
2945
- if (check2004ValidFormat(progress_measure, scorm2004_cmi_scorm2004_regex.CMIDecimal) &&
2946
- check2004ValidRange(progress_measure, scorm2004_cmi_scorm2004_regex.progress_range)) {
2910
+ if (check2004ValidFormat(progress_measure, regex.scorm2004.CMIDecimal) &&
2911
+ check2004ValidRange(progress_measure, regex.scorm2004.progress_range)) {
2947
2912
  this._progress_measure = progress_measure;
2948
2913
  }
2949
2914
  }
@@ -2957,10 +2922,10 @@ var CMIObjectivesObject = (function (_super) {
2957
2922
  },
2958
2923
  set: function (description) {
2959
2924
  if (this.initialized && this._id === "") {
2960
- throw new Scorm2004ValidationError(scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED);
2925
+ throw new Scorm2004ValidationError(error_codes.scorm2004.DEPENDENCY_NOT_ESTABLISHED);
2961
2926
  }
2962
2927
  else {
2963
- if (check2004ValidFormat(description, scorm2004_cmi_scorm2004_regex.CMILangString250, true)) {
2928
+ if (check2004ValidFormat(description, regex.scorm2004.CMILangString250, true)) {
2964
2929
  this._description = description;
2965
2930
  }
2966
2931
  }
@@ -2984,294 +2949,384 @@ var CMIObjectivesObject = (function (_super) {
2984
2949
  return CMIObjectivesObject;
2985
2950
  }(BaseCMI));
2986
2951
 
2987
- var Scorm2004CMIScore = (function (_super) {
2988
- __extends(Scorm2004CMIScore, _super);
2989
- function Scorm2004CMIScore() {
2990
- var _this = _super.call(this, {
2991
- score_children: scorm2004_constants.score_children,
2992
- max: "",
2993
- invalidErrorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
2994
- invalidTypeCode: scorm2004_error_codes.TYPE_MISMATCH,
2995
- invalidRangeCode: scorm2004_error_codes.VALUE_OUT_OF_RANGE,
2996
- decimalRegex: scorm2004_cmi_scorm2004_regex.CMIDecimal,
2997
- errorClass: Scorm2004ValidationError,
2998
- }) || this;
2999
- _this._scaled = "";
2952
+
2953
+ ;// ./src/cmi/scorm2004/cmi.ts
2954
+
2955
+
2956
+
2957
+
2958
+
2959
+
2960
+
2961
+
2962
+
2963
+
2964
+
2965
+
2966
+
2967
+ var CMI = (function (_super) {
2968
+ __extends(CMI, _super);
2969
+ function CMI(initialized) {
2970
+ if (initialized === void 0) { initialized = false; }
2971
+ var _this = _super.call(this) || this;
2972
+ _this.__version = "1.0";
2973
+ _this.__children = api_constants.scorm2004.cmi_children;
2974
+ _this._completion_status = "unknown";
2975
+ _this._completion_threshold = "";
2976
+ _this._credit = "credit";
2977
+ _this._entry = "";
2978
+ _this._exit = "";
2979
+ _this._launch_data = "";
2980
+ _this._learner_id = "";
2981
+ _this._learner_name = "";
2982
+ _this._location = "";
2983
+ _this._max_time_allowed = "";
2984
+ _this._mode = "normal";
2985
+ _this._progress_measure = "";
2986
+ _this._scaled_passing_score = "";
2987
+ _this._session_time = "PT0H0M0S";
2988
+ _this._success_status = "unknown";
2989
+ _this._suspend_data = "";
2990
+ _this._time_limit_action = "continue,no message";
2991
+ _this._total_time = "";
2992
+ _this.learner_preference = new CMILearnerPreference();
2993
+ _this.score = new Scorm2004CMIScore();
2994
+ _this.comments_from_learner = new CMICommentsFromLearner();
2995
+ _this.comments_from_lms = new CMICommentsFromLMS();
2996
+ _this.interactions = new CMIInteractions();
2997
+ _this.objectives = new CMIObjectives();
2998
+ if (initialized)
2999
+ _this.initialize();
3000
3000
  return _this;
3001
3001
  }
3002
- Object.defineProperty(Scorm2004CMIScore.prototype, "scaled", {
3002
+ CMI.prototype.initialize = function () {
3003
+ var _a, _b, _c, _d, _e, _f;
3004
+ _super.prototype.initialize.call(this);
3005
+ (_a = this.learner_preference) === null || _a === void 0 ? void 0 : _a.initialize();
3006
+ (_b = this.score) === null || _b === void 0 ? void 0 : _b.initialize();
3007
+ (_c = this.comments_from_learner) === null || _c === void 0 ? void 0 : _c.initialize();
3008
+ (_d = this.comments_from_lms) === null || _d === void 0 ? void 0 : _d.initialize();
3009
+ (_e = this.interactions) === null || _e === void 0 ? void 0 : _e.initialize();
3010
+ (_f = this.objectives) === null || _f === void 0 ? void 0 : _f.initialize();
3011
+ };
3012
+ Object.defineProperty(CMI.prototype, "_version", {
3013
+ get: function () {
3014
+ return this.__version;
3015
+ },
3016
+ set: function (_version) {
3017
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3018
+ },
3019
+ enumerable: false,
3020
+ configurable: true
3021
+ });
3022
+ Object.defineProperty(CMI.prototype, "_children", {
3023
+ get: function () {
3024
+ return this.__children;
3025
+ },
3026
+ set: function (_children) {
3027
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3028
+ },
3029
+ enumerable: false,
3030
+ configurable: true
3031
+ });
3032
+ Object.defineProperty(CMI.prototype, "completion_status", {
3033
+ get: function () {
3034
+ return this._completion_status;
3035
+ },
3036
+ set: function (completion_status) {
3037
+ if (check2004ValidFormat(completion_status, regex.scorm2004.CMICStatus)) {
3038
+ this._completion_status = completion_status;
3039
+ }
3040
+ },
3041
+ enumerable: false,
3042
+ configurable: true
3043
+ });
3044
+ Object.defineProperty(CMI.prototype, "completion_threshold", {
3045
+ get: function () {
3046
+ return this._completion_threshold;
3047
+ },
3048
+ set: function (completion_threshold) {
3049
+ if (this.initialized) {
3050
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3051
+ }
3052
+ else {
3053
+ this._completion_threshold = completion_threshold;
3054
+ }
3055
+ },
3056
+ enumerable: false,
3057
+ configurable: true
3058
+ });
3059
+ Object.defineProperty(CMI.prototype, "credit", {
3060
+ get: function () {
3061
+ return this._credit;
3062
+ },
3063
+ set: function (credit) {
3064
+ if (this.initialized) {
3065
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3066
+ }
3067
+ else {
3068
+ this._credit = credit;
3069
+ }
3070
+ },
3071
+ enumerable: false,
3072
+ configurable: true
3073
+ });
3074
+ Object.defineProperty(CMI.prototype, "entry", {
3075
+ get: function () {
3076
+ return this._entry;
3077
+ },
3078
+ set: function (entry) {
3079
+ if (this.initialized) {
3080
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3081
+ }
3082
+ else {
3083
+ this._entry = entry;
3084
+ }
3085
+ },
3086
+ enumerable: false,
3087
+ configurable: true
3088
+ });
3089
+ Object.defineProperty(CMI.prototype, "exit", {
3090
+ get: function () {
3091
+ if (!this.jsonString) {
3092
+ throw new Scorm2004ValidationError(error_codes.scorm2004.WRITE_ONLY_ELEMENT);
3093
+ }
3094
+ return this._exit;
3095
+ },
3096
+ set: function (exit) {
3097
+ if (check2004ValidFormat(exit, regex.scorm2004.CMIExit, true)) {
3098
+ this._exit = exit;
3099
+ }
3100
+ },
3101
+ enumerable: false,
3102
+ configurable: true
3103
+ });
3104
+ Object.defineProperty(CMI.prototype, "launch_data", {
3105
+ get: function () {
3106
+ return this._launch_data;
3107
+ },
3108
+ set: function (launch_data) {
3109
+ if (this.initialized) {
3110
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3111
+ }
3112
+ else {
3113
+ this._launch_data = launch_data;
3114
+ }
3115
+ },
3116
+ enumerable: false,
3117
+ configurable: true
3118
+ });
3119
+ Object.defineProperty(CMI.prototype, "learner_id", {
3120
+ get: function () {
3121
+ return this._learner_id;
3122
+ },
3123
+ set: function (learner_id) {
3124
+ if (this.initialized) {
3125
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3126
+ }
3127
+ else {
3128
+ this._learner_id = learner_id;
3129
+ }
3130
+ },
3131
+ enumerable: false,
3132
+ configurable: true
3133
+ });
3134
+ Object.defineProperty(CMI.prototype, "learner_name", {
3135
+ get: function () {
3136
+ return this._learner_name;
3137
+ },
3138
+ set: function (learner_name) {
3139
+ if (this.initialized) {
3140
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3141
+ }
3142
+ else {
3143
+ this._learner_name = learner_name;
3144
+ }
3145
+ },
3146
+ enumerable: false,
3147
+ configurable: true
3148
+ });
3149
+ Object.defineProperty(CMI.prototype, "location", {
3003
3150
  get: function () {
3004
- return this._scaled;
3151
+ return this._location;
3005
3152
  },
3006
- set: function (scaled) {
3007
- if (check2004ValidFormat(scaled, scorm2004_cmi_scorm2004_regex.CMIDecimal) &&
3008
- check2004ValidRange(scaled, scorm2004_cmi_scorm2004_regex.scaled_range)) {
3009
- this._scaled = scaled;
3153
+ set: function (location) {
3154
+ if (check2004ValidFormat(location, regex.scorm2004.CMIString1000)) {
3155
+ this._location = location;
3010
3156
  }
3011
3157
  },
3012
3158
  enumerable: false,
3013
3159
  configurable: true
3014
3160
  });
3015
- Scorm2004CMIScore.prototype.toJSON = function () {
3016
- this.jsonString = true;
3017
- var result = {
3018
- scaled: this.scaled,
3019
- raw: this.raw,
3020
- min: this.min,
3021
- max: this.max,
3022
- };
3023
- delete this.jsonString;
3024
- return result;
3025
- };
3026
- return Scorm2004CMIScore;
3027
- }(CMIScore));
3028
- var CMICommentsObject = (function (_super) {
3029
- __extends(CMICommentsObject, _super);
3030
- function CMICommentsObject(readOnlyAfterInit) {
3031
- if (readOnlyAfterInit === void 0) { readOnlyAfterInit = false; }
3032
- var _this = _super.call(this) || this;
3033
- _this._comment = "";
3034
- _this._location = "";
3035
- _this._timestamp = "";
3036
- _this._comment = "";
3037
- _this._location = "";
3038
- _this._timestamp = "";
3039
- _this._readOnlyAfterInit = readOnlyAfterInit;
3040
- return _this;
3041
- }
3042
- Object.defineProperty(CMICommentsObject.prototype, "comment", {
3161
+ Object.defineProperty(CMI.prototype, "max_time_allowed", {
3043
3162
  get: function () {
3044
- return this._comment;
3163
+ return this._max_time_allowed;
3045
3164
  },
3046
- set: function (comment) {
3047
- if (this.initialized && this._readOnlyAfterInit) {
3048
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
3165
+ set: function (max_time_allowed) {
3166
+ if (this.initialized) {
3167
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3049
3168
  }
3050
3169
  else {
3051
- if (check2004ValidFormat(comment, scorm2004_cmi_scorm2004_regex.CMILangString4000, true)) {
3052
- this._comment = comment;
3053
- }
3170
+ this._max_time_allowed = max_time_allowed;
3054
3171
  }
3055
3172
  },
3056
3173
  enumerable: false,
3057
3174
  configurable: true
3058
3175
  });
3059
- Object.defineProperty(CMICommentsObject.prototype, "location", {
3176
+ Object.defineProperty(CMI.prototype, "mode", {
3060
3177
  get: function () {
3061
- return this._location;
3178
+ return this._mode;
3062
3179
  },
3063
- set: function (location) {
3064
- if (this.initialized && this._readOnlyAfterInit) {
3065
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
3180
+ set: function (mode) {
3181
+ if (this.initialized) {
3182
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3066
3183
  }
3067
3184
  else {
3068
- if (check2004ValidFormat(location, scorm2004_cmi_scorm2004_regex.CMIString250)) {
3069
- this._location = location;
3070
- }
3185
+ this._mode = mode;
3071
3186
  }
3072
3187
  },
3073
3188
  enumerable: false,
3074
3189
  configurable: true
3075
3190
  });
3076
- Object.defineProperty(CMICommentsObject.prototype, "timestamp", {
3191
+ Object.defineProperty(CMI.prototype, "progress_measure", {
3077
3192
  get: function () {
3078
- return this._timestamp;
3193
+ return this._progress_measure;
3079
3194
  },
3080
- set: function (timestamp) {
3081
- if (this.initialized && this._readOnlyAfterInit) {
3082
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
3195
+ set: function (progress_measure) {
3196
+ if (check2004ValidFormat(progress_measure, regex.scorm2004.CMIDecimal) &&
3197
+ check2004ValidRange(progress_measure, regex.scorm2004.progress_range)) {
3198
+ this._progress_measure = progress_measure;
3199
+ }
3200
+ },
3201
+ enumerable: false,
3202
+ configurable: true
3203
+ });
3204
+ Object.defineProperty(CMI.prototype, "scaled_passing_score", {
3205
+ get: function () {
3206
+ return this._scaled_passing_score;
3207
+ },
3208
+ set: function (scaled_passing_score) {
3209
+ if (this.initialized) {
3210
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3083
3211
  }
3084
3212
  else {
3085
- if (check2004ValidFormat(timestamp, scorm2004_cmi_scorm2004_regex.CMITime)) {
3086
- this._timestamp = timestamp;
3087
- }
3213
+ this._scaled_passing_score = scaled_passing_score;
3088
3214
  }
3089
3215
  },
3090
3216
  enumerable: false,
3091
3217
  configurable: true
3092
3218
  });
3093
- CMICommentsObject.prototype.toJSON = function () {
3094
- this.jsonString = true;
3095
- var result = {
3096
- comment: this.comment,
3097
- location: this.location,
3098
- timestamp: this.timestamp,
3099
- };
3100
- delete this.jsonString;
3101
- return result;
3102
- };
3103
- return CMICommentsObject;
3104
- }(BaseCMI));
3105
-
3106
- var CMIInteractionsObjectivesObject = (function (_super) {
3107
- __extends(CMIInteractionsObjectivesObject, _super);
3108
- function CMIInteractionsObjectivesObject() {
3109
- var _this = _super.call(this) || this;
3110
- _this._id = "";
3111
- return _this;
3112
- }
3113
- Object.defineProperty(CMIInteractionsObjectivesObject.prototype, "id", {
3219
+ Object.defineProperty(CMI.prototype, "session_time", {
3114
3220
  get: function () {
3115
- return this._id;
3221
+ if (!this.jsonString) {
3222
+ throw new Scorm2004ValidationError(error_codes.scorm2004.WRITE_ONLY_ELEMENT);
3223
+ }
3224
+ return this._session_time;
3116
3225
  },
3117
- set: function (id) {
3118
- if (check2004ValidFormat(id, scorm2004_cmi_scorm2004_regex.CMILongIdentifier)) {
3119
- this._id = id;
3226
+ set: function (session_time) {
3227
+ if (check2004ValidFormat(session_time, regex.scorm2004.CMITimespan)) {
3228
+ this._session_time = session_time;
3120
3229
  }
3121
3230
  },
3122
3231
  enumerable: false,
3123
3232
  configurable: true
3124
3233
  });
3125
- CMIInteractionsObjectivesObject.prototype.toJSON = function () {
3126
- this.jsonString = true;
3127
- var result = {
3128
- id: this.id,
3129
- };
3130
- delete this.jsonString;
3131
- return result;
3132
- };
3133
- return CMIInteractionsObjectivesObject;
3134
- }(BaseCMI));
3135
-
3136
- var CMIInteractionsCorrectResponsesObject = (function (_super) {
3137
- __extends(CMIInteractionsCorrectResponsesObject, _super);
3138
- function CMIInteractionsCorrectResponsesObject() {
3139
- var _this = _super.call(this) || this;
3140
- _this._pattern = "";
3141
- return _this;
3142
- }
3143
- Object.defineProperty(CMIInteractionsCorrectResponsesObject.prototype, "pattern", {
3234
+ Object.defineProperty(CMI.prototype, "success_status", {
3144
3235
  get: function () {
3145
- return this._pattern;
3236
+ return this._success_status;
3146
3237
  },
3147
- set: function (pattern) {
3148
- if (check2004ValidFormat(pattern, scorm2004_cmi_scorm2004_regex.CMIFeedback)) {
3149
- this._pattern = pattern;
3238
+ set: function (success_status) {
3239
+ if (check2004ValidFormat(success_status, regex.scorm2004.CMISStatus)) {
3240
+ this._success_status = success_status;
3150
3241
  }
3151
3242
  },
3152
3243
  enumerable: false,
3153
3244
  configurable: true
3154
3245
  });
3155
- CMIInteractionsCorrectResponsesObject.prototype.toJSON = function () {
3156
- this.jsonString = true;
3157
- var result = {
3158
- pattern: this.pattern,
3159
- };
3160
- delete this.jsonString;
3161
- return result;
3162
- };
3163
- return CMIInteractionsCorrectResponsesObject;
3164
- }(BaseCMI));
3165
-
3166
- var ADL = (function (_super) {
3167
- __extends(ADL, _super);
3168
- function ADL() {
3169
- var _this = _super.call(this) || this;
3170
- _this.nav = new ADLNav();
3171
- return _this;
3172
- }
3173
- ADL.prototype.initialize = function () {
3174
- var _a;
3175
- _super.prototype.initialize.call(this);
3176
- (_a = this.nav) === null || _a === void 0 ? void 0 : _a.initialize();
3177
- };
3178
- ADL.prototype.toJSON = function () {
3179
- this.jsonString = true;
3180
- var result = {
3181
- nav: this.nav,
3182
- };
3183
- delete this.jsonString;
3184
- return result;
3185
- };
3186
- return ADL;
3187
- }(BaseCMI));
3188
-
3189
- var ADLNav = (function (_super) {
3190
- __extends(ADLNav, _super);
3191
- function ADLNav() {
3192
- var _this = _super.call(this) || this;
3193
- _this._request = "_none_";
3194
- _this.request_valid = new ADLNavRequestValid();
3195
- return _this;
3196
- }
3197
- ADLNav.prototype.initialize = function () {
3198
- var _a;
3199
- _super.prototype.initialize.call(this);
3200
- (_a = this.request_valid) === null || _a === void 0 ? void 0 : _a.initialize();
3201
- };
3202
- Object.defineProperty(ADLNav.prototype, "request", {
3246
+ Object.defineProperty(CMI.prototype, "suspend_data", {
3203
3247
  get: function () {
3204
- return this._request;
3248
+ return this._suspend_data;
3205
3249
  },
3206
- set: function (request) {
3207
- if (check2004ValidFormat(request, scorm2004_cmi_scorm2004_regex.NAVEvent)) {
3208
- this._request = request;
3250
+ set: function (suspend_data) {
3251
+ if (check2004ValidFormat(suspend_data, regex.scorm2004.CMIString64000, true)) {
3252
+ this._suspend_data = suspend_data;
3209
3253
  }
3210
3254
  },
3211
3255
  enumerable: false,
3212
3256
  configurable: true
3213
3257
  });
3214
- ADLNav.prototype.toJSON = function () {
3215
- this.jsonString = true;
3216
- var result = {
3217
- request: this.request,
3218
- };
3219
- delete this.jsonString;
3220
- return result;
3221
- };
3222
- return ADLNav;
3223
- }(BaseCMI));
3224
- var ADLNavRequestValid = (function (_super) {
3225
- __extends(ADLNavRequestValid, _super);
3226
- function ADLNavRequestValid() {
3227
- var _this = _super.call(this) || this;
3228
- _this._continue = "unknown";
3229
- _this._previous = "unknown";
3230
- _this.choice = (function () {
3231
- function class_1() {
3232
- this._isTargetValid = function (_target) { return "unknown"; };
3233
- }
3234
- return class_1;
3235
- }());
3236
- _this.jump = (function () {
3237
- function class_2() {
3238
- this._isTargetValid = function (_target) { return "unknown"; };
3239
- }
3240
- return class_2;
3241
- }());
3242
- return _this;
3243
- }
3244
- Object.defineProperty(ADLNavRequestValid.prototype, "continue", {
3258
+ Object.defineProperty(CMI.prototype, "time_limit_action", {
3245
3259
  get: function () {
3246
- return this._continue;
3260
+ return this._time_limit_action;
3247
3261
  },
3248
- set: function (_continue) {
3249
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
3262
+ set: function (time_limit_action) {
3263
+ if (this.initialized) {
3264
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3265
+ }
3266
+ else {
3267
+ this._time_limit_action = time_limit_action;
3268
+ }
3250
3269
  },
3251
3270
  enumerable: false,
3252
3271
  configurable: true
3253
3272
  });
3254
- Object.defineProperty(ADLNavRequestValid.prototype, "previous", {
3273
+ Object.defineProperty(CMI.prototype, "total_time", {
3255
3274
  get: function () {
3256
- return this._previous;
3275
+ return this._total_time;
3257
3276
  },
3258
- set: function (_previous) {
3259
- throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
3277
+ set: function (total_time) {
3278
+ if (this.initialized) {
3279
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3280
+ }
3281
+ else {
3282
+ this._total_time = total_time;
3283
+ }
3260
3284
  },
3261
3285
  enumerable: false,
3262
3286
  configurable: true
3263
3287
  });
3264
- ADLNavRequestValid.prototype.toJSON = function () {
3288
+ CMI.prototype.getCurrentTotalTime = function () {
3289
+ var sessionTime = this._session_time;
3290
+ var startTime = this.start_time;
3291
+ if (typeof startTime !== "undefined" && startTime !== null) {
3292
+ var seconds = new Date().getTime() - startTime;
3293
+ sessionTime = getSecondsAsISODuration(seconds / 1000);
3294
+ }
3295
+ return addTwoDurations(this._total_time, sessionTime, regex.scorm2004.CMITimespan);
3296
+ };
3297
+ CMI.prototype.toJSON = function () {
3265
3298
  this.jsonString = true;
3266
3299
  var result = {
3267
- previous: this._previous,
3268
- continue: this.continue,
3300
+ comments_from_learner: this.comments_from_learner,
3301
+ comments_from_lms: this.comments_from_lms,
3302
+ completion_status: this.completion_status,
3303
+ completion_threshold: this.completion_threshold,
3304
+ credit: this.credit,
3305
+ entry: this.entry,
3306
+ exit: this.exit,
3307
+ interactions: this.interactions,
3308
+ launch_data: this.launch_data,
3309
+ learner_id: this.learner_id,
3310
+ learner_name: this.learner_name,
3311
+ learner_preference: this.learner_preference,
3312
+ location: this.location,
3313
+ max_time_allowed: this.max_time_allowed,
3314
+ mode: this.mode,
3315
+ objectives: this.objectives,
3316
+ progress_measure: this.progress_measure,
3317
+ scaled_passing_score: this.scaled_passing_score,
3318
+ score: this.score,
3319
+ session_time: this.session_time,
3320
+ success_status: this.success_status,
3321
+ suspend_data: this.suspend_data,
3322
+ time_limit_action: this.time_limit_action,
3269
3323
  };
3270
3324
  delete this.jsonString;
3271
3325
  return result;
3272
3326
  };
3273
- return ADLNavRequestValid;
3274
- }(BaseCMI));
3327
+ return CMI;
3328
+ }(BaseRootCMI));
3329
+
3275
3330
 
3276
3331
  ;// ./src/constants/language_constants.ts
3277
3332
  var ValidLanguages = [
@@ -3669,6 +3724,195 @@ var ValidLanguages = [
3669
3724
  ];
3670
3725
  /* harmony default export */ var language_constants = (ValidLanguages);
3671
3726
 
3727
+ ;// ./src/constants/enums.ts
3728
+ var NAVBoolean;
3729
+ (function (NAVBoolean) {
3730
+ NAVBoolean["unknown"] = "unknown";
3731
+ NAVBoolean["true"] = "true";
3732
+ NAVBoolean["false"] = "false";
3733
+ })(NAVBoolean || (NAVBoolean = {}));
3734
+ var SuccessStatus;
3735
+ (function (SuccessStatus) {
3736
+ SuccessStatus["passed"] = "passed";
3737
+ SuccessStatus["failed"] = "failed";
3738
+ SuccessStatus["unknown"] = "unknown";
3739
+ })(SuccessStatus || (SuccessStatus = {}));
3740
+ var CompletionStatus;
3741
+ (function (CompletionStatus) {
3742
+ CompletionStatus["completed"] = "completed";
3743
+ CompletionStatus["incomplete"] = "incomplete";
3744
+ CompletionStatus["unknown"] = "unknown";
3745
+ })(CompletionStatus || (CompletionStatus = {}));
3746
+
3747
+ ;// ./src/cmi/scorm2004/adl.ts
3748
+
3749
+
3750
+
3751
+
3752
+
3753
+
3754
+
3755
+ var ADL = (function (_super) {
3756
+ __extends(ADL, _super);
3757
+ function ADL() {
3758
+ var _this = _super.call(this) || this;
3759
+ _this.nav = new ADLNav();
3760
+ return _this;
3761
+ }
3762
+ ADL.prototype.initialize = function () {
3763
+ var _a;
3764
+ _super.prototype.initialize.call(this);
3765
+ (_a = this.nav) === null || _a === void 0 ? void 0 : _a.initialize();
3766
+ };
3767
+ ADL.prototype.toJSON = function () {
3768
+ this.jsonString = true;
3769
+ var result = {
3770
+ nav: this.nav,
3771
+ };
3772
+ delete this.jsonString;
3773
+ return result;
3774
+ };
3775
+ return ADL;
3776
+ }(BaseCMI));
3777
+
3778
+ var ADLNav = (function (_super) {
3779
+ __extends(ADLNav, _super);
3780
+ function ADLNav() {
3781
+ var _this = _super.call(this) || this;
3782
+ _this._request = "_none_";
3783
+ _this.request_valid = new ADLNavRequestValid();
3784
+ return _this;
3785
+ }
3786
+ ADLNav.prototype.initialize = function () {
3787
+ var _a;
3788
+ _super.prototype.initialize.call(this);
3789
+ (_a = this.request_valid) === null || _a === void 0 ? void 0 : _a.initialize();
3790
+ };
3791
+ Object.defineProperty(ADLNav.prototype, "request", {
3792
+ get: function () {
3793
+ return this._request;
3794
+ },
3795
+ set: function (request) {
3796
+ if (check2004ValidFormat(request, regex.scorm2004.NAVEvent)) {
3797
+ this._request = request;
3798
+ }
3799
+ },
3800
+ enumerable: false,
3801
+ configurable: true
3802
+ });
3803
+ ADLNav.prototype.toJSON = function () {
3804
+ this.jsonString = true;
3805
+ var result = {
3806
+ request: this.request,
3807
+ };
3808
+ delete this.jsonString;
3809
+ return result;
3810
+ };
3811
+ return ADLNav;
3812
+ }(BaseCMI));
3813
+
3814
+ var ADLNavRequestValid = (function (_super) {
3815
+ __extends(ADLNavRequestValid, _super);
3816
+ function ADLNavRequestValid() {
3817
+ var _this = _super.call(this) || this;
3818
+ _this._continue = "unknown";
3819
+ _this._previous = "unknown";
3820
+ _this._choice = {};
3821
+ _this._jump = {};
3822
+ return _this;
3823
+ }
3824
+ Object.defineProperty(ADLNavRequestValid.prototype, "continue", {
3825
+ get: function () {
3826
+ return this._continue;
3827
+ },
3828
+ set: function (_continue) {
3829
+ if (this.initialized) {
3830
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3831
+ }
3832
+ if (check2004ValidFormat(_continue, regex.scorm2004.NAVBoolean)) {
3833
+ this._continue = _continue;
3834
+ }
3835
+ },
3836
+ enumerable: false,
3837
+ configurable: true
3838
+ });
3839
+ Object.defineProperty(ADLNavRequestValid.prototype, "previous", {
3840
+ get: function () {
3841
+ return this._previous;
3842
+ },
3843
+ set: function (_previous) {
3844
+ if (this.initialized) {
3845
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3846
+ }
3847
+ if (check2004ValidFormat(_previous, regex.scorm2004.NAVBoolean)) {
3848
+ this._previous = _previous;
3849
+ }
3850
+ },
3851
+ enumerable: false,
3852
+ configurable: true
3853
+ });
3854
+ Object.defineProperty(ADLNavRequestValid.prototype, "choice", {
3855
+ get: function () {
3856
+ return this._choice;
3857
+ },
3858
+ set: function (choice) {
3859
+ if (this.initialized) {
3860
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3861
+ }
3862
+ if (typeof choice !== "object") {
3863
+ throw new Scorm2004ValidationError(error_codes.scorm2004.TYPE_MISMATCH);
3864
+ }
3865
+ for (var key in choice) {
3866
+ if ({}.hasOwnProperty.call(choice, key)) {
3867
+ if (check2004ValidFormat(choice[key], regex.scorm2004.NAVBoolean) &&
3868
+ check2004ValidFormat(key, regex.scorm2004.NAVTarget)) {
3869
+ this._choice[key] =
3870
+ NAVBoolean[choice[key]];
3871
+ }
3872
+ }
3873
+ }
3874
+ },
3875
+ enumerable: false,
3876
+ configurable: true
3877
+ });
3878
+ Object.defineProperty(ADLNavRequestValid.prototype, "jump", {
3879
+ get: function () {
3880
+ return this._jump;
3881
+ },
3882
+ set: function (jump) {
3883
+ if (this.initialized) {
3884
+ throw new Scorm2004ValidationError(error_codes.scorm2004.READ_ONLY_ELEMENT);
3885
+ }
3886
+ if (typeof jump !== "object") {
3887
+ throw new Scorm2004ValidationError(error_codes.scorm2004.TYPE_MISMATCH);
3888
+ }
3889
+ for (var key in jump) {
3890
+ if ({}.hasOwnProperty.call(jump, key)) {
3891
+ if (check2004ValidFormat(jump[key], regex.scorm2004.NAVBoolean) &&
3892
+ check2004ValidFormat(key, regex.scorm2004.NAVTarget)) {
3893
+ this._jump[key] = NAVBoolean[jump[key]];
3894
+ }
3895
+ }
3896
+ }
3897
+ },
3898
+ enumerable: false,
3899
+ configurable: true
3900
+ });
3901
+ ADLNavRequestValid.prototype.toJSON = function () {
3902
+ this.jsonString = true;
3903
+ var result = {
3904
+ previous: this._previous,
3905
+ continue: this._continue,
3906
+ choice: this._choice,
3907
+ jump: this._jump,
3908
+ };
3909
+ delete this.jsonString;
3910
+ return result;
3911
+ };
3912
+ return ADLNavRequestValid;
3913
+ }(BaseCMI));
3914
+
3915
+
3672
3916
  ;// ./src/Scorm2004API.ts
3673
3917
 
3674
3918
 
@@ -3679,11 +3923,13 @@ var ValidLanguages = [
3679
3923
 
3680
3924
 
3681
3925
 
3682
- var Scorm2004API_scorm2004_constants = api_constants.scorm2004;
3683
- var Scorm2004API_global_constants = api_constants.global;
3684
- var Scorm2004API_scorm2004_error_codes = error_codes.scorm2004;
3685
- var correct_responses = CorrectResponses;
3686
- var Scorm2004API_scorm2004_regex = regex.scorm2004;
3926
+
3927
+
3928
+
3929
+
3930
+
3931
+
3932
+
3687
3933
  var Scorm2004API = (function (_super) {
3688
3934
  __extends(Scorm2004API, _super);
3689
3935
  function Scorm2004API(settings) {
@@ -3693,7 +3939,7 @@ var Scorm2004API = (function (_super) {
3693
3939
  settings.mastery_override = false;
3694
3940
  }
3695
3941
  }
3696
- _this = _super.call(this, Scorm2004API_scorm2004_error_codes, settings) || this;
3942
+ _this = _super.call(this, error_codes.scorm2004, settings) || this;
3697
3943
  _this._version = "1.0";
3698
3944
  _this.cmi = new CMI();
3699
3945
  _this.adl = new ADL();
@@ -3707,6 +3953,11 @@ var Scorm2004API = (function (_super) {
3707
3953
  _this.GetDiagnostic = _this.lmsGetDiagnostic;
3708
3954
  return _this;
3709
3955
  }
3956
+ Scorm2004API.prototype.reset = function (settings) {
3957
+ this.commonReset(settings);
3958
+ this.cmi = new CMI();
3959
+ this.adl = new ADL();
3960
+ };
3710
3961
  Object.defineProperty(Scorm2004API.prototype, "version", {
3711
3962
  get: function () {
3712
3963
  return this._version;
@@ -3719,47 +3970,92 @@ var Scorm2004API = (function (_super) {
3719
3970
  return this.initialize("Initialize");
3720
3971
  };
3721
3972
  Scorm2004API.prototype.lmsFinish = function () {
3722
- var result = this.terminate("Terminate", true);
3723
- if (result === Scorm2004API_global_constants.SCORM_TRUE) {
3724
- if (this.adl.nav.request !== "_none_") {
3725
- switch (this.adl.nav.request) {
3726
- case "continue":
3727
- this.processListeners("SequenceNext");
3728
- break;
3729
- case "previous":
3730
- this.processListeners("SequencePrevious");
3731
- break;
3732
- case "choice":
3733
- this.processListeners("SequenceChoice");
3734
- break;
3735
- case "exit":
3736
- this.processListeners("SequenceExit");
3737
- break;
3738
- case "exitAll":
3739
- this.processListeners("SequenceExitAll");
3740
- break;
3741
- case "abandon":
3742
- this.processListeners("SequenceAbandon");
3743
- break;
3744
- case "abandonAll":
3745
- this.processListeners("SequenceAbandonAll");
3746
- break;
3973
+ var _this = this;
3974
+ (function () { return __awaiter(_this, void 0, void 0, function () {
3975
+ return __generator(this, function (_a) {
3976
+ switch (_a.label) {
3977
+ case 0: return [4, this.internalFinish()];
3978
+ case 1:
3979
+ _a.sent();
3980
+ return [2];
3747
3981
  }
3748
- }
3749
- else if (this.settings.autoProgress) {
3750
- this.processListeners("SequenceNext");
3751
- }
3752
- }
3753
- return result;
3982
+ });
3983
+ }); })();
3984
+ return api_constants.global.SCORM_TRUE;
3985
+ };
3986
+ Scorm2004API.prototype.internalFinish = function () {
3987
+ return __awaiter(this, void 0, void 0, function () {
3988
+ var result, navActions, request, choiceJumpRegex, matches, target, action;
3989
+ return __generator(this, function (_a) {
3990
+ switch (_a.label) {
3991
+ case 0: return [4, this.terminate("Terminate", true)];
3992
+ case 1:
3993
+ result = _a.sent();
3994
+ if (result === api_constants.global.SCORM_TRUE) {
3995
+ if (this.adl.nav.request !== "_none_") {
3996
+ navActions = {
3997
+ continue: "SequenceNext",
3998
+ previous: "SequencePrevious",
3999
+ choice: "SequenceChoice",
4000
+ jump: "SequenceJump",
4001
+ exit: "SequenceExit",
4002
+ exitAll: "SequenceExitAll",
4003
+ abandon: "SequenceAbandon",
4004
+ abandonAll: "SequenceAbandonAll",
4005
+ };
4006
+ request = this.adl.nav.request;
4007
+ choiceJumpRegex = new RegExp(regex.scorm2004.NAVEvent);
4008
+ matches = request.match(choiceJumpRegex);
4009
+ target = "";
4010
+ if (matches && matches.length > 2) {
4011
+ target = matches[2];
4012
+ request = matches[1].replace(target, "");
4013
+ }
4014
+ action = navActions[request];
4015
+ if (action) {
4016
+ this.processListeners(action, "adl.nav.request", target);
4017
+ }
4018
+ }
4019
+ else if (this.settings.autoProgress) {
4020
+ this.processListeners("SequenceNext");
4021
+ }
4022
+ }
4023
+ return [2, result];
4024
+ }
4025
+ });
4026
+ });
3754
4027
  };
3755
4028
  Scorm2004API.prototype.lmsGetValue = function (CMIElement) {
4029
+ var adlNavRequestRegex = "^adl\\.nav\\.request_valid\\.(choice|jump)\\.{target=\\S{0,}([a-zA-Z0-9-_]+)}$";
4030
+ if (stringMatches(CMIElement, adlNavRequestRegex)) {
4031
+ var matches = CMIElement.match(adlNavRequestRegex);
4032
+ var request = matches[1];
4033
+ var target = matches[2].replace("{target=", "").replace("}", "");
4034
+ if (request === "choice" || request === "jump") {
4035
+ if (this.settings.scoItemIdValidator) {
4036
+ return String(this.settings.scoItemIdValidator(target));
4037
+ }
4038
+ return String(this.settings.scoItemIds.includes(target));
4039
+ }
4040
+ }
3756
4041
  return this.getValue("GetValue", true, CMIElement);
3757
4042
  };
3758
4043
  Scorm2004API.prototype.lmsSetValue = function (CMIElement, value) {
3759
4044
  return this.setValue("SetValue", "Commit", true, CMIElement, value);
3760
4045
  };
3761
4046
  Scorm2004API.prototype.lmsCommit = function () {
3762
- return this.commit("Commit");
4047
+ var _this = this;
4048
+ (function () { return __awaiter(_this, void 0, void 0, function () {
4049
+ return __generator(this, function (_a) {
4050
+ switch (_a.label) {
4051
+ case 0: return [4, this.commit("Commit")];
4052
+ case 1:
4053
+ _a.sent();
4054
+ return [2];
4055
+ }
4056
+ });
4057
+ }); })();
4058
+ return api_constants.global.SCORM_TRUE;
3763
4059
  };
3764
4060
  Scorm2004API.prototype.lmsGetLastError = function () {
3765
4061
  return this.getLastError("GetLastError");
@@ -3774,49 +4070,52 @@ var Scorm2004API = (function (_super) {
3774
4070
  return this._commonSetCMIValue("SetValue", true, CMIElement, value);
3775
4071
  };
3776
4072
  Scorm2004API.prototype.getChildElement = function (CMIElement, value, foundFirstIndex) {
3777
- if (this.stringMatches(CMIElement, "cmi\\.objectives\\.\\d+")) {
4073
+ if (stringMatches(CMIElement, "cmi\\.objectives\\.\\d+")) {
3778
4074
  return new CMIObjectivesObject();
3779
4075
  }
3780
- else if (foundFirstIndex &&
3781
- this.stringMatches(CMIElement, "cmi\\.interactions\\.\\d+\\.correct_responses\\.\\d+")) {
3782
- var parts = CMIElement.split(".");
3783
- var index = Number(parts[2]);
3784
- var interaction = this.cmi.interactions.childArray[index];
3785
- if (this.isInitialized()) {
3786
- if (!interaction.type) {
3787
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED);
3788
- }
3789
- else {
3790
- this.checkDuplicateChoiceResponse(interaction, value);
3791
- var response_type = correct_responses[interaction.type];
3792
- if (response_type) {
3793
- this.checkValidResponseType(response_type, value, interaction.type);
3794
- }
3795
- else {
3796
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.GENERAL_SET_FAILURE, "Incorrect Response Type: " + interaction.type);
3797
- }
3798
- }
4076
+ if (foundFirstIndex) {
4077
+ if (stringMatches(CMIElement, "cmi\\.interactions\\.\\d+\\.correct_responses\\.\\d+")) {
4078
+ return this.createCorrectResponsesObject(CMIElement, value);
3799
4079
  }
3800
- if (this.lastErrorCode === "0") {
3801
- return new CMIInteractionsCorrectResponsesObject();
4080
+ else if (stringMatches(CMIElement, "cmi\\.interactions\\.\\d+\\.objectives\\.\\d+")) {
4081
+ return new CMIInteractionsObjectivesObject();
3802
4082
  }
3803
4083
  }
3804
- else if (foundFirstIndex &&
3805
- this.stringMatches(CMIElement, "cmi\\.interactions\\.\\d+\\.objectives\\.\\d+")) {
3806
- return new CMIInteractionsObjectivesObject();
3807
- }
3808
- else if (!foundFirstIndex &&
3809
- this.stringMatches(CMIElement, "cmi\\.interactions\\.\\d+")) {
4084
+ else if (stringMatches(CMIElement, "cmi\\.interactions\\.\\d+")) {
3810
4085
  return new CMIInteractionsObject();
3811
4086
  }
3812
- else if (this.stringMatches(CMIElement, "cmi\\.comments_from_learner\\.\\d+")) {
4087
+ if (stringMatches(CMIElement, "cmi\\.comments_from_learner\\.\\d+")) {
3813
4088
  return new CMICommentsObject();
3814
4089
  }
3815
- else if (this.stringMatches(CMIElement, "cmi\\.comments_from_lms\\.\\d+")) {
4090
+ else if (stringMatches(CMIElement, "cmi\\.comments_from_lms\\.\\d+")) {
3816
4091
  return new CMICommentsObject(true);
3817
4092
  }
3818
4093
  return null;
3819
4094
  };
4095
+ Scorm2004API.prototype.createCorrectResponsesObject = function (CMIElement, value) {
4096
+ var parts = CMIElement.split(".");
4097
+ var index = Number(parts[2]);
4098
+ var interaction = this.cmi.interactions.childArray[index];
4099
+ if (this.isInitialized()) {
4100
+ if (!interaction.type) {
4101
+ this.throwSCORMError(error_codes.scorm2004.DEPENDENCY_NOT_ESTABLISHED);
4102
+ }
4103
+ else {
4104
+ this.checkDuplicateChoiceResponse(interaction, value);
4105
+ var response_type = CorrectResponses[interaction.type];
4106
+ if (response_type) {
4107
+ this.checkValidResponseType(response_type, value, interaction.type);
4108
+ }
4109
+ else {
4110
+ this.throwSCORMError(error_codes.scorm2004.GENERAL_SET_FAILURE, "Incorrect Response Type: " + interaction.type);
4111
+ }
4112
+ }
4113
+ }
4114
+ if (this.lastErrorCode === "0") {
4115
+ return new CMIInteractionsCorrectResponsesObject();
4116
+ }
4117
+ return null;
4118
+ };
3820
4119
  Scorm2004API.prototype.checkValidResponseType = function (response_type, value, interaction_type) {
3821
4120
  var nodes = [];
3822
4121
  if (response_type === null || response_type === void 0 ? void 0 : response_type.delimiter) {
@@ -3829,7 +4128,7 @@ var Scorm2004API = (function (_super) {
3829
4128
  this.checkCorrectResponseValue(interaction_type, nodes, value);
3830
4129
  }
3831
4130
  else if (nodes.length > response_type.max) {
3832
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.GENERAL_SET_FAILURE, "Data Model Element Pattern Too Long");
4131
+ this.throwSCORMError(error_codes.scorm2004.GENERAL_SET_FAILURE, "Data Model Element Pattern Too Long");
3833
4132
  }
3834
4133
  };
3835
4134
  Scorm2004API.prototype.checkDuplicateChoiceResponse = function (interaction, value) {
@@ -3838,7 +4137,7 @@ var Scorm2004API = (function (_super) {
3838
4137
  for (var i = 0; i < interaction_count && this.lastErrorCode === "0"; i++) {
3839
4138
  var response = interaction.correct_responses.childArray[i];
3840
4139
  if (response.pattern === value) {
3841
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.GENERAL_SET_FAILURE);
4140
+ this.throwSCORMError(error_codes.scorm2004.GENERAL_SET_FAILURE);
3842
4141
  }
3843
4142
  }
3844
4143
  }
@@ -3850,7 +4149,7 @@ var Scorm2004API = (function (_super) {
3850
4149
  var interaction = this.cmi.interactions.childArray[index];
3851
4150
  var interaction_count = interaction.correct_responses._count;
3852
4151
  this.checkDuplicateChoiceResponse(interaction, value);
3853
- var response_type = correct_responses[interaction.type];
4152
+ var response_type = CorrectResponses[interaction.type];
3854
4153
  if (typeof response_type.limit === "undefined" ||
3855
4154
  interaction_count <= response_type.limit) {
3856
4155
  this.checkValidResponseType(response_type, value, interaction.type);
@@ -3861,12 +4160,12 @@ var Scorm2004API = (function (_super) {
3861
4160
  }
3862
4161
  else {
3863
4162
  if (this.lastErrorCode === "0") {
3864
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.GENERAL_SET_FAILURE, "Data Model Element Pattern Already Exists");
4163
+ this.throwSCORMError(error_codes.scorm2004.GENERAL_SET_FAILURE, "Data Model Element Pattern Already Exists");
3865
4164
  }
3866
4165
  }
3867
4166
  }
3868
4167
  else {
3869
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.GENERAL_SET_FAILURE, "Data Model Element Collection Limit Reached");
4168
+ this.throwSCORMError(error_codes.scorm2004.GENERAL_SET_FAILURE, "Data Model Element Collection Limit Reached");
3870
4169
  }
3871
4170
  };
3872
4171
  Scorm2004API.prototype.getCMIValue = function (CMIElement) {
@@ -3876,11 +4175,11 @@ var Scorm2004API = (function (_super) {
3876
4175
  var basicMessage = "";
3877
4176
  var detailMessage = "";
3878
4177
  errorNumber = String(errorNumber);
3879
- if (Scorm2004API_scorm2004_constants.error_descriptions[errorNumber]) {
4178
+ if (api_constants.scorm2004.error_descriptions[errorNumber]) {
3880
4179
  basicMessage =
3881
- Scorm2004API_scorm2004_constants.error_descriptions[errorNumber].basicMessage;
4180
+ api_constants.scorm2004.error_descriptions[errorNumber].basicMessage;
3882
4181
  detailMessage =
3883
- Scorm2004API_scorm2004_constants.error_descriptions[errorNumber].detailMessage;
4182
+ api_constants.scorm2004.error_descriptions[errorNumber].detailMessage;
3884
4183
  }
3885
4184
  return detail ? detailMessage : basicMessage;
3886
4185
  };
@@ -3895,7 +4194,7 @@ var Scorm2004API = (function (_super) {
3895
4194
  return found;
3896
4195
  };
3897
4196
  Scorm2004API.prototype.checkCorrectResponseValue = function (interaction_type, nodes, value) {
3898
- var response = correct_responses[interaction_type];
4197
+ var response = CorrectResponses[interaction_type];
3899
4198
  var formatRegex = new RegExp(response.format);
3900
4199
  for (var i = 0; i < nodes.length && this.lastErrorCode === "0"; i++) {
3901
4200
  if (interaction_type.match("^(fill-in|long-fill-in|matching|performance|sequencing)$")) {
@@ -3906,36 +4205,36 @@ var Scorm2004API = (function (_super) {
3906
4205
  if (values.length === 2) {
3907
4206
  var matches = values[0].match(formatRegex);
3908
4207
  if (!matches) {
3909
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.TYPE_MISMATCH);
4208
+ this.throwSCORMError(error_codes.scorm2004.TYPE_MISMATCH);
3910
4209
  }
3911
4210
  else {
3912
4211
  if (!response.format2 ||
3913
4212
  !values[1].match(new RegExp(response.format2))) {
3914
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.TYPE_MISMATCH);
4213
+ this.throwSCORMError(error_codes.scorm2004.TYPE_MISMATCH);
3915
4214
  }
3916
4215
  }
3917
4216
  }
3918
4217
  else {
3919
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.TYPE_MISMATCH);
4218
+ this.throwSCORMError(error_codes.scorm2004.TYPE_MISMATCH);
3920
4219
  }
3921
4220
  }
3922
4221
  else {
3923
4222
  var matches = nodes[i].match(formatRegex);
3924
4223
  if ((!matches && value !== "") ||
3925
4224
  (!matches && interaction_type === "true-false")) {
3926
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.TYPE_MISMATCH);
4225
+ this.throwSCORMError(error_codes.scorm2004.TYPE_MISMATCH);
3927
4226
  }
3928
4227
  else {
3929
4228
  if (interaction_type === "numeric" && nodes.length > 1) {
3930
4229
  if (Number(nodes[0]) > Number(nodes[1])) {
3931
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.TYPE_MISMATCH);
4230
+ this.throwSCORMError(error_codes.scorm2004.TYPE_MISMATCH);
3932
4231
  }
3933
4232
  }
3934
4233
  else {
3935
4234
  if (nodes[i] !== "" && response.unique) {
3936
4235
  for (var j = 0; j < i && this.lastErrorCode === "0"; j++) {
3937
4236
  if (nodes[i] === nodes[j]) {
3938
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.TYPE_MISMATCH);
4237
+ this.throwSCORMError(error_codes.scorm2004.TYPE_MISMATCH);
3939
4238
  }
3940
4239
  }
3941
4240
  }
@@ -3954,12 +4253,12 @@ var Scorm2004API = (function (_super) {
3954
4253
  while (matches) {
3955
4254
  switch (matches[2]) {
3956
4255
  case "lang":
3957
- langMatches = node.match(Scorm2004API_scorm2004_regex.CMILangcr);
4256
+ langMatches = node.match(regex.scorm2004.CMILangcr);
3958
4257
  if (langMatches) {
3959
4258
  var lang = langMatches[3];
3960
4259
  if (lang !== undefined && lang.length > 0) {
3961
4260
  if (!language_constants.includes(lang.toLowerCase())) {
3962
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.TYPE_MISMATCH);
4261
+ this.throwSCORMError(error_codes.scorm2004.TYPE_MISMATCH);
3963
4262
  }
3964
4263
  }
3965
4264
  }
@@ -3968,7 +4267,7 @@ var Scorm2004API = (function (_super) {
3968
4267
  case "case_matters":
3969
4268
  if (!seenLang && !seenOrder && !seenCase) {
3970
4269
  if (matches[3] !== "true" && matches[3] !== "false") {
3971
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.TYPE_MISMATCH);
4270
+ this.throwSCORMError(error_codes.scorm2004.TYPE_MISMATCH);
3972
4271
  }
3973
4272
  }
3974
4273
  seenCase = true;
@@ -3976,13 +4275,11 @@ var Scorm2004API = (function (_super) {
3976
4275
  case "order_matters":
3977
4276
  if (!seenCase && !seenLang && !seenOrder) {
3978
4277
  if (matches[3] !== "true" && matches[3] !== "false") {
3979
- this.throwSCORMError(Scorm2004API_scorm2004_error_codes.TYPE_MISMATCH);
4278
+ this.throwSCORMError(error_codes.scorm2004.TYPE_MISMATCH);
3980
4279
  }
3981
4280
  }
3982
4281
  seenOrder = true;
3983
4282
  break;
3984
- default:
3985
- break;
3986
4283
  }
3987
4284
  node = node.substring(matches[1].length);
3988
4285
  matches = node.match(prefixRegex);
@@ -4015,58 +4312,118 @@ var Scorm2004API = (function (_super) {
4015
4312
  return cmiExport;
4016
4313
  }
4017
4314
  };
4315
+ Scorm2004API.prototype.renderCommitObject = function (terminateCommit) {
4316
+ var cmiExport = this.renderCommitCMI(terminateCommit);
4317
+ var totalTimeDuration = this.cmi.getCurrentTotalTime();
4318
+ var totalTimeSeconds = getDurationAsSeconds(totalTimeDuration, regex.scorm2004.CMITimespan);
4319
+ var completionStatus = CompletionStatus.unknown;
4320
+ var successStatus = SuccessStatus.unknown;
4321
+ if (this.cmi.completion_status) {
4322
+ if (this.cmi.completion_status === "completed") {
4323
+ completionStatus = CompletionStatus.completed;
4324
+ }
4325
+ else if (this.cmi.completion_status === "incomplete") {
4326
+ completionStatus = CompletionStatus.incomplete;
4327
+ }
4328
+ }
4329
+ if (this.cmi.success_status) {
4330
+ if (this.cmi.success_status === "passed") {
4331
+ successStatus = SuccessStatus.passed;
4332
+ }
4333
+ else if (this.cmi.success_status === "failed") {
4334
+ successStatus = SuccessStatus.failed;
4335
+ }
4336
+ }
4337
+ var score = this.cmi.score;
4338
+ var scoreObject = null;
4339
+ if (score) {
4340
+ scoreObject = {};
4341
+ if (!Number.isNaN(Number.parseFloat(score.raw))) {
4342
+ scoreObject.raw = Number.parseFloat(score.raw);
4343
+ }
4344
+ if (!Number.isNaN(Number.parseFloat(score.min))) {
4345
+ scoreObject.min = Number.parseFloat(score.min);
4346
+ }
4347
+ if (!Number.isNaN(Number.parseFloat(score.max))) {
4348
+ scoreObject.max = Number.parseFloat(score.max);
4349
+ }
4350
+ if (!Number.isNaN(Number.parseFloat(score.scaled))) {
4351
+ scoreObject.scaled = Number.parseFloat(score.scaled);
4352
+ }
4353
+ }
4354
+ var commitObject = {
4355
+ completionStatus: completionStatus,
4356
+ successStatus: successStatus,
4357
+ totalTimeSeconds: totalTimeSeconds,
4358
+ runtimeData: cmiExport,
4359
+ };
4360
+ if (scoreObject) {
4361
+ commitObject.score = scoreObject;
4362
+ }
4363
+ return commitObject;
4364
+ };
4018
4365
  Scorm2004API.prototype.storeData = function (terminateCommit) {
4019
- var _a, _b, _c;
4020
- if (terminateCommit) {
4021
- if (this.cmi.mode === "normal") {
4022
- if (this.cmi.credit === "credit") {
4023
- if (this.cmi.completion_threshold && this.cmi.progress_measure) {
4024
- if (this.cmi.progress_measure >= this.cmi.completion_threshold) {
4025
- this.cmi.completion_status = "completed";
4366
+ return __awaiter(this, void 0, void 0, function () {
4367
+ var navRequest, shouldTerminateCommit, commitObject, result;
4368
+ var _a, _b, _c;
4369
+ return __generator(this, function (_d) {
4370
+ switch (_d.label) {
4371
+ case 0:
4372
+ if (terminateCommit) {
4373
+ if (this.cmi.mode === "normal") {
4374
+ if (this.cmi.credit === "credit") {
4375
+ if (this.cmi.completion_threshold && this.cmi.progress_measure) {
4376
+ if (this.cmi.progress_measure >= this.cmi.completion_threshold) {
4377
+ this.cmi.completion_status = "completed";
4378
+ }
4379
+ else {
4380
+ this.cmi.completion_status = "incomplete";
4381
+ }
4382
+ }
4383
+ if (this.cmi.scaled_passing_score && this.cmi.score.scaled) {
4384
+ if (this.cmi.score.scaled >= this.cmi.scaled_passing_score) {
4385
+ this.cmi.success_status = "passed";
4386
+ }
4387
+ else {
4388
+ this.cmi.success_status = "failed";
4389
+ }
4390
+ }
4391
+ }
4392
+ }
4026
4393
  }
4027
- else {
4028
- this.cmi.completion_status = "incomplete";
4394
+ navRequest = false;
4395
+ if (this.adl.nav.request !== ((_c = (_b = (_a = this.startingData) === null || _a === void 0 ? void 0 : _a.adl) === null || _b === void 0 ? void 0 : _b.nav) === null || _c === void 0 ? void 0 : _c.request) &&
4396
+ this.adl.nav.request !== "_none_") {
4397
+ this.adl.nav.request = encodeURIComponent(this.adl.nav.request);
4398
+ navRequest = true;
4029
4399
  }
4030
- }
4031
- if (this.cmi.scaled_passing_score && this.cmi.score.scaled) {
4032
- if (this.cmi.score.scaled >= this.cmi.scaled_passing_score) {
4033
- this.cmi.success_status = "passed";
4400
+ shouldTerminateCommit = terminateCommit || this.settings.alwaysSendTotalTime;
4401
+ commitObject = this.settings.renderCommonCommitFields
4402
+ ? this.renderCommitObject(shouldTerminateCommit)
4403
+ : this.renderCommitCMI(shouldTerminateCommit);
4404
+ if (this.apiLogLevel === api_constants.global.LOG_LEVEL_DEBUG) {
4405
+ console.debug("Commit (terminated: " + (terminateCommit ? "yes" : "no") + "): ");
4406
+ console.debug(commitObject);
4034
4407
  }
4035
- else {
4036
- this.cmi.success_status = "failed";
4408
+ if (!(typeof this.settings.lmsCommitUrl === "string")) return [3, 2];
4409
+ return [4, this.processHttpRequest(this.settings.lmsCommitUrl, commitObject, terminateCommit)];
4410
+ case 1:
4411
+ result = _d.sent();
4412
+ {
4413
+ if (navRequest &&
4414
+ result.navRequest !== undefined &&
4415
+ result.navRequest !== "") {
4416
+ Function("\"use strict\";(() => { ".concat(result.navRequest, " })()"))();
4417
+ }
4037
4418
  }
4038
- }
4039
- }
4040
- }
4041
- }
4042
- var navRequest = false;
4043
- if (this.adl.nav.request !== ((_c = (_b = (_a = this.startingData) === null || _a === void 0 ? void 0 : _a.adl) === null || _b === void 0 ? void 0 : _b.nav) === null || _c === void 0 ? void 0 : _c.request) &&
4044
- this.adl.nav.request !== "_none_") {
4045
- this.adl.nav.request = encodeURIComponent(this.adl.nav.request);
4046
- navRequest = true;
4047
- }
4048
- var commitObject = this.renderCommitCMI(terminateCommit || this.settings.alwaysSendTotalTime);
4049
- if (this.apiLogLevel === Scorm2004API_global_constants.LOG_LEVEL_DEBUG) {
4050
- console.debug("Commit (terminated: " + (terminateCommit ? "yes" : "no") + "): ");
4051
- console.debug(commitObject);
4052
- }
4053
- if (typeof this.settings.lmsCommitUrl === "string") {
4054
- var result = this.processHttpRequest(this.settings.lmsCommitUrl, commitObject, terminateCommit);
4055
- {
4056
- if (navRequest &&
4057
- result.navRequest !== undefined &&
4058
- result.navRequest !== "") {
4059
- Function("\"use strict\";(() => { ".concat(result.navRequest, " })()"))();
4419
+ return [2, result];
4420
+ case 2: return [2, {
4421
+ result: api_constants.global.SCORM_TRUE,
4422
+ errorCode: 0,
4423
+ }];
4060
4424
  }
4061
- }
4062
- return result;
4063
- }
4064
- else {
4065
- return {
4066
- result: Scorm2004API_global_constants.SCORM_TRUE,
4067
- errorCode: 0,
4068
- };
4069
- }
4425
+ });
4426
+ });
4070
4427
  };
4071
4428
  return Scorm2004API;
4072
4429
  }(src_BaseAPI));