cassproject 5.0.15 → 5.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cassproject",
3
- "version": "5.0.15",
3
+ "version": "5.0.16",
4
4
  "description": "Competency and Skills Service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -143,7 +143,7 @@
143
143
  "base64-arraybuffer": "^1.0.2",
144
144
  "jsonld": "^9.0.0",
145
145
  "node-forge": "^1.4.0",
146
- "papaparse": "^5.5.3",
146
+ "papaparse": "^5.5.4",
147
147
  "promise-worker": "^2.0.1",
148
148
  "web-worker": "1.3.0"
149
149
  },
@@ -169,12 +169,12 @@
169
169
  },
170
170
  "homepage": "https://github.com/cassproject/cass-npm#readme",
171
171
  "devDependencies": {
172
- "@cypress/webpack-preprocessor": "^7.1.0",
172
+ "@cypress/webpack-preprocessor": "^7.1.1",
173
173
  "chai": "^4.5.0",
174
- "concurrently": "^10.0.0",
175
- "cypress": "^15.16.0",
174
+ "concurrently": "^10.0.3",
175
+ "cypress": "^15.18.0",
176
176
  "cypress-fail-fast": "^8.1.0",
177
- "eslint": "^10.4.1",
177
+ "eslint": "^10.5.0",
178
178
  "fake-indexeddb": "^6.2.5",
179
179
  "mocha": "^11.7.6",
180
180
  "node-polyfill-webpack-plugin": "^4.1.0",
@@ -1,4 +1,3 @@
1
- const { v4: uuidv4 } = require('uuid');
2
1
  let forge = require("node-forge");
3
2
  /**
4
3
  * @author Fritz
@@ -71,9 +70,19 @@ module.exports = class EcCrypto {
71
70
  return new TextEncoder("utf-8").encode(str).buffer;
72
71
  }
73
72
  static generateUUID()
74
- {
75
- let uuid = uuidv4();
76
- uuid = uuid.substr(0,9)+'c455'+uuid.substr(13);
77
- return uuid;
73
+ {
74
+ var d = new Date().getTime(); //Timestamp
75
+ var d2 = ((typeof performance !== 'undefined') && performance.now && (performance.now() * 1000)) || 0;//Time in microseconds since page-load or 0 if unsupported
76
+ return 'xxxxxxxx-c455-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
77
+ var r = Math.random() * 16;//random number between 0 and 16
78
+ if (d > 0) {//Use timestamp until depleted
79
+ r = (d + r) % 16 | 0;
80
+ d = Math.floor(d / 16);
81
+ } else {//Use microseconds since page-load if supported
82
+ r = (d2 + r) % 16 | 0;
83
+ d2 = Math.floor(d2 / 16);
84
+ }
85
+ return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
86
+ });
78
87
  }
79
88
  };
package/src/index/env.js CHANGED
@@ -4,16 +4,19 @@ if (typeof window !== "undefined" && window) {
4
4
  }
5
5
 
6
6
  global.generateUUID = function () {
7
- let d = new Date().getTime();
8
- if (typeof window !== "undefined" && window && window.performance && typeof window.performance.now === "function") {
9
- d += performance.now(); // use high-precision timer if available
10
- }
11
- let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
12
- let r = (d + Math.random() * 16) % 16 | 0;
13
- d = Math.floor(d / 16);
14
- return (c == 'x' ? r : r & 0x3 | 0x8).toString(16);
7
+ var d = new Date().getTime(); //Timestamp
8
+ var d2 = ((typeof performance !== 'undefined') && performance.now && (performance.now() * 1000)) || 0;//Time in microseconds since page-load or 0 if unsupported
9
+ return 'xxxxxxxx-c455-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
10
+ var r = Math.random() * 16;//random number between 0 and 16
11
+ if (d > 0) {//Use timestamp until depleted
12
+ r = (d + r) % 16 | 0;
13
+ d = Math.floor(d / 16);
14
+ } else {//Use microseconds since page-load if supported
15
+ r = (d2 + r) % 16 | 0;
16
+ d2 = Math.floor(d2 / 16);
17
+ }
18
+ return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
15
19
  });
16
- return uuid;
17
20
  };
18
21
 
19
22
  try {
@@ -122,13 +122,12 @@ module.exports = class EcLevel extends Level {
122
122
  repo, eim
123
123
  ) {
124
124
  let a = new EcAlignment();
125
- a.source = this.id;
126
- a.target = targetLevel.id;
125
+ a.source = this.shortId();
126
+ a.target = targetLevel.shortId();
127
127
  a.relationType = alignmentType;
128
128
  a.addOwner(identity.toPk());
129
129
  if (repo?.selectedServer != null)
130
130
  a.generateId(repo.selectedServer);
131
- await a.signWith(identity);
132
131
  await a.save(success, failure, repo, eim);
133
132
  return a;
134
133
  }
@@ -146,7 +146,9 @@ module.exports = class EcRepository {
146
146
  postMaxSize = null;
147
147
  init(selectedServer, success, failure, loginObjectCallback) {
148
148
  this.selectedServer = selectedServer;
149
- return this.negotiateTimeOffset(success, failure, loginObjectCallback);
149
+ return this.negotiateTimeOffset(success, failure, loginObjectCallback).then(()=>{
150
+ return this.fetchServerAdminKeys()
151
+ });
150
152
  }
151
153
  negotiateTimeOffset = function (success, failure, loginObjectCallback) {
152
154
  let oldTimeout = EcRemote.timeout;
@@ -781,16 +783,7 @@ module.exports = class EcRepository {
781
783
  } else {
782
784
  offset = repo.timeOffset;
783
785
  }
784
- if (data.owner != null && data.owner.length > 0) {
785
- p = eim.signatureSheetFor(
786
- data.owner,
787
- 300000 + offset,
788
- data.id,
789
- null, null, repo != null ? repo.signatureSheetHashAlgorithm : null
790
- );
791
- } else {
792
- p = eim.signatureSheet(300000 + offset, data.id, null, null, repo != null ? repo.signatureSheetHashAlgorithm : null);
793
- }
786
+ p = eim.signatureSheet(300000 + offset, data.id, null, null, repo != null ? repo.signatureSheetHashAlgorithm : null);
794
787
  p = p.then((signatureSheet) => {
795
788
  let fd = new FormData();
796
789
  fd.append("data", data.toJson());
@@ -895,23 +888,18 @@ module.exports = class EcRepository {
895
888
  let targetUrl;
896
889
  targetUrl = data.shortId();
897
890
  let offset = this.setOffset(data.id);
898
- if (data.owner != null && data.owner.length > 0) {
899
- return eim.signatureSheetFor(
900
- data.owner,
901
- 300000 + offset,
902
- data.id,
903
- null, null, repo != null ? repo.signatureSheetHashAlgorithm : null
904
- ).then((signatureSheet) => {
905
- return EcRemote._delete(
906
- targetUrl,
907
- signatureSheet,
908
- success,
909
- failure
910
- );
911
- });
912
- } else {
913
- return EcRemote._delete(targetUrl, [], success, failure);
914
- }
891
+ return eim.signatureSheet(
892
+ 300000 + offset,
893
+ data.id,
894
+ null, null, repo != null ? repo.signatureSheetHashAlgorithm : null
895
+ ).then((signatureSheet) => {
896
+ return EcRemote._delete(
897
+ targetUrl,
898
+ signatureSheet,
899
+ success,
900
+ failure
901
+ );
902
+ });
915
903
  };
916
904
  /**
917
905
  * Attempts to delete a piece of data.
@@ -965,23 +953,18 @@ module.exports = class EcRepository {
965
953
  EcCrypto.md5(data.shortId())
966
954
  );
967
955
  let offset = EcRepository.setOffset(data.id);
968
- if (data.owner != null && data.owner.length > 0) {
969
- return eim.signatureSheetFor(
970
- data.owner,
971
- 300000 + offset,
972
- data.id,
973
- null, null, this != null ? this.signatureSheetHashAlgorithm : null
974
- ).then((signatureSheet) => {
975
- return EcRemote._delete(
976
- targetUrl,
977
- signatureSheet,
978
- success,
979
- failure
980
- );
981
- });
982
- } else {
983
- return EcRemote._delete(targetUrl, [], success, failure);
984
- }
956
+ return eim.signatureSheet(
957
+ 300000 + offset,
958
+ data.id,
959
+ null, null, this != null ? this.signatureSheetHashAlgorithm : null
960
+ ).then((signatureSheet) => {
961
+ return EcRemote._delete(
962
+ targetUrl,
963
+ signatureSheet,
964
+ success,
965
+ failure
966
+ );
967
+ });
985
968
  };
986
969
  /**
987
970
  * Attempts to save many pieces of data. Does some checks before saving to
@@ -1001,7 +984,6 @@ module.exports = class EcRepository {
1001
984
  multiput = function (data, success, failure, eim) {
1002
985
  if (eim === undefined || eim == null)
1003
986
  eim = EcIdentityManager.default;
1004
- let allOwners = [];
1005
987
  for (let d of data) {
1006
988
  if (d.invalid())
1007
989
  throw new Error("Cannot save data. It is missing a vital component.");
@@ -1034,9 +1016,6 @@ module.exports = class EcRepository {
1034
1016
  )
1035
1017
  ];
1036
1018
  }
1037
- if (d.owner != null)
1038
- for (let j = 0; j < d.owner.length; j++)
1039
- EcArray.setAdd(allOwners, d.owner[j]);
1040
1019
  }
1041
1020
  let encryptionAndSigningPromises = data.map((d) => {
1042
1021
  return cassReturnAsPromise(d)
@@ -1064,19 +1043,10 @@ module.exports = class EcRepository {
1064
1043
  return Promise.all(encryptionAndSigningPromises)
1065
1044
  .then((readyToSendData) => {
1066
1045
  preparedData = readyToSendData;
1067
- if (allOwners != null && allOwners.length > 0) {
1068
- return eim.signatureSheetFor(
1069
- allOwners,
1070
- 300000 + this.timeOffset,
1071
- this.selectedServer,
1072
- null, null, this.signatureSheetHashAlgorithm
1073
- );
1074
- } else {
1075
- return eim.signatureSheet(
1076
- 300000 + this.timeOffset,
1077
- this.selectedServer, null, null, this.signatureSheetHashAlgorithm
1078
- );
1079
- }
1046
+ return eim.signatureSheet(
1047
+ 300000 + this.timeOffset,
1048
+ this.selectedServer, null, null, this.signatureSheetHashAlgorithm
1049
+ );
1080
1050
  })
1081
1051
  .then((signatureSheet) => {
1082
1052
  let fd = new FormData();
@@ -1950,7 +1920,7 @@ module.exports = class EcRepository {
1950
1920
  service = "/sky/admin";
1951
1921
  }
1952
1922
  let me = this;
1953
- EcRemote.getExpectingObject(
1923
+ return EcRemote.getExpectingObject(
1954
1924
  this.selectedServer,
1955
1925
  service,
1956
1926
  function (p1) {
@@ -1959,10 +1929,16 @@ module.exports = class EcRepository {
1959
1929
  for (let i = 0; i < ary.length; i++) {
1960
1930
  me.adminKeys.push(ary[i]);
1961
1931
  }
1962
- success(ary);
1932
+ if (success != null)
1933
+ success(ary);
1934
+ else
1935
+ return ary;
1963
1936
  },
1964
1937
  function (p1) {
1965
- failure("");
1938
+ if (failure != null)
1939
+ failure(p1);
1940
+ else
1941
+ throw new Error(p1);
1966
1942
  }
1967
1943
  );
1968
1944
  };
@@ -1981,9 +1957,7 @@ module.exports = class EcRepository {
1981
1957
  } else
1982
1958
  return p1;
1983
1959
  }
1984
- p1 = await EcEncryptedValue.fromEncryptedValue(
1985
- p1, null, null, eim
1986
- );
1960
+ p1 = await EcEncryptedValue.fromEncryptedValue(p1, null, null, eim);
1987
1961
  if (p1.isAny(result.getTypes())) {
1988
1962
  result.copyFrom(p1, eim);
1989
1963
  if (this.caching) {
@@ -9,128 +9,6 @@ const EcIdentityManager = require('../org/cassproject/ebac/identity/EcIdentityMa
9
9
  const { expect } = chai;
10
10
 
11
11
  describe('EcLevel', () => {
12
- let sandbox;
13
-
14
- beforeEach(() => {
15
- sandbox = sinon.createSandbox();
16
- });
17
-
18
- afterEach(() => {
19
- sandbox.restore();
20
- });
21
-
22
- describe('get', () => {
23
- it('should retrieve a level by ID', (done) => {
24
- const id = 'testId';
25
- const success = sinon.spy();
26
- const failure = sinon.spy();
27
- const repo = {};
28
- const eim = {};
29
-
30
- sandbox.stub(EcRepository, 'getAs').callsFake((id, level, successCallback, failureCallback, repo, eim) => {
31
- successCallback(level);
32
- });
33
-
34
- EcLevel.get(id, success, failure, repo, eim);
35
-
36
- expect(success.calledOnce).to.be.true;
37
- expect(failure.called).to.be.false;
38
- done();
39
- });
40
- });
41
-
42
- describe('getBlocking', () => {
43
- it('should retrieve a level by ID synchronously', () => {
44
- const id = 'testId';
45
- const repo = {};
46
- const eim = {};
47
-
48
- sandbox.stub(EcRepository, 'getAs').returns(new EcLevel());
49
-
50
- const result = EcLevel.getBlocking(id, repo, eim);
51
-
52
- expect(result).to.be.instanceOf(EcLevel);
53
- });
54
- });
55
-
56
- describe('search', () => {
57
- it('should search for levels with a query', (done) => {
58
- const repo = {};
59
- const query = 'testQuery';
60
- const success = sinon.spy();
61
- const failure = sinon.spy();
62
- const paramObj = {};
63
- const eim = {};
64
-
65
- sandbox.stub(EcRepository, 'searchAs').callsFake((repo, query, levelFactory, successCallback, failureCallback, paramObj, eim) => {
66
- successCallback([new EcLevel()]);
67
- });
68
-
69
- EcLevel.search(repo, query, success, failure, paramObj, eim);
70
-
71
- expect(success.calledOnce).to.be.true;
72
- expect(failure.called).to.be.false;
73
- done();
74
- });
75
- });
76
-
77
- describe('searchByCompetency', () => {
78
- it('should search for levels by competency ID', (done) => {
79
- const repo = {};
80
- const competencyId = 'testCompetencyId';
81
- const success = sinon.spy();
82
- const failure = sinon.spy();
83
- const paramObj = {};
84
- const eim = {};
85
-
86
- sandbox.stub(EcLevel, 'search').callsFake((repo, query, successCallback, failureCallback, paramObj, eim) => {
87
- successCallback([new EcLevel()]);
88
- });
89
-
90
- EcLevel.searchByCompetency(repo, competencyId, success, failure, paramObj, eim);
91
-
92
- expect(success.calledOnce).to.be.true;
93
- expect(failure.called).to.be.false;
94
- done();
95
- });
96
-
97
- it('should call failure callback if no competency ID is provided', () => {
98
- const repo = {};
99
- const competencyId = '';
100
- const success = sinon.spy();
101
- const failure = sinon.spy();
102
- const paramObj = {};
103
- const eim = {};
104
-
105
- EcLevel.searchByCompetency(repo, competencyId, success, failure, paramObj, eim);
106
-
107
- expect(failure.calledOnce).to.be.true;
108
- expect(success.called).to.be.false;
109
- });
110
- });
111
-
112
- describe('addRelationship', () => {
113
- it('should add a relationship between levels', async () => {
114
- const level = new EcLevel();
115
- level.id = 'sourceId';
116
- const targetLevel = new EcLevel();
117
- targetLevel.id = 'targetId';
118
- const alignmentType = 'testType';
119
- const identity = EcPpk.generateKey();
120
- const success = sinon.spy();
121
- const failure = sinon.spy();
122
- const repo = new EcRepository();
123
- await repo.init(process.env.CASS_LOOPBACK || 'http://localhost/api/');
124
- const eim = EcIdentityManager.default;
125
-
126
- let a = await level.addRelationship(targetLevel, alignmentType, identity, success, failure, repo, eim);
127
-
128
- expect(a.source).to.equal(level.id);
129
- expect(a.target).to.equal(targetLevel.id);
130
- expect(a.relationType).to.equal(alignmentType);
131
- });
132
- });
133
-
134
12
  describe('setName', () => {
135
13
  it('should set the name of the level', () => {
136
14
  const level = new EcLevel();