@alacard-project/shared 1.0.7 → 1.0.8
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/enums/user.enum.d.ts +0 -1
- package/package.json +2 -2
- package/proto/auth.proto +11 -2
- package/src/constants/env.constants.ts +1 -0
- package/src/constants/grpc.constants.ts +2 -1
- package/src/contracts/auth.contract.ts +12 -1
- package/src/contracts/index.ts +11 -1
- package/src/utils/app.utils.ts +0 -11
package/package.json
CHANGED
package/proto/auth.proto
CHANGED
|
@@ -3,7 +3,7 @@ syntax = "proto3";
|
|
|
3
3
|
package auth;
|
|
4
4
|
|
|
5
5
|
service AuthService {
|
|
6
|
-
rpc
|
|
6
|
+
rpc CreateIdentity (CreateIdentityRequest) returns (TokenResponse);
|
|
7
7
|
rpc Login (LoginRequest) returns (TokenResponse);
|
|
8
8
|
rpc Validate (ValidateRequest) returns (ValidateResponse);
|
|
9
9
|
rpc GetUserById (GetUserByIdRequest) returns (UserResponse);
|
|
@@ -11,14 +11,23 @@ service AuthService {
|
|
|
11
11
|
rpc ValidateToken (ValidateTokenRequest) returns (ValidateTokenResponse);
|
|
12
12
|
rpc RefreshToken (RefreshTokenRequest) returns (TokenResponse);
|
|
13
13
|
rpc RevokeToken (RevokeTokenRequest) returns (RevokeTokenResponse);
|
|
14
|
+
rpc GenerateTokens (GenerateTokensRequest) returns (TokenResponse);
|
|
14
15
|
rpc CheckPermission (CheckPermissionRequest) returns (CheckPermissionResponse);
|
|
15
16
|
rpc GetUserPermissions (GetUserPermissionsRequest) returns (GetUserPermissionsResponse);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
message
|
|
19
|
+
message GenerateTokensRequest {
|
|
20
|
+
string userId = 1;
|
|
21
|
+
string email = 2;
|
|
22
|
+
string role = 3;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
message CreateIdentityRequest {
|
|
19
26
|
string email = 1;
|
|
20
27
|
string password = 2;
|
|
21
28
|
string name = 3;
|
|
29
|
+
string userId = 4;
|
|
30
|
+
string role = 5;
|
|
22
31
|
}
|
|
23
32
|
|
|
24
33
|
message LoginRequest {
|
|
@@ -8,6 +8,7 @@ export const ENV_KEYS = {
|
|
|
8
8
|
KAFKA_BROKERS: 'KAFKA_BROKERS',
|
|
9
9
|
JWT_SECRET: 'JWT_SECRET',
|
|
10
10
|
JWT_EXPIRES_IN: 'JWT_EXPIRES_IN',
|
|
11
|
+
JWT_REFRESH_SECRET: 'JWT_REFRESH_SECRET',
|
|
11
12
|
JWT_REFRESH_EXPIRES_IN: 'JWT_REFRESH_EXPIRES_IN',
|
|
12
13
|
GRPC_PORT: 'GRPC_PORT',
|
|
13
14
|
GRPC_URL: 'GRPC_URL',
|
|
@@ -19,13 +19,14 @@ export const GRPC_METHODS = {
|
|
|
19
19
|
AUTH: {
|
|
20
20
|
SERVICE: 'AuthService',
|
|
21
21
|
LOGIN: 'Login',
|
|
22
|
-
|
|
22
|
+
CREATE_IDENTITY: 'CreateIdentity',
|
|
23
23
|
VALIDATE: 'Validate',
|
|
24
24
|
GET_USER_BY_ID: 'GetUserById',
|
|
25
25
|
GET_USER_BY_EMAIL: 'GetUserByEmail',
|
|
26
26
|
VALIDATE_TOKEN: 'ValidateToken',
|
|
27
27
|
REFRESH_TOKEN: 'RefreshToken',
|
|
28
28
|
REVOKE_TOKEN: 'RevokeToken',
|
|
29
|
+
GENERATE_TOKENS: 'GenerateTokens',
|
|
29
30
|
CHECK_PERMISSION: 'CheckPermission',
|
|
30
31
|
GET_USER_PERMISSIONS: 'GetUserPermissions',
|
|
31
32
|
},
|
|
@@ -54,6 +54,14 @@ export interface GetUserPermissionsGrpcRequest {
|
|
|
54
54
|
userId: string;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
export interface CreateIdentityRequest {
|
|
58
|
+
email: string;
|
|
59
|
+
password: string;
|
|
60
|
+
name?: string;
|
|
61
|
+
userId: string;
|
|
62
|
+
role: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
57
65
|
export interface GetUserPermissionsGrpcResponse {
|
|
58
66
|
userId: string;
|
|
59
67
|
permissions: Array<{ resource: string; action: string }>;
|
|
@@ -101,9 +109,12 @@ export type GetUserByEmailRequest = GetUserByEmailGrpcRequest;
|
|
|
101
109
|
export type GetUserPermissionsRequest = GetUserPermissionsGrpcRequest;
|
|
102
110
|
export type DeleteUserResponse = { success: boolean };
|
|
103
111
|
|
|
112
|
+
import { GenerateTokensRequest } from './token.contract';
|
|
113
|
+
|
|
104
114
|
export interface IAuthService {
|
|
105
115
|
loginGrpc(data: LoginDto): Observable<JwtTokens>;
|
|
106
|
-
|
|
116
|
+
generateTokensGrpc(data: GenerateTokensRequest): Observable<JwtTokens>;
|
|
117
|
+
createIdentityGrpc(data: CreateIdentityRequest): Observable<any>;
|
|
107
118
|
validateGrpc(data: { token: string }): Observable<{ valid: boolean; userId?: string; email?: string; role?: string }>;
|
|
108
119
|
validateTokenGrpc(data: ValidateTokenGrpcRequest): Observable<ValidateTokenGrpcResponse>;
|
|
109
120
|
refreshTokenGrpc(data: RefreshTokenGrpcRequest): Observable<JwtTokens>;
|
package/src/contracts/index.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
export * from './config.contract';
|
|
2
2
|
export * from './logging.contract';
|
|
3
3
|
export * from './auth.contract';
|
|
4
|
-
export * from './token.contract';
|
|
4
|
+
// export * from './token.contract';
|
|
5
|
+
export type {
|
|
6
|
+
GenerateTokensRequest,
|
|
7
|
+
TokensResponse,
|
|
8
|
+
ITokenService,
|
|
9
|
+
ValidateTokenRequest,
|
|
10
|
+
ValidateTokenResponse,
|
|
11
|
+
RefreshTokensRequest,
|
|
12
|
+
RevokeTokenRequest,
|
|
13
|
+
RevokeTokenResponse
|
|
14
|
+
} from './token.contract';
|
package/src/utils/app.utils.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Application Setup Utilities
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
1
|
import { INestApplication, ValidationPipe } from '@nestjs/common';
|
|
6
2
|
import { API_PREFIX } from '../constants/http.constants';
|
|
7
3
|
import helmet from 'helmet';
|
|
@@ -13,9 +9,6 @@ export interface AppSetupOptions {
|
|
|
13
9
|
validation?: boolean;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
/**
|
|
17
|
-
* Setup standard NestJS application middleware
|
|
18
|
-
*/
|
|
19
12
|
export function setupStandardApp(
|
|
20
13
|
app: INestApplication,
|
|
21
14
|
options: AppSetupOptions = {}
|
|
@@ -27,21 +20,17 @@ export function setupStandardApp(
|
|
|
27
20
|
validation = true,
|
|
28
21
|
} = options;
|
|
29
22
|
|
|
30
|
-
// CORS
|
|
31
23
|
app.enableCors({
|
|
32
24
|
origin: corsOrigins,
|
|
33
25
|
credentials: true,
|
|
34
26
|
});
|
|
35
27
|
|
|
36
|
-
// API Prefix
|
|
37
28
|
app.setGlobalPrefix(apiPrefix);
|
|
38
29
|
|
|
39
|
-
// Security
|
|
40
30
|
if (useHelmet) {
|
|
41
31
|
app.use(helmet());
|
|
42
32
|
}
|
|
43
33
|
|
|
44
|
-
// Validation
|
|
45
34
|
if (validation) {
|
|
46
35
|
app.useGlobalPipes(
|
|
47
36
|
new ValidationPipe({
|