import { GraphQLError } from 'graphql'; import type { MiddlewareFn } from 'type-graphql'; /** * **A refusal the server knows and names** (ADR-0054). * * ── Why a gate does not throw a sentence ────────────────────────────────── * A gate that throws an English sentence puts English on a Korean screen. A screen that translates * it is then writing the reason itself, and the gate and the screen end up with two accounts of the * same refusal. So the gate throws a name and values, and the sentence is made where the request's * language is known. * * ── What gets stored is the name ────────────────────────────────────────── * Never write the sentence onto an event or a work row. A sentence differs per reader and the wording * changes later; a stored one freezes that day's language. The `code` is the contract, and it travels * unchanged to the client (ADR-0042 - no mapping table on the way out). * * ── Two traps ───────────────────────────────────────────────────────────── * ① `t(key, undefined)` loses the locale and answers in English, so `params` is always passed - the * spread below makes an object even when a refusal carries none. * ② Never pass a **value** to `t` as a key: `:` reads as a namespace separator and cuts `urn:epc:…` * apart. Values travel in `params` only. * * ── Why it lives in the shell ───────────────────────────────────────────── * operato-plant wrote this first and operato-warehouse copied it; worklist is the third consumer as * the work-door screens move there (ADR-0069 decision 3). Everything it needs is `graphql`, * `type-graphql` and the request's `t`, all of which sit at or below the shell, so this is the floor * that every consumer already stands on. The translations stay with each module: `refusalKey` names * `error.` inside the caller's own namespace, and a module that does not declare the key falls * back to the English sentence rather than printing the key. */ export declare class Refusal extends Error { readonly code: string; readonly params: RefusalParams; /** * @param code this refusal's name (kebab). It states **the gate's fact**; a screen does not pick its * own sentence from this name. * @param params the values the sentence is built from. * @param english the sentence used when the translation key is missing. An English sentence reads * better than the key printed raw. */ constructor(code: string, params: RefusalParams, english: string); } /** Values a refusal sentence is built from. Scalars only: they travel in the GraphQL response as they are. */ export type RefusalParams = Record; export declare function refusalKey(code: string): string; type Translate = (key: string, options?: Record) => string; /** * **The one place a refusal becomes a sentence.** The resolver wrapper and the worklist callbacks both * call this, so the two exits cannot drift apart. * * Apollo's own `extensions.code` gets `BAD_USER_INPUT`: a refusal is not a server error, and left empty * Apollo would fill in `INTERNAL_SERVER_ERROR`. The name rides separately in `extensions.refusal`; its * presence is what tells a client the server refused on purpose. */ export declare function speakRefusal(refusal: Refusal, context: { t?: Translate; }): GraphQLError; /** Rethrow a refusal as a sentence in the caller's language; anything else passes through untouched. */ export declare function rethrowSpoken(error: unknown, context: { t?: Translate; }): never; /** A resolver class passes through this (`@UseMiddleware(SpeakRefusals)`). */ export declare const SpeakRefusals: MiddlewareFn; /** * An activity callback runs inside a worklist mutation, not the module's own resolver, so * `SpeakRefusals` never sees what it throws. Declarations wrap their callback in this: the same * `speakRefusal`, the other exit. */ export declare function speaksRefusals(callback: (instance: any, addendum: any, context: any) => Promise): (instance: any, addendum: any, context: any) => Promise; export {};