@vritti/api-sdk 0.1.5 → 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 +668 -253
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +82 -28
- package/dist/index.d.ts +82 -28
- package/dist/index.js +530 -119
- 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
|
|
@@ -21,7 +21,8 @@ var defaultConfig = {
|
|
|
21
21
|
refreshCookieMaxAge: 30 * 24 * 60 * 60 * 1e3,
|
|
22
22
|
refreshCookiePath: "/",
|
|
23
23
|
refreshCookieSecure: process.env.NODE_ENV === "production",
|
|
24
|
-
refreshCookieSameSite: "strict"
|
|
24
|
+
refreshCookieSameSite: "strict",
|
|
25
|
+
refreshCookieDomain: "localhost"
|
|
25
26
|
},
|
|
26
27
|
jwt: {
|
|
27
28
|
accessTokenExpiry: "15m",
|
|
@@ -70,13 +71,17 @@ function resetConfig() {
|
|
|
70
71
|
}
|
|
71
72
|
__name(resetConfig, "resetConfig");
|
|
72
73
|
function getRefreshCookieOptions() {
|
|
73
|
-
|
|
74
|
+
const options = {
|
|
74
75
|
httpOnly: true,
|
|
75
76
|
secure: currentConfig.cookie.refreshCookieSecure,
|
|
76
77
|
sameSite: currentConfig.cookie.refreshCookieSameSite,
|
|
77
78
|
path: currentConfig.cookie.refreshCookiePath,
|
|
78
79
|
maxAge: currentConfig.cookie.refreshCookieMaxAge
|
|
79
80
|
};
|
|
81
|
+
if (currentConfig.cookie.refreshCookieDomain) {
|
|
82
|
+
options.domain = currentConfig.cookie.refreshCookieDomain;
|
|
83
|
+
}
|
|
84
|
+
return options;
|
|
80
85
|
}
|
|
81
86
|
__name(getRefreshCookieOptions, "getRefreshCookieOptions");
|
|
82
87
|
function getJwtExpiry() {
|
|
@@ -212,11 +217,16 @@ RequestModule = _ts_decorate2([
|
|
|
212
217
|
], RequestModule);
|
|
213
218
|
|
|
214
219
|
// src/auth/guards/vritti-auth.guard.ts
|
|
215
|
-
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";
|
|
216
221
|
import { ConfigService } from "@nestjs/config";
|
|
217
222
|
import { Reflector } from "@nestjs/core";
|
|
218
223
|
import { JwtService } from "@nestjs/jwt";
|
|
219
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
|
+
|
|
220
230
|
// src/database/services/primary-database.service.ts
|
|
221
231
|
import { Inject as Inject2, Injectable as Injectable2, InternalServerErrorException, Logger as Logger2 } from "@nestjs/common";
|
|
222
232
|
import { eq, or } from "drizzle-orm";
|
|
@@ -498,6 +508,14 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
498
508
|
}
|
|
499
509
|
async canActivate(context) {
|
|
500
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
|
+
}
|
|
501
519
|
const isPublic = this.reflector.getAllAndOverride("isPublic", [
|
|
502
520
|
context.getHandler(),
|
|
503
521
|
context.getClass()
|
|
@@ -643,6 +661,52 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
643
661
|
}
|
|
644
662
|
this.logger.debug("Token binding validated successfully");
|
|
645
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
|
+
}
|
|
646
710
|
};
|
|
647
711
|
VrittiAuthGuard = _ts_decorate4([
|
|
648
712
|
Injectable3({
|
|
@@ -702,6 +766,11 @@ var AuthConfigModule = class _AuthConfigModule {
|
|
|
702
766
|
})
|
|
703
767
|
],
|
|
704
768
|
providers: [
|
|
769
|
+
// Required for external packages - NestJS global Reflector not available
|
|
770
|
+
{
|
|
771
|
+
provide: Reflector2,
|
|
772
|
+
useClass: Reflector2
|
|
773
|
+
},
|
|
705
774
|
{
|
|
706
775
|
provide: APP_GUARD,
|
|
707
776
|
useClass: VrittiAuthGuard
|
|
@@ -719,12 +788,12 @@ AuthConfigModule = _ts_decorate5([
|
|
|
719
788
|
], AuthConfigModule);
|
|
720
789
|
|
|
721
790
|
// src/auth/decorators/onboarding.decorator.ts
|
|
722
|
-
import { SetMetadata } from "@nestjs/common";
|
|
723
|
-
var Onboarding = /* @__PURE__ */ __name(() =>
|
|
791
|
+
import { SetMetadata as SetMetadata2 } from "@nestjs/common";
|
|
792
|
+
var Onboarding = /* @__PURE__ */ __name(() => SetMetadata2("isOnboarding", true), "Onboarding");
|
|
724
793
|
|
|
725
794
|
// src/auth/decorators/public.decorator.ts
|
|
726
|
-
import { SetMetadata as
|
|
727
|
-
var Public = /* @__PURE__ */ __name(() =>
|
|
795
|
+
import { SetMetadata as SetMetadata3 } from "@nestjs/common";
|
|
796
|
+
var Public = /* @__PURE__ */ __name(() => SetMetadata3("isPublic", true), "Public");
|
|
728
797
|
|
|
729
798
|
// src/auth/decorators/user-id.decorator.ts
|
|
730
799
|
import { createParamDecorator } from "@nestjs/common";
|
|
@@ -737,23 +806,123 @@ var UserId = createParamDecorator((_data, ctx) => {
|
|
|
737
806
|
return user.id;
|
|
738
807
|
});
|
|
739
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
|
+
|
|
740
909
|
// src/database/database.module.ts
|
|
741
910
|
import { Global as Global3, Module as Module3 } from "@nestjs/common";
|
|
742
|
-
import { APP_INTERCEPTOR } from "@nestjs/core";
|
|
911
|
+
import { APP_INTERCEPTOR, Reflector as Reflector4 } from "@nestjs/core";
|
|
743
912
|
|
|
744
913
|
// src/database/interceptors/message-tenant-context.interceptor.ts
|
|
745
|
-
import { Injectable as
|
|
914
|
+
import { Injectable as Injectable6, Logger as Logger5, Scope as Scope5 } from "@nestjs/common";
|
|
746
915
|
import { tap } from "rxjs/operators";
|
|
747
916
|
|
|
748
917
|
// src/database/services/tenant-context.service.ts
|
|
749
|
-
import { Injectable as
|
|
750
|
-
function
|
|
918
|
+
import { Injectable as Injectable5, Scope as Scope4, UnauthorizedException as UnauthorizedException3 } from "@nestjs/common";
|
|
919
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
751
920
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
752
921
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
753
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;
|
|
754
923
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
755
924
|
}
|
|
756
|
-
__name(
|
|
925
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
757
926
|
var TenantContextService = class {
|
|
758
927
|
static {
|
|
759
928
|
__name(this, "TenantContextService");
|
|
@@ -784,7 +953,7 @@ var TenantContextService = class {
|
|
|
784
953
|
*/
|
|
785
954
|
getTenant() {
|
|
786
955
|
if (!this.tenantInfo) {
|
|
787
|
-
throw new
|
|
956
|
+
throw new UnauthorizedException3("Tenant context not set");
|
|
788
957
|
}
|
|
789
958
|
return this.tenantInfo;
|
|
790
959
|
}
|
|
@@ -825,30 +994,30 @@ var TenantContextService = class {
|
|
|
825
994
|
return this.tenantInfo?.subdomain ?? null;
|
|
826
995
|
}
|
|
827
996
|
};
|
|
828
|
-
TenantContextService =
|
|
829
|
-
|
|
830
|
-
scope:
|
|
997
|
+
TenantContextService = _ts_decorate7([
|
|
998
|
+
Injectable5({
|
|
999
|
+
scope: Scope4.REQUEST
|
|
831
1000
|
})
|
|
832
1001
|
], TenantContextService);
|
|
833
1002
|
|
|
834
1003
|
// src/database/interceptors/message-tenant-context.interceptor.ts
|
|
835
|
-
function
|
|
1004
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
836
1005
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
837
1006
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
838
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;
|
|
839
1008
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
840
1009
|
}
|
|
841
|
-
__name(
|
|
842
|
-
function
|
|
1010
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
1011
|
+
function _ts_metadata5(k, v) {
|
|
843
1012
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
844
1013
|
}
|
|
845
|
-
__name(
|
|
1014
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
846
1015
|
var MessageTenantContextInterceptor = class _MessageTenantContextInterceptor {
|
|
847
1016
|
static {
|
|
848
1017
|
__name(this, "MessageTenantContextInterceptor");
|
|
849
1018
|
}
|
|
850
1019
|
tenantContext;
|
|
851
|
-
logger = new
|
|
1020
|
+
logger = new Logger5(_MessageTenantContextInterceptor.name);
|
|
852
1021
|
constructor(tenantContext) {
|
|
853
1022
|
this.tenantContext = tenantContext;
|
|
854
1023
|
}
|
|
@@ -893,30 +1062,30 @@ var MessageTenantContextInterceptor = class _MessageTenantContextInterceptor {
|
|
|
893
1062
|
}
|
|
894
1063
|
}
|
|
895
1064
|
};
|
|
896
|
-
MessageTenantContextInterceptor =
|
|
897
|
-
|
|
898
|
-
scope:
|
|
1065
|
+
MessageTenantContextInterceptor = _ts_decorate8([
|
|
1066
|
+
Injectable6({
|
|
1067
|
+
scope: Scope5.REQUEST
|
|
899
1068
|
}),
|
|
900
|
-
|
|
901
|
-
|
|
1069
|
+
_ts_metadata5("design:type", Function),
|
|
1070
|
+
_ts_metadata5("design:paramtypes", [
|
|
902
1071
|
typeof TenantContextService === "undefined" ? Object : TenantContextService
|
|
903
1072
|
])
|
|
904
1073
|
], MessageTenantContextInterceptor);
|
|
905
1074
|
|
|
906
1075
|
// src/database/interceptors/tenant-context.interceptor.ts
|
|
907
|
-
import { Injectable as
|
|
908
|
-
import { Reflector as
|
|
909
|
-
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) {
|
|
910
1079
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
911
1080
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
912
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;
|
|
913
1082
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
914
1083
|
}
|
|
915
|
-
__name(
|
|
916
|
-
function
|
|
1084
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
1085
|
+
function _ts_metadata6(k, v) {
|
|
917
1086
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
918
1087
|
}
|
|
919
|
-
__name(
|
|
1088
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
920
1089
|
var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
921
1090
|
static {
|
|
922
1091
|
__name(this, "TenantContextInterceptor");
|
|
@@ -925,7 +1094,7 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
|
925
1094
|
tenantContext;
|
|
926
1095
|
primaryDatabase;
|
|
927
1096
|
requestService;
|
|
928
|
-
logger = new
|
|
1097
|
+
logger = new Logger6(_TenantContextInterceptor.name);
|
|
929
1098
|
constructor(reflector, tenantContext, primaryDatabase, requestService) {
|
|
930
1099
|
this.reflector = reflector;
|
|
931
1100
|
this.tenantContext = tenantContext;
|
|
@@ -946,7 +1115,7 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
|
946
1115
|
return next.handle();
|
|
947
1116
|
}
|
|
948
1117
|
if (!tenantIdentifier) {
|
|
949
|
-
throw new
|
|
1118
|
+
throw new UnauthorizedException4("Tenant identifier not found in request");
|
|
950
1119
|
}
|
|
951
1120
|
this.logger.debug(`Tenant identifier extracted: ${tenantIdentifier}`);
|
|
952
1121
|
if (tenantIdentifier === "cloud") {
|
|
@@ -956,11 +1125,11 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
|
956
1125
|
const tenantInfo = await this.primaryDatabase.getTenantInfo(tenantIdentifier);
|
|
957
1126
|
if (!tenantInfo) {
|
|
958
1127
|
this.logger.warn(`Invalid tenant: ${tenantIdentifier}`);
|
|
959
|
-
throw new
|
|
1128
|
+
throw new UnauthorizedException4("Invalid tenant");
|
|
960
1129
|
}
|
|
961
1130
|
if (tenantInfo.status !== "ACTIVE") {
|
|
962
1131
|
this.logger.warn(`Tenant ${tenantIdentifier} has status: ${tenantInfo.status}`);
|
|
963
|
-
throw new
|
|
1132
|
+
throw new UnauthorizedException4(`Tenant is ${tenantInfo.status}`);
|
|
964
1133
|
}
|
|
965
1134
|
this.logger.debug(`Tenant config loaded: ${tenantInfo.subdomain} (${tenantInfo.type})`);
|
|
966
1135
|
this.tenantContext.setTenant(tenantInfo);
|
|
@@ -973,13 +1142,13 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
|
973
1142
|
return next.handle();
|
|
974
1143
|
}
|
|
975
1144
|
};
|
|
976
|
-
TenantContextInterceptor =
|
|
977
|
-
|
|
978
|
-
scope:
|
|
1145
|
+
TenantContextInterceptor = _ts_decorate9([
|
|
1146
|
+
Injectable7({
|
|
1147
|
+
scope: Scope6.REQUEST
|
|
979
1148
|
}),
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
typeof
|
|
1149
|
+
_ts_metadata6("design:type", Function),
|
|
1150
|
+
_ts_metadata6("design:paramtypes", [
|
|
1151
|
+
typeof Reflector3 === "undefined" ? Object : Reflector3,
|
|
983
1152
|
typeof TenantContextService === "undefined" ? Object : TenantContextService,
|
|
984
1153
|
typeof PrimaryDatabaseService === "undefined" ? Object : PrimaryDatabaseService,
|
|
985
1154
|
typeof RequestService === "undefined" ? Object : RequestService
|
|
@@ -987,20 +1156,20 @@ TenantContextInterceptor = _ts_decorate8([
|
|
|
987
1156
|
], TenantContextInterceptor);
|
|
988
1157
|
|
|
989
1158
|
// src/database/services/tenant-database.service.ts
|
|
990
|
-
import { Inject as Inject3, Injectable as
|
|
1159
|
+
import { Inject as Inject3, Injectable as Injectable8, InternalServerErrorException as InternalServerErrorException2, Logger as Logger7 } from "@nestjs/common";
|
|
991
1160
|
import { drizzle as drizzle2 } from "drizzle-orm/node-postgres";
|
|
992
1161
|
import { Pool as Pool2 } from "pg";
|
|
993
|
-
function
|
|
1162
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
994
1163
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
995
1164
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
996
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;
|
|
997
1166
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
998
1167
|
}
|
|
999
|
-
__name(
|
|
1000
|
-
function
|
|
1168
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
1169
|
+
function _ts_metadata7(k, v) {
|
|
1001
1170
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1002
1171
|
}
|
|
1003
|
-
__name(
|
|
1172
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
1004
1173
|
function _ts_param3(paramIndex, decorator) {
|
|
1005
1174
|
return function(target, key) {
|
|
1006
1175
|
decorator(target, key, paramIndex);
|
|
@@ -1013,7 +1182,7 @@ var TenantDatabaseService = class _TenantDatabaseService {
|
|
|
1013
1182
|
}
|
|
1014
1183
|
options;
|
|
1015
1184
|
tenantContext;
|
|
1016
|
-
logger = new
|
|
1185
|
+
logger = new Logger7(_TenantDatabaseService.name);
|
|
1017
1186
|
/** Connection pool: Map<cacheKey, TenantConnection> */
|
|
1018
1187
|
clients = /* @__PURE__ */ new Map();
|
|
1019
1188
|
/** Track last usage time for idle connection cleanup */
|
|
@@ -1182,24 +1351,24 @@ var TenantDatabaseService = class _TenantDatabaseService {
|
|
|
1182
1351
|
this.logger.log("All database connections closed");
|
|
1183
1352
|
}
|
|
1184
1353
|
};
|
|
1185
|
-
TenantDatabaseService =
|
|
1186
|
-
|
|
1354
|
+
TenantDatabaseService = _ts_decorate10([
|
|
1355
|
+
Injectable8(),
|
|
1187
1356
|
_ts_param3(0, Inject3(DATABASE_MODULE_OPTIONS)),
|
|
1188
|
-
|
|
1189
|
-
|
|
1357
|
+
_ts_metadata7("design:type", Function),
|
|
1358
|
+
_ts_metadata7("design:paramtypes", [
|
|
1190
1359
|
typeof DatabaseModuleOptions === "undefined" ? Object : DatabaseModuleOptions,
|
|
1191
1360
|
typeof TenantContextService === "undefined" ? Object : TenantContextService
|
|
1192
1361
|
])
|
|
1193
1362
|
], TenantDatabaseService);
|
|
1194
1363
|
|
|
1195
1364
|
// src/database/database.module.ts
|
|
1196
|
-
function
|
|
1365
|
+
function _ts_decorate11(decorators, target, key, desc) {
|
|
1197
1366
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1198
1367
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1199
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;
|
|
1200
1369
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1201
1370
|
}
|
|
1202
|
-
__name(
|
|
1371
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
1203
1372
|
var DatabaseModule = class _DatabaseModule {
|
|
1204
1373
|
static {
|
|
1205
1374
|
__name(this, "DatabaseModule");
|
|
@@ -1270,6 +1439,11 @@ var DatabaseModule = class _DatabaseModule {
|
|
|
1270
1439
|
inject: options.inject || []
|
|
1271
1440
|
};
|
|
1272
1441
|
const providers = [
|
|
1442
|
+
// Required for external packages - NestJS global Reflector not available
|
|
1443
|
+
{
|
|
1444
|
+
provide: Reflector4,
|
|
1445
|
+
useClass: Reflector4
|
|
1446
|
+
},
|
|
1273
1447
|
asyncProvider,
|
|
1274
1448
|
TenantContextService,
|
|
1275
1449
|
PrimaryDatabaseService,
|
|
@@ -1301,7 +1475,7 @@ var DatabaseModule = class _DatabaseModule {
|
|
|
1301
1475
|
};
|
|
1302
1476
|
}
|
|
1303
1477
|
};
|
|
1304
|
-
DatabaseModule =
|
|
1478
|
+
DatabaseModule = _ts_decorate11([
|
|
1305
1479
|
Global3(),
|
|
1306
1480
|
Module3({})
|
|
1307
1481
|
], DatabaseModule);
|
|
@@ -1318,7 +1492,7 @@ var Tenant = createParamDecorator2((_data, ctx) => {
|
|
|
1318
1492
|
});
|
|
1319
1493
|
|
|
1320
1494
|
// src/database/repositories/primary-base.repository.ts
|
|
1321
|
-
import { Logger as
|
|
1495
|
+
import { Logger as Logger8 } from "@nestjs/common";
|
|
1322
1496
|
import { eq as eq2, getTableName, sql } from "drizzle-orm";
|
|
1323
1497
|
function snakeToCamel(str) {
|
|
1324
1498
|
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
@@ -1389,7 +1563,7 @@ var PrimaryBaseRepository = class {
|
|
|
1389
1563
|
this.table = table;
|
|
1390
1564
|
const dbTableName = getTableName(table);
|
|
1391
1565
|
this.tableName = snakeToCamel(dbTableName);
|
|
1392
|
-
this.logger = new
|
|
1566
|
+
this.logger = new Logger8(this.constructor.name);
|
|
1393
1567
|
this.logger.debug(`Initialized ${this.constructor.name}`);
|
|
1394
1568
|
this.logger.debug(`Table name: '${dbTableName}' -> query key: '${this.tableName}'`);
|
|
1395
1569
|
}
|
|
@@ -1629,7 +1803,7 @@ var PrimaryBaseRepository = class {
|
|
|
1629
1803
|
};
|
|
1630
1804
|
|
|
1631
1805
|
// src/database/repositories/tenant-base.repository.ts
|
|
1632
|
-
import { Logger as
|
|
1806
|
+
import { Logger as Logger9 } from "@nestjs/common";
|
|
1633
1807
|
import { eq as eq3, getTableName as getTableName2, sql as sql2 } from "drizzle-orm";
|
|
1634
1808
|
var TenantBaseRepository = class {
|
|
1635
1809
|
static {
|
|
@@ -1686,7 +1860,7 @@ var TenantBaseRepository = class {
|
|
|
1686
1860
|
this.database = database;
|
|
1687
1861
|
this.table = table;
|
|
1688
1862
|
this.tableName = getTableName2(table);
|
|
1689
|
-
this.logger = new
|
|
1863
|
+
this.logger = new Logger9(this.constructor.name);
|
|
1690
1864
|
this.logger.debug(`Initialized ${this.constructor.name}`);
|
|
1691
1865
|
}
|
|
1692
1866
|
/**
|
|
@@ -2029,7 +2203,7 @@ var ConflictException = class extends BaseFieldException {
|
|
|
2029
2203
|
|
|
2030
2204
|
// src/exceptions/forbidden.exception.ts
|
|
2031
2205
|
import { HttpStatus as HttpStatus5 } from "@nestjs/common";
|
|
2032
|
-
var
|
|
2206
|
+
var ForbiddenException2 = class extends BaseFieldException {
|
|
2033
2207
|
static {
|
|
2034
2208
|
__name(this, "ForbiddenException");
|
|
2035
2209
|
}
|
|
@@ -2238,7 +2412,7 @@ var TooManyRequestsException = class extends BaseFieldException {
|
|
|
2238
2412
|
|
|
2239
2413
|
// src/exceptions/unauthorized.exception.ts
|
|
2240
2414
|
import { HttpStatus as HttpStatus16 } from "@nestjs/common";
|
|
2241
|
-
var
|
|
2415
|
+
var UnauthorizedException5 = class extends BaseFieldException {
|
|
2242
2416
|
static {
|
|
2243
2417
|
__name(this, "UnauthorizedException");
|
|
2244
2418
|
}
|
|
@@ -2305,14 +2479,14 @@ var ValidationException = class extends BaseFieldException {
|
|
|
2305
2479
|
};
|
|
2306
2480
|
|
|
2307
2481
|
// src/filters/http-exception.filter.ts
|
|
2308
|
-
import { Catch, HttpException as HttpException2, HttpStatus as HttpStatus20, Logger as
|
|
2309
|
-
function
|
|
2482
|
+
import { Catch, HttpException as HttpException2, HttpStatus as HttpStatus20, Logger as Logger10 } from "@nestjs/common";
|
|
2483
|
+
function _ts_decorate12(decorators, target, key, desc) {
|
|
2310
2484
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2311
2485
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2312
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;
|
|
2313
2487
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2314
2488
|
}
|
|
2315
|
-
__name(
|
|
2489
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
2316
2490
|
function getHttpStatusTitle(status) {
|
|
2317
2491
|
const enumKey = Object.entries(HttpStatus20).find(([key, value]) => value === status && Number.isNaN(Number(key)))?.[0];
|
|
2318
2492
|
if (!enumKey) {
|
|
@@ -2325,7 +2499,7 @@ var HttpExceptionFilter = class _HttpExceptionFilter {
|
|
|
2325
2499
|
static {
|
|
2326
2500
|
__name(this, "HttpExceptionFilter");
|
|
2327
2501
|
}
|
|
2328
|
-
logger = new
|
|
2502
|
+
logger = new Logger10(_HttpExceptionFilter.name);
|
|
2329
2503
|
catch(exception, host) {
|
|
2330
2504
|
const ctx = host.switchToHttp();
|
|
2331
2505
|
const response = ctx.getResponse();
|
|
@@ -2390,25 +2564,45 @@ var HttpExceptionFilter = class _HttpExceptionFilter {
|
|
|
2390
2564
|
response.status(status).send(problemDetails);
|
|
2391
2565
|
}
|
|
2392
2566
|
};
|
|
2393
|
-
HttpExceptionFilter =
|
|
2567
|
+
HttpExceptionFilter = _ts_decorate12([
|
|
2394
2568
|
Catch()
|
|
2395
2569
|
], HttpExceptionFilter);
|
|
2396
2570
|
|
|
2571
|
+
// src/http/http.module.ts
|
|
2572
|
+
import { Module as Module4 } from "@nestjs/common";
|
|
2573
|
+
|
|
2397
2574
|
// src/http/guards/csrf.guard.ts
|
|
2398
|
-
import { ForbiddenException as
|
|
2399
|
-
|
|
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) {
|
|
2400
2578
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2401
2579
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2402
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;
|
|
2403
2581
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2404
2582
|
}
|
|
2405
|
-
__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");
|
|
2406
2588
|
var CsrfGuard = class _CsrfGuard {
|
|
2407
2589
|
static {
|
|
2408
2590
|
__name(this, "CsrfGuard");
|
|
2409
2591
|
}
|
|
2410
|
-
|
|
2592
|
+
reflector;
|
|
2593
|
+
logger = new Logger11(_CsrfGuard.name);
|
|
2594
|
+
constructor(reflector) {
|
|
2595
|
+
this.reflector = reflector;
|
|
2596
|
+
}
|
|
2411
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
|
+
}
|
|
2412
2606
|
const request = context.switchToHttp().getRequest();
|
|
2413
2607
|
const reply = context.switchToHttp().getResponse();
|
|
2414
2608
|
const safeMethods = [
|
|
@@ -2423,7 +2617,7 @@ var CsrfGuard = class _CsrfGuard {
|
|
|
2423
2617
|
const fastifyInstance = request.server;
|
|
2424
2618
|
if (!fastifyInstance.csrfProtection) {
|
|
2425
2619
|
this.logger.error("CSRF protection plugin not found. Ensure @fastify/csrf-protection is registered.");
|
|
2426
|
-
throw new
|
|
2620
|
+
throw new ForbiddenException3("CSRF protection not configured");
|
|
2427
2621
|
}
|
|
2428
2622
|
await new Promise((resolve, reject) => {
|
|
2429
2623
|
fastifyInstance.csrfProtection(request, reply, (err) => {
|
|
@@ -2438,7 +2632,7 @@ var CsrfGuard = class _CsrfGuard {
|
|
|
2438
2632
|
return true;
|
|
2439
2633
|
} catch (error) {
|
|
2440
2634
|
this.logger.warn(`CSRF validation failed for ${request.method} ${request.url}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2441
|
-
throw new
|
|
2635
|
+
throw new ForbiddenException3({
|
|
2442
2636
|
errors: [
|
|
2443
2637
|
{
|
|
2444
2638
|
field: "csrf",
|
|
@@ -2450,25 +2644,28 @@ var CsrfGuard = class _CsrfGuard {
|
|
|
2450
2644
|
}
|
|
2451
2645
|
}
|
|
2452
2646
|
};
|
|
2453
|
-
CsrfGuard =
|
|
2454
|
-
|
|
2647
|
+
CsrfGuard = _ts_decorate13([
|
|
2648
|
+
Injectable9(),
|
|
2649
|
+
_ts_metadata8("design:type", Function),
|
|
2650
|
+
_ts_metadata8("design:paramtypes", [
|
|
2651
|
+
typeof Reflector5 === "undefined" ? Object : Reflector5
|
|
2652
|
+
])
|
|
2455
2653
|
], CsrfGuard);
|
|
2456
2654
|
|
|
2457
2655
|
// src/http/http.module.ts
|
|
2458
|
-
|
|
2459
|
-
function _ts_decorate13(decorators, target, key, desc) {
|
|
2656
|
+
function _ts_decorate14(decorators, target, key, desc) {
|
|
2460
2657
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2461
2658
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2462
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;
|
|
2463
2660
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2464
2661
|
}
|
|
2465
|
-
__name(
|
|
2662
|
+
__name(_ts_decorate14, "_ts_decorate");
|
|
2466
2663
|
var HttpModule = class {
|
|
2467
2664
|
static {
|
|
2468
2665
|
__name(this, "HttpModule");
|
|
2469
2666
|
}
|
|
2470
2667
|
};
|
|
2471
|
-
HttpModule =
|
|
2668
|
+
HttpModule = _ts_decorate14([
|
|
2472
2669
|
Module4({
|
|
2473
2670
|
providers: [
|
|
2474
2671
|
CsrfGuard
|
|
@@ -2479,12 +2676,222 @@ HttpModule = _ts_decorate13([
|
|
|
2479
2676
|
})
|
|
2480
2677
|
], HttpModule);
|
|
2481
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
|
+
|
|
2482
2889
|
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2483
|
-
import { Injectable as
|
|
2890
|
+
import { Injectable as Injectable11, Optional as Optional2 } from "@nestjs/common";
|
|
2484
2891
|
import { catchError, tap as tap2 } from "rxjs/operators";
|
|
2485
2892
|
|
|
2486
2893
|
// src/logger/services/logger.service.ts
|
|
2487
|
-
import { Injectable as
|
|
2894
|
+
import { Injectable as Injectable10, Optional } from "@nestjs/common";
|
|
2488
2895
|
import { createLogger, format, transports } from "winston";
|
|
2489
2896
|
import DailyRotateFile from "winston-daily-rotate-file";
|
|
2490
2897
|
|
|
@@ -2522,17 +2929,17 @@ function addCorrelationIdToResponse(reply, correlationId, headerName = DEFAULT_C
|
|
|
2522
2929
|
__name(addCorrelationIdToResponse, "addCorrelationIdToResponse");
|
|
2523
2930
|
|
|
2524
2931
|
// src/logger/services/logger.service.ts
|
|
2525
|
-
function
|
|
2932
|
+
function _ts_decorate15(decorators, target, key, desc) {
|
|
2526
2933
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2527
2934
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2528
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;
|
|
2529
2936
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2530
2937
|
}
|
|
2531
|
-
__name(
|
|
2532
|
-
function
|
|
2938
|
+
__name(_ts_decorate15, "_ts_decorate");
|
|
2939
|
+
function _ts_metadata9(k, v) {
|
|
2533
2940
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2534
2941
|
}
|
|
2535
|
-
__name(
|
|
2942
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
2536
2943
|
function _ts_param4(paramIndex, decorator) {
|
|
2537
2944
|
return function(target, key) {
|
|
2538
2945
|
decorator(target, key, paramIndex);
|
|
@@ -2740,29 +3147,29 @@ ${trace}`;
|
|
|
2740
3147
|
return childLogger;
|
|
2741
3148
|
}
|
|
2742
3149
|
};
|
|
2743
|
-
LoggerService =
|
|
2744
|
-
|
|
3150
|
+
LoggerService = _ts_decorate15([
|
|
3151
|
+
Injectable10(),
|
|
2745
3152
|
_ts_param4(0, Optional()),
|
|
2746
3153
|
_ts_param4(1, Optional()),
|
|
2747
|
-
|
|
2748
|
-
|
|
3154
|
+
_ts_metadata9("design:type", Function),
|
|
3155
|
+
_ts_metadata9("design:paramtypes", [
|
|
2749
3156
|
typeof LoggerModuleOptions === "undefined" ? Object : LoggerModuleOptions,
|
|
2750
3157
|
typeof Logger === "undefined" ? Object : Logger
|
|
2751
3158
|
])
|
|
2752
3159
|
], LoggerService);
|
|
2753
3160
|
|
|
2754
3161
|
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2755
|
-
function
|
|
3162
|
+
function _ts_decorate16(decorators, target, key, desc) {
|
|
2756
3163
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2757
3164
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2758
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;
|
|
2759
3166
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2760
3167
|
}
|
|
2761
|
-
__name(
|
|
2762
|
-
function
|
|
3168
|
+
__name(_ts_decorate16, "_ts_decorate");
|
|
3169
|
+
function _ts_metadata10(k, v) {
|
|
2763
3170
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2764
3171
|
}
|
|
2765
|
-
__name(
|
|
3172
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
2766
3173
|
function _ts_param5(paramIndex, decorator) {
|
|
2767
3174
|
return function(target, key) {
|
|
2768
3175
|
decorator(target, key, paramIndex);
|
|
@@ -2870,32 +3277,32 @@ var HttpLoggerInterceptor = class {
|
|
|
2870
3277
|
}
|
|
2871
3278
|
}
|
|
2872
3279
|
};
|
|
2873
|
-
HttpLoggerInterceptor =
|
|
2874
|
-
|
|
3280
|
+
HttpLoggerInterceptor = _ts_decorate16([
|
|
3281
|
+
Injectable11(),
|
|
2875
3282
|
_ts_param5(1, Optional2()),
|
|
2876
|
-
|
|
2877
|
-
|
|
3283
|
+
_ts_metadata10("design:type", Function),
|
|
3284
|
+
_ts_metadata10("design:paramtypes", [
|
|
2878
3285
|
typeof LoggerService === "undefined" ? Object : LoggerService,
|
|
2879
3286
|
typeof HttpLoggerOptions === "undefined" ? Object : HttpLoggerOptions
|
|
2880
3287
|
])
|
|
2881
3288
|
], HttpLoggerInterceptor);
|
|
2882
3289
|
|
|
2883
3290
|
// src/logger/logger.module.ts
|
|
2884
|
-
import { Global as Global4, Logger as
|
|
3291
|
+
import { Global as Global4, Logger as Logger12, Module as Module5 } from "@nestjs/common";
|
|
2885
3292
|
|
|
2886
3293
|
// src/logger/middleware/correlation-id.middleware.ts
|
|
2887
|
-
import { Injectable as
|
|
2888
|
-
function
|
|
3294
|
+
import { Injectable as Injectable12 } from "@nestjs/common";
|
|
3295
|
+
function _ts_decorate17(decorators, target, key, desc) {
|
|
2889
3296
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2890
3297
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2891
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;
|
|
2892
3299
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2893
3300
|
}
|
|
2894
|
-
__name(
|
|
2895
|
-
function
|
|
3301
|
+
__name(_ts_decorate17, "_ts_decorate");
|
|
3302
|
+
function _ts_metadata11(k, v) {
|
|
2896
3303
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2897
3304
|
}
|
|
2898
|
-
__name(
|
|
3305
|
+
__name(_ts_metadata11, "_ts_metadata");
|
|
2899
3306
|
var CorrelationIdMiddleware = class {
|
|
2900
3307
|
static {
|
|
2901
3308
|
__name(this, "CorrelationIdMiddleware");
|
|
@@ -2938,22 +3345,22 @@ var CorrelationIdMiddleware = class {
|
|
|
2938
3345
|
}
|
|
2939
3346
|
}
|
|
2940
3347
|
};
|
|
2941
|
-
CorrelationIdMiddleware =
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
3348
|
+
CorrelationIdMiddleware = _ts_decorate17([
|
|
3349
|
+
Injectable12(),
|
|
3350
|
+
_ts_metadata11("design:type", Function),
|
|
3351
|
+
_ts_metadata11("design:paramtypes", [
|
|
2945
3352
|
typeof CorrelationIdMiddlewareOptions === "undefined" ? Object : CorrelationIdMiddlewareOptions
|
|
2946
3353
|
])
|
|
2947
3354
|
], CorrelationIdMiddleware);
|
|
2948
3355
|
|
|
2949
3356
|
// src/logger/logger.module.ts
|
|
2950
|
-
function
|
|
3357
|
+
function _ts_decorate18(decorators, target, key, desc) {
|
|
2951
3358
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2952
3359
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2953
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;
|
|
2954
3361
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2955
3362
|
}
|
|
2956
|
-
__name(
|
|
3363
|
+
__name(_ts_decorate18, "_ts_decorate");
|
|
2957
3364
|
var LOGGER_MODULE_OPTIONS = Symbol("LOGGER_MODULE_OPTIONS");
|
|
2958
3365
|
var DEFAULT_LOGGER_OPTIONS = {
|
|
2959
3366
|
provider: "winston",
|
|
@@ -3042,9 +3449,9 @@ function mergeWithDefaults(options = {}) {
|
|
|
3042
3449
|
__name(mergeWithDefaults, "mergeWithDefaults");
|
|
3043
3450
|
function createDefaultLoggerProvider(options) {
|
|
3044
3451
|
return {
|
|
3045
|
-
provide:
|
|
3452
|
+
provide: Logger12,
|
|
3046
3453
|
useFactory: /* @__PURE__ */ __name(() => {
|
|
3047
|
-
const logger = new
|
|
3454
|
+
const logger = new Logger12();
|
|
3048
3455
|
if (options.level && typeof logger.setLogLevels === "function") {
|
|
3049
3456
|
const levels = getLevelsUpTo(options.level);
|
|
3050
3457
|
logger.setLogLevels(levels);
|
|
@@ -3074,7 +3481,7 @@ function createLoggerProviders(options = {}) {
|
|
|
3074
3481
|
inject: [
|
|
3075
3482
|
LOGGER_MODULE_OPTIONS,
|
|
3076
3483
|
{
|
|
3077
|
-
token:
|
|
3484
|
+
token: Logger12,
|
|
3078
3485
|
optional: true
|
|
3079
3486
|
}
|
|
3080
3487
|
]
|
|
@@ -3225,10 +3632,10 @@ var LoggerModule = class _LoggerModule {
|
|
|
3225
3632
|
...asyncProviders,
|
|
3226
3633
|
// Default logger provider
|
|
3227
3634
|
{
|
|
3228
|
-
provide:
|
|
3635
|
+
provide: Logger12,
|
|
3229
3636
|
useFactory: /* @__PURE__ */ __name((opts) => {
|
|
3230
3637
|
if (opts.provider === "default") {
|
|
3231
|
-
const logger = new
|
|
3638
|
+
const logger = new Logger12();
|
|
3232
3639
|
if (opts.level && typeof logger.setLogLevels === "function") {
|
|
3233
3640
|
const levels = getLevelsUpTo(opts.level);
|
|
3234
3641
|
logger.setLogLevels(levels);
|
|
@@ -3250,7 +3657,7 @@ var LoggerModule = class _LoggerModule {
|
|
|
3250
3657
|
inject: [
|
|
3251
3658
|
LOGGER_MODULE_OPTIONS,
|
|
3252
3659
|
{
|
|
3253
|
-
token:
|
|
3660
|
+
token: Logger12,
|
|
3254
3661
|
optional: true
|
|
3255
3662
|
}
|
|
3256
3663
|
]
|
|
@@ -3356,7 +3763,7 @@ var LoggerModule = class _LoggerModule {
|
|
|
3356
3763
|
throw new Error("LoggerModule.forRootAsync() requires one of: useFactory, useClass, or useExisting");
|
|
3357
3764
|
}
|
|
3358
3765
|
};
|
|
3359
|
-
LoggerModule =
|
|
3766
|
+
LoggerModule = _ts_decorate18([
|
|
3360
3767
|
Global4(),
|
|
3361
3768
|
Module5({})
|
|
3362
3769
|
], LoggerModule);
|
|
@@ -3367,10 +3774,9 @@ export {
|
|
|
3367
3774
|
BaseFieldException,
|
|
3368
3775
|
ConflictException,
|
|
3369
3776
|
CorrelationIdMiddleware,
|
|
3370
|
-
CsrfGuard,
|
|
3371
3777
|
DEFAULT_CORRELATION_HEADER,
|
|
3372
3778
|
DatabaseModule,
|
|
3373
|
-
ForbiddenException,
|
|
3779
|
+
ForbiddenException2 as ForbiddenException,
|
|
3374
3780
|
GoneException,
|
|
3375
3781
|
HttpExceptionFilter,
|
|
3376
3782
|
HttpLoggerInterceptor,
|
|
@@ -3389,13 +3795,16 @@ export {
|
|
|
3389
3795
|
PrimaryDatabaseService,
|
|
3390
3796
|
Public,
|
|
3391
3797
|
RequestTimeoutException,
|
|
3798
|
+
SKIP_CSRF_KEY,
|
|
3392
3799
|
ServiceUnavailableException,
|
|
3800
|
+
SkipCsrf,
|
|
3801
|
+
SseAuthGuard,
|
|
3393
3802
|
Tenant,
|
|
3394
3803
|
TenantBaseRepository,
|
|
3395
3804
|
TenantContextService,
|
|
3396
3805
|
TenantDatabaseService,
|
|
3397
3806
|
TooManyRequestsException,
|
|
3398
|
-
|
|
3807
|
+
UnauthorizedException5 as UnauthorizedException,
|
|
3399
3808
|
UnprocessableEntityException,
|
|
3400
3809
|
UnsupportedMediaTypeException,
|
|
3401
3810
|
UserId,
|
|
@@ -3405,6 +3814,7 @@ export {
|
|
|
3405
3814
|
configureApiSdk,
|
|
3406
3815
|
correlationStorage,
|
|
3407
3816
|
defineConfig,
|
|
3817
|
+
extractCountryFromPhone,
|
|
3408
3818
|
generateCorrelationId,
|
|
3409
3819
|
getConfig,
|
|
3410
3820
|
getCorrelationContext,
|
|
@@ -3412,6 +3822,7 @@ export {
|
|
|
3412
3822
|
getJwtExpiry,
|
|
3413
3823
|
getRefreshCookieOptions,
|
|
3414
3824
|
hashToken,
|
|
3825
|
+
normalizePhoneNumber,
|
|
3415
3826
|
resetConfig,
|
|
3416
3827
|
runWithCorrelationContext,
|
|
3417
3828
|
updateCorrelationContext,
|