@sdflc/backend-helpers 1.0.78 → 1.0.79

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.
Files changed (109) hide show
  1. package/build/BaseCore.js +0 -3
  2. package/build/BaseGateway.js +0 -2
  3. package/build/RedisDataLoader.js +7 -12
  4. package/build/commonValidators.js +3 -9
  5. package/build/esm/BaseCore.d.ts +88 -0
  6. package/build/esm/BaseCore.js +810 -0
  7. package/build/esm/BaseGateway.d.ts +49 -0
  8. package/build/esm/BaseGateway.js +476 -0
  9. package/build/esm/DataCache.d.ts +14 -0
  10. package/build/esm/DataCache.js +98 -0
  11. package/build/esm/Database.d.ts +32 -0
  12. package/build/esm/Database.js +192 -0
  13. package/build/esm/DbMigratorAndSeeder.d.ts +49 -0
  14. package/build/esm/DbMigratorAndSeeder.js +199 -0
  15. package/build/esm/RedisDataLoader.d.ts +41 -0
  16. package/build/esm/RedisDataLoader.js +237 -0
  17. package/build/esm/apiContext.d.ts +11 -0
  18. package/build/esm/apiContext.js +135 -0
  19. package/build/esm/baseController.d.ts +17 -0
  20. package/build/esm/baseController.js +60 -0
  21. package/build/esm/checkItHelpers.d.ts +3 -0
  22. package/build/esm/checkItHelpers.js +23 -0
  23. package/build/esm/commonValidators.d.ts +17 -0
  24. package/build/esm/commonValidators.js +273 -0
  25. package/build/esm/configBulder.d.ts +2 -0
  26. package/build/esm/configBulder.js +28 -0
  27. package/build/esm/constants.d.ts +30 -0
  28. package/build/esm/constants.js +69 -0
  29. package/build/esm/dbHelpers.d.ts +43 -0
  30. package/build/esm/dbHelpers.js +154 -0
  31. package/build/esm/dbSeeder.d.ts +2 -0
  32. package/build/esm/dbSeeder.js +53 -0
  33. package/build/esm/dbTableHelpers.d.ts +11 -0
  34. package/build/esm/dbTableHelpers.js +99 -0
  35. package/build/esm/downloadHelpers.d.ts +2 -0
  36. package/build/esm/downloadHelpers.js +76 -0
  37. package/build/esm/index.d.ts +21 -0
  38. package/build/esm/index.js +21 -0
  39. package/build/esm/interfaces/ApiContext.d.ts +24 -0
  40. package/build/esm/interfaces/ApiContext.js +1 -0
  41. package/build/esm/interfaces/ApiContextInterface.d.ts +12 -0
  42. package/build/esm/interfaces/ApiContextInterface.js +1 -0
  43. package/build/esm/interfaces/BaseCoreActionsInterface.d.ts +38 -0
  44. package/build/esm/interfaces/BaseCoreActionsInterface.js +1 -0
  45. package/build/esm/interfaces/BaseCoreDoAuthOnActionInterface.d.ts +12 -0
  46. package/build/esm/interfaces/BaseCoreDoAuthOnActionInterface.js +1 -0
  47. package/build/esm/interfaces/BaseCoreDoingWhatInterface.d.ts +13 -0
  48. package/build/esm/interfaces/BaseCoreDoingWhatInterface.js +1 -0
  49. package/build/esm/interfaces/BaseCorePropsInterface.d.ts +36 -0
  50. package/build/esm/interfaces/BaseCorePropsInterface.js +1 -0
  51. package/build/esm/interfaces/BaseCoreValidatorsInterface.d.ts +13 -0
  52. package/build/esm/interfaces/BaseCoreValidatorsInterface.js +1 -0
  53. package/build/esm/interfaces/BaseGatewayPropsInterface.d.ts +39 -0
  54. package/build/esm/interfaces/BaseGatewayPropsInterface.js +1 -0
  55. package/build/esm/interfaces/BuildConfigOptions.d.ts +6 -0
  56. package/build/esm/interfaces/BuildConfigOptions.js +1 -0
  57. package/build/esm/interfaces/BuildDefaultResolversOptions.d.ts +17 -0
  58. package/build/esm/interfaces/BuildDefaultResolversOptions.js +1 -0
  59. package/build/esm/interfaces/BuildListQueryArgsInterface.d.ts +6 -0
  60. package/build/esm/interfaces/BuildListQueryArgsInterface.js +1 -0
  61. package/build/esm/interfaces/CacheInterface.d.ts +15 -0
  62. package/build/esm/interfaces/CacheInterface.js +1 -0
  63. package/build/esm/interfaces/CommonValidatorArgs.d.ts +3 -0
  64. package/build/esm/interfaces/CommonValidatorArgs.js +1 -0
  65. package/build/esm/interfaces/CoreActionInterface.d.ts +14 -0
  66. package/build/esm/interfaces/CoreActionInterface.js +1 -0
  67. package/build/esm/interfaces/CreateUserTokenArgs.d.ts +11 -0
  68. package/build/esm/interfaces/CreateUserTokenArgs.js +1 -0
  69. package/build/esm/interfaces/CreateUserTokenResult.d.ts +4 -0
  70. package/build/esm/interfaces/CreateUserTokenResult.js +1 -0
  71. package/build/esm/interfaces/DatabaseOptions.d.ts +22 -0
  72. package/build/esm/interfaces/DatabaseOptions.js +1 -0
  73. package/build/esm/interfaces/DatabaseReadInterface.d.ts +14 -0
  74. package/build/esm/interfaces/DatabaseReadInterface.js +1 -0
  75. package/build/esm/interfaces/DbFieldAddDefaultInterface.d.ts +9 -0
  76. package/build/esm/interfaces/DbFieldAddDefaultInterface.js +1 -0
  77. package/build/esm/interfaces/DownloadFileArgs.d.ts +6 -0
  78. package/build/esm/interfaces/DownloadFileArgs.js +1 -0
  79. package/build/esm/interfaces/ExtractCredentialsArgs.d.ts +19 -0
  80. package/build/esm/interfaces/ExtractCredentialsArgs.js +1 -0
  81. package/build/esm/interfaces/JwtTokenSecretAndSettings.d.ts +5 -0
  82. package/build/esm/interfaces/JwtTokenSecretAndSettings.js +1 -0
  83. package/build/esm/interfaces/ListArgsInterface.d.ts +5 -0
  84. package/build/esm/interfaces/ListArgsInterface.js +1 -0
  85. package/build/esm/interfaces/LoaderInterface.d.ts +4 -0
  86. package/build/esm/interfaces/LoaderInterface.js +1 -0
  87. package/build/esm/interfaces/PaginationInterface.d.ts +7 -0
  88. package/build/esm/interfaces/PaginationInterface.js +1 -0
  89. package/build/esm/interfaces/SortItemInterface.d.ts +4 -0
  90. package/build/esm/interfaces/SortItemInterface.js +1 -0
  91. package/build/esm/interfaces/UserTokenParams.d.ts +8 -0
  92. package/build/esm/interfaces/UserTokenParams.js +1 -0
  93. package/build/esm/interfaces/VerifyUserTokenArgs.d.ts +13 -0
  94. package/build/esm/interfaces/VerifyUserTokenArgs.js +1 -0
  95. package/build/esm/interfaces/index.d.ts +28 -0
  96. package/build/esm/interfaces/index.js +27 -0
  97. package/build/esm/knexConfigBuilder.d.ts +1 -0
  98. package/build/esm/knexConfigBuilder.js +73 -0
  99. package/build/esm/passwordHelpers.d.ts +5 -0
  100. package/build/esm/passwordHelpers.js +22 -0
  101. package/build/esm/redisClient.d.ts +17 -0
  102. package/build/esm/redisClient.js +94 -0
  103. package/build/esm/resolversHelpers.d.ts +3 -0
  104. package/build/esm/resolversHelpers.js +59 -0
  105. package/build/esm/userToken.d.ts +8 -0
  106. package/build/esm/userToken.js +74 -0
  107. package/build/esm/utils.d.ts +2 -0
  108. package/build/esm/utils.js +13 -0
  109. package/package.json +13 -5
@@ -0,0 +1,99 @@
1
+ import { STATUSES, UUID_EMPTY } from '@sdflc/utils';
2
+ import { FIELDS } from './constants';
3
+ export const dbFieldAddDefaults = (table, opt) => {
4
+ const { addUserInfo, addVersion, addStatus, skipTimestamps, skipRemovedAtStr } = opt || {};
5
+ if (addStatus) {
6
+ table
7
+ .integer(FIELDS.STATUS)
8
+ .defaultTo(STATUSES.ACTIVE)
9
+ .comment((opt === null || opt === void 0 ? void 0 : opt.statusComment) ||
10
+ 'The field is used to specify record status: 50 - Test, 100 - Active, 200 - Draft, 300 - Pending, 1000 - Blocked, 5000 - Disabled, 10000 - Removed');
11
+ }
12
+ if (addVersion) {
13
+ table
14
+ .integer(FIELDS.VERSION)
15
+ .defaultTo(0)
16
+ .comment((opt === null || opt === void 0 ? void 0 : opt.versionComment) || 'The field is used to control versioning');
17
+ }
18
+ if (addUserInfo) {
19
+ table.uuid(FIELDS.CREATED_BY).comment('ID of user who created the record');
20
+ table.uuid(FIELDS.UPDATED_BY).comment('ID of the last user who update the record');
21
+ table.uuid(FIELDS.REMOVED_BY).comment('ID of user who removed the record');
22
+ }
23
+ if (skipTimestamps !== true) {
24
+ table.timestamps(true, true);
25
+ table
26
+ .dateTime(FIELDS.REMOVED_AT)
27
+ .comment('Date and time of removal. As it is nullable it cannot be used in any unique index');
28
+ if (skipRemovedAtStr !== true) {
29
+ table.text(FIELDS.REMOVED_AT_STR).defaultTo('').comment('Used to create unique indexes.');
30
+ }
31
+ table.index([FIELDS.CREATED_AT]);
32
+ table.index([FIELDS.UPDATED_AT]);
33
+ }
34
+ if (addStatus) {
35
+ table.index([FIELDS.STATUS]);
36
+ }
37
+ if (skipRemovedAtStr !== true) {
38
+ table.index([FIELDS.REMOVED_AT_STR]);
39
+ }
40
+ };
41
+ export const addOrderNo = (table, opt) => {
42
+ const chain = table.text(FIELDS.ORDER_NO).notNullable().defaultTo('10000000');
43
+ if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
44
+ table.index([FIELDS.ORDER_NO]);
45
+ }
46
+ return chain;
47
+ };
48
+ export const addAmount = (table, fieldName) => {
49
+ return table.decimal(fieldName, 19, 4);
50
+ };
51
+ export const addSpaceId = (table, opt) => {
52
+ const chain = table.text(FIELDS.SPACE_ID).notNullable().comment('Reference to the space table');
53
+ if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
54
+ table.foreign(FIELDS.SPACE_ID).references(`space.${FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
55
+ }
56
+ return chain;
57
+ };
58
+ export const addUserId = (table, opt) => {
59
+ const chain = table.uuid(FIELDS.USER_ID).notNullable().comment('Reference to the user table');
60
+ if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
61
+ table.foreign(FIELDS.USER_ID).references(`user.${FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
62
+ }
63
+ if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
64
+ table.index([FIELDS.USER_ID]);
65
+ }
66
+ return chain;
67
+ };
68
+ export const addAccountId = (table, opt) => {
69
+ const chain = table.uuid(FIELDS.ACCOUNT_ID).notNullable().comment('Reference to the user table');
70
+ if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
71
+ table.foreign(FIELDS.ACCOUNT_ID).references(`account.${FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
72
+ }
73
+ if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
74
+ table.index([FIELDS.ACCOUNT_ID]);
75
+ }
76
+ return chain;
77
+ };
78
+ export const addLang = (table, opt) => {
79
+ const chain = table.text(FIELDS.LANG).defaultTo('en').notNullable().comment('Language, example: en, ru, en_CA, etc');
80
+ if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
81
+ table.foreign(FIELDS.LANG).references(`language.${FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
82
+ }
83
+ if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
84
+ table.index([FIELDS.LANG]);
85
+ }
86
+ return chain;
87
+ };
88
+ export const defaultFields = (opt) => {
89
+ const { addUserInfo } = opt || {};
90
+ const obj = {
91
+ [FIELDS.CREATED_AT]: '2021-01-01T00:00:00Z', // dh.dbUtcNow(),
92
+ [FIELDS.UPDATED_AT]: '2021-01-01T00:00:00Z', // dh.dbUtcNow(),
93
+ };
94
+ if (addUserInfo === true) {
95
+ obj[FIELDS.CREATED_BY] = UUID_EMPTY;
96
+ obj[FIELDS.UPDATED_BY] = UUID_EMPTY;
97
+ }
98
+ return obj;
99
+ };
@@ -0,0 +1,2 @@
1
+ import { DownloadFileArgs } from './interfaces';
2
+ export declare const downloadFile: (args: DownloadFileArgs) => Promise<any>;
@@ -0,0 +1,76 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import util from 'util';
11
+ import fs from 'fs';
12
+ import stream from 'stream';
13
+ import path from 'path';
14
+ import { URL } from 'url';
15
+ import axios from 'axios';
16
+ import { OpResult, OP_RESULT_CODES } from '@sdflc/api-helpers';
17
+ import { MeasureTool } from '@sdflc/utils';
18
+ import { HEADERS } from './constants';
19
+ const pipeline = util.promisify(stream.pipeline);
20
+ const MESSAGES = {
21
+ NO_URL: 'Failed to download file as "url" prop was not provided',
22
+ NO_FILENAME: 'Failed to download file as "fileName" prop was not provided and no file name was in the "url"',
23
+ };
24
+ const CHARSET = 'charset=';
25
+ export const downloadFile = (args) => __awaiter(void 0, void 0, void 0, function* () {
26
+ const measureTool = new MeasureTool();
27
+ const { durationMs, result } = yield measureTool.measureExecTime('', () => __awaiter(void 0, void 0, void 0, function* () {
28
+ var _a, _b, _c;
29
+ if (!(args === null || args === void 0 ? void 0 : args.url)) {
30
+ return OpResult.fail(OP_RESULT_CODES.VALIDATION_FAILED, {}, MESSAGES.NO_URL);
31
+ }
32
+ const url = new URL(args === null || args === void 0 ? void 0 : args.url);
33
+ 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) || '';
34
+ if (!fileName) {
35
+ return OpResult.fail(OP_RESULT_CODES.VALIDATION_FAILED, {}, MESSAGES.NO_FILENAME);
36
+ }
37
+ const fullPathName = path.resolve((args === null || args === void 0 ? void 0 : args.folder) || '', fileName);
38
+ try {
39
+ const response = yield axios.get(url.toString(), {
40
+ responseType: 'stream',
41
+ });
42
+ const strease2use = (args === null || args === void 0 ? void 0 : args.stream) || fs.createWriteStream(fullPathName);
43
+ yield pipeline(response.data, strease2use);
44
+ const contentType = ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[HEADERS.CONTENT_TYPE]) || '';
45
+ const [mimeType, charset] = contentType.split('; ');
46
+ const encoding = (charset === null || charset === void 0 ? void 0 : charset.startsWith(CHARSET)) ? charset.slice(CHARSET.length) : '';
47
+ return OpResult.ok({
48
+ url: url.toString(),
49
+ fileName,
50
+ fullPathName,
51
+ size: Number((_c = (_b = response.headers) === null || _b === void 0 ? void 0 : _b[HEADERS.CONTENT_LENGTH]) !== null && _c !== void 0 ? _c : 0),
52
+ mimeType,
53
+ encoding,
54
+ });
55
+ }
56
+ catch (ex) {
57
+ return OpResult.fail(OP_RESULT_CODES.FAILED, { url: url.toString(), fileName, fullPathName, size: 0, mimeType: '' }, ex.message);
58
+ }
59
+ }));
60
+ const data = result.getDataFirst();
61
+ result.setData(Object.assign(Object.assign({}, data), { speed: (data.size * 1000) / durationMs, durationMs }));
62
+ return result;
63
+ });
64
+ // const run = async () => {
65
+ // // const result = await downloadFile({
66
+ // // url: 'https://sushitei.com/wp-content/uploads/2022/08/2022-Sushi-Tei-Autumn-Menu.pdf',
67
+ // // fileName: '',
68
+ // // });
69
+ // const result = await downloadFile({
70
+ // url: 'https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v6.15/windows/pgadmin4-6.15-x64.exe',
71
+ // fileName: '',
72
+ // folder: path.resolve('d:\\Users\\dcerge\\Downloads'),
73
+ // });
74
+ // console.log('result', JSON.stringify(result, null, 2));
75
+ // };
76
+ // run();
@@ -0,0 +1,21 @@
1
+ export * from './constants';
2
+ export * from './interfaces';
3
+ export * from './configBulder';
4
+ export * from './Database';
5
+ export * from './dbHelpers';
6
+ export * from './DbMigratorAndSeeder';
7
+ export * from './dbSeeder';
8
+ export * from './knexConfigBuilder';
9
+ export * from './redisClient';
10
+ export * from './checkItHelpers';
11
+ export * from './DataCache';
12
+ export * from './BaseGateway';
13
+ export * from './BaseCore';
14
+ export * from './apiContext';
15
+ export * from './baseController';
16
+ export * from './dbTableHelpers';
17
+ export * from './resolversHelpers';
18
+ export * from './userToken';
19
+ export * from './passwordHelpers';
20
+ export * from './commonValidators';
21
+ export * from './downloadHelpers';
@@ -0,0 +1,21 @@
1
+ export * from './constants';
2
+ export * from './interfaces';
3
+ export * from './configBulder';
4
+ export * from './Database';
5
+ export * from './dbHelpers';
6
+ export * from './DbMigratorAndSeeder';
7
+ export * from './dbSeeder';
8
+ export * from './knexConfigBuilder';
9
+ export * from './redisClient';
10
+ export * from './checkItHelpers';
11
+ export * from './DataCache';
12
+ export * from './BaseGateway';
13
+ export * from './BaseCore';
14
+ export * from './apiContext';
15
+ export * from './baseController';
16
+ export * from './dbTableHelpers';
17
+ export * from './resolversHelpers';
18
+ export * from './userToken';
19
+ export * from './passwordHelpers';
20
+ export * from './commonValidators';
21
+ export * from './downloadHelpers';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Interface of application API interface which should be created on receiving of a request
3
+ */
4
+ export interface ApiContext {
5
+ requestId: string;
6
+ cores: any;
7
+ gateways: any;
8
+ req: any;
9
+ spaceId?: string;
10
+ apiKey?: string;
11
+ managementApiKey?: string;
12
+ userAgent?: string;
13
+ referer?: string;
14
+ ipAddress?: string;
15
+ acceptLanguage?: string;
16
+ languages?: string[];
17
+ requestedLang?: string;
18
+ authorization?: string;
19
+ accountId?: string;
20
+ roleId?: string;
21
+ userId?: string;
22
+ lang?: string;
23
+ [key: string]: any;
24
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { BaseCorePropsInterface } from './BaseCorePropsInterface';
2
+ import { BaseGatewayPropsInterface } from './BaseGatewayPropsInterface';
3
+ export interface ApiContextInterface {
4
+ cores: any;
5
+ gateways: any;
6
+ req: any;
7
+ res: any;
8
+ requestId: any;
9
+ getCoreContext?(args: any): Promise<BaseCorePropsInterface>;
10
+ getGatewayContext?(args: any): Promise<BaseGatewayPropsInterface>;
11
+ extendContext?(args: any): any;
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,38 @@
1
+ import { BaseCore } from '..';
2
+ export interface BaseCoreActionsInterface {
3
+ /**
4
+ * Reference to the core object that processes the request
5
+ */
6
+ core: BaseCore;
7
+ /**
8
+ * Sets current step when processing an action
9
+ * @param str Name of step
10
+ */
11
+ setStep?(str: string): void;
12
+ /**
13
+ * The sameRequest is true when we call a core method when handling the same request (actual for GraphQL resolvers)
14
+ */
15
+ sameRequest?: boolean;
16
+ /**
17
+ * The transaction is active when processing some of actions that configured to open transaction
18
+ */
19
+ hasTransaction?: boolean;
20
+ /**
21
+ * The validatedItems exists after validator execution.
22
+ * It is expected that validator return an array in which second element is some
23
+ * items that were read from data or created otherwise during validation
24
+ */
25
+ validatedItems?: any;
26
+ /**
27
+ * The exception object exists only when exception happened when processing an action
28
+ */
29
+ exception?: any;
30
+ /**
31
+ * Name of action for exception error messages
32
+ */
33
+ doingWhat?: string;
34
+ /**
35
+ * Object with incoming request params
36
+ */
37
+ args?: any;
38
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -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
+ }
@@ -0,0 +1,13 @@
1
+ export interface BaseCoreDoingWhatInterface {
2
+ list: string;
3
+ get: string;
4
+ getMany: string;
5
+ create: string;
6
+ createMany: string;
7
+ update: string;
8
+ updateMany: string;
9
+ set: string;
10
+ remove: string;
11
+ removeMany: string;
12
+ [key: string]: string;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ import { Logger } from '@sdflc/utils';
2
+ import { Database } from '../Database';
3
+ import { BaseGateway } from '../BaseGateway';
4
+ import { BaseCoreValidatorsInterface } from './BaseCoreValidatorsInterface';
5
+ import { BaseCoreDoingWhatInterface } from './BaseCoreDoingWhatInterface';
6
+ import { VerifyUserTokenArgs } from './VerifyUserTokenArgs';
7
+ import { ApiContext } from './ApiContext';
8
+ import { ID_TYPES } from '../constants';
9
+ import { BaseCoreDoAuthOnActionInterface } from './BaseCoreDoAuthOnActionInterface';
10
+ export interface BaseCorePropsInterface {
11
+ /**
12
+ * Application API context with all necessary information about request
13
+ */
14
+ context: ApiContext;
15
+ /**
16
+ * Database instance to handle queries to DB within one request
17
+ */
18
+ db: Database;
19
+ /**
20
+ * Name of a gateway that will perform default CRUD operations, it should be initialized in the API context
21
+ */
22
+ gatewayName: string;
23
+ isProduction: boolean;
24
+ logger: Logger;
25
+ name?: string;
26
+ doAuth: boolean;
27
+ doAuthOnAction?: BaseCoreDoAuthOnActionInterface;
28
+ doingWhat?: BaseCoreDoingWhatInterface;
29
+ validators?: BaseCoreValidatorsInterface;
30
+ spaceGw?: BaseGateway;
31
+ interserviceApiKey?: string;
32
+ jwtSecret?: string;
33
+ verifyTokenArgs?: VerifyUserTokenArgs;
34
+ hasOrderNo?: boolean;
35
+ idType?: ID_TYPES;
36
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import { BaseCoreActionsInterface } from './BaseCoreActionsInterface';
2
+ export interface BaseCoreValidatorsInterface {
3
+ list?(params: any, opt?: BaseCoreActionsInterface): Promise<any[]> | any[];
4
+ get?(params: any, opt?: BaseCoreActionsInterface): Promise<any[]> | any[];
5
+ getMany?(params: any, opt?: BaseCoreActionsInterface): Promise<any[]> | any[];
6
+ create?(params: any, opt?: BaseCoreActionsInterface): Promise<any[]> | any[];
7
+ createMany?(params: any, opt?: BaseCoreActionsInterface): Promise<any[]> | any[];
8
+ update?(params: any, opt?: BaseCoreActionsInterface): Promise<any[]> | any[];
9
+ updateMany?(params: any, opt?: BaseCoreActionsInterface): Promise<any[]> | any[];
10
+ set?(params: any, opt?: BaseCoreActionsInterface): Promise<any[]> | any[];
11
+ remove?(params: any, opt?: BaseCoreActionsInterface): Promise<any[]> | any[];
12
+ removeMany?(params: any, opt?: BaseCoreActionsInterface): Promise<any[]> | any[];
13
+ }
@@ -0,0 +1,39 @@
1
+ import { Logger } from '@sdflc/utils';
2
+ import { ApiContext } from '.';
3
+ import { CacheInterface } from '..';
4
+ import { LoaderInterface } from './LoaderInterface';
5
+ import { SortItemInterface } from './SortItemInterface';
6
+ export interface BaseGatewayPropsInterface extends CacheInterface {
7
+ context: ApiContext;
8
+ table?: string;
9
+ idField?: string;
10
+ idFieldUpdateRemove?: string;
11
+ idFieldAs?: string;
12
+ setFields?: string[] | string;
13
+ mergeFields?: string[];
14
+ hasStatus?: boolean;
15
+ hasCreatedBy?: boolean;
16
+ hasUpdatedBy?: boolean;
17
+ hasRemovedBy?: boolean;
18
+ hasCreatedAt?: boolean;
19
+ hasUpdatedAt?: boolean;
20
+ hasRemovedAt?: boolean;
21
+ hasRemovedAtStr?: boolean;
22
+ hasSpace?: boolean;
23
+ hasVersion?: boolean;
24
+ hasLang?: boolean;
25
+ hasUserId?: boolean;
26
+ localizationForField?: string;
27
+ defaultSorting?: SortItemInterface[];
28
+ fieldForKeyword?: string;
29
+ filterByUserField?: string;
30
+ insertChunkSize?: number;
31
+ hardRemove?: boolean;
32
+ loader?: LoaderInterface;
33
+ noCache?: boolean;
34
+ returnFields?: any[];
35
+ activeStatuses?: number[];
36
+ logger: Logger;
37
+ isProduction: boolean;
38
+ usedKeyPrefixes?: any;
39
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export interface BuildConfigOptions {
2
+ envFile?: string;
3
+ envFileExample?: string;
4
+ defaultNodeEnv?: string;
5
+ allowEmptyValues?: boolean;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ export interface BuildDefaultResolvers {
2
+ prefix: string;
3
+ core: string;
4
+ query?: any;
5
+ mutation?: any;
6
+ types?: any;
7
+ disableList?: boolean;
8
+ disableGet?: boolean;
9
+ disableGetMany?: boolean;
10
+ disableCreate?: boolean;
11
+ disableCreateMany?: boolean;
12
+ disableUpdate?: boolean;
13
+ disableUpdateMany?: boolean;
14
+ disableSet?: boolean;
15
+ disableRemove?: boolean;
16
+ disableRemoveMany?: boolean;
17
+ }
@@ -0,0 +1,6 @@
1
+ export interface BuildListQueryArgsInterface {
2
+ filter: any;
3
+ params: any;
4
+ fieldsToUse: any;
5
+ useCache: boolean;
6
+ }
@@ -0,0 +1,15 @@
1
+ import { Database } from '../Database';
2
+ export interface CacheInterface {
3
+ db: Database;
4
+ keyPrefix?: string;
5
+ context?: any;
6
+ table?: string;
7
+ idField?: string;
8
+ idFieldAs?: string;
9
+ selectFields?: any[];
10
+ readAll?: boolean;
11
+ redisClient?: any;
12
+ cacheTtl?: number;
13
+ loaderFn?(args?: any): any;
14
+ buildKey?(args: any): string;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export interface CommonValidatorArgs {
2
+ rules: any;
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { BaseCoreActionsInterface } from './BaseCoreActionsInterface';
2
+ export interface CoreActionInterface {
3
+ args: any;
4
+ actionName?: string;
5
+ doAuth?: boolean;
6
+ accessRights?: any[];
7
+ validate?(args: any, opt: BaseCoreActionsInterface): Promise<any[]> | any[];
8
+ action(args?: any, opt?: any): any;
9
+ hasTransaction: boolean;
10
+ doingWhat?: string;
11
+ onException?(params: any, opt?: BaseCoreActionsInterface): Promise<any | undefined | null>;
12
+ shouldLogArgs?: boolean;
13
+ requireSpace?: boolean;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ export interface CreateUserTokenArgs {
2
+ algorithm?: any;
3
+ audience?: string | string[];
4
+ issuer?: string;
5
+ jwtid?: string;
6
+ noTimestamp?: boolean;
7
+ header?: any;
8
+ keyid?: any;
9
+ expiresIn?: number;
10
+ useFingerprint?: boolean;
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export interface CreateUserTokenResult {
2
+ token: string;
3
+ fingerprint: string;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ import { Logger } from '@sdflc/utils';
2
+ /**
3
+ * Interface to initialize Database object
4
+ */
5
+ export interface DatabaseOptions {
6
+ /**
7
+ * Knex configuration object
8
+ */
9
+ knexConfig: any;
10
+ /**
11
+ * Name of database schema
12
+ */
13
+ dbSchema: string;
14
+ /**
15
+ * Knex transaction object
16
+ */
17
+ trx?: any;
18
+ /**
19
+ * Logger for debugging/logging
20
+ */
21
+ logger?: Logger;
22
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Interface for Database.ReadAll method
3
+ */
4
+ export interface DatabaseReadInterface {
5
+ table?: string;
6
+ selectFields?: string[];
7
+ sortBy?: any;
8
+ where?: any;
9
+ whereIn?: any;
10
+ extendQuery?(query: any): any;
11
+ mapBy?: string;
12
+ calculated?: any[];
13
+ buildKey?(key: string): string;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export interface DbFieldAddDefaultInterface {
2
+ addUserInfo?: boolean;
3
+ addVersion?: boolean;
4
+ addStatus?: boolean;
5
+ skipTimestamps?: boolean;
6
+ skipRemovedAtStr?: boolean;
7
+ statusComment?: string;
8
+ versionComment?: string;
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export interface DownloadFileArgs {
2
+ url: string;
3
+ fileName: string;
4
+ folder?: string;
5
+ stream?: any;
6
+ }
@@ -0,0 +1 @@
1
+ export {};