"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _util=require("@middy/util");var _secretsmanagerJs=_interopRequireDefault(require("aws-sdk/clients/secretsmanager.js"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}const defaults={AwsClient:_secretsmanagerJs.default,awsClientOptions:{},awsClientAssumeRole:undefined,awsClientCapture:undefined,fetchData:{},disablePrefetch:false,cacheKey:"secrets-manager",cacheExpiry:-1,setToContext:false};const secretsManagerMiddleware=(opts={})=>{const options={...defaults,...opts};const fetch=(request,cachedValues={})=>{const values={};for(const internalKey of Object.keys(options.fetchData)){if(cachedValues[internalKey])continue;values[internalKey]=client.getSecretValue({SecretId:options.fetchData[internalKey]}).promise().then(resp=>(0,_util).jsonSafeParse(resp.SecretString)).catch(e=>{const value=(0,_util).getCache(options.cacheKey).value??{};value[internalKey]=undefined;(0,_util).modifyCache(options.cacheKey,value);throw e})}return values};let prefetch,client;if((0,_util).canPrefetch(options)){client=(0,_util).createPrefetchClient(options);prefetch=(0,_util).processCache(options,fetch)}const secretsManagerMiddlewareBefore=async request=>{if(!client){client=await (0,_util).createClient(options,request)}const{value}=prefetch??(0,_util).processCache(options,fetch,request);Object.assign(request.internal,value);if(options.setToContext){const data=await (0,_util).getInternal(Object.keys(options.fetchData),request);Object.assign(request.context,data)}prefetch=null};return{before:secretsManagerMiddlewareBefore}};var _default=secretsManagerMiddleware;exports.default=_default //# sourceMappingURL=index.cjs.map