Files
WRNexusJS/examples/inter-app-api-showcase/app/api/product-summary.ts
T
ClintchizandClaude Opus 5 790b81330a
Quality / quality (ubuntu-latest) (push) Failing after 11m9s
Quality / quality (windows-latest) (push) Canceled after 0s
fix: repair main after an unreviewed commit, and record the cause
Three separate problems, all traceable to `git add -A` sweeping up a working
tree I had not inspected.

Commit 69020b25 ("docs: make the component sections executable") committed far
more than docs: 79 files of a half-scaffolded inter-app example, and four of
those files were truncated mid-statement. That broke `bun run typecheck` on
main. The example is reverted to its last green six-file form. The truncated
fragments and the fuller working copy are NOT in this commit -- if any of that
workspace was wanted, it needs to be reconstructed deliberately and committed on
its own, not as a side effect of a docs change.

Separately, `scripts/generate-ui-complete-catalog.mjs` was run while checking
which helper scripts still work. It rewrites components in place, so it
flattened six of them to stubs, deleted 24 more and lower-cased four filenames
before crashing. Contents were restored from HEAD, but the renames survived
that restore: Windows is case-insensitive, so `git status` reported clean while
Card, Container, Divider and Grid sat on disk under the wrong names. The index
now tracks the capitalised names, which is what the components declare and what
ui-redesign-contract.test.ts reads -- that test would have failed on any
case-sensitive checkout.

Documented both as 4.7 and 4.8 in the remediation plan, with the general rule:
no script that rewrites packages/ui/components/ may write in place. Also fixes
the heading level on 4.6, which was rendering outside section 4.

bun run check is green: 1,433 pass, 0 fail.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-09 11:11:57 +05:30

61 lines
2.3 KiB
TypeScript

import type { Context } from "@wrnexus/core";
import { httpTransport, serviceClient } from "@wrnexus/rpc";
import { auditService, catalogService } from "../lib/contracts.ts";
interface GitHubRepository {
full_name?: unknown;
stargazers_count?: unknown;
}
function requestedSku(ctx: Context): string {
return new URL(ctx.req.url).searchParams.get("sku")?.trim() || "starter";
}
/** GET /api/product-summary?sku=starter */
export async function GET(ctx: Context): Promise<Response> {
const sku = requestedSku(ctx);
const transport = httpTransport();
// Inter-app call #1: query the catalog app. `{ as: ctx }` forwards the
// signed subject/tenant context; catalog still authorizes independently.
const catalog = serviceClient(catalogService, { app: "catalog", as: ctx, transport });
const product = await catalog.getProduct({ sku });
// External API call: GitHub's public repository endpoint. Do not send the
// user's RPC identity token or internal headers to external services.
let githubResponse: Response;
try {
githubResponse = await fetch("https://api.github.com/repos/octocat/Hello-World", {
headers: { accept: "application/vnd.github+json", "user-agent": "wrnexus-example" },
signal: ctx.req.signal,
});
} catch {
return Response.json({ error: "External repository lookup failed." }, { status: 502 });
}
if (!githubResponse.ok) {
return Response.json({ error: "External repository lookup failed." }, { status: 502 });
}
const github = (await githubResponse.json()) as GitHubRepository;
if (typeof github.full_name !== "string" || typeof github.stargazers_count !== "number") {
return Response.json(
{ error: "External repository returned an unexpected response." },
{ status: 502 },
);
}
// Inter-app call #2: record the completed lookup in the audit app. This is
// intentionally awaited: callers learn whether the audit record was saved.
const audit = serviceClient(auditService, { app: "audit", as: ctx, transport });
const receipt = await audit.recordLookup({
sku: product.sku,
repository: github.full_name,
stars: github.stargazers_count,
});
return Response.json({
product,
external: { repository: github.full_name, stars: github.stargazers_count },
audit: receipt,
});
}