aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 10.8 kB
JavaScript
;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.ChannelNamespace=exports.HandlerBehavior=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},data_source_common_1=()=>{var tmp=require("./data-source-common");return data_source_common_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},prop_injectable_1=()=>{var tmp=require("../../core/lib/prop-injectable");return prop_injectable_1=()=>tmp,tmp},HandlerBehavior;(function(HandlerBehavior2){HandlerBehavior2.CODE="CODE",HandlerBehavior2.DIRECT="DIRECT"})(HandlerBehavior||(exports.HandlerBehavior=HandlerBehavior={}));let ChannelNamespace=(()=>{let _classDecorators=[prop_injectable_1().propertyInjectable],_classDescriptor,_classExtraInitializers=[],_classThis,_classSuper=core_1().Resource,_instanceExtraInitializers=[],_grantSubscribe_decorators,_grantPublish_decorators,_grantPublishAndSubscribe_decorators;var ChannelNamespace2=class extends _classSuper{static{_classThis=this}static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;_grantSubscribe_decorators=[(0,metadata_resource_1().MethodMetadata)()],_grantPublish_decorators=[(0,metadata_resource_1().MethodMetadata)()],_grantPublishAndSubscribe_decorators=[(0,metadata_resource_1().MethodMetadata)()],__esDecorate(this,null,_grantSubscribe_decorators,{kind:"method",name:"grantSubscribe",static:!1,private:!1,access:{has:obj=>"grantSubscribe"in obj,get:obj=>obj.grantSubscribe},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,_grantPublish_decorators,{kind:"method",name:"grantPublish",static:!1,private:!1,access:{has:obj=>"grantPublish"in obj,get:obj=>obj.grantPublish},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,_grantPublishAndSubscribe_decorators,{kind:"method",name:"grantPublishAndSubscribe",static:!1,private:!1,access:{has:obj=>"grantPublishAndSubscribe"in obj,get:obj=>obj.grantPublishAndSubscribe},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(null,_classDescriptor={value:_classThis},_classDecorators,{kind:"class",name:_classThis.name,metadata:_metadata},null,_classExtraInitializers),ChannelNamespace2=_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_appsync.ChannelNamespace",version:"2.233.0"};static PROPERTY_INJECTION_ID="aws-cdk-lib.aws-appsync.ChannelNamespace";static fromChannelNamespaceArn(scope,id,channelNamespaceArn){class Import extends core_1().Resource{channelNamespaceArn=channelNamespaceArn}return new Import(scope,id)}channelNamespaceArn=__runInitializers(this,_instanceExtraInitializers);channelNamespace;api;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,ChannelNamespace2),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),this.validateHandlerConfig(props);const code=props.code?.bind(this);let handlerConfig={};props.publishHandlerConfig&&(handlerConfig={onPublish:{behavior:props.publishHandlerConfig?.direct?HandlerBehavior.DIRECT:HandlerBehavior.CODE,integration:{dataSourceName:props.publishHandlerConfig?.dataSource?.name||""}}},handlerConfig.onPublish.behavior===HandlerBehavior.DIRECT&&(handlerConfig.onPublish.integration.lambdaConfig={invokeType:props.publishHandlerConfig?.lambdaInvokeType||data_source_common_1().LambdaInvokeType.REQUEST_RESPONSE})),props.subscribeHandlerConfig&&(handlerConfig={...handlerConfig,onSubscribe:{behavior:props.subscribeHandlerConfig?.direct?HandlerBehavior.DIRECT:HandlerBehavior.CODE,integration:{dataSourceName:props.subscribeHandlerConfig?.dataSource?.name||""}}},handlerConfig.onSubscribe.behavior===HandlerBehavior.DIRECT&&(handlerConfig.onSubscribe.integration.lambdaConfig={invokeType:props.subscribeHandlerConfig?.lambdaInvokeType||data_source_common_1().LambdaInvokeType.REQUEST_RESPONSE})),this.validateAuthorizationConfig(props.api.authProviderTypes,props.authorizationConfig?.publishAuthModeTypes??[]),this.validateAuthorizationConfig(props.api.authProviderTypes,props.authorizationConfig?.subscribeAuthModeTypes??[]),this.channelNamespace=new(appsync_generated_1()).CfnChannelNamespace(this,"Resource",{name:this.physicalName,apiId:props.api.apiId,codeHandlers:code?.inlineCode,codeS3Location:code?.s3Location,handlerConfigs:handlerConfig,publishAuthModes:props.authorizationConfig?.publishAuthModeTypes?.map(mode=>({authType:mode})),subscribeAuthModes:props.authorizationConfig?.subscribeAuthModeTypes?.map(mode=>({authType:mode}))}),props.publishHandlerConfig?.dataSource&&this.channelNamespace.addDependency(props.publishHandlerConfig.dataSource.resource),props.subscribeHandlerConfig?.dataSource&&this.channelNamespace.addDependency(props.subscribeHandlerConfig.dataSource.resource),this.channelNamespaceArn=this.channelNamespace.attrChannelNamespaceArn,this.api=props.api}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)}validateHandlerConfig(props){if(!(!props?.publishHandlerConfig&&!props?.subscribeHandlerConfig)){if(props.publishHandlerConfig?.direct){if(!props.publishHandlerConfig.dataSource)throw new(core_1()).ValidationError("No data source provided. AWS_LAMBDA data source is required for Direct handler behavior type",this);if(props.publishHandlerConfig.dataSource.resource.type!==data_source_common_1().AppSyncDataSourceType.LAMBDA)throw new(core_1()).ValidationError("Direct integration is only supported for AWS_LAMBDA data sources.",this)}if(props.subscribeHandlerConfig?.direct){if(!props.subscribeHandlerConfig.dataSource)throw new(core_1()).ValidationError("No data source provided. AWS_LAMBDA data source is required for Direct handler behavior type",this);if(props.subscribeHandlerConfig.dataSource.resource.type!==data_source_common_1().AppSyncDataSourceType.LAMBDA)throw new(core_1()).ValidationError("Direct integration is only supported for AWS_LAMBDA data sources.",this)}if(props.publishHandlerConfig?.direct&&props.subscribeHandlerConfig?.direct&&props.code)throw new(core_1()).ValidationError("Code handlers are not supported when both publish and subscribe use the Direct data source behavior",this);if(!props.publishHandlerConfig?.direct&&props.publishHandlerConfig?.lambdaInvokeType)throw new(core_1()).ValidationError("LambdaInvokeType is only supported for Direct handler behavior type",this);if(!props.subscribeHandlerConfig?.direct&&props.subscribeHandlerConfig?.lambdaInvokeType)throw new(core_1()).ValidationError("LambdaInvokeType is only supported for Direct handler behavior type",this)}}static{__runInitializers(_classThis,_classExtraInitializers)}};return ChannelNamespace2=_classThis})();exports.ChannelNamespace=ChannelNamespace;