@sdflc/backend-helpers 1.0.14 → 1.0.15

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.js CHANGED
@@ -59,7 +59,7 @@ var ACCESS_RIGHTS = constants_1.default.ACCESS_RIGHTS;
59
59
  var defaultAfterAndBefore = function (params) {
60
60
  return params;
61
61
  };
62
- var defaultValidate = function (params, gateways) {
62
+ var defaultValidate = function (params, gateways, opt) {
63
63
  return [true, {}];
64
64
  };
65
65
  var defaultValidators = {
@@ -232,7 +232,12 @@ var BaseCore = /** @class */ (function () {
232
232
  case 5:
233
233
  validatedItems = {};
234
234
  if (!(typeof validate === 'function')) return [3 /*break*/, 8];
235
- return [4 /*yield*/, validate(args, this.getGateways())];
235
+ return [4 /*yield*/, validate(args, this.getGateways(), {
236
+ core: this,
237
+ setStep: setStep,
238
+ sameRequest: sameRequest,
239
+ hasTransaction: hasTransaction,
240
+ })];
236
241
  case 6:
237
242
  valideResult = _c.sent();
238
243
  result_1 = valideResult;
@@ -285,20 +290,20 @@ var BaseCore = /** @class */ (function () {
285
290
  args: args,
286
291
  validate: this.validators.list,
287
292
  accessRights: [ACCESS_RIGHTS.LIST],
288
- action: function (args) { return __awaiter(_this, void 0, void 0, function () {
293
+ action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
289
294
  var object, items, result;
290
295
  var _a;
291
296
  return __generator(this, function (_b) {
292
297
  switch (_b.label) {
293
298
  case 0:
294
299
  this.logger.log("Requesting a list for " + this.name + ":", args);
295
- return [4 /*yield*/, this.beforeList(args, this.getGateways())];
300
+ return [4 /*yield*/, this.beforeList(args, this.getGateways(), __assign({ core: this }, opt))];
296
301
  case 1:
297
302
  object = _b.sent();
298
303
  return [4 /*yield*/, ((_a = this.gateway) === null || _a === void 0 ? void 0 : _a.list(object))];
299
304
  case 2:
300
305
  items = _b.sent();
301
- return [4 /*yield*/, this.afterList(items, this.getGateways())];
306
+ return [4 /*yield*/, this.afterList(items, this.getGateways(), __assign({ core: this }, opt))];
302
307
  case 3:
303
308
  result = _b.sent();
304
309
  // ON NO DATA RETURN EMPTY CODE
@@ -381,7 +386,7 @@ var BaseCore = /** @class */ (function () {
381
386
  args: args,
382
387
  validate: this.validators.create,
383
388
  accessRights: [ACCESS_RIGHTS.CREATE],
384
- action: function (args) { return __awaiter(_this, void 0, void 0, function () {
389
+ action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
385
390
  var params, object, item, result;
386
391
  var _a;
387
392
  return __generator(this, function (_b) {
@@ -389,13 +394,13 @@ var BaseCore = /** @class */ (function () {
389
394
  case 0:
390
395
  params = (args || {}).params;
391
396
  this.logger.log("Requesting creation of an item for " + this.name + ":", args);
392
- return [4 /*yield*/, this.beforeCreate(params, this.getGateways())];
397
+ return [4 /*yield*/, this.beforeCreate(params, this.getGateways(), __assign({ core: this }, opt))];
393
398
  case 1:
394
399
  object = _b.sent();
395
400
  return [4 /*yield*/, ((_a = this.gateway) === null || _a === void 0 ? void 0 : _a.create(object))];
396
401
  case 2:
397
402
  item = _b.sent();
398
- return [4 /*yield*/, this.afterCreate(item, this.getGateways())];
403
+ return [4 /*yield*/, this.afterCreate(item, this.getGateways(), __assign({ core: this }, opt))];
399
404
  case 3:
400
405
  result = _b.sent();
401
406
  return [2 /*return*/, this.success(result)];
@@ -417,7 +422,7 @@ var BaseCore = /** @class */ (function () {
417
422
  args: args,
418
423
  validate: this.validators.createMany,
419
424
  accessRights: [ACCESS_RIGHTS.CREATE],
420
- action: function (args) { return __awaiter(_this, void 0, void 0, function () {
425
+ action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
421
426
  var params, objects, items, result;
422
427
  var _a;
423
428
  return __generator(this, function (_b) {
@@ -425,13 +430,13 @@ var BaseCore = /** @class */ (function () {
425
430
  case 0:
426
431
  params = (args || {}).params;
427
432
  this.logger.log("Requesting creation of multiple items for " + this.name + ":", args);
428
- return [4 /*yield*/, this.beforeCreateMany(params, this.getGateways())];
433
+ return [4 /*yield*/, this.beforeCreateMany(params, this.getGateways(), __assign({ core: this }, opt))];
429
434
  case 1:
430
435
  objects = _b.sent();
431
436
  return [4 /*yield*/, ((_a = this.gateway) === null || _a === void 0 ? void 0 : _a.create(objects))];
432
437
  case 2:
433
438
  items = _b.sent();
434
- return [4 /*yield*/, this.afterCreateMany(items, this.getGateways())];
439
+ return [4 /*yield*/, this.afterCreateMany(items, this.getGateways(), __assign({ core: this }, opt))];
435
440
  case 3:
436
441
  result = _b.sent();
437
442
  return [2 /*return*/, this.success(result)];
@@ -453,7 +458,7 @@ var BaseCore = /** @class */ (function () {
453
458
  args: args,
454
459
  validate: this.validators.update,
455
460
  accessRights: [ACCESS_RIGHTS.UPDATE],
456
- action: function (args) { return __awaiter(_this, void 0, void 0, function () {
461
+ action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
457
462
  var _a, where, params, object, item, result;
458
463
  var _b;
459
464
  return __generator(this, function (_c) {
@@ -461,13 +466,13 @@ var BaseCore = /** @class */ (function () {
461
466
  case 0:
462
467
  _a = args || {}, where = _a.where, params = _a.params;
463
468
  this.logger.log("Requesting update of an item for " + this.name + ":", args);
464
- return [4 /*yield*/, this.beforeUpdate(params, this.getGateways())];
469
+ return [4 /*yield*/, this.beforeUpdate(params, this.getGateways(), __assign({ core: this }, opt))];
465
470
  case 1:
466
471
  object = _c.sent();
467
472
  return [4 /*yield*/, ((_b = this.gateway) === null || _b === void 0 ? void 0 : _b.update(where, object))];
468
473
  case 2:
469
474
  item = _c.sent();
470
- return [4 /*yield*/, this.afterUpdate(item, this.getGateways())];
475
+ return [4 /*yield*/, this.afterUpdate(item, this.getGateways(), __assign({ core: this }, opt))];
471
476
  case 3:
472
477
  result = _c.sent();
473
478
  return [2 /*return*/, this.success(result, result.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND)];
@@ -489,7 +494,7 @@ var BaseCore = /** @class */ (function () {
489
494
  args: args,
490
495
  validate: this.validators.updateMany,
491
496
  accessRights: [ACCESS_RIGHTS.UPDATE],
492
- action: function (args) { return __awaiter(_this, void 0, void 0, function () {
497
+ action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
493
498
  var params, object, items, result;
494
499
  var _a;
495
500
  return __generator(this, function (_b) {
@@ -497,13 +502,13 @@ var BaseCore = /** @class */ (function () {
497
502
  case 0:
498
503
  params = (args || {}).params;
499
504
  this.logger.log("Requesting update of an item for " + this.name + ":", args);
500
- return [4 /*yield*/, this.beforeUpdateMany(params, this.getGateways())];
505
+ return [4 /*yield*/, this.beforeUpdateMany(params, this.getGateways(), __assign({ core: this }, opt))];
501
506
  case 1:
502
507
  object = _b.sent();
503
508
  return [4 /*yield*/, ((_a = this.gateway) === null || _a === void 0 ? void 0 : _a.updateMany(object))];
504
509
  case 2:
505
510
  items = _b.sent();
506
- return [4 /*yield*/, this.afterUpdateMany(items, this.getGateways())];
511
+ return [4 /*yield*/, this.afterUpdateMany(items, this.getGateways(), __assign({ core: this }, opt))];
507
512
  case 3:
508
513
  result = _b.sent();
509
514
  return [2 /*return*/, this.success(result)];
@@ -525,7 +530,7 @@ var BaseCore = /** @class */ (function () {
525
530
  args: args,
526
531
  validate: this.validators.set,
527
532
  accessRights: [ACCESS_RIGHTS.CREATE, ACCESS_RIGHTS.UPDATE],
528
- action: function (args) { return __awaiter(_this, void 0, void 0, function () {
533
+ action: function (args, opt /* { setStep, validatedItems, sameRequest } */) { return __awaiter(_this, void 0, void 0, function () {
529
534
  var params, object, items, result;
530
535
  var _a;
531
536
  return __generator(this, function (_b) {
@@ -533,13 +538,13 @@ var BaseCore = /** @class */ (function () {
533
538
  case 0:
534
539
  params = (args || {}).params;
535
540
  this.logger.log("Requesting setting of item(s) for " + this.name + ":", args);
536
- return [4 /*yield*/, this.beforeSet(params, this.getGateways())];
541
+ return [4 /*yield*/, this.beforeSet(params, __assign({ core: this }, opt))];
537
542
  case 1:
538
543
  object = _b.sent();
539
544
  return [4 /*yield*/, ((_a = this.gateway) === null || _a === void 0 ? void 0 : _a.set(object))];
540
545
  case 2:
541
546
  items = _b.sent();
542
- return [4 /*yield*/, this.afterSet(items, this.getGateways())];
547
+ return [4 /*yield*/, this.afterSet(items, __assign({ core: this }, opt))];
543
548
  case 3:
544
549
  result = _b.sent();
545
550
  return [2 /*return*/, this.success(result)];
@@ -561,7 +566,7 @@ var BaseCore = /** @class */ (function () {
561
566
  args: args,
562
567
  validate: this.validators.remove,
563
568
  accessRights: [ACCESS_RIGHTS.REMOVE],
564
- action: function (args) { return __awaiter(_this, void 0, void 0, function () {
569
+ action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
565
570
  var where, object, items, result;
566
571
  var _a;
567
572
  return __generator(this, function (_b) {
@@ -569,13 +574,13 @@ var BaseCore = /** @class */ (function () {
569
574
  case 0:
570
575
  where = (args || {}).where;
571
576
  this.logger.log("Requesting removal of an item for " + this.name + ":", args);
572
- return [4 /*yield*/, this.beforeRemove(where, this.getGateways())];
577
+ return [4 /*yield*/, this.beforeRemove(where, this.getGateways(), __assign({ core: this }, opt))];
573
578
  case 1:
574
579
  object = _b.sent();
575
580
  return [4 /*yield*/, ((_a = this.gateway) === null || _a === void 0 ? void 0 : _a.remove(object))];
576
581
  case 2:
577
582
  items = _b.sent();
578
- return [4 /*yield*/, this.afterRemove(items, this.getGateways())];
583
+ return [4 /*yield*/, this.afterRemove(items, this.getGateways(), __assign({ core: this }, opt))];
579
584
  case 3:
580
585
  result = _b.sent();
581
586
  return [2 /*return*/, this.success(result, result.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND)];
@@ -597,7 +602,7 @@ var BaseCore = /** @class */ (function () {
597
602
  args: args,
598
603
  validate: this.validators.removeMany,
599
604
  accessRights: [ACCESS_RIGHTS.REMOVE],
600
- action: function (args) { return __awaiter(_this, void 0, void 0, function () {
605
+ action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
601
606
  var where, object, items, result;
602
607
  var _a;
603
608
  return __generator(this, function (_b) {
@@ -605,13 +610,13 @@ var BaseCore = /** @class */ (function () {
605
610
  case 0:
606
611
  where = (args || {}).where;
607
612
  this.logger.log("Requesting removal of multiple items for " + this.name + ":", args);
608
- return [4 /*yield*/, this.beforeRemoveMany(where, this.getGateways())];
613
+ return [4 /*yield*/, this.beforeRemoveMany(where, this.getGateways(), __assign({ core: this }, opt))];
609
614
  case 1:
610
615
  object = _b.sent();
611
616
  return [4 /*yield*/, ((_a = this.gateway) === null || _a === void 0 ? void 0 : _a.remove(object))];
612
617
  case 2:
613
618
  items = _b.sent();
614
- return [4 /*yield*/, this.afterRemoveMany(items, this.getGateways())];
619
+ return [4 /*yield*/, this.afterRemoveMany(items, this.getGateways(), __assign({ core: this }, opt))];
615
620
  case 3:
616
621
  result = _b.sent();
617
622
  return [2 /*return*/, this.success(result, result.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND)];
package/build/index.d.ts CHANGED
@@ -15,4 +15,5 @@ export { createApiContext } from './apiContext';
15
15
  export { BaseController } from './baseController';
16
16
  export { dbFieldAddDefaults } from './dbTableHelpers';
17
17
  export { buildDefaultResolvers } from './resolversHelpers';
18
+ export { createUserToken, verifyUserToken } from './userToken';
18
19
  export { constants };
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.constants = exports.buildDefaultResolvers = exports.dbFieldAddDefaults = exports.BaseController = 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.constants = exports.verifyUserToken = exports.createUserToken = exports.buildDefaultResolvers = exports.dbFieldAddDefaults = exports.BaseController = 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");
@@ -43,3 +43,6 @@ var dbTableHelpers_1 = require("./dbTableHelpers");
43
43
  Object.defineProperty(exports, "dbFieldAddDefaults", { enumerable: true, get: function () { return dbTableHelpers_1.dbFieldAddDefaults; } });
44
44
  var resolversHelpers_1 = require("./resolversHelpers");
45
45
  Object.defineProperty(exports, "buildDefaultResolvers", { enumerable: true, get: function () { return resolversHelpers_1.buildDefaultResolvers; } });
46
+ var userToken_1 = require("./userToken");
47
+ Object.defineProperty(exports, "createUserToken", { enumerable: true, get: function () { return userToken_1.createUserToken; } });
48
+ Object.defineProperty(exports, "verifyUserToken", { enumerable: true, get: function () { return userToken_1.verifyUserToken; } });
@@ -25,32 +25,32 @@ export interface BaseCoreInterface {
25
25
  logger?: Logger;
26
26
  name?: string;
27
27
  doingWhat?: DoingWhatInterface;
28
- beforeList?(params: any, gateways?: any): any;
29
- beforeCreate?(params: any, gateways?: any): any;
30
- beforeCreateMany?(params: any, gateways?: any): any;
31
- beforeUpdate?(params: any, gateways?: any): any;
32
- beforeUpdateMany?(params: any, gateways?: any): any;
33
- beforeSet?(params: any, gateways?: any): any;
34
- beforeRemove?(params: any, gateways?: any): any;
35
- beforeRemoveMany?(params: any, gateways?: any): any;
36
- afterList?(params: any, gateways?: any): any;
37
- afterCreate?(params: any, gateways?: any): any;
38
- afterCreateMany?(params: any, gateways?: any): any;
39
- afterUpdate?(params: any, gateways?: any): any;
40
- afterUpdateMany?(params: any, gateways?: any): any;
41
- afterSet?(params: any, gateways?: any): any;
42
- afterRemove?(params: any, gateways?: any): any;
43
- afterRemoveMany?(params: any, gateways?: any): any;
44
- validateList?(params: any, gateways?: any): Promise<any[]> | any[];
45
- validateGet?(params: any, gateways?: any): Promise<any[]> | any[];
46
- validateGetMany?(params: any, gateways?: any): Promise<any[]> | any[];
47
- validateCreate?(params: any, gateways?: any): Promise<any[]> | any[];
48
- validateCreateMany?(params: any, gateways?: any): Promise<any[]> | any[];
49
- validateUpdate?(params: any, gateways?: any): Promise<any[]> | any[];
50
- validateUpdateMany?(params: any, gateways?: any): Promise<any[]> | any[];
51
- validateSet?(params: any, gateways?: any): Promise<any[]> | any[];
52
- validateRemove?(params: any, gateways?: any): Promise<any[]> | any[];
53
- validateRemoveMany?(params: any, gateways?: any): Promise<any[]> | any[];
28
+ beforeList?(params: any, gateways?: any, opt?: any): any;
29
+ beforeCreate?(params: any, gateways?: any, opt?: any): any;
30
+ beforeCreateMany?(params: any, gateways?: any, opt?: any): any;
31
+ beforeUpdate?(params: any, gateways?: any, opt?: any): any;
32
+ beforeUpdateMany?(params: any, gateways?: any, opt?: any): any;
33
+ beforeSet?(params: any, gateways?: any, opt?: any): any;
34
+ beforeRemove?(params: any, gateways?: any, opt?: any): any;
35
+ beforeRemoveMany?(params: any, gateways?: any, opt?: any): any;
36
+ afterList?(params: any, gateways?: any, opt?: any): any;
37
+ afterCreate?(params: any, gateways?: any, opt?: any): any;
38
+ afterCreateMany?(params: any, gateways?: any, opt?: any): any;
39
+ afterUpdate?(params: any, gateways?: any, opt?: any): any;
40
+ afterUpdateMany?(params: any, gateways?: any, opt?: any): any;
41
+ afterSet?(params: any, gateways?: any, opt?: any): any;
42
+ afterRemove?(params: any, gateways?: any, opt?: any): any;
43
+ afterRemoveMany?(params: any, gateways?: any, opt?: any): any;
44
+ validateList?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
45
+ validateGet?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
46
+ validateGetMany?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
47
+ validateCreate?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
48
+ validateCreateMany?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
49
+ validateUpdate?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
50
+ validateUpdateMany?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
51
+ validateSet?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
52
+ validateRemove?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
53
+ validateRemoveMany?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
54
54
  validators?: BaseCoreValidatorsInterface;
55
55
  authenticate?(params: any): Promise<any[]> | any[];
56
56
  doAuth: boolean;
@@ -1,12 +1,12 @@
1
1
  export interface BaseCoreValidatorsInterface {
2
- list?(params: any, gateways?: any): Promise<any[]> | any[];
3
- get?(params: any, gateways?: any): Promise<any[]> | any[];
4
- getMany?(params: any, gateways?: any): Promise<any[]> | any[];
5
- create?(params: any, gateways?: any): Promise<any[]> | any[];
6
- createMany?(params: any, gateways?: any): Promise<any[]> | any[];
7
- update?(params: any, gateways?: any): Promise<any[]> | any[];
8
- updateMany?(params: any, gateways?: any): Promise<any[]> | any[];
9
- set?(params: any, gateways?: any): Promise<any[]> | any[];
10
- remove?(params: any, gateways?: any): Promise<any[]> | any[];
11
- removeMany?(params: any, gateways?: any): Promise<any[]> | any[];
2
+ list?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
3
+ get?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
4
+ getMany?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
5
+ create?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
6
+ createMany?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
7
+ update?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
8
+ updateMany?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
9
+ set?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
10
+ remove?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
11
+ removeMany?(params: any, gateways?: any, opt?: any): Promise<any[]> | any[];
12
12
  }
@@ -2,7 +2,7 @@ export interface CoreActionInterface {
2
2
  args: any;
3
3
  doAuth?: boolean;
4
4
  accessRights?: any[];
5
- validate?(args?: any, gateways?: any): Promise<any[]> | any[];
5
+ validate?(args?: any, gateways?: any, opt?: any): Promise<any[]> | any[];
6
6
  action(args?: any, opt?: any): any;
7
7
  hasTransaction: boolean;
8
8
  doingWhat: string;
@@ -0,0 +1,14 @@
1
+ import { UserTokenParams } from './UserTokenParams';
2
+ export interface CreateUserTokenArgs {
3
+ params: UserTokenParams;
4
+ secret: string;
5
+ algorithm?: any;
6
+ audience?: string | string[];
7
+ issuer?: string;
8
+ jwtid?: string;
9
+ subject?: string;
10
+ noTimestamp?: boolean;
11
+ header?: any;
12
+ keyid?: any;
13
+ expiresIn?: number;
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export interface UserTokenParams {
2
+ accountId: string;
3
+ roleId: string;
4
+ userId: string;
5
+ [tokenProp: string]: string;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ export interface VerifyUserTokenArgs {
2
+ token: string;
3
+ secret: string;
4
+ algorithms?: any;
5
+ audience?: string | string[];
6
+ issuer?: string | string[];
7
+ ignoreExpiration?: boolean;
8
+ ignoreNotBefore?: boolean;
9
+ subject?: string;
10
+ clockTolerance?: number;
11
+ maxAge?: number;
12
+ clockTimestamp?: number;
13
+ nonce?: string;
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -13,3 +13,6 @@ export { DatabaseOptions } from './DatabaseOptions';
13
13
  export { DatabaseReadInterface } from './DatabaseReadInterface';
14
14
  export { BuildDefaultResolvers } from './BuildDefaultResolversOptions';
15
15
  export { BaseCoreValidatorsInterface } from './BaseCoreValidatorsInterface';
16
+ export { UserTokenParams } from './UserTokenParams';
17
+ export { CreateUserTokenArgs } from './CreateUserTokenArgs';
18
+ export { VerifyUserTokenArgs } from './VerifyUserTokenArgs';
@@ -0,0 +1,4 @@
1
+ import { OpResult } from '@sdflc/api-helpers';
2
+ import { CreateUserTokenArgs, VerifyUserTokenArgs } from './interfaces';
3
+ export declare const createUserToken: (args: CreateUserTokenArgs) => OpResult;
4
+ export declare const verifyUserToken: (args: VerifyUserTokenArgs) => OpResult;
@@ -0,0 +1,47 @@
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 = void 0;
7
+ var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ var api_helpers_1 = require("@sdflc/api-helpers");
9
+ var createUserToken = function (args) {
10
+ var _a = args || {}, params = _a.params, secret = _a.secret, 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 (!args) {
12
+ return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED);
13
+ }
14
+ var token = jsonwebtoken_1.default.sign(params, secret, {
15
+ algorithm: algorithm,
16
+ audience: audience,
17
+ issuer: issuer,
18
+ jwtid: jwtid,
19
+ subject: subject,
20
+ noTimestamp: noTimestamp,
21
+ header: header,
22
+ keyid: keyid,
23
+ expiresIn: expiresIn && !isNaN(expiresIn) ? expiresIn : undefined,
24
+ });
25
+ return api_helpers_1.OpResult.ok(token);
26
+ };
27
+ exports.createUserToken = createUserToken;
28
+ var verifyUserToken = function (args) {
29
+ var _a = args || {}, token = _a.token, secret = _a.secret, 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
+ if (!args) {
31
+ return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED);
32
+ }
33
+ var obj = jsonwebtoken_1.default.verify(token, secret, {
34
+ algorithms: algorithms,
35
+ audience: audience,
36
+ issuer: issuer,
37
+ ignoreExpiration: ignoreExpiration,
38
+ ignoreNotBefore: ignoreNotBefore,
39
+ subject: subject,
40
+ clockTolerance: clockTolerance,
41
+ maxAge: maxAge,
42
+ clockTimestamp: clockTimestamp,
43
+ nonce: nonce,
44
+ });
45
+ return api_helpers_1.OpResult.ok(obj);
46
+ };
47
+ exports.verifyUserToken = verifyUserToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdflc/backend-helpers",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Set of helper functions and classes to simplify building backend apps within @sdflc ecosystem",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -27,6 +27,7 @@
27
27
  "@types/bluebird": "^3.5.35",
28
28
  "@types/dotenv-safe": "^8.1.1",
29
29
  "@types/jest": "^26.0.16",
30
+ "@types/jsonwebtoken": "^8.5.8",
30
31
  "@types/lodash": "^4.14.165",
31
32
  "@types/node": "^14.14.10",
32
33
  "@types/redis": "^2.8.29",
@@ -52,7 +53,9 @@
52
53
  "@sdflc/utils": "^1.0.12",
53
54
  "bluebird": "^3.7.2",
54
55
  "dataloader": "^2.0.0",
56
+ "dayjs": "^1.10.7",
55
57
  "dotenv-safe": "^8.2.0",
58
+ "jsonwebtoken": "^8.5.1",
56
59
  "knex": "^0.95.6",
57
60
  "lodash": "^4.17.20",
58
61
  "pg": "^8.6.0",