@xapi-js/adaptor-nestjs
Version:
NestJS adaptor for X-API.
43 lines (39 loc) • 2.1 kB
TypeScript
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
import { Observable } from 'rxjs';
import { XapiRoot } from '@xapi-js/core';
/**
* Interceptor that parses incoming XML request bodies into XapiRoot objects.
* This interceptor should be applied to routes that expect an `application/xml` content type
* and whose body contains X-API XML data.
*/
declare class XapiRequestInterceptor implements NestInterceptor {
private readonly logger;
/**
* Intercepts the incoming request to parse XML body.
* If the content type is `application/xml` and a body exists, it attempts to parse the body
* into an `XapiRoot` object and replaces the original request body with it.
* @param context - The execution context of the request.
* @param next - A `CallHandler` to invoke the next interceptor or the route handler.
* @returns An `Observable` that will eventually contain the response.
*/
intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>>;
}
/**
* Interceptor that serializes XapiRoot objects returned by NestJS route handlers into XML strings.
* This interceptor should be applied to routes that return an `XapiRoot` instance
* and whose response should be `application/xml`.
*/
declare class XapiResponseInterceptor implements NestInterceptor<XapiRoot, Promise<string>> {
private readonly logger;
/**
* Intercepts the outgoing response to serialize XapiRoot to XML string.
* If the handler returns an `XapiRoot` instance, it attempts to serialize it
* into an XML string.
* @param context - The execution context of the request.
* @param next - A `CallHandler` to invoke the next interceptor or the route handler.
* @returns An `Observable` that will eventually contain the XML string response.
* @throws {Error} if the handler does not return an `XapiRoot` instance or serialization fails.
*/
intercept(context: ExecutionContext, next: CallHandler): Observable<Promise<string>>;
}
export { XapiRequestInterceptor, XapiResponseInterceptor };