@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,106 +1,136 @@
1
1
  import { terminal } from "./terminal.js";
2
- /**
3
- * Handle SDK errors with user-friendly messaging
4
- */
5
- export function handleSDKError(error, context) {
6
- const sdkError = error;
2
+ function getSDKErrorCodeAndMessage(sdkError, context) {
7
3
  const contextMsg = context ? `${context}: ` : "";
8
- terminal.blank();
9
- // Handle network/connection errors
10
4
  if (sdkError.message?.includes("ECONNREFUSED")) {
11
- terminal.error(`${contextMsg}Unable to connect to Griffin Hub`);
12
- terminal.dim("Make sure the hub is running and the URL is correct.");
13
- return terminal.exit(1);
5
+ return {
6
+ code: "CONNECTION_REFUSED",
7
+ message: `${contextMsg}Unable to connect to Griffin Hub`,
8
+ hint: "Make sure the hub is running and the URL is correct.",
9
+ };
14
10
  }
15
11
  if (sdkError.message?.includes("ENOTFOUND")) {
16
- terminal.error(`${contextMsg}Hub host not found`);
17
- terminal.dim("Check your hub URL configuration.");
18
- return terminal.exit(1);
12
+ return {
13
+ code: "HOST_NOT_FOUND",
14
+ message: `${contextMsg}Hub host not found`,
15
+ hint: "Check your hub URL configuration.",
16
+ };
19
17
  }
20
18
  if (sdkError.message?.includes("ETIMEDOUT")) {
21
- terminal.error(`${contextMsg}Connection to hub timed out`);
22
- terminal.dim("The hub may be unresponsive or the network is slow.");
23
- return terminal.exit(1);
19
+ return {
20
+ code: "TIMEOUT",
21
+ message: `${contextMsg}Connection to hub timed out`,
22
+ hint: "The hub may be unresponsive or the network is slow.",
23
+ };
24
24
  }
25
- // Handle HTTP status codes
26
25
  if (sdkError.status) {
27
26
  switch (sdkError.status) {
28
27
  case 401:
29
- terminal.error(`${contextMsg}Authentication failed`);
30
- terminal.dim("Your API token may be invalid or expired.");
31
- terminal.dim("Run 'griffin auth login' to authenticate again.");
32
- return terminal.exit(1);
28
+ return {
29
+ code: "AUTH_FAILED",
30
+ message: `${contextMsg}Authentication failed`,
31
+ hint: "Your API token may be invalid or expired. Run 'griffin auth login' to authenticate again.",
32
+ };
33
33
  case 403:
34
- terminal.error(`${contextMsg}Access denied`);
35
- terminal.dim("You don't have permission to perform this action.");
36
- return terminal.exit(1);
34
+ return {
35
+ code: "ACCESS_DENIED",
36
+ message: `${contextMsg}Access denied`,
37
+ hint: "You don't have permission to perform this action.",
38
+ };
37
39
  case 404:
38
- terminal.error(`${contextMsg}Resource not found`);
39
- if (sdkError.url) {
40
- terminal.dim(`URL: ${sdkError.url}`);
41
- }
42
- terminal.dim("The requested resource may not exist on the hub.");
43
- return terminal.exit(1);
40
+ return {
41
+ code: "NOT_FOUND",
42
+ message: `${contextMsg}Resource not found`,
43
+ details: sdkError.url ? { url: sdkError.url } : undefined,
44
+ hint: "The requested resource may not exist on the hub.",
45
+ };
44
46
  case 409:
45
- terminal.error(`${contextMsg}Conflict`);
46
- if (sdkError.body?.message) {
47
- terminal.dim(sdkError.body.message);
48
- }
49
- else {
50
- terminal.dim("The operation conflicts with the current state.");
51
- }
52
- return terminal.exit(1);
47
+ return {
48
+ code: "CONFLICT",
49
+ message: `${contextMsg}Conflict`,
50
+ details: sdkError.body?.message ? { message: sdkError.body.message } : undefined,
51
+ hint: "The operation conflicts with the current state.",
52
+ };
53
53
  case 422:
54
- terminal.error(`${contextMsg}Validation error`);
55
- if (sdkError.body?.message) {
56
- terminal.dim(sdkError.body.message);
57
- }
58
- else if (sdkError.body?.errors) {
59
- terminal.dim("Validation failed:");
60
- for (const err of sdkError.body.errors) {
61
- terminal.dim(` - ${err.message || err}`);
62
- }
63
- }
64
- else {
65
- terminal.dim("The request data is invalid.");
66
- }
67
- return terminal.exit(1);
54
+ return {
55
+ code: "VALIDATION_ERROR",
56
+ message: `${contextMsg}Validation error`,
57
+ details: sdkError.body?.message
58
+ ? { message: sdkError.body.message }
59
+ : sdkError.body?.errors
60
+ ? { errors: sdkError.body.errors }
61
+ : undefined,
62
+ hint: "The request data is invalid.",
63
+ };
68
64
  case 429:
69
- terminal.error(`${contextMsg}Rate limit exceeded`);
70
- terminal.dim("Too many requests. Please wait and try again.");
71
- return terminal.exit(1);
65
+ return {
66
+ code: "RATE_LIMITED",
67
+ message: `${contextMsg}Rate limit exceeded`,
68
+ hint: "Too many requests. Please wait and try again.",
69
+ };
72
70
  case 500:
73
71
  case 502:
74
72
  case 503:
75
73
  case 504:
76
- terminal.error(`${contextMsg}Hub server error`);
77
- terminal.dim(`Status: ${sdkError.status} ${sdkError.statusText || ""}`);
78
- if (sdkError.body?.message) {
79
- terminal.dim(sdkError.body.message);
80
- }
81
- else {
82
- terminal.dim("The hub encountered an internal error.");
83
- }
84
- return terminal.exit(1);
74
+ return {
75
+ code: "SERVER_ERROR",
76
+ message: `${contextMsg}Hub server error`,
77
+ details: {
78
+ status: sdkError.status,
79
+ statusText: sdkError.statusText,
80
+ ...(sdkError.body?.message && { bodyMessage: sdkError.body.message }),
81
+ },
82
+ hint: "The hub encountered an internal error.",
83
+ };
85
84
  default:
86
- terminal.error(`${contextMsg}Request failed`);
87
- terminal.dim(`Status: ${sdkError.status} ${sdkError.statusText || ""}`);
88
- if (sdkError.body?.message) {
89
- terminal.dim(sdkError.body.message);
90
- }
91
- else if (sdkError.message) {
92
- terminal.dim(sdkError.message);
93
- }
94
- return terminal.exit(1);
85
+ return {
86
+ code: "UNKNOWN_ERROR",
87
+ message: `${contextMsg}Request failed`,
88
+ details: {
89
+ status: sdkError.status,
90
+ statusText: sdkError.statusText,
91
+ ...(sdkError.body?.message && { bodyMessage: sdkError.body.message }),
92
+ ...(sdkError.message && { message: sdkError.message }),
93
+ },
94
+ };
95
95
  }
96
96
  }
97
- // Fallback for unknown errors
98
- terminal.error(`${contextMsg}${sdkError.message || "An unexpected error occurred"}`);
99
- if (sdkError.stack) {
100
- terminal.dim("Run with DEBUG=* for more details.");
97
+ return {
98
+ code: "UNKNOWN_ERROR",
99
+ message: `${contextMsg}${sdkError.message || "An unexpected error occurred"}`,
100
+ hint: sdkError.stack ? "Run with DEBUG=* for more details." : undefined,
101
+ };
102
+ }
103
+ /**
104
+ * Handle SDK errors with user-friendly messaging (terminal output)
105
+ */
106
+ export function handleSDKError(error, context) {
107
+ const sdkError = error;
108
+ const { message, details, hint } = getSDKErrorCodeAndMessage(sdkError, context);
109
+ terminal.blank();
110
+ terminal.error(message);
111
+ if (hint)
112
+ terminal.dim(hint);
113
+ if (details !== undefined && details !== null) {
114
+ if (typeof details === "object" && "message" in details) {
115
+ terminal.dim(String(details.message));
116
+ }
117
+ else if (typeof details === "object" && "errors" in details) {
118
+ terminal.dim("Validation failed:");
119
+ for (const err of details.errors) {
120
+ terminal.dim(` - ${err.message || err}`);
121
+ }
122
+ }
101
123
  }
102
124
  return terminal.exit(1);
103
125
  }
126
+ /**
127
+ * Handle SDK errors using OutputContext (JSON or human output)
128
+ */
129
+ export function handleSDKErrorWithOutput(error, output, context) {
130
+ const sdkError = error;
131
+ const { code, message, details, hint } = getSDKErrorCodeAndMessage(sdkError, context);
132
+ output.flushError(code, message, details, hint);
133
+ }
104
134
  /**
105
135
  * Wrap an SDK call with error handling
106
136
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@griffin-app/griffin-cli",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "CLI tool for running and managing griffin API tests",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -26,7 +26,7 @@
26
26
  "dependencies": {
27
27
  "@griffin-app/griffin-hub-sdk": "1.0.25",
28
28
  "@griffin-app/griffin-executor": "0.1.1",
29
- "@griffin-app/griffin-core": "0.2.0",
29
+ "@griffin-app/griffin-core": "0.2.2",
30
30
  "better-auth": "^1.4.17",
31
31
  "cli-table3": "^0.6.5",
32
32
  "commander": "^12.1.0",