@ez4/aws-topic 0.38.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.cjs +3 -3
- package/dist/client.mjs +4 -4
- package/dist/main.cjs +129 -126
- package/dist/main.mjs +124 -120
- package/dist/subscription/client.d.ts +3 -3
- package/dist/topic/client.d.ts +5 -5
- package/dist/utils/deploy.d.ts +2 -0
- package/lib/message.ts +1 -2
- package/package.json +16 -16
package/dist/client.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";var r=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var p=(e,t)=>r(e,"name",{value:t,configurable:!0});var S=(e,t)=>{for(var s in t)r(e,s,{get:t[s],enumerable:!0})},y=(e,t,s,i)=>{if(t&&
|
|
2
2
|
typeof t=="object"||typeof t=="function")for(let o of f(t))!I.call(e,o)&&o!==s&&
|
|
3
3
|
r(e,o,{get:()=>t[o],enumerable:!(i=T(t,o))||i.enumerable});return e};var w=e=>y(r({},"__esModule",{value:!0}),e);var b={};S(b,{Client:()=>d});module.exports=w(b);var n=require("@ez4/topic/utils"),
|
|
4
|
-
a=require("@aws-sdk/client-sns"),g=require("@ez4/
|
|
5
|
-
let M=await(0,n.getJsonStringMessage)(m,o),l=
|
|
4
|
+
a=require("@aws-sdk/client-sns"),g=require("@ez4/utils"),u=require("@ez4/common");var d;(s=>{let e=new a.SNSClient;s.make=p((i,o,c)=>new class{async sendMessage(m){
|
|
5
|
+
let M=await(0,n.getJsonStringMessage)(m,o),l=u.Runtime.getScope();await e.send(new a.PublishCommand(
|
|
6
6
|
{TargetArn:i,Message:M,...c&&{...P(m,c)},MessageAttributes:{"EZ4.TRACE_ID":{StringValue:l?.
|
|
7
|
-
traceId??(0,
|
|
7
|
+
traceId??(0,g.getRandomUUID)(),DataType:"String"}}}))}},"make")})(d||={});var P=p(
|
|
8
8
|
(e,t)=>{let s={};if(t){let{groupId:i,uniqueId:o}=t;if(s.MessageGroupId=`${e[i]}`,
|
|
9
9
|
!s.MessageGroupId)throw new n.MissingMessageGroupError(i.toString());o&&e[o]&&(s.
|
|
10
10
|
MessageDeduplicationId=`${e[o]}`)}return s},"getFifoParameters");0&&(module.exports={Client});
|
package/dist/client.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var m=Object.defineProperty;var r=(e,s)=>m(e,"name",{value:s,configurable:!0});import{getJsonStringMessage as g,MissingMessageGroupError as u}from"@ez4/topic/utils";
|
|
2
|
-
import{PublishCommand as d,SNSClient as M}from"@aws-sdk/client-sns";import{
|
|
3
|
-
import{
|
|
4
|
-
a,o),c=
|
|
5
|
-
MessageAttributes:{"EZ4.TRACE_ID":{StringValue:c?.traceId??
|
|
2
|
+
import{PublishCommand as d,SNSClient as M}from"@aws-sdk/client-sns";import{getRandomUUID as l}from"@ez4/utils";
|
|
3
|
+
import{Runtime as T}from"@ez4/common";var f;(t=>{let e=new M;t.make=r((i,o,n)=>new class{async sendMessage(a){let p=await g(
|
|
4
|
+
a,o),c=T.getScope();await e.send(new d({TargetArn:i,Message:p,...n&&{...I(a,n)},
|
|
5
|
+
MessageAttributes:{"EZ4.TRACE_ID":{StringValue:c?.traceId??l(),DataType:"String"}}}))}},
|
|
6
6
|
"make")})(f||={});var I=r((e,s)=>{let t={};if(s){let{groupId:i,uniqueId:o}=s;if(t.
|
|
7
7
|
MessageGroupId=`${e[i]}`,!t.MessageGroupId)throw new u(i.toString());o&&e[o]&&(t.
|
|
8
8
|
MessageDeduplicationId=`${e[o]}`)}return t},"getFifoParameters");export{f as Client};
|
package/dist/main.cjs
CHANGED
|
@@ -1,141 +1,144 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
typeof
|
|
3
|
-
|
|
4
|
-
TopicServiceType:()=>y,createSubscription:()=>
|
|
5
|
-
createTopic:()=>
|
|
6
|
-
isSubscriptionState:()=>
|
|
7
|
-
lt(
|
|
8
|
-
Ye=require("@ez4/aws-queue"),et=require("@ez4/topic/library"),tt=require("@ez4/project/library");var
|
|
9
|
-
|
|
10
|
-
[{permissions:["sns:Publish"],resourceIds:
|
|
11
|
-
cyDocument");var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
"use strict";var L=Object.defineProperty;var at=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var ut=Object.prototype.hasOwnProperty;var i=(t,e)=>L(t,"name",{value:e,configurable:!0});var St=(t,e)=>{for(var r in e)L(t,r,{get:e[r],enumerable:!0})},ft=(t,e,r,o)=>{if(e&&
|
|
2
|
+
typeof e=="object"||typeof e=="function")for(let n of mt(e))!ut.call(t,n)&&n!==r&&
|
|
3
|
+
L(t,n,{get:()=>e[n],enumerable:!(o=at(e,n))||o.enumerable});return t};var lt=t=>ft(L({},"__esModule",{value:!0}),t);var Ft={};St(Ft,{SubscriptionServiceName:()=>m,SubscriptionServiceType:()=>T,TopicServiceName:()=>l,
|
|
4
|
+
TopicServiceType:()=>y,createSubscription:()=>k,createSubscriptionFunction:()=>W,
|
|
5
|
+
createTopic:()=>h,createTopicStateId:()=>D,getTopic:()=>Ct,getTopicArn:()=>V,getTopicState:()=>J,
|
|
6
|
+
isSubscriptionState:()=>Lt,isTopicState:()=>M,registerTriggers:()=>Pt});module.exports=
|
|
7
|
+
lt(Ft);var Ve=require("@ez4/aws-common"),We=require("@ez4/aws-identity"),Xe=require("@ez4/aws-function"),
|
|
8
|
+
Ye=require("@ez4/aws-queue"),et=require("@ez4/topic/library"),tt=require("@ez4/project/library");var le=require("@ez4/aws-common");var f=require("@ez4/aws-common"),F=require("@ez4/aws-identity"),ue=require("@ez4/utils");var v=require("@ez4/aws-identity");var E=i((t,e,r)=>`arn:aws:sns:${e}:${r}:${t}`,"buildTopicArn"),ie=i(async t=>{let[
|
|
9
|
+
e,r]=await Promise.all([(0,v.getRegion)(),(0,v.getAccountId)()]);return(0,v.createPolicyDocument)(
|
|
10
|
+
[{permissions:["sns:Publish"],resourceIds:t.map(o=>E(`${o}-*`,e,r))}])},"getPoli\
|
|
11
|
+
cyDocument");var S=require("@aws-sdk/client-sns"),Z=require("@ez4/aws-common");var ne=require("@ez4/aws-common"),pe=require("@aws-sdk/client-sns");var d=i(()=>new pe.SNSClient((0,ne.getAwsClientOptions)()),"getSNSClient");var ce=i(async(t,e)=>{t.update("Creating topic");let{topicName:r,fifoMode:o}=e;return{
|
|
12
|
+
topicArn:(await d().send(new S.CreateTopicCommand({Name:r,Attributes:{...o&&{ContentBasedDeduplication:"\
|
|
13
|
+
true",FifoThroughputScope:"MessageGroup",FifoTopic:"true"}},Tags:(0,Z.getTagList)(
|
|
14
|
+
{...e.tags,ManagedBy:"EZ4"})}))).TopicArn}},"createTopic"),se=i(async(t,e)=>{t.update(
|
|
15
|
+
"Deleting topic");try{return await d().send(new S.DeleteTopicCommand({TopicArn:e})),
|
|
16
|
+
!0}catch(r){if(!(r instanceof S.NotFoundException))throw r;return!1}},"deleteTop\
|
|
17
|
+
ic"),ae=i(async(t,e,r)=>{t.update("Tag topic"),await d().send(new S.TagResourceCommand(
|
|
18
|
+
{ResourceArn:e,Tags:(0,Z.getTagList)({...r,ManagedBy:"EZ4"})}))},"tagTopic"),me=i(
|
|
19
|
+
async(t,e,r)=>{t.update("Untag topic"),await d().send(new S.UntagResourceCommand(
|
|
20
|
+
{ResourceArn:e,TagKeys:r}))},"untagTopic");var l="AWS:SNS/Topic",y="aws:sns.topic";var Se=i(()=>({equals:yt,create:fe,replace:dt,preview:gt,update:Tt,delete:bt}),"\
|
|
21
|
+
getTopicHandler"),yt=i((t,e)=>!!t.result&&t.result.topicArn===e.result?.topicArn,
|
|
22
|
+
"equalsResource"),gt=i((t,e)=>{let r={...t.parameters,dependencies:t.dependencies},
|
|
23
|
+
o={...e.parameters,dependencies:e.dependencies},n=(0,ue.deepCompare)(r,o);if(n.counts)
|
|
24
|
+
return{...n,name:r.topicName}},"previewResource"),dt=i(async(t,e)=>{if(e.result)
|
|
25
|
+
throw new f.ReplaceResourceError(l,t.entryId,e.entryId);return fe(t)},"replaceRe\
|
|
26
|
+
source"),fe=i(t=>{let{parameters:e}=t;return f.OperationLogger.logExecution(l,e.
|
|
27
|
+
topicName,"creation",async r=>{if(e.import){let[n,p]=await Promise.all([(0,F.getRegion)(),
|
|
28
|
+
(0,F.getAccountId)()]);return{topicArn:E(e.topicName,n,p)}}let{topicArn:o}=await ce(
|
|
29
|
+
r,e);return{topicArn:o}})},"createResource"),Tt=i((t,e)=>{let{result:r,parameters:o}=t,
|
|
30
|
+
{topicName:n}=o;if(!r)throw new f.CorruptedResourceError(l,n);return o.import?Promise.
|
|
31
|
+
resolve(r):f.OperationLogger.logExecution(l,n,"updates",async p=>(await xt(p,r.topicArn,
|
|
32
|
+
o,e.parameters),r))},"updateResource"),bt=i(async t=>{let{result:e,parameters:r}=t;
|
|
33
|
+
!e||r.import||await f.OperationLogger.logExecution(l,r.topicName,"deletion",async o=>{
|
|
34
|
+
await se(o,e.topicArn)})},"deleteResource"),xt=i(async(t,e,r,o)=>{await(0,f.applyTagUpdates)(
|
|
35
|
+
r.tags,o.tags,n=>ae(t,e,n),n=>me(t,e,n))},"checkTagUpdates");var ye=i(()=>{(0,le.tryRegisterProvider)(y,Se())},"registerTopicProvider");var Ee=require("@ez4/aws-common");var P=require("@ez4/aws-common"),be=require("@ez4/utils");var b=require("@ez4/aws-common");var w=require("@aws-sdk/client-sns");var ge=i(async(t,e)=>{t.update("Creating topic subscription");let{topicArn:r,protocol:o,
|
|
36
|
+
endpoint:n}=e;return{subscriptionArn:(await d().send(new w.SubscribeCommand({TopicArn:r,
|
|
37
|
+
Protocol:o,Endpoint:n,ReturnSubscriptionArn:!0,Attributes:{...o==="sqs"&&{RawMessageDelivery:"\
|
|
38
|
+
true"}}}))).SubscriptionArn}},"createSubscription"),de=i(async(t,e)=>{t.update("\
|
|
39
|
+
Deleting topic subscription");try{return await d().send(new w.UnsubscribeCommand(
|
|
40
|
+
{SubscriptionArn:e})),!0}catch(r){if(!(r instanceof w.NotFoundException))throw r;
|
|
41
|
+
return!1}},"deleteSubscription");var Te=i((t,e)=>{if(!(0,b.isArn)(e))throw new b.InvalidParameterError(t,`endpoin\
|
|
42
|
+
t ${e} is not supported.`);let{service:r}=(0,b.parseArn)(e);switch(r){case"lambd\
|
|
43
|
+
a":case"sqs":return r}throw new b.InvalidParameterError(t,`protocol ${r} is not \
|
|
44
|
+
supported.`)},"getSubscriptionProtocol");var m="AWS:SNS/Subscription",T="aws:sns.subscription";var xe=i(()=>({equals:vt,create:ve,replace:wt,preview:Et,update:Rt,delete:At}),"\
|
|
45
|
+
getSubscriptionHandler"),vt=i((t,e)=>!!t.result&&t.result.subscriptionArn===e.result?.
|
|
46
|
+
subscriptionArn,"equalsResource"),Et=i((t,e)=>{let r={...t.parameters,dependencies:t.
|
|
47
|
+
dependencies},o={...e.parameters,dependencies:e.dependencies},n=(0,be.deepCompare)(
|
|
47
48
|
r,o,{exclude:{getTopicArn:!0,getEndpoint:!0}});if(n.counts)return{...n,name:r.fromService}},
|
|
48
|
-
"previewResource"),
|
|
49
|
-
m,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
y).
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
o
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
49
|
+
"previewResource"),wt=i(async(t,e,r)=>{if(e.result)throw new P.ReplaceResourceError(
|
|
50
|
+
m,t.entryId,e.entryId);return ve(t,r)},"replaceResource"),ve=i((t,e)=>{let{parameters:r}=t;
|
|
51
|
+
return P.OperationLogger.logExecution(m,r.fromService,"creation",async o=>{let[n,
|
|
52
|
+
p]=await Promise.all([r.getTopicArn(e),r.getEndpoint(e)]),{subscriptionArn:c}=await ge(
|
|
53
|
+
o,{protocol:Te(m,p),topicArn:n,endpoint:p});return{subscriptionArn:c,topicArn:n,
|
|
54
|
+
endpoint:p}})},"createResource"),Rt=i(async()=>{},"updateResource"),At=i(async t=>{
|
|
55
|
+
let{result:e,parameters:r}=t;e&&await P.OperationLogger.logExecution(m,r.fromService,
|
|
56
|
+
"deletion",async o=>{await de(o,e.subscriptionArn)})},"deleteResource");var we=i(()=>{(0,Ee.tryRegisterProvider)(T,xe())},"registerSubscriptionProvider");var _=require("@ez4/topic/library"),qe=require("@ez4/project/library");var Ae=require("@ez4/stateful"),Ce=require("@ez4/utils");var Re=require("@ez4/aws-common"),O=require("@ez4/utils");var z=class extends Error{static{i(this,"TopicNotFoundError")}constructor(e){super(
|
|
57
|
+
`Topic service ${e} wasn't found.`)}};var D=i((t,e=!0)=>(0,O.hashData)(y,e?(0,O.toKebabCase)(t):t),"createTopicStateId"),
|
|
58
|
+
M=i(t=>t.type===y,"isTopicState"),J=i((t,e,r)=>{let o=t.getServiceState(e,r);if(!M(
|
|
59
|
+
o))throw new z(e);return o},"getTopicState"),V=i((t,e,r)=>{let o=r.getDependencies(
|
|
60
|
+
y).at(0)?.result;if(!o?.topicArn)throw new Re.IncompleteResourceError(t,e,"topic\
|
|
61
|
+
Arn");return o.topicArn},"getTopicArn");var h=i((t,e)=>{let r=(0,Ce.toKebabCase)(e.topicName),o=e.fifoMode?`${r}.fifo`:r,
|
|
62
|
+
n=D(o,!1);return(0,Ae.attachEntry)(t,{type:y,entryId:n,dependencies:[],parameters:{
|
|
63
|
+
...e,topicName:o}})},"createTopic"),Ct=i((t,e)=>{let r=D(e),o=t[r];return o&&M(o)?
|
|
64
|
+
o:null},"getTopic");var Y=require("@ez4/project/library"),N=require("@ez4/topic/library"),q=require("@ez4/aws-function"),
|
|
65
|
+
$=require("@ez4/aws-common"),ee=require("@ez4/aws-identity"),je=require("@ez4/aws-logs"),
|
|
66
|
+
te=require("@ez4/aws-queue");var Fe=require("@ez4/aws-function"),ze=require("@ez4/utils");var Pe=require("node:path"),he=require("@ez4/project/library"),Ie=require("@ez4/aws-function"),
|
|
67
|
+
Ne=require("@ez4/aws-common");var Le=i(async(t,e)=>{let{handler:r,listener:o,messageSchema:n,context:p,debug:c}=t,
|
|
68
|
+
s=(0,he.getDefinitionsObject)(e);return(0,Ne.getFunctionBundle)(Ie.MappingServiceName,
|
|
69
|
+
{templateFile:(0,Pe.join)(__dirname,"../lib/message.ts"),filePrefix:"sns",define:{
|
|
67
70
|
...s,__EZ4_SCHEMA:n?JSON.stringify(n):"undefined"},handler:r,listener:o,context:p,
|
|
68
|
-
debug:c})},"bundleSubscriptionFunction");var W=i((e,
|
|
69
|
-
return(0,
|
|
71
|
+
debug:c})},"bundleSubscriptionFunction");var W=i((t,e,r,o)=>{let{handler:n,variables:p,architecture:c,messageSchema:s}=o;
|
|
72
|
+
return(0,Fe.createFunction)(t,e,r,{handlerName:"snsEntryPoint",sourceFile:n.sourceFile,
|
|
70
73
|
functionName:o.functionName,description:o.description,architecture:o.architecture,
|
|
71
|
-
runtime:o.runtime,timeout:o.timeout,memory:o.memory,debug:o.debug,
|
|
72
|
-
()=>p.reduce((a,
|
|
73
|
-
()=>[n.sourceFile,n.dependencies],"
|
|
74
|
-
o,[...a.getDependencies(),...a.getConnections()]),
|
|
75
|
-
()=>(0,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
r)){let s=(0,g.getPermission)(e,
|
|
79
|
-
fromService,getPermission:i(async()=>{let[a,
|
|
80
|
-
(0,
|
|
74
|
+
runtime:o.runtime,release:o.release,timeout:o.timeout,memory:o.memory,debug:o.debug,
|
|
75
|
+
tags:o.tags,getFunctionVariables:i(()=>p.reduce((a,u)=>({...a,...u}),{}),"getFun\
|
|
76
|
+
ctionVariables"),getFunctionFiles:i(()=>[n.sourceFile,n.dependencies],"getFuncti\
|
|
77
|
+
onFiles"),getFunctionBundle:i(a=>Le(o,[...a.getDependencies(),...a.getConnections()]),
|
|
78
|
+
"getFunctionBundle"),getFunctionHash:i(()=>(0,ze.hashObject)({architecture:c,messageSchema:s}),
|
|
79
|
+
"getFunctionHash")})},"createSubscriptionFunction");var g=require("@ez4/aws-function"),A=require("@ez4/aws-queue"),R=require("@ez4/aws-identity"),
|
|
80
|
+
Oe=require("@ez4/stateful"),De=require("@ez4/utils");var k=i((t,e,r,o)=>{let n=e.parameters.topicName,p=[e.entryId,r.entryId];if((0,g.isFunctionState)(
|
|
81
|
+
r)){let s=(0,g.getPermission)(t,e,r)??(0,g.createPermission)(t,e,r,{fromService:o.
|
|
82
|
+
fromService,getPermission:i(async()=>{let[a,u]=await Promise.all([(0,R.getRegion)(),
|
|
83
|
+
(0,R.getAccountId)()]);return{sourceArn:E(n,a,u),principal:"sns.amazonaws.com"}},
|
|
81
84
|
"getPermission")});p.push(s.entryId)}if((0,A.isQueueState)(r)){let s=(0,A.attachQueuePolicy)(
|
|
82
|
-
|
|
83
|
-
all([(0,
|
|
84
|
-
m",sourceArn:E(n,a,
|
|
85
|
-
entryId);return(0,
|
|
85
|
+
t,r,e,{fromService:o.fromService,policyGetters:[async()=>{let[a,u]=await Promise.
|
|
86
|
+
all([(0,R.getRegion)(),(0,R.getAccountId)()]);return{principal:"sns.amazonaws.co\
|
|
87
|
+
m",sourceArn:E(n,a,u)}}]});p.push(s.entryId)}let c=(0,De.hashData)(T,e.entryId,r.
|
|
88
|
+
entryId);return(0,Oe.attachEntry)(t,{type:T,entryId:c,dependencies:p,parameters:{
|
|
86
89
|
...o,getTopicArn:i(s=>V(l,c,s),"getTopicArn"),getEndpoint:i(s=>(0,g.isFunctionState)(
|
|
87
90
|
r)?(0,g.getFunctionArn)(m,c,s):(0,A.getQueueArn)(m,c,s),"getEndpoint")}})},"crea\
|
|
88
|
-
teSubscription");var
|
|
89
|
-
alName"),ke=i((e,
|
|
90
|
-
getFunctionName");var
|
|
91
|
-
"Execution role for SNS is missing.")}};var
|
|
92
|
-
p.Architecture=
|
|
93
|
-
p.Timeout=
|
|
94
|
-
subscriptions)switch(p.type){default:throw new
|
|
95
|
-
iption not supported.");case
|
|
91
|
+
teSubscription");var Me=require("@ez4/project/library"),j=require("@ez4/utils");var X=i((t,e)=>`${(0,j.toKebabCase)(t.name)}-${(0,j.toKebabCase)(e)}`,"getIntern\
|
|
92
|
+
alName"),ke=i((t,e,r)=>`${(0,Me.getServiceName)(t,r)}-${(0,j.toKebabCase)(e)}`,"\
|
|
93
|
+
getFunctionName");var I=class extends Error{static{i(this,"RoleMissingError")}constructor(){super(
|
|
94
|
+
"Execution role for SNS is missing.")}};var C=require("@ez4/aws-function"),x;(p=>(p.LogRetention=C.FunctionDefaults.LogRetention,
|
|
95
|
+
p.Architecture=C.FunctionDefaults.Architecture,p.Runtime=C.FunctionDefaults.Runtime,
|
|
96
|
+
p.Timeout=C.FunctionDefaults.Timeout,p.Memory=C.FunctionDefaults.Memory))(x||={});var Q=i((t,e,r,o,n)=>{if(!n.role||!(0,ee.isRoleState)(n.role))throw new I;for(let p of e.
|
|
97
|
+
subscriptions)switch(p.type){default:throw new $.InvalidParameterError(m,"subscr\
|
|
98
|
+
iption not supported.");case N.TopicSubscriptionType.Lambda:{if(e.fifoMode)throw new $.InvalidParameterError(
|
|
96
99
|
m,"lambda subscription not supported for FIFO topics.");let{handler:c,listener:s}=p,
|
|
97
|
-
a=X(
|
|
100
|
+
a=X(e,c.name),u=(0,q.tryGetFunctionState)(n,a,o);if(!u){let oe=ke(e,c.name,o),rt=n.
|
|
98
101
|
getDependencyFiles(c.file),{runtime:ot=o.defaults?.runtime??x.Runtime,architecture:it=o.
|
|
99
102
|
defaults?.architecture??x.Architecture,logRetention:nt=o.defaults?.logRetention??
|
|
100
103
|
x.LogRetention,memory:pt=o.defaults?.memory??x.Memory,timeout:ct=x.Timeout}=p,st=(0,je.createLogGroup)(
|
|
101
|
-
|
|
102
|
-
description,messageSchema:
|
|
103
|
-
o.variables,
|
|
104
|
-
handler:{sourceFile:c.file,functionName:c.name,module:c.module,
|
|
105
|
-
listener:s&&{functionName:s.name,sourceFile:s.file,module:s.module}}),
|
|
106
|
-
|
|
107
|
-
Queue:{let c=(0,te.getQueueState)(n,p.service,o);
|
|
108
|
-
queueName});break}}},"prepareSubscriptions"),
|
|
109
|
-
o.role))throw new
|
|
110
|
-
m,"subscription not supported.");case
|
|
111
|
-
n.handler.name),c=(0,q.getFunctionState)(o,p,r);(0,Y.linkServiceContext)(
|
|
112
|
-
|
|
113
|
-
o,n.service,r);(0,Y.linkServiceContext)(
|
|
114
|
-
Subscriptions");var $e=require("@ez4/project/library");var
|
|
115
|
-
cArn"),c=JSON.stringify(
|
|
104
|
+
t,{groupName:oe,retention:nt,tags:o.tags});u=W(t,n.role,st,{functionName:oe,description:c.
|
|
105
|
+
description,messageSchema:e.schema,context:e.context,release:o.release,debug:o.debug,
|
|
106
|
+
tags:o.tags,variables:[o.variables,e.variables,p.variables],architecture:it,runtime:ot,
|
|
107
|
+
timeout:ct,memory:pt,handler:{sourceFile:c.file,functionName:c.name,module:c.module,
|
|
108
|
+
dependencies:rt},listener:s&&{functionName:s.name,sourceFile:s.file,module:s.module}}),
|
|
109
|
+
n.setServiceState(u,a,o)}k(t,r,u,{fromService:u.parameters.functionName});break}case N.TopicSubscriptionType.
|
|
110
|
+
Queue:{let c=(0,te.getQueueState)(n,p.service,o);k(t,r,c,{fromService:c.parameters.
|
|
111
|
+
queueName});break}}},"prepareSubscriptions"),G=i((t,e,r,o)=>{if(!o.role||!(0,ee.isRoleState)(
|
|
112
|
+
o.role))throw new I;for(let n of e.subscriptions)switch(n.type){default:throw new $.InvalidParameterError(
|
|
113
|
+
m,"subscription not supported.");case N.TopicSubscriptionType.Lambda:{let p=X(e,
|
|
114
|
+
n.handler.name),c=(0,q.getFunctionState)(o,p,r);(0,Y.linkServiceContext)(t,c.entryId,
|
|
115
|
+
e.context);break}case N.TopicSubscriptionType.Queue:{let p=(0,te.getQueueState)(
|
|
116
|
+
o,n.service,r);(0,Y.linkServiceContext)(t,p.entryId,e.context);break}}},"connect\
|
|
117
|
+
Subscriptions");var $e=require("@ez4/project/library");var H=i((t,e,r)=>{let n=J(t,e.name,r).entryId,p=(0,$e.getDefinitionName)(n,"topi\
|
|
118
|
+
cArn"),c=JSON.stringify(e.fifoMode??null),s=JSON.stringify(e.schema);return{module:"\
|
|
116
119
|
Client",from:"@ez4/aws-topic/client",constructor:`@{EZ4_MODULE_IMPORT}.make(${p}\
|
|
117
|
-
, ${s}, ${c})`,connectionIds:[n],dependencyIds:[n]}},"prepareLinkedClient");var
|
|
118
|
-
|
|
119
|
-
context:n}=
|
|
120
|
-
r,o),fifoMode:!!p,tags:o.tags});return n.setServiceState(c,r,o),
|
|
121
|
-
"prepareServices"),He=i(
|
|
122
|
-
r)&&
|
|
123
|
-
let{project:n}=
|
|
124
|
-
n);return
|
|
125
|
-
context:n}=
|
|
126
|
-
if(!s||!s[c])throw new re.MissingImportedProjectError(c);let a=
|
|
127
|
-
p,s[c]),fifoMode:!!r.fifoMode,import:!0});return n.setServiceState(a,r,o),
|
|
128
|
-
a,o,n),!0},"prepareImports"),Ke=i(
|
|
129
|
-
(0,
|
|
130
|
-
r!==
|
|
131
|
-
"",s)),[p]=n,c=`${p}-topic-policy`;return(0,
|
|
132
|
-
|
|
133
|
-
y");var
|
|
120
|
+
, ${s}, ${c})`,connectionIds:[n],dependencyIds:[n]}},"prepareLinkedClient");var Qe=i(t=>{let{service:e,options:r,context:o}=t;return(0,_.isTopicService)(e)?
|
|
121
|
+
H(o,e,r):null},"prepareLinkedServices"),Ge=i(t=>{let{state:e,service:r,options:o,
|
|
122
|
+
context:n}=t;if(!(0,_.isTopicService)(r))return!1;let{fifoMode:p}=r,c=h(e,{topicName:(0,qe.getServiceName)(
|
|
123
|
+
r,o),fifoMode:!!p,tags:o.tags});return n.setServiceState(c,r,o),Q(e,r,c,o,n),!0},
|
|
124
|
+
"prepareServices"),He=i(t=>{let{state:e,service:r,options:o,context:n}=t;(0,_.isTopicService)(
|
|
125
|
+
r)&&G(e,r,o,n)},"connectServices");var re=require("@ez4/project/library"),_e=require("@ez4/project/library"),U=require("@ez4/topic/library");var Ue=i(t=>{let{service:e,options:r,context:o}=t;if(!(0,U.isTopicImport)(e))return null;
|
|
126
|
+
let{project:n}=e,{imports:p}=r;if(!p||!p[n])throw new re.MissingImportedProjectError(
|
|
127
|
+
n);return H(o,e,p[n])},"prepareLinkedImports"),Be=i(t=>{let{state:e,service:r,options:o,
|
|
128
|
+
context:n}=t;if(!(0,U.isTopicImport)(r))return!1;let{reference:p,project:c}=r,{imports:s}=o;
|
|
129
|
+
if(!s||!s[c])throw new re.MissingImportedProjectError(c);let a=h(e,{topicName:(0,_e.getServiceName)(
|
|
130
|
+
p,s[c]),fifoMode:!!r.fifoMode,import:!0});return n.setServiceState(a,r,o),Q(e,r,
|
|
131
|
+
a,o,n),!0},"prepareImports"),Ke=i(t=>{let{state:e,service:r,options:o,context:n}=t;
|
|
132
|
+
(0,U.isTopicImport)(r)&&G(e,r,o,n)},"connectImports");var B=require("@ez4/topic/library"),K=require("@ez4/aws-identity"),Ze=require("@ez4/project/library");var Je=i(async t=>{let{state:e,serviceType:r,options:o}=t;if(r!==B.ServiceType&&
|
|
133
|
+
r!==B.ImportType)return null;let n=Object.values({options:o,...o.imports}).map(s=>(0,Ze.getServiceName)(
|
|
134
|
+
"",s)),[p]=n,c=`${p}-topic-policy`;return(0,K.tryGetPolicy)(e,c)??(0,K.createPolicy)(
|
|
135
|
+
e,{tags:o.tags,policyDocument:await ie(n),policyName:c})},"prepareExecutionPolic\
|
|
136
|
+
y");var Pt=i(()=>{(0,Ve.registerTriggers)(),(0,We.registerTriggers)(),(0,Xe.registerTriggers)(),
|
|
134
137
|
(0,Ye.registerTriggers)(),(0,et.registerTriggers)(),(0,tt.tryCreateTrigger)("@ez\
|
|
135
|
-
4/aws-topic",{"deploy:prepareExecutionPolicy":Je,"deploy:prepareLinkedService":
|
|
136
|
-
"deploy:prepareResources":
|
|
137
|
-
Triggers"),
|
|
138
|
-
|
|
138
|
+
4/aws-topic",{"deploy:prepareExecutionPolicy":Je,"deploy:prepareLinkedService":ht,
|
|
139
|
+
"deploy:prepareResources":It,"deploy:connectResources":Nt}),ye(),we()},"register\
|
|
140
|
+
Triggers"),ht=i(t=>Qe(t)??Ue(t)??null,"prepareLinkedService"),It=i(t=>Ge(t)||Be(
|
|
141
|
+
t),"prepareQueueResources"),Nt=i(t=>{He(t),Ke(t)},"connectQueueResources");var Lt=i(t=>t.type===T,"isSubscriptionState");0&&(module.exports={SubscriptionServiceName,SubscriptionServiceType,TopicServiceName,
|
|
139
142
|
TopicServiceType,createSubscription,createSubscriptionFunction,createTopic,createTopicStateId,
|
|
140
143
|
getTopic,getTopicArn,getTopicState,isSubscriptionState,isTopicState,registerTriggers});
|
|
141
144
|
//# sourceMappingURL=main.cjs.map
|
package/dist/main.mjs
CHANGED
|
@@ -1,127 +1,131 @@
|
|
|
1
|
-
var
|
|
2
|
-
import{registerTriggers as
|
|
3
|
-
import{registerTriggers as
|
|
4
|
-
getAccountId as
|
|
5
|
-
|
|
6
|
-
map(o=>
|
|
7
|
-
UntagResourceCommand as Oe,NotFoundException as
|
|
8
|
-
getTagList as
|
|
9
|
-
|
|
10
|
-
true",FifoThroughputScope:"MessageGroup",FifoTopic:"true"}},Tags:
|
|
11
|
-
EZ4"})}))).TopicArn}},"createTopic")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
tTopicHandler"),
|
|
18
|
-
equalsResource"),
|
|
19
|
-
o={...
|
|
20
|
-
name:r.topicName}},"previewResource"),
|
|
21
|
-
|
|
22
|
-
if(
|
|
23
|
-
|
|
24
|
-
let{result:r,parameters:o}=
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
var Ae=Object.defineProperty;var i=(t,e)=>Ae(t,"name",{value:e,configurable:!0});import{registerTriggers as $t}from"@ez4/aws-common";import{registerTriggers as qt}from"@ez4/aws-identity";
|
|
2
|
+
import{registerTriggers as Qt}from"@ez4/aws-function";import{registerTriggers as Gt}from"@ez4/aws-queue";
|
|
3
|
+
import{registerTriggers as Ht}from"@ez4/topic/library";import{tryCreateTrigger as _t}from"@ez4/project/library";import{tryRegisterProvider as Ze}from"@ez4/aws-common";import{applyTagUpdates as Me,CorruptedResourceError as ke,OperationLogger as C,ReplaceResourceError as je}from"@ez4/aws-common";
|
|
4
|
+
import{getAccountId as $e,getRegion as qe}from"@ez4/aws-identity";import{deepCompare as Qe}from"@ez4/utils";import{getAccountId as Ce,getRegion as Pe,createPolicyDocument as he}from"@ez4/aws-identity";var d=i((t,e,r)=>`arn:aws:sns:${e}:${r}:${t}`,"buildTopicArn"),M=i(async t=>{let[
|
|
5
|
+
e,r]=await Promise.all([Pe(),Ce()]);return he([{permissions:["sns:Publish"],resourceIds:t.
|
|
6
|
+
map(o=>d(`${o}-*`,e,r))}])},"getPolicyDocument");import{CreateTopicCommand as Le,DeleteTopicCommand as Fe,TagResourceCommand as ze,
|
|
7
|
+
UntagResourceCommand as Oe,NotFoundException as De}from"@aws-sdk/client-sns";import{
|
|
8
|
+
getTagList as k}from"@ez4/aws-common";import{getAwsClientOptions as Ie}from"@ez4/aws-common";import{SNSClient as Ne}from"@aws-sdk/client-sns";var S=i(()=>new Ne(Ie()),"getSNSClient");var j=i(async(t,e)=>{t.update("Creating topic");let{topicName:r,fifoMode:o}=e;return{
|
|
9
|
+
topicArn:(await S().send(new Le({Name:r,Attributes:{...o&&{ContentBasedDeduplication:"\
|
|
10
|
+
true",FifoThroughputScope:"MessageGroup",FifoTopic:"true"}},Tags:k({...e.tags,ManagedBy:"\
|
|
11
|
+
EZ4"})}))).TopicArn}},"createTopic"),$=i(async(t,e)=>{t.update("Deleting topic");
|
|
12
|
+
try{return await S().send(new Fe({TopicArn:e})),!0}catch(r){if(!(r instanceof De))
|
|
13
|
+
throw r;return!1}},"deleteTopic"),q=i(async(t,e,r)=>{t.update("Tag topic"),await S().
|
|
14
|
+
send(new ze({ResourceArn:e,Tags:k({...r,ManagedBy:"EZ4"})}))},"tagTopic"),Q=i(async(t,e,r)=>{
|
|
15
|
+
t.update("Untag topic"),await S().send(new Oe({ResourceArn:e,TagKeys:r}))},"unta\
|
|
16
|
+
gTopic");var f="AWS:SNS/Topic",l="aws:sns.topic";var G=i(()=>({equals:Ge,create:H,replace:_e,preview:He,update:Ue,delete:Be}),"ge\
|
|
17
|
+
tTopicHandler"),Ge=i((t,e)=>!!t.result&&t.result.topicArn===e.result?.topicArn,"\
|
|
18
|
+
equalsResource"),He=i((t,e)=>{let r={...t.parameters,dependencies:t.dependencies},
|
|
19
|
+
o={...e.parameters,dependencies:e.dependencies},n=Qe(r,o);if(n.counts)return{...n,
|
|
20
|
+
name:r.topicName}},"previewResource"),_e=i(async(t,e)=>{if(e.result)throw new je(
|
|
21
|
+
f,t.entryId,e.entryId);return H(t)},"replaceResource"),H=i(t=>{let{parameters:e}=t;
|
|
22
|
+
return C.logExecution(f,e.topicName,"creation",async r=>{if(e.import){let[n,p]=await Promise.
|
|
23
|
+
all([qe(),$e()]);return{topicArn:d(e.topicName,n,p)}}let{topicArn:o}=await j(r,e);
|
|
24
|
+
return{topicArn:o}})},"createResource"),Ue=i((t,e)=>{let{result:r,parameters:o}=t,
|
|
25
|
+
{topicName:n}=o;if(!r)throw new ke(f,n);return o.import?Promise.resolve(r):C.logExecution(
|
|
26
|
+
f,n,"updates",async p=>(await Ke(p,r.topicArn,o,e.parameters),r))},"updateResour\
|
|
27
|
+
ce"),Be=i(async t=>{let{result:e,parameters:r}=t;!e||r.import||await C.logExecution(
|
|
28
|
+
f,r.topicName,"deletion",async o=>{await $(o,e.topicArn)})},"deleteResource"),Ke=i(
|
|
29
|
+
async(t,e,r,o)=>{await Me(r.tags,o.tags,n=>q(t,e,n),n=>Q(t,e,n))},"checkTagUpdat\
|
|
30
|
+
es");var _=i(()=>{Ze(l,G())},"registerTopicProvider");import{tryRegisterProvider as ct}from"@ez4/aws-common";import{OperationLogger as J,ReplaceResourceError as et}from"@ez4/aws-common";import{
|
|
31
|
+
deepCompare as tt}from"@ez4/utils";import{InvalidParameterError as K,isArn as Xe,parseArn as Ye}from"@ez4/aws-common";import{NotFoundException as Je,SubscribeCommand as Ve,UnsubscribeCommand as We}from"@aws-sdk/client-sns";var U=i(async(t,e)=>{t.update("Creating topic subscription");let{topicArn:r,protocol:o,
|
|
32
|
+
endpoint:n}=e;return{subscriptionArn:(await S().send(new Ve({TopicArn:r,Protocol:o,
|
|
33
|
+
Endpoint:n,ReturnSubscriptionArn:!0,Attributes:{...o==="sqs"&&{RawMessageDelivery:"\
|
|
34
|
+
true"}}}))).SubscriptionArn}},"createSubscription"),B=i(async(t,e)=>{t.update("D\
|
|
35
|
+
eleting topic subscription");try{return await S().send(new We({SubscriptionArn:e})),
|
|
36
|
+
!0}catch(r){if(!(r instanceof Je))throw r;return!1}},"deleteSubscription");var Z=i((t,e)=>{if(!Xe(e))throw new K(t,`endpoint ${e} is not supported.`);let{service:r}=Ye(
|
|
37
|
+
e);switch(r){case"lambda":case"sqs":return r}throw new K(t,`protocol ${r} is not\
|
|
38
|
+
supported.`)},"getSubscriptionProtocol");var m="AWS:SNS/Subscription",y="aws:sns.subscription";var V=i(()=>({equals:rt,create:W,replace:it,preview:ot,update:nt,delete:pt}),"ge\
|
|
39
|
+
tSubscriptionHandler"),rt=i((t,e)=>!!t.result&&t.result.subscriptionArn===e.result?.
|
|
40
|
+
subscriptionArn,"equalsResource"),ot=i((t,e)=>{let r={...t.parameters,dependencies:t.
|
|
41
|
+
dependencies},o={...e.parameters,dependencies:e.dependencies},n=tt(r,o,{exclude:{
|
|
40
42
|
getTopicArn:!0,getEndpoint:!0}});if(n.counts)return{...n,name:r.fromService}},"p\
|
|
41
|
-
reviewResource"),
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
import{
|
|
56
|
-
import{
|
|
57
|
-
import{
|
|
58
|
-
|
|
43
|
+
reviewResource"),it=i(async(t,e,r)=>{if(e.result)throw new et(m,t.entryId,e.entryId);
|
|
44
|
+
return W(t,r)},"replaceResource"),W=i((t,e)=>{let{parameters:r}=t;return J.logExecution(
|
|
45
|
+
m,r.fromService,"creation",async o=>{let[n,p]=await Promise.all([r.getTopicArn(e),
|
|
46
|
+
r.getEndpoint(e)]),{subscriptionArn:c}=await U(o,{protocol:Z(m,p),topicArn:n,endpoint:p});
|
|
47
|
+
return{subscriptionArn:c,topicArn:n,endpoint:p}})},"createResource"),nt=i(async()=>{},
|
|
48
|
+
"updateResource"),pt=i(async t=>{let{result:e,parameters:r}=t;e&&await J.logExecution(
|
|
49
|
+
m,r.fromService,"deletion",async o=>{await B(o,e.subscriptionArn)})},"deleteReso\
|
|
50
|
+
urce");var X=i(()=>{ct(y,V())},"registerSubscriptionProvider");import{isTopicService as z}from"@ez4/topic/library";import{getServiceName as Ft}from"@ez4/project/library";import{attachEntry as ut}from"@ez4/stateful";import{toKebabCase as St}from"@ez4/utils";import{IncompleteResourceError as st}from"@ez4/aws-common";import{hashData as at,
|
|
51
|
+
toKebabCase as mt}from"@ez4/utils";var x=class extends Error{static{i(this,"TopicNotFoundError")}constructor(e){super(
|
|
52
|
+
`Topic service ${e} wasn't found.`)}};var P=i((t,e=!0)=>at(l,e?mt(t):t),"createTopicStateId"),h=i(t=>t.type===l,"isTop\
|
|
53
|
+
icState"),Y=i((t,e,r)=>{let o=t.getServiceState(e,r);if(!h(o))throw new x(e);return o},
|
|
54
|
+
"getTopicState"),ee=i((t,e,r)=>{let o=r.getDependencies(l).at(0)?.result;if(!o?.
|
|
55
|
+
topicArn)throw new st(t,e,"topicArn");return o.topicArn},"getTopicArn");var v=i((t,e)=>{let r=St(e.topicName),o=e.fifoMode?`${r}.fifo`:r,n=P(o,!1);return ut(
|
|
56
|
+
t,{type:l,entryId:n,dependencies:[],parameters:{...e,topicName:o}})},"createTopi\
|
|
57
|
+
c"),Yr=i((t,e)=>{let r=P(e),o=t[r];return o&&h(o)?o:null},"getTopic");import{linkServiceContext as ce}from"@ez4/project/library";import{TopicSubscriptionType as E}from"@ez4/topic/library";
|
|
58
|
+
import{getFunctionState as ht,tryGetFunctionState as It}from"@ez4/aws-function";
|
|
59
|
+
import{InvalidParameterError as F}from"@ez4/aws-common";import{isRoleState as se}from"@ez4/aws-identity";
|
|
60
|
+
import{createLogGroup as Nt}from"@ez4/aws-logs";import{getQueueState as ae}from"@ez4/aws-queue";import{createFunction as dt}from"@ez4/aws-function";import{hashObject as Tt}from"@ez4/utils";import{join as ft}from"node:path";import{getDefinitionsObject as lt}from"@ez4/project/library";
|
|
61
|
+
import{MappingServiceName as yt}from"@ez4/aws-function";import{getFunctionBundle as gt}from"@ez4/aws-common";var te=i(async(t,e)=>{let{handler:r,listener:o,messageSchema:n,context:p,debug:c}=t,
|
|
62
|
+
s=lt(e);return gt(yt,{templateFile:ft(import.meta.dirname,"../lib/message.ts"),filePrefix:"\
|
|
59
63
|
sns",define:{...s,__EZ4_SCHEMA:n?JSON.stringify(n):"undefined"},handler:r,listener:o,
|
|
60
|
-
context:p,debug:c})},"bundleSubscriptionFunction");var
|
|
61
|
-
return
|
|
64
|
+
context:p,debug:c})},"bundleSubscriptionFunction");var re=i((t,e,r,o)=>{let{handler:n,variables:p,architecture:c,messageSchema:s}=o;
|
|
65
|
+
return dt(t,e,r,{handlerName:"snsEntryPoint",sourceFile:n.sourceFile,functionName:o.
|
|
62
66
|
functionName,description:o.description,architecture:o.architecture,runtime:o.runtime,
|
|
63
|
-
timeout:o.timeout,memory:o.memory,debug:o.debug,tags:o.tags,getFunctionVariables:i(
|
|
67
|
+
release:o.release,timeout:o.timeout,memory:o.memory,debug:o.debug,tags:o.tags,getFunctionVariables:i(
|
|
64
68
|
()=>p.reduce((a,u)=>({...a,...u}),{}),"getFunctionVariables"),getFunctionFiles:i(
|
|
65
|
-
()=>[n.sourceFile,n.dependencies],"getFunctionFiles"),getFunctionBundle:i(a=>
|
|
69
|
+
()=>[n.sourceFile,n.dependencies],"getFunctionFiles"),getFunctionBundle:i(a=>te(
|
|
66
70
|
o,[...a.getDependencies(),...a.getConnections()]),"getFunctionBundle"),getFunctionHash:i(
|
|
67
|
-
()=>
|
|
68
|
-
onFunction");import{createPermission as
|
|
69
|
-
import{attachQueuePolicy as
|
|
70
|
-
import{getAccountId as
|
|
71
|
-
import{hashData as
|
|
72
|
-
let s=
|
|
73
|
-
a,u]=await Promise.all([
|
|
74
|
-
zonaws.com"}},"getPermission")});p.push(s.entryId)}if(
|
|
75
|
-
fromService,policyGetters:[async()=>{let[a,u]=await Promise.all([
|
|
76
|
-
principal:"sns.amazonaws.com",sourceArn:
|
|
77
|
-
|
|
78
|
-
...o,getTopicArn:i(s=>
|
|
79
|
-
|
|
80
|
-
-${
|
|
81
|
-
"Execution role for SNS is missing.")}};import{FunctionDefaults as
|
|
82
|
-
LogRetention,p.Architecture=
|
|
83
|
-
p.Memory=
|
|
84
|
-
switch(p.type){default:throw new
|
|
85
|
-
if(
|
|
86
|
-
let{handler:c,listener:s}=p,a=
|
|
87
|
-
|
|
88
|
-
defaults?.architecture??
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
description,messageSchema:
|
|
92
|
-
o.variables,
|
|
93
|
-
handler:{sourceFile:c.file,functionName:c.name,module:c.module,
|
|
94
|
-
listener:s&&{functionName:s.name,sourceFile:s.file,module:s.module}}),
|
|
95
|
-
u,a,o)}I(
|
|
96
|
-
n,p.service,o);I(
|
|
97
|
-
|
|
98
|
-
subscriptions)switch(n.type){default:throw new
|
|
99
|
-
Lambda:{let p=
|
|
100
|
-
Queue:{let p=
|
|
101
|
-
iptions");import{getDefinitionName as Lt}from"@ez4/project/library";var
|
|
102
|
-
|
|
71
|
+
()=>Tt({architecture:c,messageSchema:s}),"getFunctionHash")})},"createSubscripti\
|
|
72
|
+
onFunction");import{createPermission as bt,getFunctionArn as xt,getPermission as vt,isFunctionState as oe}from"@ez4/aws-function";
|
|
73
|
+
import{attachQueuePolicy as Et,getQueueArn as wt,isQueueState as Rt}from"@ez4/aws-queue";
|
|
74
|
+
import{getAccountId as ie,getRegion as ne}from"@ez4/aws-identity";import{attachEntry as At}from"@ez4/stateful";
|
|
75
|
+
import{hashData as Ct}from"@ez4/utils";var I=i((t,e,r,o)=>{let n=e.parameters.topicName,p=[e.entryId,r.entryId];if(oe(r)){
|
|
76
|
+
let s=vt(t,e,r)??bt(t,e,r,{fromService:o.fromService,getPermission:i(async()=>{let[
|
|
77
|
+
a,u]=await Promise.all([ne(),ie()]);return{sourceArn:d(n,a,u),principal:"sns.ama\
|
|
78
|
+
zonaws.com"}},"getPermission")});p.push(s.entryId)}if(Rt(r)){let s=Et(t,r,e,{fromService:o.
|
|
79
|
+
fromService,policyGetters:[async()=>{let[a,u]=await Promise.all([ne(),ie()]);return{
|
|
80
|
+
principal:"sns.amazonaws.com",sourceArn:d(n,a,u)}}]});p.push(s.entryId)}let c=Ct(
|
|
81
|
+
y,e.entryId,r.entryId);return At(t,{type:y,entryId:c,dependencies:p,parameters:{
|
|
82
|
+
...o,getTopicArn:i(s=>ee(f,c,s),"getTopicArn"),getEndpoint:i(s=>oe(r)?xt(m,c,s):
|
|
83
|
+
wt(m,c,s),"getEndpoint")}})},"createSubscription");import{getServiceName as Pt}from"@ez4/project/library";import{toKebabCase as N}from"@ez4/utils";var L=i((t,e)=>`${N(t.name)}-${N(e)}`,"getInternalName"),pe=i((t,e,r)=>`${Pt(t,r)}\
|
|
84
|
+
-${N(e)}`,"getFunctionName");var T=class extends Error{static{i(this,"RoleMissingError")}constructor(){super(
|
|
85
|
+
"Execution role for SNS is missing.")}};import{FunctionDefaults as b}from"@ez4/aws-function";var g;(p=>(p.LogRetention=b.
|
|
86
|
+
LogRetention,p.Architecture=b.Architecture,p.Runtime=b.Runtime,p.Timeout=b.Timeout,
|
|
87
|
+
p.Memory=b.Memory))(g||={});var w=i((t,e,r,o,n)=>{if(!n.role||!se(n.role))throw new T;for(let p of e.subscriptions)
|
|
88
|
+
switch(p.type){default:throw new F(m,"subscription not supported.");case E.Lambda:{
|
|
89
|
+
if(e.fifoMode)throw new F(m,"lambda subscription not supported for FIFO topics.");
|
|
90
|
+
let{handler:c,listener:s}=p,a=L(e,c.name),u=It(n,a,o);if(!u){let D=pe(e,c.name,o),
|
|
91
|
+
Te=n.getDependencyFiles(c.file),{runtime:be=o.defaults?.runtime??g.Runtime,architecture:xe=o.
|
|
92
|
+
defaults?.architecture??g.Architecture,logRetention:ve=o.defaults?.logRetention??
|
|
93
|
+
g.LogRetention,memory:Ee=o.defaults?.memory??g.Memory,timeout:we=g.Timeout}=p,Re=Nt(
|
|
94
|
+
t,{groupName:D,retention:ve,tags:o.tags});u=re(t,n.role,Re,{functionName:D,description:c.
|
|
95
|
+
description,messageSchema:e.schema,context:e.context,release:o.release,debug:o.debug,
|
|
96
|
+
tags:o.tags,variables:[o.variables,e.variables,p.variables],architecture:xe,runtime:be,
|
|
97
|
+
timeout:we,memory:Ee,handler:{sourceFile:c.file,functionName:c.name,module:c.module,
|
|
98
|
+
dependencies:Te},listener:s&&{functionName:s.name,sourceFile:s.file,module:s.module}}),
|
|
99
|
+
n.setServiceState(u,a,o)}I(t,r,u,{fromService:u.parameters.functionName});break}case E.
|
|
100
|
+
Queue:{let c=ae(n,p.service,o);I(t,r,c,{fromService:c.parameters.queueName});break}}},
|
|
101
|
+
"prepareSubscriptions"),R=i((t,e,r,o)=>{if(!o.role||!se(o.role))throw new T;for(let n of e.
|
|
102
|
+
subscriptions)switch(n.type){default:throw new F(m,"subscription not supported.");case E.
|
|
103
|
+
Lambda:{let p=L(e,n.handler.name),c=ht(o,p,r);ce(t,c.entryId,e.context);break}case E.
|
|
104
|
+
Queue:{let p=ae(o,n.service,r);ce(t,p.entryId,e.context);break}}},"connectSubscr\
|
|
105
|
+
iptions");import{getDefinitionName as Lt}from"@ez4/project/library";var A=i((t,e,r)=>{let n=Y(t,e.name,r).entryId,p=Lt(n,"topicArn"),c=JSON.stringify(
|
|
106
|
+
e.fifoMode??null),s=JSON.stringify(e.schema);return{module:"Client",from:"@ez4/a\
|
|
103
107
|
ws-topic/client",constructor:`@{EZ4_MODULE_IMPORT}.make(${p}, ${s}, ${c})`,connectionIds:[
|
|
104
|
-
n],dependencyIds:[n]}},"prepareLinkedClient");var
|
|
105
|
-
epareLinkedServices"),
|
|
106
|
-
r))return!1;let{fifoMode:p}=r,c=
|
|
107
|
-
return n.setServiceState(c,r,o),w(
|
|
108
|
-
state:
|
|
109
|
-
import{isTopicImport as
|
|
110
|
-
{imports:p}=r;if(!p||!p[n])throw new
|
|
111
|
-
orts"),
|
|
112
|
-
reference:p,project:c}=r,{imports:s}=o;if(!s||!s[c])throw new
|
|
113
|
-
p,s[c]),fifoMode:!!r.fifoMode,import:!0});return n.setServiceState(a,r,o),w(
|
|
114
|
-
a,o,n),!0},"prepareImports"),
|
|
115
|
-
|
|
116
|
-
tryGetPolicy as
|
|
117
|
-
let n=Object.values({options:o,...o.imports}).map(s=>
|
|
118
|
-
ic-policy`;return
|
|
119
|
-
"prepareExecutionPolicy");var
|
|
120
|
-
tionPolicy":
|
|
121
|
-
ploy:connectResources":
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
h as isTopicState,
|
|
108
|
+
n],dependencyIds:[n]}},"prepareLinkedClient");var me=i(t=>{let{service:e,options:r,context:o}=t;return z(e)?A(o,e,r):null},"pr\
|
|
109
|
+
epareLinkedServices"),ue=i(t=>{let{state:e,service:r,options:o,context:n}=t;if(!z(
|
|
110
|
+
r))return!1;let{fifoMode:p}=r,c=v(e,{topicName:Ft(r,o),fifoMode:!!p,tags:o.tags});
|
|
111
|
+
return n.setServiceState(c,r,o),w(e,r,c,o,n),!0},"prepareServices"),Se=i(t=>{let{
|
|
112
|
+
state:e,service:r,options:o,context:n}=t;z(r)&&R(e,r,o,n)},"connectServices");import{MissingImportedProjectError as fe}from"@ez4/project/library";import{getServiceName as zt}from"@ez4/project/library";
|
|
113
|
+
import{isTopicImport as O}from"@ez4/topic/library";var le=i(t=>{let{service:e,options:r,context:o}=t;if(!O(e))return null;let{project:n}=e,
|
|
114
|
+
{imports:p}=r;if(!p||!p[n])throw new fe(n);return A(o,e,p[n])},"prepareLinkedImp\
|
|
115
|
+
orts"),ye=i(t=>{let{state:e,service:r,options:o,context:n}=t;if(!O(r))return!1;let{
|
|
116
|
+
reference:p,project:c}=r,{imports:s}=o;if(!s||!s[c])throw new fe(c);let a=v(e,{topicName:zt(
|
|
117
|
+
p,s[c]),fifoMode:!!r.fifoMode,import:!0});return n.setServiceState(a,r,o),w(e,r,
|
|
118
|
+
a,o,n),!0},"prepareImports"),ge=i(t=>{let{state:e,service:r,options:o,context:n}=t;
|
|
119
|
+
O(r)&&R(e,r,o,n)},"connectImports");import{ServiceType as Ot,ImportType as Dt}from"@ez4/topic/library";import{createPolicy as Mt,
|
|
120
|
+
tryGetPolicy as kt}from"@ez4/aws-identity";import{getServiceName as jt}from"@ez4/project/library";var de=i(async t=>{let{state:e,serviceType:r,options:o}=t;if(r!==Ot&&r!==Dt)return null;
|
|
121
|
+
let n=Object.values({options:o,...o.imports}).map(s=>jt("",s)),[p]=n,c=`${p}-top\
|
|
122
|
+
ic-policy`;return kt(e,c)??Mt(e,{tags:o.tags,policyDocument:await M(n),policyName:c})},
|
|
123
|
+
"prepareExecutionPolicy");var Ni=i(()=>{$t(),qt(),Qt(),Gt(),Ht(),_t("@ez4/aws-topic",{"deploy:prepareExecu\
|
|
124
|
+
tionPolicy":de,"deploy:prepareLinkedService":Ut,"deploy:prepareResources":Bt,"de\
|
|
125
|
+
ploy:connectResources":Kt}),_(),X()},"registerTriggers"),Ut=i(t=>me(t)??le(t)??null,
|
|
126
|
+
"prepareLinkedService"),Bt=i(t=>ue(t)||ye(t),"prepareQueueResources"),Kt=i(t=>{Se(
|
|
127
|
+
t),ge(t)},"connectQueueResources");var Oi=i(t=>t.type===y,"isSubscriptionState");export{m as SubscriptionServiceName,y as SubscriptionServiceType,f as TopicServiceName,
|
|
128
|
+
l as TopicServiceType,I as createSubscription,re as createSubscriptionFunction,v as createTopic,
|
|
129
|
+
P as createTopicStateId,Yr as getTopic,ee as getTopicArn,Y as getTopicState,Oi as isSubscriptionState,
|
|
130
|
+
h as isTopicState,Ni as registerTriggers};
|
|
127
131
|
//# sourceMappingURL=main.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Arn } from '@ez4/aws-common';
|
|
1
|
+
import type { Arn, OperationLogLine } from '@ez4/aws-common';
|
|
2
2
|
export declare const enum SubscriptionProtocol {
|
|
3
3
|
Lambda = "lambda",
|
|
4
4
|
SQS = "sqs"
|
|
@@ -11,5 +11,5 @@ export type CreateRequest = {
|
|
|
11
11
|
export type CreateResponse = {
|
|
12
12
|
subscriptionArn: Arn;
|
|
13
13
|
};
|
|
14
|
-
export declare const createSubscription: (request: CreateRequest) => Promise<CreateResponse>;
|
|
15
|
-
export declare const deleteSubscription: (subscriptionArn: string) => Promise<boolean>;
|
|
14
|
+
export declare const createSubscription: (logger: OperationLogLine, request: CreateRequest) => Promise<CreateResponse>;
|
|
15
|
+
export declare const deleteSubscription: (logger: OperationLogLine, subscriptionArn: string) => Promise<boolean>;
|
package/dist/topic/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Arn, ResourceTags } from '@ez4/aws-common';
|
|
1
|
+
import type { Arn, OperationLogLine, ResourceTags } from '@ez4/aws-common';
|
|
2
2
|
export type CreateRequest = {
|
|
3
3
|
topicName: string;
|
|
4
4
|
fifoMode: boolean;
|
|
@@ -7,7 +7,7 @@ export type CreateRequest = {
|
|
|
7
7
|
export type CreateResponse = {
|
|
8
8
|
topicArn: Arn;
|
|
9
9
|
};
|
|
10
|
-
export declare const createTopic: (request: CreateRequest) => Promise<CreateResponse>;
|
|
11
|
-
export declare const deleteTopic: (topicArn: string) => Promise<boolean>;
|
|
12
|
-
export declare const tagTopic: (topicArn: string, tags: ResourceTags) => Promise<void>;
|
|
13
|
-
export declare const untagTopic: (topicArn: string, tagKeys: string[]) => Promise<void>;
|
|
10
|
+
export declare const createTopic: (logger: OperationLogLine, request: CreateRequest) => Promise<CreateResponse>;
|
|
11
|
+
export declare const deleteTopic: (logger: OperationLogLine, topicArn: string) => Promise<boolean>;
|
|
12
|
+
export declare const tagTopic: (logger: OperationLogLine, topicArn: string, tags: ResourceTags) => Promise<void>;
|
|
13
|
+
export declare const untagTopic: (logger: OperationLogLine, topicArn: string, tagKeys: string[]) => Promise<void>;
|
package/lib/message.ts
CHANGED
|
@@ -3,8 +3,7 @@ import type { MessageSchema } from '@ez4/topic/utils';
|
|
|
3
3
|
import type { Topic } from '@ez4/topic';
|
|
4
4
|
|
|
5
5
|
import { getJsonMessage } from '@ez4/topic/utils';
|
|
6
|
-
import { ServiceEventType } from '@ez4/common';
|
|
7
|
-
import { Runtime } from '@ez4/common/runtime';
|
|
6
|
+
import { ServiceEventType, Runtime } from '@ez4/common';
|
|
8
7
|
import { getRandomUUID } from '@ez4/utils';
|
|
9
8
|
|
|
10
9
|
declare const __EZ4_SCHEMA: MessageSchema | null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ez4/aws-topic",
|
|
3
3
|
"description": "EZ4: Self-managed AWS SNS topics provider",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.40.0",
|
|
5
5
|
"author": "Silas B.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
],
|
|
40
40
|
"scripts": {
|
|
41
41
|
"lint": "eslint --cache",
|
|
42
|
-
"clean": "rm -
|
|
42
|
+
"clean": "rm -rf dist/* *.tsbuildinfo .eslintcache",
|
|
43
43
|
"build": "tsc && node tools/bundler.mjs",
|
|
44
44
|
"test": "npm run build && tsc -p tsconfig.test.json && ez4 test -e ../../../local.env",
|
|
45
45
|
"local:publish": "npm run build && npm run clean:registry && npm publish --registry http://localhost:4873",
|
|
@@ -51,19 +51,19 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@aws-sdk/client-sns": "^3.958.0",
|
|
54
|
-
"@ez4/aws-common": "^0.
|
|
55
|
-
"@ez4/aws-identity": "^0.
|
|
56
|
-
"@ez4/aws-function": "^0.
|
|
57
|
-
"@ez4/aws-logs": "^0.
|
|
58
|
-
"@ez4/aws-queue": "^0.
|
|
59
|
-
"@ez4/common": "^0.
|
|
60
|
-
"@ez4/project": "^0.
|
|
61
|
-
"@ez4/queue": "^0.
|
|
62
|
-
"@ez4/schema": "^0.
|
|
63
|
-
"@ez4/stateful": "^0.
|
|
64
|
-
"@ez4/topic": "^0.
|
|
65
|
-
"@ez4/transform": "^0.
|
|
66
|
-
"@ez4/utils": "^0.
|
|
67
|
-
"@ez4/validator": "^0.
|
|
54
|
+
"@ez4/aws-common": "^0.40.0",
|
|
55
|
+
"@ez4/aws-identity": "^0.40.0",
|
|
56
|
+
"@ez4/aws-function": "^0.40.0",
|
|
57
|
+
"@ez4/aws-logs": "^0.40.0",
|
|
58
|
+
"@ez4/aws-queue": "^0.40.0",
|
|
59
|
+
"@ez4/common": "^0.40.0",
|
|
60
|
+
"@ez4/project": "^0.40.0",
|
|
61
|
+
"@ez4/queue": "^0.40.0",
|
|
62
|
+
"@ez4/schema": "^0.40.0",
|
|
63
|
+
"@ez4/stateful": "^0.40.0",
|
|
64
|
+
"@ez4/topic": "^0.40.0",
|
|
65
|
+
"@ez4/transform": "^0.40.0",
|
|
66
|
+
"@ez4/utils": "^0.40.0",
|
|
67
|
+
"@ez4/validator": "^0.40.0"
|
|
68
68
|
}
|
|
69
69
|
}
|