@nsshunt/stsdatamanagement 1.10.3 → 1.11.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.
package/blcauth.js CHANGED
@@ -152,11 +152,32 @@ class BLCAuth
152
152
  }
153
153
  }
154
154
 
155
+ #ValidateApplication = async (apiPermissions, app) => {
156
+ const { clientId, clientName, permissions } = app;
157
+
158
+ let applicationResource = null;
159
+ try {
160
+ applicationResource = await this.GetApplication(clientId)
161
+ } catch (error) {
162
+ return { status: status.notfound , error: 'Cannot find client application.', detail: { message: error.message }};
163
+ }
164
+ if (applicationResource.clientName.localeCompare(clientName) !== 0) {
165
+ return { status: status.error, error: 'clientName mismatch.', detail: { message: `clientName mismatch: Value: [${clientName}], Expecting: [${applicationResource.clientName}]` }};
166
+ }
167
+ for (let j=0; j < permissions.length; j++) {
168
+ const permission = permissions[j];
169
+ if (!apiPermissions.includes(permission)) {
170
+ return { status: status.error, error: 'M2M permission not found within API available permission list.', detail: { message: `Permission not found within API available permission list: [${permission}]` }};
171
+ }
172
+ }
173
+ return null;
174
+ }
175
+
155
176
  async AddAPI(api)
156
177
  {
157
178
  try
158
179
  {
159
- const { M2MApplications, permissions, identifier } = api;
180
+ const { M2MApplications, apiPermissions, identifier, SPA } = api;
160
181
  let APIidentifier = BLCAuth.API_ID_PREFIX + identifier;
161
182
  let existingAPI = await this.#accessLayer.getLatestResource(APIidentifier);
162
183
  if (existingAPI.status === 200) {
@@ -164,26 +185,26 @@ class BLCAuth
164
185
  }
165
186
 
166
187
  // Validate M2MApplications
167
- for (let i=0; i < M2MApplications.length; i++) {
168
- const m2mapplication = M2MApplications[i];
169
- let appid = BLCAuth.APPLICATION_ID_PREFIX + m2mapplication.clientId;
170
- let retVal = await this.#accessLayer.getLatestResource(appid);
171
- if (retVal.status !== 200) {
172
- return { status: status.notfound , error: 'Cannot find client application.', detail: { message: `Cannot find client application: [${appid}].` }};
173
- }
174
- let applicationResource = JSON.parse(retVal.detail.resdesc);
175
- if (applicationResource.clientName.localeCompare(m2mapplication.clientName) !== 0) {
176
- return { status: status.error, error: 'clientName mismatch.', detail: { message: `clientName mismatch: Value: [${m2mapplication.clientName}], Expecting: [${applicationResource.clientName}]` }};
188
+ if (M2MApplications) {
189
+ for (let i=0; i < M2MApplications.length; i++) {
190
+ let retVal = await this.#ValidateApplication(apiPermissions, M2MApplications[i]);
191
+ if (retVal !== null) {
192
+ return retVal;
193
+ }
177
194
  }
178
- for (let j=0; j < m2mapplication.permissions.length; j++) {
179
- const permission = m2mapplication.permissions[j];
180
- if (!permissions.includes(permission)) {
181
- return { status: status.error, error: 'M2M permission not found within API available permission list.', detail: { message: `M2M permission not found within API available permission list: [${permission}]` }};
195
+ }
196
+
197
+ // Validate SPA
198
+ if (SPA) {
199
+ for (let i=0; i < SPA.length; i++) {
200
+ let retVal = await this.#ValidateApplication(apiPermissions, SPA[i]);
201
+ if (retVal !== null) {
202
+ return retVal;
182
203
  }
183
204
  }
184
205
  }
185
-
186
- // Client Secret is not returned. Seperate function used to display this field.
206
+
207
+ // Client Secret is not returned. Separate function used to display this field.
187
208
  let payload =
188
209
  {
189
210
  APIidentifier: APIidentifier,
@@ -204,18 +225,20 @@ class BLCAuth
204
225
  let clientIdentifier = BLCAuth.APPLICATION_ID_PREFIX + clientId;
205
226
  let application = await this.#accessLayer.getLatestResource(clientIdentifier);
206
227
  if (application.status !== 200) {
207
- return { status: status.notfound, error: 'Application not found.', detail: { message: `Application not found: [${clientId}]` }};
228
+ throw new Error(`Application not found: [${clientId}]`);
208
229
  }
209
- return application;
230
+ let applicationResource = JSON.parse(application.detail.resdesc);
231
+ return applicationResource;
210
232
  }
211
233
 
212
234
  async GetAPI(identifier) {
213
235
  let APIidentifier = BLCAuth.API_ID_PREFIX + identifier;
214
236
  let api = await this.#accessLayer.getLatestResource(APIidentifier);
215
237
  if (api.status !== 200) {
216
- return { status: status.notfound, error: 'API not found.', detail: { message: `API not found: [${identifier}]` }};
238
+ throw new Error(`API not found: [${identifier}]`);
217
239
  }
218
- return api;
240
+ let apiResource = JSON.parse(api.detail.resdesc);
241
+ return apiResource;
219
242
  }
220
243
  }
221
244
 
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@nsshunt/stsdatamanagement",
3
- "version": "1.10.3",
3
+ "version": "1.11.0",
4
4
  "description": "STS Data Management Modules, Utilities and Services",
5
5
  "main": "dbaccess.js",
6
6
  "dependencies": {
7
- "@nsshunt/stsconfig": "^1.19.0",
7
+ "@nsshunt/stsconfig": "^1.20.0",
8
8
  "@nsshunt/stsinstrumentation": "^6.4.3",
9
- "@nsshunt/stsutils": "^1.7.6",
9
+ "@nsshunt/stsutils": "^1.8.5",
10
10
  "axios": "^0.26.0",
11
11
  "bcryptjs": "^2.4.3",
12
12
  "cli-progress": "^3.10.0",
13
13
  "colors": "^1.4.0",
14
14
  "debug": "^4.3.4",
15
- "ioredis": "^4.28.5",
15
+ "ioredis": "^5.0.3",
16
16
  "pg": "^8.7.3",
17
17
  "pg-copy-streams": "^6.0.2",
18
18
  "prompts": "^2.4.2",
@@ -31,7 +31,7 @@
31
31
  "@babel/eslint-parser": "^7.17.0",
32
32
  "@babel/plugin-proposal-class-properties": "^7.16.7",
33
33
  "@babel/plugin-proposal-private-methods": "^7.16.11",
34
- "eslint": "^8.11.0",
34
+ "eslint": "^8.12.0",
35
35
  "jest": "^27.5.1"
36
36
  },
37
37
  "scripts": {
package/pgaccesslayer.js CHANGED
@@ -332,6 +332,19 @@ class PGAccessLayer
332
332
  }
333
333
  }
334
334
 
335
+ async deleteLatestResource(userid, resid)
336
+ {
337
+ const fname = 'deleteLatestResource';
338
+ let retVal = await this.getLatestResource(resid);
339
+ if (retVal.status !== status.success)
340
+ {
341
+ return { status: retVal.status, error: `[${fname}]: Operation was not successful: [${resid}]`, detail: retVal };
342
+ } else {
343
+ let vnum = retVal.detail.vnum;
344
+ await this.deleteResource(userid, resid, vnum);
345
+ }
346
+ }
347
+
335
348
  async deleteResource(userid, resourceid, resourcevnum)
336
349
  {
337
350
  const fname = 'deleteResource';