expresso-macchiato 0.4.11 → 1.0.0-dev.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/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { DataSource, MixedList, EntitySchema, BaseEntity } from 'typeorm';
2
1
  import { Request, Response as Response$1, RequestHandler, Router, Express } from 'express';
2
+ import { BaseEntity, MixedList, EntitySchema } from 'typeorm';
3
3
  import { Socket, Namespace, Server as Server$1, ServerOptions } from 'socket.io';
4
4
  import http from 'http';
5
5
  import * as utils_logger_av from 'utils-logger-av';
@@ -50,14 +50,6 @@ type ListOptions = {
50
50
  order?: 'ASC' | 'DESC';
51
51
  } & SearchQuery;
52
52
 
53
- declare class DbConnector {
54
- private static DataSource;
55
- static getDataSource: () => DataSource;
56
- private readonly projectConfig;
57
- constructor(projectConfig: ProjectConfigs);
58
- connect: (entities: MixedList<Function | string | EntitySchema>, migrations?: string[], sync?: boolean, logging?: boolean) => Promise<void>;
59
- }
60
-
61
53
  interface Info {
62
54
  title: string;
63
55
  version: string;
@@ -410,6 +402,7 @@ type SecureTokenConfig = boolean | {
410
402
  };
411
403
  type TokenConstructor = {
412
404
  SECRET_KEY: string;
405
+ TOKEN_COOKIE_NAME?: string;
413
406
  ExpTime: number;
414
407
  EncAlgorithm: string;
415
408
  KeyLength: number;
@@ -503,6 +496,7 @@ declare class SocketWrapper<Metadata extends Record<string, any> = any> {
503
496
 
504
497
  declare class Token<Payload extends Record<string, any> = DefaultTokenPayload> {
505
498
  private SECRET_KEY;
499
+ private TOKEN_COOKIE_NAME;
506
500
  private ExpTime;
507
501
  private EncAlgorithm;
508
502
  private KeyLength;
@@ -534,7 +528,6 @@ type StarterOptions = {
534
528
  entities: MixedList<Function | string | EntitySchema>;
535
529
  migrations?: string[];
536
530
  sync?: boolean;
537
- log?: boolean;
538
531
  afterDbConnection?: () => Promise<void>;
539
532
  };
540
533
  backgroundServices?: Array<BackgroundService>;
@@ -666,4 +659,4 @@ declare const socketNok: (message: string) => SocketConnectionNok;
666
659
  declare const sleep: (ms: number) => Promise<unknown>;
667
660
  declare const getCompiledPath: (__filename: string, __dirname: string, pathsWithoutExtension: string[]) => string[];
668
661
 
669
- export { type ApiKeySecurity, BackgroundService, type BaseFormatContrainedParameter, type BaseOAuthSecurity, type BaseParameter, type BaseSchema, type BaseSecurity, type BasicAuthenticationSecurity, type BodyParameter, type Components, type ConnectedSocketClient, type Contact, DbConnector, type DefaultTokenPayload, type DynamicDbRouterOptions, type DynamicSwaggerOperation, type DynamicSwaggerOperationBody, type DynamicSwaggerPath, type DynamicSwaggerRequestBodyOperation, type ErrorsMapping, type ExpressReturn, type ExternalDocs, type FormDataParameter, type GenericFormat, type Header, type HeaderParameter, type Info, type IntegerFormat, type License, type ListOptions, type MethodPathHandling, type Methods, type NumberFormat, type OAuth2AccessCodeSecurity, type OAuth2ApplicationSecurity, type OAuth2ImplicitSecurity, type OAuth2PasswordSecurity, type OAuthScope, type Operation, type Parameter, type ParameterCollectionFormat, type ParameterType, type Path, type PathParameter, type ProjectConfigs, type QueryParameter, type Reference, type RequestBodyOperation, type Response, RouterWrapper, type RouterWrapperInterface, type Schema, type SchemaFormatConstraints, type SchemaV3, type SearchQuery, type SecureTokenConfig, type Security, type Server, type SocketConnectionMiddleware, type SocketConnectionNok, type SocketConnectionOk, SocketWrapper, type SocketWrapperConstructor, type Spec, Starter, type StarterOptions, type StringFormat, Swagger, type SwaggerMetadataInterface, type Tag, Token, type TokenApiOptions, type TokenConstructor, type XML, apiNok, apiOk, c, errorCatcher, fullLogNok, fullLogOk, getCompiledPath, i, log, sleep, socketNok, socketOk };
662
+ export { type ApiKeySecurity, BackgroundService, type BaseFormatContrainedParameter, type BaseOAuthSecurity, type BaseParameter, type BaseSchema, type BaseSecurity, type BasicAuthenticationSecurity, type BodyParameter, type Components, type ConnectedSocketClient, type Contact, type DefaultTokenPayload, type DynamicDbRouterOptions, type DynamicSwaggerOperation, type DynamicSwaggerOperationBody, type DynamicSwaggerPath, type DynamicSwaggerRequestBodyOperation, type ErrorsMapping, type ExpressReturn, type ExternalDocs, type FormDataParameter, type GenericFormat, type Header, type HeaderParameter, type Info, type IntegerFormat, type License, type ListOptions, type MethodPathHandling, type Methods, type NumberFormat, type OAuth2AccessCodeSecurity, type OAuth2ApplicationSecurity, type OAuth2ImplicitSecurity, type OAuth2PasswordSecurity, type OAuthScope, type Operation, type Parameter, type ParameterCollectionFormat, type ParameterType, type Path, type PathParameter, type ProjectConfigs, type QueryParameter, type Reference, type RequestBodyOperation, type Response, RouterWrapper, type RouterWrapperInterface, type Schema, type SchemaFormatConstraints, type SchemaV3, type SearchQuery, type SecureTokenConfig, type Security, type Server, type SocketConnectionMiddleware, type SocketConnectionNok, type SocketConnectionOk, SocketWrapper, type SocketWrapperConstructor, type Spec, Starter, type StarterOptions, type StringFormat, Swagger, type SwaggerMetadataInterface, type Tag, Token, type TokenApiOptions, type TokenConstructor, type XML, apiNok, apiOk, c, errorCatcher, fullLogNok, fullLogOk, getCompiledPath, i, log, sleep, socketNok, socketOk };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { DataSource, MixedList, EntitySchema, BaseEntity } from 'typeorm';
2
1
  import { Request, Response as Response$1, RequestHandler, Router, Express } from 'express';
2
+ import { BaseEntity, MixedList, EntitySchema } from 'typeorm';
3
3
  import { Socket, Namespace, Server as Server$1, ServerOptions } from 'socket.io';
4
4
  import http from 'http';
5
5
  import * as utils_logger_av from 'utils-logger-av';
@@ -50,14 +50,6 @@ type ListOptions = {
50
50
  order?: 'ASC' | 'DESC';
51
51
  } & SearchQuery;
52
52
 
53
- declare class DbConnector {
54
- private static DataSource;
55
- static getDataSource: () => DataSource;
56
- private readonly projectConfig;
57
- constructor(projectConfig: ProjectConfigs);
58
- connect: (entities: MixedList<Function | string | EntitySchema>, migrations?: string[], sync?: boolean, logging?: boolean) => Promise<void>;
59
- }
60
-
61
53
  interface Info {
62
54
  title: string;
63
55
  version: string;
@@ -410,6 +402,7 @@ type SecureTokenConfig = boolean | {
410
402
  };
411
403
  type TokenConstructor = {
412
404
  SECRET_KEY: string;
405
+ TOKEN_COOKIE_NAME?: string;
413
406
  ExpTime: number;
414
407
  EncAlgorithm: string;
415
408
  KeyLength: number;
@@ -503,6 +496,7 @@ declare class SocketWrapper<Metadata extends Record<string, any> = any> {
503
496
 
504
497
  declare class Token<Payload extends Record<string, any> = DefaultTokenPayload> {
505
498
  private SECRET_KEY;
499
+ private TOKEN_COOKIE_NAME;
506
500
  private ExpTime;
507
501
  private EncAlgorithm;
508
502
  private KeyLength;
@@ -534,7 +528,6 @@ type StarterOptions = {
534
528
  entities: MixedList<Function | string | EntitySchema>;
535
529
  migrations?: string[];
536
530
  sync?: boolean;
537
- log?: boolean;
538
531
  afterDbConnection?: () => Promise<void>;
539
532
  };
540
533
  backgroundServices?: Array<BackgroundService>;
@@ -666,4 +659,4 @@ declare const socketNok: (message: string) => SocketConnectionNok;
666
659
  declare const sleep: (ms: number) => Promise<unknown>;
667
660
  declare const getCompiledPath: (__filename: string, __dirname: string, pathsWithoutExtension: string[]) => string[];
668
661
 
669
- export { type ApiKeySecurity, BackgroundService, type BaseFormatContrainedParameter, type BaseOAuthSecurity, type BaseParameter, type BaseSchema, type BaseSecurity, type BasicAuthenticationSecurity, type BodyParameter, type Components, type ConnectedSocketClient, type Contact, DbConnector, type DefaultTokenPayload, type DynamicDbRouterOptions, type DynamicSwaggerOperation, type DynamicSwaggerOperationBody, type DynamicSwaggerPath, type DynamicSwaggerRequestBodyOperation, type ErrorsMapping, type ExpressReturn, type ExternalDocs, type FormDataParameter, type GenericFormat, type Header, type HeaderParameter, type Info, type IntegerFormat, type License, type ListOptions, type MethodPathHandling, type Methods, type NumberFormat, type OAuth2AccessCodeSecurity, type OAuth2ApplicationSecurity, type OAuth2ImplicitSecurity, type OAuth2PasswordSecurity, type OAuthScope, type Operation, type Parameter, type ParameterCollectionFormat, type ParameterType, type Path, type PathParameter, type ProjectConfigs, type QueryParameter, type Reference, type RequestBodyOperation, type Response, RouterWrapper, type RouterWrapperInterface, type Schema, type SchemaFormatConstraints, type SchemaV3, type SearchQuery, type SecureTokenConfig, type Security, type Server, type SocketConnectionMiddleware, type SocketConnectionNok, type SocketConnectionOk, SocketWrapper, type SocketWrapperConstructor, type Spec, Starter, type StarterOptions, type StringFormat, Swagger, type SwaggerMetadataInterface, type Tag, Token, type TokenApiOptions, type TokenConstructor, type XML, apiNok, apiOk, c, errorCatcher, fullLogNok, fullLogOk, getCompiledPath, i, log, sleep, socketNok, socketOk };
662
+ export { type ApiKeySecurity, BackgroundService, type BaseFormatContrainedParameter, type BaseOAuthSecurity, type BaseParameter, type BaseSchema, type BaseSecurity, type BasicAuthenticationSecurity, type BodyParameter, type Components, type ConnectedSocketClient, type Contact, type DefaultTokenPayload, type DynamicDbRouterOptions, type DynamicSwaggerOperation, type DynamicSwaggerOperationBody, type DynamicSwaggerPath, type DynamicSwaggerRequestBodyOperation, type ErrorsMapping, type ExpressReturn, type ExternalDocs, type FormDataParameter, type GenericFormat, type Header, type HeaderParameter, type Info, type IntegerFormat, type License, type ListOptions, type MethodPathHandling, type Methods, type NumberFormat, type OAuth2AccessCodeSecurity, type OAuth2ApplicationSecurity, type OAuth2ImplicitSecurity, type OAuth2PasswordSecurity, type OAuthScope, type Operation, type Parameter, type ParameterCollectionFormat, type ParameterType, type Path, type PathParameter, type ProjectConfigs, type QueryParameter, type Reference, type RequestBodyOperation, type Response, RouterWrapper, type RouterWrapperInterface, type Schema, type SchemaFormatConstraints, type SchemaV3, type SearchQuery, type SecureTokenConfig, type Security, type Server, type SocketConnectionMiddleware, type SocketConnectionNok, type SocketConnectionOk, SocketWrapper, type SocketWrapperConstructor, type Spec, Starter, type StarterOptions, type StringFormat, Swagger, type SwaggerMetadataInterface, type Tag, Token, type TokenApiOptions, type TokenConstructor, type XML, apiNok, apiOk, c, errorCatcher, fullLogNok, fullLogOk, getCompiledPath, i, log, sleep, socketNok, socketOk };
package/dist/index.js CHANGED
@@ -58,12 +58,18 @@ var BackgroundService = class {
58
58
  }
59
59
  };
60
60
 
61
+ // src/RouterWrapper.ts
62
+ var _express = require('express'); var _express2 = _interopRequireDefault(_express);
63
+
64
+ // src/DynamicDbRouter.ts
65
+ var _typeorm = require('typeorm');
66
+
61
67
  // src/DbConnector.ts
62
68
  require('reflect-metadata');
63
- var _typeorm = require('typeorm');
69
+
64
70
  var _DbConnector = class _DbConnector {
65
71
  constructor(projectConfig) {
66
- this.connect = async (entities, migrations, sync, logging = false) => {
72
+ this.connect = async (entities, migrations, sync) => {
67
73
  try {
68
74
  if (!this.projectConfig.DB_DIALECT || !this.projectConfig.DB_NAME) throw new Error("[DB-CONNECTOR] Missing configs => DB_DIALECT || DB_NAME");
69
75
  const AppDataSource = new (0, _typeorm.DataSource)({
@@ -75,7 +81,7 @@ var _DbConnector = class _DbConnector {
75
81
  database: this.projectConfig.DB_NAME,
76
82
  entities,
77
83
  synchronize: _nullishCoalesce(sync, () => ( false)),
78
- logging,
84
+ logging: false,
79
85
  migrations
80
86
  });
81
87
  await AppDataSource.initialize();
@@ -107,12 +113,6 @@ var _DbConnector = class _DbConnector {
107
113
  _DbConnector.getDataSource = () => _DbConnector.DataSource;
108
114
  var DbConnector = _DbConnector;
109
115
 
110
- // src/RouterWrapper.ts
111
- var _express = require('express'); var _express2 = _interopRequireDefault(_express);
112
-
113
- // src/DynamicDbRouter.ts
114
-
115
-
116
116
  // src/Swagger.ts
117
117
  var _Swagger = class _Swagger {
118
118
  };
@@ -627,8 +627,8 @@ var RouterWrapper = class {
627
627
  constructor(data) {
628
628
  this.createExpressRouter = () => {
629
629
  const newRouter = _express.Router.call(void 0, );
630
- const avoidOptionsForDefinedApis = [];
631
630
  if (this.data.dbRouting) {
631
+ const avoidOptionsForDefinedApis = [];
632
632
  if (_optionalChain([this, 'access', _17 => _17.data, 'access', _18 => _18.apis, 'optionalAccess', _19 => _19["/"], 'optionalAccess', _20 => _20.GET])) avoidOptionsForDefinedApis.push("LIST");
633
633
  if (_optionalChain([this, 'access', _21 => _21.data, 'access', _22 => _22.apis, 'optionalAccess', _23 => _23["/:id"], 'optionalAccess', _24 => _24.GET])) avoidOptionsForDefinedApis.push("GET");
634
634
  if (_optionalChain([this, 'access', _25 => _25.data, 'access', _26 => _26.apis, 'optionalAccess', _27 => _27["/"], 'optionalAccess', _28 => _28.POST])) avoidOptionsForDefinedApis.push("POST");
@@ -637,6 +637,19 @@ var RouterWrapper = class {
637
637
  for (const avoid of _nullishCoalesce(this.data.dbRouting.avoid, () => ( []))) {
638
638
  if (!avoidOptionsForDefinedApis.includes(avoid)) avoidOptionsForDefinedApis.push(avoid);
639
639
  }
640
+ const { entity, bodyParameters, getParameters, primaryKey, secure, returningProps } = this.data.dbRouting;
641
+ DynamicDbRouter.createDbRouter({
642
+ entity,
643
+ bodyParameters,
644
+ getParameters,
645
+ primaryKey,
646
+ router: newRouter,
647
+ basePath: this.data.basePath,
648
+ tag: this.data.tag,
649
+ avoid: avoidOptionsForDefinedApis,
650
+ secure,
651
+ returningProps
652
+ });
640
653
  }
641
654
  if (this.data.swaggerNewSchemas) {
642
655
  for (const schema in this.data.swaggerNewSchemas) Swagger.addSchema(schema, this.data.swaggerNewSchemas[schema].properties);
@@ -677,19 +690,7 @@ var RouterWrapper = class {
677
690
  }
678
691
  }
679
692
  if (this.data.dbRouting) {
680
- const { entity, bodyParameters, getParameters, primaryKey, secure, returningProps } = this.data.dbRouting;
681
- DynamicDbRouter.createDbRouter({
682
- entity,
683
- bodyParameters,
684
- getParameters,
685
- primaryKey,
686
- router: newRouter,
687
- basePath: this.data.basePath,
688
- tag: this.data.tag,
689
- avoid: avoidOptionsForDefinedApis,
690
- secure,
691
- returningProps
692
- });
693
+ const { entity, bodyParameters, getParameters, primaryKey } = this.data.dbRouting;
693
694
  DynamicDbRouter.addDbRouterSwagger({
694
695
  entity,
695
696
  bodyParameters,
@@ -818,7 +819,7 @@ var Starter = class {
818
819
  this.init = async (options) => {
819
820
  const app = _express2.default.call(void 0, );
820
821
  if (options.db) {
821
- await this.initDb(options.projectConfig, options.db.entities, options.db.migrations, options.db.sync, options.db.log);
822
+ await this.initDb(options.projectConfig, options.db.entities, options.db.migrations, options.db.sync);
822
823
  if (options.db.afterDbConnection) await options.db.afterDbConnection();
823
824
  }
824
825
  for (const plugin of _nullishCoalesce(options.plugins, () => ( []))) app.use(plugin);
@@ -859,9 +860,9 @@ var Starter = class {
859
860
  server.listen(options.projectConfig.SERVER_PORT, () => log.base("Server started.", `Listening on port ${options.projectConfig.SERVER_PORT}`));
860
861
  }
861
862
  };
862
- this.initDb = async (projectConfig, entities, migrations, sync, logging) => {
863
+ this.initDb = async (projectConfig, entities, migrations, sync) => {
863
864
  const connector = new DbConnector(projectConfig);
864
- await connector.connect(entities, migrations, sync, logging);
865
+ await connector.connect(entities, migrations, sync);
865
866
  };
866
867
  try {
867
868
  log.setFilePath(options.projectConfig.ERROR_FILE_PATH);
@@ -873,6 +874,7 @@ var Starter = class {
873
874
  };
874
875
 
875
876
  // src/Token.ts
877
+ var _cookie = require('cookie');
876
878
  var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
877
879
  var _nodejose = require('node-jose'); var _nodejose2 = _interopRequireDefault(_nodejose);
878
880
  var Token = class {
@@ -881,16 +883,25 @@ var Token = class {
881
883
  // Metodo per autorizzare una richiesta
882
884
  this.authorize = async (req) => {
883
885
  if (typeof req === "string") {
884
- const payload2 = await this.verifyJWE(req);
885
- return payload2;
886
+ const payload = await this.verifyJWE(req);
887
+ return payload;
888
+ } else if (this.TOKEN_COOKIE_NAME) {
889
+ const rawCookies = _nullishCoalesce(req.headers.cookie, () => ( ""));
890
+ const cookies = _cookie.parse.call(void 0, rawCookies);
891
+ const cookieToken = _nullishCoalesce(cookies[this.TOKEN_COOKIE_NAME], () => ( null));
892
+ if (cookieToken === null) throw new Error("UNAUTH");
893
+ const payload = await this.verifyJWE(cookieToken);
894
+ return payload;
895
+ } else {
896
+ const token = _nullishCoalesce(_optionalChain([req, 'access', _56 => _56.headers, 'access', _57 => _57.authorization, 'optionalAccess', _58 => _58.split, 'call', _59 => _59("Bearer "), 'optionalAccess', _60 => _60[1]]), () => ( null));
897
+ if (token === null) throw new Error("UNAUTH");
898
+ const payload = await this.verifyJWE(token);
899
+ return payload;
886
900
  }
887
- const token = _nullishCoalesce(_optionalChain([req, 'access', _56 => _56.headers, 'access', _57 => _57.authorization, 'optionalAccess', _58 => _58.split, 'call', _59 => _59("Bearer "), 'optionalAccess', _60 => _60[1]]), () => ( null));
888
- if (token === null) throw new Error("UNAUTH");
889
- const payload = await this.verifyJWE(token);
890
- return payload;
891
901
  };
892
902
  if (!tokenPayload.SECRET_KEY) throw new Error("SECRET_KEY is required if you want to use the Token Class");
893
903
  this.SECRET_KEY = tokenPayload.SECRET_KEY;
904
+ this.TOKEN_COOKIE_NAME = tokenPayload.TOKEN_COOKIE_NAME;
894
905
  this.ExpTime = tokenPayload.ExpTime;
895
906
  this.EncAlgorithm = tokenPayload.EncAlgorithm;
896
907
  this.KeyLength = tokenPayload.KeyLength;
@@ -961,5 +972,4 @@ var Token = class {
961
972
 
962
973
 
963
974
 
964
-
965
- exports.BackgroundService = BackgroundService; exports.DbConnector = DbConnector; exports.RouterWrapper = RouterWrapper; exports.SocketWrapper = SocketWrapper; exports.Starter = Starter; exports.Swagger = Swagger; exports.Token = Token; exports.apiNok = apiNok; exports.apiOk = apiOk; exports.c = c; exports.errorCatcher = errorCatcher; exports.fullLogNok = fullLogNok; exports.fullLogOk = fullLogOk; exports.getCompiledPath = getCompiledPath; exports.i = i; exports.log = log; exports.sleep = sleep; exports.socketNok = socketNok; exports.socketOk = socketOk;
975
+ exports.BackgroundService = BackgroundService; exports.RouterWrapper = RouterWrapper; exports.SocketWrapper = SocketWrapper; exports.Starter = Starter; exports.Swagger = Swagger; exports.Token = Token; exports.apiNok = apiNok; exports.apiOk = apiOk; exports.c = c; exports.errorCatcher = errorCatcher; exports.fullLogNok = fullLogNok; exports.fullLogOk = fullLogOk; exports.getCompiledPath = getCompiledPath; exports.i = i; exports.log = log; exports.sleep = sleep; exports.socketNok = socketNok; exports.socketOk = socketOk;
package/dist/index.mjs CHANGED
@@ -58,12 +58,18 @@ var BackgroundService = class {
58
58
  }
59
59
  };
60
60
 
61
+ // src/RouterWrapper.ts
62
+ import { Router } from "express";
63
+
64
+ // src/DynamicDbRouter.ts
65
+ import { EntityMetadataNotFoundError, Equal, Like } from "typeorm";
66
+
61
67
  // src/DbConnector.ts
62
68
  import "reflect-metadata";
63
69
  import { DataSource } from "typeorm";
64
70
  var _DbConnector = class _DbConnector {
65
71
  constructor(projectConfig) {
66
- this.connect = async (entities, migrations, sync, logging = false) => {
72
+ this.connect = async (entities, migrations, sync) => {
67
73
  try {
68
74
  if (!this.projectConfig.DB_DIALECT || !this.projectConfig.DB_NAME) throw new Error("[DB-CONNECTOR] Missing configs => DB_DIALECT || DB_NAME");
69
75
  const AppDataSource = new DataSource({
@@ -75,7 +81,7 @@ var _DbConnector = class _DbConnector {
75
81
  database: this.projectConfig.DB_NAME,
76
82
  entities,
77
83
  synchronize: sync ?? false,
78
- logging,
84
+ logging: false,
79
85
  migrations
80
86
  });
81
87
  await AppDataSource.initialize();
@@ -107,12 +113,6 @@ var _DbConnector = class _DbConnector {
107
113
  _DbConnector.getDataSource = () => _DbConnector.DataSource;
108
114
  var DbConnector = _DbConnector;
109
115
 
110
- // src/RouterWrapper.ts
111
- import { Router } from "express";
112
-
113
- // src/DynamicDbRouter.ts
114
- import { EntityMetadataNotFoundError, Equal, Like } from "typeorm";
115
-
116
116
  // src/Swagger.ts
117
117
  var _Swagger = class _Swagger {
118
118
  };
@@ -627,8 +627,8 @@ var RouterWrapper = class {
627
627
  constructor(data) {
628
628
  this.createExpressRouter = () => {
629
629
  const newRouter = Router();
630
- const avoidOptionsForDefinedApis = [];
631
630
  if (this.data.dbRouting) {
631
+ const avoidOptionsForDefinedApis = [];
632
632
  if (this.data.apis?.["/"]?.GET) avoidOptionsForDefinedApis.push("LIST");
633
633
  if (this.data.apis?.["/:id"]?.GET) avoidOptionsForDefinedApis.push("GET");
634
634
  if (this.data.apis?.["/"]?.POST) avoidOptionsForDefinedApis.push("POST");
@@ -637,6 +637,19 @@ var RouterWrapper = class {
637
637
  for (const avoid of this.data.dbRouting.avoid ?? []) {
638
638
  if (!avoidOptionsForDefinedApis.includes(avoid)) avoidOptionsForDefinedApis.push(avoid);
639
639
  }
640
+ const { entity, bodyParameters, getParameters, primaryKey, secure, returningProps } = this.data.dbRouting;
641
+ DynamicDbRouter.createDbRouter({
642
+ entity,
643
+ bodyParameters,
644
+ getParameters,
645
+ primaryKey,
646
+ router: newRouter,
647
+ basePath: this.data.basePath,
648
+ tag: this.data.tag,
649
+ avoid: avoidOptionsForDefinedApis,
650
+ secure,
651
+ returningProps
652
+ });
640
653
  }
641
654
  if (this.data.swaggerNewSchemas) {
642
655
  for (const schema in this.data.swaggerNewSchemas) Swagger.addSchema(schema, this.data.swaggerNewSchemas[schema].properties);
@@ -677,19 +690,7 @@ var RouterWrapper = class {
677
690
  }
678
691
  }
679
692
  if (this.data.dbRouting) {
680
- const { entity, bodyParameters, getParameters, primaryKey, secure, returningProps } = this.data.dbRouting;
681
- DynamicDbRouter.createDbRouter({
682
- entity,
683
- bodyParameters,
684
- getParameters,
685
- primaryKey,
686
- router: newRouter,
687
- basePath: this.data.basePath,
688
- tag: this.data.tag,
689
- avoid: avoidOptionsForDefinedApis,
690
- secure,
691
- returningProps
692
- });
693
+ const { entity, bodyParameters, getParameters, primaryKey } = this.data.dbRouting;
693
694
  DynamicDbRouter.addDbRouterSwagger({
694
695
  entity,
695
696
  bodyParameters,
@@ -818,7 +819,7 @@ var Starter = class {
818
819
  this.init = async (options) => {
819
820
  const app = express();
820
821
  if (options.db) {
821
- await this.initDb(options.projectConfig, options.db.entities, options.db.migrations, options.db.sync, options.db.log);
822
+ await this.initDb(options.projectConfig, options.db.entities, options.db.migrations, options.db.sync);
822
823
  if (options.db.afterDbConnection) await options.db.afterDbConnection();
823
824
  }
824
825
  for (const plugin of options.plugins ?? []) app.use(plugin);
@@ -859,9 +860,9 @@ var Starter = class {
859
860
  server.listen(options.projectConfig.SERVER_PORT, () => log.base("Server started.", `Listening on port ${options.projectConfig.SERVER_PORT}`));
860
861
  }
861
862
  };
862
- this.initDb = async (projectConfig, entities, migrations, sync, logging) => {
863
+ this.initDb = async (projectConfig, entities, migrations, sync) => {
863
864
  const connector = new DbConnector(projectConfig);
864
- await connector.connect(entities, migrations, sync, logging);
865
+ await connector.connect(entities, migrations, sync);
865
866
  };
866
867
  try {
867
868
  log.setFilePath(options.projectConfig.ERROR_FILE_PATH);
@@ -873,6 +874,7 @@ var Starter = class {
873
874
  };
874
875
 
875
876
  // src/Token.ts
877
+ import { parse } from "cookie";
876
878
  import crypto from "crypto";
877
879
  import jose from "node-jose";
878
880
  var Token = class {
@@ -881,16 +883,25 @@ var Token = class {
881
883
  // Metodo per autorizzare una richiesta
882
884
  this.authorize = async (req) => {
883
885
  if (typeof req === "string") {
884
- const payload2 = await this.verifyJWE(req);
885
- return payload2;
886
+ const payload = await this.verifyJWE(req);
887
+ return payload;
888
+ } else if (this.TOKEN_COOKIE_NAME) {
889
+ const rawCookies = req.headers.cookie ?? "";
890
+ const cookies = parse(rawCookies);
891
+ const cookieToken = cookies[this.TOKEN_COOKIE_NAME] ?? null;
892
+ if (cookieToken === null) throw new Error("UNAUTH");
893
+ const payload = await this.verifyJWE(cookieToken);
894
+ return payload;
895
+ } else {
896
+ const token = req.headers.authorization?.split("Bearer ")?.[1] ?? null;
897
+ if (token === null) throw new Error("UNAUTH");
898
+ const payload = await this.verifyJWE(token);
899
+ return payload;
886
900
  }
887
- const token = req.headers.authorization?.split("Bearer ")?.[1] ?? null;
888
- if (token === null) throw new Error("UNAUTH");
889
- const payload = await this.verifyJWE(token);
890
- return payload;
891
901
  };
892
902
  if (!tokenPayload.SECRET_KEY) throw new Error("SECRET_KEY is required if you want to use the Token Class");
893
903
  this.SECRET_KEY = tokenPayload.SECRET_KEY;
904
+ this.TOKEN_COOKIE_NAME = tokenPayload.TOKEN_COOKIE_NAME;
894
905
  this.ExpTime = tokenPayload.ExpTime;
895
906
  this.EncAlgorithm = tokenPayload.EncAlgorithm;
896
907
  this.KeyLength = tokenPayload.KeyLength;
@@ -944,7 +955,6 @@ var Token = class {
944
955
  };
945
956
  export {
946
957
  BackgroundService,
947
- DbConnector,
948
958
  RouterWrapper,
949
959
  SocketWrapper,
950
960
  Starter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expresso-macchiato",
3
- "version": "0.4.11",
3
+ "version": "1.0.0-dev.1",
4
4
  "author": "Alessio Velluso",
5
5
  "license": "MIT",
6
6
  "description": "Description",
@@ -16,8 +16,8 @@
16
16
  "@types/swagger-ui-express": "^4.1.8",
17
17
  "@types/validator": "^13.12.2",
18
18
  "@types/winston": "^2.4.4",
19
- "@typescript-eslint/eslint-plugin": "^6.18.1",
20
- "@typescript-eslint/parser": "^6.18.1",
19
+ "@typescript-eslint/eslint-plugin": "^8.56.1",
20
+ "@typescript-eslint/parser": "^8.56.1",
21
21
  "eslint": "^8.56.0",
22
22
  "express-winston": "^4.2.0",
23
23
  "nodemon": "^3.0.2",
@@ -27,8 +27,9 @@
27
27
  "winston": "^3.11.0"
28
28
  },
29
29
  "dependencies": {
30
- "bcrypt": "^5.1.1",
30
+ "bcrypt": "^6.0.0",
31
31
  "body-parser": "^1.20.2",
32
+ "cookie": "^1.1.1",
32
33
  "cors": "^2.8.5",
33
34
  "dotenv": "^16.3.1",
34
35
  "express": "^4.18.2",
@@ -43,7 +44,7 @@
43
44
  "utils-stuff": "^4.5.0"
44
45
  },
45
46
  "peerDependencies": {
46
- "typeorm": "^0.3.21"
47
+ "typeorm": "^0.3.28"
47
48
  },
48
49
  "repository": {
49
50
  "url": ""
@@ -28,7 +28,6 @@ export type StarterOptions = {
28
28
  entities:MixedList<Function | string |EntitySchema>,
29
29
  migrations?:string[],
30
30
  sync?:boolean,
31
- log?:boolean,
32
31
  afterDbConnection?:() => Promise<void>
33
32
  },
34
33
  backgroundServices?:Array<BackgroundService>
@@ -12,6 +12,7 @@ export type SecureTokenConfig = boolean | { [columnName:string]:{
12
12
  export type TokenConstructor =
13
13
  {
14
14
  SECRET_KEY:string,
15
+ TOKEN_COOKIE_NAME?:string,
15
16
  ExpTime:number,
16
17
  EncAlgorithm:string // https://github.com/panva/jose/issues/210#jwe-alg
17
18
  KeyLength:number