@vritti/api-sdk 0.1.6 → 0.1.7
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 +661 -251
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -21
- package/dist/index.d.ts +75 -21
- package/dist/index.js +523 -117
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/auth/auth-config.module.ts
|
|
5
5
|
import { Global as Global2, Module as Module2 } from "@nestjs/common";
|
|
6
6
|
import { ConfigModule, ConfigService as ConfigService2 } from "@nestjs/config";
|
|
7
|
-
import { APP_GUARD } from "@nestjs/core";
|
|
7
|
+
import { APP_GUARD, Reflector as Reflector2 } from "@nestjs/core";
|
|
8
8
|
import { JwtModule } from "@nestjs/jwt";
|
|
9
9
|
|
|
10
10
|
// src/request/request.module.ts
|
|
@@ -217,11 +217,16 @@ RequestModule = _ts_decorate2([
|
|
|
217
217
|
], RequestModule);
|
|
218
218
|
|
|
219
219
|
// src/auth/guards/vritti-auth.guard.ts
|
|
220
|
-
import { Injectable as Injectable3, Logger as Logger3, Scope as Scope2, UnauthorizedException } from "@nestjs/common";
|
|
220
|
+
import { ForbiddenException, Injectable as Injectable3, Logger as Logger3, Scope as Scope2, UnauthorizedException } from "@nestjs/common";
|
|
221
221
|
import { ConfigService } from "@nestjs/config";
|
|
222
222
|
import { Reflector } from "@nestjs/core";
|
|
223
223
|
import { JwtService } from "@nestjs/jwt";
|
|
224
224
|
|
|
225
|
+
// src/auth/decorators/skip-csrf.decorator.ts
|
|
226
|
+
import { SetMetadata } from "@nestjs/common";
|
|
227
|
+
var SKIP_CSRF_KEY = "skipCsrf";
|
|
228
|
+
var SkipCsrf = /* @__PURE__ */ __name(() => SetMetadata(SKIP_CSRF_KEY, true), "SkipCsrf");
|
|
229
|
+
|
|
225
230
|
// src/database/services/primary-database.service.ts
|
|
226
231
|
import { Inject as Inject2, Injectable as Injectable2, InternalServerErrorException, Logger as Logger2 } from "@nestjs/common";
|
|
227
232
|
import { eq, or } from "drizzle-orm";
|
|
@@ -503,6 +508,14 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
503
508
|
}
|
|
504
509
|
async canActivate(context) {
|
|
505
510
|
const request = context.switchToHttp().getRequest();
|
|
511
|
+
const reply = context.switchToHttp().getResponse();
|
|
512
|
+
const skipCsrf = this.reflector.getAllAndOverride(SKIP_CSRF_KEY, [
|
|
513
|
+
context.getHandler(),
|
|
514
|
+
context.getClass()
|
|
515
|
+
]);
|
|
516
|
+
if (!skipCsrf) {
|
|
517
|
+
await this.validateCsrf(request, reply);
|
|
518
|
+
}
|
|
506
519
|
const isPublic = this.reflector.getAllAndOverride("isPublic", [
|
|
507
520
|
context.getHandler(),
|
|
508
521
|
context.getClass()
|
|
@@ -648,6 +661,52 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
648
661
|
}
|
|
649
662
|
this.logger.debug("Token binding validated successfully");
|
|
650
663
|
}
|
|
664
|
+
/**
|
|
665
|
+
* Validate CSRF token for state-changing requests
|
|
666
|
+
* Uses Fastify's csrf-protection plugin for token validation
|
|
667
|
+
*
|
|
668
|
+
* @param request - Fastify request object
|
|
669
|
+
* @param reply - Fastify reply object
|
|
670
|
+
* @throws ForbiddenException if CSRF validation fails
|
|
671
|
+
*/
|
|
672
|
+
async validateCsrf(request, reply) {
|
|
673
|
+
const safeMethods = [
|
|
674
|
+
"GET",
|
|
675
|
+
"HEAD",
|
|
676
|
+
"OPTIONS"
|
|
677
|
+
];
|
|
678
|
+
if (safeMethods.includes(request.method)) {
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
try {
|
|
682
|
+
const fastifyInstance = request.server;
|
|
683
|
+
if (!fastifyInstance.csrfProtection) {
|
|
684
|
+
this.logger.error("CSRF protection plugin not found. Ensure @fastify/csrf-protection is registered.");
|
|
685
|
+
throw new ForbiddenException("CSRF protection not configured");
|
|
686
|
+
}
|
|
687
|
+
await new Promise((resolve, reject) => {
|
|
688
|
+
fastifyInstance.csrfProtection(request, reply, (err) => {
|
|
689
|
+
if (err) {
|
|
690
|
+
reject(err);
|
|
691
|
+
} else {
|
|
692
|
+
resolve();
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
});
|
|
696
|
+
this.logger.debug(`CSRF validation successful for ${request.method} ${request.url}`);
|
|
697
|
+
} catch (error) {
|
|
698
|
+
this.logger.warn(`CSRF validation failed for ${request.method} ${request.url}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
699
|
+
throw new ForbiddenException({
|
|
700
|
+
errors: [
|
|
701
|
+
{
|
|
702
|
+
field: "csrf",
|
|
703
|
+
message: "Invalid or missing CSRF token"
|
|
704
|
+
}
|
|
705
|
+
],
|
|
706
|
+
message: "CSRF validation failed"
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
}
|
|
651
710
|
};
|
|
652
711
|
VrittiAuthGuard = _ts_decorate4([
|
|
653
712
|
Injectable3({
|
|
@@ -707,6 +766,11 @@ var AuthConfigModule = class _AuthConfigModule {
|
|
|
707
766
|
})
|
|
708
767
|
],
|
|
709
768
|
providers: [
|
|
769
|
+
// Required for external packages - NestJS global Reflector not available
|
|
770
|
+
{
|
|
771
|
+
provide: Reflector2,
|
|
772
|
+
useClass: Reflector2
|
|
773
|
+
},
|
|
710
774
|
{
|
|
711
775
|
provide: APP_GUARD,
|
|
712
776
|
useClass: VrittiAuthGuard
|
|
@@ -724,12 +788,12 @@ AuthConfigModule = _ts_decorate5([
|
|
|
724
788
|
], AuthConfigModule);
|
|
725
789
|
|
|
726
790
|
// src/auth/decorators/onboarding.decorator.ts
|
|
727
|
-
import { SetMetadata } from "@nestjs/common";
|
|
728
|
-
var Onboarding = /* @__PURE__ */ __name(() =>
|
|
791
|
+
import { SetMetadata as SetMetadata2 } from "@nestjs/common";
|
|
792
|
+
var Onboarding = /* @__PURE__ */ __name(() => SetMetadata2("isOnboarding", true), "Onboarding");
|
|
729
793
|
|
|
730
794
|
// src/auth/decorators/public.decorator.ts
|
|
731
|
-
import { SetMetadata as
|
|
732
|
-
var Public = /* @__PURE__ */ __name(() =>
|
|
795
|
+
import { SetMetadata as SetMetadata3 } from "@nestjs/common";
|
|
796
|
+
var Public = /* @__PURE__ */ __name(() => SetMetadata3("isPublic", true), "Public");
|
|
733
797
|
|
|
734
798
|
// src/auth/decorators/user-id.decorator.ts
|
|
735
799
|
import { createParamDecorator } from "@nestjs/common";
|
|
@@ -742,23 +806,123 @@ var UserId = createParamDecorator((_data, ctx) => {
|
|
|
742
806
|
return user.id;
|
|
743
807
|
});
|
|
744
808
|
|
|
809
|
+
// src/auth/guards/sse-auth.guard.ts
|
|
810
|
+
import { Injectable as Injectable4, Logger as Logger4, Scope as Scope3, UnauthorizedException as UnauthorizedException2 } from "@nestjs/common";
|
|
811
|
+
import { JwtService as JwtService2 } from "@nestjs/jwt";
|
|
812
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
813
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
814
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
815
|
+
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;
|
|
816
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
817
|
+
}
|
|
818
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
819
|
+
function _ts_metadata4(k, v) {
|
|
820
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
821
|
+
}
|
|
822
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
823
|
+
var SSE_ALLOWED_ORIGINS = [
|
|
824
|
+
"http://localhost:5173",
|
|
825
|
+
"http://localhost:3001",
|
|
826
|
+
"http://localhost:3012",
|
|
827
|
+
"http://localhost:5174",
|
|
828
|
+
"http://local.vrittiai.com:3012",
|
|
829
|
+
"http://cloud.local.vrittiai.com:3012",
|
|
830
|
+
"https://local.vrittiai.com:3012",
|
|
831
|
+
"https://cloud.local.vrittiai.com:3012"
|
|
832
|
+
];
|
|
833
|
+
var SseAuthGuard = class _SseAuthGuard {
|
|
834
|
+
static {
|
|
835
|
+
__name(this, "SseAuthGuard");
|
|
836
|
+
}
|
|
837
|
+
jwtService;
|
|
838
|
+
logger = new Logger4(_SseAuthGuard.name);
|
|
839
|
+
constructor(jwtService) {
|
|
840
|
+
this.jwtService = jwtService;
|
|
841
|
+
}
|
|
842
|
+
async canActivate(context) {
|
|
843
|
+
const request = context.switchToHttp().getRequest();
|
|
844
|
+
const response = context.switchToHttp().getResponse();
|
|
845
|
+
this.setCorsHeaders(request, response);
|
|
846
|
+
const token = request.query?.token;
|
|
847
|
+
if (!token) {
|
|
848
|
+
this.logger.warn("SSE authentication failed: token not found in query params");
|
|
849
|
+
throw new UnauthorizedException2("Authentication required");
|
|
850
|
+
}
|
|
851
|
+
try {
|
|
852
|
+
const decodedToken = this.jwtService.decode(token);
|
|
853
|
+
if (!decodedToken) {
|
|
854
|
+
this.logger.warn("SSE authentication failed: invalid token format");
|
|
855
|
+
throw new UnauthorizedException2("Invalid token format");
|
|
856
|
+
}
|
|
857
|
+
if (decodedToken.type !== "onboarding") {
|
|
858
|
+
this.logger.warn("SSE authentication failed: endpoint requires onboarding token");
|
|
859
|
+
throw new UnauthorizedException2("This endpoint requires an onboarding token");
|
|
860
|
+
}
|
|
861
|
+
const validatedToken = this.jwtService.verify(token);
|
|
862
|
+
this.logger.debug(`SSE token validated for user: ${validatedToken.userId}`);
|
|
863
|
+
request.user = {
|
|
864
|
+
id: validatedToken.userId
|
|
865
|
+
};
|
|
866
|
+
return true;
|
|
867
|
+
} catch (error) {
|
|
868
|
+
if (error instanceof UnauthorizedException2) {
|
|
869
|
+
throw error;
|
|
870
|
+
}
|
|
871
|
+
const jwtError = error;
|
|
872
|
+
if (jwtError?.name === "TokenExpiredError") {
|
|
873
|
+
this.logger.warn("SSE authentication failed: token expired");
|
|
874
|
+
throw new UnauthorizedException2("Token has expired");
|
|
875
|
+
}
|
|
876
|
+
if (jwtError?.name === "JsonWebTokenError") {
|
|
877
|
+
this.logger.warn(`SSE authentication failed: ${jwtError?.message}`);
|
|
878
|
+
throw new UnauthorizedException2("Invalid token");
|
|
879
|
+
}
|
|
880
|
+
this.logger.error("Unexpected error in SSE auth guard", error);
|
|
881
|
+
throw new UnauthorizedException2("Authentication failed");
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Set CORS headers for SSE responses
|
|
886
|
+
* Must be called before any potential exceptions
|
|
887
|
+
*/
|
|
888
|
+
setCorsHeaders(request, response) {
|
|
889
|
+
const origin = request.headers.origin;
|
|
890
|
+
if (origin && SSE_ALLOWED_ORIGINS.includes(origin)) {
|
|
891
|
+
response.header("Access-Control-Allow-Origin", origin);
|
|
892
|
+
response.header("Access-Control-Allow-Credentials", "true");
|
|
893
|
+
this.logger.debug(`CORS headers set for origin: ${origin}`);
|
|
894
|
+
} else if (origin) {
|
|
895
|
+
this.logger.warn(`SSE request from unauthorized origin: ${origin}`);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
SseAuthGuard = _ts_decorate6([
|
|
900
|
+
Injectable4({
|
|
901
|
+
scope: Scope3.REQUEST
|
|
902
|
+
}),
|
|
903
|
+
_ts_metadata4("design:type", Function),
|
|
904
|
+
_ts_metadata4("design:paramtypes", [
|
|
905
|
+
typeof JwtService2 === "undefined" ? Object : JwtService2
|
|
906
|
+
])
|
|
907
|
+
], SseAuthGuard);
|
|
908
|
+
|
|
745
909
|
// src/database/database.module.ts
|
|
746
910
|
import { Global as Global3, Module as Module3 } from "@nestjs/common";
|
|
747
|
-
import { APP_INTERCEPTOR } from "@nestjs/core";
|
|
911
|
+
import { APP_INTERCEPTOR, Reflector as Reflector4 } from "@nestjs/core";
|
|
748
912
|
|
|
749
913
|
// src/database/interceptors/message-tenant-context.interceptor.ts
|
|
750
|
-
import { Injectable as
|
|
914
|
+
import { Injectable as Injectable6, Logger as Logger5, Scope as Scope5 } from "@nestjs/common";
|
|
751
915
|
import { tap } from "rxjs/operators";
|
|
752
916
|
|
|
753
917
|
// src/database/services/tenant-context.service.ts
|
|
754
|
-
import { Injectable as
|
|
755
|
-
function
|
|
918
|
+
import { Injectable as Injectable5, Scope as Scope4, UnauthorizedException as UnauthorizedException3 } from "@nestjs/common";
|
|
919
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
756
920
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
757
921
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
758
922
|
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;
|
|
759
923
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
760
924
|
}
|
|
761
|
-
__name(
|
|
925
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
762
926
|
var TenantContextService = class {
|
|
763
927
|
static {
|
|
764
928
|
__name(this, "TenantContextService");
|
|
@@ -789,7 +953,7 @@ var TenantContextService = class {
|
|
|
789
953
|
*/
|
|
790
954
|
getTenant() {
|
|
791
955
|
if (!this.tenantInfo) {
|
|
792
|
-
throw new
|
|
956
|
+
throw new UnauthorizedException3("Tenant context not set");
|
|
793
957
|
}
|
|
794
958
|
return this.tenantInfo;
|
|
795
959
|
}
|
|
@@ -830,30 +994,30 @@ var TenantContextService = class {
|
|
|
830
994
|
return this.tenantInfo?.subdomain ?? null;
|
|
831
995
|
}
|
|
832
996
|
};
|
|
833
|
-
TenantContextService =
|
|
834
|
-
|
|
835
|
-
scope:
|
|
997
|
+
TenantContextService = _ts_decorate7([
|
|
998
|
+
Injectable5({
|
|
999
|
+
scope: Scope4.REQUEST
|
|
836
1000
|
})
|
|
837
1001
|
], TenantContextService);
|
|
838
1002
|
|
|
839
1003
|
// src/database/interceptors/message-tenant-context.interceptor.ts
|
|
840
|
-
function
|
|
1004
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
841
1005
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
842
1006
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
843
1007
|
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;
|
|
844
1008
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
845
1009
|
}
|
|
846
|
-
__name(
|
|
847
|
-
function
|
|
1010
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
1011
|
+
function _ts_metadata5(k, v) {
|
|
848
1012
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
849
1013
|
}
|
|
850
|
-
__name(
|
|
1014
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
851
1015
|
var MessageTenantContextInterceptor = class _MessageTenantContextInterceptor {
|
|
852
1016
|
static {
|
|
853
1017
|
__name(this, "MessageTenantContextInterceptor");
|
|
854
1018
|
}
|
|
855
1019
|
tenantContext;
|
|
856
|
-
logger = new
|
|
1020
|
+
logger = new Logger5(_MessageTenantContextInterceptor.name);
|
|
857
1021
|
constructor(tenantContext) {
|
|
858
1022
|
this.tenantContext = tenantContext;
|
|
859
1023
|
}
|
|
@@ -898,30 +1062,30 @@ var MessageTenantContextInterceptor = class _MessageTenantContextInterceptor {
|
|
|
898
1062
|
}
|
|
899
1063
|
}
|
|
900
1064
|
};
|
|
901
|
-
MessageTenantContextInterceptor =
|
|
902
|
-
|
|
903
|
-
scope:
|
|
1065
|
+
MessageTenantContextInterceptor = _ts_decorate8([
|
|
1066
|
+
Injectable6({
|
|
1067
|
+
scope: Scope5.REQUEST
|
|
904
1068
|
}),
|
|
905
|
-
|
|
906
|
-
|
|
1069
|
+
_ts_metadata5("design:type", Function),
|
|
1070
|
+
_ts_metadata5("design:paramtypes", [
|
|
907
1071
|
typeof TenantContextService === "undefined" ? Object : TenantContextService
|
|
908
1072
|
])
|
|
909
1073
|
], MessageTenantContextInterceptor);
|
|
910
1074
|
|
|
911
1075
|
// src/database/interceptors/tenant-context.interceptor.ts
|
|
912
|
-
import { Injectable as
|
|
913
|
-
import { Reflector as
|
|
914
|
-
function
|
|
1076
|
+
import { Injectable as Injectable7, Logger as Logger6, Scope as Scope6, UnauthorizedException as UnauthorizedException4 } from "@nestjs/common";
|
|
1077
|
+
import { Reflector as Reflector3 } from "@nestjs/core";
|
|
1078
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
915
1079
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
916
1080
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
917
1081
|
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;
|
|
918
1082
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
919
1083
|
}
|
|
920
|
-
__name(
|
|
921
|
-
function
|
|
1084
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
1085
|
+
function _ts_metadata6(k, v) {
|
|
922
1086
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
923
1087
|
}
|
|
924
|
-
__name(
|
|
1088
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
925
1089
|
var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
926
1090
|
static {
|
|
927
1091
|
__name(this, "TenantContextInterceptor");
|
|
@@ -930,7 +1094,7 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
|
930
1094
|
tenantContext;
|
|
931
1095
|
primaryDatabase;
|
|
932
1096
|
requestService;
|
|
933
|
-
logger = new
|
|
1097
|
+
logger = new Logger6(_TenantContextInterceptor.name);
|
|
934
1098
|
constructor(reflector, tenantContext, primaryDatabase, requestService) {
|
|
935
1099
|
this.reflector = reflector;
|
|
936
1100
|
this.tenantContext = tenantContext;
|
|
@@ -951,7 +1115,7 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
|
951
1115
|
return next.handle();
|
|
952
1116
|
}
|
|
953
1117
|
if (!tenantIdentifier) {
|
|
954
|
-
throw new
|
|
1118
|
+
throw new UnauthorizedException4("Tenant identifier not found in request");
|
|
955
1119
|
}
|
|
956
1120
|
this.logger.debug(`Tenant identifier extracted: ${tenantIdentifier}`);
|
|
957
1121
|
if (tenantIdentifier === "cloud") {
|
|
@@ -961,11 +1125,11 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
|
961
1125
|
const tenantInfo = await this.primaryDatabase.getTenantInfo(tenantIdentifier);
|
|
962
1126
|
if (!tenantInfo) {
|
|
963
1127
|
this.logger.warn(`Invalid tenant: ${tenantIdentifier}`);
|
|
964
|
-
throw new
|
|
1128
|
+
throw new UnauthorizedException4("Invalid tenant");
|
|
965
1129
|
}
|
|
966
1130
|
if (tenantInfo.status !== "ACTIVE") {
|
|
967
1131
|
this.logger.warn(`Tenant ${tenantIdentifier} has status: ${tenantInfo.status}`);
|
|
968
|
-
throw new
|
|
1132
|
+
throw new UnauthorizedException4(`Tenant is ${tenantInfo.status}`);
|
|
969
1133
|
}
|
|
970
1134
|
this.logger.debug(`Tenant config loaded: ${tenantInfo.subdomain} (${tenantInfo.type})`);
|
|
971
1135
|
this.tenantContext.setTenant(tenantInfo);
|
|
@@ -978,13 +1142,13 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
|
978
1142
|
return next.handle();
|
|
979
1143
|
}
|
|
980
1144
|
};
|
|
981
|
-
TenantContextInterceptor =
|
|
982
|
-
|
|
983
|
-
scope:
|
|
1145
|
+
TenantContextInterceptor = _ts_decorate9([
|
|
1146
|
+
Injectable7({
|
|
1147
|
+
scope: Scope6.REQUEST
|
|
984
1148
|
}),
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
typeof
|
|
1149
|
+
_ts_metadata6("design:type", Function),
|
|
1150
|
+
_ts_metadata6("design:paramtypes", [
|
|
1151
|
+
typeof Reflector3 === "undefined" ? Object : Reflector3,
|
|
988
1152
|
typeof TenantContextService === "undefined" ? Object : TenantContextService,
|
|
989
1153
|
typeof PrimaryDatabaseService === "undefined" ? Object : PrimaryDatabaseService,
|
|
990
1154
|
typeof RequestService === "undefined" ? Object : RequestService
|
|
@@ -992,20 +1156,20 @@ TenantContextInterceptor = _ts_decorate8([
|
|
|
992
1156
|
], TenantContextInterceptor);
|
|
993
1157
|
|
|
994
1158
|
// src/database/services/tenant-database.service.ts
|
|
995
|
-
import { Inject as Inject3, Injectable as
|
|
1159
|
+
import { Inject as Inject3, Injectable as Injectable8, InternalServerErrorException as InternalServerErrorException2, Logger as Logger7 } from "@nestjs/common";
|
|
996
1160
|
import { drizzle as drizzle2 } from "drizzle-orm/node-postgres";
|
|
997
1161
|
import { Pool as Pool2 } from "pg";
|
|
998
|
-
function
|
|
1162
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
999
1163
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1000
1164
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1001
1165
|
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;
|
|
1002
1166
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1003
1167
|
}
|
|
1004
|
-
__name(
|
|
1005
|
-
function
|
|
1168
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
1169
|
+
function _ts_metadata7(k, v) {
|
|
1006
1170
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1007
1171
|
}
|
|
1008
|
-
__name(
|
|
1172
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
1009
1173
|
function _ts_param3(paramIndex, decorator) {
|
|
1010
1174
|
return function(target, key) {
|
|
1011
1175
|
decorator(target, key, paramIndex);
|
|
@@ -1018,7 +1182,7 @@ var TenantDatabaseService = class _TenantDatabaseService {
|
|
|
1018
1182
|
}
|
|
1019
1183
|
options;
|
|
1020
1184
|
tenantContext;
|
|
1021
|
-
logger = new
|
|
1185
|
+
logger = new Logger7(_TenantDatabaseService.name);
|
|
1022
1186
|
/** Connection pool: Map<cacheKey, TenantConnection> */
|
|
1023
1187
|
clients = /* @__PURE__ */ new Map();
|
|
1024
1188
|
/** Track last usage time for idle connection cleanup */
|
|
@@ -1187,24 +1351,24 @@ var TenantDatabaseService = class _TenantDatabaseService {
|
|
|
1187
1351
|
this.logger.log("All database connections closed");
|
|
1188
1352
|
}
|
|
1189
1353
|
};
|
|
1190
|
-
TenantDatabaseService =
|
|
1191
|
-
|
|
1354
|
+
TenantDatabaseService = _ts_decorate10([
|
|
1355
|
+
Injectable8(),
|
|
1192
1356
|
_ts_param3(0, Inject3(DATABASE_MODULE_OPTIONS)),
|
|
1193
|
-
|
|
1194
|
-
|
|
1357
|
+
_ts_metadata7("design:type", Function),
|
|
1358
|
+
_ts_metadata7("design:paramtypes", [
|
|
1195
1359
|
typeof DatabaseModuleOptions === "undefined" ? Object : DatabaseModuleOptions,
|
|
1196
1360
|
typeof TenantContextService === "undefined" ? Object : TenantContextService
|
|
1197
1361
|
])
|
|
1198
1362
|
], TenantDatabaseService);
|
|
1199
1363
|
|
|
1200
1364
|
// src/database/database.module.ts
|
|
1201
|
-
function
|
|
1365
|
+
function _ts_decorate11(decorators, target, key, desc) {
|
|
1202
1366
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1203
1367
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1204
1368
|
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;
|
|
1205
1369
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1206
1370
|
}
|
|
1207
|
-
__name(
|
|
1371
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
1208
1372
|
var DatabaseModule = class _DatabaseModule {
|
|
1209
1373
|
static {
|
|
1210
1374
|
__name(this, "DatabaseModule");
|
|
@@ -1275,6 +1439,11 @@ var DatabaseModule = class _DatabaseModule {
|
|
|
1275
1439
|
inject: options.inject || []
|
|
1276
1440
|
};
|
|
1277
1441
|
const providers = [
|
|
1442
|
+
// Required for external packages - NestJS global Reflector not available
|
|
1443
|
+
{
|
|
1444
|
+
provide: Reflector4,
|
|
1445
|
+
useClass: Reflector4
|
|
1446
|
+
},
|
|
1278
1447
|
asyncProvider,
|
|
1279
1448
|
TenantContextService,
|
|
1280
1449
|
PrimaryDatabaseService,
|
|
@@ -1306,7 +1475,7 @@ var DatabaseModule = class _DatabaseModule {
|
|
|
1306
1475
|
};
|
|
1307
1476
|
}
|
|
1308
1477
|
};
|
|
1309
|
-
DatabaseModule =
|
|
1478
|
+
DatabaseModule = _ts_decorate11([
|
|
1310
1479
|
Global3(),
|
|
1311
1480
|
Module3({})
|
|
1312
1481
|
], DatabaseModule);
|
|
@@ -1323,7 +1492,7 @@ var Tenant = createParamDecorator2((_data, ctx) => {
|
|
|
1323
1492
|
});
|
|
1324
1493
|
|
|
1325
1494
|
// src/database/repositories/primary-base.repository.ts
|
|
1326
|
-
import { Logger as
|
|
1495
|
+
import { Logger as Logger8 } from "@nestjs/common";
|
|
1327
1496
|
import { eq as eq2, getTableName, sql } from "drizzle-orm";
|
|
1328
1497
|
function snakeToCamel(str) {
|
|
1329
1498
|
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
@@ -1394,7 +1563,7 @@ var PrimaryBaseRepository = class {
|
|
|
1394
1563
|
this.table = table;
|
|
1395
1564
|
const dbTableName = getTableName(table);
|
|
1396
1565
|
this.tableName = snakeToCamel(dbTableName);
|
|
1397
|
-
this.logger = new
|
|
1566
|
+
this.logger = new Logger8(this.constructor.name);
|
|
1398
1567
|
this.logger.debug(`Initialized ${this.constructor.name}`);
|
|
1399
1568
|
this.logger.debug(`Table name: '${dbTableName}' -> query key: '${this.tableName}'`);
|
|
1400
1569
|
}
|
|
@@ -1634,7 +1803,7 @@ var PrimaryBaseRepository = class {
|
|
|
1634
1803
|
};
|
|
1635
1804
|
|
|
1636
1805
|
// src/database/repositories/tenant-base.repository.ts
|
|
1637
|
-
import { Logger as
|
|
1806
|
+
import { Logger as Logger9 } from "@nestjs/common";
|
|
1638
1807
|
import { eq as eq3, getTableName as getTableName2, sql as sql2 } from "drizzle-orm";
|
|
1639
1808
|
var TenantBaseRepository = class {
|
|
1640
1809
|
static {
|
|
@@ -1691,7 +1860,7 @@ var TenantBaseRepository = class {
|
|
|
1691
1860
|
this.database = database;
|
|
1692
1861
|
this.table = table;
|
|
1693
1862
|
this.tableName = getTableName2(table);
|
|
1694
|
-
this.logger = new
|
|
1863
|
+
this.logger = new Logger9(this.constructor.name);
|
|
1695
1864
|
this.logger.debug(`Initialized ${this.constructor.name}`);
|
|
1696
1865
|
}
|
|
1697
1866
|
/**
|
|
@@ -2034,7 +2203,7 @@ var ConflictException = class extends BaseFieldException {
|
|
|
2034
2203
|
|
|
2035
2204
|
// src/exceptions/forbidden.exception.ts
|
|
2036
2205
|
import { HttpStatus as HttpStatus5 } from "@nestjs/common";
|
|
2037
|
-
var
|
|
2206
|
+
var ForbiddenException2 = class extends BaseFieldException {
|
|
2038
2207
|
static {
|
|
2039
2208
|
__name(this, "ForbiddenException");
|
|
2040
2209
|
}
|
|
@@ -2243,7 +2412,7 @@ var TooManyRequestsException = class extends BaseFieldException {
|
|
|
2243
2412
|
|
|
2244
2413
|
// src/exceptions/unauthorized.exception.ts
|
|
2245
2414
|
import { HttpStatus as HttpStatus16 } from "@nestjs/common";
|
|
2246
|
-
var
|
|
2415
|
+
var UnauthorizedException5 = class extends BaseFieldException {
|
|
2247
2416
|
static {
|
|
2248
2417
|
__name(this, "UnauthorizedException");
|
|
2249
2418
|
}
|
|
@@ -2310,14 +2479,14 @@ var ValidationException = class extends BaseFieldException {
|
|
|
2310
2479
|
};
|
|
2311
2480
|
|
|
2312
2481
|
// src/filters/http-exception.filter.ts
|
|
2313
|
-
import { Catch, HttpException as HttpException2, HttpStatus as HttpStatus20, Logger as
|
|
2314
|
-
function
|
|
2482
|
+
import { Catch, HttpException as HttpException2, HttpStatus as HttpStatus20, Logger as Logger10 } from "@nestjs/common";
|
|
2483
|
+
function _ts_decorate12(decorators, target, key, desc) {
|
|
2315
2484
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2316
2485
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2317
2486
|
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;
|
|
2318
2487
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2319
2488
|
}
|
|
2320
|
-
__name(
|
|
2489
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
2321
2490
|
function getHttpStatusTitle(status) {
|
|
2322
2491
|
const enumKey = Object.entries(HttpStatus20).find(([key, value]) => value === status && Number.isNaN(Number(key)))?.[0];
|
|
2323
2492
|
if (!enumKey) {
|
|
@@ -2330,7 +2499,7 @@ var HttpExceptionFilter = class _HttpExceptionFilter {
|
|
|
2330
2499
|
static {
|
|
2331
2500
|
__name(this, "HttpExceptionFilter");
|
|
2332
2501
|
}
|
|
2333
|
-
logger = new
|
|
2502
|
+
logger = new Logger10(_HttpExceptionFilter.name);
|
|
2334
2503
|
catch(exception, host) {
|
|
2335
2504
|
const ctx = host.switchToHttp();
|
|
2336
2505
|
const response = ctx.getResponse();
|
|
@@ -2395,25 +2564,45 @@ var HttpExceptionFilter = class _HttpExceptionFilter {
|
|
|
2395
2564
|
response.status(status).send(problemDetails);
|
|
2396
2565
|
}
|
|
2397
2566
|
};
|
|
2398
|
-
HttpExceptionFilter =
|
|
2567
|
+
HttpExceptionFilter = _ts_decorate12([
|
|
2399
2568
|
Catch()
|
|
2400
2569
|
], HttpExceptionFilter);
|
|
2401
2570
|
|
|
2571
|
+
// src/http/http.module.ts
|
|
2572
|
+
import { Module as Module4 } from "@nestjs/common";
|
|
2573
|
+
|
|
2402
2574
|
// src/http/guards/csrf.guard.ts
|
|
2403
|
-
import { ForbiddenException as
|
|
2404
|
-
|
|
2575
|
+
import { ForbiddenException as ForbiddenException3, Injectable as Injectable9, Logger as Logger11 } from "@nestjs/common";
|
|
2576
|
+
import { Reflector as Reflector5 } from "@nestjs/core";
|
|
2577
|
+
function _ts_decorate13(decorators, target, key, desc) {
|
|
2405
2578
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2406
2579
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2407
2580
|
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;
|
|
2408
2581
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2409
2582
|
}
|
|
2410
|
-
__name(
|
|
2583
|
+
__name(_ts_decorate13, "_ts_decorate");
|
|
2584
|
+
function _ts_metadata8(k, v) {
|
|
2585
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2586
|
+
}
|
|
2587
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
2411
2588
|
var CsrfGuard = class _CsrfGuard {
|
|
2412
2589
|
static {
|
|
2413
2590
|
__name(this, "CsrfGuard");
|
|
2414
2591
|
}
|
|
2415
|
-
|
|
2592
|
+
reflector;
|
|
2593
|
+
logger = new Logger11(_CsrfGuard.name);
|
|
2594
|
+
constructor(reflector) {
|
|
2595
|
+
this.reflector = reflector;
|
|
2596
|
+
}
|
|
2416
2597
|
async canActivate(context) {
|
|
2598
|
+
const skipCsrf = this.reflector.getAllAndOverride(SKIP_CSRF_KEY, [
|
|
2599
|
+
context.getHandler(),
|
|
2600
|
+
context.getClass()
|
|
2601
|
+
]);
|
|
2602
|
+
if (skipCsrf) {
|
|
2603
|
+
this.logger.debug("CSRF validation skipped due to @SkipCsrf decorator");
|
|
2604
|
+
return true;
|
|
2605
|
+
}
|
|
2417
2606
|
const request = context.switchToHttp().getRequest();
|
|
2418
2607
|
const reply = context.switchToHttp().getResponse();
|
|
2419
2608
|
const safeMethods = [
|
|
@@ -2428,7 +2617,7 @@ var CsrfGuard = class _CsrfGuard {
|
|
|
2428
2617
|
const fastifyInstance = request.server;
|
|
2429
2618
|
if (!fastifyInstance.csrfProtection) {
|
|
2430
2619
|
this.logger.error("CSRF protection plugin not found. Ensure @fastify/csrf-protection is registered.");
|
|
2431
|
-
throw new
|
|
2620
|
+
throw new ForbiddenException3("CSRF protection not configured");
|
|
2432
2621
|
}
|
|
2433
2622
|
await new Promise((resolve, reject) => {
|
|
2434
2623
|
fastifyInstance.csrfProtection(request, reply, (err) => {
|
|
@@ -2443,7 +2632,7 @@ var CsrfGuard = class _CsrfGuard {
|
|
|
2443
2632
|
return true;
|
|
2444
2633
|
} catch (error) {
|
|
2445
2634
|
this.logger.warn(`CSRF validation failed for ${request.method} ${request.url}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2446
|
-
throw new
|
|
2635
|
+
throw new ForbiddenException3({
|
|
2447
2636
|
errors: [
|
|
2448
2637
|
{
|
|
2449
2638
|
field: "csrf",
|
|
@@ -2455,25 +2644,28 @@ var CsrfGuard = class _CsrfGuard {
|
|
|
2455
2644
|
}
|
|
2456
2645
|
}
|
|
2457
2646
|
};
|
|
2458
|
-
CsrfGuard =
|
|
2459
|
-
|
|
2647
|
+
CsrfGuard = _ts_decorate13([
|
|
2648
|
+
Injectable9(),
|
|
2649
|
+
_ts_metadata8("design:type", Function),
|
|
2650
|
+
_ts_metadata8("design:paramtypes", [
|
|
2651
|
+
typeof Reflector5 === "undefined" ? Object : Reflector5
|
|
2652
|
+
])
|
|
2460
2653
|
], CsrfGuard);
|
|
2461
2654
|
|
|
2462
2655
|
// src/http/http.module.ts
|
|
2463
|
-
|
|
2464
|
-
function _ts_decorate13(decorators, target, key, desc) {
|
|
2656
|
+
function _ts_decorate14(decorators, target, key, desc) {
|
|
2465
2657
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2466
2658
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2467
2659
|
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;
|
|
2468
2660
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2469
2661
|
}
|
|
2470
|
-
__name(
|
|
2662
|
+
__name(_ts_decorate14, "_ts_decorate");
|
|
2471
2663
|
var HttpModule = class {
|
|
2472
2664
|
static {
|
|
2473
2665
|
__name(this, "HttpModule");
|
|
2474
2666
|
}
|
|
2475
2667
|
};
|
|
2476
|
-
HttpModule =
|
|
2668
|
+
HttpModule = _ts_decorate14([
|
|
2477
2669
|
Module4({
|
|
2478
2670
|
providers: [
|
|
2479
2671
|
CsrfGuard
|
|
@@ -2484,12 +2676,222 @@ HttpModule = _ts_decorate13([
|
|
|
2484
2676
|
})
|
|
2485
2677
|
], HttpModule);
|
|
2486
2678
|
|
|
2679
|
+
// src/utils/phone.utils.ts
|
|
2680
|
+
var CALLING_CODE_TO_COUNTRY = {
|
|
2681
|
+
// 3-digit codes
|
|
2682
|
+
"355": "AL",
|
|
2683
|
+
"213": "DZ",
|
|
2684
|
+
"376": "AD",
|
|
2685
|
+
"244": "AO",
|
|
2686
|
+
"672": "AQ",
|
|
2687
|
+
"374": "AM",
|
|
2688
|
+
"297": "AW",
|
|
2689
|
+
"994": "AZ",
|
|
2690
|
+
"973": "BH",
|
|
2691
|
+
"880": "BD",
|
|
2692
|
+
"375": "BY",
|
|
2693
|
+
"501": "BZ",
|
|
2694
|
+
"229": "BJ",
|
|
2695
|
+
"975": "BT",
|
|
2696
|
+
"591": "BO",
|
|
2697
|
+
"387": "BA",
|
|
2698
|
+
"267": "BW",
|
|
2699
|
+
"673": "BN",
|
|
2700
|
+
"359": "BG",
|
|
2701
|
+
"226": "BF",
|
|
2702
|
+
"257": "BI",
|
|
2703
|
+
"855": "KH",
|
|
2704
|
+
"237": "CM",
|
|
2705
|
+
"238": "CV",
|
|
2706
|
+
"236": "CF",
|
|
2707
|
+
"235": "TD",
|
|
2708
|
+
"269": "KM",
|
|
2709
|
+
"242": "CG",
|
|
2710
|
+
"243": "CD",
|
|
2711
|
+
"506": "CR",
|
|
2712
|
+
"385": "HR",
|
|
2713
|
+
"357": "CY",
|
|
2714
|
+
"420": "CZ",
|
|
2715
|
+
"253": "DJ",
|
|
2716
|
+
"593": "EC",
|
|
2717
|
+
"503": "SV",
|
|
2718
|
+
"240": "GQ",
|
|
2719
|
+
"291": "ER",
|
|
2720
|
+
"372": "EE",
|
|
2721
|
+
"251": "ET",
|
|
2722
|
+
"679": "FJ",
|
|
2723
|
+
"358": "FI",
|
|
2724
|
+
"241": "GA",
|
|
2725
|
+
"220": "GM",
|
|
2726
|
+
"995": "GE",
|
|
2727
|
+
"233": "GH",
|
|
2728
|
+
"350": "GI",
|
|
2729
|
+
"299": "GL",
|
|
2730
|
+
"502": "GT",
|
|
2731
|
+
"224": "GN",
|
|
2732
|
+
"245": "GW",
|
|
2733
|
+
"592": "GY",
|
|
2734
|
+
"509": "HT",
|
|
2735
|
+
"504": "HN",
|
|
2736
|
+
"354": "IS",
|
|
2737
|
+
"964": "IQ",
|
|
2738
|
+
"353": "IE",
|
|
2739
|
+
"972": "IL",
|
|
2740
|
+
"225": "CI",
|
|
2741
|
+
"962": "JO",
|
|
2742
|
+
"254": "KE",
|
|
2743
|
+
"686": "KI",
|
|
2744
|
+
"965": "KW",
|
|
2745
|
+
"996": "KG",
|
|
2746
|
+
"856": "LA",
|
|
2747
|
+
"371": "LV",
|
|
2748
|
+
"961": "LB",
|
|
2749
|
+
"266": "LS",
|
|
2750
|
+
"231": "LR",
|
|
2751
|
+
"218": "LY",
|
|
2752
|
+
"423": "LI",
|
|
2753
|
+
"370": "LT",
|
|
2754
|
+
"352": "LU",
|
|
2755
|
+
"389": "MK",
|
|
2756
|
+
"261": "MG",
|
|
2757
|
+
"265": "MW",
|
|
2758
|
+
"960": "MV",
|
|
2759
|
+
"223": "ML",
|
|
2760
|
+
"356": "MT",
|
|
2761
|
+
"692": "MH",
|
|
2762
|
+
"222": "MR",
|
|
2763
|
+
"230": "MU",
|
|
2764
|
+
"262": "YT",
|
|
2765
|
+
"691": "FM",
|
|
2766
|
+
"373": "MD",
|
|
2767
|
+
"377": "MC",
|
|
2768
|
+
"976": "MN",
|
|
2769
|
+
"382": "ME",
|
|
2770
|
+
"258": "MZ",
|
|
2771
|
+
"264": "NA",
|
|
2772
|
+
"674": "NR",
|
|
2773
|
+
"977": "NP",
|
|
2774
|
+
"505": "NI",
|
|
2775
|
+
"227": "NE",
|
|
2776
|
+
"234": "NG",
|
|
2777
|
+
"683": "NU",
|
|
2778
|
+
"968": "OM",
|
|
2779
|
+
"680": "PW",
|
|
2780
|
+
"970": "PS",
|
|
2781
|
+
"507": "PA",
|
|
2782
|
+
"675": "PG",
|
|
2783
|
+
"595": "PY",
|
|
2784
|
+
"351": "PT",
|
|
2785
|
+
"974": "QA",
|
|
2786
|
+
"250": "RW",
|
|
2787
|
+
"685": "WS",
|
|
2788
|
+
"378": "SM",
|
|
2789
|
+
"239": "ST",
|
|
2790
|
+
"966": "SA",
|
|
2791
|
+
"221": "SN",
|
|
2792
|
+
"381": "RS",
|
|
2793
|
+
"248": "SC",
|
|
2794
|
+
"232": "SL",
|
|
2795
|
+
"421": "SK",
|
|
2796
|
+
"386": "SI",
|
|
2797
|
+
"677": "SB",
|
|
2798
|
+
"252": "SO",
|
|
2799
|
+
"211": "SS",
|
|
2800
|
+
"249": "SD",
|
|
2801
|
+
"597": "SR",
|
|
2802
|
+
"268": "SZ",
|
|
2803
|
+
"963": "SY",
|
|
2804
|
+
"992": "TJ",
|
|
2805
|
+
"255": "TZ",
|
|
2806
|
+
"228": "TG",
|
|
2807
|
+
"676": "TO",
|
|
2808
|
+
"216": "TN",
|
|
2809
|
+
"993": "TM",
|
|
2810
|
+
"688": "TV",
|
|
2811
|
+
"256": "UG",
|
|
2812
|
+
"380": "UA",
|
|
2813
|
+
"971": "AE",
|
|
2814
|
+
"598": "UY",
|
|
2815
|
+
"998": "UZ",
|
|
2816
|
+
"678": "VU",
|
|
2817
|
+
"379": "VA",
|
|
2818
|
+
"967": "YE",
|
|
2819
|
+
"260": "ZM",
|
|
2820
|
+
"263": "ZW",
|
|
2821
|
+
// 2-digit codes
|
|
2822
|
+
"93": "AF",
|
|
2823
|
+
"54": "AR",
|
|
2824
|
+
"61": "AU",
|
|
2825
|
+
"43": "AT",
|
|
2826
|
+
"32": "BE",
|
|
2827
|
+
"55": "BR",
|
|
2828
|
+
"56": "CL",
|
|
2829
|
+
"86": "CN",
|
|
2830
|
+
"57": "CO",
|
|
2831
|
+
"53": "CU",
|
|
2832
|
+
"45": "DK",
|
|
2833
|
+
"20": "EG",
|
|
2834
|
+
"33": "FR",
|
|
2835
|
+
"49": "DE",
|
|
2836
|
+
"30": "GR",
|
|
2837
|
+
"36": "HU",
|
|
2838
|
+
"91": "IN",
|
|
2839
|
+
"62": "ID",
|
|
2840
|
+
"98": "IR",
|
|
2841
|
+
"39": "IT",
|
|
2842
|
+
"81": "JP",
|
|
2843
|
+
"82": "KR",
|
|
2844
|
+
"60": "MY",
|
|
2845
|
+
"52": "MX",
|
|
2846
|
+
"31": "NL",
|
|
2847
|
+
"64": "NZ",
|
|
2848
|
+
"47": "NO",
|
|
2849
|
+
"92": "PK",
|
|
2850
|
+
"51": "PE",
|
|
2851
|
+
"63": "PH",
|
|
2852
|
+
"48": "PL",
|
|
2853
|
+
"40": "RO",
|
|
2854
|
+
"65": "SG",
|
|
2855
|
+
"27": "ZA",
|
|
2856
|
+
"34": "ES",
|
|
2857
|
+
"94": "LK",
|
|
2858
|
+
"46": "SE",
|
|
2859
|
+
"41": "CH",
|
|
2860
|
+
"66": "TH",
|
|
2861
|
+
"90": "TR",
|
|
2862
|
+
"44": "GB",
|
|
2863
|
+
"58": "VE",
|
|
2864
|
+
"84": "VN",
|
|
2865
|
+
// 1-digit codes (shared codes default to most common country)
|
|
2866
|
+
"1": "US",
|
|
2867
|
+
"7": "RU"
|
|
2868
|
+
};
|
|
2869
|
+
function extractCountryFromPhone(phone) {
|
|
2870
|
+
const digits = phone.startsWith("+") ? phone.slice(1) : phone;
|
|
2871
|
+
for (const length of [
|
|
2872
|
+
3,
|
|
2873
|
+
2,
|
|
2874
|
+
1
|
|
2875
|
+
]) {
|
|
2876
|
+
const prefix = digits.slice(0, length);
|
|
2877
|
+
if (CALLING_CODE_TO_COUNTRY[prefix]) {
|
|
2878
|
+
return CALLING_CODE_TO_COUNTRY[prefix];
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
return void 0;
|
|
2882
|
+
}
|
|
2883
|
+
__name(extractCountryFromPhone, "extractCountryFromPhone");
|
|
2884
|
+
function normalizePhoneNumber(phone) {
|
|
2885
|
+
return phone.startsWith("+") ? phone : `+${phone}`;
|
|
2886
|
+
}
|
|
2887
|
+
__name(normalizePhoneNumber, "normalizePhoneNumber");
|
|
2888
|
+
|
|
2487
2889
|
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2488
|
-
import { Injectable as
|
|
2890
|
+
import { Injectable as Injectable11, Optional as Optional2 } from "@nestjs/common";
|
|
2489
2891
|
import { catchError, tap as tap2 } from "rxjs/operators";
|
|
2490
2892
|
|
|
2491
2893
|
// src/logger/services/logger.service.ts
|
|
2492
|
-
import { Injectable as
|
|
2894
|
+
import { Injectable as Injectable10, Optional } from "@nestjs/common";
|
|
2493
2895
|
import { createLogger, format, transports } from "winston";
|
|
2494
2896
|
import DailyRotateFile from "winston-daily-rotate-file";
|
|
2495
2897
|
|
|
@@ -2527,17 +2929,17 @@ function addCorrelationIdToResponse(reply, correlationId, headerName = DEFAULT_C
|
|
|
2527
2929
|
__name(addCorrelationIdToResponse, "addCorrelationIdToResponse");
|
|
2528
2930
|
|
|
2529
2931
|
// src/logger/services/logger.service.ts
|
|
2530
|
-
function
|
|
2932
|
+
function _ts_decorate15(decorators, target, key, desc) {
|
|
2531
2933
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2532
2934
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2533
2935
|
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;
|
|
2534
2936
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2535
2937
|
}
|
|
2536
|
-
__name(
|
|
2537
|
-
function
|
|
2938
|
+
__name(_ts_decorate15, "_ts_decorate");
|
|
2939
|
+
function _ts_metadata9(k, v) {
|
|
2538
2940
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2539
2941
|
}
|
|
2540
|
-
__name(
|
|
2942
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
2541
2943
|
function _ts_param4(paramIndex, decorator) {
|
|
2542
2944
|
return function(target, key) {
|
|
2543
2945
|
decorator(target, key, paramIndex);
|
|
@@ -2745,29 +3147,29 @@ ${trace}`;
|
|
|
2745
3147
|
return childLogger;
|
|
2746
3148
|
}
|
|
2747
3149
|
};
|
|
2748
|
-
LoggerService =
|
|
2749
|
-
|
|
3150
|
+
LoggerService = _ts_decorate15([
|
|
3151
|
+
Injectable10(),
|
|
2750
3152
|
_ts_param4(0, Optional()),
|
|
2751
3153
|
_ts_param4(1, Optional()),
|
|
2752
|
-
|
|
2753
|
-
|
|
3154
|
+
_ts_metadata9("design:type", Function),
|
|
3155
|
+
_ts_metadata9("design:paramtypes", [
|
|
2754
3156
|
typeof LoggerModuleOptions === "undefined" ? Object : LoggerModuleOptions,
|
|
2755
3157
|
typeof Logger === "undefined" ? Object : Logger
|
|
2756
3158
|
])
|
|
2757
3159
|
], LoggerService);
|
|
2758
3160
|
|
|
2759
3161
|
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2760
|
-
function
|
|
3162
|
+
function _ts_decorate16(decorators, target, key, desc) {
|
|
2761
3163
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2762
3164
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2763
3165
|
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;
|
|
2764
3166
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2765
3167
|
}
|
|
2766
|
-
__name(
|
|
2767
|
-
function
|
|
3168
|
+
__name(_ts_decorate16, "_ts_decorate");
|
|
3169
|
+
function _ts_metadata10(k, v) {
|
|
2768
3170
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2769
3171
|
}
|
|
2770
|
-
__name(
|
|
3172
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
2771
3173
|
function _ts_param5(paramIndex, decorator) {
|
|
2772
3174
|
return function(target, key) {
|
|
2773
3175
|
decorator(target, key, paramIndex);
|
|
@@ -2875,32 +3277,32 @@ var HttpLoggerInterceptor = class {
|
|
|
2875
3277
|
}
|
|
2876
3278
|
}
|
|
2877
3279
|
};
|
|
2878
|
-
HttpLoggerInterceptor =
|
|
2879
|
-
|
|
3280
|
+
HttpLoggerInterceptor = _ts_decorate16([
|
|
3281
|
+
Injectable11(),
|
|
2880
3282
|
_ts_param5(1, Optional2()),
|
|
2881
|
-
|
|
2882
|
-
|
|
3283
|
+
_ts_metadata10("design:type", Function),
|
|
3284
|
+
_ts_metadata10("design:paramtypes", [
|
|
2883
3285
|
typeof LoggerService === "undefined" ? Object : LoggerService,
|
|
2884
3286
|
typeof HttpLoggerOptions === "undefined" ? Object : HttpLoggerOptions
|
|
2885
3287
|
])
|
|
2886
3288
|
], HttpLoggerInterceptor);
|
|
2887
3289
|
|
|
2888
3290
|
// src/logger/logger.module.ts
|
|
2889
|
-
import { Global as Global4, Logger as
|
|
3291
|
+
import { Global as Global4, Logger as Logger12, Module as Module5 } from "@nestjs/common";
|
|
2890
3292
|
|
|
2891
3293
|
// src/logger/middleware/correlation-id.middleware.ts
|
|
2892
|
-
import { Injectable as
|
|
2893
|
-
function
|
|
3294
|
+
import { Injectable as Injectable12 } from "@nestjs/common";
|
|
3295
|
+
function _ts_decorate17(decorators, target, key, desc) {
|
|
2894
3296
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2895
3297
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2896
3298
|
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;
|
|
2897
3299
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2898
3300
|
}
|
|
2899
|
-
__name(
|
|
2900
|
-
function
|
|
3301
|
+
__name(_ts_decorate17, "_ts_decorate");
|
|
3302
|
+
function _ts_metadata11(k, v) {
|
|
2901
3303
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2902
3304
|
}
|
|
2903
|
-
__name(
|
|
3305
|
+
__name(_ts_metadata11, "_ts_metadata");
|
|
2904
3306
|
var CorrelationIdMiddleware = class {
|
|
2905
3307
|
static {
|
|
2906
3308
|
__name(this, "CorrelationIdMiddleware");
|
|
@@ -2943,22 +3345,22 @@ var CorrelationIdMiddleware = class {
|
|
|
2943
3345
|
}
|
|
2944
3346
|
}
|
|
2945
3347
|
};
|
|
2946
|
-
CorrelationIdMiddleware =
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
3348
|
+
CorrelationIdMiddleware = _ts_decorate17([
|
|
3349
|
+
Injectable12(),
|
|
3350
|
+
_ts_metadata11("design:type", Function),
|
|
3351
|
+
_ts_metadata11("design:paramtypes", [
|
|
2950
3352
|
typeof CorrelationIdMiddlewareOptions === "undefined" ? Object : CorrelationIdMiddlewareOptions
|
|
2951
3353
|
])
|
|
2952
3354
|
], CorrelationIdMiddleware);
|
|
2953
3355
|
|
|
2954
3356
|
// src/logger/logger.module.ts
|
|
2955
|
-
function
|
|
3357
|
+
function _ts_decorate18(decorators, target, key, desc) {
|
|
2956
3358
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2957
3359
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2958
3360
|
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;
|
|
2959
3361
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2960
3362
|
}
|
|
2961
|
-
__name(
|
|
3363
|
+
__name(_ts_decorate18, "_ts_decorate");
|
|
2962
3364
|
var LOGGER_MODULE_OPTIONS = Symbol("LOGGER_MODULE_OPTIONS");
|
|
2963
3365
|
var DEFAULT_LOGGER_OPTIONS = {
|
|
2964
3366
|
provider: "winston",
|
|
@@ -3047,9 +3449,9 @@ function mergeWithDefaults(options = {}) {
|
|
|
3047
3449
|
__name(mergeWithDefaults, "mergeWithDefaults");
|
|
3048
3450
|
function createDefaultLoggerProvider(options) {
|
|
3049
3451
|
return {
|
|
3050
|
-
provide:
|
|
3452
|
+
provide: Logger12,
|
|
3051
3453
|
useFactory: /* @__PURE__ */ __name(() => {
|
|
3052
|
-
const logger = new
|
|
3454
|
+
const logger = new Logger12();
|
|
3053
3455
|
if (options.level && typeof logger.setLogLevels === "function") {
|
|
3054
3456
|
const levels = getLevelsUpTo(options.level);
|
|
3055
3457
|
logger.setLogLevels(levels);
|
|
@@ -3079,7 +3481,7 @@ function createLoggerProviders(options = {}) {
|
|
|
3079
3481
|
inject: [
|
|
3080
3482
|
LOGGER_MODULE_OPTIONS,
|
|
3081
3483
|
{
|
|
3082
|
-
token:
|
|
3484
|
+
token: Logger12,
|
|
3083
3485
|
optional: true
|
|
3084
3486
|
}
|
|
3085
3487
|
]
|
|
@@ -3230,10 +3632,10 @@ var LoggerModule = class _LoggerModule {
|
|
|
3230
3632
|
...asyncProviders,
|
|
3231
3633
|
// Default logger provider
|
|
3232
3634
|
{
|
|
3233
|
-
provide:
|
|
3635
|
+
provide: Logger12,
|
|
3234
3636
|
useFactory: /* @__PURE__ */ __name((opts) => {
|
|
3235
3637
|
if (opts.provider === "default") {
|
|
3236
|
-
const logger = new
|
|
3638
|
+
const logger = new Logger12();
|
|
3237
3639
|
if (opts.level && typeof logger.setLogLevels === "function") {
|
|
3238
3640
|
const levels = getLevelsUpTo(opts.level);
|
|
3239
3641
|
logger.setLogLevels(levels);
|
|
@@ -3255,7 +3657,7 @@ var LoggerModule = class _LoggerModule {
|
|
|
3255
3657
|
inject: [
|
|
3256
3658
|
LOGGER_MODULE_OPTIONS,
|
|
3257
3659
|
{
|
|
3258
|
-
token:
|
|
3660
|
+
token: Logger12,
|
|
3259
3661
|
optional: true
|
|
3260
3662
|
}
|
|
3261
3663
|
]
|
|
@@ -3361,7 +3763,7 @@ var LoggerModule = class _LoggerModule {
|
|
|
3361
3763
|
throw new Error("LoggerModule.forRootAsync() requires one of: useFactory, useClass, or useExisting");
|
|
3362
3764
|
}
|
|
3363
3765
|
};
|
|
3364
|
-
LoggerModule =
|
|
3766
|
+
LoggerModule = _ts_decorate18([
|
|
3365
3767
|
Global4(),
|
|
3366
3768
|
Module5({})
|
|
3367
3769
|
], LoggerModule);
|
|
@@ -3372,10 +3774,9 @@ export {
|
|
|
3372
3774
|
BaseFieldException,
|
|
3373
3775
|
ConflictException,
|
|
3374
3776
|
CorrelationIdMiddleware,
|
|
3375
|
-
CsrfGuard,
|
|
3376
3777
|
DEFAULT_CORRELATION_HEADER,
|
|
3377
3778
|
DatabaseModule,
|
|
3378
|
-
ForbiddenException,
|
|
3779
|
+
ForbiddenException2 as ForbiddenException,
|
|
3379
3780
|
GoneException,
|
|
3380
3781
|
HttpExceptionFilter,
|
|
3381
3782
|
HttpLoggerInterceptor,
|
|
@@ -3394,13 +3795,16 @@ export {
|
|
|
3394
3795
|
PrimaryDatabaseService,
|
|
3395
3796
|
Public,
|
|
3396
3797
|
RequestTimeoutException,
|
|
3798
|
+
SKIP_CSRF_KEY,
|
|
3397
3799
|
ServiceUnavailableException,
|
|
3800
|
+
SkipCsrf,
|
|
3801
|
+
SseAuthGuard,
|
|
3398
3802
|
Tenant,
|
|
3399
3803
|
TenantBaseRepository,
|
|
3400
3804
|
TenantContextService,
|
|
3401
3805
|
TenantDatabaseService,
|
|
3402
3806
|
TooManyRequestsException,
|
|
3403
|
-
|
|
3807
|
+
UnauthorizedException5 as UnauthorizedException,
|
|
3404
3808
|
UnprocessableEntityException,
|
|
3405
3809
|
UnsupportedMediaTypeException,
|
|
3406
3810
|
UserId,
|
|
@@ -3410,6 +3814,7 @@ export {
|
|
|
3410
3814
|
configureApiSdk,
|
|
3411
3815
|
correlationStorage,
|
|
3412
3816
|
defineConfig,
|
|
3817
|
+
extractCountryFromPhone,
|
|
3413
3818
|
generateCorrelationId,
|
|
3414
3819
|
getConfig,
|
|
3415
3820
|
getCorrelationContext,
|
|
@@ -3417,6 +3822,7 @@ export {
|
|
|
3417
3822
|
getJwtExpiry,
|
|
3418
3823
|
getRefreshCookieOptions,
|
|
3419
3824
|
hashToken,
|
|
3825
|
+
normalizePhoneNumber,
|
|
3420
3826
|
resetConfig,
|
|
3421
3827
|
runWithCorrelationContext,
|
|
3422
3828
|
updateCorrelationContext,
|