kool-koala 1.1.1 → 1.1.2

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.
@@ -7,13 +7,13 @@ export interface DatabaseConfigurationParamters {
7
7
  }
8
8
  export interface ConfigurationParameters<U extends AuthenticableEntity, P extends Record<string, string | number>> {
9
9
  port: number;
10
- controllers: (ControllerConstructor)[];
10
+ controllers?: (ControllerConstructor)[];
11
11
  database?: DatabaseConfigurationParamters;
12
12
  jwt?: {
13
13
  saltRounds: number;
14
14
  secretKey: string;
15
15
  };
16
- userRepository: Repository<U>;
17
- permissionType: P;
16
+ userRepository?: Repository<U>;
17
+ permissionType?: P;
18
18
  restPrefix?: string;
19
19
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/../src/common/configuration-parameters.ts"],"names":[],"mappings":"","file":"configuration-parameters.js","sourcesContent":["import { DataSource, Repository } from \"typeorm\";\nimport { ControllerConstructor } from \"../controllers\";\nimport { AuthenticableEntity } from \"../types\";\n\nexport interface DatabaseConfigurationParamters {\n dataSource: DataSource,\n shouldRunMigrations: boolean\n}\n\nexport interface ConfigurationParameters<\n U extends AuthenticableEntity,\n P extends Record<string, string | number>\n> {\n port: number,\n controllers: (ControllerConstructor)[],\n database?: DatabaseConfigurationParamters,\n jwt?: {\n saltRounds: number,\n secretKey: string\n },\n userRepository: Repository<U>,\n permissionType: P,\n restPrefix?: string,\n}"]}
1
+ {"version":3,"sources":["../src/../src/common/configuration-parameters.ts"],"names":[],"mappings":"","file":"configuration-parameters.js","sourcesContent":["import { DataSource, Repository } from \"typeorm\";\nimport { ControllerConstructor } from \"../controllers\";\nimport { AuthenticableEntity } from \"../types\";\n\nexport interface DatabaseConfigurationParamters {\n dataSource: DataSource,\n shouldRunMigrations: boolean\n}\n\nexport interface ConfigurationParameters<\n U extends AuthenticableEntity,\n P extends Record<string, string | number>\n> {\n port: number,\n controllers?: (ControllerConstructor)[],\n database?: DatabaseConfigurationParamters,\n jwt?: {\n saltRounds: number,\n secretKey: string\n },\n userRepository?: Repository<U>,\n permissionType?: P,\n restPrefix?: string,\n}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kool-koala",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Full-stack framework to create NodeJS applications on server side and Angular applications on the client side with ease.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,7 +1,5 @@
1
- import { Repository } from 'typeorm';
2
1
  import { AuthenticableEntity } from '../types';
3
2
  export declare class AuthorizationService<U extends AuthenticableEntity, P> {
4
- private userRepository;
5
- constructor(userRepository: Repository<U>);
3
+ constructor();
6
4
  userHasRight(user: U, permission: P): Promise<void>;
7
5
  }
@@ -11,20 +11,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.AuthorizationService = void 0;
13
13
  const authorization_error_1 = require("../types/errors/authorization-error");
14
+ const common_1 = require("../common");
14
15
  class AuthorizationService {
15
- constructor(userRepository) {
16
- this.userRepository = userRepository;
16
+ constructor() {
17
17
  }
18
18
  userHasRight(user, permission) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- user = yield this.userRepository.findOne({
20
+ user = (yield common_1.KoalApp.getInstance().getConfiguration().getUserRepository().findOne({
21
21
  where: {
22
22
  id: user.id
23
23
  },
24
24
  relations: {
25
25
  permissions: true
26
26
  }
27
- });
27
+ }));
28
28
  if (!user.permissions.some((p) => p.textId === permission)) {
29
29
  throw new authorization_error_1.AuthorizationError(user, permission);
30
30
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/../src/services/authorization-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,6EAAyE;AAGzE,MAAa,oBAAoB;IAI/B,YAAoB,cAA6B;QAA7B,mBAAc,GAAd,cAAc,CAAe;IACjD,CAAC;IACK,YAAY,CAAC,IAAO,EAAE,UAAa;;YACvC,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;gBACvC,KAAK,EAAuB;oBAC1B,EAAE,EAAE,IAAI,CAAC,EAAE;iBACZ;gBACD,SAAS,EAA2B;oBAClC,WAAW,EAAE,IAAI;iBAClB;aACF,CAAC,CAAC;YACH,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC,EAAE,CAAC;gBAC3D,MAAM,IAAI,wCAAkB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;KAAA;CACF;AAnBD,oDAmBC","file":"authorization-service.js","sourcesContent":["import { FindOptionsRelations, FindOptionsWhere, Repository } from 'typeorm';\nimport { AuthorizationError } from '../types/errors/authorization-error';\nimport { AuthenticableEntity } from '../types';\n\nexport class AuthorizationService<\n U extends AuthenticableEntity,\n P\n> {\n constructor(private userRepository: Repository<U>) {\n }\n async userHasRight(user: U, permission: P) {\n user = await this.userRepository.findOne({\n where: <FindOptionsWhere<U>>{\n id: user.id\n },\n relations: <FindOptionsRelations<U>>{\n permissions: true\n }\n });\n if (!user.permissions.some((p) => p.textId === permission)) {\n throw new AuthorizationError(user, permission);\n }\n }\n}"]}
1
+ {"version":3,"sources":["../src/../src/services/authorization-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,6EAAyE;AAEzE,sCAAoC;AAEpC,MAAa,oBAAoB;IAI/B;IACA,CAAC;IACK,YAAY,CAAC,IAAO,EAAE,UAAa;;YACvC,IAAI,IAAM,MAAM,gBAAO,CAAC,WAAW,EAAE,CAAC,gBAAgB,EAAE,CAAC,iBAAiB,EAAE,CAAC,OAAO,CAAC;gBACnF,KAAK,EAAuB;oBAC1B,EAAE,EAAE,IAAI,CAAC,EAAE;iBACZ;gBACD,SAAS,EAA2B;oBAClC,WAAW,EAAE,IAAI;iBAClB;aACF,CAAC,CAAA,CAAC;YACH,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC,EAAE,CAAC;gBAC3D,MAAM,IAAI,wCAAkB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;KAAA;CACF;AAnBD,oDAmBC","file":"authorization-service.js","sourcesContent":["import { FindOptionsRelations, FindOptionsWhere, Repository } from 'typeorm';\nimport { AuthorizationError } from '../types/errors/authorization-error';\nimport { AuthenticableEntity } from '../types';\nimport { KoalApp } from '../common';\n\nexport class AuthorizationService<\n U extends AuthenticableEntity,\n P\n> {\n constructor() {\n }\n async userHasRight(user: U, permission: P) {\n user = <U>await KoalApp.getInstance().getConfiguration().getUserRepository().findOne({\n where: <FindOptionsWhere<U>>{\n id: user.id\n },\n relations: <FindOptionsRelations<U>>{\n permissions: true\n }\n });\n if (!user.permissions.some((p) => p.textId === permission)) {\n throw new AuthorizationError(user, permission);\n }\n }\n}"]}
@@ -7,9 +7,10 @@ exports.RouterService = void 0;
7
7
  const koa_router_1 = __importDefault(require("koa-router"));
8
8
  class RouterService {
9
9
  constructor(controllers) {
10
+ var _a;
10
11
  this.controllers = controllers;
11
12
  this.router = new koa_router_1.default();
12
- this.controllers.forEach((controllerType) => {
13
+ ((_a = this.controllers) !== null && _a !== void 0 ? _a : []).forEach((controllerType) => {
13
14
  console.log(`Register endpoints of '${controllerType.name}'`);
14
15
  const controller = new controllerType(this.router);
15
16
  controller.registerEndpoints();
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/../src/services/router-service.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAgC;AAGhC,MAAa,aAAa;IAExB,YAAoB,WAAsC;QAAtC,gBAAW,GAAX,WAAW,CAA2B;QACxD,IAAI,CAAC,MAAM,GAAG,IAAI,oBAAM,EAAE,CAAC;QAC3B,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,EAAE;YAC1C,OAAO,CAAC,GAAG,CAAC,0BAA0B,cAAc,CAAC,IAAI,GAAG,CAAC,CAAC;YAC9D,MAAM,UAAU,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACnD,UAAU,CAAC,iBAAiB,EAAE,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACtC,CAAC;CACF;AAlBD,sCAkBC","file":"router-service.js","sourcesContent":["import Router from \"koa-router\";\nimport { ControllerConstructor } from \"../controllers/controller-base\";\n\nexport class RouterService {\n private router: Router;\n constructor(private controllers: (ControllerConstructor)[]) {\n this.router = new Router();\n this.controllers.forEach((controllerType) => {\n console.log(`Register endpoints of '${controllerType.name}'`);\n const controller = new controllerType(this.router);\n controller.registerEndpoints();\n });\n }\n\n getRoutes() {\n return this.router.routes();\n }\n\n allowedMethods() {\n return this.router.allowedMethods();\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/../src/services/router-service.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAgC;AAGhC,MAAa,aAAa;IAExB,YAAoB,WAAsC;;QAAtC,gBAAW,GAAX,WAAW,CAA2B;QACxD,IAAI,CAAC,MAAM,GAAG,IAAI,oBAAM,EAAE,CAAC;QAC3B,CAAC,MAAA,IAAI,CAAC,WAAW,mCAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,EAAE;YAClD,OAAO,CAAC,GAAG,CAAC,0BAA0B,cAAc,CAAC,IAAI,GAAG,CAAC,CAAC;YAC9D,MAAM,UAAU,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACnD,UAAU,CAAC,iBAAiB,EAAE,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACtC,CAAC;CACF;AAlBD,sCAkBC","file":"router-service.js","sourcesContent":["import Router from \"koa-router\";\nimport { ControllerConstructor } from \"../controllers/controller-base\";\n\nexport class RouterService {\n private router: Router;\n constructor(private controllers: (ControllerConstructor)[]) {\n this.router = new Router();\n (this.controllers ?? []).forEach((controllerType) => {\n console.log(`Register endpoints of '${controllerType.name}'`);\n const controller = new controllerType(this.router);\n controller.registerEndpoints();\n });\n }\n\n getRoutes() {\n return this.router.routes();\n }\n\n allowedMethods() {\n return this.router.allowedMethods();\n }\n}\n"]}