@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,805 +0,0 @@
1
- import type {
2
- CognitoUserPool,
3
- CognitoUserPoolClient,
4
- CognitoUserPoolDomain,
5
- CognitoIdentityPool,
6
- CognitoIdentityPoolRoleAttachment,
7
- IAMRole,
8
- } from '@stacksjs/ts-cloud-aws-types'
9
- import type { EnvironmentType } from '@stacksjs/ts-cloud-types'
10
- import { Fn } from '../intrinsic-functions'
11
- import { generateLogicalId, generateResourceName } from '../resource-naming'
12
-
13
- export interface UserPoolOptions {
14
- slug: string
15
- environment: EnvironmentType
16
- userPoolName?: string
17
- aliasAttributes?: ('email' | 'phone_number')[]
18
- autoVerifiedAttributes?: ('email' | 'phone_number')[]
19
- passwordPolicy?: PasswordPolicyOptions
20
- mfaConfiguration?: 'OFF' | 'ON' | 'OPTIONAL'
21
- emailConfiguration?: EmailConfigurationOptions
22
- smsConfiguration?: SmsConfigurationOptions
23
- lambdaTriggers?: LambdaTriggersOptions
24
- userPoolAddOns?: {
25
- advancedSecurityMode?: 'OFF' | 'AUDIT' | 'ENFORCED'
26
- }
27
- accountRecoverySetting?: {
28
- recoveryMechanisms: Array<{
29
- Name: 'verified_email' | 'verified_phone_number' | 'admin_only'
30
- Priority: number
31
- }>
32
- }
33
- }
34
-
35
- export interface PasswordPolicyOptions {
36
- minimumLength?: number
37
- requireLowercase?: boolean
38
- requireUppercase?: boolean
39
- requireNumbers?: boolean
40
- requireSymbols?: boolean
41
- temporaryPasswordValidityDays?: number
42
- }
43
-
44
- export interface EmailConfigurationOptions {
45
- emailSendingAccount?: 'COGNITO_DEFAULT' | 'DEVELOPER'
46
- from?: string
47
- replyToEmailAddress?: string
48
- sourceArn?: string
49
- configurationSet?: string
50
- }
51
-
52
- export interface SmsConfigurationOptions {
53
- externalId: string
54
- snsCallerArn: string
55
- }
56
-
57
- export interface LambdaTriggersOptions {
58
- preSignUp?: string
59
- postConfirmation?: string
60
- preAuthentication?: string
61
- postAuthentication?: string
62
- customMessage?: string
63
- defineAuthChallenge?: string
64
- createAuthChallenge?: string
65
- verifyAuthChallengeResponse?: string
66
- preTokenGeneration?: string
67
- userMigration?: string
68
- }
69
-
70
- export interface UserPoolClientOptions {
71
- slug: string
72
- environment: EnvironmentType
73
- clientName?: string
74
- generateSecret?: boolean
75
- refreshTokenValidity?: number
76
- accessTokenValidity?: number
77
- idTokenValidity?: number
78
- tokenValidityUnits?: {
79
- RefreshToken?: 'seconds' | 'minutes' | 'hours' | 'days'
80
- AccessToken?: 'seconds' | 'minutes' | 'hours' | 'days'
81
- IdToken?: 'seconds' | 'minutes' | 'hours' | 'days'
82
- }
83
- readAttributes?: string[]
84
- writeAttributes?: string[]
85
- explicitAuthFlows?: string[]
86
- preventUserExistenceErrors?: 'ENABLED' | 'LEGACY'
87
- enableTokenRevocation?: boolean
88
- callbackURLs?: string[]
89
- logoutURLs?: string[]
90
- allowedOAuthFlows?: ('code' | 'implicit' | 'client_credentials')[]
91
- allowedOAuthScopes?: string[]
92
- allowedOAuthFlowsUserPoolClient?: boolean
93
- supportedIdentityProviders?: string[]
94
- }
95
-
96
- export interface UserPoolDomainOptions {
97
- slug: string
98
- environment: EnvironmentType
99
- domain: string
100
- customDomainConfig?: {
101
- CertificateArn: string
102
- }
103
- }
104
-
105
- export interface IdentityPoolOptions {
106
- slug: string
107
- environment: EnvironmentType
108
- identityPoolName?: string
109
- allowUnauthenticatedIdentities?: boolean
110
- cognitoIdentityProviders?: Array<{
111
- ClientId: string
112
- ProviderName: string
113
- ServerSideTokenCheck?: boolean
114
- }>
115
- supportedLoginProviders?: Record<string, string>
116
- samlProviderARNs?: string[]
117
- openIdConnectProviderARNs?: string[]
118
- }
119
-
120
- export interface IdentityPoolRoleAttachmentOptions {
121
- slug: string
122
- environment: EnvironmentType
123
- authenticatedRole: string
124
- unauthenticatedRole?: string
125
- roleMappings?: Record<string, {
126
- Type: 'Token' | 'Rules'
127
- AmbiguousRoleResolution?: 'AuthenticatedRole' | 'Deny'
128
- RulesConfiguration?: {
129
- Rules: Array<{
130
- Claim: string
131
- MatchType: 'Equals' | 'Contains' | 'StartsWith' | 'NotEqual'
132
- Value: string
133
- RoleARN: string
134
- }>
135
- }
136
- }>
137
- }
138
-
139
- /**
140
- * Authentication Module - Cognito
141
- * Provides clean API for user authentication and identity management
142
- */
143
- export class Auth {
144
- /**
145
- * Create a Cognito User Pool
146
- */
147
- static createUserPool(options: UserPoolOptions): {
148
- userPool: CognitoUserPool
149
- logicalId: string
150
- } {
151
- const {
152
- slug,
153
- environment,
154
- userPoolName,
155
- aliasAttributes,
156
- autoVerifiedAttributes,
157
- passwordPolicy,
158
- mfaConfiguration,
159
- emailConfiguration,
160
- smsConfiguration,
161
- lambdaTriggers,
162
- userPoolAddOns,
163
- accountRecoverySetting,
164
- } = options
165
-
166
- const resourceName = userPoolName || generateResourceName({
167
- slug,
168
- environment,
169
- resourceType: 'user-pool',
170
- })
171
-
172
- const logicalId = generateLogicalId(resourceName)
173
-
174
- const userPool: CognitoUserPool = {
175
- Type: 'AWS::Cognito::UserPool',
176
- Properties: {
177
- UserPoolName: resourceName,
178
- Policies: passwordPolicy
179
- ? {
180
- PasswordPolicy: {
181
- MinimumLength: passwordPolicy.minimumLength,
182
- RequireLowercase: passwordPolicy.requireLowercase,
183
- RequireUppercase: passwordPolicy.requireUppercase,
184
- RequireNumbers: passwordPolicy.requireNumbers,
185
- RequireSymbols: passwordPolicy.requireSymbols,
186
- TemporaryPasswordValidityDays: passwordPolicy.temporaryPasswordValidityDays,
187
- },
188
- }
189
- : undefined,
190
- MfaConfiguration: mfaConfiguration,
191
- Schema: [
192
- {
193
- Name: 'email',
194
- AttributeDataType: 'String',
195
- Required: true,
196
- Mutable: false,
197
- },
198
- ],
199
- },
200
- }
201
-
202
- if (aliasAttributes && aliasAttributes.length > 0) {
203
- userPool.Properties!.UsernameAttributes = aliasAttributes
204
- }
205
-
206
- if (autoVerifiedAttributes && autoVerifiedAttributes.length > 0) {
207
- userPool.Properties!.AutoVerifiedAttributes = autoVerifiedAttributes
208
- }
209
-
210
- if (emailConfiguration) {
211
- userPool.Properties!.EmailConfiguration = {
212
- EmailSendingAccount: emailConfiguration.emailSendingAccount,
213
- From: emailConfiguration.from,
214
- ReplyToEmailAddress: emailConfiguration.replyToEmailAddress,
215
- SourceArn: emailConfiguration.sourceArn,
216
- ConfigurationSet: emailConfiguration.configurationSet,
217
- }
218
- }
219
-
220
- if (smsConfiguration) {
221
- userPool.Properties!.SmsConfiguration = {
222
- ExternalId: smsConfiguration.externalId,
223
- SnsCallerArn: smsConfiguration.snsCallerArn,
224
- }
225
- }
226
-
227
- if (lambdaTriggers) {
228
- userPool.Properties!.LambdaConfig = {
229
- PreSignUp: lambdaTriggers.preSignUp,
230
- PostConfirmation: lambdaTriggers.postConfirmation,
231
- PreAuthentication: lambdaTriggers.preAuthentication,
232
- PostAuthentication: lambdaTriggers.postAuthentication,
233
- CustomMessage: lambdaTriggers.customMessage,
234
- DefineAuthChallenge: lambdaTriggers.defineAuthChallenge,
235
- CreateAuthChallenge: lambdaTriggers.createAuthChallenge,
236
- VerifyAuthChallengeResponse: lambdaTriggers.verifyAuthChallengeResponse,
237
- PreTokenGeneration: lambdaTriggers.preTokenGeneration,
238
- UserMigration: lambdaTriggers.userMigration,
239
- }
240
- }
241
-
242
- if (userPoolAddOns) {
243
- userPool.Properties!.UserPoolAddOns = {
244
- AdvancedSecurityMode: userPoolAddOns.advancedSecurityMode,
245
- }
246
- }
247
-
248
- if (accountRecoverySetting) {
249
- userPool.Properties!.AccountRecoverySetting = {
250
- RecoveryMechanisms: accountRecoverySetting.recoveryMechanisms,
251
- }
252
- }
253
-
254
- return { userPool, logicalId }
255
- }
256
-
257
- /**
258
- * Create a Cognito User Pool Client
259
- */
260
- static createUserPoolClient(
261
- userPoolLogicalId: string,
262
- options: UserPoolClientOptions,
263
- ): {
264
- client: CognitoUserPoolClient
265
- logicalId: string
266
- } {
267
- const {
268
- slug,
269
- environment,
270
- clientName,
271
- generateSecret = false,
272
- refreshTokenValidity,
273
- accessTokenValidity,
274
- idTokenValidity,
275
- tokenValidityUnits,
276
- readAttributes,
277
- writeAttributes,
278
- explicitAuthFlows,
279
- preventUserExistenceErrors,
280
- enableTokenRevocation,
281
- callbackURLs,
282
- logoutURLs,
283
- allowedOAuthFlows,
284
- allowedOAuthScopes,
285
- allowedOAuthFlowsUserPoolClient,
286
- supportedIdentityProviders,
287
- } = options
288
-
289
- const resourceName = clientName || generateResourceName({
290
- slug,
291
- environment,
292
- resourceType: 'user-pool-client',
293
- })
294
-
295
- const logicalId = generateLogicalId(resourceName)
296
-
297
- const client: CognitoUserPoolClient = {
298
- Type: 'AWS::Cognito::UserPoolClient',
299
- Properties: {
300
- ClientName: resourceName,
301
- UserPoolId: Fn.Ref(userPoolLogicalId) as unknown as string,
302
- GenerateSecret: generateSecret,
303
- RefreshTokenValidity: refreshTokenValidity,
304
- AccessTokenValidity: accessTokenValidity,
305
- IdTokenValidity: idTokenValidity,
306
- TokenValidityUnits: tokenValidityUnits,
307
- ReadAttributes: readAttributes,
308
- WriteAttributes: writeAttributes,
309
- ExplicitAuthFlows: explicitAuthFlows,
310
- PreventUserExistenceErrors: preventUserExistenceErrors,
311
- EnableTokenRevocation: enableTokenRevocation,
312
- CallbackURLs: callbackURLs,
313
- LogoutURLs: logoutURLs,
314
- AllowedOAuthFlows: allowedOAuthFlows,
315
- AllowedOAuthScopes: allowedOAuthScopes,
316
- AllowedOAuthFlowsUserPoolClient: allowedOAuthFlowsUserPoolClient,
317
- SupportedIdentityProviders: supportedIdentityProviders,
318
- },
319
- }
320
-
321
- return { client, logicalId }
322
- }
323
-
324
- /**
325
- * Create a Cognito User Pool Domain
326
- */
327
- static createUserPoolDomain(
328
- userPoolLogicalId: string,
329
- options: UserPoolDomainOptions,
330
- ): {
331
- domain: CognitoUserPoolDomain
332
- logicalId: string
333
- } {
334
- const {
335
- slug,
336
- environment,
337
- domain,
338
- customDomainConfig,
339
- } = options
340
-
341
- const resourceName = generateResourceName({
342
- slug,
343
- environment,
344
- resourceType: 'user-pool-domain',
345
- })
346
-
347
- const logicalId = generateLogicalId(resourceName)
348
-
349
- const userPoolDomain: CognitoUserPoolDomain = {
350
- Type: 'AWS::Cognito::UserPoolDomain',
351
- Properties: {
352
- Domain: domain,
353
- UserPoolId: Fn.Ref(userPoolLogicalId) as unknown as string,
354
- CustomDomainConfig: customDomainConfig,
355
- },
356
- }
357
-
358
- return { domain: userPoolDomain, logicalId }
359
- }
360
-
361
- /**
362
- * Create a Cognito Identity Pool
363
- */
364
- static createIdentityPool(options: IdentityPoolOptions): {
365
- identityPool: CognitoIdentityPool
366
- logicalId: string
367
- } {
368
- const {
369
- slug,
370
- environment,
371
- identityPoolName,
372
- allowUnauthenticatedIdentities = false,
373
- cognitoIdentityProviders,
374
- supportedLoginProviders,
375
- samlProviderARNs,
376
- openIdConnectProviderARNs,
377
- } = options
378
-
379
- const resourceName = identityPoolName || generateResourceName({
380
- slug,
381
- environment,
382
- resourceType: 'identity-pool',
383
- })
384
-
385
- const logicalId = generateLogicalId(resourceName)
386
-
387
- const identityPool: CognitoIdentityPool = {
388
- Type: 'AWS::Cognito::IdentityPool',
389
- Properties: {
390
- IdentityPoolName: resourceName,
391
- AllowUnauthenticatedIdentities: allowUnauthenticatedIdentities,
392
- CognitoIdentityProviders: cognitoIdentityProviders,
393
- SupportedLoginProviders: supportedLoginProviders,
394
- SamlProviderARNs: samlProviderARNs,
395
- OpenIdConnectProviderARNs: openIdConnectProviderARNs,
396
- },
397
- }
398
-
399
- return { identityPool, logicalId }
400
- }
401
-
402
- /**
403
- * Create an Identity Pool Role Attachment
404
- */
405
- static createIdentityPoolRoleAttachment(
406
- identityPoolLogicalId: string,
407
- options: IdentityPoolRoleAttachmentOptions,
408
- ): {
409
- attachment: CognitoIdentityPoolRoleAttachment
410
- logicalId: string
411
- } {
412
- const {
413
- slug,
414
- environment,
415
- authenticatedRole,
416
- unauthenticatedRole,
417
- roleMappings,
418
- } = options
419
-
420
- const resourceName = generateResourceName({
421
- slug,
422
- environment,
423
- resourceType: 'identity-pool-role-attachment',
424
- })
425
-
426
- const logicalId = generateLogicalId(resourceName)
427
-
428
- const roles: Record<string, string> = {
429
- authenticated: authenticatedRole,
430
- }
431
-
432
- if (unauthenticatedRole) {
433
- roles.unauthenticated = unauthenticatedRole
434
- }
435
-
436
- const attachment: CognitoIdentityPoolRoleAttachment = {
437
- Type: 'AWS::Cognito::IdentityPoolRoleAttachment',
438
- Properties: {
439
- IdentityPoolId: Fn.Ref(identityPoolLogicalId) as unknown as string,
440
- Roles: roles,
441
- RoleMappings: roleMappings,
442
- },
443
- }
444
-
445
- return { attachment, logicalId }
446
- }
447
-
448
- /**
449
- * Create IAM role for authenticated users
450
- */
451
- static createAuthenticatedRole(options: {
452
- slug: string
453
- environment: EnvironmentType
454
- identityPoolLogicalId: string
455
- }): {
456
- role: IAMRole
457
- logicalId: string
458
- } {
459
- const { slug, environment, identityPoolLogicalId } = options
460
-
461
- const resourceName = generateResourceName({
462
- slug,
463
- environment,
464
- resourceType: 'cognito-authenticated-role',
465
- })
466
-
467
- const logicalId = generateLogicalId(resourceName)
468
-
469
- const role: IAMRole = {
470
- Type: 'AWS::IAM::Role',
471
- Properties: {
472
- RoleName: resourceName,
473
- AssumeRolePolicyDocument: {
474
- Version: '2012-10-17',
475
- Statement: [
476
- {
477
- Effect: 'Allow',
478
- Principal: {
479
- Federated: 'cognito-identity.amazonaws.com',
480
- },
481
- Action: 'sts:AssumeRoleWithWebIdentity',
482
- Condition: {
483
- StringEquals: {
484
- 'cognito-identity.amazonaws.com:aud': Fn.Ref(identityPoolLogicalId) as unknown as string,
485
- },
486
- 'ForAnyValue:StringLike': {
487
- 'cognito-identity.amazonaws.com:amr': 'authenticated',
488
- },
489
- },
490
- },
491
- ],
492
- },
493
- Policies: [
494
- {
495
- PolicyName: 'CognitoAuthenticatedPolicy',
496
- PolicyDocument: {
497
- Version: '2012-10-17',
498
- Statement: [
499
- {
500
- Effect: 'Allow',
501
- Action: [
502
- 'cognito-sync:*',
503
- 'cognito-identity:*',
504
- ],
505
- Resource: '*',
506
- },
507
- ],
508
- },
509
- },
510
- ],
511
- Tags: [
512
- { Key: 'Name', Value: resourceName },
513
- { Key: 'Environment', Value: environment },
514
- ],
515
- },
516
- }
517
-
518
- return { role, logicalId }
519
- }
520
-
521
- /**
522
- * Create IAM role for unauthenticated users
523
- */
524
- static createUnauthenticatedRole(options: {
525
- slug: string
526
- environment: EnvironmentType
527
- identityPoolLogicalId: string
528
- }): {
529
- role: IAMRole
530
- logicalId: string
531
- } {
532
- const { slug, environment, identityPoolLogicalId } = options
533
-
534
- const resourceName = generateResourceName({
535
- slug,
536
- environment,
537
- resourceType: 'cognito-unauthenticated-role',
538
- })
539
-
540
- const logicalId = generateLogicalId(resourceName)
541
-
542
- const role: IAMRole = {
543
- Type: 'AWS::IAM::Role',
544
- Properties: {
545
- RoleName: resourceName,
546
- AssumeRolePolicyDocument: {
547
- Version: '2012-10-17',
548
- Statement: [
549
- {
550
- Effect: 'Allow',
551
- Principal: {
552
- Federated: 'cognito-identity.amazonaws.com',
553
- },
554
- Action: 'sts:AssumeRoleWithWebIdentity',
555
- Condition: {
556
- StringEquals: {
557
- 'cognito-identity.amazonaws.com:aud': Fn.Ref(identityPoolLogicalId) as unknown as string,
558
- },
559
- 'ForAnyValue:StringLike': {
560
- 'cognito-identity.amazonaws.com:amr': 'unauthenticated',
561
- },
562
- },
563
- },
564
- ],
565
- },
566
- Policies: [
567
- {
568
- PolicyName: 'CognitoUnauthenticatedPolicy',
569
- PolicyDocument: {
570
- Version: '2012-10-17',
571
- Statement: [
572
- {
573
- Effect: 'Allow',
574
- Action: [
575
- 'cognito-sync:*',
576
- ],
577
- Resource: '*',
578
- },
579
- ],
580
- },
581
- },
582
- ],
583
- Tags: [
584
- { Key: 'Name', Value: resourceName },
585
- { Key: 'Environment', Value: environment },
586
- ],
587
- },
588
- }
589
-
590
- return { role, logicalId }
591
- }
592
-
593
- /**
594
- * Common password policies
595
- */
596
- static readonly PasswordPolicies = {
597
- /**
598
- * Relaxed password policy for development
599
- */
600
- relaxed: (): PasswordPolicyOptions => ({
601
- minimumLength: 8,
602
- requireLowercase: false,
603
- requireUppercase: false,
604
- requireNumbers: false,
605
- requireSymbols: false,
606
- temporaryPasswordValidityDays: 7,
607
- }),
608
-
609
- /**
610
- * Standard password policy
611
- */
612
- standard: (): PasswordPolicyOptions => ({
613
- minimumLength: 8,
614
- requireLowercase: true,
615
- requireUppercase: true,
616
- requireNumbers: true,
617
- requireSymbols: false,
618
- temporaryPasswordValidityDays: 3,
619
- }),
620
-
621
- /**
622
- * Strict password policy for production
623
- */
624
- strict: (): PasswordPolicyOptions => ({
625
- minimumLength: 12,
626
- requireLowercase: true,
627
- requireUppercase: true,
628
- requireNumbers: true,
629
- requireSymbols: true,
630
- temporaryPasswordValidityDays: 1,
631
- }),
632
- } as const
633
-
634
- /**
635
- * Common authentication flows
636
- */
637
- static readonly AuthFlows = {
638
- /**
639
- * Standard auth flows (SRP, refresh token)
640
- */
641
- standard: [
642
- 'ALLOW_USER_SRP_AUTH',
643
- 'ALLOW_REFRESH_TOKEN_AUTH',
644
- ],
645
-
646
- /**
647
- * Admin auth flows (for server-side authentication)
648
- */
649
- admin: [
650
- 'ALLOW_ADMIN_USER_PASSWORD_AUTH',
651
- 'ALLOW_REFRESH_TOKEN_AUTH',
652
- ],
653
-
654
- /**
655
- * Custom auth flows
656
- */
657
- custom: [
658
- 'ALLOW_CUSTOM_AUTH',
659
- 'ALLOW_REFRESH_TOKEN_AUTH',
660
- ],
661
-
662
- /**
663
- * All auth flows (not recommended for production)
664
- */
665
- all: [
666
- 'ALLOW_USER_SRP_AUTH',
667
- 'ALLOW_USER_PASSWORD_AUTH',
668
- 'ALLOW_ADMIN_USER_PASSWORD_AUTH',
669
- 'ALLOW_CUSTOM_AUTH',
670
- 'ALLOW_REFRESH_TOKEN_AUTH',
671
- ],
672
- } as const
673
-
674
- /**
675
- * Common OAuth scopes
676
- */
677
- static readonly OAuthScopes = {
678
- /**
679
- * Basic OAuth scopes
680
- */
681
- basic: [
682
- 'openid',
683
- 'email',
684
- 'profile',
685
- ],
686
-
687
- /**
688
- * All standard scopes
689
- */
690
- all: [
691
- 'openid',
692
- 'email',
693
- 'profile',
694
- 'phone',
695
- 'aws.cognito.signin.user.admin',
696
- ],
697
- } as const
698
-
699
- /**
700
- * Common use cases
701
- */
702
- static readonly UseCases = {
703
- /**
704
- * Create a basic user pool for web application
705
- */
706
- webApp: (slug: string, environment: EnvironmentType, callbackUrl: string): {
707
- userPool: CognitoUserPool
708
- poolId: string
709
- client: CognitoUserPoolClient
710
- clientId: string
711
- } => {
712
- const { userPool, logicalId: poolId } = Auth.createUserPool({
713
- slug,
714
- environment,
715
- aliasAttributes: ['email'],
716
- autoVerifiedAttributes: ['email'],
717
- passwordPolicy: Auth.PasswordPolicies.standard(),
718
- mfaConfiguration: 'OPTIONAL',
719
- })
720
-
721
- const { client, logicalId: clientId } = Auth.createUserPoolClient(poolId, {
722
- slug,
723
- environment,
724
- explicitAuthFlows: [...Auth.AuthFlows.standard],
725
- callbackURLs: [callbackUrl],
726
- allowedOAuthFlows: ['code'],
727
- allowedOAuthScopes: [...Auth.OAuthScopes.basic],
728
- allowedOAuthFlowsUserPoolClient: true,
729
- })
730
-
731
- return { userPool, poolId, client, clientId }
732
- },
733
-
734
- /**
735
- * Create a user pool with identity pool for mobile app
736
- */
737
- mobileApp: (slug: string, environment: EnvironmentType): {
738
- userPool: CognitoUserPool
739
- poolId: string
740
- client: CognitoUserPoolClient
741
- clientId: string
742
- identityPool: CognitoIdentityPool
743
- identityPoolId: string
744
- authRole: IAMRole
745
- authRoleId: string
746
- attachment: CognitoIdentityPoolRoleAttachment
747
- attachmentId: string
748
- } => {
749
- const { userPool, logicalId: poolId } = Auth.createUserPool({
750
- slug,
751
- environment,
752
- aliasAttributes: ['email'],
753
- autoVerifiedAttributes: ['email'],
754
- passwordPolicy: Auth.PasswordPolicies.standard(),
755
- mfaConfiguration: 'OPTIONAL',
756
- })
757
-
758
- const { client, logicalId: clientId } = Auth.createUserPoolClient(poolId, {
759
- slug,
760
- environment,
761
- explicitAuthFlows: [...Auth.AuthFlows.standard],
762
- })
763
-
764
- const { identityPool, logicalId: identityPoolId } = Auth.createIdentityPool({
765
- slug,
766
- environment,
767
- allowUnauthenticatedIdentities: false,
768
- cognitoIdentityProviders: [
769
- {
770
- ClientId: Fn.Ref(clientId) as unknown as string,
771
- ProviderName: Fn.GetAtt(poolId, 'ProviderName') as unknown as string,
772
- },
773
- ],
774
- })
775
-
776
- const { role: authRole, logicalId: authRoleId } = Auth.createAuthenticatedRole({
777
- slug,
778
- environment,
779
- identityPoolLogicalId: identityPoolId,
780
- })
781
-
782
- const { attachment, logicalId: attachmentId } = Auth.createIdentityPoolRoleAttachment(
783
- identityPoolId,
784
- {
785
- slug,
786
- environment,
787
- authenticatedRole: Fn.GetAtt(authRoleId, 'Arn') as unknown as string,
788
- },
789
- )
790
-
791
- return {
792
- userPool,
793
- poolId,
794
- client,
795
- clientId,
796
- identityPool,
797
- identityPoolId,
798
- authRole,
799
- authRoleId,
800
- attachment,
801
- attachmentId,
802
- }
803
- },
804
- } as const
805
- }