kool-koala 1.1.0 → 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.
- package/common/configuration-parameters.d.ts +19 -0
- package/common/configuration-parameters.js.map +1 -1
- package/common/configuration.d.ts +21 -0
- package/common/index.d.ts +4 -0
- package/common/koalapp.d.ts +23 -0
- package/common/status-code.d.ts +10 -0
- package/controllers/controller-base.d.ts +8 -0
- package/controllers/index.d.ts +1 -0
- package/index.d.ts +5 -0
- package/koalas/index.d.ts +1 -0
- package/package.json +2 -1
- package/services/authorization-service.d.ts +5 -0
- package/services/authorization-service.js +4 -4
- package/services/authorization-service.js.map +1 -1
- package/services/index.d.ts +2 -0
- package/services/router-service.d.ts +9 -0
- package/services/router-service.js +2 -1
- package/services/router-service.js.map +1 -1
- package/types/entities/authenticable-entity.d.ts +4 -0
- package/types/entities/human-identifiable-entity.d.ts +3 -0
- package/types/entities/identifiable-entity.d.ts +3 -0
- package/types/entities/index.d.ts +6 -0
- package/types/entities/permission-entity.d.ts +4 -0
- package/types/entities/permission-holder-entity.d.ts +4 -0
- package/types/entities/user-entity.d.ts +4 -0
- package/types/errors/authorization-error.d.ts +5 -0
- package/types/errors/error-base.d.ts +9 -0
- package/types/errors/index.d.ts +2 -0
- package/types/index.d.ts +3 -0
- package/types/responses/base-response.d.ts +4 -0
- package/types/responses/index.d.ts +1 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DataSource, Repository } from "typeorm";
|
|
2
|
+
import { ControllerConstructor } from "../controllers";
|
|
3
|
+
import { AuthenticableEntity } from "../types";
|
|
4
|
+
export interface DatabaseConfigurationParamters {
|
|
5
|
+
dataSource: DataSource;
|
|
6
|
+
shouldRunMigrations: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface ConfigurationParameters<U extends AuthenticableEntity, P extends Record<string, string | number>> {
|
|
9
|
+
port: number;
|
|
10
|
+
controllers?: (ControllerConstructor)[];
|
|
11
|
+
database?: DatabaseConfigurationParamters;
|
|
12
|
+
jwt?: {
|
|
13
|
+
saltRounds: number;
|
|
14
|
+
secretKey: string;
|
|
15
|
+
};
|
|
16
|
+
userRepository?: Repository<U>;
|
|
17
|
+
permissionType?: P;
|
|
18
|
+
restPrefix?: string;
|
|
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
|
|
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}"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Repository } from "typeorm";
|
|
2
|
+
import { ControllerConstructor } from "../controllers/controller-base";
|
|
3
|
+
import { AuthenticableEntity } from "../types/entities/authenticable-entity";
|
|
4
|
+
import { ConfigurationParameters, DatabaseConfigurationParamters } from "./configuration-parameters";
|
|
5
|
+
interface JwtParameters {
|
|
6
|
+
saltRounds: number;
|
|
7
|
+
secretKey: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class Configuration<U extends AuthenticableEntity, P extends Record<string, string | number>> {
|
|
10
|
+
private parameters;
|
|
11
|
+
constructor(parameters: ConfigurationParameters<U, P>);
|
|
12
|
+
static instantiate<T extends AuthenticableEntity, Q extends Record<string, string | number>>(configurationParameters: ConfigurationParameters<T, Q>): Configuration<T, Q>;
|
|
13
|
+
getControllers(): ControllerConstructor[];
|
|
14
|
+
getDatabase(): DatabaseConfigurationParamters;
|
|
15
|
+
getPort(): number;
|
|
16
|
+
getJwtParameters(): JwtParameters;
|
|
17
|
+
getUserRepository(): Repository<U>;
|
|
18
|
+
getPermissionType(): P;
|
|
19
|
+
getRestPrefix(): string;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Next, ParameterizedContext } from 'koa';
|
|
2
|
+
import { Configuration } from './configuration';
|
|
3
|
+
import { AuthenticableEntity } from '../types/entities/authenticable-entity';
|
|
4
|
+
import { DataSource } from 'typeorm';
|
|
5
|
+
import { AuthorizationService } from '../services';
|
|
6
|
+
export declare class KoalApp<U extends AuthenticableEntity, P extends Record<string, string | number>> {
|
|
7
|
+
private configuration;
|
|
8
|
+
private static instance;
|
|
9
|
+
private koa;
|
|
10
|
+
private routerService;
|
|
11
|
+
private databaseConnection;
|
|
12
|
+
private authorizationService;
|
|
13
|
+
private constructor();
|
|
14
|
+
static getInstance<T extends AuthenticableEntity, Q extends Record<string, string | number>>(configuration?: Configuration<T, Q>): KoalApp<T, Q>;
|
|
15
|
+
getConfiguration(): Configuration<U, P>;
|
|
16
|
+
getDatabaseConnection(): DataSource;
|
|
17
|
+
initialize(): Promise<void>;
|
|
18
|
+
registerStaticFileServerMiddleware(): void;
|
|
19
|
+
start(callback?: (configuration: Configuration<U, P>) => void): Promise<void>;
|
|
20
|
+
authorizationHeaderParser(context: ParameterizedContext, next: Next): Promise<void>;
|
|
21
|
+
errorHandler(context: ParameterizedContext, next: Next): Promise<void>;
|
|
22
|
+
getAuthorizationService(): AuthorizationService<U, P>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import Router from "koa-router";
|
|
2
|
+
export declare abstract class ControllerBase {
|
|
3
|
+
protected router: Router;
|
|
4
|
+
constructor(router: Router);
|
|
5
|
+
abstract registerEndpoints(): void;
|
|
6
|
+
protected getApiUrl(path: string): string;
|
|
7
|
+
}
|
|
8
|
+
export type ControllerConstructor = new (router: Router) => ControllerBase;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './controller-base';
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function printKoalaArt(): void;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kool-koala",
|
|
3
|
-
"version": "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
|
+
"types": "index.d.ts",
|
|
6
7
|
"bin": {
|
|
7
8
|
"kool-koala": "./bin/kool-koala.js"
|
|
8
9
|
},
|
|
@@ -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(
|
|
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
|
|
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;
|
|
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}"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Router from "koa-router";
|
|
2
|
+
import { ControllerConstructor } from "../controllers/controller-base";
|
|
3
|
+
export declare class RouterService {
|
|
4
|
+
private controllers;
|
|
5
|
+
private router;
|
|
6
|
+
constructor(controllers: (ControllerConstructor)[]);
|
|
7
|
+
getRoutes(): Router.IMiddleware<any, {}>;
|
|
8
|
+
allowedMethods(): Router.IMiddleware<any, {}>;
|
|
9
|
+
}
|
|
@@ -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
|
|
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"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { HumanIdentifiableEntity } from "./human-identifiable-entity";
|
|
2
|
+
import { IdentifiableEntity } from "./identifiable-entity";
|
|
3
|
+
import { PermissionHolderEntity } from "./permission-holder-entity";
|
|
4
|
+
export type AuthenticableEntity = IdentifiableEntity & PermissionHolderEntity & HumanIdentifiableEntity;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StatusCode } from "../../common/status-code";
|
|
2
|
+
export declare class ErrorBase extends Error {
|
|
3
|
+
message: string;
|
|
4
|
+
protected statusCode: StatusCode;
|
|
5
|
+
protected error?: Error;
|
|
6
|
+
constructor(message: string, statusCode: StatusCode, error?: Error);
|
|
7
|
+
getStatusCode(): StatusCode;
|
|
8
|
+
getError(): Error | undefined;
|
|
9
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './base-response';
|