/*! * Copyright (c) 2020 Ville de Montreal. All rights reserved. * Licensed under the MIT license. * See LICENSE file in the project root for full license information. */ import { IOidcSession, IOidcAuthenticatorConfig, } from '@villedemontreal/auth-oidc'; import { ILogger, IHttpRequestCorrelator } from '@villedemontreal/auth-core'; import { authenticator } from './authenticator'; import { requestLogger } from './requestLogger'; import { requestCorrelator } from './requestCorrelator'; /** * creates an interceptor that will configure the authenticator plugin for an API class * generated by https://openapi-generator.tech/docs/generators/typescript-node. * @param session the OIDC session * @param authenticatorConfig the authenticator options */ export function authInterceptor( session: IOidcSession, authenticatorConfig?: Readonly, ) { return function interceptor(requestOptions: any): Promise | void { authenticator(session, authenticatorConfig).bind(requestOptions); }; } /** * creates an interceptor that will configure the logger plugin for an API class * generated by https://openapi-generator.tech/docs/generators/typescript-node. * @param logger the logger */ export function requestLoggingInterceptor(logger: ILogger) { return function interceptor(requestOptions: any): Promise | void { requestLogger(logger).bind(requestOptions); }; } /** * creates an interceptor that will configure the correlator plugin for an API class * generated by https://openapi-generator.tech/docs/generators/typescript-node. * @param correlator the request correlator */ export function requestCorrelationInterceptor( correlator: IHttpRequestCorrelator, ) { return function interceptor(requestOptions: any): Promise | void { requestCorrelator(correlator).bind(requestOptions); }; }