UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 9.54 kB
"use strict";var __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},__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};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Topic=exports.TracingConfig=exports.LoggingProtocol=exports.FifoThroughputScope=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var sns_generated_1=()=>{var tmp=require("./sns.generated");return sns_generated_1=()=>tmp,tmp},topic_base_1=()=>{var tmp=require("./topic-base");return topic_base_1=()=>tmp,tmp},aws_kms_1=()=>{var tmp=require("../../aws-kms");return aws_kms_1=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},errors_1=()=>{var tmp=require("../../core/lib/errors");return errors_1=()=>tmp,tmp},metadata_resource_1=()=>{var tmp=require("../../core/lib/metadata-resource");return metadata_resource_1=()=>tmp,tmp},prop_injectable_1=()=>{var tmp=require("../../core/lib/prop-injectable");return prop_injectable_1=()=>tmp,tmp},FifoThroughputScope;(function(FifoThroughputScope2){FifoThroughputScope2.TOPIC="Topic",FifoThroughputScope2.MESSAGE_GROUP="MessageGroup"})(FifoThroughputScope||(exports.FifoThroughputScope=FifoThroughputScope={}));var LoggingProtocol;(function(LoggingProtocol2){LoggingProtocol2.HTTP="http/s",LoggingProtocol2.SQS="sqs",LoggingProtocol2.LAMBDA="lambda",LoggingProtocol2.FIREHOSE="firehose",LoggingProtocol2.APPLICATION="application"})(LoggingProtocol||(exports.LoggingProtocol=LoggingProtocol={}));var TracingConfig;(function(TracingConfig2){TracingConfig2.PASS_THROUGH="PassThrough",TracingConfig2.ACTIVE="Active"})(TracingConfig||(exports.TracingConfig=TracingConfig={}));let Topic=(()=>{let _classDecorators=[prop_injectable_1().propertyInjectable],_classDescriptor,_classExtraInitializers=[],_classThis,_classSuper=topic_base_1().TopicBase,_instanceExtraInitializers=[],_addLoggingConfig_decorators;var Topic2=class extends _classSuper{static{_classThis=this}static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;_addLoggingConfig_decorators=[(0,metadata_resource_1().MethodMetadata)()],__esDecorate(this,null,_addLoggingConfig_decorators,{kind:"method",name:"addLoggingConfig",static:!1,private:!1,access:{has:obj=>"addLoggingConfig"in obj,get:obj=>obj.addLoggingConfig},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(null,_classDescriptor={value:_classThis},_classDecorators,{kind:"class",name:_classThis.name,metadata:_metadata},null,_classExtraInitializers),Topic2=_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_sns.Topic",version:"2.233.0"};static PROPERTY_INJECTION_ID="aws-cdk-lib.aws-sns.Topic";static fromTopicArn(scope,id,topicArn){return Topic2.fromTopicAttributes(scope,id,{topicArn})}static fromTopicAttributes(scope,id,attrs){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_sns_TopicAttributes(attrs)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromTopicAttributes),error}const topicName=core_1().Stack.of(scope).splitArn(attrs.topicArn,core_1().ArnFormat.NO_RESOURCE_NAME).resource,fifo=topicName.endsWith(".fifo");if(attrs.contentBasedDeduplication&&!fifo)throw new(errors_1()).ValidationError("Cannot import topic; contentBasedDeduplication is only available for FIFO SNS topics.",scope);class Import extends topic_base_1().TopicBase{topicArn=attrs.topicArn;topicName=topicName;masterKey=attrs.keyArn?aws_kms_1().Key.fromKeyArn(this,"Key",attrs.keyArn):void 0;fifo=fifo;contentBasedDeduplication=attrs.contentBasedDeduplication||!1;autoCreatePolicy=!1}return new Import(scope,id,{environmentFromArn:attrs.topicArn})}topicArn=__runInitializers(this,_instanceExtraInitializers);topicName;masterKey;contentBasedDeduplication;fifo;autoCreatePolicy=!0;loggingConfigs=[];constructor(scope,id,props={}){super(scope,id,{physicalName:props.topicName});try{jsiiDeprecationWarnings().aws_cdk_lib_aws_sns_TopicProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,Topic2),error}if((0,metadata_resource_1().addConstructMetadata)(this,props),this.enforceSSL=props.enforceSSL,props.contentBasedDeduplication&&!props.fifo)throw new(errors_1()).ValidationError("Content based deduplication can only be enabled for FIFO SNS topics.",this);if(props.messageRetentionPeriodInDays&&!props.fifo)throw new(errors_1()).ValidationError("`messageRetentionPeriodInDays` is only valid for FIFO SNS topics.",this);if(props.fifoThroughputScope&&!props.fifo)throw new(errors_1()).ValidationError("`fifoThroughputScope` can only be set for FIFO SNS topics.",this);if(props.messageRetentionPeriodInDays!==void 0&&!core_1().Token.isUnresolved(props.messageRetentionPeriodInDays)&&(!Number.isInteger(props.messageRetentionPeriodInDays)||props.messageRetentionPeriodInDays>365||props.messageRetentionPeriodInDays<1))throw new(errors_1()).ValidationError("`messageRetentionPeriodInDays` must be an integer between 1 and 365",this);props.loggingConfigs&&props.loggingConfigs.forEach(c=>this.addLoggingConfig(c));let cfnTopicName;if(props.fifo&&props.topicName&&!props.topicName.endsWith(".fifo")?cfnTopicName=this.physicalName+".fifo":props.fifo&&!props.topicName?cfnTopicName=`${core_1().Names.uniqueResourceName(this,{maxLength:251,separator:"-"})}.fifo`:cfnTopicName=this.physicalName,props.signatureVersion&&!core_1().Token.isUnresolved(props.signatureVersion)&&props.signatureVersion!=="1"&&props.signatureVersion!=="2")throw new(errors_1()).ValidationError(`signatureVersion must be "1" or "2", received: "${props.signatureVersion}"`,this);if(props.displayName&&!core_1().Token.isUnresolved(props.displayName)&&props.displayName.length>100)throw new(errors_1()).ValidationError(`displayName must be less than or equal to 100 characters, got ${props.displayName.length}`,this);const resource=new(sns_generated_1()).CfnTopic(this,"Resource",{archivePolicy:props.messageRetentionPeriodInDays?{MessageRetentionPeriod:props.messageRetentionPeriodInDays}:void 0,displayName:props.displayName,topicName:cfnTopicName,kmsMasterKeyId:props.masterKey&&props.masterKey.keyArn,contentBasedDeduplication:props.contentBasedDeduplication,fifoTopic:props.fifo,signatureVersion:props.signatureVersion,deliveryStatusLogging:core_1().Lazy.any({produce:()=>this.renderLoggingConfigs()},{omitEmptyArray:!0}),tracingConfig:props.tracingConfig,fifoThroughputScope:props.fifoThroughputScope});this.topicArn=this.getResourceArnAttribute(resource.ref,{service:"sns",resource:this.physicalName}),this.topicName=this.getResourceNameAttribute(resource.attrTopicName),this.masterKey=props.masterKey,this.fifo=props.fifo||!1,this.contentBasedDeduplication=props.contentBasedDeduplication||!1,this.enforceSSL&&this.addSSLPolicy()}renderLoggingConfigs(){const renderLoggingConfig=spec=>{if(spec.successFeedbackSampleRate!==void 0){const rate=spec.successFeedbackSampleRate;if(!Number.isInteger(rate)||rate<0||rate>100)throw new(errors_1()).ValidationError("Success feedback sample rate must be an integer between 0 and 100",this)}return{protocol:spec.protocol,failureFeedbackRoleArn:spec.failureFeedbackRole?.roleRef.roleArn,successFeedbackRoleArn:spec.successFeedbackRole?.roleRef.roleArn,successFeedbackSampleRate:spec.successFeedbackSampleRate?.toString()}};return this.loggingConfigs.map(renderLoggingConfig)}addLoggingConfig(config){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_sns_LoggingConfig(config)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.addLoggingConfig),error}this.loggingConfigs.push(config)}static{__runInitializers(_classThis,_classExtraInitializers)}};return Topic2=_classThis})();exports.Topic=Topic;