/** * Tail application logs from Managed Runtime environments via WebSocket. * * Connects to the MRT logging WebSocket to stream real-time application logs * from SSR environments. * * @module operations/mrt/tail-logs */ import type { AuthStrategy } from '../../auth/types.js'; /** * A parsed MRT log entry. */ export interface MrtLogEntry { /** ISO 8601 timestamp, if present. */ timestamp?: string; /** Full request UUID, if present. */ requestId?: string; /** Shortened request ID (first 8 hex chars). */ shortRequestId?: string; /** Log level (ERROR, WARN, INFO, DEBUG, etc.), if detected. */ level?: string; /** The log message content. */ message: string; /** The original raw log line. */ raw: string; } /** * Options for creating a logging JWT token. */ export interface CreateLoggingTokenOptions { /** MRT project slug. */ projectSlug: string; /** MRT environment slug. */ environmentSlug: string; /** MRT API origin URL. */ origin?: string; } /** * Options for tailing MRT logs. */ export interface TailMrtLogsOptions { /** MRT project slug. */ projectSlug: string; /** MRT environment slug. */ environmentSlug: string; /** MRT API origin URL. */ origin?: string; /** User email for the WebSocket connection. */ user?: string; /** Called for each parsed log entry. */ onEntry?: (entry: MrtLogEntry) => void; /** Called when the WebSocket connection is established. */ onConnect?: () => void; /** Called on WebSocket error. */ onError?: (error: Error) => void; /** Called when the WebSocket connection closes. */ onClose?: (code: number, reason: string) => void; } /** * Result from starting a log tail session. */ export interface TailMrtLogsResult { /** Call to stop tailing and close the WebSocket. */ stop: () => void; /** Resolves when the WebSocket connection is closed. */ done: Promise; } /** * Creates a logging JWT token for WebSocket authentication. * * POST /api/projects/{project}/target/{environment}/jwt/ * * @param options - Token creation options * @param auth - Authentication strategy (ApiKeyStrategy) * @returns The JWT token string * @throws Error if token creation fails */ export declare function createLoggingToken(options: CreateLoggingTokenOptions, auth: AuthStrategy): Promise; /** * Parses a raw MRT log line into a structured entry. * * Application log format (tab-separated): * {ISO8601}\t{UUID}\t{LEVEL}\t{message} * * Platform log format: * {LEVEL} {message} * * @param raw - The raw log line string * @returns Parsed log entry */ export declare function parseMrtLogLine(raw: string): MrtLogEntry; /** * Transforms the MRT cloud origin URL into the logs WebSocket URL. * * Replaces the `cloud` prefix in the hostname with `logs` and switches * the protocol to `wss://`. * * @example * getLogsWebSocketUrl('https://cloud.mobify.com') * // → 'wss://logs.mobify.com' * * getLogsWebSocketUrl('https://cloud-soak.mrt-soak.com') * // → 'wss://logs-soak.mrt-soak.com' */ export declare function getLogsWebSocketUrl(origin: string): string; /** * Streams application logs from an MRT environment via WebSocket. * * @param options - Tail options * @param auth - Authentication strategy (ApiKeyStrategy) * @returns Object with `stop()` to end streaming and `done` promise * * @example * ```typescript * import { ApiKeyStrategy } from '@salesforce/b2c-tooling-sdk/auth'; * import { tailMrtLogs } from '@salesforce/b2c-tooling-sdk/operations/mrt'; * * const auth = new ApiKeyStrategy(process.env.MRT_API_KEY!, 'Authorization'); * * const { stop, done } = await tailMrtLogs({ * projectSlug: 'my-storefront', * environmentSlug: 'staging', * onEntry: (entry) => console.log(entry.message), * onConnect: () => console.log('Connected'), * }, auth); * * // Later: stop() * ``` */ export declare function tailMrtLogs(options: TailMrtLogsOptions, auth: AuthStrategy): Promise;