@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.
Files changed (49) hide show
  1. package/README.md +122 -367
  2. package/dist/cli.js +48 -29
  3. package/dist/commands/env.d.ts +14 -3
  4. package/dist/commands/env.js +24 -22
  5. package/dist/commands/generate-key.d.ts +5 -6
  6. package/dist/commands/generate-key.js +20 -26
  7. package/dist/commands/hub/apply.d.ts +1 -0
  8. package/dist/commands/hub/apply.js +44 -29
  9. package/dist/commands/hub/connect.d.ts +2 -1
  10. package/dist/commands/hub/connect.js +18 -22
  11. package/dist/commands/hub/destroy.d.ts +2 -1
  12. package/dist/commands/hub/destroy.js +123 -119
  13. package/dist/commands/hub/integrations.d.ts +4 -1
  14. package/dist/commands/hub/integrations.js +160 -141
  15. package/dist/commands/hub/login.d.ts +13 -1
  16. package/dist/commands/hub/login.js +81 -15
  17. package/dist/commands/hub/logout.d.ts +2 -1
  18. package/dist/commands/hub/logout.js +7 -12
  19. package/dist/commands/hub/metrics.js +29 -27
  20. package/dist/commands/hub/monitor.js +16 -16
  21. package/dist/commands/hub/notifications.d.ts +3 -6
  22. package/dist/commands/hub/notifications.js +52 -38
  23. package/dist/commands/hub/run.d.ts +1 -0
  24. package/dist/commands/hub/run.js +114 -87
  25. package/dist/commands/hub/runs.d.ts +2 -0
  26. package/dist/commands/hub/runs.js +47 -45
  27. package/dist/commands/hub/secrets.d.ts +5 -5
  28. package/dist/commands/hub/secrets.js +80 -72
  29. package/dist/commands/hub/status.d.ts +4 -1
  30. package/dist/commands/hub/status.js +15 -9
  31. package/dist/commands/init.d.ts +2 -1
  32. package/dist/commands/init.js +31 -25
  33. package/dist/commands/local/run.d.ts +1 -0
  34. package/dist/commands/local/run.js +34 -26
  35. package/dist/commands/validate.d.ts +4 -1
  36. package/dist/commands/validate.js +23 -14
  37. package/dist/commands/variables.d.ts +17 -3
  38. package/dist/commands/variables.js +29 -28
  39. package/dist/core/credentials.d.ts +15 -0
  40. package/dist/core/credentials.js +37 -0
  41. package/dist/core/variables.js +4 -0
  42. package/dist/monitor-runner.js +0 -12
  43. package/dist/utils/command-wrapper.d.ts +9 -0
  44. package/dist/utils/command-wrapper.js +23 -0
  45. package/dist/utils/output.d.ts +66 -0
  46. package/dist/utils/output.js +202 -0
  47. package/dist/utils/sdk-error.d.ts +6 -1
  48. package/dist/utils/sdk-error.js +107 -77
  49. 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 { terminal } from "../../utils/terminal.js";
4
- import { withSDKErrorHandling } from "../../utils/sdk-error.js";
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 async function executeDestroy(options) {
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
- // Load state
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
- }), "Failed to fetch remote monitors");
35
- const remoteMonitors = response?.data?.data;
36
- fetchSpinner.succeed(`Found ${remoteMonitors.length} remote monitor(s)`);
37
- if (remoteMonitors.length === 0) {
38
- terminal.success("No monitors to destroy.");
39
- return;
40
- }
41
- // Filter monitors if --monitor option is provided
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
- terminal.error(`Monitor "${options.monitor}" not found in ${envName} environment`);
47
- terminal.blank();
48
- terminal.dim("Available monitors:");
49
- remoteMonitors.forEach((m) => {
50
- terminal.dim(` - ${m.name} (${m.id})`);
51
- });
52
- terminal.exit(1);
53
- return; // TypeScript doesn't know exit(1) terminates
54
- }
55
- monitorsToDestroy = [targetMonitor];
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
- // Show what will be destroyed
58
- terminal.blank();
59
- terminal.warn(`The following ${monitorsToDestroy.length} monitor(s) will be DESTROYED:`);
60
- terminal.blank();
61
- monitorsToDestroy.forEach((monitor) => {
62
- terminal.log(` ${terminal.colors.red("-")} ${monitor.name} (${monitor.id})`);
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
- terminal.blank();
65
- // Show dry run message if applicable
66
- if (options.dryRun) {
67
- terminal.info("[DRY RUN] No changes will be made");
68
- terminal.blank();
69
- terminal.log("Summary:");
70
- terminal.log(` Would destroy: ${monitorsToDestroy.length} monitor(s)`);
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
- // Ask for confirmation unless auto-approved
74
- if (!options.autoApprove) {
75
- terminal.blank();
76
- terminal.warn(terminal.colors.bold("This action is DESTRUCTIVE and cannot be undone!"));
77
- terminal.blank();
78
- const confirmed = await terminal.confirm("Do you really want to destroy these monitors?");
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
- if (failureCount === 0) {
117
- destroySpinner.succeed("All monitors destroyed successfully");
118
- }
119
- else {
120
- destroySpinner.fail("Some monitors failed to destroy");
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
- // Show summary
123
- terminal.blank();
124
- terminal.log("Destroy complete:");
125
- terminal.blank();
126
- terminal.log(` ${terminal.colors.green("✓")} Destroyed: ${successCount}`);
127
- if (failureCount > 0) {
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
- terminal.exit(1);
116
+ output.error(`Failed to destroy: ${monitor.name} - ${errorMessage}`);
135
117
  }
136
118
  }
137
- catch (error) {
138
- terminal.error(error.message);
139
- terminal.exit(1);
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 function executeIntegrationsConnect(options: IntegrationsConnectOptions): Promise<void>;
51
+ export declare const executeIntegrationsConnect: (options: IntegrationsConnectOptions) => Promise<void>;