@sdflc/backend-helpers 1.0.68 → 1.0.70
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/build/BaseController.js +1 -1
- package/build/BaseCore.js +110 -47
- package/build/BaseGateway.js +4 -3
- package/build/constants.d.ts +13 -1
- package/build/constants.js +14 -1
- package/build/interfaces/BaseCoreActionsInterface.d.ts +4 -0
- package/build/interfaces/BaseCoreDoAuthOnActionInterface.d.ts +12 -0
- package/build/interfaces/BaseCoreDoAuthOnActionInterface.js +2 -0
- package/build/interfaces/BaseCorePropsInterface.d.ts +2 -0
- package/build/interfaces/CoreActionInterface.d.ts +1 -0
- package/build/interfaces/ExtractCredentialsArgs.d.ts +4 -0
- package/build/interfaces/index.d.ts +1 -0
- package/build/interfaces/index.js +1 -0
- package/package.json +1 -1
package/build/BaseController.js
CHANGED
|
@@ -29,7 +29,7 @@ class BaseController {
|
|
|
29
29
|
/* TODO */
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
this.logger = props.logger instanceof utils_1.Logger ? props.logger : new utils_1.Logger({ level: utils_1.LoggerLevels.
|
|
32
|
+
this.logger = (props === null || props === void 0 ? void 0 : props.logger) instanceof utils_1.Logger ? props.logger : new utils_1.Logger({ level: utils_1.LoggerLevels.ERROR });
|
|
33
33
|
}
|
|
34
34
|
init(props) {
|
|
35
35
|
// const { app } = props;
|
package/build/BaseCore.js
CHANGED
|
@@ -40,9 +40,22 @@ const defaultValidators = {
|
|
|
40
40
|
};
|
|
41
41
|
class BaseCore {
|
|
42
42
|
constructor(props) {
|
|
43
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
43
44
|
this.measureTool = new utils_1.MeasureTool();
|
|
44
|
-
this.config = props;
|
|
45
|
-
this.logger =
|
|
45
|
+
this.config = props || {};
|
|
46
|
+
this.logger = this.config.logger instanceof utils_1.Logger ? this.config.logger : new utils_1.Logger({ level: utils_1.LoggerLevels.ERROR });
|
|
47
|
+
this.config.doAuthOnAction = {
|
|
48
|
+
list: ((_a = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.list) != null ? (_b = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _b === void 0 ? void 0 : _b.list : props === null || props === void 0 ? void 0 : props.doAuth,
|
|
49
|
+
get: ((_c = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _c === void 0 ? void 0 : _c.get) != null ? (_d = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _d === void 0 ? void 0 : _d.get : props === null || props === void 0 ? void 0 : props.doAuth,
|
|
50
|
+
getMany: ((_e = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _e === void 0 ? void 0 : _e.getMany) != null ? (_f = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _f === void 0 ? void 0 : _f.getMany : props === null || props === void 0 ? void 0 : props.doAuth,
|
|
51
|
+
create: ((_g = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _g === void 0 ? void 0 : _g.create) != null ? (_h = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _h === void 0 ? void 0 : _h.create : props === null || props === void 0 ? void 0 : props.doAuth,
|
|
52
|
+
createMany: ((_j = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _j === void 0 ? void 0 : _j.createMany) != null ? (_k = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _k === void 0 ? void 0 : _k.createMany : props === null || props === void 0 ? void 0 : props.doAuth,
|
|
53
|
+
update: ((_l = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _l === void 0 ? void 0 : _l.update) != null ? (_m = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _m === void 0 ? void 0 : _m.update : props === null || props === void 0 ? void 0 : props.doAuth,
|
|
54
|
+
updateMany: ((_o = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _o === void 0 ? void 0 : _o.updateMany) != null ? (_p = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _p === void 0 ? void 0 : _p.updateMany : props === null || props === void 0 ? void 0 : props.doAuth,
|
|
55
|
+
set: ((_q = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _q === void 0 ? void 0 : _q.set) != null ? (_r = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _r === void 0 ? void 0 : _r.set : props === null || props === void 0 ? void 0 : props.doAuth,
|
|
56
|
+
remove: ((_s = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _s === void 0 ? void 0 : _s.remove) != null ? (_t = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _t === void 0 ? void 0 : _t.remove : props === null || props === void 0 ? void 0 : props.doAuth,
|
|
57
|
+
removeMany: ((_u = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _u === void 0 ? void 0 : _u.removeMany) != null ? (_v = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _v === void 0 ? void 0 : _v.removeMany : props === null || props === void 0 ? void 0 : props.doAuth,
|
|
58
|
+
};
|
|
46
59
|
}
|
|
47
60
|
getIdType() {
|
|
48
61
|
var _a;
|
|
@@ -227,7 +240,7 @@ class BaseCore {
|
|
|
227
240
|
}
|
|
228
241
|
let time = this.measureTool.stop();
|
|
229
242
|
this.logger.debug(`Authorization and validation time for the ${doingWhat} took ${time.durationMs} ms`);
|
|
230
|
-
const result = yield action(args, Object.assign(Object.assign({}, actionOpt), { validatedItems }));
|
|
243
|
+
const result = yield action(args, Object.assign(Object.assign({}, actionOpt), { validatedItems, args }));
|
|
231
244
|
yield this.checkResult({ hasTransaction, result, sameRequest, doingWhat });
|
|
232
245
|
time = this.measureTool.stop(doingWhat);
|
|
233
246
|
this.logger.debug(`The ${time.name} process time is ${time.durationMs} ms`);
|
|
@@ -262,39 +275,49 @@ class BaseCore {
|
|
|
262
275
|
});
|
|
263
276
|
}
|
|
264
277
|
list(args) {
|
|
265
|
-
var _a, _b, _c;
|
|
278
|
+
var _a, _b, _c, _d;
|
|
266
279
|
return __awaiter(this, void 0, void 0, function* () {
|
|
267
280
|
return this.runAction({
|
|
268
281
|
args,
|
|
282
|
+
doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.list,
|
|
283
|
+
actionName: constants_1.ACTIONS.LIST,
|
|
269
284
|
validate: this.getValidators().list,
|
|
270
285
|
accessRights: [utils_1.ACCESS_RIGHTS.LIST],
|
|
271
286
|
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
272
|
-
var
|
|
287
|
+
var _e;
|
|
273
288
|
const object = yield this.beforeList(args, opt);
|
|
274
|
-
|
|
289
|
+
if (object instanceof api_helpers_1.OpResult) {
|
|
290
|
+
return object;
|
|
291
|
+
}
|
|
292
|
+
const items = yield ((_e = this.getContext().gateways[this.config.gatewayName]) === null || _e === void 0 ? void 0 : _e.list(object));
|
|
275
293
|
const result = yield this.afterList(items, opt);
|
|
276
294
|
// ON NO DATA RETURN EMPTY CODE
|
|
277
295
|
return this.success(result);
|
|
278
296
|
}),
|
|
279
297
|
hasTransaction: false,
|
|
280
|
-
doingWhat: (
|
|
298
|
+
doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.list) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'listing',
|
|
281
299
|
});
|
|
282
300
|
});
|
|
283
301
|
}
|
|
284
302
|
get(args) {
|
|
285
|
-
var _a, _b, _c;
|
|
303
|
+
var _a, _b, _c, _d;
|
|
286
304
|
return __awaiter(this, void 0, void 0, function* () {
|
|
287
305
|
return this.runAction({
|
|
288
306
|
args,
|
|
307
|
+
doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.get,
|
|
308
|
+
actionName: constants_1.ACTIONS.GET,
|
|
289
309
|
validate: this.getValidators().get,
|
|
290
310
|
accessRights: [utils_1.ACCESS_RIGHTS.GET],
|
|
291
311
|
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
292
|
-
var
|
|
312
|
+
var _e;
|
|
293
313
|
const args2use = yield this.beforeGet(args, opt);
|
|
314
|
+
if (args2use instanceof api_helpers_1.OpResult) {
|
|
315
|
+
return args2use;
|
|
316
|
+
}
|
|
294
317
|
if ((args2use === null || args2use === void 0 ? void 0 : args2use.id) == null) {
|
|
295
318
|
return this.failure(api_helpers_1.OP_RESULT_CODES.NOT_FOUND, '', []);
|
|
296
319
|
}
|
|
297
|
-
const item = yield ((
|
|
320
|
+
const item = yield ((_e = this.getContext().gateways[this.config.gatewayName]) === null || _e === void 0 ? void 0 : _e.get(args2use === null || args2use === void 0 ? void 0 : args2use.id));
|
|
298
321
|
const result = yield this.afterGet(item, opt);
|
|
299
322
|
if (!result) {
|
|
300
323
|
return this.failure(api_helpers_1.OP_RESULT_CODES.NOT_FOUND, '', []);
|
|
@@ -302,29 +325,34 @@ class BaseCore {
|
|
|
302
325
|
return this.success([result]);
|
|
303
326
|
}),
|
|
304
327
|
hasTransaction: false,
|
|
305
|
-
doingWhat: (
|
|
328
|
+
doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.get) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'getting an item',
|
|
306
329
|
});
|
|
307
330
|
});
|
|
308
331
|
}
|
|
309
332
|
getMany(args) {
|
|
310
|
-
var _a, _b, _c;
|
|
333
|
+
var _a, _b, _c, _d;
|
|
311
334
|
return __awaiter(this, void 0, void 0, function* () {
|
|
312
335
|
return this.runAction({
|
|
313
336
|
args,
|
|
337
|
+
doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.getMany,
|
|
338
|
+
actionName: constants_1.ACTIONS.GET_MANY,
|
|
314
339
|
validate: this.getValidators().getMany,
|
|
315
340
|
accessRights: [utils_1.ACCESS_RIGHTS.GET],
|
|
316
341
|
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
317
|
-
var
|
|
342
|
+
var _e;
|
|
318
343
|
const args2use = yield this.beforeGetMany(args, opt);
|
|
344
|
+
if (args2use instanceof api_helpers_1.OpResult) {
|
|
345
|
+
return args2use;
|
|
346
|
+
}
|
|
319
347
|
if (!Array.isArray(args2use === null || args2use === void 0 ? void 0 : args2use.ids)) {
|
|
320
348
|
return this.failure(api_helpers_1.OP_RESULT_CODES.NOT_FOUND, '', []);
|
|
321
349
|
}
|
|
322
|
-
const items = yield ((
|
|
350
|
+
const items = yield ((_e = this.getContext().gateways[this.config.gatewayName]) === null || _e === void 0 ? void 0 : _e.getMany(args2use.ids));
|
|
323
351
|
const result = yield this.afterGetMany(items, opt);
|
|
324
352
|
return this.success(result);
|
|
325
353
|
}),
|
|
326
354
|
hasTransaction: false,
|
|
327
|
-
doingWhat: (
|
|
355
|
+
doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.getMany) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'geting multiple items',
|
|
328
356
|
});
|
|
329
357
|
});
|
|
330
358
|
}
|
|
@@ -335,14 +363,16 @@ class BaseCore {
|
|
|
335
363
|
return {};
|
|
336
364
|
}
|
|
337
365
|
create(args) {
|
|
338
|
-
var _a, _b, _c;
|
|
366
|
+
var _a, _b, _c, _d;
|
|
339
367
|
return __awaiter(this, void 0, void 0, function* () {
|
|
340
368
|
return this.runAction({
|
|
341
369
|
args,
|
|
370
|
+
doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.create,
|
|
371
|
+
actionName: constants_1.ACTIONS.CREATE,
|
|
342
372
|
validate: this.getValidators().create,
|
|
343
373
|
accessRights: [utils_1.ACCESS_RIGHTS.CREATE],
|
|
344
374
|
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
345
|
-
var
|
|
375
|
+
var _e;
|
|
346
376
|
const { params } = args || {};
|
|
347
377
|
if (this.config.hasOrderNo === true) {
|
|
348
378
|
this.setOrderNo({
|
|
@@ -352,132 +382,165 @@ class BaseCore {
|
|
|
352
382
|
});
|
|
353
383
|
}
|
|
354
384
|
const object = yield this.beforeCreate(params, opt);
|
|
355
|
-
|
|
385
|
+
if (object instanceof api_helpers_1.OpResult) {
|
|
386
|
+
return object;
|
|
387
|
+
}
|
|
388
|
+
const items = yield ((_e = this.getContext().gateways[this.config.gatewayName]) === null || _e === void 0 ? void 0 : _e.create(object));
|
|
356
389
|
const result = yield this.afterCreate(items, opt);
|
|
357
390
|
return this.success(result);
|
|
358
391
|
}),
|
|
359
392
|
hasTransaction: true,
|
|
360
|
-
doingWhat: (
|
|
393
|
+
doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.create) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'creating an item',
|
|
361
394
|
});
|
|
362
395
|
});
|
|
363
396
|
}
|
|
364
397
|
createMany(args) {
|
|
365
|
-
var _a, _b, _c;
|
|
398
|
+
var _a, _b, _c, _d;
|
|
366
399
|
return __awaiter(this, void 0, void 0, function* () {
|
|
367
400
|
return this.runAction({
|
|
368
401
|
args,
|
|
402
|
+
doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.createMany,
|
|
403
|
+
actionName: constants_1.ACTIONS.CREATE_MANY,
|
|
369
404
|
validate: this.getValidators().createMany,
|
|
370
405
|
accessRights: [utils_1.ACCESS_RIGHTS.CREATE],
|
|
371
406
|
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
372
|
-
var
|
|
407
|
+
var _e;
|
|
373
408
|
const { params } = args || {};
|
|
374
409
|
const objects = yield this.beforeCreateMany(params, opt);
|
|
375
|
-
|
|
410
|
+
if (objects instanceof api_helpers_1.OpResult) {
|
|
411
|
+
return objects;
|
|
412
|
+
}
|
|
413
|
+
const items = yield ((_e = this.getContext().gateways[this.config.gatewayName]) === null || _e === void 0 ? void 0 : _e.create(objects));
|
|
376
414
|
const result = yield this.afterCreateMany(items, opt);
|
|
377
415
|
return this.success(result);
|
|
378
416
|
}),
|
|
379
417
|
hasTransaction: true,
|
|
380
|
-
doingWhat: (
|
|
418
|
+
doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.createMany) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'creating multiple items',
|
|
381
419
|
});
|
|
382
420
|
});
|
|
383
421
|
}
|
|
384
422
|
update(args) {
|
|
385
|
-
var _a, _b, _c;
|
|
423
|
+
var _a, _b, _c, _d;
|
|
386
424
|
return __awaiter(this, void 0, void 0, function* () {
|
|
387
425
|
return this.runAction({
|
|
388
426
|
args,
|
|
427
|
+
doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.update,
|
|
428
|
+
actionName: constants_1.ACTIONS.UPDATE,
|
|
389
429
|
validate: this.getValidators().update,
|
|
390
430
|
accessRights: [utils_1.ACCESS_RIGHTS.UPDATE],
|
|
391
431
|
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
392
|
-
var
|
|
432
|
+
var _e;
|
|
393
433
|
const { where, params } = args || {};
|
|
394
434
|
const object = yield this.beforeUpdate(params, opt);
|
|
395
|
-
|
|
435
|
+
if (object instanceof api_helpers_1.OpResult) {
|
|
436
|
+
return object;
|
|
437
|
+
}
|
|
438
|
+
const items = yield ((_e = this.getContext().gateways[this.config.gatewayName]) === null || _e === void 0 ? void 0 : _e.update(where, object));
|
|
396
439
|
const result = yield this.afterUpdate(items, opt);
|
|
397
440
|
return this.success(result, result.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND);
|
|
398
441
|
}),
|
|
399
442
|
hasTransaction: true,
|
|
400
|
-
doingWhat: (
|
|
443
|
+
doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.update) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'updating an item',
|
|
401
444
|
});
|
|
402
445
|
});
|
|
403
446
|
}
|
|
404
447
|
updateMany(args) {
|
|
405
|
-
var _a, _b, _c;
|
|
448
|
+
var _a, _b, _c, _d;
|
|
406
449
|
return __awaiter(this, void 0, void 0, function* () {
|
|
407
450
|
return this.runAction({
|
|
408
451
|
args,
|
|
452
|
+
doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.updateMany,
|
|
453
|
+
actionName: constants_1.ACTIONS.UPDATE_MANY,
|
|
409
454
|
validate: this.getValidators().updateMany,
|
|
410
455
|
accessRights: [utils_1.ACCESS_RIGHTS.UPDATE],
|
|
411
456
|
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
412
|
-
var
|
|
457
|
+
var _e;
|
|
413
458
|
const { params } = args || {};
|
|
414
459
|
const object = yield this.beforeUpdateMany(params, opt);
|
|
415
|
-
|
|
460
|
+
if (object instanceof api_helpers_1.OpResult) {
|
|
461
|
+
return object;
|
|
462
|
+
}
|
|
463
|
+
const items = yield ((_e = this.getContext().gateways[this.config.gatewayName]) === null || _e === void 0 ? void 0 : _e.updateMany(object));
|
|
416
464
|
const result = yield this.afterUpdateMany(items, opt);
|
|
417
465
|
return this.success(result);
|
|
418
466
|
}),
|
|
419
467
|
hasTransaction: true,
|
|
420
|
-
doingWhat: (
|
|
468
|
+
doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.updateMany) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'updating multiple items',
|
|
421
469
|
});
|
|
422
470
|
});
|
|
423
471
|
}
|
|
424
472
|
set(args) {
|
|
425
|
-
var _a, _b, _c;
|
|
473
|
+
var _a, _b, _c, _d;
|
|
426
474
|
return __awaiter(this, void 0, void 0, function* () {
|
|
427
475
|
return this.runAction({
|
|
428
476
|
args,
|
|
477
|
+
doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.set,
|
|
478
|
+
actionName: constants_1.ACTIONS.SET,
|
|
429
479
|
validate: this.getValidators().set,
|
|
430
480
|
accessRights: [utils_1.ACCESS_RIGHTS.CREATE, utils_1.ACCESS_RIGHTS.UPDATE],
|
|
431
481
|
action: (args, opt /* { setStep, validatedItems, sameRequest } */) => __awaiter(this, void 0, void 0, function* () {
|
|
432
|
-
var
|
|
482
|
+
var _e;
|
|
433
483
|
const { params } = args || {};
|
|
434
484
|
const object = yield this.beforeSet(params, opt);
|
|
435
|
-
|
|
485
|
+
if (object instanceof api_helpers_1.OpResult) {
|
|
486
|
+
return object;
|
|
487
|
+
}
|
|
488
|
+
const items = yield ((_e = this.getContext().gateways[this.config.gatewayName]) === null || _e === void 0 ? void 0 : _e.set(object));
|
|
436
489
|
const result = yield this.afterSet(items, opt);
|
|
437
490
|
return this.success(result);
|
|
438
491
|
}),
|
|
439
492
|
hasTransaction: true,
|
|
440
|
-
doingWhat: (
|
|
493
|
+
doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.updateMany) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'updating multiple items',
|
|
441
494
|
});
|
|
442
495
|
});
|
|
443
496
|
}
|
|
444
497
|
remove(args) {
|
|
445
|
-
var _a, _b, _c;
|
|
498
|
+
var _a, _b, _c, _d;
|
|
446
499
|
return __awaiter(this, void 0, void 0, function* () {
|
|
447
500
|
return this.runAction({
|
|
448
501
|
args,
|
|
502
|
+
doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.remove,
|
|
503
|
+
actionName: constants_1.ACTIONS.REMOVE,
|
|
449
504
|
validate: this.getValidators().remove,
|
|
450
505
|
accessRights: [utils_1.ACCESS_RIGHTS.REMOVE],
|
|
451
506
|
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
452
|
-
var
|
|
507
|
+
var _e;
|
|
453
508
|
const { where } = args || {};
|
|
454
509
|
const object = yield this.beforeRemove(where, opt);
|
|
455
|
-
|
|
510
|
+
if (object instanceof api_helpers_1.OpResult) {
|
|
511
|
+
return object;
|
|
512
|
+
}
|
|
513
|
+
const items = yield ((_e = this.getContext().gateways[this.config.gatewayName]) === null || _e === void 0 ? void 0 : _e.remove(object));
|
|
456
514
|
const result = yield this.afterRemove(items, opt);
|
|
457
515
|
return this.success(result, result.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND);
|
|
458
516
|
}),
|
|
459
517
|
hasTransaction: false,
|
|
460
|
-
doingWhat: (
|
|
518
|
+
doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.remove) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'removing an item',
|
|
461
519
|
});
|
|
462
520
|
});
|
|
463
521
|
}
|
|
464
522
|
removeMany(args) {
|
|
465
|
-
var _a, _b, _c;
|
|
523
|
+
var _a, _b, _c, _d;
|
|
466
524
|
return __awaiter(this, void 0, void 0, function* () {
|
|
467
525
|
return this.runAction({
|
|
468
526
|
args,
|
|
527
|
+
doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.removeMany,
|
|
528
|
+
actionName: constants_1.ACTIONS.REMOVE_MANY,
|
|
469
529
|
validate: this.getValidators().removeMany,
|
|
470
530
|
accessRights: [utils_1.ACCESS_RIGHTS.REMOVE],
|
|
471
531
|
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
472
|
-
var
|
|
532
|
+
var _e;
|
|
473
533
|
const { where } = args || {};
|
|
474
534
|
const object = yield this.beforeRemoveMany(where, opt);
|
|
475
|
-
|
|
535
|
+
if (object instanceof api_helpers_1.OpResult) {
|
|
536
|
+
return object;
|
|
537
|
+
}
|
|
538
|
+
const items = yield ((_e = this.getContext().gateways[this.config.gatewayName]) === null || _e === void 0 ? void 0 : _e.remove(object));
|
|
476
539
|
const result = yield this.afterRemoveMany(items, opt);
|
|
477
540
|
return this.success(result, result.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND);
|
|
478
541
|
}),
|
|
479
542
|
hasTransaction: false,
|
|
480
|
-
doingWhat: (
|
|
543
|
+
doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.removeMany) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'removing multiple items',
|
|
481
544
|
});
|
|
482
545
|
});
|
|
483
546
|
}
|
|
@@ -672,9 +735,9 @@ class BaseCore {
|
|
|
672
735
|
let authByToken = false;
|
|
673
736
|
const [spaceResult, space] = yield this.findSpace();
|
|
674
737
|
if (spaceResult !== true) {
|
|
675
|
-
return spaceResult;
|
|
738
|
+
return [spaceResult, space];
|
|
676
739
|
}
|
|
677
|
-
const { token, fingerprint } = yield this.extractCredentials({ req, authorization, space });
|
|
740
|
+
const { token, fingerprint } = yield this.extractCredentials({ req, authorization, space, params });
|
|
678
741
|
const { jwtSecret, verifyTokenArgs } = yield this.getJwtTokenSecretAndSettings(params);
|
|
679
742
|
if (token && jwtSecret) {
|
|
680
743
|
const verifyResult = (0, userToken_1.verifyUserToken)(token, jwtSecret, Object.assign(Object.assign({}, verifyTokenArgs), { algorithms: (verifyTokenArgs === null || verifyTokenArgs === void 0 ? void 0 : verifyTokenArgs.algorithms) || [(0, userToken_1.getDefaultJwtAlgorithm)()], audience: (verifyTokenArgs === null || verifyTokenArgs === void 0 ? void 0 : verifyTokenArgs.audience) || space.id, issuer: (verifyTokenArgs === null || verifyTokenArgs === void 0 ? void 0 : verifyTokenArgs.issuer) || (0, userToken_1.getDefaultJwtIssuer)(), fingerprint }));
|
|
@@ -686,8 +749,8 @@ class BaseCore {
|
|
|
686
749
|
context.roleId = tokenData.roleId;
|
|
687
750
|
context.userId = tokenData.userId;
|
|
688
751
|
context.isSuperAdmin = context.roleId === 'superadmin';
|
|
689
|
-
context.spaceId =
|
|
690
|
-
context.lang =
|
|
752
|
+
context.spaceId = context.spaceId || tokenData.spaceId;
|
|
753
|
+
context.lang = context.requestedLang || tokenData.lang;
|
|
691
754
|
authByToken = true;
|
|
692
755
|
}
|
|
693
756
|
if (!authByToken) {
|
package/build/BaseGateway.js
CHANGED
|
@@ -19,10 +19,11 @@ const lodash_1 = require("lodash");
|
|
|
19
19
|
const utils_1 = require("@sdflc/utils");
|
|
20
20
|
const DataCache_1 = require("./DataCache");
|
|
21
21
|
const constants_1 = require("./constants");
|
|
22
|
+
const check_types_1 = __importDefault(require("check-types"));
|
|
22
23
|
const DEFAULT_CHUNCK_SIZE = 2500;
|
|
23
24
|
class BaseGateway {
|
|
24
25
|
constructor(props) {
|
|
25
|
-
var _a, _b;
|
|
26
|
+
var _a, _b, _c;
|
|
26
27
|
this.dateTime = new utils_1.DateTimeHelpers();
|
|
27
28
|
this.dateTimeNow = new Date();
|
|
28
29
|
this.config = props;
|
|
@@ -38,8 +39,8 @@ class BaseGateway {
|
|
|
38
39
|
}
|
|
39
40
|
this.config.context.usedKeyPrefixes[this.config.keyPrefix] = true;
|
|
40
41
|
}
|
|
41
|
-
this.logger = props.logger instanceof utils_1.Logger ? props.logger : new utils_1.Logger({ level: utils_1.LoggerLevels.WARNING });
|
|
42
|
-
this.loader =
|
|
42
|
+
this.logger = (props === null || props === void 0 ? void 0 : props.logger) instanceof utils_1.Logger ? props.logger : new utils_1.Logger({ level: utils_1.LoggerLevels.WARNING });
|
|
43
|
+
this.loader = check_types_1.default.function((_c = this.config) === null || _c === void 0 ? void 0 : _c.loader) ? this.config.loader : new DataCache_1.DataCache(this.config);
|
|
43
44
|
}
|
|
44
45
|
setConfigPart(props) {
|
|
45
46
|
Object.assign(this.config, props);
|
package/build/constants.d.ts
CHANGED
|
@@ -15,4 +15,16 @@ declare const DEFAULT_ORDER_NO = "10000000";
|
|
|
15
15
|
declare const DEFAULT_ORDER_NO_STEP = "1000";
|
|
16
16
|
declare const DEFAULT_JWT_ALGORITHM = "HS256";
|
|
17
17
|
declare const DEFAULT_JWT_ISSUER = "microservices-auth";
|
|
18
|
-
|
|
18
|
+
declare const ACTIONS: {
|
|
19
|
+
LIST: string;
|
|
20
|
+
GET: string;
|
|
21
|
+
GET_MANY: string;
|
|
22
|
+
CREATE: string;
|
|
23
|
+
CREATE_MANY: string;
|
|
24
|
+
UPDATE: string;
|
|
25
|
+
UPDATE_MANY: string;
|
|
26
|
+
SET: string;
|
|
27
|
+
REMOVE: string;
|
|
28
|
+
REMOVE_MANY: string;
|
|
29
|
+
};
|
|
30
|
+
export { ID_FIELD, FIELDS, ORDER_BYS, HEADERS, DEFAULT_ORDER_NO, DEFAULT_ORDER_NO_STEP, ID_TYPES, DEFAULT_JWT_ALGORITHM, DEFAULT_JWT_ISSUER, ACTIONS, };
|
package/build/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_JWT_ISSUER = exports.DEFAULT_JWT_ALGORITHM = exports.ID_TYPES = exports.DEFAULT_ORDER_NO_STEP = exports.DEFAULT_ORDER_NO = exports.HEADERS = exports.ORDER_BYS = exports.FIELDS = exports.ID_FIELD = void 0;
|
|
3
|
+
exports.ACTIONS = exports.DEFAULT_JWT_ISSUER = exports.DEFAULT_JWT_ALGORITHM = exports.ID_TYPES = exports.DEFAULT_ORDER_NO_STEP = exports.DEFAULT_ORDER_NO = exports.HEADERS = exports.ORDER_BYS = exports.FIELDS = exports.ID_FIELD = void 0;
|
|
4
4
|
const FIELDS = {
|
|
5
5
|
ID: 'id',
|
|
6
6
|
STATUS: 'status',
|
|
@@ -66,3 +66,16 @@ const DEFAULT_JWT_ALGORITHM = 'HS256';
|
|
|
66
66
|
exports.DEFAULT_JWT_ALGORITHM = DEFAULT_JWT_ALGORITHM;
|
|
67
67
|
const DEFAULT_JWT_ISSUER = 'microservices-auth';
|
|
68
68
|
exports.DEFAULT_JWT_ISSUER = DEFAULT_JWT_ISSUER;
|
|
69
|
+
const ACTIONS = {
|
|
70
|
+
LIST: 'LIST',
|
|
71
|
+
GET: 'GET',
|
|
72
|
+
GET_MANY: 'GET_MANY',
|
|
73
|
+
CREATE: 'CREATE',
|
|
74
|
+
CREATE_MANY: 'CREATE_MANY',
|
|
75
|
+
UPDATE: 'UPDATE',
|
|
76
|
+
UPDATE_MANY: 'UPDATE_MANY',
|
|
77
|
+
SET: 'SET',
|
|
78
|
+
REMOVE: 'REMOVE',
|
|
79
|
+
REMOVE_MANY: 'REMOVE_MANY',
|
|
80
|
+
};
|
|
81
|
+
exports.ACTIONS = ACTIONS;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface BaseCoreDoAuthOnActionInterface {
|
|
2
|
+
list?: boolean;
|
|
3
|
+
get?: boolean;
|
|
4
|
+
getMany?: boolean;
|
|
5
|
+
create?: boolean;
|
|
6
|
+
createMany?: boolean;
|
|
7
|
+
update?: boolean;
|
|
8
|
+
updateMany?: boolean;
|
|
9
|
+
set?: boolean;
|
|
10
|
+
remove?: boolean;
|
|
11
|
+
removeMany?: boolean;
|
|
12
|
+
}
|
|
@@ -6,6 +6,7 @@ import { BaseCoreDoingWhatInterface } from './BaseCoreDoingWhatInterface';
|
|
|
6
6
|
import { VerifyUserTokenArgs } from './VerifyUserTokenArgs';
|
|
7
7
|
import { ApiContext } from './ApiContext';
|
|
8
8
|
import { ID_TYPES } from '../constants';
|
|
9
|
+
import { BaseCoreDoAuthOnActionInterface } from './BaseCoreDoAuthOnActionInterface';
|
|
9
10
|
export interface BaseCorePropsInterface {
|
|
10
11
|
/**
|
|
11
12
|
* Application API context with all necessary information about request
|
|
@@ -23,6 +24,7 @@ export interface BaseCorePropsInterface {
|
|
|
23
24
|
logger: Logger;
|
|
24
25
|
name?: string;
|
|
25
26
|
doAuth: boolean;
|
|
27
|
+
doAuthOnAction?: BaseCoreDoAuthOnActionInterface;
|
|
26
28
|
doingWhat?: BaseCoreDoingWhatInterface;
|
|
27
29
|
validators?: BaseCoreValidatorsInterface;
|
|
28
30
|
spaceGw?: BaseGateway;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseCoreActionsInterface } from './BaseCoreActionsInterface';
|
|
2
2
|
export interface CoreActionInterface {
|
|
3
3
|
args: any;
|
|
4
|
+
actionName?: string;
|
|
4
5
|
doAuth?: boolean;
|
|
5
6
|
accessRights?: any[];
|
|
6
7
|
validate?(args: any, opt: BaseCoreActionsInterface): Promise<any[]> | any[];
|
|
@@ -40,3 +40,4 @@ __exportStar(require("./CreateUserTokenResult"), exports);
|
|
|
40
40
|
__exportStar(require("./ExtractCredentialsArgs"), exports);
|
|
41
41
|
__exportStar(require("./DownloadFileArgs"), exports);
|
|
42
42
|
__exportStar(require("./BuildListQueryArgsInterface"), exports);
|
|
43
|
+
__exportStar(require("./BaseCoreDoAuthOnActionInterface"), exports);
|
package/package.json
CHANGED