2019-12-16 08:49:10 +00:00
|
|
|
import { AxiosPromise } from "axios";
|
2021-03-22 09:22:24 +00:00
|
|
|
import Api from "api/Api";
|
2022-04-12 10:50:01 +00:00
|
|
|
import { ApiResponse } from "api/ApiResponses";
|
2019-12-16 08:49:10 +00:00
|
|
|
|
|
|
|
|
export interface LoginUserRequest {
|
|
|
|
|
email: string;
|
|
|
|
|
password: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CreateUserRequest {
|
|
|
|
|
email: string;
|
|
|
|
|
password: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
export type CreateUserResponse = ApiResponse & {
|
2019-12-16 08:49:10 +00:00
|
|
|
email: string;
|
|
|
|
|
id: string;
|
2022-06-21 13:57:34 +00:00
|
|
|
};
|
2019-12-16 08:49:10 +00:00
|
|
|
|
|
|
|
|
export interface ForgotPasswordRequest {
|
|
|
|
|
email: string;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 09:07:30 +00:00
|
|
|
export interface TokenPasswordUpdateRequest {
|
2019-12-16 08:49:10 +00:00
|
|
|
token: string;
|
2020-01-06 09:07:30 +00:00
|
|
|
password: string;
|
|
|
|
|
email: string;
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-06 09:07:30 +00:00
|
|
|
export interface VerifyTokenRequest {
|
2019-12-16 08:49:10 +00:00
|
|
|
email: string;
|
|
|
|
|
token: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
export type FetchUserResponse = ApiResponse & {
|
2019-12-23 12:16:33 +00:00
|
|
|
id: string;
|
2022-06-21 13:57:34 +00:00
|
|
|
};
|
2019-12-23 12:16:33 +00:00
|
|
|
|
|
|
|
|
export interface FetchUserRequest {
|
|
|
|
|
id: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
export interface LeaveWorkspaceRequest {
|
|
|
|
|
workspaceId: string;
|
2021-06-02 09:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-23 12:16:33 +00:00
|
|
|
export interface InviteUserRequest {
|
|
|
|
|
email: string;
|
|
|
|
|
groupIds: string[];
|
|
|
|
|
status?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 09:37:02 +00:00
|
|
|
export interface UpdateUserRequest {
|
2021-05-20 12:03:08 +00:00
|
|
|
name?: string;
|
|
|
|
|
email?: string;
|
2021-10-21 05:36:17 +00:00
|
|
|
role?: string;
|
|
|
|
|
useCase?: string;
|
2021-03-04 09:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-09 12:11:45 +00:00
|
|
|
export interface SendTestEmailPayload {
|
|
|
|
|
smtpHost: string;
|
|
|
|
|
fromEmail: string;
|
|
|
|
|
smtpPort?: string;
|
|
|
|
|
username?: string;
|
|
|
|
|
password?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-12 16:36:43 +00:00
|
|
|
export interface CreateSuperUserRequest {
|
|
|
|
|
email: string;
|
|
|
|
|
name: string;
|
|
|
|
|
source: "FORM";
|
|
|
|
|
state: "ACTIVATED";
|
|
|
|
|
isEnabled: boolean;
|
|
|
|
|
password: string;
|
|
|
|
|
role: "Developer";
|
|
|
|
|
companyName: string;
|
|
|
|
|
allowCollectingAnonymousData: boolean;
|
|
|
|
|
signupForNewsletter: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-12 10:50:01 +00:00
|
|
|
export class UserApi extends Api {
|
2020-01-06 09:07:30 +00:00
|
|
|
static usersURL = "v1/users";
|
|
|
|
|
static forgotPasswordURL = `${UserApi.usersURL}/forgotPassword`;
|
|
|
|
|
static verifyResetPasswordTokenURL = `${UserApi.usersURL}/verifyPasswordResetToken`;
|
|
|
|
|
static resetPasswordURL = `${UserApi.usersURL}/resetPassword`;
|
2019-12-23 12:16:33 +00:00
|
|
|
static inviteUserURL = "v1/users/invite";
|
2020-01-06 09:07:30 +00:00
|
|
|
static verifyInviteTokenURL = `${UserApi.inviteUserURL}/verify`;
|
|
|
|
|
static confirmUserInviteURL = `${UserApi.inviteUserURL}/confirm`;
|
2022-06-15 15:37:41 +00:00
|
|
|
static addWorkspaceURL = `${UserApi.usersURL}/addWorkspace`;
|
|
|
|
|
static leaveWorkspaceURL = `${UserApi.usersURL}/leaveWorkspace`;
|
2020-01-22 12:26:25 +00:00
|
|
|
static logoutURL = "v1/logout";
|
2020-07-08 10:14:03 +00:00
|
|
|
static currentUserURL = "v1/users/me";
|
2021-05-20 12:03:08 +00:00
|
|
|
static photoURL = "v1/users/photo";
|
2021-08-05 06:10:19 +00:00
|
|
|
static featureFlagsURL = "v1/users/features";
|
2021-09-12 16:36:43 +00:00
|
|
|
static superUserURL = "v1/users/super";
|
2021-10-18 07:47:55 +00:00
|
|
|
static adminSettingsURL = "v1/admin/env";
|
|
|
|
|
static restartServerURL = "v1/admin/restart";
|
2021-10-21 04:57:10 +00:00
|
|
|
static downloadConfigURL = "v1/admin/env/download";
|
2021-11-09 07:01:36 +00:00
|
|
|
static sendTestEmailURL = "/v1/admin/send-test-email";
|
2020-01-06 09:07:30 +00:00
|
|
|
|
2019-12-16 08:49:10 +00:00
|
|
|
static createUser(
|
|
|
|
|
request: CreateUserRequest,
|
|
|
|
|
): AxiosPromise<CreateUserResponse> {
|
2020-01-06 09:07:30 +00:00
|
|
|
return Api.post(UserApi.usersURL, request);
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-04 09:37:02 +00:00
|
|
|
static updateUser(request: UpdateUserRequest): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.put(UserApi.usersURL, request);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 09:07:30 +00:00
|
|
|
static fetchUser(request: FetchUserRequest): AxiosPromise<FetchUserResponse> {
|
|
|
|
|
return Api.get(UserApi.usersURL + "/" + request.id);
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-08 10:14:03 +00:00
|
|
|
static getCurrentUser(): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.get(UserApi.currentUserURL);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 09:07:30 +00:00
|
|
|
static forgotPassword(
|
|
|
|
|
request: ForgotPasswordRequest,
|
2019-12-16 08:49:10 +00:00
|
|
|
): AxiosPromise<ApiResponse> {
|
2020-01-06 09:07:30 +00:00
|
|
|
return Api.post(UserApi.forgotPasswordURL, request);
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static verifyResetPasswordToken(
|
2020-01-06 09:07:30 +00:00
|
|
|
request: VerifyTokenRequest,
|
2019-12-16 08:49:10 +00:00
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.get(UserApi.verifyResetPasswordTokenURL, request);
|
|
|
|
|
}
|
2019-12-23 12:16:33 +00:00
|
|
|
|
2020-01-06 09:07:30 +00:00
|
|
|
static resetPassword(
|
|
|
|
|
request: TokenPasswordUpdateRequest,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.put(UserApi.resetPasswordURL, request);
|
2019-12-23 12:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inviteUser(request: InviteUserRequest): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.post(UserApi.inviteUserURL, request);
|
|
|
|
|
}
|
2020-01-03 08:49:47 +00:00
|
|
|
|
2020-01-06 09:07:30 +00:00
|
|
|
static verifyUserInvite(
|
|
|
|
|
request: VerifyTokenRequest,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.get(UserApi.verifyInviteTokenURL, request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static confirmInvitedUserSignup(
|
|
|
|
|
request: TokenPasswordUpdateRequest,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.put(UserApi.confirmUserInviteURL, request);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-03 08:49:47 +00:00
|
|
|
static logoutUser(): AxiosPromise<ApiResponse> {
|
2020-01-22 12:26:25 +00:00
|
|
|
return Api.post(UserApi.logoutURL);
|
2020-01-03 08:49:47 +00:00
|
|
|
}
|
2021-05-20 12:03:08 +00:00
|
|
|
|
2021-12-02 05:56:41 +00:00
|
|
|
static uploadPhoto(request: {
|
|
|
|
|
file: File;
|
|
|
|
|
}): AxiosPromise<{
|
|
|
|
|
id: string;
|
|
|
|
|
new: boolean;
|
|
|
|
|
profilePhotoAssetId: string;
|
2022-06-15 15:37:41 +00:00
|
|
|
recentlyUsedWorkspaceIds: string[];
|
2021-12-02 05:56:41 +00:00
|
|
|
}> {
|
2021-05-20 12:03:08 +00:00
|
|
|
const formData = new FormData();
|
|
|
|
|
if (request.file) {
|
|
|
|
|
formData.append("file", request.file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Api.post(UserApi.photoURL, formData, null, {
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "multipart/form-data",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static deletePhoto(): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.delete(UserApi.photoURL);
|
|
|
|
|
}
|
2021-06-02 09:56:22 +00:00
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
static leaveWorkspace(
|
|
|
|
|
request: LeaveWorkspaceRequest,
|
|
|
|
|
): AxiosPromise<LeaveWorkspaceRequest> {
|
|
|
|
|
return Api.put(UserApi.leaveWorkspaceURL + "/" + request.workspaceId);
|
2021-06-02 09:56:22 +00:00
|
|
|
}
|
2021-08-05 06:10:19 +00:00
|
|
|
|
|
|
|
|
static fetchFeatureFlags(): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.get(UserApi.featureFlagsURL);
|
|
|
|
|
}
|
2021-09-12 16:36:43 +00:00
|
|
|
|
|
|
|
|
static createSuperUser(
|
|
|
|
|
request: CreateSuperUserRequest,
|
|
|
|
|
): AxiosPromise<CreateUserResponse> {
|
|
|
|
|
return Api.post(UserApi.superUserURL, request);
|
|
|
|
|
}
|
2021-10-01 16:25:55 +00:00
|
|
|
|
2021-10-21 04:57:10 +00:00
|
|
|
/*
|
|
|
|
|
* Super user endpoints
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-18 07:47:55 +00:00
|
|
|
static fetchAdminSettings(): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.get(UserApi.adminSettingsURL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static saveAdminSettings(
|
|
|
|
|
request: Record<string, string>,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.put(UserApi.adminSettingsURL, request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static restartServer(): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.post(UserApi.restartServerURL);
|
|
|
|
|
}
|
2021-11-09 07:01:36 +00:00
|
|
|
|
2021-12-09 12:11:45 +00:00
|
|
|
static sendTestEmail(
|
|
|
|
|
payload: SendTestEmailPayload,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.post(UserApi.sendTestEmailURL, payload);
|
2021-11-09 07:01:36 +00:00
|
|
|
}
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default UserApi;
|