@eleva-io/erp-sdk
Version:
SDK oficial para el ERP de Eleva
67 lines • 3.88 kB
TypeScript
import { ElevaError, ElevaErrorArgs, ElevaErrorJSON } from './errors';
import { ErrorCode } from './catalog';
/**
* Context about the outgoing call that triggered a remote error. All fields are optional.
* `M` types the transport-level `metadata` (e.g. `Record<string, string>` for HTTP headers).
*/
export type RemoteRequest<M extends Record<string, unknown> = Record<string, unknown>> = {
/** Operation type or name (e.g. HTTP method, gRPC method, message type). */
operation?: string;
/** Target resource identifier (e.g. URL path, topic name, procedure). */
resource?: string;
/** Transport-level metadata sent with the call (e.g. HTTP headers, gRPC metadata). */
metadata?: M;
/** Data sent with the call (request body, message payload, etc.). */
payload?: unknown;
};
/**
* Context about the response received from a remote call. All fields are optional.
* `M` types the transport-level `metadata` (e.g. `Record<string, string>` for HTTP headers).
*/
export type RemoteResponse<M extends Record<string, unknown> = Record<string, unknown>> = {
/** Status code returned by the remote system (e.g. HTTP status, gRPC status). */
statusCode?: number;
/** Transport-level metadata received with the response (e.g. HTTP response headers). */
metadata?: M;
/** Data received from the remote system. */
payload?: unknown;
};
/** `ElevaErrorJSON` extended with the originating remote call context. */
export type RemoteElevaErrorJSON<C extends ErrorCode = ErrorCode, ReqM extends Record<string, unknown> = Record<string, unknown>, ResM extends Record<string, unknown> = Record<string, unknown>> = ElevaErrorJSON<C> & {
request: RemoteRequest<ReqM>;
response: RemoteResponse<ResM>;
};
/**
* An `ElevaError` enriched with the context of a failed remote call.
* Not tied to HTTP — covers any outbound call (HTTP, gRPC, message queues, etc.)
* where capturing the outgoing request and incoming response aids debugging.
*
* `ReqM` / `ResM` type the transport metadata for the request and response respectively;
* both default to `Record<string, unknown>` for untyped usage.
*
* @example
* type HttpHeaders = Record<string, string>
* const err = RemoteElevaError.from<ErrorCode, HttpHeaders, HttpHeaders>(body, req, res)
* err.request.metadata?.['authorization'] // string
*/
export declare class RemoteElevaError<C extends ErrorCode = ErrorCode, ReqM extends Record<string, unknown> = Record<string, unknown>, ResM extends Record<string, unknown> = Record<string, unknown>> extends ElevaError<C> {
/** Context about the outgoing call that produced this error. */
readonly request: RemoteRequest<ReqM>;
/** Context about the response that contained or triggered the error. */
readonly response: RemoteResponse<ResM>;
constructor(args: ElevaErrorArgs<C> & {
request: RemoteRequest<ReqM>;
response: RemoteResponse<ResM>;
});
/** Full serialisation including remote call request and response context. */
toJSON(): RemoteElevaErrorJSON<C, ReqM, ResM>;
/** Narrows to `RemoteElevaError<K, ReqM, ResM>`, preserving metadata types on the narrowed type. */
is<K extends ErrorCode>(code: K | string): this is RemoteElevaError<K, ReqM, ResM>;
/**
* Builds a `RemoteElevaError` from a raw response payload and remote call context.
* Delegates payload parsing to `ElevaError._parsePayload()`; malformed payloads become `INTERNAL_SERVER_ERROR`.
* `cause` takes precedence over any cause inferred from the payload.
*/
static from<ReqM extends Record<string, unknown> = Record<string, unknown>, ResM extends Record<string, unknown> = Record<string, unknown>>(body: unknown, request: RemoteRequest<ReqM>, response: RemoteResponse<ResM>, cause?: unknown): RemoteElevaError<ErrorCode, ReqM, ResM>;
}
//# sourceMappingURL=errors_remote.d.ts.map