"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Provider=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var path=()=>{var tmp=require("path");return path=()=>tmp,tmp},constructs_1=()=>{var tmp=require("constructs");return constructs_1=()=>tmp,tmp},consts=()=>{var tmp=require("./runtime/consts");return consts=()=>tmp,tmp},util_1=()=>{var tmp=require("./util");return util_1=()=>tmp,tmp},waiter_state_machine_1=()=>{var tmp=require("./waiter-state-machine");return waiter_state_machine_1=()=>tmp,tmp},lambda=()=>{var tmp=require("../../../aws-lambda");return lambda=()=>tmp,tmp},core_1=()=>{var tmp=require("../../../core");return core_1=()=>tmp,tmp};const RUNTIME_HANDLER_PATH=path().join(__dirname,"runtime"),FRAMEWORK_HANDLER_TIMEOUT=core_1().Duration.minutes(15);class Provider extends constructs_1().Construct{constructor(scope,id,props){super(scope,id);try{jsiiDeprecationWarnings().aws_cdk_lib_custom_resources_ProviderProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,Provider),error}if(!props.isCompleteHandler&&(props.queryInterval||props.totalTimeout||props.waiterStateMachineLogOptions||props.disableWaiterStateMachineLogging!==void 0))throw new Error('"queryInterval", "totalTimeout", "waiterStateMachineLogOptions", and "disableWaiterStateMachineLogging" can only be configured if "isCompleteHandler" is specified. Otherwise, they have no meaning');this.onEventHandler=props.onEventHandler,this.isCompleteHandler=props.isCompleteHandler,this.logRetention=props.logRetention,this.logGroup=props.logGroup,this.vpc=props.vpc,this.vpcSubnets=props.vpcSubnets,this.securityGroups=props.securityGroups,this.role=props.role,this.providerFunctionEnvEncryption=props.providerFunctionEnvEncryption;const onEventFunction=this.createFunction(consts().FRAMEWORK_ON_EVENT_HANDLER_NAME,props.providerFunctionName);if(this.isCompleteHandler){const isCompleteFunction=this.createFunction(consts().FRAMEWORK_IS_COMPLETE_HANDLER_NAME),timeoutFunction=this.createFunction(consts().FRAMEWORK_ON_TIMEOUT_HANDLER_NAME),retry=(0,util_1().calculateRetryPolicy)(props),waiterStateMachine=new(waiter_state_machine_1()).WaiterStateMachine(this,"waiter-state-machine",{isCompleteHandler:isCompleteFunction,timeoutHandler:timeoutFunction,backoffRate:retry.backoffRate,interval:retry.interval,maxAttempts:retry.maxAttempts,logOptions:props.waiterStateMachineLogOptions,disableLogging:props.disableWaiterStateMachineLogging});onEventFunction.addEnvironment(consts().WAITER_STATE_MACHINE_ARN_ENV,waiterStateMachine.stateMachineArn),waiterStateMachine.grantStartExecution(onEventFunction)}this.entrypoint=onEventFunction,this.serviceToken=this.entrypoint.functionArn}bind(_scope){return{serviceToken:this.entrypoint.functionArn}}createFunction(entrypoint,name){const fn=new(lambda()).Function(this,`framework-${entrypoint}`,{code:lambda().Code.fromAsset(RUNTIME_HANDLER_PATH,{exclude:["*.ts"]}),description:`AWS CDK resource provider framework - ${entrypoint} (${this.node.path})`.slice(0,256),runtime:lambda().determineLatestNodeRuntime(this),handler:`framework.${entrypoint}`,timeout:FRAMEWORK_HANDLER_TIMEOUT,...this.logRetention?{logRetention:this.logRetention}:{},logGroup:this.logGroup,vpc:this.vpc,vpcSubnets:this.vpcSubnets,securityGroups:this.securityGroups,role:this.role,functionName:name,environmentEncryption:this.providerFunctionEnvEncryption});return fn.addEnvironment(consts().USER_ON_EVENT_FUNCTION_ARN_ENV,this.onEventHandler.functionArn),this.onEventHandler.grantInvoke(fn),this.isCompleteHandler&&(fn.addEnvironment(consts().USER_IS_COMPLETE_FUNCTION_ARN_ENV,this.isCompleteHandler.functionArn),this.isCompleteHandler.grantInvoke(fn)),fn}}exports.Provider=Provider,_a=JSII_RTTI_SYMBOL_1,Provider[_a]={fqn:"aws-cdk-lib.custom_resources.Provider",version:"2.159.0"};
