import Link from 'next/link'; import { createHighlighter } from 'shiki'; import { getApiGroups, getGrantIndex, getOperationCount, getSdkLanguages, getSecurityScheme, } from '@/lib/api-reference'; import { MethodBadge, methodStyle } from './method-badge'; import { Tabs } from './tabs'; /** * Overview surfaces for the API reference. Every list here is derived * from the committed OpenAPI document — resource groups from * `x-docs-groups`, credential names from the security schemes, and the * capability tables by inverting each operation's `x-required-*`. A new * operation or group in the contract shows up here with no edit. */ const CARD = 'border-cp-border overflow-hidden rounded-[14px] border bg-white'; const installHighlighter = createHighlighter({ themes: ['material-theme-palenight'], langs: ['sh', 'groovy'], }); /** * Install commands per SDK, sharing the reference's language switcher — * so choosing a language here also settles every operation page's * examples, and arriving from the docs landing lands on your language. */ export async function ApiInstall() { const languages = getSdkLanguages(); const highlighter = await installHighlighter; const blocks = languages.map((language) => ({ ...language, html: highlighter.codeToHtml(language.install, { lang: language.installFence, theme: 'material-theme-palenight', }), })); return ( block.label)} storageKey="cloudpdf-sdk-language"> {blocks.map((block) => (
))} ); } /** The reference's resource groups, each listing the operations it holds. */ export function ApiResources() { const groups = getApiGroups().filter((group) => group.operations.length > 0); return (
{groups.map((group) => (
{group.title} {group.operations.length} {group.operations.length === 1 ? 'operation' : 'operations'} {group.operatorOnly ? ( Self-hosted ) : null}
{group.operations.map((operation) => ( {operation.title} ))}
))}
); } export function ApiOperationCount() { return <>{getOperationCount()}; } const CREDENTIAL_ORDER = ['apiToken', 'tenantToken', 'docToken', 'uploadToken'] as const; const CREDENTIAL_HOLDER: Record = { apiToken: 'Your server environment', tenantToken: 'Your backend', docToken: "The end user's browser", uploadToken: "The end user's browser, to upload", }; /** * The credentials as a ladder. Authority mints only downward, and * each rung's blast radius shrinks as it moves closer to the browser — * the one idea that makes every per-operation auth rule obvious. */ export function ApiCredentials() { return (
{CREDENTIAL_ORDER.map((name, index) => { const scheme = getSecurityScheme(name); if (!scheme) return null; return (
{index + 1}
{scheme['x-docs-title'] ?? name} {CREDENTIAL_HOLDER[name]}

{scheme.description}

); })}
); } /** * Inverts the per-operation grants: one row per capability (or tenant * scope) listing what it unlocks, so choosing the scopes for a token is * one lookup instead of twenty operation pages. */ export function ApiGrants({ kind }: { kind: 'capability' | 'scope' }) { const grants = getGrantIndex( kind === 'capability' ? 'x-required-capability' : 'x-required-scope', ).filter((entry) => entry.grant !== ''); return (
{grants.map(({ grant, operations }) => (
{grant}
{operations.map((operation) => ( {operation.title} ))}
))}
); }