UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 5.49 kB
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Topic=exports.TracingConfig=exports.LoggingProtocol=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},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},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={}));class Topic extends topic_base_1().TopicBase{static fromTopicArn(scope,id,topicArn){return Topic.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 Error("Cannot import topic; contentBasedDeduplication is only available for FIFO SNS topics.");class Import extends topic_base_1().TopicBase{constructor(){super(...arguments),this.topicArn=attrs.topicArn,this.topicName=topicName,this.fifo=fifo,this.contentBasedDeduplication=attrs.contentBasedDeduplication||!1,this.autoCreatePolicy=!1}}return new Import(scope,id,{environmentFromArn:attrs.topicArn})}constructor(scope,id,props={}){super(scope,id,{physicalName:props.topicName}),this.autoCreatePolicy=!0,this.loggingConfigs=[];try{jsiiDeprecationWarnings().aws_cdk_lib_aws_sns_TopicProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,Topic),error}if(this.enforceSSL=props.enforceSSL,props.contentBasedDeduplication&&!props.fifo)throw new Error("Content based deduplication can only be enabled for FIFO SNS topics.");if(props.messageRetentionPeriodInDays&&!props.fifo)throw new Error("`messageRetentionPeriodInDays` is only valid for FIFO SNS topics.");if(props.messageRetentionPeriodInDays!==void 0&&!core_1().Token.isUnresolved(props.messageRetentionPeriodInDays)&&(!Number.isInteger(props.messageRetentionPeriodInDays)||props.messageRetentionPeriodInDays>365||props.messageRetentionPeriodInDays<1))throw new Error("`messageRetentionPeriodInDays` must be an integer between 1 and 365");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 Error(`signatureVersion must be "1" or "2", received: "${props.signatureVersion}"`);if(props.displayName&&!core_1().Token.isUnresolved(props.displayName)&&props.displayName.length>100)throw new Error(`displayName must be less than or equal to 100 characters, got ${props.displayName.length}`);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});this.topicArn=this.getResourceArnAttribute(resource.ref,{service:"sns",resource:this.physicalName}),this.topicName=this.getResourceNameAttribute(resource.attrTopicName),this.fifo=props.fifo||!1,this.contentBasedDeduplication=props.contentBasedDeduplication||!1}renderLoggingConfigs(){return this.loggingConfigs.map(renderLoggingConfig);function renderLoggingConfig(spec){if(spec.successFeedbackSampleRate!==void 0){const rate=spec.successFeedbackSampleRate;if(!Number.isInteger(rate)||rate<0||rate>100)throw new Error("Success feedback sample rate must be an integer between 0 and 100")}return{protocol:spec.protocol,failureFeedbackRoleArn:spec.failureFeedbackRole?.roleArn,successFeedbackRoleArn:spec.successFeedbackRole?.roleArn,successFeedbackSampleRate:spec.successFeedbackSampleRate?.toString()}}}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)}}exports.Topic=Topic,_a=JSII_RTTI_SYMBOL_1,Topic[_a]={fqn:"aws-cdk-lib.aws_sns.Topic",version:"2.160.0"};