@sdflc/backend-helpers 1.0.49 → 1.0.52

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.
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultFields = exports.addLang = exports.addAccountId = exports.addUserId = exports.addSpaceId = exports.addAmount = exports.addOrderNo = exports.dbFieldAddDefaults = void 0;
4
- var utils_1 = require("@sdflc/utils");
5
- var constants_1 = require("./constants");
6
- var dbFieldAddDefaults = function (table, opt) {
7
- var _a = opt || {}, addUserInfo = _a.addUserInfo, addVersion = _a.addVersion, addStatus = _a.addStatus, skipTimestamps = _a.skipTimestamps, skipRemovedAtStr = _a.skipRemovedAtStr;
4
+ const utils_1 = require("@sdflc/utils");
5
+ const constants_1 = require("./constants");
6
+ const dbFieldAddDefaults = (table, opt) => {
7
+ const { addUserInfo, addVersion, addStatus, skipTimestamps, skipRemovedAtStr } = opt || {};
8
8
  if (addStatus) {
9
9
  table
10
10
  .integer(constants_1.FIELDS.STATUS)
@@ -38,30 +38,30 @@ var dbFieldAddDefaults = function (table, opt) {
38
38
  }
39
39
  };
40
40
  exports.dbFieldAddDefaults = dbFieldAddDefaults;
41
- var addOrderNo = function (table, opt) {
42
- var chain = table.text(constants_1.FIELDS.ORDER_NO).notNullable().defaultTo('10000000');
41
+ const addOrderNo = (table, opt) => {
42
+ const chain = table.text(constants_1.FIELDS.ORDER_NO).notNullable().defaultTo('10000000');
43
43
  if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
44
44
  table.index([constants_1.FIELDS.ORDER_NO]);
45
45
  }
46
46
  return chain;
47
47
  };
48
48
  exports.addOrderNo = addOrderNo;
49
- var addAmount = function (table, fieldName) {
49
+ const addAmount = (table, fieldName) => {
50
50
  return table.decimal(fieldName, 19, 4);
51
51
  };
52
52
  exports.addAmount = addAmount;
53
- var addSpaceId = function (table, opt) {
54
- var chain = table.text(constants_1.FIELDS.SPACE_ID).notNullable().comment('Reference to the space table');
53
+ const addSpaceId = (table, opt) => {
54
+ const chain = table.text(constants_1.FIELDS.SPACE_ID).notNullable().comment('Reference to the space table');
55
55
  if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
56
- table.foreign(constants_1.FIELDS.SPACE_ID).references("space.".concat(constants_1.FIELDS.ID)).onUpdate('CASCADE').onDelete('CASCADE');
56
+ table.foreign(constants_1.FIELDS.SPACE_ID).references(`space.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
57
57
  }
58
58
  return chain;
59
59
  };
60
60
  exports.addSpaceId = addSpaceId;
61
- var addUserId = function (table, opt) {
62
- var chain = table.uuid(constants_1.FIELDS.USER_ID).notNullable().comment('Reference to the user table');
61
+ const addUserId = (table, opt) => {
62
+ const chain = table.uuid(constants_1.FIELDS.USER_ID).notNullable().comment('Reference to the user table');
63
63
  if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
64
- table.foreign(constants_1.FIELDS.USER_ID).references("user.".concat(constants_1.FIELDS.ID)).onUpdate('CASCADE').onDelete('CASCADE');
64
+ table.foreign(constants_1.FIELDS.USER_ID).references(`user.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
65
65
  }
66
66
  if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
67
67
  table.index([constants_1.FIELDS.USER_ID]);
@@ -69,10 +69,10 @@ var addUserId = function (table, opt) {
69
69
  return chain;
70
70
  };
71
71
  exports.addUserId = addUserId;
72
- var addAccountId = function (table, opt) {
73
- var chain = table.uuid(constants_1.FIELDS.ACCOUNT_ID).notNullable().comment('Reference to the user table');
72
+ const addAccountId = (table, opt) => {
73
+ const chain = table.uuid(constants_1.FIELDS.ACCOUNT_ID).notNullable().comment('Reference to the user table');
74
74
  if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
75
- table.foreign(constants_1.FIELDS.ACCOUNT_ID).references("account.".concat(constants_1.FIELDS.ID)).onUpdate('CASCADE').onDelete('CASCADE');
75
+ table.foreign(constants_1.FIELDS.ACCOUNT_ID).references(`account.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
76
76
  }
77
77
  if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
78
78
  table.index([constants_1.FIELDS.ACCOUNT_ID]);
@@ -80,10 +80,10 @@ var addAccountId = function (table, opt) {
80
80
  return chain;
81
81
  };
82
82
  exports.addAccountId = addAccountId;
83
- var addLang = function (table, opt) {
84
- var chain = table.text(constants_1.FIELDS.LANG).defaultTo('en').notNullable().comment('Language, example: en, ru, en_CA, etc');
83
+ const addLang = (table, opt) => {
84
+ const chain = table.text(constants_1.FIELDS.LANG).defaultTo('en').notNullable().comment('Language, example: en, ru, en_CA, etc');
85
85
  if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
86
- table.foreign(constants_1.FIELDS.LANG).references("language.".concat(constants_1.FIELDS.ID)).onUpdate('CASCADE').onDelete('CASCADE');
86
+ table.foreign(constants_1.FIELDS.LANG).references(`language.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
87
87
  }
88
88
  if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
89
89
  table.index([constants_1.FIELDS.LANG]);
@@ -91,13 +91,12 @@ var addLang = function (table, opt) {
91
91
  return chain;
92
92
  };
93
93
  exports.addLang = addLang;
94
- var defaultFields = function (opt) {
95
- var _a;
96
- var addUserInfo = (opt || {}).addUserInfo;
97
- var obj = (_a = {},
98
- _a[constants_1.FIELDS.CREATED_AT] = '2021-01-01T00:00:00Z',
99
- _a[constants_1.FIELDS.UPDATED_AT] = '2021-01-01T00:00:00Z',
100
- _a);
94
+ const defaultFields = (opt) => {
95
+ const { addUserInfo } = opt || {};
96
+ const obj = {
97
+ [constants_1.FIELDS.CREATED_AT]: '2021-01-01T00:00:00Z',
98
+ [constants_1.FIELDS.UPDATED_AT]: '2021-01-01T00:00:00Z', // dh.dbUtcNow(),
99
+ };
101
100
  if (addUserInfo === true) {
102
101
  obj[constants_1.FIELDS.CREATED_BY] = utils_1.UUID_EMPTY;
103
102
  obj[constants_1.FIELDS.UPDATED_BY] = utils_1.UUID_EMPTY;
@@ -31,4 +31,5 @@ export interface BaseGatewayPropsInterface extends CacheInterface {
31
31
  activeStatuses?: number[];
32
32
  logger: Logger;
33
33
  isProduction: boolean;
34
+ usedKeyPrefixes?: any;
34
35
  }
@@ -1,39 +1,28 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
5
  Object.defineProperty(exports, "__esModule", { value: true });
17
6
  exports.buildKnexConfig = void 0;
18
- var path_1 = __importDefault(require("path"));
19
- var lodash_1 = require("lodash");
20
- var utils_1 = require("@sdflc/utils");
21
- var defaultMigrationsTable = 'migrations';
22
- var defaultMigrationsFolder = 'migrations';
23
- var defaultMigrationsTemplateFileName = 'migrations-template.js';
24
- var defaultSeedsFolder = 'seeds';
25
- var camelResponse = function (result) {
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) => {
26
15
  if (!result || result.rows) {
27
16
  return result;
28
17
  }
29
18
  return (0, utils_1.camelKeys)(result);
30
19
  };
31
- var buildKnexConfig = function (dirName, appConfig) {
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
- var sharedConfig = {
20
+ const buildKnexConfig = (dirName, appConfig) => {
21
+ const { dbType, dbHost, dbPort, dbName, dbSchema, dbUser, dbPassword, debug, nodeEnv, migrationsTemplateFileName, migrationsFolder, migrationsTable, useSchemaForMigrationsTable, seedsFolder, seedsFolderDev, seedsFolderProd, } = appConfig;
22
+ const sharedConfig = {
34
23
  client: dbType || 'pg',
35
24
  postProcessResponse: camelResponse,
36
- wrapIdentifier: function (value, origImpl) { return (value === '*' ? origImpl(value) : origImpl((0, lodash_1.snakeCase)(value))); },
25
+ wrapIdentifier: (value, origImpl) => (value === '*' ? origImpl(value) : origImpl((0, lodash_1.snakeCase)(value))),
37
26
  connection: {
38
27
  host: dbHost,
39
28
  port: dbPort,
@@ -43,19 +32,19 @@ var buildKnexConfig = function (dirName, appConfig) {
43
32
  //ssl: database.ssl,
44
33
  },
45
34
  };
46
- var config = {
47
- development: __assign(__assign({}, sharedConfig), { debug: debug, migrations: {
35
+ const config = {
36
+ development: Object.assign(Object.assign({}, sharedConfig), { debug, migrations: {
48
37
  stub: path_1.default.join(dirName, migrationsTemplateFileName || defaultMigrationsTemplateFileName),
49
38
  directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
50
39
  tableName: migrationsTable ||
51
- "".concat(useSchemaForMigrationsTable ? "".concat(dbSchema, ".") : '').concat(migrationsTable || defaultMigrationsTable),
40
+ `${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
52
41
  }, seeds: {
53
42
  directory: path_1.default.join(dirName, seedsFolderDev || seedsFolder || defaultSeedsFolder),
54
43
  } }),
55
- production: __assign(__assign({}, sharedConfig), { debug: debug, migrations: {
44
+ production: Object.assign(Object.assign({}, sharedConfig), { debug, migrations: {
56
45
  directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
57
46
  tableName: migrationsTable ||
58
- "".concat(useSchemaForMigrationsTable ? "".concat(dbSchema, ".") : '').concat(migrationsTable || defaultMigrationsTable),
47
+ `${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
59
48
  }, seeds: {
60
49
  directory: path_1.default.join(dirName, seedsFolderProd || seedsFolder || defaultSeedsFolder),
61
50
  } }),
@@ -8,69 +8,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
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
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
13
  };
41
14
  Object.defineProperty(exports, "__esModule", { value: true });
42
15
  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
- };
16
+ const bcrypt_1 = __importDefault(require("bcrypt"));
17
+ const getSaltAndHash = (password, saltRounds = 10) => __awaiter(void 0, void 0, void 0, function* () {
18
+ const salt = yield bcrypt_1.default.genSalt(saltRounds);
19
+ const hash = yield bcrypt_1.default.hash(password, salt);
20
+ return {
21
+ salt,
22
+ hash,
23
+ };
24
+ });
64
25
  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
- }); };
26
+ const checkPassword = (password, hashedPassword) => __awaiter(void 0, void 0, void 0, function* () {
27
+ const isCorrect = yield bcrypt_1.default.compare(password, hashedPassword);
28
+ return isCorrect;
29
+ });
76
30
  exports.checkPassword = checkPassword;
@@ -6,6 +6,12 @@ interface CreateRedisClientInterface {
6
6
  retryAttempts?: number;
7
7
  firstTimeout?: number;
8
8
  pingInterval?: number;
9
+ connectionTimeout?: number;
10
+ onConnecting?(): void;
11
+ onConnected?(): void;
12
+ onDisconnected?(): void;
13
+ onReconnecting?(): void;
14
+ onError?(err: any): void;
9
15
  }
10
16
  declare const createRedisClient: (args: CreateRedisClientInterface) => any;
11
17
  export { createRedisClient };
@@ -1,98 +1,97 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
42
3
  exports.createRedisClient = void 0;
43
- var redis_1 = __importDefault(require("redis"));
44
- var bluebird_1 = __importDefault(require("bluebird"));
45
- // Convert Redis client API to use promises, to make it usable with async/await syntax
46
- bluebird_1.default.promisifyAll(redis_1.default.RedisClient.prototype);
47
- bluebird_1.default.promisifyAll(redis_1.default.Multi.prototype);
48
- var DEFAULT_RETRY_ATTEMPTS = 10;
49
- var DEFAULT_FIRST_TIMEOUT = 3000;
50
- var createRedisClient = function (args) {
51
- var _a = args || {}, redisHost = _a.redisHost, redisPort = _a.redisPort, redisPassword = _a.redisPassword, redisSsl = _a.redisSsl, retryAttempts = _a.retryAttempts, firstTimeout = _a.firstTimeout, pingInterval = _a.pingInterval;
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 || {};
52
12
  if (!redisHost) {
53
13
  return null;
54
14
  }
55
- var newRedisClient = redis_1.default.createClient({
56
- host: redisHost,
57
- port: Number(redisPort),
58
- password: redisPassword || undefined,
59
- no_ready_check: true,
60
- retry_strategy: function (options) {
61
- if (options.error && options.error.code === 'ECONNREFUSED') {
62
- // End reconnecting on a specific error and flush all commands with
63
- // a individual error
64
- return new Error('The server refused the connection');
65
- }
66
- if (options.total_retry_time > 1000 * 60 * 60) {
67
- // End reconnecting after a specific timeout and flush all commands
68
- // with a individual error
69
- return new Error('Retry time exhausted');
70
- }
71
- var attempts = !retryAttempts || retryAttempts == null || isNaN(retryAttempts)
72
- ? DEFAULT_RETRY_ATTEMPTS
73
- : Number(retryAttempts);
74
- if (options.attempt > attempts) {
75
- // End reconnecting with built in error
76
- return undefined;
77
- }
78
- var timeout = !firstTimeout || firstTimeout == null || isNaN(firstTimeout) ? DEFAULT_FIRST_TIMEOUT : Number(firstTimeout);
79
- // reconnect after
80
- return Math.min(options.attempt * 100, timeout);
15
+ const cfg = {
16
+ socket: {
17
+ host: redisHost,
18
+ port: Number(redisPort),
19
+ family: 0,
20
+ connectTimeout: connectionTimeout != undefined ? connectionTimeout : 5000,
21
+ noDelay: true,
22
+ keepAlive: pingInterval != undefined ? pingInterval : 5000,
23
+ tls: redisSsl,
24
+ rejectUnauthorized: false,
25
+ reconnectStrategy: (retries) => Math.min(retries * 50, 500),
81
26
  },
82
- tls: redisSsl
83
- ? {
84
- servername: redisHost,
85
- }
86
- : undefined,
27
+ password: redisPassword || undefined,
28
+ };
29
+ const redisClient = (0, redis_1.createClient)(cfg);
30
+ redisClient.on('connect', () => {
31
+ if (typeof onConnecting === 'function') {
32
+ onConnecting();
33
+ }
87
34
  });
88
- if (pingInterval && !isNaN(pingInterval) && pingInterval > 1000) {
89
- setInterval(function () { return __awaiter(void 0, void 0, void 0, function () {
90
- return __generator(this, function (_a) {
91
- newRedisClient.ping();
92
- return [2 /*return*/];
93
- });
94
- }); }, pingInterval);
95
- }
96
- return newRedisClient;
35
+ redisClient.on('ready', () => {
36
+ if (typeof onConnected === 'function') {
37
+ onConnected();
38
+ }
39
+ });
40
+ redisClient.on('end', () => {
41
+ if (typeof onDisconnected === 'function') {
42
+ onDisconnected();
43
+ }
44
+ });
45
+ redisClient.on('reconnecting', () => {
46
+ if (typeof onReconnecting === 'function') {
47
+ onReconnecting();
48
+ }
49
+ });
50
+ redisClient.on('error', (err) => {
51
+ if (typeof onError === 'function') {
52
+ onError(err);
53
+ }
54
+ });
55
+ // const redisClientOld = redis.createClient({
56
+ // host: redisHost,
57
+ // port: Number(redisPort),
58
+ // password: redisPassword || undefined,
59
+ // no_ready_check: true,
60
+ // retry_strategy: function (options) {
61
+ // if (options.error && options.error.code === 'ECONNREFUSED') {
62
+ // // End reconnecting on a specific error and flush all commands with
63
+ // // a individual error
64
+ // return new Error('The server refused the connection');
65
+ // }
66
+ // if (options.total_retry_time > 1000 * 60 * 60) {
67
+ // // End reconnecting after a specific timeout and flush all commands
68
+ // // with a individual error
69
+ // return new Error('Retry time exhausted');
70
+ // }
71
+ // const attempts =
72
+ // !retryAttempts || retryAttempts == null || isNaN(retryAttempts)
73
+ // ? DEFAULT_RETRY_ATTEMPTS
74
+ // : Number(retryAttempts);
75
+ // if (options.attempt > attempts) {
76
+ // // End reconnecting with built in error
77
+ // return undefined;
78
+ // }
79
+ // const timeout =
80
+ // !firstTimeout || firstTimeout == null || isNaN(firstTimeout) ? DEFAULT_FIRST_TIMEOUT : Number(firstTimeout);
81
+ // // reconnect after
82
+ // return Math.min(options.attempt * 100, timeout);
83
+ // },
84
+ // tls: redisSsl
85
+ // ? {
86
+ // servername: redisHost,
87
+ // }
88
+ // : undefined,
89
+ // });
90
+ // if (pingInterval && !isNaN(pingInterval) && pingInterval > 1000) {
91
+ // setInterval(async () => {
92
+ // redisClient.ping();
93
+ // }, pingInterval);
94
+ // }
95
+ return redisClient;
97
96
  };
98
97
  exports.createRedisClient = createRedisClient;
@@ -1,72 +1,62 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.buildDefaultResolvers = void 0;
15
- var buildDefaultResolvers = function (args) {
16
- var _a = args || {}, prefix = _a.prefix, core = _a.core, query = _a.query, mutation = _a.mutation, types = _a.types, disableList = _a.disableList, disableGet = _a.disableGet, disableGetMany = _a.disableGetMany, disableCreate = _a.disableCreate, disableCreateMany = _a.disableCreateMany, disableUpdate = _a.disableUpdate, disableUpdateMany = _a.disableUpdateMany, disableSet = _a.disableSet, disableRemove = _a.disableRemove, disableRemoveMany = _a.disableRemoveMany;
17
- var Query = __assign({}, (query || {}));
18
- var Mutation = __assign({}, (mutation || {}));
19
- var coreToUse = core || "".concat(prefix, "Core");
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 = Object.assign({}, (query || {}));
7
+ const Mutation = Object.assign({}, (mutation || {}));
8
+ const coreToUse = core || `${prefix}Core`;
20
9
  if (disableList !== true) {
21
- Query["".concat(prefix, "List")] = function (parent, args, context) {
10
+ Query[`${prefix}List`] = (parent, args, context) => {
22
11
  return context.cores[coreToUse].list(args);
23
12
  };
24
13
  }
25
14
  if (disableGet !== true) {
26
- Query["".concat(prefix, "Get")] = function (parent, args, context) {
15
+ Query[`${prefix}Get`] = (parent, args, context) => {
27
16
  return context.cores[coreToUse].get(args);
28
17
  };
29
18
  }
30
19
  if (disableGetMany !== true) {
31
- Query["".concat(prefix, "GetMany")] = function (parent, args, context) {
20
+ Query[`${prefix}GetMany`] = (parent, args, context) => {
32
21
  return context.cores[coreToUse].getMany(args);
33
22
  };
34
23
  }
35
24
  if (disableCreate !== true) {
36
- Mutation["".concat(prefix, "Create")] = function (parent, args, context) {
25
+ Mutation[`${prefix}Create`] = (parent, args, context) => {
37
26
  return context.cores[coreToUse].create(args);
38
27
  };
39
28
  }
40
29
  if (disableCreateMany !== true) {
41
- Mutation["".concat(prefix, "CreateMany")] = function (parent, args, context) {
30
+ Mutation[`${prefix}CreateMany`] = (parent, args, context) => {
42
31
  return context.cores[coreToUse].createMany(args);
43
32
  };
44
33
  }
45
34
  if (disableUpdate !== true) {
46
- Mutation["".concat(prefix, "Update")] = function (parent, args, context) {
35
+ Mutation[`${prefix}Update`] = (parent, args, context) => {
47
36
  return context.cores[coreToUse].update(args);
48
37
  };
49
38
  }
50
39
  if (disableUpdateMany !== true) {
51
- Mutation["".concat(prefix, "UpdateMany")] = function (parent, args, context) {
40
+ Mutation[`${prefix}UpdateMany`] = (parent, args, context) => {
52
41
  return context.cores[coreToUse].updateMany(args);
53
42
  };
54
43
  }
55
44
  if (disableSet !== true) {
56
- Mutation["".concat(prefix, "Set")] = function (parent, args, context) {
45
+ Mutation[`${prefix}Set`] = (parent, args, context) => {
57
46
  return context.cores[coreToUse].set(args);
58
47
  };
59
48
  }
60
49
  if (disableRemove !== true) {
61
- Mutation["".concat(prefix, "Remove")] = function (parent, args, context) {
50
+ Mutation[`${prefix}Remove`] = (parent, args, context) => {
62
51
  return context.cores[coreToUse].remove(args);
63
52
  };
64
53
  }
65
54
  if (disableRemoveMany !== true) {
66
- Mutation["".concat(prefix, "RemoveMany")] = function (parent, args, context) {
55
+ Mutation[`${prefix}RemoveMany`] = (parent, args, context) => {
67
56
  return context.cores[coreToUse].removeMany(args);
68
57
  };
69
58
  }
70
- return __assign({ Query: Query, Mutation: Mutation }, (types || {}));
59
+ return Object.assign({ Query,
60
+ Mutation }, (types || {}));
71
61
  };
72
62
  exports.buildDefaultResolvers = buildDefaultResolvers;
@@ -4,44 +4,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.verifyUserToken = exports.createUserToken = void 0;
7
- var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
- var api_helpers_1 = require("@sdflc/api-helpers");
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;
7
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ const api_helpers_1 = require("@sdflc/api-helpers");
9
+ const createUserToken = (params, secret, opt) => {
10
+ const { algorithm, audience, issuer, jwtid, subject, noTimestamp, header, keyid, expiresIn } = opt || {};
11
11
  if (!params || !secret) {
12
12
  return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED, null, 'Failed to create user JWT');
13
13
  }
14
- var token = jsonwebtoken_1.default.sign(params, secret, {
14
+ const token = jsonwebtoken_1.default.sign(params, secret, {
15
15
  algorithm: algorithm || 'HS256',
16
- audience: audience,
17
- issuer: issuer,
18
- jwtid: jwtid,
19
- subject: subject,
20
- noTimestamp: noTimestamp,
21
- header: header,
22
- keyid: keyid,
16
+ audience,
17
+ issuer,
18
+ jwtid,
19
+ subject,
20
+ noTimestamp,
21
+ header,
22
+ keyid,
23
23
  expiresIn: expiresIn && !isNaN(expiresIn) ? expiresIn : undefined,
24
24
  });
25
25
  return api_helpers_1.OpResult.ok(token);
26
26
  };
27
27
  exports.createUserToken = createUserToken;
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;
28
+ const verifyUserToken = (token, secret, args) => {
29
+ const { algorithms, audience, issuer, ignoreExpiration, ignoreNotBefore, subject, clockTolerance, maxAge, clockTimestamp, nonce, } = args || {};
30
30
  if (!args) {
31
31
  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');
32
32
  }
33
33
  try {
34
- var obj = jsonwebtoken_1.default.verify(token, secret, {
34
+ const obj = jsonwebtoken_1.default.verify(token, secret, {
35
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,
36
+ audience,
37
+ issuer,
38
+ ignoreExpiration,
39
+ ignoreNotBefore,
40
+ subject,
41
+ clockTolerance,
42
+ maxAge,
43
+ clockTimestamp,
44
+ nonce,
45
45
  });
46
46
  return api_helpers_1.OpResult.ok(obj);
47
47
  }