Skip to content

Commit

Permalink
chore: fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
35C4n0r committed Nov 25, 2024
1 parent 76c0cbe commit 72c5837
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 30 deletions.
30 changes: 20 additions & 10 deletions source/commands/env/copy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ type Props = {
readonly options: zInfer<typeof options>;
};

interface EnvCopyResult {
existingEnvId?: string;
newEnvKey?: string;
newEnvName?: string;
newEnvDescription?: string;
conflictStartegy?: string;
scope?: string;
}

export default function Copy({
options: {
key: apiKey,
Expand All @@ -105,19 +114,20 @@ export default function Copy({
const { getApiKeyScope } = useApiKeyApi();
const { copyEnvironment } = useEnvironmentApi();

function handleEnvCopy(result: any) {
function handleEnvCopy(result: object) {
const envCopyResult = result as EnvCopyResult;
let body = {};
if (result.existingEnvId) {
if (envCopyResult.existingEnvId) {
body = {
target_env: { existing: result.existingEnvId },
target_env: { existing: envCopyResult.existingEnvId },
};
} else if (result.newEnvKey && result.newEnvName) {
} else if (envCopyResult.newEnvKey && envCopyResult.newEnvName) {
body = {
target_env: {
new: {
key: result.newEnvKey,
name: result.newEnvName,
description: result.newEnvDescription,
key: envCopyResult.newEnvKey,
name: envCopyResult.newEnvName,
description: envCopyResult.newEnvDescription,
},
},
};
Expand All @@ -132,16 +142,16 @@ export default function Copy({
}
body = {
...body,
conflict_strategy: result.conflictStartegy,
scope: result.scope,
conflict_strategy: envCopyResult.conflictStartegy,
scope: envCopyResult.scope,
};
(async () => {
const { error } = await copyEnvironment(
projectFrom ?? '',
envFrom ?? '',
apiKey,
null,
JSON.stringify(body),
body,
);
if (error) {
setError(`Error while copying Environment: ${error}`);
Expand Down
12 changes: 9 additions & 3 deletions source/commands/env/member.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ type Props = {
readonly options: zInfer<typeof options>;
};

interface MemberInviteResult {
memberEmail: string;
memberRole: string;
}

export default function Member({ options: { key: apiKey } }: Props) {
const [error, setError] = React.useState<string | null>(null);
const [state, setState] = useState<'loading' | 'selecting' | 'done'>(
Expand Down Expand Up @@ -99,14 +104,15 @@ export default function Member({ options: { key: apiKey } }: Props) {
setState('selecting');
}, [apiKey]);

Check warning on line 105 in source/commands/env/member.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

React Hook useEffect has a missing dependency: 'getApiKeyScope'. Either include it or remove the dependency array

Check warning on line 105 in source/commands/env/member.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

React Hook useEffect has a missing dependency: 'getApiKeyScope'. Either include it or remove the dependency array

Check warning on line 105 in source/commands/env/member.tsx

View workflow job for this annotation

GitHub Actions / build (22.x)

React Hook useEffect has a missing dependency: 'getApiKeyScope'. Either include it or remove the dependency array

const handleMemberInvite = (result: any) => {
const handleMemberInvite = (result: object) => {
const memberInvite = result as MemberInviteResult;
const requestBody = {
email: result.memberEmail,
email: memberInvite.memberEmail,
permissions: [
{
...keyScope,
object_type: 'env',
access_level: result.memberRole,
access_level: memberInvite.memberRole,
},
],
};
Expand Down
4 changes: 2 additions & 2 deletions source/commands/env/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export default function Select({ options: { key: apiKey } }: Props) {
) => {
try {
await saveAuthToken(secret);
} catch (error: any) {
setError(error);
} catch (error: unknown) {
setError(error as string);
}
setEnvironment(environment.label);
setState('done');
Expand Down
2 changes: 1 addition & 1 deletion source/components/LoginFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const LoginFlow: React.FC<LoginFlowProps> = ({
return;
}
onSuccess(token, headers.getSetCookie()[0] ?? '');
} catch (error: any) {
} catch (error: unknown) {
onError(`Unexpected error during authentication. ${error}`);
return;
}
Expand Down
5 changes: 3 additions & 2 deletions source/components/SelectEnvironment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ const SelectEnvironment: React.FC<Props> = ({

const { getEnvironments } = useEnvironmentApi();

const handleEnvironmentSelect = (environment: any) => {
onComplete({ label: environment.label, value: environment.value });
const handleEnvironmentSelect = (environment: object) => {
const selectedEnv = environment as ActiveState;
onComplete({ label: selectedEnv.label, value: selectedEnv.value });
};

useEffect(() => {
Expand Down
5 changes: 3 additions & 2 deletions source/components/SelectOrganization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ const SelectOrganization: React.FC<SelectOrganizationProps> = ({

const { getOrgs } = useOrganisationApi();

const handleSelectOrganization = async (organization: any) => {
onComplete({ label: organization.label, value: organization.value });
const handleSelectOrganization = async (organization: object) => {
const selectedOrg = organization as ActiveState;
onComplete({ label: selectedOrg.label, value: selectedOrg.value });
};

useEffect(() => {
Expand Down
5 changes: 3 additions & 2 deletions source/components/SelectProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ const SelectProject: React.FC<Props> = ({

const { getProjects } = useProjectAPI();

const handleProjectSelect = (project: any) => {
onComplete({ label: project.label, value: project.value });
const handleProjectSelect = (project: object) => {
const selectedProject = project as ActiveState;
onComplete({ label: selectedProject.label, value: selectedProject.value });
};

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions source/hooks/useEnvironmentApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export const useEnvironmentApi = () => {
environmentId: string,
accessToken: string,
cookie: string | null,
body: any,
body: object,
) => {
return await apiCall(
`v2/projects/${projectId}/envs/${environmentId}/copy`,
accessToken,
cookie ?? '',
'POST',
body,
JSON.stringify(body),
);
};

Expand Down
2 changes: 1 addition & 1 deletion source/hooks/useMemberApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { apiCall } from '../lib/api.js';

export const useMemberApi = () => {
const inviteNewMember = async (authToken: string, body: any) => {
const inviteNewMember = async (authToken: string, body: object) => {
return await apiCall(
`v2/members`,
authToken,
Expand Down
8 changes: 4 additions & 4 deletions source/hooks/useRolesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export type Role = {
name: string; // The name of the role
description?: string; // Optional description explaining the role
permissions: string[]; // List of actions this role is permitted to perform
attributes?: Record<string, any>; // Optional key-value metadata for filtering
attributes?: Record<string, string>; // Optional key-value metadata for filtering
extends: string[]; // List of roles this role extends
granted_to?: Record<string, any>; // Derived role definition block
v1compat_settings?: Record<string, any>; // Optional v1 compatibility settings
v1compat_attributes?: Record<string, any>; // Optional v1 compatibility attributes
granted_to?: Record<string, string>; // Derived role definition block
v1compat_settings?: Record<string, string>; // Optional v1 compatibility settings
v1compat_attributes?: Record<string, string>; // Optional v1 compatibility attributes
organization_id: string; // UUID of the organization this role belongs to
project_id: string; // UUID of the project this role belongs to
environment_id: string; // UUID of the environment this role belongs to
Expand Down
3 changes: 2 additions & 1 deletion source/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type ApiResponse<T> = {
error: string | null;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const apiCall = async <T = any>(
endpoint: string,
token: string,
Expand Down Expand Up @@ -49,7 +50,7 @@ export const apiCall = async <T = any>(
defaultResponse.response = response as T;
defaultResponse.status = res.status;
}
} catch (error: any) {
} catch (error: unknown) {
defaultResponse.error =
error instanceof Error ? error.message : 'Unknown fetch error occurred';
}
Expand Down

0 comments on commit 72c5837

Please sign in to comment.