import { type CallAction, type OcppRequest, type OcppResponse, type OCPPVersionType, type RawCall, type RawCallError, type RawCallResult, ErrorCode, MessageTypeId } from '@citrineos/types'; /** * MessageId used when the one on the frame cannot be read (OCPP 2.0.1 part 4, * section 4.2.3: the CALLERROR SHALL then contain "-1" as MessageId). */ export declare const UNREADABLE_MESSAGE_ID = "-1"; /** * Reads the messageId off a frame that has not been validated yet, falling back * to {@link UNREADABLE_MESSAGE_ID} when it is absent or not a string. */ export declare function readMessageId(raw: unknown): string; /** * A CALL message (4.2.1) with named fields. * * Construct from a parsed frame to validate its structure and read it by field * name, or from the fields themselves to build an outbound CALL: * * ```ts * const call = new Call(JSON.parse(rawMessage) as RawCall); // inbound, validates * const call = new Call(correlationId, action, payload); // outbound, trusted * ``` * * The frame form is untrusted and throws on anything malformed. The field form is * type-checked at the call site and never throws, so building an error reply * cannot itself fail. * * `JSON.stringify` yields the wire form again, so a model object can be handed * straight to the socket. */ export declare class Call { readonly messageTypeId: MessageTypeId.Call; readonly messageId: string; readonly action: CallAction; readonly payload: OcppRequest; /** * @param raw - A parsed CALL frame, not yet known to be well-formed. * @throws {OcppError} ProtocolError if the frame is not a structurally valid CALL. * @throws {Error} if the frame is not a CALL at all, which is a caller bug. */ constructor(raw: RawCall); constructor(messageId: string, action: CallAction, payload: OcppRequest); toJSON(): RawCall; } /** * A CALLRESULT message (4.2.2) with named fields. See {@link Call}. */ export declare class CallResult { readonly messageTypeId: MessageTypeId.CallResult; readonly messageId: string; readonly payload: OcppResponse; /** * @param raw - A parsed CALLRESULT frame, not yet known to be well-formed. * @throws {OcppError} ProtocolError if the frame is not a structurally valid CALLRESULT. * @throws {Error} if the frame is not a CALLRESULT at all, which is a caller bug. */ constructor(raw: RawCallResult); constructor(messageId: string, payload: OcppResponse); toJSON(): RawCallResult; } /** * A CALLERROR message (4.2.3) with named fields. See {@link Call}. */ export declare class CallError { readonly messageTypeId: MessageTypeId.CallError; readonly messageId: string; readonly errorCode: ErrorCode; readonly errorDescription: string; readonly errorDetails: object; /** * @param raw - A parsed CALLERROR frame, not yet known to be well-formed. * @throws {OcppError} ProtocolError if the frame is not a structurally valid CALLERROR. * @throws {Error} if the frame is not a CALLERROR at all, which is a caller bug. */ constructor(raw: RawCallError); constructor(messageId: string, errorCode: ErrorCode, errorDescription: string, errorDetails?: object); /** * The error as an {@link OcppError}, for routing to the module that issued the * original Call. */ asOcppError(): OcppError; toJSON(): RawCallError; } /** * Any OCPP RPC frame as a model object. Discriminate on `messageTypeId`. */ export type RpcMessage = Call | CallResult | CallError; /** * Custom error to handle OCPP errors better. */ export declare class OcppError extends Error { private _messageId; private _errorCode; private _errorDetails; get message(): string; get messageId(): string; get errorCode(): ErrorCode; get errorDetails(): object; constructor(messageId: string, errorCode: ErrorCode, errorDescription: string, errorDetails?: object); asCallError(): CallError; } /** * Maps a string to the corresponding OCPP CallAction enum value based on protocol version * @param version OCPP protocol version * @param action String representation of the action * @returns The corresponding enum value * @throws Error if the action is invalid for the specified version */ export declare function mapToCallAction(version: OCPPVersionType, action: string): CallAction;