@vritti/api-sdk 0.1.6 → 0.1.8

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.cjs CHANGED
@@ -34,17 +34,15 @@ __export(index_exports, {
34
34
  AuthConfigModule: () => AuthConfigModule,
35
35
  BadGatewayException: () => BadGatewayException,
36
36
  BadRequestException: () => BadRequestException,
37
- BaseFieldException: () => BaseFieldException,
38
37
  ConflictException: () => ConflictException,
39
38
  CorrelationIdMiddleware: () => CorrelationIdMiddleware,
40
- CsrfGuard: () => CsrfGuard,
41
39
  DEFAULT_CORRELATION_HEADER: () => DEFAULT_CORRELATION_HEADER,
42
40
  DatabaseModule: () => DatabaseModule,
43
- ForbiddenException: () => ForbiddenException,
41
+ ForbiddenException: () => ForbiddenException2,
44
42
  GoneException: () => GoneException,
45
43
  HttpExceptionFilter: () => HttpExceptionFilter,
46
44
  HttpLoggerInterceptor: () => HttpLoggerInterceptor,
47
- HttpModule: () => HttpModule,
45
+ HttpProblemException: () => HttpProblemException,
48
46
  InternalServerErrorException: () => InternalServerErrorException3,
49
47
  LOGGER_MODULE_OPTIONS: () => LOGGER_MODULE_OPTIONS,
50
48
  LoggerModule: () => LoggerModule,
@@ -59,13 +57,16 @@ __export(index_exports, {
59
57
  PrimaryDatabaseService: () => PrimaryDatabaseService,
60
58
  Public: () => Public,
61
59
  RequestTimeoutException: () => RequestTimeoutException,
60
+ SKIP_CSRF_KEY: () => SKIP_CSRF_KEY,
62
61
  ServiceUnavailableException: () => ServiceUnavailableException,
62
+ SkipCsrf: () => SkipCsrf,
63
+ SseAuthGuard: () => SseAuthGuard,
63
64
  Tenant: () => Tenant,
64
65
  TenantBaseRepository: () => TenantBaseRepository,
65
66
  TenantContextService: () => TenantContextService,
66
67
  TenantDatabaseService: () => TenantDatabaseService,
67
68
  TooManyRequestsException: () => TooManyRequestsException,
68
- UnauthorizedException: () => UnauthorizedException4,
69
+ UnauthorizedException: () => UnauthorizedException5,
69
70
  UnprocessableEntityException: () => UnprocessableEntityException,
70
71
  UnsupportedMediaTypeException: () => UnsupportedMediaTypeException,
71
72
  UserId: () => UserId,
@@ -75,6 +76,7 @@ __export(index_exports, {
75
76
  configureApiSdk: () => configureApiSdk,
76
77
  correlationStorage: () => correlationStorage,
77
78
  defineConfig: () => defineConfig,
79
+ extractCountryFromPhone: () => extractCountryFromPhone,
78
80
  generateCorrelationId: () => generateCorrelationId,
79
81
  getConfig: () => getConfig,
80
82
  getCorrelationContext: () => getCorrelationContext,
@@ -82,6 +84,7 @@ __export(index_exports, {
82
84
  getJwtExpiry: () => getJwtExpiry,
83
85
  getRefreshCookieOptions: () => getRefreshCookieOptions,
84
86
  hashToken: () => hashToken,
87
+ normalizePhoneNumber: () => normalizePhoneNumber,
85
88
  resetConfig: () => resetConfig,
86
89
  runWithCorrelationContext: () => runWithCorrelationContext,
87
90
  updateCorrelationContext: () => updateCorrelationContext,
@@ -90,7 +93,7 @@ __export(index_exports, {
90
93
  module.exports = __toCommonJS(index_exports);
91
94
 
92
95
  // src/auth/auth-config.module.ts
93
- var import_common5 = require("@nestjs/common");
96
+ var import_common6 = require("@nestjs/common");
94
97
  var import_config4 = require("@nestjs/config");
95
98
  var import_core3 = require("@nestjs/core");
96
99
  var import_jwt2 = require("@nestjs/jwt");
@@ -305,13 +308,18 @@ RequestModule = _ts_decorate2([
305
308
  ], RequestModule);
306
309
 
307
310
  // src/auth/guards/vritti-auth.guard.ts
308
- var import_common4 = require("@nestjs/common");
311
+ var import_common5 = require("@nestjs/common");
309
312
  var import_config2 = require("@nestjs/config");
310
313
  var import_core2 = require("@nestjs/core");
311
314
  var import_jwt = require("@nestjs/jwt");
312
315
 
313
- // src/database/services/primary-database.service.ts
316
+ // src/auth/decorators/skip-csrf.decorator.ts
314
317
  var import_common3 = require("@nestjs/common");
318
+ var SKIP_CSRF_KEY = "skipCsrf";
319
+ var SkipCsrf = /* @__PURE__ */ __name(() => (0, import_common3.SetMetadata)(SKIP_CSRF_KEY, true), "SkipCsrf");
320
+
321
+ // src/database/services/primary-database.service.ts
322
+ var import_common4 = require("@nestjs/common");
315
323
  var import_drizzle_orm = require("drizzle-orm");
316
324
  var import_node_postgres = require("drizzle-orm/node-postgres");
317
325
  var import_pg = require("pg");
@@ -342,7 +350,7 @@ var PrimaryDatabaseService = class _PrimaryDatabaseService {
342
350
  __name(this, "PrimaryDatabaseService");
343
351
  }
344
352
  options;
345
- logger = new import_common3.Logger(_PrimaryDatabaseService.name);
353
+ logger = new import_common4.Logger(_PrimaryDatabaseService.name);
346
354
  /** PostgreSQL connection pool */
347
355
  pool = null;
348
356
  /** Drizzle database instance */
@@ -382,7 +390,7 @@ var PrimaryDatabaseService = class _PrimaryDatabaseService {
382
390
  this.logger.log("Connected to primary database (tenant registry)");
383
391
  } catch (error) {
384
392
  this.logger.error("Failed to connect to primary database", error);
385
- throw new import_common3.InternalServerErrorException("Failed to initialize tenant registry");
393
+ throw new import_common4.InternalServerErrorException("Failed to initialize tenant registry");
386
394
  }
387
395
  }
388
396
  /**
@@ -463,7 +471,7 @@ var PrimaryDatabaseService = class _PrimaryDatabaseService {
463
471
  return info;
464
472
  } catch (error) {
465
473
  this.logger.error(`Failed to fetch tenant info: ${tenantIdentifier}`, error);
466
- throw new import_common3.InternalServerErrorException("Failed to resolve tenant");
474
+ throw new import_common4.InternalServerErrorException("Failed to resolve tenant");
467
475
  }
468
476
  }
469
477
  /**
@@ -539,8 +547,8 @@ var PrimaryDatabaseService = class _PrimaryDatabaseService {
539
547
  }
540
548
  };
541
549
  PrimaryDatabaseService = _ts_decorate3([
542
- (0, import_common3.Injectable)(),
543
- _ts_param2(0, (0, import_common3.Inject)(DATABASE_MODULE_OPTIONS)),
550
+ (0, import_common4.Injectable)(),
551
+ _ts_param2(0, (0, import_common4.Inject)(DATABASE_MODULE_OPTIONS)),
544
552
  _ts_metadata2("design:type", Function),
545
553
  _ts_metadata2("design:paramtypes", [
546
554
  typeof DatabaseModuleOptions === "undefined" ? Object : DatabaseModuleOptions
@@ -581,7 +589,7 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
581
589
  jwtService;
582
590
  primaryDatabase;
583
591
  requestService;
584
- logger = new import_common4.Logger(_VrittiAuthGuard.name);
592
+ logger = new import_common5.Logger(_VrittiAuthGuard.name);
585
593
  constructor(reflector, _configService, jwtService, primaryDatabase, requestService) {
586
594
  this.reflector = reflector;
587
595
  this._configService = _configService;
@@ -591,6 +599,14 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
591
599
  }
592
600
  async canActivate(context) {
593
601
  const request = context.switchToHttp().getRequest();
602
+ const reply = context.switchToHttp().getResponse();
603
+ const skipCsrf = this.reflector.getAllAndOverride(SKIP_CSRF_KEY, [
604
+ context.getHandler(),
605
+ context.getClass()
606
+ ]);
607
+ if (!skipCsrf) {
608
+ await this.validateCsrf(request, reply);
609
+ }
594
610
  const isPublic = this.reflector.getAllAndOverride("isPublic", [
595
611
  context.getHandler(),
596
612
  context.getClass()
@@ -607,17 +623,17 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
607
623
  const accessToken = this.requestService.getAccessToken();
608
624
  if (!accessToken) {
609
625
  this.logger.warn("Access token not found in Authorization header");
610
- throw new import_common4.UnauthorizedException("Access token not found");
626
+ throw new import_common5.UnauthorizedException("Access token not found");
611
627
  }
612
628
  const decodedToken = this.jwtService.decode(accessToken);
613
629
  if (!decodedToken) {
614
630
  this.logger.warn("Failed to decode access token");
615
- throw new import_common4.UnauthorizedException("Invalid token format");
631
+ throw new import_common5.UnauthorizedException("Invalid token format");
616
632
  }
617
633
  if (isOnboarding) {
618
634
  if (decodedToken.type !== "onboarding") {
619
635
  this.logger.warn("Onboarding endpoint requires onboarding token");
620
- throw new import_common4.UnauthorizedException("This endpoint requires an onboarding token");
636
+ throw new import_common5.UnauthorizedException("This endpoint requires an onboarding token");
621
637
  }
622
638
  const validatedToken2 = this.validateAccessToken(accessToken);
623
639
  this.logger.debug("Onboarding token validated successfully");
@@ -630,7 +646,7 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
630
646
  }
631
647
  if (decodedToken.type === "onboarding") {
632
648
  this.logger.warn("Regular endpoint accessed with onboarding token");
633
- throw new import_common4.UnauthorizedException("Onboarding tokens cannot access this endpoint");
649
+ throw new import_common5.UnauthorizedException("Onboarding tokens cannot access this endpoint");
634
650
  }
635
651
  const validatedToken = this.validateAccessToken(accessToken);
636
652
  this.logger.debug("Access token validated successfully");
@@ -642,7 +658,7 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
642
658
  const tenantIdentifier = this.requestService.getTenantIdentifier();
643
659
  if (!tenantIdentifier) {
644
660
  this.logger.warn("Tenant identifier not found in request");
645
- throw new import_common4.UnauthorizedException("Tenant identifier not found");
661
+ throw new import_common5.UnauthorizedException("Tenant identifier not found");
646
662
  }
647
663
  this.logger.debug(`Tenant identifier extracted: ${tenantIdentifier}`);
648
664
  if (tenantIdentifier === "cloud") {
@@ -652,20 +668,20 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
652
668
  const tenantInfo = await this.primaryDatabase.getTenantInfo(tenantIdentifier);
653
669
  if (!tenantInfo) {
654
670
  this.logger.warn(`Invalid tenant: ${tenantIdentifier}`);
655
- throw new import_common4.UnauthorizedException("Invalid tenant");
671
+ throw new import_common5.UnauthorizedException("Invalid tenant");
656
672
  }
657
673
  if (tenantInfo.status !== "ACTIVE") {
658
674
  this.logger.warn(`Tenant ${tenantIdentifier} has status: ${tenantInfo.status}`);
659
- throw new import_common4.UnauthorizedException(`Tenant is ${tenantInfo.status}`);
675
+ throw new import_common5.UnauthorizedException(`Tenant is ${tenantInfo.status}`);
660
676
  }
661
677
  this.logger.debug(`Tenant validated: ${tenantInfo.subdomain} (${tenantInfo.type})`);
662
678
  return true;
663
679
  } catch (error) {
664
- if (error instanceof import_common4.UnauthorizedException) {
680
+ if (error instanceof import_common5.UnauthorizedException) {
665
681
  throw error;
666
682
  }
667
683
  this.logger.error("Unexpected error in auth guard", error);
668
- throw new import_common4.UnauthorizedException("Authentication failed");
684
+ throw new import_common5.UnauthorizedException("Authentication failed");
669
685
  }
670
686
  }
671
687
  /**
@@ -684,24 +700,24 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
684
700
  }
685
701
  return decoded;
686
702
  } catch (error) {
687
- if (error instanceof import_common4.UnauthorizedException) {
703
+ if (error instanceof import_common5.UnauthorizedException) {
688
704
  throw error;
689
705
  }
690
706
  const jwtError = error;
691
707
  if (jwtError?.name === "TokenExpiredError") {
692
708
  this.logger.warn(`Access token expired at: ${jwtError?.expiredAt}`);
693
- throw new import_common4.UnauthorizedException("Access token has expired");
709
+ throw new import_common5.UnauthorizedException("Access token has expired");
694
710
  }
695
711
  if (jwtError?.name === "JsonWebTokenError") {
696
712
  this.logger.warn(`Access token verification failed: ${jwtError?.message}`);
697
- throw new import_common4.UnauthorizedException("Invalid access token");
713
+ throw new import_common5.UnauthorizedException("Invalid access token");
698
714
  }
699
715
  if (jwtError?.name === "NotBeforeError") {
700
716
  this.logger.warn("Access token used before valid (nbf claim)");
701
- throw new import_common4.UnauthorizedException("Access token not yet valid");
717
+ throw new import_common5.UnauthorizedException("Access token not yet valid");
702
718
  }
703
719
  this.logger.error("Unexpected error validating access token", error);
704
- throw new import_common4.UnauthorizedException("Access token validation failed");
720
+ throw new import_common5.UnauthorizedException("Access token validation failed");
705
721
  }
706
722
  }
707
723
  /**
@@ -728,18 +744,64 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
728
744
  const refreshToken = cookies[config.cookie.refreshCookieName];
729
745
  if (!refreshToken) {
730
746
  this.logger.warn("Session validation failed - refresh token cookie not found");
731
- throw new import_common4.UnauthorizedException("Session validation failed");
747
+ throw new import_common5.UnauthorizedException("Session validation failed");
732
748
  }
733
749
  if (!verifyTokenHash(refreshToken, validatedToken.refreshTokenHash)) {
734
750
  this.logger.warn("Session validation failed - token binding mismatch");
735
- throw new import_common4.UnauthorizedException("Session validation failed");
751
+ throw new import_common5.UnauthorizedException("Session validation failed");
736
752
  }
737
753
  this.logger.debug("Token binding validated successfully");
738
754
  }
755
+ /**
756
+ * Validate CSRF token for state-changing requests
757
+ * Uses Fastify's csrf-protection plugin for token validation
758
+ *
759
+ * @param request - Fastify request object
760
+ * @param reply - Fastify reply object
761
+ * @throws ForbiddenException if CSRF validation fails
762
+ */
763
+ async validateCsrf(request, reply) {
764
+ const safeMethods = [
765
+ "GET",
766
+ "HEAD",
767
+ "OPTIONS"
768
+ ];
769
+ if (safeMethods.includes(request.method)) {
770
+ return;
771
+ }
772
+ try {
773
+ const fastifyInstance = request.server;
774
+ if (!fastifyInstance.csrfProtection) {
775
+ this.logger.error("CSRF protection plugin not found. Ensure @fastify/csrf-protection is registered.");
776
+ throw new import_common5.ForbiddenException("CSRF protection not configured");
777
+ }
778
+ await new Promise((resolve, reject) => {
779
+ fastifyInstance.csrfProtection(request, reply, (err) => {
780
+ if (err) {
781
+ reject(err);
782
+ } else {
783
+ resolve();
784
+ }
785
+ });
786
+ });
787
+ this.logger.debug(`CSRF validation successful for ${request.method} ${request.url}`);
788
+ } catch (error) {
789
+ this.logger.warn(`CSRF validation failed for ${request.method} ${request.url}: ${error instanceof Error ? error.message : "Unknown error"}`);
790
+ throw new import_common5.ForbiddenException({
791
+ errors: [
792
+ {
793
+ field: "csrf",
794
+ message: "Invalid or missing CSRF token"
795
+ }
796
+ ],
797
+ message: "CSRF validation failed"
798
+ });
799
+ }
800
+ }
739
801
  };
740
802
  VrittiAuthGuard = _ts_decorate4([
741
- (0, import_common4.Injectable)({
742
- scope: import_common4.Scope.REQUEST
803
+ (0, import_common5.Injectable)({
804
+ scope: import_common5.Scope.REQUEST
743
805
  }),
744
806
  _ts_metadata3("design:type", Function),
745
807
  _ts_metadata3("design:paramtypes", [
@@ -795,6 +857,11 @@ var AuthConfigModule = class _AuthConfigModule {
795
857
  })
796
858
  ],
797
859
  providers: [
860
+ // Required for external packages - NestJS global Reflector not available
861
+ {
862
+ provide: import_core3.Reflector,
863
+ useClass: import_core3.Reflector
864
+ },
798
865
  {
799
866
  provide: import_core3.APP_GUARD,
800
867
  useClass: VrittiAuthGuard
@@ -807,21 +874,21 @@ var AuthConfigModule = class _AuthConfigModule {
807
874
  }
808
875
  };
809
876
  AuthConfigModule = _ts_decorate5([
810
- (0, import_common5.Global)(),
811
- (0, import_common5.Module)({})
877
+ (0, import_common6.Global)(),
878
+ (0, import_common6.Module)({})
812
879
  ], AuthConfigModule);
813
880
 
814
881
  // src/auth/decorators/onboarding.decorator.ts
815
- var import_common6 = require("@nestjs/common");
816
- var Onboarding = /* @__PURE__ */ __name(() => (0, import_common6.SetMetadata)("isOnboarding", true), "Onboarding");
882
+ var import_common7 = require("@nestjs/common");
883
+ var Onboarding = /* @__PURE__ */ __name(() => (0, import_common7.SetMetadata)("isOnboarding", true), "Onboarding");
817
884
 
818
885
  // src/auth/decorators/public.decorator.ts
819
- var import_common7 = require("@nestjs/common");
820
- var Public = /* @__PURE__ */ __name(() => (0, import_common7.SetMetadata)("isPublic", true), "Public");
886
+ var import_common8 = require("@nestjs/common");
887
+ var Public = /* @__PURE__ */ __name(() => (0, import_common8.SetMetadata)("isPublic", true), "Public");
821
888
 
822
889
  // src/auth/decorators/user-id.decorator.ts
823
- var import_common8 = require("@nestjs/common");
824
- var UserId = (0, import_common8.createParamDecorator)((_data, ctx) => {
890
+ var import_common9 = require("@nestjs/common");
891
+ var UserId = (0, import_common9.createParamDecorator)((_data, ctx) => {
825
892
  const request = ctx.switchToHttp().getRequest();
826
893
  const user = request.user;
827
894
  if (!user?.id) {
@@ -830,23 +897,123 @@ var UserId = (0, import_common8.createParamDecorator)((_data, ctx) => {
830
897
  return user.id;
831
898
  });
832
899
 
900
+ // src/auth/guards/sse-auth.guard.ts
901
+ var import_common10 = require("@nestjs/common");
902
+ var import_jwt3 = require("@nestjs/jwt");
903
+ function _ts_decorate6(decorators, target, key, desc) {
904
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
905
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
906
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
907
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
908
+ }
909
+ __name(_ts_decorate6, "_ts_decorate");
910
+ function _ts_metadata4(k, v) {
911
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
912
+ }
913
+ __name(_ts_metadata4, "_ts_metadata");
914
+ var SSE_ALLOWED_ORIGINS = [
915
+ "http://localhost:5173",
916
+ "http://localhost:3001",
917
+ "http://localhost:3012",
918
+ "http://localhost:5174",
919
+ "http://local.vrittiai.com:3012",
920
+ "http://cloud.local.vrittiai.com:3012",
921
+ "https://local.vrittiai.com:3012",
922
+ "https://cloud.local.vrittiai.com:3012"
923
+ ];
924
+ var SseAuthGuard = class _SseAuthGuard {
925
+ static {
926
+ __name(this, "SseAuthGuard");
927
+ }
928
+ jwtService;
929
+ logger = new import_common10.Logger(_SseAuthGuard.name);
930
+ constructor(jwtService) {
931
+ this.jwtService = jwtService;
932
+ }
933
+ async canActivate(context) {
934
+ const request = context.switchToHttp().getRequest();
935
+ const response = context.switchToHttp().getResponse();
936
+ this.setCorsHeaders(request, response);
937
+ const token = request.query?.token;
938
+ if (!token) {
939
+ this.logger.warn("SSE authentication failed: token not found in query params");
940
+ throw new import_common10.UnauthorizedException("Authentication required");
941
+ }
942
+ try {
943
+ const decodedToken = this.jwtService.decode(token);
944
+ if (!decodedToken) {
945
+ this.logger.warn("SSE authentication failed: invalid token format");
946
+ throw new import_common10.UnauthorizedException("Invalid token format");
947
+ }
948
+ if (decodedToken.type !== "onboarding") {
949
+ this.logger.warn("SSE authentication failed: endpoint requires onboarding token");
950
+ throw new import_common10.UnauthorizedException("This endpoint requires an onboarding token");
951
+ }
952
+ const validatedToken = this.jwtService.verify(token);
953
+ this.logger.debug(`SSE token validated for user: ${validatedToken.userId}`);
954
+ request.user = {
955
+ id: validatedToken.userId
956
+ };
957
+ return true;
958
+ } catch (error) {
959
+ if (error instanceof import_common10.UnauthorizedException) {
960
+ throw error;
961
+ }
962
+ const jwtError = error;
963
+ if (jwtError?.name === "TokenExpiredError") {
964
+ this.logger.warn("SSE authentication failed: token expired");
965
+ throw new import_common10.UnauthorizedException("Token has expired");
966
+ }
967
+ if (jwtError?.name === "JsonWebTokenError") {
968
+ this.logger.warn(`SSE authentication failed: ${jwtError?.message}`);
969
+ throw new import_common10.UnauthorizedException("Invalid token");
970
+ }
971
+ this.logger.error("Unexpected error in SSE auth guard", error);
972
+ throw new import_common10.UnauthorizedException("Authentication failed");
973
+ }
974
+ }
975
+ /**
976
+ * Set CORS headers for SSE responses
977
+ * Must be called before any potential exceptions
978
+ */
979
+ setCorsHeaders(request, response) {
980
+ const origin = request.headers.origin;
981
+ if (origin && SSE_ALLOWED_ORIGINS.includes(origin)) {
982
+ response.header("Access-Control-Allow-Origin", origin);
983
+ response.header("Access-Control-Allow-Credentials", "true");
984
+ this.logger.debug(`CORS headers set for origin: ${origin}`);
985
+ } else if (origin) {
986
+ this.logger.warn(`SSE request from unauthorized origin: ${origin}`);
987
+ }
988
+ }
989
+ };
990
+ SseAuthGuard = _ts_decorate6([
991
+ (0, import_common10.Injectable)({
992
+ scope: import_common10.Scope.REQUEST
993
+ }),
994
+ _ts_metadata4("design:type", Function),
995
+ _ts_metadata4("design:paramtypes", [
996
+ typeof import_jwt3.JwtService === "undefined" ? Object : import_jwt3.JwtService
997
+ ])
998
+ ], SseAuthGuard);
999
+
833
1000
  // src/database/database.module.ts
834
- var import_common13 = require("@nestjs/common");
1001
+ var import_common15 = require("@nestjs/common");
835
1002
  var import_core5 = require("@nestjs/core");
836
1003
 
837
1004
  // src/database/interceptors/message-tenant-context.interceptor.ts
838
- var import_common10 = require("@nestjs/common");
1005
+ var import_common12 = require("@nestjs/common");
839
1006
  var import_operators = require("rxjs/operators");
840
1007
 
841
1008
  // src/database/services/tenant-context.service.ts
842
- var import_common9 = require("@nestjs/common");
843
- function _ts_decorate6(decorators, target, key, desc) {
1009
+ var import_common11 = require("@nestjs/common");
1010
+ function _ts_decorate7(decorators, target, key, desc) {
844
1011
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
845
1012
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
846
1013
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
847
1014
  return c > 3 && r && Object.defineProperty(target, key, r), r;
848
1015
  }
849
- __name(_ts_decorate6, "_ts_decorate");
1016
+ __name(_ts_decorate7, "_ts_decorate");
850
1017
  var TenantContextService = class {
851
1018
  static {
852
1019
  __name(this, "TenantContextService");
@@ -877,7 +1044,7 @@ var TenantContextService = class {
877
1044
  */
878
1045
  getTenant() {
879
1046
  if (!this.tenantInfo) {
880
- throw new import_common9.UnauthorizedException("Tenant context not set");
1047
+ throw new import_common11.UnauthorizedException("Tenant context not set");
881
1048
  }
882
1049
  return this.tenantInfo;
883
1050
  }
@@ -918,30 +1085,30 @@ var TenantContextService = class {
918
1085
  return this.tenantInfo?.subdomain ?? null;
919
1086
  }
920
1087
  };
921
- TenantContextService = _ts_decorate6([
922
- (0, import_common9.Injectable)({
923
- scope: import_common9.Scope.REQUEST
1088
+ TenantContextService = _ts_decorate7([
1089
+ (0, import_common11.Injectable)({
1090
+ scope: import_common11.Scope.REQUEST
924
1091
  })
925
1092
  ], TenantContextService);
926
1093
 
927
1094
  // src/database/interceptors/message-tenant-context.interceptor.ts
928
- function _ts_decorate7(decorators, target, key, desc) {
1095
+ function _ts_decorate8(decorators, target, key, desc) {
929
1096
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
930
1097
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
931
1098
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
932
1099
  return c > 3 && r && Object.defineProperty(target, key, r), r;
933
1100
  }
934
- __name(_ts_decorate7, "_ts_decorate");
935
- function _ts_metadata4(k, v) {
1101
+ __name(_ts_decorate8, "_ts_decorate");
1102
+ function _ts_metadata5(k, v) {
936
1103
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
937
1104
  }
938
- __name(_ts_metadata4, "_ts_metadata");
1105
+ __name(_ts_metadata5, "_ts_metadata");
939
1106
  var MessageTenantContextInterceptor = class _MessageTenantContextInterceptor {
940
1107
  static {
941
1108
  __name(this, "MessageTenantContextInterceptor");
942
1109
  }
943
1110
  tenantContext;
944
- logger = new import_common10.Logger(_MessageTenantContextInterceptor.name);
1111
+ logger = new import_common12.Logger(_MessageTenantContextInterceptor.name);
945
1112
  constructor(tenantContext) {
946
1113
  this.tenantContext = tenantContext;
947
1114
  }
@@ -986,30 +1153,30 @@ var MessageTenantContextInterceptor = class _MessageTenantContextInterceptor {
986
1153
  }
987
1154
  }
988
1155
  };
989
- MessageTenantContextInterceptor = _ts_decorate7([
990
- (0, import_common10.Injectable)({
991
- scope: import_common10.Scope.REQUEST
1156
+ MessageTenantContextInterceptor = _ts_decorate8([
1157
+ (0, import_common12.Injectable)({
1158
+ scope: import_common12.Scope.REQUEST
992
1159
  }),
993
- _ts_metadata4("design:type", Function),
994
- _ts_metadata4("design:paramtypes", [
1160
+ _ts_metadata5("design:type", Function),
1161
+ _ts_metadata5("design:paramtypes", [
995
1162
  typeof TenantContextService === "undefined" ? Object : TenantContextService
996
1163
  ])
997
1164
  ], MessageTenantContextInterceptor);
998
1165
 
999
1166
  // src/database/interceptors/tenant-context.interceptor.ts
1000
- var import_common11 = require("@nestjs/common");
1167
+ var import_common13 = require("@nestjs/common");
1001
1168
  var import_core4 = require("@nestjs/core");
1002
- function _ts_decorate8(decorators, target, key, desc) {
1169
+ function _ts_decorate9(decorators, target, key, desc) {
1003
1170
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1004
1171
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1005
1172
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1006
1173
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1007
1174
  }
1008
- __name(_ts_decorate8, "_ts_decorate");
1009
- function _ts_metadata5(k, v) {
1175
+ __name(_ts_decorate9, "_ts_decorate");
1176
+ function _ts_metadata6(k, v) {
1010
1177
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1011
1178
  }
1012
- __name(_ts_metadata5, "_ts_metadata");
1179
+ __name(_ts_metadata6, "_ts_metadata");
1013
1180
  var TenantContextInterceptor = class _TenantContextInterceptor {
1014
1181
  static {
1015
1182
  __name(this, "TenantContextInterceptor");
@@ -1018,7 +1185,7 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
1018
1185
  tenantContext;
1019
1186
  primaryDatabase;
1020
1187
  requestService;
1021
- logger = new import_common11.Logger(_TenantContextInterceptor.name);
1188
+ logger = new import_common13.Logger(_TenantContextInterceptor.name);
1022
1189
  constructor(reflector, tenantContext, primaryDatabase, requestService) {
1023
1190
  this.reflector = reflector;
1024
1191
  this.tenantContext = tenantContext;
@@ -1039,7 +1206,7 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
1039
1206
  return next.handle();
1040
1207
  }
1041
1208
  if (!tenantIdentifier) {
1042
- throw new import_common11.UnauthorizedException("Tenant identifier not found in request");
1209
+ throw new import_common13.UnauthorizedException("Tenant identifier not found in request");
1043
1210
  }
1044
1211
  this.logger.debug(`Tenant identifier extracted: ${tenantIdentifier}`);
1045
1212
  if (tenantIdentifier === "cloud") {
@@ -1049,11 +1216,11 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
1049
1216
  const tenantInfo = await this.primaryDatabase.getTenantInfo(tenantIdentifier);
1050
1217
  if (!tenantInfo) {
1051
1218
  this.logger.warn(`Invalid tenant: ${tenantIdentifier}`);
1052
- throw new import_common11.UnauthorizedException("Invalid tenant");
1219
+ throw new import_common13.UnauthorizedException("Invalid tenant");
1053
1220
  }
1054
1221
  if (tenantInfo.status !== "ACTIVE") {
1055
1222
  this.logger.warn(`Tenant ${tenantIdentifier} has status: ${tenantInfo.status}`);
1056
- throw new import_common11.UnauthorizedException(`Tenant is ${tenantInfo.status}`);
1223
+ throw new import_common13.UnauthorizedException(`Tenant is ${tenantInfo.status}`);
1057
1224
  }
1058
1225
  this.logger.debug(`Tenant config loaded: ${tenantInfo.subdomain} (${tenantInfo.type})`);
1059
1226
  this.tenantContext.setTenant(tenantInfo);
@@ -1066,12 +1233,12 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
1066
1233
  return next.handle();
1067
1234
  }
1068
1235
  };
1069
- TenantContextInterceptor = _ts_decorate8([
1070
- (0, import_common11.Injectable)({
1071
- scope: import_common11.Scope.REQUEST
1236
+ TenantContextInterceptor = _ts_decorate9([
1237
+ (0, import_common13.Injectable)({
1238
+ scope: import_common13.Scope.REQUEST
1072
1239
  }),
1073
- _ts_metadata5("design:type", Function),
1074
- _ts_metadata5("design:paramtypes", [
1240
+ _ts_metadata6("design:type", Function),
1241
+ _ts_metadata6("design:paramtypes", [
1075
1242
  typeof import_core4.Reflector === "undefined" ? Object : import_core4.Reflector,
1076
1243
  typeof TenantContextService === "undefined" ? Object : TenantContextService,
1077
1244
  typeof PrimaryDatabaseService === "undefined" ? Object : PrimaryDatabaseService,
@@ -1080,20 +1247,20 @@ TenantContextInterceptor = _ts_decorate8([
1080
1247
  ], TenantContextInterceptor);
1081
1248
 
1082
1249
  // src/database/services/tenant-database.service.ts
1083
- var import_common12 = require("@nestjs/common");
1250
+ var import_common14 = require("@nestjs/common");
1084
1251
  var import_node_postgres2 = require("drizzle-orm/node-postgres");
1085
1252
  var import_pg2 = require("pg");
1086
- function _ts_decorate9(decorators, target, key, desc) {
1253
+ function _ts_decorate10(decorators, target, key, desc) {
1087
1254
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1088
1255
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1089
1256
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1090
1257
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1091
1258
  }
1092
- __name(_ts_decorate9, "_ts_decorate");
1093
- function _ts_metadata6(k, v) {
1259
+ __name(_ts_decorate10, "_ts_decorate");
1260
+ function _ts_metadata7(k, v) {
1094
1261
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1095
1262
  }
1096
- __name(_ts_metadata6, "_ts_metadata");
1263
+ __name(_ts_metadata7, "_ts_metadata");
1097
1264
  function _ts_param3(paramIndex, decorator) {
1098
1265
  return function(target, key) {
1099
1266
  decorator(target, key, paramIndex);
@@ -1106,7 +1273,7 @@ var TenantDatabaseService = class _TenantDatabaseService {
1106
1273
  }
1107
1274
  options;
1108
1275
  tenantContext;
1109
- logger = new import_common12.Logger(_TenantDatabaseService.name);
1276
+ logger = new import_common14.Logger(_TenantDatabaseService.name);
1110
1277
  /** Connection pool: Map<cacheKey, TenantConnection> */
1111
1278
  clients = /* @__PURE__ */ new Map();
1112
1279
  /** Track last usage time for idle connection cleanup */
@@ -1183,7 +1350,7 @@ var TenantDatabaseService = class _TenantDatabaseService {
1183
1350
  };
1184
1351
  } catch (error) {
1185
1352
  this.logger.error(`Failed to create database connection for tenant: ${tenant.subdomain}`, error);
1186
- throw new import_common12.InternalServerErrorException("Failed to connect to tenant database");
1353
+ throw new import_common14.InternalServerErrorException("Failed to connect to tenant database");
1187
1354
  }
1188
1355
  }
1189
1356
  /**
@@ -1275,24 +1442,24 @@ var TenantDatabaseService = class _TenantDatabaseService {
1275
1442
  this.logger.log("All database connections closed");
1276
1443
  }
1277
1444
  };
1278
- TenantDatabaseService = _ts_decorate9([
1279
- (0, import_common12.Injectable)(),
1280
- _ts_param3(0, (0, import_common12.Inject)(DATABASE_MODULE_OPTIONS)),
1281
- _ts_metadata6("design:type", Function),
1282
- _ts_metadata6("design:paramtypes", [
1445
+ TenantDatabaseService = _ts_decorate10([
1446
+ (0, import_common14.Injectable)(),
1447
+ _ts_param3(0, (0, import_common14.Inject)(DATABASE_MODULE_OPTIONS)),
1448
+ _ts_metadata7("design:type", Function),
1449
+ _ts_metadata7("design:paramtypes", [
1283
1450
  typeof DatabaseModuleOptions === "undefined" ? Object : DatabaseModuleOptions,
1284
1451
  typeof TenantContextService === "undefined" ? Object : TenantContextService
1285
1452
  ])
1286
1453
  ], TenantDatabaseService);
1287
1454
 
1288
1455
  // src/database/database.module.ts
1289
- function _ts_decorate10(decorators, target, key, desc) {
1456
+ function _ts_decorate11(decorators, target, key, desc) {
1290
1457
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1291
1458
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1292
1459
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1293
1460
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1294
1461
  }
1295
- __name(_ts_decorate10, "_ts_decorate");
1462
+ __name(_ts_decorate11, "_ts_decorate");
1296
1463
  var DatabaseModule = class _DatabaseModule {
1297
1464
  static {
1298
1465
  __name(this, "DatabaseModule");
@@ -1363,6 +1530,11 @@ var DatabaseModule = class _DatabaseModule {
1363
1530
  inject: options.inject || []
1364
1531
  };
1365
1532
  const providers = [
1533
+ // Required for external packages - NestJS global Reflector not available
1534
+ {
1535
+ provide: import_core5.Reflector,
1536
+ useClass: import_core5.Reflector
1537
+ },
1366
1538
  asyncProvider,
1367
1539
  TenantContextService,
1368
1540
  PrimaryDatabaseService,
@@ -1394,14 +1566,14 @@ var DatabaseModule = class _DatabaseModule {
1394
1566
  };
1395
1567
  }
1396
1568
  };
1397
- DatabaseModule = _ts_decorate10([
1398
- (0, import_common13.Global)(),
1399
- (0, import_common13.Module)({})
1569
+ DatabaseModule = _ts_decorate11([
1570
+ (0, import_common15.Global)(),
1571
+ (0, import_common15.Module)({})
1400
1572
  ], DatabaseModule);
1401
1573
 
1402
1574
  // src/database/decorators/tenant.decorator.ts
1403
- var import_common14 = require("@nestjs/common");
1404
- var Tenant = (0, import_common14.createParamDecorator)((_data, ctx) => {
1575
+ var import_common16 = require("@nestjs/common");
1576
+ var Tenant = (0, import_common16.createParamDecorator)((_data, ctx) => {
1405
1577
  const request = ctx.switchToHttp().getRequest();
1406
1578
  const tenantContext = request.app?.get?.(TenantContextService);
1407
1579
  if (!tenantContext) {
@@ -1411,7 +1583,7 @@ var Tenant = (0, import_common14.createParamDecorator)((_data, ctx) => {
1411
1583
  });
1412
1584
 
1413
1585
  // src/database/repositories/primary-base.repository.ts
1414
- var import_common15 = require("@nestjs/common");
1586
+ var import_common17 = require("@nestjs/common");
1415
1587
  var import_drizzle_orm2 = require("drizzle-orm");
1416
1588
  function snakeToCamel(str) {
1417
1589
  return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
@@ -1482,7 +1654,7 @@ var PrimaryBaseRepository = class {
1482
1654
  this.table = table;
1483
1655
  const dbTableName = (0, import_drizzle_orm2.getTableName)(table);
1484
1656
  this.tableName = snakeToCamel(dbTableName);
1485
- this.logger = new import_common15.Logger(this.constructor.name);
1657
+ this.logger = new import_common17.Logger(this.constructor.name);
1486
1658
  this.logger.debug(`Initialized ${this.constructor.name}`);
1487
1659
  this.logger.debug(`Table name: '${dbTableName}' -> query key: '${this.tableName}'`);
1488
1660
  }
@@ -1722,7 +1894,7 @@ var PrimaryBaseRepository = class {
1722
1894
  };
1723
1895
 
1724
1896
  // src/database/repositories/tenant-base.repository.ts
1725
- var import_common16 = require("@nestjs/common");
1897
+ var import_common18 = require("@nestjs/common");
1726
1898
  var import_drizzle_orm3 = require("drizzle-orm");
1727
1899
  var TenantBaseRepository = class {
1728
1900
  static {
@@ -1779,7 +1951,7 @@ var TenantBaseRepository = class {
1779
1951
  this.database = database;
1780
1952
  this.table = table;
1781
1953
  this.tableName = (0, import_drizzle_orm3.getTableName)(table);
1782
- this.logger = new import_common16.Logger(this.constructor.name);
1954
+ this.logger = new import_common18.Logger(this.constructor.name);
1783
1955
  this.logger.debug(`Initialized ${this.constructor.name}`);
1784
1956
  }
1785
1957
  /**
@@ -2012,402 +2184,235 @@ var TenantBaseRepository = class {
2012
2184
  };
2013
2185
 
2014
2186
  // src/exceptions/bad-gateway.exception.ts
2015
- var import_common18 = require("@nestjs/common");
2187
+ var import_common20 = require("@nestjs/common");
2016
2188
 
2017
2189
  // src/exceptions/base-field.exception.ts
2018
- var import_common17 = require("@nestjs/common");
2019
- var BaseFieldException = class extends import_common17.HttpException {
2190
+ var import_common19 = require("@nestjs/common");
2191
+ var HttpProblemException = class extends import_common19.HttpException {
2020
2192
  static {
2021
- __name(this, "BaseFieldException");
2022
- }
2023
- constructor(statusOrMessageOrErrors, messageOrStatus, statusOrDetail, detail) {
2024
- let errors;
2025
- let httpStatus;
2026
- let finalDetail;
2027
- if (Array.isArray(statusOrMessageOrErrors)) {
2028
- errors = statusOrMessageOrErrors;
2029
- httpStatus = messageOrStatus || import_common17.HttpStatus.BAD_REQUEST;
2030
- finalDetail = typeof statusOrDetail === "string" ? statusOrDetail : void 0;
2031
- } else if (typeof statusOrMessageOrErrors === "string" && typeof messageOrStatus === "string") {
2032
- errors = [
2033
- {
2034
- field: statusOrMessageOrErrors,
2035
- message: messageOrStatus
2036
- }
2037
- ];
2038
- httpStatus = statusOrDetail;
2039
- finalDetail = detail;
2040
- } else if (typeof statusOrMessageOrErrors === "string") {
2041
- errors = [
2042
- {
2043
- message: statusOrMessageOrErrors
2044
- }
2045
- ];
2046
- httpStatus = messageOrStatus;
2047
- finalDetail = typeof statusOrDetail === "string" ? statusOrDetail : void 0;
2048
- } else {
2049
- errors = [
2050
- {
2051
- message: "An error occurred"
2052
- }
2053
- ];
2054
- httpStatus = statusOrMessageOrErrors;
2055
- finalDetail = void 0;
2056
- }
2057
- const response = finalDetail !== void 0 ? {
2058
- errors,
2059
- detail: finalDetail
2060
- } : {
2061
- errors
2062
- };
2063
- super(response, httpStatus);
2193
+ __name(this, "HttpProblemException");
2194
+ }
2195
+ constructor(detailOrOptions, httpStatus) {
2196
+ const options = typeof detailOrOptions === "string" ? {
2197
+ detail: detailOrOptions
2198
+ } : detailOrOptions;
2199
+ super({
2200
+ type: options.type ?? "about:blank",
2201
+ label: options.label,
2202
+ detail: options.detail,
2203
+ errors: options.errors ?? []
2204
+ }, httpStatus);
2064
2205
  }
2065
2206
  };
2066
2207
 
2067
2208
  // src/exceptions/bad-gateway.exception.ts
2068
- var BadGatewayException = class extends BaseFieldException {
2209
+ var BadGatewayException = class extends HttpProblemException {
2069
2210
  static {
2070
2211
  __name(this, "BadGatewayException");
2071
2212
  }
2072
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2073
- if (Array.isArray(messageOrField)) {
2074
- super(messageOrField, import_common18.HttpStatus.BAD_GATEWAY, fieldMessageOrDetail);
2075
- } else if (detail !== void 0) {
2076
- super(messageOrField, fieldMessageOrDetail, import_common18.HttpStatus.BAD_GATEWAY, detail);
2077
- } else if (fieldMessageOrDetail) {
2078
- super(messageOrField, fieldMessageOrDetail, import_common18.HttpStatus.BAD_GATEWAY);
2079
- } else {
2080
- super(messageOrField, import_common18.HttpStatus.BAD_GATEWAY);
2081
- }
2213
+ constructor(detailOrOptions) {
2214
+ super(detailOrOptions ?? "Bad Gateway", import_common20.HttpStatus.BAD_GATEWAY);
2082
2215
  }
2083
2216
  };
2084
2217
 
2085
2218
  // src/exceptions/bad-request.exception.ts
2086
- var import_common19 = require("@nestjs/common");
2087
- var BadRequestException = class extends BaseFieldException {
2219
+ var import_common21 = require("@nestjs/common");
2220
+ var BadRequestException = class extends HttpProblemException {
2088
2221
  static {
2089
2222
  __name(this, "BadRequestException");
2090
2223
  }
2091
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2092
- if (Array.isArray(messageOrField)) {
2093
- super(messageOrField, import_common19.HttpStatus.BAD_REQUEST, fieldMessageOrDetail);
2094
- } else if (detail !== void 0) {
2095
- super(messageOrField, fieldMessageOrDetail, import_common19.HttpStatus.BAD_REQUEST, detail);
2096
- } else if (fieldMessageOrDetail) {
2097
- super(messageOrField, fieldMessageOrDetail, import_common19.HttpStatus.BAD_REQUEST);
2098
- } else {
2099
- super(messageOrField, import_common19.HttpStatus.BAD_REQUEST);
2100
- }
2224
+ constructor(detailOrOptions) {
2225
+ super(detailOrOptions ?? "Bad Request", import_common21.HttpStatus.BAD_REQUEST);
2101
2226
  }
2102
2227
  };
2103
2228
 
2104
2229
  // src/exceptions/conflict.exception.ts
2105
- var import_common20 = require("@nestjs/common");
2106
- var ConflictException = class extends BaseFieldException {
2230
+ var import_common22 = require("@nestjs/common");
2231
+ var ConflictException = class extends HttpProblemException {
2107
2232
  static {
2108
2233
  __name(this, "ConflictException");
2109
2234
  }
2110
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2111
- if (Array.isArray(messageOrField)) {
2112
- super(messageOrField, import_common20.HttpStatus.CONFLICT, fieldMessageOrDetail);
2113
- } else if (detail !== void 0) {
2114
- super(messageOrField, fieldMessageOrDetail, import_common20.HttpStatus.CONFLICT, detail);
2115
- } else if (fieldMessageOrDetail) {
2116
- super(messageOrField, fieldMessageOrDetail, import_common20.HttpStatus.CONFLICT);
2117
- } else {
2118
- super(messageOrField, import_common20.HttpStatus.CONFLICT);
2119
- }
2235
+ constructor(detailOrOptions) {
2236
+ super(detailOrOptions ?? "Conflict", import_common22.HttpStatus.CONFLICT);
2120
2237
  }
2121
2238
  };
2122
2239
 
2123
2240
  // src/exceptions/forbidden.exception.ts
2124
- var import_common21 = require("@nestjs/common");
2125
- var ForbiddenException = class extends BaseFieldException {
2241
+ var import_common23 = require("@nestjs/common");
2242
+ var ForbiddenException2 = class extends HttpProblemException {
2126
2243
  static {
2127
2244
  __name(this, "ForbiddenException");
2128
2245
  }
2129
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2130
- if (Array.isArray(messageOrField)) {
2131
- super(messageOrField, import_common21.HttpStatus.FORBIDDEN, fieldMessageOrDetail);
2132
- } else if (detail !== void 0) {
2133
- super(messageOrField, fieldMessageOrDetail, import_common21.HttpStatus.FORBIDDEN, detail);
2134
- } else if (fieldMessageOrDetail) {
2135
- super(messageOrField, fieldMessageOrDetail, import_common21.HttpStatus.FORBIDDEN);
2136
- } else {
2137
- super(messageOrField, import_common21.HttpStatus.FORBIDDEN);
2138
- }
2246
+ constructor(detailOrOptions) {
2247
+ super(detailOrOptions ?? "Forbidden", import_common23.HttpStatus.FORBIDDEN);
2139
2248
  }
2140
2249
  };
2141
2250
 
2142
2251
  // src/exceptions/gone.exception.ts
2143
- var import_common22 = require("@nestjs/common");
2144
- var GoneException = class extends BaseFieldException {
2252
+ var import_common24 = require("@nestjs/common");
2253
+ var GoneException = class extends HttpProblemException {
2145
2254
  static {
2146
2255
  __name(this, "GoneException");
2147
2256
  }
2148
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2149
- if (Array.isArray(messageOrField)) {
2150
- super(messageOrField, import_common22.HttpStatus.GONE, fieldMessageOrDetail);
2151
- } else if (detail !== void 0) {
2152
- super(messageOrField, fieldMessageOrDetail, import_common22.HttpStatus.GONE, detail);
2153
- } else if (fieldMessageOrDetail) {
2154
- super(messageOrField, fieldMessageOrDetail, import_common22.HttpStatus.GONE);
2155
- } else {
2156
- super(messageOrField, import_common22.HttpStatus.GONE);
2157
- }
2257
+ constructor(detailOrOptions) {
2258
+ super(detailOrOptions ?? "Gone", import_common24.HttpStatus.GONE);
2158
2259
  }
2159
2260
  };
2160
2261
 
2161
2262
  // src/exceptions/internal-server-error.exception.ts
2162
- var import_common23 = require("@nestjs/common");
2163
- var InternalServerErrorException3 = class extends BaseFieldException {
2263
+ var import_common25 = require("@nestjs/common");
2264
+ var InternalServerErrorException3 = class extends HttpProblemException {
2164
2265
  static {
2165
2266
  __name(this, "InternalServerErrorException");
2166
2267
  }
2167
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2168
- if (Array.isArray(messageOrField)) {
2169
- super(messageOrField, import_common23.HttpStatus.INTERNAL_SERVER_ERROR, fieldMessageOrDetail);
2170
- } else if (detail !== void 0) {
2171
- super(messageOrField, fieldMessageOrDetail, import_common23.HttpStatus.INTERNAL_SERVER_ERROR, detail);
2172
- } else if (fieldMessageOrDetail) {
2173
- super(messageOrField, fieldMessageOrDetail, import_common23.HttpStatus.INTERNAL_SERVER_ERROR);
2174
- } else {
2175
- super(messageOrField, import_common23.HttpStatus.INTERNAL_SERVER_ERROR);
2176
- }
2268
+ constructor(detailOrOptions) {
2269
+ super(detailOrOptions ?? "Internal Server Error", import_common25.HttpStatus.INTERNAL_SERVER_ERROR);
2177
2270
  }
2178
2271
  };
2179
2272
 
2180
2273
  // src/exceptions/method-not-allowed.exception.ts
2181
- var import_common24 = require("@nestjs/common");
2182
- var MethodNotAllowedException = class extends BaseFieldException {
2274
+ var import_common26 = require("@nestjs/common");
2275
+ var MethodNotAllowedException = class extends HttpProblemException {
2183
2276
  static {
2184
2277
  __name(this, "MethodNotAllowedException");
2185
2278
  }
2186
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2187
- if (Array.isArray(messageOrField)) {
2188
- super(messageOrField, import_common24.HttpStatus.METHOD_NOT_ALLOWED, fieldMessageOrDetail);
2189
- } else if (detail !== void 0) {
2190
- super(messageOrField, fieldMessageOrDetail, import_common24.HttpStatus.METHOD_NOT_ALLOWED, detail);
2191
- } else if (fieldMessageOrDetail) {
2192
- super(messageOrField, fieldMessageOrDetail, import_common24.HttpStatus.METHOD_NOT_ALLOWED);
2193
- } else {
2194
- super(messageOrField, import_common24.HttpStatus.METHOD_NOT_ALLOWED);
2195
- }
2279
+ constructor(detailOrOptions) {
2280
+ super(detailOrOptions ?? "Method Not Allowed", import_common26.HttpStatus.METHOD_NOT_ALLOWED);
2196
2281
  }
2197
2282
  };
2198
2283
 
2199
2284
  // src/exceptions/not-acceptable.exception.ts
2200
- var import_common25 = require("@nestjs/common");
2201
- var NotAcceptableException = class extends BaseFieldException {
2285
+ var import_common27 = require("@nestjs/common");
2286
+ var NotAcceptableException = class extends HttpProblemException {
2202
2287
  static {
2203
2288
  __name(this, "NotAcceptableException");
2204
2289
  }
2205
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2206
- if (Array.isArray(messageOrField)) {
2207
- super(messageOrField, import_common25.HttpStatus.NOT_ACCEPTABLE, fieldMessageOrDetail);
2208
- } else if (detail !== void 0) {
2209
- super(messageOrField, fieldMessageOrDetail, import_common25.HttpStatus.NOT_ACCEPTABLE, detail);
2210
- } else if (fieldMessageOrDetail) {
2211
- super(messageOrField, fieldMessageOrDetail, import_common25.HttpStatus.NOT_ACCEPTABLE);
2212
- } else {
2213
- super(messageOrField, import_common25.HttpStatus.NOT_ACCEPTABLE);
2214
- }
2290
+ constructor(detailOrOptions) {
2291
+ super(detailOrOptions ?? "Not Acceptable", import_common27.HttpStatus.NOT_ACCEPTABLE);
2215
2292
  }
2216
2293
  };
2217
2294
 
2218
2295
  // src/exceptions/not-found.exception.ts
2219
- var import_common26 = require("@nestjs/common");
2220
- var NotFoundException = class extends BaseFieldException {
2296
+ var import_common28 = require("@nestjs/common");
2297
+ var NotFoundException = class extends HttpProblemException {
2221
2298
  static {
2222
2299
  __name(this, "NotFoundException");
2223
2300
  }
2224
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2225
- if (Array.isArray(messageOrField)) {
2226
- super(messageOrField, import_common26.HttpStatus.NOT_FOUND, fieldMessageOrDetail);
2227
- } else if (detail !== void 0) {
2228
- super(messageOrField, fieldMessageOrDetail, import_common26.HttpStatus.NOT_FOUND, detail);
2229
- } else if (fieldMessageOrDetail) {
2230
- super(messageOrField, fieldMessageOrDetail, import_common26.HttpStatus.NOT_FOUND);
2231
- } else {
2232
- super(messageOrField, import_common26.HttpStatus.NOT_FOUND);
2233
- }
2301
+ constructor(detailOrOptions) {
2302
+ super(detailOrOptions ?? "Not Found", import_common28.HttpStatus.NOT_FOUND);
2234
2303
  }
2235
2304
  };
2236
2305
 
2237
2306
  // src/exceptions/not-implemented.exception.ts
2238
- var import_common27 = require("@nestjs/common");
2239
- var NotImplementedException = class extends BaseFieldException {
2307
+ var import_common29 = require("@nestjs/common");
2308
+ var NotImplementedException = class extends HttpProblemException {
2240
2309
  static {
2241
2310
  __name(this, "NotImplementedException");
2242
2311
  }
2243
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2244
- if (Array.isArray(messageOrField)) {
2245
- super(messageOrField, import_common27.HttpStatus.NOT_IMPLEMENTED, fieldMessageOrDetail);
2246
- } else if (detail !== void 0) {
2247
- super(messageOrField, fieldMessageOrDetail, import_common27.HttpStatus.NOT_IMPLEMENTED, detail);
2248
- } else if (fieldMessageOrDetail) {
2249
- super(messageOrField, fieldMessageOrDetail, import_common27.HttpStatus.NOT_IMPLEMENTED);
2250
- } else {
2251
- super(messageOrField, import_common27.HttpStatus.NOT_IMPLEMENTED);
2252
- }
2312
+ constructor(detailOrOptions) {
2313
+ super(detailOrOptions ?? "Not Implemented", import_common29.HttpStatus.NOT_IMPLEMENTED);
2253
2314
  }
2254
2315
  };
2255
2316
 
2256
2317
  // src/exceptions/payload-too-large.exception.ts
2257
- var import_common28 = require("@nestjs/common");
2258
- var PayloadTooLargeException = class extends BaseFieldException {
2318
+ var import_common30 = require("@nestjs/common");
2319
+ var PayloadTooLargeException = class extends HttpProblemException {
2259
2320
  static {
2260
2321
  __name(this, "PayloadTooLargeException");
2261
2322
  }
2262
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2263
- if (Array.isArray(messageOrField)) {
2264
- super(messageOrField, import_common28.HttpStatus.PAYLOAD_TOO_LARGE, fieldMessageOrDetail);
2265
- } else if (detail !== void 0) {
2266
- super(messageOrField, fieldMessageOrDetail, import_common28.HttpStatus.PAYLOAD_TOO_LARGE, detail);
2267
- } else if (fieldMessageOrDetail) {
2268
- super(messageOrField, fieldMessageOrDetail, import_common28.HttpStatus.PAYLOAD_TOO_LARGE);
2269
- } else {
2270
- super(messageOrField, import_common28.HttpStatus.PAYLOAD_TOO_LARGE);
2271
- }
2323
+ constructor(detailOrOptions) {
2324
+ super(detailOrOptions ?? "Payload Too Large", import_common30.HttpStatus.PAYLOAD_TOO_LARGE);
2272
2325
  }
2273
2326
  };
2274
2327
 
2275
2328
  // src/exceptions/request-timeout.exception.ts
2276
- var import_common29 = require("@nestjs/common");
2277
- var RequestTimeoutException = class extends BaseFieldException {
2329
+ var import_common31 = require("@nestjs/common");
2330
+ var RequestTimeoutException = class extends HttpProblemException {
2278
2331
  static {
2279
2332
  __name(this, "RequestTimeoutException");
2280
2333
  }
2281
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2282
- if (Array.isArray(messageOrField)) {
2283
- super(messageOrField, import_common29.HttpStatus.REQUEST_TIMEOUT, fieldMessageOrDetail);
2284
- } else if (detail !== void 0) {
2285
- super(messageOrField, fieldMessageOrDetail, import_common29.HttpStatus.REQUEST_TIMEOUT, detail);
2286
- } else if (fieldMessageOrDetail) {
2287
- super(messageOrField, fieldMessageOrDetail, import_common29.HttpStatus.REQUEST_TIMEOUT);
2288
- } else {
2289
- super(messageOrField, import_common29.HttpStatus.REQUEST_TIMEOUT);
2290
- }
2334
+ constructor(detailOrOptions) {
2335
+ super(detailOrOptions ?? "Request Timeout", import_common31.HttpStatus.REQUEST_TIMEOUT);
2291
2336
  }
2292
2337
  };
2293
2338
 
2294
2339
  // src/exceptions/service-unavailable.exception.ts
2295
- var import_common30 = require("@nestjs/common");
2296
- var ServiceUnavailableException = class extends BaseFieldException {
2340
+ var import_common32 = require("@nestjs/common");
2341
+ var ServiceUnavailableException = class extends HttpProblemException {
2297
2342
  static {
2298
2343
  __name(this, "ServiceUnavailableException");
2299
2344
  }
2300
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2301
- if (Array.isArray(messageOrField)) {
2302
- super(messageOrField, import_common30.HttpStatus.SERVICE_UNAVAILABLE, fieldMessageOrDetail);
2303
- } else if (detail !== void 0) {
2304
- super(messageOrField, fieldMessageOrDetail, import_common30.HttpStatus.SERVICE_UNAVAILABLE, detail);
2305
- } else if (fieldMessageOrDetail) {
2306
- super(messageOrField, fieldMessageOrDetail, import_common30.HttpStatus.SERVICE_UNAVAILABLE);
2307
- } else {
2308
- super(messageOrField, import_common30.HttpStatus.SERVICE_UNAVAILABLE);
2309
- }
2345
+ constructor(detailOrOptions) {
2346
+ super(detailOrOptions ?? "Service Unavailable", import_common32.HttpStatus.SERVICE_UNAVAILABLE);
2310
2347
  }
2311
2348
  };
2312
2349
 
2313
2350
  // src/exceptions/too-many-requests.exception.ts
2314
- var import_common31 = require("@nestjs/common");
2315
- var TooManyRequestsException = class extends BaseFieldException {
2351
+ var import_common33 = require("@nestjs/common");
2352
+ var TooManyRequestsException = class extends HttpProblemException {
2316
2353
  static {
2317
2354
  __name(this, "TooManyRequestsException");
2318
2355
  }
2319
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2320
- if (Array.isArray(messageOrField)) {
2321
- super(messageOrField, import_common31.HttpStatus.TOO_MANY_REQUESTS, fieldMessageOrDetail);
2322
- } else if (detail !== void 0) {
2323
- super(messageOrField, fieldMessageOrDetail, import_common31.HttpStatus.TOO_MANY_REQUESTS, detail);
2324
- } else if (fieldMessageOrDetail) {
2325
- super(messageOrField, fieldMessageOrDetail, import_common31.HttpStatus.TOO_MANY_REQUESTS);
2326
- } else {
2327
- super(messageOrField, import_common31.HttpStatus.TOO_MANY_REQUESTS);
2328
- }
2356
+ constructor(detailOrOptions) {
2357
+ super(detailOrOptions ?? "Too Many Requests", import_common33.HttpStatus.TOO_MANY_REQUESTS);
2329
2358
  }
2330
2359
  };
2331
2360
 
2332
2361
  // src/exceptions/unauthorized.exception.ts
2333
- var import_common32 = require("@nestjs/common");
2334
- var UnauthorizedException4 = class extends BaseFieldException {
2362
+ var import_common34 = require("@nestjs/common");
2363
+ var UnauthorizedException5 = class extends HttpProblemException {
2335
2364
  static {
2336
2365
  __name(this, "UnauthorizedException");
2337
2366
  }
2338
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2339
- if (Array.isArray(messageOrField)) {
2340
- super(messageOrField, import_common32.HttpStatus.UNAUTHORIZED, fieldMessageOrDetail);
2341
- } else if (detail !== void 0) {
2342
- super(messageOrField, fieldMessageOrDetail, import_common32.HttpStatus.UNAUTHORIZED, detail);
2343
- } else if (fieldMessageOrDetail) {
2344
- super(messageOrField, fieldMessageOrDetail, import_common32.HttpStatus.UNAUTHORIZED);
2345
- } else {
2346
- super(messageOrField, import_common32.HttpStatus.UNAUTHORIZED);
2347
- }
2367
+ constructor(detailOrOptions) {
2368
+ super(detailOrOptions ?? "Unauthorized", import_common34.HttpStatus.UNAUTHORIZED);
2348
2369
  }
2349
2370
  };
2350
2371
 
2351
2372
  // src/exceptions/unprocessable-entity.exception.ts
2352
- var import_common33 = require("@nestjs/common");
2353
- var UnprocessableEntityException = class extends BaseFieldException {
2373
+ var import_common35 = require("@nestjs/common");
2374
+ var UnprocessableEntityException = class extends HttpProblemException {
2354
2375
  static {
2355
2376
  __name(this, "UnprocessableEntityException");
2356
2377
  }
2357
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2358
- if (Array.isArray(messageOrField)) {
2359
- super(messageOrField, import_common33.HttpStatus.UNPROCESSABLE_ENTITY, fieldMessageOrDetail);
2360
- } else if (detail !== void 0) {
2361
- super(messageOrField, fieldMessageOrDetail, import_common33.HttpStatus.UNPROCESSABLE_ENTITY, detail);
2362
- } else if (fieldMessageOrDetail) {
2363
- super(messageOrField, fieldMessageOrDetail, import_common33.HttpStatus.UNPROCESSABLE_ENTITY);
2364
- } else {
2365
- super(messageOrField, import_common33.HttpStatus.UNPROCESSABLE_ENTITY);
2366
- }
2378
+ constructor(detailOrOptions) {
2379
+ super(detailOrOptions ?? "Unprocessable Entity", import_common35.HttpStatus.UNPROCESSABLE_ENTITY);
2367
2380
  }
2368
2381
  };
2369
2382
 
2370
2383
  // src/exceptions/unsupported-media-type.exception.ts
2371
- var import_common34 = require("@nestjs/common");
2372
- var UnsupportedMediaTypeException = class extends BaseFieldException {
2384
+ var import_common36 = require("@nestjs/common");
2385
+ var UnsupportedMediaTypeException = class extends HttpProblemException {
2373
2386
  static {
2374
2387
  __name(this, "UnsupportedMediaTypeException");
2375
2388
  }
2376
- constructor(messageOrField, fieldMessageOrDetail, detail) {
2377
- if (Array.isArray(messageOrField)) {
2378
- super(messageOrField, import_common34.HttpStatus.UNSUPPORTED_MEDIA_TYPE, fieldMessageOrDetail);
2379
- } else if (detail !== void 0) {
2380
- super(messageOrField, fieldMessageOrDetail, import_common34.HttpStatus.UNSUPPORTED_MEDIA_TYPE, detail);
2381
- } else if (fieldMessageOrDetail) {
2382
- super(messageOrField, fieldMessageOrDetail, import_common34.HttpStatus.UNSUPPORTED_MEDIA_TYPE);
2383
- } else {
2384
- super(messageOrField, import_common34.HttpStatus.UNSUPPORTED_MEDIA_TYPE);
2385
- }
2389
+ constructor(detailOrOptions) {
2390
+ super(detailOrOptions ?? "Unsupported Media Type", import_common36.HttpStatus.UNSUPPORTED_MEDIA_TYPE);
2386
2391
  }
2387
2392
  };
2388
2393
 
2389
2394
  // src/exceptions/validation.exception.ts
2390
- var import_common35 = require("@nestjs/common");
2391
- var ValidationException = class extends BaseFieldException {
2395
+ var import_common37 = require("@nestjs/common");
2396
+ var ValidationException = class extends HttpProblemException {
2392
2397
  static {
2393
2398
  __name(this, "ValidationException");
2394
2399
  }
2395
- constructor(errors, detail) {
2396
- super(errors, import_common35.HttpStatus.BAD_REQUEST, detail);
2400
+ constructor(detailOrOptions) {
2401
+ super(detailOrOptions ?? "Validation Failed", import_common37.HttpStatus.BAD_REQUEST);
2397
2402
  }
2398
2403
  };
2399
2404
 
2400
2405
  // src/filters/http-exception.filter.ts
2401
- var import_common36 = require("@nestjs/common");
2402
- function _ts_decorate11(decorators, target, key, desc) {
2406
+ var import_common38 = require("@nestjs/common");
2407
+ function _ts_decorate12(decorators, target, key, desc) {
2403
2408
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2404
2409
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2405
2410
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2406
2411
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2407
2412
  }
2408
- __name(_ts_decorate11, "_ts_decorate");
2413
+ __name(_ts_decorate12, "_ts_decorate");
2409
2414
  function getHttpStatusTitle(status) {
2410
- const enumKey = Object.entries(import_common36.HttpStatus).find(([key, value]) => value === status && Number.isNaN(Number(key)))?.[0];
2415
+ const enumKey = Object.entries(import_common38.HttpStatus).find(([key, value]) => value === status && Number.isNaN(Number(key)))?.[0];
2411
2416
  if (!enumKey) {
2412
2417
  return "Error";
2413
2418
  }
@@ -2418,21 +2423,27 @@ var HttpExceptionFilter = class _HttpExceptionFilter {
2418
2423
  static {
2419
2424
  __name(this, "HttpExceptionFilter");
2420
2425
  }
2421
- logger = new import_common36.Logger(_HttpExceptionFilter.name);
2426
+ logger = new import_common38.Logger(_HttpExceptionFilter.name);
2422
2427
  catch(exception, host) {
2423
2428
  const ctx = host.switchToHttp();
2424
2429
  const response = ctx.getResponse();
2425
- let status = import_common36.HttpStatus.INTERNAL_SERVER_ERROR;
2426
- let errors = [];
2430
+ const request = ctx.getRequest();
2431
+ let status = import_common38.HttpStatus.INTERNAL_SERVER_ERROR;
2432
+ let type = "about:blank";
2433
+ let label;
2427
2434
  let detail = "Internal server error";
2428
- if (exception instanceof import_common36.HttpException) {
2435
+ let errors = [];
2436
+ if (exception instanceof import_common38.HttpException) {
2429
2437
  status = exception.getStatus();
2430
2438
  const exceptionResponse = exception.getResponse();
2431
2439
  if (typeof exceptionResponse === "object" && exceptionResponse !== null) {
2432
2440
  const responseObj = exceptionResponse;
2433
- if ("errors" in responseObj && Array.isArray(responseObj.errors)) {
2434
- errors = responseObj.errors;
2435
- detail = ("detail" in responseObj ? responseObj.detail : void 0) || exception.message;
2441
+ if ("type" in responseObj || "label" in responseObj || "errors" in responseObj) {
2442
+ const problemResponse = responseObj;
2443
+ type = problemResponse.type ?? "about:blank";
2444
+ label = problemResponse.label;
2445
+ detail = problemResponse.detail ?? exception.message ?? getHttpStatusTitle(status);
2446
+ errors = problemResponse.errors ?? [];
2436
2447
  } else if ("message" in responseObj && Array.isArray(responseObj.message)) {
2437
2448
  errors = responseObj.message.map((msg) => {
2438
2449
  if (typeof msg === "object" && "property" in msg && "constraints" in msg) {
@@ -2442,135 +2453,249 @@ var HttpExceptionFilter = class _HttpExceptionFilter {
2442
2453
  message: constraintValues[0] ?? "Validation failed"
2443
2454
  };
2444
2455
  }
2445
- return {
2446
- message: typeof msg === "string" ? msg : JSON.stringify(msg)
2447
- };
2448
- });
2456
+ return null;
2457
+ }).filter((error) => error !== null);
2449
2458
  detail = "Validation failed";
2450
2459
  } else if ("message" in responseObj) {
2451
2460
  const message = responseObj.message;
2452
- errors = [
2453
- {
2454
- message: Array.isArray(message) ? message.join(", ") : message
2455
- }
2456
- ];
2457
- detail = ("error" in responseObj ? responseObj.error : void 0) || exception.message;
2461
+ detail = Array.isArray(message) ? message.join(", ") : message;
2458
2462
  }
2459
2463
  } else if (typeof exceptionResponse === "string") {
2460
- errors = [
2461
- {
2462
- message: exceptionResponse
2463
- }
2464
- ];
2465
2464
  detail = exceptionResponse;
2466
2465
  }
2467
2466
  } else {
2468
2467
  const errorMessage = exception instanceof Error ? exception.message : "Unknown error";
2469
2468
  const stack = exception instanceof Error ? exception.stack : void 0;
2470
2469
  this.logger.error(`Unexpected error: ${errorMessage}`, stack);
2471
- errors = [
2472
- {
2473
- message: "An unexpected error occurred"
2474
- }
2475
- ];
2470
+ detail = "An unexpected error occurred";
2476
2471
  }
2477
2472
  const problemDetails = {
2473
+ type,
2478
2474
  title: getHttpStatusTitle(status),
2479
2475
  status,
2476
+ ...label && {
2477
+ label
2478
+ },
2480
2479
  detail,
2480
+ instance: request.url,
2481
2481
  errors
2482
2482
  };
2483
- response.status(status).send(problemDetails);
2483
+ response.header("Content-Type", "application/problem+json").status(status).send(problemDetails);
2484
2484
  }
2485
2485
  };
2486
- HttpExceptionFilter = _ts_decorate11([
2487
- (0, import_common36.Catch)()
2486
+ HttpExceptionFilter = _ts_decorate12([
2487
+ (0, import_common38.Catch)()
2488
2488
  ], HttpExceptionFilter);
2489
2489
 
2490
- // src/http/guards/csrf.guard.ts
2491
- var import_common37 = require("@nestjs/common");
2492
- function _ts_decorate12(decorators, target, key, desc) {
2493
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2494
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2495
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2496
- return c > 3 && r && Object.defineProperty(target, key, r), r;
2497
- }
2498
- __name(_ts_decorate12, "_ts_decorate");
2499
- var CsrfGuard = class _CsrfGuard {
2500
- static {
2501
- __name(this, "CsrfGuard");
2502
- }
2503
- logger = new import_common37.Logger(_CsrfGuard.name);
2504
- async canActivate(context) {
2505
- const request = context.switchToHttp().getRequest();
2506
- const reply = context.switchToHttp().getResponse();
2507
- const safeMethods = [
2508
- "GET",
2509
- "HEAD",
2510
- "OPTIONS"
2511
- ];
2512
- if (safeMethods.includes(request.method)) {
2513
- return true;
2514
- }
2515
- try {
2516
- const fastifyInstance = request.server;
2517
- if (!fastifyInstance.csrfProtection) {
2518
- this.logger.error("CSRF protection plugin not found. Ensure @fastify/csrf-protection is registered.");
2519
- throw new import_common37.ForbiddenException("CSRF protection not configured");
2520
- }
2521
- await new Promise((resolve, reject) => {
2522
- fastifyInstance.csrfProtection(request, reply, (err) => {
2523
- if (err) {
2524
- reject(err);
2525
- } else {
2526
- resolve();
2527
- }
2528
- });
2529
- });
2530
- this.logger.debug(`CSRF validation successful for ${request.method} ${request.url}`);
2531
- return true;
2532
- } catch (error) {
2533
- this.logger.warn(`CSRF validation failed for ${request.method} ${request.url}: ${error instanceof Error ? error.message : "Unknown error"}`);
2534
- throw new import_common37.ForbiddenException({
2535
- errors: [
2536
- {
2537
- field: "csrf",
2538
- message: "Invalid or missing CSRF token"
2539
- }
2540
- ],
2541
- message: "CSRF validation failed"
2542
- });
2543
- }
2544
- }
2490
+ // src/utils/phone.utils.ts
2491
+ var CALLING_CODE_TO_COUNTRY = {
2492
+ // 3-digit codes
2493
+ "355": "AL",
2494
+ "213": "DZ",
2495
+ "376": "AD",
2496
+ "244": "AO",
2497
+ "672": "AQ",
2498
+ "374": "AM",
2499
+ "297": "AW",
2500
+ "994": "AZ",
2501
+ "973": "BH",
2502
+ "880": "BD",
2503
+ "375": "BY",
2504
+ "501": "BZ",
2505
+ "229": "BJ",
2506
+ "975": "BT",
2507
+ "591": "BO",
2508
+ "387": "BA",
2509
+ "267": "BW",
2510
+ "673": "BN",
2511
+ "359": "BG",
2512
+ "226": "BF",
2513
+ "257": "BI",
2514
+ "855": "KH",
2515
+ "237": "CM",
2516
+ "238": "CV",
2517
+ "236": "CF",
2518
+ "235": "TD",
2519
+ "269": "KM",
2520
+ "242": "CG",
2521
+ "243": "CD",
2522
+ "506": "CR",
2523
+ "385": "HR",
2524
+ "357": "CY",
2525
+ "420": "CZ",
2526
+ "253": "DJ",
2527
+ "593": "EC",
2528
+ "503": "SV",
2529
+ "240": "GQ",
2530
+ "291": "ER",
2531
+ "372": "EE",
2532
+ "251": "ET",
2533
+ "679": "FJ",
2534
+ "358": "FI",
2535
+ "241": "GA",
2536
+ "220": "GM",
2537
+ "995": "GE",
2538
+ "233": "GH",
2539
+ "350": "GI",
2540
+ "299": "GL",
2541
+ "502": "GT",
2542
+ "224": "GN",
2543
+ "245": "GW",
2544
+ "592": "GY",
2545
+ "509": "HT",
2546
+ "504": "HN",
2547
+ "354": "IS",
2548
+ "964": "IQ",
2549
+ "353": "IE",
2550
+ "972": "IL",
2551
+ "225": "CI",
2552
+ "962": "JO",
2553
+ "254": "KE",
2554
+ "686": "KI",
2555
+ "965": "KW",
2556
+ "996": "KG",
2557
+ "856": "LA",
2558
+ "371": "LV",
2559
+ "961": "LB",
2560
+ "266": "LS",
2561
+ "231": "LR",
2562
+ "218": "LY",
2563
+ "423": "LI",
2564
+ "370": "LT",
2565
+ "352": "LU",
2566
+ "389": "MK",
2567
+ "261": "MG",
2568
+ "265": "MW",
2569
+ "960": "MV",
2570
+ "223": "ML",
2571
+ "356": "MT",
2572
+ "692": "MH",
2573
+ "222": "MR",
2574
+ "230": "MU",
2575
+ "262": "YT",
2576
+ "691": "FM",
2577
+ "373": "MD",
2578
+ "377": "MC",
2579
+ "976": "MN",
2580
+ "382": "ME",
2581
+ "258": "MZ",
2582
+ "264": "NA",
2583
+ "674": "NR",
2584
+ "977": "NP",
2585
+ "505": "NI",
2586
+ "227": "NE",
2587
+ "234": "NG",
2588
+ "683": "NU",
2589
+ "968": "OM",
2590
+ "680": "PW",
2591
+ "970": "PS",
2592
+ "507": "PA",
2593
+ "675": "PG",
2594
+ "595": "PY",
2595
+ "351": "PT",
2596
+ "974": "QA",
2597
+ "250": "RW",
2598
+ "685": "WS",
2599
+ "378": "SM",
2600
+ "239": "ST",
2601
+ "966": "SA",
2602
+ "221": "SN",
2603
+ "381": "RS",
2604
+ "248": "SC",
2605
+ "232": "SL",
2606
+ "421": "SK",
2607
+ "386": "SI",
2608
+ "677": "SB",
2609
+ "252": "SO",
2610
+ "211": "SS",
2611
+ "249": "SD",
2612
+ "597": "SR",
2613
+ "268": "SZ",
2614
+ "963": "SY",
2615
+ "992": "TJ",
2616
+ "255": "TZ",
2617
+ "228": "TG",
2618
+ "676": "TO",
2619
+ "216": "TN",
2620
+ "993": "TM",
2621
+ "688": "TV",
2622
+ "256": "UG",
2623
+ "380": "UA",
2624
+ "971": "AE",
2625
+ "598": "UY",
2626
+ "998": "UZ",
2627
+ "678": "VU",
2628
+ "379": "VA",
2629
+ "967": "YE",
2630
+ "260": "ZM",
2631
+ "263": "ZW",
2632
+ // 2-digit codes
2633
+ "93": "AF",
2634
+ "54": "AR",
2635
+ "61": "AU",
2636
+ "43": "AT",
2637
+ "32": "BE",
2638
+ "55": "BR",
2639
+ "56": "CL",
2640
+ "86": "CN",
2641
+ "57": "CO",
2642
+ "53": "CU",
2643
+ "45": "DK",
2644
+ "20": "EG",
2645
+ "33": "FR",
2646
+ "49": "DE",
2647
+ "30": "GR",
2648
+ "36": "HU",
2649
+ "91": "IN",
2650
+ "62": "ID",
2651
+ "98": "IR",
2652
+ "39": "IT",
2653
+ "81": "JP",
2654
+ "82": "KR",
2655
+ "60": "MY",
2656
+ "52": "MX",
2657
+ "31": "NL",
2658
+ "64": "NZ",
2659
+ "47": "NO",
2660
+ "92": "PK",
2661
+ "51": "PE",
2662
+ "63": "PH",
2663
+ "48": "PL",
2664
+ "40": "RO",
2665
+ "65": "SG",
2666
+ "27": "ZA",
2667
+ "34": "ES",
2668
+ "94": "LK",
2669
+ "46": "SE",
2670
+ "41": "CH",
2671
+ "66": "TH",
2672
+ "90": "TR",
2673
+ "44": "GB",
2674
+ "58": "VE",
2675
+ "84": "VN",
2676
+ // 1-digit codes (shared codes default to most common country)
2677
+ "1": "US",
2678
+ "7": "RU"
2545
2679
  };
2546
- CsrfGuard = _ts_decorate12([
2547
- (0, import_common37.Injectable)()
2548
- ], CsrfGuard);
2549
-
2550
- // src/http/http.module.ts
2551
- var import_common38 = require("@nestjs/common");
2552
- function _ts_decorate13(decorators, target, key, desc) {
2553
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2554
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2555
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2556
- return c > 3 && r && Object.defineProperty(target, key, r), r;
2680
+ function extractCountryFromPhone(phone) {
2681
+ const digits = phone.startsWith("+") ? phone.slice(1) : phone;
2682
+ for (const length of [
2683
+ 3,
2684
+ 2,
2685
+ 1
2686
+ ]) {
2687
+ const prefix = digits.slice(0, length);
2688
+ if (CALLING_CODE_TO_COUNTRY[prefix]) {
2689
+ return CALLING_CODE_TO_COUNTRY[prefix];
2690
+ }
2691
+ }
2692
+ return void 0;
2557
2693
  }
2558
- __name(_ts_decorate13, "_ts_decorate");
2559
- var HttpModule = class {
2560
- static {
2561
- __name(this, "HttpModule");
2562
- }
2563
- };
2564
- HttpModule = _ts_decorate13([
2565
- (0, import_common38.Module)({
2566
- providers: [
2567
- CsrfGuard
2568
- ],
2569
- exports: [
2570
- CsrfGuard
2571
- ]
2572
- })
2573
- ], HttpModule);
2694
+ __name(extractCountryFromPhone, "extractCountryFromPhone");
2695
+ function normalizePhoneNumber(phone) {
2696
+ return phone.startsWith("+") ? phone : `+${phone}`;
2697
+ }
2698
+ __name(normalizePhoneNumber, "normalizePhoneNumber");
2574
2699
 
2575
2700
  // src/logger/interceptors/http-logger.interceptor.ts
2576
2701
  var import_common40 = require("@nestjs/common");
@@ -2615,17 +2740,17 @@ function addCorrelationIdToResponse(reply, correlationId, headerName = DEFAULT_C
2615
2740
  __name(addCorrelationIdToResponse, "addCorrelationIdToResponse");
2616
2741
 
2617
2742
  // src/logger/services/logger.service.ts
2618
- function _ts_decorate14(decorators, target, key, desc) {
2743
+ function _ts_decorate13(decorators, target, key, desc) {
2619
2744
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2620
2745
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2621
2746
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2622
2747
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2623
2748
  }
2624
- __name(_ts_decorate14, "_ts_decorate");
2625
- function _ts_metadata7(k, v) {
2749
+ __name(_ts_decorate13, "_ts_decorate");
2750
+ function _ts_metadata8(k, v) {
2626
2751
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2627
2752
  }
2628
- __name(_ts_metadata7, "_ts_metadata");
2753
+ __name(_ts_metadata8, "_ts_metadata");
2629
2754
  function _ts_param4(paramIndex, decorator) {
2630
2755
  return function(target, key) {
2631
2756
  decorator(target, key, paramIndex);
@@ -2833,29 +2958,29 @@ ${trace}`;
2833
2958
  return childLogger;
2834
2959
  }
2835
2960
  };
2836
- LoggerService = _ts_decorate14([
2961
+ LoggerService = _ts_decorate13([
2837
2962
  (0, import_common39.Injectable)(),
2838
2963
  _ts_param4(0, (0, import_common39.Optional)()),
2839
2964
  _ts_param4(1, (0, import_common39.Optional)()),
2840
- _ts_metadata7("design:type", Function),
2841
- _ts_metadata7("design:paramtypes", [
2965
+ _ts_metadata8("design:type", Function),
2966
+ _ts_metadata8("design:paramtypes", [
2842
2967
  typeof LoggerModuleOptions === "undefined" ? Object : LoggerModuleOptions,
2843
2968
  typeof Logger === "undefined" ? Object : Logger
2844
2969
  ])
2845
2970
  ], LoggerService);
2846
2971
 
2847
2972
  // src/logger/interceptors/http-logger.interceptor.ts
2848
- function _ts_decorate15(decorators, target, key, desc) {
2973
+ function _ts_decorate14(decorators, target, key, desc) {
2849
2974
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2850
2975
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2851
2976
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2852
2977
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2853
2978
  }
2854
- __name(_ts_decorate15, "_ts_decorate");
2855
- function _ts_metadata8(k, v) {
2979
+ __name(_ts_decorate14, "_ts_decorate");
2980
+ function _ts_metadata9(k, v) {
2856
2981
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2857
2982
  }
2858
- __name(_ts_metadata8, "_ts_metadata");
2983
+ __name(_ts_metadata9, "_ts_metadata");
2859
2984
  function _ts_param5(paramIndex, decorator) {
2860
2985
  return function(target, key) {
2861
2986
  decorator(target, key, paramIndex);
@@ -2963,11 +3088,11 @@ var HttpLoggerInterceptor = class {
2963
3088
  }
2964
3089
  }
2965
3090
  };
2966
- HttpLoggerInterceptor = _ts_decorate15([
3091
+ HttpLoggerInterceptor = _ts_decorate14([
2967
3092
  (0, import_common40.Injectable)(),
2968
3093
  _ts_param5(1, (0, import_common40.Optional)()),
2969
- _ts_metadata8("design:type", Function),
2970
- _ts_metadata8("design:paramtypes", [
3094
+ _ts_metadata9("design:type", Function),
3095
+ _ts_metadata9("design:paramtypes", [
2971
3096
  typeof LoggerService === "undefined" ? Object : LoggerService,
2972
3097
  typeof HttpLoggerOptions === "undefined" ? Object : HttpLoggerOptions
2973
3098
  ])
@@ -2978,17 +3103,17 @@ var import_common42 = require("@nestjs/common");
2978
3103
 
2979
3104
  // src/logger/middleware/correlation-id.middleware.ts
2980
3105
  var import_common41 = require("@nestjs/common");
2981
- function _ts_decorate16(decorators, target, key, desc) {
3106
+ function _ts_decorate15(decorators, target, key, desc) {
2982
3107
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2983
3108
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2984
3109
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2985
3110
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2986
3111
  }
2987
- __name(_ts_decorate16, "_ts_decorate");
2988
- function _ts_metadata9(k, v) {
3112
+ __name(_ts_decorate15, "_ts_decorate");
3113
+ function _ts_metadata10(k, v) {
2989
3114
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2990
3115
  }
2991
- __name(_ts_metadata9, "_ts_metadata");
3116
+ __name(_ts_metadata10, "_ts_metadata");
2992
3117
  var CorrelationIdMiddleware = class {
2993
3118
  static {
2994
3119
  __name(this, "CorrelationIdMiddleware");
@@ -3031,22 +3156,22 @@ var CorrelationIdMiddleware = class {
3031
3156
  }
3032
3157
  }
3033
3158
  };
3034
- CorrelationIdMiddleware = _ts_decorate16([
3159
+ CorrelationIdMiddleware = _ts_decorate15([
3035
3160
  (0, import_common41.Injectable)(),
3036
- _ts_metadata9("design:type", Function),
3037
- _ts_metadata9("design:paramtypes", [
3161
+ _ts_metadata10("design:type", Function),
3162
+ _ts_metadata10("design:paramtypes", [
3038
3163
  typeof CorrelationIdMiddlewareOptions === "undefined" ? Object : CorrelationIdMiddlewareOptions
3039
3164
  ])
3040
3165
  ], CorrelationIdMiddleware);
3041
3166
 
3042
3167
  // src/logger/logger.module.ts
3043
- function _ts_decorate17(decorators, target, key, desc) {
3168
+ function _ts_decorate16(decorators, target, key, desc) {
3044
3169
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3045
3170
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3046
3171
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3047
3172
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3048
3173
  }
3049
- __name(_ts_decorate17, "_ts_decorate");
3174
+ __name(_ts_decorate16, "_ts_decorate");
3050
3175
  var LOGGER_MODULE_OPTIONS = Symbol("LOGGER_MODULE_OPTIONS");
3051
3176
  var DEFAULT_LOGGER_OPTIONS = {
3052
3177
  provider: "winston",
@@ -3449,7 +3574,7 @@ var LoggerModule = class _LoggerModule {
3449
3574
  throw new Error("LoggerModule.forRootAsync() requires one of: useFactory, useClass, or useExisting");
3450
3575
  }
3451
3576
  };
3452
- LoggerModule = _ts_decorate17([
3577
+ LoggerModule = _ts_decorate16([
3453
3578
  (0, import_common42.Global)(),
3454
3579
  (0, import_common42.Module)({})
3455
3580
  ], LoggerModule);
@@ -3458,17 +3583,15 @@ LoggerModule = _ts_decorate17([
3458
3583
  AuthConfigModule,
3459
3584
  BadGatewayException,
3460
3585
  BadRequestException,
3461
- BaseFieldException,
3462
3586
  ConflictException,
3463
3587
  CorrelationIdMiddleware,
3464
- CsrfGuard,
3465
3588
  DEFAULT_CORRELATION_HEADER,
3466
3589
  DatabaseModule,
3467
3590
  ForbiddenException,
3468
3591
  GoneException,
3469
3592
  HttpExceptionFilter,
3470
3593
  HttpLoggerInterceptor,
3471
- HttpModule,
3594
+ HttpProblemException,
3472
3595
  InternalServerErrorException,
3473
3596
  LOGGER_MODULE_OPTIONS,
3474
3597
  LoggerModule,
@@ -3483,7 +3606,10 @@ LoggerModule = _ts_decorate17([
3483
3606
  PrimaryDatabaseService,
3484
3607
  Public,
3485
3608
  RequestTimeoutException,
3609
+ SKIP_CSRF_KEY,
3486
3610
  ServiceUnavailableException,
3611
+ SkipCsrf,
3612
+ SseAuthGuard,
3487
3613
  Tenant,
3488
3614
  TenantBaseRepository,
3489
3615
  TenantContextService,
@@ -3499,6 +3625,7 @@ LoggerModule = _ts_decorate17([
3499
3625
  configureApiSdk,
3500
3626
  correlationStorage,
3501
3627
  defineConfig,
3628
+ extractCountryFromPhone,
3502
3629
  generateCorrelationId,
3503
3630
  getConfig,
3504
3631
  getCorrelationContext,
@@ -3506,6 +3633,7 @@ LoggerModule = _ts_decorate17([
3506
3633
  getJwtExpiry,
3507
3634
  getRefreshCookieOptions,
3508
3635
  hashToken,
3636
+ normalizePhoneNumber,
3509
3637
  resetConfig,
3510
3638
  runWithCorrelationContext,
3511
3639
  updateCorrelationContext,