import type { Context, ErrorHandler, MiddlewareHandler } from 'hono'; /** * One entry of an error's `errors` array. Production's items carry a `code` and `message` and, * for some codes, further detail (`minimum_length`, `warning`, `suggestions`, …), which is * rendered as given. */ export interface ApiErrorItem { field?: string; code: string; message?: string; [detail: string]: unknown; } export declare class WorkOSApiError extends Error { status: number; code: string; errors?: ApiErrorItem[] | undefined; /** * Body fields beyond `message`, `code` and `errors`, spread into the rendered body: production's * `ConnectionAlreadyExistsForOrganizationException` carries the `organization_id`, for one, * and a few of its entity-not-found sites an `entity_type`. */ extra?: Record | undefined; constructor(status: number, message: string, code: string, errors?: ApiErrorItem[] | undefined, /** * Body fields beyond `message`, `code` and `errors`, spread into the rendered body: production's * `ConnectionAlreadyExistsForOrganizationException` carries the `organization_id`, for one, * and a few of its entity-not-found sites an `entity_type`. */ extra?: Record | undefined); } /** * A failure of an RFC 6749 grant, rendered OAuth-style as `{error, error_description}` — * production only uses this shape for the standard grants; the `urn:workos:` grants keep * the plain `{code, message}` shape. Reuses `code`/`message` storage so event payloads * (which always carry `{code, message}`) need no special casing. */ export declare class OauthApiError extends WorkOSApiError { /** Response headers the failure carries, e.g. the `WWW-Authenticate` a 401 invalid_client needs (RFC 6749 §5.2). */ readonly headers?: Record; /** * `description` is optional because production's OAuth2 exception renders `error_description` * only when one was given: its code and refresh-token failures are the bare `{ error }`. */ constructor(status: number, error: string, description?: string, headers?: Record); } /** * A lookup that found nothing, rendered as production's `EntityNotFoundException` * (api-services `common/exceptions/entity-not-found/entity-not-found-exception.ts`): * `{message: " not found: ''.", code: 'entity_not_found', entity_id: ''}`. * * Production always has an id to name, so `entityId` is optional only for the handful of sites * that resolved by something the response cannot quote; those render no `entity_id` rather than * an invented one. `message` and `extra` exist for the few production sites that depart from the * template (an agent session's wording, an `entity_type` field) and are otherwise left alone. */ export declare class EntityNotFoundError extends WorkOSApiError { readonly entityType: string; readonly entityId?: string | undefined; constructor(entityType: string, entityId?: string | undefined, opts?: { message?: string; extra?: Record; }); } /** * A 404 production raises as a bare Nest `NotFoundException` rather than an entity one. Nest * renders `{message}` — plus `error: 'Not Found'` when the message was passed as a string — and * no `code` at all (`HttpException.createBody`; the API's `CustomExceptionFilter` only strips * `statusCode`). The `code` stored here is bookkeeping for `instanceof WorkOSApiError` callers; * it is never rendered. */ export declare class NestNotFoundError extends WorkOSApiError { readonly error?: 'Not Found' | undefined; constructor(message?: string, error?: 'Not Found' | undefined); } /** * The same code-less Nest rendering as `NestNotFoundError`, for the other statuses. Nest raises * these two ways: an exception built from a plain string (`new UnprocessableEntityException('…')`), * whose body is `{ message, error: 'Unprocessable Entity' }`, and one built from a code-less * object, like the validation pipe's `{ message: 'Validation failed', errors }`. `code` is still * kept in-process — error hooks and event payloads read `{ code, message }` — but is not rendered. */ export declare class PlainApiError extends WorkOSApiError { /** Nest's status text, rendered as `error` when production raised the exception from a string. */ readonly error?: string; constructor(status: number, message: string, code: string, opts?: { error?: string; errors?: WorkOSApiError['errors']; }); } export declare function createApiErrorHandler(): ErrorHandler; export declare function requestIdMiddleware(): MiddlewareHandler; /** * `entityType` is the name production's exception class passes (`'Organization'`, `'API Key'`, * `'UserOrganizationMembership'`, …) and `entityId` whatever the route looked up by: an id, a * slug, a token, an email. Pass the id whenever the lookup had one. */ export declare function notFound(entityType: string, entityId?: string): EntityNotFoundError; export declare function validationError(message: string, errors?: WorkOSApiError['errors']): WorkOSApiError; /** Production's `BadRequestException('')`: 400 `{ message, error: 'Bad Request' }`, no `code`. */ export declare function badRequest(message: string): PlainApiError; /** Production's `UnprocessableEntityException('')`: 422 `{ message, error: 'Unprocessable Entity' }`, no `code`. */ export declare function unprocessableEntity(message: string): PlainApiError; /** * Production's validation pipe: 422 `{ message: 'Validation failed', errors: [{ field, code }] }` * with no top-level `code`; each entry's `code` is the failed constraint's message. */ export declare function validationFailed(errors: Array<{ field: string; code: string; }>): PlainApiError; export declare function unauthorized(): WorkOSApiError; export declare function forbidden(): WorkOSApiError; export declare function parseJsonBody(c: Context): Promise>; export declare function parseOAuthBody(c: Context): Promise>;