Handles and unwraps responses from Cloudflare API
// Source: https://github.com/corsairdev/corsair | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import { CloudflareAPIError } from './api-error';
export type CloudflareApiResponse<T> = {
result: T;
success: boolean;
errors: Array<{ code: number; message: string }>;
// Cloudflare may include diagnostic messages; shape varies by endpoint.
messages: unknown[];
};
/** Runtime check for Cloudflare's `{ success, result, errors }` JSON envelope. */
export function isCloudflareEnvelope(
response: unknown,
): response is CloudflareApiResponse<unknown> {
return (
response !== null &&
typeof response === 'object' &&
'success' in response &&
'result' in response
);
}
funct
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key