@griffin-app/griffin-cli 1.0.26 → 1.0.28
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/README.md +122 -367
- package/dist/cli.js +48 -29
- package/dist/commands/env.d.ts +14 -3
- package/dist/commands/env.js +24 -22
- package/dist/commands/generate-key.d.ts +5 -6
- package/dist/commands/generate-key.js +20 -26
- package/dist/commands/hub/apply.d.ts +1 -0
- package/dist/commands/hub/apply.js +44 -29
- package/dist/commands/hub/connect.d.ts +2 -1
- package/dist/commands/hub/connect.js +18 -22
- package/dist/commands/hub/destroy.d.ts +2 -1
- package/dist/commands/hub/destroy.js +123 -119
- package/dist/commands/hub/integrations.d.ts +4 -1
- package/dist/commands/hub/integrations.js +160 -141
- package/dist/commands/hub/login.d.ts +13 -1
- package/dist/commands/hub/login.js +81 -15
- package/dist/commands/hub/logout.d.ts +2 -1
- package/dist/commands/hub/logout.js +7 -12
- package/dist/commands/hub/metrics.js +29 -27
- package/dist/commands/hub/monitor.js +16 -16
- package/dist/commands/hub/notifications.d.ts +3 -6
- package/dist/commands/hub/notifications.js +52 -38
- package/dist/commands/hub/run.d.ts +1 -0
- package/dist/commands/hub/run.js +114 -87
- package/dist/commands/hub/runs.d.ts +2 -0
- package/dist/commands/hub/runs.js +47 -45
- package/dist/commands/hub/secrets.d.ts +5 -5
- package/dist/commands/hub/secrets.js +80 -72
- package/dist/commands/hub/status.d.ts +4 -1
- package/dist/commands/hub/status.js +15 -9
- package/dist/commands/init.d.ts +2 -1
- package/dist/commands/init.js +31 -25
- package/dist/commands/local/run.d.ts +1 -0
- package/dist/commands/local/run.js +34 -26
- package/dist/commands/validate.d.ts +4 -1
- package/dist/commands/validate.js +23 -14
- package/dist/commands/variables.d.ts +17 -3
- package/dist/commands/variables.js +29 -28
- package/dist/core/credentials.d.ts +15 -0
- package/dist/core/credentials.js +37 -0
- package/dist/core/variables.js +4 -0
- package/dist/monitor-runner.js +0 -12
- package/dist/utils/command-wrapper.d.ts +9 -0
- package/dist/utils/command-wrapper.js +23 -0
- package/dist/utils/output.d.ts +66 -0
- package/dist/utils/output.js +202 -0
- package/dist/utils/sdk-error.d.ts +6 -1
- package/dist/utils/sdk-error.js +107 -77
- package/package.json +2 -2
|
@@ -1,141 +1,145 @@
|
|
|
1
1
|
import { loadState, resolveEnvironment } from "../../core/state.js";
|
|
2
2
|
import { createSdkWithCredentials } from "../../core/sdk.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { handleSDKErrorWithOutput } from "../../utils/sdk-error.js";
|
|
4
|
+
import { createCommandHandler } from "../../utils/command-wrapper.js";
|
|
5
5
|
/**
|
|
6
6
|
* Destroy monitors on the hub
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
8
|
+
export const executeDestroy = createCommandHandler("destroy", async (options, output) => {
|
|
9
|
+
const state = await loadState();
|
|
10
|
+
const envName = await resolveEnvironment(options.env);
|
|
11
|
+
if (!state.hub?.baseUrl) {
|
|
12
|
+
output.setData({
|
|
13
|
+
error: "NOT_CONFIGURED",
|
|
14
|
+
message: "Hub connection not configured.",
|
|
15
|
+
});
|
|
16
|
+
output.error("Hub connection not configured.");
|
|
17
|
+
output.dim("Connect with:");
|
|
18
|
+
output.dim(" griffin hub connect --url <url> --token <token>");
|
|
19
|
+
output.exit(1);
|
|
20
|
+
}
|
|
21
|
+
const sdk = await createSdkWithCredentials(state.hub.baseUrl);
|
|
22
|
+
const fetchSpinner = output.spinner("Fetching remote monitors...").start();
|
|
23
|
+
let response;
|
|
9
24
|
try {
|
|
10
|
-
|
|
11
|
-
const state = await loadState();
|
|
12
|
-
// Resolve environment
|
|
13
|
-
const envName = await resolveEnvironment(options.env);
|
|
14
|
-
// Check if hub is configured
|
|
15
|
-
if (!state.hub?.baseUrl) {
|
|
16
|
-
terminal.error("Hub connection not configured.");
|
|
17
|
-
terminal.dim("Connect with:");
|
|
18
|
-
terminal.dim(" griffin hub connect --url <url> --token <token>");
|
|
19
|
-
terminal.exit(1);
|
|
20
|
-
}
|
|
21
|
-
terminal.info(`Destroying monitors in ${terminal.colors.cyan(envName)} environment`);
|
|
22
|
-
terminal.blank();
|
|
23
|
-
// Create SDK client with credentials
|
|
24
|
-
const sdk = await createSdkWithCredentials(state.hub.baseUrl);
|
|
25
|
-
// Fetch remote monitors for this project + environment
|
|
26
|
-
const fetchSpinner = terminal
|
|
27
|
-
.spinner("Fetching remote monitors...")
|
|
28
|
-
.start();
|
|
29
|
-
const response = await withSDKErrorHandling(() => sdk.getMonitor({
|
|
25
|
+
response = await sdk.getMonitor({
|
|
30
26
|
query: {
|
|
31
27
|
projectId: state.projectId,
|
|
32
28
|
environment: envName,
|
|
33
29
|
},
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
handleSDKErrorWithOutput(err, output, "Failed to fetch remote monitors");
|
|
34
|
+
}
|
|
35
|
+
const remoteMonitors = response.data?.data;
|
|
36
|
+
fetchSpinner.succeed(`Found ${remoteMonitors.length} remote monitor(s)`);
|
|
37
|
+
if (remoteMonitors.length === 0) {
|
|
38
|
+
output.setData({ destroyed: [], total: 0, dryRun: options.dryRun ?? false });
|
|
39
|
+
output.success("No monitors to destroy.");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
let monitorsToDestroy = remoteMonitors;
|
|
43
|
+
if (options.monitor) {
|
|
44
|
+
const targetMonitor = remoteMonitors.find((m) => m.name === options.monitor || m.id === options.monitor);
|
|
45
|
+
if (!targetMonitor) {
|
|
46
|
+
output.setData({
|
|
47
|
+
error: "NOT_FOUND",
|
|
48
|
+
message: `Monitor "${options.monitor}" not found in ${envName} environment`,
|
|
49
|
+
});
|
|
50
|
+
output.error(`Monitor "${options.monitor}" not found in ${envName} environment`);
|
|
51
|
+
output.blank();
|
|
52
|
+
output.dim("Available monitors:");
|
|
53
|
+
remoteMonitors.forEach((m) => {
|
|
54
|
+
output.dim(` - ${m.name} (${m.id})`);
|
|
55
|
+
});
|
|
56
|
+
output.exit(1);
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
monitorsToDestroy = [targetMonitor];
|
|
59
|
+
}
|
|
60
|
+
output.blank();
|
|
61
|
+
output.warn(`The following ${monitorsToDestroy.length} monitor(s) will be DESTROYED:`);
|
|
62
|
+
output.blank();
|
|
63
|
+
monitorsToDestroy.forEach((monitor) => {
|
|
64
|
+
output.log(` ${output.colors.red("-")} ${monitor.name} (${monitor.id})`);
|
|
65
|
+
});
|
|
66
|
+
output.blank();
|
|
67
|
+
if (options.dryRun) {
|
|
68
|
+
output.setData({
|
|
69
|
+
dryRun: true,
|
|
70
|
+
wouldDestroy: monitorsToDestroy.map((m) => ({ id: m.id, name: m.name })),
|
|
71
|
+
total: monitorsToDestroy.length,
|
|
63
72
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
output.info("[DRY RUN] No changes will be made");
|
|
74
|
+
output.blank();
|
|
75
|
+
output.log("Summary:");
|
|
76
|
+
output.log(` Would destroy: ${monitorsToDestroy.length} monitor(s)`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (!options.autoApprove) {
|
|
80
|
+
output.blank();
|
|
81
|
+
output.warn(output.colors.bold("This action is DESTRUCTIVE and cannot be undone!"));
|
|
82
|
+
output.blank();
|
|
83
|
+
const confirmed = await output.confirm("Do you really want to destroy these monitors?");
|
|
84
|
+
if (!confirmed) {
|
|
85
|
+
output.setData({ destroyed: [], cancelled: true });
|
|
86
|
+
output.warn("Destroy cancelled.");
|
|
71
87
|
return;
|
|
72
88
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (!confirmed) {
|
|
80
|
-
terminal.warn("Destroy cancelled.");
|
|
89
|
+
if (!options.monitor && monitorsToDestroy.length > 1) {
|
|
90
|
+
output.blank();
|
|
91
|
+
const doubleConfirmed = await output.confirm(`Type 'yes' to confirm destroying ALL ${monitorsToDestroy.length} monitors`);
|
|
92
|
+
if (!doubleConfirmed) {
|
|
93
|
+
output.setData({ destroyed: [], cancelled: true });
|
|
94
|
+
output.warn("Destroy cancelled.");
|
|
81
95
|
return;
|
|
82
96
|
}
|
|
83
|
-
// Double confirmation for destroying all monitors
|
|
84
|
-
if (!options.monitor && monitorsToDestroy.length > 1) {
|
|
85
|
-
terminal.blank();
|
|
86
|
-
const doubleConfirmed = await terminal.confirm(`Type 'yes' to confirm destroying ALL ${monitorsToDestroy.length} monitors`);
|
|
87
|
-
if (!doubleConfirmed) {
|
|
88
|
-
terminal.warn("Destroy cancelled.");
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
// Destroy monitors
|
|
94
|
-
terminal.blank();
|
|
95
|
-
const destroySpinner = terminal.spinner("Destroying monitors...").start();
|
|
96
|
-
let successCount = 0;
|
|
97
|
-
let failureCount = 0;
|
|
98
|
-
const errors = [];
|
|
99
|
-
for (const monitor of monitorsToDestroy) {
|
|
100
|
-
try {
|
|
101
|
-
await withSDKErrorHandling(() => sdk.deleteMonitorById({
|
|
102
|
-
path: {
|
|
103
|
-
id: monitor.id,
|
|
104
|
-
},
|
|
105
|
-
}), `Failed to delete monitor "${monitor.name}"`);
|
|
106
|
-
successCount++;
|
|
107
|
-
terminal.success(`Destroyed: ${terminal.colors.cyan(monitor.name)}`);
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
failureCount++;
|
|
111
|
-
const errorMessage = error.message;
|
|
112
|
-
errors.push({ monitor, error: errorMessage });
|
|
113
|
-
terminal.error(`Failed to destroy: ${monitor.name} - ${errorMessage}`);
|
|
114
|
-
}
|
|
115
97
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
98
|
+
}
|
|
99
|
+
output.blank();
|
|
100
|
+
const destroySpinner = output.spinner("Destroying monitors...").start();
|
|
101
|
+
const destroyed = [];
|
|
102
|
+
const errors = [];
|
|
103
|
+
for (const monitor of monitorsToDestroy) {
|
|
104
|
+
try {
|
|
105
|
+
await sdk.deleteMonitorById({ path: { id: monitor.id } });
|
|
106
|
+
destroyed.push({ id: monitor.id, name: monitor.name });
|
|
107
|
+
output.success(`Destroyed: ${output.colors.cyan(monitor.name)}`);
|
|
121
108
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
terminal.log(` ${terminal.colors.red("✗")} Failed: ${failureCount}`);
|
|
129
|
-
terminal.blank();
|
|
130
|
-
terminal.error("Errors:");
|
|
131
|
-
errors.forEach(({ monitor, error }) => {
|
|
132
|
-
terminal.error(` - ${monitor.name}: ${error}`);
|
|
109
|
+
catch (err) {
|
|
110
|
+
const errorMessage = err.message;
|
|
111
|
+
errors.push({
|
|
112
|
+
monitorId: monitor.id,
|
|
113
|
+
monitorName: monitor.name,
|
|
114
|
+
error: errorMessage,
|
|
133
115
|
});
|
|
134
|
-
|
|
116
|
+
output.error(`Failed to destroy: ${monitor.name} - ${errorMessage}`);
|
|
135
117
|
}
|
|
136
118
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
119
|
+
if (errors.length === 0) {
|
|
120
|
+
destroySpinner.succeed("All monitors destroyed successfully");
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
destroySpinner.fail("Some monitors failed to destroy");
|
|
124
|
+
}
|
|
125
|
+
output.setData({
|
|
126
|
+
destroyed,
|
|
127
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
128
|
+
total: monitorsToDestroy.length,
|
|
129
|
+
successCount: destroyed.length,
|
|
130
|
+
failureCount: errors.length,
|
|
131
|
+
});
|
|
132
|
+
output.blank();
|
|
133
|
+
output.log("Destroy complete:");
|
|
134
|
+
output.blank();
|
|
135
|
+
output.log(` ${output.colors.green("✓")} Destroyed: ${destroyed.length}`);
|
|
136
|
+
if (errors.length > 0) {
|
|
137
|
+
output.log(` ${output.colors.red("✗")} Failed: ${errors.length}`);
|
|
138
|
+
output.blank();
|
|
139
|
+
output.error("Errors:");
|
|
140
|
+
errors.forEach(({ monitorName, error }) => {
|
|
141
|
+
output.error(` - ${monitorName}: ${error}`);
|
|
142
|
+
});
|
|
143
|
+
output.exit(1);
|
|
140
144
|
}
|
|
141
|
-
}
|
|
145
|
+
});
|
|
@@ -35,6 +35,7 @@ export declare const executeIntegrationsUpdate: (options: IntegrationsUpdateOpti
|
|
|
35
35
|
export interface IntegrationsRemoveOptions {
|
|
36
36
|
id: string;
|
|
37
37
|
force?: boolean;
|
|
38
|
+
json?: boolean;
|
|
38
39
|
}
|
|
39
40
|
export declare const executeIntegrationsRemove: (options: IntegrationsRemoveOptions) => Promise<void>;
|
|
40
41
|
export interface IntegrationsConnectOptions {
|
|
@@ -43,6 +44,8 @@ export interface IntegrationsConnectOptions {
|
|
|
43
44
|
name?: string;
|
|
44
45
|
environment: string;
|
|
45
46
|
json?: boolean;
|
|
47
|
+
configJson?: string;
|
|
48
|
+
credentialsJson?: string;
|
|
46
49
|
}
|
|
47
50
|
export declare function printConnectHelp(providers: ProviderDefinition[]): void;
|
|
48
|
-
export declare
|
|
51
|
+
export declare const executeIntegrationsConnect: (options: IntegrationsConnectOptions) => Promise<void>;
|