@sdflc/backend-helpers 1.0.60 → 1.0.62
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/BaseCore.d.ts +34 -11
- package/build/BaseCore.js +122 -43
- package/build/apiContext.js +19 -18
- package/build/commonValidators.d.ts +4 -0
- package/build/commonValidators.js +98 -2
- package/build/constants.d.ts +7 -1
- package/build/constants.js +11 -1
- package/build/downloadHelpers.d.ts +2 -0
- package/build/downloadHelpers.js +83 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/interfaces/BaseCorePropsInterface.d.ts +3 -0
- package/build/interfaces/DownloadFileArgs.d.ts +6 -0
- package/build/interfaces/DownloadFileArgs.js +2 -0
- package/build/interfaces/index.d.ts +25 -24
- package/build/interfaces/index.js +39 -0
- package/build/knexConfigBuilder.js +8 -2
- package/package.json +5 -1
package/build/BaseCore.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OpResult } from '@sdflc/api-helpers';
|
|
2
2
|
import { Logger, MeasureTool } from '@sdflc/utils';
|
|
3
|
+
import { ID_TYPES } from './constants';
|
|
3
4
|
import { Database } from './Database';
|
|
4
5
|
import { BaseCorePropsInterface, BaseCoreActionsInterface, CoreActionInterface, JwtTokenSecretAndSettings, ApiContext, ExtractCredentialsArgs } from './interfaces';
|
|
5
6
|
declare class BaseCore {
|
|
@@ -7,10 +8,12 @@ declare class BaseCore {
|
|
|
7
8
|
protected config: BaseCorePropsInterface;
|
|
8
9
|
protected logger: Logger;
|
|
9
10
|
constructor(props: BaseCorePropsInterface);
|
|
11
|
+
getIdType(): ID_TYPES;
|
|
10
12
|
getDb(): Database;
|
|
11
13
|
getRequestId(): string;
|
|
12
14
|
getContext(): ApiContext;
|
|
13
15
|
getGateways(): any;
|
|
16
|
+
getGateway(name?: string): any;
|
|
14
17
|
getValidators(): any;
|
|
15
18
|
success(data: any, code?: number): any;
|
|
16
19
|
failure(code: number, errorMsg: string, data?: any): any;
|
|
@@ -21,6 +24,8 @@ declare class BaseCore {
|
|
|
21
24
|
list(args: any): Promise<any>;
|
|
22
25
|
get(args: any): Promise<any>;
|
|
23
26
|
getMany(args: any): Promise<any>;
|
|
27
|
+
getGatewayToSetOrerNo(): any;
|
|
28
|
+
getFilterToSetOrderNo(args: any): {};
|
|
24
29
|
create(args: any): Promise<any>;
|
|
25
30
|
createMany(args: any): Promise<any>;
|
|
26
31
|
update(args: any): Promise<any>;
|
|
@@ -29,22 +34,40 @@ declare class BaseCore {
|
|
|
29
34
|
remove(args: any): Promise<any>;
|
|
30
35
|
removeMany(args: any): Promise<any>;
|
|
31
36
|
defaultAfterAndBefore(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Used to transform an object before sending it in the response
|
|
39
|
+
* @param {any} item An object coming from the database
|
|
40
|
+
* @param {BaseCoreActionsInterface} opt Options
|
|
41
|
+
* @returns {any} transformed object
|
|
42
|
+
*/
|
|
43
|
+
processItemOnOut(item: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
44
|
+
/**
|
|
45
|
+
* Used to transform an object before processing it on the request
|
|
46
|
+
* @param {any} item An object coming from the outside
|
|
47
|
+
* @param {BaseCoreActionsInterface} opt Options
|
|
48
|
+
* @returns {any} transformed object
|
|
49
|
+
*/
|
|
50
|
+
processItemOnIn(item: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
51
|
+
beforeGet(item: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
52
|
+
beforeGetMany(items: any[], opt?: BaseCoreActionsInterface): Promise<any>;
|
|
53
|
+
beforeList(filter: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
54
|
+
afterGet(item: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
55
|
+
afterGetMany(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
56
|
+
afterList(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
34
57
|
beforeCreate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
35
|
-
afterCreate(
|
|
36
|
-
beforeCreateMany(
|
|
37
|
-
afterCreateMany(
|
|
58
|
+
afterCreate(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
59
|
+
beforeCreateMany(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
60
|
+
afterCreateMany(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
38
61
|
beforeUpdate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
39
|
-
afterUpdate(
|
|
40
|
-
beforeUpdateMany(
|
|
41
|
-
afterUpdateMany(
|
|
62
|
+
afterUpdate(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
63
|
+
beforeUpdateMany(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
64
|
+
afterUpdateMany(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
42
65
|
beforeSet(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
43
|
-
afterSet(
|
|
66
|
+
afterSet(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
44
67
|
beforeRemove(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
45
|
-
afterRemove(
|
|
68
|
+
afterRemove(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
46
69
|
beforeRemoveMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
47
|
-
afterRemoveMany(
|
|
70
|
+
afterRemoveMany(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
48
71
|
onException(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
49
72
|
/**
|
|
50
73
|
* Returns JWT secret and its settings to verify received JWT token
|
package/build/BaseCore.js
CHANGED
|
@@ -13,22 +13,26 @@ exports.BaseCore = void 0;
|
|
|
13
13
|
const api_helpers_1 = require("@sdflc/api-helpers");
|
|
14
14
|
const utils_1 = require("@sdflc/utils");
|
|
15
15
|
const lodash_1 = require("lodash");
|
|
16
|
+
const commonValidators_1 = require("./commonValidators");
|
|
16
17
|
const constants_1 = require("./constants");
|
|
17
18
|
const userToken_1 = require("./userToken");
|
|
18
|
-
const defaultValidate = ( /*
|
|
19
|
+
const defaultValidate = ( /*args: any, opt?: BaseCoreActionsInterface*/) => {
|
|
20
|
+
return [true, {}];
|
|
21
|
+
};
|
|
22
|
+
const defaultMutationValidate = ( /*args: any, opt?: BaseCoreActionsInterface*/) => {
|
|
19
23
|
return [true, {}];
|
|
20
24
|
};
|
|
21
25
|
const defaultValidators = {
|
|
22
26
|
list: defaultValidate,
|
|
23
|
-
get:
|
|
24
|
-
getMany:
|
|
27
|
+
get: commonValidators_1.validateGet,
|
|
28
|
+
getMany: commonValidators_1.validateGetMany,
|
|
25
29
|
create: defaultValidate,
|
|
26
30
|
createMany: defaultValidate,
|
|
27
31
|
update: defaultValidate,
|
|
28
32
|
updateMany: defaultValidate,
|
|
29
33
|
set: defaultValidate,
|
|
30
|
-
remove:
|
|
31
|
-
removeMany:
|
|
34
|
+
remove: commonValidators_1.validateRemove,
|
|
35
|
+
removeMany: commonValidators_1.validateRemoveMany,
|
|
32
36
|
};
|
|
33
37
|
class BaseCore {
|
|
34
38
|
constructor(props) {
|
|
@@ -36,6 +40,10 @@ class BaseCore {
|
|
|
36
40
|
this.config = props;
|
|
37
41
|
this.logger = props.logger;
|
|
38
42
|
}
|
|
43
|
+
getIdType() {
|
|
44
|
+
var _a;
|
|
45
|
+
return (_a = this.config.idType) !== null && _a !== void 0 ? _a : constants_1.ID_TYPES.UNKNOWN;
|
|
46
|
+
}
|
|
39
47
|
getDb() {
|
|
40
48
|
return this.config.db;
|
|
41
49
|
}
|
|
@@ -48,6 +56,10 @@ class BaseCore {
|
|
|
48
56
|
getGateways() {
|
|
49
57
|
return this.config.context.gateways || {};
|
|
50
58
|
}
|
|
59
|
+
getGateway(name) {
|
|
60
|
+
var _a;
|
|
61
|
+
return (_a = this.getGateways()) === null || _a === void 0 ? void 0 : _a[name || this.config.gatewayName];
|
|
62
|
+
}
|
|
51
63
|
getValidators() {
|
|
52
64
|
return defaultValidators;
|
|
53
65
|
}
|
|
@@ -238,7 +250,7 @@ class BaseCore {
|
|
|
238
250
|
const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.list(object));
|
|
239
251
|
const result = yield this.afterList(items, opt);
|
|
240
252
|
// ON NO DATA RETURN EMPTY CODE
|
|
241
|
-
return this.success(result
|
|
253
|
+
return this.success(result);
|
|
242
254
|
}),
|
|
243
255
|
hasTransaction: false,
|
|
244
256
|
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',
|
|
@@ -252,11 +264,18 @@ class BaseCore {
|
|
|
252
264
|
args,
|
|
253
265
|
validate: this.getValidators().get,
|
|
254
266
|
accessRights: [utils_1.ACCESS_RIGHTS.GET],
|
|
255
|
-
action: (args) => __awaiter(this, void 0, void 0, function* () {
|
|
267
|
+
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
256
268
|
var _d;
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
269
|
+
const args2use = yield this.beforeGet(args, opt);
|
|
270
|
+
if ((args2use === null || args2use === void 0 ? void 0 : args2use.id) == null) {
|
|
271
|
+
return this.failure(api_helpers_1.OP_RESULT_CODES.NOT_FOUND, '', []);
|
|
272
|
+
}
|
|
273
|
+
const item = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.get(args2use === null || args2use === void 0 ? void 0 : args2use.id));
|
|
274
|
+
const result = yield this.afterGet(item, opt);
|
|
275
|
+
if (!result) {
|
|
276
|
+
return this.failure(api_helpers_1.OP_RESULT_CODES.NOT_FOUND, '', []);
|
|
277
|
+
}
|
|
278
|
+
return this.success([result]);
|
|
260
279
|
}),
|
|
261
280
|
hasTransaction: false,
|
|
262
281
|
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',
|
|
@@ -270,17 +289,27 @@ class BaseCore {
|
|
|
270
289
|
args,
|
|
271
290
|
validate: this.getValidators().getMany,
|
|
272
291
|
accessRights: [utils_1.ACCESS_RIGHTS.GET],
|
|
273
|
-
action: (args) => __awaiter(this, void 0, void 0, function* () {
|
|
292
|
+
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
274
293
|
var _d;
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
294
|
+
const args2use = yield this.beforeGetMany(args, opt);
|
|
295
|
+
if (!Array.isArray(args2use === null || args2use === void 0 ? void 0 : args2use.ids)) {
|
|
296
|
+
return this.failure(api_helpers_1.OP_RESULT_CODES.NOT_FOUND, '', []);
|
|
297
|
+
}
|
|
298
|
+
const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.getMany(args2use.ids));
|
|
299
|
+
const result = yield this.afterGetMany(items, opt);
|
|
300
|
+
return this.success(result);
|
|
278
301
|
}),
|
|
279
302
|
hasTransaction: false,
|
|
280
303
|
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',
|
|
281
304
|
});
|
|
282
305
|
});
|
|
283
306
|
}
|
|
307
|
+
getGatewayToSetOrerNo() {
|
|
308
|
+
return this.getContext().gateways[this.config.gatewayName];
|
|
309
|
+
}
|
|
310
|
+
getFilterToSetOrderNo(args) {
|
|
311
|
+
return {};
|
|
312
|
+
}
|
|
284
313
|
create(args) {
|
|
285
314
|
var _a, _b, _c;
|
|
286
315
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -291,9 +320,16 @@ class BaseCore {
|
|
|
291
320
|
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
292
321
|
var _d;
|
|
293
322
|
const { params } = args || {};
|
|
323
|
+
if (this.config.hasOrderNo === true) {
|
|
324
|
+
this.setOrderNo({
|
|
325
|
+
params,
|
|
326
|
+
filter: this.getFilterToSetOrderNo({ params, opt }),
|
|
327
|
+
gateway: this.getGatewayToSetOrerNo(),
|
|
328
|
+
});
|
|
329
|
+
}
|
|
294
330
|
const object = yield this.beforeCreate(params, opt);
|
|
295
|
-
const
|
|
296
|
-
const result = yield this.afterCreate(
|
|
331
|
+
const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.create(object));
|
|
332
|
+
const result = yield this.afterCreate(items, opt);
|
|
297
333
|
return this.success(result);
|
|
298
334
|
}),
|
|
299
335
|
hasTransaction: true,
|
|
@@ -332,8 +368,8 @@ class BaseCore {
|
|
|
332
368
|
var _d;
|
|
333
369
|
const { where, params } = args || {};
|
|
334
370
|
const object = yield this.beforeUpdate(params, opt);
|
|
335
|
-
const
|
|
336
|
-
const result = yield this.afterUpdate(
|
|
371
|
+
const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.update(where, object));
|
|
372
|
+
const result = yield this.afterUpdate(items, opt);
|
|
337
373
|
return this.success(result, result.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND);
|
|
338
374
|
}),
|
|
339
375
|
hasTransaction: true,
|
|
@@ -427,64 +463,107 @@ class BaseCore {
|
|
|
427
463
|
return params;
|
|
428
464
|
});
|
|
429
465
|
}
|
|
430
|
-
|
|
466
|
+
/**
|
|
467
|
+
* Used to transform an object before sending it in the response
|
|
468
|
+
* @param {any} item An object coming from the database
|
|
469
|
+
* @param {BaseCoreActionsInterface} opt Options
|
|
470
|
+
* @returns {any} transformed object
|
|
471
|
+
*/
|
|
472
|
+
processItemOnOut(item, opt) {
|
|
473
|
+
return this.defaultAfterAndBefore(item, opt);
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Used to transform an object before processing it on the request
|
|
477
|
+
* @param {any} item An object coming from the outside
|
|
478
|
+
* @param {BaseCoreActionsInterface} opt Options
|
|
479
|
+
* @returns {any} transformed object
|
|
480
|
+
*/
|
|
481
|
+
processItemOnIn(item, opt) {
|
|
482
|
+
return this.defaultAfterAndBefore(item, opt);
|
|
483
|
+
}
|
|
484
|
+
beforeGet(item, opt) {
|
|
431
485
|
return __awaiter(this, void 0, void 0, function* () {
|
|
432
|
-
return this.defaultAfterAndBefore(
|
|
486
|
+
return this.defaultAfterAndBefore(item, opt);
|
|
433
487
|
});
|
|
434
488
|
}
|
|
435
|
-
|
|
489
|
+
beforeGetMany(items, opt) {
|
|
436
490
|
return __awaiter(this, void 0, void 0, function* () {
|
|
437
|
-
return this.defaultAfterAndBefore(
|
|
491
|
+
return this.defaultAfterAndBefore(items, opt);
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
beforeList(filter, opt) {
|
|
495
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
496
|
+
return this.defaultAfterAndBefore(filter, opt);
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
afterGet(item, opt) {
|
|
500
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
501
|
+
return this.processItemOnOut(item, opt);
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
afterGetMany(items, opt) {
|
|
505
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
506
|
+
return items.map((item) => this.processItemOnOut(item, opt));
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
afterList(items, opt) {
|
|
510
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
511
|
+
return items.map((item) => this.processItemOnOut(item, opt));
|
|
438
512
|
});
|
|
439
513
|
}
|
|
440
514
|
beforeCreate(params, opt) {
|
|
441
515
|
return __awaiter(this, void 0, void 0, function* () {
|
|
442
|
-
return this.
|
|
516
|
+
return this.processItemOnIn(params, opt);
|
|
443
517
|
});
|
|
444
518
|
}
|
|
445
|
-
afterCreate(
|
|
519
|
+
afterCreate(items, opt) {
|
|
446
520
|
return __awaiter(this, void 0, void 0, function* () {
|
|
447
|
-
return this.
|
|
521
|
+
return items.map((item) => this.processItemOnOut(item, opt));
|
|
448
522
|
});
|
|
449
523
|
}
|
|
450
|
-
beforeCreateMany(
|
|
524
|
+
beforeCreateMany(items, opt) {
|
|
451
525
|
return __awaiter(this, void 0, void 0, function* () {
|
|
452
|
-
return this.
|
|
526
|
+
return items.map((item) => this.processItemOnIn(item, opt));
|
|
453
527
|
});
|
|
454
528
|
}
|
|
455
|
-
afterCreateMany(
|
|
529
|
+
afterCreateMany(items, opt) {
|
|
456
530
|
return __awaiter(this, void 0, void 0, function* () {
|
|
457
|
-
return this.
|
|
531
|
+
return items.map((item) => this.processItemOnOut(item, opt));
|
|
458
532
|
});
|
|
459
533
|
}
|
|
460
534
|
beforeUpdate(params, opt) {
|
|
461
535
|
return __awaiter(this, void 0, void 0, function* () {
|
|
462
|
-
return this.
|
|
536
|
+
return this.processItemOnIn(params, opt);
|
|
463
537
|
});
|
|
464
538
|
}
|
|
465
|
-
afterUpdate(
|
|
539
|
+
afterUpdate(items, opt) {
|
|
466
540
|
return __awaiter(this, void 0, void 0, function* () {
|
|
467
|
-
return this.
|
|
541
|
+
return items.map((item) => this.processItemOnOut(item, opt));
|
|
468
542
|
});
|
|
469
543
|
}
|
|
470
|
-
beforeUpdateMany(
|
|
544
|
+
beforeUpdateMany(items, opt) {
|
|
471
545
|
return __awaiter(this, void 0, void 0, function* () {
|
|
472
|
-
return
|
|
546
|
+
return items.map((item) => {
|
|
547
|
+
return {
|
|
548
|
+
params: this.processItemOnIn(item.params, opt),
|
|
549
|
+
where: item.where,
|
|
550
|
+
};
|
|
551
|
+
});
|
|
473
552
|
});
|
|
474
553
|
}
|
|
475
|
-
afterUpdateMany(
|
|
554
|
+
afterUpdateMany(items, opt) {
|
|
476
555
|
return __awaiter(this, void 0, void 0, function* () {
|
|
477
|
-
return this.
|
|
556
|
+
return items.map((item) => this.processItemOnOut(item, opt));
|
|
478
557
|
});
|
|
479
558
|
}
|
|
480
559
|
beforeSet(params, opt) {
|
|
481
560
|
return __awaiter(this, void 0, void 0, function* () {
|
|
482
|
-
return this.
|
|
561
|
+
return (0, lodash_1.castArray)(params).map((item) => this.processItemOnIn(item, opt));
|
|
483
562
|
});
|
|
484
563
|
}
|
|
485
|
-
afterSet(
|
|
564
|
+
afterSet(items, opt) {
|
|
486
565
|
return __awaiter(this, void 0, void 0, function* () {
|
|
487
|
-
return this.
|
|
566
|
+
return items.map((item) => this.processItemOnOut(item, opt));
|
|
488
567
|
});
|
|
489
568
|
}
|
|
490
569
|
beforeRemove(params, opt) {
|
|
@@ -492,9 +571,9 @@ class BaseCore {
|
|
|
492
571
|
return this.defaultAfterAndBefore(params, opt);
|
|
493
572
|
});
|
|
494
573
|
}
|
|
495
|
-
afterRemove(
|
|
574
|
+
afterRemove(items, opt) {
|
|
496
575
|
return __awaiter(this, void 0, void 0, function* () {
|
|
497
|
-
return this.
|
|
576
|
+
return items.map((item) => this.processItemOnOut(item, opt));
|
|
498
577
|
});
|
|
499
578
|
}
|
|
500
579
|
beforeRemoveMany(params, opt) {
|
|
@@ -502,9 +581,9 @@ class BaseCore {
|
|
|
502
581
|
return this.defaultAfterAndBefore(params, opt);
|
|
503
582
|
});
|
|
504
583
|
}
|
|
505
|
-
afterRemoveMany(
|
|
584
|
+
afterRemoveMany(items, opt) {
|
|
506
585
|
return __awaiter(this, void 0, void 0, function* () {
|
|
507
|
-
return this.
|
|
586
|
+
return items.map((item) => this.processItemOnOut(item, opt));
|
|
508
587
|
});
|
|
509
588
|
}
|
|
510
589
|
onException(params, opt) {
|
package/build/apiContext.js
CHANGED
|
@@ -51,23 +51,23 @@ exports.createApiContext = createApiContext;
|
|
|
51
51
|
* @returns {object} A context object with all available cores
|
|
52
52
|
*/
|
|
53
53
|
const createContextDefault = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
-
const { knexConfig, isProduction, logger, doAuth, spaceGw, interserviceApiKey, jwtSecret, verifyTokenArgs, dbSchema, cores, gateways, req, res, extendContext, getCoreContext, getGatewayContext, } = args || {};
|
|
55
|
-
const authorization = (req.headers[constants_1.HEADERS.AUTHORIZATION] || '').replace('Bearer ', '');
|
|
56
|
-
const fingerprint = req.headers[constants_1.HEADERS.FINGERPRINT] || '';
|
|
57
|
-
const spaceId = req.headers[constants_1.HEADERS.SPACE_ID];
|
|
58
|
-
const apiKey = req.headers[constants_1.HEADERS.API_KEY];
|
|
59
|
-
const managementApiKey = req.headers[constants_1.HEADERS.MANAGEMENT_API_KEY];
|
|
60
|
-
const accountId = req.headers[constants_1.HEADERS.ACCOUNT_ID];
|
|
61
|
-
const roleId = req.headers[constants_1.HEADERS.ROLE_ID];
|
|
62
|
-
const userId = req.headers[constants_1.HEADERS.USER_ID];
|
|
63
|
-
const userAgent = req.headers[constants_1.HEADERS.USER_AGENT];
|
|
64
|
-
const referer = req.headers[constants_1.HEADERS.REFERER];
|
|
65
|
-
const ipAddress = req.headers[constants_1.HEADERS.IP_ADDRESS] || req.connection.remoteAddress;
|
|
66
|
-
const acceptLanguage = req.headers[constants_1.HEADERS.ACCEPT_LANGUAGE];
|
|
67
|
-
const languages = (0, utils_1.extractLanguages)(acceptLanguage);
|
|
68
|
-
const requestedLang = req.headers[constants_1.HEADERS.REQUESTED_LANGUAGE] || (languages === null || languages === void 0 ? void 0 : languages[0]) || 'en';
|
|
54
|
+
const { knexConfig, isProduction, logger, doAuth, spaceGw, interserviceApiKey, jwtSecret, verifyTokenArgs, dbSchema, cores, gateways, req, res, extendContext, getCoreContext, getGatewayContext, authorizationToken, } = args || {};
|
|
69
55
|
const headers = req.headers || { noHeadersSetup: true };
|
|
70
56
|
const cookies = req.cookies || { noCookiesSetup: true };
|
|
57
|
+
const authorization = (headers[constants_1.HEADERS.AUTHORIZATION] || authorizationToken || '').replace('Bearer ', '');
|
|
58
|
+
const fingerprint = headers[constants_1.HEADERS.FINGERPRINT] || '';
|
|
59
|
+
const spaceId = headers[constants_1.HEADERS.SPACE_ID];
|
|
60
|
+
const apiKey = headers[constants_1.HEADERS.API_KEY];
|
|
61
|
+
const managementApiKey = headers[constants_1.HEADERS.MANAGEMENT_API_KEY];
|
|
62
|
+
const userAgent = headers[constants_1.HEADERS.USER_AGENT];
|
|
63
|
+
const referer = headers[constants_1.HEADERS.REFERER];
|
|
64
|
+
const ipAddress = headers[constants_1.HEADERS.IP_ADDRESS] || req.connection.remoteAddress;
|
|
65
|
+
const acceptLanguage = headers[constants_1.HEADERS.ACCEPT_LANGUAGE];
|
|
66
|
+
const languages = (0, utils_1.extractLanguages)(acceptLanguage);
|
|
67
|
+
const requestedLang = headers[constants_1.HEADERS.REQUESTED_LANGUAGE] || (languages === null || languages === void 0 ? void 0 : languages[0]) || 'en';
|
|
68
|
+
// const accountId = headers[HEADERS.ACCOUNT_ID];
|
|
69
|
+
// const roleId = headers[HEADERS.ROLE_ID];
|
|
70
|
+
// const userId = headers[HEADERS.USER_ID];
|
|
71
71
|
const requestId = (0, uuid_1.v4)();
|
|
72
72
|
const db = new Database_1.Database({
|
|
73
73
|
knexConfig,
|
|
@@ -85,13 +85,14 @@ const createContextDefault = (args) => __awaiter(void 0, void 0, void 0, functio
|
|
|
85
85
|
requestedLang,
|
|
86
86
|
authorization,
|
|
87
87
|
fingerprint,
|
|
88
|
-
accountId,
|
|
89
|
-
roleId,
|
|
90
|
-
userId,
|
|
88
|
+
// accountId,
|
|
89
|
+
// roleId,
|
|
90
|
+
// userId,
|
|
91
91
|
req,
|
|
92
92
|
res,
|
|
93
93
|
headers,
|
|
94
94
|
cookies,
|
|
95
|
+
authorizationToken,
|
|
95
96
|
};
|
|
96
97
|
return yield (0, exports.createApiContext)({
|
|
97
98
|
cores,
|
|
@@ -9,5 +9,9 @@ export declare const validateMultipleIntIds: (args: any, opt: BaseCoreActionsInt
|
|
|
9
9
|
export declare const validateMultipleUuidIds: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
10
10
|
export declare const validateMultipleTextIds: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
11
11
|
export declare const validateList: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
12
|
+
export declare const validateGet: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
13
|
+
export declare const validateRemove: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
14
|
+
export declare const validateGetMany: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
15
|
+
export declare const validateRemoveMany: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
12
16
|
export declare const validateCreate: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<{}[] | {}[]>;
|
|
13
17
|
export declare const validateUpdate: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<{}[] | {}[]>;
|
|
@@ -12,10 +12,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.validateUpdate = exports.validateCreate = exports.validateList = exports.validateMultipleTextIds = exports.validateMultipleUuidIds = exports.validateMultipleIntIds = exports.validateSingleTextId = exports.validateSingleUuidId = exports.validateSingleIntId = exports.shouldHaveId = exports.shouldHaveParams = void 0;
|
|
15
|
+
exports.validateUpdate = exports.validateCreate = exports.validateRemoveMany = exports.validateGetMany = exports.validateRemove = exports.validateGet = exports.validateList = exports.validateMultipleTextIds = exports.validateMultipleUuidIds = exports.validateMultipleIntIds = exports.validateSingleTextId = exports.validateSingleUuidId = exports.validateSingleIntId = exports.shouldHaveId = exports.shouldHaveParams = void 0;
|
|
16
|
+
const lodash_1 = require("lodash");
|
|
17
|
+
const checkit_1 = __importDefault(require("checkit"));
|
|
18
|
+
const check_types_1 = __importDefault(require("check-types"));
|
|
19
|
+
const is_uuid_1 = __importDefault(require("is-uuid"));
|
|
16
20
|
const api_helpers_1 = require("@sdflc/api-helpers");
|
|
17
21
|
const checkItHelpers_1 = require("./checkItHelpers");
|
|
18
|
-
const
|
|
22
|
+
const constants_1 = require("./constants");
|
|
19
23
|
const rulesSingleIntId = new checkit_1.default({
|
|
20
24
|
id: [
|
|
21
25
|
{
|
|
@@ -62,6 +66,20 @@ const rulesMultipleIntIds = new checkit_1.default({
|
|
|
62
66
|
rule: 'array',
|
|
63
67
|
message: 'IDs should be an array of integer',
|
|
64
68
|
},
|
|
69
|
+
{
|
|
70
|
+
rule: (values) => {
|
|
71
|
+
const opResult = new api_helpers_1.OpResult();
|
|
72
|
+
(0, lodash_1.castArray)(values).forEach((value, idx) => {
|
|
73
|
+
if (!check_types_1.default.integer(value)) {
|
|
74
|
+
opResult.addError('ids', `The ids[${idx}] should be an integer`);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
if (opResult.hasErrors()) {
|
|
78
|
+
opResult.setCode(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED);
|
|
79
|
+
throw opResult;
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
},
|
|
65
83
|
],
|
|
66
84
|
});
|
|
67
85
|
const rulesMultipleUuidIds = new checkit_1.default({
|
|
@@ -74,6 +92,20 @@ const rulesMultipleUuidIds = new checkit_1.default({
|
|
|
74
92
|
rule: 'array',
|
|
75
93
|
message: 'IDs should be an array of UUIDs',
|
|
76
94
|
},
|
|
95
|
+
{
|
|
96
|
+
rule: (values) => {
|
|
97
|
+
const opResult = new api_helpers_1.OpResult();
|
|
98
|
+
(0, lodash_1.castArray)(values).forEach((value, idx) => {
|
|
99
|
+
if (!is_uuid_1.default.v4(value)) {
|
|
100
|
+
opResult.addError('ids', `The ids[${idx}] should be a UUID of version 4`);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
if (opResult.hasErrors()) {
|
|
104
|
+
opResult.setCode(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED);
|
|
105
|
+
throw opResult;
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
},
|
|
77
109
|
],
|
|
78
110
|
});
|
|
79
111
|
const rulesMultipleTextIds = new checkit_1.default({
|
|
@@ -86,6 +118,20 @@ const rulesMultipleTextIds = new checkit_1.default({
|
|
|
86
118
|
rule: 'array',
|
|
87
119
|
message: 'IDs should be an array of strings',
|
|
88
120
|
},
|
|
121
|
+
{
|
|
122
|
+
rule: (values) => {
|
|
123
|
+
const opResult = new api_helpers_1.OpResult();
|
|
124
|
+
(0, lodash_1.castArray)(values).forEach((value, idx) => {
|
|
125
|
+
if (!check_types_1.default.string(value)) {
|
|
126
|
+
opResult.addError('ids', `The ids[${idx}] should be a string`);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
if (opResult.hasErrors()) {
|
|
130
|
+
opResult.setCode(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED);
|
|
131
|
+
throw opResult;
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
},
|
|
89
135
|
],
|
|
90
136
|
});
|
|
91
137
|
const shouldHaveParams = (args) => {
|
|
@@ -166,6 +212,56 @@ const validateList = ({ rules }) =>
|
|
|
166
212
|
return [true, {}];
|
|
167
213
|
});
|
|
168
214
|
exports.validateList = validateList;
|
|
215
|
+
const validateGet = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
216
|
+
const idType = opt.core.getIdType();
|
|
217
|
+
let rules = null;
|
|
218
|
+
switch (idType) {
|
|
219
|
+
case constants_1.ID_TYPES.INT:
|
|
220
|
+
rules = rulesSingleIntId;
|
|
221
|
+
break;
|
|
222
|
+
case constants_1.ID_TYPES.UUID:
|
|
223
|
+
rules = rulesSingleUuidId;
|
|
224
|
+
break;
|
|
225
|
+
case constants_1.ID_TYPES.TEXT:
|
|
226
|
+
rules = rulesSingleTextId;
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
if (!rules) {
|
|
230
|
+
return [true, {}];
|
|
231
|
+
}
|
|
232
|
+
const [result] = rules.validateSync(args);
|
|
233
|
+
if (result) {
|
|
234
|
+
return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
|
|
235
|
+
}
|
|
236
|
+
return [true, {}];
|
|
237
|
+
});
|
|
238
|
+
exports.validateGet = validateGet;
|
|
239
|
+
exports.validateRemove = exports.validateGet;
|
|
240
|
+
const validateGetMany = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
241
|
+
const idType = opt.core.getIdType();
|
|
242
|
+
let rules = null;
|
|
243
|
+
switch (idType) {
|
|
244
|
+
case constants_1.ID_TYPES.INT:
|
|
245
|
+
rules = rulesMultipleIntIds;
|
|
246
|
+
break;
|
|
247
|
+
case constants_1.ID_TYPES.UUID:
|
|
248
|
+
rules = rulesMultipleUuidIds;
|
|
249
|
+
break;
|
|
250
|
+
case constants_1.ID_TYPES.TEXT:
|
|
251
|
+
rules = rulesMultipleTextIds;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
if (!rules) {
|
|
255
|
+
return [true, {}];
|
|
256
|
+
}
|
|
257
|
+
const [result] = rules.validateSync(args);
|
|
258
|
+
if (result) {
|
|
259
|
+
return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
|
|
260
|
+
}
|
|
261
|
+
return [true, {}];
|
|
262
|
+
});
|
|
263
|
+
exports.validateGetMany = validateGetMany;
|
|
264
|
+
exports.validateRemoveMany = exports.validateGetMany;
|
|
169
265
|
const validateCreate = ({ rules }) =>
|
|
170
266
|
// eslint-disable-next-line
|
|
171
267
|
(args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
package/build/constants.d.ts
CHANGED
|
@@ -4,7 +4,13 @@ declare const ORDER_BYS: {
|
|
|
4
4
|
DESC: string;
|
|
5
5
|
};
|
|
6
6
|
declare const HEADERS: any;
|
|
7
|
+
declare enum ID_TYPES {
|
|
8
|
+
UNKNOWN = 0,
|
|
9
|
+
INT = 1,
|
|
10
|
+
UUID = 2,
|
|
11
|
+
TEXT = 3
|
|
12
|
+
}
|
|
7
13
|
declare const ID_FIELD: any;
|
|
8
14
|
declare const DEFAULT_ORDER_NO = "10000000";
|
|
9
15
|
declare const DEFAULT_ORDER_NO_STEP = "1000";
|
|
10
|
-
export { ID_FIELD, FIELDS, ORDER_BYS, HEADERS, DEFAULT_ORDER_NO, DEFAULT_ORDER_NO_STEP };
|
|
16
|
+
export { ID_FIELD, FIELDS, ORDER_BYS, HEADERS, DEFAULT_ORDER_NO, DEFAULT_ORDER_NO_STEP, ID_TYPES };
|
package/build/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_ORDER_NO_STEP = exports.DEFAULT_ORDER_NO = exports.HEADERS = exports.ORDER_BYS = exports.FIELDS = exports.ID_FIELD = void 0;
|
|
3
|
+
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',
|
|
@@ -44,8 +44,18 @@ const HEADERS = {
|
|
|
44
44
|
IP_ADDRESS: 'x-forwarded-for',
|
|
45
45
|
ACCEPT_LANGUAGE: 'accept-language',
|
|
46
46
|
REQUESTED_LANGUAGE: 'x-lang',
|
|
47
|
+
CONTENT_TYPE: 'content-type',
|
|
48
|
+
CONTENT_LENGTH: 'content-length',
|
|
47
49
|
};
|
|
48
50
|
exports.HEADERS = HEADERS;
|
|
51
|
+
var ID_TYPES;
|
|
52
|
+
(function (ID_TYPES) {
|
|
53
|
+
ID_TYPES[ID_TYPES["UNKNOWN"] = 0] = "UNKNOWN";
|
|
54
|
+
ID_TYPES[ID_TYPES["INT"] = 1] = "INT";
|
|
55
|
+
ID_TYPES[ID_TYPES["UUID"] = 2] = "UUID";
|
|
56
|
+
ID_TYPES[ID_TYPES["TEXT"] = 3] = "TEXT";
|
|
57
|
+
})(ID_TYPES || (ID_TYPES = {}));
|
|
58
|
+
exports.ID_TYPES = ID_TYPES;
|
|
49
59
|
const ID_FIELD = FIELDS.ID;
|
|
50
60
|
exports.ID_FIELD = ID_FIELD;
|
|
51
61
|
const DEFAULT_ORDER_NO = '10000000';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.downloadFile = void 0;
|
|
16
|
+
const util_1 = __importDefault(require("util"));
|
|
17
|
+
const fs_1 = __importDefault(require("fs"));
|
|
18
|
+
const stream_1 = __importDefault(require("stream"));
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const url_1 = require("url");
|
|
21
|
+
const axios_1 = __importDefault(require("axios"));
|
|
22
|
+
const api_helpers_1 = require("@sdflc/api-helpers");
|
|
23
|
+
const utils_1 = require("@sdflc/utils");
|
|
24
|
+
const constants_1 = require("./constants");
|
|
25
|
+
const pipeline = util_1.default.promisify(stream_1.default.pipeline);
|
|
26
|
+
const MESSAGES = {
|
|
27
|
+
NO_URL: 'Failed to download file as "url" prop was not provided',
|
|
28
|
+
NO_FILENAME: 'Failed to download file as "fileName" prop was not provided and no file name was in the "url"',
|
|
29
|
+
};
|
|
30
|
+
const CHARSET = 'charset=';
|
|
31
|
+
const downloadFile = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
const measureTool = new utils_1.MeasureTool();
|
|
33
|
+
const { durationMs, result } = yield measureTool.measureExecTime('', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
var _a, _b, _c;
|
|
35
|
+
if (!(args === null || args === void 0 ? void 0 : args.url)) {
|
|
36
|
+
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED, {}, MESSAGES.NO_URL);
|
|
37
|
+
}
|
|
38
|
+
const url = new url_1.URL(args === null || args === void 0 ? void 0 : args.url);
|
|
39
|
+
const fileName = !(args === null || args === void 0 ? void 0 : args.fileName) ? url.pathname.split('/').pop() || `${url.hostname}.html` : (args === null || args === void 0 ? void 0 : args.fileName) || '';
|
|
40
|
+
if (!fileName) {
|
|
41
|
+
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED, {}, MESSAGES.NO_FILENAME);
|
|
42
|
+
}
|
|
43
|
+
const fullPathName = path_1.default.resolve((args === null || args === void 0 ? void 0 : args.folder) || '', fileName);
|
|
44
|
+
try {
|
|
45
|
+
const response = yield axios_1.default.get(url.toString(), {
|
|
46
|
+
responseType: 'stream',
|
|
47
|
+
});
|
|
48
|
+
const strease2use = (args === null || args === void 0 ? void 0 : args.stream) || fs_1.default.createWriteStream(fullPathName);
|
|
49
|
+
yield pipeline(response.data, strease2use);
|
|
50
|
+
const contentType = ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[constants_1.HEADERS.CONTENT_TYPE]) || '';
|
|
51
|
+
const [mimeType, charset] = contentType.split('; ');
|
|
52
|
+
const encoding = (charset === null || charset === void 0 ? void 0 : charset.startsWith(CHARSET)) ? charset.slice(CHARSET.length) : '';
|
|
53
|
+
return api_helpers_1.OpResult.ok({
|
|
54
|
+
url: url.toString(),
|
|
55
|
+
fileName,
|
|
56
|
+
fullPathName,
|
|
57
|
+
size: Number((_c = (_b = response.headers) === null || _b === void 0 ? void 0 : _b[constants_1.HEADERS.CONTENT_LENGTH]) !== null && _c !== void 0 ? _c : 0),
|
|
58
|
+
mimeType,
|
|
59
|
+
encoding,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (ex) {
|
|
63
|
+
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.FAILED, { url: url.toString(), fileName, fullPathName, size: 0, mimeType: '' }, ex.message);
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
const data = result.getDataFirst();
|
|
67
|
+
result.setData(Object.assign(Object.assign({}, data), { speed: (data.size * 1000) / durationMs, durationMs }));
|
|
68
|
+
return result;
|
|
69
|
+
});
|
|
70
|
+
exports.downloadFile = downloadFile;
|
|
71
|
+
// const run = async () => {
|
|
72
|
+
// // const result = await downloadFile({
|
|
73
|
+
// // url: 'https://sushitei.com/wp-content/uploads/2022/08/2022-Sushi-Tei-Autumn-Menu.pdf',
|
|
74
|
+
// // fileName: '',
|
|
75
|
+
// // });
|
|
76
|
+
// const result = await downloadFile({
|
|
77
|
+
// url: 'https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v6.15/windows/pgadmin4-6.15-x64.exe',
|
|
78
|
+
// fileName: '',
|
|
79
|
+
// folder: path.resolve('d:\\Users\\dcerge\\Downloads'),
|
|
80
|
+
// });
|
|
81
|
+
// console.log('result', JSON.stringify(result, null, 2));
|
|
82
|
+
// };
|
|
83
|
+
// run();
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -34,3 +34,4 @@ __exportStar(require("./resolversHelpers"), exports);
|
|
|
34
34
|
__exportStar(require("./userToken"), exports);
|
|
35
35
|
__exportStar(require("./passwordHelpers"), exports);
|
|
36
36
|
__exportStar(require("./commonValidators"), exports);
|
|
37
|
+
__exportStar(require("./downloadHelpers"), exports);
|
|
@@ -5,6 +5,7 @@ import { BaseCoreValidatorsInterface } from './BaseCoreValidatorsInterface';
|
|
|
5
5
|
import { BaseCoreDoingWhatInterface } from './BaseCoreDoingWhatInterface';
|
|
6
6
|
import { VerifyUserTokenArgs } from './VerifyUserTokenArgs';
|
|
7
7
|
import { ApiContext } from './ApiContext';
|
|
8
|
+
import { ID_TYPES } from '../constants';
|
|
8
9
|
export interface BaseCorePropsInterface {
|
|
9
10
|
/**
|
|
10
11
|
* Application API context with all necessary information about request
|
|
@@ -28,4 +29,6 @@ export interface BaseCorePropsInterface {
|
|
|
28
29
|
interserviceApiKey?: string;
|
|
29
30
|
jwtSecret?: string;
|
|
30
31
|
verifyTokenArgs?: VerifyUserTokenArgs;
|
|
32
|
+
hasOrderNo?: boolean;
|
|
33
|
+
idType?: ID_TYPES;
|
|
31
34
|
}
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
export { CacheInterface } from './CacheInterface';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export
|
|
23
|
-
export
|
|
24
|
-
export
|
|
25
|
-
export
|
|
2
|
+
export * from './LoaderInterface';
|
|
3
|
+
export * from './BaseGatewayPropsInterface';
|
|
4
|
+
export * from './ListArgsInterface';
|
|
5
|
+
export * from './SortItemInterface';
|
|
6
|
+
export * from './PaginationInterface';
|
|
7
|
+
export * from './BaseCorePropsInterface';
|
|
8
|
+
export * from './CoreActionInterface';
|
|
9
|
+
export * from './ApiContextInterface';
|
|
10
|
+
export * from './ApiContext';
|
|
11
|
+
export * from './DbFieldAddDefaultInterface';
|
|
12
|
+
export * from './BuildConfigOptions';
|
|
13
|
+
export * from './DatabaseOptions';
|
|
14
|
+
export * from './DatabaseReadInterface';
|
|
15
|
+
export * from './BuildDefaultResolversOptions';
|
|
16
|
+
export * from './BaseCoreValidatorsInterface';
|
|
17
|
+
export * from './UserTokenParams';
|
|
18
|
+
export * from './CreateUserTokenArgs';
|
|
19
|
+
export * from './VerifyUserTokenArgs';
|
|
20
|
+
export * from './BaseCoreActionsInterface';
|
|
21
|
+
export * from './BaseCoreDoingWhatInterface';
|
|
22
|
+
export * from './JwtTokenSecretAndSettings';
|
|
23
|
+
export * from './CommonValidatorArgs';
|
|
24
|
+
export * from './CreateUserTokenResult';
|
|
25
|
+
export * from './ExtractCredentialsArgs';
|
|
26
|
+
export * from './DownloadFileArgs';
|
|
@@ -1,2 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./LoaderInterface"), exports);
|
|
18
|
+
__exportStar(require("./BaseGatewayPropsInterface"), exports);
|
|
19
|
+
__exportStar(require("./ListArgsInterface"), exports);
|
|
20
|
+
__exportStar(require("./SortItemInterface"), exports);
|
|
21
|
+
__exportStar(require("./PaginationInterface"), exports);
|
|
22
|
+
__exportStar(require("./BaseCorePropsInterface"), exports);
|
|
23
|
+
__exportStar(require("./CoreActionInterface"), exports);
|
|
24
|
+
__exportStar(require("./ApiContextInterface"), exports);
|
|
25
|
+
__exportStar(require("./ApiContext"), exports);
|
|
26
|
+
__exportStar(require("./DbFieldAddDefaultInterface"), exports);
|
|
27
|
+
__exportStar(require("./BuildConfigOptions"), exports);
|
|
28
|
+
__exportStar(require("./DatabaseOptions"), exports);
|
|
29
|
+
__exportStar(require("./DatabaseReadInterface"), exports);
|
|
30
|
+
__exportStar(require("./BuildDefaultResolversOptions"), exports);
|
|
31
|
+
__exportStar(require("./BaseCoreValidatorsInterface"), exports);
|
|
32
|
+
__exportStar(require("./UserTokenParams"), exports);
|
|
33
|
+
__exportStar(require("./CreateUserTokenArgs"), exports);
|
|
34
|
+
__exportStar(require("./VerifyUserTokenArgs"), exports);
|
|
35
|
+
__exportStar(require("./BaseCoreActionsInterface"), exports);
|
|
36
|
+
__exportStar(require("./BaseCoreDoingWhatInterface"), exports);
|
|
37
|
+
__exportStar(require("./JwtTokenSecretAndSettings"), exports);
|
|
38
|
+
__exportStar(require("./CommonValidatorArgs"), exports);
|
|
39
|
+
__exportStar(require("./CreateUserTokenResult"), exports);
|
|
40
|
+
__exportStar(require("./ExtractCredentialsArgs"), exports);
|
|
41
|
+
__exportStar(require("./DownloadFileArgs"), exports);
|
|
@@ -18,11 +18,17 @@ const camelResponse = (result) => {
|
|
|
18
18
|
return (0, utils_1.camelKeys)(result);
|
|
19
19
|
};
|
|
20
20
|
const buildKnexConfig = (dirName, appConfig) => {
|
|
21
|
-
const { dbType, dbHost, dbPort, dbName, dbSchema, dbUser, dbPassword, debug, nodeEnv, migrationsTemplateFileName, migrationsFolder, migrationsTable, useSchemaForMigrationsTable, seedsFolder, seedsFolderDev, seedsFolderProd, } = appConfig;
|
|
21
|
+
const { dbType, dbHost, dbPort, dbName, dbSchema, dbUser, dbPassword, debug, nodeEnv, migrationsTemplateFileName, migrationsFolder, migrationsTable, useSchemaForMigrationsTable, seedsFolder, seedsFolderDev, seedsFolderProd, wrapIdentifierOverrideMap, } = appConfig;
|
|
22
22
|
const sharedConfig = {
|
|
23
23
|
client: dbType || 'pg',
|
|
24
24
|
postProcessResponse: camelResponse,
|
|
25
|
-
wrapIdentifier: (value, origImpl) =>
|
|
25
|
+
wrapIdentifier: (value, origImpl) => {
|
|
26
|
+
if (value === '*') {
|
|
27
|
+
return origImpl(value);
|
|
28
|
+
}
|
|
29
|
+
const value2use = (wrapIdentifierOverrideMap === null || wrapIdentifierOverrideMap === void 0 ? void 0 : wrapIdentifierOverrideMap[value]) || origImpl((0, lodash_1.snakeCase)(value));
|
|
30
|
+
return value2use;
|
|
31
|
+
},
|
|
26
32
|
connection: {
|
|
27
33
|
host: dbHost,
|
|
28
34
|
port: dbPort,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdflc/backend-helpers",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.62",
|
|
4
4
|
"description": "Set of helper functions and classes to simplify building backend apps within @sdflc ecosystem",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -27,10 +27,12 @@
|
|
|
27
27
|
"@sdflc/utils": "^1.0.22",
|
|
28
28
|
"bcrypt": "^5.1.0",
|
|
29
29
|
"bluebird": "^3.7.2",
|
|
30
|
+
"check-types": "^11.2.2",
|
|
30
31
|
"checkit": "^0.7.0",
|
|
31
32
|
"dataloader": "^2.1.0",
|
|
32
33
|
"dayjs": "^1.11.6",
|
|
33
34
|
"dotenv-safe": "^8.2.0",
|
|
35
|
+
"is-uuid": "^1.0.2",
|
|
34
36
|
"json-stable-stringify": "^1.0.1",
|
|
35
37
|
"jsonwebtoken": "^8.5.1",
|
|
36
38
|
"knex": "^2.3.0",
|
|
@@ -42,7 +44,9 @@
|
|
|
42
44
|
"devDependencies": {
|
|
43
45
|
"@types/bcrypt": "^5.0.0",
|
|
44
46
|
"@types/bluebird": "^3.5.37",
|
|
47
|
+
"@types/check-types": "^7.3.4",
|
|
45
48
|
"@types/dotenv-safe": "^8.1.2",
|
|
49
|
+
"@types/is-uuid": "^1.0.0",
|
|
46
50
|
"@types/jest": "^29.2.0",
|
|
47
51
|
"@types/json-stable-stringify": "^1.0.34",
|
|
48
52
|
"@types/jsonwebtoken": "^8.5.9",
|