serverless-aws-lambda
Version:
AWS Application Load Balancer and API Gateway - Lambda dev tool for Serverless. Allows Express synthax in handlers. Supports packaging, local invoking and offline ALB, APG, S3, SNS, SQS, DynamoDB Stream server mocking.
2 lines (1 loc) • 3.31 kB
JavaScript
var m=(f,r,o)=>new Promise((t,s)=>{var i=e=>{try{d(o.next(e))}catch(n){s(n)}},u=e=>{try{d(o.throw(e))}catch(n){s(n)}},d=e=>e.done?t(e.value):Promise.resolve(e.value).then(i,u);d((o=o.apply(f,r)).next())});var v=(f,r)=>(r&&(r.override&&Object.entries(r.override).forEach(o=>{let[t,s]=o;t in f&&(f[t]=s)}),r.default&&Object.entries(r.default).forEach(o=>{let[t,s]=o;f[t]==null&&(f[t]=s)})),f),S=f=>{let{QueueName:r,ContentBasedDeduplication:o,DeduplicationScope:t,DelaySeconds:s,FifoQueue:i,FifoThroughputLimit:u,KmsDataKeyReusePeriodSeconds:d,KmsMasterKeyId:e,MaximumMessageSize:n,MessageRetentionPeriod:c,ReceiveMessageWaitTimeSeconds:g,VisibilityTimeout:h,Tags:y,RedrivePolicy:l}=f,p={QueueName:r};y&&Object.keys(y).length&&(p.tags=y);let a={};return typeof o!="undefined"&&(a.ContentBasedDeduplication=o),typeof t!="undefined"&&(a.DeduplicationScope=t),typeof s!="undefined"&&(a.DelaySeconds=s),typeof i!="undefined"&&(a.FifoQueue=i),typeof u!="undefined"&&(a.FifoThroughputLimit=u),typeof d!="undefined"&&(a.KmsDataKeyReusePeriodSeconds=d),typeof e!="undefined"&&(a.KmsMasterKeyId=e),typeof n!="undefined"&&(a.MaximumMessageSize=n),typeof c!="undefined"&&(a.MessageRetentionPeriod=c),typeof g!="undefined"&&(a.ReceiveMessageWaitTimeSeconds=g),typeof h!="undefined"&&(a.VisibilityTimeout=h),typeof l!="undefined"&&(a.RedrivePolicy=JSON.stringify({deadLetterTargetArn:l.deadLetterTargetArn,maxReceiveCount:l.maxReceiveCount})),r.endsWith(".fifo")&&(a.FifoQueue="true"),Object.keys(a).length&&(p.Attributes=a),p},R=(f,r,o)=>{let t=Object.values(f),s=i=>{if(t.findIndex(d=>d.QueueName==i)==-1){let d={QueueName:i};return t.push(d),!0}};return r.forEach(i=>{var u,d,e;i.sns.forEach(n=>{typeof n.redrivePolicy=="string"&&s(n.redrivePolicy)}),i.ddb.forEach(n=>{var c;((c=n.onFailure)==null?void 0:c.kind)=="sqs"&&s(n.onFailure.name)}),i.kinesis.forEach(n=>{var c;((c=n.onFailure)==null?void 0:c.kind)=="sqs"&&s(n.onFailure.name)}),((u=i.onError)==null?void 0:u.kind)=="sqs"&&s(i.onError.name),((d=i.onFailure)==null?void 0:d.kind)=="sqs"&&s(i.onFailure.name),((e=i.onSuccess)==null?void 0:e.kind)=="sqs"&&s(i.onSuccess.name),i.sqs.forEach(n=>{s(n.name)})}),t.forEach(i=>{i.RedrivePolicy&&s(i.RedrivePolicy.name)}),t.map(i=>S(v(i,o)))};import{createRequestHandler as b}from"local-aws-sqs";var q=f=>{let r=(e,n)=>{},o,t,s=[],i=()=>m(void 0,null,function*(){u.pluginData.isReady=!0;for(let e of s)try{yield e()}catch(n){}}),u={name:"sqs-plugin",pluginData:{isReady:!1,onReady:e=>{typeof e=="function"?s.push(e):console.warn("onReady callback must be a function")}},onInit:function(){var e,n;if(!this.isDeploying&&!this.isPackaging){let c=this.serverless.service.provider.region;c&&(o=c),(n=(e=this.serverless.providers)==null?void 0:e.aws)!=null&&n.accountId&&(t=this.serverless.providers.aws.accountId)}},offline:{onReady(e,n){return m(this,null,function*(){this.getServices().sqs||(yield this.setServices({sqs:{region:"us-east-1",endpoint:`http://localhost:${e}/@sqs`,credentials:{accessKeyId:"fake",secretAccessKey:"fake"}}})),r=b({port:e,region:o,accountId:t,validateDlqDestination:!1,emulateQueueCreationLifecycle:!1,baseUrl:"/@sqs/",queues:R(this.resources.sqs,this.lambdas,f)}),i()})},request:[{method:"POST",filter:"/@sqs",callback:function(e,n){r(e,n)}}]}};return u},A=q;export{A as default,q as sqsPlugin};