import type { ApiNotificationMessage } from "./api/ApiMessage"; export type Serializable = string | number | boolean | null | undefined | Serializable[] | SerializableObject; interface SerializableObject { [key: string]: Serializable; } export interface RequestContext { originDomain?: string; } export interface SessionContext { connectionId?: string; connectionPath?: string; langs?: string[]; identity?: string; } interface ContextEvents { enter: { context: Context; }; exit: { context: Context; exitedContext: Context; }; "api:request": { domain: string; method: string; payload: unknown; context: Context; }; "service:request": { domain: string; method: string; payload: unknown; context: Context; }; "api:error": { error: unknown; domain: string; method: string; payload: unknown; context: Context; }; "service:error": { error: unknown; domain: string; method: string; payload: unknown; context: Context; }; } export declare const dispatchContextEvent: , R extends RequestContext, S extends SessionContext>(event: K, payload: Omit[K], "context">) => Promise; declare class Context { readonly id: string; state: "current" | "exited" | "detached"; private _requestContext; private _sessionContext; readonly parentContext: Context | undefined; private extensions; private apiClient; constructor(requestContext: R, sessionContext: S, options?: { parentContext?: Context; isDetached?: boolean; }); /** * Extend the context. This will be run every time the context is referenced. * However, each extension will only be applied once. */ extend(extFn: (context: Context) => unknown): void; get requestContext(): R; get sessionContext(): S; /** * Subscribe the current connection for WS push notifications on the specified topic. * @param topic */ subscribe(topic: string, options?: { filter?(payload: unknown): boolean; }): Promise; /** * Unsubscribe the current connection from WS push notifications on the specified topic. * @param topic */ unsubscribe(topic: string): Promise; /** * Unsubscribe all connections from WS push notifications on the specified topic. * @param topic */ destroyTopic(topic: string): Promise; /** * Send a notification to the given recipient. The payload must have a `type` attribute. * If no recipient is provided, the notification will be sent as a push on the WebSocket * connection associated with the current context. * @param payload * @param recipient * @returns */ notify

(payload: P, recipient?: ApiNotificationMessage["recipient"]): Promise; get(key: K): R[K]; get(key: K): S[K]; setRequest(key: K, val: R[K] | null): void; setSession(key: K, val: S[K] | null): void; merge(sessionContext: SessionContext): void; get identity(): S["identity"]; get domain(): R["originDomain"]; get langs(): S["langs"]; get connectionId(): S["connectionId"]; } export interface ContextFactory { enter(r: R, s: S): Promise; exit(): void; apply(r: R, s: S, fn: () => Promise): Promise; current: Context & X1; extend(xFn: (context: Context) => X2): ContextFactory; on: >(event: K, listener: (payload: ContextEvents[K]) => Promise) => void; } export declare const createContextFactory: (extFn?: (context: Context) => unknown) => ContextFactory; declare const DefaultContext: ContextFactory; export default DefaultContext;