Skip to content

Commit 410f319

Browse files
feat/impersonation - types and constants (#2431)
* added types file for impersonation Requests * all types and constants required for impersonation * fixed constants and types according to review comments * updated isImpersonationStarted field to isImpersonationFinished
1 parent c5fed60 commit 410f319

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

config/custom-environment-variables.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ module.exports = {
8888
__name: "USER_TOKEN_REFRESH_TTL",
8989
__format: "number",
9090
},
91+
impersonationTtl: {
92+
__name: "USER_TOKEN_IMPERSONATION_TTL",
93+
__format: "number",
94+
},
9195
publicKey: "PUBLIC_KEY",
9296
privateKey: "PRIVATE_KEY",
9397
},

config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ module.exports = {
8686
cookieV2Name: `rds-session-v2-${NODE_ENV}`,
8787
ttl: 30 * 24 * 60 * 60, // in seconds
8888
refreshTtl: 180 * 24 * 60 * 60, // in seconds
89+
impersonationTtl: 15 * 60, // in seconds
8990
publicKey: "<publicKey>",
9091
privateKey: "<privateKey>",
9192
},

constants/requests.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,9 @@ export const INVALID_REQUEST_TYPE = "Invalid request type";
6868
export const INVALID_REQUEST_DEADLINE = "New deadline of the request must be greater than old deadline";
6969
export const REQUEST_UPDATED_SUCCESSFULLY = "Request updated successfully";
7070
export const UNAUTHORIZED_TO_UPDATE_REQUEST = "Unauthorized to update request";
71+
72+
export const FEATURE_NOT_IMPLEMENTED = "Feature not implemented";
73+
74+
export const IMPERSONATION_NOT_COMPLETED = "Please complete impersonation before creating a new request";
75+
export const IMPERSONATION_ALREADY_ATTEMPTED = "No active request is available for impersonation";
76+
export const IMPERSONATION_REQUEST_NOT_APPROVED = "Awaiting approval for impersonation request";

types/impersonationRequest.d.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { Request, Response } from "express";
2+
import { REQUEST_STATE } from "../constants/requests";
3+
import { Boom } from "express-boom";
4+
import {RequestQuery } from "./requests";
5+
import { userData } from "./global";
6+
import { Timestamp } from "firebase-admin/firestore";
7+
8+
export type ImpersonationRequest = {
9+
id: string;
10+
status: REQUEST_STATE;
11+
isImpersonationFinished: boolean;
12+
createdBy: string;
13+
createdFor: string;
14+
userId: string;
15+
reason: string;
16+
message?: string;
17+
impersonatedUserId: string;
18+
createdAt: Timestamp;
19+
updatedAt: Timestamp;
20+
startedAt?: Timestamp;
21+
endedAt?: Timestamp;
22+
}
23+
24+
export type CreateImpersonationRequestBody = {
25+
impersonatedUserId: string;
26+
reason: string;
27+
};
28+
29+
export type CreateImpersonationRequestModelBody = {
30+
status: REQUEST_STATE;
31+
isImpersonationFinished: boolean;
32+
createdBy: string;
33+
createdFor: string;
34+
userId: string;
35+
reason: string;
36+
impersonatedUserId: string;
37+
}
38+
39+
export type UpdateImpersonationRequestDataBody = {
40+
startedAt?: Timestamp;
41+
endedAt: Timestamp;
42+
isImpersonationFinished?: boolean;
43+
}
44+
45+
export type UpdateImpersonationRequestStatusBody = {
46+
status: REQUEST_STATE.APPROVED | REQUEST_STATE.REJECTED;
47+
message?: string;
48+
}
49+
50+
export type ImpersonationRequestQuery = RequestQuery & {
51+
dev?: string;
52+
};
53+
54+
export type ImpersonationRequestResponse = Response & {
55+
boom: Boom;
56+
};
57+
58+
export type RequestParams = {
59+
id: string;
60+
}
61+
62+
export type CreateImpersonationRequest = Request & {
63+
userData: userData;
64+
body: CreateImpersonationRequestBody;
65+
query: ImpersonationRequestQuery;
66+
};
67+
68+
export type UpdateImpersonationRequestStatus = Request & {
69+
userData: userData;
70+
body: UpdateImpersonationRequestStatusBody;
71+
query: ImpersonationRequestQuery;
72+
params: RequestParams;
73+
}
74+
75+
export type PaginatedImpersonationRequests = {
76+
allRequests: ImpersonationRequest[];
77+
next: string;
78+
prev: string;
79+
page: number;
80+
count: number;
81+
}

0 commit comments

Comments
 (0)