@stacksjs/ts-cloud-core 0.1.2 → 0.1.6

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 (250) hide show
  1. package/README.md +98 -13
  2. package/package.json +12 -3
  3. package/src/advanced-features.test.ts +0 -465
  4. package/src/aws/cloudformation.ts +0 -421
  5. package/src/aws/cloudfront.ts +0 -158
  6. package/src/aws/credentials.test.ts +0 -132
  7. package/src/aws/credentials.ts +0 -545
  8. package/src/aws/index.ts +0 -87
  9. package/src/aws/s3.test.ts +0 -188
  10. package/src/aws/s3.ts +0 -1088
  11. package/src/aws/signature.test.ts +0 -670
  12. package/src/aws/signature.ts +0 -1155
  13. package/src/backup/disaster-recovery.test.ts +0 -726
  14. package/src/backup/disaster-recovery.ts +0 -500
  15. package/src/backup/index.ts +0 -34
  16. package/src/backup/manager.test.ts +0 -498
  17. package/src/backup/manager.ts +0 -432
  18. package/src/cicd/circleci.ts +0 -430
  19. package/src/cicd/github-actions.ts +0 -424
  20. package/src/cicd/gitlab-ci.ts +0 -255
  21. package/src/cicd/index.ts +0 -8
  22. package/src/cli/history.ts +0 -396
  23. package/src/cli/index.ts +0 -10
  24. package/src/cli/progress.ts +0 -458
  25. package/src/cli/repl.ts +0 -454
  26. package/src/cli/suggestions.ts +0 -327
  27. package/src/cli/table.test.ts +0 -319
  28. package/src/cli/table.ts +0 -332
  29. package/src/cloudformation/builder.test.ts +0 -327
  30. package/src/cloudformation/builder.ts +0 -378
  31. package/src/cloudformation/builders/api-gateway.ts +0 -449
  32. package/src/cloudformation/builders/cache.ts +0 -334
  33. package/src/cloudformation/builders/cdn.ts +0 -278
  34. package/src/cloudformation/builders/compute.ts +0 -485
  35. package/src/cloudformation/builders/database.ts +0 -392
  36. package/src/cloudformation/builders/functions.ts +0 -343
  37. package/src/cloudformation/builders/messaging.ts +0 -140
  38. package/src/cloudformation/builders/monitoring.ts +0 -300
  39. package/src/cloudformation/builders/network.ts +0 -264
  40. package/src/cloudformation/builders/queue.ts +0 -147
  41. package/src/cloudformation/builders/security.ts +0 -399
  42. package/src/cloudformation/builders/storage.ts +0 -285
  43. package/src/cloudformation/index.ts +0 -30
  44. package/src/cloudformation/types.ts +0 -173
  45. package/src/compliance/aws-config.ts +0 -543
  46. package/src/compliance/cloudtrail.ts +0 -376
  47. package/src/compliance/compliance.test.ts +0 -423
  48. package/src/compliance/guardduty.ts +0 -446
  49. package/src/compliance/index.ts +0 -66
  50. package/src/compliance/security-hub.ts +0 -456
  51. package/src/containers/build-optimization.ts +0 -416
  52. package/src/containers/containers.test.ts +0 -508
  53. package/src/containers/image-scanning.ts +0 -360
  54. package/src/containers/index.ts +0 -9
  55. package/src/containers/registry.ts +0 -293
  56. package/src/containers/service-mesh.ts +0 -520
  57. package/src/database/database.test.ts +0 -762
  58. package/src/database/index.ts +0 -9
  59. package/src/database/migrations.ts +0 -444
  60. package/src/database/performance.ts +0 -528
  61. package/src/database/replicas.ts +0 -534
  62. package/src/database/users.ts +0 -494
  63. package/src/dependency-graph.ts +0 -143
  64. package/src/deployment/ab-testing.ts +0 -582
  65. package/src/deployment/blue-green.ts +0 -452
  66. package/src/deployment/canary.ts +0 -500
  67. package/src/deployment/deployment.test.ts +0 -526
  68. package/src/deployment/index.ts +0 -61
  69. package/src/deployment/progressive.ts +0 -62
  70. package/src/dns/dns.test.ts +0 -641
  71. package/src/dns/dnssec.ts +0 -315
  72. package/src/dns/index.ts +0 -8
  73. package/src/dns/resolver.ts +0 -496
  74. package/src/dns/routing.ts +0 -593
  75. package/src/email/advanced/analytics.ts +0 -445
  76. package/src/email/advanced/index.ts +0 -11
  77. package/src/email/advanced/rules.ts +0 -465
  78. package/src/email/advanced/scheduling.ts +0 -352
  79. package/src/email/advanced/search.ts +0 -412
  80. package/src/email/advanced/shared-mailboxes.ts +0 -404
  81. package/src/email/advanced/templates.ts +0 -455
  82. package/src/email/advanced/threading.ts +0 -281
  83. package/src/email/analytics.ts +0 -467
  84. package/src/email/bounce-handling.ts +0 -425
  85. package/src/email/email.test.ts +0 -431
  86. package/src/email/handlers/__tests__/inbound.test.ts +0 -38
  87. package/src/email/handlers/__tests__/outbound.test.ts +0 -37
  88. package/src/email/handlers/converter.ts +0 -227
  89. package/src/email/handlers/feedback.ts +0 -228
  90. package/src/email/handlers/inbound.ts +0 -169
  91. package/src/email/handlers/outbound.ts +0 -178
  92. package/src/email/index.ts +0 -15
  93. package/src/email/reputation.ts +0 -303
  94. package/src/email/templates.ts +0 -352
  95. package/src/errors/index.test.ts +0 -434
  96. package/src/errors/index.ts +0 -416
  97. package/src/health-checks/index.ts +0 -40
  98. package/src/index.ts +0 -360
  99. package/src/intrinsic-functions.ts +0 -118
  100. package/src/lambda/concurrency.ts +0 -330
  101. package/src/lambda/destinations.ts +0 -345
  102. package/src/lambda/dlq.ts +0 -425
  103. package/src/lambda/index.ts +0 -11
  104. package/src/lambda/lambda.test.ts +0 -840
  105. package/src/lambda/layers.ts +0 -263
  106. package/src/lambda/versions.ts +0 -376
  107. package/src/lambda/vpc.ts +0 -399
  108. package/src/local/config.ts +0 -114
  109. package/src/local/index.ts +0 -6
  110. package/src/local/mock-aws.ts +0 -351
  111. package/src/modules/ai.ts +0 -340
  112. package/src/modules/api.ts +0 -478
  113. package/src/modules/auth.ts +0 -805
  114. package/src/modules/cache.ts +0 -417
  115. package/src/modules/cdn.ts +0 -1062
  116. package/src/modules/communication.ts +0 -1094
  117. package/src/modules/compute.ts +0 -3348
  118. package/src/modules/database.ts +0 -554
  119. package/src/modules/deployment.ts +0 -1079
  120. package/src/modules/dns.ts +0 -337
  121. package/src/modules/email.ts +0 -1538
  122. package/src/modules/filesystem.ts +0 -515
  123. package/src/modules/index.ts +0 -32
  124. package/src/modules/messaging.ts +0 -486
  125. package/src/modules/monitoring.ts +0 -2086
  126. package/src/modules/network.ts +0 -664
  127. package/src/modules/parameter-store.ts +0 -325
  128. package/src/modules/permissions.ts +0 -1081
  129. package/src/modules/phone.ts +0 -494
  130. package/src/modules/queue.ts +0 -1260
  131. package/src/modules/redirects.ts +0 -464
  132. package/src/modules/registry.ts +0 -699
  133. package/src/modules/search.ts +0 -401
  134. package/src/modules/secrets.ts +0 -416
  135. package/src/modules/security.ts +0 -731
  136. package/src/modules/sms.ts +0 -389
  137. package/src/modules/storage.ts +0 -1120
  138. package/src/modules/workflow.ts +0 -680
  139. package/src/multi-account/config.ts +0 -521
  140. package/src/multi-account/index.ts +0 -7
  141. package/src/multi-account/manager.ts +0 -427
  142. package/src/multi-region/cross-region.ts +0 -410
  143. package/src/multi-region/index.ts +0 -8
  144. package/src/multi-region/manager.ts +0 -483
  145. package/src/multi-region/regions.ts +0 -435
  146. package/src/network-security/index.ts +0 -48
  147. package/src/observability/index.ts +0 -9
  148. package/src/observability/logs.ts +0 -522
  149. package/src/observability/metrics.ts +0 -460
  150. package/src/observability/observability.test.ts +0 -782
  151. package/src/observability/synthetics.ts +0 -568
  152. package/src/observability/xray.ts +0 -358
  153. package/src/phone/advanced/analytics.ts +0 -349
  154. package/src/phone/advanced/callbacks.ts +0 -428
  155. package/src/phone/advanced/index.ts +0 -8
  156. package/src/phone/advanced/ivr-builder.ts +0 -504
  157. package/src/phone/advanced/recording.ts +0 -310
  158. package/src/phone/handlers/__tests__/incoming-call.test.ts +0 -40
  159. package/src/phone/handlers/incoming-call.ts +0 -117
  160. package/src/phone/handlers/missed-call.ts +0 -116
  161. package/src/phone/handlers/voicemail.ts +0 -179
  162. package/src/phone/index.ts +0 -9
  163. package/src/presets/api-backend.ts +0 -134
  164. package/src/presets/data-pipeline.ts +0 -204
  165. package/src/presets/extend.test.ts +0 -295
  166. package/src/presets/extend.ts +0 -297
  167. package/src/presets/fullstack-app.ts +0 -144
  168. package/src/presets/index.ts +0 -27
  169. package/src/presets/jamstack.ts +0 -135
  170. package/src/presets/microservices.ts +0 -167
  171. package/src/presets/ml-api.ts +0 -208
  172. package/src/presets/nodejs-server.ts +0 -104
  173. package/src/presets/nodejs-serverless.ts +0 -114
  174. package/src/presets/realtime-app.ts +0 -184
  175. package/src/presets/static-site.ts +0 -64
  176. package/src/presets/traditional-web-app.ts +0 -339
  177. package/src/presets/wordpress.ts +0 -138
  178. package/src/preview/github.test.ts +0 -249
  179. package/src/preview/github.ts +0 -297
  180. package/src/preview/index.ts +0 -37
  181. package/src/preview/manager.test.ts +0 -440
  182. package/src/preview/manager.ts +0 -326
  183. package/src/preview/notifications.test.ts +0 -582
  184. package/src/preview/notifications.ts +0 -341
  185. package/src/queue/batch-processing.ts +0 -402
  186. package/src/queue/dlq-monitoring.ts +0 -402
  187. package/src/queue/fifo.ts +0 -342
  188. package/src/queue/index.ts +0 -9
  189. package/src/queue/management.ts +0 -428
  190. package/src/queue/queue.test.ts +0 -429
  191. package/src/resource-mgmt/index.ts +0 -39
  192. package/src/resource-naming.ts +0 -62
  193. package/src/s3/index.ts +0 -523
  194. package/src/schema/cloud-config.schema.json +0 -554
  195. package/src/schema/index.ts +0 -68
  196. package/src/security/certificate-manager.ts +0 -492
  197. package/src/security/index.ts +0 -9
  198. package/src/security/scanning.ts +0 -545
  199. package/src/security/secrets-manager.ts +0 -476
  200. package/src/security/secrets-rotation.ts +0 -456
  201. package/src/security/security.test.ts +0 -738
  202. package/src/sms/advanced/ab-testing.ts +0 -389
  203. package/src/sms/advanced/analytics.ts +0 -336
  204. package/src/sms/advanced/campaigns.ts +0 -523
  205. package/src/sms/advanced/chatbot.ts +0 -224
  206. package/src/sms/advanced/index.ts +0 -10
  207. package/src/sms/advanced/link-tracking.ts +0 -248
  208. package/src/sms/advanced/mms.ts +0 -308
  209. package/src/sms/handlers/__tests__/send.test.ts +0 -40
  210. package/src/sms/handlers/delivery-status.ts +0 -133
  211. package/src/sms/handlers/receive.ts +0 -162
  212. package/src/sms/handlers/send.ts +0 -174
  213. package/src/sms/index.ts +0 -9
  214. package/src/stack-diff.ts +0 -389
  215. package/src/static-site/index.ts +0 -85
  216. package/src/template-builder.ts +0 -110
  217. package/src/template-validator.ts +0 -574
  218. package/src/utils/cache.ts +0 -291
  219. package/src/utils/diff.ts +0 -269
  220. package/src/utils/hash.ts +0 -227
  221. package/src/utils/index.ts +0 -8
  222. package/src/utils/parallel.ts +0 -294
  223. package/src/validators/credentials.test.ts +0 -274
  224. package/src/validators/credentials.ts +0 -233
  225. package/src/validators/quotas.test.ts +0 -434
  226. package/src/validators/quotas.ts +0 -217
  227. package/test/ai.test.ts +0 -327
  228. package/test/api.test.ts +0 -511
  229. package/test/auth.test.ts +0 -632
  230. package/test/cache.test.ts +0 -406
  231. package/test/cdn.test.ts +0 -247
  232. package/test/compute.test.ts +0 -861
  233. package/test/database.test.ts +0 -523
  234. package/test/deployment.test.ts +0 -499
  235. package/test/dns.test.ts +0 -270
  236. package/test/email.test.ts +0 -439
  237. package/test/filesystem.test.ts +0 -382
  238. package/test/integration.test.ts +0 -350
  239. package/test/messaging.test.ts +0 -514
  240. package/test/monitoring.test.ts +0 -634
  241. package/test/network.test.ts +0 -425
  242. package/test/permissions.test.ts +0 -488
  243. package/test/queue.test.ts +0 -484
  244. package/test/registry.test.ts +0 -306
  245. package/test/security.test.ts +0 -462
  246. package/test/storage.test.ts +0 -463
  247. package/test/template-validator.test.ts +0 -559
  248. package/test/workflow.test.ts +0 -592
  249. package/tsconfig.json +0 -16
  250. package/tsconfig.tsbuildinfo +0 -1
@@ -1,351 +0,0 @@
1
- /**
2
- * Mock AWS services for unit testing
3
- * Provides in-memory implementations of AWS services without external dependencies
4
- */
5
-
6
- export interface MockAWSConfig {
7
- region?: string
8
- credentials?: {
9
- accessKeyId: string
10
- secretAccessKey: string
11
- }
12
- }
13
-
14
- /**
15
- * Mock CloudFormation service
16
- */
17
- export class MockCloudFormation {
18
- private stacks: Map<string, any> = new Map()
19
- private stackEvents: Map<string, any[]> = new Map()
20
-
21
- async createStack(params: any): Promise<any> {
22
- const stackId = `arn:aws:cloudformation:${params.region || 'us-east-1'}:123456789012:stack/${params.StackName}/${Date.now()}`
23
-
24
- this.stacks.set(params.StackName, {
25
- StackId: stackId,
26
- StackName: params.StackName,
27
- StackStatus: 'CREATE_IN_PROGRESS',
28
- CreationTime: new Date().toISOString(),
29
- TemplateBody: params.TemplateBody,
30
- Parameters: params.Parameters || [],
31
- })
32
-
33
- this.addEvent(params.StackName, {
34
- EventId: Date.now().toString(),
35
- StackName: params.StackName,
36
- LogicalResourceId: params.StackName,
37
- ResourceType: 'AWS::CloudFormation::Stack',
38
- Timestamp: new Date().toISOString(),
39
- ResourceStatus: 'CREATE_IN_PROGRESS',
40
- })
41
-
42
- // Simulate async stack creation
43
- setTimeout(() => {
44
- const stack = this.stacks.get(params.StackName)
45
- if (stack) {
46
- stack.StackStatus = 'CREATE_COMPLETE'
47
- this.addEvent(params.StackName, {
48
- EventId: (Date.now() + 1).toString(),
49
- StackName: params.StackName,
50
- LogicalResourceId: params.StackName,
51
- ResourceType: 'AWS::CloudFormation::Stack',
52
- Timestamp: new Date().toISOString(),
53
- ResourceStatus: 'CREATE_COMPLETE',
54
- })
55
- }
56
- }, 100)
57
-
58
- return { StackId: stackId }
59
- }
60
-
61
- async updateStack(params: any): Promise<any> {
62
- const stack = this.stacks.get(params.StackName)
63
-
64
- if (!stack) {
65
- throw new Error(`Stack ${params.StackName} does not exist`)
66
- }
67
-
68
- stack.StackStatus = 'UPDATE_IN_PROGRESS'
69
- stack.TemplateBody = params.TemplateBody || stack.TemplateBody
70
-
71
- this.addEvent(params.StackName, {
72
- EventId: Date.now().toString(),
73
- StackName: params.StackName,
74
- LogicalResourceId: params.StackName,
75
- ResourceType: 'AWS::CloudFormation::Stack',
76
- Timestamp: new Date().toISOString(),
77
- ResourceStatus: 'UPDATE_IN_PROGRESS',
78
- })
79
-
80
- setTimeout(() => {
81
- stack.StackStatus = 'UPDATE_COMPLETE'
82
- this.addEvent(params.StackName, {
83
- EventId: (Date.now() + 1).toString(),
84
- StackName: params.StackName,
85
- LogicalResourceId: params.StackName,
86
- ResourceType: 'AWS::CloudFormation::Stack',
87
- Timestamp: new Date().toISOString(),
88
- ResourceStatus: 'UPDATE_COMPLETE',
89
- })
90
- }, 100)
91
-
92
- return { StackId: stack.StackId }
93
- }
94
-
95
- async deleteStack(params: any): Promise<void> {
96
- const stack = this.stacks.get(params.StackName)
97
-
98
- if (!stack) {
99
- throw new Error(`Stack ${params.StackName} does not exist`)
100
- }
101
-
102
- stack.StackStatus = 'DELETE_IN_PROGRESS'
103
-
104
- this.addEvent(params.StackName, {
105
- EventId: Date.now().toString(),
106
- StackName: params.StackName,
107
- LogicalResourceId: params.StackName,
108
- ResourceType: 'AWS::CloudFormation::Stack',
109
- Timestamp: new Date().toISOString(),
110
- ResourceStatus: 'DELETE_IN_PROGRESS',
111
- })
112
-
113
- setTimeout(() => {
114
- this.stacks.delete(params.StackName)
115
- this.addEvent(params.StackName, {
116
- EventId: (Date.now() + 1).toString(),
117
- StackName: params.StackName,
118
- LogicalResourceId: params.StackName,
119
- ResourceType: 'AWS::CloudFormation::Stack',
120
- Timestamp: new Date().toISOString(),
121
- ResourceStatus: 'DELETE_COMPLETE',
122
- })
123
- }, 100)
124
- }
125
-
126
- async describeStacks(params: any): Promise<any> {
127
- if (params.StackName) {
128
- const stack = this.stacks.get(params.StackName)
129
-
130
- if (!stack) {
131
- throw new Error(`Stack ${params.StackName} does not exist`)
132
- }
133
-
134
- return {
135
- Stacks: [stack],
136
- }
137
- }
138
-
139
- return {
140
- Stacks: Array.from(this.stacks.values()),
141
- }
142
- }
143
-
144
- async describeStackEvents(params: any): Promise<any> {
145
- const events = this.stackEvents.get(params.StackName) || []
146
-
147
- return {
148
- StackEvents: events,
149
- }
150
- }
151
-
152
- private addEvent(stackName: string, event: any): void {
153
- if (!this.stackEvents.has(stackName)) {
154
- this.stackEvents.set(stackName, [])
155
- }
156
-
157
- this.stackEvents.get(stackName)!.unshift(event)
158
- }
159
-
160
- /**
161
- * Reset mock state (useful for testing)
162
- */
163
- reset(): void {
164
- this.stacks.clear()
165
- this.stackEvents.clear()
166
- }
167
- }
168
-
169
- /**
170
- * Mock S3 service
171
- */
172
- export class MockS3 {
173
- private buckets: Map<string, Map<string, Buffer>> = new Map()
174
-
175
- async createBucket(params: any): Promise<any> {
176
- this.buckets.set(params.Bucket, new Map())
177
-
178
- return {
179
- Location: `/${params.Bucket}`,
180
- }
181
- }
182
-
183
- async deleteBucket(params: any): Promise<void> {
184
- this.buckets.delete(params.Bucket)
185
- }
186
-
187
- async putObject(params: any): Promise<any> {
188
- let bucket = this.buckets.get(params.Bucket)
189
-
190
- if (!bucket) {
191
- bucket = new Map()
192
- this.buckets.set(params.Bucket, bucket)
193
- }
194
-
195
- bucket.set(params.Key, Buffer.from(params.Body || ''))
196
-
197
- return {
198
- ETag: `"${Date.now()}"`,
199
- }
200
- }
201
-
202
- async getObject(params: any): Promise<any> {
203
- const bucket = this.buckets.get(params.Bucket)
204
-
205
- if (!bucket) {
206
- throw new Error(`Bucket ${params.Bucket} does not exist`)
207
- }
208
-
209
- const data = bucket.get(params.Key)
210
-
211
- if (!data) {
212
- throw new Error(`Object ${params.Key} does not exist`)
213
- }
214
-
215
- return {
216
- Body: data,
217
- ContentLength: data.length,
218
- }
219
- }
220
-
221
- async deleteObject(params: any): Promise<void> {
222
- const bucket = this.buckets.get(params.Bucket)
223
-
224
- if (bucket) {
225
- bucket.delete(params.Key)
226
- }
227
- }
228
-
229
- async listObjects(params: any): Promise<any> {
230
- const bucket = this.buckets.get(params.Bucket)
231
-
232
- if (!bucket) {
233
- throw new Error(`Bucket ${params.Bucket} does not exist`)
234
- }
235
-
236
- const objects = Array.from(bucket.keys()).map(key => ({
237
- Key: key,
238
- Size: bucket.get(key)!.length,
239
- LastModified: new Date().toISOString(),
240
- }))
241
-
242
- return {
243
- Contents: objects,
244
- }
245
- }
246
-
247
- /**
248
- * Reset mock state
249
- */
250
- reset(): void {
251
- this.buckets.clear()
252
- }
253
- }
254
-
255
- /**
256
- * Mock DynamoDB service
257
- */
258
- export class MockDynamoDB {
259
- private tables: Map<string, any> = new Map()
260
- private data: Map<string, Map<string, any>> = new Map()
261
-
262
- async createTable(params: any): Promise<any> {
263
- this.tables.set(params.TableName, {
264
- TableName: params.TableName,
265
- KeySchema: params.KeySchema,
266
- AttributeDefinitions: params.AttributeDefinitions,
267
- TableStatus: 'ACTIVE',
268
- CreationDateTime: new Date().toISOString(),
269
- })
270
-
271
- this.data.set(params.TableName, new Map())
272
-
273
- return {
274
- TableDescription: this.tables.get(params.TableName),
275
- }
276
- }
277
-
278
- async deleteTable(params: any): Promise<void> {
279
- this.tables.delete(params.TableName)
280
- this.data.delete(params.TableName)
281
- }
282
-
283
- async putItem(params: any): Promise<void> {
284
- let tableData = this.data.get(params.TableName)
285
-
286
- if (!tableData) {
287
- tableData = new Map()
288
- this.data.set(params.TableName, tableData)
289
- }
290
-
291
- const key = JSON.stringify(params.Item)
292
- tableData.set(key, params.Item)
293
- }
294
-
295
- async getItem(params: any): Promise<any> {
296
- const tableData = this.data.get(params.TableName)
297
-
298
- if (!tableData) {
299
- return {}
300
- }
301
-
302
- const key = JSON.stringify(params.Key)
303
- const item = tableData.get(key)
304
-
305
- return item ? { Item: item } : {}
306
- }
307
-
308
- async deleteItem(params: any): Promise<void> {
309
- const tableData = this.data.get(params.TableName)
310
-
311
- if (tableData) {
312
- const key = JSON.stringify(params.Key)
313
- tableData.delete(key)
314
- }
315
- }
316
-
317
- async scan(params: any): Promise<any> {
318
- const tableData = this.data.get(params.TableName)
319
-
320
- if (!tableData) {
321
- return { Items: [] }
322
- }
323
-
324
- return {
325
- Items: Array.from(tableData.values()),
326
- }
327
- }
328
-
329
- /**
330
- * Reset mock state
331
- */
332
- reset(): void {
333
- this.tables.clear()
334
- this.data.clear()
335
- }
336
- }
337
-
338
- /**
339
- * Create mock AWS services
340
- */
341
- export function createMockAWS(config?: MockAWSConfig): {
342
- cloudformation: MockCloudFormation
343
- s3: MockS3
344
- dynamodb: MockDynamoDB
345
- } {
346
- return {
347
- cloudformation: new MockCloudFormation(),
348
- s3: new MockS3(),
349
- dynamodb: new MockDynamoDB(),
350
- }
351
- }
package/src/modules/ai.ts DELETED
@@ -1,340 +0,0 @@
1
- import type {
2
- IAMRole,
3
- IAMManagedPolicy,
4
- } from '@stacksjs/ts-cloud-aws-types'
5
- import type { EnvironmentType } from '@stacksjs/ts-cloud-types'
6
- import { generateLogicalId, generateResourceName } from '../resource-naming'
7
-
8
- export interface BedrockRoleOptions {
9
- slug: string
10
- environment: EnvironmentType
11
- name?: string
12
- models?: string[]
13
- allowStreaming?: boolean
14
- }
15
-
16
- export interface BedrockPolicyOptions {
17
- slug: string
18
- environment: EnvironmentType
19
- name?: string
20
- models?: string[]
21
- allowInvoke?: boolean
22
- allowStreaming?: boolean
23
- allowAsync?: boolean
24
- }
25
-
26
- /**
27
- * AI Module - Amazon Bedrock
28
- * Provides clean API for setting up Bedrock permissions and roles
29
- */
30
- export class AI {
31
- /**
32
- * Create an IAM role for Bedrock access
33
- */
34
- static createBedrockRole(
35
- servicePrincipal: string,
36
- options: BedrockRoleOptions,
37
- ): {
38
- role: IAMRole
39
- logicalId: string
40
- } {
41
- const {
42
- slug,
43
- environment,
44
- name,
45
- models = ['*'],
46
- allowStreaming = true,
47
- } = options
48
-
49
- const resourceName = name || generateResourceName({
50
- slug,
51
- environment,
52
- resourceType: 'bedrock-role',
53
- })
54
-
55
- const logicalId = generateLogicalId(resourceName)
56
-
57
- // Build actions array
58
- const actions = ['bedrock:InvokeModel']
59
- if (allowStreaming) {
60
- actions.push('bedrock:InvokeModelWithResponseStream')
61
- }
62
-
63
- // Build resource ARNs for models
64
- const modelArns = models.map(model =>
65
- model === '*'
66
- ? 'arn:aws:bedrock:*::foundation-model/*'
67
- : `arn:aws:bedrock:*::foundation-model/${model}`,
68
- )
69
-
70
- const role: IAMRole = {
71
- Type: 'AWS::IAM::Role',
72
- Properties: {
73
- RoleName: resourceName,
74
- AssumeRolePolicyDocument: {
75
- Version: '2012-10-17',
76
- Statement: [
77
- {
78
- Effect: 'Allow',
79
- Principal: {
80
- Service: servicePrincipal,
81
- },
82
- Action: 'sts:AssumeRole',
83
- },
84
- ],
85
- },
86
- Policies: [
87
- {
88
- PolicyName: `${resourceName}-policy`,
89
- PolicyDocument: {
90
- Version: '2012-10-17',
91
- Statement: [
92
- {
93
- Effect: 'Allow',
94
- Action: actions,
95
- Resource: modelArns,
96
- },
97
- ],
98
- },
99
- },
100
- ],
101
- Tags: [
102
- { Key: 'Name', Value: resourceName },
103
- { Key: 'Environment', Value: environment },
104
- ],
105
- },
106
- }
107
-
108
- return { role, logicalId }
109
- }
110
-
111
- /**
112
- * Create an IAM policy for Bedrock model invocation
113
- */
114
- static createBedrockPolicy(options: BedrockPolicyOptions): {
115
- policy: IAMManagedPolicy
116
- logicalId: string
117
- } {
118
- const {
119
- slug,
120
- environment,
121
- name,
122
- models = ['*'],
123
- allowInvoke = true,
124
- allowStreaming = true,
125
- allowAsync = false,
126
- } = options
127
-
128
- const resourceName = name || generateResourceName({
129
- slug,
130
- environment,
131
- resourceType: 'bedrock-policy',
132
- })
133
-
134
- const logicalId = generateLogicalId(resourceName)
135
-
136
- // Build actions array
137
- const actions: string[] = []
138
- if (allowInvoke) {
139
- actions.push('bedrock:InvokeModel')
140
- }
141
- if (allowStreaming) {
142
- actions.push('bedrock:InvokeModelWithResponseStream')
143
- }
144
- if (allowAsync) {
145
- actions.push('bedrock:InvokeModelAsync')
146
- }
147
-
148
- // Build resource ARNs for models
149
- const modelArns = models.map(model =>
150
- model === '*'
151
- ? 'arn:aws:bedrock:*::foundation-model/*'
152
- : `arn:aws:bedrock:*::foundation-model/${model}`,
153
- )
154
-
155
- const policy: IAMManagedPolicy = {
156
- Type: 'AWS::IAM::ManagedPolicy',
157
- Properties: {
158
- ManagedPolicyName: resourceName,
159
- PolicyDocument: {
160
- Version: '2012-10-17',
161
- Statement: [
162
- {
163
- Sid: 'BedrockModelInvocation',
164
- Effect: 'Allow',
165
- Action: actions,
166
- Resource: modelArns,
167
- },
168
- ],
169
- },
170
- },
171
- }
172
-
173
- return { policy, logicalId }
174
- }
175
-
176
- /**
177
- * Enable Bedrock for Lambda function
178
- * Returns a role with Bedrock permissions
179
- */
180
- static enableBedrockForLambda(options: BedrockRoleOptions): {
181
- role: IAMRole
182
- logicalId: string
183
- } {
184
- return AI.createBedrockRole('lambda.amazonaws.com', options)
185
- }
186
-
187
- /**
188
- * Enable Bedrock for ECS task
189
- * Returns a role with Bedrock permissions
190
- */
191
- static enableBedrockForEcs(options: BedrockRoleOptions): {
192
- role: IAMRole
193
- logicalId: string
194
- } {
195
- return AI.createBedrockRole('ecs-tasks.amazonaws.com', options)
196
- }
197
-
198
- /**
199
- * Enable Bedrock for EC2 instance
200
- * Returns a role with Bedrock permissions
201
- */
202
- static enableBedrockForEc2(options: BedrockRoleOptions): {
203
- role: IAMRole
204
- logicalId: string
205
- } {
206
- return AI.createBedrockRole('ec2.amazonaws.com', options)
207
- }
208
-
209
- /**
210
- * Add Bedrock permissions to an existing role
211
- */
212
- static addBedrockPermissions(
213
- role: IAMRole,
214
- models: string[] = ['*'],
215
- allowStreaming = true,
216
- ): IAMRole {
217
- // Build actions array
218
- const actions = ['bedrock:InvokeModel']
219
- if (allowStreaming) {
220
- actions.push('bedrock:InvokeModelWithResponseStream')
221
- }
222
-
223
- // Build resource ARNs for models
224
- const modelArns = models.map(model =>
225
- model === '*'
226
- ? 'arn:aws:bedrock:*::foundation-model/*'
227
- : `arn:aws:bedrock:*::foundation-model/${model}`,
228
- )
229
-
230
- if (!role.Properties.Policies) {
231
- role.Properties.Policies = []
232
- }
233
-
234
- // Add Bedrock policy
235
- role.Properties.Policies.push({
236
- PolicyName: 'bedrock-permissions',
237
- PolicyDocument: {
238
- Version: '2012-10-17',
239
- Statement: [
240
- {
241
- Effect: 'Allow',
242
- Action: actions,
243
- Resource: modelArns,
244
- },
245
- ],
246
- },
247
- })
248
-
249
- return role
250
- }
251
-
252
- /**
253
- * Common Bedrock model IDs
254
- */
255
- static readonly Models = {
256
- // Anthropic Claude Models
257
- Claude3_5_Sonnet: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
258
- Claude3_5_Haiku: 'anthropic.claude-3-5-haiku-20241022-v1:0',
259
- Claude3_Opus: 'anthropic.claude-3-opus-20240229-v1:0',
260
- Claude3_Sonnet: 'anthropic.claude-3-sonnet-20240229-v1:0',
261
- Claude3_Haiku: 'anthropic.claude-3-haiku-20240307-v1:0',
262
-
263
- // Amazon Titan Models
264
- TitanTextG1Express: 'amazon.titan-text-express-v1',
265
- TitanTextG1Lite: 'amazon.titan-text-lite-v1',
266
- TitanEmbedG1Text: 'amazon.titan-embed-text-v1',
267
- TitanImageG1: 'amazon.titan-image-generator-v1',
268
-
269
- // AI21 Labs Models
270
- JurassicUltra: 'ai21.j2-ultra-v1',
271
- JurassicMid: 'ai21.j2-mid-v1',
272
-
273
- // Cohere Models
274
- CommandText: 'cohere.command-text-v14',
275
- CommandLight: 'cohere.command-light-text-v14',
276
- EmbedEnglish: 'cohere.embed-english-v3',
277
- EmbedMultilingual: 'cohere.embed-multilingual-v3',
278
-
279
- // Meta Llama Models
280
- Llama3_2_1B: 'meta.llama3-2-1b-instruct-v1:0',
281
- Llama3_2_3B: 'meta.llama3-2-3b-instruct-v1:0',
282
- Llama3_2_11B: 'meta.llama3-2-11b-instruct-v1:0',
283
- Llama3_2_90B: 'meta.llama3-2-90b-instruct-v1:0',
284
- Llama3_1_8B: 'meta.llama3-1-8b-instruct-v1:0',
285
- Llama3_1_70B: 'meta.llama3-1-70b-instruct-v1:0',
286
- Llama3_1_405B: 'meta.llama3-1-405b-instruct-v1:0',
287
-
288
- // Mistral AI Models
289
- Mistral7B: 'mistral.mistral-7b-instruct-v0:2',
290
- Mixtral8x7B: 'mistral.mixtral-8x7b-instruct-v0:1',
291
- MistralLarge: 'mistral.mistral-large-2402-v1:0',
292
-
293
- // Stability AI Models
294
- StableDiffusionXL: 'stability.stable-diffusion-xl-v1',
295
- } as const
296
-
297
- /**
298
- * Common model groups for easier permission management
299
- */
300
- static readonly ModelGroups = {
301
- AllClaude: [
302
- 'anthropic.claude-3-5-sonnet-20241022-v2:0',
303
- 'anthropic.claude-3-5-haiku-20241022-v1:0',
304
- 'anthropic.claude-3-opus-20240229-v1:0',
305
- 'anthropic.claude-3-sonnet-20240229-v1:0',
306
- 'anthropic.claude-3-haiku-20240307-v1:0',
307
- ],
308
- AllTitan: [
309
- 'amazon.titan-text-express-v1',
310
- 'amazon.titan-text-lite-v1',
311
- 'amazon.titan-embed-text-v1',
312
- 'amazon.titan-image-generator-v1',
313
- ],
314
- AllLlama: [
315
- 'meta.llama3-2-1b-instruct-v1:0',
316
- 'meta.llama3-2-3b-instruct-v1:0',
317
- 'meta.llama3-2-11b-instruct-v1:0',
318
- 'meta.llama3-2-90b-instruct-v1:0',
319
- 'meta.llama3-1-8b-instruct-v1:0',
320
- 'meta.llama3-1-70b-instruct-v1:0',
321
- 'meta.llama3-1-405b-instruct-v1:0',
322
- ],
323
- TextModels: [
324
- 'anthropic.claude-3-5-sonnet-20241022-v2:0',
325
- 'anthropic.claude-3-5-haiku-20241022-v1:0',
326
- 'amazon.titan-text-express-v1',
327
- 'meta.llama3-2-11b-instruct-v1:0',
328
- 'mistral.mistral-7b-instruct-v0:2',
329
- ],
330
- EmbeddingModels: [
331
- 'amazon.titan-embed-text-v1',
332
- 'cohere.embed-english-v3',
333
- 'cohere.embed-multilingual-v3',
334
- ],
335
- ImageModels: [
336
- 'amazon.titan-image-generator-v1',
337
- 'stability.stable-diffusion-xl-v1',
338
- ],
339
- } as const
340
- }