"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.FunctionUrl=exports.HttpMethod=exports.InvokeMode=exports.FunctionUrlAuthType=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),lambda_generated_1=require("./lambda.generated"),iam=require("../../aws-iam"),core_1=require("../../core");var FunctionUrlAuthType;(function(FunctionUrlAuthType2){FunctionUrlAuthType2.AWS_IAM="AWS_IAM",FunctionUrlAuthType2.NONE="NONE"})(FunctionUrlAuthType||(exports.FunctionUrlAuthType=FunctionUrlAuthType={}));var InvokeMode;(function(InvokeMode2){InvokeMode2.BUFFERED="BUFFERED",InvokeMode2.RESPONSE_STREAM="RESPONSE_STREAM"})(InvokeMode||(exports.InvokeMode=InvokeMode={}));var HttpMethod;(function(HttpMethod2){HttpMethod2.GET="GET",HttpMethod2.PUT="PUT",HttpMethod2.HEAD="HEAD",HttpMethod2.POST="POST",HttpMethod2.DELETE="DELETE",HttpMethod2.PATCH="PATCH",HttpMethod2.OPTIONS="OPTIONS",HttpMethod2.ALL="*"})(HttpMethod||(exports.HttpMethod=HttpMethod={}));class FunctionUrl extends core_1.Resource{constructor(scope,id,props){super(scope,id);try{jsiiDeprecationWarnings.aws_cdk_lib_aws_lambda_FunctionUrlProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,FunctionUrl),error}if(this.instanceOfVersion(props.function))throw new Error("FunctionUrl cannot be used with a Version");const{targetFunction,alias}=this.instanceOfAlias(props.function)?{targetFunction:props.function.version.lambda,alias:props.function}:{targetFunction:props.function,alias:void 0},resource=new lambda_generated_1.CfnUrl(this,"Resource",{authType:props.authType??FunctionUrlAuthType.AWS_IAM,cors:props.cors?this.renderCors(props.cors):void 0,invokeMode:props.invokeMode,targetFunctionArn:targetFunction.functionArn,qualifier:alias?.aliasName});alias?.node.defaultChild!=null&&resource.node.addDependency(alias.node.defaultChild),this.url=resource.attrFunctionUrl,this.functionArn=resource.attrFunctionArn,this.function=props.function,props.authType===FunctionUrlAuthType.NONE&&props.function.addPermission("invoke-function-url",{principal:new iam.AnyPrincipal,action:"lambda:InvokeFunctionUrl",functionUrlAuthType:props.authType})}grantInvokeUrl(grantee){try{jsiiDeprecationWarnings.aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantInvokeUrl),error}return this.function.grantInvokeUrl(grantee)}instanceOfVersion(fn){return"version"in fn&&!this.instanceOfAlias(fn)}instanceOfAlias(fn){return"aliasName"in fn}renderCors(cors){if(cors.maxAge&&!cors.maxAge.isUnresolved()&&cors.maxAge.toSeconds()>86400)throw new Error(`FunctionUrl CORS maxAge should be less than or equal to 86400 secs (got ${cors.maxAge.toSeconds()})`);return{allowCredentials:cors.allowCredentials,allowHeaders:cors.allowedHeaders,allowMethods:cors.allowedMethods??[HttpMethod.ALL],allowOrigins:cors.allowedOrigins,exposeHeaders:cors.exposedHeaders,maxAge:cors.maxAge?.toSeconds()}}}exports.FunctionUrl=FunctionUrl,_a=JSII_RTTI_SYMBOL_1,FunctionUrl[_a]={fqn:"aws-cdk-lib.aws_lambda.FunctionUrl",version:"2.96.1"};
