|
1 | 1 | import {
|
2 | 2 | EndpointBearer,
|
| 3 | + HandlerExecutionContext, |
3 | 4 | RequestSerializer,
|
4 | 5 | SerializeHandler,
|
5 | 6 | SerializeHandlerArguments,
|
6 | 7 | SerializeHandlerOutput,
|
7 | 8 | SerializeMiddleware,
|
8 | 9 | } from "@aws-sdk/types";
|
9 | 10 |
|
10 |
| -export function serializerMiddleware<Input extends object, Output extends object, RuntimeUtils extends EndpointBearer>( |
| 11 | +export const serializerMiddleware = <Input extends object, Output extends object, RuntimeUtils extends EndpointBearer>( |
11 | 12 | options: RuntimeUtils,
|
12 | 13 | serializer: RequestSerializer<any, RuntimeUtils>
|
13 |
| -): SerializeMiddleware<Input, Output> { |
14 |
| - return (next: SerializeHandler<Input, Output>): SerializeHandler<Input, Output> => async ( |
15 |
| - args: SerializeHandlerArguments<Input> |
16 |
| - ): Promise<SerializeHandlerOutput<Output>> => { |
17 |
| - const request = await serializer(args.input, options); |
18 |
| - return next({ |
19 |
| - ...args, |
20 |
| - request, |
| 14 | +): SerializeMiddleware<Input, Output> => ( |
| 15 | + next: SerializeHandler<Input, Output>, |
| 16 | + context: HandlerExecutionContext |
| 17 | +): SerializeHandler<Input, Output> => async ( |
| 18 | + args: SerializeHandlerArguments<Input> |
| 19 | +): Promise<SerializeHandlerOutput<Output>> => { |
| 20 | + const { logger, inputFilterSensitiveLog } = context; |
| 21 | + |
| 22 | + if (typeof logger?.info === "function") { |
| 23 | + logger.info({ |
| 24 | + input: inputFilterSensitiveLog(args.input), |
21 | 25 | });
|
22 |
| - }; |
23 |
| -} |
| 26 | + } |
| 27 | + |
| 28 | + const request = await serializer(args.input, options); |
| 29 | + |
| 30 | + if (typeof logger?.debug === "function") { |
| 31 | + logger.debug({ |
| 32 | + httpRequest: request, |
| 33 | + }); |
| 34 | + } |
| 35 | + |
| 36 | + return next({ |
| 37 | + ...args, |
| 38 | + request, |
| 39 | + }); |
| 40 | +}; |
0 commit comments