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 #35166 Fix - For an OS version, we first fetch the version with max_vulnerabilities=0. - If the OS version has vulnerabilities and it is non-Linux, then we refetch the OS version without specifying the `max_vulnerabilities` parameter, which fetches all vulnerabilities. # Checklist for submitter ## Testing - [x] QA'd all new/changed functionality manually For unreleased bug fixes in a release candidate, one of: - [x] Confirmed that the fix is not expected to adversely impact load test results <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Optimized vulnerability data loading for operating system details with enhanced fetching strategy * Improved loading state management for clearer visibility during data retrieval on OS version pages <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jacob Shandling <jacob@shandling.dev>
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,
|
|
team_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({
|
|
team_id: teamId,
|
|
max_vulnerabilities,
|
|
});
|
|
const path = queryString ? `${endpoint}?${queryString}` : endpoint;
|
|
|
|
return sendRequest("GET", path);
|
|
};
|
|
|
|
export default {
|
|
getOSVersions,
|
|
getOSVersion,
|
|
};
|