Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 1x 3x 3x 3x 3x 2x 2x 3x 1x 1x | import { NextResponse } from "next/server";
import { edcClient } from "@/lib/edc";
import { requireAuth, isAuthError } from "@/lib/auth-guard";
export const dynamic = "force-dynamic";
/**
* GET /api/credentials/definitions — List available credential definitions.
*
* Queries the IssuerService Admin API for all credential definitions
* registered under the "issuer" participant context. These define which
* Verifiable Credential types can be issued.
*
* @see jad/openapi/issuer-admin-api.yaml — IssuerService Admin API spec
*/
export async function GET() {
const auth = await requireAuth();
Iif (isAuthError(auth)) return auth;
try {
const credDefs = await edcClient.issuer<Record<string, unknown>[]>(
"/v1alpha/participants/issuer/credentialdefinitions/query",
"POST",
{}, // empty QuerySpec → return all
);
const definitions = Array.isArray(credDefs)
? credDefs.map((d) => ({
id: d.id,
credentialType: d.credentialType || d.type,
format: d.format,
attestations: d.attestations,
validity: d.validity,
}))
: [];
return NextResponse.json({ definitions });
} catch (err) {
console.error("Failed to fetch credential definitions:", err);
return NextResponse.json(
{
definitions: [],
error: "Could not reach IssuerService",
detail: err instanceof Error ? err.message : String(err),
},
{ status: 502 },
);
}
}
|