@didask/scol-r 2.5.3 → 2.6.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.
@@ -12,10 +12,11 @@ export declare class SCORMAdapter {
12
12
  private _callAPIFunction;
13
13
  private _handleError;
14
14
  private _warnNOAPI;
15
- LMSInitialize(): any;
16
- LMSTerminate(): any;
15
+ private validateResult;
16
+ LMSInitialize(): true | void;
17
+ LMSTerminate(): true | void;
17
18
  LMSGetValue(name: string): any;
18
- LMSSetValue(name: string, value: string | number): any;
19
+ LMSSetValue(name: string, value: string | number): true | void;
19
20
  LMSCommit(): any;
20
21
  LMSGetLastError(): number;
21
22
  LMSGetErrorString(errorCode: number): any;
@@ -144,11 +144,20 @@ var SCORMAdapter = /** @class */ (function () {
144
144
  console.warn("Cannot execute this function because the SCORM API is not available.");
145
145
  this._errorCallback("apiNotFound");
146
146
  };
147
+ SCORMAdapter.prototype.validateResult = function (result) {
148
+ if (typeof result === "string") {
149
+ return result === "true";
150
+ }
151
+ else if (typeof result === "boolean") {
152
+ return result;
153
+ }
154
+ return false;
155
+ };
147
156
  SCORMAdapter.prototype.LMSInitialize = function () {
148
157
  var functionName = "Initialize";
149
158
  var result = this._callAPIFunction(functionName);
150
159
  var lastErrorCode = this.LMSGetLastError();
151
- var success = eval(result.toString()) ||
160
+ var success = this.validateResult(result) ||
152
161
  (this._isSCORM2004
153
162
  ? lastErrorCode === 103 // 103 in 2004.* = already initialized
154
163
  : lastErrorCode === 101); // 101 in 1.2 = already initialized
@@ -160,7 +169,7 @@ var SCORMAdapter = /** @class */ (function () {
160
169
  SCORMAdapter.prototype.LMSTerminate = function () {
161
170
  var functionName = this._isSCORM2004 ? "Terminate" : "Finish";
162
171
  var result = this._callAPIFunction(functionName);
163
- var success = eval(result.toString());
172
+ var success = this.validateResult(result);
164
173
  return success || this._handleError(functionName);
165
174
  };
166
175
  SCORMAdapter.prototype.LMSGetValue = function (name) {
@@ -174,13 +183,24 @@ var SCORMAdapter = /** @class */ (function () {
174
183
  this._lastRequest = { method: "set", key: name };
175
184
  var functionName = "SetValue";
176
185
  var result = this._callAPIFunction(functionName, [name, value]);
177
- var success = eval(result.toString());
186
+ var success = this.validateResult(result);
178
187
  return success || this._handleError("".concat(functionName, ": {").concat(name, ": ").concat(value, "}"));
179
188
  };
180
189
  SCORMAdapter.prototype.LMSCommit = function () {
190
+ var _this = this;
181
191
  var result = this._callAPIFunction("Commit");
182
- var success = eval(result.toString());
183
- return success || this._errorCallback("commitFailed");
192
+ if ("then" in result && typeof result.then === "function") {
193
+ result.then(function (success) {
194
+ if (!_this.validateResult(success)) {
195
+ _this._errorCallback("commitFailed");
196
+ }
197
+ });
198
+ return true;
199
+ }
200
+ else {
201
+ var success = this.validateResult(result);
202
+ return success || this._errorCallback("commitFailed");
203
+ }
184
204
  };
185
205
  SCORMAdapter.prototype.LMSGetLastError = function () {
186
206
  return parseInt(this._callAPIFunction("GetLastError"));
@@ -360,12 +380,12 @@ var convertToTimeInterval = function (milliseconds) {
360
380
  var minutes = data.minutes % 60;
361
381
  var seconds = data.seconds % 60;
362
382
  var cents = data.cents % 100;
363
- var daysString = days ? days + 'D' : '';
364
- var hoursString = hours ? hours + 'H' : '';
365
- var minutesString = minutes ? minutes + 'M' : '';
366
- var secondsString = seconds || '0' + (cents ? '.' + cents : '') + 'S';
367
- var hms = [hoursString, minutesString, secondsString].join('');
368
- return 'P' + daysString + 'T' + hms;
383
+ var daysString = days ? days + "D" : "";
384
+ var hoursString = hours ? hours + "H" : "";
385
+ var minutesString = minutes ? minutes + "M" : "";
386
+ var secondsString = seconds || "0" + (cents ? "." + cents : "") + "S";
387
+ var hms = [hoursString, minutesString, secondsString].join("");
388
+ return "P" + daysString + "T" + hms;
369
389
  };
370
390
  exports.convertToTimeInterval = convertToTimeInterval;
371
391
  var convertMsToCMITimespan = function (milliseconds) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@didask/scol-r",
3
- "version": "2.5.3",
3
+ "version": "2.6.0",
4
4
  "description": "Shareable Cross-Origin Learning Resources",
5
5
  "main": "index.html",
6
6
  "types": "lib/index.d.ts",
@@ -1 +0,0 @@
1
- export {};
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var bun_test_1 = require("bun:test");
4
- var SCORMAdapter_1 = require("./SCORMAdapter");
5
- bun_test_1.test('convertMsToCMITimespan ("0000:00:00.00")', function () {
6
- var milliseconds = (36 * 60 * 60 * 1000) + (6 * 60 * 1000) + (2 * 1000) + (23 * 10);
7
- var CMITimespan = SCORMAdapter_1.convertMsToCMITimespan(milliseconds);
8
- bun_test_1.expect(CMITimespan).toBe('0036:06:02.23');
9
- });
10
- bun_test_1.test('convertToTimeInterval', function () {
11
- var milliseconds = (36 * 60 * 60 * 1000) + (6 * 60 * 1000) + (2 * 1000) + (23 * 10);
12
- var timeInterval = SCORMAdapter_1.convertToTimeInterval(milliseconds);
13
- bun_test_1.expect(timeInterval).toBe('P1DT12H6M2');
14
- });