Add eslint rule and fix as many issues as possible

This commit is contained in:
Khoa Le
2023-06-19 23:42:04 -04:00
parent e9eacc445d
commit 9d33e4756b
689 changed files with 9446 additions and 21821 deletions
+3 -4
View File
@@ -1,7 +1,6 @@
export {
useGetAuthToken,
useSendMfaToken,
useVerifyMfaToken,
useGetCommonPasswords,
useRevokeAllSessions,
useGetCommonPasswords
} from './queries'
useSendMfaToken,
useVerifyMfaToken} from "./queries"
+11 -11
View File
@@ -1,23 +1,23 @@
import { useMutation, useQuery } from '@tanstack/react-query';
import { useMutation, useQuery } from "@tanstack/react-query";
import { apiRequest } from '@app/config/request';
import { setAuthToken } from '@app/reactQuery';
import { apiRequest } from "@app/config/request";
import { setAuthToken } from "@app/reactQuery";
import {
GetAuthTokenAPI,
SendMfaTokenDTO,
VerifyMfaTokenDTO,
VerifyMfaTokenRes} from './types';
VerifyMfaTokenRes} from "./types";
const authKeys = {
getAuthToken: ['token'] as const,
commonPasswords: ['common-passwords'] as const
getAuthToken: ["token"] as const,
commonPasswords: ["common-passwords"] as const
};
export const useSendMfaToken = () => {
return useMutation<{}, {}, SendMfaTokenDTO>({
mutationFn: async ({ email }) => {
const { data } = await apiRequest.post('/api/v2/auth/mfa/send', { email });
const { data } = await apiRequest.post("/api/v2/auth/mfa/send", { email });
return data;
}
});
@@ -26,7 +26,7 @@ export const useSendMfaToken = () => {
export const useVerifyMfaToken = () => {
return useMutation<VerifyMfaTokenRes, {}, VerifyMfaTokenDTO>({
mutationFn: async ({ email, mfaCode }) => {
const { data } = await apiRequest.post('/api/v2/auth/mfa/verify', {
const { data } = await apiRequest.post("/api/v2/auth/mfa/verify", {
email,
mfaToken: mfaCode
});
@@ -38,7 +38,7 @@ export const useVerifyMfaToken = () => {
// Refresh token is set as cookie when logged in
// Using that we fetch the auth bearer token needed for auth calls
const fetchAuthToken = async () => {
const { data } = await apiRequest.post<GetAuthTokenAPI>('/api/v1/auth/token', undefined, {
const { data } = await apiRequest.post<GetAuthTokenAPI>("/api/v1/auth/token", undefined, {
withCredentials: true
});
@@ -54,14 +54,14 @@ export const useGetAuthToken = () =>
export const useRevokeAllSessions = () => {
return useMutation({
mutationFn: async () => {
const { data } = await apiRequest.delete('/api/v1/auth/sessions');
const { data } = await apiRequest.delete("/api/v1/auth/sessions");
return data;
}
});
}
const fetchCommonPasswords = async () => {
const { data } = await apiRequest.get('/api/v1/auth/common-passwords');
const { data } = await apiRequest.get("/api/v1/auth/common-passwords");
return data || [];
};
@@ -2,4 +2,4 @@ export {
useAddIncidentContact,
useDeleteIncidentContact,
useGetOrgIncidentContact
} from './queries';
} from "./queries";
@@ -1,11 +1,11 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from '@app/config/request';
import { apiRequest } from "@app/config/request";
import { AddIncidentContactDTO, DeleteIncidentContactDTO, IncidentContact } from './types';
import { AddIncidentContactDTO, DeleteIncidentContactDTO, IncidentContact } from "./types";
const incidentContactKeys = {
getAllContact: (orgId: string) => ['org-incident-contacts', { orgId }] as const
getAllContact: (orgId: string) => ["org-incident-contacts", { orgId }] as const
};
const fetchOrgIncidentContacts = async (orgId: string) => {
+13 -13
View File
@@ -1,13 +1,13 @@
export * from './auth';
export * from './incidentContacts';
export * from './keys';
export * from './organization';
export * from './secretFolders';
export * from './secrets';
export * from './secretSnapshots';
export * from './serviceAccounts';
export * from './serviceTokens';
export * from './subscriptions';
export * from './tags';
export * from './users';
export * from './workspace';
export * from "./auth";
export * from "./incidentContacts";
export * from "./keys";
export * from "./organization";
export * from "./secretFolders";
export * from "./secrets";
export * from "./secretSnapshots";
export * from "./serviceAccounts";
export * from "./serviceTokens";
export * from "./subscriptions";
export * from "./tags";
export * from "./users";
export * from "./workspace";
@@ -4,4 +4,4 @@ export {
useGetIntegrationAuthRailwayEnvironments,
useGetIntegrationAuthRailwayServices,
useGetIntegrationAuthTeams,
useGetIntegrationAuthVercelBranches} from './queries';
useGetIntegrationAuthVercelBranches} from "./queries";
@@ -8,33 +8,33 @@ import {
IntegrationAuth,
Service,
Team
} from './types';
} from "./types";
const integrationAuthKeys = {
getIntegrationAuthById: (integrationAuthId: string) => [{ integrationAuthId }, 'integrationAuth'] as const,
getIntegrationAuthApps: (integrationAuthId: string, teamId?: string) => [{ integrationAuthId, teamId }, 'integrationAuthApps'] as const,
getIntegrationAuthTeams: (integrationAuthId: string) => [{ integrationAuthId }, 'integrationAuthTeams'] as const,
getIntegrationAuthById: (integrationAuthId: string) => [{ integrationAuthId }, "integrationAuth"] as const,
getIntegrationAuthApps: (integrationAuthId: string, teamId?: string) => [{ integrationAuthId, teamId }, "integrationAuthApps"] as const,
getIntegrationAuthTeams: (integrationAuthId: string) => [{ integrationAuthId }, "integrationAuthTeams"] as const,
getIntegrationAuthVercelBranches: ({
integrationAuthId,
appId,
}: {
integrationAuthId: string;
appId: string;
}) => [{ integrationAuthId, appId }, 'integrationAuthVercelBranches'] as const,
}) => [{ integrationAuthId, appId }, "integrationAuthVercelBranches"] as const,
getIntegrationAuthRailwayEnvironments: ({
integrationAuthId,
appId
}: {
integrationAuthId: string;
appId: string;
}) => [{ integrationAuthId, appId }, 'integrationAuthRailwayEnvironments'] as const,
}) => [{ integrationAuthId, appId }, "integrationAuthRailwayEnvironments"] as const,
getIntegrationAuthRailwayServices: ({
integrationAuthId,
appId
}: {
integrationAuthId: string;
appId: string;
}) => [{ integrationAuthId, appId }, 'integrationAuthRailwayServices'] as const
}) => [{ integrationAuthId, appId }, "integrationAuthRailwayServices"] as const
}
const fetchIntegrationAuthById = async (integrationAuthId: string) => {
+1 -1
View File
@@ -1 +1 @@
export { useGetUserWsKey, useUploadWsKey } from './queries';
export { useGetUserWsKey, useUploadWsKey } from "./queries";
+4 -4
View File
@@ -1,11 +1,11 @@
import { useMutation, useQuery } from '@tanstack/react-query';
import { useMutation, useQuery } from "@tanstack/react-query";
import { apiRequest } from '@app/config/request';
import { apiRequest } from "@app/config/request";
import { UploadWsKeyDTO, UserWsKeyPair } from './types';
import { UploadWsKeyDTO, UserWsKeyPair } from "./types";
const encKeyKeys = {
getUserWorkspaceKey: (workspaceID: string) => ['workspace-key-pair', { workspaceID }] as const
getUserWorkspaceKey: (workspaceID: string) => ["workspace-key-pair", { workspaceID }] as const
};
const fetchUserWsKey = async (workspaceID: string) => {
+1 -1
View File
@@ -1 +1 @@
export { useGetOrganization, useRenameOrg } from './queries';
export { useGetOrganization, useRenameOrg } from "./queries";
@@ -1,15 +1,15 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from '@app/config/request';
import { apiRequest } from "@app/config/request";
import { Organization, RenameOrgDTO } from './types';
import { Organization, RenameOrgDTO } from "./types";
const organizationKeys = {
getUserOrganization: ['organization'] as const
getUserOrganization: ["organization"] as const
};
const fetchUserOrganization = async () => {
const { data } = await apiRequest.get<{ organizations: Organization[] }>('/api/v1/organization');
const { data } = await apiRequest.get<{ organizations: Organization[] }>("/api/v1/organization");
return data.organizations;
};
@@ -4,4 +4,4 @@ export {
useGetProjectFolders,
useGetProjectFoldersBatch,
useUpdateFolder
} from './queries';
} from "./queries";
@@ -1,9 +1,9 @@
import { useCallback } from 'react';
import { useMutation, useQueries, useQuery, useQueryClient } from '@tanstack/react-query';
import { useCallback } from "react";
import { useMutation, useQueries, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from '@app/config/request';
import { apiRequest } from "@app/config/request";
import { secretSnapshotKeys } from '../secretSnapshots/queries';
import { secretSnapshotKeys } from "../secretSnapshots/queries";
import {
CreateFolderDTO,
DeleteFolderDTO,
@@ -11,11 +11,11 @@ import {
GetProjectFoldersDTO,
TSecretFolder,
UpdateFolderDTO
} from './types';
} from "./types";
const queryKeys = {
getSecretFolders: (workspaceId: string, environment: string, parentFolderId?: string) =>
['secret-folders', { workspaceId, environment, parentFolderId }] as const
["secret-folders", { workspaceId, environment, parentFolderId }] as const
};
const fetchProjectFolders = async (
@@ -25,7 +25,7 @@ const fetchProjectFolders = async (
parentFolderPath?: string
) => {
const { data } = await apiRequest.get<{ folders: TSecretFolder[]; dir: TSecretFolder[] }>(
'/api/v1/folders',
"/api/v1/folders",
{
params: {
workspaceId,
@@ -53,9 +53,9 @@ export const useGetProjectFolders = ({
({ folders, dir }: { folders: TSecretFolder[]; dir: TSecretFolder[] }) => ({
dir,
folders: folders.sort((a, b) =>
sortDir === 'asc'
? a?.name?.localeCompare(b?.name || '')
: b?.name?.localeCompare(a?.name || '')
sortDir === "asc"
? a?.name?.localeCompare(b?.name || "")
: b?.name?.localeCompare(a?.name || "")
)
}),
[sortDir]
@@ -86,7 +86,7 @@ export const useCreateFolder = () => {
return useMutation<{}, {}, CreateFolderDTO>({
mutationFn: async (dto) => {
const { data } = await apiRequest.post('/api/v1/folders', dto);
const { data } = await apiRequest.post("/api/v1/folders", dto);
return data;
},
onSuccess: (_, { workspaceId, environment, parentFolderId }) => {
@@ -8,11 +8,11 @@ export type GetProjectFoldersDTO = {
environment: string;
parentFolderId?: string;
isPaused?: boolean;
sortDir?: 'asc' | 'desc';
sortDir?: "asc" | "desc";
};
export type GetProjectFoldersBatchDTO = {
folders: Omit<GetProjectFoldersDTO, 'isPaused' | 'sortDir'>[];
folders: Omit<GetProjectFoldersDTO, "isPaused" | "sortDir">[];
isPaused?: boolean;
parentFolderPath?: string;
};
@@ -3,4 +3,4 @@ export {
useGetWorkspaceSecretSnapshots,
useGetWsSnapshotCount,
usePerformSecretRollback
} from './queries';
} from "./queries";
@@ -1,29 +1,29 @@
/* eslint-disable no-param-reassign */
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import {
decryptAssymmetric,
decryptSymmetric
} from '@app/components/utilities/cryptography/crypto';
import { apiRequest } from '@app/config/request';
} from "@app/components/utilities/cryptography/crypto";
import { apiRequest } from "@app/config/request";
import { DecryptedSecret } from '../secrets/types';
import { DecryptedSecret } from "../secrets/types";
import {
GetWorkspaceSecretSnapshotsDTO,
TSecretRollbackDTO,
TSnapshotSecret,
TSnapshotSecretProps,
TWorkspaceSecretSnapshot
} from './types';
} from "./types";
export const secretSnapshotKeys = {
list: (workspaceId: string, env: string, folderId?: string) =>
[{ workspaceId, env, folderId }, 'secret-snapshot'] as const,
snapshotSecrets: (snapshotId: string) => [{ snapshotId }, 'secret-snapshot'] as const,
[{ workspaceId, env, folderId }, "secret-snapshot"] as const,
snapshotSecrets: (snapshotId: string) => [{ snapshotId }, "secret-snapshot"] as const,
count: (workspaceId: string, env: string, folderId?: string) => [
{ workspaceId, env, folderId },
'count',
'secret-snapshot'
"count",
"secret-snapshot"
]
};
@@ -78,7 +78,7 @@ export const useGetSnapshotSecrets = ({ decryptFileKey, env, snapshotId }: TSnap
enabled: Boolean(snapshotId && decryptFileKey),
queryFn: () => fetchSnapshotEncSecrets(snapshotId),
select: (data) => {
const PRIVATE_KEY = localStorage.getItem('PRIVATE_KEY') as string;
const PRIVATE_KEY = localStorage.getItem("PRIVATE_KEY") as string;
const latestKey = decryptFileKey;
const key = decryptAssymmetric({
ciphertext: latestKey.encryptedKey,
@@ -106,7 +106,7 @@ export const useGetSnapshotSecrets = ({ decryptFileKey, env, snapshotId }: TSnap
key
});
const secretComment = '';
const secretComment = "";
const decryptedSecret = {
_id: encSecret.secret,
@@ -117,10 +117,10 @@ export const useGetSnapshotSecrets = ({ decryptFileKey, env, snapshotId }: TSnap
comment: secretComment,
createdAt: encSecret.createdAt,
updatedAt: encSecret.updatedAt,
type: 'modified'
type: "modified"
};
if (encSecret.type === 'personal') {
if (encSecret.type === "personal") {
personalSecrets[decryptedSecret.key] = { id: encSecret.secret, value: secretValue };
} else {
sharedSecrets.push(decryptedSecret);
@@ -131,7 +131,7 @@ export const useGetSnapshotSecrets = ({ decryptFileKey, env, snapshotId }: TSnap
if (personalSecrets?.[val.key]) {
val.idOverride = personalSecrets[val.key].id;
val.valueOverride = personalSecrets[val.key].value;
val.overrideAction = 'modified';
val.overrideAction = "modified";
}
});
@@ -180,7 +180,7 @@ export const usePerformSecretRollback = () => {
return data;
},
onSuccess: (_, { workspaceId, environment, folderId }) => {
queryClient.invalidateQueries([{ workspaceId, environment }, 'secrets']);
queryClient.invalidateQueries([{ workspaceId, environment }, "secrets"]);
queryClient.invalidateQueries(secretSnapshotKeys.list(workspaceId, environment, folderId));
queryClient.invalidateQueries(secretSnapshotKeys.count(workspaceId, environment, folderId));
}
@@ -1,5 +1,5 @@
import { UserWsKeyPair } from '../keys/types';
import { EncryptedSecretVersion } from '../secrets/types';
import { UserWsKeyPair } from "../keys/types";
import { EncryptedSecretVersion } from "../secrets/types";
export type TWorkspaceSecretSnapshot = {
_id: string;
@@ -11,7 +11,7 @@ export type TWorkspaceSecretSnapshot = {
__v: number;
};
export type TSnapshotSecret = Omit<TWorkspaceSecretSnapshot, 'secretVersions'> & {
export type TSnapshotSecret = Omit<TWorkspaceSecretSnapshot, "secretVersions"> & {
secretVersions: EncryptedSecretVersion[];
folderVersion: Array<{ name: string; id: string }>;
};
+1 -1
View File
@@ -3,4 +3,4 @@ export {
useGetProjectSecrets,
useGetProjectSecretsByKey,
useGetSecretVersion
} from './queries';
} from "./queries";
+20 -20
View File
@@ -1,14 +1,14 @@
/* eslint-disable no-param-reassign */
import { useCallback } from 'react';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useCallback } from "react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import {
decryptAssymmetric,
decryptSymmetric
} from '@app/components/utilities/cryptography/crypto';
import { apiRequest } from '@app/config/request';
} from "@app/components/utilities/cryptography/crypto";
import { apiRequest } from "@app/config/request";
import { secretSnapshotKeys } from '../secretSnapshots/queries';
import { secretSnapshotKeys } from "../secretSnapshots/queries";
import {
BatchSecretDTO,
DecryptedSecret,
@@ -16,15 +16,15 @@ import {
EncryptedSecretVersion,
GetProjectSecretsDTO,
GetSecretVersionsDTO
} from './types';
} from "./types";
export const secretKeys = {
// this is also used in secretSnapshot part
getProjectSecret: (workspaceId: string, env: string | string[], folderId?: string) => [
{ workspaceId, env, folderId },
'secrets'
"secrets"
],
getSecretVersion: (secretId: string) => [{ secretId }, 'secret-versions']
getSecretVersion: (secretId: string) => [{ secretId }, "secret-versions"]
};
const fetchProjectEncryptedSecrets = async (
@@ -33,8 +33,8 @@ const fetchProjectEncryptedSecrets = async (
folderId?: string,
secretPath?: string
) => {
if (typeof env === 'string') {
const { data } = await apiRequest.get<{ secrets: EncryptedSecret[] }>('/api/v2/secrets', {
if (typeof env === "string") {
const { data } = await apiRequest.get<{ secrets: EncryptedSecret[] }>("/api/v2/secrets", {
params: {
environment: env,
workspaceId,
@@ -45,13 +45,13 @@ const fetchProjectEncryptedSecrets = async (
return data.secrets;
}
if (typeof env === 'object') {
if (typeof env === "object") {
let allEnvData: any = [];
// eslint-disable-next-line no-restricted-syntax
for (const envPoint of env) {
// eslint-disable-next-line no-await-in-loop
const { data } = await apiRequest.get<{ secrets: EncryptedSecret[] }>('/api/v2/secrets', {
const { data } = await apiRequest.get<{ secrets: EncryptedSecret[] }>("/api/v2/secrets", {
params: {
environment: envPoint,
workspaceId,
@@ -82,7 +82,7 @@ export const useGetProjectSecrets = ({
queryKey: secretKeys.getProjectSecret(workspaceId, env, folderId),
queryFn: () => fetchProjectEncryptedSecrets(workspaceId, env, folderId),
select: useCallback((data: EncryptedSecret[]) => {
const PRIVATE_KEY = localStorage.getItem('PRIVATE_KEY') as string;
const PRIVATE_KEY = localStorage.getItem("PRIVATE_KEY") as string;
const latestKey = decryptFileKey;
const key = decryptAssymmetric({
ciphertext: latestKey.encryptedKey,
@@ -129,7 +129,7 @@ export const useGetProjectSecrets = ({
updatedAt: encSecret.updatedAt
};
if (encSecret.type === 'personal') {
if (encSecret.type === "personal") {
personalSecrets[`${decryptedSecret.key}-${decryptedSecret.env}`] = {
id: encSecret._id,
value: secretValue
@@ -146,7 +146,7 @@ export const useGetProjectSecrets = ({
if (personalSecrets?.[dupKey]) {
val.idOverride = personalSecrets[dupKey].id;
val.valueOverride = personalSecrets[dupKey].value;
val.overrideAction = 'modified';
val.overrideAction = "modified";
}
});
return { secrets: sharedSecrets };
@@ -168,7 +168,7 @@ export const useGetProjectSecretsByKey = ({
queryKey: secretKeys.getProjectSecret(workspaceId, env, secretPath),
queryFn: () => fetchProjectEncryptedSecrets(workspaceId, env, folderId, secretPath),
select: useCallback((data: EncryptedSecret[]) => {
const PRIVATE_KEY = localStorage.getItem('PRIVATE_KEY') as string;
const PRIVATE_KEY = localStorage.getItem("PRIVATE_KEY") as string;
const latestKey = decryptFileKey;
const key = decryptAssymmetric({
ciphertext: latestKey.encryptedKey,
@@ -217,7 +217,7 @@ export const useGetProjectSecretsByKey = ({
updatedAt: encSecret.updatedAt
};
if (encSecret.type === 'personal') {
if (encSecret.type === "personal") {
personalSecrets[`${decryptedSecret.key}-${decryptedSecret.env}`] = {
id: encSecret._id,
value: secretValue
@@ -236,7 +236,7 @@ export const useGetProjectSecretsByKey = ({
if (personalSecrets?.[dupKey]) {
val.idOverride = personalSecrets[dupKey].id;
val.valueOverride = personalSecrets[dupKey].value;
val.overrideAction = 'modified';
val.overrideAction = "modified";
}
});
});
@@ -264,7 +264,7 @@ export const useGetSecretVersion = (dto: GetSecretVersionsDTO) =>
queryKey: secretKeys.getSecretVersion(dto.secretId),
queryFn: () => fetchEncryptedSecretVersion(dto.secretId, dto.offset, dto.limit),
select: useCallback((data: EncryptedSecretVersion[]) => {
const PRIVATE_KEY = localStorage.getItem('PRIVATE_KEY') as string;
const PRIVATE_KEY = localStorage.getItem("PRIVATE_KEY") as string;
const latestKey = dto.decryptFileKey;
const key = decryptAssymmetric({
ciphertext: latestKey.encryptedKey,
@@ -293,7 +293,7 @@ export const useBatchSecretsOp = () => {
return useMutation<{}, {}, BatchSecretDTO>({
mutationFn: async (dto) => {
const { data } = await apiRequest.post('/api/v2/secrets/batch', dto);
const { data } = await apiRequest.post("/api/v2/secrets/batch", dto);
return data;
},
onSuccess: (_, dto) => {
+8 -8
View File
@@ -1,11 +1,11 @@
import type { UserWsKeyPair } from '../keys/types';
import type { WsTag } from '../tags/types';
import type { UserWsKeyPair } from "../keys/types";
import type { WsTag } from "../tags/types";
export type EncryptedSecret = {
_id: string;
version: number;
workspace: string;
type: 'shared' | 'personal';
type: "shared" | "personal";
environment: string;
secretKeyCiphertext: string;
secretKeyIV: string;
@@ -62,7 +62,7 @@ type SecretTagArg = { _id: string; name: string; slug: string };
export type UpdateSecretArg = {
_id: string;
folderId?: string;
type: 'shared' | 'personal';
type: "shared" | "personal";
secretName: string;
secretKeyCiphertext: string;
secretKeyIV: string;
@@ -76,7 +76,7 @@ export type UpdateSecretArg = {
tags: SecretTagArg[];
};
export type CreateSecretArg = Omit<UpdateSecretArg, '_id'>;
export type CreateSecretArg = Omit<UpdateSecretArg, "_id">;
export type DeleteSecretArg = { _id: string };
@@ -85,9 +85,9 @@ export type BatchSecretDTO = {
folderId: string;
environment: string;
requests: Array<
| { method: 'POST'; secret: CreateSecretArg }
| { method: 'PATCH'; secret: UpdateSecretArg }
| { method: 'DELETE'; secret: DeleteSecretArg }
| { method: "POST"; secret: CreateSecretArg }
| { method: "PATCH"; secret: UpdateSecretArg }
| { method: "DELETE"; secret: DeleteSecretArg }
>;
};
@@ -1 +1 @@
export { useFetchServerStatus } from './queries'
export { useFetchServerStatus } from "./queries"
@@ -1,16 +1,16 @@
import {useQuery } from '@tanstack/react-query';
import {useQuery } from "@tanstack/react-query";
import { apiRequest } from '@app/config/request';
import { apiRequest } from "@app/config/request";
import { ServerStatus } from './types';
import { ServerStatus } from "./types";
// cache key
const serverStatusKeys = {
serverStatus: ['serverStatus'] as const
serverStatus: ["serverStatus"] as const
};
const fetchServerStatus = async () => {
const {data} = await apiRequest.get<ServerStatus>('/api/status');
const {data} = await apiRequest.get<ServerStatus>("/api/status");
return data;
};
@@ -7,4 +7,4 @@ export {
useGetServiceAccountProjectLevelPermissions,
useGetServiceAccounts,
useRenameServiceAccount
} from './queries';
} from "./queries";
@@ -1,6 +1,6 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from '@app/config/request';
import { apiRequest } from "@app/config/request";
import {
CreateServiceAccountDTO,
@@ -10,12 +10,12 @@ import {
RenameServiceAccountDTO,
ServiceAccount,
ServiceAccountWorkspacePermission
} from './types';
} from "./types";
const serviceAccountKeys = {
getServiceAccountById: (serviceAccountId: string) => [{ serviceAccountId }, 'service-account'] as const,
getServiceAccounts: (organizationID: string) => [{ organizationID }, 'service-accounts'] as const,
getServiceAccountProjectLevelPermissions: (serviceAccountId: string) => [{ serviceAccountId }, 'service-account-project-level-permissions'] as const
getServiceAccountById: (serviceAccountId: string) => [{ serviceAccountId }, "service-account"] as const,
getServiceAccounts: (organizationID: string) => [{ organizationID }, "service-accounts"] as const,
getServiceAccountProjectLevelPermissions: (serviceAccountId: string) => [{ serviceAccountId }, "service-account-project-level-permissions"] as const
}
const fetchServiceAccounts = async (organizationID: string) => {
@@ -54,7 +54,7 @@ export const useCreateServiceAccount = () => {
return useMutation<CreateServiceAccountRes, {}, CreateServiceAccountDTO>({
mutationFn: async (body) => {
const { data } = await apiRequest.post('/api/v2/service-accounts/', body);
const { data } = await apiRequest.post("/api/v2/service-accounts/", body);
return data;
},
onSuccess: ({ serviceAccount }) => {
@@ -1,4 +1,4 @@
import { Workspace } from '../workspace/types';
import { Workspace } from "../workspace/types";
export type ServiceAccount = {
_id: string;
@@ -1 +1 @@
export { useCreateServiceToken, useDeleteServiceToken, useGetUserWsServiceTokens } from './queries';
export { useCreateServiceToken, useDeleteServiceToken, useGetUserWsServiceTokens } from "./queries";
@@ -1,16 +1,16 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from '@app/config/request';
import { apiRequest } from "@app/config/request";
import {
CreateServiceTokenDTO,
CreateServiceTokenRes,
DeleteServiceTokenRes,
ServiceToken
} from './types';
} from "./types";
const serviceTokenKeys = {
getAllWorkspaceServiceToken: (workspaceID: string) => [{ workspaceID }, 'service-tokens'] as const
getAllWorkspaceServiceToken: (workspaceID: string) => [{ workspaceID }, "service-tokens"] as const
};
const fetchWorkspaceServiceTokens = async (workspaceID: string) => {
@@ -36,7 +36,7 @@ export const useCreateServiceToken = () => {
return useMutation<CreateServiceTokenRes, {}, CreateServiceTokenDTO>({
mutationFn: async (body) => {
const { data } = await apiRequest.post('/api/v2/service-token/', body);
const { data } = await apiRequest.post("/api/v2/service-token/", body);
data.serviceToken += `.${body.randomBytes}`;
return data;
},
@@ -1 +1 @@
export { useGetOrgSubscription } from './queries';
export { useGetOrgSubscription } from "./queries";
@@ -1,13 +1,13 @@
import { useQuery } from '@tanstack/react-query';
import { useQuery } from "@tanstack/react-query";
import { apiRequest } from '@app/config/request';
import { apiRequest } from "@app/config/request";
import { SubscriptionPlan } from './types';
import { SubscriptionPlan } from "./types";
// import { Workspace } from './types';
const subscriptionKeys = {
getOrgSubsription: (orgID: string) => ['plan', { orgID }] as const
getOrgSubsription: (orgID: string) => ["plan", { orgID }] as const
};
const fetchOrgSubscription = async (orgID: string) => {
+3 -3
View File
@@ -1,3 +1,3 @@
export { useGetWsTags } from './queries';
export { useCreateWsTag } from './queries';
export { useDeleteWsTag } from './queries';
export { useGetWsTags } from "./queries";
export { useCreateWsTag } from "./queries";
export { useDeleteWsTag } from "./queries";
+4 -4
View File
@@ -1,6 +1,6 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from '@app/config/request';
import { apiRequest } from "@app/config/request";
import {
CreateTagDTO,
@@ -8,11 +8,11 @@ import {
DeleteTagDTO,
DeleteWsTagRes,
UserWsTags
} from './types';
} from "./types";
const workspaceTags = {
getWsTags: (workspaceID: string) => ['workspace-tags', { workspaceID }] as const
getWsTags: (workspaceID: string) => ["workspace-tags", { workspaceID }] as const
};
const fetchWsTag = async (workspaceID: string) => {
+9 -9
View File
@@ -1,11 +1,11 @@
export type { GetAuthTokenAPI } from './auth/types';
export type { IncidentContact } from './incidentContacts/types';
export type { UserWsKeyPair } from './keys/types';
export type { Organization } from './organization/types';
export type { CreateServiceTokenDTO, ServiceToken } from './serviceTokens/types';
export type { SubscriptionPlan } from './subscriptions/types';
export type { WsTag } from './tags/types';
export type { AddUserToWsDTO, AddUserToWsRes, OrgUser, User } from './users/types';
export type { GetAuthTokenAPI } from "./auth/types";
export type { IncidentContact } from "./incidentContacts/types";
export type { UserWsKeyPair } from "./keys/types";
export type { Organization } from "./organization/types";
export type { CreateServiceTokenDTO, ServiceToken } from "./serviceTokens/types";
export type { SubscriptionPlan } from "./subscriptions/types";
export type { WsTag } from "./tags/types";
export type { AddUserToWsDTO, AddUserToWsRes, OrgUser, User } from "./users/types";
export type {
CreateEnvironmentDTO,
CreateWorkspaceDTO,
@@ -17,4 +17,4 @@ export type {
Workspace,
WorkspaceEnv,
WorkspaceTag
} from './workspace/types';
} from "./workspace/types";
+1 -1
View File
@@ -9,4 +9,4 @@ export {
useLogoutUser,
useRegisterUserAction,
useUpdateOrgUserRole
} from './queries';
} from "./queries";
+21 -21
View File
@@ -1,13 +1,13 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import {
decryptAssymmetric,
encryptAssymmetric
} from '@app/components/utilities/cryptography/crypto';
import { apiRequest } from '@app/config/request';
import { setAuthToken } from '@app/reactQuery';
} from "@app/components/utilities/cryptography/crypto";
import { apiRequest } from "@app/config/request";
import { setAuthToken } from "@app/reactQuery";
import { useUploadWsKey } from '../keys/queries';
import { useUploadWsKey } from "../keys/queries";
import {
AddUserToOrgDTO,
AddUserToWsDTO,
@@ -16,16 +16,16 @@ import {
OrgUser,
UpdateOrgUserRoleDTO,
User
} from './types';
} from "./types";
const userKeys = {
getUser: ['user'] as const,
userAction: ['user-action'] as const,
getOrgUsers: (orgId: string) => [{ orgId }, 'user']
getUser: ["user"] as const,
userAction: ["user-action"] as const,
getOrgUsers: (orgId: string) => [{ orgId }, "user"]
};
const fetchUserDetails = async () => {
const { data } = await apiRequest.get<{ user: User }>('/api/v1/user');
const { data } = await apiRequest.get<{ user: User }>("/api/v1/user");
return data.user;
};
@@ -33,7 +33,7 @@ const fetchUserDetails = async () => {
export const useGetUser = () => useQuery(userKeys.getUser, fetchUserDetails);
const fetchUserAction = async (action: string) => {
const { data } = await apiRequest.get<{ userAction: string }>('/api/v1/user-action', {
const { data } = await apiRequest.get<{ userAction: string }>("/api/v1/user-action", {
params: {
action
}
@@ -70,7 +70,7 @@ export const useAddUserToWs = () => {
mutationFn: ({ email, workspaceId }) =>
apiRequest.post(`/api/v1/workspace/${workspaceId}/invite-signup`, { email }),
onSuccess: ({ data }, { workspaceId }) => {
const PRIVATE_KEY = localStorage.getItem('PRIVATE_KEY');
const PRIVATE_KEY = localStorage.getItem("PRIVATE_KEY");
if (!PRIVATE_KEY) return;
// assymmetrically decrypt symmetric key with local private key
@@ -107,7 +107,7 @@ export const useAddUserToOrg = () => {
}
return useMutation<Response, {}, AddUserToOrgDTO>({
mutationFn: (dto) => apiRequest.post(`/api/v1/invite-org/signup`, dto),
mutationFn: (dto) => apiRequest.post("/api/v1/invite-org/signup", dto),
onSuccess: (_, { organizationId }) => {
queryClient.invalidateQueries(userKeys.getOrgUsers(organizationId));
}
@@ -147,7 +147,7 @@ export const useUpdateOrgUserRole = () => {
export const useRegisterUserAction = () => {
const queryClient = useQueryClient();
return useMutation<{}, {}, string>({
mutationFn: (action) => apiRequest.post('/api/v1/user-action', { action }),
mutationFn: (action) => apiRequest.post("/api/v1/user-action", { action }),
onSuccess: () => {
queryClient.invalidateQueries(userKeys.userAction);
}
@@ -156,14 +156,14 @@ export const useRegisterUserAction = () => {
export const useLogoutUser = () =>
useMutation({
mutationFn: () => apiRequest.post('/api/v1/auth/logout'),
mutationFn: () => apiRequest.post("/api/v1/auth/logout"),
onSuccess: () => {
setAuthToken('');
setAuthToken("");
// Delete the cookie by not setting a value; Alternatively clear the local storage
localStorage.setItem('publicKey', '');
localStorage.setItem('encryptedPrivateKey', '');
localStorage.setItem('iv', '');
localStorage.setItem('tag', '');
localStorage.setItem('PRIVATE_KEY', '');
localStorage.setItem("publicKey", "");
localStorage.setItem("encryptedPrivateKey", "");
localStorage.setItem("iv", "");
localStorage.setItem("tag", "");
localStorage.setItem("PRIVATE_KEY", "");
}
});
+4 -4
View File
@@ -1,4 +1,4 @@
import { UserWsKeyPair } from '../keys/types';
import { UserWsKeyPair } from "../keys/types";
export type User = {
createdAt: Date;
@@ -31,8 +31,8 @@ export type OrgUser = {
};
inviteEmail: string;
organization: string;
role: 'owner' | 'admin' | 'member';
status: 'invited' | 'accepted' | 'verified' | 'completed';
role: "owner" | "admin" | "member";
status: "invited" | "accepted" | "verified" | "completed";
deniedPermissions: any[];
};
@@ -42,7 +42,7 @@ export type AddUserToWsDTO = {
};
export type AddUserToWsRes = {
invitee: OrgUser['user'];
invitee: OrgUser["user"];
latestKey: UserWsKeyPair;
};
+1 -1
View File
@@ -13,4 +13,4 @@ export {
useRenameWorkspace,
useToggleAutoCapitalization,
useUpdateWsEnvironment
} from './queries';
} from "./queries";
+12 -12
View File
@@ -1,10 +1,10 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from '@app/config/request';
import { apiRequest } from "@app/config/request";
import {
EncryptedSecret
} from '../secrets/types';
} from "../secrets/types";
import {
CreateEnvironmentDTO,
CreateWorkspaceDTO,
@@ -17,15 +17,15 @@ import {
UpdateEnvironmentDTO,
Workspace,
WorkspaceEnv
} from './types';
} from "./types";
const workspaceKeys = {
getWorkspaceById: (workspaceId: string) => [{ workspaceId }, 'workspace'] as const,
getWorkspaceSecrets: (workspaceId: string) => [{ workspaceId }, 'workspace-secrets'] as const,
getWorkspaceIndexStatus: (workspaceId: string) => [{ workspaceId}, 'workspace-index-status'] as const,
getWorkspaceMemberships: (orgId: string) => [{ orgId }, 'workspace-memberships'],
getAllUserWorkspace: ['workspaces'] as const,
getUserWsEnvironments: (workspaceId: string) => ['workspace-env', { workspaceId }] as const
getWorkspaceById: (workspaceId: string) => [{ workspaceId }, "workspace"] as const,
getWorkspaceSecrets: (workspaceId: string) => [{ workspaceId }, "workspace-secrets"] as const,
getWorkspaceIndexStatus: (workspaceId: string) => [{ workspaceId}, "workspace-index-status"] as const,
getWorkspaceMemberships: (orgId: string) => [{ orgId }, "workspace-memberships"],
getAllUserWorkspace: ["workspaces"] as const,
getUserWsEnvironments: (workspaceId: string) => ["workspace-env", { workspaceId }] as const
};
const fetchWorkspaceById = async (workspaceId: string) => {
@@ -53,7 +53,7 @@ const fetchWorkspaceSecrets = async (workspaceId: string) => {
}
const fetchUserWorkspaces = async () => {
const { data } = await apiRequest.get<{ workspaces: Workspace[] }>('/api/v1/workspace');
const { data } = await apiRequest.get<{ workspaces: Workspace[] }>("/api/v1/workspace");
return data.workspaces;
};
@@ -134,7 +134,7 @@ export const useCreateWorkspace = () => {
return useMutation<{ data: { workspace: Workspace } }, {}, CreateWorkspaceDTO>({
mutationFn: async ({ organizationId, workspaceName }) =>
apiRequest.post('/api/v1/workspace', { workspaceName, organizationId }),
apiRequest.post("/api/v1/workspace", { workspaceName, organizationId }),
onSuccess: () => {
queryClient.invalidateQueries(workspaceKeys.getAllUserWorkspace);
}
+4 -4
View File
@@ -1,4 +1,4 @@
export { useLeaveConfirm } from './useLeaveConfirm';
export { usePersistentState } from './usePersistentState';
export { usePopUp } from './usePopUp';
export { useToggle } from './useToggle';
export { useLeaveConfirm } from "./useLeaveConfirm";
export { usePersistentState } from "./usePersistentState";
export { usePopUp } from "./usePopUp";
export { useToggle } from "./useToggle";
+7 -7
View File
@@ -1,7 +1,7 @@
import { Dispatch, SetStateAction, useCallback, useEffect, useState } from 'react';
import { useRouter } from 'next/router';
import { Dispatch, SetStateAction, useCallback, useEffect, useState } from "react";
import { useRouter } from "next/router";
import { leaveConfirmDefaultMessage } from '@app/const';
import { leaveConfirmDefaultMessage } from "@app/const";
type LeaveConfirmProps = {
initialValue: boolean;
@@ -43,12 +43,12 @@ export function useLeaveConfirm({
);
useEffect(() => {
router.events.on('routeChangeStart', onRouteChangeStart);
window.addEventListener('beforeunload', handleWindowClose);
router.events.on("routeChangeStart", onRouteChangeStart);
window.addEventListener("beforeunload", handleWindowClose);
return () => {
router.events.off('routeChangeStart', onRouteChangeStart);
window.removeEventListener('beforeunload', handleWindowClose);
router.events.off("routeChangeStart", onRouteChangeStart);
window.removeEventListener("beforeunload", handleWindowClose);
};
}, [onRouteChangeStart, handleWindowClose]);
+1 -1
View File
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useEffect, useState } from "react";
type TPersisntentStateReturn<T extends unknown> = [T, (val: T) => void];
+4 -4
View File
@@ -1,4 +1,4 @@
import { useCallback, useState } from 'react';
import { useCallback, useState } from "react";
interface UsePopUpProps {
name: Readonly<string>;
@@ -11,7 +11,7 @@ interface UsePopUpProps {
* SIDENOTE: On inputting give it as const and not string with (as const)
*/
type UsePopUpState<T extends Readonly<string[]> | UsePopUpProps[]> = {
[P in T extends UsePopUpProps[] ? T[number]['name'] : T[number]]: {
[P in T extends UsePopUpProps[] ? T[number]["name"] : T[number]]: {
isOpen: boolean;
data?: unknown;
};
@@ -35,7 +35,7 @@ export const usePopUp = <T extends Readonly<string[]> | UsePopUpProps[]>(
const [popUp, setPopUp] = useState<UsePopUpState<T>>(
Object.fromEntries(
popUpNames.map((popUpName) =>
typeof popUpName === 'string'
typeof popUpName === "string"
? [popUpName, { isOpen: false }]
: [popUpName.name, { isOpen: popUpName.isOpen }]
) // convert into an array of [[popUpName,state]] then into Object
@@ -53,7 +53,7 @@ export const usePopUp = <T extends Readonly<string[]> | UsePopUpProps[]>(
const handlePopUpToggle = useCallback((popUpName: keyof UsePopUpState<T>, state?: boolean) => {
setPopUp((oldState) => ({
...oldState,
[popUpName]: { isOpen: typeof state === 'undefined' ? !oldState[popUpName].isOpen : state }
[popUpName]: { isOpen: typeof state === "undefined" ? !oldState[popUpName].isOpen : state }
}));
}, []);
+18 -18
View File
@@ -1,21 +1,21 @@
import { useEffect, useState } from 'react';
import { useRouter } from 'next/router';
import jwt_decode from 'jwt-decode';
import { useEffect, useState } from "react";
import { useRouter } from "next/router";
import jwt_decode from "jwt-decode";
import { useNotificationContext } from '@app/components/context/Notifications/NotificationProvider';
import SecurityClient, { PROVIDER_AUTH_TOKEN_KEY } from '@app/components/utilities/SecurityClient';
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
import SecurityClient, { PROVIDER_AUTH_TOKEN_KEY } from "@app/components/utilities/SecurityClient";
export const useProviderAuth = () => {
const router = useRouter();
const { providerAuthToken: redirectedProviderAuthToken } = router.query;
const [email, setEmail] = useState<string>('');
const [userId, setUserId] = useState<string>('');
const [email, setEmail] = useState<string>("");
const [userId, setUserId] = useState<string>("");
const [providerAuthToken, setProviderAuthToken] = useState<string>(
redirectedProviderAuthToken as string || ''
redirectedProviderAuthToken as string || ""
);
const [isProviderUserCompleted, setIsProviderUserCompleted] = useState<boolean>();
const { createNotification } = useNotificationContext();
const AUTH_ERROR_KEY = 'PROVIDER_AUTH_ERROR'
const AUTH_ERROR_KEY = "PROVIDER_AUTH_ERROR"
const handleRedirectWithToken = () => {
if (providerAuthToken) {
@@ -36,7 +36,7 @@ export const useProviderAuth = () => {
// reset when there is no redirect auth token
if (!providerAuthToken) {
SecurityClient.setProviderAuthToken('');
SecurityClient.setProviderAuthToken("");
}
window.localStorage.removeItem(AUTH_ERROR_KEY);
@@ -59,19 +59,19 @@ export const useProviderAuth = () => {
setEmail(resultEmail);
setUserId(resultUserId);
} else {
setProviderAuthToken('');
setEmail('');
setUserId('');
setProviderAuthToken("");
setEmail("");
setUserId("");
setIsProviderUserCompleted(false);
}
setProviderAuthToken(event.newValue || '');
setProviderAuthToken(event.newValue || "");
}
if (event.key === AUTH_ERROR_KEY) {
if (event.newValue) {
createNotification({
text: 'An error has occured during login.',
type: 'error',
text: "An error has occured during login.",
type: "error",
timeoutMs: 6000,
})
@@ -80,10 +80,10 @@ export const useProviderAuth = () => {
}
};
window.addEventListener('storage', handleStorageChange);
window.addEventListener("storage", handleStorageChange);
return () => {
window.removeEventListener('storage', handleStorageChange);
window.removeEventListener("storage", handleStorageChange);
};
}, []);
+2 -2
View File
@@ -1,4 +1,4 @@
import { useCallback, useState } from 'react';
import { useCallback, useState } from "react";
type VoidFn = () => void;
@@ -23,7 +23,7 @@ export const useToggle = (initialState = false): UseToggleReturn => {
}, []);
const toggle = useCallback((isOpen?: boolean) => {
setValue((prev) => (typeof isOpen === 'boolean' ? isOpen : !prev));
setValue((prev) => (typeof isOpen === "boolean" ? isOpen : !prev));
}, []);
return [value, { on, off, toggle }];