@stacksjs/ts-cloud-core 0.1.1
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/LICENSE.md +21 -0
- package/README.md +321 -0
- package/package.json +31 -0
- package/src/advanced-features.test.ts +465 -0
- package/src/aws/cloudformation.ts +421 -0
- package/src/aws/cloudfront.ts +158 -0
- package/src/aws/credentials.test.ts +132 -0
- package/src/aws/credentials.ts +545 -0
- package/src/aws/index.ts +87 -0
- package/src/aws/s3.test.ts +188 -0
- package/src/aws/s3.ts +1088 -0
- package/src/aws/signature.test.ts +670 -0
- package/src/aws/signature.ts +1155 -0
- package/src/backup/disaster-recovery.test.ts +726 -0
- package/src/backup/disaster-recovery.ts +500 -0
- package/src/backup/index.ts +34 -0
- package/src/backup/manager.test.ts +498 -0
- package/src/backup/manager.ts +432 -0
- package/src/cicd/circleci.ts +430 -0
- package/src/cicd/github-actions.ts +424 -0
- package/src/cicd/gitlab-ci.ts +255 -0
- package/src/cicd/index.ts +8 -0
- package/src/cli/history.ts +396 -0
- package/src/cli/index.ts +10 -0
- package/src/cli/progress.ts +458 -0
- package/src/cli/repl.ts +454 -0
- package/src/cli/suggestions.ts +327 -0
- package/src/cli/table.test.ts +319 -0
- package/src/cli/table.ts +332 -0
- package/src/cloudformation/builder.test.ts +327 -0
- package/src/cloudformation/builder.ts +378 -0
- package/src/cloudformation/builders/api-gateway.ts +449 -0
- package/src/cloudformation/builders/cache.ts +334 -0
- package/src/cloudformation/builders/cdn.ts +278 -0
- package/src/cloudformation/builders/compute.ts +485 -0
- package/src/cloudformation/builders/database.ts +392 -0
- package/src/cloudformation/builders/functions.ts +343 -0
- package/src/cloudformation/builders/messaging.ts +140 -0
- package/src/cloudformation/builders/monitoring.ts +300 -0
- package/src/cloudformation/builders/network.ts +264 -0
- package/src/cloudformation/builders/queue.ts +147 -0
- package/src/cloudformation/builders/security.ts +399 -0
- package/src/cloudformation/builders/storage.ts +285 -0
- package/src/cloudformation/index.ts +30 -0
- package/src/cloudformation/types.ts +173 -0
- package/src/compliance/aws-config.ts +543 -0
- package/src/compliance/cloudtrail.ts +376 -0
- package/src/compliance/compliance.test.ts +423 -0
- package/src/compliance/guardduty.ts +446 -0
- package/src/compliance/index.ts +66 -0
- package/src/compliance/security-hub.ts +456 -0
- package/src/containers/build-optimization.ts +416 -0
- package/src/containers/containers.test.ts +508 -0
- package/src/containers/image-scanning.ts +360 -0
- package/src/containers/index.ts +9 -0
- package/src/containers/registry.ts +293 -0
- package/src/containers/service-mesh.ts +520 -0
- package/src/database/database.test.ts +762 -0
- package/src/database/index.ts +9 -0
- package/src/database/migrations.ts +444 -0
- package/src/database/performance.ts +528 -0
- package/src/database/replicas.ts +534 -0
- package/src/database/users.ts +494 -0
- package/src/dependency-graph.ts +143 -0
- package/src/deployment/ab-testing.ts +582 -0
- package/src/deployment/blue-green.ts +452 -0
- package/src/deployment/canary.ts +500 -0
- package/src/deployment/deployment.test.ts +526 -0
- package/src/deployment/index.ts +61 -0
- package/src/deployment/progressive.ts +62 -0
- package/src/dns/dns.test.ts +641 -0
- package/src/dns/dnssec.ts +315 -0
- package/src/dns/index.ts +8 -0
- package/src/dns/resolver.ts +496 -0
- package/src/dns/routing.ts +593 -0
- package/src/email/advanced/analytics.ts +445 -0
- package/src/email/advanced/index.ts +11 -0
- package/src/email/advanced/rules.ts +465 -0
- package/src/email/advanced/scheduling.ts +352 -0
- package/src/email/advanced/search.ts +412 -0
- package/src/email/advanced/shared-mailboxes.ts +404 -0
- package/src/email/advanced/templates.ts +455 -0
- package/src/email/advanced/threading.ts +281 -0
- package/src/email/analytics.ts +467 -0
- package/src/email/bounce-handling.ts +425 -0
- package/src/email/email.test.ts +431 -0
- package/src/email/handlers/__tests__/inbound.test.ts +38 -0
- package/src/email/handlers/__tests__/outbound.test.ts +37 -0
- package/src/email/handlers/converter.ts +227 -0
- package/src/email/handlers/feedback.ts +228 -0
- package/src/email/handlers/inbound.ts +169 -0
- package/src/email/handlers/outbound.ts +178 -0
- package/src/email/index.ts +15 -0
- package/src/email/reputation.ts +303 -0
- package/src/email/templates.ts +352 -0
- package/src/errors/index.test.ts +434 -0
- package/src/errors/index.ts +416 -0
- package/src/health-checks/index.ts +40 -0
- package/src/index.ts +360 -0
- package/src/intrinsic-functions.ts +118 -0
- package/src/lambda/concurrency.ts +330 -0
- package/src/lambda/destinations.ts +345 -0
- package/src/lambda/dlq.ts +425 -0
- package/src/lambda/index.ts +11 -0
- package/src/lambda/lambda.test.ts +840 -0
- package/src/lambda/layers.ts +263 -0
- package/src/lambda/versions.ts +376 -0
- package/src/lambda/vpc.ts +399 -0
- package/src/local/config.ts +114 -0
- package/src/local/index.ts +6 -0
- package/src/local/mock-aws.ts +351 -0
- package/src/modules/ai.ts +340 -0
- package/src/modules/api.ts +478 -0
- package/src/modules/auth.ts +805 -0
- package/src/modules/cache.ts +417 -0
- package/src/modules/cdn.ts +1062 -0
- package/src/modules/communication.ts +1094 -0
- package/src/modules/compute.ts +3348 -0
- package/src/modules/database.ts +554 -0
- package/src/modules/deployment.ts +1079 -0
- package/src/modules/dns.ts +337 -0
- package/src/modules/email.ts +1538 -0
- package/src/modules/filesystem.ts +515 -0
- package/src/modules/index.ts +32 -0
- package/src/modules/messaging.ts +486 -0
- package/src/modules/monitoring.ts +2086 -0
- package/src/modules/network.ts +664 -0
- package/src/modules/parameter-store.ts +325 -0
- package/src/modules/permissions.ts +1081 -0
- package/src/modules/phone.ts +494 -0
- package/src/modules/queue.ts +1260 -0
- package/src/modules/redirects.ts +464 -0
- package/src/modules/registry.ts +699 -0
- package/src/modules/search.ts +401 -0
- package/src/modules/secrets.ts +416 -0
- package/src/modules/security.ts +731 -0
- package/src/modules/sms.ts +389 -0
- package/src/modules/storage.ts +1120 -0
- package/src/modules/workflow.ts +680 -0
- package/src/multi-account/config.ts +521 -0
- package/src/multi-account/index.ts +7 -0
- package/src/multi-account/manager.ts +427 -0
- package/src/multi-region/cross-region.ts +410 -0
- package/src/multi-region/index.ts +8 -0
- package/src/multi-region/manager.ts +483 -0
- package/src/multi-region/regions.ts +435 -0
- package/src/network-security/index.ts +48 -0
- package/src/observability/index.ts +9 -0
- package/src/observability/logs.ts +522 -0
- package/src/observability/metrics.ts +460 -0
- package/src/observability/observability.test.ts +782 -0
- package/src/observability/synthetics.ts +568 -0
- package/src/observability/xray.ts +358 -0
- package/src/phone/advanced/analytics.ts +349 -0
- package/src/phone/advanced/callbacks.ts +428 -0
- package/src/phone/advanced/index.ts +8 -0
- package/src/phone/advanced/ivr-builder.ts +504 -0
- package/src/phone/advanced/recording.ts +310 -0
- package/src/phone/handlers/__tests__/incoming-call.test.ts +40 -0
- package/src/phone/handlers/incoming-call.ts +117 -0
- package/src/phone/handlers/missed-call.ts +116 -0
- package/src/phone/handlers/voicemail.ts +179 -0
- package/src/phone/index.ts +9 -0
- package/src/presets/api-backend.ts +134 -0
- package/src/presets/data-pipeline.ts +204 -0
- package/src/presets/extend.test.ts +295 -0
- package/src/presets/extend.ts +297 -0
- package/src/presets/fullstack-app.ts +144 -0
- package/src/presets/index.ts +27 -0
- package/src/presets/jamstack.ts +135 -0
- package/src/presets/microservices.ts +167 -0
- package/src/presets/ml-api.ts +208 -0
- package/src/presets/nodejs-server.ts +104 -0
- package/src/presets/nodejs-serverless.ts +114 -0
- package/src/presets/realtime-app.ts +184 -0
- package/src/presets/static-site.ts +64 -0
- package/src/presets/traditional-web-app.ts +339 -0
- package/src/presets/wordpress.ts +138 -0
- package/src/preview/github.test.ts +249 -0
- package/src/preview/github.ts +297 -0
- package/src/preview/index.ts +37 -0
- package/src/preview/manager.test.ts +440 -0
- package/src/preview/manager.ts +326 -0
- package/src/preview/notifications.test.ts +582 -0
- package/src/preview/notifications.ts +341 -0
- package/src/queue/batch-processing.ts +402 -0
- package/src/queue/dlq-monitoring.ts +402 -0
- package/src/queue/fifo.ts +342 -0
- package/src/queue/index.ts +9 -0
- package/src/queue/management.ts +428 -0
- package/src/queue/queue.test.ts +429 -0
- package/src/resource-mgmt/index.ts +39 -0
- package/src/resource-naming.ts +62 -0
- package/src/s3/index.ts +523 -0
- package/src/schema/cloud-config.schema.json +554 -0
- package/src/schema/index.ts +68 -0
- package/src/security/certificate-manager.ts +492 -0
- package/src/security/index.ts +9 -0
- package/src/security/scanning.ts +545 -0
- package/src/security/secrets-manager.ts +476 -0
- package/src/security/secrets-rotation.ts +456 -0
- package/src/security/security.test.ts +738 -0
- package/src/sms/advanced/ab-testing.ts +389 -0
- package/src/sms/advanced/analytics.ts +336 -0
- package/src/sms/advanced/campaigns.ts +523 -0
- package/src/sms/advanced/chatbot.ts +224 -0
- package/src/sms/advanced/index.ts +10 -0
- package/src/sms/advanced/link-tracking.ts +248 -0
- package/src/sms/advanced/mms.ts +308 -0
- package/src/sms/handlers/__tests__/send.test.ts +40 -0
- package/src/sms/handlers/delivery-status.ts +133 -0
- package/src/sms/handlers/receive.ts +162 -0
- package/src/sms/handlers/send.ts +174 -0
- package/src/sms/index.ts +9 -0
- package/src/stack-diff.ts +389 -0
- package/src/static-site/index.ts +85 -0
- package/src/template-builder.ts +110 -0
- package/src/template-validator.ts +574 -0
- package/src/utils/cache.ts +291 -0
- package/src/utils/diff.ts +269 -0
- package/src/utils/hash.ts +227 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/parallel.ts +294 -0
- package/src/validators/credentials.test.ts +274 -0
- package/src/validators/credentials.ts +233 -0
- package/src/validators/quotas.test.ts +434 -0
- package/src/validators/quotas.ts +217 -0
- package/test/ai.test.ts +327 -0
- package/test/api.test.ts +511 -0
- package/test/auth.test.ts +632 -0
- package/test/cache.test.ts +406 -0
- package/test/cdn.test.ts +247 -0
- package/test/compute.test.ts +861 -0
- package/test/database.test.ts +523 -0
- package/test/deployment.test.ts +499 -0
- package/test/dns.test.ts +270 -0
- package/test/email.test.ts +439 -0
- package/test/filesystem.test.ts +382 -0
- package/test/integration.test.ts +350 -0
- package/test/messaging.test.ts +514 -0
- package/test/monitoring.test.ts +634 -0
- package/test/network.test.ts +425 -0
- package/test/permissions.test.ts +488 -0
- package/test/queue.test.ts +484 -0
- package/test/registry.test.ts +306 -0
- package/test/security.test.ts +462 -0
- package/test/storage.test.ts +463 -0
- package/test/template-validator.test.ts +559 -0
- package/test/workflow.test.ts +592 -0
- package/tsconfig.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
import { Messaging } from '../src/modules/messaging'
|
|
3
|
+
import { TemplateBuilder } from '../src/template-builder'
|
|
4
|
+
|
|
5
|
+
describe('Messaging Module', () => {
|
|
6
|
+
describe('createTopic', () => {
|
|
7
|
+
it('should create SNS topic with default settings', () => {
|
|
8
|
+
const { topic, logicalId } = Messaging.createTopic({
|
|
9
|
+
slug: 'my-app',
|
|
10
|
+
environment: 'production',
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
expect(topic.Type).toBe('AWS::SNS::Topic')
|
|
14
|
+
expect(topic.Properties?.TopicName).toBeDefined()
|
|
15
|
+
expect(topic.Properties?.DisplayName).toBeDefined()
|
|
16
|
+
expect(topic.Properties?.Tags).toHaveLength(2)
|
|
17
|
+
expect(logicalId).toBeDefined()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('should support custom topic name', () => {
|
|
21
|
+
const { topic } = Messaging.createTopic({
|
|
22
|
+
slug: 'my-app',
|
|
23
|
+
environment: 'production',
|
|
24
|
+
topicName: 'custom-topic',
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
expect(topic.Properties?.TopicName).toBe('custom-topic')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('should support custom display name', () => {
|
|
31
|
+
const { topic } = Messaging.createTopic({
|
|
32
|
+
slug: 'my-app',
|
|
33
|
+
environment: 'production',
|
|
34
|
+
displayName: 'My Custom Topic',
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
expect(topic.Properties?.DisplayName).toBe('My Custom Topic')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('should support KMS encryption', () => {
|
|
41
|
+
const { topic } = Messaging.createTopic({
|
|
42
|
+
slug: 'my-app',
|
|
43
|
+
environment: 'production',
|
|
44
|
+
encrypted: true,
|
|
45
|
+
kmsKeyId: 'arn:aws:kms:us-east-1:123456789:key/abc',
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
expect(topic.Properties?.KmsMasterKeyId).toBe('arn:aws:kms:us-east-1:123456789:key/abc')
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
describe('subscribe', () => {
|
|
53
|
+
it('should create subscription', () => {
|
|
54
|
+
const { subscription, logicalId } = Messaging.subscribe('topic-id', {
|
|
55
|
+
slug: 'my-app',
|
|
56
|
+
environment: 'production',
|
|
57
|
+
protocol: 'email',
|
|
58
|
+
endpoint: 'user@example.com',
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
expect(subscription.Type).toBe('AWS::SNS::Subscription')
|
|
62
|
+
expect(subscription.Properties.Protocol).toBe('email')
|
|
63
|
+
expect(subscription.Properties.Endpoint).toBe('user@example.com')
|
|
64
|
+
expect(subscription.Properties.RawMessageDelivery).toBe(false)
|
|
65
|
+
expect(logicalId).toBeDefined()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('should support filter policy', () => {
|
|
69
|
+
const { subscription } = Messaging.subscribe('topic-id', {
|
|
70
|
+
slug: 'my-app',
|
|
71
|
+
environment: 'production',
|
|
72
|
+
protocol: 'sqs',
|
|
73
|
+
endpoint: 'arn:aws:sqs:us-east-1:123456789:my-queue',
|
|
74
|
+
filterPolicy: {
|
|
75
|
+
eventType: ['order.created', 'order.updated'],
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
expect(subscription.Properties.FilterPolicy).toEqual({
|
|
80
|
+
eventType: ['order.created', 'order.updated'],
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('should support raw message delivery', () => {
|
|
85
|
+
const { subscription } = Messaging.subscribe('topic-id', {
|
|
86
|
+
slug: 'my-app',
|
|
87
|
+
environment: 'production',
|
|
88
|
+
protocol: 'sqs',
|
|
89
|
+
endpoint: 'arn:aws:sqs:us-east-1:123456789:my-queue',
|
|
90
|
+
rawMessageDelivery: true,
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
expect(subscription.Properties.RawMessageDelivery).toBe(true)
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
describe('subscribeEmail', () => {
|
|
98
|
+
it('should create email subscription', () => {
|
|
99
|
+
const { subscription } = Messaging.subscribeEmail('topic-id', 'admin@example.com', {
|
|
100
|
+
slug: 'my-app',
|
|
101
|
+
environment: 'production',
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
expect(subscription.Properties.Protocol).toBe('email')
|
|
105
|
+
expect(subscription.Properties.Endpoint).toBe('admin@example.com')
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('should support filter policy for email', () => {
|
|
109
|
+
const { subscription } = Messaging.subscribeEmail('topic-id', 'admin@example.com', {
|
|
110
|
+
slug: 'my-app',
|
|
111
|
+
environment: 'production',
|
|
112
|
+
filterPolicy: { priority: ['high', 'critical'] },
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
expect(subscription.Properties.FilterPolicy).toEqual({ priority: ['high', 'critical'] })
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
describe('subscribeLambda', () => {
|
|
120
|
+
it('should create Lambda subscription', () => {
|
|
121
|
+
const { subscription } = Messaging.subscribeLambda('topic-id', 'arn:aws:lambda:us-east-1:123456789:function:handler', {
|
|
122
|
+
slug: 'my-app',
|
|
123
|
+
environment: 'production',
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
expect(subscription.Properties.Protocol).toBe('lambda')
|
|
127
|
+
expect(subscription.Properties.Endpoint).toBe('arn:aws:lambda:us-east-1:123456789:function:handler')
|
|
128
|
+
expect(subscription.Properties.RawMessageDelivery).toBe(true)
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
describe('subscribeSqs', () => {
|
|
133
|
+
it('should create SQS subscription', () => {
|
|
134
|
+
const { subscription } = Messaging.subscribeSqs('topic-id', 'arn:aws:sqs:us-east-1:123456789:my-queue', {
|
|
135
|
+
slug: 'my-app',
|
|
136
|
+
environment: 'production',
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
expect(subscription.Properties.Protocol).toBe('sqs')
|
|
140
|
+
expect(subscription.Properties.Endpoint).toBe('arn:aws:sqs:us-east-1:123456789:my-queue')
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('should support raw message delivery for SQS', () => {
|
|
144
|
+
const { subscription } = Messaging.subscribeSqs('topic-id', 'arn:aws:sqs:us-east-1:123456789:my-queue', {
|
|
145
|
+
slug: 'my-app',
|
|
146
|
+
environment: 'production',
|
|
147
|
+
rawMessageDelivery: true,
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
expect(subscription.Properties.RawMessageDelivery).toBe(true)
|
|
151
|
+
})
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
describe('subscribeHttp', () => {
|
|
155
|
+
it('should create HTTP subscription', () => {
|
|
156
|
+
const { subscription } = Messaging.subscribeHttp('topic-id', 'http://example.com/webhook', {
|
|
157
|
+
slug: 'my-app',
|
|
158
|
+
environment: 'production',
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
expect(subscription.Properties.Protocol).toBe('http')
|
|
162
|
+
expect(subscription.Properties.Endpoint).toBe('http://example.com/webhook')
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
it('should create HTTPS subscription', () => {
|
|
166
|
+
const { subscription } = Messaging.subscribeHttp('topic-id', 'https://example.com/webhook', {
|
|
167
|
+
slug: 'my-app',
|
|
168
|
+
environment: 'production',
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
expect(subscription.Properties.Protocol).toBe('https')
|
|
172
|
+
expect(subscription.Properties.Endpoint).toBe('https://example.com/webhook')
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
describe('subscribeSms', () => {
|
|
177
|
+
it('should create SMS subscription', () => {
|
|
178
|
+
const { subscription } = Messaging.subscribeSms('topic-id', '+1234567890', {
|
|
179
|
+
slug: 'my-app',
|
|
180
|
+
environment: 'production',
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
expect(subscription.Properties.Protocol).toBe('sms')
|
|
184
|
+
expect(subscription.Properties.Endpoint).toBe('+1234567890')
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
describe('setTopicPolicy', () => {
|
|
189
|
+
it('should create topic policy for AWS principals', () => {
|
|
190
|
+
const { policy, logicalId } = Messaging.setTopicPolicy('topic-id', {
|
|
191
|
+
slug: 'my-app',
|
|
192
|
+
environment: 'production',
|
|
193
|
+
allowedPrincipals: 'arn:aws:iam::123456789:root',
|
|
194
|
+
actions: 'SNS:Publish',
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
expect(policy.Type).toBe('AWS::SNS::TopicPolicy')
|
|
198
|
+
expect((policy.Properties.PolicyDocument.Statement[0].Principal as any).AWS).toBe('arn:aws:iam::123456789:root')
|
|
199
|
+
expect(policy.Properties.PolicyDocument.Statement[0].Action).toBe('SNS:Publish')
|
|
200
|
+
expect(logicalId).toBeDefined()
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
it('should create topic policy for service principals', () => {
|
|
204
|
+
const { policy } = Messaging.setTopicPolicy('topic-id', {
|
|
205
|
+
slug: 'my-app',
|
|
206
|
+
environment: 'production',
|
|
207
|
+
allowedServices: 'lambda.amazonaws.com',
|
|
208
|
+
actions: 'SNS:Publish',
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
expect((policy.Properties.PolicyDocument.Statement[0].Principal as any).Service).toBe('lambda.amazonaws.com')
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
it('should support multiple principals', () => {
|
|
215
|
+
const { policy } = Messaging.setTopicPolicy('topic-id', {
|
|
216
|
+
slug: 'my-app',
|
|
217
|
+
environment: 'production',
|
|
218
|
+
allowedPrincipals: ['arn:aws:iam::123456789:root', 'arn:aws:iam::987654321:root'],
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
expect((policy.Properties.PolicyDocument.Statement[0].Principal as any).AWS).toEqual([
|
|
222
|
+
'arn:aws:iam::123456789:root',
|
|
223
|
+
'arn:aws:iam::987654321:root',
|
|
224
|
+
])
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
it('should support multiple actions', () => {
|
|
228
|
+
const { policy } = Messaging.setTopicPolicy('topic-id', {
|
|
229
|
+
slug: 'my-app',
|
|
230
|
+
environment: 'production',
|
|
231
|
+
allowedServices: 's3.amazonaws.com',
|
|
232
|
+
actions: ['SNS:Publish', 'SNS:Subscribe'],
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
expect(policy.Properties.PolicyDocument.Statement[0].Action).toEqual(['SNS:Publish', 'SNS:Subscribe'])
|
|
236
|
+
})
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
describe('allowCloudWatchAlarms', () => {
|
|
240
|
+
it('should create policy for CloudWatch Alarms', () => {
|
|
241
|
+
const { policy } = Messaging.allowCloudWatchAlarms('topic-id', {
|
|
242
|
+
slug: 'my-app',
|
|
243
|
+
environment: 'production',
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
expect((policy.Properties.PolicyDocument.Statement[0].Principal as any).Service).toBe('cloudwatch.amazonaws.com')
|
|
247
|
+
expect(policy.Properties.PolicyDocument.Statement[0].Action).toBe('SNS:Publish')
|
|
248
|
+
})
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
describe('allowEventBridge', () => {
|
|
252
|
+
it('should create policy for EventBridge', () => {
|
|
253
|
+
const { policy } = Messaging.allowEventBridge('topic-id', {
|
|
254
|
+
slug: 'my-app',
|
|
255
|
+
environment: 'production',
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
expect((policy.Properties.PolicyDocument.Statement[0].Principal as any).Service).toBe('events.amazonaws.com')
|
|
259
|
+
})
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
describe('allowS3', () => {
|
|
263
|
+
it('should create policy for S3', () => {
|
|
264
|
+
const { policy } = Messaging.allowS3('topic-id', {
|
|
265
|
+
slug: 'my-app',
|
|
266
|
+
environment: 'production',
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
expect((policy.Properties.PolicyDocument.Statement[0].Principal as any).Service).toBe('s3.amazonaws.com')
|
|
270
|
+
})
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
describe('enableEncryption', () => {
|
|
274
|
+
it('should enable encryption on topic', () => {
|
|
275
|
+
const { topic } = Messaging.createTopic({
|
|
276
|
+
slug: 'my-app',
|
|
277
|
+
environment: 'production',
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
Messaging.enableEncryption(topic, 'arn:aws:kms:us-east-1:123456789:key/abc')
|
|
281
|
+
|
|
282
|
+
expect(topic.Properties?.KmsMasterKeyId).toBe('arn:aws:kms:us-east-1:123456789:key/abc')
|
|
283
|
+
})
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
describe('addInlineSubscription', () => {
|
|
287
|
+
it('should add inline subscription to topic', () => {
|
|
288
|
+
const { topic } = Messaging.createTopic({
|
|
289
|
+
slug: 'my-app',
|
|
290
|
+
environment: 'production',
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
Messaging.addInlineSubscription(topic, 'email', 'user@example.com')
|
|
294
|
+
|
|
295
|
+
expect(topic.Properties?.Subscription).toHaveLength(1)
|
|
296
|
+
expect(topic.Properties?.Subscription![0].Protocol).toBe('email')
|
|
297
|
+
expect(topic.Properties?.Subscription![0].Endpoint).toBe('user@example.com')
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
it('should add multiple inline subscriptions', () => {
|
|
301
|
+
const { topic } = Messaging.createTopic({
|
|
302
|
+
slug: 'my-app',
|
|
303
|
+
environment: 'production',
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
Messaging.addInlineSubscription(topic, 'email', 'user1@example.com')
|
|
307
|
+
Messaging.addInlineSubscription(topic, 'email', 'user2@example.com')
|
|
308
|
+
|
|
309
|
+
expect(topic.Properties?.Subscription).toHaveLength(2)
|
|
310
|
+
})
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
describe('FilterPolicies', () => {
|
|
314
|
+
it('should create event type filter', () => {
|
|
315
|
+
const filter = Messaging.FilterPolicies.eventType(['order.created', 'order.updated'])
|
|
316
|
+
|
|
317
|
+
expect(filter).toEqual({
|
|
318
|
+
eventType: ['order.created', 'order.updated'],
|
|
319
|
+
})
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
it('should create status filter', () => {
|
|
323
|
+
const filter = Messaging.FilterPolicies.status(['success', 'failed'])
|
|
324
|
+
|
|
325
|
+
expect(filter).toEqual({
|
|
326
|
+
status: ['success', 'failed'],
|
|
327
|
+
})
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
it('should create numeric range filter', () => {
|
|
331
|
+
const filter = Messaging.FilterPolicies.numericRange('price', 10, 100)
|
|
332
|
+
|
|
333
|
+
expect(filter).toEqual({
|
|
334
|
+
price: [{ numeric: ['>=', 10, '<=', 100] }],
|
|
335
|
+
})
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
it('should create prefix filter', () => {
|
|
339
|
+
const filter = Messaging.FilterPolicies.prefix('eventType', 'order.')
|
|
340
|
+
|
|
341
|
+
expect(filter).toEqual({
|
|
342
|
+
eventType: [{ prefix: 'order.' }],
|
|
343
|
+
})
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
it('should create exists filter', () => {
|
|
347
|
+
const filter = Messaging.FilterPolicies.exists('userId', true)
|
|
348
|
+
|
|
349
|
+
expect(filter).toEqual({
|
|
350
|
+
userId: [{ exists: true }],
|
|
351
|
+
})
|
|
352
|
+
})
|
|
353
|
+
|
|
354
|
+
it('should combine multiple filters with AND', () => {
|
|
355
|
+
const filter = Messaging.FilterPolicies.and(
|
|
356
|
+
Messaging.FilterPolicies.eventType(['order.created']),
|
|
357
|
+
Messaging.FilterPolicies.status(['success']),
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
expect(filter).toEqual({
|
|
361
|
+
eventType: ['order.created'],
|
|
362
|
+
status: ['success'],
|
|
363
|
+
})
|
|
364
|
+
})
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
describe('UseCases', () => {
|
|
368
|
+
it('should create alert topic', () => {
|
|
369
|
+
const { topic } = Messaging.UseCases.createAlertTopic({
|
|
370
|
+
slug: 'my-app',
|
|
371
|
+
environment: 'production',
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
expect(topic.Properties?.TopicName).toContain('alerts')
|
|
375
|
+
expect(topic.Properties?.DisplayName).toBe('Alert Notifications')
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
it('should create event fanout topic', () => {
|
|
379
|
+
const { topic } = Messaging.UseCases.createEventFanout({
|
|
380
|
+
slug: 'my-app',
|
|
381
|
+
environment: 'production',
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
expect(topic.Properties?.TopicName).toContain('events')
|
|
385
|
+
expect(topic.Properties?.DisplayName).toBe('Event Fanout')
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
it('should create notification topic', () => {
|
|
389
|
+
const { topic } = Messaging.UseCases.createNotificationTopic({
|
|
390
|
+
slug: 'my-app',
|
|
391
|
+
environment: 'production',
|
|
392
|
+
})
|
|
393
|
+
|
|
394
|
+
expect(topic.Properties?.TopicName).toContain('notifications')
|
|
395
|
+
expect(topic.Properties?.DisplayName).toBe('User Notifications')
|
|
396
|
+
})
|
|
397
|
+
})
|
|
398
|
+
|
|
399
|
+
describe('Integration with TemplateBuilder', () => {
|
|
400
|
+
it('should create topic with multiple subscriptions', () => {
|
|
401
|
+
const template = new TemplateBuilder('SNS Topic with Subscriptions')
|
|
402
|
+
|
|
403
|
+
// Create topic
|
|
404
|
+
const { topic, logicalId: topicId } = Messaging.createTopic({
|
|
405
|
+
slug: 'my-app',
|
|
406
|
+
environment: 'production',
|
|
407
|
+
})
|
|
408
|
+
|
|
409
|
+
// Add subscriptions
|
|
410
|
+
const { subscription: emailSub, logicalId: emailSubId } = Messaging.subscribeEmail(topicId, 'admin@example.com', {
|
|
411
|
+
slug: 'my-app',
|
|
412
|
+
environment: 'production',
|
|
413
|
+
})
|
|
414
|
+
|
|
415
|
+
const { subscription: lambdaSub, logicalId: lambdaSubId } = Messaging.subscribeLambda(
|
|
416
|
+
topicId,
|
|
417
|
+
'arn:aws:lambda:us-east-1:123456789:function:handler',
|
|
418
|
+
{
|
|
419
|
+
slug: 'my-app',
|
|
420
|
+
environment: 'production',
|
|
421
|
+
},
|
|
422
|
+
)
|
|
423
|
+
|
|
424
|
+
template.addResource(topicId, topic)
|
|
425
|
+
template.addResource(emailSubId, emailSub)
|
|
426
|
+
template.addResource(lambdaSubId, lambdaSub)
|
|
427
|
+
|
|
428
|
+
const result = template.build()
|
|
429
|
+
|
|
430
|
+
expect(Object.keys(result.Resources)).toHaveLength(3)
|
|
431
|
+
expect(result.Resources[topicId].Type).toBe('AWS::SNS::Topic')
|
|
432
|
+
expect(result.Resources[emailSubId].Type).toBe('AWS::SNS::Subscription')
|
|
433
|
+
expect(result.Resources[lambdaSubId].Type).toBe('AWS::SNS::Subscription')
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
it('should create fanout pattern (SNS to multiple SQS)', () => {
|
|
437
|
+
const template = new TemplateBuilder('Event Fanout')
|
|
438
|
+
|
|
439
|
+
const { topic, logicalId: topicId } = Messaging.UseCases.createEventFanout({
|
|
440
|
+
slug: 'my-app',
|
|
441
|
+
environment: 'production',
|
|
442
|
+
})
|
|
443
|
+
|
|
444
|
+
const { subscription: queue1Sub, logicalId: queue1SubId } = Messaging.subscribeSqs(
|
|
445
|
+
topicId,
|
|
446
|
+
'arn:aws:sqs:us-east-1:123456789:queue1',
|
|
447
|
+
{
|
|
448
|
+
slug: 'my-app',
|
|
449
|
+
environment: 'production',
|
|
450
|
+
filterPolicy: Messaging.FilterPolicies.eventType(['order.created']),
|
|
451
|
+
},
|
|
452
|
+
)
|
|
453
|
+
|
|
454
|
+
const { subscription: queue2Sub, logicalId: queue2SubId } = Messaging.subscribeSqs(
|
|
455
|
+
topicId,
|
|
456
|
+
'arn:aws:sqs:us-east-1:123456789:queue2',
|
|
457
|
+
{
|
|
458
|
+
slug: 'my-app',
|
|
459
|
+
environment: 'production',
|
|
460
|
+
filterPolicy: Messaging.FilterPolicies.eventType(['order.updated']),
|
|
461
|
+
},
|
|
462
|
+
)
|
|
463
|
+
|
|
464
|
+
template.addResource(topicId, topic)
|
|
465
|
+
template.addResource(queue1SubId, queue1Sub)
|
|
466
|
+
template.addResource(queue2SubId, queue2Sub)
|
|
467
|
+
|
|
468
|
+
const result = template.build()
|
|
469
|
+
|
|
470
|
+
expect(Object.keys(result.Resources)).toHaveLength(3)
|
|
471
|
+
expect(result.Resources[queue1SubId]!.Properties!.FilterPolicy).toBeDefined()
|
|
472
|
+
expect(result.Resources[queue2SubId]!.Properties!.FilterPolicy).toBeDefined()
|
|
473
|
+
})
|
|
474
|
+
|
|
475
|
+
it('should create topic with policy', () => {
|
|
476
|
+
const template = new TemplateBuilder('Topic with Policy')
|
|
477
|
+
|
|
478
|
+
const { topic, logicalId: topicId } = Messaging.createTopic({
|
|
479
|
+
slug: 'my-app',
|
|
480
|
+
environment: 'production',
|
|
481
|
+
})
|
|
482
|
+
|
|
483
|
+
const { policy, logicalId: policyId } = Messaging.allowCloudWatchAlarms(topicId, {
|
|
484
|
+
slug: 'my-app',
|
|
485
|
+
environment: 'production',
|
|
486
|
+
})
|
|
487
|
+
|
|
488
|
+
template.addResource(topicId, topic)
|
|
489
|
+
template.addResource(policyId, policy)
|
|
490
|
+
|
|
491
|
+
const result = template.build()
|
|
492
|
+
|
|
493
|
+
expect(Object.keys(result.Resources)).toHaveLength(2)
|
|
494
|
+
expect(result.Resources[policyId].Type).toBe('AWS::SNS::TopicPolicy')
|
|
495
|
+
})
|
|
496
|
+
|
|
497
|
+
it('should generate valid JSON template', () => {
|
|
498
|
+
const template = new TemplateBuilder('Messaging Test')
|
|
499
|
+
|
|
500
|
+
const { topic, logicalId } = Messaging.createTopic({
|
|
501
|
+
slug: 'test',
|
|
502
|
+
environment: 'development',
|
|
503
|
+
})
|
|
504
|
+
|
|
505
|
+
template.addResource(logicalId, topic)
|
|
506
|
+
|
|
507
|
+
const json = template.toJSON()
|
|
508
|
+
const parsed = JSON.parse(json)
|
|
509
|
+
|
|
510
|
+
expect(parsed.Resources[logicalId].Type).toBe('AWS::SNS::Topic')
|
|
511
|
+
expect(parsed.Resources[logicalId].Properties.TopicName).toBeDefined()
|
|
512
|
+
})
|
|
513
|
+
})
|
|
514
|
+
})
|