///
import express from "express";
import * as http from "http";
import { Server, CustomTransportStrategy } from "@nestjs/microservices";
import { HttpServer } from "@nestjs/common";
import { TypesafeMap } from "./typesafe-map";
export declare class JsonRpcContext {
private req;
private server;
private _customData;
constructor(req: express.Request, server: express.Application);
/**
* Allows you to access and set custom data into individual remote procedure call contexts
* in a type-safe way.
*
* To use this property, you need to instantiate a TypesafeKey.
*
* The following example decodes and adds user info to the context. JWT is extracted from
* the RPC request metadata (the Authorization header for our HTTP transport)
*
* ```
* import { TypesafeKey } from '@hfour/nestjs-json-rpc'
* import { UserInfo } from './my-code';
*
* const UserInfoKey = new TypesafeKey('myapp:auth:UserInfo');
*
* export class TestAuthenticateGuard implements CanActivate {
* public async canActivate(context: ExecutionContext): Promise {
* const ctx = context.switchToRpc().getContext();
* let jwtMetadata = ctx.getMetadataByKey('Authorization');
* if (!jwtMetadata) return false;
* const decoded: Result = jwt.decodeBearer(jwtMetadata);
* if (decoded.error) return false;
* ctx.customData.set(UserInfo, decoded.result)
* return true;
* }
* }
* ```
*/
get customData(): TypesafeMap;
getMetadataByKey(metadataKey: string): string | undefined;
getParams(): unknown;
}
interface HybridJsonRpcServerOptions {
/**
* The path at which the JSON RPC endpoint should be mounted
*/
path: string;
/**
* The HTTP Server provided by the Nest runtime
*/
adapter: HttpServer;
}
interface StandaloneJsonRpcServerOptions {
/**
* Listening port for the HTTP server
*/
port: number;
/**
* Listening host (optional, defaults to any)
*/
hostname?: string;
path: string;
}
export type JsonRpcServerOptions = HybridJsonRpcServerOptions | StandaloneJsonRpcServerOptions;
export declare class JsonRpcServer extends Server implements CustomTransportStrategy {
private readonly options;
server: http.Server | null;
/**
* Creates a new JSON RPC Server strategy. When used to create a NestJS microservice, it will
* expose a new microservce with a HTTP transport which implements JSON-RPC
*/
constructor(options: JsonRpcServerOptions);
listen(callback: () => void): Promise;
close(): Promise;
private isHybrid;
private isStandalone;
}
export {};