@sdflc/backend-helpers 1.0.106 → 1.0.107
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 +88 -0
- package/build/BaseCore.js +734 -0
- package/build/BaseGateway.d.ts +56 -0
- package/build/BaseGateway.js +477 -0
- package/build/DataCache.d.ts +16 -0
- package/build/DataCache.js +113 -0
- package/build/Database.d.ts +36 -0
- package/build/Database.js +195 -0
- package/build/DbMigratorAndSeeder.d.ts +49 -0
- package/build/DbMigratorAndSeeder.js +212 -0
- package/build/RedisDataLoader.d.ts +41 -0
- package/build/RedisDataLoader.js +212 -0
- package/build/apiContext.d.ts +11 -0
- package/build/apiContext.js +146 -0
- package/build/baseController.d.ts +17 -0
- package/build/baseController.js +59 -0
- package/build/checkItHelpers.d.ts +3 -0
- package/build/checkItHelpers.js +28 -0
- package/build/commonValidators.d.ts +17 -0
- package/build/commonValidators.js +311 -0
- package/build/configBulder.d.ts +2 -0
- package/build/configBulder.js +36 -0
- package/build/constants.d.ts +30 -0
- package/build/constants.js +80 -0
- package/build/dbHelpers.d.ts +43 -0
- package/build/dbHelpers.js +156 -0
- package/build/dbSeeder.d.ts +2 -0
- package/build/dbSeeder.js +83 -0
- package/build/dbTableHelpers.d.ts +14 -0
- package/build/dbTableHelpers.js +118 -0
- package/build/downloadHelpers.d.ts +2 -0
- package/build/downloadHelpers.js +73 -0
- package/build/esm/BaseCore.d.ts +88 -0
- package/build/esm/BaseCore.js +728 -0
- package/build/esm/BaseGateway.d.ts +56 -0
- package/build/esm/BaseGateway.js +471 -0
- package/build/esm/DataCache.d.ts +16 -0
- package/build/esm/DataCache.js +107 -0
- package/build/esm/Database.d.ts +36 -0
- package/build/esm/Database.js +189 -0
- package/build/esm/DbMigratorAndSeeder.d.ts +49 -0
- package/build/esm/DbMigratorAndSeeder.js +173 -0
- package/build/esm/RedisDataLoader.d.ts +41 -0
- package/build/esm/RedisDataLoader.js +206 -0
- package/build/esm/apiContext.d.ts +11 -0
- package/build/esm/apiContext.js +138 -0
- package/build/esm/baseController.d.ts +17 -0
- package/build/esm/baseController.js +53 -0
- package/build/esm/checkItHelpers.d.ts +3 -0
- package/build/esm/checkItHelpers.js +23 -0
- package/build/esm/commonValidators.d.ts +17 -0
- package/build/esm/commonValidators.js +291 -0
- package/build/esm/configBulder.d.ts +2 -0
- package/build/esm/configBulder.js +32 -0
- package/build/esm/constants.d.ts +30 -0
- package/build/esm/constants.js +69 -0
- package/build/esm/dbHelpers.d.ts +43 -0
- package/build/esm/dbHelpers.js +144 -0
- package/build/esm/dbSeeder.d.ts +2 -0
- package/build/esm/dbSeeder.js +44 -0
- package/build/esm/dbTableHelpers.d.ts +14 -0
- package/build/esm/dbTableHelpers.js +106 -0
- package/build/esm/downloadHelpers.d.ts +2 -0
- package/build/esm/downloadHelpers.js +66 -0
- package/build/esm/index.d.ts +21 -0
- package/build/esm/index.js +21 -0
- package/build/esm/interfaces/ApiContext.d.ts +25 -0
- package/build/esm/interfaces/ApiContext.js +1 -0
- package/build/esm/interfaces/ApiContextInterface.d.ts +12 -0
- package/build/esm/interfaces/ApiContextInterface.js +1 -0
- package/build/esm/interfaces/BaseCoreActionsInterface.d.ts +38 -0
- package/build/esm/interfaces/BaseCoreActionsInterface.js +1 -0
- package/build/esm/interfaces/BaseCoreDoAuthOnActionInterface.d.ts +12 -0
- package/build/esm/interfaces/BaseCoreDoAuthOnActionInterface.js +1 -0
- package/build/esm/interfaces/BaseCoreDoingWhatInterface.d.ts +13 -0
- package/build/esm/interfaces/BaseCoreDoingWhatInterface.js +1 -0
- package/build/esm/interfaces/BaseCorePropsInterface.d.ts +37 -0
- package/build/esm/interfaces/BaseCorePropsInterface.js +1 -0
- package/build/esm/interfaces/BaseCoreValidatorsInterface.d.ts +13 -0
- package/build/esm/interfaces/BaseCoreValidatorsInterface.js +1 -0
- package/build/esm/interfaces/BaseGatewayPropsInterface.d.ts +39 -0
- package/build/esm/interfaces/BaseGatewayPropsInterface.js +1 -0
- package/build/esm/interfaces/BuildConfigOptions.d.ts +6 -0
- package/build/esm/interfaces/BuildConfigOptions.js +1 -0
- package/build/esm/interfaces/BuildDefaultResolversOptions.d.ts +17 -0
- package/build/esm/interfaces/BuildDefaultResolversOptions.js +1 -0
- package/build/esm/interfaces/BuildListQueryArgsInterface.d.ts +6 -0
- package/build/esm/interfaces/BuildListQueryArgsInterface.js +1 -0
- package/build/esm/interfaces/CacheInterface.d.ts +15 -0
- package/build/esm/interfaces/CacheInterface.js +1 -0
- package/build/esm/interfaces/CommonValidatorArgs.d.ts +3 -0
- package/build/esm/interfaces/CommonValidatorArgs.js +1 -0
- package/build/esm/interfaces/CoreActionInterface.d.ts +15 -0
- package/build/esm/interfaces/CoreActionInterface.js +1 -0
- package/build/esm/interfaces/CreateUserTokenArgs.d.ts +11 -0
- package/build/esm/interfaces/CreateUserTokenArgs.js +1 -0
- package/build/esm/interfaces/CreateUserTokenResult.d.ts +4 -0
- package/build/esm/interfaces/CreateUserTokenResult.js +1 -0
- package/build/esm/interfaces/DatabaseOptions.d.ts +26 -0
- package/build/esm/interfaces/DatabaseOptions.js +1 -0
- package/build/esm/interfaces/DatabaseReadInterface.d.ts +14 -0
- package/build/esm/interfaces/DatabaseReadInterface.js +1 -0
- package/build/esm/interfaces/DbFieldAddDefaultInterface.d.ts +9 -0
- package/build/esm/interfaces/DbFieldAddDefaultInterface.js +1 -0
- package/build/esm/interfaces/DownloadFileArgs.d.ts +6 -0
- package/build/esm/interfaces/DownloadFileArgs.js +1 -0
- package/build/esm/interfaces/ExtractCredentialsArgs.d.ts +19 -0
- package/build/esm/interfaces/ExtractCredentialsArgs.js +1 -0
- package/build/esm/interfaces/JwtTokenSecretAndSettings.d.ts +5 -0
- package/build/esm/interfaces/JwtTokenSecretAndSettings.js +1 -0
- package/build/esm/interfaces/ListArgsInterface.d.ts +7 -0
- package/build/esm/interfaces/ListArgsInterface.js +1 -0
- package/build/esm/interfaces/LoaderInterface.d.ts +7 -0
- package/build/esm/interfaces/LoaderInterface.js +1 -0
- package/build/esm/interfaces/PaginationInterface.d.ts +10 -0
- package/build/esm/interfaces/PaginationInterface.js +1 -0
- package/build/esm/interfaces/SortItemInterface.d.ts +4 -0
- package/build/esm/interfaces/SortItemInterface.js +1 -0
- package/build/esm/interfaces/UserTokenParams.d.ts +8 -0
- package/build/esm/interfaces/UserTokenParams.js +1 -0
- package/build/esm/interfaces/VerifyUserTokenArgs.d.ts +13 -0
- package/build/esm/interfaces/VerifyUserTokenArgs.js +1 -0
- package/build/esm/interfaces/index.d.ts +28 -0
- package/build/esm/interfaces/index.js +27 -0
- package/build/esm/knexConfigBuilder.d.ts +1 -0
- package/build/esm/knexConfigBuilder.js +84 -0
- package/build/esm/passwordHelpers.d.ts +5 -0
- package/build/esm/passwordHelpers.js +13 -0
- package/build/esm/redisClient.d.ts +17 -0
- package/build/esm/redisClient.js +97 -0
- package/build/esm/resolversHelpers.d.ts +3 -0
- package/build/esm/resolversHelpers.js +66 -0
- package/build/esm/userToken.d.ts +8 -0
- package/build/esm/userToken.js +80 -0
- package/build/esm/utils.d.ts +2 -0
- package/build/esm/utils.js +13 -0
- package/build/index.d.ts +21 -0
- package/build/index.js +37 -0
- package/build/interfaces/ApiContext.d.ts +25 -0
- package/build/interfaces/ApiContext.js +2 -0
- package/build/interfaces/ApiContextInterface.d.ts +12 -0
- package/build/interfaces/ApiContextInterface.js +2 -0
- package/build/interfaces/BaseCoreActionsInterface.d.ts +38 -0
- package/build/interfaces/BaseCoreActionsInterface.js +2 -0
- package/build/interfaces/BaseCoreDoAuthOnActionInterface.d.ts +12 -0
- package/build/interfaces/BaseCoreDoAuthOnActionInterface.js +2 -0
- package/build/interfaces/BaseCoreDoingWhatInterface.d.ts +13 -0
- package/build/interfaces/BaseCoreDoingWhatInterface.js +2 -0
- package/build/interfaces/BaseCorePropsInterface.d.ts +37 -0
- package/build/interfaces/BaseCorePropsInterface.js +2 -0
- package/build/interfaces/BaseCoreValidatorsInterface.d.ts +13 -0
- package/build/interfaces/BaseCoreValidatorsInterface.js +2 -0
- package/build/interfaces/BaseGatewayPropsInterface.d.ts +39 -0
- package/build/interfaces/BaseGatewayPropsInterface.js +2 -0
- package/build/interfaces/BuildConfigOptions.d.ts +6 -0
- package/build/interfaces/BuildConfigOptions.js +2 -0
- package/build/interfaces/BuildDefaultResolversOptions.d.ts +17 -0
- package/build/interfaces/BuildDefaultResolversOptions.js +2 -0
- package/build/interfaces/BuildListQueryArgsInterface.d.ts +6 -0
- package/build/interfaces/BuildListQueryArgsInterface.js +2 -0
- package/build/interfaces/CacheInterface.d.ts +15 -0
- package/build/interfaces/CacheInterface.js +2 -0
- package/build/interfaces/CommonValidatorArgs.d.ts +3 -0
- package/build/interfaces/CommonValidatorArgs.js +2 -0
- package/build/interfaces/CoreActionInterface.d.ts +15 -0
- package/build/interfaces/CoreActionInterface.js +2 -0
- package/build/interfaces/CreateUserTokenArgs.d.ts +11 -0
- package/build/interfaces/CreateUserTokenArgs.js +2 -0
- package/build/interfaces/CreateUserTokenResult.d.ts +4 -0
- package/build/interfaces/CreateUserTokenResult.js +2 -0
- package/build/interfaces/DatabaseOptions.d.ts +26 -0
- package/build/interfaces/DatabaseOptions.js +2 -0
- package/build/interfaces/DatabaseReadInterface.d.ts +14 -0
- package/build/interfaces/DatabaseReadInterface.js +2 -0
- package/build/interfaces/DbFieldAddDefaultInterface.d.ts +9 -0
- package/build/interfaces/DbFieldAddDefaultInterface.js +2 -0
- package/build/interfaces/DownloadFileArgs.d.ts +6 -0
- package/build/interfaces/DownloadFileArgs.js +2 -0
- package/build/interfaces/ExtractCredentialsArgs.d.ts +19 -0
- package/build/interfaces/ExtractCredentialsArgs.js +2 -0
- package/build/interfaces/JwtTokenSecretAndSettings.d.ts +5 -0
- package/build/interfaces/JwtTokenSecretAndSettings.js +2 -0
- package/build/interfaces/ListArgsInterface.d.ts +7 -0
- package/build/interfaces/ListArgsInterface.js +2 -0
- package/build/interfaces/LoaderInterface.d.ts +7 -0
- package/build/interfaces/LoaderInterface.js +2 -0
- package/build/interfaces/PaginationInterface.d.ts +10 -0
- package/build/interfaces/PaginationInterface.js +2 -0
- package/build/interfaces/SortItemInterface.d.ts +4 -0
- package/build/interfaces/SortItemInterface.js +2 -0
- package/build/interfaces/UserTokenParams.d.ts +8 -0
- package/build/interfaces/UserTokenParams.js +2 -0
- package/build/interfaces/VerifyUserTokenArgs.d.ts +13 -0
- package/build/interfaces/VerifyUserTokenArgs.js +2 -0
- package/build/interfaces/index.d.ts +28 -0
- package/build/interfaces/index.js +43 -0
- package/build/knexConfigBuilder.d.ts +1 -0
- package/build/knexConfigBuilder.js +91 -0
- package/build/passwordHelpers.d.ts +5 -0
- package/build/passwordHelpers.js +21 -0
- package/build/redisClient.d.ts +17 -0
- package/build/redisClient.js +100 -0
- package/build/resolversHelpers.d.ts +3 -0
- package/build/resolversHelpers.js +69 -0
- package/build/userToken.d.ts +8 -0
- package/build/userToken.js +92 -0
- package/build/utils.d.ts +2 -0
- package/build/utils.js +21 -0
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ExtractCredentialsArgs {
|
|
2
|
+
/**
|
|
3
|
+
* Req is a request object of the Express library
|
|
4
|
+
*/
|
|
5
|
+
req: any;
|
|
6
|
+
/**
|
|
7
|
+
* Space is an object with configuration where to get data from
|
|
8
|
+
*/
|
|
9
|
+
space: any;
|
|
10
|
+
/**
|
|
11
|
+
* Authorization is a token from the Authorization header
|
|
12
|
+
*/
|
|
13
|
+
authorization?: string;
|
|
14
|
+
fingerprint?: string;
|
|
15
|
+
/**
|
|
16
|
+
* An object with parameters passed to the authenticate methods
|
|
17
|
+
*/
|
|
18
|
+
params?: any;
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SortItemInterface } from './SortItemInterface';
|
|
2
|
+
export interface PaginationInterface {
|
|
3
|
+
page?: number;
|
|
4
|
+
pageSize?: number;
|
|
5
|
+
cursor?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PaginationAndSortingInterface {
|
|
8
|
+
pagination?: PaginationInterface;
|
|
9
|
+
sortBy: SortItemInterface[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface VerifyUserTokenArgs {
|
|
2
|
+
algorithms?: any;
|
|
3
|
+
audience?: string | string[];
|
|
4
|
+
issuer?: string | string[];
|
|
5
|
+
ignoreExpiration?: boolean;
|
|
6
|
+
ignoreNotBefore?: boolean;
|
|
7
|
+
subject?: string;
|
|
8
|
+
clockTolerance?: number;
|
|
9
|
+
maxAge?: number;
|
|
10
|
+
clockTimestamp?: number;
|
|
11
|
+
nonce?: string;
|
|
12
|
+
fingerprint?: string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { CacheInterface } from './CacheInterface';
|
|
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';
|
|
27
|
+
export * from './BuildListQueryArgsInterface';
|
|
28
|
+
export * from './BaseCoreDoAuthOnActionInterface';
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
};
|
|
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);
|
|
42
|
+
__exportStar(require("./BuildListQueryArgsInterface"), exports);
|
|
43
|
+
__exportStar(require("./BaseCoreDoAuthOnActionInterface"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const buildKnexConfig: (dirName: string, appConfig: any) => any;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildKnexConfig = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const utils_1 = require("@sdflc/utils");
|
|
10
|
+
const defaultMigrationsTable = 'migrations';
|
|
11
|
+
const defaultMigrationsFolder = 'migrations';
|
|
12
|
+
const defaultMigrationsTemplateFileName = 'migrations-template.js';
|
|
13
|
+
const defaultSeedsFolder = 'seeds';
|
|
14
|
+
const camelResponse = (result) => {
|
|
15
|
+
if (!result || result.rows) {
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
return (0, utils_1.camelKeys)(result);
|
|
19
|
+
};
|
|
20
|
+
const buildKnexConfig = (dirName, appConfig) => {
|
|
21
|
+
const { dbType, dbHost, dbPort, dbName, dbSchema, dbUser, dbPassword, dbPoolMin, dbPoolMax, debug, nodeEnv, migrationsTemplateFileName, migrationsFolder, migrationsTable, useSchemaForMigrationsTable, seedsFolder, seedsFolderDev, seedsFolderProd, wrapIdentifierOverrideMap, dbPool, } = appConfig;
|
|
22
|
+
const sharedConfig = {
|
|
23
|
+
client: dbType || 'pg',
|
|
24
|
+
postProcessResponse: camelResponse,
|
|
25
|
+
wrapIdentifier: (value, origImpl) => {
|
|
26
|
+
if (value === '*') {
|
|
27
|
+
return origImpl(value);
|
|
28
|
+
}
|
|
29
|
+
const value2use = wrapIdentifierOverrideMap?.[value] || origImpl((0, lodash_1.snakeCase)(value));
|
|
30
|
+
return value2use;
|
|
31
|
+
},
|
|
32
|
+
connection: {
|
|
33
|
+
host: dbHost,
|
|
34
|
+
port: dbPort,
|
|
35
|
+
user: dbUser,
|
|
36
|
+
password: dbPassword,
|
|
37
|
+
database: dbName,
|
|
38
|
+
//ssl: database.ssl,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
if (typeof dbPool === 'object') {
|
|
42
|
+
sharedConfig.pool = dbPool;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
sharedConfig.pool = {
|
|
46
|
+
min: dbPoolMin != null && !isNaN(dbPoolMin) ? dbPoolMin : 0,
|
|
47
|
+
max: dbPoolMax != null && !isNaN(dbPoolMax) ? dbPoolMax : 50,
|
|
48
|
+
acquireTimeoutMillis: 30000,
|
|
49
|
+
createTimeoutMillis: 30000,
|
|
50
|
+
destroyTimeoutMillis: 5000,
|
|
51
|
+
idleTimeoutMillis: 30000,
|
|
52
|
+
reapIntervalMillis: 1000,
|
|
53
|
+
createRetryIntervalMillis: 200,
|
|
54
|
+
propagateCreateError: false,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const config = {
|
|
58
|
+
development: {
|
|
59
|
+
...sharedConfig,
|
|
60
|
+
debug,
|
|
61
|
+
migrations: {
|
|
62
|
+
// https://knexjs.org/guide/migrations.html#migration-api
|
|
63
|
+
stub: path_1.default.join(dirName, migrationsTemplateFileName || defaultMigrationsTemplateFileName),
|
|
64
|
+
directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
|
|
65
|
+
schemaName: useSchemaForMigrationsTable ? dbSchema : undefined,
|
|
66
|
+
tableName: migrationsTable || defaultMigrationsTable,
|
|
67
|
+
},
|
|
68
|
+
seeds: {
|
|
69
|
+
directory: path_1.default.join(dirName, seedsFolderDev || seedsFolder || defaultSeedsFolder),
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
production: {
|
|
73
|
+
...sharedConfig,
|
|
74
|
+
debug,
|
|
75
|
+
migrations: {
|
|
76
|
+
directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
|
|
77
|
+
schemaName: useSchemaForMigrationsTable ? dbSchema : undefined,
|
|
78
|
+
tableName: migrationsTable || defaultMigrationsTable,
|
|
79
|
+
},
|
|
80
|
+
seeds: {
|
|
81
|
+
directory: path_1.default.join(dirName, seedsFolderProd || seedsFolder || defaultSeedsFolder),
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
let config2use = (0, lodash_1.get)(config, nodeEnv);
|
|
86
|
+
if (!config2use) {
|
|
87
|
+
config2use = config.development;
|
|
88
|
+
}
|
|
89
|
+
return config2use;
|
|
90
|
+
};
|
|
91
|
+
exports.buildKnexConfig = buildKnexConfig;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.checkPassword = exports.getSaltAndHash = void 0;
|
|
7
|
+
const bcrypt_1 = __importDefault(require("bcrypt"));
|
|
8
|
+
const getSaltAndHash = async (password, saltRounds = 10) => {
|
|
9
|
+
const salt = await bcrypt_1.default.genSalt(saltRounds);
|
|
10
|
+
const hash = await bcrypt_1.default.hash(password, salt);
|
|
11
|
+
return {
|
|
12
|
+
salt,
|
|
13
|
+
hash,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.getSaltAndHash = getSaltAndHash;
|
|
17
|
+
const checkPassword = async (password, hashedPassword) => {
|
|
18
|
+
const isCorrect = await bcrypt_1.default.compare(password, hashedPassword);
|
|
19
|
+
return isCorrect;
|
|
20
|
+
};
|
|
21
|
+
exports.checkPassword = checkPassword;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface CreateRedisClientInterface {
|
|
2
|
+
redisHost: string;
|
|
3
|
+
redisPort: string | number;
|
|
4
|
+
redisPassword: string;
|
|
5
|
+
redisSsl: boolean;
|
|
6
|
+
retryAttempts?: number;
|
|
7
|
+
firstTimeout?: number;
|
|
8
|
+
pingInterval?: number;
|
|
9
|
+
connectionTimeout?: number;
|
|
10
|
+
onConnecting?(): void;
|
|
11
|
+
onConnected?(): void;
|
|
12
|
+
onDisconnected?(): void;
|
|
13
|
+
onReconnecting?(): void;
|
|
14
|
+
onError?(err: any): void;
|
|
15
|
+
}
|
|
16
|
+
declare const createRedisClient: (args: CreateRedisClientInterface) => any;
|
|
17
|
+
export { createRedisClient };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRedisClient = void 0;
|
|
4
|
+
const redis_1 = require("redis");
|
|
5
|
+
// const DEFAULT_RETRY_ATTEMPTS = 10;
|
|
6
|
+
// const DEFAULT_FIRST_TIMEOUT = 3000;
|
|
7
|
+
const createRedisClient = (args) => {
|
|
8
|
+
const { redisHost, redisPort, redisPassword, redisSsl,
|
|
9
|
+
//retryAttempts,
|
|
10
|
+
//firstTimeout,
|
|
11
|
+
pingInterval, connectionTimeout, onConnecting, onConnected, onDisconnected, onReconnecting, onError, } = args || {};
|
|
12
|
+
if (!redisHost) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const baseSocketConfig = {
|
|
16
|
+
host: redisHost,
|
|
17
|
+
port: Number(redisPort),
|
|
18
|
+
family: 0,
|
|
19
|
+
connectTimeout: connectionTimeout != undefined ? connectionTimeout : 5000,
|
|
20
|
+
noDelay: true,
|
|
21
|
+
keepAlive: true,
|
|
22
|
+
keepAliveInitialDelay: pingInterval != undefined ? pingInterval : 5000,
|
|
23
|
+
reconnectStrategy: (retries) => Math.min(retries * 50, 500),
|
|
24
|
+
};
|
|
25
|
+
const socketConfig = redisSsl
|
|
26
|
+
? { ...baseSocketConfig, tls: true, rejectUnauthorized: false }
|
|
27
|
+
: { ...baseSocketConfig, tls: false };
|
|
28
|
+
const cfg = {
|
|
29
|
+
socket: socketConfig,
|
|
30
|
+
password: redisPassword || undefined,
|
|
31
|
+
};
|
|
32
|
+
const redisClient = (0, redis_1.createClient)(cfg);
|
|
33
|
+
redisClient.on('connect', () => {
|
|
34
|
+
if (typeof onConnecting === 'function') {
|
|
35
|
+
onConnecting();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
redisClient.on('ready', () => {
|
|
39
|
+
if (typeof onConnected === 'function') {
|
|
40
|
+
onConnected();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
redisClient.on('end', () => {
|
|
44
|
+
if (typeof onDisconnected === 'function') {
|
|
45
|
+
onDisconnected();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
redisClient.on('reconnecting', () => {
|
|
49
|
+
if (typeof onReconnecting === 'function') {
|
|
50
|
+
onReconnecting();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
redisClient.on('error', (err) => {
|
|
54
|
+
if (typeof onError === 'function') {
|
|
55
|
+
onError(err);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
// const redisClientOld = redis.createClient({
|
|
59
|
+
// host: redisHost,
|
|
60
|
+
// port: Number(redisPort),
|
|
61
|
+
// password: redisPassword || undefined,
|
|
62
|
+
// no_ready_check: true,
|
|
63
|
+
// retry_strategy: function (options) {
|
|
64
|
+
// if (options.error && options.error.code === 'ECONNREFUSED') {
|
|
65
|
+
// // End reconnecting on a specific error and flush all commands with
|
|
66
|
+
// // a individual error
|
|
67
|
+
// return new Error('The server refused the connection');
|
|
68
|
+
// }
|
|
69
|
+
// if (options.total_retry_time > 1000 * 60 * 60) {
|
|
70
|
+
// // End reconnecting after a specific timeout and flush all commands
|
|
71
|
+
// // with a individual error
|
|
72
|
+
// return new Error('Retry time exhausted');
|
|
73
|
+
// }
|
|
74
|
+
// const attempts =
|
|
75
|
+
// !retryAttempts || retryAttempts == null || isNaN(retryAttempts)
|
|
76
|
+
// ? DEFAULT_RETRY_ATTEMPTS
|
|
77
|
+
// : Number(retryAttempts);
|
|
78
|
+
// if (options.attempt > attempts) {
|
|
79
|
+
// // End reconnecting with built in error
|
|
80
|
+
// return undefined;
|
|
81
|
+
// }
|
|
82
|
+
// const timeout =
|
|
83
|
+
// !firstTimeout || firstTimeout == null || isNaN(firstTimeout) ? DEFAULT_FIRST_TIMEOUT : Number(firstTimeout);
|
|
84
|
+
// // reconnect after
|
|
85
|
+
// return Math.min(options.attempt * 100, timeout);
|
|
86
|
+
// },
|
|
87
|
+
// tls: redisSsl
|
|
88
|
+
// ? {
|
|
89
|
+
// servername: redisHost,
|
|
90
|
+
// }
|
|
91
|
+
// : undefined,
|
|
92
|
+
// });
|
|
93
|
+
// if (pingInterval && !isNaN(pingInterval) && pingInterval > 1000) {
|
|
94
|
+
// setInterval(async () => {
|
|
95
|
+
// redisClient.ping();
|
|
96
|
+
// }, pingInterval);
|
|
97
|
+
// }
|
|
98
|
+
return redisClient;
|
|
99
|
+
};
|
|
100
|
+
exports.createRedisClient = createRedisClient;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildDefaultResolvers = void 0;
|
|
4
|
+
const buildDefaultResolvers = (args) => {
|
|
5
|
+
const { prefix, core, query, mutation, types, disableList, disableGet, disableGetMany, disableCreate, disableCreateMany, disableUpdate, disableUpdateMany, disableSet, disableRemove, disableRemoveMany, } = args || {};
|
|
6
|
+
const Query = {
|
|
7
|
+
...(query || {}),
|
|
8
|
+
};
|
|
9
|
+
const Mutation = {
|
|
10
|
+
...(mutation || {}),
|
|
11
|
+
};
|
|
12
|
+
const coreToUse = core || `${prefix}Core`;
|
|
13
|
+
if (disableList !== true) {
|
|
14
|
+
Query[`${prefix}List`] = (parent, args, context) => {
|
|
15
|
+
return context.cores[coreToUse].list(args);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (disableGet !== true) {
|
|
19
|
+
Query[`${prefix}Get`] = (parent, args, context) => {
|
|
20
|
+
return context.cores[coreToUse].get(args);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (disableGetMany !== true) {
|
|
24
|
+
Query[`${prefix}GetMany`] = (parent, args, context) => {
|
|
25
|
+
return context.cores[coreToUse].getMany(args);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (disableCreate !== true) {
|
|
29
|
+
Mutation[`${prefix}Create`] = (parent, args, context) => {
|
|
30
|
+
return context.cores[coreToUse].create(args);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (disableCreateMany !== true) {
|
|
34
|
+
Mutation[`${prefix}CreateMany`] = (parent, args, context) => {
|
|
35
|
+
return context.cores[coreToUse].createMany(args);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (disableUpdate !== true) {
|
|
39
|
+
Mutation[`${prefix}Update`] = (parent, args, context) => {
|
|
40
|
+
return context.cores[coreToUse].update(args);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (disableUpdateMany !== true) {
|
|
44
|
+
Mutation[`${prefix}UpdateMany`] = (parent, args, context) => {
|
|
45
|
+
return context.cores[coreToUse].updateMany(args);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (disableSet !== true) {
|
|
49
|
+
Mutation[`${prefix}Set`] = (parent, args, context) => {
|
|
50
|
+
return context.cores[coreToUse].set(args);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (disableRemove !== true) {
|
|
54
|
+
Mutation[`${prefix}Remove`] = (parent, args, context) => {
|
|
55
|
+
return context.cores[coreToUse].remove(args);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (disableRemoveMany !== true) {
|
|
59
|
+
Mutation[`${prefix}RemoveMany`] = (parent, args, context) => {
|
|
60
|
+
return context.cores[coreToUse].removeMany(args);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
Query,
|
|
65
|
+
Mutation,
|
|
66
|
+
...(types || {}),
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
exports.buildDefaultResolvers = buildDefaultResolvers;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OpResult } from '@sdflc/api-helpers';
|
|
2
|
+
import { UserTokenParams, CreateUserTokenArgs, VerifyUserTokenArgs } from './interfaces';
|
|
3
|
+
export declare const setDefaultJwtAlgorithm: (algorithm: string) => void;
|
|
4
|
+
export declare const getDefaultJwtAlgorithm: () => string;
|
|
5
|
+
export declare const setDefaultJwtIssuer: (issuer: string) => void;
|
|
6
|
+
export declare const getDefaultJwtIssuer: () => string;
|
|
7
|
+
export declare const createUserToken: (params: UserTokenParams, secret: string, opt: CreateUserTokenArgs) => any;
|
|
8
|
+
export declare const verifyUserToken: (token: string, secret: string, args?: VerifyUserTokenArgs) => OpResult;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.verifyUserToken = exports.createUserToken = exports.getDefaultJwtIssuer = exports.setDefaultJwtIssuer = exports.getDefaultJwtAlgorithm = exports.setDefaultJwtAlgorithm = void 0;
|
|
7
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
+
const uuid_1 = require("uuid");
|
|
9
|
+
const api_helpers_1 = require("@sdflc/api-helpers");
|
|
10
|
+
const constants_1 = require("./constants");
|
|
11
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
12
|
+
let defaultJwtAlgorithm = constants_1.DEFAULT_JWT_ALGORITHM;
|
|
13
|
+
let defaultIssuer = constants_1.DEFAULT_JWT_ISSUER;
|
|
14
|
+
const setDefaultJwtAlgorithm = (algorithm) => {
|
|
15
|
+
defaultJwtAlgorithm = algorithm;
|
|
16
|
+
};
|
|
17
|
+
exports.setDefaultJwtAlgorithm = setDefaultJwtAlgorithm;
|
|
18
|
+
const getDefaultJwtAlgorithm = () => {
|
|
19
|
+
return defaultJwtAlgorithm;
|
|
20
|
+
};
|
|
21
|
+
exports.getDefaultJwtAlgorithm = getDefaultJwtAlgorithm;
|
|
22
|
+
const setDefaultJwtIssuer = (issuer) => {
|
|
23
|
+
defaultIssuer = issuer;
|
|
24
|
+
};
|
|
25
|
+
exports.setDefaultJwtIssuer = setDefaultJwtIssuer;
|
|
26
|
+
const getDefaultJwtIssuer = () => {
|
|
27
|
+
return defaultIssuer;
|
|
28
|
+
};
|
|
29
|
+
exports.getDefaultJwtIssuer = getDefaultJwtIssuer;
|
|
30
|
+
const createUserToken = (params, secret, opt) => {
|
|
31
|
+
const { algorithm, audience, issuer, jwtid, noTimestamp, header, keyid, expiresIn, useFingerprint } = opt || {};
|
|
32
|
+
if (!params || !secret) {
|
|
33
|
+
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED, null, 'Failed to create user JWT');
|
|
34
|
+
}
|
|
35
|
+
if (useFingerprint) {
|
|
36
|
+
const fingerprint = (0, uuid_1.v4)();
|
|
37
|
+
params['fingerprint'] = fingerprint;
|
|
38
|
+
}
|
|
39
|
+
const token = jsonwebtoken_1.default.sign(params, secret, {
|
|
40
|
+
algorithm: algorithm || defaultJwtAlgorithm,
|
|
41
|
+
audience,
|
|
42
|
+
issuer: issuer || defaultIssuer,
|
|
43
|
+
jwtid: jwtid || (0, uuid_1.v4)(),
|
|
44
|
+
subject: params.userId,
|
|
45
|
+
noTimestamp: noTimestamp ?? false,
|
|
46
|
+
header,
|
|
47
|
+
keyid,
|
|
48
|
+
expiresIn: expiresIn && !isNaN(expiresIn) ? expiresIn : undefined,
|
|
49
|
+
});
|
|
50
|
+
return api_helpers_1.OpResult.ok({ token, fingerprint: params.fingerprint });
|
|
51
|
+
};
|
|
52
|
+
exports.createUserToken = createUserToken;
|
|
53
|
+
function toNonEmptyArray(arr) {
|
|
54
|
+
if (!arr || arr.length === 0)
|
|
55
|
+
return undefined;
|
|
56
|
+
return arr;
|
|
57
|
+
}
|
|
58
|
+
const verifyUserToken = (token, secret, args) => {
|
|
59
|
+
const { algorithms, audience, issuer, ignoreExpiration, ignoreNotBefore, subject, clockTolerance, maxAge, clockTimestamp, nonce, fingerprint, } = args || {};
|
|
60
|
+
if (!args) {
|
|
61
|
+
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED, null, 'Cannot verify user token as there are no parameters specified');
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const issuerToUse = issuer || defaultIssuer;
|
|
65
|
+
const obj = jsonwebtoken_1.default.verify(token, secret, {
|
|
66
|
+
algorithms: algorithms || [defaultJwtAlgorithm],
|
|
67
|
+
audience: typeof audience === 'string' ? audience : toNonEmptyArray(audience),
|
|
68
|
+
issuer: typeof issuerToUse === 'string' ? issuerToUse : toNonEmptyArray(issuerToUse),
|
|
69
|
+
ignoreExpiration,
|
|
70
|
+
ignoreNotBefore,
|
|
71
|
+
subject,
|
|
72
|
+
clockTolerance,
|
|
73
|
+
maxAge,
|
|
74
|
+
clockTimestamp,
|
|
75
|
+
nonce,
|
|
76
|
+
});
|
|
77
|
+
if (obj?.fingerprint && obj.fingerprint != fingerprint) {
|
|
78
|
+
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.UNAUTHORIZED, null, 'User unauthenticated');
|
|
79
|
+
}
|
|
80
|
+
return api_helpers_1.OpResult.ok(obj);
|
|
81
|
+
}
|
|
82
|
+
catch (ex) {
|
|
83
|
+
if (ex.name === 'TokenExpiredError') {
|
|
84
|
+
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.EXPIRED, null, `User authorization has expired at ${(0, dayjs_1.default)(ex.expiredAt).toDate()}`);
|
|
85
|
+
}
|
|
86
|
+
else if (ex.name === 'JsonWebTokenError') {
|
|
87
|
+
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.EXPIRED, null, `JWT is invalid, reason: ${ex.message}`);
|
|
88
|
+
}
|
|
89
|
+
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.UNAUTHORIZED, null, 'User unauthenticated');
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
exports.verifyUserToken = verifyUserToken;
|
package/build/utils.d.ts
ADDED
package/build/utils.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.setFunctions = exports.setFunction = void 0;
|
|
7
|
+
const check_types_1 = __importDefault(require("check-types"));
|
|
8
|
+
const setFunction = (func, defaultFunc) => {
|
|
9
|
+
return check_types_1.default.function(func) ? func : defaultFunc;
|
|
10
|
+
};
|
|
11
|
+
exports.setFunction = setFunction;
|
|
12
|
+
const setFunctions = (obj, defaultFuncs = {}) => {
|
|
13
|
+
const keys = Object.keys(defaultFuncs || {});
|
|
14
|
+
return keys.reduce((acc, key) => {
|
|
15
|
+
if (check_types_1.default.function(obj[key])) {
|
|
16
|
+
acc[key] = obj[key];
|
|
17
|
+
}
|
|
18
|
+
return acc;
|
|
19
|
+
}, {});
|
|
20
|
+
};
|
|
21
|
+
exports.setFunctions = setFunctions;
|