@mettlecast/domain-cdk-packer 0.2.0

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 (66) hide show
  1. package/README.md +83 -0
  2. package/dist/DomainStack.d.ts +68 -0
  3. package/dist/DomainStack.js +567 -0
  4. package/dist/__tests__/domain-stack.test.d.ts +1 -0
  5. package/dist/__tests__/domain-stack.test.js +223 -0
  6. package/dist/__tests__/lambda-factory.test.d.ts +1 -0
  7. package/dist/__tests__/lambda-factory.test.js +76 -0
  8. package/dist/__tests__/pack-flows.test.d.ts +1 -0
  9. package/dist/__tests__/pack-flows.test.js +283 -0
  10. package/dist/__tests__/registry.test.d.ts +1 -0
  11. package/dist/__tests__/registry.test.js +34 -0
  12. package/dist/__tests__/step-functions-codegen.test.d.ts +1 -0
  13. package/dist/__tests__/step-functions-codegen.test.js +159 -0
  14. package/dist/aspects/iam-boundaries-aspect.d.ts +11 -0
  15. package/dist/aspects/iam-boundaries-aspect.js +15 -0
  16. package/dist/aspects/index.d.ts +5 -0
  17. package/dist/aspects/index.js +3 -0
  18. package/dist/aspects/log-retention-aspect.d.ts +8 -0
  19. package/dist/aspects/log-retention-aspect.js +24 -0
  20. package/dist/aspects/tagging-aspect.d.ts +13 -0
  21. package/dist/aspects/tagging-aspect.js +17 -0
  22. package/dist/constructs/action-construct.d.ts +35 -0
  23. package/dist/constructs/action-construct.js +35 -0
  24. package/dist/constructs/alarm-construct.d.ts +19 -0
  25. package/dist/constructs/alarm-construct.js +58 -0
  26. package/dist/constructs/alarms-construct.d.ts +17 -0
  27. package/dist/constructs/alarms-construct.js +42 -0
  28. package/dist/constructs/api-construct.d.ts +30 -0
  29. package/dist/constructs/api-construct.js +64 -0
  30. package/dist/constructs/canary-construct.d.ts +13 -0
  31. package/dist/constructs/canary-construct.js +30 -0
  32. package/dist/constructs/cmk-construct.d.ts +9 -0
  33. package/dist/constructs/cmk-construct.js +20 -0
  34. package/dist/constructs/dashboard-construct.d.ts +15 -0
  35. package/dist/constructs/dashboard-construct.js +62 -0
  36. package/dist/constructs/health-construct.d.ts +11 -0
  37. package/dist/constructs/health-construct.js +29 -0
  38. package/dist/constructs/job-construct.d.ts +33 -0
  39. package/dist/constructs/job-construct.js +54 -0
  40. package/dist/constructs/schedule-construct.d.ts +27 -0
  41. package/dist/constructs/schedule-construct.js +54 -0
  42. package/dist/constructs/subscriber-construct.d.ts +30 -0
  43. package/dist/constructs/subscriber-construct.js +63 -0
  44. package/dist/constructs/waf-construct.d.ts +13 -0
  45. package/dist/constructs/waf-construct.js +75 -0
  46. package/dist/constructs/webhook-construct.d.ts +33 -0
  47. package/dist/constructs/webhook-construct.js +50 -0
  48. package/dist/flow-registry.d.ts +81 -0
  49. package/dist/flow-registry.js +2 -0
  50. package/dist/grouped-lambda-factory.d.ts +43 -0
  51. package/dist/grouped-lambda-factory.js +71 -0
  52. package/dist/iam/iam-policy-builder.d.ts +95 -0
  53. package/dist/iam/iam-policy-builder.js +232 -0
  54. package/dist/index.d.ts +36 -0
  55. package/dist/index.js +17 -0
  56. package/dist/lambda-factory.d.ts +46 -0
  57. package/dist/lambda-factory.js +80 -0
  58. package/dist/pack-domain.d.ts +35 -0
  59. package/dist/pack-domain.js +32 -0
  60. package/dist/pack-flows.d.ts +28 -0
  61. package/dist/pack-flows.js +154 -0
  62. package/dist/registry.d.ts +224 -0
  63. package/dist/registry.js +1 -0
  64. package/dist/step-functions-codegen.d.ts +65 -0
  65. package/dist/step-functions-codegen.js +55 -0
  66. package/package.json +36 -0
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # @mettlecast/domain-cdk-packer
2
+
3
+ AWS CDK L3 constructs that compile a `DomainRegistry` snapshot into CloudFormation. Takes the output of `mc-domain-module build` and generates type-safe infrastructure.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @mettlecast/domain-cdk-packer --save-dev
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ Pack a domain registry into a CDK stack:
14
+
15
+ ```typescript
16
+ import { packDomain } from '@mettlecast/domain-cdk-packer';
17
+ import * as cdk from 'aws-cdk-lib';
18
+ import * as fs from 'fs';
19
+
20
+ const app = new cdk.App();
21
+ const registry = JSON.parse(
22
+ fs.readFileSync('.mc/domain-registry.json', 'utf-8')
23
+ );
24
+
25
+ packDomain(registry, app, {
26
+ env: { region: 'eu-north-1', account: '123456789' },
27
+ });
28
+
29
+ app.synth();
30
+ ```
31
+
32
+ Or use `DomainStack` directly:
33
+
34
+ ```typescript
35
+ import { DomainStack } from '@mettlecast/domain-cdk-packer';
36
+
37
+ new DomainStack(app, 'PaymentsStack', {
38
+ registry,
39
+ env: { region: 'eu-north-1', account: '123456789' },
40
+ });
41
+ ```
42
+
43
+ ## Constructs Generated
44
+
45
+ For each handler in the registry, the packer provisions:
46
+
47
+ | Handler Type | Generated Constructs |
48
+ |---|---|
49
+ | `defineApi()` | Lambda function, API Gateway route (method + path), EventBridge integration |
50
+ | `defineWebhook()` | Lambda function, API Gateway webhook route, GitHub webhook validation |
51
+ | `defineSubscriber()` | Lambda function, EventBridge rule (event filter), Lambda target |
52
+ | `defineSchedule()` | Lambda function, EventBridge Scheduler rule (cron expression) |
53
+ | `defineJob()` | Lambda function, SQS queue, Lambda event source mapping |
54
+ | `defineAction()` | Lambda function, Function URL (for workspace invocation) |
55
+ | `defineIntegration()` | Lambda function, SQS DLQ, error retry logic |
56
+
57
+ All handlers use **esbuild** for bundling and **Drizzle ORM** for database access.
58
+
59
+ ## Advanced Features
60
+
61
+ **StepFunctionsCodegen** — Convert domain actions into AWS Step Functions task states for TIB Flow Designer integration:
62
+
63
+ ```typescript
64
+ import { StepFunctionsCodegen } from '@mettlecast/domain-cdk-packer';
65
+
66
+ const sfnCodegen = new StepFunctionsCodegen(registry);
67
+ const taskStates = sfnCodegen.generate();
68
+ // taskStates: StepFunctionsTaskState[] — ready to be serialized to Flow Designer
69
+ ```
70
+
71
+ ## Peer Dependencies
72
+
73
+ `@mettlecast/domain-cdk-packer` requires:
74
+
75
+ - `aws-cdk-lib` (^2.0)
76
+ - `constructs` (^10.0)
77
+
78
+ And expects `@mettlecast/domain-runtime` to be installed in the same project (used for type reflection).
79
+
80
+ ## See Also
81
+
82
+ - `@mettlecast/domain-runtime` — handler definitions
83
+ - `@mettlecast/domain-cli` — local build and validation
@@ -0,0 +1,68 @@
1
+ import * as cdk from 'aws-cdk-lib';
2
+ import * as apigwv2 from 'aws-cdk-lib/aws-apigatewayv2';
3
+ import * as ec2 from 'aws-cdk-lib/aws-ec2';
4
+ import { Construct } from 'constructs';
5
+ import type { DomainRegistry } from './registry.js';
6
+ /**
7
+ * Configuration properties for DomainStack.
8
+ */
9
+ export interface DomainStackProps extends cdk.StackProps {
10
+ /** The compiled domain registry. */
11
+ registry: DomainRegistry;
12
+ /** ARN of the EventBridge event bus for event subscribers. */
13
+ eventBusArn: string;
14
+ /** Database connection URL passed from DataStorageStack. */
15
+ databaseUrl?: string;
16
+ /** ARN of the RDS secret for DB credentials — added to Lambda env as DB_SECRET_ARN. */
17
+ dbSecretArn?: string;
18
+ /** Cognito User Pool ARN — when provided, HTTP API routes are JWT-protected. */
19
+ userPoolArn?: string;
20
+ /** Cognito User Pool Client ID — required alongside userPoolArn for JWT authorizer. */
21
+ userPoolClientId?: string;
22
+ /** VPC to place domain Lambdas in — required for Aurora connectivity. */
23
+ vpc?: ec2.IVpc;
24
+ /** Security group for domain Lambdas — must allow egress to Aurora SG. */
25
+ lambdaSg?: ec2.ISecurityGroup;
26
+ /** Enable CMK encryption for DynamoDB, S3, SQS. */
27
+ enableCmk?: boolean;
28
+ /** Enable WAF WebACL on the domain API Gateway. */
29
+ enableWaf?: boolean;
30
+ /** Enable CloudWatch alarms and DLQ depth alarms. */
31
+ enableAlarms?: boolean;
32
+ /** SNS topic ARN for alarm notifications. Used when enableAlarms is true. */
33
+ alarmSnsTopicArn?: string;
34
+ /** Enable canary deployments with CodeDeploy and auto-rollback on alarm breach. */
35
+ enableCanaryDeploy?: boolean;
36
+ /** Reserved concurrency for all Lambdas in this domain. If omitted, no limit. */
37
+ reservedConcurrency?: number;
38
+ /** Log retention in days. Default: 30. */
39
+ logRetentionDays?: 30 | 90 | 365 | 2557;
40
+ /**
41
+ * Explicit CORS allowed origins for the HTTP API and Function URLs.
42
+ * When omitted, defaults to ['*'] (open — only appropriate during early dev).
43
+ * Set to the list of dashboard URLs + localhost for production workloads.
44
+ */
45
+ corsAllowedOrigins?: string[];
46
+ /**
47
+ * Allow CORS with credentials (Access-Control-Allow-Credentials: true).
48
+ * Requires corsAllowedOrigins to be a non-wildcard list.
49
+ */
50
+ allowCredentials?: boolean;
51
+ }
52
+ /**
53
+ * Top-level CDK Stack that composes all domain constructs from a single DomainRegistry input.
54
+ * Uses grouped Lambdas for each primitive type to reduce deployment artifact size.
55
+ */
56
+ export declare class DomainStack extends cdk.Stack {
57
+ /** Shared HTTP API for routing API and webhook requests. */
58
+ readonly httpApi: apigwv2.HttpApi;
59
+ /** Map of primitive-type key to Lambda function ARN, used by FlowsStack for direct invocation. */
60
+ readonly lambdaArns: Record<string, string>;
61
+ /**
62
+ * Create a new DomainStack instance.
63
+ * @param scope - Parent CDK scope.
64
+ * @param id - Stack identifier.
65
+ * @param props - Stack properties including domain registry and event bus ARN.
66
+ */
67
+ constructor(scope: Construct, id: string, props: DomainStackProps);
68
+ }