@sdflc/backend-helpers 1.0.21 → 1.0.24
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/apiContext.d.ts +2 -2
- package/build/apiContext.js +122 -65
- package/build/baseCore.d.ts +7 -2
- package/build/baseCore.js +83 -37
- package/build/baseGateway.d.ts +9 -8
- package/build/baseGateway.js +141 -62
- package/build/baseGatewayHelpers.js +7 -6
- package/build/checkItHelpers.js +1 -1
- package/build/configBulder.js +4 -4
- package/build/constants.d.ts +5 -2
- package/build/constants.js +22 -36
- package/build/dataCache.js +1 -1
- package/build/database.js +2 -2
- package/build/dbHelpers.js +3 -3
- package/build/dbMigratorAndSeeder.js +10 -10
- package/build/dbSeeder.js +6 -6
- package/build/dbTableHelpers.d.ts +1 -2
- package/build/dbTableHelpers.js +9 -7
- package/build/index.d.ts +2 -1
- package/build/index.js +9 -1
- package/build/interfaces/BaseCoreInterface.d.ts +5 -0
- package/build/interfaces/BaseGatewayInterface.d.ts +2 -2
- package/build/interfaces/CreateUserTokenArgs.d.ts +0 -3
- package/build/interfaces/VerifyUserTokenArgs.d.ts +0 -2
- package/build/knexConfigBuilder.js +5 -5
- package/build/passwordHelpers.d.ts +5 -0
- package/build/passwordHelpers.js +76 -0
- package/build/resolversHelpers.js +11 -12
- package/build/userToken.d.ts +3 -3
- package/build/userToken.js +24 -19
- package/package.json +21 -19
package/build/dbTableHelpers.js
CHANGED
|
@@ -3,16 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
var constants_1 = __importDefault(require("./constants"));
|
|
6
|
+
exports.defaultFields = exports.addUserId = exports.addSpaceId = exports.addAmount = exports.addOrderNo = exports.dbFieldAddDefaults = void 0;
|
|
8
7
|
var utils_1 = require("@sdflc/utils");
|
|
9
|
-
var
|
|
8
|
+
var constants_1 = __importDefault(require("./constants"));
|
|
9
|
+
var FIELDS = constants_1.default.FIELDS;
|
|
10
10
|
var dbFieldAddDefaults = function (table, opt) {
|
|
11
11
|
var _a = opt || {}, addUserInfo = _a.addUserInfo, addVersion = _a.addVersion, addStatus = _a.addStatus, skipTimestamps = _a.skipTimestamps, skipRemovedAtStr = _a.skipRemovedAtStr;
|
|
12
12
|
if (addStatus) {
|
|
13
13
|
table
|
|
14
14
|
.integer(FIELDS.STATUS)
|
|
15
|
-
.defaultTo(STATUSES.ACTIVE)
|
|
15
|
+
.defaultTo(utils_1.STATUSES.ACTIVE)
|
|
16
16
|
.comment('The field is used to specify record status: 50 - Test, 100 - Active, 200 - Draft, 300 - Pending, 1000 - Blocked, 5000 - Disabled, 10000 - Removed');
|
|
17
17
|
}
|
|
18
18
|
if (addVersion) {
|
|
@@ -31,6 +31,8 @@ var dbFieldAddDefaults = function (table, opt) {
|
|
|
31
31
|
if (skipRemovedAtStr !== true) {
|
|
32
32
|
table.text(FIELDS.REMOVED_AT_STR).defaultTo('').comment('Used to create unique indexes.');
|
|
33
33
|
}
|
|
34
|
+
table.index([FIELDS.CREATED_AT]);
|
|
35
|
+
table.index([FIELDS.UPDATED_AT]);
|
|
34
36
|
}
|
|
35
37
|
if (addStatus) {
|
|
36
38
|
table.index([FIELDS.STATUS]);
|
|
@@ -53,9 +55,9 @@ var addAmount = function (table, fieldName) {
|
|
|
53
55
|
};
|
|
54
56
|
exports.addAmount = addAmount;
|
|
55
57
|
var addSpaceId = function (table, opt) {
|
|
56
|
-
var chain = table.text(FIELDS.
|
|
58
|
+
var chain = table.text(FIELDS.SPACE_ID).notNullable().comment('Reference to the space table');
|
|
57
59
|
if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
|
|
58
|
-
table.foreign(FIELDS.
|
|
60
|
+
table.foreign(FIELDS.SPACE_ID).references("space.".concat(FIELDS.ID)).onUpdate('CASCADE').onDelete('CASCADE');
|
|
59
61
|
}
|
|
60
62
|
return chain;
|
|
61
63
|
};
|
|
@@ -63,7 +65,7 @@ exports.addSpaceId = addSpaceId;
|
|
|
63
65
|
var addUserId = function (table, opt) {
|
|
64
66
|
var chain = table.uuid(FIELDS.USER_ID).notNullable().comment('Reference to the user table');
|
|
65
67
|
if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
|
|
66
|
-
table.foreign(FIELDS.userId).references("user."
|
|
68
|
+
table.foreign(FIELDS.userId).references("user.".concat(FIELDS.ID)).onUpdate('CASCADE').onDelete('CASCADE');
|
|
67
69
|
}
|
|
68
70
|
return chain;
|
|
69
71
|
};
|
package/build/index.d.ts
CHANGED
|
@@ -13,8 +13,9 @@ export { BaseGateway } from './baseGateway';
|
|
|
13
13
|
export { BaseCore } from './baseCore';
|
|
14
14
|
export { createApiContext, createContextDefault } from './apiContext';
|
|
15
15
|
export { BaseController } from './baseController';
|
|
16
|
-
export { dbFieldAddDefaults } from './dbTableHelpers';
|
|
16
|
+
export { dbFieldAddDefaults, addOrderNo, addAmount, addSpaceId, addUserId, defaultFields } from './dbTableHelpers';
|
|
17
17
|
export { buildDefaultResolvers } from './resolversHelpers';
|
|
18
18
|
export { createUserToken, verifyUserToken } from './userToken';
|
|
19
19
|
export { constants };
|
|
20
20
|
export { buildDefaultGatewayProps } from './baseGatewayHelpers';
|
|
21
|
+
export { getSaltAndHash, checkPassword } from './passwordHelpers';
|
package/build/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.buildDefaultGatewayProps = exports.constants = exports.verifyUserToken = exports.createUserToken = exports.buildDefaultResolvers = exports.dbFieldAddDefaults = exports.BaseController = exports.createContextDefault = exports.createApiContext = exports.BaseCore = exports.BaseGateway = exports.DataCache = exports.createErrorOnCheckError = exports.checkArray = exports.createRedisClient = exports.buildKnexConfig = exports.dbSeed = exports.DbMigratorAndSeeder = exports.dbRunMigrations = exports.dbTransformSeedsToObject = exports.dbReset = exports.dbWipe = exports.dbClean = exports.dbListTables = exports.dbCleanTable = exports.Database = exports.buildConfig = void 0;
|
|
6
|
+
exports.checkPassword = exports.getSaltAndHash = exports.buildDefaultGatewayProps = exports.constants = exports.verifyUserToken = exports.createUserToken = exports.buildDefaultResolvers = exports.defaultFields = exports.addUserId = exports.addSpaceId = exports.addAmount = exports.addOrderNo = exports.dbFieldAddDefaults = exports.BaseController = exports.createContextDefault = exports.createApiContext = exports.BaseCore = exports.BaseGateway = exports.DataCache = exports.createErrorOnCheckError = exports.checkArray = exports.createRedisClient = exports.buildKnexConfig = exports.dbSeed = exports.DbMigratorAndSeeder = exports.dbRunMigrations = exports.dbTransformSeedsToObject = exports.dbReset = exports.dbWipe = exports.dbClean = exports.dbListTables = exports.dbCleanTable = exports.Database = exports.buildConfig = void 0;
|
|
7
7
|
var constants_1 = __importDefault(require("./constants"));
|
|
8
8
|
exports.constants = constants_1.default;
|
|
9
9
|
var configBulder_1 = require("./configBulder");
|
|
@@ -42,6 +42,11 @@ var baseController_1 = require("./baseController");
|
|
|
42
42
|
Object.defineProperty(exports, "BaseController", { enumerable: true, get: function () { return baseController_1.BaseController; } });
|
|
43
43
|
var dbTableHelpers_1 = require("./dbTableHelpers");
|
|
44
44
|
Object.defineProperty(exports, "dbFieldAddDefaults", { enumerable: true, get: function () { return dbTableHelpers_1.dbFieldAddDefaults; } });
|
|
45
|
+
Object.defineProperty(exports, "addOrderNo", { enumerable: true, get: function () { return dbTableHelpers_1.addOrderNo; } });
|
|
46
|
+
Object.defineProperty(exports, "addAmount", { enumerable: true, get: function () { return dbTableHelpers_1.addAmount; } });
|
|
47
|
+
Object.defineProperty(exports, "addSpaceId", { enumerable: true, get: function () { return dbTableHelpers_1.addSpaceId; } });
|
|
48
|
+
Object.defineProperty(exports, "addUserId", { enumerable: true, get: function () { return dbTableHelpers_1.addUserId; } });
|
|
49
|
+
Object.defineProperty(exports, "defaultFields", { enumerable: true, get: function () { return dbTableHelpers_1.defaultFields; } });
|
|
45
50
|
var resolversHelpers_1 = require("./resolversHelpers");
|
|
46
51
|
Object.defineProperty(exports, "buildDefaultResolvers", { enumerable: true, get: function () { return resolversHelpers_1.buildDefaultResolvers; } });
|
|
47
52
|
var userToken_1 = require("./userToken");
|
|
@@ -49,3 +54,6 @@ Object.defineProperty(exports, "createUserToken", { enumerable: true, get: funct
|
|
|
49
54
|
Object.defineProperty(exports, "verifyUserToken", { enumerable: true, get: function () { return userToken_1.verifyUserToken; } });
|
|
50
55
|
var baseGatewayHelpers_1 = require("./baseGatewayHelpers");
|
|
51
56
|
Object.defineProperty(exports, "buildDefaultGatewayProps", { enumerable: true, get: function () { return baseGatewayHelpers_1.buildDefaultGatewayProps; } });
|
|
57
|
+
var passwordHelpers_1 = require("./passwordHelpers");
|
|
58
|
+
Object.defineProperty(exports, "getSaltAndHash", { enumerable: true, get: function () { return passwordHelpers_1.getSaltAndHash; } });
|
|
59
|
+
Object.defineProperty(exports, "checkPassword", { enumerable: true, get: function () { return passwordHelpers_1.checkPassword; } });
|
|
@@ -4,6 +4,7 @@ import { Database } from '../database';
|
|
|
4
4
|
import { BaseGateway } from '../baseGateway';
|
|
5
5
|
import { BaseCoreValidatorsInterface } from './BaseCoreValidatorsInterface';
|
|
6
6
|
import { BaseCoreDoingWhatInterface } from './BaseCoreDoingWhatInterface';
|
|
7
|
+
import { VerifyUserTokenArgs } from './VerifyUserTokenArgs';
|
|
7
8
|
export interface BaseCoreInterface {
|
|
8
9
|
db: Database;
|
|
9
10
|
context?: any;
|
|
@@ -35,4 +36,8 @@ export interface BaseCoreInterface {
|
|
|
35
36
|
onException?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
36
37
|
validators?: BaseCoreValidatorsInterface;
|
|
37
38
|
authenticate?(params: any, opt?: BaseCoreActionsInterface): Promise<any[]> | any[];
|
|
39
|
+
gwSpace?: BaseGateway;
|
|
40
|
+
interserviceApiKey?: string;
|
|
41
|
+
jwtSecret?: string;
|
|
42
|
+
verifytokenArgs?: VerifyUserTokenArgs;
|
|
38
43
|
}
|
|
@@ -5,7 +5,7 @@ import { LoaderInterface } from './LoaderInterface';
|
|
|
5
5
|
import { SortItemInterface } from './SortItemInterface';
|
|
6
6
|
export interface BaseGatewayInterface {
|
|
7
7
|
db: Database;
|
|
8
|
-
core
|
|
8
|
+
core?: BaseCore;
|
|
9
9
|
table?: string;
|
|
10
10
|
idField?: string;
|
|
11
11
|
setFields?: string[] | string;
|
|
@@ -16,7 +16,7 @@ export interface BaseGatewayInterface {
|
|
|
16
16
|
noCache?: boolean;
|
|
17
17
|
idGenerator?(args?: any): any;
|
|
18
18
|
insertFormatter?(args?: any): any;
|
|
19
|
-
updateFormatter?(args?: any): any;
|
|
19
|
+
updateFormatter?(args?: any, where?: any): any;
|
|
20
20
|
updateFilter?(query: any, params: any): any;
|
|
21
21
|
removeFormatter?(args?: any): any;
|
|
22
22
|
removeFilter?(query: any, params: any): any;
|
|
@@ -26,14 +26,14 @@ var camelResponse = function (result) {
|
|
|
26
26
|
if (!result || result.rows) {
|
|
27
27
|
return result;
|
|
28
28
|
}
|
|
29
|
-
return utils_1.camelKeys(result);
|
|
29
|
+
return (0, utils_1.camelKeys)(result);
|
|
30
30
|
};
|
|
31
31
|
var buildKnexConfig = function (dirName, appConfig) {
|
|
32
32
|
var dbType = appConfig.dbType, dbHost = appConfig.dbHost, dbPort = appConfig.dbPort, dbName = appConfig.dbName, dbSchema = appConfig.dbSchema, dbUser = appConfig.dbUser, dbPassword = appConfig.dbPassword, debug = appConfig.debug, nodeEnv = appConfig.nodeEnv, migrationsTemplateFileName = appConfig.migrationsTemplateFileName, migrationsFolder = appConfig.migrationsFolder, migrationsTable = appConfig.migrationsTable, useSchemaForMigrationsTable = appConfig.useSchemaForMigrationsTable, seedsFolder = appConfig.seedsFolder, seedsFolderDev = appConfig.seedsFolderDev, seedsFolderProd = appConfig.seedsFolderProd;
|
|
33
33
|
var sharedConfig = {
|
|
34
34
|
client: dbType || 'pg',
|
|
35
35
|
postProcessResponse: camelResponse,
|
|
36
|
-
wrapIdentifier: function (value, origImpl) { return (value === '*' ? origImpl(value) : origImpl(lodash_1.snakeCase(value))); },
|
|
36
|
+
wrapIdentifier: function (value, origImpl) { return (value === '*' ? origImpl(value) : origImpl((0, lodash_1.snakeCase)(value))); },
|
|
37
37
|
connection: {
|
|
38
38
|
host: dbHost,
|
|
39
39
|
port: dbPort,
|
|
@@ -48,18 +48,18 @@ var buildKnexConfig = function (dirName, appConfig) {
|
|
|
48
48
|
stub: path_1.default.join(dirName, migrationsTemplateFileName || defaultMigrationsTemplateFileName),
|
|
49
49
|
directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
|
|
50
50
|
tableName: migrationsTable ||
|
|
51
|
-
""
|
|
51
|
+
"".concat(useSchemaForMigrationsTable ? "".concat(dbSchema, ".") : '').concat(migrationsTable || defaultMigrationsTable),
|
|
52
52
|
}, seeds: {
|
|
53
53
|
directory: path_1.default.join(dirName, seedsFolderDev || seedsFolder || defaultSeedsFolder),
|
|
54
54
|
} }),
|
|
55
55
|
production: __assign(__assign({}, sharedConfig), { debug: debug, migrations: {
|
|
56
56
|
directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
|
|
57
57
|
tableName: migrationsTable ||
|
|
58
|
-
""
|
|
58
|
+
"".concat(useSchemaForMigrationsTable ? "".concat(dbSchema, ".") : '').concat(migrationsTable || defaultMigrationsTable),
|
|
59
59
|
}, seeds: {
|
|
60
60
|
directory: path_1.default.join(dirName, seedsFolderProd || seedsFolder || defaultSeedsFolder),
|
|
61
61
|
} }),
|
|
62
62
|
};
|
|
63
|
-
return lodash_1.get(config, nodeEnv);
|
|
63
|
+
return (0, lodash_1.get)(config, nodeEnv);
|
|
64
64
|
};
|
|
65
65
|
exports.buildKnexConfig = buildKnexConfig;
|
|
@@ -0,0 +1,76 @@
|
|
|
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.checkPassword = exports.getSaltAndHash = void 0;
|
|
43
|
+
var bcrypt_1 = __importDefault(require("bcrypt"));
|
|
44
|
+
var getSaltAndHash = function (password, saltRounds) {
|
|
45
|
+
if (saltRounds === void 0) { saltRounds = 10; }
|
|
46
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
47
|
+
var salt, hash;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
50
|
+
case 0: return [4 /*yield*/, bcrypt_1.default.genSalt(saltRounds)];
|
|
51
|
+
case 1:
|
|
52
|
+
salt = _a.sent();
|
|
53
|
+
return [4 /*yield*/, bcrypt_1.default.hash(password, salt)];
|
|
54
|
+
case 2:
|
|
55
|
+
hash = _a.sent();
|
|
56
|
+
return [2 /*return*/, {
|
|
57
|
+
salt: salt,
|
|
58
|
+
hash: hash,
|
|
59
|
+
}];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
exports.getSaltAndHash = getSaltAndHash;
|
|
65
|
+
var checkPassword = function (password, hashedPassword) { return __awaiter(void 0, void 0, void 0, function () {
|
|
66
|
+
var isCorrect;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0: return [4 /*yield*/, bcrypt_1.default.compare(password, hashedPassword)];
|
|
70
|
+
case 1:
|
|
71
|
+
isCorrect = _a.sent();
|
|
72
|
+
return [2 /*return*/, isCorrect];
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}); };
|
|
76
|
+
exports.checkPassword = checkPassword;
|
|
@@ -17,56 +17,55 @@ var buildDefaultResolvers = function (args) {
|
|
|
17
17
|
var Query = __assign({}, (query || {}));
|
|
18
18
|
var Mutation = __assign({}, (mutation || {}));
|
|
19
19
|
if (disableList !== true) {
|
|
20
|
-
Query[prefix
|
|
20
|
+
Query["".concat(prefix, "List")] = function (parent, args, context) {
|
|
21
21
|
return context[core].list(args);
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
if (disableGet !== true) {
|
|
25
|
-
Query[prefix
|
|
25
|
+
Query["".concat(prefix, "Get")] = function (parent, args, context) {
|
|
26
26
|
return context[core].get(args);
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
if (disableGetMany !== true) {
|
|
30
|
-
Query[prefix
|
|
30
|
+
Query["".concat(prefix, "GetMany")] = function (parent, args, context) {
|
|
31
31
|
return context[core].getMany(args);
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
if (disableCreate !== true) {
|
|
35
|
-
Mutation[prefix
|
|
35
|
+
Mutation["".concat(prefix, "Create")] = function (parent, args, context) {
|
|
36
36
|
return context[core].create(args);
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
if (disableCreateMany !== true) {
|
|
40
|
-
Mutation[prefix
|
|
40
|
+
Mutation["".concat(prefix, "CreateMany")] = function (parent, args, context) {
|
|
41
41
|
return context[core].createMany(args);
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
if (disableUpdate !== true) {
|
|
45
|
-
Mutation[prefix
|
|
45
|
+
Mutation["".concat(prefix, "Update")] = function (parent, args, context) {
|
|
46
46
|
return context[core].update(args);
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
if (disableUpdateMany !== true) {
|
|
50
|
-
Mutation[prefix
|
|
50
|
+
Mutation["".concat(prefix, "UpdateMany")] = function (parent, args, context) {
|
|
51
51
|
return context[core].updateMany(args);
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
if (disableSet !== true) {
|
|
55
|
-
Mutation[prefix
|
|
55
|
+
Mutation["".concat(prefix, "Set")] = function (parent, args, context) {
|
|
56
56
|
return context[core].set(args);
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
if (disableRemove !== true) {
|
|
60
|
-
Mutation[prefix
|
|
60
|
+
Mutation["".concat(prefix, "Remove")] = function (parent, args, context) {
|
|
61
61
|
return context[core].remove(args);
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
if (disableRemoveMany !== true) {
|
|
65
|
-
Mutation[prefix
|
|
65
|
+
Mutation["".concat(prefix, "RemoveMany")] = function (parent, args, context) {
|
|
66
66
|
return context[core].removeMany(args);
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
|
-
return __assign({ Query: Query,
|
|
70
|
-
Mutation: Mutation }, (types || {}));
|
|
69
|
+
return __assign({ Query: Query, Mutation: Mutation }, (types || {}));
|
|
71
70
|
};
|
|
72
71
|
exports.buildDefaultResolvers = buildDefaultResolvers;
|
package/build/userToken.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { OpResult } from '@sdflc/api-helpers';
|
|
2
|
-
import { CreateUserTokenArgs, VerifyUserTokenArgs } from './interfaces';
|
|
3
|
-
export declare const createUserToken: (
|
|
4
|
-
export declare const verifyUserToken: (
|
|
2
|
+
import { UserTokenParams, CreateUserTokenArgs, VerifyUserTokenArgs } from './interfaces';
|
|
3
|
+
export declare const createUserToken: (params: UserTokenParams, secret: string, opt: CreateUserTokenArgs) => OpResult;
|
|
4
|
+
export declare const verifyUserToken: (token: string, secret: string, args?: VerifyUserTokenArgs | undefined) => OpResult;
|
package/build/userToken.js
CHANGED
|
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.verifyUserToken = exports.createUserToken = void 0;
|
|
7
7
|
var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
8
|
var api_helpers_1 = require("@sdflc/api-helpers");
|
|
9
|
-
var createUserToken = function (
|
|
10
|
-
var _a =
|
|
11
|
-
if (!
|
|
9
|
+
var createUserToken = function (params, secret, opt) {
|
|
10
|
+
var _a = opt || {}, algorithm = _a.algorithm, audience = _a.audience, issuer = _a.issuer, jwtid = _a.jwtid, subject = _a.subject, noTimestamp = _a.noTimestamp, header = _a.header, keyid = _a.keyid, expiresIn = _a.expiresIn;
|
|
11
|
+
if (!params || !secret) {
|
|
12
12
|
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED);
|
|
13
13
|
}
|
|
14
14
|
var token = jsonwebtoken_1.default.sign(params, secret, {
|
|
15
|
-
algorithm: algorithm,
|
|
15
|
+
algorithm: algorithm || 'HS256',
|
|
16
16
|
audience: audience,
|
|
17
17
|
issuer: issuer,
|
|
18
18
|
jwtid: jwtid,
|
|
@@ -25,23 +25,28 @@ var createUserToken = function (args) {
|
|
|
25
25
|
return api_helpers_1.OpResult.ok(token);
|
|
26
26
|
};
|
|
27
27
|
exports.createUserToken = createUserToken;
|
|
28
|
-
var verifyUserToken = function (args) {
|
|
29
|
-
var _a = args || {},
|
|
28
|
+
var verifyUserToken = function (token, secret, args) {
|
|
29
|
+
var _a = args || {}, algorithms = _a.algorithms, audience = _a.audience, issuer = _a.issuer, ignoreExpiration = _a.ignoreExpiration, ignoreNotBefore = _a.ignoreNotBefore, subject = _a.subject, clockTolerance = _a.clockTolerance, maxAge = _a.maxAge, clockTimestamp = _a.clockTimestamp, nonce = _a.nonce;
|
|
30
30
|
if (!args) {
|
|
31
31
|
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED);
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
try {
|
|
34
|
+
var obj = jsonwebtoken_1.default.verify(token, secret, {
|
|
35
|
+
algorithms: algorithms || ['HS256'],
|
|
36
|
+
audience: audience,
|
|
37
|
+
issuer: issuer,
|
|
38
|
+
ignoreExpiration: ignoreExpiration,
|
|
39
|
+
ignoreNotBefore: ignoreNotBefore,
|
|
40
|
+
subject: subject,
|
|
41
|
+
clockTolerance: clockTolerance,
|
|
42
|
+
maxAge: maxAge,
|
|
43
|
+
clockTimestamp: clockTimestamp,
|
|
44
|
+
nonce: nonce,
|
|
45
|
+
});
|
|
46
|
+
return api_helpers_1.OpResult.ok(obj);
|
|
47
|
+
}
|
|
48
|
+
catch (ex) {
|
|
49
|
+
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.UNAUTHORIZED);
|
|
50
|
+
}
|
|
46
51
|
};
|
|
47
52
|
exports.verifyUserToken = verifyUserToken;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdflc/backend-helpers",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24",
|
|
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",
|
|
@@ -24,41 +24,43 @@
|
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"peerDependencies": {},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@types/
|
|
28
|
-
"@types/
|
|
29
|
-
"@types/
|
|
27
|
+
"@types/bcrypt": "^5.0.0",
|
|
28
|
+
"@types/bluebird": "^3.5.36",
|
|
29
|
+
"@types/dotenv-safe": "^8.1.2",
|
|
30
|
+
"@types/jest": "^26.0.24",
|
|
30
31
|
"@types/jsonwebtoken": "^8.5.8",
|
|
31
|
-
"@types/lodash": "^4.14.
|
|
32
|
-
"@types/node": "^14.
|
|
33
|
-
"@types/redis": "^2.8.
|
|
34
|
-
"@types/uuid": "^8.3.
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^4.
|
|
36
|
-
"@typescript-eslint/parser": "^4.
|
|
37
|
-
"eslint": "^7.
|
|
32
|
+
"@types/lodash": "^4.14.178",
|
|
33
|
+
"@types/node": "^14.18.12",
|
|
34
|
+
"@types/redis": "^2.8.32",
|
|
35
|
+
"@types/uuid": "^8.3.4",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
37
|
+
"@typescript-eslint/parser": "^4.33.0",
|
|
38
|
+
"eslint": "^7.32.0",
|
|
38
39
|
"eslint-config-prettier": "^6.15.0",
|
|
39
|
-
"eslint-plugin-jest": "^24.
|
|
40
|
-
"eslint-plugin-prettier": "^3.1
|
|
41
|
-
"eslint-plugin-react": "^7.
|
|
40
|
+
"eslint-plugin-jest": "^24.7.0",
|
|
41
|
+
"eslint-plugin-prettier": "^3.4.1",
|
|
42
|
+
"eslint-plugin-react": "^7.28.0",
|
|
42
43
|
"husky": "^6.0.0",
|
|
43
44
|
"jest": "^26.6.3",
|
|
44
|
-
"prettier": "^2.
|
|
45
|
+
"prettier": "^2.5.1",
|
|
45
46
|
"rimraf": "^3.0.2",
|
|
46
47
|
"run-script-os": "^1.1.3",
|
|
47
48
|
"ts-jest": "^26.4.4",
|
|
48
49
|
"ts-node": "^9.0.0",
|
|
49
|
-
"typescript": "^4.
|
|
50
|
+
"typescript": "^4.5.5"
|
|
50
51
|
},
|
|
51
52
|
"dependencies": {
|
|
52
53
|
"@sdflc/api-helpers": "^1.1.7",
|
|
53
|
-
"@sdflc/utils": "^1.0.
|
|
54
|
+
"@sdflc/utils": "^1.0.18",
|
|
55
|
+
"bcrypt": "^5.0.1",
|
|
54
56
|
"bluebird": "^3.7.2",
|
|
55
57
|
"dataloader": "^2.0.0",
|
|
56
58
|
"dayjs": "^1.10.7",
|
|
57
59
|
"dotenv-safe": "^8.2.0",
|
|
58
60
|
"jsonwebtoken": "^8.5.1",
|
|
59
|
-
"knex": "^0.95.
|
|
61
|
+
"knex": "^0.95.15",
|
|
60
62
|
"lodash": "^4.17.20",
|
|
61
|
-
"pg": "^8.
|
|
63
|
+
"pg": "^8.7.3",
|
|
62
64
|
"redis": "^3.1.2",
|
|
63
65
|
"redis-dataloader": "^1.0.2",
|
|
64
66
|
"uuid": "^8.3.2"
|