aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 4.74 kB
JavaScript
var __decorate=exports&&exports.__decorate||function(decorators,target,key,desc){var c=arguments.length,r=c<3?target:desc===null?desc=Object.getOwnPropertyDescriptor(target,key):desc,d;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)(d=decorators[i])&&(r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r);return c>3&&r&&Object.defineProperty(target,key,r),r},_a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChannelNamespace=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var appsync_common_1=()=>{var tmp=require("./appsync-common");return appsync_common_1=()=>tmp,tmp},appsync_generated_1=()=>{var tmp=require("./appsync.generated");return appsync_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};class ChannelNamespace extends core_1().Resource{static fromChannelNamespaceArn(scope,id,channelNamespaceArn){class Import extends core_1().Resource{constructor(){super(...arguments),this.channelNamespaceArn=channelNamespaceArn}}return new Import(scope,id)}constructor(scope,id,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_appsync_ChannelNamespaceProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,ChannelNamespace),error}if(props.channelNamespaceName!==void 0&&!core_1().Token.isUnresolved(props.channelNamespaceName)&&(props.channelNamespaceName.length<1||props.channelNamespaceName.length>50))throw new(core_1()).ValidationError(`\`channelNamespaceName\` must be between 1 and 50 characters, got: ${props.channelNamespaceName.length} characters.`,scope);super(scope,id,{physicalName:props.channelNamespaceName??id}),(0,metadata_resource_1().addConstructMetadata)(this,props);const code=props.code?.bind(this);this.validateAuthorizationConfig(props.api.authProviderTypes,props.authorizationConfig?.publishAuthModeTypes??[]),this.validateAuthorizationConfig(props.api.authProviderTypes,props.authorizationConfig?.subscribeAuthModeTypes??[]),this.api=props.api,this.channelNamespace=new(appsync_generated_1()).CfnChannelNamespace(this,"Resource",{name:this.physicalName,apiId:props.api.apiId,codeHandlers:code?.inlineCode,codeS3Location:code?.s3Location,publishAuthModes:props.authorizationConfig?.publishAuthModeTypes?.map(mode=>({authType:mode})),subscribeAuthModes:props.authorizationConfig?.subscribeAuthModeTypes?.map(mode=>({authType:mode}))}),this.channelNamespaceArn=this.channelNamespace.attrChannelNamespaceArn}grantSubscribe(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.grantSubscribe),error}return this.api.grant(grantee,appsync_common_1().AppSyncEventResource.ofChannelNamespace(this.channelNamespace.name),"appsync:EventSubscribe")}grantPublish(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.grantPublish),error}return this.api.grant(grantee,appsync_common_1().AppSyncEventResource.ofChannelNamespace(this.channelNamespace.name),"appsync:EventPublish")}grantPublishAndSubscribe(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.grantPublishAndSubscribe),error}return this.api.grant(grantee,appsync_common_1().AppSyncEventResource.ofChannelNamespace(this.channelNamespace.name),"appsync:EventPublish","appsync:EventSubscribe")}validateAuthorizationConfig(apiAuthProviders,channelAuthModeTypes){for(const mode of channelAuthModeTypes)if(!apiAuthProviders.find(authProvider=>authProvider===mode))throw new(core_1()).ValidationError(`API is missing authorization configuration for ${mode}`,this)}}exports.ChannelNamespace=ChannelNamespace,_a=JSII_RTTI_SYMBOL_1,ChannelNamespace[_a]={fqn:"aws-cdk-lib.aws_appsync.ChannelNamespace",version:"2.185.0"},__decorate([(0,metadata_resource_1().MethodMetadata)()],ChannelNamespace.prototype,"grantSubscribe",null),__decorate([(0,metadata_resource_1().MethodMetadata)()],ChannelNamespace.prototype,"grantPublish",null),__decorate([(0,metadata_resource_1().MethodMetadata)()],ChannelNamespace.prototype,"grantPublishAndSubscribe",null);
;