speedly 1.2.10 → 1.2.12

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,5 +1,4 @@
1
1
  import { Request, Response, NextFunction } from 'express';
2
- type Handler = (req: Request, res: Response, next: (errorMessage?: string) => unknown) => unknown;
3
2
  declare const auth: (config?: {
4
3
  admin: {
5
4
  role: string;
@@ -7,12 +6,5 @@ declare const auth: (config?: {
7
6
  };
8
7
  jwtSecretEnv: string;
9
8
  customValidator: (req: Request, key: string) => boolean;
10
- }) => {
11
- (req: Request, res: Response, next: NextFunction): Promise<unknown>;
12
- admin(...handlers: [{
13
- permission: string;
14
- }, ...Handler[]] | Handler[]): /*elided*/ any;
15
- user(...handlers: Handler[]): /*elided*/ any;
16
- any(...handlers: Handler[]): /*elided*/ any;
17
- };
9
+ }) => (req: Request, res: Response, next: NextFunction) => Promise<unknown>;
18
10
  export default auth;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const getConfig_1 = __importDefault(require("../util/getConfig"));
7
7
  const gConfig = { admin: { role: 'ADMIN', model: '../models/admin' }, jwtSecretEnv: 'JWT_KEY', customValidator: (req, key) => { return true; }, ...(0, getConfig_1.default)('auth') };
8
+ const holders = {};
8
9
  const auth = (config = gConfig) => {
9
10
  // const adminModel = require('../models/admin')
10
11
  let handlerState = {};
@@ -57,7 +58,7 @@ const auth = (config = gConfig) => {
57
58
  next({ status: 403, json: { message: (error instanceof Error ? error.message : 'error on authentication please login again') } });
58
59
  }
59
60
  };
60
- useAuth.admin = (...handlers) => {
61
+ holders.admin = (...handlers) => {
61
62
  if (!Array.isArray(handlers))
62
63
  throw new Error('handlers must be an array');
63
64
  const hasConfig = typeof handlers[0] === 'object' && 'permission' in handlers[0];
@@ -69,18 +70,19 @@ const auth = (config = gConfig) => {
69
70
  };
70
71
  return useAuth;
71
72
  };
72
- useAuth.user = (...handlers) => {
73
+ holders.user = (...handlers) => {
73
74
  if (!Array.isArray(handlers))
74
75
  throw new Error('handlers must be an array');
75
76
  handlerState.user = { handlers };
76
77
  return useAuth;
77
78
  };
78
- useAuth.any = (...handlers) => {
79
+ holders.any = (...handlers) => {
79
80
  if (!Array.isArray(handlers))
80
81
  throw new Error('handlers must be an array');
81
82
  handlerState.any = { handlers };
82
83
  return useAuth;
83
84
  };
85
+ Object.assign(useAuth, holders);
84
86
  return useAuth;
85
87
  };
86
88
  exports.default = auth;
@@ -1,5 +1,4 @@
1
1
  import { Request, Response, NextFunction } from 'express';
2
- type Handler = (req: Request, res: Response, next: (errorMessage?: string) => unknown) => unknown;
3
2
  declare const auth: (config?: {
4
3
  admin: {
5
4
  role: string;
@@ -7,12 +6,5 @@ declare const auth: (config?: {
7
6
  };
8
7
  jwtSecretEnv: string;
9
8
  customValidator: (req: Request, key: string) => boolean;
10
- }) => {
11
- (req: Request, res: Response, next: NextFunction): Promise<unknown>;
12
- admin(...handlers: [{
13
- permission: string;
14
- }, ...Handler[]] | Handler[]): /*elided*/ any;
15
- user(...handlers: Handler[]): /*elided*/ any;
16
- any(...handlers: Handler[]): /*elided*/ any;
17
- };
9
+ }) => (req: Request, res: Response, next: NextFunction) => Promise<unknown>;
18
10
  export default auth;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const getConfig_1 = __importDefault(require("../util/getConfig"));
7
7
  const gConfig = { admin: { role: 'ADMIN', model: '../models/admin' }, jwtSecretEnv: 'JWT_KEY', customValidator: (req, key) => { return true; }, ...(0, getConfig_1.default)('auth') };
8
+ const holders = {};
8
9
  const auth = (config = gConfig) => {
9
10
  // const adminModel = require('../models/admin')
10
11
  let handlerState = {};
@@ -57,7 +58,7 @@ const auth = (config = gConfig) => {
57
58
  next({ status: 403, json: { message: (error instanceof Error ? error.message : 'error on authentication please login again') } });
58
59
  }
59
60
  };
60
- useAuth.admin = (...handlers) => {
61
+ holders.admin = (...handlers) => {
61
62
  if (!Array.isArray(handlers))
62
63
  throw new Error('handlers must be an array');
63
64
  const hasConfig = typeof handlers[0] === 'object' && 'permission' in handlers[0];
@@ -69,18 +70,19 @@ const auth = (config = gConfig) => {
69
70
  };
70
71
  return useAuth;
71
72
  };
72
- useAuth.user = (...handlers) => {
73
+ holders.user = (...handlers) => {
73
74
  if (!Array.isArray(handlers))
74
75
  throw new Error('handlers must be an array');
75
76
  handlerState.user = { handlers };
76
77
  return useAuth;
77
78
  };
78
- useAuth.any = (...handlers) => {
79
+ holders.any = (...handlers) => {
79
80
  if (!Array.isArray(handlers))
80
81
  throw new Error('handlers must be an array');
81
82
  handlerState.any = { handlers };
82
83
  return useAuth;
83
84
  };
85
+ Object.assign(useAuth, holders);
84
86
  return useAuth;
85
87
  };
86
88
  exports.default = auth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedly",
3
- "version": "1.2.10",
3
+ "version": "1.2.12",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",