mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +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 -->
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import { HOST_LINUX_PLATFORMS } from "./platform";
|
|
|
|
export interface IScript {
|
|
id: number;
|
|
team_id: number | null;
|
|
name: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
}
|
|
|
|
export const isScriptSupportedPlatform = (hostPlatform: string) =>
|
|
["darwin", "windows", ...HOST_LINUX_PLATFORMS].includes(hostPlatform); // excludes chrome, ios, ipados, android see also https://github.com/fleetdm/fleet/blob/5a21e2cfb029053ddad0508869eb9f1f23997bf2/server/fleet/hosts.go#L775
|
|
|
|
export const addTeamIdCriteria = (
|
|
pred: any,
|
|
teamId: number,
|
|
isFreeTier?: boolean
|
|
) => (isFreeTier ? { ...pred } : { ...pred, fleet_id: teamId });
|
|
|
|
export type IScriptExecutionStatus = "ran" | "pending" | "error";
|
|
|
|
export interface ILastExecution {
|
|
execution_id: string;
|
|
executed_at: string;
|
|
status: IScriptExecutionStatus;
|
|
}
|
|
|
|
export type ScriptContent = string;
|
|
|
|
export interface IHostScript {
|
|
script_id: number;
|
|
name: string;
|
|
last_execution: ILastExecution | null;
|
|
}
|
|
|
|
const SCRIPT_BATCH_STATUSES = ["started", "scheduled", "finished"] as const;
|
|
export type ScriptBatchStatus = typeof SCRIPT_BATCH_STATUSES[number];
|
|
|
|
export const isValidScriptBatchStatus = (
|
|
status: string | null | undefined
|
|
): status is ScriptBatchStatus => {
|
|
return SCRIPT_BATCH_STATUSES.includes((status ?? "") as ScriptBatchStatus);
|
|
};
|
|
|
|
export const SCRIPT_BATCH_HOST_EXECUTED_STATUSES = ["ran", "errored"];
|
|
export const SCRIPT_BATCH_HOST_NOT_EXECUTED_STATUSES = [
|
|
"pending",
|
|
"incompatible",
|
|
"canceled",
|
|
];
|
|
|
|
export const SCRIPT_BATCH_HOST_STATUSES = SCRIPT_BATCH_HOST_EXECUTED_STATUSES.concat(
|
|
SCRIPT_BATCH_HOST_NOT_EXECUTED_STATUSES
|
|
);
|
|
export type ScriptBatchHostStatus = typeof SCRIPT_BATCH_HOST_STATUSES[number];
|
|
|
|
export const isValidScriptBatchHostStatus = (
|
|
status: string | null | undefined
|
|
): status is ScriptBatchHostStatus => {
|
|
return SCRIPT_BATCH_HOST_STATUSES.includes(
|
|
(status ?? "") as ScriptBatchHostStatus
|
|
);
|
|
};
|