@stacksjs/ts-cloud-types 0.1.7 → 0.1.9

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/src/index.ts ADDED
@@ -0,0 +1,2804 @@
1
+ /**
2
+ * AWS-specific configuration
3
+ */
4
+ export interface AwsConfig {
5
+ /**
6
+ * AWS region for deployment
7
+ */
8
+ region?: string
9
+
10
+ /**
11
+ * AWS CLI profile to use
12
+ */
13
+ profile?: string
14
+
15
+ /**
16
+ * AWS account ID
17
+ */
18
+ accountId?: string
19
+ }
20
+
21
+ // Core configuration types
22
+ export interface CloudConfig {
23
+ project: ProjectConfig
24
+ mode?: DeploymentMode // Optional - auto-detected from infrastructure config
25
+ environments: Record<string, EnvironmentConfig>
26
+ infrastructure?: InfrastructureConfig
27
+ sites?: Record<string, SiteConfig>
28
+
29
+ /**
30
+ * AWS-specific configuration
31
+ */
32
+ aws?: AwsConfig
33
+
34
+ /**
35
+ * Feature flags to enable/disable resources conditionally
36
+ * Example: { enableCache: true, enableMonitoring: false }
37
+ */
38
+ features?: Record<string, boolean>
39
+
40
+ /**
41
+ * Deployment hooks for custom logic
42
+ */
43
+ hooks?: {
44
+ beforeDeploy?: string | ((config: CloudConfig) => Promise<void>)
45
+ afterDeploy?: string | ((config: CloudConfig) => Promise<void>)
46
+ beforeBuild?: string | ((config: CloudConfig) => Promise<void>)
47
+ afterBuild?: string | ((config: CloudConfig) => Promise<void>)
48
+ }
49
+
50
+ /**
51
+ * Cost optimization preset
52
+ * Automatically adjusts resource sizes based on budget
53
+ */
54
+ costPreset?: 'minimal' | 'balanced' | 'performance' | 'custom'
55
+
56
+ /**
57
+ * Tags applied to all resources
58
+ */
59
+ tags?: Record<string, string>
60
+ }
61
+
62
+ export type CloudOptions = Partial<CloudConfig>
63
+
64
+ export interface ProjectConfig {
65
+ name: string
66
+ slug: string
67
+ region: string
68
+ }
69
+
70
+ /**
71
+ * Deployment mode (optional)
72
+ * @deprecated Mode is now auto-detected from your infrastructure configuration.
73
+ * Simply define the resources you need (functions, servers, storage, etc.) and
74
+ * ts-cloud will deploy them accordingly. No need to specify a mode.
75
+ */
76
+ export type DeploymentMode = 'server' | 'serverless' | 'hybrid'
77
+
78
+ export type EnvironmentType = 'production' | 'staging' | 'development'
79
+
80
+ export interface EnvironmentConfig {
81
+ type: EnvironmentType
82
+ region?: string
83
+ variables?: Record<string, string>
84
+ /**
85
+ * Custom domain for this environment
86
+ * Example: 'example.com' for production, 'staging.example.com' for staging
87
+ */
88
+ domain?: string
89
+ /**
90
+ * Environment-specific infrastructure overrides
91
+ * Allows different infrastructure per environment
92
+ * Example: smaller instances in dev, larger in production
93
+ */
94
+ infrastructure?: Partial<InfrastructureConfig>
95
+ }
96
+
97
+ /**
98
+ * Network/VPC configuration
99
+ */
100
+ export interface NetworkConfig {
101
+ vpc?: VpcConfig
102
+ subnets?: {
103
+ public?: number
104
+ private?: number
105
+ }
106
+ natGateway?: boolean | 'single' | 'perAz'
107
+ }
108
+
109
+ /**
110
+ * API Gateway configuration
111
+ */
112
+ export interface ApiGatewayConfig {
113
+ type?: 'REST' | 'HTTP' | 'websocket'
114
+ name?: string
115
+ description?: string
116
+ stageName?: string
117
+ cors?: boolean | {
118
+ allowOrigins?: string[]
119
+ allowMethods?: string[]
120
+ allowHeaders?: string[]
121
+ maxAge?: number
122
+ }
123
+ authorization?: 'NONE' | 'IAM' | 'COGNITO' | 'LAMBDA'
124
+ throttling?: {
125
+ rateLimit?: number
126
+ burstLimit?: number
127
+ }
128
+ customDomain?: {
129
+ domain?: string
130
+ certificateArn?: string
131
+ }
132
+ authorizer?: {
133
+ type?: string
134
+ identitySource?: string
135
+ audience?: string[]
136
+ }
137
+ routes?: Array<{
138
+ path?: string
139
+ method?: string
140
+ integration?: string | { type?: string; service?: string }
141
+ authorizer?: string
142
+ }> | Record<string, {
143
+ path?: string
144
+ method?: string
145
+ integration?: string | { type?: string; service?: string }
146
+ }>
147
+ }
148
+
149
+ /**
150
+ * Messaging (SNS) configuration
151
+ */
152
+ export interface MessagingConfig {
153
+ topics?: Record<string, {
154
+ name?: string
155
+ displayName?: string
156
+ subscriptions?: Array<{
157
+ protocol: 'email' | 'sqs' | 'lambda' | 'http' | 'https'
158
+ endpoint: string
159
+ filterPolicy?: Record<string, string[]>
160
+ }>
161
+ }>
162
+ }
163
+
164
+ export interface InfrastructureConfig {
165
+ vpc?: VpcConfig
166
+
167
+ /**
168
+ * Network/VPC configuration
169
+ * Defines the network infrastructure including VPC, subnets, and NAT gateways
170
+ */
171
+ network?: NetworkConfig
172
+
173
+ /**
174
+ * Compute/EC2 configuration
175
+ * Defines the EC2 instances running your Stacks/Bun application
176
+ *
177
+ * @example
178
+ * // Single instance (no load balancer needed)
179
+ * compute: {
180
+ * instances: 1,
181
+ * instanceType: 't3.micro',
182
+ * }
183
+ *
184
+ * @example
185
+ * // Multiple instances (load balancer auto-enabled)
186
+ * compute: {
187
+ * instances: 3,
188
+ * instanceType: 't3.small',
189
+ * autoScaling: {
190
+ * min: 2,
191
+ * max: 10,
192
+ * scaleUpThreshold: 70,
193
+ * },
194
+ * }
195
+ */
196
+ compute?: ComputeConfig
197
+
198
+ /**
199
+ * Container configuration (ECS Fargate)
200
+ * Defines containerized services for serverless deployment mode
201
+ *
202
+ * @example
203
+ * containers: {
204
+ * api: {
205
+ * cpu: 512,
206
+ * memory: 1024,
207
+ * port: 3000,
208
+ * healthCheck: '/health',
209
+ * desiredCount: 2,
210
+ * autoScaling: { min: 1, max: 10, targetCpuUtilization: 70 },
211
+ * }
212
+ * }
213
+ */
214
+ containers?: Record<string, ContainerItemConfig>
215
+
216
+ storage?: Record<string, StorageItemConfig & ResourceConditions>
217
+ functions?: Record<string, FunctionConfig & ResourceConditions>
218
+ /** @deprecated Use `compute` instead for EC2 configuration */
219
+ servers?: Record<string, ServerItemConfig & ResourceConditions>
220
+ databases?: Record<string, DatabaseItemConfig & ResourceConditions>
221
+ cache?: CacheConfig
222
+ cdn?: Record<string, CdnItemConfig & ResourceConditions> | CdnItemConfig
223
+ /**
224
+ * Elastic File System (EFS) configuration
225
+ * For shared file storage across multiple instances
226
+ */
227
+ fileSystem?: Record<string, FileSystemItemConfig>
228
+
229
+ /**
230
+ * API Gateway configuration
231
+ * Defines the API Gateway for routing HTTP requests to Lambda functions
232
+ */
233
+ apiGateway?: ApiGatewayConfig
234
+
235
+ /**
236
+ * Messaging (SNS) configuration
237
+ * Defines SNS topics for pub/sub messaging patterns
238
+ */
239
+ messaging?: MessagingConfig
240
+
241
+ /**
242
+ * Queue (SQS) configuration
243
+ * Defines message queues for async processing, background jobs, and event-driven architectures
244
+ *
245
+ * @example
246
+ * queues: {
247
+ * // Standard queue for background jobs
248
+ * jobs: {
249
+ * visibilityTimeout: 120,
250
+ * deadLetterQueue: true,
251
+ * },
252
+ * // FIFO queue for ordered processing
253
+ * orders: {
254
+ * fifo: true,
255
+ * contentBasedDeduplication: true,
256
+ * },
257
+ * // High-throughput events queue
258
+ * events: {
259
+ * receiveMessageWaitTime: 20,
260
+ * },
261
+ * }
262
+ */
263
+ queues?: Record<string, QueueItemConfig & ResourceConditions>
264
+
265
+ /**
266
+ * Realtime (WebSocket) configuration
267
+ * Laravel Echo / Pusher-compatible broadcasting for Stacks.js
268
+ *
269
+ * @example
270
+ * realtime: {
271
+ * enabled: true,
272
+ * channels: { public: true, private: true, presence: true },
273
+ * auth: { functionName: 'authorizeChannel' },
274
+ * }
275
+ *
276
+ * @example Using presets
277
+ * realtime: RealtimePresets.production
278
+ */
279
+ realtime?: RealtimeConfig
280
+
281
+ dns?: DnsConfig
282
+ security?: SecurityConfig
283
+ monitoring?: MonitoringConfig
284
+ api?: ApiConfig
285
+ loadBalancer?: LoadBalancerConfig
286
+ ssl?: SslConfig
287
+ streaming?: Record<string, {
288
+ name?: string
289
+ shardCount?: number
290
+ retentionPeriod?: number
291
+ encryption?: boolean | string
292
+ }>
293
+ machineLearning?: {
294
+ sagemakerEndpoint?: string
295
+ modelBucket?: string
296
+ sagemaker?: {
297
+ endpointName?: string
298
+ instanceType?: string
299
+ endpoints?: Array<{
300
+ name?: string
301
+ modelName?: string
302
+ modelS3Path?: string
303
+ instanceType?: string
304
+ instanceCount?: number
305
+ initialInstanceCount?: number
306
+ autoScaling?: {
307
+ minInstances?: number
308
+ maxInstances?: number
309
+ targetInvocationsPerInstance?: number
310
+ }
311
+ }>
312
+ trainingJobs?: Array<{
313
+ name?: string
314
+ algorithmSpecification?: {
315
+ trainingImage?: string
316
+ trainingInputMode?: string
317
+ }
318
+ instanceType?: string
319
+ instanceCount?: number
320
+ volumeSizeInGB?: number
321
+ maxRuntimeInSeconds?: number
322
+ }>
323
+ }
324
+ }
325
+ analytics?: {
326
+ enabled?: boolean
327
+ firehose?: Record<string, {
328
+ name?: string
329
+ destination?: string
330
+ bufferSize?: number
331
+ bufferInterval?: number
332
+ }>
333
+ athena?: {
334
+ database?: string
335
+ workgroup?: string
336
+ outputLocation?: string
337
+ outputBucket?: string
338
+ tables?: Array<{
339
+ name?: string
340
+ location?: string
341
+ format?: string
342
+ partitionKeys?: string[]
343
+ }>
344
+ }
345
+ glue?: {
346
+ crawlers?: Array<{
347
+ name?: string
348
+ databaseName?: string
349
+ s3Targets?: string[]
350
+ schedule?: string
351
+ }>
352
+ jobs?: Array<{
353
+ name?: string
354
+ scriptLocation?: string
355
+ role?: string
356
+ maxCapacity?: number
357
+ timeout?: number
358
+ }>
359
+ }
360
+ }
361
+ workflow?: {
362
+ pipelines?: Array<{
363
+ name?: string
364
+ type?: 'stepFunctions' | string
365
+ definition?: Record<string, unknown>
366
+ schedule?: string
367
+ }>
368
+ }
369
+ }
370
+
371
+ /**
372
+ * Conditions that determine if a resource should be deployed
373
+ */
374
+ export interface ResourceConditions {
375
+ /**
376
+ * Only deploy in these environments
377
+ * Example: ['production', 'staging']
378
+ */
379
+ environments?: EnvironmentType[]
380
+
381
+ /**
382
+ * Only deploy if these features are enabled
383
+ * Example: ['enableDatabase', 'enableCache']
384
+ */
385
+ requiresFeatures?: string[]
386
+
387
+ /**
388
+ * Only deploy in these regions
389
+ */
390
+ regions?: string[]
391
+
392
+ /**
393
+ * Custom condition function
394
+ */
395
+ condition?: (config: CloudConfig, env: EnvironmentType) => boolean
396
+ }
397
+
398
+ export interface SiteConfig {
399
+ /** Root directory containing the built static files (e.g., '.output/public', 'dist') */
400
+ root: string
401
+ /** Path prefix for deployment (usually '/') */
402
+ path?: string
403
+ /** Custom domain for the site (e.g., 'stage.easyotc.com') */
404
+ domain?: string
405
+ /** SSL certificate ARN (auto-created if not provided) */
406
+ certificateArn?: string
407
+ /** Build command to run before deployment (e.g., 'bun run generate', 'npm run build') */
408
+ build?: string
409
+ }
410
+
411
+ export interface VpcConfig {
412
+ cidr?: string
413
+ zones?: number
414
+ availabilityZones?: number // Alias for zones
415
+ natGateway?: boolean
416
+ natGateways?: number | boolean
417
+ }
418
+
419
+ export interface StorageConfig {
420
+ buckets?: BucketConfig[]
421
+ }
422
+
423
+ export interface BucketConfig {
424
+ name: string
425
+ public?: boolean
426
+ versioning?: boolean
427
+ website?: boolean
428
+ encryption?: boolean
429
+ }
430
+
431
+ export interface DatabaseConfig {
432
+ type?: 'rds' | 'dynamodb'
433
+ engine?: 'postgres' | 'mysql'
434
+ instanceType?: string
435
+ }
436
+
437
+ export interface CacheConfig {
438
+ type?: 'redis' | 'memcached'
439
+ nodeType?: string
440
+ /**
441
+ * Redis-specific configuration
442
+ */
443
+ redis?: {
444
+ nodeType?: string
445
+ numCacheNodes?: number
446
+ engine?: string
447
+ engineVersion?: string
448
+ port?: number
449
+ parameterGroup?: Record<string, string>
450
+ snapshotRetentionLimit?: number
451
+ snapshotWindow?: string
452
+ automaticFailoverEnabled?: boolean
453
+ }
454
+ /**
455
+ * ElastiCache configuration
456
+ */
457
+ elasticache?: {
458
+ nodeType?: string
459
+ numCacheNodes?: number
460
+ engine?: string
461
+ engineVersion?: string
462
+ }
463
+ }
464
+
465
+ export interface CdnConfig {
466
+ enabled?: boolean
467
+ customDomain?: string
468
+ certificateArn?: string
469
+ }
470
+
471
+ export interface DnsConfig {
472
+ domain?: string
473
+ hostedZoneId?: string
474
+ /**
475
+ * External DNS provider configuration
476
+ * When set, DNS records will be managed via the external provider API
477
+ * instead of Route53
478
+ */
479
+ provider?: 'route53' | 'cloudflare' | 'porkbun' | 'godaddy'
480
+ }
481
+
482
+ export interface SecurityConfig {
483
+ waf?: WafConfig
484
+ kms?: boolean
485
+ /**
486
+ * SSL/TLS Certificate configuration
487
+ */
488
+ certificate?: {
489
+ domain: string
490
+ subdomains?: string[]
491
+ validationMethod?: 'DNS' | 'EMAIL'
492
+ }
493
+ /**
494
+ * Security groups configuration
495
+ */
496
+ securityGroups?: Record<string, {
497
+ ingress?: Array<{
498
+ port: number
499
+ protocol: string
500
+ cidr?: string
501
+ source?: string
502
+ }>
503
+ egress?: Array<{
504
+ port: number
505
+ protocol: string
506
+ cidr?: string
507
+ destination?: string
508
+ }>
509
+ }>
510
+ }
511
+
512
+ export interface WafConfig {
513
+ enabled?: boolean
514
+ blockCountries?: string[]
515
+ blockIps?: string[]
516
+ rateLimit?: number
517
+ /**
518
+ * WAF rules to enable
519
+ * @example ['rateLimit', 'sqlInjection', 'xss']
520
+ */
521
+ rules?: string[]
522
+ }
523
+
524
+ export interface MonitoringConfig {
525
+ alarms?: Record<string, AlarmItemConfig> | AlarmItemConfig[]
526
+ dashboards?: boolean
527
+ /**
528
+ * Dashboard configuration
529
+ */
530
+ dashboard?: {
531
+ name?: string
532
+ widgets?: Array<{
533
+ type?: string
534
+ metrics?: string[] | Array<{
535
+ service?: string
536
+ metric?: string
537
+ }>
538
+ }>
539
+ }
540
+ /**
541
+ * Log configuration
542
+ */
543
+ logs?: {
544
+ retention?: number
545
+ groups?: string[]
546
+ }
547
+ }
548
+
549
+ export interface AlarmConfig {
550
+ name: string
551
+ metric: string
552
+ threshold: number
553
+ }
554
+
555
+ export interface AlarmItemConfig {
556
+ /**
557
+ * Name of the alarm (optional, auto-generated if not provided)
558
+ */
559
+ name?: string
560
+ /**
561
+ * Metric name (short form)
562
+ */
563
+ metric?: string
564
+ metricName?: string
565
+ namespace?: string
566
+ threshold: number
567
+ comparisonOperator?: string
568
+ /**
569
+ * Period in seconds for metric aggregation
570
+ */
571
+ period?: number
572
+ /**
573
+ * Number of periods to evaluate
574
+ */
575
+ evaluationPeriods?: number
576
+ /**
577
+ * Service name for service-specific alarms
578
+ */
579
+ service?: string
580
+ }
581
+
582
+ export interface StorageItemConfig {
583
+ /**
584
+ * Make bucket publicly accessible
585
+ */
586
+ public?: boolean
587
+ versioning?: boolean
588
+ encryption?: boolean
589
+ encrypted?: boolean // Alias for encryption (for EFS compatibility)
590
+ website?: boolean | {
591
+ indexDocument?: string
592
+ errorDocument?: string
593
+ }
594
+ /**
595
+ * Storage type (for special storage like EFS)
596
+ */
597
+ type?: 'efs' | 's3'
598
+ /**
599
+ * Enable Intelligent Tiering for cost optimization
600
+ */
601
+ intelligentTiering?: boolean
602
+ /**
603
+ * CORS configuration
604
+ */
605
+ cors?: Array<{
606
+ allowedOrigins?: string[]
607
+ allowedMethods?: string[]
608
+ allowedHeaders?: string[]
609
+ maxAge?: number
610
+ }>
611
+ /**
612
+ * Lifecycle rules for automatic transitions/deletions
613
+ */
614
+ lifecycleRules?: Array<{
615
+ id?: string
616
+ enabled?: boolean
617
+ expirationDays?: number
618
+ transitions?: Array<{
619
+ days?: number
620
+ storageClass?: string
621
+ }>
622
+ }>
623
+ /**
624
+ * Performance mode (for EFS)
625
+ */
626
+ performanceMode?: string
627
+ /**
628
+ * Throughput mode (for EFS)
629
+ */
630
+ throughputMode?: string
631
+ /**
632
+ * Lifecycle policy (for EFS)
633
+ */
634
+ lifecyclePolicy?: {
635
+ transitionToIA?: number
636
+ }
637
+ }
638
+
639
+ export interface FunctionConfig {
640
+ handler?: string
641
+ runtime?: string
642
+ code?: string
643
+ timeout?: number
644
+ memorySize?: number
645
+ memory?: number // Alias for memorySize
646
+ events?: Array<{
647
+ type?: string
648
+ path?: string
649
+ method?: string
650
+ queueName?: string
651
+ streamName?: string
652
+ tableName?: string
653
+ expression?: string
654
+ batchSize?: number
655
+ startingPosition?: string
656
+ parallelizationFactor?: number
657
+ bucket?: string
658
+ prefix?: string
659
+ suffix?: string
660
+ }>
661
+ environment?: Record<string, string>
662
+ }
663
+
664
+ /**
665
+ * Elastic File System (EFS) configuration
666
+ */
667
+ export interface FileSystemItemConfig {
668
+ /**
669
+ * Performance mode
670
+ */
671
+ performanceMode?: 'generalPurpose' | 'maxIO' | string
672
+ /**
673
+ * Throughput mode
674
+ */
675
+ throughputMode?: 'bursting' | 'provisioned' | string
676
+ /**
677
+ * Enable encryption
678
+ */
679
+ encrypted?: boolean
680
+ /**
681
+ * Lifecycle policy
682
+ */
683
+ lifecyclePolicy?: {
684
+ transitionToIA?: number
685
+ }
686
+ /**
687
+ * Mount path
688
+ */
689
+ mountPath?: string
690
+ }
691
+
692
+ /**
693
+ * Instance size presets
694
+ * Provider-agnostic sizing that maps to appropriate instance types
695
+ */
696
+ export type InstanceSize =
697
+ | 'nano' // ~0.5 vCPU, 0.5GB RAM
698
+ | 'micro' // ~1 vCPU, 1GB RAM
699
+ | 'small' // ~1 vCPU, 2GB RAM
700
+ | 'medium' // ~2 vCPU, 4GB RAM
701
+ | 'large' // ~2 vCPU, 8GB RAM
702
+ | 'xlarge' // ~4 vCPU, 16GB RAM
703
+ | '2xlarge' // ~8 vCPU, 32GB RAM
704
+ | (string & {}) // Allow provider-specific types like 't3.micro'
705
+
706
+ /**
707
+ * Server/VM Instance Configuration
708
+ */
709
+ export interface ServerItemConfig {
710
+ /**
711
+ * Instance size or provider-specific type
712
+ * @example 'small', 'medium', 'large' or 't3.micro'
713
+ * @default 'micro'
714
+ */
715
+ size?: InstanceSize
716
+
717
+ /**
718
+ * Custom machine image (optional)
719
+ * If not specified, uses the provider's default Linux image
720
+ */
721
+ image?: string
722
+
723
+ /**
724
+ * Custom startup script
725
+ */
726
+ startupScript?: string
727
+ }
728
+
729
+ /**
730
+ * Instance configuration for mixed instance fleets
731
+ */
732
+ export interface InstanceConfig {
733
+ /**
734
+ * Instance size or provider-specific type
735
+ * @example 'small', 'medium', 'large' or 't3.micro'
736
+ */
737
+ size: InstanceSize
738
+
739
+ /**
740
+ * Weight for this instance type in auto scaling
741
+ * Higher weight = more capacity per instance
742
+ * @default 1
743
+ */
744
+ weight?: number
745
+
746
+ /**
747
+ * Use spot/preemptible instances for cost savings
748
+ * @default false
749
+ */
750
+ spot?: boolean
751
+
752
+ /**
753
+ * Maximum price for spot instances (per hour)
754
+ * Only used when spot: true
755
+ */
756
+ maxPrice?: string
757
+ }
758
+
759
+ /**
760
+ * Compute Configuration
761
+ * Defines the virtual machines/instances for your application
762
+ *
763
+ * @example Single instance
764
+ * compute: {
765
+ * instances: 1,
766
+ * size: 'small',
767
+ * }
768
+ *
769
+ * @example Multiple instances (auto-enables load balancer)
770
+ * compute: {
771
+ * instances: 3,
772
+ * size: 'medium',
773
+ * autoScaling: { min: 2, max: 10 },
774
+ * }
775
+ *
776
+ * @example Mixed instance fleet for cost optimization
777
+ * compute: {
778
+ * instances: 3,
779
+ * fleet: [
780
+ * { size: 'small', weight: 1 },
781
+ * { size: 'medium', weight: 2 },
782
+ * { size: 'small', weight: 1, spot: true },
783
+ * ],
784
+ * }
785
+ */
786
+ export interface ContainerItemConfig {
787
+ cpu?: number
788
+ memory?: number
789
+ port?: number
790
+ healthCheck?: string
791
+ desiredCount?: number
792
+ autoScaling?: {
793
+ min?: number
794
+ max?: number
795
+ targetCpuUtilization?: number
796
+ targetMemoryUtilization?: number
797
+ }
798
+ }
799
+
800
+ export interface ComputeConfig {
801
+ /**
802
+ * Compute mode: 'server' for EC2, 'serverless' for Fargate/Lambda
803
+ */
804
+ mode?: 'server' | 'serverless'
805
+
806
+ /**
807
+ * Number of instances to run
808
+ * When > 1, load balancer is automatically enabled
809
+ * @default 1
810
+ */
811
+ instances?: number
812
+
813
+ /**
814
+ * Instance size (simple configuration)
815
+ * Use this OR fleet, not both
816
+ * @default 'micro'
817
+ */
818
+ size?: InstanceSize
819
+
820
+ /**
821
+ * Mixed instance fleet for cost optimization
822
+ * Allows combining different sizes and spot instances
823
+ *
824
+ * @example
825
+ * fleet: [
826
+ * { size: 'small', weight: 1 },
827
+ * { size: 'medium', weight: 2 },
828
+ * { size: 'small', weight: 1, spot: true },
829
+ * ]
830
+ */
831
+ fleet?: InstanceConfig[]
832
+
833
+ /**
834
+ * Custom machine image (optional)
835
+ * If not specified, uses the provider's default Linux image
836
+ */
837
+ image?: string
838
+
839
+ /**
840
+ * Server mode (EC2) configuration
841
+ */
842
+ server?: {
843
+ instanceType?: string
844
+ ami?: string
845
+ keyPair?: string
846
+ autoScaling?: {
847
+ min?: number
848
+ max?: number
849
+ desired?: number
850
+ targetCPU?: number
851
+ scaleUpCooldown?: number
852
+ scaleDownCooldown?: number
853
+ }
854
+ loadBalancer?: {
855
+ type?: string
856
+ healthCheck?: {
857
+ path?: string
858
+ interval?: number
859
+ timeout?: number
860
+ healthyThreshold?: number
861
+ unhealthyThreshold?: number
862
+ }
863
+ stickySession?: {
864
+ enabled?: boolean
865
+ duration?: number
866
+ }
867
+ }
868
+ userData?: string | {
869
+ packages?: string[]
870
+ commands?: string[]
871
+ }
872
+ }
873
+
874
+ /**
875
+ * Serverless configuration (ECS/Lambda)
876
+ */
877
+ serverless?: {
878
+ cpu?: number
879
+ memory?: number
880
+ desiredCount?: number
881
+ }
882
+
883
+ /**
884
+ * Fargate configuration
885
+ */
886
+ fargate?: {
887
+ taskDefinition?: {
888
+ cpu?: string
889
+ memory?: string
890
+ containerDefinitions?: Array<{
891
+ name?: string
892
+ image?: string
893
+ portMappings?: Array<{
894
+ containerPort?: number
895
+ }>
896
+ environment?: unknown[]
897
+ secrets?: unknown[]
898
+ }>
899
+ }
900
+ service?: {
901
+ desiredCount?: number
902
+ healthCheck?: {
903
+ path?: string
904
+ interval?: number
905
+ timeout?: number
906
+ healthyThreshold?: number
907
+ unhealthyThreshold?: number
908
+ }
909
+ serviceDiscovery?: {
910
+ enabled?: boolean
911
+ namespace?: string
912
+ }
913
+ autoScaling?: {
914
+ min?: number
915
+ max?: number
916
+ targetCPU?: number
917
+ targetMemory?: number
918
+ }
919
+ }
920
+ loadBalancer?: {
921
+ type?: string
922
+ customDomain?: {
923
+ domain?: string
924
+ certificateArn?: string
925
+ }
926
+ }
927
+ }
928
+
929
+ /**
930
+ * Microservices configuration
931
+ */
932
+ services?: Array<{
933
+ name: string
934
+ type?: string
935
+ taskDefinition?: {
936
+ cpu?: string
937
+ memory?: string
938
+ containerDefinitions?: Array<{
939
+ name?: string
940
+ image?: string
941
+ portMappings?: Array<{
942
+ containerPort?: number
943
+ }>
944
+ healthCheck?: {
945
+ command?: string[]
946
+ interval?: number
947
+ timeout?: number
948
+ retries?: number
949
+ }
950
+ }>
951
+ }
952
+ service?: {
953
+ desiredCount?: number
954
+ serviceDiscovery?: {
955
+ enabled?: boolean
956
+ namespace?: string
957
+ }
958
+ autoScaling?: {
959
+ min?: number
960
+ max?: number
961
+ targetCPU?: number
962
+ }
963
+ }
964
+ }>
965
+
966
+ /**
967
+ * Auto Scaling configuration
968
+ */
969
+ autoScaling?: {
970
+ /** Minimum number of instances @default 1 */
971
+ min?: number
972
+ /** Maximum number of instances @default instances value */
973
+ max?: number
974
+ /** Desired number of instances @default instances value */
975
+ desired?: number
976
+ /** CPU threshold to scale up (%) @default 70 */
977
+ scaleUpThreshold?: number
978
+ /** CPU threshold to scale down (%) @default 30 */
979
+ scaleDownThreshold?: number
980
+ /** Cooldown in seconds @default 300 */
981
+ cooldown?: number
982
+ }
983
+
984
+ /**
985
+ * Root disk configuration
986
+ */
987
+ disk?: {
988
+ /** Size in GB @default 20 */
989
+ size?: number
990
+ /** Disk type @default 'ssd' */
991
+ type?: 'standard' | 'ssd' | 'premium'
992
+ /** Enable encryption @default true */
993
+ encrypted?: boolean
994
+ }
995
+
996
+ /**
997
+ * SSH key name for instance access
998
+ */
999
+ sshKey?: string
1000
+
1001
+ /**
1002
+ * Enable detailed monitoring
1003
+ * @default false
1004
+ */
1005
+ monitoring?: boolean
1006
+
1007
+ /**
1008
+ * Spot/preemptible instance settings (when using fleet)
1009
+ */
1010
+ spotConfig?: {
1011
+ /** Base capacity that must be on-demand @default 1 */
1012
+ baseCapacity?: number
1013
+ /** % of instances above base that are on-demand @default 100 */
1014
+ onDemandPercentage?: number
1015
+ /** Allocation strategy @default 'capacity-optimized' */
1016
+ strategy?: 'lowest-price' | 'capacity-optimized'
1017
+ }
1018
+ }
1019
+
1020
+ export interface DatabaseItemConfig {
1021
+ engine?: 'dynamodb' | 'postgres' | 'mysql'
1022
+ partitionKey?: string | { name: string; type: string }
1023
+ sortKey?: string | { name: string; type: string }
1024
+ username?: string
1025
+ password?: string
1026
+ storage?: number
1027
+ instanceClass?: string
1028
+ version?: string
1029
+ allocatedStorage?: number
1030
+ maxAllocatedStorage?: number
1031
+ multiAZ?: boolean
1032
+ backupRetentionDays?: number
1033
+ preferredBackupWindow?: string
1034
+ preferredMaintenanceWindow?: string
1035
+ deletionProtection?: boolean
1036
+ streamEnabled?: boolean
1037
+ pointInTimeRecovery?: boolean
1038
+ billingMode?: string
1039
+ parameters?: Record<string, string | number>
1040
+ databaseName?: string
1041
+ enablePerformanceInsights?: boolean
1042
+ performanceInsightsRetention?: number
1043
+ tables?: Record<string, {
1044
+ name?: string
1045
+ partitionKey?: string | { name: string; type: string }
1046
+ sortKey?: string | { name: string; type: string }
1047
+ billing?: string
1048
+ billingMode?: string
1049
+ streamEnabled?: boolean
1050
+ pointInTimeRecovery?: boolean
1051
+ globalSecondaryIndexes?: Array<{
1052
+ name: string
1053
+ partitionKey: { name: string; type: string }
1054
+ sortKey?: { name: string; type: string }
1055
+ projection: string
1056
+ }>
1057
+ }>
1058
+ }
1059
+
1060
+ export interface CdnItemConfig {
1061
+ origin?: string
1062
+ customDomain?: string | {
1063
+ domain: string
1064
+ certificateArn?: string
1065
+ }
1066
+ certificateArn?: string
1067
+ /**
1068
+ * Custom domain configuration
1069
+ */
1070
+ domain?: string
1071
+ /**
1072
+ * Enable CDN
1073
+ */
1074
+ enabled?: boolean
1075
+ /**
1076
+ * Cache policy configuration
1077
+ */
1078
+ cachePolicy?: {
1079
+ minTTL?: number
1080
+ defaultTTL?: number
1081
+ maxTTL?: number
1082
+ }
1083
+ /**
1084
+ * TTL settings
1085
+ */
1086
+ minTTL?: number
1087
+ defaultTTL?: number
1088
+ maxTTL?: number
1089
+ /**
1090
+ * Enable compression
1091
+ */
1092
+ compress?: boolean
1093
+ /**
1094
+ * Enable HTTP/3
1095
+ */
1096
+ http3?: boolean
1097
+ /**
1098
+ * Custom error pages
1099
+ */
1100
+ errorPages?: Record<number | string, string>
1101
+ /**
1102
+ * Origins configuration
1103
+ */
1104
+ origins?: Array<{
1105
+ type?: string
1106
+ pathPattern?: string
1107
+ domainName?: string
1108
+ originId?: string
1109
+ }>
1110
+ /**
1111
+ * Edge functions for Lambda@Edge
1112
+ */
1113
+ edgeFunctions?: Array<{
1114
+ eventType?: string
1115
+ functionArn?: string
1116
+ name?: string
1117
+ }>
1118
+ }
1119
+
1120
+ /**
1121
+ * Lambda trigger configuration for SQS queues
1122
+ */
1123
+ export interface QueueLambdaTrigger {
1124
+ /**
1125
+ * Name of the Lambda function to trigger (references functions config)
1126
+ * @example 'processOrders' - references infrastructure.functions.processOrders
1127
+ */
1128
+ functionName: string
1129
+
1130
+ /**
1131
+ * Number of messages to process in each batch
1132
+ * @default 10
1133
+ */
1134
+ batchSize?: number
1135
+
1136
+ /**
1137
+ * Maximum time to gather messages before invoking (0-300 seconds)
1138
+ * Helps reduce Lambda invocations for low-traffic queues
1139
+ * @default 0
1140
+ */
1141
+ batchWindow?: number
1142
+
1143
+ /**
1144
+ * Enable partial batch responses (report individual failures)
1145
+ * @default true
1146
+ */
1147
+ reportBatchItemFailures?: boolean
1148
+
1149
+ /**
1150
+ * Maximum concurrency for Lambda invocations (2-1000)
1151
+ * Limits how many concurrent Lambda instances process this queue
1152
+ */
1153
+ maxConcurrency?: number
1154
+
1155
+ /**
1156
+ * Filter pattern to selectively process messages
1157
+ * @example { body: { type: ['order'] } }
1158
+ */
1159
+ filterPattern?: Record<string, unknown>
1160
+ }
1161
+
1162
+ /**
1163
+ * CloudWatch alarm configuration for SQS queues
1164
+ */
1165
+ export interface QueueAlarms {
1166
+ /**
1167
+ * Enable all default alarms
1168
+ * @default false
1169
+ */
1170
+ enabled?: boolean
1171
+
1172
+ /**
1173
+ * Alarm when queue depth exceeds this threshold
1174
+ * @default 1000
1175
+ */
1176
+ queueDepthThreshold?: number
1177
+
1178
+ /**
1179
+ * Alarm when oldest message age exceeds this (in seconds)
1180
+ * @default 3600 (1 hour)
1181
+ */
1182
+ messageAgeThreshold?: number
1183
+
1184
+ /**
1185
+ * Alarm when DLQ has any messages
1186
+ * @default true when deadLetterQueue is enabled
1187
+ */
1188
+ dlqAlarm?: boolean
1189
+
1190
+ /**
1191
+ * SNS topic ARN for alarm notifications
1192
+ */
1193
+ notificationTopicArn?: string
1194
+
1195
+ /**
1196
+ * Email addresses to notify (creates SNS topic automatically)
1197
+ */
1198
+ notificationEmails?: string[]
1199
+ }
1200
+
1201
+ /**
1202
+ * SNS subscription configuration for SQS queues
1203
+ */
1204
+ export interface QueueSnsSubscription {
1205
+ /**
1206
+ * SNS topic ARN to subscribe to
1207
+ */
1208
+ topicArn?: string
1209
+
1210
+ /**
1211
+ * SNS topic name (references infrastructure or creates new)
1212
+ */
1213
+ topicName?: string
1214
+
1215
+ /**
1216
+ * Filter policy for selective message delivery
1217
+ * @example { eventType: ['order.created', 'order.updated'] }
1218
+ */
1219
+ filterPolicy?: Record<string, string[]>
1220
+
1221
+ /**
1222
+ * Apply filter to message attributes (default) or body
1223
+ * @default 'MessageAttributes'
1224
+ */
1225
+ filterPolicyScope?: 'MessageAttributes' | 'MessageBody'
1226
+
1227
+ /**
1228
+ * Enable raw message delivery (no SNS envelope)
1229
+ * @default false
1230
+ */
1231
+ rawMessageDelivery?: boolean
1232
+ }
1233
+
1234
+ /**
1235
+ * Queue (SQS) Configuration
1236
+ * Defines message queue settings for async processing
1237
+ *
1238
+ * @example Standard queue with Lambda trigger
1239
+ * queues: {
1240
+ * orders: {
1241
+ * visibilityTimeout: 60,
1242
+ * deadLetterQueue: true,
1243
+ * trigger: {
1244
+ * functionName: 'processOrders',
1245
+ * batchSize: 10,
1246
+ * },
1247
+ * }
1248
+ * }
1249
+ *
1250
+ * @example FIFO queue with alarms
1251
+ * queues: {
1252
+ * transactions: {
1253
+ * fifo: true,
1254
+ * contentBasedDeduplication: true,
1255
+ * alarms: {
1256
+ * enabled: true,
1257
+ * queueDepthThreshold: 500,
1258
+ * notificationEmails: ['ops@example.com'],
1259
+ * },
1260
+ * }
1261
+ * }
1262
+ *
1263
+ * @example Queue subscribed to SNS topic
1264
+ * queues: {
1265
+ * notifications: {
1266
+ * subscribe: {
1267
+ * topicArn: 'arn:aws:sns:us-east-1:123456789:events',
1268
+ * filterPolicy: { eventType: ['user.created'] },
1269
+ * },
1270
+ * }
1271
+ * }
1272
+ */
1273
+ export interface QueueItemConfig {
1274
+ /**
1275
+ * Enable FIFO (First-In-First-Out) queue
1276
+ * FIFO queues guarantee message ordering and exactly-once processing
1277
+ * @default false
1278
+ */
1279
+ fifo?: boolean
1280
+
1281
+ /**
1282
+ * Time (in seconds) a message is invisible after being received
1283
+ * Should be long enough for your consumer to process the message
1284
+ * @default 30
1285
+ */
1286
+ visibilityTimeout?: number
1287
+
1288
+ /**
1289
+ * Time (in seconds) messages are retained in the queue
1290
+ * Valid range: 60 (1 minute) to 1209600 (14 days)
1291
+ * @default 345600 (4 days)
1292
+ */
1293
+ messageRetentionPeriod?: number
1294
+
1295
+ /**
1296
+ * Time (in seconds) to delay message delivery
1297
+ * Useful for scheduling or rate limiting
1298
+ * Valid range: 0 to 900 (15 minutes)
1299
+ * @default 0
1300
+ */
1301
+ delaySeconds?: number
1302
+
1303
+ /**
1304
+ * Maximum message size in bytes
1305
+ * Valid range: 1024 (1 KB) to 262144 (256 KB)
1306
+ * @default 262144 (256 KB)
1307
+ */
1308
+ maxMessageSize?: number
1309
+
1310
+ /**
1311
+ * Time (in seconds) to wait for messages when polling
1312
+ * Use 1-20 for long polling (recommended), 0 for short polling
1313
+ * Long polling reduces costs and improves responsiveness
1314
+ * @default 0
1315
+ */
1316
+ receiveMessageWaitTime?: number
1317
+
1318
+ /**
1319
+ * Enable dead letter queue for failed messages
1320
+ * Messages that fail processing will be moved to a DLQ
1321
+ * @default false
1322
+ */
1323
+ deadLetterQueue?: boolean
1324
+
1325
+ /**
1326
+ * Number of times a message can be received before going to DLQ
1327
+ * Only used when deadLetterQueue is true
1328
+ * @default 3
1329
+ */
1330
+ maxReceiveCount?: number
1331
+
1332
+ /**
1333
+ * Enable content-based deduplication (FIFO queues only)
1334
+ * Uses SHA-256 hash of message body as deduplication ID
1335
+ * @default false
1336
+ */
1337
+ contentBasedDeduplication?: boolean
1338
+
1339
+ /**
1340
+ * Enable server-side encryption
1341
+ * @default true
1342
+ */
1343
+ encrypted?: boolean
1344
+
1345
+ /**
1346
+ * Custom KMS key ID for encryption
1347
+ * If not specified, uses AWS managed key
1348
+ */
1349
+ kmsKeyId?: string
1350
+
1351
+ /**
1352
+ * Lambda function trigger configuration
1353
+ * Automatically invokes a Lambda when messages arrive
1354
+ *
1355
+ * @example
1356
+ * trigger: {
1357
+ * functionName: 'processOrders',
1358
+ * batchSize: 10,
1359
+ * batchWindow: 30,
1360
+ * }
1361
+ */
1362
+ trigger?: QueueLambdaTrigger
1363
+
1364
+ /**
1365
+ * CloudWatch alarms for queue monitoring
1366
+ * Creates alarms for queue depth, message age, and DLQ
1367
+ *
1368
+ * @example
1369
+ * alarms: {
1370
+ * enabled: true,
1371
+ * queueDepthThreshold: 500,
1372
+ * notificationEmails: ['ops@example.com'],
1373
+ * }
1374
+ */
1375
+ alarms?: QueueAlarms
1376
+
1377
+ /**
1378
+ * Subscribe this queue to an SNS topic
1379
+ * Enables fan-out patterns where one message reaches multiple queues
1380
+ *
1381
+ * @example
1382
+ * subscribe: {
1383
+ * topicArn: 'arn:aws:sns:us-east-1:123456789:events',
1384
+ * filterPolicy: { eventType: ['order.created'] },
1385
+ * }
1386
+ */
1387
+ subscribe?: QueueSnsSubscription
1388
+
1389
+ /**
1390
+ * Custom tags for the queue
1391
+ * Useful for cost allocation and organization
1392
+ */
1393
+ tags?: Record<string, string>
1394
+ }
1395
+
1396
+ /**
1397
+ * Queue configuration presets for common use cases
1398
+ * Use these to quickly configure queues with sensible defaults
1399
+ *
1400
+ * @example Basic usage
1401
+ * import { QueuePresets } from '@stacksjs/ts-cloud-types'
1402
+ *
1403
+ * queues: {
1404
+ * jobs: QueuePresets.backgroundJobs,
1405
+ * orders: QueuePresets.fifo,
1406
+ * events: QueuePresets.highThroughput,
1407
+ * }
1408
+ *
1409
+ * @example With Lambda trigger
1410
+ * queues: {
1411
+ * orders: {
1412
+ * ...QueuePresets.backgroundJobs,
1413
+ * trigger: { functionName: 'processOrders' },
1414
+ * },
1415
+ * }
1416
+ *
1417
+ * @example With monitoring
1418
+ * queues: {
1419
+ * critical: {
1420
+ * ...QueuePresets.monitored,
1421
+ * alarms: {
1422
+ * ...QueuePresets.monitored.alarms,
1423
+ * notificationEmails: ['ops@example.com'],
1424
+ * },
1425
+ * },
1426
+ * }
1427
+ */
1428
+ export const QueuePresets: {
1429
+ backgroundJobs: QueueItemConfig
1430
+ fifo: QueueItemConfig
1431
+ highThroughput: QueueItemConfig
1432
+ delayed: QueueItemConfig
1433
+ longRunning: QueueItemConfig
1434
+ monitored: QueueItemConfig
1435
+ lambdaOptimized: QueueItemConfig
1436
+ fanOut: QueueItemConfig
1437
+ } = {
1438
+ /**
1439
+ * Background job queue with dead letter support
1440
+ * Good for: async tasks, email sending, file processing
1441
+ */
1442
+ backgroundJobs: {
1443
+ visibilityTimeout: 120,
1444
+ messageRetentionPeriod: 604800, // 7 days
1445
+ deadLetterQueue: true,
1446
+ maxReceiveCount: 3,
1447
+ encrypted: true,
1448
+ },
1449
+
1450
+ /**
1451
+ * FIFO queue for ordered, exactly-once processing
1452
+ * Good for: financial transactions, order processing
1453
+ */
1454
+ fifo: {
1455
+ fifo: true,
1456
+ contentBasedDeduplication: true,
1457
+ visibilityTimeout: 30,
1458
+ encrypted: true,
1459
+ },
1460
+
1461
+ /**
1462
+ * High-throughput queue with long polling
1463
+ * Good for: event streaming, real-time processing
1464
+ */
1465
+ highThroughput: {
1466
+ visibilityTimeout: 30,
1467
+ receiveMessageWaitTime: 20,
1468
+ encrypted: true,
1469
+ },
1470
+
1471
+ /**
1472
+ * Delayed queue for scheduled messages
1473
+ * Good for: scheduled tasks, rate limiting
1474
+ */
1475
+ delayed: {
1476
+ delaySeconds: 60,
1477
+ visibilityTimeout: 60,
1478
+ encrypted: true,
1479
+ },
1480
+
1481
+ /**
1482
+ * Long-running task queue
1483
+ * Good for: video processing, ML inference, batch jobs
1484
+ */
1485
+ longRunning: {
1486
+ visibilityTimeout: 900, // 15 minutes
1487
+ messageRetentionPeriod: 1209600, // 14 days
1488
+ deadLetterQueue: true,
1489
+ maxReceiveCount: 2,
1490
+ encrypted: true,
1491
+ },
1492
+
1493
+ /**
1494
+ * Production queue with full monitoring
1495
+ * Good for: critical workloads requiring observability
1496
+ */
1497
+ monitored: {
1498
+ visibilityTimeout: 60,
1499
+ messageRetentionPeriod: 604800, // 7 days
1500
+ deadLetterQueue: true,
1501
+ maxReceiveCount: 3,
1502
+ encrypted: true,
1503
+ alarms: {
1504
+ enabled: true,
1505
+ queueDepthThreshold: 1000,
1506
+ messageAgeThreshold: 3600,
1507
+ dlqAlarm: true,
1508
+ },
1509
+ },
1510
+
1511
+ /**
1512
+ * Event-driven queue optimized for Lambda processing
1513
+ * Good for: serverless event processing, webhooks
1514
+ */
1515
+ lambdaOptimized: {
1516
+ visibilityTimeout: 360, // 6x default Lambda timeout
1517
+ receiveMessageWaitTime: 20,
1518
+ deadLetterQueue: true,
1519
+ maxReceiveCount: 3,
1520
+ encrypted: true,
1521
+ },
1522
+
1523
+ /**
1524
+ * Fan-out queue for SNS integration
1525
+ * Good for: pub/sub patterns, multi-consumer scenarios
1526
+ */
1527
+ fanOut: {
1528
+ visibilityTimeout: 30,
1529
+ receiveMessageWaitTime: 20,
1530
+ encrypted: true,
1531
+ },
1532
+ }
1533
+
1534
+ // ============================================================================
1535
+ // Realtime (WebSocket) Configuration
1536
+ // Laravel Echo / Pusher-compatible broadcasting for Stacks.js
1537
+ // Supports both serverless (API Gateway) and server (ts-broadcasting) modes
1538
+ // ============================================================================
1539
+
1540
+ /**
1541
+ * Realtime deployment mode
1542
+ * - 'serverless': Uses API Gateway WebSocket + Lambda (auto-scales, pay-per-use)
1543
+ * - 'server': Uses ts-broadcasting Bun WebSocket server on EC2/ECS (lowest latency)
1544
+ */
1545
+ export type RealtimeMode = 'serverless' | 'server'
1546
+
1547
+ /**
1548
+ * Server mode configuration (ts-broadcasting)
1549
+ * High-performance Bun WebSocket server for EC2/ECS deployments
1550
+ */
1551
+ export interface RealtimeServerConfig {
1552
+ /**
1553
+ * Server host binding
1554
+ * @default '0.0.0.0'
1555
+ */
1556
+ host?: string
1557
+
1558
+ /**
1559
+ * Server port
1560
+ * @default 6001
1561
+ */
1562
+ port?: number
1563
+
1564
+ /**
1565
+ * WebSocket scheme
1566
+ * @default 'wss' in production, 'ws' in development
1567
+ */
1568
+ scheme?: 'ws' | 'wss'
1569
+
1570
+ /**
1571
+ * Driver to use
1572
+ * @default 'bun'
1573
+ */
1574
+ driver?: 'bun' | 'reverb' | 'pusher' | 'ably'
1575
+
1576
+ /**
1577
+ * Idle connection timeout in seconds
1578
+ * @default 120
1579
+ */
1580
+ idleTimeout?: number
1581
+
1582
+ /**
1583
+ * Maximum message payload size in bytes
1584
+ * @default 16777216 (16 MB)
1585
+ */
1586
+ maxPayloadLength?: number
1587
+
1588
+ /**
1589
+ * Backpressure limit in bytes
1590
+ * @default 1048576 (1 MB)
1591
+ */
1592
+ backpressureLimit?: number
1593
+
1594
+ /**
1595
+ * Close connection when backpressure limit is reached
1596
+ * @default false
1597
+ */
1598
+ closeOnBackpressureLimit?: boolean
1599
+
1600
+ /**
1601
+ * Send WebSocket ping frames
1602
+ * @default true
1603
+ */
1604
+ sendPings?: boolean
1605
+
1606
+ /**
1607
+ * Enable per-message deflate compression
1608
+ * @default true
1609
+ */
1610
+ perMessageDeflate?: boolean
1611
+
1612
+ /**
1613
+ * Redis configuration for horizontal scaling
1614
+ * Enables multiple server instances to share state
1615
+ */
1616
+ redis?: RealtimeRedisConfig
1617
+
1618
+ /**
1619
+ * Rate limiting configuration
1620
+ */
1621
+ rateLimit?: RealtimeRateLimitConfig
1622
+
1623
+ /**
1624
+ * Message encryption configuration
1625
+ */
1626
+ encryption?: RealtimeEncryptionConfig
1627
+
1628
+ /**
1629
+ * Webhook notifications configuration
1630
+ */
1631
+ webhooks?: RealtimeWebhooksConfig
1632
+
1633
+ /**
1634
+ * Queue configuration for background jobs
1635
+ */
1636
+ queue?: RealtimeQueueConfig
1637
+
1638
+ /**
1639
+ * Load management configuration
1640
+ */
1641
+ loadManagement?: RealtimeLoadConfig
1642
+
1643
+ /**
1644
+ * Prometheus metrics endpoint
1645
+ * @default false
1646
+ */
1647
+ metrics?: boolean | {
1648
+ enabled: boolean
1649
+ path?: string
1650
+ }
1651
+
1652
+ /**
1653
+ * Health check endpoint path
1654
+ * @default '/health'
1655
+ */
1656
+ healthCheckPath?: string
1657
+
1658
+ /**
1659
+ * Number of server instances to run
1660
+ * Used when deploying to EC2/ECS
1661
+ * @default 1
1662
+ */
1663
+ instances?: number
1664
+
1665
+ /**
1666
+ * Auto-scaling configuration for EC2/ECS
1667
+ */
1668
+ autoScaling?: {
1669
+ min?: number
1670
+ max?: number
1671
+ targetCPU?: number
1672
+ targetConnections?: number
1673
+ }
1674
+ }
1675
+
1676
+ /**
1677
+ * Redis configuration for ts-broadcasting horizontal scaling
1678
+ */
1679
+ export interface RealtimeRedisConfig {
1680
+ /**
1681
+ * Enable Redis adapter
1682
+ * @default false
1683
+ */
1684
+ enabled?: boolean
1685
+
1686
+ /**
1687
+ * Redis host
1688
+ * @default 'localhost'
1689
+ */
1690
+ host?: string
1691
+
1692
+ /**
1693
+ * Redis port
1694
+ * @default 6379
1695
+ */
1696
+ port?: number
1697
+
1698
+ /**
1699
+ * Redis password
1700
+ */
1701
+ password?: string
1702
+
1703
+ /**
1704
+ * Redis database number
1705
+ * @default 0
1706
+ */
1707
+ database?: number
1708
+
1709
+ /**
1710
+ * Redis connection URL (overrides host/port)
1711
+ * @example 'redis://user:pass@localhost:6379/0'
1712
+ */
1713
+ url?: string
1714
+
1715
+ /**
1716
+ * Key prefix for Redis keys
1717
+ * @default 'broadcasting:'
1718
+ */
1719
+ keyPrefix?: string
1720
+
1721
+ /**
1722
+ * Use existing ElastiCache from cache config
1723
+ * References infrastructure.cache
1724
+ */
1725
+ useElastiCache?: boolean
1726
+ }
1727
+
1728
+ /**
1729
+ * Rate limiting for WebSocket connections
1730
+ */
1731
+ export interface RealtimeRateLimitConfig {
1732
+ /**
1733
+ * Enable rate limiting
1734
+ * @default true
1735
+ */
1736
+ enabled?: boolean
1737
+
1738
+ /**
1739
+ * Maximum messages per window
1740
+ * @default 100
1741
+ */
1742
+ max?: number
1743
+
1744
+ /**
1745
+ * Time window in milliseconds
1746
+ * @default 60000 (1 minute)
1747
+ */
1748
+ window?: number
1749
+
1750
+ /**
1751
+ * Apply rate limit per channel
1752
+ * @default true
1753
+ */
1754
+ perChannel?: boolean
1755
+
1756
+ /**
1757
+ * Apply rate limit per user
1758
+ * @default true
1759
+ */
1760
+ perUser?: boolean
1761
+ }
1762
+
1763
+ /**
1764
+ * Message encryption configuration
1765
+ */
1766
+ export interface RealtimeEncryptionConfig {
1767
+ /**
1768
+ * Enable message encryption
1769
+ * @default false
1770
+ */
1771
+ enabled?: boolean
1772
+
1773
+ /**
1774
+ * Encryption algorithm
1775
+ * @default 'aes-256-gcm'
1776
+ */
1777
+ algorithm?: 'aes-256-gcm' | 'aes-128-gcm'
1778
+
1779
+ /**
1780
+ * Key rotation interval in milliseconds
1781
+ * @default 86400000 (24 hours)
1782
+ */
1783
+ keyRotationInterval?: number
1784
+ }
1785
+
1786
+ /**
1787
+ * Webhook notifications for realtime events
1788
+ */
1789
+ export interface RealtimeWebhooksConfig {
1790
+ /**
1791
+ * Enable webhooks
1792
+ * @default false
1793
+ */
1794
+ enabled?: boolean
1795
+
1796
+ /**
1797
+ * Webhook endpoints for different events
1798
+ */
1799
+ endpoints?: {
1800
+ /**
1801
+ * Called when a client connects
1802
+ */
1803
+ connection?: string
1804
+
1805
+ /**
1806
+ * Called when a client subscribes to a channel
1807
+ */
1808
+ subscribe?: string
1809
+
1810
+ /**
1811
+ * Called when a client unsubscribes
1812
+ */
1813
+ unsubscribe?: string
1814
+
1815
+ /**
1816
+ * Called when a client disconnects
1817
+ */
1818
+ disconnect?: string
1819
+
1820
+ /**
1821
+ * Custom event webhooks
1822
+ */
1823
+ [event: string]: string | undefined
1824
+ }
1825
+ }
1826
+
1827
+ /**
1828
+ * Queue configuration for background broadcasting
1829
+ */
1830
+ export interface RealtimeQueueConfig {
1831
+ /**
1832
+ * Enable queue for broadcast operations
1833
+ * @default false
1834
+ */
1835
+ enabled?: boolean
1836
+
1837
+ /**
1838
+ * Default queue name
1839
+ * @default 'broadcasts'
1840
+ */
1841
+ defaultQueue?: string
1842
+
1843
+ /**
1844
+ * Retry configuration
1845
+ */
1846
+ retry?: {
1847
+ attempts?: number
1848
+ backoff?: {
1849
+ type: 'fixed' | 'exponential'
1850
+ delay: number
1851
+ }
1852
+ }
1853
+
1854
+ /**
1855
+ * Dead letter queue for failed broadcasts
1856
+ */
1857
+ deadLetter?: {
1858
+ enabled?: boolean
1859
+ maxRetries?: number
1860
+ }
1861
+ }
1862
+
1863
+ /**
1864
+ * Load management for server mode
1865
+ */
1866
+ export interface RealtimeLoadConfig {
1867
+ /**
1868
+ * Enable load management
1869
+ * @default true
1870
+ */
1871
+ enabled?: boolean
1872
+
1873
+ /**
1874
+ * Maximum concurrent connections
1875
+ * @default 10000
1876
+ */
1877
+ maxConnections?: number
1878
+
1879
+ /**
1880
+ * Maximum subscriptions per connection
1881
+ * @default 100
1882
+ */
1883
+ maxSubscriptionsPerConnection?: number
1884
+
1885
+ /**
1886
+ * CPU threshold to start shedding load (0-1)
1887
+ * @default 0.8
1888
+ */
1889
+ shedLoadThreshold?: number
1890
+ }
1891
+
1892
+ /**
1893
+ * Channel authorization configuration
1894
+ */
1895
+ export interface RealtimeChannelAuth {
1896
+ /**
1897
+ * Lambda function name for channel authorization
1898
+ * Called when clients join private/presence channels
1899
+ * @example 'authorizeChannel'
1900
+ */
1901
+ functionName?: string
1902
+
1903
+ /**
1904
+ * Authorization endpoint URL (if using external auth)
1905
+ * @example 'https://api.example.com/broadcasting/auth'
1906
+ */
1907
+ endpoint?: string
1908
+
1909
+ /**
1910
+ * JWT secret for token validation
1911
+ * Can reference Secrets Manager: '{{resolve:secretsmanager:my-secret}}'
1912
+ */
1913
+ jwtSecret?: string
1914
+
1915
+ /**
1916
+ * Token expiration time in seconds
1917
+ * @default 3600
1918
+ */
1919
+ tokenExpiration?: number
1920
+ }
1921
+
1922
+ /**
1923
+ * Presence channel configuration
1924
+ */
1925
+ export interface RealtimePresenceConfig {
1926
+ /**
1927
+ * Enable presence channels (who's online)
1928
+ * @default true
1929
+ */
1930
+ enabled?: boolean
1931
+
1932
+ /**
1933
+ * Maximum members per presence channel
1934
+ * @default 100
1935
+ */
1936
+ maxMembers?: number
1937
+
1938
+ /**
1939
+ * How often to send presence heartbeats (seconds)
1940
+ * @default 30
1941
+ */
1942
+ heartbeatInterval?: number
1943
+
1944
+ /**
1945
+ * Time before considering a member offline (seconds)
1946
+ * @default 60
1947
+ */
1948
+ inactivityTimeout?: number
1949
+ }
1950
+
1951
+ /**
1952
+ * Connection storage configuration
1953
+ */
1954
+ export interface RealtimeStorageConfig {
1955
+ /**
1956
+ * Storage type for connection management
1957
+ * - 'dynamodb': DynamoDB tables (recommended, auto-scales)
1958
+ * - 'elasticache': Redis cluster (lowest latency)
1959
+ * @default 'dynamodb'
1960
+ */
1961
+ type?: 'dynamodb' | 'elasticache'
1962
+
1963
+ /**
1964
+ * DynamoDB table configuration
1965
+ */
1966
+ dynamodb?: {
1967
+ /**
1968
+ * Billing mode for DynamoDB
1969
+ * @default 'PAY_PER_REQUEST'
1970
+ */
1971
+ billingMode?: 'PAY_PER_REQUEST' | 'PROVISIONED'
1972
+
1973
+ /**
1974
+ * Read capacity units (only for PROVISIONED)
1975
+ * @default 5
1976
+ */
1977
+ readCapacity?: number
1978
+
1979
+ /**
1980
+ * Write capacity units (only for PROVISIONED)
1981
+ * @default 5
1982
+ */
1983
+ writeCapacity?: number
1984
+
1985
+ /**
1986
+ * Enable point-in-time recovery
1987
+ * @default false
1988
+ */
1989
+ pointInTimeRecovery?: boolean
1990
+
1991
+ /**
1992
+ * TTL for connection records (seconds)
1993
+ * @default 86400 (24 hours)
1994
+ */
1995
+ connectionTTL?: number
1996
+ }
1997
+
1998
+ /**
1999
+ * ElastiCache configuration (if using Redis)
2000
+ */
2001
+ elasticache?: {
2002
+ /**
2003
+ * Node type for Redis cluster
2004
+ * @default 'cache.t3.micro'
2005
+ */
2006
+ nodeType?: string
2007
+
2008
+ /**
2009
+ * Number of cache nodes
2010
+ * @default 1
2011
+ */
2012
+ numNodes?: number
2013
+ }
2014
+ }
2015
+
2016
+ /**
2017
+ * WebSocket scaling configuration
2018
+ */
2019
+ export interface RealtimeScalingConfig {
2020
+ /**
2021
+ * Maximum concurrent connections
2022
+ * @default 10000
2023
+ */
2024
+ maxConnections?: number
2025
+
2026
+ /**
2027
+ * Message throughput limit per second
2028
+ * @default 1000
2029
+ */
2030
+ messagesPerSecond?: number
2031
+
2032
+ /**
2033
+ * Lambda memory for WebSocket handlers (MB)
2034
+ * @default 256
2035
+ */
2036
+ handlerMemory?: number
2037
+
2038
+ /**
2039
+ * Lambda timeout for WebSocket handlers (seconds)
2040
+ * @default 30
2041
+ */
2042
+ handlerTimeout?: number
2043
+
2044
+ /**
2045
+ * Enable Lambda provisioned concurrency for low latency
2046
+ */
2047
+ provisionedConcurrency?: number
2048
+ }
2049
+
2050
+ /**
2051
+ * Realtime monitoring and alarms
2052
+ */
2053
+ export interface RealtimeMonitoringConfig {
2054
+ /**
2055
+ * Enable CloudWatch alarms
2056
+ * @default false
2057
+ */
2058
+ enabled?: boolean
2059
+
2060
+ /**
2061
+ * Alert when concurrent connections exceed threshold
2062
+ * @default 8000
2063
+ */
2064
+ connectionThreshold?: number
2065
+
2066
+ /**
2067
+ * Alert when message errors exceed threshold per minute
2068
+ * @default 100
2069
+ */
2070
+ errorThreshold?: number
2071
+
2072
+ /**
2073
+ * Alert when latency exceeds threshold (ms)
2074
+ * @default 1000
2075
+ */
2076
+ latencyThreshold?: number
2077
+
2078
+ /**
2079
+ * SNS topic ARN for alarm notifications
2080
+ */
2081
+ notificationTopicArn?: string
2082
+
2083
+ /**
2084
+ * Email addresses for alarm notifications
2085
+ */
2086
+ notificationEmails?: string[]
2087
+ }
2088
+
2089
+ /**
2090
+ * Realtime event hooks
2091
+ */
2092
+ export interface RealtimeHooksConfig {
2093
+ /**
2094
+ * Lambda function called on new connections
2095
+ * Receives: { connectionId, requestContext }
2096
+ */
2097
+ onConnect?: string
2098
+
2099
+ /**
2100
+ * Lambda function called on disconnections
2101
+ * Receives: { connectionId, requestContext }
2102
+ */
2103
+ onDisconnect?: string
2104
+
2105
+ /**
2106
+ * Lambda function called for incoming messages
2107
+ * Receives: { connectionId, body, requestContext }
2108
+ */
2109
+ onMessage?: string
2110
+
2111
+ /**
2112
+ * Lambda function called when clients subscribe to channels
2113
+ * Receives: { connectionId, channel, auth }
2114
+ */
2115
+ onSubscribe?: string
2116
+
2117
+ /**
2118
+ * Lambda function called when clients unsubscribe
2119
+ * Receives: { connectionId, channel }
2120
+ */
2121
+ onUnsubscribe?: string
2122
+ }
2123
+
2124
+ /**
2125
+ * Realtime (WebSocket) Configuration
2126
+ * Provides Laravel Echo / Pusher-compatible broadcasting
2127
+ *
2128
+ * @example Serverless mode (API Gateway WebSocket)
2129
+ * realtime: {
2130
+ * enabled: true,
2131
+ * mode: 'serverless',
2132
+ * channels: { public: true, private: true, presence: true },
2133
+ * }
2134
+ *
2135
+ * @example Server mode (ts-broadcasting on EC2/ECS)
2136
+ * realtime: {
2137
+ * enabled: true,
2138
+ * mode: 'server',
2139
+ * server: {
2140
+ * port: 6001,
2141
+ * redis: { enabled: true, host: 'redis.example.com' },
2142
+ * rateLimit: { max: 100, window: 60000 },
2143
+ * },
2144
+ * }
2145
+ *
2146
+ * @example Production server mode with clustering
2147
+ * realtime: {
2148
+ * enabled: true,
2149
+ * mode: 'server',
2150
+ * server: {
2151
+ * port: 6001,
2152
+ * instances: 3,
2153
+ * redis: { enabled: true, useElastiCache: true },
2154
+ * autoScaling: { min: 2, max: 10, targetCPU: 70 },
2155
+ * metrics: true,
2156
+ * },
2157
+ * channels: { public: true, private: true, presence: true },
2158
+ * }
2159
+ *
2160
+ * @example Integration with Stacks.js
2161
+ * // In your Stacks app:
2162
+ * import { Broadcast } from '@stacksjs/broadcast'
2163
+ *
2164
+ * // Broadcast to a channel
2165
+ * Broadcast.channel('orders').emit('order.created', { id: 123 })
2166
+ *
2167
+ * // Client-side (similar to Laravel Echo)
2168
+ * Echo.channel('orders').listen('order.created', (e) => {
2169
+ * console.log('New order:', e.id)
2170
+ * })
2171
+ *
2172
+ * // Private channel
2173
+ * Echo.private(`user.${userId}`).listen('notification', (e) => {
2174
+ * console.log('Private notification:', e)
2175
+ * })
2176
+ *
2177
+ * // Presence channel
2178
+ * Echo.join('chat-room')
2179
+ * .here((users) => console.log('Online:', users))
2180
+ * .joining((user) => console.log('Joined:', user))
2181
+ * .leaving((user) => console.log('Left:', user))
2182
+ */
2183
+ export interface RealtimeConfig {
2184
+ /**
2185
+ * Enable realtime/WebSocket support
2186
+ * @default false
2187
+ */
2188
+ enabled?: boolean
2189
+
2190
+ /**
2191
+ * Deployment mode
2192
+ * - 'serverless': API Gateway WebSocket + Lambda (auto-scales, pay-per-use)
2193
+ * - 'server': ts-broadcasting Bun WebSocket on EC2/ECS (lowest latency)
2194
+ * @default 'serverless'
2195
+ */
2196
+ mode?: RealtimeMode
2197
+
2198
+ /**
2199
+ * Custom WebSocket API/server name
2200
+ */
2201
+ name?: string
2202
+
2203
+ /**
2204
+ * Server mode configuration (ts-broadcasting)
2205
+ * Only used when mode is 'server'
2206
+ */
2207
+ server?: RealtimeServerConfig
2208
+
2209
+ /**
2210
+ * Channel configuration
2211
+ */
2212
+ channels?: {
2213
+ /**
2214
+ * Enable public channels (no auth required)
2215
+ * @default true
2216
+ */
2217
+ public?: boolean
2218
+
2219
+ /**
2220
+ * Enable private channels (requires auth)
2221
+ * @default true
2222
+ */
2223
+ private?: boolean
2224
+
2225
+ /**
2226
+ * Enable presence channels (track online users)
2227
+ * @default false
2228
+ */
2229
+ presence?: boolean | RealtimePresenceConfig
2230
+ }
2231
+
2232
+ /**
2233
+ * Channel authorization configuration
2234
+ */
2235
+ auth?: RealtimeChannelAuth
2236
+
2237
+ /**
2238
+ * Connection storage configuration
2239
+ */
2240
+ storage?: RealtimeStorageConfig
2241
+
2242
+ /**
2243
+ * Scaling configuration
2244
+ */
2245
+ scaling?: RealtimeScalingConfig
2246
+
2247
+ /**
2248
+ * Monitoring and alarms
2249
+ */
2250
+ monitoring?: RealtimeMonitoringConfig
2251
+
2252
+ /**
2253
+ * Event hooks (Lambda functions)
2254
+ */
2255
+ hooks?: RealtimeHooksConfig
2256
+
2257
+ /**
2258
+ * Custom domain for WebSocket endpoint
2259
+ * @example 'ws.example.com'
2260
+ */
2261
+ customDomain?: string
2262
+
2263
+ /**
2264
+ * ACM certificate ARN for custom domain
2265
+ */
2266
+ certificateArn?: string
2267
+
2268
+ /**
2269
+ * Enable connection keep-alive pings
2270
+ * @default true
2271
+ */
2272
+ keepAlive?: boolean
2273
+
2274
+ /**
2275
+ * Keep-alive interval in seconds
2276
+ * @default 30
2277
+ */
2278
+ keepAliveInterval?: number
2279
+
2280
+ /**
2281
+ * Idle connection timeout in seconds
2282
+ * @default 600 (10 minutes)
2283
+ */
2284
+ idleTimeout?: number
2285
+
2286
+ /**
2287
+ * Maximum message size in bytes
2288
+ * @default 32768 (32 KB)
2289
+ */
2290
+ maxMessageSize?: number
2291
+
2292
+ /**
2293
+ * Enable message compression
2294
+ * @default false
2295
+ */
2296
+ compression?: boolean
2297
+
2298
+ /**
2299
+ * Custom tags for all realtime resources
2300
+ */
2301
+ tags?: Record<string, string>
2302
+ }
2303
+
2304
+ /**
2305
+ * Realtime configuration presets
2306
+ *
2307
+ * @example Serverless presets
2308
+ * import { RealtimePresets } from '@stacksjs/ts-cloud-types'
2309
+ * realtime: RealtimePresets.serverless.production
2310
+ *
2311
+ * @example Server presets (ts-broadcasting)
2312
+ * realtime: RealtimePresets.server.production
2313
+ */
2314
+ export const RealtimePresets: {
2315
+ serverless: {
2316
+ development: RealtimeConfig
2317
+ production: RealtimeConfig
2318
+ notifications: RealtimeConfig
2319
+ }
2320
+ server: {
2321
+ development: RealtimeConfig
2322
+ production: RealtimeConfig
2323
+ highPerformance: RealtimeConfig
2324
+ chat: RealtimeConfig
2325
+ gaming: RealtimeConfig
2326
+ single: RealtimeConfig
2327
+ }
2328
+ } = {
2329
+ // ============================================
2330
+ // SERVERLESS MODE PRESETS (API Gateway WebSocket)
2331
+ // ============================================
2332
+ serverless: {
2333
+ /**
2334
+ * Development preset - minimal resources
2335
+ */
2336
+ development: {
2337
+ enabled: true,
2338
+ mode: 'serverless',
2339
+ channels: {
2340
+ public: true,
2341
+ private: true,
2342
+ presence: true,
2343
+ },
2344
+ storage: {
2345
+ type: 'dynamodb',
2346
+ dynamodb: { billingMode: 'PAY_PER_REQUEST' },
2347
+ },
2348
+ scaling: {
2349
+ maxConnections: 1000,
2350
+ handlerMemory: 128,
2351
+ },
2352
+ },
2353
+
2354
+ /**
2355
+ * Production preset - scalable with monitoring
2356
+ */
2357
+ production: {
2358
+ enabled: true,
2359
+ mode: 'serverless',
2360
+ channels: {
2361
+ public: true,
2362
+ private: true,
2363
+ presence: {
2364
+ enabled: true,
2365
+ maxMembers: 100,
2366
+ heartbeatInterval: 30,
2367
+ inactivityTimeout: 60,
2368
+ },
2369
+ },
2370
+ storage: {
2371
+ type: 'dynamodb',
2372
+ dynamodb: {
2373
+ billingMode: 'PAY_PER_REQUEST',
2374
+ pointInTimeRecovery: true,
2375
+ connectionTTL: 86400,
2376
+ },
2377
+ },
2378
+ scaling: {
2379
+ maxConnections: 50000,
2380
+ messagesPerSecond: 5000,
2381
+ handlerMemory: 256,
2382
+ handlerTimeout: 30,
2383
+ },
2384
+ monitoring: {
2385
+ enabled: true,
2386
+ connectionThreshold: 40000,
2387
+ errorThreshold: 100,
2388
+ latencyThreshold: 500,
2389
+ },
2390
+ keepAlive: true,
2391
+ keepAliveInterval: 30,
2392
+ idleTimeout: 600,
2393
+ },
2394
+
2395
+ /**
2396
+ * Notifications only preset - no presence
2397
+ */
2398
+ notifications: {
2399
+ enabled: true,
2400
+ mode: 'serverless',
2401
+ channels: {
2402
+ public: false,
2403
+ private: true,
2404
+ presence: false,
2405
+ },
2406
+ storage: {
2407
+ type: 'dynamodb',
2408
+ dynamodb: { billingMode: 'PAY_PER_REQUEST' },
2409
+ },
2410
+ scaling: {
2411
+ maxConnections: 50000,
2412
+ messagesPerSecond: 2000,
2413
+ handlerMemory: 128,
2414
+ },
2415
+ keepAlive: true,
2416
+ keepAliveInterval: 60,
2417
+ idleTimeout: 1800,
2418
+ },
2419
+ },
2420
+
2421
+ // ============================================
2422
+ // SERVER MODE PRESETS (ts-broadcasting / Bun)
2423
+ // ============================================
2424
+ server: {
2425
+ /**
2426
+ * Development preset - single server, no clustering
2427
+ */
2428
+ development: {
2429
+ enabled: true,
2430
+ mode: 'server',
2431
+ channels: {
2432
+ public: true,
2433
+ private: true,
2434
+ presence: true,
2435
+ },
2436
+ server: {
2437
+ host: '0.0.0.0',
2438
+ port: 6001,
2439
+ scheme: 'ws',
2440
+ driver: 'bun',
2441
+ idleTimeout: 120,
2442
+ perMessageDeflate: false, // Faster in dev
2443
+ metrics: false,
2444
+ },
2445
+ },
2446
+
2447
+ /**
2448
+ * Production preset - clustered with Redis
2449
+ */
2450
+ production: {
2451
+ enabled: true,
2452
+ mode: 'server',
2453
+ channels: {
2454
+ public: true,
2455
+ private: true,
2456
+ presence: true,
2457
+ },
2458
+ server: {
2459
+ host: '0.0.0.0',
2460
+ port: 6001,
2461
+ scheme: 'wss',
2462
+ driver: 'bun',
2463
+ idleTimeout: 120,
2464
+ maxPayloadLength: 16 * 1024 * 1024, // 16 MB
2465
+ backpressureLimit: 1024 * 1024, // 1 MB
2466
+ sendPings: true,
2467
+ perMessageDeflate: true,
2468
+ instances: 2,
2469
+ redis: {
2470
+ enabled: true,
2471
+ keyPrefix: 'broadcasting:',
2472
+ },
2473
+ rateLimit: {
2474
+ enabled: true,
2475
+ max: 100,
2476
+ window: 60000,
2477
+ perChannel: true,
2478
+ perUser: true,
2479
+ },
2480
+ loadManagement: {
2481
+ enabled: true,
2482
+ maxConnections: 10000,
2483
+ maxSubscriptionsPerConnection: 100,
2484
+ shedLoadThreshold: 0.8,
2485
+ },
2486
+ metrics: true,
2487
+ autoScaling: {
2488
+ min: 2,
2489
+ max: 10,
2490
+ targetCPU: 70,
2491
+ },
2492
+ },
2493
+ monitoring: {
2494
+ enabled: true,
2495
+ connectionThreshold: 8000,
2496
+ errorThreshold: 100,
2497
+ },
2498
+ },
2499
+
2500
+ /**
2501
+ * High-performance preset - optimized for lowest latency
2502
+ */
2503
+ highPerformance: {
2504
+ enabled: true,
2505
+ mode: 'server',
2506
+ channels: {
2507
+ public: true,
2508
+ private: true,
2509
+ presence: true,
2510
+ },
2511
+ server: {
2512
+ host: '0.0.0.0',
2513
+ port: 6001,
2514
+ scheme: 'wss',
2515
+ driver: 'bun',
2516
+ idleTimeout: 60,
2517
+ maxPayloadLength: 8 * 1024 * 1024, // 8 MB
2518
+ backpressureLimit: 2 * 1024 * 1024, // 2 MB
2519
+ closeOnBackpressureLimit: true,
2520
+ sendPings: true,
2521
+ perMessageDeflate: true,
2522
+ instances: 4,
2523
+ redis: {
2524
+ enabled: true,
2525
+ useElastiCache: true,
2526
+ keyPrefix: 'rt:',
2527
+ },
2528
+ rateLimit: {
2529
+ enabled: true,
2530
+ max: 200,
2531
+ window: 60000,
2532
+ perChannel: true,
2533
+ },
2534
+ loadManagement: {
2535
+ enabled: true,
2536
+ maxConnections: 25000,
2537
+ maxSubscriptionsPerConnection: 50,
2538
+ shedLoadThreshold: 0.7,
2539
+ },
2540
+ metrics: { enabled: true, path: '/metrics' },
2541
+ autoScaling: {
2542
+ min: 4,
2543
+ max: 20,
2544
+ targetCPU: 60,
2545
+ targetConnections: 20000,
2546
+ },
2547
+ },
2548
+ monitoring: {
2549
+ enabled: true,
2550
+ connectionThreshold: 80000,
2551
+ errorThreshold: 50,
2552
+ latencyThreshold: 50,
2553
+ },
2554
+ },
2555
+
2556
+ /**
2557
+ * Chat application preset - optimized for presence and typing indicators
2558
+ */
2559
+ chat: {
2560
+ enabled: true,
2561
+ mode: 'server',
2562
+ channels: {
2563
+ public: true,
2564
+ private: true,
2565
+ presence: {
2566
+ enabled: true,
2567
+ maxMembers: 200,
2568
+ heartbeatInterval: 20,
2569
+ inactivityTimeout: 60,
2570
+ },
2571
+ },
2572
+ server: {
2573
+ host: '0.0.0.0',
2574
+ port: 6001,
2575
+ scheme: 'wss',
2576
+ driver: 'bun',
2577
+ idleTimeout: 300, // 5 minutes for chat
2578
+ maxPayloadLength: 1024 * 1024, // 1 MB (smaller for chat)
2579
+ sendPings: true,
2580
+ perMessageDeflate: true,
2581
+ instances: 2,
2582
+ redis: {
2583
+ enabled: true,
2584
+ keyPrefix: 'chat:',
2585
+ },
2586
+ rateLimit: {
2587
+ enabled: true,
2588
+ max: 60, // 1 message per second
2589
+ window: 60000,
2590
+ perChannel: true,
2591
+ },
2592
+ loadManagement: {
2593
+ enabled: true,
2594
+ maxConnections: 15000,
2595
+ maxSubscriptionsPerConnection: 20,
2596
+ },
2597
+ metrics: true,
2598
+ },
2599
+ keepAlive: true,
2600
+ keepAliveInterval: 25,
2601
+ idleTimeout: 900,
2602
+ },
2603
+
2604
+ /**
2605
+ * Gaming/real-time app preset - ultra-low latency
2606
+ */
2607
+ gaming: {
2608
+ enabled: true,
2609
+ mode: 'server',
2610
+ channels: {
2611
+ public: true,
2612
+ private: true,
2613
+ presence: {
2614
+ enabled: true,
2615
+ maxMembers: 100,
2616
+ heartbeatInterval: 10,
2617
+ inactivityTimeout: 30,
2618
+ },
2619
+ },
2620
+ server: {
2621
+ host: '0.0.0.0',
2622
+ port: 6001,
2623
+ scheme: 'wss',
2624
+ driver: 'bun',
2625
+ idleTimeout: 30,
2626
+ maxPayloadLength: 64 * 1024, // 64 KB (small, fast messages)
2627
+ backpressureLimit: 512 * 1024, // 512 KB
2628
+ closeOnBackpressureLimit: true,
2629
+ sendPings: true,
2630
+ perMessageDeflate: false, // Disable for lowest latency
2631
+ instances: 4,
2632
+ redis: {
2633
+ enabled: true,
2634
+ useElastiCache: true,
2635
+ },
2636
+ rateLimit: {
2637
+ enabled: true,
2638
+ max: 120, // 2 messages per second
2639
+ window: 60000,
2640
+ },
2641
+ loadManagement: {
2642
+ enabled: true,
2643
+ maxConnections: 5000,
2644
+ maxSubscriptionsPerConnection: 10,
2645
+ shedLoadThreshold: 0.6,
2646
+ },
2647
+ metrics: true,
2648
+ autoScaling: {
2649
+ min: 4,
2650
+ max: 16,
2651
+ targetCPU: 50,
2652
+ },
2653
+ },
2654
+ keepAlive: true,
2655
+ keepAliveInterval: 10,
2656
+ idleTimeout: 60,
2657
+ },
2658
+
2659
+ /**
2660
+ * Single server preset - no clustering, simple setup
2661
+ */
2662
+ single: {
2663
+ enabled: true,
2664
+ mode: 'server',
2665
+ channels: {
2666
+ public: true,
2667
+ private: true,
2668
+ presence: true,
2669
+ },
2670
+ server: {
2671
+ host: '0.0.0.0',
2672
+ port: 6001,
2673
+ scheme: 'wss',
2674
+ driver: 'bun',
2675
+ idleTimeout: 120,
2676
+ sendPings: true,
2677
+ perMessageDeflate: true,
2678
+ instances: 1,
2679
+ rateLimit: {
2680
+ enabled: true,
2681
+ max: 100,
2682
+ window: 60000,
2683
+ },
2684
+ loadManagement: {
2685
+ enabled: true,
2686
+ maxConnections: 10000,
2687
+ },
2688
+ metrics: true,
2689
+ },
2690
+ },
2691
+ },
2692
+ }
2693
+
2694
+ export interface ApiConfig {
2695
+ enabled?: boolean
2696
+ name?: string
2697
+ }
2698
+
2699
+ /**
2700
+ * Load Balancer Configuration
2701
+ * Controls whether and how traffic is load balanced
2702
+ */
2703
+ export interface LoadBalancerConfig {
2704
+ /**
2705
+ * Enable Application Load Balancer
2706
+ * When false, traffic goes directly to EC2 instances
2707
+ * @default true for production with SSL
2708
+ */
2709
+ enabled?: boolean
2710
+
2711
+ /**
2712
+ * Load balancer type
2713
+ * - 'application': HTTP/HTTPS traffic (ALB)
2714
+ * - 'network': TCP/UDP traffic (NLB)
2715
+ * @default 'application'
2716
+ */
2717
+ type?: 'application' | 'network'
2718
+
2719
+ /**
2720
+ * Health check configuration
2721
+ */
2722
+ healthCheck?: {
2723
+ path?: string
2724
+ interval?: number
2725
+ timeout?: number
2726
+ healthyThreshold?: number
2727
+ unhealthyThreshold?: number
2728
+ }
2729
+
2730
+ /**
2731
+ * Idle timeout in seconds
2732
+ * @default 60
2733
+ */
2734
+ idleTimeout?: number
2735
+
2736
+ /**
2737
+ * Enable access logs
2738
+ */
2739
+ accessLogs?: {
2740
+ enabled?: boolean
2741
+ bucket?: string
2742
+ prefix?: string
2743
+ }
2744
+ }
2745
+
2746
+ /**
2747
+ * SSL/TLS Configuration
2748
+ * Supports both AWS ACM certificates and Let's Encrypt
2749
+ */
2750
+ export interface SslConfig {
2751
+ /**
2752
+ * Enable HTTPS
2753
+ * @default true for production
2754
+ */
2755
+ enabled?: boolean
2756
+
2757
+ /**
2758
+ * SSL certificate provider
2759
+ * - 'acm': AWS Certificate Manager (requires ALB or CloudFront)
2760
+ * - 'letsencrypt': Free certificates from Let's Encrypt (works without ALB)
2761
+ * @default 'acm' if loadBalancer.enabled, otherwise 'letsencrypt'
2762
+ */
2763
+ provider?: 'acm' | 'letsencrypt'
2764
+
2765
+ /**
2766
+ * ACM certificate ARN (if using ACM)
2767
+ * If not provided, a certificate will be automatically requested
2768
+ */
2769
+ certificateArn?: string
2770
+
2771
+ /**
2772
+ * Domain names for the certificate
2773
+ * If not provided, uses the primary domain from dns config
2774
+ */
2775
+ domains?: string[]
2776
+
2777
+ /**
2778
+ * Redirect HTTP to HTTPS
2779
+ * @default true when SSL is enabled
2780
+ */
2781
+ redirectHttp?: boolean
2782
+
2783
+ /**
2784
+ * Let's Encrypt specific options
2785
+ */
2786
+ letsEncrypt?: {
2787
+ /**
2788
+ * Email for Let's Encrypt notifications
2789
+ */
2790
+ email?: string
2791
+
2792
+ /**
2793
+ * Use staging server for testing
2794
+ * @default false
2795
+ */
2796
+ staging?: boolean
2797
+
2798
+ /**
2799
+ * Auto-renew certificates
2800
+ * @default true
2801
+ */
2802
+ autoRenew?: boolean
2803
+ }
2804
+ }