kool-koala 1.5.1 → 1.6.1

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/README.md CHANGED
@@ -33,8 +33,10 @@ const configuration = new Configuration({
33
33
  port: 8080,
34
34
  });
35
35
 
36
- KoalApp.getInstance(configuration).start((configuration) => {
37
- console.log(`KoalApp is started.`);
36
+ KoalApp.getInstance(configuration).initialize().then(() => {
37
+ KoalApp.getInstance().start((configuration) => {
38
+ console.log(`KoalApp is started.`);
39
+ });
38
40
  });
39
41
  ```
40
42
 
@@ -4,6 +4,7 @@ import { StringEnum } from "../types/common/string-enum";
4
4
  import { JwtConfigurationParameters } from "./jwt-configuration-parameters";
5
5
  import { DatabaseConfigurationParamters } from "./database-configuration-paramters";
6
6
  import { RepositoryBase } from "../database";
7
+ import { StaticFilesConfigurationParameters } from "./static-files-configuration-parameters";
7
8
  export interface ConfigurationParameters<U extends AuthenticableEntity = AuthenticableEntity, P extends StringEnum = {}> {
8
9
  port: number;
9
10
  controllers?: (ControllerConstructor)[];
@@ -12,4 +13,5 @@ export interface ConfigurationParameters<U extends AuthenticableEntity = Authent
12
13
  userRepository?: RepositoryBase<U>;
13
14
  permissionType?: P;
14
15
  restPrefix?: string;
16
+ staticFiles?: StaticFilesConfigurationParameters[];
15
17
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/../src/common/configuration-parameters.ts"],"names":[],"mappings":"","file":"configuration-parameters.js","sourcesContent":["import { ControllerConstructor } from \"../controllers\";\nimport { AuthenticableEntity } from \"../types\";\nimport { StringEnum } from \"../types/common/string-enum\";\nimport { JwtConfigurationParameters } from \"./jwt-configuration-parameters\";\nimport { DatabaseConfigurationParamters } from \"./database-configuration-paramters\";\nimport { RepositoryBase } from \"../database\";\n\nexport interface ConfigurationParameters<\n U extends AuthenticableEntity = AuthenticableEntity,\n P extends StringEnum = {}\n> {\n port: number,\n controllers?: (ControllerConstructor)[],\n database?: DatabaseConfigurationParamters,\n jwt?: JwtConfigurationParameters,\n userRepository?: RepositoryBase<U>,\n permissionType?: P,\n restPrefix?: string,\n}\n"]}
1
+ {"version":3,"sources":["../src/../src/common/configuration-parameters.ts"],"names":[],"mappings":"","file":"configuration-parameters.js","sourcesContent":["import { ControllerConstructor } from \"../controllers\";\nimport { AuthenticableEntity } from \"../types\";\nimport { StringEnum } from \"../types/common/string-enum\";\nimport { JwtConfigurationParameters } from \"./jwt-configuration-parameters\";\nimport { DatabaseConfigurationParamters } from \"./database-configuration-paramters\";\nimport { RepositoryBase } from \"../database\";\nimport { StaticFilesConfigurationParameters } from \"./static-files-configuration-parameters\";\n\nexport interface ConfigurationParameters<\n U extends AuthenticableEntity = AuthenticableEntity,\n P extends StringEnum = {}\n> {\n port: number,\n controllers?: (ControllerConstructor)[],\n database?: DatabaseConfigurationParamters,\n jwt?: JwtConfigurationParameters,\n userRepository?: RepositoryBase<U>,\n permissionType?: P,\n restPrefix?: string,\n staticFiles?: StaticFilesConfigurationParameters[]\n}\n"]}
@@ -13,4 +13,5 @@ export declare class Configuration<U extends AuthenticableEntity, P extends Stri
13
13
  getUserRepository(): import("..").RepositoryBase<U>;
14
14
  getPermissionType(): P;
15
15
  getRestPrefix(): string;
16
+ getStaticFilesConfiguration(): import("./static-files-configuration-parameters").StaticFilesConfigurationParameters[];
16
17
  }
@@ -30,6 +30,9 @@ class Configuration {
30
30
  var _a;
31
31
  return (_a = this.parameters.restPrefix) !== null && _a !== void 0 ? _a : '/api';
32
32
  }
33
+ getStaticFilesConfiguration() {
34
+ return this.parameters.staticFiles;
35
+ }
33
36
  }
34
37
  exports.Configuration = Configuration;
35
38
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/../src/common/configuration.ts"],"names":[],"mappings":";;;AAKA,MAAa,aAAa;IAIxB,YACU,UAAyC;QAAzC,eAAU,GAAV,UAAU,CAA+B;IAC/C,CAAC;IACL,MAAM,CAAC,WAAW,CAGhB,uBAAsD;QACtD,OAAO,IAAI,aAAa,CACtB,uBAAuB,CACxB,CAAC;IACJ,CAAC;IACD,cAAc;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;IACrC,CAAC;IACD,WAAW;QACT,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;IAClC,CAAC;IACD,OAAO;QACL,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;IAC9B,CAAC;IACD,gBAAgB;QACd,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;IAC7B,CAAC;IACD,iBAAiB;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC;IACxC,CAAC;IACD,iBAAiB;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC;IACxC,CAAC;IACD,aAAa;;QACX,OAAO,MAAA,IAAI,CAAC,UAAU,CAAC,UAAU,mCAAI,MAAM,CAAC;IAC9C,CAAC;CACF;AApCD,sCAoCC","file":"configuration.js","sourcesContent":["import { AuthenticableEntity } from \"../types/entities/authenticable-entity\";\nimport { ConfigurationParameters } from \"./configuration-parameters\";\nimport { StringEnum } from \"../types/common/string-enum\";\nimport { JwtConfigurationParameters } from \"./jwt-configuration-parameters\";\n\nexport class Configuration<\n U extends AuthenticableEntity,\n P extends StringEnum\n> {\n constructor(\n private parameters: ConfigurationParameters<U, P>\n ) { }\n static instantiate<\n T extends AuthenticableEntity,\n Q extends StringEnum\n >(configurationParameters: ConfigurationParameters<T, Q>): Configuration<T, Q> {\n return new Configuration<T, Q>(\n configurationParameters\n );\n }\n getControllers() {\n return this.parameters.controllers;\n }\n getDatabase() {\n return this.parameters.database;\n }\n getPort(): number {\n return this.parameters.port;\n }\n getJwtParameters(): JwtConfigurationParameters {\n return this.parameters.jwt;\n }\n getUserRepository() {\n return this.parameters.userRepository;\n }\n getPermissionType() {\n return this.parameters.permissionType;\n }\n getRestPrefix() {\n return this.parameters.restPrefix ?? '/api';\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/../src/common/configuration.ts"],"names":[],"mappings":";;;AAKA,MAAa,aAAa;IAIxB,YACU,UAAyC;QAAzC,eAAU,GAAV,UAAU,CAA+B;IAC/C,CAAC;IACL,MAAM,CAAC,WAAW,CAGhB,uBAAsD;QACtD,OAAO,IAAI,aAAa,CACtB,uBAAuB,CACxB,CAAC;IACJ,CAAC;IACD,cAAc;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;IACrC,CAAC;IACD,WAAW;QACT,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;IAClC,CAAC;IACD,OAAO;QACL,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;IAC9B,CAAC;IACD,gBAAgB;QACd,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;IAC7B,CAAC;IACD,iBAAiB;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC;IACxC,CAAC;IACD,iBAAiB;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC;IACxC,CAAC;IACD,aAAa;;QACX,OAAO,MAAA,IAAI,CAAC,UAAU,CAAC,UAAU,mCAAI,MAAM,CAAC;IAC9C,CAAC;IACD,2BAA2B;QACzB,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;IACrC,CAAC;CACF;AAvCD,sCAuCC","file":"configuration.js","sourcesContent":["import { AuthenticableEntity } from \"../types/entities/authenticable-entity\";\nimport { ConfigurationParameters } from \"./configuration-parameters\";\nimport { StringEnum } from \"../types/common/string-enum\";\nimport { JwtConfigurationParameters } from \"./jwt-configuration-parameters\";\n\nexport class Configuration<\n U extends AuthenticableEntity,\n P extends StringEnum\n> {\n constructor(\n private parameters: ConfigurationParameters<U, P>\n ) { }\n static instantiate<\n T extends AuthenticableEntity,\n Q extends StringEnum\n >(configurationParameters: ConfigurationParameters<T, Q>): Configuration<T, Q> {\n return new Configuration<T, Q>(\n configurationParameters\n );\n }\n getControllers() {\n return this.parameters.controllers;\n }\n getDatabase() {\n return this.parameters.database;\n }\n getPort(): number {\n return this.parameters.port;\n }\n getJwtParameters(): JwtConfigurationParameters {\n return this.parameters.jwt;\n }\n getUserRepository() {\n return this.parameters.userRepository;\n }\n getPermissionType() {\n return this.parameters.permissionType;\n }\n getRestPrefix() {\n return this.parameters.restPrefix ?? '/api';\n }\n getStaticFilesConfiguration() {\n return this.parameters.staticFiles;\n }\n}\n"]}
package/common/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './configuration';
2
2
  export * from './configuration-parameters';
3
3
  export * from './koalapp';
4
4
  export * from './status-code';
5
+ export * from './static-files-configuration-parameters';
package/common/index.js CHANGED
@@ -18,5 +18,6 @@ __exportStar(require("./configuration"), exports);
18
18
  __exportStar(require("./configuration-parameters"), exports);
19
19
  __exportStar(require("./koalapp"), exports);
20
20
  __exportStar(require("./status-code"), exports);
21
+ __exportStar(require("./static-files-configuration-parameters"), exports);
21
22
 
22
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,6DAA2C;AAC3C,4CAA0B;AAC1B,gDAA8B","file":"index.js","sourcesContent":["export * from './configuration';\nexport * from './configuration-parameters';\nexport * from './koalapp';\nexport * from './status-code';"]}
1
+ {"version":3,"sources":["../src/../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,6DAA2C;AAC3C,4CAA0B;AAC1B,gDAA8B;AAC9B,0EAAwD","file":"index.js","sourcesContent":["export * from './configuration';\nexport * from './configuration-parameters';\nexport * from './koalapp';\nexport * from './status-code';\nexport * from './static-files-configuration-parameters';\n"]}
@@ -27,7 +27,7 @@ export declare class KoalApp<U extends AuthenticableEntity, P extends StringEnum
27
27
  registerStaticFileServerMiddleware(): void;
28
28
  registerEndpoints(): void;
29
29
  start(callback?: (configuration: Configuration<U, P>) => void): Promise<void>;
30
- stop(): void;
30
+ stop(): Promise<void>;
31
31
  authorizationHeaderParser(context: Context, next: Next): Promise<void>;
32
32
  errorHandler(context: Context, next: Next): Promise<void>;
33
33
  getAuthorizationService(): AuthorizationService<U, P>;
package/common/koalapp.js CHANGED
@@ -92,18 +92,26 @@ class KoalApp {
92
92
  this.koa.use(transaction_middleware_1.transactionMiddleware);
93
93
  }
94
94
  registerStaticFileServerMiddleware() {
95
- this.koa.use((0, koa_static_1.default)(path_1.default.join(__dirname, '../client', 'browser')));
96
- this.koa.use((0, koa_static_1.default)(path_1.default.join(__dirname, '../../static')));
97
- this.koa.use((ctx, next) => __awaiter(this, void 0, void 0, function* () {
98
- const requestPath = ctx.request.path;
99
- if (!requestPath.startsWith(this.configuration.getRestPrefix()) && !/\.[a-z]+$/.test(requestPath)) {
100
- ctx.type = 'html';
101
- ctx.body = fs_1.default.createReadStream(path_1.default.join(__dirname, '../client', 'browser', 'index.html'));
102
- }
103
- else {
104
- yield next();
105
- }
106
- }));
95
+ if (!this.configuration.getStaticFilesConfiguration()) {
96
+ return;
97
+ }
98
+ for (const staticFilesConfig of this.configuration.getStaticFilesConfiguration()) {
99
+ const staticFilesPath = path_1.default.isAbsolute(staticFilesConfig.folder) ? staticFilesConfig.folder : path_1.default.join(path_1.default.dirname(require.main.filename), staticFilesConfig.folder);
100
+ console.log(`Serving files from: ${staticFilesPath}`);
101
+ this.koa.use((0, koa_static_1.default)(staticFilesPath));
102
+ this.koa.use((ctx, next) => __awaiter(this, void 0, void 0, function* () {
103
+ var _a, _b;
104
+ console.log(`Request received for static file: ${ctx.request.path}`);
105
+ const requestPath = ctx.request.path;
106
+ if (!requestPath.startsWith(this.configuration.getRestPrefix()) && !/\.[a-z]+$/.test(requestPath)) {
107
+ ctx.type = (_a = staticFilesConfig.defaultFileMimeType) !== null && _a !== void 0 ? _a : 'html';
108
+ ctx.body = fs_1.default.createReadStream(path_1.default.join(staticFilesPath, (_b = staticFilesConfig.defaultFile) !== null && _b !== void 0 ? _b : 'index.html'));
109
+ }
110
+ else {
111
+ yield next();
112
+ }
113
+ }));
114
+ }
107
115
  }
108
116
  registerEndpoints() {
109
117
  this.routerService = new router_service_1.RouterService(this.configuration.getControllers());
@@ -121,10 +129,22 @@ class KoalApp {
121
129
  });
122
130
  }
123
131
  stop() {
124
- if (this.server) {
125
- this.server.close();
126
- this.server = undefined;
127
- }
132
+ return new Promise((resolve, reject) => {
133
+ if (this.server) {
134
+ this.server.close((error) => {
135
+ if (!error) {
136
+ resolve();
137
+ }
138
+ else {
139
+ reject();
140
+ }
141
+ });
142
+ this.server = undefined;
143
+ }
144
+ else {
145
+ reject();
146
+ }
147
+ });
128
148
  }
129
149
  authorizationHeaderParser(context, next) {
130
150
  return __awaiter(this, void 0, void 0, function* () {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/../src/common/koalapp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8CAAgC;AAEhC,+DAA2D;AAG3D,+CAA2C;AAC3C,gEAA+B;AAC/B,oEAAwC;AACxC,oCAAmD;AACnD,4DAA+B;AAC/B,gDAAwB;AACxB,4CAAoB;AAGpB,sFAAiF;AACjF,kFAA8E;AAI9E,MAAa,OAAO;IAclB,YAA4B,aAAkC;QAAlC,kBAAa,GAAb,aAAa,CAAqB;QARtD,QAAG,GAAG,IAAI,aAAG,EAAE,CAAC;IASxB,CAAC;IAEM,MAAM,CAAC,WAAW,CAGvB,aAAmC;QACnC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACtB,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;YAC/C,CAAC;YACD,OAAO,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAC,aAAc,CAAC,CAAC;QACjD,CAAC;QACD,OAAO,OAAO,CAAC,QAAQ,CAAC;IAC1B,CAAC;IAEM,MAAM,CAAO,aAAa;;YAC/B,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC,qBAAqB,EAA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CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,MAAM,GAAG,wBAAU,CAAC,YAAY,CAAC;oBACzC,OAAO,CAAC,IAAI,GAAG;wBACb,OAAO,EAAE,KAAK;wBACd,OAAO,EAAE,eAAe;qBACzB,CAAA;gBACH,CAAC;YACH,CAAC;iBACI,CAAC;gBACJ,MAAM,IAAI,EAAE,CAAC;YACf,CAAC;QACH,CAAC;KAAA;IAEK,YAAY,CAAC,OAAgB,EAAE,IAAU;;YAC7C,IAAI,CAAC;gBACH,MAAM,IAAI,EAAE,CAAC;YACf,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,iBAAS,EAAE,CAAC;oBAC/B,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,aAAa,EAAE,CAAC;oBACvC,OAAO,CAAC,IAAI,GAAiB;wBAC3B,OAAO,EAAE,KAAK;wBACd,OAAO,EAAE,KAAK,CAAC,OAAO;qBACvB,CAAC;gBACJ,CAAC;qBACI,CAAC;oBACJ,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;oBACnB,OAAO,CAAC,MAAM,GAAG,wBAAU,CAAC,qBAAqB,CAAC;oBAClD,OAAO,CAAC,IAAI,GAAiB;wBAC3B,OAAO,EAAE,KAAK;qBACf,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;KAAA;IAED,uBAAuB;QACrB,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;CACF;AAnKD,0BAmKC","file":"koalapp.js","sourcesContent":["import Koa, { Next } from 'koa';\nimport { Configuration } from './configuration';\nimport { RouterService } from '../services/router-service';\nimport { AuthenticableEntity } from '../types/entities/authenticable-entity';\nimport { DataSource } from 'typeorm';\nimport { StatusCode } from './status-code';\nimport jwt from 'jsonwebtoken';\nimport bodyParser from 'koa-bodyparser';\nimport { BaseResponse, ErrorBase } from '../types';\nimport serve from \"koa-static\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport { AuthorizationService } from '../services';\nimport { StringEnum } from '../types/common/string-enum';\nimport { errorHandlerMiddleware } from '../middlewares/error-handler-middleware';\nimport { transactionMiddleware } from '../middlewares/transaction-middleware';\nimport { Server } from 'http';\nimport { Context } from '../types/common/context';\n\nexport class KoalApp<\n U extends AuthenticableEntity,\n P extends StringEnum\n> {\n private static instance: KoalApp<any, any>;\n\n private koa = new Koa();\n private routerService: RouterService;\n private databaseConnection: DataSource;\n\n private server: Server;\n\n private authorizationService: AuthorizationService<U, P>;\n\n private constructor(private configuration: Configuration<U, P>) {\n }\n\n public static getInstance<\n T extends AuthenticableEntity,\n Q extends StringEnum\n >(configuration?: Configuration<T, Q>): KoalApp<T, Q> {\n if (!KoalApp.instance) {\n if (!configuration) {\n throw new Error(\"Configuration is required\");\n }\n KoalApp.instance = new KoalApp(configuration!);\n }\n return KoalApp.instance;\n }\n\n public static async resetInstance() {\n await KoalApp.getInstance().getDatabaseConnection().destroy();\n KoalApp.instance = undefined;\n }\n\n public getConfiguration(): Configuration<U, P> {\n return this.configuration;\n }\n\n public getRouterService(): RouterService {\n return this.routerService;\n }\n\n public getDatabaseConnection(): DataSource {\n return this.databaseConnection;\n }\n async initialize() {\n try {\n await this.setupDatabaseConnection();\n console.log(\"Database connection initialized.\");\n this.setupErrorHandler();\n console.log(\"Error handler initialized.\");\n this.setupTransaction();\n console.log(\"Transaction starter middleware initialized.\");\n this.koa.use(this.authorizationHeaderParser.bind(this));\n console.log(\"Authorization header parser initialized.\");\n this.koa.use(bodyParser());\n console.log(\"Body parser initialized.\");\n this.registerStaticFileServerMiddleware();\n console.log(\"Static file server initialized.\");\n this.registerEndpoints();\n console.log(\"Endpoints registered.\");\n } catch (error) {\n console.log(\"Error during database initialization...\", error);\n throw new Error('Error during application intialization...');\n }\n }\n async setupDatabaseConnection() {\n if (this.configuration.getDatabase()) {\n this.databaseConnection = await this.configuration.getDatabase().dataSource.initialize();\n await this.databaseConnection.runMigrations();\n }\n }\n setupErrorHandler() {\n this.koa.use(errorHandlerMiddleware);\n }\n setupTransaction() {\n this.koa.use(transactionMiddleware);\n }\n\n registerStaticFileServerMiddleware() {\n this.koa.use(serve(path.join(__dirname, '../client', 'browser')));\n this.koa.use(serve(path.join(__dirname, '../../static')));\n this.koa.use(async (ctx, next) => {\n const requestPath = ctx.request.path;\n\n if (!requestPath.startsWith(this.configuration.getRestPrefix()) && !/\\.[a-z]+$/.test(requestPath)) {\n ctx.type = 'html';\n ctx.body = fs.createReadStream(path.join(__dirname, '../client', 'browser', 'index.html'));\n } else {\n await next();\n }\n });\n }\n\n registerEndpoints() {\n this.routerService = new RouterService(\n this.configuration.getControllers()\n );\n this.koa\n .use(this.routerService.getRoutes())\n .use(this.routerService.allowedMethods());\n }\n\n async start(callback?: (configuration: Configuration<U, P>) => void) {\n this.server = this.koa.listen(this.configuration.getPort(), () => {\n if (callback) {\n callback(this.configuration);\n }\n });\n }\n\n stop() {\n if (this.server) {\n this.server.close();\n this.server = undefined;\n }\n }\n\n async authorizationHeaderParser(context: Context, next: Next) {\n const authHeader = context.headers.authorization;\n if (authHeader) {\n const token = authHeader.split(' ')[1];\n try {\n context.state.user = <AuthenticableEntity>jwt.verify(token, this.configuration.getJwtParameters().secretKey);\n await next();\n } catch (error) {\n context.status = StatusCode.UNAUTHORIZED;\n context.body = {\n success: false,\n message: 'Invalid token'\n }\n }\n }\n else {\n await next();\n }\n }\n\n async errorHandler(context: Context, next: Next) {\n try {\n await next();\n } catch (error) {\n if (error instanceof ErrorBase) {\n context.status = error.getStatusCode();\n context.body = <BaseResponse>{\n success: false,\n message: error.message\n };\n }\n else {\n console.log(error);\n context.status = StatusCode.INTERNAL_SERVER_ERROR;\n context.body = <BaseResponse>{\n success: false\n };\n }\n }\n }\n\n getAuthorizationService() {\n return this.authorizationService;\n }\n}"]}
1
+ {"version":3,"sources":["../src/../src/common/koalapp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8CAAgC;AAEhC,+DAA2D;AA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AAI,CAAC;oBACH,OAAO,CAAC,KAAK,CAAC,IAAI,GAAwB,sBAAG,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE,CAAC,SAAS,CAAC,CAAC;oBAC7G,MAAM,IAAI,EAAE,CAAC;gBACf,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,MAAM,GAAG,wBAAU,CAAC,YAAY,CAAC;oBACzC,OAAO,CAAC,IAAI,GAAG;wBACb,OAAO,EAAE,KAAK;wBACd,OAAO,EAAE,eAAe;qBACzB,CAAA;gBACH,CAAC;YACH,CAAC;iBACI,CAAC;gBACJ,MAAM,IAAI,EAAE,CAAC;YACf,CAAC;QACH,CAAC;KAAA;IAEK,YAAY,CAAC,OAAgB,EAAE,IAAU;;YAC7C,IAAI,CAAC;gBACH,MAAM,IAAI,EAAE,CAAC;YACf,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,iBAAS,EAAE,CAAC;oBAC/B,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,aAAa,EAAE,CAAC;oBACvC,OAAO,CAAC,IAAI,GAAiB;wBAC3B,OAAO,EAAE,KAAK;wBACd,OAAO,EAAE,KAAK,CAAC,OAAO;qBACvB,CAAC;gBACJ,CAAC;qBACI,CAAC;oBACJ,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;oBACnB,OAAO,CAAC,MAAM,GAAG,wBAAU,CAAC,qBAAqB,CAAC;oBAClD,OAAO,CAAC,IAAI,GAAiB;wBAC3B,OAAO,EAAE,KAAK;qBACf,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;KAAA;IAED,uBAAuB;QACrB,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;CACF;AAtLD,0BAsLC","file":"koalapp.js","sourcesContent":["import Koa, { Next } from 'koa';\nimport { Configuration } from './configuration';\nimport { RouterService } from '../services/router-service';\nimport { AuthenticableEntity } from '../types/entities/authenticable-entity';\nimport { DataSource } from 'typeorm';\nimport { StatusCode } from './status-code';\nimport jwt from 'jsonwebtoken';\nimport bodyParser from 'koa-bodyparser';\nimport { BaseResponse, ErrorBase } from '../types';\nimport serve from \"koa-static\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport { AuthorizationService } from '../services';\nimport { StringEnum } from '../types/common/string-enum';\nimport { errorHandlerMiddleware } from '../middlewares/error-handler-middleware';\nimport { transactionMiddleware } from '../middlewares/transaction-middleware';\nimport { Server } from 'http';\nimport { Context } from '../types/common/context';\n\nexport class KoalApp<\n U extends AuthenticableEntity,\n P extends StringEnum\n> {\n private static instance: KoalApp<any, any>;\n\n private koa = new Koa();\n private routerService: RouterService;\n private databaseConnection: DataSource;\n\n private server: Server;\n\n private authorizationService: AuthorizationService<U, P>;\n\n private constructor(private configuration: Configuration<U, P>) {\n }\n\n public static getInstance<\n T extends AuthenticableEntity,\n Q extends StringEnum\n >(configuration?: Configuration<T, Q>): KoalApp<T, Q> {\n if (!KoalApp.instance) {\n if (!configuration) {\n throw new Error(\"Configuration is required\");\n }\n KoalApp.instance = new KoalApp(configuration!);\n }\n return KoalApp.instance;\n }\n\n public static async resetInstance() {\n await KoalApp.getInstance().getDatabaseConnection().destroy();\n KoalApp.instance = undefined;\n }\n\n public getConfiguration(): Configuration<U, P> {\n return this.configuration;\n }\n\n public getRouterService(): RouterService {\n return this.routerService;\n }\n\n public getDatabaseConnection(): DataSource {\n return this.databaseConnection;\n }\n async initialize() {\n try {\n await this.setupDatabaseConnection();\n console.log(\"Database connection initialized.\");\n this.setupErrorHandler();\n console.log(\"Error handler initialized.\");\n this.setupTransaction();\n console.log(\"Transaction starter middleware initialized.\");\n this.koa.use(this.authorizationHeaderParser.bind(this));\n console.log(\"Authorization header parser initialized.\");\n this.koa.use(bodyParser());\n console.log(\"Body parser initialized.\");\n this.registerStaticFileServerMiddleware();\n console.log(\"Static file server initialized.\");\n this.registerEndpoints();\n console.log(\"Endpoints registered.\");\n } catch (error) {\n console.log(\"Error during database initialization...\", error);\n throw new Error('Error during application intialization...');\n }\n }\n async setupDatabaseConnection() {\n if (this.configuration.getDatabase()) {\n this.databaseConnection = await this.configuration.getDatabase().dataSource.initialize();\n await this.databaseConnection.runMigrations();\n }\n }\n setupErrorHandler() {\n this.koa.use(errorHandlerMiddleware);\n }\n setupTransaction() {\n this.koa.use(transactionMiddleware);\n }\n\n registerStaticFileServerMiddleware() {\n if (!this.configuration.getStaticFilesConfiguration()) {\n return;\n }\n for (const staticFilesConfig of this.configuration.getStaticFilesConfiguration()) {\n const staticFilesPath = path.isAbsolute(staticFilesConfig.folder) ? staticFilesConfig.folder : path.join(path.dirname(require.main.filename), staticFilesConfig.folder);\n console.log(`Serving files from: ${staticFilesPath}`);\n this.koa.use(serve(staticFilesPath));\n this.koa.use(async (ctx, next) => {\n console.log(`Request received for static file: ${ctx.request.path}`);\n const requestPath = ctx.request.path;\n\n if (!requestPath.startsWith(this.configuration.getRestPrefix()) && !/\\.[a-z]+$/.test(requestPath)) {\n ctx.type = staticFilesConfig.defaultFileMimeType ?? 'html';\n ctx.body = fs.createReadStream(path.join(staticFilesPath, staticFilesConfig.defaultFile ?? 'index.html'));\n } else {\n await next();\n }\n });\n }\n }\n\n registerEndpoints() {\n this.routerService = new RouterService(\n this.configuration.getControllers()\n );\n this.koa\n .use(this.routerService.getRoutes())\n .use(this.routerService.allowedMethods());\n }\n\n async start(callback?: (configuration: Configuration<U, P>) => void) {\n this.server = this.koa.listen(this.configuration.getPort(), () => {\n if (callback) {\n callback(this.configuration);\n }\n });\n }\n\n stop() {\n return new Promise<void>((resolve, reject) => {\n if (this.server) {\n this.server.close((error) => {\n if (!error) {\n resolve();\n }\n else {\n reject();\n }\n });\n this.server = undefined;\n }\n else {\n reject();\n }\n });\n }\n\n async authorizationHeaderParser(context: Context, next: Next) {\n const authHeader = context.headers.authorization;\n if (authHeader) {\n const token = authHeader.split(' ')[1];\n try {\n context.state.user = <AuthenticableEntity>jwt.verify(token, this.configuration.getJwtParameters().secretKey);\n await next();\n } catch (error) {\n context.status = StatusCode.UNAUTHORIZED;\n context.body = {\n success: false,\n message: 'Invalid token'\n }\n }\n }\n else {\n await next();\n }\n }\n\n async errorHandler(context: Context, next: Next) {\n try {\n await next();\n } catch (error) {\n if (error instanceof ErrorBase) {\n context.status = error.getStatusCode();\n context.body = <BaseResponse>{\n success: false,\n message: error.message\n };\n }\n else {\n console.log(error);\n context.status = StatusCode.INTERNAL_SERVER_ERROR;\n context.body = <BaseResponse>{\n success: false\n };\n }\n }\n }\n\n getAuthorizationService() {\n return this.authorizationService;\n }\n}"]}
@@ -0,0 +1,5 @@
1
+ export interface StaticFilesConfigurationParameters {
2
+ folder: string;
3
+ defaultFile?: string;
4
+ defaultFileMimeType?: string;
5
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+
4
+ //# sourceMappingURL=static-files-configuration-parameters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/../src/common/static-files-configuration-parameters.ts"],"names":[],"mappings":"","file":"static-files-configuration-parameters.js","sourcesContent":["export interface StaticFilesConfigurationParameters {\n folder: string;\n defaultFile?: string;\n defaultFileMimeType?: string;\n}\n"]}
@@ -11,7 +11,7 @@ export declare abstract class RestControllerBase<T extends IdentifiableEntity, R
11
11
  abstract getEndpoint(): RouteType[keyof RouteType];
12
12
  abstract getRepository(): RepositoryBase<T>;
13
13
  registerEndpoints(): void;
14
- protected getAuthorizationService(): import("..").AuthorizationService<import("../types").AuthenticableEntity, import("../types/common/string-enum").StringEnum>;
14
+ protected getAuthorizationService(): import("..").AuthorizationService<import("../types").AuthenticableEntity, import("../types").StringEnum>;
15
15
  listEntities(context: Context): Promise<void>;
16
16
  viewEntity(context: Context): Promise<void>;
17
17
  createEntity(context: Context): Promise<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kool-koala",
3
- "version": "1.5.1",
3
+ "version": "1.6.1",
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",
@@ -8,7 +8,7 @@
8
8
  "kool-koala": "./bin/kool-koala.js"
9
9
  },
10
10
  "scripts": {
11
- "gulp": "gulp",
11
+ "gulp": "gulp --gulpfile build/gulpfile.ts",
12
12
  "dev": "gulp --gulpfile build/gulpfile.ts dev",
13
13
  "compile": "gulp --gulpfile build/gulpfile.ts compile",
14
14
  "compile-release": "gulp --gulpfile build/gulpfile.ts compile-release",
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/../src/types/common/context.ts"],"names":[],"mappings":"","file":"context.js","sourcesContent":["import { ParameterizedContext } from \"koa\";\nimport { State } from \"./state\";\n\nexport type Context = ParameterizedContext<State>;"]}
1
+ {"version":3,"sources":["../src/../src/types/common/context.ts"],"names":[],"mappings":"","file":"context.js","sourcesContent":["import { ParameterizedContext } from \"koa\";\nimport { State } from \"./state\";\n\nexport type Context = ParameterizedContext<State>;\n"]}
@@ -0,0 +1,3 @@
1
+ export * from './context';
2
+ export * from './state';
3
+ export * from './string-enum';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./context"), exports);
18
+ __exportStar(require("./state"), exports);
19
+ __exportStar(require("./string-enum"), exports);
20
+
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/../src/types/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,0CAAwB;AACxB,gDAA8B","file":"index.js","sourcesContent":["export * from './context';\nexport * from './state';\nexport * from './string-enum';\n"]}
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './common';
1
2
  export * from './entities';
2
3
  export * from './errors';
3
4
  export * from './responses';
package/types/index.js CHANGED
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./common"), exports);
17
18
  __exportStar(require("./entities"), exports);
18
19
  __exportStar(require("./errors"), exports);
19
20
  __exportStar(require("./responses"), exports);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,2CAAyB;AACzB,8CAA4B","file":"index.js","sourcesContent":["export * from './entities';\nexport * from './errors';\nexport * from './responses';\n"]}
1
+ {"version":3,"sources":["../src/../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,6CAA2B;AAC3B,2CAAyB;AACzB,8CAA4B","file":"index.js","sourcesContent":["export * from './common';\nexport * from './entities';\nexport * from './errors';\nexport * from './responses';\n"]}