@getmateo/cli 0.0.0-stage → 0.19.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +211 -0
- package/bin/mateo +3 -0
- package/dist/classify.d.ts +19 -0
- package/dist/classify.js +49 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +143 -0
- package/dist/commands/agent/archive.d.ts +27 -0
- package/dist/commands/agent/archive.js +88 -0
- package/dist/commands/agent/attach.d.ts +8 -0
- package/dist/commands/agent/attach.js +160 -0
- package/dist/commands/agent/delete.d.ts +15 -0
- package/dist/commands/agent/delete.js +104 -0
- package/dist/commands/agent/detach.d.ts +16 -0
- package/dist/commands/agent/detach.js +44 -0
- package/dist/commands/agent/import.d.ts +14 -0
- package/dist/commands/agent/import.js +108 -0
- package/dist/commands/agent/index.d.ts +3 -0
- package/dist/commands/agent/index.js +56 -0
- package/dist/commands/agent/inspect.d.ts +15 -0
- package/dist/commands/agent/inspect.js +196 -0
- package/dist/commands/agent/logs.d.ts +39 -0
- package/dist/commands/agent/logs.js +369 -0
- package/dist/commands/agent/ls.d.ts +61 -0
- package/dist/commands/agent/ls.js +201 -0
- package/dist/commands/agent/mode.d.ts +18 -0
- package/dist/commands/agent/mode.js +100 -0
- package/dist/commands/agent/open.d.ts +11 -0
- package/dist/commands/agent/open.js +74 -0
- package/dist/commands/agent/reload.d.ts +25 -0
- package/dist/commands/agent/reload.js +64 -0
- package/dist/commands/agent/run.d.ts +77 -0
- package/dist/commands/agent/run.js +556 -0
- package/dist/commands/agent/send.d.ts +21 -0
- package/dist/commands/agent/send.js +187 -0
- package/dist/commands/agent/stop.d.ts +17 -0
- package/dist/commands/agent/stop.js +102 -0
- package/dist/commands/agent/update.d.ts +51 -0
- package/dist/commands/agent/update.js +173 -0
- package/dist/commands/agent/wait.d.ts +31 -0
- package/dist/commands/agent/wait.js +161 -0
- package/dist/commands/clone.d.ts +17 -0
- package/dist/commands/clone.js +59 -0
- package/dist/commands/daemon/config.d.ts +3 -0
- package/dist/commands/daemon/config.js +103 -0
- package/dist/commands/daemon/index.d.ts +3 -0
- package/dist/commands/daemon/index.js +28 -0
- package/dist/commands/daemon/local-daemon.d.ts +13 -0
- package/dist/commands/daemon/local-daemon.js +105 -0
- package/dist/commands/daemon/pair.d.ts +30 -0
- package/dist/commands/daemon/pair.js +145 -0
- package/dist/commands/daemon/reload.d.ts +12 -0
- package/dist/commands/daemon/reload.js +44 -0
- package/dist/commands/daemon/restart.d.ts +29 -0
- package/dist/commands/daemon/restart.js +169 -0
- package/dist/commands/daemon/runtime-toolchain.d.ts +6 -0
- package/dist/commands/daemon/runtime-toolchain.js +87 -0
- package/dist/commands/daemon/set-password.d.ts +17 -0
- package/dist/commands/daemon/set-password.js +89 -0
- package/dist/commands/daemon/start.d.ts +20 -0
- package/dist/commands/daemon/start.js +52 -0
- package/dist/commands/daemon/status.d.ts +13 -0
- package/dist/commands/daemon/status.js +119 -0
- package/dist/commands/daemon/stop.d.ts +20 -0
- package/dist/commands/daemon/stop.js +58 -0
- package/dist/commands/fleet/index.d.ts +4 -0
- package/dist/commands/fleet/index.js +57 -0
- package/dist/commands/heartbeat/index.d.ts +3 -0
- package/dist/commands/heartbeat/index.js +139 -0
- package/dist/commands/hooks.d.ts +19 -0
- package/dist/commands/hooks.js +89 -0
- package/dist/commands/hub/authority.d.ts +17 -0
- package/dist/commands/hub/authority.js +18 -0
- package/dist/commands/hub/connect.d.ts +24 -0
- package/dist/commands/hub/connect.js +44 -0
- package/dist/commands/hub/credentials.d.ts +21 -0
- package/dist/commands/hub/credentials.js +143 -0
- package/dist/commands/hub/daemon-client.d.ts +41 -0
- package/dist/commands/hub/daemon-client.js +14 -0
- package/dist/commands/hub/deploy-bundle.d.ts +16 -0
- package/dist/commands/hub/deploy-bundle.js +248 -0
- package/dist/commands/hub/deploy-triggers.d.ts +6 -0
- package/dist/commands/hub/deploy-triggers.js +116 -0
- package/dist/commands/hub/deploy.d.ts +50 -0
- package/dist/commands/hub/deploy.js +159 -0
- package/dist/commands/hub/disconnect.d.ts +17 -0
- package/dist/commands/hub/disconnect.js +24 -0
- package/dist/commands/hub/error.d.ts +6 -0
- package/dist/commands/hub/error.js +9 -0
- package/dist/commands/hub/export.d.ts +28 -0
- package/dist/commands/hub/export.js +80 -0
- package/dist/commands/hub/help.d.ts +3 -0
- package/dist/commands/hub/help.js +5 -0
- package/dist/commands/hub/hub-client/index.d.ts +22 -0
- package/dist/commands/hub/hub-client/index.js +135 -0
- package/dist/commands/hub/hub-client/internal/contracts.d.ts +126 -0
- package/dist/commands/hub/hub-client/internal/contracts.js +85 -0
- package/dist/commands/hub/hub-client/internal/problem.d.ts +3 -0
- package/dist/commands/hub/hub-client/internal/problem.js +85 -0
- package/dist/commands/hub/hub-client/internal/transport.d.ts +15 -0
- package/dist/commands/hub/hub-client/internal/transport.js +30 -0
- package/dist/commands/hub/index.d.ts +20 -0
- package/dist/commands/hub/index.js +94 -0
- package/dist/commands/hub/init-plan.d.ts +33 -0
- package/dist/commands/hub/init-plan.js +94 -0
- package/dist/commands/hub/init.d.ts +37 -0
- package/dist/commands/hub/init.js +525 -0
- package/dist/commands/hub/login-flow.d.ts +34 -0
- package/dist/commands/hub/login-flow.js +78 -0
- package/dist/commands/hub/login.d.ts +23 -0
- package/dist/commands/hub/login.js +40 -0
- package/dist/commands/hub/logout.d.ts +33 -0
- package/dist/commands/hub/logout.js +71 -0
- package/dist/commands/hub/origin.d.ts +2 -0
- package/dist/commands/hub/origin.js +27 -0
- package/dist/commands/hub/permissions.d.ts +22 -0
- package/dist/commands/hub/permissions.js +61 -0
- package/dist/commands/hub/projects.d.ts +24 -0
- package/dist/commands/hub/projects.js +49 -0
- package/dist/commands/hub/reporter.d.ts +10 -0
- package/dist/commands/hub/reporter.js +11 -0
- package/dist/commands/hub/starter-agent-runtime.d.ts +37 -0
- package/dist/commands/hub/starter-agent-runtime.js +49 -0
- package/dist/commands/hub/starter-trigger.d.ts +10 -0
- package/dist/commands/hub/starter-trigger.js +30 -0
- package/dist/commands/hub/status-output.d.ts +13 -0
- package/dist/commands/hub/status-output.js +30 -0
- package/dist/commands/onboard.d.ts +14 -0
- package/dist/commands/onboard.js +169 -0
- package/dist/commands/open.d.ts +4 -0
- package/dist/commands/open.js +91 -0
- package/dist/commands/permit/allow.d.ts +38 -0
- package/dist/commands/permit/allow.js +138 -0
- package/dist/commands/permit/deny.d.ts +13 -0
- package/dist/commands/permit/deny.js +100 -0
- package/dist/commands/permit/index.d.ts +3 -0
- package/dist/commands/permit/index.js +27 -0
- package/dist/commands/permit/ls.d.ts +21 -0
- package/dist/commands/permit/ls.js +54 -0
- package/dist/commands/plugin/index.d.ts +23 -0
- package/dist/commands/plugin/index.js +174 -0
- package/dist/commands/plugin/scaffold.d.ts +6 -0
- package/dist/commands/plugin/scaffold.js +212 -0
- package/dist/commands/plugin/shared.d.ts +7 -0
- package/dist/commands/plugin/shared.js +34 -0
- package/dist/commands/plugin/update.d.ts +37 -0
- package/dist/commands/plugin/update.js +58 -0
- package/dist/commands/project/create.d.ts +10 -0
- package/dist/commands/project/create.js +43 -0
- package/dist/commands/project/delete.d.ts +9 -0
- package/dist/commands/project/delete.js +35 -0
- package/dist/commands/project/index.d.ts +3 -0
- package/dist/commands/project/index.js +28 -0
- package/dist/commands/project/ls.d.ts +5 -0
- package/dist/commands/project/ls.js +19 -0
- package/dist/commands/project/rename.d.ts +15 -0
- package/dist/commands/project/rename.js +52 -0
- package/dist/commands/project/shared.d.ts +11 -0
- package/dist/commands/project/shared.js +18 -0
- package/dist/commands/provider/diagnostic.d.ts +12 -0
- package/dist/commands/provider/diagnostic.js +31 -0
- package/dist/commands/provider/index.d.ts +3 -0
- package/dist/commands/provider/index.js +21 -0
- package/dist/commands/provider/ls.d.ts +19 -0
- package/dist/commands/provider/ls.js +46 -0
- package/dist/commands/provider/models.d.ts +20 -0
- package/dist/commands/provider/models.js +53 -0
- package/dist/commands/schedule/create.d.ts +19 -0
- package/dist/commands/schedule/create.js +41 -0
- package/dist/commands/schedule/delete.d.ts +10 -0
- package/dist/commands/schedule/delete.js +32 -0
- package/dist/commands/schedule/index.d.ts +3 -0
- package/dist/commands/schedule/index.js +66 -0
- package/dist/commands/schedule/inspect.d.ts +6 -0
- package/dist/commands/schedule/inspect.js +27 -0
- package/dist/commands/schedule/logs.d.ts +6 -0
- package/dist/commands/schedule/logs.js +24 -0
- package/dist/commands/schedule/ls.d.ts +5 -0
- package/dist/commands/schedule/ls.js +25 -0
- package/dist/commands/schedule/pause.d.ts +5 -0
- package/dist/commands/schedule/pause.js +24 -0
- package/dist/commands/schedule/resume.d.ts +5 -0
- package/dist/commands/schedule/resume.js +24 -0
- package/dist/commands/schedule/run-once.d.ts +5 -0
- package/dist/commands/schedule/run-once.js +24 -0
- package/dist/commands/schedule/schema.d.ts +21 -0
- package/dist/commands/schedule/schema.js +67 -0
- package/dist/commands/schedule/shared.d.ts +61 -0
- package/dist/commands/schedule/shared.js +360 -0
- package/dist/commands/schedule/types.d.ts +165 -0
- package/dist/commands/schedule/types.js +2 -0
- package/dist/commands/schedule/update.d.ts +19 -0
- package/dist/commands/schedule/update.js +40 -0
- package/dist/commands/script/index.d.ts +3 -0
- package/dist/commands/script/index.js +19 -0
- package/dist/commands/script/ls.d.ts +6 -0
- package/dist/commands/script/ls.js +20 -0
- package/dist/commands/script/schema.d.ts +5 -0
- package/dist/commands/script/schema.js +13 -0
- package/dist/commands/script/shared.d.ts +12 -0
- package/dist/commands/script/shared.js +59 -0
- package/dist/commands/script/start.d.ts +6 -0
- package/dist/commands/script/start.js +23 -0
- package/dist/commands/script/stop.d.ts +6 -0
- package/dist/commands/script/stop.js +23 -0
- package/dist/commands/terminal/capture.d.ts +10 -0
- package/dist/commands/terminal/capture.js +67 -0
- package/dist/commands/terminal/create.d.ts +11 -0
- package/dist/commands/terminal/create.js +29 -0
- package/dist/commands/terminal/index.d.ts +3 -0
- package/dist/commands/terminal/index.js +51 -0
- package/dist/commands/terminal/kill.d.ts +6 -0
- package/dist/commands/terminal/kill.js +36 -0
- package/dist/commands/terminal/ls.d.ts +11 -0
- package/dist/commands/terminal/ls.js +21 -0
- package/dist/commands/terminal/schema.d.ts +10 -0
- package/dist/commands/terminal/schema.js +17 -0
- package/dist/commands/terminal/send-keys.d.ts +7 -0
- package/dist/commands/terminal/send-keys.js +44 -0
- package/dist/commands/terminal/shared.d.ts +13 -0
- package/dist/commands/terminal/shared.js +64 -0
- package/dist/commands/terminal/upgrade-hosts.d.ts +11 -0
- package/dist/commands/terminal/upgrade-hosts.js +46 -0
- package/dist/commands/usage/index.d.ts +29 -0
- package/dist/commands/usage/index.js +62 -0
- package/dist/commands/usage/presentation.d.ts +4 -0
- package/dist/commands/usage/presentation.js +146 -0
- package/dist/commands/workspace/archive.d.ts +13 -0
- package/dist/commands/workspace/archive.js +43 -0
- package/dist/commands/workspace/create.d.ts +50 -0
- package/dist/commands/workspace/create.js +132 -0
- package/dist/commands/workspace/index.d.ts +3 -0
- package/dist/commands/workspace/index.js +50 -0
- package/dist/commands/workspace/ls.d.ts +11 -0
- package/dist/commands/workspace/ls.js +33 -0
- package/dist/commands/workspace/rename.d.ts +23 -0
- package/dist/commands/workspace/rename.js +63 -0
- package/dist/commands/workspace/setup.d.ts +12 -0
- package/dist/commands/workspace/setup.js +41 -0
- package/dist/commands/workspace/shared.d.ts +15 -0
- package/dist/commands/workspace/shared.js +29 -0
- package/dist/commands/worktree/archive.d.ts +21 -0
- package/dist/commands/worktree/archive.js +108 -0
- package/dist/commands/worktree/create-input.d.ts +15 -0
- package/dist/commands/worktree/create-input.js +56 -0
- package/dist/commands/worktree/create.d.ts +11 -0
- package/dist/commands/worktree/create.js +50 -0
- package/dist/commands/worktree/index.d.ts +3 -0
- package/dist/commands/worktree/index.js +29 -0
- package/dist/commands/worktree/ls.d.ts +18 -0
- package/dist/commands/worktree/ls.js +73 -0
- package/dist/commands/worktree/repository-directory.d.ts +6 -0
- package/dist/commands/worktree/repository-directory.js +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/output/index.d.ts +45 -0
- package/dist/output/index.js +47 -0
- package/dist/output/json.d.ts +11 -0
- package/dist/output/json.js +37 -0
- package/dist/output/pairing.d.ts +9 -0
- package/dist/output/pairing.js +36 -0
- package/dist/output/quiet.d.ts +9 -0
- package/dist/output/quiet.js +22 -0
- package/dist/output/render.d.ts +15 -0
- package/dist/output/render.js +84 -0
- package/dist/output/table.d.ts +13 -0
- package/dist/output/table.js +135 -0
- package/dist/output/types.d.ts +73 -0
- package/dist/output/types.js +8 -0
- package/dist/output/with-output.d.ts +43 -0
- package/dist/output/with-output.js +85 -0
- package/dist/output/yaml.d.ts +11 -0
- package/dist/output/yaml.js +38 -0
- package/dist/run.d.ts +14 -0
- package/dist/run.js +62 -0
- package/dist/ssh/ssh-tunnel.d.ts +2 -0
- package/dist/ssh/ssh-tunnel.js +3 -0
- package/dist/utils/agent-directory.d.ts +31 -0
- package/dist/utils/agent-directory.js +48 -0
- package/dist/utils/caller-agent.d.ts +14 -0
- package/dist/utils/caller-agent.js +16 -0
- package/dist/utils/client-id.d.ts +2 -0
- package/dist/utils/client-id.js +31 -0
- package/dist/utils/client.d.ts +57 -0
- package/dist/utils/client.js +360 -0
- package/dist/utils/command-options.d.ts +8 -0
- package/dist/utils/command-options.js +49 -0
- package/dist/utils/daemon-target.d.ts +13 -0
- package/dist/utils/daemon-target.js +51 -0
- package/dist/utils/duration.d.ts +7 -0
- package/dist/utils/duration.js +39 -0
- package/dist/utils/errors.d.ts +5 -0
- package/dist/utils/errors.js +10 -0
- package/dist/utils/paths.d.ts +12 -0
- package/dist/utils/paths.js +22 -0
- package/dist/utils/provider-model.d.ts +11 -0
- package/dist/utils/provider-model.js +49 -0
- package/dist/utils/timeline.d.ts +12 -0
- package/dist/utils/timeline.js +16 -0
- package/dist/utils/wait-for-stop.d.ts +2 -0
- package/dist/utils/wait-for-stop.js +28 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.js +24 -0
- package/package.json +58 -4
- package/README.md +0 -3
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { DaemonTarget } from "../../utils/daemon-target.js";
|
|
2
|
+
import type { ProviderSnapshotEntry } from "@getmateo/protocol/agent-types";
|
|
3
|
+
export interface HubStatus {
|
|
4
|
+
state: string;
|
|
5
|
+
daemonId: string | null;
|
|
6
|
+
hubOrigin: string | null;
|
|
7
|
+
permissions: string[];
|
|
8
|
+
connectedAt: string | null;
|
|
9
|
+
lastError: string | null;
|
|
10
|
+
}
|
|
11
|
+
export interface HubProvidersSnapshotOptions {
|
|
12
|
+
cwd?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface HubDaemonClient {
|
|
15
|
+
connectHub(url: string, token: string, permissions?: readonly string[]): Promise<{
|
|
16
|
+
status: HubStatus;
|
|
17
|
+
}>;
|
|
18
|
+
updateHubPermissions(input: {
|
|
19
|
+
grant?: readonly string[];
|
|
20
|
+
revoke?: readonly string[];
|
|
21
|
+
}): Promise<{
|
|
22
|
+
status: HubStatus;
|
|
23
|
+
}>;
|
|
24
|
+
getHubStatus(): Promise<{
|
|
25
|
+
status: HubStatus;
|
|
26
|
+
}>;
|
|
27
|
+
disconnectHub(force: boolean): Promise<{
|
|
28
|
+
status: HubStatus;
|
|
29
|
+
warning?: string;
|
|
30
|
+
}>;
|
|
31
|
+
getProvidersSnapshot(options?: HubProvidersSnapshotOptions): Promise<{
|
|
32
|
+
entries: ProviderSnapshotEntry[];
|
|
33
|
+
}>;
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export interface HubDaemonConnection {
|
|
37
|
+
connect(target: DaemonTarget): Promise<HubDaemonClient>;
|
|
38
|
+
}
|
|
39
|
+
export declare const productionHubDaemonConnection: HubDaemonConnection;
|
|
40
|
+
export declare function withHubDaemon<T>(connection: HubDaemonConnection, target: DaemonTarget, action: (client: HubDaemonClient) => Promise<T>): Promise<T>;
|
|
41
|
+
//# sourceMappingURL=daemon-client.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { connectToDaemon } from "../../utils/client.js";
|
|
2
|
+
export const productionHubDaemonConnection = {
|
|
3
|
+
connect: (target) => connectToDaemon({ target }),
|
|
4
|
+
};
|
|
5
|
+
export async function withHubDaemon(connection, target, action) {
|
|
6
|
+
const client = await connection.connect(target);
|
|
7
|
+
try {
|
|
8
|
+
return await action(client);
|
|
9
|
+
}
|
|
10
|
+
finally {
|
|
11
|
+
await client.close().catch(() => undefined);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=daemon-client.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface HubBundleFile {
|
|
2
|
+
path: string;
|
|
3
|
+
content: string;
|
|
4
|
+
}
|
|
5
|
+
export interface HubDeployBundle {
|
|
6
|
+
projectSlug: string;
|
|
7
|
+
files: readonly HubBundleFile[];
|
|
8
|
+
workflowCount: number;
|
|
9
|
+
}
|
|
10
|
+
interface DiscoverHubBundleInput {
|
|
11
|
+
cwd: string;
|
|
12
|
+
project?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function discoverHubBundle(input: DiscoverHubBundleInput): Promise<HubDeployBundle>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=deploy-bundle.d.ts.map
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { lstat, readFile, readdir } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import YAML from "yaml";
|
|
4
|
+
import { HubCommandError } from "./error.js";
|
|
5
|
+
const HUB_RESOURCE_PATH = ".mateo/hub.yml";
|
|
6
|
+
const LEGACY_TOML_PATH = ".mateo/hub.toml";
|
|
7
|
+
const WORKFLOW_DIRECTORY = ".mateo/workflows";
|
|
8
|
+
const PARTIAL_DIRECTORY = `${WORKFLOW_DIRECTORY}/partials`;
|
|
9
|
+
const PROJECT_SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
10
|
+
export async function discoverHubBundle(input) {
|
|
11
|
+
const projectSlug = requireProjectSlug(input.project);
|
|
12
|
+
const root = path.resolve(input.cwd);
|
|
13
|
+
await rejectLegacyToml(root);
|
|
14
|
+
const resource = await readBundleFile(root, HUB_RESOURCE_PATH, {
|
|
15
|
+
missingCode: "HUB_RESOURCE_MISSING",
|
|
16
|
+
missingMessage: `${HUB_RESOURCE_PATH} does not exist. Run this command from the project root.`,
|
|
17
|
+
});
|
|
18
|
+
const workflowNames = await discoverWorkflowNames(root);
|
|
19
|
+
const workflows = await Promise.all(workflowNames.map((name) => readBundleFile(root, `${WORKFLOW_DIRECTORY}/${name}`)));
|
|
20
|
+
const partialPaths = collectPartialPaths(workflows);
|
|
21
|
+
const partials = await Promise.all(partialPaths.map((file) => readBundleFile(root, file)));
|
|
22
|
+
const files = [resource, ...workflows, ...partials].toSorted(compareBundleFiles);
|
|
23
|
+
assertUniqueBundlePaths(files);
|
|
24
|
+
return { projectSlug, files, workflowCount: workflows.length };
|
|
25
|
+
}
|
|
26
|
+
function requireProjectSlug(project) {
|
|
27
|
+
if (project === undefined) {
|
|
28
|
+
throw new HubCommandError("HUB_PROJECT_REQUIRED", "Project is required. Pass --project <slug>.");
|
|
29
|
+
}
|
|
30
|
+
if (!PROJECT_SLUG_PATTERN.test(project)) {
|
|
31
|
+
throw new HubCommandError("HUB_INVALID_PROJECT", "Project must be a bare slug such as my-project.");
|
|
32
|
+
}
|
|
33
|
+
return project;
|
|
34
|
+
}
|
|
35
|
+
async function rejectLegacyToml(root) {
|
|
36
|
+
try {
|
|
37
|
+
await lstat(path.join(root, LEGACY_TOML_PATH));
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (errorCode(error) === "ENOENT")
|
|
41
|
+
return;
|
|
42
|
+
throw unreadablePath(LEGACY_TOML_PATH);
|
|
43
|
+
}
|
|
44
|
+
throw new HubCommandError("HUB_CONFIGURATION_EXTENSION_UNSUPPORTED", `${LEGACY_TOML_PATH} is not supported. Use ${HUB_RESOURCE_PATH}.`);
|
|
45
|
+
}
|
|
46
|
+
async function discoverWorkflowNames(root) {
|
|
47
|
+
const directory = path.join(root, WORKFLOW_DIRECTORY);
|
|
48
|
+
await requireSafeDirectory(root, directory, WORKFLOW_DIRECTORY, {
|
|
49
|
+
missingCode: "HUB_WORKFLOW_DIRECTORY_MISSING",
|
|
50
|
+
missingMessage: `${WORKFLOW_DIRECTORY} does not exist.`,
|
|
51
|
+
});
|
|
52
|
+
let entries;
|
|
53
|
+
try {
|
|
54
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
throw unreadablePath(WORKFLOW_DIRECTORY);
|
|
58
|
+
}
|
|
59
|
+
const names = [];
|
|
60
|
+
for (const entry of entries.toSorted((left, right) => compareText(left.name, right.name))) {
|
|
61
|
+
const bundlePath = `${WORKFLOW_DIRECTORY}/${entry.name}`;
|
|
62
|
+
if (entry.isSymbolicLink())
|
|
63
|
+
throw unsafePath(bundlePath);
|
|
64
|
+
if (entry.isDirectory()) {
|
|
65
|
+
if (entry.name === "partials")
|
|
66
|
+
continue;
|
|
67
|
+
throw new HubCommandError("HUB_WORKFLOW_PATH_UNSUPPORTED", `${bundlePath} is not a direct-child .yml workflow.`);
|
|
68
|
+
}
|
|
69
|
+
if (!entry.isFile())
|
|
70
|
+
throw regularFileRequired(bundlePath);
|
|
71
|
+
if (!entry.name.endsWith(".yml")) {
|
|
72
|
+
throw new HubCommandError("HUB_WORKFLOW_EXTENSION_UNSUPPORTED", `${bundlePath} must use the .yml extension.`);
|
|
73
|
+
}
|
|
74
|
+
names.push(entry.name);
|
|
75
|
+
}
|
|
76
|
+
if (names.length === 0) {
|
|
77
|
+
throw new HubCommandError("HUB_WORKFLOW_MISSING", `${WORKFLOW_DIRECTORY} must contain at least one direct-child .yml workflow.`);
|
|
78
|
+
}
|
|
79
|
+
return names;
|
|
80
|
+
}
|
|
81
|
+
function collectPartialPaths(workflows) {
|
|
82
|
+
const paths = new Set();
|
|
83
|
+
for (const workflow of workflows) {
|
|
84
|
+
let document;
|
|
85
|
+
try {
|
|
86
|
+
document = YAML.parse(workflow.content);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
throw new HubCommandError("HUB_WORKFLOW_INVALID_YAML", `${workflow.path} is not valid YAML.`);
|
|
90
|
+
}
|
|
91
|
+
if (!isRecord(document) || !Array.isArray(document["steps"]))
|
|
92
|
+
continue;
|
|
93
|
+
for (const step of document["steps"]) {
|
|
94
|
+
if (!isRecord(step) || !Array.isArray(step["prompt"]))
|
|
95
|
+
continue;
|
|
96
|
+
for (const block of step["prompt"]) {
|
|
97
|
+
if (!isRecord(block) || !Object.hasOwn(block, "include"))
|
|
98
|
+
continue;
|
|
99
|
+
const include = block["include"];
|
|
100
|
+
if (typeof include !== "string") {
|
|
101
|
+
throw invalidPartialPath(workflow.path, String(include));
|
|
102
|
+
}
|
|
103
|
+
paths.add(resolvePartialPath(workflow.path, include));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return [...paths].sort(compareText);
|
|
108
|
+
}
|
|
109
|
+
function resolvePartialPath(workflowPath, include) {
|
|
110
|
+
const decoded = decodePartialPath(workflowPath, include);
|
|
111
|
+
if (/^(?:[a-zA-Z]:[\\/]|[\\/]{1,2})/u.test(decoded)) {
|
|
112
|
+
throw invalidPartialPath(workflowPath, include);
|
|
113
|
+
}
|
|
114
|
+
const segments = decoded.replaceAll("\\", "/").split("/");
|
|
115
|
+
if (segments.some((segment) => segment.length === 0 || segment === "." || segment === "..") ||
|
|
116
|
+
segments[0] !== "partials") {
|
|
117
|
+
throw invalidPartialPath(workflowPath, include);
|
|
118
|
+
}
|
|
119
|
+
return `${WORKFLOW_DIRECTORY}/${segments.join("/")}`;
|
|
120
|
+
}
|
|
121
|
+
function decodePartialPath(workflowPath, include) {
|
|
122
|
+
let decoded = include;
|
|
123
|
+
for (let attempt = 0; attempt < 8; attempt += 1) {
|
|
124
|
+
let next;
|
|
125
|
+
try {
|
|
126
|
+
next = decodeURIComponent(decoded);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
throw invalidPartialPath(workflowPath, include);
|
|
130
|
+
}
|
|
131
|
+
if (next === decoded)
|
|
132
|
+
break;
|
|
133
|
+
decoded = next;
|
|
134
|
+
}
|
|
135
|
+
if (decoded.includes("\0") || /%[0-9a-f]{2}/iu.test(decoded)) {
|
|
136
|
+
throw invalidPartialPath(workflowPath, include);
|
|
137
|
+
}
|
|
138
|
+
return decoded;
|
|
139
|
+
}
|
|
140
|
+
async function readBundleFile(root, bundlePath, missing = {
|
|
141
|
+
missingCode: "HUB_BUNDLE_FILE_MISSING",
|
|
142
|
+
missingMessage: `${bundlePath} does not exist.`,
|
|
143
|
+
}) {
|
|
144
|
+
const absolutePath = path.join(root, ...bundlePath.split("/"));
|
|
145
|
+
await rejectSymlinkComponents(root, absolutePath, bundlePath);
|
|
146
|
+
let stats;
|
|
147
|
+
try {
|
|
148
|
+
stats = await lstat(absolutePath);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
if (errorCode(error) === "ENOENT") {
|
|
152
|
+
throw new HubCommandError(missing.missingCode, missing.missingMessage);
|
|
153
|
+
}
|
|
154
|
+
throw unreadablePath(bundlePath);
|
|
155
|
+
}
|
|
156
|
+
if (stats.isSymbolicLink())
|
|
157
|
+
throw unsafePath(bundlePath);
|
|
158
|
+
if (!stats.isFile())
|
|
159
|
+
throw regularFileRequired(bundlePath);
|
|
160
|
+
if (!hasReadPermission(stats.mode))
|
|
161
|
+
throw unreadablePath(bundlePath);
|
|
162
|
+
try {
|
|
163
|
+
return { path: bundlePath, content: (await readFile(absolutePath)).toString("utf8") };
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
throw unreadablePath(bundlePath);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async function requireSafeDirectory(root, absolutePath, bundlePath, missing) {
|
|
170
|
+
await rejectSymlinkComponents(root, absolutePath, bundlePath);
|
|
171
|
+
let stats;
|
|
172
|
+
try {
|
|
173
|
+
stats = await lstat(absolutePath);
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
if (errorCode(error) === "ENOENT") {
|
|
177
|
+
throw new HubCommandError(missing.missingCode, missing.missingMessage);
|
|
178
|
+
}
|
|
179
|
+
throw unreadablePath(bundlePath);
|
|
180
|
+
}
|
|
181
|
+
if (stats.isSymbolicLink())
|
|
182
|
+
throw unsafePath(bundlePath);
|
|
183
|
+
if (!stats.isDirectory()) {
|
|
184
|
+
throw new HubCommandError("HUB_WORKFLOW_DIRECTORY_INVALID", `${bundlePath} must be a directory.`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async function rejectSymlinkComponents(root, target, bundlePath) {
|
|
188
|
+
const relative = path.relative(root, target);
|
|
189
|
+
let current = root;
|
|
190
|
+
for (const segment of relative.split(path.sep).filter(Boolean)) {
|
|
191
|
+
current = path.join(current, segment);
|
|
192
|
+
try {
|
|
193
|
+
if ((await lstat(current)).isSymbolicLink())
|
|
194
|
+
throw unsafePath(bundlePath);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
if (error instanceof HubCommandError)
|
|
198
|
+
throw error;
|
|
199
|
+
if (errorCode(error) === "ENOENT")
|
|
200
|
+
return;
|
|
201
|
+
throw unreadablePath(bundlePath);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function assertUniqueBundlePaths(files) {
|
|
206
|
+
const seen = new Set();
|
|
207
|
+
for (const file of files) {
|
|
208
|
+
if (seen.has(file.path)) {
|
|
209
|
+
throw new HubCommandError("HUB_BUNDLE_PATH_DUPLICATE", `${file.path} appears more than once in the discovered bundle.`);
|
|
210
|
+
}
|
|
211
|
+
seen.add(file.path);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function invalidPartialPath(workflowPath, include) {
|
|
215
|
+
return new HubCommandError("HUB_PARTIAL_PATH_INVALID", `${workflowPath} includes an unsafe path outside ${PARTIAL_DIRECTORY}: ${include}`);
|
|
216
|
+
}
|
|
217
|
+
function unsafePath(bundlePath) {
|
|
218
|
+
return new HubCommandError("HUB_BUNDLE_UNSAFE_PATH", `${bundlePath} must not use a symlink.`);
|
|
219
|
+
}
|
|
220
|
+
function unreadablePath(bundlePath) {
|
|
221
|
+
return new HubCommandError("HUB_BUNDLE_UNREADABLE", `Could not read ${bundlePath}. Check the file and permissions.`);
|
|
222
|
+
}
|
|
223
|
+
function regularFileRequired(bundlePath) {
|
|
224
|
+
return new HubCommandError("HUB_BUNDLE_NOT_FILE", `${bundlePath} must be a regular file.`);
|
|
225
|
+
}
|
|
226
|
+
function compareBundleFiles(left, right) {
|
|
227
|
+
return compareText(left.path, right.path);
|
|
228
|
+
}
|
|
229
|
+
function compareText(left, right) {
|
|
230
|
+
if (left < right)
|
|
231
|
+
return -1;
|
|
232
|
+
if (left > right)
|
|
233
|
+
return 1;
|
|
234
|
+
return 0;
|
|
235
|
+
}
|
|
236
|
+
function hasReadPermission(mode) {
|
|
237
|
+
return (mode & 0o444) !== 0;
|
|
238
|
+
}
|
|
239
|
+
function errorCode(error) {
|
|
240
|
+
if (typeof error !== "object" || error === null)
|
|
241
|
+
return undefined;
|
|
242
|
+
const code = Reflect.get(error, "code");
|
|
243
|
+
return typeof code === "string" ? code : undefined;
|
|
244
|
+
}
|
|
245
|
+
function isRecord(value) {
|
|
246
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=deploy-bundle.js.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { lstat, readFile, readdir } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { HubCommandError } from "./error.js";
|
|
4
|
+
const TRIGGER_DIRECTORY = ".mateo/triggers";
|
|
5
|
+
export async function discoverHubTriggers(cwd) {
|
|
6
|
+
const root = path.resolve(cwd);
|
|
7
|
+
const directory = path.join(root, TRIGGER_DIRECTORY);
|
|
8
|
+
const mateoDirectory = await readStats(path.join(root, ".mateo"), {
|
|
9
|
+
code: "HUB_TRIGGER_DIRECTORY_MISSING",
|
|
10
|
+
message: `${TRIGGER_DIRECTORY} does not exist. Run this command from the project root.`,
|
|
11
|
+
});
|
|
12
|
+
if (mateoDirectory.isSymbolicLink())
|
|
13
|
+
throw unsafeTriggerPath(TRIGGER_DIRECTORY);
|
|
14
|
+
const directoryStats = await readTriggerDirectoryStats(root, directory);
|
|
15
|
+
if (directoryStats.isSymbolicLink())
|
|
16
|
+
throw unsafeTriggerPath(TRIGGER_DIRECTORY);
|
|
17
|
+
if (!directoryStats.isDirectory()) {
|
|
18
|
+
throw new HubCommandError("HUB_TRIGGER_DIRECTORY_INVALID", `${TRIGGER_DIRECTORY} must be a directory.`);
|
|
19
|
+
}
|
|
20
|
+
let entries;
|
|
21
|
+
try {
|
|
22
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (!isExpectedReadError(error))
|
|
26
|
+
throw error;
|
|
27
|
+
throw unreadableTriggerPath(TRIGGER_DIRECTORY);
|
|
28
|
+
}
|
|
29
|
+
const triggers = [];
|
|
30
|
+
for (const entry of entries.toSorted((left, right) => left.name.localeCompare(right.name))) {
|
|
31
|
+
const triggerPath = `${TRIGGER_DIRECTORY}/${entry.name}`;
|
|
32
|
+
if (entry.isSymbolicLink())
|
|
33
|
+
throw unsafeTriggerPath(triggerPath);
|
|
34
|
+
if (!entry.isFile() || !entry.name.endsWith(".yml")) {
|
|
35
|
+
throw new HubCommandError("HUB_TRIGGER_PATH_UNSUPPORTED", `${triggerPath} must be a direct-child .yml trigger.`);
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
triggers.push({
|
|
39
|
+
path: triggerPath,
|
|
40
|
+
yaml: await readFile(path.join(root, triggerPath), "utf8"),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (!isExpectedReadError(error))
|
|
45
|
+
throw error;
|
|
46
|
+
throw unreadableTriggerPath(triggerPath);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (triggers.length === 0) {
|
|
50
|
+
throw new HubCommandError("HUB_TRIGGER_MISSING", `${TRIGGER_DIRECTORY} must contain at least one direct-child .yml trigger.`);
|
|
51
|
+
}
|
|
52
|
+
return triggers;
|
|
53
|
+
}
|
|
54
|
+
async function readTriggerDirectoryStats(root, directory) {
|
|
55
|
+
try {
|
|
56
|
+
return await lstat(directory);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (errorCode(error) !== "ENOENT") {
|
|
60
|
+
if (!isExpectedReadError(error))
|
|
61
|
+
throw error;
|
|
62
|
+
throw unreadableTriggerPath(TRIGGER_DIRECTORY);
|
|
63
|
+
}
|
|
64
|
+
if (await legacyBundleExists(root)) {
|
|
65
|
+
throw new HubCommandError("HUB_PROJECT_REQUIRED", "This directory contains a legacy .mateo/hub.yml bundle. Pass --project <slug> to deploy it.");
|
|
66
|
+
}
|
|
67
|
+
throw new HubCommandError("HUB_TRIGGER_DIRECTORY_MISSING", `${TRIGGER_DIRECTORY} does not exist. Run this command from the project root.`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function legacyBundleExists(root) {
|
|
71
|
+
try {
|
|
72
|
+
await lstat(path.join(root, ".mateo/hub.yml"));
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (errorCode(error) === "ENOENT")
|
|
77
|
+
return false;
|
|
78
|
+
if (!isExpectedReadError(error))
|
|
79
|
+
throw error;
|
|
80
|
+
throw unreadableTriggerPath(".mateo/hub.yml");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function readStats(target, missing) {
|
|
84
|
+
try {
|
|
85
|
+
return await lstat(target);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (errorCode(error) === "ENOENT")
|
|
89
|
+
throw new HubCommandError(missing.code, missing.message);
|
|
90
|
+
if (!isExpectedReadError(error))
|
|
91
|
+
throw error;
|
|
92
|
+
throw unreadableTriggerPath(TRIGGER_DIRECTORY);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function unsafeTriggerPath(triggerPath) {
|
|
96
|
+
return new HubCommandError("HUB_TRIGGER_UNSAFE_PATH", `${triggerPath} must not use a symlink.`);
|
|
97
|
+
}
|
|
98
|
+
function unreadableTriggerPath(triggerPath) {
|
|
99
|
+
return new HubCommandError("HUB_TRIGGER_UNREADABLE", `Could not read ${triggerPath}. Check the file and permissions.`);
|
|
100
|
+
}
|
|
101
|
+
function errorCode(error) {
|
|
102
|
+
if (typeof error !== "object" || error === null)
|
|
103
|
+
return undefined;
|
|
104
|
+
const code = Reflect.get(error, "code");
|
|
105
|
+
return typeof code === "string" ? code : undefined;
|
|
106
|
+
}
|
|
107
|
+
function isExpectedReadError(error) {
|
|
108
|
+
const code = errorCode(error);
|
|
109
|
+
return (code === "EACCES" ||
|
|
110
|
+
code === "EPERM" ||
|
|
111
|
+
code === "ENOENT" ||
|
|
112
|
+
code === "ENOTDIR" ||
|
|
113
|
+
code === "ELOOP" ||
|
|
114
|
+
code === "EISDIR");
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=deploy-triggers.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import { type ListResult, type SingleResult } from "../../output/index.js";
|
|
3
|
+
import { HubHttpClient, type HubInstallResult, type HubTriggerInstallationResult, type HubTriggerValidationResult, type HubValidationResult } from "./hub-client/index.js";
|
|
4
|
+
import { type HubCredentialStore } from "./credentials.js";
|
|
5
|
+
import { type HubDeployBundle } from "./deploy-bundle.js";
|
|
6
|
+
import { type HubDeployTrigger } from "./deploy-triggers.js";
|
|
7
|
+
import { type HubReporter } from "./reporter.js";
|
|
8
|
+
export interface HubDeployOptions {
|
|
9
|
+
project?: string;
|
|
10
|
+
hub?: string;
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
dryRun?: boolean;
|
|
13
|
+
json?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface HubDeployEnvironment {
|
|
16
|
+
cwd: string;
|
|
17
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
18
|
+
credentials?: HubCredentialStore;
|
|
19
|
+
hub?: Pick<HubHttpClient, "installConfiguration" | "validateConfiguration" | "installTrigger" | "validateTrigger">;
|
|
20
|
+
reporter?: HubReporter;
|
|
21
|
+
}
|
|
22
|
+
export interface HubDeployCommandDependencies {
|
|
23
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
24
|
+
credentials: HubCredentialStore;
|
|
25
|
+
hub: Pick<HubHttpClient, "installConfiguration" | "validateConfiguration" | "installTrigger" | "validateTrigger">;
|
|
26
|
+
reporter: HubReporter;
|
|
27
|
+
cwd(): string;
|
|
28
|
+
}
|
|
29
|
+
interface HubDeployResult extends HubInstallResult {
|
|
30
|
+
origin: string;
|
|
31
|
+
workflows: number;
|
|
32
|
+
}
|
|
33
|
+
interface HubDryRunResult extends HubValidationResult {
|
|
34
|
+
origin: string;
|
|
35
|
+
workflows: number;
|
|
36
|
+
}
|
|
37
|
+
interface HubTriggerDeployResult extends HubTriggerInstallationResult {
|
|
38
|
+
origin: string;
|
|
39
|
+
path: string;
|
|
40
|
+
}
|
|
41
|
+
interface HubTriggerDryRunResult extends HubTriggerValidationResult {
|
|
42
|
+
origin: string;
|
|
43
|
+
path: string;
|
|
44
|
+
}
|
|
45
|
+
export declare function runHubDeploy(options: HubDeployOptions, environment?: HubDeployEnvironment): Promise<SingleResult<HubDeployResult> | SingleResult<HubDryRunResult> | ListResult<HubTriggerDeployResult> | ListResult<HubTriggerDryRunResult>>;
|
|
46
|
+
export declare function runHubDeployTriggers(options: HubDeployOptions, triggers: readonly HubDeployTrigger[], environment: HubDeployEnvironment): Promise<ListResult<HubTriggerDeployResult> | ListResult<HubTriggerDryRunResult>>;
|
|
47
|
+
export declare function runHubDeployBundle(options: HubDeployOptions, deployInput: HubDeployBundle, environment: HubDeployEnvironment): Promise<SingleResult<HubDeployResult> | SingleResult<HubDryRunResult>>;
|
|
48
|
+
export declare function addHubDeployCommand(hub: Command, dependencies: HubDeployCommandDependencies): void;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=deploy.d.ts.map
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { withOutput, } from "../../output/index.js";
|
|
2
|
+
import { addJsonOption } from "../../utils/command-options.js";
|
|
3
|
+
import { resolveHubCredential, resolveHubOrigin } from "./authority.js";
|
|
4
|
+
import { HubHttpClient, } from "./hub-client/index.js";
|
|
5
|
+
import { PrivateHubCredentialStore } from "./credentials.js";
|
|
6
|
+
import { discoverHubBundle } from "./deploy-bundle.js";
|
|
7
|
+
import { discoverHubTriggers } from "./deploy-triggers.js";
|
|
8
|
+
import { HubCommandError } from "./error.js";
|
|
9
|
+
import { processHubReporter, reportHubProgress } from "./reporter.js";
|
|
10
|
+
import { addHubResolutionHelp } from "./help.js";
|
|
11
|
+
const resultSchema = {
|
|
12
|
+
idField: "versionId",
|
|
13
|
+
columns: [
|
|
14
|
+
{ header: "PROJECT", field: "projectSlug" },
|
|
15
|
+
{ header: "VERSION", field: "version" },
|
|
16
|
+
{ header: "VERSION ID", field: "versionId" },
|
|
17
|
+
{ header: "ACTIVE", field: "active" },
|
|
18
|
+
{ header: "WORKFLOWS", field: "workflows" },
|
|
19
|
+
{ header: "HUB", field: "origin" },
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
const validationSchema = {
|
|
23
|
+
idField: "projectSlug",
|
|
24
|
+
columns: [
|
|
25
|
+
{ header: "PROJECT", field: "projectSlug" },
|
|
26
|
+
{ header: "VALID", field: "valid" },
|
|
27
|
+
{ header: "WORKFLOWS", field: "workflows" },
|
|
28
|
+
{ header: "HUB", field: "origin" },
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
const triggerResultSchema = {
|
|
32
|
+
idField: "triggerId",
|
|
33
|
+
columns: [
|
|
34
|
+
{ header: "TRIGGER", field: "name" },
|
|
35
|
+
{ header: "VERSION", field: "version" },
|
|
36
|
+
{ header: "REVISION ID", field: "revisionId" },
|
|
37
|
+
{ header: "ACTIVE", field: "active" },
|
|
38
|
+
{ header: "PATH", field: "path" },
|
|
39
|
+
{ header: "HUB", field: "origin" },
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
const triggerValidationSchema = {
|
|
43
|
+
idField: "name",
|
|
44
|
+
columns: [
|
|
45
|
+
{ header: "TRIGGER", field: "name" },
|
|
46
|
+
{ header: "VALID", field: "valid" },
|
|
47
|
+
{ header: "PATH", field: "path" },
|
|
48
|
+
{ header: "HUB", field: "origin" },
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
export async function runHubDeploy(options, environment = {
|
|
52
|
+
cwd: process.cwd(),
|
|
53
|
+
env: process.env,
|
|
54
|
+
credentials: new PrivateHubCredentialStore(),
|
|
55
|
+
hub: new HubHttpClient(),
|
|
56
|
+
}) {
|
|
57
|
+
if (options.project === undefined) {
|
|
58
|
+
return runHubDeployTriggers(options, await discoverHubTriggers(environment.cwd), environment);
|
|
59
|
+
}
|
|
60
|
+
const deployInput = await discoverHubBundle({
|
|
61
|
+
cwd: environment.cwd,
|
|
62
|
+
project: options.project,
|
|
63
|
+
});
|
|
64
|
+
return runHubDeployBundle(options, deployInput, environment);
|
|
65
|
+
}
|
|
66
|
+
export async function runHubDeployTriggers(options, triggers, environment) {
|
|
67
|
+
const credentials = environment.credentials ?? new PrivateHubCredentialStore(environment.env);
|
|
68
|
+
const resolution = {
|
|
69
|
+
options: { origin: options.hub, apiKey: options.apiKey },
|
|
70
|
+
env: environment.env,
|
|
71
|
+
credentials,
|
|
72
|
+
};
|
|
73
|
+
const origin = resolveHubOrigin(resolution);
|
|
74
|
+
const credential = resolveHubCredential({ ...resolution, origin });
|
|
75
|
+
const action = options.dryRun === true ? "Validating" : "Deploying";
|
|
76
|
+
reportHubProgress(environment.reporter ?? processHubReporter, options, `${action} ${String(triggers.length)} trigger${triggers.length === 1 ? "" : "s"} ${options.dryRun === true ? "against" : "to"} ${origin}`);
|
|
77
|
+
const hub = environment.hub ?? new HubHttpClient();
|
|
78
|
+
if (options.dryRun === true) {
|
|
79
|
+
const data = await Promise.all(triggers.map(async (trigger) => ({
|
|
80
|
+
...(await hub.validateTrigger(origin, credential, trigger.yaml)),
|
|
81
|
+
origin,
|
|
82
|
+
path: trigger.path,
|
|
83
|
+
})));
|
|
84
|
+
return { type: "list", data, schema: triggerValidationSchema };
|
|
85
|
+
}
|
|
86
|
+
await Promise.all(triggers.map((trigger) => hub.validateTrigger(origin, credential, trigger.yaml)));
|
|
87
|
+
const data = [];
|
|
88
|
+
for (const trigger of triggers) {
|
|
89
|
+
try {
|
|
90
|
+
data.push({
|
|
91
|
+
...(await hub.installTrigger(origin, credential, trigger.yaml)),
|
|
92
|
+
origin,
|
|
93
|
+
path: trigger.path,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (data.length === 0)
|
|
98
|
+
throw error;
|
|
99
|
+
throw new HubCommandError("HUB_TRIGGER_DEPLOY_PARTIAL", `Could not deploy ${trigger.path} after ${String(data.length)} trigger${data.length === 1 ? "" : "s"} had been installed.`, `${errorMessage(error)}\nInstalled before the failure:\n${data.map(({ path: installedPath }) => `- ${installedPath}`).join("\n")}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return { type: "list", data, schema: triggerResultSchema };
|
|
103
|
+
}
|
|
104
|
+
function errorMessage(error) {
|
|
105
|
+
if (error instanceof HubCommandError) {
|
|
106
|
+
return error.details === undefined ? error.message : `${error.message}\n${error.details}`;
|
|
107
|
+
}
|
|
108
|
+
return error instanceof Error ? error.message : String(error);
|
|
109
|
+
}
|
|
110
|
+
export async function runHubDeployBundle(options, deployInput, environment) {
|
|
111
|
+
const credentials = environment.credentials ?? new PrivateHubCredentialStore(environment.env);
|
|
112
|
+
const resolution = {
|
|
113
|
+
options: { origin: options.hub, apiKey: options.apiKey },
|
|
114
|
+
env: environment.env,
|
|
115
|
+
credentials,
|
|
116
|
+
};
|
|
117
|
+
const origin = resolveHubOrigin(resolution);
|
|
118
|
+
const action = options.dryRun === true ? "Validating" : "Deploying";
|
|
119
|
+
reportHubProgress(environment.reporter ?? processHubReporter, options, `${action} ${deployInput.projectSlug} ${options.dryRun === true ? "against" : "to"} ${origin}`);
|
|
120
|
+
const credential = resolveHubCredential({ ...resolution, origin });
|
|
121
|
+
const request = {
|
|
122
|
+
origin,
|
|
123
|
+
apiKey: credential,
|
|
124
|
+
...deployInput,
|
|
125
|
+
};
|
|
126
|
+
if (options.dryRun === true) {
|
|
127
|
+
const validated = await (environment.hub ?? new HubHttpClient()).validateConfiguration(request);
|
|
128
|
+
return {
|
|
129
|
+
type: "single",
|
|
130
|
+
data: { ...validated, workflows: deployInput.workflowCount, origin },
|
|
131
|
+
schema: validationSchema,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const deployed = await (environment.hub ?? new HubHttpClient()).installConfiguration(request);
|
|
135
|
+
return {
|
|
136
|
+
type: "single",
|
|
137
|
+
data: { ...deployed, workflows: deployInput.workflowCount, origin },
|
|
138
|
+
schema: resultSchema,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export function addHubDeployCommand(hub, dependencies) {
|
|
142
|
+
addJsonOption(addHubResolutionHelp(hub
|
|
143
|
+
.command("deploy")
|
|
144
|
+
.description("Deploy .mateo organization triggers or a legacy project bundle")
|
|
145
|
+
.option("-p, --project <slug>", "Deploy a legacy bundle to this project slug")
|
|
146
|
+
.option("--hub <origin>", "Mateo Hub origin")
|
|
147
|
+
.option("--api-key <secret>", "Organization API key")
|
|
148
|
+
.option("--dry-run", "Validate without installing or activating"))).action(withOutput(async (...args) => {
|
|
149
|
+
const options = args.at(-2);
|
|
150
|
+
return runHubDeploy(options, {
|
|
151
|
+
cwd: dependencies.cwd(),
|
|
152
|
+
env: dependencies.env,
|
|
153
|
+
credentials: dependencies.credentials,
|
|
154
|
+
hub: dependencies.hub,
|
|
155
|
+
reporter: dependencies.reporter,
|
|
156
|
+
});
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=deploy.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { HubDaemonConnection } from "./daemon-client.js";
|
|
3
|
+
import { type HubReporter } from "./reporter.js";
|
|
4
|
+
interface HubDisconnectOptions {
|
|
5
|
+
force?: boolean;
|
|
6
|
+
host?: string;
|
|
7
|
+
daemonTarget: import("../../utils/daemon-target.js").DaemonTarget;
|
|
8
|
+
json?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface HubDisconnectDependencies {
|
|
11
|
+
daemon: HubDaemonConnection;
|
|
12
|
+
reporter: HubReporter;
|
|
13
|
+
}
|
|
14
|
+
export declare function runHubDisconnect(options: HubDisconnectOptions, dependencies: HubDisconnectDependencies): Promise<import("../../output/types.js").ListResult<import("./status-output.js").HubRow>>;
|
|
15
|
+
export declare function addHubDisconnectCommand(parent: Command, dependencies: HubDisconnectDependencies): void;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=disconnect.d.ts.map
|