cassproject 5.0.20 → 5.0.23

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 (107) hide show
  1. package/package.json +49 -52
  2. package/src/com/eduworks/ec/array/EcArray.js +1 -1
  3. package/src/com/eduworks/ec/array/EcAsyncHelper.js +1 -1
  4. package/src/com/eduworks/ec/array/EcObject.js +1 -1
  5. package/src/com/eduworks/ec/crypto/EcAes.js +1 -1
  6. package/src/com/eduworks/ec/crypto/EcAesCtrAsync.js +20 -22
  7. package/src/com/eduworks/ec/crypto/EcCrypto.js +8 -4
  8. package/src/com/eduworks/ec/crypto/EcPk.js +7 -7
  9. package/src/com/eduworks/ec/crypto/EcPpk.js +7 -7
  10. package/src/com/eduworks/ec/crypto/EcRsaOaepAsync.js +20 -19
  11. package/src/com/eduworks/ec/crypto/EcRsaOaepAsyncWorker.js +7 -6
  12. package/src/com/eduworks/ec/crypto/forgeAsync.js +1 -9
  13. package/src/com/eduworks/ec/crypto/forgeAsyncNode.js +8 -8
  14. package/src/com/eduworks/ec/graph/EcDirectedGraph.js +1 -2
  15. package/src/com/eduworks/ec/graph/EcFrameworkGraph.js +18 -24
  16. package/src/com/eduworks/ec/promises/helpers.js +1 -3
  17. package/src/com/eduworks/ec/remote/EcRemote.js +9 -9
  18. package/src/com/eduworks/ec/task/EcAsyncTask.js +5 -20
  19. package/src/com/eduworks/ec/task/EcAsyncTaskManager.js +3 -4
  20. package/src/com/eduworks/ec/task/EcAsyncTaskWorker.js +9 -11
  21. package/src/com/eduworks/schema/cfd/competency/CfdFramework.js +36 -37
  22. package/src/com/eduworks/schema/ebac/EbacContact.js +3 -9
  23. package/src/com/eduworks/schema/ebac/EbacContactGrant.js +3 -9
  24. package/src/com/eduworks/schema/ebac/EbacCredential.js +3 -9
  25. package/src/com/eduworks/schema/ebac/EbacCredentialCommit.js +3 -9
  26. package/src/com/eduworks/schema/ebac/EbacCredentialRequest.js +3 -9
  27. package/src/com/eduworks/schema/ebac/EbacCredentials.js +3 -9
  28. package/src/com/eduworks/schema/ebac/EbacEncryptedSecret.js +3 -9
  29. package/src/com/eduworks/schema/ebac/EbacEncryptedValue.js +5 -12
  30. package/src/com/eduworks/schema/ebac/EbacSignature.js +1 -6
  31. package/src/index/env.js +6 -3
  32. package/src/index/polyfills.js +13 -27
  33. package/src/org/angles/schema/angles/VideoStory.js +1 -1
  34. package/src/org/cass/competency/EcCompetency.js +1 -2
  35. package/src/org/cass/competency/EcDirectory.js +1 -2
  36. package/src/org/cass/competency/EcFramework.js +9 -12
  37. package/src/org/cass/exporter/CSVExport.js +12 -13
  38. package/src/org/cass/importer/ASNImport.js +3 -6
  39. package/src/org/cass/importer/CSVImport.js +9 -17
  40. package/src/org/cass/importer/CTDLASNCSVConceptImport.js +25 -121
  41. package/src/org/cass/importer/CTDLASNCSVImport.js +88 -133
  42. package/src/org/cass/importer/FrameworkImport.js +16 -30
  43. package/src/org/cass/importer/MedbiqImport.js +3 -4
  44. package/src/org/cass/importer/TabStructuredImport.js +6 -6
  45. package/src/org/cass/profile/EcAssertion.js +40 -51
  46. package/src/org/cassproject/ebac/identity/EcContactGrant.js +2 -2
  47. package/src/org/cassproject/ebac/identity/EcIdentityManager.js +56 -62
  48. package/src/org/cassproject/ebac/identity/EcRekeyRequest.js +3 -2
  49. package/src/org/cassproject/ebac/identity/remote/EcRemoteIdentityManager.js +51 -62
  50. package/src/org/cassproject/ebac/identity/remote/OAuth2FileBasedRemoteIdentityManager.js +56 -70
  51. package/src/org/cassproject/ebac/identity/remote/RemoteIdentityManagerInterface.js +3 -3
  52. package/src/org/cassproject/ebac/repository/EcEncryptedValue.js +51 -44
  53. package/src/org/cassproject/ebac/repository/EcRepository.js +228 -301
  54. package/src/org/cassproject/general/repository/GeneralFile.js +8 -9
  55. package/src/org/cassproject/schema/cass/competency/Competency.js +10 -11
  56. package/src/org/cassproject/schema/cass/competency/Framework.js +10 -11
  57. package/src/org/cassproject/schema/cass/competency/Level.js +10 -11
  58. package/src/org/cassproject/schema/cass/competency/Relation.js +10 -11
  59. package/src/org/cassproject/schema/cass/competency/RollupRule.js +7 -7
  60. package/src/org/cassproject/schema/cass/profile/Assertion.js +20 -27
  61. package/src/org/cassproject/schema/cass/profile/AssertionEnvelope.js +3 -5
  62. package/src/org/cassproject/schema/general/EcRemoteLinkedData.js +41 -44
  63. package/src/org/json/ld/EcLinkedData.js +10 -12
  64. package/src/org/schema/EcOrganization.js +10 -10
  65. package/src/org/schema/EcQuestion.js +8 -8
  66. package/src/org/w3/skos/Concept.js +6 -6
  67. package/src/org/w3/skos/ConceptScheme.js +6 -6
  68. package/src/org/w3/skos/EcConcept.js +1 -2
  69. package/src/org/w3/skos/EcConceptScheme.js +1 -2
  70. package/src/test/0.start.test.js +1 -1
  71. package/src/test/0.testLibraries.test.js +172 -0
  72. package/src/test/1.ASNImport.test.js +122 -0
  73. package/src/test/1.CSVExport.test.js +57 -0
  74. package/src/test/1.CSVImport.test.js +185 -0
  75. package/src/test/1.CTDLASNCSVConceptImport.test.js +348 -0
  76. package/src/test/1.CTDLASNCSVImport.import.test.js +497 -0
  77. package/src/test/1.Ebac.schema.test.js +107 -0
  78. package/src/test/1.EcAssertion.decrypt.test.js +98 -0
  79. package/src/test/1.EcAssertion.pinned.test.js +160 -0
  80. package/src/test/1.EcCrypto.formats.test.js +293 -0
  81. package/src/test/1.EcCrypto.generateUUID.test.js +47 -0
  82. package/src/test/1.EcEncryptedValue.helpers.test.js +236 -0
  83. package/src/test/1.EcHelpers.misc.test.js +259 -0
  84. package/src/test/1.EcIdentityManager.keys.test.js +439 -0
  85. package/src/test/1.EcOrganization.rekey.test.js +68 -0
  86. package/src/test/1.EcRemote.responses.test.js +155 -0
  87. package/src/test/1.EcRemoteIdentityManager.flows.test.js +326 -0
  88. package/src/test/1.EcRemoteLinkedData.pinned.test.js +473 -0
  89. package/src/test/1.EcRepository.l0.test.js +14 -5
  90. package/src/test/1.EcRepository.l1.test.js +16 -7
  91. package/src/test/1.EcRepository.l2.test.js +20 -11
  92. package/src/test/1.EcRepository.unit.test.js +961 -0
  93. package/src/test/1.EcRsaOaep.test.js +2 -12
  94. package/src/test/1.EcRsaOaepAsync.test.js +2 -12
  95. package/src/test/1.EcRsaOaepAsyncWorker.test.js +2 -12
  96. package/src/test/1.EcRsaOaepAsyncWorker.workers.test.js +147 -0
  97. package/src/test/1.FrameworkImport.test.js +170 -0
  98. package/src/test/1.MedbiqImport.test.js +92 -0
  99. package/src/test/1.OAuth2FileBasedRemoteIdentityManager.test.js +399 -0
  100. package/src/test/1.TabStructuredImport.test.js +61 -0
  101. package/src/test/1.polyfills.test.js +89 -0
  102. package/src/test/1.schema.competency.pinned.test.js +384 -0
  103. package/src/test/3.EcFrameworkGraph.test.js +3 -2
  104. package/src/test/4.schema.test.js +33 -28
  105. package/src/test/4.skyId.test.js +4 -2
  106. package/src/test/cypressValue.js +9 -0
  107. package/src/test/2.EcCompetency.test.js +0 -17
@@ -11,8 +11,8 @@ module.exports = class GeneralFile extends EcRemoteLinkedData {
11
11
  constructor() {
12
12
  super(General.context, GeneralFile.myType);
13
13
  }
14
- static TYPE_0_1 = "http://schema.eduworks.com/general/0.1/file";
15
- static TYPE_0_2 = "http://schema.eduworks.com/general/0.2/file";
14
+ static TYPE_0_1 = "http://schema.eduworks.com/general/0.1/file"; // NOSONAR - JSON-LD identifier, never fetched
15
+ static TYPE_0_2 = "http://schema.eduworks.com/general/0.2/file"; // NOSONAR - JSON-LD identifier, never fetched
16
16
  static myType = this.TYPE_0_2;
17
17
  /**
18
18
  * Optional checksum of the file, used to verify if the file has been
@@ -56,16 +56,15 @@ module.exports = class GeneralFile extends EcRemoteLinkedData {
56
56
  upgrade() {
57
57
  super.upgrade();
58
58
  if (GeneralFile.TYPE_0_1 == (this.type)) {
59
- let me = this;
60
- if (me["@context"] == null && me["@schema"] != null)
61
- me["@context"] = me["@schema"];
59
+ if (this["@context"] == null && this["@schema"] != null)
60
+ this["@context"] = this["@schema"];
62
61
  this.setContextAndType(General.context_0_2, GeneralFile.TYPE_0_2);
63
62
  }
64
63
  }
65
64
  getTypes() {
66
- let a = [];
67
- a.push(GeneralFile.TYPE_0_2);
68
- a.push(GeneralFile.TYPE_0_1);
69
- return a;
65
+ return [
66
+ GeneralFile.TYPE_0_2,
67
+ GeneralFile.TYPE_0_1,
68
+ ];
70
69
  }
71
70
  };
@@ -37,9 +37,8 @@ module.exports = class Competency extends schema.CreativeWork {
37
37
  this.sameAs = this.url;
38
38
  this.url = null;
39
39
  }
40
- let me = this;
41
- if (me["@context"] == null && me["@schema"] != null)
42
- me["@context"] = me["@schema"];
40
+ if (this["@context"] == null && this["@schema"] != null)
41
+ this["@context"] = this["@schema"];
43
42
  this.setContextAndType(Cass.context_0_2, Competency.TYPE_0_2);
44
43
  }
45
44
  if (Competency.TYPE_0_2 == this.getFullType()) {
@@ -56,13 +55,13 @@ module.exports = class Competency extends schema.CreativeWork {
56
55
  }
57
56
  }
58
57
  getTypes() {
59
- let a = [];
60
- a.push(Competency.TYPE_0_6);
61
- a.push(Competency.TYPE_0_5);
62
- a.push(Competency.TYPE_0_4);
63
- a.push(Competency.TYPE_0_3);
64
- a.push(Competency.TYPE_0_2);
65
- a.push(Competency.TYPE_0_1);
66
- return a;
58
+ return [
59
+ Competency.TYPE_0_6,
60
+ Competency.TYPE_0_5,
61
+ Competency.TYPE_0_4,
62
+ Competency.TYPE_0_3,
63
+ Competency.TYPE_0_2,
64
+ Competency.TYPE_0_1,
65
+ ];
67
66
  }
68
67
  };
@@ -61,9 +61,8 @@ module.exports = class Framework extends schema.CreativeWork {
61
61
  upgrade() {
62
62
  super.upgrade();
63
63
  if (Framework.TYPE_0_1 == (this.type)) {
64
- let me = this;
65
- if (me["@context"] == null && me["@schema"] != null)
66
- me["@context"] = me["@schema"];
64
+ if (this["@context"] == null && this["@schema"] != null)
65
+ this["@context"] = this["@schema"];
67
66
  this.setContextAndType(Cass.context_0_2, Framework.TYPE_0_2);
68
67
  }
69
68
  if (Framework.TYPE_0_2 == (this.getFullType())) {
@@ -80,13 +79,13 @@ module.exports = class Framework extends schema.CreativeWork {
80
79
  }
81
80
  }
82
81
  getTypes() {
83
- let a = [];
84
- a.push(Framework.TYPE_0_6);
85
- a.push(Framework.TYPE_0_5);
86
- a.push(Framework.TYPE_0_4);
87
- a.push(Framework.TYPE_0_3);
88
- a.push(Framework.TYPE_0_2);
89
- a.push(Framework.TYPE_0_1);
90
- return a;
82
+ return [
83
+ Framework.TYPE_0_6,
84
+ Framework.TYPE_0_5,
85
+ Framework.TYPE_0_4,
86
+ Framework.TYPE_0_3,
87
+ Framework.TYPE_0_2,
88
+ Framework.TYPE_0_1,
89
+ ];
91
90
  }
92
91
  };
@@ -48,9 +48,8 @@ module.exports = class Level extends schema.CreativeWork {
48
48
  upgrade() {
49
49
  super.upgrade();
50
50
  if (Level.TYPE_0_1 == (this.type)) {
51
- let me = this;
52
- if (me["@context"] == null && me["@schema"] != null)
53
- me["@context"] = me["@schema"];
51
+ if (this["@context"] == null && this["@schema"] != null)
52
+ this["@context"] = this["@schema"];
54
53
  this.setContextAndType(Cass.context_0_2, Level.TYPE_0_2);
55
54
  }
56
55
  if (Level.TYPE_0_2 == (this.getFullType())) {
@@ -67,13 +66,13 @@ module.exports = class Level extends schema.CreativeWork {
67
66
  }
68
67
  }
69
68
  getTypes() {
70
- let a = [];
71
- a.push(Level.TYPE_0_6);
72
- a.push(Level.TYPE_0_5);
73
- a.push(Level.TYPE_0_4);
74
- a.push(Level.TYPE_0_3);
75
- a.push(Level.TYPE_0_2);
76
- a.push(Level.TYPE_0_1);
77
- return a;
69
+ return [
70
+ Level.TYPE_0_6,
71
+ Level.TYPE_0_5,
72
+ Level.TYPE_0_4,
73
+ Level.TYPE_0_3,
74
+ Level.TYPE_0_2,
75
+ Level.TYPE_0_1,
76
+ ];
78
77
  }
79
78
  };
@@ -130,9 +130,8 @@ module.exports = class Relation extends schema.CreativeWork {
130
130
  if ("isEquivalenTo" == this.relationType)
131
131
  this.relationType = Relation.IS_EQUIVALENT_TO;
132
132
  if (Relation.TYPE_0_1 == this.type) {
133
- let me = this;
134
- if (me["@context"] == null && me["@schema"] != null)
135
- me["@context"] = me["@schema"];
133
+ if (this["@context"] == null && this["@schema"] != null)
134
+ this["@context"] = this["@schema"];
136
135
  this.setContextAndType(Cass.context_0_2, Relation.TYPE_0_2);
137
136
  }
138
137
  if (Relation.TYPE_0_2 == this.getFullType()) {
@@ -149,13 +148,13 @@ module.exports = class Relation extends schema.CreativeWork {
149
148
  }
150
149
  }
151
150
  getTypes() {
152
- let a = [];
153
- a.push(Relation.TYPE_0_6);
154
- a.push(Relation.TYPE_0_5);
155
- a.push(Relation.TYPE_0_4);
156
- a.push(Relation.TYPE_0_3);
157
- a.push(Relation.TYPE_0_2);
158
- a.push(Relation.TYPE_0_1);
159
- return a;
151
+ return [
152
+ Relation.TYPE_0_6,
153
+ Relation.TYPE_0_5,
154
+ Relation.TYPE_0_4,
155
+ Relation.TYPE_0_3,
156
+ Relation.TYPE_0_2,
157
+ Relation.TYPE_0_1,
158
+ ];
160
159
  }
161
160
  };
@@ -52,12 +52,12 @@ module.exports = class RollupRule extends schema.CreativeWork {
52
52
  }
53
53
  }
54
54
  getTypes() {
55
- let a = [];
56
- a.push(RollupRule.TYPE_0_6);
57
- a.push(RollupRule.TYPE_0_5);
58
- a.push(RollupRule.TYPE_0_4);
59
- a.push(RollupRule.TYPE_0_3);
60
- a.push(RollupRule.TYPE_0_2);
61
- return a;
55
+ return [
56
+ RollupRule.TYPE_0_6,
57
+ RollupRule.TYPE_0_5,
58
+ RollupRule.TYPE_0_4,
59
+ RollupRule.TYPE_0_3,
60
+ RollupRule.TYPE_0_2,
61
+ ];
62
62
  }
63
63
  };
@@ -115,16 +115,10 @@ module.exports = class Assertion extends schema.CreativeWork {
115
115
  * @param pk
116
116
  */
117
117
  setSubject(pk) {
118
- let owners = [];
119
118
  let readers = this.reader;
120
119
  if (readers == null) readers = [];
121
- if (this.subject != null) {
122
- if (this.subject.owner != null)
123
- owners = owners.concat(this.subject.owner);
124
- if (this.subject.reader != null)
125
- readers = readers.concat(this.subject.reader);
126
- }
127
- if (this.owner != null) owners = owners.concat(this.owner);
120
+ if (this.subject?.reader != null)
121
+ readers = readers.concat(this.subject.reader);
128
122
  readers.push(pk.toPem());
129
123
  this.subject = pk.toPem();
130
124
  }
@@ -146,10 +140,10 @@ module.exports = class Assertion extends schema.CreativeWork {
146
140
  if (this.subject == null) return "Nobody";
147
141
  let subjectPk = this.getSubject();
148
142
  let identity = eim.getIdentity(subjectPk);
149
- if (identity != null && identity.displayName != null)
143
+ if (identity?.displayName != null)
150
144
  return identity.displayName + " (You)";
151
145
  let contact = eim.getContact(subjectPk);
152
- if (contact == null || contact.displayName == null)
146
+ if (contact?.displayName == null)
153
147
  return "Unknown Subject";
154
148
  return contact.displayName;
155
149
  }
@@ -162,12 +156,12 @@ module.exports = class Assertion extends schema.CreativeWork {
162
156
  }
163
157
  this.getSubjectAsync(function(subjectPk) {
164
158
  let identity = eim.getIdentity(subjectPk);
165
- if (identity != null && identity.displayName != null) {
159
+ if (identity?.displayName != null) {
166
160
  success(identity.displayName + " (You)");
167
161
  return;
168
162
  }
169
163
  let contact = eim.getContact(subjectPk);
170
- if (contact == null || contact.displayName == null) {
164
+ if (contact?.displayName == null) {
171
165
  success("Unknown Subject");
172
166
  return;
173
167
  }
@@ -180,10 +174,10 @@ module.exports = class Assertion extends schema.CreativeWork {
180
174
  if (this.agent == null) return "Nobody";
181
175
  let agentPk = this.getAgent();
182
176
  let identity = eim.getIdentity(agentPk);
183
- if (identity != null && identity.displayName != null)
177
+ if (identity?.displayName != null)
184
178
  return identity.displayName + " (You)";
185
179
  let contact = eim.getContact(agentPk);
186
- if (contact == null || contact.displayName == null)
180
+ if (contact?.displayName == null)
187
181
  return "Unknown Agent";
188
182
  return contact.displayName;
189
183
  }
@@ -196,12 +190,12 @@ module.exports = class Assertion extends schema.CreativeWork {
196
190
  }
197
191
  this.getAgentAsync(function(subjectPk) {
198
192
  let identity = eim.getIdentity(subjectPk);
199
- if (identity != null && identity.displayName != null) {
193
+ if (identity?.displayName != null) {
200
194
  success(identity.displayName + " (You)");
201
195
  return;
202
196
  }
203
197
  let contact = eim.getContact(subjectPk);
204
- if (contact == null || contact.displayName == null) {
198
+ if (contact?.displayName == null) {
205
199
  success("Unknown Agent");
206
200
  return;
207
201
  }
@@ -269,9 +263,8 @@ module.exports = class Assertion extends schema.CreativeWork {
269
263
  upgrade() {
270
264
  super.upgrade();
271
265
  if (Assertion.TYPE_0_1 == (this.type)) {
272
- let me = this;
273
- if (me["@context"] == null && me["@schema"] != null)
274
- me["@context"] = me["@schema"];
266
+ if (this["@context"] == null && this["@schema"] != null)
267
+ this["@context"] = this["@schema"];
275
268
  this.setContextAndType(Cass.context_0_2, Assertion.TYPE_0_2);
276
269
  }
277
270
  if (Assertion.TYPE_0_2 == (this.getFullType())) {
@@ -298,14 +291,14 @@ module.exports = class Assertion extends schema.CreativeWork {
298
291
  }
299
292
  }
300
293
  getTypes() {
301
- let a = [];
302
- a.push(Assertion.TYPE_0_6);
303
- a.push(Assertion.TYPE_0_5);
304
- a.push(Assertion.TYPE_0_4);
305
- a.push(Assertion.TYPE_0_3);
306
- a.push(Assertion.TYPE_0_2);
307
- a.push(Assertion.TYPE_0_1);
308
- return a;
294
+ return [
295
+ Assertion.TYPE_0_6,
296
+ Assertion.TYPE_0_5,
297
+ Assertion.TYPE_0_4,
298
+ Assertion.TYPE_0_3,
299
+ Assertion.TYPE_0_2,
300
+ Assertion.TYPE_0_1,
301
+ ];
309
302
  }
310
303
  static getCodebook(assertion) {
311
304
  if (Assertion.codebooks == null) Assertion.codebooks = {};
@@ -88,7 +88,6 @@ module.exports = class AssertionEnvelope extends schema.CreativeWork {
88
88
  * @method addAssertion
89
89
  */
90
90
  async addAssertion(a, eim) {
91
- let me = this;
92
91
  let ac = new AssertionCodebook();
93
92
  if (this.assertion == null) this.assertion = [];
94
93
  this.assertion.push(a);
@@ -105,9 +104,8 @@ module.exports = class AssertionEnvelope extends schema.CreativeWork {
105
104
  ac.decayFunction = await a.decayFunction.decryptSecret(eim);
106
105
  if (a.negative != null) ac.negative = await a.negative.decryptSecret(eim);
107
106
  if (a.evidence != null)
108
- for (let i = 0; i < a.evidence.length; i++) {
107
+ for (let ecEncryptedValue of a.evidence) {
109
108
  if (ac.evidence == null) ac.evidence = [];
110
- let ecEncryptedValue = a.evidence[i];
111
109
  ac.evidence.push(await ecEncryptedValue.decryptSecret(eim));
112
110
  }
113
111
  }
@@ -119,8 +117,8 @@ module.exports = class AssertionEnvelope extends schema.CreativeWork {
119
117
  */
120
118
  validate() {
121
119
  if (this.assertion != null)
122
- for (let i = 0; i < this.assertion.length; i++)
123
- if (this.assertion[i].invalid()) return false;
120
+ for (let assertion of this.assertion)
121
+ if (assertion.invalid()) return false;
124
122
  return true;
125
123
  }
126
124
  };
@@ -87,14 +87,14 @@ module.exports = class EcRemoteLinkedData extends EcLinkedData {
87
87
  if (EcRemoteLinkedData.caching && EcRemoteLinkedData.tvfuCache[id] != null)
88
88
  return EcRemoteLinkedData.tvfuCache[id];
89
89
  if (
90
- id.indexOf("/api/data/") == -1 &&
91
- id.indexOf("/api/custom/data/") == -1
90
+ !id.includes("/api/data/") &&
91
+ !id.includes("/api/custom/data/")
92
92
  ) {
93
93
  if (EcRemoteLinkedData.caching)
94
94
  EcRemoteLinkedData.tvfuCache[id] = id;
95
95
  return id;
96
96
  }
97
- if (!id.substring(id.lastIndexOf("/")).match("^\\/[0-9]+$")) {
97
+ if (!id.substring(id.lastIndexOf("/")).match(String.raw`^\/[0-9]+$`)) {
98
98
  if (EcRemoteLinkedData.caching)
99
99
  EcRemoteLinkedData.tvfuCache[id] = id;
100
100
  return id;
@@ -120,7 +120,7 @@ module.exports = class EcRemoteLinkedData extends EcLinkedData {
120
120
  this.id += "/";
121
121
  this.id += EcCrypto.generateUUID();
122
122
  this.id += "/";
123
- this.id += new Date().getTime();
123
+ this.id += Date.now();
124
124
  }
125
125
  /**
126
126
  * Will generate an short (non-versioned) identifier using the server URL provided (usually from
@@ -138,7 +138,7 @@ module.exports = class EcRemoteLinkedData extends EcLinkedData {
138
138
  return this.getFullType()
139
139
  .replace("http://", "")
140
140
  .replace("https://", "")
141
- .replace(/\//g, ".");
141
+ .replaceAll("/", ".");
142
142
  }
143
143
  /**
144
144
  * Will generate an identifier using the server URL provided (usually from
@@ -156,7 +156,7 @@ module.exports = class EcRemoteLinkedData extends EcLinkedData {
156
156
  this.id += "/";
157
157
  this.id += uniqueIdentifier;
158
158
  this.id += "/";
159
- this.id += new Date().getTime();
159
+ this.id += Date.now();
160
160
  }
161
161
  /**
162
162
  * Will generate an identifier using the server URL provided (usually from
@@ -298,8 +298,7 @@ module.exports = class EcRemoteLinkedData extends EcLinkedData {
298
298
  works = false;
299
299
  let sig = this.signature[i];
300
300
  if (this.owner != null) {
301
- for (let j = 0; j < this.owner.length; j++) {
302
- let own = this.owner[j];
301
+ for (let own of this.owner) {
303
302
  let pk = EcPk.fromPem(own);
304
303
  let verify = false;
305
304
  try {
@@ -309,10 +308,10 @@ module.exports = class EcRemoteLinkedData extends EcLinkedData {
309
308
  sig
310
309
  );
311
310
  global.auditLogger.report(global.auditLogger.LogCategory.SYSTEM, global.auditLogger.Severity.INFO, "EcRemoteLDVerify", verify);
312
- } catch (ex) {
311
+ } catch (ex) { // NOSONAR - A signature that cannot be checked counts as unverified; the next owner is tried.
313
312
  verify = false;
314
313
  }
315
- if (verify == true) {
314
+ if (verify == true) { // NOSONAR - The worker result is not guaranteed to be a boolean; == true also accepts 1.
316
315
  works = true;
317
316
  break;
318
317
  }
@@ -328,8 +327,7 @@ module.exports = class EcRemoteLinkedData extends EcLinkedData {
328
327
  works256 = false;
329
328
  let sig = this.signatureSha256[i];
330
329
  if (this.owner != null) {
331
- for (let j = 0; j < this.owner.length; j++) {
332
- let own = this.owner[j];
330
+ for (let own of this.owner) {
333
331
  let pk = EcPk.fromPem(own);
334
332
  let verify = false;
335
333
  try {
@@ -339,10 +337,10 @@ module.exports = class EcRemoteLinkedData extends EcLinkedData {
339
337
  sig
340
338
  );
341
339
  global.auditLogger.report(global.auditLogger.LogCategory.SYSTEM, global.auditLogger.Severity.INFO, "EcRemoteLDVer256", verify);
342
- } catch (ex) {
340
+ } catch (ex) { // NOSONAR - A signature that cannot be checked counts as unverified; the next owner is tried.
343
341
  verify = false;
344
342
  }
345
- if (verify == true) {
343
+ if (verify == true) { // NOSONAR - The worker result is not guaranteed to be a boolean; == true also accepts 1.
346
344
  works256 = true;
347
345
  break;
348
346
  }
@@ -367,8 +365,8 @@ module.exports = class EcRemoteLinkedData extends EcLinkedData {
367
365
  addOwner(newOwner) {
368
366
  let pem = newOwner.toPem();
369
367
  if (this.owner == null) this.owner = [];
370
- for (let i = 0; i < this.owner.length; i++)
371
- if (this.owner[i] == pem) return;
368
+ for (let owner of this.owner)
369
+ if (owner == pem) return;
372
370
  this.owner.push(pem);
373
371
  this.signature = null;
374
372
  }
@@ -423,8 +421,8 @@ module.exports = class EcRemoteLinkedData extends EcLinkedData {
423
421
  if (this.context == null) return true;
424
422
  if (this.getFullType() == null) return true;
425
423
  if (
426
- this.getFullType().indexOf("http://") == -1 &&
427
- this.getFullType().indexOf("https://") == -1
424
+ !this.getFullType().includes("http://") &&
425
+ !this.getFullType().includes("https://")
428
426
  )
429
427
  return true;
430
428
  return false;
@@ -437,8 +435,8 @@ module.exports = class EcRemoteLinkedData extends EcLinkedData {
437
435
  updateTimestamp() {
438
436
  if (this.getTimestamp() == null) return;
439
437
  let rawId = this.id.substring(0, this.id.lastIndexOf("/"));
440
- if (rawId.endsWith("/") == false) rawId += "/";
441
- rawId += new Date().getTime();
438
+ if (!rawId.endsWith("/")) rawId += "/";
439
+ rawId += Date.now();
442
440
  this.id = rawId;
443
441
  }
444
442
  /**
@@ -459,7 +457,7 @@ module.exports = class EcRemoteLinkedData extends EcLinkedData {
459
457
  if (!id) return null;
460
458
  let timestamp = id.substring(id.lastIndexOf("/") + 1);
461
459
  if (timestamp.match("^[0-9]+$")) {
462
- return parseInt(timestamp);
460
+ return Number.parseInt(timestamp);
463
461
  } else {
464
462
  return null;
465
463
  }
@@ -530,28 +528,28 @@ module.exports = class EcRemoteLinkedData extends EcLinkedData {
530
528
  types[i].substring(lastSlash + 1) +
531
529
  '")';
532
530
  }
533
- for (let i = 0; i < types.length; i++) {
531
+ for (let type of types) {
534
532
  if (result != "") result += " OR ";
535
- result += '\\*encryptedType:"' + types[i] + '"';
536
- let lastSlash = types[i].lastIndexOf("/");
533
+ result += String.raw`\*encryptedType:"` + type + '"';
534
+ let lastSlash = type.lastIndexOf("/");
537
535
  result +=
538
536
  ' OR (@context:"' +
539
537
  Ebac.context +
540
- '" AND \\*encryptedType:"' +
541
- types[i].substring(lastSlash + 1) +
538
+ String.raw`" AND \*encryptedType:"` +
539
+ type.substring(lastSlash + 1) +
542
540
  '")';
543
541
  }
544
542
  //Replace http with https in schema or visa versa and then do it again
545
- for (let i = 0; i < types.length; i++) {
543
+ for (let type of types) {
546
544
  if (result != "") result += " OR ";
547
- let lastSlash = types[i].lastIndexOf("/");
548
- let context = types[i].substring(0, lastSlash + 1);
545
+ let lastSlash = type.lastIndexOf("/");
546
+ let context = type.substring(0, lastSlash + 1);
549
547
  if (context.startsWith("http://")) {
550
548
  let httpsContext = context.replace("http://", "https://");
551
- result += '(@context:"' + httpsContext + '" AND @type:"' + types[i].substring(lastSlash + 1) + '")';
549
+ result += '(@context:"' + httpsContext + '" AND @type:"' + type.substring(lastSlash + 1) + '")';
552
550
  } else if (context.startsWith("https://")) {
553
551
  let httpContext = context.replace("https://", "http://");
554
- result += '(@context:"' + httpContext + '" AND @type:"' + types[i].substring(lastSlash + 1) + '")';
552
+ result += '(@context:"' + httpContext + '" AND @type:"' + type.substring(lastSlash + 1) + '")';
555
553
  }
556
554
  }
557
555
  return "(" + result + ")";
@@ -610,24 +608,23 @@ module.exports = class EcRemoteLinkedData extends EcLinkedData {
610
608
  * @method upgrade
611
609
  */
612
610
  upgrade() {
613
- let me = this;
614
- if (me["@owner"] != null) {
615
- me["owner"] = me["@owner"];
611
+ if (this["@owner"] != null) {
612
+ this["owner"] = this["@owner"];
616
613
  }
617
- if (me["@reader"] != null) {
618
- me["reader"] = me["@reader"];
614
+ if (this["@reader"] != null) {
615
+ this["reader"] = this["@reader"];
619
616
  }
620
- if (me["@signature"] != null) {
621
- me["signature"] = me["@signature"];
617
+ if (this["@signature"] != null) {
618
+ this["signature"] = this["@signature"];
622
619
  }
623
- if (me["@signatureSha256"] != null) {
624
- me["signatureSha256"] = me["@signatureSha256"];
620
+ if (this["@signatureSha256"] != null) {
621
+ this["signatureSha256"] = this["@signatureSha256"];
625
622
  }
626
- if (me["@encryptedType"] != null) {
627
- me["encryptedType"] = me["@encryptedType"];
623
+ if (this["@encryptedType"] != null) {
624
+ this["encryptedType"] = this["@encryptedType"];
628
625
  }
629
- if (me["@encryptedContext"] != null) {
630
- me["encryptedContext"] = me["@encryptedContext"];
626
+ if (this["@encryptedContext"] != null) {
627
+ this["encryptedContext"] = this["@encryptedContext"];
631
628
  }
632
629
  this.handleForwarding();
633
630
  }
@@ -181,7 +181,7 @@ global.jsonld = require("jsonld");
181
181
  */
182
182
  getFullType() {
183
183
  if (this.context == null) return this.type;
184
- if (this.type.indexOf("http") != -1) return this.type;
184
+ if (this.type.includes("http")) return this.type;
185
185
  let computedType = this.context;
186
186
  if (EcObject.isObject(this.context)) {
187
187
  let typeParts = this.type.split(":");
@@ -266,7 +266,6 @@ global.jsonld = require("jsonld");
266
266
  }
267
267
  }
268
268
  async recast(translationContext, targetContext, documentLoader) {
269
- let me = this;
270
269
  let json = JSON.parse(this.toJson());
271
270
  if (targetContext == null) targetContext = json["@context"];
272
271
  json["@context"] = translationContext;
@@ -286,15 +285,15 @@ global.jsonld = require("jsonld");
286
285
  let o;
287
286
  try {
288
287
  o = await jsonld.compact(actual, finalTargetContext, docLoader);
289
- } catch(s) {
290
- if (s != null) {
291
- global.auditLogger.report(global.auditLogger.LogCategory.SYSTEM, global.auditLogger.Severity.ERROR, "EcLinkedDataRecast", s);
288
+ } catch(error_) {
289
+ if (error_ != null) {
290
+ global.auditLogger.report(global.auditLogger.LogCategory.SYSTEM, global.auditLogger.Severity.ERROR, "EcLinkedDataRecast", error_);
292
291
  return;
293
292
  }
294
293
  }
295
- me.copyFrom(o);
296
- me["@context"] = finalTargetContext;
297
- return me;
294
+ this.copyFrom(o);
295
+ this["@context"] = finalTargetContext;
296
+ return this;
298
297
  }
299
298
  /**
300
299
  * Encodes the object in a form where it is ready to be signed.
@@ -306,8 +305,8 @@ global.jsonld = require("jsonld");
306
305
  toSignableJson() {
307
306
  let d = JSON.parse(this.toJson());
308
307
  if (
309
- this.type.indexOf("http://schema.eduworks.com/") == 0 &&
310
- this.type.indexOf("/0.1/") != -1
308
+ this.type.indexOf("http://schema.eduworks.com/") == 0 && // NOSONAR - JSON-LD identifier, never fetched
309
+ this.type.includes("/0.1/")
311
310
  ) {
312
311
  delete d["signature"];
313
312
  delete d["owner"];
@@ -377,10 +376,9 @@ global.jsonld = require("jsonld");
377
376
  return a;
378
377
  }
379
378
  async compact(remoteContextUrl, success, failure) {
380
- let me = this;
381
379
  try {
382
380
  let compacted = await jsonld.compact(this.toJson(), remoteContextUrl);
383
- me.copyFrom(compacted);
381
+ this.copyFrom(compacted);
384
382
  success(this);
385
383
  } catch(err) {
386
384
  if (err != null) {