fleet/frontend/interfaces/script.ts
Scott Gress e985d20b1d
UI for scheduling batch scripts (#31885)
# Details

This PR merges the feature branch for the scheduled scripts UI into
main. This includes the following previously-approved PRs:

* https://github.com/fleetdm/fleet/pull/31750
* https://github.com/fleetdm/fleet/pull/31604
* https://github.com/fleetdm/fleet/pull/31797


# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [X] 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.

## Testing

- [X] Added/updated automated tests
- [X] Where appropriate, [automated tests simulate multiple hosts and
test for host
isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing)
(updates to one hosts's records do not affect another)

- [X] QA'd all new/changed functionality manually

---------

Co-authored-by: jacobshandling <61553566+jacobshandling@users.noreply.github.com>
Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-08-14 10:10:45 -05:00

43 lines
1.3 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, team_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);
};