@sdflc/backend-helpers 1.0.25 → 1.0.28
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/README.md +175 -0
- package/build/{baseController.d.ts → BaseController.d.ts} +0 -0
- package/build/{baseController.js → BaseController.js} +0 -0
- package/build/{baseCore.d.ts → BaseCore.d.ts} +13 -19
- package/build/{baseCore.js → BaseCore.js} +115 -157
- package/build/{baseGateway.d.ts → BaseGateway.d.ts} +15 -11
- package/build/{baseGateway.js → BaseGateway.js} +148 -97
- package/build/{dataCache.d.ts → DataCache.d.ts} +0 -0
- package/build/{dataCache.js → DataCache.js} +2 -2
- package/build/{database.d.ts → Database.d.ts} +0 -0
- package/build/{database.js → Database.js} +0 -0
- package/build/{dbMigratorAndSeeder.d.ts → DbMigratorAndSeeder.d.ts} +0 -0
- package/build/{dbMigratorAndSeeder.js → DbMigratorAndSeeder.js} +5 -1
- package/build/apiContext.d.ts +3 -3
- package/build/apiContext.js +89 -32
- package/build/constants.d.ts +4 -5
- package/build/constants.js +23 -4
- package/build/dbSeeder.js +5 -1
- package/build/dbTableHelpers.d.ts +2 -0
- package/build/dbTableHelpers.js +48 -27
- package/build/index.d.ts +9 -11
- package/build/index.js +19 -20
- package/build/interfaces/ApiContext.d.ts +23 -0
- package/build/interfaces/{BaseCoreInterface.js → ApiContext.js} +0 -0
- package/build/interfaces/ApiContextInterface.d.ts +5 -1
- package/build/interfaces/BaseCorePropsInterface.d.ts +31 -0
- package/build/interfaces/{BaseGatewayInterface.js → BaseCorePropsInterface.js} +0 -0
- package/build/interfaces/BaseGatewayPropsInterface.d.ts +29 -0
- package/build/interfaces/BaseGatewayPropsInterface.js +2 -0
- package/build/interfaces/CacheInterface.d.ts +3 -3
- package/build/interfaces/CoreActionInterface.d.ts +1 -1
- package/build/interfaces/JwtTokenSecretAndSettings.d.ts +5 -0
- package/build/interfaces/JwtTokenSecretAndSettings.js +2 -0
- package/build/interfaces/index.d.ts +4 -2
- package/build/resolversHelpers.js +11 -10
- package/build/userToken.js +3 -3
- package/package.json +68 -68
- package/build/baseGatewayHelpers.d.ts +0 -20
- package/build/baseGatewayHelpers.js +0 -87
- package/build/interfaces/BaseCoreInterface.d.ts +0 -43
- package/build/interfaces/BaseGatewayInterface.d.ts +0 -26
|
@@ -51,12 +51,7 @@ exports.BaseCore = void 0;
|
|
|
51
51
|
var api_helpers_1 = require("@sdflc/api-helpers");
|
|
52
52
|
var utils_1 = require("@sdflc/utils");
|
|
53
53
|
var userToken_1 = require("./userToken");
|
|
54
|
-
var
|
|
55
|
-
var utils_2 = require("./utils");
|
|
56
|
-
var defaultAfterAndBefore = function (params, opt) {
|
|
57
|
-
return params;
|
|
58
|
-
};
|
|
59
|
-
var defaultValidate = function (params, opt) {
|
|
54
|
+
var defaultValidate = function ( /*params: any, opt?: BaseCoreActionsInterface*/) {
|
|
60
55
|
return [true, {}];
|
|
61
56
|
};
|
|
62
57
|
var defaultValidators = {
|
|
@@ -73,44 +68,23 @@ var defaultValidators = {
|
|
|
73
68
|
};
|
|
74
69
|
var BaseCore = /** @class */ (function () {
|
|
75
70
|
function BaseCore(props) {
|
|
76
|
-
|
|
77
|
-
this.
|
|
78
|
-
this.props = props || {};
|
|
79
|
-
this.db = props.db;
|
|
80
|
-
this.name = props.name || '';
|
|
81
|
-
this.context = props.context || {};
|
|
82
|
-
this.doingWhat = props.doingWhat;
|
|
83
|
-
this.logger = props.logger || new utils_1.Logger({ level: props.logLevel });
|
|
84
|
-
this.gateway = props.gateway;
|
|
85
|
-
this.gateways = __assign({ gateway: this.gateway }, (props.gateways || {}));
|
|
86
|
-
if (this.gateway instanceof baseGateway_1.BaseGateway) {
|
|
87
|
-
this.gateway.setCore(this);
|
|
88
|
-
}
|
|
89
|
-
Object.keys(this.gateways).forEach(function (gatewayName) {
|
|
90
|
-
var gateway = _this.gateways[gatewayName];
|
|
91
|
-
if (gateway instanceof baseGateway_1.BaseGateway) {
|
|
92
|
-
gateway.setCore(_this);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
this.gwSpace = props.gwSpace;
|
|
96
|
-
this.interserviceApiKey = props.interserviceApiKey;
|
|
97
|
-
this.jwtSecret = props.jwtSecret || '';
|
|
98
|
-
this.verifytokenArgs = props.verifytokenArgs;
|
|
99
|
-
this.validators = (0, utils_2.setFunctions)((props === null || props === void 0 ? void 0 : props.validators) || {}, this.validators);
|
|
100
|
-
this.doAuth = props.doAuth === true;
|
|
101
|
-
this.requestId = props.requestId || '';
|
|
71
|
+
this.config = props;
|
|
72
|
+
this.logger = props.logger;
|
|
102
73
|
}
|
|
103
74
|
BaseCore.prototype.getDb = function () {
|
|
104
|
-
return this.db;
|
|
75
|
+
return this.config.db;
|
|
105
76
|
};
|
|
106
77
|
BaseCore.prototype.getRequestId = function () {
|
|
107
|
-
return this.requestId;
|
|
78
|
+
return this.config.context.requestId;
|
|
108
79
|
};
|
|
109
|
-
BaseCore.prototype.getContext = function (
|
|
110
|
-
return
|
|
80
|
+
BaseCore.prototype.getContext = function () {
|
|
81
|
+
return this.config.context;
|
|
111
82
|
};
|
|
112
83
|
BaseCore.prototype.getGateways = function () {
|
|
113
|
-
return this.gateways || {};
|
|
84
|
+
return this.config.context.gateways || {};
|
|
85
|
+
};
|
|
86
|
+
BaseCore.prototype.getValidators = function () {
|
|
87
|
+
return defaultValidators;
|
|
114
88
|
};
|
|
115
89
|
BaseCore.prototype.success = function (data, code) {
|
|
116
90
|
var code2use = code != null ? code : api_helpers_1.OP_RESULT_CODES.OK;
|
|
@@ -175,11 +149,11 @@ var BaseCore = /** @class */ (function () {
|
|
|
175
149
|
}
|
|
176
150
|
if (!(hasTransaction && result)) return [3 /*break*/, 4];
|
|
177
151
|
if (!(result.code >= api_helpers_1.OP_RESULT_CODES.OK)) return [3 /*break*/, 2];
|
|
178
|
-
return [4 /*yield*/, this.
|
|
152
|
+
return [4 /*yield*/, this.getDb().commitTransaction()];
|
|
179
153
|
case 1:
|
|
180
154
|
_a.sent();
|
|
181
155
|
return [3 /*break*/, 4];
|
|
182
|
-
case 2: return [4 /*yield*/, this.
|
|
156
|
+
case 2: return [4 /*yield*/, this.getDb().rollbackTransaction()];
|
|
183
157
|
case 3:
|
|
184
158
|
_a.sent();
|
|
185
159
|
_a.label = 4;
|
|
@@ -195,7 +169,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
195
169
|
switch (_c.label) {
|
|
196
170
|
case 0:
|
|
197
171
|
_a = opt || {}, args = _a.args, validate = _a.validate, doAuth = _a.doAuth, action = _a.action, hasTransaction = _a.hasTransaction, doingWhat = _a.doingWhat;
|
|
198
|
-
sameRequest = !!this.requestId && (args === null || args === void 0 ? void 0 : args.requestId) === this.requestId;
|
|
172
|
+
sameRequest = !!this.config.context.requestId && (args === null || args === void 0 ? void 0 : args.requestId) === this.config.context.requestId;
|
|
199
173
|
step = doingWhat || '';
|
|
200
174
|
setStep = function (stepName) {
|
|
201
175
|
step = stepName;
|
|
@@ -211,12 +185,12 @@ var BaseCore = /** @class */ (function () {
|
|
|
211
185
|
_c.trys.push([1, 11, , 15]);
|
|
212
186
|
if (!!sameRequest) return [3 /*break*/, 5];
|
|
213
187
|
if (!hasTransaction) return [3 /*break*/, 3];
|
|
214
|
-
return [4 /*yield*/, this.
|
|
188
|
+
return [4 /*yield*/, this.getDb().startTransaction()];
|
|
215
189
|
case 2:
|
|
216
190
|
_c.sent();
|
|
217
191
|
_c.label = 3;
|
|
218
192
|
case 3:
|
|
219
|
-
if (!(doAuth === true || (doAuth == null && this.doAuth))) return [3 /*break*/, 5];
|
|
193
|
+
if (!(doAuth === true || (doAuth == null && this.config.doAuth))) return [3 /*break*/, 5];
|
|
220
194
|
return [4 /*yield*/, this.authenticate(opt, actionOpt)];
|
|
221
195
|
case 4:
|
|
222
196
|
_b = _c.sent(), authResult = _b[0], errMsg = _b[1];
|
|
@@ -254,7 +228,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
254
228
|
case 11:
|
|
255
229
|
ex_1 = _c.sent();
|
|
256
230
|
if (!(!sameRequest && hasTransaction)) return [3 /*break*/, 13];
|
|
257
|
-
return [4 /*yield*/, this.
|
|
231
|
+
return [4 /*yield*/, this.getDb().rollbackTransaction()];
|
|
258
232
|
case 12:
|
|
259
233
|
_c.sent();
|
|
260
234
|
_c.label = 13;
|
|
@@ -280,7 +254,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
280
254
|
return __generator(this, function (_d) {
|
|
281
255
|
return [2 /*return*/, this.runAction({
|
|
282
256
|
args: args,
|
|
283
|
-
validate: this.
|
|
257
|
+
validate: this.getValidators().list,
|
|
284
258
|
accessRights: [utils_1.ACCESS_RIGHTS.LIST],
|
|
285
259
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
286
260
|
var object, items, result;
|
|
@@ -288,11 +262,11 @@ var BaseCore = /** @class */ (function () {
|
|
|
288
262
|
return __generator(this, function (_b) {
|
|
289
263
|
switch (_b.label) {
|
|
290
264
|
case 0:
|
|
291
|
-
this.logger.log("Requesting a list for ".concat(this.name, ":"), args);
|
|
265
|
+
this.logger.log("Requesting a list for ".concat(this.config.name, ":"), args);
|
|
292
266
|
return [4 /*yield*/, this.beforeList(args, opt)];
|
|
293
267
|
case 1:
|
|
294
268
|
object = _b.sent();
|
|
295
|
-
return [4 /*yield*/, ((_a = this.
|
|
269
|
+
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.list(object))];
|
|
296
270
|
case 2:
|
|
297
271
|
items = _b.sent();
|
|
298
272
|
return [4 /*yield*/, this.afterList(items, opt)];
|
|
@@ -304,7 +278,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
304
278
|
});
|
|
305
279
|
}); },
|
|
306
280
|
hasTransaction: false,
|
|
307
|
-
doingWhat: (_c = (_b = (_a = this.doingWhat) === null || _a === void 0 ? void 0 : _a.list) !== null && _b !== void 0 ? _b : this.name) !== null && _c !== void 0 ? _c : 'listing',
|
|
281
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.list) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'listing',
|
|
308
282
|
})];
|
|
309
283
|
});
|
|
310
284
|
});
|
|
@@ -316,7 +290,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
316
290
|
return __generator(this, function (_d) {
|
|
317
291
|
return [2 /*return*/, this.runAction({
|
|
318
292
|
args: args,
|
|
319
|
-
validate: this.
|
|
293
|
+
validate: this.getValidators().get,
|
|
320
294
|
accessRights: [utils_1.ACCESS_RIGHTS.GET],
|
|
321
295
|
action: function (args) { return __awaiter(_this, void 0, void 0, function () {
|
|
322
296
|
var id, item;
|
|
@@ -325,8 +299,8 @@ var BaseCore = /** @class */ (function () {
|
|
|
325
299
|
switch (_b.label) {
|
|
326
300
|
case 0:
|
|
327
301
|
id = (args || {}).id;
|
|
328
|
-
this.logger.log("Requesting an item for ".concat(this.name, ":"), args);
|
|
329
|
-
return [4 /*yield*/, ((_a = this.
|
|
302
|
+
this.logger.log("Requesting an item for ".concat(this.config.name, ":"), args);
|
|
303
|
+
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.get(id))];
|
|
330
304
|
case 1:
|
|
331
305
|
item = _b.sent();
|
|
332
306
|
return [2 /*return*/, this.success([item], item ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND)];
|
|
@@ -334,7 +308,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
334
308
|
});
|
|
335
309
|
}); },
|
|
336
310
|
hasTransaction: false,
|
|
337
|
-
doingWhat: (_c = (_b = (_a = this.doingWhat) === null || _a === void 0 ? void 0 : _a.get) !== null && _b !== void 0 ? _b : this.name) !== null && _c !== void 0 ? _c : 'getting an item',
|
|
311
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.get) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'getting an item',
|
|
338
312
|
})];
|
|
339
313
|
});
|
|
340
314
|
});
|
|
@@ -346,7 +320,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
346
320
|
return __generator(this, function (_d) {
|
|
347
321
|
return [2 /*return*/, this.runAction({
|
|
348
322
|
args: args,
|
|
349
|
-
validate: this.
|
|
323
|
+
validate: this.getValidators().getMany,
|
|
350
324
|
accessRights: [utils_1.ACCESS_RIGHTS.GET],
|
|
351
325
|
action: function (args) { return __awaiter(_this, void 0, void 0, function () {
|
|
352
326
|
var ids, items;
|
|
@@ -355,8 +329,8 @@ var BaseCore = /** @class */ (function () {
|
|
|
355
329
|
switch (_b.label) {
|
|
356
330
|
case 0:
|
|
357
331
|
ids = (args || {}).ids;
|
|
358
|
-
this.logger.log("Requesting multiple items for ".concat(this.name, ":"), args);
|
|
359
|
-
return [4 /*yield*/, ((_a = this.
|
|
332
|
+
this.logger.log("Requesting multiple items for ".concat(this.config.name, ":"), args);
|
|
333
|
+
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.getMany(ids))];
|
|
360
334
|
case 1:
|
|
361
335
|
items = _b.sent();
|
|
362
336
|
return [2 /*return*/, this.success(items, items.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND)];
|
|
@@ -364,7 +338,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
364
338
|
});
|
|
365
339
|
}); },
|
|
366
340
|
hasTransaction: false,
|
|
367
|
-
doingWhat: (_c = (_b = (_a = this.doingWhat) === null || _a === void 0 ? void 0 : _a.getMany) !== null && _b !== void 0 ? _b : this.name) !== null && _c !== void 0 ? _c : 'geting multiple items',
|
|
341
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.getMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'geting multiple items',
|
|
368
342
|
})];
|
|
369
343
|
});
|
|
370
344
|
});
|
|
@@ -376,7 +350,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
376
350
|
return __generator(this, function (_d) {
|
|
377
351
|
return [2 /*return*/, this.runAction({
|
|
378
352
|
args: args,
|
|
379
|
-
validate: this.
|
|
353
|
+
validate: this.getValidators().create,
|
|
380
354
|
accessRights: [utils_1.ACCESS_RIGHTS.CREATE],
|
|
381
355
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
382
356
|
var params, object, item, result;
|
|
@@ -385,11 +359,11 @@ var BaseCore = /** @class */ (function () {
|
|
|
385
359
|
switch (_b.label) {
|
|
386
360
|
case 0:
|
|
387
361
|
params = (args || {}).params;
|
|
388
|
-
this.logger.log("Requesting creation of an item for ".concat(this.name, ":"), args);
|
|
362
|
+
this.logger.log("Requesting creation of an item for ".concat(this.config.name, ":"), args);
|
|
389
363
|
return [4 /*yield*/, this.beforeCreate(params, opt)];
|
|
390
364
|
case 1:
|
|
391
365
|
object = _b.sent();
|
|
392
|
-
return [4 /*yield*/, ((_a = this.
|
|
366
|
+
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.create(object))];
|
|
393
367
|
case 2:
|
|
394
368
|
item = _b.sent();
|
|
395
369
|
return [4 /*yield*/, this.afterCreate(item, opt)];
|
|
@@ -400,7 +374,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
400
374
|
});
|
|
401
375
|
}); },
|
|
402
376
|
hasTransaction: true,
|
|
403
|
-
doingWhat: (_c = (_b = (_a = this.doingWhat) === null || _a === void 0 ? void 0 : _a.create) !== null && _b !== void 0 ? _b : this.name) !== null && _c !== void 0 ? _c : 'creating an item',
|
|
377
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.create) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'creating an item',
|
|
404
378
|
})];
|
|
405
379
|
});
|
|
406
380
|
});
|
|
@@ -412,7 +386,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
412
386
|
return __generator(this, function (_d) {
|
|
413
387
|
return [2 /*return*/, this.runAction({
|
|
414
388
|
args: args,
|
|
415
|
-
validate: this.
|
|
389
|
+
validate: this.getValidators().createMany,
|
|
416
390
|
accessRights: [utils_1.ACCESS_RIGHTS.CREATE],
|
|
417
391
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
418
392
|
var params, objects, items, result;
|
|
@@ -421,11 +395,11 @@ var BaseCore = /** @class */ (function () {
|
|
|
421
395
|
switch (_b.label) {
|
|
422
396
|
case 0:
|
|
423
397
|
params = (args || {}).params;
|
|
424
|
-
this.logger.log("Requesting creation of multiple items for ".concat(this.name, ":"), args);
|
|
398
|
+
this.logger.log("Requesting creation of multiple items for ".concat(this.config.name, ":"), args);
|
|
425
399
|
return [4 /*yield*/, this.beforeCreateMany(params, opt)];
|
|
426
400
|
case 1:
|
|
427
401
|
objects = _b.sent();
|
|
428
|
-
return [4 /*yield*/, ((_a = this.
|
|
402
|
+
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.create(objects))];
|
|
429
403
|
case 2:
|
|
430
404
|
items = _b.sent();
|
|
431
405
|
return [4 /*yield*/, this.afterCreateMany(items, opt)];
|
|
@@ -436,7 +410,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
436
410
|
});
|
|
437
411
|
}); },
|
|
438
412
|
hasTransaction: true,
|
|
439
|
-
doingWhat: (_c = (_b = (_a = this.doingWhat) === null || _a === void 0 ? void 0 : _a.createMany) !== null && _b !== void 0 ? _b : this.name) !== null && _c !== void 0 ? _c : 'creating multiple items',
|
|
413
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.createMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'creating multiple items',
|
|
440
414
|
})];
|
|
441
415
|
});
|
|
442
416
|
});
|
|
@@ -448,7 +422,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
448
422
|
return __generator(this, function (_d) {
|
|
449
423
|
return [2 /*return*/, this.runAction({
|
|
450
424
|
args: args,
|
|
451
|
-
validate: this.
|
|
425
|
+
validate: this.getValidators().update,
|
|
452
426
|
accessRights: [utils_1.ACCESS_RIGHTS.UPDATE],
|
|
453
427
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
454
428
|
var _a, where, params, object, item, result;
|
|
@@ -457,11 +431,11 @@ var BaseCore = /** @class */ (function () {
|
|
|
457
431
|
switch (_c.label) {
|
|
458
432
|
case 0:
|
|
459
433
|
_a = args || {}, where = _a.where, params = _a.params;
|
|
460
|
-
this.logger.log("Requesting update of an item for ".concat(this.name, ":"), args);
|
|
434
|
+
this.logger.log("Requesting update of an item for ".concat(this.config.name, ":"), args);
|
|
461
435
|
return [4 /*yield*/, this.beforeUpdate(params, opt)];
|
|
462
436
|
case 1:
|
|
463
437
|
object = _c.sent();
|
|
464
|
-
return [4 /*yield*/, ((_b = this.
|
|
438
|
+
return [4 /*yield*/, ((_b = this.getContext().gateways[this.config.gatewayName]) === null || _b === void 0 ? void 0 : _b.update(where, object))];
|
|
465
439
|
case 2:
|
|
466
440
|
item = _c.sent();
|
|
467
441
|
return [4 /*yield*/, this.afterUpdate(item, opt)];
|
|
@@ -472,7 +446,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
472
446
|
});
|
|
473
447
|
}); },
|
|
474
448
|
hasTransaction: true,
|
|
475
|
-
doingWhat: (_c = (_b = (_a = this.doingWhat) === null || _a === void 0 ? void 0 : _a.update) !== null && _b !== void 0 ? _b : this.name) !== null && _c !== void 0 ? _c : 'updating an item',
|
|
449
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.update) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'updating an item',
|
|
476
450
|
})];
|
|
477
451
|
});
|
|
478
452
|
});
|
|
@@ -484,7 +458,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
484
458
|
return __generator(this, function (_d) {
|
|
485
459
|
return [2 /*return*/, this.runAction({
|
|
486
460
|
args: args,
|
|
487
|
-
validate: this.
|
|
461
|
+
validate: this.getValidators().updateMany,
|
|
488
462
|
accessRights: [utils_1.ACCESS_RIGHTS.UPDATE],
|
|
489
463
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
490
464
|
var params, object, items, result;
|
|
@@ -493,11 +467,11 @@ var BaseCore = /** @class */ (function () {
|
|
|
493
467
|
switch (_b.label) {
|
|
494
468
|
case 0:
|
|
495
469
|
params = (args || {}).params;
|
|
496
|
-
this.logger.log("Requesting update of an item for ".concat(this.name, ":"), args);
|
|
470
|
+
this.logger.log("Requesting update of an item for ".concat(this.config.name, ":"), args);
|
|
497
471
|
return [4 /*yield*/, this.beforeUpdateMany(params, opt)];
|
|
498
472
|
case 1:
|
|
499
473
|
object = _b.sent();
|
|
500
|
-
return [4 /*yield*/, ((_a = this.
|
|
474
|
+
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.updateMany(object))];
|
|
501
475
|
case 2:
|
|
502
476
|
items = _b.sent();
|
|
503
477
|
return [4 /*yield*/, this.afterUpdateMany(items, opt)];
|
|
@@ -508,7 +482,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
508
482
|
});
|
|
509
483
|
}); },
|
|
510
484
|
hasTransaction: true,
|
|
511
|
-
doingWhat: (_c = (_b = (_a = this.doingWhat) === null || _a === void 0 ? void 0 : _a.updateMany) !== null && _b !== void 0 ? _b : this.name) !== null && _c !== void 0 ? _c : 'updating multiple items',
|
|
485
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.updateMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'updating multiple items',
|
|
512
486
|
})];
|
|
513
487
|
});
|
|
514
488
|
});
|
|
@@ -520,7 +494,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
520
494
|
return __generator(this, function (_d) {
|
|
521
495
|
return [2 /*return*/, this.runAction({
|
|
522
496
|
args: args,
|
|
523
|
-
validate: this.
|
|
497
|
+
validate: this.getValidators().set,
|
|
524
498
|
accessRights: [utils_1.ACCESS_RIGHTS.CREATE, utils_1.ACCESS_RIGHTS.UPDATE],
|
|
525
499
|
action: function (args, opt /* { setStep, validatedItems, sameRequest } */) { return __awaiter(_this, void 0, void 0, function () {
|
|
526
500
|
var params, object, items, result;
|
|
@@ -529,11 +503,11 @@ var BaseCore = /** @class */ (function () {
|
|
|
529
503
|
switch (_b.label) {
|
|
530
504
|
case 0:
|
|
531
505
|
params = (args || {}).params;
|
|
532
|
-
this.logger.log("Requesting setting of item(s) for ".concat(this.name, ":"), args);
|
|
506
|
+
this.logger.log("Requesting setting of item(s) for ".concat(this.config.name, ":"), args);
|
|
533
507
|
return [4 /*yield*/, this.beforeSet(params, opt)];
|
|
534
508
|
case 1:
|
|
535
509
|
object = _b.sent();
|
|
536
|
-
return [4 /*yield*/, ((_a = this.
|
|
510
|
+
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.set(object))];
|
|
537
511
|
case 2:
|
|
538
512
|
items = _b.sent();
|
|
539
513
|
return [4 /*yield*/, this.afterSet(items, opt)];
|
|
@@ -544,7 +518,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
544
518
|
});
|
|
545
519
|
}); },
|
|
546
520
|
hasTransaction: true,
|
|
547
|
-
doingWhat: (_c = (_b = (_a = this.doingWhat) === null || _a === void 0 ? void 0 : _a.updateMany) !== null && _b !== void 0 ? _b : this.name) !== null && _c !== void 0 ? _c : 'updating multiple items',
|
|
521
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.updateMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'updating multiple items',
|
|
548
522
|
})];
|
|
549
523
|
});
|
|
550
524
|
});
|
|
@@ -556,7 +530,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
556
530
|
return __generator(this, function (_d) {
|
|
557
531
|
return [2 /*return*/, this.runAction({
|
|
558
532
|
args: args,
|
|
559
|
-
validate: this.
|
|
533
|
+
validate: this.getValidators().remove,
|
|
560
534
|
accessRights: [utils_1.ACCESS_RIGHTS.REMOVE],
|
|
561
535
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
562
536
|
var where, object, items, result;
|
|
@@ -565,11 +539,11 @@ var BaseCore = /** @class */ (function () {
|
|
|
565
539
|
switch (_b.label) {
|
|
566
540
|
case 0:
|
|
567
541
|
where = (args || {}).where;
|
|
568
|
-
this.logger.log("Requesting removal of an item for ".concat(this.name, ":"), args);
|
|
542
|
+
this.logger.log("Requesting removal of an item for ".concat(this.config.name, ":"), args);
|
|
569
543
|
return [4 /*yield*/, this.beforeRemove(where, opt)];
|
|
570
544
|
case 1:
|
|
571
545
|
object = _b.sent();
|
|
572
|
-
return [4 /*yield*/, ((_a = this.
|
|
546
|
+
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.remove(object))];
|
|
573
547
|
case 2:
|
|
574
548
|
items = _b.sent();
|
|
575
549
|
return [4 /*yield*/, this.afterRemove(items, opt)];
|
|
@@ -580,7 +554,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
580
554
|
});
|
|
581
555
|
}); },
|
|
582
556
|
hasTransaction: false,
|
|
583
|
-
doingWhat: (_c = (_b = (_a = this.doingWhat) === null || _a === void 0 ? void 0 : _a.remove) !== null && _b !== void 0 ? _b : this.name) !== null && _c !== void 0 ? _c : 'removing an item',
|
|
557
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.remove) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'removing an item',
|
|
584
558
|
})];
|
|
585
559
|
});
|
|
586
560
|
});
|
|
@@ -592,7 +566,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
592
566
|
return __generator(this, function (_d) {
|
|
593
567
|
return [2 /*return*/, this.runAction({
|
|
594
568
|
args: args,
|
|
595
|
-
validate: this.
|
|
569
|
+
validate: this.getValidators().removeMany,
|
|
596
570
|
accessRights: [utils_1.ACCESS_RIGHTS.REMOVE],
|
|
597
571
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
598
572
|
var where, object, items, result;
|
|
@@ -601,11 +575,11 @@ var BaseCore = /** @class */ (function () {
|
|
|
601
575
|
switch (_b.label) {
|
|
602
576
|
case 0:
|
|
603
577
|
where = (args || {}).where;
|
|
604
|
-
this.logger.log("Requesting removal of multiple items for ".concat(this.name, ":"), args);
|
|
578
|
+
this.logger.log("Requesting removal of multiple items for ".concat(this.config.name, ":"), args);
|
|
605
579
|
return [4 /*yield*/, this.beforeRemoveMany(where, opt)];
|
|
606
580
|
case 1:
|
|
607
581
|
object = _b.sent();
|
|
608
|
-
return [4 /*yield*/, ((_a = this.
|
|
582
|
+
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.remove(object))];
|
|
609
583
|
case 2:
|
|
610
584
|
items = _b.sent();
|
|
611
585
|
return [4 /*yield*/, this.afterRemoveMany(items, opt)];
|
|
@@ -616,181 +590,177 @@ var BaseCore = /** @class */ (function () {
|
|
|
616
590
|
});
|
|
617
591
|
}); },
|
|
618
592
|
hasTransaction: false,
|
|
619
|
-
doingWhat: (_c = (_b = (_a = this.doingWhat) === null || _a === void 0 ? void 0 : _a.removeMany) !== null && _b !== void 0 ? _b : this.name) !== null && _c !== void 0 ? _c : 'removing multiple items',
|
|
593
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.removeMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'removing multiple items',
|
|
620
594
|
})];
|
|
621
595
|
});
|
|
622
596
|
});
|
|
623
597
|
};
|
|
598
|
+
BaseCore.prototype.defaultAfterAndBefore = function (params, opt) {
|
|
599
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
600
|
+
return __generator(this, function (_a) {
|
|
601
|
+
return [2 /*return*/, params];
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
};
|
|
624
605
|
BaseCore.prototype.beforeList = function (params, opt) {
|
|
625
606
|
return __awaiter(this, void 0, void 0, function () {
|
|
626
|
-
var fn;
|
|
627
607
|
return __generator(this, function (_a) {
|
|
628
|
-
|
|
629
|
-
return [2 /*return*/, fn(params, opt)];
|
|
608
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
630
609
|
});
|
|
631
610
|
});
|
|
632
611
|
};
|
|
633
612
|
BaseCore.prototype.afterList = function (params, opt) {
|
|
634
613
|
return __awaiter(this, void 0, void 0, function () {
|
|
635
|
-
var fn;
|
|
636
614
|
return __generator(this, function (_a) {
|
|
637
|
-
|
|
638
|
-
return [2 /*return*/, fn(params, opt)];
|
|
615
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
639
616
|
});
|
|
640
617
|
});
|
|
641
618
|
};
|
|
642
619
|
BaseCore.prototype.beforeCreate = function (params, opt) {
|
|
643
620
|
return __awaiter(this, void 0, void 0, function () {
|
|
644
|
-
var fn;
|
|
645
621
|
return __generator(this, function (_a) {
|
|
646
|
-
|
|
647
|
-
return [2 /*return*/, fn(params, opt)];
|
|
622
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
648
623
|
});
|
|
649
624
|
});
|
|
650
625
|
};
|
|
651
626
|
BaseCore.prototype.afterCreate = function (params, opt) {
|
|
652
627
|
return __awaiter(this, void 0, void 0, function () {
|
|
653
|
-
var fn;
|
|
654
628
|
return __generator(this, function (_a) {
|
|
655
|
-
|
|
656
|
-
return [2 /*return*/, fn(params, opt)];
|
|
629
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
657
630
|
});
|
|
658
631
|
});
|
|
659
632
|
};
|
|
660
633
|
BaseCore.prototype.beforeCreateMany = function (params, opt) {
|
|
661
634
|
return __awaiter(this, void 0, void 0, function () {
|
|
662
|
-
var fn;
|
|
663
635
|
return __generator(this, function (_a) {
|
|
664
|
-
|
|
665
|
-
return [2 /*return*/, fn(params, opt)];
|
|
636
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
666
637
|
});
|
|
667
638
|
});
|
|
668
639
|
};
|
|
669
640
|
BaseCore.prototype.afterCreateMany = function (params, opt) {
|
|
670
641
|
return __awaiter(this, void 0, void 0, function () {
|
|
671
|
-
var fn;
|
|
672
642
|
return __generator(this, function (_a) {
|
|
673
|
-
|
|
674
|
-
return [2 /*return*/, fn(params, opt)];
|
|
643
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
675
644
|
});
|
|
676
645
|
});
|
|
677
646
|
};
|
|
678
647
|
BaseCore.prototype.beforeUpdate = function (params, opt) {
|
|
679
648
|
return __awaiter(this, void 0, void 0, function () {
|
|
680
|
-
var fn;
|
|
681
649
|
return __generator(this, function (_a) {
|
|
682
|
-
|
|
683
|
-
return [2 /*return*/, fn(params, opt)];
|
|
650
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
684
651
|
});
|
|
685
652
|
});
|
|
686
653
|
};
|
|
687
654
|
BaseCore.prototype.afterUpdate = function (params, opt) {
|
|
688
655
|
return __awaiter(this, void 0, void 0, function () {
|
|
689
|
-
var fn;
|
|
690
656
|
return __generator(this, function (_a) {
|
|
691
|
-
|
|
692
|
-
return [2 /*return*/, fn(params, opt)];
|
|
657
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
693
658
|
});
|
|
694
659
|
});
|
|
695
660
|
};
|
|
696
661
|
BaseCore.prototype.beforeUpdateMany = function (params, opt) {
|
|
697
662
|
return __awaiter(this, void 0, void 0, function () {
|
|
698
|
-
var fn;
|
|
699
663
|
return __generator(this, function (_a) {
|
|
700
|
-
|
|
701
|
-
return [2 /*return*/, fn(params, opt)];
|
|
664
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
702
665
|
});
|
|
703
666
|
});
|
|
704
667
|
};
|
|
705
668
|
BaseCore.prototype.afterUpdateMany = function (params, opt) {
|
|
706
669
|
return __awaiter(this, void 0, void 0, function () {
|
|
707
|
-
var fn;
|
|
708
670
|
return __generator(this, function (_a) {
|
|
709
|
-
|
|
710
|
-
return [2 /*return*/, fn(params, opt)];
|
|
671
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
711
672
|
});
|
|
712
673
|
});
|
|
713
674
|
};
|
|
714
675
|
BaseCore.prototype.beforeSet = function (params, opt) {
|
|
715
676
|
return __awaiter(this, void 0, void 0, function () {
|
|
716
|
-
var fn;
|
|
717
677
|
return __generator(this, function (_a) {
|
|
718
|
-
|
|
719
|
-
return [2 /*return*/, fn(params, opt)];
|
|
678
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
720
679
|
});
|
|
721
680
|
});
|
|
722
681
|
};
|
|
723
682
|
BaseCore.prototype.afterSet = function (params, opt) {
|
|
724
683
|
return __awaiter(this, void 0, void 0, function () {
|
|
725
|
-
var fn;
|
|
726
684
|
return __generator(this, function (_a) {
|
|
727
|
-
|
|
728
|
-
return [2 /*return*/, fn(params, opt)];
|
|
685
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
729
686
|
});
|
|
730
687
|
});
|
|
731
688
|
};
|
|
732
689
|
BaseCore.prototype.beforeRemove = function (params, opt) {
|
|
733
690
|
return __awaiter(this, void 0, void 0, function () {
|
|
734
|
-
var fn;
|
|
735
691
|
return __generator(this, function (_a) {
|
|
736
|
-
|
|
737
|
-
return [2 /*return*/, fn(params, opt)];
|
|
692
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
738
693
|
});
|
|
739
694
|
});
|
|
740
695
|
};
|
|
741
696
|
BaseCore.prototype.afterRemove = function (params, opt) {
|
|
742
697
|
return __awaiter(this, void 0, void 0, function () {
|
|
743
|
-
var fn;
|
|
744
698
|
return __generator(this, function (_a) {
|
|
745
|
-
|
|
746
|
-
return [2 /*return*/, fn(params, opt)];
|
|
699
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
747
700
|
});
|
|
748
701
|
});
|
|
749
702
|
};
|
|
750
703
|
BaseCore.prototype.beforeRemoveMany = function (params, opt) {
|
|
751
704
|
return __awaiter(this, void 0, void 0, function () {
|
|
752
|
-
var fn;
|
|
753
705
|
return __generator(this, function (_a) {
|
|
754
|
-
|
|
755
|
-
return [2 /*return*/, fn(params, opt)];
|
|
706
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
756
707
|
});
|
|
757
708
|
});
|
|
758
709
|
};
|
|
759
710
|
BaseCore.prototype.afterRemoveMany = function (params, opt) {
|
|
760
711
|
return __awaiter(this, void 0, void 0, function () {
|
|
761
|
-
var fn;
|
|
762
712
|
return __generator(this, function (_a) {
|
|
763
|
-
|
|
764
|
-
return [2 /*return*/, fn(params, opt)];
|
|
713
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
765
714
|
});
|
|
766
715
|
});
|
|
767
716
|
};
|
|
768
717
|
BaseCore.prototype.onException = function (params, opt) {
|
|
769
718
|
return __awaiter(this, void 0, void 0, function () {
|
|
770
|
-
var fn;
|
|
771
719
|
return __generator(this, function (_a) {
|
|
772
|
-
|
|
773
|
-
|
|
720
|
+
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
721
|
+
});
|
|
722
|
+
});
|
|
723
|
+
};
|
|
724
|
+
/**
|
|
725
|
+
* Returns JWT secret and its settings to verify received JWT token
|
|
726
|
+
* @param params Object of parameters passed to the authenticate method
|
|
727
|
+
* @returns Object with the jwtSecret and verifyTokenArgs
|
|
728
|
+
*/
|
|
729
|
+
BaseCore.prototype.getJwtTokenSecretAndSettings = function (params) {
|
|
730
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
731
|
+
return __generator(this, function (_a) {
|
|
732
|
+
return [2 /*return*/, { jwtSecret: this.config.jwtSecret || '', verifyTokenArgs: this.config.verifyTokenArgs }];
|
|
774
733
|
});
|
|
775
734
|
});
|
|
776
735
|
};
|
|
777
736
|
BaseCore.prototype.authenticate = function (params, opt) {
|
|
778
|
-
var _a;
|
|
779
737
|
return __awaiter(this, void 0, void 0, function () {
|
|
780
|
-
var context, authByToken, verifyResult, token
|
|
738
|
+
var context, space, authByToken, _a, jwtSecret, verifyTokenArgs, verifyResult, token;
|
|
781
739
|
return __generator(this, function (_b) {
|
|
782
740
|
switch (_b.label) {
|
|
783
741
|
case 0:
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
742
|
+
context = this.config.context;
|
|
743
|
+
space = null;
|
|
744
|
+
if (!this.config.spaceGw) return [3 /*break*/, 2];
|
|
745
|
+
if (!context.spaceId) {
|
|
746
|
+
return [2 /*return*/, [false, 'Space not specified']];
|
|
747
|
+
}
|
|
748
|
+
return [4 /*yield*/, this.config.spaceGw.get(context.spaceId || '')];
|
|
749
|
+
case 1:
|
|
750
|
+
// Lookup space in case we have gateway
|
|
751
|
+
space = _b.sent();
|
|
752
|
+
if (!space) {
|
|
753
|
+
return [2 /*return*/, [false, 'Space not found']];
|
|
754
|
+
}
|
|
755
|
+
context.space = space;
|
|
756
|
+
_b.label = 2;
|
|
789
757
|
case 2:
|
|
790
|
-
context = this.context;
|
|
791
758
|
authByToken = false;
|
|
792
|
-
|
|
793
|
-
|
|
759
|
+
return [4 /*yield*/, this.getJwtTokenSecretAndSettings(params)];
|
|
760
|
+
case 3:
|
|
761
|
+
_a = _b.sent(), jwtSecret = _a.jwtSecret, verifyTokenArgs = _a.verifyTokenArgs;
|
|
762
|
+
if (context.authorization && jwtSecret) {
|
|
763
|
+
verifyResult = (0, userToken_1.verifyUserToken)(context.authorization, jwtSecret, verifyTokenArgs);
|
|
794
764
|
if (verifyResult.didFail()) {
|
|
795
765
|
return [2 /*return*/, [false, verifyResult.getErrorSummary('')]];
|
|
796
766
|
}
|
|
@@ -801,20 +771,8 @@ var BaseCore = /** @class */ (function () {
|
|
|
801
771
|
context.spaceId = token.spaceId || context.spaceId;
|
|
802
772
|
authByToken = true;
|
|
803
773
|
}
|
|
804
|
-
space = null;
|
|
805
|
-
if (!this.gwSpace) return [3 /*break*/, 4];
|
|
806
|
-
return [4 /*yield*/, ((_a = this.gwSpace) === null || _a === void 0 ? void 0 : _a.get(context.spaceId || ''))];
|
|
807
|
-
case 3:
|
|
808
|
-
// Lookup space in case we have gateway
|
|
809
|
-
space = _b.sent();
|
|
810
|
-
if (!space) {
|
|
811
|
-
return [2 /*return*/, [false, 'Space Not Found']];
|
|
812
|
-
}
|
|
813
|
-
context.space = space;
|
|
814
|
-
_b.label = 4;
|
|
815
|
-
case 4:
|
|
816
774
|
if (!authByToken) {
|
|
817
|
-
if (this.interserviceApiKey && context.apiKey === this.interserviceApiKey) {
|
|
775
|
+
if (this.config.interserviceApiKey && context.apiKey === this.config.interserviceApiKey) {
|
|
818
776
|
return [2 /*return*/, [true, '']];
|
|
819
777
|
}
|
|
820
778
|
else if ((space === null || space === void 0 ? void 0 : space.apiKey) && (space === null || space === void 0 ? void 0 : space.apiKey) !== context.apiKey) {
|