@stefaninigo/security-client 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generated/authentication/authentication.d.ts +22 -0
- package/dist/generated/authentication/authentication.js +55 -0
- package/dist/generated/authentication/authentication.js.map +1 -0
- package/dist/generated/bootstrap/bootstrap.d.ts +12 -0
- package/dist/generated/bootstrap/bootstrap.js +24 -0
- package/dist/generated/bootstrap/bootstrap.js.map +1 -0
- package/dist/generated/client-assignments/client-assignments.d.ts +24 -0
- package/dist/generated/client-assignments/client-assignments.js +50 -0
- package/dist/generated/client-assignments/client-assignments.js.map +1 -0
- package/dist/generated/credentials/credentials.d.ts +18 -0
- package/dist/generated/credentials/credentials.js +39 -0
- package/dist/generated/credentials/credentials.js.map +1 -0
- package/dist/generated/health/health.d.ts +11 -0
- package/dist/generated/health/health.js +21 -0
- package/dist/generated/health/health.js.map +1 -0
- package/dist/generated/location-tracking-deprecated/location-tracking-deprecated.d.ts +20 -0
- package/dist/generated/location-tracking-deprecated/location-tracking-deprecated.js +42 -0
- package/dist/generated/location-tracking-deprecated/location-tracking-deprecated.js.map +1 -0
- package/dist/generated/provider-client-assignments/provider-client-assignments.d.ts +20 -0
- package/dist/generated/provider-client-assignments/provider-client-assignments.js +42 -0
- package/dist/generated/provider-client-assignments/provider-client-assignments.js.map +1 -0
- package/dist/generated/providers/providers.d.ts +20 -0
- package/dist/generated/providers/providers.js +42 -0
- package/dist/generated/providers/providers.js.map +1 -0
- package/dist/generated/stefaniniGoServiceAPI.schemas.d.ts +963 -0
- package/dist/generated/stefaniniGoServiceAPI.schemas.js +169 -0
- package/dist/generated/stefaniniGoServiceAPI.schemas.js.map +1 -0
- package/dist/generated/users/users.d.ts +36 -0
- package/dist/generated/users/users.js +90 -0
- package/dist/generated/users/users.js.map +1 -0
- package/dist/guards/{security-auth.guard.d.ts → cognito-auth.guard.d.ts} +1 -3
- package/dist/guards/{security-auth.guard.js → cognito-auth.guard.js} +15 -29
- package/dist/guards/cognito-auth.guard.js.map +1 -0
- package/dist/guards/role.guard.js +0 -8
- package/dist/guards/role.guard.js.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/module/security-client.module.d.ts +0 -5
- package/dist/module/security-client.module.js +3 -29
- package/dist/module/security-client.module.js.map +1 -1
- package/dist/services/security-client.service.d.ts +0 -15
- package/dist/services/security-client.service.js +7 -95
- package/dist/services/security-client.service.js.map +1 -1
- package/dist/types/user.types.d.ts +0 -5
- package/dist/types/user.types.js +0 -1
- package/dist/types/user.types.js.map +1 -1
- package/dist/utils/mutator.d.ts +3 -0
- package/dist/utils/mutator.js +22 -0
- package/dist/utils/mutator.js.map +1 -0
- package/package.json +3 -4
- package/dist/decorators/public.decorator.d.ts +0 -2
- package/dist/decorators/public.decorator.js +0 -8
- package/dist/decorators/public.decorator.js.map +0 -1
- package/dist/guards/provider.guard.d.ts +0 -7
- package/dist/guards/provider.guard.js +0 -43
- package/dist/guards/provider.guard.js.map +0 -1
- package/dist/guards/security-auth.guard.js.map +0 -1
|
@@ -19,13 +19,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
exports.SecurityClientService = exports.SECURITY_CLIENT_CONFIG = void 0;
|
|
20
20
|
const common_1 = require("@nestjs/common");
|
|
21
21
|
const axios_1 = __importDefault(require("axios"));
|
|
22
|
-
const crypto_1 = require("crypto");
|
|
23
22
|
exports.SECURITY_CLIENT_CONFIG = 'SECURITY_CLIENT_CONFIG';
|
|
24
23
|
let SecurityClientService = SecurityClientService_1 = class SecurityClientService {
|
|
25
24
|
constructor(config) {
|
|
26
25
|
this.config = config;
|
|
27
26
|
this.logger = new common_1.Logger(SecurityClientService_1.name);
|
|
28
|
-
this.cache = new Map();
|
|
29
27
|
this.httpClient = axios_1.default.create({
|
|
30
28
|
baseURL: config.securityServiceUrl,
|
|
31
29
|
timeout: config.timeout || 5000,
|
|
@@ -33,88 +31,18 @@ let SecurityClientService = SecurityClientService_1 = class SecurityClientServic
|
|
|
33
31
|
'Content-Type': 'application/json',
|
|
34
32
|
},
|
|
35
33
|
});
|
|
36
|
-
this.cacheTtlMs = config.cacheTtlMs ?? 60000;
|
|
37
|
-
this.maxCacheSize = config.maxCacheSize ?? 1000;
|
|
38
|
-
this.retryAttempts = config.retryAttempts ?? 2;
|
|
39
|
-
this.retryDelayMs = config.retryDelayMs ?? 1000;
|
|
40
|
-
}
|
|
41
|
-
hashToken(token) {
|
|
42
|
-
return (0, crypto_1.createHash)('sha256').update(token).digest('hex').substring(0, 16);
|
|
43
|
-
}
|
|
44
|
-
getCached(key) {
|
|
45
|
-
const entry = this.cache.get(key);
|
|
46
|
-
if (!entry)
|
|
47
|
-
return null;
|
|
48
|
-
if (Date.now() > entry.expiresAt) {
|
|
49
|
-
this.cache.delete(key);
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
return entry.user;
|
|
53
|
-
}
|
|
54
|
-
setCache(key, user) {
|
|
55
|
-
if (this.cache.size >= this.maxCacheSize) {
|
|
56
|
-
this.evictExpired();
|
|
57
|
-
if (this.cache.size >= this.maxCacheSize) {
|
|
58
|
-
const firstKey = this.cache.keys().next().value;
|
|
59
|
-
if (firstKey)
|
|
60
|
-
this.cache.delete(firstKey);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
this.cache.set(key, {
|
|
64
|
-
user,
|
|
65
|
-
expiresAt: Date.now() + this.cacheTtlMs,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
evictExpired() {
|
|
69
|
-
const now = Date.now();
|
|
70
|
-
for (const [key, entry] of this.cache) {
|
|
71
|
-
if (now > entry.expiresAt) {
|
|
72
|
-
this.cache.delete(key);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
isAuthError(status) {
|
|
77
|
-
return status === 401 || status === 403;
|
|
78
|
-
}
|
|
79
|
-
async withRetry(fn) {
|
|
80
|
-
let lastError;
|
|
81
|
-
for (let attempt = 0; attempt <= this.retryAttempts; attempt++) {
|
|
82
|
-
try {
|
|
83
|
-
return await fn();
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
lastError = error;
|
|
87
|
-
if (error.response && this.isAuthError(error.response.status)) {
|
|
88
|
-
throw error;
|
|
89
|
-
}
|
|
90
|
-
if (attempt < this.retryAttempts) {
|
|
91
|
-
const delay = Math.pow(2, attempt) * this.retryDelayMs;
|
|
92
|
-
this.logger.warn(`Retry attempt ${attempt + 1}/${this.retryAttempts} after ${delay}ms`);
|
|
93
|
-
await new Promise(resolve => setTimeout(resolve, delay));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
throw lastError;
|
|
98
34
|
}
|
|
99
35
|
async validateTokenAndGetUser(token) {
|
|
100
|
-
const cacheKey = this.hashToken(token);
|
|
101
|
-
const cached = this.getCached(cacheKey);
|
|
102
|
-
if (cached) {
|
|
103
|
-
return cached;
|
|
104
|
-
}
|
|
105
36
|
try {
|
|
106
|
-
const response = await this.
|
|
37
|
+
const response = await this.httpClient.get('/api/v1/security/users/me', {
|
|
107
38
|
headers: {
|
|
108
39
|
Authorization: `Bearer ${token}`,
|
|
109
40
|
},
|
|
110
|
-
})
|
|
41
|
+
});
|
|
111
42
|
if (!response.data || typeof response.data !== 'object') {
|
|
112
43
|
throw new Error('Invalid response format from security service');
|
|
113
44
|
}
|
|
114
|
-
const
|
|
115
|
-
const userData = (rawData?.success !== undefined && rawData?.message && typeof rawData.message === 'object')
|
|
116
|
-
? rawData.message
|
|
117
|
-
: rawData;
|
|
45
|
+
const userData = response.data;
|
|
118
46
|
if (!userData.id || !userData.email || !userData.role || !userData.status) {
|
|
119
47
|
this.logger.warn('Security service returned incomplete user data', {
|
|
120
48
|
hasId: !!userData.id,
|
|
@@ -124,9 +52,7 @@ let SecurityClientService = SecurityClientService_1 = class SecurityClientServic
|
|
|
124
52
|
});
|
|
125
53
|
throw new Error('Incomplete user data from security service');
|
|
126
54
|
}
|
|
127
|
-
|
|
128
|
-
this.setCache(cacheKey, user);
|
|
129
|
-
return user;
|
|
55
|
+
return userData;
|
|
130
56
|
}
|
|
131
57
|
catch (error) {
|
|
132
58
|
this.logger.error(`Error validating token: ${error.message}`);
|
|
@@ -140,18 +66,15 @@ let SecurityClientService = SecurityClientService_1 = class SecurityClientServic
|
|
|
140
66
|
}
|
|
141
67
|
async getUserById(userId, token) {
|
|
142
68
|
try {
|
|
143
|
-
const response = await this.
|
|
69
|
+
const response = await this.httpClient.get(`/api/v1/security/users/${userId}`, {
|
|
144
70
|
headers: {
|
|
145
71
|
Authorization: `Bearer ${token}`,
|
|
146
72
|
},
|
|
147
|
-
})
|
|
73
|
+
});
|
|
148
74
|
if (!response.data || typeof response.data !== 'object') {
|
|
149
75
|
throw new Error('Invalid response format from security service');
|
|
150
76
|
}
|
|
151
|
-
const
|
|
152
|
-
const userData = (rawData?.success !== undefined && rawData?.message && typeof rawData.message === 'object')
|
|
153
|
-
? rawData.message
|
|
154
|
-
: rawData;
|
|
77
|
+
const userData = response.data;
|
|
155
78
|
if (!userData.id || !userData.email || !userData.role || !userData.status) {
|
|
156
79
|
this.logger.warn('Security service returned incomplete user data', {
|
|
157
80
|
hasId: !!userData.id,
|
|
@@ -173,17 +96,6 @@ let SecurityClientService = SecurityClientService_1 = class SecurityClientServic
|
|
|
173
96
|
throw new Error(`Failed to connect to security service: ${error.message}`);
|
|
174
97
|
}
|
|
175
98
|
}
|
|
176
|
-
async healthCheck() {
|
|
177
|
-
const start = Date.now();
|
|
178
|
-
try {
|
|
179
|
-
await this.httpClient.get('/api/v1/security/health', { timeout: 3000 });
|
|
180
|
-
return { healthy: true, responseTimeMs: Date.now() - start };
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
this.logger.error(`Health check failed: ${error.message}`);
|
|
184
|
-
return { healthy: false, responseTimeMs: Date.now() - start };
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
99
|
};
|
|
188
100
|
exports.SecurityClientService = SecurityClientService;
|
|
189
101
|
exports.SecurityClientService = SecurityClientService = SecurityClientService_1 = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security-client.service.js","sourceRoot":"","sources":["../../src/services/security-client.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,kDAA6C;
|
|
1
|
+
{"version":3,"file":"security-client.service.js","sourceRoot":"","sources":["../../src/services/security-client.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,kDAA6C;AAIhC,QAAA,sBAAsB,GAAG,wBAAwB,CAAC;AAGxD,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAIhC,YACkC,MAA6C;QAA5B,WAAM,GAAN,MAAM,CAAsB;QAJ9D,WAAM,GAAG,IAAI,eAAM,CAAC,uBAAqB,CAAC,IAAI,CAAC,CAAC;QAM/D,IAAI,CAAC,UAAU,GAAG,eAAK,CAAC,MAAM,CAAC;YAC7B,OAAO,EAAE,MAAM,CAAC,kBAAkB;YAClC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI;YAC/B,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,KAAa;QACzC,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,2BAA2B,EAAE;gBACtE,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,KAAK,EAAE;iBACjC;aACF,CAAC,CAAC;YAGH,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACxD,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;YACnE,CAAC;YAED,MAAM,QAAQ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AK,CAAC,mCAAmC,MAAM,MAAM,OAAO,EAAE,CAAC,CAAC;YAC5E,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,0CAA0C,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;CACF,CAAA;AAvFY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,eAAM,EAAC,8BAAsB,CAAC,CAAA;;GALtB,qBAAqB,CAuFjC"}
|
|
@@ -2,7 +2,6 @@ export declare enum UserRole {
|
|
|
2
2
|
ROOT = "root",
|
|
3
3
|
ADMIN = "admin",
|
|
4
4
|
DISPATCHER = "dispatcher",
|
|
5
|
-
CLIENT = "client",
|
|
6
5
|
TECHNICIAN = "technician"
|
|
7
6
|
}
|
|
8
7
|
export declare enum UserStatus {
|
|
@@ -21,8 +20,4 @@ export interface AuthUser {
|
|
|
21
20
|
export interface SecurityClientConfig {
|
|
22
21
|
securityServiceUrl: string;
|
|
23
22
|
timeout?: number;
|
|
24
|
-
cacheTtlMs?: number;
|
|
25
|
-
maxCacheSize?: number;
|
|
26
|
-
retryAttempts?: number;
|
|
27
|
-
retryDelayMs?: number;
|
|
28
23
|
}
|
package/dist/types/user.types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.types.js","sourceRoot":"","sources":["../../src/types/user.types.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"user.types.js","sourceRoot":"","sources":["../../src/types/user.types.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,2BAAe,CAAA;IACf,qCAAyB,CAAA;IACzB,qCAAyB,CAAA;AAC3B,CAAC,EALW,QAAQ,wBAAR,QAAQ,QAKnB;AAED,IAAY,UAIX;AAJD,WAAY,UAAU;IACpB,+BAAiB,CAAA;IACjB,iCAAmB,CAAA;IACnB,iCAAmB,CAAA;AACrB,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.customInstance = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const customInstance = (config, options) => {
|
|
9
|
+
const source = axios_1.default.CancelToken.source();
|
|
10
|
+
const promise = (0, axios_1.default)({
|
|
11
|
+
...config,
|
|
12
|
+
...options,
|
|
13
|
+
cancelToken: source.token,
|
|
14
|
+
}).then(({ data }) => data);
|
|
15
|
+
promise.cancel = () => {
|
|
16
|
+
source.cancel('Query was cancelled');
|
|
17
|
+
};
|
|
18
|
+
return promise;
|
|
19
|
+
};
|
|
20
|
+
exports.customInstance = customInstance;
|
|
21
|
+
exports.default = exports.customInstance;
|
|
22
|
+
//# sourceMappingURL=mutator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutator.js","sourceRoot":"","sources":["../../src/utils/mutator.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAkD;AAE3C,MAAM,cAAc,GAAG,CAC5B,MAA0B,EAC1B,OAA4B,EAChB,EAAE;IACd,MAAM,MAAM,GAAG,eAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;IAC1C,MAAM,OAAO,GAAG,IAAA,eAAK,EAAC;QACpB,GAAG,MAAM;QACT,GAAG,OAAO;QACV,WAAW,EAAE,MAAM,CAAC,KAAK;KAC1B,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IAG5B,OAAO,CAAC,MAAM,GAAG,GAAG,EAAE;QACpB,MAAM,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;IACvC,CAAC,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAjBW,QAAA,cAAc,kBAiBzB;AAEF,kBAAe,sBAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stefaninigo/security-client",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "StefaniniGo Security Client SDK - Guards, decorators and HTTP client for authentication and authorization",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"directory": "packages/security-client"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@nestjs/common": "^
|
|
35
|
-
"@nestjs/core": "^
|
|
34
|
+
"@nestjs/common": "^11.1.6",
|
|
35
|
+
"@nestjs/core": "^11.1.6",
|
|
36
36
|
"axios": "^1.7.9",
|
|
37
37
|
"reflect-metadata": "^0.2.2",
|
|
38
38
|
"rxjs": "^7.8.2"
|
|
@@ -42,7 +42,6 @@
|
|
|
42
42
|
"@nestjs/core": "^10.0.0 || ^11.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@types/express": "^5.0.6",
|
|
46
45
|
"@types/node": "^24.7.2",
|
|
47
46
|
"typescript": "^5.9.3"
|
|
48
47
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Public = exports.IS_PUBLIC_KEY = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
exports.IS_PUBLIC_KEY = 'isPublic';
|
|
6
|
-
const Public = () => (0, common_1.SetMetadata)(exports.IS_PUBLIC_KEY, true);
|
|
7
|
-
exports.Public = Public;
|
|
8
|
-
//# sourceMappingURL=public.decorator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"public.decorator.js","sourceRoot":"","sources":["../../src/decorators/public.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAEhC,QAAA,aAAa,GAAG,UAAU,CAAC;AACjC,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAA,oBAAW,EAAC,qBAAa,EAAE,IAAI,CAAC,CAAC;AAAhD,QAAA,MAAM,UAA0C"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
-
import { Reflector } from '@nestjs/core';
|
|
3
|
-
export declare class ProviderGuard implements CanActivate {
|
|
4
|
-
private readonly reflector;
|
|
5
|
-
constructor(reflector: Reflector);
|
|
6
|
-
canActivate(context: ExecutionContext): boolean;
|
|
7
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ProviderGuard = void 0;
|
|
13
|
-
const common_1 = require("@nestjs/common");
|
|
14
|
-
const core_1 = require("@nestjs/core");
|
|
15
|
-
const public_decorator_1 = require("../decorators/public.decorator");
|
|
16
|
-
let ProviderGuard = class ProviderGuard {
|
|
17
|
-
constructor(reflector) {
|
|
18
|
-
this.reflector = reflector;
|
|
19
|
-
}
|
|
20
|
-
canActivate(context) {
|
|
21
|
-
const isPublic = this.reflector.getAllAndOverride(public_decorator_1.IS_PUBLIC_KEY, [
|
|
22
|
-
context.getHandler(),
|
|
23
|
-
context.getClass(),
|
|
24
|
-
]);
|
|
25
|
-
if (isPublic) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
const { user } = context.switchToHttp().getRequest();
|
|
29
|
-
if (!user) {
|
|
30
|
-
throw new common_1.ForbiddenException('Usuario no autenticado');
|
|
31
|
-
}
|
|
32
|
-
if (!user.providerId) {
|
|
33
|
-
throw new common_1.ForbiddenException('Se requiere un proveedor asociado');
|
|
34
|
-
}
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
exports.ProviderGuard = ProviderGuard;
|
|
39
|
-
exports.ProviderGuard = ProviderGuard = __decorate([
|
|
40
|
-
(0, common_1.Injectable)(),
|
|
41
|
-
__metadata("design:paramtypes", [core_1.Reflector])
|
|
42
|
-
], ProviderGuard);
|
|
43
|
-
//# sourceMappingURL=provider.guard.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider.guard.js","sourceRoot":"","sources":["../../src/guards/provider.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA+F;AAC/F,uCAAyC;AACzC,qEAA+D;AAGxD,IAAM,aAAa,GAAnB,MAAM,aAAa;IACxB,YAA6B,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAErD,WAAW,CAAC,OAAyB;QACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAU,gCAAa,EAAE;YACxE,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SACnB,CAAC,CAAC;QAEH,IAAI,QAAQ,EAAE,CAAC;YACb,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