diff --git a/packages/middleware-flexible-checksums/src/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS.ts b/packages/middleware-flexible-checksums/src/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS.ts index cf21cfcc5a86f..8fd3ff0804b0d 100644 --- a/packages/middleware-flexible-checksums/src/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS.ts +++ b/packages/middleware-flexible-checksums/src/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS.ts @@ -6,7 +6,7 @@ import { SelectorType, stringUnionSelector } from "./stringUnionSelector"; export const ENV_REQUEST_CHECKSUM_CALCULATION = "AWS_REQUEST_CHECKSUM_CALCULATION"; export const CONFIG_REQUEST_CHECKSUM_CALCULATION = "request_checksum_calculation"; -export const NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS: LoadedConfigSelectors = { +export const NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS: LoadedConfigSelectors = { environmentVariableSelector: (env) => stringUnionSelector(env, ENV_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation, SelectorType.ENV), configFileSelector: (profile) => diff --git a/packages/middleware-flexible-checksums/src/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS.ts b/packages/middleware-flexible-checksums/src/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS.ts index fcf839559c10c..9fa568b334385 100644 --- a/packages/middleware-flexible-checksums/src/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS.ts +++ b/packages/middleware-flexible-checksums/src/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS.ts @@ -1,15 +1,15 @@ import { LoadedConfigSelectors } from "@smithy/node-config-provider"; -import { DEFAULT_RESPONSE_CHECKSUM_VALIDATION, RequestChecksumCalculation } from "./constants"; +import { DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation } from "./constants"; import { SelectorType, stringUnionSelector } from "./stringUnionSelector"; export const ENV_RESPONSE_CHECKSUM_VALIDATION = "AWS_RESPONSE_CHECKSUM_VALIDATION"; export const CONFIG_RESPONSE_CHECKSUM_VALIDATION = "response_checksum_validation"; -export const NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS: LoadedConfigSelectors = { +export const NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS: LoadedConfigSelectors = { environmentVariableSelector: (env) => - stringUnionSelector(env, ENV_RESPONSE_CHECKSUM_VALIDATION, RequestChecksumCalculation, SelectorType.ENV), + stringUnionSelector(env, ENV_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation, SelectorType.ENV), configFileSelector: (profile) => - stringUnionSelector(profile, CONFIG_RESPONSE_CHECKSUM_VALIDATION, RequestChecksumCalculation, SelectorType.CONFIG), + stringUnionSelector(profile, CONFIG_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation, SelectorType.CONFIG), default: DEFAULT_RESPONSE_CHECKSUM_VALIDATION, }; diff --git a/packages/middleware-flexible-checksums/src/resolveFlexibleChecksumsConfig.spec.ts b/packages/middleware-flexible-checksums/src/resolveFlexibleChecksumsConfig.spec.ts index 7bb1cd64f0d68..59d909a607f39 100644 --- a/packages/middleware-flexible-checksums/src/resolveFlexibleChecksumsConfig.spec.ts +++ b/packages/middleware-flexible-checksums/src/resolveFlexibleChecksumsConfig.spec.ts @@ -1,6 +1,11 @@ import { normalizeProvider } from "@smithy/util-middleware"; -import { DEFAULT_REQUEST_CHECKSUM_CALCULATION, DEFAULT_RESPONSE_CHECKSUM_VALIDATION } from "./constants"; +import { + DEFAULT_REQUEST_CHECKSUM_CALCULATION, + DEFAULT_RESPONSE_CHECKSUM_VALIDATION, + RequestChecksumCalculation, + ResponseChecksumValidation, +} from "./constants"; import { resolveFlexibleChecksumsConfig } from "./resolveFlexibleChecksumsConfig"; jest.mock("@smithy/util-middleware"); @@ -25,8 +30,8 @@ describe(resolveFlexibleChecksumsConfig.name, () => { it("normalizes client checksums configuration", () => { const mockInput = { - requestChecksumCalculation: "WHEN_REQUIRED", - responseChecksumValidation: "WHEN_REQUIRED", + requestChecksumCalculation: RequestChecksumCalculation.WHEN_REQUIRED, + responseChecksumValidation: ResponseChecksumValidation.WHEN_REQUIRED, }; const resolvedConfig = resolveFlexibleChecksumsConfig(mockInput); expect(resolvedConfig).toEqual(mockInput); diff --git a/packages/middleware-flexible-checksums/src/resolveFlexibleChecksumsConfig.ts b/packages/middleware-flexible-checksums/src/resolveFlexibleChecksumsConfig.ts index b57f894b23fbd..57cfd22e7ed91 100644 --- a/packages/middleware-flexible-checksums/src/resolveFlexibleChecksumsConfig.ts +++ b/packages/middleware-flexible-checksums/src/resolveFlexibleChecksumsConfig.ts @@ -1,23 +1,28 @@ import { Provider } from "@smithy/types"; import { normalizeProvider } from "@smithy/util-middleware"; -import { DEFAULT_REQUEST_CHECKSUM_CALCULATION, DEFAULT_RESPONSE_CHECKSUM_VALIDATION } from "./constants"; +import { + DEFAULT_REQUEST_CHECKSUM_CALCULATION, + DEFAULT_RESPONSE_CHECKSUM_VALIDATION, + RequestChecksumCalculation, + ResponseChecksumValidation, +} from "./constants"; export interface FlexibleChecksumsInputConfig { /** * Determines when a checksum will be calculated for request payloads. */ - requestChecksumCalculation?: string | Provider; + requestChecksumCalculation?: RequestChecksumCalculation | Provider; /** * Determines when checksum validation will be performed on response payloads. */ - responseChecksumValidation?: string | Provider; + responseChecksumValidation?: ResponseChecksumValidation | Provider; } export interface FlexibleChecksumsResolvedConfig { - requestChecksumCalculation: Provider; - responseChecksumValidation: Provider; + requestChecksumCalculation: Provider; + responseChecksumValidation: Provider; } export const resolveFlexibleChecksumsConfig = ( diff --git a/packages/middleware-flexible-checksums/src/stringUnionSelector.ts b/packages/middleware-flexible-checksums/src/stringUnionSelector.ts index 2ad49baa50e85..4a557eded5c37 100644 --- a/packages/middleware-flexible-checksums/src/stringUnionSelector.ts +++ b/packages/middleware-flexible-checksums/src/stringUnionSelector.ts @@ -10,12 +10,12 @@ export enum SelectorType { * * @internal */ -export const stringUnionSelector = ( +export const stringUnionSelector = ( obj: Record, key: string, - union: Record, + union: U, type: SelectorType -) => { +): U[K] | undefined => { if (!(key in obj)) return undefined; const value = obj[key]!.toUpperCase(); @@ -23,5 +23,5 @@ export const stringUnionSelector = ( throw new TypeError(`Cannot load ${type} '${key}'. Expected one of ${Object.values(union)}, got '${obj[key]}'.`); } - return value; + return value as U[K]; };