@didask/scol-r 2.2.0 → 2.2.2

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.
@@ -2,6 +2,7 @@ export declare class SCORMAdapter {
2
2
  private _API;
3
3
  private _isSCORM2004;
4
4
  private _errorCallback;
5
+ private _lastRequest;
5
6
  private _ignorableErrorCodes;
6
7
  constructor(errorCallback?: Function);
7
8
  get foundAPI(): boolean;
@@ -19,6 +20,10 @@ export declare class SCORMAdapter {
19
20
  LMSGetLastError(): number;
20
21
  LMSGetErrorString(errorCode: number): any;
21
22
  LMSGetDiagnostic(errorCode: number): any;
23
+ get lastRequest(): {
24
+ method: "get" | "set";
25
+ key: string;
26
+ };
22
27
  getDataFromLMS(): any;
23
28
  getLearnerId(): any;
24
29
  setScore(score: number): void;
@@ -5,12 +5,36 @@ var SCORMAdapter = /** @class */ (function () {
5
5
  function SCORMAdapter(errorCallback) {
6
6
  if (errorCallback === void 0) { errorCallback = function () { }; }
7
7
  this._ignorableErrorCodes = [
8
- { code: 0 },
9
- { code: 403, scope: "2004" },
8
+ { code: 0, shouldBeIgnored: true },
9
+ {
10
+ code: 403,
11
+ get shouldBeIgnored() {
12
+ return this._isSCORM2004;
13
+ },
14
+ },
15
+ {
16
+ code: 401,
17
+ get shouldBeIgnored() {
18
+ return (!this._isSCORM2004 &&
19
+ this._lastRequest &&
20
+ this._lastRequest.method === "get" &&
21
+ this._lastRequest.key === "cmi.objectives._children");
22
+ },
23
+ },
24
+ {
25
+ code: 402,
26
+ get shouldBeIgnored() {
27
+ return (this._isSCORM2004 &&
28
+ this._lastRequest &&
29
+ this._lastRequest.method === "get" &&
30
+ this._lastRequest.key === "cmi.objectives._children");
31
+ },
32
+ },
10
33
  ];
11
34
  this._API = null;
12
35
  this._isSCORM2004 = false;
13
36
  this._errorCallback = errorCallback;
37
+ this._lastRequest = null;
14
38
  this._findAndSetAPI();
15
39
  }
16
40
  Object.defineProperty(SCORMAdapter.prototype, "foundAPI", {
@@ -31,7 +55,6 @@ var SCORMAdapter = /** @class */ (function () {
31
55
  }
32
56
  };
33
57
  SCORMAdapter.prototype._findAndSetAPI = function () {
34
- var _this = this;
35
58
  if (typeof window === "undefined") {
36
59
  console.error("Unable to find an API adapter");
37
60
  }
@@ -48,10 +71,6 @@ var SCORMAdapter = /** @class */ (function () {
48
71
  else {
49
72
  this._API = theAPI["API"];
50
73
  this._isSCORM2004 = theAPI["isSCORM2004"];
51
- this._ignorableErrorCodes = this._ignorableErrorCodes.filter(function (_a) {
52
- var scope = _a.scope;
53
- return !scope || (_this._isSCORM2004 ? scope === "2004" : scope === "1.2");
54
- });
55
74
  }
56
75
  if (this._API == null) {
57
76
  console.error("Couldn't find the API!");
@@ -105,8 +124,8 @@ var SCORMAdapter = /** @class */ (function () {
105
124
  var lastErrorString = this.LMSGetErrorString(lastErrorCode);
106
125
  var lastErrorDiagnostic = this.LMSGetDiagnostic(lastErrorCode);
107
126
  if (!this._ignorableErrorCodes.some(function (_a) {
108
- var code = _a.code;
109
- return code === lastErrorCode;
127
+ var code = _a.code, shouldBeIgnored = _a.shouldBeIgnored;
128
+ return code === lastErrorCode && shouldBeIgnored;
110
129
  })) {
111
130
  console.warn(functionName, "An error occured on the SCORM API: code " + lastErrorCode + ", message: " + lastErrorString, lastErrorDiagnostic);
112
131
  this._errorCallback(lastErrorString, lastErrorDiagnostic && lastErrorDiagnostic != lastErrorCode
@@ -138,12 +157,14 @@ var SCORMAdapter = /** @class */ (function () {
138
157
  return success || this._handleError(functionName);
139
158
  };
140
159
  SCORMAdapter.prototype.LMSGetValue = function (name) {
160
+ this._lastRequest = { method: "get", key: name };
141
161
  var functionName = "GetValue";
142
162
  var value = this._callAPIFunction(functionName, [name]);
143
163
  var success = this.LMSGetLastError() === 0;
144
164
  return success ? value : this._handleError(functionName + ": " + name);
145
165
  };
146
166
  SCORMAdapter.prototype.LMSSetValue = function (name, value) {
167
+ this._lastRequest = { method: "set", key: name };
147
168
  var functionName = "SetValue";
148
169
  var result = this._callAPIFunction(functionName, [name, value]);
149
170
  var success = eval(result.toString());
@@ -163,6 +184,13 @@ var SCORMAdapter = /** @class */ (function () {
163
184
  SCORMAdapter.prototype.LMSGetDiagnostic = function (errorCode) {
164
185
  return this._callAPIFunction("GetDiagnostic", [errorCode]);
165
186
  };
187
+ Object.defineProperty(SCORMAdapter.prototype, "lastRequest", {
188
+ get: function () {
189
+ return this._lastRequest;
190
+ },
191
+ enumerable: false,
192
+ configurable: true
193
+ });
166
194
  SCORMAdapter.prototype.getDataFromLMS = function () {
167
195
  return this.LMSGetValue("cmi.launch_data");
168
196
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@didask/scol-r",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "Shareable Cross-Origin Learning Resources",
5
5
  "main": "index.html",
6
6
  "types": "lib/index.d.ts",