@hemia/common 0.0.14 → 0.0.16

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.
@@ -21,6 +21,16 @@ const METADATA_KEYS = {
21
21
  MODULE: "hemia:module",
22
22
  INJECTION_ID: "hemia:injection_id",
23
23
  MANUAL_REGISTER: 'hemia:controller:manual_register',
24
+ IS_PUBLIC: 'isPublic',
25
+ ALLOW_ANY: 'allowAny',
26
+ OWNER_PARAM: 'ownerParam',
27
+ RATE_LIMIT: 'rateLimit',
28
+ SCOPES: 'scopes',
29
+ THROTTLE: 'hemia:throttle',
30
+ API_KEY: 'hemia:apiKey',
31
+ IP_WHITELIST: 'hemia:ipWhitelist',
32
+ POLICIES: 'hemia:policies',
33
+ FEATURE_FLAGS: 'hemia:featureFlags'
24
34
  };
25
35
 
26
36
  var HttpMethod;
@@ -456,6 +466,61 @@ class GatewayTimeoutError extends HttpError {
456
466
  super(message, 504, error);
457
467
  }
458
468
  }
469
+ class TooManyRequestsError extends HttpError {
470
+ constructor(message = 'Too Many Requests', error) {
471
+ super(message, 429, error);
472
+ }
473
+ }
474
+ class MethodNotAllowedError extends HttpError {
475
+ constructor(message = 'Method Not Allowed', error) {
476
+ super(message, 405, error);
477
+ }
478
+ }
479
+ class NotAcceptableError extends HttpError {
480
+ constructor(message = 'Not Acceptable', error) {
481
+ super(message, 406, error);
482
+ }
483
+ }
484
+ class ProxyAuthenticationRequiredError extends HttpError {
485
+ constructor(message = 'Proxy Authentication Required', error) {
486
+ super(message, 407, error);
487
+ }
488
+ }
489
+ class RequestTimeoutError extends HttpError {
490
+ constructor(message = 'Request Timeout', error) {
491
+ super(message, 408, error);
492
+ }
493
+ }
494
+ class UnsupportedMediaTypeError extends HttpError {
495
+ constructor(message = 'Unsupported Media Type', error) {
496
+ super(message, 415, error);
497
+ }
498
+ }
499
+ class PreconditionFailedError extends HttpError {
500
+ constructor(message = 'Precondition Failed', error) {
501
+ super(message, 412, error);
502
+ }
503
+ }
504
+ class PayloadTooLargeError extends HttpError {
505
+ constructor(message = 'Payload Too Large', error) {
506
+ super(message, 413, error);
507
+ }
508
+ }
509
+ class URITooLongError extends HttpError {
510
+ constructor(message = 'URI Too Long', error) {
511
+ super(message, 414, error);
512
+ }
513
+ }
514
+ class NotImplementedError extends HttpError {
515
+ constructor(message = 'Not Implemented', error) {
516
+ super(message, 501, error);
517
+ }
518
+ }
519
+ class BadGatewayError extends HttpError {
520
+ constructor(message = 'Bad Gateway', error) {
521
+ super(message, 502, error);
522
+ }
523
+ }
459
524
  class CustomHttpError extends HttpError {
460
525
  constructor(message, statusCode, error) {
461
526
  super(message, statusCode, error);
@@ -919,6 +984,105 @@ class ParseDatePipe {
919
984
  }
920
985
  }
921
986
 
987
+ /**
988
+ * Define los roles requeridos para acceder a un recurso.
989
+ * @param roles Lista de roles (ej: 'admin', 'user')
990
+ */
991
+ const Roles = (...roles) => {
992
+ return SetMetadata(METADATA_KEYS.ROLES, roles);
993
+ };
994
+
995
+ /**
996
+ * Define los permisos específicos requeridos para acceder a un recurso.
997
+ * @param permissions Lista de permisos (ej: 'read:users', 'write:posts')
998
+ */
999
+ const Permissions = (...permissions) => {
1000
+ return SetMetadata(METADATA_KEYS.PERMISSIONS, permissions);
1001
+ };
1002
+
1003
+ /**
1004
+ * Marca una ruta como pública, sin requerir autenticación.
1005
+ */
1006
+ const Public = () => {
1007
+ return SetMetadata(METADATA_KEYS.IS_PUBLIC, true);
1008
+ };
1009
+
1010
+ /**
1011
+ * Permite el acceso sin restricciones de roles o permisos.
1012
+ * El usuario debe estar autenticado pero no se validan roles/permisos.
1013
+ */
1014
+ const AllowAny = () => {
1015
+ return SetMetadata(METADATA_KEYS.ALLOW_ANY, true);
1016
+ };
1017
+
1018
+ /**
1019
+ * Valida que el usuario autenticado sea el propietario del recurso.
1020
+ * @param paramName Nombre del parámetro que contiene el ID del propietario (default: 'id')
1021
+ */
1022
+ const Owner = (paramName = 'id') => {
1023
+ return SetMetadata(METADATA_KEYS.OWNER_PARAM, paramName);
1024
+ };
1025
+
1026
+ /**
1027
+ * Limita el número de peticiones por ventana de tiempo.
1028
+ * @param options Configuración de rate limiting
1029
+ */
1030
+ const RateLimit = (options) => {
1031
+ return SetMetadata(METADATA_KEYS.RATE_LIMIT, options);
1032
+ };
1033
+
1034
+ /**
1035
+ * Define los scopes OAuth requeridos para acceder a un recurso.
1036
+ * @param scopes Lista de scopes (ej: 'email', 'profile', 'openid')
1037
+ */
1038
+ const Scopes = (...scopes) => {
1039
+ return SetMetadata(METADATA_KEYS.SCOPES, scopes);
1040
+ };
1041
+
1042
+ /**
1043
+ * Requiere una API Key válida para acceder al recurso.
1044
+ * @param options Configuración de la API Key
1045
+ */
1046
+ const ApiKey = (options = {}) => {
1047
+ return SetMetadata(METADATA_KEYS.API_KEY, {
1048
+ headerName: options.headerName || 'X-API-Key',
1049
+ queryParam: options.queryParam || 'apiKey',
1050
+ required: options.required !== false,
1051
+ });
1052
+ };
1053
+
1054
+ /**
1055
+ * Restringe el acceso solo a las IPs especificadas.
1056
+ * @param ips Lista de direcciones IP permitidas
1057
+ */
1058
+ const IpWhitelist = (...ips) => {
1059
+ return SetMetadata(METADATA_KEYS.IP_WHITELIST, ips);
1060
+ };
1061
+
1062
+ /**
1063
+ * Define políticas de autorización complejas.
1064
+ * @param policies Lista de nombres de políticas a evaluar
1065
+ */
1066
+ const PolicyBased = (...policies) => {
1067
+ return SetMetadata(METADATA_KEYS.POLICIES, policies);
1068
+ };
1069
+
1070
+ /**
1071
+ * Requiere que ciertas feature flags estén habilitadas.
1072
+ * @param flags Lista de feature flags requeridas
1073
+ */
1074
+ const FeatureFlag = (...flags) => {
1075
+ return SetMetadata(METADATA_KEYS.FEATURE_FLAGS, flags);
1076
+ };
1077
+
1078
+ /**
1079
+ * Limita el número de peticiones por usuario en un periodo de tiempo.
1080
+ * @param options Configuración de throttling
1081
+ */
1082
+ const Throttle = (options) => {
1083
+ return SetMetadata(METADATA_KEYS.THROTTLE, options);
1084
+ };
1085
+
922
1086
  class ApiResponse {
923
1087
  static success(data, message = 'OK', status = 200) {
924
1088
  return {
@@ -938,4 +1102,4 @@ class ApiResponse {
938
1102
  }
939
1103
  }
940
1104
 
941
- export { ApiResponse, BackupError, BadRequestError, Body, BusinessRuleViolationError, ConfigurationError, ConflictError, ConnectionError, Controller, ControllerRegistry, Cookies, Custom, CustomHttpError, DataConflictError, DataIntegrityError, DataMigrationError, DataNotFoundError, DataValidationError, DefaultValuePipe, Delete, DependencyError, DomainError, DuplicateEntityError, EntityNotFoundError, File, Files, ForbiddenError, GatewayTimeoutError, Get, Head, Header, Headers, Host, HttpError, HttpErrorWithDetails, HttpMethod, IndexingError, InfraAuthenticationError, InfraAuthorizationError, InfraCacheConnectionError, InfraConfigurationError, InfraDataDeserializationError, InfraDataSerializationError, InfraDatabaseConnectionError, InfraExternalServiceError, InfraMessageQueueError, InfraNetworkError, InfraServiceUnavailableError, InfraTimeoutError, InfrastructureError, InternalServerError, Ip, Locale, METADATA_KEYS, ManualRegister, Module, Next, NotFoundError, OperationNotAllowedError, Options, Param, ParamType, ParseArrayPipe, ParseBoolPipe, ParseDatePipe, ParseEnumPipe, ParseFilePipe, ParseFloatPipe, ParseIntPipe, ParseUUIDPipe, Patch, PersistenceError, Post, Put, Query, QueryExecutionError, Redirect, Repository, Req, ReqAuth, ReqContext, ReqPermissions, ReqUser, Request, Res, ResourceLimitError, ResourceLimitExceededError, Response, RestoreError, SchemaMismatchError, Serialize, Service, ServiceUnavailableError, Session, SetMetadata, TimeoutError, TransactionError, Transform, UnauthorizedError, UnprocessableEntityError, UseGuards, UseInterceptors, UsePipes, Validate, ValidationError, ValidationPipe, isRedirectResponse };
1105
+ export { AllowAny, ApiKey, ApiResponse, BackupError, BadGatewayError, BadRequestError, Body, BusinessRuleViolationError, ConfigurationError, ConflictError, ConnectionError, Controller, ControllerRegistry, Cookies, Custom, CustomHttpError, DataConflictError, DataIntegrityError, DataMigrationError, DataNotFoundError, DataValidationError, DefaultValuePipe, Delete, DependencyError, DomainError, DuplicateEntityError, EntityNotFoundError, FeatureFlag, File, Files, ForbiddenError, GatewayTimeoutError, Get, Head, Header, Headers, Host, HttpError, HttpErrorWithDetails, HttpMethod, IndexingError, InfraAuthenticationError, InfraAuthorizationError, InfraCacheConnectionError, InfraConfigurationError, InfraDataDeserializationError, InfraDataSerializationError, InfraDatabaseConnectionError, InfraExternalServiceError, InfraMessageQueueError, InfraNetworkError, InfraServiceUnavailableError, InfraTimeoutError, InfrastructureError, InternalServerError, Ip, IpWhitelist, Locale, METADATA_KEYS, ManualRegister, MethodNotAllowedError, Module, Next, NotAcceptableError, NotFoundError, NotImplementedError, OperationNotAllowedError, Options, Owner, Param, ParamType, ParseArrayPipe, ParseBoolPipe, ParseDatePipe, ParseEnumPipe, ParseFilePipe, ParseFloatPipe, ParseIntPipe, ParseUUIDPipe, Patch, PayloadTooLargeError, Permissions, PersistenceError, PolicyBased, Post, PreconditionFailedError, ProxyAuthenticationRequiredError, Public, Put, Query, QueryExecutionError, RateLimit, Redirect, Repository, Req, ReqAuth, ReqContext, ReqPermissions, ReqUser, Request, RequestTimeoutError, Res, ResourceLimitError, ResourceLimitExceededError, Response, RestoreError, Roles, SchemaMismatchError, Scopes, Serialize, Service, ServiceUnavailableError, Session, SetMetadata, Throttle, TimeoutError, TooManyRequestsError, TransactionError, Transform, URITooLongError, UnauthorizedError, UnprocessableEntityError, UnsupportedMediaTypeError, UseGuards, UseInterceptors, UsePipes, Validate, ValidationError, ValidationPipe, isRedirectResponse };
@@ -23,6 +23,16 @@ const METADATA_KEYS = {
23
23
  MODULE: "hemia:module",
24
24
  INJECTION_ID: "hemia:injection_id",
25
25
  MANUAL_REGISTER: 'hemia:controller:manual_register',
26
+ IS_PUBLIC: 'isPublic',
27
+ ALLOW_ANY: 'allowAny',
28
+ OWNER_PARAM: 'ownerParam',
29
+ RATE_LIMIT: 'rateLimit',
30
+ SCOPES: 'scopes',
31
+ THROTTLE: 'hemia:throttle',
32
+ API_KEY: 'hemia:apiKey',
33
+ IP_WHITELIST: 'hemia:ipWhitelist',
34
+ POLICIES: 'hemia:policies',
35
+ FEATURE_FLAGS: 'hemia:featureFlags'
26
36
  };
27
37
 
28
38
  exports.HttpMethod = void 0;
@@ -458,6 +468,61 @@ class GatewayTimeoutError extends HttpError {
458
468
  super(message, 504, error);
459
469
  }
460
470
  }
471
+ class TooManyRequestsError extends HttpError {
472
+ constructor(message = 'Too Many Requests', error) {
473
+ super(message, 429, error);
474
+ }
475
+ }
476
+ class MethodNotAllowedError extends HttpError {
477
+ constructor(message = 'Method Not Allowed', error) {
478
+ super(message, 405, error);
479
+ }
480
+ }
481
+ class NotAcceptableError extends HttpError {
482
+ constructor(message = 'Not Acceptable', error) {
483
+ super(message, 406, error);
484
+ }
485
+ }
486
+ class ProxyAuthenticationRequiredError extends HttpError {
487
+ constructor(message = 'Proxy Authentication Required', error) {
488
+ super(message, 407, error);
489
+ }
490
+ }
491
+ class RequestTimeoutError extends HttpError {
492
+ constructor(message = 'Request Timeout', error) {
493
+ super(message, 408, error);
494
+ }
495
+ }
496
+ class UnsupportedMediaTypeError extends HttpError {
497
+ constructor(message = 'Unsupported Media Type', error) {
498
+ super(message, 415, error);
499
+ }
500
+ }
501
+ class PreconditionFailedError extends HttpError {
502
+ constructor(message = 'Precondition Failed', error) {
503
+ super(message, 412, error);
504
+ }
505
+ }
506
+ class PayloadTooLargeError extends HttpError {
507
+ constructor(message = 'Payload Too Large', error) {
508
+ super(message, 413, error);
509
+ }
510
+ }
511
+ class URITooLongError extends HttpError {
512
+ constructor(message = 'URI Too Long', error) {
513
+ super(message, 414, error);
514
+ }
515
+ }
516
+ class NotImplementedError extends HttpError {
517
+ constructor(message = 'Not Implemented', error) {
518
+ super(message, 501, error);
519
+ }
520
+ }
521
+ class BadGatewayError extends HttpError {
522
+ constructor(message = 'Bad Gateway', error) {
523
+ super(message, 502, error);
524
+ }
525
+ }
461
526
  class CustomHttpError extends HttpError {
462
527
  constructor(message, statusCode, error) {
463
528
  super(message, statusCode, error);
@@ -921,6 +986,105 @@ class ParseDatePipe {
921
986
  }
922
987
  }
923
988
 
989
+ /**
990
+ * Define los roles requeridos para acceder a un recurso.
991
+ * @param roles Lista de roles (ej: 'admin', 'user')
992
+ */
993
+ const Roles = (...roles) => {
994
+ return SetMetadata(METADATA_KEYS.ROLES, roles);
995
+ };
996
+
997
+ /**
998
+ * Define los permisos específicos requeridos para acceder a un recurso.
999
+ * @param permissions Lista de permisos (ej: 'read:users', 'write:posts')
1000
+ */
1001
+ const Permissions = (...permissions) => {
1002
+ return SetMetadata(METADATA_KEYS.PERMISSIONS, permissions);
1003
+ };
1004
+
1005
+ /**
1006
+ * Marca una ruta como pública, sin requerir autenticación.
1007
+ */
1008
+ const Public = () => {
1009
+ return SetMetadata(METADATA_KEYS.IS_PUBLIC, true);
1010
+ };
1011
+
1012
+ /**
1013
+ * Permite el acceso sin restricciones de roles o permisos.
1014
+ * El usuario debe estar autenticado pero no se validan roles/permisos.
1015
+ */
1016
+ const AllowAny = () => {
1017
+ return SetMetadata(METADATA_KEYS.ALLOW_ANY, true);
1018
+ };
1019
+
1020
+ /**
1021
+ * Valida que el usuario autenticado sea el propietario del recurso.
1022
+ * @param paramName Nombre del parámetro que contiene el ID del propietario (default: 'id')
1023
+ */
1024
+ const Owner = (paramName = 'id') => {
1025
+ return SetMetadata(METADATA_KEYS.OWNER_PARAM, paramName);
1026
+ };
1027
+
1028
+ /**
1029
+ * Limita el número de peticiones por ventana de tiempo.
1030
+ * @param options Configuración de rate limiting
1031
+ */
1032
+ const RateLimit = (options) => {
1033
+ return SetMetadata(METADATA_KEYS.RATE_LIMIT, options);
1034
+ };
1035
+
1036
+ /**
1037
+ * Define los scopes OAuth requeridos para acceder a un recurso.
1038
+ * @param scopes Lista de scopes (ej: 'email', 'profile', 'openid')
1039
+ */
1040
+ const Scopes = (...scopes) => {
1041
+ return SetMetadata(METADATA_KEYS.SCOPES, scopes);
1042
+ };
1043
+
1044
+ /**
1045
+ * Requiere una API Key válida para acceder al recurso.
1046
+ * @param options Configuración de la API Key
1047
+ */
1048
+ const ApiKey = (options = {}) => {
1049
+ return SetMetadata(METADATA_KEYS.API_KEY, {
1050
+ headerName: options.headerName || 'X-API-Key',
1051
+ queryParam: options.queryParam || 'apiKey',
1052
+ required: options.required !== false,
1053
+ });
1054
+ };
1055
+
1056
+ /**
1057
+ * Restringe el acceso solo a las IPs especificadas.
1058
+ * @param ips Lista de direcciones IP permitidas
1059
+ */
1060
+ const IpWhitelist = (...ips) => {
1061
+ return SetMetadata(METADATA_KEYS.IP_WHITELIST, ips);
1062
+ };
1063
+
1064
+ /**
1065
+ * Define políticas de autorización complejas.
1066
+ * @param policies Lista de nombres de políticas a evaluar
1067
+ */
1068
+ const PolicyBased = (...policies) => {
1069
+ return SetMetadata(METADATA_KEYS.POLICIES, policies);
1070
+ };
1071
+
1072
+ /**
1073
+ * Requiere que ciertas feature flags estén habilitadas.
1074
+ * @param flags Lista de feature flags requeridas
1075
+ */
1076
+ const FeatureFlag = (...flags) => {
1077
+ return SetMetadata(METADATA_KEYS.FEATURE_FLAGS, flags);
1078
+ };
1079
+
1080
+ /**
1081
+ * Limita el número de peticiones por usuario en un periodo de tiempo.
1082
+ * @param options Configuración de throttling
1083
+ */
1084
+ const Throttle = (options) => {
1085
+ return SetMetadata(METADATA_KEYS.THROTTLE, options);
1086
+ };
1087
+
924
1088
  class ApiResponse {
925
1089
  static success(data, message = 'OK', status = 200) {
926
1090
  return {
@@ -940,8 +1104,11 @@ class ApiResponse {
940
1104
  }
941
1105
  }
942
1106
 
1107
+ exports.AllowAny = AllowAny;
1108
+ exports.ApiKey = ApiKey;
943
1109
  exports.ApiResponse = ApiResponse;
944
1110
  exports.BackupError = BackupError;
1111
+ exports.BadGatewayError = BadGatewayError;
945
1112
  exports.BadRequestError = BadRequestError;
946
1113
  exports.Body = Body;
947
1114
  exports.BusinessRuleViolationError = BusinessRuleViolationError;
@@ -964,6 +1131,7 @@ exports.DependencyError = DependencyError;
964
1131
  exports.DomainError = DomainError;
965
1132
  exports.DuplicateEntityError = DuplicateEntityError;
966
1133
  exports.EntityNotFoundError = EntityNotFoundError;
1134
+ exports.FeatureFlag = FeatureFlag;
967
1135
  exports.File = File;
968
1136
  exports.Files = Files;
969
1137
  exports.ForbiddenError = ForbiddenError;
@@ -991,14 +1159,19 @@ exports.InfraTimeoutError = InfraTimeoutError;
991
1159
  exports.InfrastructureError = InfrastructureError;
992
1160
  exports.InternalServerError = InternalServerError;
993
1161
  exports.Ip = Ip;
1162
+ exports.IpWhitelist = IpWhitelist;
994
1163
  exports.Locale = Locale;
995
1164
  exports.METADATA_KEYS = METADATA_KEYS;
996
1165
  exports.ManualRegister = ManualRegister;
1166
+ exports.MethodNotAllowedError = MethodNotAllowedError;
997
1167
  exports.Module = Module;
998
1168
  exports.Next = Next;
1169
+ exports.NotAcceptableError = NotAcceptableError;
999
1170
  exports.NotFoundError = NotFoundError;
1171
+ exports.NotImplementedError = NotImplementedError;
1000
1172
  exports.OperationNotAllowedError = OperationNotAllowedError;
1001
1173
  exports.Options = Options;
1174
+ exports.Owner = Owner;
1002
1175
  exports.Param = Param;
1003
1176
  exports.ParseArrayPipe = ParseArrayPipe;
1004
1177
  exports.ParseBoolPipe = ParseBoolPipe;
@@ -1009,11 +1182,18 @@ exports.ParseFloatPipe = ParseFloatPipe;
1009
1182
  exports.ParseIntPipe = ParseIntPipe;
1010
1183
  exports.ParseUUIDPipe = ParseUUIDPipe;
1011
1184
  exports.Patch = Patch;
1185
+ exports.PayloadTooLargeError = PayloadTooLargeError;
1186
+ exports.Permissions = Permissions;
1012
1187
  exports.PersistenceError = PersistenceError;
1188
+ exports.PolicyBased = PolicyBased;
1013
1189
  exports.Post = Post;
1190
+ exports.PreconditionFailedError = PreconditionFailedError;
1191
+ exports.ProxyAuthenticationRequiredError = ProxyAuthenticationRequiredError;
1192
+ exports.Public = Public;
1014
1193
  exports.Put = Put;
1015
1194
  exports.Query = Query;
1016
1195
  exports.QueryExecutionError = QueryExecutionError;
1196
+ exports.RateLimit = RateLimit;
1017
1197
  exports.Redirect = Redirect;
1018
1198
  exports.Repository = Repository;
1019
1199
  exports.Req = Req;
@@ -1022,22 +1202,29 @@ exports.ReqContext = ReqContext;
1022
1202
  exports.ReqPermissions = ReqPermissions;
1023
1203
  exports.ReqUser = ReqUser;
1024
1204
  exports.Request = Request;
1205
+ exports.RequestTimeoutError = RequestTimeoutError;
1025
1206
  exports.Res = Res;
1026
1207
  exports.ResourceLimitError = ResourceLimitError;
1027
1208
  exports.ResourceLimitExceededError = ResourceLimitExceededError;
1028
1209
  exports.Response = Response;
1029
1210
  exports.RestoreError = RestoreError;
1211
+ exports.Roles = Roles;
1030
1212
  exports.SchemaMismatchError = SchemaMismatchError;
1213
+ exports.Scopes = Scopes;
1031
1214
  exports.Serialize = Serialize;
1032
1215
  exports.Service = Service;
1033
1216
  exports.ServiceUnavailableError = ServiceUnavailableError;
1034
1217
  exports.Session = Session;
1035
1218
  exports.SetMetadata = SetMetadata;
1219
+ exports.Throttle = Throttle;
1036
1220
  exports.TimeoutError = TimeoutError;
1221
+ exports.TooManyRequestsError = TooManyRequestsError;
1037
1222
  exports.TransactionError = TransactionError;
1038
1223
  exports.Transform = Transform;
1224
+ exports.URITooLongError = URITooLongError;
1039
1225
  exports.UnauthorizedError = UnauthorizedError;
1040
1226
  exports.UnprocessableEntityError = UnprocessableEntityError;
1227
+ exports.UnsupportedMediaTypeError = UnsupportedMediaTypeError;
1041
1228
  exports.UseGuards = UseGuards;
1042
1229
  exports.UseInterceptors = UseInterceptors;
1043
1230
  exports.UsePipes = UsePipes;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Permite el acceso sin restricciones de roles o permisos.
3
+ * El usuario debe estar autenticado pero no se validan roles/permisos.
4
+ */
5
+ export declare const AllowAny: () => (target: object | Function, key?: string | symbol, descriptor?: PropertyDescriptor) => object;
@@ -0,0 +1,10 @@
1
+ export interface ApiKeyOptions {
2
+ headerName?: string;
3
+ queryParam?: string;
4
+ required?: boolean;
5
+ }
6
+ /**
7
+ * Requiere una API Key válida para acceder al recurso.
8
+ * @param options Configuración de la API Key
9
+ */
10
+ export declare const ApiKey: (options?: ApiKeyOptions) => (target: object | Function, key?: string | symbol, descriptor?: PropertyDescriptor) => object;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Requiere que ciertas feature flags estén habilitadas.
3
+ * @param flags Lista de feature flags requeridas
4
+ */
5
+ export declare const FeatureFlag: (...flags: string[]) => (target: object | Function, key?: string | symbol, descriptor?: PropertyDescriptor) => object;
@@ -1,2 +1,12 @@
1
1
  export * from './roles.decorator';
2
2
  export * from './permissions.decorator';
3
+ export * from './public.decorator';
4
+ export * from './allow-any.decorator';
5
+ export * from './owner.decorator';
6
+ export * from './rate-limit.decorator';
7
+ export * from './scopes.decorator';
8
+ export * from './api-key.decorator';
9
+ export * from './ip-whitelist.decorator';
10
+ export * from './policy-based.decorator';
11
+ export * from './feature-flag.decorator';
12
+ export * from './throttle.decorator';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Restringe el acceso solo a las IPs especificadas.
3
+ * @param ips Lista de direcciones IP permitidas
4
+ */
5
+ export declare const IpWhitelist: (...ips: string[]) => (target: object | Function, key?: string | symbol, descriptor?: PropertyDescriptor) => object;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Valida que el usuario autenticado sea el propietario del recurso.
3
+ * @param paramName Nombre del parámetro que contiene el ID del propietario (default: 'id')
4
+ */
5
+ export declare const Owner: (paramName?: string) => (target: object | Function, key?: string | symbol, descriptor?: PropertyDescriptor) => object;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Define políticas de autorización complejas.
3
+ * @param policies Lista de nombres de políticas a evaluar
4
+ */
5
+ export declare const PolicyBased: (...policies: string[]) => (target: object | Function, key?: string | symbol, descriptor?: PropertyDescriptor) => object;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Marca una ruta como pública, sin requerir autenticación.
3
+ */
4
+ export declare const Public: () => (target: object | Function, key?: string | symbol, descriptor?: PropertyDescriptor) => object;
@@ -0,0 +1,10 @@
1
+ export interface RateLimitOptions {
2
+ maxRequests: number;
3
+ windowMs: number;
4
+ message?: string;
5
+ }
6
+ /**
7
+ * Limita el número de peticiones por ventana de tiempo.
8
+ * @param options Configuración de rate limiting
9
+ */
10
+ export declare const RateLimit: (options: RateLimitOptions) => (target: object | Function, key?: string | symbol, descriptor?: PropertyDescriptor) => object;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Define los scopes OAuth requeridos para acceder a un recurso.
3
+ * @param scopes Lista de scopes (ej: 'email', 'profile', 'openid')
4
+ */
5
+ export declare const Scopes: (...scopes: string[]) => (target: object | Function, key?: string | symbol, descriptor?: PropertyDescriptor) => object;
@@ -0,0 +1,10 @@
1
+ export interface ThrottleOptions {
2
+ limit: number;
3
+ ttl: number;
4
+ skipIf?: (context: any) => boolean;
5
+ }
6
+ /**
7
+ * Limita el número de peticiones por usuario en un periodo de tiempo.
8
+ * @param options Configuración de throttling
9
+ */
10
+ export declare const Throttle: (options: ThrottleOptions) => (target: object | Function, key?: string | symbol, descriptor?: PropertyDescriptor) => object;
@@ -5,3 +5,4 @@ export * from "./custom";
5
5
  export * from "./validation";
6
6
  export * from "./transform";
7
7
  export * from "./pipes";
8
+ export * from "./auth";
@@ -18,4 +18,14 @@ export declare const METADATA_KEYS: {
18
18
  readonly MODULE: "hemia:module";
19
19
  readonly INJECTION_ID: "hemia:injection_id";
20
20
  readonly MANUAL_REGISTER: "hemia:controller:manual_register";
21
+ readonly IS_PUBLIC: "isPublic";
22
+ readonly ALLOW_ANY: "allowAny";
23
+ readonly OWNER_PARAM: "ownerParam";
24
+ readonly RATE_LIMIT: "rateLimit";
25
+ readonly SCOPES: "scopes";
26
+ readonly THROTTLE: "hemia:throttle";
27
+ readonly API_KEY: "hemia:apiKey";
28
+ readonly IP_WHITELIST: "hemia:ipWhitelist";
29
+ readonly POLICIES: "hemia:policies";
30
+ readonly FEATURE_FLAGS: "hemia:featureFlags";
21
31
  };
@@ -31,6 +31,39 @@ export declare class ServiceUnavailableError extends HttpError {
31
31
  export declare class GatewayTimeoutError extends HttpError {
32
32
  constructor(message?: string, error?: string);
33
33
  }
34
+ export declare class TooManyRequestsError extends HttpError {
35
+ constructor(message?: string, error?: string);
36
+ }
37
+ export declare class MethodNotAllowedError extends HttpError {
38
+ constructor(message?: string, error?: string);
39
+ }
40
+ export declare class NotAcceptableError extends HttpError {
41
+ constructor(message?: string, error?: string);
42
+ }
43
+ export declare class ProxyAuthenticationRequiredError extends HttpError {
44
+ constructor(message?: string, error?: string);
45
+ }
46
+ export declare class RequestTimeoutError extends HttpError {
47
+ constructor(message?: string, error?: string);
48
+ }
49
+ export declare class UnsupportedMediaTypeError extends HttpError {
50
+ constructor(message?: string, error?: string);
51
+ }
52
+ export declare class PreconditionFailedError extends HttpError {
53
+ constructor(message?: string, error?: string);
54
+ }
55
+ export declare class PayloadTooLargeError extends HttpError {
56
+ constructor(message?: string, error?: string);
57
+ }
58
+ export declare class URITooLongError extends HttpError {
59
+ constructor(message?: string, error?: string);
60
+ }
61
+ export declare class NotImplementedError extends HttpError {
62
+ constructor(message?: string, error?: string);
63
+ }
64
+ export declare class BadGatewayError extends HttpError {
65
+ constructor(message?: string, error?: string);
66
+ }
34
67
  export declare class CustomHttpError extends HttpError {
35
68
  constructor(message: string, statusCode: number, error?: string);
36
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hemia/common",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "Paquete común para proyectos de Hemia",
5
5
  "main": "dist/hemia-common.js",
6
6
  "module": "dist/hemia-common.esm.js",