@volontariapp/auth 1.0.0-next.20260403124714

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.
Files changed (45) hide show
  1. package/dist/auth.module.d.ts +6 -0
  2. package/dist/auth.module.d.ts.map +1 -0
  3. package/dist/auth.module.js +33 -0
  4. package/dist/auth.module.js.map +1 -0
  5. package/dist/constants/index.d.ts +3 -0
  6. package/dist/constants/index.d.ts.map +1 -0
  7. package/dist/constants/index.js +3 -0
  8. package/dist/constants/index.js.map +1 -0
  9. package/dist/decorators/current-user.decorator.d.ts +2 -0
  10. package/dist/decorators/current-user.decorator.d.ts.map +1 -0
  11. package/dist/decorators/current-user.decorator.js +10 -0
  12. package/dist/decorators/current-user.decorator.js.map +1 -0
  13. package/dist/guards/grpc-internal.guard.d.ts +9 -0
  14. package/dist/guards/grpc-internal.guard.d.ts.map +1 -0
  15. package/dist/guards/grpc-internal.guard.js +50 -0
  16. package/dist/guards/grpc-internal.guard.js.map +1 -0
  17. package/dist/index.d.ts +10 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +10 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/interceptors/grpc-internal.interceptor.d.ts +9 -0
  22. package/dist/interceptors/grpc-internal.interceptor.d.ts.map +1 -0
  23. package/dist/interceptors/grpc-internal.interceptor.js +34 -0
  24. package/dist/interceptors/grpc-internal.interceptor.js.map +1 -0
  25. package/dist/interfaces/auth-config.interface.d.ts +7 -0
  26. package/dist/interfaces/auth-config.interface.d.ts.map +1 -0
  27. package/dist/interfaces/auth-config.interface.js +2 -0
  28. package/dist/interfaces/auth-config.interface.js.map +1 -0
  29. package/dist/interfaces/auth-user.interface.d.ts +5 -0
  30. package/dist/interfaces/auth-user.interface.d.ts.map +1 -0
  31. package/dist/interfaces/auth-user.interface.js +2 -0
  32. package/dist/interfaces/auth-user.interface.js.map +1 -0
  33. package/dist/interfaces/index.d.ts +3 -0
  34. package/dist/interfaces/index.d.ts.map +1 -0
  35. package/dist/interfaces/index.js +3 -0
  36. package/dist/interfaces/index.js.map +1 -0
  37. package/dist/services/grpc-metadata.helper.d.ts +9 -0
  38. package/dist/services/grpc-metadata.helper.d.ts.map +1 -0
  39. package/dist/services/grpc-metadata.helper.js +30 -0
  40. package/dist/services/grpc-metadata.helper.js.map +1 -0
  41. package/dist/services/jwt.service.d.ts +11 -0
  42. package/dist/services/jwt.service.d.ts.map +1 -0
  43. package/dist/services/jwt.service.js +66 -0
  44. package/dist/services/jwt.service.js.map +1 -0
  45. package/package.json +55 -0
@@ -0,0 +1,6 @@
1
+ import type { DynamicModule } from '@nestjs/common';
2
+ import type { AuthConfig } from './interfaces/index.js';
3
+ export declare class AuthModule {
4
+ static register(options: AuthConfig): DynamicModule;
5
+ }
6
+ //# sourceMappingURL=auth.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.module.d.ts","sourceRoot":"","sources":["../src/auth.module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAIpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD,qBAEa,UAAU;IACrB,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,aAAa;CAcpD"}
@@ -0,0 +1,33 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var AuthModule_1;
8
+ import { Module, Global } from '@nestjs/common';
9
+ import { JwtService } from './services/jwt.service.js';
10
+ import { AUTH_OPTIONS } from './constants/index.js';
11
+ import { GrpcMetadataHelper } from './services/grpc-metadata.helper.js';
12
+ let AuthModule = AuthModule_1 = class AuthModule {
13
+ static register(options) {
14
+ return {
15
+ module: AuthModule_1,
16
+ providers: [
17
+ {
18
+ provide: AUTH_OPTIONS,
19
+ useValue: options,
20
+ },
21
+ JwtService,
22
+ GrpcMetadataHelper,
23
+ ],
24
+ exports: [JwtService, GrpcMetadataHelper],
25
+ };
26
+ }
27
+ };
28
+ AuthModule = AuthModule_1 = __decorate([
29
+ Global(),
30
+ Module({})
31
+ ], AuthModule);
32
+ export { AuthModule };
33
+ //# sourceMappingURL=auth.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../src/auth.module.ts"],"names":[],"mappings":";;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAIjE,IAAM,UAAU,kBAAhB,MAAM,UAAU;IACrB,MAAM,CAAC,QAAQ,CAAC,OAAmB;QACjC,OAAO;YACL,MAAM,EAAE,YAAU;YAClB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,YAAY;oBACrB,QAAQ,EAAE,OAAO;iBAClB;gBACD,UAAU;gBACV,kBAAkB;aACnB;YACD,OAAO,EAAE,CAAC,UAAU,EAAE,kBAAkB,CAAC;SAC1C,CAAC;IACJ,CAAC;CACF,CAAA;AAfY,UAAU;IAFtB,MAAM,EAAE;IACR,MAAM,CAAC,EAAE,CAAC;GACE,UAAU,CAetB"}
@@ -0,0 +1,3 @@
1
+ export declare const INTERNAL_TOKEN_METADATA_KEY = "x-internal-token";
2
+ export declare const AUTH_OPTIONS = "AUTH_OPTIONS";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,qBAAqB,CAAC;AAC9D,eAAO,MAAM,YAAY,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export const INTERNAL_TOKEN_METADATA_KEY = 'x-internal-token';
2
+ export const AUTH_OPTIONS = 'AUTH_OPTIONS';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,2BAA2B,GAAG,kBAAkB,CAAC;AAC9D,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const CurrentUser: (...dataOrPipes: unknown[]) => ParameterDecorator;
2
+ //# sourceMappingURL=current-user.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-user.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/current-user.decorator.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,mDASvB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { createParamDecorator } from '@nestjs/common';
2
+ export const CurrentUser = createParamDecorator((_data, ctx) => {
3
+ if (ctx.getType() === 'rpc') {
4
+ const rpcContext = ctx.switchToRpc().getContext();
5
+ return rpcContext.user;
6
+ }
7
+ const request = ctx.switchToHttp().getRequest();
8
+ return request.user;
9
+ });
10
+ //# sourceMappingURL=current-user.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-user.decorator.js","sourceRoot":"","sources":["../../src/decorators/current-user.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAGtD,MAAM,CAAC,MAAM,WAAW,GAAG,oBAAoB,CAC7C,CAAC,KAAc,EAAE,GAAqB,EAAwB,EAAE;IAC9D,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,EAAE,CAAC;QAC5B,MAAM,UAAU,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,UAAU,EAA2B,CAAC;QAC3E,OAAO,UAAU,CAAC,IAA4B,CAAC;IACjD,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAuB,CAAC;IACrE,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC,CACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { CanActivate, ExecutionContext } from '@nestjs/common';
2
+ import type { JwtService } from '../services/jwt.service.js';
3
+ export declare class GrpcInternalGuard implements CanActivate {
4
+ private readonly jwtService;
5
+ private readonly logger;
6
+ constructor(jwtService: JwtService);
7
+ canActivate(context: ExecutionContext): Promise<boolean>;
8
+ }
9
+ //# sourceMappingURL=grpc-internal.guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grpc-internal.guard.d.ts","sourceRoot":"","sources":["../../src/guards/grpc-internal.guard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAG7D,qBACa,iBAAkB,YAAW,WAAW;IAGvC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAFvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;gBAEhC,UAAU,EAAE,UAAU;IAE7C,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CA6B/D"}
@@ -0,0 +1,50 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var GrpcInternalGuard_1;
11
+ import { Injectable, Logger } from '@nestjs/common';
12
+ import { UnauthorizedError } from '@volontariapp/errors';
13
+ import { INTERNAL_TOKEN_METADATA_KEY } from '../constants/index.js';
14
+ let GrpcInternalGuard = GrpcInternalGuard_1 = class GrpcInternalGuard {
15
+ jwtService;
16
+ logger = new Logger(GrpcInternalGuard_1.name);
17
+ constructor(jwtService) {
18
+ this.jwtService = jwtService;
19
+ }
20
+ async canActivate(context) {
21
+ if (context.getType() !== 'rpc') {
22
+ return true;
23
+ }
24
+ const rpcArgumentsHost = context.switchToRpc();
25
+ const metadata = rpcArgumentsHost.getContext();
26
+ const tokens = metadata.get(INTERNAL_TOKEN_METADATA_KEY);
27
+ if (tokens.length === 0) {
28
+ this.logger.warn(`Missing ${INTERNAL_TOKEN_METADATA_KEY} in metadata`);
29
+ throw new UnauthorizedError('Missing internal token');
30
+ }
31
+ const token = tokens[0];
32
+ try {
33
+ const user = await this.jwtService.verifyInternal(token);
34
+ const rpcContext = rpcArgumentsHost.getContext();
35
+ rpcContext.user = user;
36
+ return true;
37
+ }
38
+ catch (error) {
39
+ const message = error instanceof Error ? error.message : 'Unknown error';
40
+ this.logger.error(`Invalid internal token: ${message}`);
41
+ throw new UnauthorizedError('Invalid internal token');
42
+ }
43
+ }
44
+ };
45
+ GrpcInternalGuard = GrpcInternalGuard_1 = __decorate([
46
+ Injectable(),
47
+ __metadata("design:paramtypes", [Function])
48
+ ], GrpcInternalGuard);
49
+ export { GrpcInternalGuard };
50
+ //# sourceMappingURL=grpc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AAG,IAAI,CAAC;YAEvB,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;YACzE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,OAAO,EAAE,CAAC,CAAC;YACxD,MAAM,IAAI,iBAAiB,CAAC,wBAAwB,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;CACF,CAAA;AAlCY,iBAAiB;IAD7B,UAAU,EAAE;;GACA,iBAAiB,CAkC7B"}
@@ -0,0 +1,10 @@
1
+ import 'reflect-metadata';
2
+ export * from './constants/index.js';
3
+ export * from './interfaces/index.js';
4
+ export * from './services/jwt.service.js';
5
+ export * from './services/grpc-metadata.helper.js';
6
+ export * from './auth.module.js';
7
+ export * from './guards/grpc-internal.guard.js';
8
+ export * from './decorators/current-user.decorator.js';
9
+ export * from './interceptors/grpc-internal.interceptor.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kBAAkB,CAAC;AACjC,cAAc,iCAAiC,CAAC;AAChD,cAAc,wCAAwC,CAAC;AACvD,cAAc,6CAA6C,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import 'reflect-metadata';
2
+ export * from './constants/index.js';
3
+ export * from './interfaces/index.js';
4
+ export * from './services/jwt.service.js';
5
+ export * from './services/grpc-metadata.helper.js';
6
+ export * from './auth.module.js';
7
+ export * from './guards/grpc-internal.guard.js';
8
+ export * from './decorators/current-user.decorator.js';
9
+ export * from './interceptors/grpc-internal.interceptor.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kBAAkB,CAAC;AACjC,cAAc,iCAAiC,CAAC;AAChD,cAAc,wCAAwC,CAAC;AACvD,cAAc,6CAA6C,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
2
+ import type { Observable } from 'rxjs';
3
+ import type { JwtService } from '../services/jwt.service.js';
4
+ export declare class GrpcInternalInterceptor implements NestInterceptor {
5
+ private readonly jwtService;
6
+ constructor(jwtService: JwtService);
7
+ intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
8
+ }
9
+ //# sourceMappingURL=grpc-internal.interceptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grpc-internal.interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptors/grpc-internal.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAErF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAG7D,qBACa,uBAAwB,YAAW,eAAe;IACjD,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,UAAU;IAEnD,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;CAc7E"}
@@ -0,0 +1,34 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Injectable } from '@nestjs/common';
11
+ import { from } from 'rxjs';
12
+ import { switchMap } from 'rxjs/operators';
13
+ let GrpcInternalInterceptor = class GrpcInternalInterceptor {
14
+ jwtService;
15
+ constructor(jwtService) {
16
+ this.jwtService = jwtService;
17
+ }
18
+ intercept(context, next) {
19
+ const httpRequest = context.switchToHttp().getRequest();
20
+ const user = httpRequest.user;
21
+ if (!user) {
22
+ return next.handle();
23
+ }
24
+ return from(this.jwtService.signInternal(user)).pipe(switchMap((_token) => {
25
+ return next.handle();
26
+ }));
27
+ }
28
+ };
29
+ GrpcInternalInterceptor = __decorate([
30
+ Injectable(),
31
+ __metadata("design:paramtypes", [Function])
32
+ ], GrpcInternalInterceptor);
33
+ export { GrpcInternalInterceptor };
34
+ //# sourceMappingURL=grpc-internal.interceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grpc-internal.interceptor.js","sourceRoot":"","sources":["../../src/interceptors/grpc-internal.interceptor.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKpC,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IACL;IAA7B,YAA6B,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAEvD,SAAS,CAAC,OAAyB,EAAE,IAAiB;QACpD,MAAM,WAAW,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAuB,CAAC;QAC7E,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC;QAE9B,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC;QAED,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAClD,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;YACnB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF,CAAA;AAjBY,uBAAuB;IADnC,UAAU,EAAE;;GACA,uBAAuB,CAiBnC"}
@@ -0,0 +1,7 @@
1
+ export interface AuthConfig {
2
+ internalSecret: string;
3
+ gatewaySecret: string;
4
+ internalExpiresIn: number;
5
+ gatewayExpiresIn: number;
6
+ }
7
+ //# sourceMappingURL=auth-config.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-config.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/auth-config.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;CAC1B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=auth-config.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-config.interface.js","sourceRoot":"","sources":["../../src/interfaces/auth-config.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export interface AuthUser {
2
+ id: string;
3
+ role: string;
4
+ }
5
+ //# sourceMappingURL=auth-user.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-user.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/auth-user.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=auth-user.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-user.interface.js","sourceRoot":"","sources":["../../src/interfaces/auth-user.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from './auth-user.interface.js';
2
+ export * from './auth-config.interface.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './auth-user.interface.js';
2
+ export * from './auth-config.interface.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Metadata } from '@grpc/grpc-js';
2
+ import type { JwtService } from './jwt.service.js';
3
+ import type { AuthUser } from '../interfaces/index.js';
4
+ export declare class GrpcMetadataHelper {
5
+ private readonly jwtService;
6
+ constructor(jwtService: JwtService);
7
+ createInternalMetadata(user: AuthUser): Promise<Metadata>;
8
+ }
9
+ //# sourceMappingURL=grpc-metadata.helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grpc-metadata.helper.d.ts","sourceRoot":"","sources":["../../src/services/grpc-metadata.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD,qBACa,kBAAkB;IACjB,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,UAAU;IAE7C,sBAAsB,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;CAMhE"}
@@ -0,0 +1,30 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Injectable } from '@nestjs/common';
11
+ import { Metadata } from '@grpc/grpc-js';
12
+ import { INTERNAL_TOKEN_METADATA_KEY } from '../constants/index.js';
13
+ let GrpcMetadataHelper = class GrpcMetadataHelper {
14
+ jwtService;
15
+ constructor(jwtService) {
16
+ this.jwtService = jwtService;
17
+ }
18
+ async createInternalMetadata(user) {
19
+ const metadata = new Metadata();
20
+ const token = await this.jwtService.signInternal(user);
21
+ metadata.add(INTERNAL_TOKEN_METADATA_KEY, token);
22
+ return metadata;
23
+ }
24
+ };
25
+ GrpcMetadataHelper = __decorate([
26
+ Injectable(),
27
+ __metadata("design:paramtypes", [Function])
28
+ ], GrpcMetadataHelper);
29
+ export { GrpcMetadataHelper };
30
+ //# sourceMappingURL=grpc-metadata.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grpc-metadata.helper.js","sourceRoot":"","sources":["../../src/services/grpc-metadata.helper.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAI7D,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IACA;IAA7B,YAA6B,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAEvD,KAAK,CAAC,sBAAsB,CAAC,IAAc;QACzC,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACvD,QAAQ,CAAC,GAAG,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;QACjD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAA;AATY,kBAAkB;IAD9B,UAAU,EAAE;;GACA,kBAAkB,CAS9B"}
@@ -0,0 +1,11 @@
1
+ import type { AuthConfig, AuthUser } from '../interfaces/index.js';
2
+ export declare class JwtService {
3
+ private readonly options;
4
+ private readonly internalSecret;
5
+ private readonly gatewaySecret?;
6
+ constructor(options: AuthConfig);
7
+ signInternal(user: AuthUser): Promise<string>;
8
+ verifyInternal(token: string): Promise<AuthUser>;
9
+ verifyExternal(token: string): Promise<AuthUser>;
10
+ }
11
+ //# sourceMappingURL=jwt.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.service.d.ts","sourceRoot":"","sources":["../../src/services/jwt.service.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEnE,qBACa,UAAU;IAIa,OAAO,CAAC,QAAQ,CAAC,OAAO;IAH1D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAa;IAC5C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAa;gBAEO,OAAO,EAAE,UAAU;IAkBhE,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAY7C,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAKhD,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;CAQvD"}
@@ -0,0 +1,66 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { Inject, Injectable } from '@nestjs/common';
14
+ import * as jose from 'jose';
15
+ import { InternalServerError } from '@volontariapp/errors';
16
+ import { AUTH_OPTIONS } from '../constants/index.js';
17
+ let JwtService = class JwtService {
18
+ options;
19
+ internalSecret;
20
+ gatewaySecret;
21
+ constructor(options) {
22
+ this.options = options;
23
+ if (!options.internalSecret) {
24
+ throw new InternalServerError('Internal secret not configured', 'AUTH_CONFIG_ERROR');
25
+ }
26
+ if (!options.internalExpiresIn) {
27
+ throw new InternalServerError('Internal expiration time not configured', 'AUTH_CONFIG_ERROR');
28
+ }
29
+ if (!options.gatewaySecret) {
30
+ throw new InternalServerError('Gateway secret not configured', 'AUTH_CONFIG_ERROR');
31
+ }
32
+ if (!options.gatewayExpiresIn) {
33
+ throw new InternalServerError('Gateway expiration time not configured', 'AUTH_CONFIG_ERROR');
34
+ }
35
+ this.internalSecret = new TextEncoder().encode(options.internalSecret);
36
+ this.gatewaySecret = new TextEncoder().encode(options.gatewaySecret);
37
+ }
38
+ async signInternal(user) {
39
+ const sessionPayload = { ...user };
40
+ const token = await new jose.SignJWT(sessionPayload)
41
+ .setProtectedHeader({ alg: 'HS256' })
42
+ .setIssuedAt()
43
+ .setExpirationTime(this.options.internalExpiresIn.toString())
44
+ .sign(this.internalSecret);
45
+ return token;
46
+ }
47
+ async verifyInternal(token) {
48
+ const { payload } = await jose.jwtVerify(token, this.internalSecret);
49
+ return payload;
50
+ }
51
+ async verifyExternal(token) {
52
+ const secret = this.gatewaySecret;
53
+ if (!secret) {
54
+ throw new InternalServerError('Gateway secret not configured', 'AUTH_CONFIG_ERROR');
55
+ }
56
+ const { payload } = await jose.jwtVerify(token, secret);
57
+ return payload;
58
+ }
59
+ };
60
+ JwtService = __decorate([
61
+ Injectable(),
62
+ __param(0, Inject(AUTH_OPTIONS)),
63
+ __metadata("design:paramtypes", [Object])
64
+ ], JwtService);
65
+ export { JwtService };
66
+ //# sourceMappingURL=jwt.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.service.js","sourceRoot":"","sources":["../../src/services/jwt.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAI9C,IAAM,UAAU,GAAhB,MAAM,UAAU;IAI8B;IAHlC,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AC,KAAa;QAChC,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QACrE,OAAO,OAA8B,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,KAAa;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC;QAClC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,mBAAmB,CAAC,+BAA+B,EAAE,mBAAmB,CAAC,CAAC;QACtF,CAAC;QACD,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACxD,OAAO,OAA8B,CAAC;IACxC,CAAC;CACF,CAAA;AA/CY,UAAU;IADtB,UAAU,EAAE;IAKE,WAAA,MAAM,CAAC,YAAY,CAAC,CAAA;;GAJtB,UAAU,CA+CtB"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@volontariapp/auth",
3
+ "version": "1.0.0-next.20260403124714",
4
+ "publishConfig": {
5
+ "access": "public",
6
+ "provenance": true
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Volontariapp/npm-packages.git"
11
+ },
12
+ "description": "",
13
+ "license": "UNLICENSED",
14
+ "type": "module",
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "engines": {
27
+ "node": ">=24.14.0"
28
+ },
29
+ "scripts": {
30
+ "prepublishOnly": "yarn build",
31
+ "build": "tsc -p tsconfig.json",
32
+ "lint": "eslint src/",
33
+ "test": "echo \"No tests yet\""
34
+ },
35
+ "dependencies": {
36
+ "@volontariapp/errors": "0.2.0",
37
+ "jose": "^6.2.2",
38
+ "reflect-metadata": "^0.2.2",
39
+ "rxjs": "^7.8.1"
40
+ },
41
+ "peerDependencies": {
42
+ "@grpc/grpc-js": "^1.12.0",
43
+ "@nestjs/common": "^10.0.0 || ^11.0.0",
44
+ "@nestjs/core": "^10.0.0 || ^11.0.0",
45
+ "@nestjs/microservices": "^10.0.0 || ^11.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "@grpc/grpc-js": "^1.12.0",
49
+ "@nestjs/common": "^11.0.0",
50
+ "@nestjs/core": "^11.0.0",
51
+ "@nestjs/microservices": "^11.0.0",
52
+ "@types/node": "^24.1.0",
53
+ "typescript": "5.7.3"
54
+ }
55
+ }