-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpreflight.ts
More file actions
35 lines (30 loc) · 1.32 KB
/
preflight.ts
File metadata and controls
35 lines (30 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { ensureLocalStackCli, getLocalStackStatus } from "../lib/localstack/localstack.utils";
import { checkProFeature, ProFeature } from "../lib/localstack/license-checker";
import { ResponseBuilder } from "./response-builder";
type ToolResponse = ReturnType<typeof ResponseBuilder.error>;
export const requireLocalStackCli = async (): Promise<ToolResponse | null> => {
const cliCheck = await ensureLocalStackCli();
return cliCheck ? (cliCheck as ToolResponse) : null;
};
export const requireProFeature = async (feature: ProFeature): Promise<ToolResponse | null> => {
const licenseCheck = await checkProFeature(feature);
return !licenseCheck.isSupported
? ResponseBuilder.error("Feature Not Available", licenseCheck.errorMessage)
: null;
};
export const runPreflights = async (
checks: Array<Promise<ToolResponse | null>>
): Promise<ToolResponse | null> => {
const results = await Promise.all(checks);
return results.find((r) => r !== null) || null;
};
export const requireLocalStackRunning = async (): Promise<ToolResponse | null> => {
const statusResult = await getLocalStackStatus();
if (!statusResult.isRunning) {
return ResponseBuilder.error(
"LocalStack Not Running",
"LocalStack is not running. Please start LocalStack (e.g., 'localstack start') and try again."
);
}
return null;
};