@stacksjs/ts-cloud 0.1.9 → 0.1.14

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.
Files changed (150) hide show
  1. package/README.md +39 -377
  2. package/dist/bin/cli.js +1047 -424
  3. package/dist/index.d.ts +36 -3
  4. package/dist/index.js +76430 -7096
  5. package/package.json +7 -8
  6. package/dist/aws/acm.d.ts +0 -129
  7. package/dist/aws/application-autoscaling.d.ts +0 -282
  8. package/dist/aws/bedrock.d.ts +0 -2292
  9. package/dist/aws/client.d.ts +0 -79
  10. package/dist/aws/cloudformation.d.ts +0 -105
  11. package/dist/aws/cloudfront.d.ts +0 -265
  12. package/dist/aws/cloudwatch-logs.d.ts +0 -48
  13. package/dist/aws/comprehend.d.ts +0 -505
  14. package/dist/aws/connect.d.ts +0 -377
  15. package/dist/aws/deploy-imap.d.ts +0 -14
  16. package/dist/aws/dynamodb.d.ts +0 -176
  17. package/dist/aws/ec2.d.ts +0 -272
  18. package/dist/aws/ecr.d.ts +0 -149
  19. package/dist/aws/ecs.d.ts +0 -162
  20. package/dist/aws/elasticache.d.ts +0 -71
  21. package/dist/aws/elbv2.d.ts +0 -248
  22. package/dist/aws/email.d.ts +0 -175
  23. package/dist/aws/eventbridge.d.ts +0 -142
  24. package/dist/aws/iam.d.ts +0 -638
  25. package/dist/aws/imap-server.d.ts +0 -119
  26. package/dist/aws/index.d.ts +0 -192
  27. package/dist/aws/kendra.d.ts +0 -782
  28. package/dist/aws/lambda.d.ts +0 -232
  29. package/dist/aws/opensearch.d.ts +0 -87
  30. package/dist/aws/personalize.d.ts +0 -516
  31. package/dist/aws/polly.d.ts +0 -214
  32. package/dist/aws/rds.d.ts +0 -240
  33. package/dist/aws/rekognition.d.ts +0 -543
  34. package/dist/aws/route53-domains.d.ts +0 -113
  35. package/dist/aws/route53.d.ts +0 -215
  36. package/dist/aws/s3.d.ts +0 -212
  37. package/dist/aws/scheduler.d.ts +0 -140
  38. package/dist/aws/secrets-manager.d.ts +0 -170
  39. package/dist/aws/ses.d.ts +0 -288
  40. package/dist/aws/setup-phone.d.ts +0 -0
  41. package/dist/aws/setup-sms.d.ts +0 -115
  42. package/dist/aws/sms.d.ts +0 -304
  43. package/dist/aws/smtp-server.d.ts +0 -61
  44. package/dist/aws/sns.d.ts +0 -117
  45. package/dist/aws/sqs.d.ts +0 -65
  46. package/dist/aws/ssm.d.ts +0 -179
  47. package/dist/aws/sts.d.ts +0 -15
  48. package/dist/aws/support.d.ts +0 -104
  49. package/dist/aws/test-imap.d.ts +0 -0
  50. package/dist/aws/textract.d.ts +0 -403
  51. package/dist/aws/transcribe.d.ts +0 -60
  52. package/dist/aws/translate.d.ts +0 -358
  53. package/dist/aws/voice.d.ts +0 -219
  54. package/dist/config.d.ts +0 -7
  55. package/dist/deploy/index.d.ts +0 -2
  56. package/dist/deploy/static-site-external-dns.d.ts +0 -51
  57. package/dist/deploy/static-site.d.ts +0 -71
  58. package/dist/dns/cloudflare.d.ts +0 -52
  59. package/dist/dns/godaddy.d.ts +0 -38
  60. package/dist/dns/index.d.ts +0 -45
  61. package/dist/dns/porkbun.d.ts +0 -18
  62. package/dist/dns/route53-adapter.d.ts +0 -38
  63. package/dist/dns/types.d.ts +0 -77
  64. package/dist/dns/validator.d.ts +0 -78
  65. package/dist/generators/index.d.ts +0 -1
  66. package/dist/generators/infrastructure.d.ts +0 -30
  67. package/dist/push/apns.d.ts +0 -60
  68. package/dist/push/fcm.d.ts +0 -117
  69. package/dist/push/index.d.ts +0 -14
  70. package/dist/security/pre-deploy-scanner.d.ts +0 -69
  71. package/dist/ssl/acme-client.d.ts +0 -67
  72. package/dist/ssl/index.d.ts +0 -2
  73. package/dist/ssl/letsencrypt.d.ts +0 -48
  74. package/dist/types.d.ts +0 -1
  75. package/dist/utils/cli.d.ts +0 -123
  76. package/dist/validation/index.d.ts +0 -1
  77. package/dist/validation/template.d.ts +0 -23
  78. package/src/aws/acm.ts +0 -768
  79. package/src/aws/application-autoscaling.ts +0 -845
  80. package/src/aws/bedrock.ts +0 -4074
  81. package/src/aws/client.ts +0 -891
  82. package/src/aws/cloudformation.ts +0 -896
  83. package/src/aws/cloudfront.ts +0 -1531
  84. package/src/aws/cloudwatch-logs.ts +0 -154
  85. package/src/aws/comprehend.ts +0 -839
  86. package/src/aws/connect.ts +0 -1056
  87. package/src/aws/deploy-imap.ts +0 -384
  88. package/src/aws/dynamodb.ts +0 -340
  89. package/src/aws/ec2.ts +0 -1385
  90. package/src/aws/ecr.ts +0 -621
  91. package/src/aws/ecs.ts +0 -615
  92. package/src/aws/elasticache.ts +0 -301
  93. package/src/aws/elbv2.ts +0 -942
  94. package/src/aws/email.ts +0 -928
  95. package/src/aws/eventbridge.ts +0 -248
  96. package/src/aws/iam.ts +0 -1689
  97. package/src/aws/imap-server.ts +0 -2100
  98. package/src/aws/index.ts +0 -213
  99. package/src/aws/kendra.ts +0 -1097
  100. package/src/aws/lambda.ts +0 -786
  101. package/src/aws/opensearch.ts +0 -158
  102. package/src/aws/personalize.ts +0 -977
  103. package/src/aws/polly.ts +0 -559
  104. package/src/aws/rds.ts +0 -888
  105. package/src/aws/rekognition.ts +0 -846
  106. package/src/aws/route53-domains.ts +0 -359
  107. package/src/aws/route53.ts +0 -1046
  108. package/src/aws/s3.ts +0 -2334
  109. package/src/aws/scheduler.ts +0 -571
  110. package/src/aws/secrets-manager.ts +0 -769
  111. package/src/aws/ses.ts +0 -1081
  112. package/src/aws/setup-phone.ts +0 -104
  113. package/src/aws/setup-sms.ts +0 -580
  114. package/src/aws/sms.ts +0 -1735
  115. package/src/aws/smtp-server.ts +0 -531
  116. package/src/aws/sns.ts +0 -758
  117. package/src/aws/sqs.ts +0 -382
  118. package/src/aws/ssm.ts +0 -807
  119. package/src/aws/sts.ts +0 -92
  120. package/src/aws/support.ts +0 -391
  121. package/src/aws/test-imap.ts +0 -86
  122. package/src/aws/textract.ts +0 -780
  123. package/src/aws/transcribe.ts +0 -108
  124. package/src/aws/translate.ts +0 -641
  125. package/src/aws/voice.ts +0 -1379
  126. package/src/config.ts +0 -35
  127. package/src/deploy/index.ts +0 -7
  128. package/src/deploy/static-site-external-dns.ts +0 -945
  129. package/src/deploy/static-site.ts +0 -1175
  130. package/src/dns/cloudflare.ts +0 -548
  131. package/src/dns/godaddy.ts +0 -412
  132. package/src/dns/index.ts +0 -205
  133. package/src/dns/porkbun.ts +0 -362
  134. package/src/dns/route53-adapter.ts +0 -414
  135. package/src/dns/types.ts +0 -119
  136. package/src/dns/validator.ts +0 -369
  137. package/src/generators/index.ts +0 -5
  138. package/src/generators/infrastructure.ts +0 -1660
  139. package/src/index.ts +0 -163
  140. package/src/push/apns.ts +0 -452
  141. package/src/push/fcm.ts +0 -506
  142. package/src/push/index.ts +0 -58
  143. package/src/security/pre-deploy-scanner.ts +0 -655
  144. package/src/ssl/acme-client.ts +0 -478
  145. package/src/ssl/index.ts +0 -7
  146. package/src/ssl/letsencrypt.ts +0 -747
  147. package/src/types.ts +0 -2
  148. package/src/utils/cli.ts +0 -398
  149. package/src/validation/index.ts +0 -5
  150. package/src/validation/template.ts +0 -405
@@ -1,405 +0,0 @@
1
- /**
2
- * CloudFormation Template Validation
3
- * Validates templates before deployment
4
- */
5
-
6
- import type { CloudFormationTemplate } from '@stacksjs/ts-cloud-aws-types'
7
-
8
- export interface ValidationError {
9
- path: string
10
- message: string
11
- severity: 'error' | 'warning'
12
- }
13
-
14
- export interface ValidationResult {
15
- valid: boolean
16
- errors: ValidationError[]
17
- warnings: ValidationError[]
18
- }
19
-
20
- /**
21
- * Validate a CloudFormation template
22
- */
23
- export function validateTemplate(template: CloudFormationTemplate): ValidationResult {
24
- const errors: ValidationError[] = []
25
- const warnings: ValidationError[] = []
26
-
27
- // Check required fields
28
- if (!template.AWSTemplateFormatVersion) {
29
- errors.push({
30
- path: 'AWSTemplateFormatVersion',
31
- message: 'AWSTemplateFormatVersion is required',
32
- severity: 'error',
33
- })
34
- }
35
- else if (template.AWSTemplateFormatVersion !== '2010-09-09') {
36
- warnings.push({
37
- path: 'AWSTemplateFormatVersion',
38
- message: 'AWSTemplateFormatVersion should be "2010-09-09"',
39
- severity: 'warning',
40
- })
41
- }
42
-
43
- // Check Resources section
44
- if (!template.Resources || Object.keys(template.Resources).length === 0) {
45
- errors.push({
46
- path: 'Resources',
47
- message: 'At least one resource is required',
48
- severity: 'error',
49
- })
50
- }
51
- else {
52
- // Validate each resource
53
- for (const [logicalId, resource] of Object.entries(template.Resources)) {
54
- validateResource(logicalId, resource, errors, warnings)
55
- }
56
- }
57
-
58
- // Check for circular dependencies
59
- if (template.Resources) {
60
- const circularDeps = findCircularDependencies(template.Resources)
61
- if (circularDeps.length > 0) {
62
- errors.push({
63
- path: 'Resources',
64
- message: `Circular dependencies detected: ${circularDeps.join(' -> ')}`,
65
- severity: 'error',
66
- })
67
- }
68
- }
69
-
70
- // Validate Parameters if present
71
- if (template.Parameters) {
72
- for (const [paramName, param] of Object.entries(template.Parameters)) {
73
- validateParameter(paramName, param, errors, warnings)
74
- }
75
- }
76
-
77
- // Validate Outputs if present
78
- if (template.Outputs) {
79
- for (const [outputName, output] of Object.entries(template.Outputs)) {
80
- validateOutput(outputName, output, errors, warnings)
81
- }
82
- }
83
-
84
- return {
85
- valid: errors.length === 0,
86
- errors,
87
- warnings,
88
- }
89
- }
90
-
91
- /**
92
- * Validate a single resource
93
- */
94
- function validateResource(
95
- logicalId: string,
96
- resource: any,
97
- errors: ValidationError[],
98
- warnings: ValidationError[],
99
- ): void {
100
- // Check required fields
101
- if (!resource.Type) {
102
- errors.push({
103
- path: `Resources.${logicalId}.Type`,
104
- message: 'Resource Type is required',
105
- severity: 'error',
106
- })
107
- }
108
-
109
- // Check logical ID format
110
- if (!/^[a-zA-Z0-9]+$/.test(logicalId)) {
111
- warnings.push({
112
- path: `Resources.${logicalId}`,
113
- message: 'Logical ID should only contain alphanumeric characters',
114
- severity: 'warning',
115
- })
116
- }
117
-
118
- // Validate resource type format
119
- if (resource.Type && !resource.Type.startsWith('AWS::') && !resource.Type.startsWith('Custom::')) {
120
- errors.push({
121
- path: `Resources.${logicalId}.Type`,
122
- message: 'Resource Type must start with "AWS::" or "Custom::"',
123
- severity: 'error',
124
- })
125
- }
126
-
127
- // Check for common mistakes
128
- if (resource.Properties) {
129
- // Check for undefined or null values
130
- for (const [propName, propValue] of Object.entries(resource.Properties)) {
131
- if (propValue === undefined || propValue === null) {
132
- warnings.push({
133
- path: `Resources.${logicalId}.Properties.${propName}`,
134
- message: 'Property has undefined or null value',
135
- severity: 'warning',
136
- })
137
- }
138
- }
139
- }
140
-
141
- // Validate DependsOn
142
- if (resource.DependsOn) {
143
- if (typeof resource.DependsOn === 'string') {
144
- if (resource.DependsOn === logicalId) {
145
- errors.push({
146
- path: `Resources.${logicalId}.DependsOn`,
147
- message: 'Resource cannot depend on itself',
148
- severity: 'error',
149
- })
150
- }
151
- }
152
- else if (Array.isArray(resource.DependsOn)) {
153
- if (resource.DependsOn.includes(logicalId)) {
154
- errors.push({
155
- path: `Resources.${logicalId}.DependsOn`,
156
- message: 'Resource cannot depend on itself',
157
- severity: 'error',
158
- })
159
- }
160
- }
161
- }
162
- }
163
-
164
- /**
165
- * Validate a parameter
166
- */
167
- function validateParameter(
168
- paramName: string,
169
- param: any,
170
- errors: ValidationError[],
171
- warnings: ValidationError[],
172
- ): void {
173
- if (!param.Type) {
174
- errors.push({
175
- path: `Parameters.${paramName}.Type`,
176
- message: 'Parameter Type is required',
177
- severity: 'error',
178
- })
179
- }
180
-
181
- const validTypes = ['String', 'Number', 'List<Number>', 'CommaDelimitedList', 'AWS::SSM::Parameter::Value<String>']
182
- if (param.Type && !validTypes.includes(param.Type) && !param.Type.startsWith('AWS::')) {
183
- warnings.push({
184
- path: `Parameters.${paramName}.Type`,
185
- message: `Uncommon parameter type: ${param.Type}`,
186
- severity: 'warning',
187
- })
188
- }
189
-
190
- // Check for default value with NoEcho
191
- if (param.NoEcho && param.Default) {
192
- warnings.push({
193
- path: `Parameters.${paramName}`,
194
- message: 'NoEcho parameters should not have default values',
195
- severity: 'warning',
196
- })
197
- }
198
- }
199
-
200
- /**
201
- * Validate an output
202
- */
203
- function validateOutput(
204
- outputName: string,
205
- output: any,
206
- errors: ValidationError[],
207
- warnings: ValidationError[],
208
- ): void {
209
- if (!output.Value) {
210
- errors.push({
211
- path: `Outputs.${outputName}.Value`,
212
- message: 'Output Value is required',
213
- severity: 'error',
214
- })
215
- }
216
- }
217
-
218
- /**
219
- * Find circular dependencies in resources
220
- */
221
- function findCircularDependencies(resources: Record<string, any>): string[] {
222
- const graph: Record<string, string[]> = {}
223
-
224
- // Build dependency graph
225
- for (const [logicalId, resource] of Object.entries(resources)) {
226
- graph[logicalId] = []
227
-
228
- // Explicit dependencies (DependsOn)
229
- if (resource.DependsOn) {
230
- if (typeof resource.DependsOn === 'string') {
231
- graph[logicalId].push(resource.DependsOn)
232
- }
233
- else if (Array.isArray(resource.DependsOn)) {
234
- graph[logicalId].push(...resource.DependsOn)
235
- }
236
- }
237
-
238
- // Implicit dependencies (Ref, GetAtt)
239
- const deps = extractDependencies(resource)
240
- graph[logicalId].push(...deps)
241
- }
242
-
243
- // Detect cycles using DFS
244
- const visited = new Set<string>()
245
- const recursionStack = new Set<string>()
246
- const cycle: string[] = []
247
-
248
- function dfs(node: string, path: string[]): boolean {
249
- visited.add(node)
250
- recursionStack.add(node)
251
- path.push(node)
252
-
253
- const neighbors = graph[node] || []
254
- for (const neighbor of neighbors) {
255
- if (!visited.has(neighbor)) {
256
- if (dfs(neighbor, path)) {
257
- return true
258
- }
259
- }
260
- else if (recursionStack.has(neighbor)) {
261
- // Cycle detected
262
- const cycleStart = path.indexOf(neighbor)
263
- cycle.push(...path.slice(cycleStart), neighbor)
264
- return true
265
- }
266
- }
267
-
268
- path.pop()
269
- recursionStack.delete(node)
270
- return false
271
- }
272
-
273
- for (const node of Object.keys(graph)) {
274
- if (!visited.has(node)) {
275
- if (dfs(node, [])) {
276
- return cycle
277
- }
278
- }
279
- }
280
-
281
- return []
282
- }
283
-
284
- /**
285
- * Extract dependencies from a resource (Ref, GetAtt, etc.)
286
- */
287
- function extractDependencies(obj: any, deps: string[] = []): string[] {
288
- if (typeof obj !== 'object' || obj === null) {
289
- return deps
290
- }
291
-
292
- if (Array.isArray(obj)) {
293
- for (const item of obj) {
294
- extractDependencies(item, deps)
295
- }
296
- return deps
297
- }
298
-
299
- // Check for Ref
300
- if (obj.Ref && typeof obj.Ref === 'string' && !obj.Ref.startsWith('AWS::')) {
301
- deps.push(obj.Ref)
302
- }
303
-
304
- // Check for GetAtt
305
- if (obj['Fn::GetAtt']) {
306
- const getAtt = obj['Fn::GetAtt']
307
- if (Array.isArray(getAtt) && getAtt.length > 0) {
308
- deps.push(getAtt[0])
309
- }
310
- }
311
-
312
- // Recurse into object properties
313
- for (const value of Object.values(obj)) {
314
- extractDependencies(value, deps)
315
- }
316
-
317
- return deps
318
- }
319
-
320
- /**
321
- * Validate template size
322
- */
323
- export function validateTemplateSize(templateBody: string): ValidationResult {
324
- const errors: ValidationError[] = []
325
- const warnings: ValidationError[] = []
326
-
327
- const sizeInBytes = new TextEncoder().encode(templateBody).length
328
-
329
- // CloudFormation limits
330
- const maxBodySize = 51200 // 51,200 bytes (50 KB)
331
- const maxS3Size = 460800 // 460,800 bytes (450 KB)
332
-
333
- if (sizeInBytes > maxBodySize) {
334
- if (sizeInBytes > maxS3Size) {
335
- errors.push({
336
- path: 'template',
337
- message: `Template size (${sizeInBytes} bytes) exceeds maximum allowed size of ${maxS3Size} bytes`,
338
- severity: 'error',
339
- })
340
- }
341
- else {
342
- warnings.push({
343
- path: 'template',
344
- message: `Template size (${sizeInBytes} bytes) exceeds direct upload limit (${maxBodySize} bytes). You must upload to S3 first.`,
345
- severity: 'warning',
346
- })
347
- }
348
- }
349
-
350
- return {
351
- valid: errors.length === 0,
352
- errors,
353
- warnings,
354
- }
355
- }
356
-
357
- /**
358
- * Validate template resource limits
359
- */
360
- export function validateResourceLimits(template: CloudFormationTemplate): ValidationResult {
361
- const errors: ValidationError[] = []
362
- const warnings: ValidationError[] = []
363
-
364
- const resourceCount = template.Resources ? Object.keys(template.Resources).length : 0
365
- const parameterCount = template.Parameters ? Object.keys(template.Parameters).length : 0
366
- const outputCount = template.Outputs ? Object.keys(template.Outputs).length : 0
367
-
368
- // CloudFormation limits
369
- if (resourceCount > 500) {
370
- errors.push({
371
- path: 'Resources',
372
- message: `Template has ${resourceCount} resources, exceeding the limit of 500`,
373
- severity: 'error',
374
- })
375
- }
376
- else if (resourceCount > 200) {
377
- warnings.push({
378
- path: 'Resources',
379
- message: `Template has ${resourceCount} resources. Consider using nested stacks for better organization.`,
380
- severity: 'warning',
381
- })
382
- }
383
-
384
- if (parameterCount > 200) {
385
- errors.push({
386
- path: 'Parameters',
387
- message: `Template has ${parameterCount} parameters, exceeding the limit of 200`,
388
- severity: 'error',
389
- })
390
- }
391
-
392
- if (outputCount > 200) {
393
- errors.push({
394
- path: 'Outputs',
395
- message: `Template has ${outputCount} outputs, exceeding the limit of 200`,
396
- severity: 'error',
397
- })
398
- }
399
-
400
- return {
401
- valid: errors.length === 0,
402
- errors,
403
- warnings,
404
- }
405
- }