diff --git a/resources/scripts/api/admin/databases/createDatabase.ts b/resources/scripts/api/admin/databases/createDatabase.ts index 98d37bf1d..75d2b79b2 100644 --- a/resources/scripts/api/admin/databases/createDatabase.ts +++ b/resources/scripts/api/admin/databases/createDatabase.ts @@ -1,11 +1,26 @@ import http from '@/api/http'; import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases'; -export default (name: string, host: string, port: number, username: string, password: string, include: string[] = []): Promise => { +export default ( + name: string, + host: string, + port: number, + username: string, + password: string, + include: string[] = [], +): Promise => { return new Promise((resolve, reject) => { - http.post('/api/application/databases', { - name, host, port, username, password, - }, { params: { include: include.join(',') } }) + http.post( + '/api/application/databases', + { + name, + host, + port, + username, + password, + }, + { params: { include: include.join(',') } }, + ) .then(({ data }) => resolve(rawDataToDatabase(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/databases/getDatabases.ts b/resources/scripts/api/admin/databases/getDatabases.ts index 4ad5f4a3d..622a3eadf 100644 --- a/resources/scripts/api/admin/databases/getDatabases.ts +++ b/resources/scripts/api/admin/databases/getDatabases.ts @@ -13,7 +13,7 @@ export interface Database { createdAt: Date; updatedAt: Date; - getAddress (): string; + getAddress(): string; } export const rawDataToDatabase = ({ attributes }: FractalResponseData): Database => ({ @@ -53,12 +53,14 @@ export default (include: string[] = []) => { params.sort = (sortDirection ? '-' : '') + sort; } - return useSWR>([ 'databases', page, filters, sort, sortDirection ], async () => { - const { data } = await http.get('/api/application/databases', { params: { include: include.join(','), page, ...params } }); + return useSWR>(['databases', page, filters, sort, sortDirection], async () => { + const { data } = await http.get('/api/application/databases', { + params: { include: include.join(','), page, ...params }, + }); - return ({ + return { items: (data.data || []).map(rawDataToDatabase), pagination: getPaginationSet(data.meta.pagination), - }); + }; }); }; diff --git a/resources/scripts/api/admin/databases/searchDatabases.ts b/resources/scripts/api/admin/databases/searchDatabases.ts index 99533b5dc..7a9bb9c38 100644 --- a/resources/scripts/api/admin/databases/searchDatabases.ts +++ b/resources/scripts/api/admin/databases/searchDatabases.ts @@ -17,9 +17,7 @@ export default (filters?: Filters): Promise => { return new Promise((resolve, reject) => { http.get('/api/application/databases', { params }) - .then(response => resolve( - (response.data.data || []).map(rawDataToDatabase) - )) + .then(response => resolve((response.data.data || []).map(rawDataToDatabase))) .catch(reject); }); }; diff --git a/resources/scripts/api/admin/databases/updateDatabase.ts b/resources/scripts/api/admin/databases/updateDatabase.ts index 7d01a9024..18325eb75 100644 --- a/resources/scripts/api/admin/databases/updateDatabase.ts +++ b/resources/scripts/api/admin/databases/updateDatabase.ts @@ -1,11 +1,27 @@ import http from '@/api/http'; import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases'; -export default (id: number, name: string, host: string, port: number, username: string, password: string | undefined, include: string[] = []): Promise => { +export default ( + id: number, + name: string, + host: string, + port: number, + username: string, + password: string | undefined, + include: string[] = [], +): Promise => { return new Promise((resolve, reject) => { - http.patch(`/api/application/databases/${id}`, { - name, host, port, username, password, - }, { params: { include: include.join(',') } }) + http.patch( + `/api/application/databases/${id}`, + { + name, + host, + port, + username, + password, + }, + { params: { include: include.join(',') } }, + ) .then(({ data }) => resolve(rawDataToDatabase(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/eggs/createEgg.ts b/resources/scripts/api/admin/eggs/createEgg.ts index 0ad08d9ee..ebb97b301 100644 --- a/resources/scripts/api/admin/eggs/createEgg.ts +++ b/resources/scripts/api/admin/eggs/createEgg.ts @@ -1,30 +1,27 @@ import http from '@/api/http'; import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg'; -type Egg2 = Omit, 'configFiles'>, 'configStartup'> & { configFiles: string, configStartup: string }; +type Egg2 = Omit, 'configFiles'>, 'configStartup'> & { configFiles: string; configStartup: string }; export default (egg: Partial): Promise => { return new Promise((resolve, reject) => { - http.post( - '/api/application/eggs', - { - nest_id: egg.nestId, - name: egg.name, - description: egg.description, - features: egg.features, - docker_images: egg.dockerImages, - config_files: egg.configFiles, - config_startup: egg.configStartup, - config_stop: egg.configStop, - config_from: egg.configFrom, - startup: egg.startup, - script_container: egg.scriptContainer, - copy_script_from: egg.copyScriptFrom, - script_entry: egg.scriptEntry, - script_is_privileged: egg.scriptIsPrivileged, - script_install: egg.scriptInstall, - }, - ) + http.post('/api/application/eggs', { + nest_id: egg.nestId, + name: egg.name, + description: egg.description, + features: egg.features, + docker_images: egg.dockerImages, + config_files: egg.configFiles, + config_startup: egg.configStartup, + config_stop: egg.configStop, + config_from: egg.configFrom, + startup: egg.startup, + script_container: egg.scriptContainer, + copy_script_from: egg.copyScriptFrom, + script_entry: egg.scriptEntry, + script_is_privileged: egg.scriptIsPrivileged, + script_install: egg.scriptInstall, + }) .then(({ data }) => resolve(rawDataToEgg(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/eggs/createEggVariable.ts b/resources/scripts/api/admin/eggs/createEggVariable.ts index 375283d2c..6701279eb 100644 --- a/resources/scripts/api/admin/eggs/createEggVariable.ts +++ b/resources/scripts/api/admin/eggs/createEggVariable.ts @@ -5,18 +5,15 @@ import { Transformers } from '@definitions/admin'; export type CreateEggVariable = Omit; export default async (eggId: number, variable: CreateEggVariable): Promise => { - const { data } = await http.post( - `/api/application/eggs/${eggId}/variables`, - { - name: variable.name, - description: variable.description, - env_variable: variable.environmentVariable, - default_value: variable.defaultValue, - user_viewable: variable.isUserViewable, - user_editable: variable.isUserEditable, - rules: variable.rules, - }, - ); + const { data } = await http.post(`/api/application/eggs/${eggId}/variables`, { + name: variable.name, + description: variable.description, + env_variable: variable.environmentVariable, + default_value: variable.defaultValue, + user_viewable: variable.isUserViewable, + user_editable: variable.isUserEditable, + rules: variable.rules, + }); return Transformers.toEggVariable(data); }; diff --git a/resources/scripts/api/admin/eggs/updateEgg.ts b/resources/scripts/api/admin/eggs/updateEgg.ts index 2500ba6b2..1df9452ef 100644 --- a/resources/scripts/api/admin/eggs/updateEgg.ts +++ b/resources/scripts/api/admin/eggs/updateEgg.ts @@ -1,30 +1,27 @@ import http from '@/api/http'; import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg'; -type Egg2 = Omit, 'configFiles'>, 'configStartup'> & { configFiles?: string, configStartup?: string }; +type Egg2 = Omit, 'configFiles'>, 'configStartup'> & { configFiles?: string; configStartup?: string }; export default (id: number, egg: Partial): Promise => { return new Promise((resolve, reject) => { - http.patch( - `/api/application/eggs/${id}`, - { - nest_id: egg.nestId, - name: egg.name, - description: egg.description, - features: egg.features, - docker_images: egg.dockerImages, - config_files: egg.configFiles, - config_startup: egg.configStartup, - config_stop: egg.configStop, - config_from: egg.configFrom, - startup: egg.startup, - script_container: egg.scriptContainer, - copy_script_from: egg.copyScriptFrom, - script_entry: egg.scriptEntry, - script_is_privileged: egg.scriptIsPrivileged, - script_install: egg.scriptInstall, - }, - ) + http.patch(`/api/application/eggs/${id}`, { + nest_id: egg.nestId, + name: egg.name, + description: egg.description, + features: egg.features, + docker_images: egg.dockerImages, + config_files: egg.configFiles, + config_startup: egg.configStartup, + config_stop: egg.configStop, + config_from: egg.configFrom, + startup: egg.startup, + script_container: egg.scriptContainer, + copy_script_from: egg.copyScriptFrom, + script_entry: egg.scriptEntry, + script_is_privileged: egg.scriptIsPrivileged, + script_install: egg.scriptInstall, + }) .then(({ data }) => resolve(rawDataToEgg(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/eggs/updateEggVariables.ts b/resources/scripts/api/admin/eggs/updateEggVariables.ts index b5d97b952..4d071190c 100644 --- a/resources/scripts/api/admin/eggs/updateEggVariables.ts +++ b/resources/scripts/api/admin/eggs/updateEggVariables.ts @@ -2,7 +2,10 @@ import http from '@/api/http'; import { EggVariable } from '@/api/admin/egg'; import { Transformers } from '@definitions/admin'; -export default async (eggId: number, variables: Omit[]): Promise => { +export default async ( + eggId: number, + variables: Omit[], +): Promise => { const { data } = await http.patch( `/api/application/eggs/${eggId}/variables`, variables.map(variable => ({ diff --git a/resources/scripts/api/admin/getVersion.ts b/resources/scripts/api/admin/getVersion.ts index 3f24911e4..bed670b4c 100644 --- a/resources/scripts/api/admin/getVersion.ts +++ b/resources/scripts/api/admin/getVersion.ts @@ -4,11 +4,11 @@ export interface VersionData { panel: { current: string; latest: string; - } + }; wings: { latest: string; - } + }; git: string | null; } diff --git a/resources/scripts/api/admin/index.ts b/resources/scripts/api/admin/index.ts index 014a207a7..a24e97557 100644 --- a/resources/scripts/api/admin/index.ts +++ b/resources/scripts/api/admin/index.ts @@ -13,8 +13,8 @@ export type UUID = string; export type WithRelationships = Omit & { relationships: Omit & { [K in R]: NonNullable; - } -} + }; +}; /** * Helper type that allows you to infer the type of an object by giving @@ -29,7 +29,7 @@ export type InferModel any> = ReturnType extends * such that TypeScript understands the relationships on it. This is just to help * reduce the amount of duplicated type casting all over the codebase. */ -export const withRelationships = (model: M, ..._keys: R[]) => { +export const withRelationships = (model: M, ..._keys: R[]) => { return model as unknown as WithRelationships; }; @@ -47,7 +47,7 @@ export interface ListContext { setSortDirection: (direction: ((p: boolean) => boolean) | boolean) => void; } -function create () { +function create() { return createContext>({ page: 1, setPage: () => 1, diff --git a/resources/scripts/api/admin/locations/createLocation.ts b/resources/scripts/api/admin/locations/createLocation.ts index 053148fc4..71e111cf2 100644 --- a/resources/scripts/api/admin/locations/createLocation.ts +++ b/resources/scripts/api/admin/locations/createLocation.ts @@ -3,9 +3,14 @@ import { Location, rawDataToLocation } from '@/api/admin/locations/getLocations' export default (short: string, long: string | null, include: string[] = []): Promise => { return new Promise((resolve, reject) => { - http.post('/api/application/locations', { - short, long, - }, { params: { include: include.join(',') } }) + http.post( + '/api/application/locations', + { + short, + long, + }, + { params: { include: include.join(',') } }, + ) .then(({ data }) => resolve(rawDataToLocation(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/locations/getLocations.ts b/resources/scripts/api/admin/locations/getLocations.ts index f43567e51..f323a1c62 100644 --- a/resources/scripts/api/admin/locations/getLocations.ts +++ b/resources/scripts/api/admin/locations/getLocations.ts @@ -43,12 +43,14 @@ export default (include: string[] = []) => { params.sort = (sortDirection ? '-' : '') + sort; } - return useSWR>([ 'locations', page, filters, sort, sortDirection ], async () => { - const { data } = await http.get('/api/application/locations', { params: { include: include.join(','), page, ...params } }); + return useSWR>(['locations', page, filters, sort, sortDirection], async () => { + const { data } = await http.get('/api/application/locations', { + params: { include: include.join(','), page, ...params }, + }); - return ({ + return { items: (data.data || []).map(rawDataToLocation), pagination: getPaginationSet(data.meta.pagination), - }); + }; }); }; diff --git a/resources/scripts/api/admin/locations/searchLocations.ts b/resources/scripts/api/admin/locations/searchLocations.ts index 6edc50e62..88fab075f 100644 --- a/resources/scripts/api/admin/locations/searchLocations.ts +++ b/resources/scripts/api/admin/locations/searchLocations.ts @@ -17,9 +17,7 @@ export default (filters?: Filters): Promise => { return new Promise((resolve, reject) => { http.get('/api/application/locations', { params }) - .then(response => resolve( - (response.data.data || []).map(rawDataToLocation) - )) + .then(response => resolve((response.data.data || []).map(rawDataToLocation))) .catch(reject); }); }; diff --git a/resources/scripts/api/admin/locations/updateLocation.ts b/resources/scripts/api/admin/locations/updateLocation.ts index bbb5f8f4c..2f0fe6a80 100644 --- a/resources/scripts/api/admin/locations/updateLocation.ts +++ b/resources/scripts/api/admin/locations/updateLocation.ts @@ -3,9 +3,14 @@ import { Location, rawDataToLocation } from '@/api/admin/locations/getLocations' export default (id: number, short: string, long: string | null, include: string[] = []): Promise => { return new Promise((resolve, reject) => { - http.patch(`/api/application/locations/${id}`, { - short, long, - }, { params: { include: include.join(',') } }) + http.patch( + `/api/application/locations/${id}`, + { + short, + long, + }, + { params: { include: include.join(',') } }, + ) .then(({ data }) => resolve(rawDataToLocation(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/mounts/createMount.ts b/resources/scripts/api/admin/mounts/createMount.ts index 63538c821..9d762edae 100644 --- a/resources/scripts/api/admin/mounts/createMount.ts +++ b/resources/scripts/api/admin/mounts/createMount.ts @@ -1,11 +1,28 @@ import http from '@/api/http'; import { Mount, rawDataToMount } from '@/api/admin/mounts/getMounts'; -export default (name: string, description: string, source: string, target: string, readOnly: boolean, userMountable: boolean, include: string[] = []): Promise => { +export default ( + name: string, + description: string, + source: string, + target: string, + readOnly: boolean, + userMountable: boolean, + include: string[] = [], +): Promise => { return new Promise((resolve, reject) => { - http.post('/api/application/mounts', { - name, description, source, target, read_only: readOnly, user_mountable: userMountable, - }, { params: { include: include.join(',') } }) + http.post( + '/api/application/mounts', + { + name, + description, + source, + target, + read_only: readOnly, + user_mountable: userMountable, + }, + { params: { include: include.join(',') } }, + ) .then(({ data }) => resolve(rawDataToMount(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/mounts/getMounts.ts b/resources/scripts/api/admin/mounts/getMounts.ts index 449308119..ba5c64dcd 100644 --- a/resources/scripts/api/admin/mounts/getMounts.ts +++ b/resources/scripts/api/admin/mounts/getMounts.ts @@ -40,7 +40,9 @@ export const rawDataToMount = ({ attributes }: FractalResponseData): Mount => ({ relations: { eggs: ((attributes.relationships?.eggs as FractalResponseList | undefined)?.data || []).map(rawDataToEgg), nodes: ((attributes.relationships?.nodes as FractalResponseList | undefined)?.data || []).map(rawDataToNode), - servers: ((attributes.relationships?.servers as FractalResponseList | undefined)?.data || []).map(rawDataToServer), + servers: ((attributes.relationships?.servers as FractalResponseList | undefined)?.data || []).map( + rawDataToServer, + ), }, }); @@ -69,12 +71,14 @@ export default (include: string[] = []) => { params.sort = (sortDirection ? '-' : '') + sort; } - return useSWR>([ 'mounts', page, filters, sort, sortDirection ], async () => { - const { data } = await http.get('/api/application/mounts', { params: { include: include.join(','), page, ...params } }); + return useSWR>(['mounts', page, filters, sort, sortDirection], async () => { + const { data } = await http.get('/api/application/mounts', { + params: { include: include.join(','), page, ...params }, + }); - return ({ + return { items: (data.data || []).map(rawDataToMount), pagination: getPaginationSet(data.meta.pagination), - }); + }; }); }; diff --git a/resources/scripts/api/admin/mounts/updateMount.ts b/resources/scripts/api/admin/mounts/updateMount.ts index c2485777a..fb79b74a1 100644 --- a/resources/scripts/api/admin/mounts/updateMount.ts +++ b/resources/scripts/api/admin/mounts/updateMount.ts @@ -1,11 +1,29 @@ import http from '@/api/http'; import { Mount, rawDataToMount } from '@/api/admin/mounts/getMounts'; -export default (id: number, name: string, description: string | null, source: string, target: string, readOnly: boolean, userMountable: boolean, include: string[] = []): Promise => { +export default ( + id: number, + name: string, + description: string | null, + source: string, + target: string, + readOnly: boolean, + userMountable: boolean, + include: string[] = [], +): Promise => { return new Promise((resolve, reject) => { - http.patch(`/api/application/mounts/${id}`, { - name, description, source, target, read_only: readOnly, user_mountable: userMountable, - }, { params: { include: include.join(',') } }) + http.patch( + `/api/application/mounts/${id}`, + { + name, + description, + source, + target, + read_only: readOnly, + user_mountable: userMountable, + }, + { params: { include: include.join(',') } }, + ) .then(({ data }) => resolve(rawDataToMount(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/nests/createNest.ts b/resources/scripts/api/admin/nests/createNest.ts index 6f8d045fa..811f0abff 100644 --- a/resources/scripts/api/admin/nests/createNest.ts +++ b/resources/scripts/api/admin/nests/createNest.ts @@ -3,9 +3,14 @@ import { Nest, rawDataToNest } from '@/api/admin/nests/getNests'; export default (name: string, description: string | null, include: string[] = []): Promise => { return new Promise((resolve, reject) => { - http.post('/api/application/nests', { - name, description, - }, { params: { include: include.join(',') } }) + http.post( + '/api/application/nests', + { + name, + description, + }, + { params: { include: include.join(',') } }, + ) .then(({ data }) => resolve(rawDataToNest(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/nests/getEggs.ts b/resources/scripts/api/admin/nests/getEggs.ts index 6a406dc96..6fb586c55 100644 --- a/resources/scripts/api/admin/nests/getEggs.ts +++ b/resources/scripts/api/admin/nests/getEggs.ts @@ -27,12 +27,14 @@ export default (nestId: number, include: string[] = []) => { params.sort = (sortDirection ? '-' : '') + sort; } - return useSWR>([ nestId, 'eggs', page, filters, sort, sortDirection ], async () => { - const { data } = await http.get(`/api/application/nests/${nestId}/eggs`, { params: { include: include.join(','), page, ...params } }); + return useSWR>([nestId, 'eggs', page, filters, sort, sortDirection], async () => { + const { data } = await http.get(`/api/application/nests/${nestId}/eggs`, { + params: { include: include.join(','), page, ...params }, + }); - return ({ + return { items: (data.data || []).map(rawDataToEgg), pagination: getPaginationSet(data.meta.pagination), - }); + }; }); }; diff --git a/resources/scripts/api/admin/nests/getNests.ts b/resources/scripts/api/admin/nests/getNests.ts index 712a2a29b..702358eb6 100644 --- a/resources/scripts/api/admin/nests/getNests.ts +++ b/resources/scripts/api/admin/nests/getNests.ts @@ -15,7 +15,7 @@ export interface Nest { relations: { eggs: Egg[] | undefined; - }, + }; } export const rawDataToNest = ({ attributes }: FractalResponseData): Nest => ({ @@ -55,12 +55,14 @@ export default (include: string[] = []) => { params.sort = (sortDirection ? '-' : '') + sort; } - return useSWR>([ 'nests', page, filters, sort, sortDirection ], async () => { - const { data } = await http.get('/api/application/nests', { params: { include: include.join(','), page, ...params } }); + return useSWR>(['nests', page, filters, sort, sortDirection], async () => { + const { data } = await http.get('/api/application/nests', { + params: { include: include.join(','), page, ...params }, + }); - return ({ + return { items: (data.data || []).map(rawDataToNest), pagination: getPaginationSet(data.meta.pagination), - }); + }; }); }; diff --git a/resources/scripts/api/admin/nests/updateNest.ts b/resources/scripts/api/admin/nests/updateNest.ts index 869f0532b..a8823446d 100644 --- a/resources/scripts/api/admin/nests/updateNest.ts +++ b/resources/scripts/api/admin/nests/updateNest.ts @@ -3,9 +3,14 @@ import { Nest, rawDataToNest } from '@/api/admin/nests/getNests'; export default (id: number, name: string, description: string | null, include: string[] = []): Promise => { return new Promise((resolve, reject) => { - http.patch(`/api/application/nests/${id}`, { - name, description, - }, { params: { include: include.join(',') } }) + http.patch( + `/api/application/nests/${id}`, + { + name, + description, + }, + { params: { include: include.join(',') } }, + ) .then(({ data }) => resolve(rawDataToNest(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/node.ts b/resources/scripts/api/admin/node.ts index dae7a09cc..d2008829b 100644 --- a/resources/scripts/api/admin/node.ts +++ b/resources/scripts/api/admin/node.ts @@ -60,7 +60,7 @@ export interface Node extends Model { export const getNode = async (id: string | number): Promise> => { const { data } = await http.get(`/api/application/nodes/${id}`, { params: { - include: [ 'location' ], + include: ['location'], }, }); @@ -75,7 +75,10 @@ export const searchNodes = async (params: QueryBuilderParams<'name'>): Promise): Promise => { +export const getAllocations = async ( + id: string | number, + params?: QueryBuilderParams<'ip' | 'server_id'>, +): Promise => { const { data } = await http.get(`/api/application/nodes/${id}/allocations`, { params: withQueryBuilderParams(params), }); diff --git a/resources/scripts/api/admin/nodes/allocations/getAllocations.ts b/resources/scripts/api/admin/nodes/allocations/getAllocations.ts index 14c99c655..e26bbf595 100644 --- a/resources/scripts/api/admin/nodes/allocations/getAllocations.ts +++ b/resources/scripts/api/admin/nodes/allocations/getAllocations.ts @@ -28,12 +28,14 @@ export default (id: number, include: string[] = []) => { params.sort = (sortDirection ? '-' : '') + sort; } - return useSWR>([ 'allocations', page, filters, sort, sortDirection ], async () => { - const { data } = await http.get(`/api/application/nodes/${id}/allocations`, { params: { include: include.join(','), page, ...params } }); + return useSWR>(['allocations', page, filters, sort, sortDirection], async () => { + const { data } = await http.get(`/api/application/nodes/${id}/allocations`, { + params: { include: include.join(','), page, ...params }, + }); - return ({ + return { items: (data.data || []).map(rawDataToAllocation), pagination: getPaginationSet(data.meta.pagination), - }); + }; }); }; diff --git a/resources/scripts/api/admin/nodes/createNode.ts b/resources/scripts/api/admin/nodes/createNode.ts index 8143a92c3..49f8447e3 100644 --- a/resources/scripts/api/admin/nodes/createNode.ts +++ b/resources/scripts/api/admin/nodes/createNode.ts @@ -25,7 +25,7 @@ export interface Values { export default (values: Values, include: string[] = []): Promise => { const data = {}; - Object.keys(values).forEach((key) => { + Object.keys(values).forEach(key => { const key2 = key .replace('HTTP', 'Http') .replace('SFTP', 'Sftp') diff --git a/resources/scripts/api/admin/nodes/getAllocations.ts b/resources/scripts/api/admin/nodes/getAllocations.ts index e6f773dfe..217dfc8dc 100644 --- a/resources/scripts/api/admin/nodes/getAllocations.ts +++ b/resources/scripts/api/admin/nodes/getAllocations.ts @@ -11,9 +11,9 @@ export interface Allocation { relations: { server?: Server; - } + }; - getDisplayText (): string; + getDisplayText(): string; } export const rawDataToAllocation = ({ attributes }: FractalResponseData): Allocation => ({ @@ -25,11 +25,14 @@ export const rawDataToAllocation = ({ attributes }: FractalResponseData): Alloca assigned: attributes.assigned, relations: { - server: attributes.relationships?.server?.object === 'server' ? rawDataToServer(attributes.relationships.server as FractalResponseData) : undefined, + server: + attributes.relationships?.server?.object === 'server' + ? rawDataToServer(attributes.relationships.server as FractalResponseData) + : undefined, }, // TODO: If IP is an IPv6, wrap IP in []. - getDisplayText (): string { + getDisplayText(): string { if (attributes.alias !== null) { return `${attributes.ip}:${attributes.port} (${attributes.alias})`; } @@ -38,7 +41,7 @@ export const rawDataToAllocation = ({ attributes }: FractalResponseData): Alloca }); export interface Filters { - ip?: string + ip?: string; /* eslint-disable camelcase */ server_id?: string; /* eslint-enable camelcase */ diff --git a/resources/scripts/api/admin/nodes/getNodes.ts b/resources/scripts/api/admin/nodes/getNodes.ts index 59e87ceb4..6328896fa 100644 --- a/resources/scripts/api/admin/nodes/getNodes.ts +++ b/resources/scripts/api/admin/nodes/getNodes.ts @@ -33,7 +33,7 @@ export interface Node { relations: { databaseHost: Database | undefined; location: Location | undefined; - } + }; } export const rawDataToNode = ({ attributes }: FractalResponseData): Node => ({ @@ -63,8 +63,15 @@ export const rawDataToNode = ({ attributes }: FractalResponseData): Node => ({ relations: { // eslint-disable-next-line camelcase - databaseHost: attributes.relationships?.database_host !== undefined && attributes.relationships?.database_host.object !== 'null_resource' ? rawDataToDatabase(attributes.relationships.database_host as FractalResponseData) : undefined, - location: attributes.relationships?.location !== undefined ? rawDataToLocation(attributes.relationships.location as FractalResponseData) : undefined, + databaseHost: + attributes.relationships?.database_host !== undefined && + attributes.relationships?.database_host.object !== 'null_resource' + ? rawDataToDatabase(attributes.relationships.database_host as FractalResponseData) + : undefined, + location: + attributes.relationships?.location !== undefined + ? rawDataToLocation(attributes.relationships.location as FractalResponseData) + : undefined, }, }); @@ -96,12 +103,14 @@ export default (include: string[] = []) => { params.sort = (sortDirection ? '-' : '') + sort; } - return useSWR>([ 'nodes', page, filters, sort, sortDirection ], async () => { - const { data } = await http.get('/api/application/nodes', { params: { include: include.join(','), page, ...params } }); + return useSWR>(['nodes', page, filters, sort, sortDirection], async () => { + const { data } = await http.get('/api/application/nodes', { + params: { include: include.join(','), page, ...params }, + }); - return ({ + return { items: (data.data || []).map(rawDataToNode), pagination: getPaginationSet(data.meta.pagination), - }); + }; }); }; diff --git a/resources/scripts/api/admin/nodes/updateNode.ts b/resources/scripts/api/admin/nodes/updateNode.ts index 623f66931..678f808f8 100644 --- a/resources/scripts/api/admin/nodes/updateNode.ts +++ b/resources/scripts/api/admin/nodes/updateNode.ts @@ -4,7 +4,7 @@ import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes'; export default (id: number, node: Partial, include: string[] = []): Promise => { const data = {}; - Object.keys(node).forEach((key) => { + Object.keys(node).forEach(key => { const key2 = key .replace('HTTP', 'Http') .replace('SFTP', 'Sftp') diff --git a/resources/scripts/api/admin/roles.ts b/resources/scripts/api/admin/roles.ts index 8fb5c4c85..e0b7894e5 100644 --- a/resources/scripts/api/admin/roles.ts +++ b/resources/scripts/api/admin/roles.ts @@ -13,9 +13,14 @@ export const Context = createContext(); const createRole = (name: string, description: string | null, include: string[] = []): Promise => { return new Promise((resolve, reject) => { - http.post('/api/application/roles', { - name, description, - }, { params: { include: include.join(',') } }) + http.post( + '/api/application/roles', + { + name, + description, + }, + { params: { include: include.join(',') } }, + ) .then(({ data }) => resolve(Transformers.toUserRole(data))) .catch(reject); }); @@ -48,18 +53,26 @@ const searchRoles = (filters?: { name?: string }): Promise => { return new Promise((resolve, reject) => { http.get('/api/application/roles', { params }) - .then(response => resolve( - (response.data.data || []).map(Transformers.toUserRole) - )) + .then(response => resolve((response.data.data || []).map(Transformers.toUserRole))) .catch(reject); }); }; -const updateRole = (id: number, name: string, description: string | null, include: string[] = []): Promise => { +const updateRole = ( + id: number, + name: string, + description: string | null, + include: string[] = [], +): Promise => { return new Promise((resolve, reject) => { - http.patch(`/api/application/roles/${id}`, { - name, description, - }, { params: { include: include.join(',') } }) + http.patch( + `/api/application/roles/${id}`, + { + name, + description, + }, + { params: { include: include.join(',') } }, + ) .then(({ data }) => resolve(Transformers.toUserRole(data))) .catch(reject); }); @@ -83,21 +96,16 @@ const getRoles = (include: string[] = []) => { } // eslint-disable-next-line react-hooks/rules-of-hooks - return useSWR>([ 'roles', page, filters, sort, sortDirection ], async () => { - const { data } = await http.get('/api/application/roles', { params: { include: include.join(','), page, ...params } }); + return useSWR>(['roles', page, filters, sort, sortDirection], async () => { + const { data } = await http.get('/api/application/roles', { + params: { include: include.join(','), page, ...params }, + }); - return ({ + return { items: (data.data || []).map(Transformers.toUserRole), pagination: getPaginationSet(data.meta.pagination), - }); + }; }); }; -export { - createRole, - deleteRole, - getRole, - searchRoles, - updateRole, - getRoles, -}; +export { createRole, deleteRole, getRole, searchRoles, updateRole, getRoles }; diff --git a/resources/scripts/api/admin/servers/createServer.ts b/resources/scripts/api/admin/servers/createServer.ts index 3fd94ca62..6421aece6 100644 --- a/resources/scripts/api/admin/servers/createServer.ts +++ b/resources/scripts/api/admin/servers/createServer.ts @@ -16,7 +16,7 @@ export interface CreateServerRequest { cpu: number; threads: string; oomDisabled: boolean; - } + }; featureLimits: { allocations: number; @@ -39,41 +39,45 @@ export interface CreateServerRequest { export default (r: CreateServerRequest, include: string[] = []): Promise => { return new Promise((resolve, reject) => { - http.post('/api/application/servers', { - externalId: r.externalId, - name: r.name, - description: r.description, - owner_id: r.ownerId, - node_id: r.nodeId, + http.post( + '/api/application/servers', + { + externalId: r.externalId, + name: r.name, + description: r.description, + owner_id: r.ownerId, + node_id: r.nodeId, - limits: { - cpu: r.limits.cpu, - disk: r.limits.disk, - io: r.limits.io, - memory: r.limits.memory, - swap: r.limits.swap, - threads: r.limits.threads, - oom_killer: r.limits.oomDisabled, + limits: { + cpu: r.limits.cpu, + disk: r.limits.disk, + io: r.limits.io, + memory: r.limits.memory, + swap: r.limits.swap, + threads: r.limits.threads, + oom_killer: r.limits.oomDisabled, + }, + + feature_limits: { + allocations: r.featureLimits.allocations, + backups: r.featureLimits.backups, + databases: r.featureLimits.databases, + }, + + allocation: { + default: r.allocation.default, + additional: r.allocation.additional, + }, + + startup: r.startup, + environment: r.environment, + egg_id: r.eggId, + image: r.image, + skip_scripts: r.skipScripts, + start_on_completion: r.startOnCompletion, }, - - feature_limits: { - allocations: r.featureLimits.allocations, - backups: r.featureLimits.backups, - databases: r.featureLimits.databases, - }, - - allocation: { - default: r.allocation.default, - additional: r.allocation.additional, - }, - - startup: r.startup, - environment: r.environment, - egg_id: r.eggId, - image: r.image, - skip_scripts: r.skipScripts, - start_on_completion: r.startOnCompletion, - }, { params: { include: include.join(',') } }) + { params: { include: include.join(',') } }, + ) .then(({ data }) => resolve(rawDataToServer(data))) .catch(reject); }); diff --git a/resources/scripts/api/admin/servers/getServers.ts b/resources/scripts/api/admin/servers/getServers.ts index 6d73f070b..acee06d7b 100644 --- a/resources/scripts/api/admin/servers/getServers.ts +++ b/resources/scripts/api/admin/servers/getServers.ts @@ -41,7 +41,7 @@ export const rawDataToServerVariable = ({ attributes }: FractalResponseData): Se export interface Server { id: number; - externalId: string | null + externalId: string | null; uuid: string; identifier: string; name: string; @@ -56,13 +56,13 @@ export interface Server { cpu: number; threads: string | null; oomDisabled: boolean; - } + }; featureLimits: { databases: number; allocations: number; backups: number; - } + }; ownerId: number; nodeId: number; @@ -74,7 +74,7 @@ export interface Server { startup: string; image: string; environment: Map; - } + }; createdAt: Date; updatedAt: Date; @@ -85,57 +85,71 @@ export interface Server { node?: Node; user?: User; variables: ServerVariable[]; - } + }; } -export const rawDataToServer = ({ attributes }: FractalResponseData): Server => ({ - id: attributes.id, - externalId: attributes.external_id, - uuid: attributes.uuid, - identifier: attributes.identifier, - name: attributes.name, - description: attributes.description, - status: attributes.status, +export const rawDataToServer = ({ attributes }: FractalResponseData): Server => + ({ + id: attributes.id, + externalId: attributes.external_id, + uuid: attributes.uuid, + identifier: attributes.identifier, + name: attributes.name, + description: attributes.description, + status: attributes.status, - limits: { - memory: attributes.limits.memory, - swap: attributes.limits.swap, - disk: attributes.limits.disk, - io: attributes.limits.io, - cpu: attributes.limits.cpu, - threads: attributes.limits.threads, - oomDisabled: attributes.limits.oom_disabled, - }, + limits: { + memory: attributes.limits.memory, + swap: attributes.limits.swap, + disk: attributes.limits.disk, + io: attributes.limits.io, + cpu: attributes.limits.cpu, + threads: attributes.limits.threads, + oomDisabled: attributes.limits.oom_disabled, + }, - featureLimits: { - databases: attributes.feature_limits.databases, - allocations: attributes.feature_limits.allocations, - backups: attributes.feature_limits.backups, - }, + featureLimits: { + databases: attributes.feature_limits.databases, + allocations: attributes.feature_limits.allocations, + backups: attributes.feature_limits.backups, + }, - ownerId: attributes.owner_id, - nodeId: attributes.node_id, - allocationId: attributes.allocation_id, - nestId: attributes.nest_id, - eggId: attributes.egg_id, + ownerId: attributes.owner_id, + nodeId: attributes.node_id, + allocationId: attributes.allocation_id, + nestId: attributes.nest_id, + eggId: attributes.egg_id, - container: { - startup: attributes.container.startup, - image: attributes.container.image, - environment: attributes.container.environment, - }, + container: { + startup: attributes.container.startup, + image: attributes.container.image, + environment: attributes.container.environment, + }, - createdAt: new Date(attributes.created_at), - updatedAt: new Date(attributes.updated_at), + createdAt: new Date(attributes.created_at), + updatedAt: new Date(attributes.updated_at), - relations: { - allocations: ((attributes.relationships?.allocations as FractalResponseList | undefined)?.data || []).map(rawDataToAllocation), - egg: attributes.relationships?.egg?.object === 'egg' ? rawDataToEgg(attributes.relationships.egg as FractalResponseData) : undefined, - node: attributes.relationships?.node?.object === 'node' ? rawDataToNode(attributes.relationships.node as FractalResponseData) : undefined, - user: attributes.relationships?.user?.object === 'user' ? Transformers.toUser(attributes.relationships.user as FractalResponseData) : undefined, - variables: ((attributes.relationships?.variables as FractalResponseList | undefined)?.data || []).map(rawDataToServerVariable), - }, -}) as Server; + relations: { + allocations: ((attributes.relationships?.allocations as FractalResponseList | undefined)?.data || []).map( + rawDataToAllocation, + ), + egg: + attributes.relationships?.egg?.object === 'egg' + ? rawDataToEgg(attributes.relationships.egg as FractalResponseData) + : undefined, + node: + attributes.relationships?.node?.object === 'node' + ? rawDataToNode(attributes.relationships.node as FractalResponseData) + : undefined, + user: + attributes.relationships?.user?.object === 'user' + ? Transformers.toUser(attributes.relationships.user as FractalResponseData) + : undefined, + variables: ((attributes.relationships?.variables as FractalResponseList | undefined)?.data || []).map( + rawDataToServerVariable, + ), + }, + } as Server); export interface Filters { id?: string; @@ -166,12 +180,14 @@ export default (include: string[] = []) => { params.sort = (sortDirection ? '-' : '') + sort; } - return useSWR>([ 'servers', page, filters, sort, sortDirection ], async () => { - const { data } = await http.get('/api/application/servers', { params: { include: include.join(','), page, ...params } }); + return useSWR>(['servers', page, filters, sort, sortDirection], async () => { + const { data } = await http.get('/api/application/servers', { + params: { include: include.join(','), page, ...params }, + }); - return ({ + return { items: (data.data || []).map(rawDataToServer), pagination: getPaginationSet(data.meta.pagination), - }); + }; }); }; diff --git a/resources/scripts/api/admin/servers/updateServer.ts b/resources/scripts/api/admin/servers/updateServer.ts index e74b7422a..cf133431b 100644 --- a/resources/scripts/api/admin/servers/updateServer.ts +++ b/resources/scripts/api/admin/servers/updateServer.ts @@ -14,13 +14,13 @@ export interface Values { cpu: number; threads: string; oomDisabled: boolean; - } + }; featureLimits: { allocations: number; backups: number; databases: number; - } + }; allocationId: number; addAllocations: number[]; @@ -56,7 +56,7 @@ export default (id: number, server: Partial, include: string[] = []): Pr add_allocations: server.addAllocations, remove_allocations: server.removeAllocations, }, - { params: { include: include.join(',') } } + { params: { include: include.join(',') } }, ) .then(({ data }) => resolve(rawDataToServer(data))) .catch(reject); diff --git a/resources/scripts/api/admin/servers/updateServerStartup.ts b/resources/scripts/api/admin/servers/updateServerStartup.ts index 7dec26e30..a67a27a83 100644 --- a/resources/scripts/api/admin/servers/updateServerStartup.ts +++ b/resources/scripts/api/admin/servers/updateServerStartup.ts @@ -20,7 +20,7 @@ export default (id: number, values: Partial, include: string[] = []): Pr image: values.image, skip_scripts: values.skipScripts, }, - { params: { include: include.join(',') } } + { params: { include: include.join(',') } }, ) .then(({ data }) => resolve(rawDataToServer(data))) .catch(reject); diff --git a/resources/scripts/components/NavigationBar.tsx b/resources/scripts/components/NavigationBar.tsx index 28e9f8861..8bf9116d9 100644 --- a/resources/scripts/components/NavigationBar.tsx +++ b/resources/scripts/components/NavigationBar.tsx @@ -46,13 +46,13 @@ export default () => { }; return ( -
+
-
+