aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 9.26 kB
JavaScript
;var __esDecorate=exports&&exports.__esDecorate||function(ctor,descriptorIn,decorators,contextIn,initializers,extraInitializers){function accept(f){if(f!==void 0&&typeof f!="function")throw new TypeError("Function expected");return f}for(var kind=contextIn.kind,key=kind==="getter"?"get":kind==="setter"?"set":"value",target=!descriptorIn&&ctor?contextIn.static?ctor:ctor.prototype:null,descriptor=descriptorIn||(target?Object.getOwnPropertyDescriptor(target,contextIn.name):{}),_,done=!1,i=decorators.length-1;i>=0;i--){var context={};for(var p in contextIn)context[p]=p==="access"?{}:contextIn[p];for(var p in contextIn.access)context.access[p]=contextIn.access[p];context.addInitializer=function(f){if(done)throw new TypeError("Cannot add initializers after decoration has completed");extraInitializers.push(accept(f||null))};var result=(0,decorators[i])(kind==="accessor"?{get:descriptor.get,set:descriptor.set}:descriptor[key],context);if(kind==="accessor"){if(result===void 0)continue;if(result===null||typeof result!="object")throw new TypeError("Object expected");(_=accept(result.get))&&(descriptor.get=_),(_=accept(result.set))&&(descriptor.set=_),(_=accept(result.init))&&initializers.unshift(_)}else(_=accept(result))&&(kind==="field"?initializers.unshift(_):descriptor[key]=_)}target&&Object.defineProperty(target,contextIn.name,descriptor),done=!0},__runInitializers=exports&&exports.__runInitializers||function(thisArg,initializers,value){for(var useValue=arguments.length>2,i=0;i<initializers.length;i++)value=useValue?initializers[i].call(thisArg,value):initializers[i].call(thisArg);return useValue?value:void 0};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CacheQueryStringBehavior=exports.CacheHeaderBehavior=exports.CacheCookieBehavior=exports.CachePolicy=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var cloudfront_generated_1=()=>{var tmp=require("./cloudfront.generated");return cloudfront_generated_1=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},metadata_resource_1=()=>{var tmp=require("../../core/lib/metadata-resource");return metadata_resource_1=()=>tmp,tmp},detached_construct_1=()=>{var tmp=require("../../core/lib/private/detached-construct");return detached_construct_1=()=>tmp,tmp},prop_injectable_1=()=>{var tmp=require("../../core/lib/prop-injectable");return prop_injectable_1=()=>tmp,tmp};let CachePolicy=(()=>{let _classDecorators=[prop_injectable_1().propertyInjectable],_classDescriptor,_classExtraInitializers=[],_classThis,_classSuper=core_1().Resource;var CachePolicy2=class extends _classSuper{static{_classThis=this}static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;__esDecorate(null,_classDescriptor={value:_classThis},_classDecorators,{kind:"class",name:_classThis.name,metadata:_metadata},null,_classExtraInitializers),CachePolicy2=_classThis=_classDescriptor.value,_metadata&&Object.defineProperty(_classThis,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_cloudfront.CachePolicy",version:"2.233.0"};static PROPERTY_INJECTION_ID="aws-cdk-lib.aws-cloudfront.CachePolicy";static AMPLIFY=CachePolicy2.fromManagedCachePolicy("2e54312d-136d-493c-8eb9-b001f22f67d2");static CACHING_OPTIMIZED=CachePolicy2.fromManagedCachePolicy("658327ea-f89d-4fab-a63d-7e88639e58f6");static CACHING_OPTIMIZED_FOR_UNCOMPRESSED_OBJECTS=CachePolicy2.fromManagedCachePolicy("b2884449-e4de-46a7-ac36-70bc7f1ddd6d");static CACHING_DISABLED=CachePolicy2.fromManagedCachePolicy("4135ea2d-6df8-44a3-9df3-4b5a84be39ad");static ELEMENTAL_MEDIA_PACKAGE=CachePolicy2.fromManagedCachePolicy("08627262-05a9-4f76-9ded-b50ca2e3a84f");static USE_ORIGIN_CACHE_CONTROL_HEADERS=CachePolicy2.fromManagedCachePolicy("83da9c7e-98b4-4e11-a168-04f0df8e2c65");static USE_ORIGIN_CACHE_CONTROL_HEADERS_QUERY_STRINGS=CachePolicy2.fromManagedCachePolicy("4cc15a8a-d715-48a4-82b8-cc0b614638fe");static fromCachePolicyId(scope,id,cachePolicyId){return new class extends core_1().Resource{cachePolicyId=cachePolicyId;cachePolicyRef={cachePolicyId}}(scope,id)}static fromManagedCachePolicy(managedCachePolicyId){return new class extends detached_construct_1().DetachedConstruct{cachePolicyId=managedCachePolicyId;cachePolicyRef={cachePolicyId:managedCachePolicyId};constructor(){super("The result of fromManagedCachePolicy can not be used in this API")}}}cachePolicyId;cachePolicyRef;constructor(scope,id,props={}){super(scope,id,{physicalName:props.cachePolicyName});try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudfront_CachePolicyProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,CachePolicy2),error}(0,metadata_resource_1().addConstructMetadata)(this,props);const cachePolicyName=props.cachePolicyName??`${core_1().Names.uniqueId(this).slice(0,110)}-${core_1().Stack.of(this).region}`;if(!core_1().Token.isUnresolved(cachePolicyName)&&!cachePolicyName.match(/^[\w-]+$/i))throw new(core_1()).ValidationError(`'cachePolicyName' can only include '-', '_', and alphanumeric characters, got: '${cachePolicyName}'`,this);if(cachePolicyName.length>128)throw new(core_1()).ValidationError(`'cachePolicyName' cannot be longer than 128 characters, got: '${cachePolicyName.length}'`,this);if(props.comment&&!core_1().Token.isUnresolved(props.comment)&&props.comment.length>128)throw new(core_1()).ValidationError(`'comment' cannot be longer than 128 characters, got: ${props.comment.length}`,this);const minTtl=(props.minTtl??core_1().Duration.seconds(0)).toSeconds();let defaultTtl=(props.defaultTtl??core_1().Duration.days(1)).toSeconds(),maxTtl=(props.maxTtl??core_1().Duration.days(365)).toSeconds();(0,core_1().withResolved)(defaultTtl,minTtl,()=>{defaultTtl=Math.max(defaultTtl,minTtl)}),(0,core_1().withResolved)(maxTtl,defaultTtl,()=>{maxTtl=Math.max(maxTtl,defaultTtl)});const resource=new(cloudfront_generated_1()).CfnCachePolicy(this,"Resource",{cachePolicyConfig:{name:cachePolicyName,comment:props.comment,minTtl,maxTtl,defaultTtl,parametersInCacheKeyAndForwardedToOrigin:this.renderCacheKey(props)}});this.cachePolicyRef=resource.cachePolicyRef,this.cachePolicyId=resource.ref}renderCacheKey(props){const cookies=props.cookieBehavior??CacheCookieBehavior.none(),headers=props.headerBehavior??CacheHeaderBehavior.none(),queryStrings=props.queryStringBehavior??CacheQueryStringBehavior.none();return{cookiesConfig:{cookieBehavior:cookies.behavior,cookies:cookies.cookies},headersConfig:{headerBehavior:headers.behavior,headers:headers.headers},enableAcceptEncodingGzip:props.enableAcceptEncodingGzip??!1,enableAcceptEncodingBrotli:props.enableAcceptEncodingBrotli??!1,queryStringsConfig:{queryStringBehavior:queryStrings.behavior,queryStrings:queryStrings.queryStrings}}}static{__runInitializers(_classThis,_classExtraInitializers)}};return CachePolicy2=_classThis})();exports.CachePolicy=CachePolicy;class CacheCookieBehavior{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_cloudfront.CacheCookieBehavior",version:"2.233.0"};static none(){return new CacheCookieBehavior("none")}static all(){return new CacheCookieBehavior("all")}static allowList(...cookies){if(cookies.length===0)throw new(core_1()).UnscopedValidationError("At least one cookie to allow must be provided");return new CacheCookieBehavior("whitelist",cookies)}static denyList(...cookies){if(cookies.length===0)throw new(core_1()).UnscopedValidationError("At least one cookie to deny must be provided");return new CacheCookieBehavior("allExcept",cookies)}behavior;cookies;constructor(behavior,cookies){this.behavior=behavior,this.cookies=cookies}}exports.CacheCookieBehavior=CacheCookieBehavior;class CacheHeaderBehavior{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_cloudfront.CacheHeaderBehavior",version:"2.233.0"};static none(){return new CacheHeaderBehavior("none")}static allowList(...headers){if(headers.length===0)throw new(core_1()).UnscopedValidationError("At least one header to allow must be provided");return new CacheHeaderBehavior("whitelist",headers)}behavior;headers;constructor(behavior,headers){this.behavior=behavior,this.headers=headers}}exports.CacheHeaderBehavior=CacheHeaderBehavior;class CacheQueryStringBehavior{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_cloudfront.CacheQueryStringBehavior",version:"2.233.0"};static none(){return new CacheQueryStringBehavior("none")}static all(){return new CacheQueryStringBehavior("all")}static allowList(...queryStrings){if(queryStrings.length===0)throw new(core_1()).UnscopedValidationError("At least one query string to allow must be provided");return new CacheQueryStringBehavior("whitelist",queryStrings)}static denyList(...queryStrings){if(queryStrings.length===0)throw new(core_1()).UnscopedValidationError("At least one query string to deny must be provided");return new CacheQueryStringBehavior("allExcept",queryStrings)}behavior;queryStrings;constructor(behavior,queryStrings){this.behavior=behavior,this.queryStrings=queryStrings}}exports.CacheQueryStringBehavior=CacheQueryStringBehavior;