@stefaninigo/security-client 1.2.0 → 1.2.2
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/context/trace-context.d.ts +7 -0
- package/dist/context/trace-context.js +10 -0
- package/dist/context/trace-context.js.map +1 -0
- package/dist/guards/cognito-auth.guard.d.ts +9 -0
- package/dist/guards/cognito-auth.guard.js +63 -0
- 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/guards/security-auth.guard.js +3 -1
- package/dist/guards/security-auth.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 +13 -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 +4 -4
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.traceContextStorage = void 0;
|
|
4
|
+
exports.getTraceId = getTraceId;
|
|
5
|
+
const async_hooks_1 = require("async_hooks");
|
|
6
|
+
exports.traceContextStorage = new async_hooks_1.AsyncLocalStorage();
|
|
7
|
+
function getTraceId() {
|
|
8
|
+
return exports.traceContextStorage.getStore()?.traceId;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=trace-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-context.js","sourceRoot":"","sources":["../../src/context/trace-context.ts"],"names":[],"mappings":";;;AAQA,gCAEC;AAVD,6CAAgD;AAMnC,QAAA,mBAAmB,GAAG,IAAI,+BAAiB,EAAgB,CAAC;AAEzE,SAAgB,UAAU;IACxB,OAAO,2BAAmB,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { SecurityClientService } from '../services/security-client.service';
|
|
3
|
+
export declare class SecurityAuthGuard implements CanActivate {
|
|
4
|
+
private readonly securityClient;
|
|
5
|
+
constructor(securityClient: SecurityClientService);
|
|
6
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
7
|
+
private extractTokenFromHeader;
|
|
8
|
+
}
|
|
9
|
+
export declare const CognitoAuthGuard: typeof SecurityAuthGuard;
|
|
@@ -0,0 +1,63 @@
|
|
|
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.CognitoAuthGuard = exports.SecurityAuthGuard = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const security_client_service_1 = require("../services/security-client.service");
|
|
15
|
+
let SecurityAuthGuard = class SecurityAuthGuard {
|
|
16
|
+
constructor(securityClient) {
|
|
17
|
+
this.securityClient = securityClient;
|
|
18
|
+
}
|
|
19
|
+
async canActivate(context) {
|
|
20
|
+
const request = context.switchToHttp().getRequest();
|
|
21
|
+
const token = this.extractTokenFromHeader(request);
|
|
22
|
+
if (!token) {
|
|
23
|
+
throw new common_1.UnauthorizedException('Token de acceso requerido');
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const user = await this.securityClient.validateTokenAndGetUser(token);
|
|
27
|
+
if (user.status !== 'active') {
|
|
28
|
+
throw new common_1.UnauthorizedException('Usuario inactivo');
|
|
29
|
+
}
|
|
30
|
+
request.user = user;
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (error instanceof common_1.UnauthorizedException) {
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
if (error instanceof Error) {
|
|
38
|
+
const errorMsg = error.message.toLowerCase();
|
|
39
|
+
if (errorMsg.includes('expired') || errorMsg.includes('jwt expired')) {
|
|
40
|
+
throw new common_1.UnauthorizedException('Token expirado');
|
|
41
|
+
}
|
|
42
|
+
if (errorMsg.includes('invalid') ||
|
|
43
|
+
errorMsg.includes('signature') ||
|
|
44
|
+
errorMsg.includes('malformed') ||
|
|
45
|
+
errorMsg.includes('jwt malformed')) {
|
|
46
|
+
throw new common_1.UnauthorizedException('Token inválido');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
throw new common_1.UnauthorizedException('Error de autenticación');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
extractTokenFromHeader(request) {
|
|
53
|
+
const [type, token] = request.headers.authorization?.split(' ') ?? [];
|
|
54
|
+
return type === 'Bearer' ? token : undefined;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
exports.SecurityAuthGuard = SecurityAuthGuard;
|
|
58
|
+
exports.SecurityAuthGuard = SecurityAuthGuard = __decorate([
|
|
59
|
+
(0, common_1.Injectable)(),
|
|
60
|
+
__metadata("design:paramtypes", [security_client_service_1.SecurityClientService])
|
|
61
|
+
], SecurityAuthGuard);
|
|
62
|
+
exports.CognitoAuthGuard = SecurityAuthGuard;
|
|
63
|
+
//# sourceMappingURL=cognito-auth.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognito-auth.guard.js","sourceRoot":"","sources":["../../src/guards/cognito-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAkG;AAElG,iFAA4E;AAerE,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,YACmB,cAAqC;QAArC,mBAAc,GAAd,cAAc,CAAuB;IACrD,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAiC,CAAC;QACnF,MAAM,KAAK,GAAG,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;QAEnD,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,8BAAqB,CAAC,2BAA2B,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC;YAEtE,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;gBAC7B,MAAM,IAAI,8BAAqB,CAAC,kBAAkB,CAAC,CAAC;YACtD,CAAC;YAED,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;YAEpB,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,8BAAqB,EAAE,CAAC;gBAC3C,MAAM,KAAK,CAAC;YACd,CAAC;YAED,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;gBAC3B,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;gBAE7C,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;oBACrE,MAAM,IAAI,8BAAqB,CAAC,gBAAgB,CAAC,CAAC;gBACpD,CAAC;gBAED,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC;oBAC5B,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC;oBAC9B,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC;oBAC9B,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;oBACvC,MAAM,IAAI,8BAAqB,CAAC,gBAAgB,CAAC,CAAC;gBACpD,CAAC;YACH,CAAC;YAED,MAAM,IAAI,8BAAqB,CAAC,wBAAwB,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;IAEO,sBAAsB,CAAC,OAAgB;QAC7C,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QACtE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/C,CAAC;CACF,CAAA;AAnDY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAGwB,+CAAqB;GAF7C,iBAAiB,CAmD7B;AAKY,QAAA,gBAAgB,GAAG,iBAAiB,CAAC"}
|
|
@@ -13,19 +13,11 @@ exports.RoleGuard = void 0;
|
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const core_1 = require("@nestjs/core");
|
|
15
15
|
const roles_decorator_1 = require("../decorators/roles.decorator");
|
|
16
|
-
const public_decorator_1 = require("../decorators/public.decorator");
|
|
17
16
|
let RoleGuard = class RoleGuard {
|
|
18
17
|
constructor(reflector) {
|
|
19
18
|
this.reflector = reflector;
|
|
20
19
|
}
|
|
21
20
|
canActivate(context) {
|
|
22
|
-
const isPublic = this.reflector.getAllAndOverride(public_decorator_1.IS_PUBLIC_KEY, [
|
|
23
|
-
context.getHandler(),
|
|
24
|
-
context.getClass(),
|
|
25
|
-
]);
|
|
26
|
-
if (isPublic) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
21
|
const requiredRoles = this.reflector.getAllAndOverride(roles_decorator_1.ROLES_KEY, [
|
|
30
22
|
context.getHandler(),
|
|
31
23
|
context.getClass(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role.guard.js","sourceRoot":"","sources":["../../src/guards/role.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA+F;AAC/F,uCAAyC;AAEzC,mEAA0D;
|
|
1
|
+
{"version":3,"file":"role.guard.js","sourceRoot":"","sources":["../../src/guards/role.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA+F;AAC/F,uCAAyC;AAEzC,mEAA0D;AAGnD,IAAM,SAAS,GAAf,MAAM,SAAS;IACpB,YAAoB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAE5C,WAAW,CAAC,OAAyB;QACnC,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAa,2BAAS,EAAE;YAC5E,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SACnB,CAAC,CAAC;QAEH,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QAErD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,2BAAkB,CAAC,wBAAwB,CAAC,CAAC;QACzD,CAAC;QAED,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QAEjE,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,2BAAkB,CAAC,4CAA4C,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACvG,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA3BY,8BAAS;oBAAT,SAAS;IADrB,IAAA,mBAAU,GAAE;qCAEoB,gBAAS;GAD7B,SAAS,CA2BrB"}
|
|
@@ -14,6 +14,7 @@ const common_1 = require("@nestjs/common");
|
|
|
14
14
|
const core_1 = require("@nestjs/core");
|
|
15
15
|
const security_client_service_1 = require("../services/security-client.service");
|
|
16
16
|
const public_decorator_1 = require("../decorators/public.decorator");
|
|
17
|
+
const trace_context_1 = require("../context/trace-context");
|
|
17
18
|
let SecurityAuthGuard = class SecurityAuthGuard {
|
|
18
19
|
constructor(securityClient, reflector) {
|
|
19
20
|
this.securityClient = securityClient;
|
|
@@ -32,8 +33,9 @@ let SecurityAuthGuard = class SecurityAuthGuard {
|
|
|
32
33
|
if (!token) {
|
|
33
34
|
throw new common_1.UnauthorizedException('Token de acceso requerido');
|
|
34
35
|
}
|
|
36
|
+
const traceId = request.traceId || request.headers['x-trace-id'] || undefined;
|
|
35
37
|
try {
|
|
36
|
-
const user = await this.securityClient.validateTokenAndGetUser(token);
|
|
38
|
+
const user = await trace_context_1.traceContextStorage.run({ traceId: traceId || 'no-trace-id' }, () => this.securityClient.validateTokenAndGetUser(token));
|
|
37
39
|
if (user.status !== 'active') {
|
|
38
40
|
throw new common_1.ForbiddenException('Usuario inactivo');
|
|
39
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security-auth.guard.js","sourceRoot":"","sources":["../../src/guards/security-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyI;AACzI,uCAAyC;AAEzC,iFAA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CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBAE5C,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;wBACnB,MAAM,IAAI,8BAAqB,CAAC,2BAA2B,CAAC,CAAC;oBAC/D,CAAC;oBAED,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;wBACnB,MAAM,IAAI,2BAAkB,CAAC,iBAAiB,CAAC,CAAC;oBAClD,CAAC;oBAED,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;wBACnB,MAAM,IAAI,0BAAiB,CAAC,uBAAuB,CAAC,CAAC;oBACvD,CAAC;gBACH,CAAC;YACH,CAAC;YAED,MAAM,IAAI,8BAAqB,CAAC,wBAAwB,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;IAEO,sBAAsB,CAAC,OAAgB;QAC7C,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QACtE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/C,CAAC;CACF,CAAA;AAtEY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAGwB,+CAAqB;QAC1B,gBAAS;GAH5B,iBAAiB,CAsE7B;AAKY,QAAA,gBAAgB,GAAG,iBAAiB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export { SecurityAuthGuard, CognitoAuthGuard } from './guards/
|
|
1
|
+
export { SecurityAuthGuard, CognitoAuthGuard } from './guards/cognito-auth.guard';
|
|
2
2
|
export * from './guards/role.guard';
|
|
3
|
-
export * from './guards/provider.guard';
|
|
4
3
|
export * from './decorators/roles.decorator';
|
|
5
|
-
export * from './decorators/public.decorator';
|
|
6
4
|
export * from './services/security-client.service';
|
|
7
5
|
export * from './module/security-client.module';
|
|
8
6
|
export * from './types/user.types';
|
package/dist/index.js
CHANGED
|
@@ -15,13 +15,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.CognitoAuthGuard = exports.SecurityAuthGuard = void 0;
|
|
18
|
-
var
|
|
19
|
-
Object.defineProperty(exports, "SecurityAuthGuard", { enumerable: true, get: function () { return
|
|
20
|
-
Object.defineProperty(exports, "CognitoAuthGuard", { enumerable: true, get: function () { return
|
|
18
|
+
var cognito_auth_guard_1 = require("./guards/cognito-auth.guard");
|
|
19
|
+
Object.defineProperty(exports, "SecurityAuthGuard", { enumerable: true, get: function () { return cognito_auth_guard_1.SecurityAuthGuard; } });
|
|
20
|
+
Object.defineProperty(exports, "CognitoAuthGuard", { enumerable: true, get: function () { return cognito_auth_guard_1.CognitoAuthGuard; } });
|
|
21
21
|
__exportStar(require("./guards/role.guard"), exports);
|
|
22
|
-
__exportStar(require("./guards/provider.guard"), exports);
|
|
23
22
|
__exportStar(require("./decorators/roles.decorator"), exports);
|
|
24
|
-
__exportStar(require("./decorators/public.decorator"), exports);
|
|
25
23
|
__exportStar(require("./services/security-client.service"), exports);
|
|
26
24
|
__exportStar(require("./module/security-client.module"), exports);
|
|
27
25
|
__exportStar(require("./types/user.types"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kEAAkF;AAAzE,uHAAA,iBAAiB,OAAA;AAAE,sHAAA,gBAAgB,OAAA;AAC5C,sDAAoC;AACpC,+DAA6C;AAC7C,qEAAmD;AACnD,kEAAgD;AAChD,qDAAmC"}
|
|
@@ -2,9 +2,4 @@ import { DynamicModule } from '@nestjs/common';
|
|
|
2
2
|
import { SecurityClientConfig } from '../types/user.types';
|
|
3
3
|
export declare class SecurityClientModule {
|
|
4
4
|
static forRoot(config: SecurityClientConfig): DynamicModule;
|
|
5
|
-
static forRootAsync(options: {
|
|
6
|
-
imports?: any[];
|
|
7
|
-
useFactory: (...args: any[]) => SecurityClientConfig | Promise<SecurityClientConfig>;
|
|
8
|
-
inject?: any[];
|
|
9
|
-
}): DynamicModule;
|
|
10
5
|
}
|
|
@@ -10,9 +10,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.SecurityClientModule = void 0;
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
12
|
const security_client_service_1 = require("../services/security-client.service");
|
|
13
|
-
const
|
|
13
|
+
const cognito_auth_guard_1 = require("../guards/cognito-auth.guard");
|
|
14
14
|
const role_guard_1 = require("../guards/role.guard");
|
|
15
|
-
const provider_guard_1 = require("../guards/provider.guard");
|
|
16
15
|
let SecurityClientModule = SecurityClientModule_1 = class SecurityClientModule {
|
|
17
16
|
static forRoot(config) {
|
|
18
17
|
if (!config.securityServiceUrl || typeof config.securityServiceUrl !== 'string' || config.securityServiceUrl.trim() === '') {
|
|
@@ -32,38 +31,13 @@ let SecurityClientModule = SecurityClientModule_1 = class SecurityClientModule {
|
|
|
32
31
|
useValue: config,
|
|
33
32
|
},
|
|
34
33
|
security_client_service_1.SecurityClientService,
|
|
35
|
-
|
|
34
|
+
cognito_auth_guard_1.SecurityAuthGuard,
|
|
36
35
|
role_guard_1.RoleGuard,
|
|
37
|
-
provider_guard_1.ProviderGuard,
|
|
38
36
|
],
|
|
39
37
|
exports: [
|
|
40
38
|
security_client_service_1.SecurityClientService,
|
|
41
|
-
|
|
39
|
+
cognito_auth_guard_1.SecurityAuthGuard,
|
|
42
40
|
role_guard_1.RoleGuard,
|
|
43
|
-
provider_guard_1.ProviderGuard,
|
|
44
|
-
],
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
static forRootAsync(options) {
|
|
48
|
-
return {
|
|
49
|
-
module: SecurityClientModule_1,
|
|
50
|
-
imports: options.imports || [],
|
|
51
|
-
providers: [
|
|
52
|
-
{
|
|
53
|
-
provide: security_client_service_1.SECURITY_CLIENT_CONFIG,
|
|
54
|
-
useFactory: options.useFactory,
|
|
55
|
-
inject: options.inject || [],
|
|
56
|
-
},
|
|
57
|
-
security_client_service_1.SecurityClientService,
|
|
58
|
-
security_auth_guard_1.SecurityAuthGuard,
|
|
59
|
-
role_guard_1.RoleGuard,
|
|
60
|
-
provider_guard_1.ProviderGuard,
|
|
61
|
-
],
|
|
62
|
-
exports: [
|
|
63
|
-
security_client_service_1.SecurityClientService,
|
|
64
|
-
security_auth_guard_1.SecurityAuthGuard,
|
|
65
|
-
role_guard_1.RoleGuard,
|
|
66
|
-
provider_guard_1.ProviderGuard,
|
|
67
41
|
],
|
|
68
42
|
};
|
|
69
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security-client.module.js","sourceRoot":"","sources":["../../src/module/security-client.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA+D;AAC/D,iFAAoG;AACpG,
|
|
1
|
+
{"version":3,"file":"security-client.module.js","sourceRoot":"","sources":["../../src/module/security-client.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA+D;AAC/D,iFAAoG;AACpG,qEAAiE;AACjE,qDAAiD;AAK1C,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAC/B,MAAM,CAAC,OAAO,CAAC,MAA4B;QACzC,IAAI,CAAC,MAAM,CAAC,kBAAkB,IAAI,OAAO,MAAM,CAAC,kBAAkB,KAAK,QAAQ,IAAI,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAC3H,MAAM,IAAI,KAAK,CAAC,uFAAuF,CAAC,CAAC;QAC3G,CAAC;QAED,IAAI,CAAC;YACH,IAAI,GAAG,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;QACrC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,sCAAsC,MAAM,CAAC,kBAAkB,wBAAwB,CAAC,CAAC;QAC3G,CAAC;QAED,OAAO;YACL,MAAM,EAAE,sBAAoB;YAC5B,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,gDAAsB;oBAC/B,QAAQ,EAAE,MAAM;iBACjB;gBACD,+CAAqB;gBACrB,sCAAiB;gBACjB,sBAAS;aACV;YACD,OAAO,EAAE;gBACP,+CAAqB;gBACrB,sCAAiB;gBACjB,sBAAS;aACV;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA9BY,oDAAoB;+BAApB,oBAAoB;IAFhC,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,oBAAoB,CA8BhC"}
|
|
@@ -5,22 +5,7 @@ export declare class SecurityClientService {
|
|
|
5
5
|
private readonly config;
|
|
6
6
|
private readonly logger;
|
|
7
7
|
private readonly httpClient;
|
|
8
|
-
private readonly cache;
|
|
9
|
-
private readonly cacheTtlMs;
|
|
10
|
-
private readonly maxCacheSize;
|
|
11
|
-
private readonly retryAttempts;
|
|
12
|
-
private readonly retryDelayMs;
|
|
13
8
|
constructor(config: SecurityClientConfig);
|
|
14
|
-
private hashToken;
|
|
15
|
-
private getCached;
|
|
16
|
-
private setCache;
|
|
17
|
-
evictExpired(): void;
|
|
18
|
-
private isAuthError;
|
|
19
|
-
private withRetry;
|
|
20
9
|
validateTokenAndGetUser(token: string): Promise<AuthUser>;
|
|
21
10
|
getUserById(userId: string, token: string): Promise<AuthUser>;
|
|
22
|
-
healthCheck(): Promise<{
|
|
23
|
-
healthy: boolean;
|
|
24
|
-
responseTimeMs: number;
|
|
25
|
-
}>;
|
|
26
11
|
}
|
|
@@ -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,21 @@ 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 =
|
|
116
|
-
?
|
|
117
|
-
:
|
|
45
|
+
const raw = response.data;
|
|
46
|
+
const userData = raw.message && typeof raw.message === 'object' && !Array.isArray(raw.message)
|
|
47
|
+
? raw.message
|
|
48
|
+
: raw;
|
|
118
49
|
if (!userData.id || !userData.email || !userData.role || !userData.status) {
|
|
119
50
|
this.logger.warn('Security service returned incomplete user data', {
|
|
120
51
|
hasId: !!userData.id,
|
|
@@ -124,9 +55,7 @@ let SecurityClientService = SecurityClientService_1 = class SecurityClientServic
|
|
|
124
55
|
});
|
|
125
56
|
throw new Error('Incomplete user data from security service');
|
|
126
57
|
}
|
|
127
|
-
|
|
128
|
-
this.setCache(cacheKey, user);
|
|
129
|
-
return user;
|
|
58
|
+
return userData;
|
|
130
59
|
}
|
|
131
60
|
catch (error) {
|
|
132
61
|
this.logger.error(`Error validating token: ${error.message}`);
|
|
@@ -140,18 +69,18 @@ let SecurityClientService = SecurityClientService_1 = class SecurityClientServic
|
|
|
140
69
|
}
|
|
141
70
|
async getUserById(userId, token) {
|
|
142
71
|
try {
|
|
143
|
-
const response = await this.
|
|
72
|
+
const response = await this.httpClient.get(`/api/v1/security/users/${userId}`, {
|
|
144
73
|
headers: {
|
|
145
74
|
Authorization: `Bearer ${token}`,
|
|
146
75
|
},
|
|
147
|
-
})
|
|
76
|
+
});
|
|
148
77
|
if (!response.data || typeof response.data !== 'object') {
|
|
149
78
|
throw new Error('Invalid response format from security service');
|
|
150
79
|
}
|
|
151
|
-
const
|
|
152
|
-
const userData =
|
|
153
|
-
?
|
|
154
|
-
:
|
|
80
|
+
const raw = response.data;
|
|
81
|
+
const userData = raw.message && typeof raw.message === 'object' && !Array.isArray(raw.message)
|
|
82
|
+
? raw.message
|
|
83
|
+
: raw;
|
|
155
84
|
if (!userData.id || !userData.email || !userData.role || !userData.status) {
|
|
156
85
|
this.logger.warn('Security service returned incomplete user data', {
|
|
157
86
|
hasId: !!userData.id,
|
|
@@ -173,17 +102,6 @@ let SecurityClientService = SecurityClientService_1 = class SecurityClientServic
|
|
|
173
102
|
throw new Error(`Failed to connect to security service: ${error.message}`);
|
|
174
103
|
}
|
|
175
104
|
}
|
|
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
105
|
};
|
|
188
106
|
exports.SecurityClientService = SecurityClientService;
|
|
189
107
|
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,CAA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CAAA;;GALtB,qBAAqB,CAiGjC"}
|
|
@@ -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.2",
|
|
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,8 +42,8 @@
|
|
|
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
|
}
|
|
49
48
|
}
|
|
49
|
+
|