/** * WebSocket-layer defaults + protocol constants. * * Pattern (per FE coding rules §1.5): * `export const X = { FOO: 'foo', BAR: 'bar' } as const;` * `export type XKey = (typeof X)[keyof typeof X];` * * See `eaera-docs/cbs/eaera-cms/docs/eaera-cms-websocket-integration-guide.md` * for the wire protocol this client implements. */ /** * Re-export the MT5 domain constants so WS consumers can grab the server * name + interval enum from the same place they import the topic builders. */ export { MT5_INTERVAL, MT5_SERVER_NAME } from '../../common/constants/mt5.constant'; export type { MT5Interval, MT5ServerName } from '../../common/constants/mt5.constant'; /** Lifecycle states surfaced by `IWsClient.connectionState`. */ export declare const WS_CONNECTION_STATE: { readonly IDLE: "idle"; readonly OPENING: "opening"; readonly AUTHENTICATING: "authenticating"; readonly OPEN: "open"; readonly RECONNECTING: "reconnecting"; readonly CLOSED: "closed"; }; export type WsConnectionState = (typeof WS_CONNECTION_STATE)[keyof typeof WS_CONNECTION_STATE]; /** * WebSocket close codes. `NORMAL` is the only one the client sends; the * rest mirror what the CMS server uses (see FEAT-010 guide §3). */ export declare const WS_CLOSE_CODE: { /** RFC 6455 — clean shutdown (e.g. user logout). */ readonly NORMAL: 1000; /** RFC 6455 — `invalid_token` / `token_expired` / `auth_timeout`. */ readonly POLICY_VIOLATION: 1008; /** RFC 6455 — `service_unavailable` (token service not configured). */ readonly INTERNAL_ERROR: 1011; /** RFC 6455 — graceful server shutdown. */ readonly TRY_AGAIN_LATER: 1013; /** * Non-standard — client-side deadline: server did not reply to `auth` * within `WS_AUTH_TIMEOUT_MS`. Closes the socket so the consumer can * react. */ readonly CLIENT_AUTH_TIMEOUT: 4000; }; export type WsCloseCode = (typeof WS_CLOSE_CODE)[keyof typeof WS_CLOSE_CODE]; /** Server-emitted error codes during the `auth` handshake / mid-session (ws-guide §3.4). */ export declare const WS_AUTH_ERROR_CODE: { readonly INVALID_TOKEN: "invalid_token"; readonly TOKEN_EXPIRED: "token_expired"; readonly AUTH_TIMEOUT: "auth_timeout"; readonly INVALID_MESSAGE: "invalid_message"; readonly SERVICE_UNAVAILABLE: "service_unavailable"; }; export type WsAuthErrorCode = (typeof WS_AUTH_ERROR_CODE)[keyof typeof WS_AUTH_ERROR_CODE]; /** * Close-frame reason strings (ws-guide §4.1). These accompany the RFC 6455 * close codes in `WS_CLOSE_CODE` — they are NOT auth error codes. Surfaced so * consumers can match `CloseEvent.reason` against stable strings. */ export declare const WS_CLOSE_REASON: { readonly NORMAL: "normal"; readonly INVALID_TOKEN: "invalid_token"; readonly TOKEN_EXPIRED: "token_expired"; readonly AUTH_TIMEOUT: "auth_timeout"; readonly PING_TIMEOUT: "ping_timeout"; readonly AUTH_REQUIRED: "auth required"; readonly AUTH_SERVICE_UNAVAILABLE: "auth service unavailable"; readonly SERVER_SHUTTING_DOWN: "server shutting down"; }; export type WsCloseReason = (typeof WS_CLOSE_REASON)[keyof typeof WS_CLOSE_REASON]; /** Server-emitted error codes on the action invocation path (FEAT-008). */ /** Accepted-stage error codes — returned on `action_accepted` (ws-guide §9.3). */ export declare const WS_ACTION_ACCEPTED_ERROR_CODE: { readonly VALIDATION_ERROR: "validation_error"; readonly NOT_FOUND: "not_found"; readonly PERMISSION_DENIED: "permission_denied"; readonly DUPLICATE: "duplicate"; readonly INTERNAL_ERROR: "internal_error"; readonly CONFIGURATION_ERROR: "configuration_error"; }; export type WsActionAcceptedErrorCode = (typeof WS_ACTION_ACCEPTED_ERROR_CODE)[keyof typeof WS_ACTION_ACCEPTED_ERROR_CODE]; /** Result-stage error codes — returned on `action_result` (ws-guide §9.4). */ export declare const WS_ACTION_RESULT_ERROR_CODE: { readonly TIMEOUT: "timeout"; }; export type WsActionResultErrorCode = (typeof WS_ACTION_RESULT_ERROR_CODE)[keyof typeof WS_ACTION_RESULT_ERROR_CODE]; /** * All action error codes — union of the accepted-stage and result-stage maps * (ws-guide §9.3 + §9.4). Kept for back-compat with consumers that do not yet * distinguish the stage; prefer the stage-specific maps above for new code. */ export declare const WS_ACTION_ERROR_CODE: { readonly TIMEOUT: "timeout"; readonly VALIDATION_ERROR: "validation_error"; readonly NOT_FOUND: "not_found"; readonly PERMISSION_DENIED: "permission_denied"; readonly DUPLICATE: "duplicate"; readonly INTERNAL_ERROR: "internal_error"; readonly CONFIGURATION_ERROR: "configuration_error"; }; export type WsActionErrorCode = (typeof WS_ACTION_ERROR_CODE)[keyof typeof WS_ACTION_ERROR_CODE]; /** * Wire `type` field for every server→client and client→server message. * * TypeScript discriminated unions require the `type` field to be a string * literal (not a const reference) on each interface — so these constants are * used for **runtime comparisons** (`switch (msg.type)`) and the interfaces * in `ws.type.ts` keep their literal `type: '…'` annotations for narrowing. */ export declare const WS_MESSAGE_TYPE: { readonly AUTH_OK: "auth_ok"; readonly AUTH_FAIL: "auth_fail"; readonly AUTH_EXPIRED: "auth_expired"; readonly SUB_OK: "sub_ok"; readonly SUB_ERROR: "sub_error"; readonly UNSUB_OK: "unsub_ok"; readonly PING: "ping"; readonly EVENT: "event"; readonly ACTION_ACCEPTED: "action_accepted"; readonly ACTION_RESULT: "action_result"; readonly ERROR: "error"; readonly ADMIN_DISCONNECT: "admin_disconnect"; readonly AUTH: "auth"; readonly SUBSCRIBE: "subscribe"; readonly UNSUBSCRIBE: "unsubscribe"; readonly UNSUBSCRIBE_ALL: "unsubscribe_all"; readonly PONG: "pong"; readonly ACTION: "action"; readonly FETCH_RESULT: "fetch_result"; }; export type WsMessageType = (typeof WS_MESSAGE_TYPE)[keyof typeof WS_MESSAGE_TYPE]; /** * Built-in topic namespaces (guide §5.4). Server-side permissions are * enforced (`risk:*` requires `content:read`, `mt5:*` requires `mt5:viewer`, * etc.). Use these as the first segment of every topic you publish / * subscribe to. */ export declare const WS_TOPIC_NAMESPACE: { readonly RISK: "risk"; readonly MT5: "mt5"; readonly SYMBOL: "symbol"; readonly ACCOUNT: "account"; readonly USER: "user"; readonly STREAM: "stream"; readonly ADMIN: "admin"; }; export type WsTopicNamespace = (typeof WS_TOPIC_NAMESPACE)[keyof typeof WS_TOPIC_NAMESPACE]; /** * Canonical topic strings for the built-in namespaces. The server-side * authz pipeline (FEAT-011) checks the prefix against the user's effective * permissions. * * MT5 topics must be built with `mt5Topic(server, eventType)` — the server * segment must match the CMS-resolved `Mt5Server.serverName` exactly. */ export declare const WS_TOPIC: { readonly RISK_RULES: "risk:rules"; readonly RISK_EXECUTIONS: "risk:executions"; }; export type WsTopic = (typeof WS_TOPIC)[keyof typeof WS_TOPIC]; /** MT5 event types — third segment of `mt5:events:{server}:{event_type}`. */ export declare const WS_MT5_EVENT_TYPE: { readonly TICK: "tick"; readonly ORDER: "order"; readonly POSITION: "position"; readonly STATEMENT: "statement"; readonly DEAL: "deal"; }; export type WsMt5EventType = (typeof WS_MT5_EVENT_TYPE)[keyof typeof WS_MT5_EVENT_TYPE]; /** * Build an MT5 topic for a specific server + event type. The server segment * MUST match the CMS-resolved `Mt5Server.serverName` exactly. */ export declare const mt5Topic: (serverName: string, eventType: WsMt5EventType) => string; /** * Build a per-account state topic: `account:`. * Subscribe with the account's UUID (NOT the numeric login) [ws§7.4, api-inventory §9.9]. */ export declare const accountTopic: (accountUuid: string) => string; /** * Build a per-account deal delta topic: `deal:`. * Subscribe with the account's UUID [ws§7.5]. */ export declare const dealTopic: (accountUuid: string) => string; /** * Build a per-account order delta topic: `order:`. * Subscribe with the account's UUID [ws§7.5]. */ export declare const orderTopic: (accountUuid: string) => string; /** * Build a per-symbol tick topic: `symbol::`. * The preferred live-tick path for charts (one topic per (server, symbol) isolates * per-connection cost to one symbol's tick rate) [ws§7.3, api-inventory §9.3]. */ export declare const symbolTopic: (serverName: string, symbol: string) => string; /** * Build a user-scoped notification topic: `user:` [ws§5]. */ export declare const userTopic: (userId: number | string) => string; /** * Build a stream-processor output topic: `stream:` [ws§5]. */ export declare const streamTopic: (streamId: string) => string; /** * Build an admin topic: `admin:` [ws§5]. */ export declare const adminTopic: (name: string) => string; /** Hard cap on topics per connection (server-side default). */ export declare const WS_MAX_SUBSCRIPTIONS = 50; /** Reconnect backoff schedule (matches the integration guide's recommendation). */ export declare const WS_RECONNECT_INITIAL_MS = 1000; export declare const WS_RECONNECT_MAX_MS = 30000; /** Random jitter added to each reconnect delay, in milliseconds. */ export declare const WS_RECONNECT_JITTER_MS = 250; /** Server-driven ping interval (server sends `ping` every N seconds). */ export declare const WS_PING_INTERVAL_MS = 30000; /** * Client-side ping-watchdog multiplier. The watchdog force-closes the socket * after `pingIntervalMs * WS_PING_WATCHDOG_FACTOR` without a server `ping`, * catching half-open (sleep / NAT-timeout) connections before the server's * own 2-missed-pong timeout (ws-guide §8). */ export declare const WS_PING_WATCHDOG_FACTOR = 1.5; /** Floor for the watchdog interval check (never probe more often than this). */ export declare const WS_PING_WATCHDOG_CHECK_MS = 15000; /** * Max reconnect attempts before the client transitions to terminal `CLOSED` * (ws-guide §10). Prevents an infinite `RECONNECTING` loop on a prolonged * outage so consumers (e.g. the Nuxt recovery plugin) can surface a * "connection lost" notification instead of retrying silently forever. */ export declare const WS_MAX_RECONNECT_ATTEMPTS = 10; /** Window in which the server expects the first `auth` message. */ export declare const WS_AUTH_TIMEOUT_MS = 10000; /** * Server-side TTL for an in-flight `action` after disconnect. The client * uses `fetch_result` within this window to recover a missed `action_result`. */ export declare const WS_ACTION_RESULT_TTL_MS: number; /** * MT5 broker retcodes surfaced through `action_result.output.data.retcode`. * Source: eaera-docs §7.5 / ws-guide §12.6. */ export declare const MT5_RETCODE: { readonly REQ_REJECT: 10004; readonly REQ_CANCELLED: 10006; readonly PRICE_OFF_QUOTES: 10016; readonly REQUEST_CHANGED: 10024; readonly NO_MONEY: 10019; readonly PRICE_OFF: 10030; readonly CONNECTION_LOST: 10031; readonly NETWORK_ERROR: 10032; }; export type Mt5Retcode = (typeof MT5_RETCODE)[keyof typeof MT5_RETCODE]; //# sourceMappingURL=ws.constants.d.ts.map