mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #41391 # Details This PR updates front-end API calls to use new URLs and API params, so that the front end doesn't cause deprecation warnings to appear on the server. # Checklist for submitter If some of the following don't apply, delete the relevant line. - [ ] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. n/a, should not be user-visible ## Testing - [X] Added/updated automated tests - [ ] QA'd all new/changed functionality manually The biggest risk here is not that we missed a spot that still causes a deprecation warning, but that we might inadvertently make a change that breaks the front end, for instance by sending `fleet_id` to a function that drops it silently and thus sends no ID to the server. Fortunately we use TypeScript in virtually every place affected by these changes, so the code would not compile if there were mismatches between the API expectation and what we're sending. Still, spot checking as many places as possible both for deprecation-warning leaks and loss of functionality is important. ## Summary by CodeRabbit * **Refactor** * Updated API nomenclature across the application to use "fleets" instead of "teams" and "reports" instead of "queries" in endpoint paths and request/response payloads. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
113 lines
2.5 KiB
TypeScript
113 lines
2.5 KiB
TypeScript
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
import sendRequest from "services";
|
|
import endpoints from "utilities/endpoints";
|
|
import { IOperatingSystemVersion } from "interfaces/operating_system";
|
|
import { Platform } from "interfaces/platform";
|
|
import { buildQueryStringFromParams } from "utilities/url";
|
|
|
|
// TODO: add platforms to this constant as new ones are supported
|
|
export const OS_VERSIONS_API_SUPPORTED_PLATFORMS = [
|
|
"darwin",
|
|
"windows",
|
|
"chrome",
|
|
"ios",
|
|
"ipados",
|
|
];
|
|
|
|
export interface IGetOSVersionsQueryParams {
|
|
platform?: Platform | "";
|
|
teamId?: number;
|
|
os_name?: string;
|
|
os_version?: string;
|
|
order_key?: string;
|
|
order_direction?: string;
|
|
page?: number;
|
|
per_page?: number;
|
|
max_vulnerabilities?: number;
|
|
}
|
|
|
|
export interface IGetOSVersionsQueryKey extends IGetOSVersionsQueryParams {
|
|
scope: string;
|
|
}
|
|
|
|
export interface IOSVersionsResponse {
|
|
count: number;
|
|
counts_updated_at: string;
|
|
os_versions: IOperatingSystemVersion[];
|
|
meta: {
|
|
has_next_results: boolean;
|
|
has_previous_results: boolean;
|
|
};
|
|
}
|
|
interface IGetOsVersionOptions {
|
|
os_version_id: number;
|
|
teamId?: number;
|
|
max_vulnerabilities?: number;
|
|
}
|
|
|
|
export interface IGetOsVersionQueryKey extends IGetOsVersionOptions {
|
|
scope: "osVersionDetails";
|
|
}
|
|
|
|
export interface IOSVersionResponse {
|
|
counts_updated_at?: string;
|
|
os_version: IOperatingSystemVersion;
|
|
}
|
|
|
|
type IGetOSVersionsRequestQueryParams = Record<
|
|
string,
|
|
string | number | undefined
|
|
>;
|
|
|
|
export const getOSVersions = ({
|
|
platform,
|
|
teamId,
|
|
os_name,
|
|
os_version,
|
|
order_key,
|
|
order_direction,
|
|
page,
|
|
per_page,
|
|
max_vulnerabilities = 0,
|
|
}: IGetOSVersionsQueryParams = {}): Promise<IOSVersionsResponse> => {
|
|
const { OS_VERSIONS } = endpoints;
|
|
let path = OS_VERSIONS;
|
|
|
|
const params: IGetOSVersionsRequestQueryParams = {
|
|
platform,
|
|
fleet_id: teamId,
|
|
os_name,
|
|
os_version,
|
|
order_key,
|
|
order_direction,
|
|
page,
|
|
per_page,
|
|
max_vulnerabilities,
|
|
};
|
|
|
|
const queryString = buildQueryStringFromParams(params);
|
|
|
|
if (queryString) path += `?${queryString}`;
|
|
|
|
return sendRequest("GET", path);
|
|
};
|
|
|
|
const getOSVersion = ({
|
|
os_version_id,
|
|
teamId,
|
|
max_vulnerabilities,
|
|
}: IGetOsVersionOptions): Promise<IOSVersionResponse> => {
|
|
const endpoint = endpoints.OS_VERSION(os_version_id);
|
|
const queryString = buildQueryStringFromParams({
|
|
fleet_id: teamId,
|
|
max_vulnerabilities,
|
|
});
|
|
const path = queryString ? `${endpoint}?${queryString}` : endpoint;
|
|
|
|
return sendRequest("GET", path);
|
|
};
|
|
|
|
export default {
|
|
getOSVersions,
|
|
getOSVersion,
|
|
};
|