Skip to content

Commit 946bc78

Browse files
feat(api): expand commerce catalog and path-based scope handling
1 parent a30c4aa commit 946bc78

24 files changed

+8280
-176
lines changed

scripts/generate-api-catalog.ts

Lines changed: 680 additions & 89 deletions
Large diffs are not rendered by default.

src/cli-entry.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,12 @@ export function runCli(rawArgv: ReadonlyArray<string>): Promise<void> {
492492
const isCliValidation =
493493
errorTag !== undefined && CLI_VALIDATION_TAGS.has(errorTag);
494494

495-
let details: { message: string; code: string; fix: string };
495+
let details: {
496+
message: string;
497+
code: string;
498+
fix: string;
499+
details?: Record<string, unknown>;
500+
};
496501

497502
if (isCliValidation) {
498503
// biome-ignore lint/suspicious/noExplicitAny: @effect/cli ValidationError is a union
@@ -508,14 +513,22 @@ export function runCli(rawArgv: ReadonlyArray<string>): Promise<void> {
508513
if (isStreaming) {
509514
yield* writer.emitStreamError(
510515
cmdStr,
511-
{ message: details.message, code: details.code },
516+
{
517+
message: details.message,
518+
code: details.code,
519+
details: details.details,
520+
},
512521
details.fix,
513522
rootNextActions,
514523
);
515524
} else {
516525
yield* writer.emitError(
517526
cmdStr,
518-
{ message: details.message, code: details.code },
527+
{
528+
message: details.message,
529+
code: details.code,
530+
details: details.details,
531+
},
519532
details.fix,
520533
rootNextActions,
521534
);

src/cli/agent/errors.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import * as HelpDoc from "@effect/cli/HelpDoc";
22
import type { ValidationError as EffectValidationError } from "@effect/cli/ValidationError";
3-
import { type CliError, errorCode } from "../../effect/errors";
3+
import {
4+
type ApiErrorContext,
5+
type CliError,
6+
errorCode,
7+
} from "../../effect/errors";
48

59
export interface AgentErrorDetails {
610
message: string;
711
code: string;
812
fix: string;
13+
details?: Record<string, unknown>;
914
}
1015

1116
const ANSI_ESCAPE_PATTERN = new RegExp(
@@ -28,9 +33,52 @@ function formatValidationMessage(error: EffectValidationError): string {
2833
return "Invalid command input";
2934
}
3035

36+
function apiDetails(error: CliError): Record<string, unknown> | undefined {
37+
const context = error as Partial<ApiErrorContext>;
38+
39+
const details: Record<string, unknown> = {};
40+
if (typeof context.status === "number") {
41+
details.status = context.status;
42+
}
43+
if (typeof context.statusText === "string" && context.statusText.length > 0) {
44+
details.status_text = context.statusText;
45+
}
46+
if (typeof context.endpoint === "string" && context.endpoint.length > 0) {
47+
details.endpoint = context.endpoint;
48+
}
49+
if (typeof context.method === "string" && context.method.length > 0) {
50+
details.method = context.method;
51+
}
52+
if (typeof context.requestId === "string" && context.requestId.length > 0) {
53+
details.request_id = context.requestId;
54+
}
55+
if (context.responseBody !== undefined) {
56+
details.response = context.responseBody;
57+
}
58+
59+
return Object.keys(details).length > 0 ? details : undefined;
60+
}
61+
62+
function fixForNetworkError(
63+
details: Record<string, unknown> | undefined,
64+
): string {
65+
const status = details?.status;
66+
if (typeof status === "number") {
67+
if (status >= 400 && status < 500) {
68+
return "Check request path/query/body. Inspect error.details.response for API validation feedback.";
69+
}
70+
if (status >= 500) {
71+
return "The API is currently failing server-side. Retry, or check service health/incidents.";
72+
}
73+
}
74+
75+
return "Verify environment connectivity with: godaddy env get and retry.";
76+
}
77+
3178
function fromTaggedError(error: CliError): AgentErrorDetails {
3279
const code = errorCode(error);
3380
const message = error.userMessage || error.message;
81+
const details = apiDetails(error);
3482

3583
switch (error._tag) {
3684
case "ValidationError":
@@ -44,6 +92,7 @@ function fromTaggedError(error: CliError): AgentErrorDetails {
4492
message,
4593
code: "AUTH_REQUIRED",
4694
fix: "Run: godaddy auth login",
95+
details,
4796
};
4897
case "ConfigurationError":
4998
return {
@@ -55,7 +104,8 @@ function fromTaggedError(error: CliError): AgentErrorDetails {
55104
return {
56105
message,
57106
code,
58-
fix: "Verify environment connectivity with: godaddy env get and retry.",
107+
fix: fixForNetworkError(details),
108+
details,
59109
};
60110
case "SecurityError":
61111
return {

src/cli/agent/stream.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export interface StreamErrorEvent {
4545
error: {
4646
message: string;
4747
code: string;
48+
details?: Record<string, unknown>;
4849
};
4950
fix: string;
5051
next_actions: NextAction[];

src/cli/agent/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface AgentErrorEnvelope {
2727
error: {
2828
message: string;
2929
code: string;
30+
details?: Record<string, unknown>;
3031
};
3132
fix: string;
3233
next_actions: NextAction[];

0 commit comments

Comments
 (0)