From 393d504ecc48be9f3f9cbb2a8310f2375829acf2 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Wed, 26 Aug 2020 22:22:06 +0000 Subject: [PATCH] chore: add loggerMiddleware initial setup --- .../middleware-logger/src/configurations.ts | 5 +++ packages/middleware-logger/src/index.ts | 1 + .../middleware-logger/src/loggerMiddleware.ts | 33 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 packages/middleware-logger/src/loggerMiddleware.ts diff --git a/packages/middleware-logger/src/configurations.ts b/packages/middleware-logger/src/configurations.ts index 9aac403af3b97..672757add3816 100644 --- a/packages/middleware-logger/src/configurations.ts +++ b/packages/middleware-logger/src/configurations.ts @@ -4,6 +4,11 @@ export interface LoggerInputConfig { logger?: Logger; } +interface PreviouslyResolved {} + export interface LoggerResolvedConfig { logger?: Logger; } + +export const resolveLoggerConfig = (input: T & PreviouslyResolved & LoggerInputConfig): T & LoggerResolvedConfig => + input; diff --git a/packages/middleware-logger/src/index.ts b/packages/middleware-logger/src/index.ts index ce4dc4128ef42..d7f2a5929d5f6 100644 --- a/packages/middleware-logger/src/index.ts +++ b/packages/middleware-logger/src/index.ts @@ -1 +1,2 @@ export * from "./configurations"; +export * from "./loggerMiddleware"; diff --git a/packages/middleware-logger/src/loggerMiddleware.ts b/packages/middleware-logger/src/loggerMiddleware.ts new file mode 100644 index 0000000000000..86c31f8b98006 --- /dev/null +++ b/packages/middleware-logger/src/loggerMiddleware.ts @@ -0,0 +1,33 @@ +import { + AbsoluteLocation, + FinalizeHandler, + FinalizeHandlerArguments, + FinalizeHandlerOutput, + FinalizeRequestHandlerOptions, + MetadataBearer, + Pluggable, +} from "@aws-sdk/types"; + +import { LoggerResolvedConfig } from "./configurations"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export const loggerMiddleware = (options: LoggerResolvedConfig) => ( + next: FinalizeHandler +): FinalizeHandler => async ( + args: FinalizeHandlerArguments +): Promise> => { + // TODO: use and call options.logger once it's available in context + return next(args); +}; + +export const loggerMiddlewareOptions: FinalizeRequestHandlerOptions & AbsoluteLocation = { + name: "loggerMiddleware", + tags: ["LOGGER"], + step: "finalizeRequest", +}; + +export const getLoggerPlugin = (options: LoggerResolvedConfig): Pluggable => ({ + applyToStack: (clientStack) => { + clientStack.add(loggerMiddleware(options), loggerMiddlewareOptions); + }, +});