@teaminabottle/domain-cdk-packer 0.1.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 (44) hide show
  1. package/README.md +83 -0
  2. package/dist/DomainStack.d.ts +36 -0
  3. package/dist/DomainStack.js +360 -0
  4. package/dist/__tests__/domain-stack.test.d.ts +1 -0
  5. package/dist/__tests__/domain-stack.test.js +138 -0
  6. package/dist/__tests__/lambda-factory.test.d.ts +1 -0
  7. package/dist/__tests__/lambda-factory.test.js +30 -0
  8. package/dist/__tests__/pack-flows.test.d.ts +1 -0
  9. package/dist/__tests__/pack-flows.test.js +121 -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/constructs/action-construct.d.ts +30 -0
  15. package/dist/constructs/action-construct.js +32 -0
  16. package/dist/constructs/api-construct.d.ts +30 -0
  17. package/dist/constructs/api-construct.js +64 -0
  18. package/dist/constructs/job-construct.d.ts +33 -0
  19. package/dist/constructs/job-construct.js +54 -0
  20. package/dist/constructs/schedule-construct.d.ts +27 -0
  21. package/dist/constructs/schedule-construct.js +54 -0
  22. package/dist/constructs/subscriber-construct.d.ts +30 -0
  23. package/dist/constructs/subscriber-construct.js +63 -0
  24. package/dist/constructs/webhook-construct.d.ts +33 -0
  25. package/dist/constructs/webhook-construct.js +50 -0
  26. package/dist/flow-registry.d.ts +78 -0
  27. package/dist/flow-registry.js +2 -0
  28. package/dist/grouped-lambda-factory.d.ts +34 -0
  29. package/dist/grouped-lambda-factory.js +40 -0
  30. package/dist/iam/iam-policy-builder.d.ts +64 -0
  31. package/dist/iam/iam-policy-builder.js +132 -0
  32. package/dist/index.d.ts +28 -0
  33. package/dist/index.js +13 -0
  34. package/dist/lambda-factory.d.ts +46 -0
  35. package/dist/lambda-factory.js +72 -0
  36. package/dist/pack-domain.d.ts +30 -0
  37. package/dist/pack-domain.js +30 -0
  38. package/dist/pack-flows.d.ts +26 -0
  39. package/dist/pack-flows.js +112 -0
  40. package/dist/registry.d.ts +209 -0
  41. package/dist/registry.js +1 -0
  42. package/dist/step-functions-codegen.d.ts +65 -0
  43. package/dist/step-functions-codegen.js +55 -0
  44. package/package.json +31 -0
@@ -0,0 +1,30 @@
1
+ import * as events from 'aws-cdk-lib/aws-events';
2
+ import { Construct } from 'constructs';
3
+ import { LambdaFactory } from '../lambda-factory.js';
4
+ import { IamPolicyBuilder } from '../iam/iam-policy-builder.js';
5
+ import type { DomainRegistry } from '../registry.js';
6
+ /**
7
+ * Configuration properties for SubscriberConstruct.
8
+ */
9
+ export interface SubscriberConstructProps {
10
+ /** Domain registry containing all subscriber entries. */
11
+ registry: DomainRegistry;
12
+ /** Factory for creating Lambda functions from registry entries. */
13
+ lambdaFactory: LambdaFactory;
14
+ /** IAM policy builder for granting permissions to Lambda roles. */
15
+ iamBuilder: IamPolicyBuilder;
16
+ /** EventBridge event bus for routing subscriber events. */
17
+ eventBus: events.IEventBus;
18
+ }
19
+ /**
20
+ * CDK Construct that synthesises Lambda + SQS + EventBridge rule per registered subscriber.
21
+ */
22
+ export declare class SubscriberConstruct extends Construct {
23
+ /**
24
+ * Create a new SubscriberConstruct instance.
25
+ * @param scope - Parent CDK scope.
26
+ * @param id - Construct identifier.
27
+ * @param props - Construct properties.
28
+ */
29
+ constructor(scope: Construct, id: string, props: SubscriberConstructProps);
30
+ }
@@ -0,0 +1,63 @@
1
+ import * as cdk from 'aws-cdk-lib';
2
+ import * as sqs from 'aws-cdk-lib/aws-sqs';
3
+ import * as events from 'aws-cdk-lib/aws-events';
4
+ import * as eventsTargets from 'aws-cdk-lib/aws-events-targets';
5
+ import * as lambdaEventSources from 'aws-cdk-lib/aws-lambda-event-sources';
6
+ import { Construct } from 'constructs';
7
+ /**
8
+ * CDK Construct that synthesises Lambda + SQS + EventBridge rule per registered subscriber.
9
+ */
10
+ export class SubscriberConstruct extends Construct {
11
+ /**
12
+ * Create a new SubscriberConstruct instance.
13
+ * @param scope - Parent CDK scope.
14
+ * @param id - Construct identifier.
15
+ * @param props - Construct properties.
16
+ */
17
+ constructor(scope, id, props) {
18
+ super(scope, id);
19
+ for (const entry of props.registry.subscribers) {
20
+ const pascalId = toPascalCase(entry.id);
21
+ // Create dead-letter queue
22
+ const dlq = new sqs.Queue(this, `${pascalId}Dlq`, {
23
+ retentionPeriod: cdk.Duration.days(14),
24
+ });
25
+ // Create main queue with dead-letter queue configuration
26
+ const queue = new sqs.Queue(this, `${pascalId}Queue`, {
27
+ visibilityTimeout: cdk.Duration.seconds(180),
28
+ deadLetterQueue: {
29
+ queue: dlq,
30
+ maxReceiveCount: 3,
31
+ },
32
+ });
33
+ // Create Lambda function from registry entry
34
+ const fn = props.lambdaFactory.createFunction(entry, entry.deployment);
35
+ // Add IAM policies for SQS access
36
+ props.iamBuilder.forSubscriber({ queueArn: queue.queueArn, dlqArn: dlq.queueArn }).forEach((statement) => {
37
+ fn.addToRolePolicy(statement);
38
+ });
39
+ // Add SQS as event source for Lambda
40
+ fn.addEventSource(new lambdaEventSources.SqsEventSource(queue, {
41
+ batchSize: 10,
42
+ maxConcurrency: entry.concurrency ?? 5,
43
+ }));
44
+ // Create EventBridge rule targeting SQS queue
45
+ new events.Rule(this, `${pascalId}Rule`, {
46
+ eventBus: props.eventBus,
47
+ eventPattern: { detailType: [entry.event] },
48
+ targets: [new eventsTargets.SqsQueue(queue)],
49
+ });
50
+ }
51
+ }
52
+ }
53
+ /**
54
+ * Convert kebab-case or snake_case string to PascalCase.
55
+ * @param s - Input string.
56
+ * @returns PascalCase string.
57
+ */
58
+ function toPascalCase(s) {
59
+ return s
60
+ .split(/[-_]/)
61
+ .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
62
+ .join('');
63
+ }
@@ -0,0 +1,33 @@
1
+ import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
2
+ import * as apigwv2 from 'aws-cdk-lib/aws-apigatewayv2';
3
+ import { Construct } from 'constructs';
4
+ import { LambdaFactory } from '../lambda-factory.js';
5
+ import { IamPolicyBuilder } from '../iam/iam-policy-builder.js';
6
+ import type { DomainRegistry } from '../registry.js';
7
+ /**
8
+ * Configuration properties for WebhookConstruct.
9
+ */
10
+ export interface WebhookConstructProps {
11
+ /** Domain registry containing all webhook entries. */
12
+ registry: DomainRegistry;
13
+ /** Shared HttpApi to route requests to Lambdas. */
14
+ httpApi: apigwv2.HttpApi;
15
+ /** Factory for creating Lambda functions from registry entries. */
16
+ lambdaFactory: LambdaFactory;
17
+ /** IAM policy builder for granting permissions to Lambda roles. */
18
+ iamBuilder: IamPolicyBuilder;
19
+ }
20
+ /**
21
+ * CDK Construct that synthesises one Lambda per registered webhook, one shared DynamoDB dedupe table, and adds webhook routes to the HttpApi.
22
+ */
23
+ export declare class WebhookConstruct extends Construct {
24
+ /** Shared webhook deduplication table. */
25
+ readonly dedupeTable: dynamodb.Table;
26
+ /**
27
+ * Create a new WebhookConstruct instance.
28
+ * @param scope - Parent CDK scope.
29
+ * @param id - Construct identifier.
30
+ * @param props - Construct properties.
31
+ */
32
+ constructor(scope: Construct, id: string, props: WebhookConstructProps);
33
+ }
@@ -0,0 +1,50 @@
1
+ import * as cdk from 'aws-cdk-lib';
2
+ import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
3
+ import * as apigwv2 from 'aws-cdk-lib/aws-apigatewayv2';
4
+ import * as apigwv2integrations from 'aws-cdk-lib/aws-apigatewayv2-integrations';
5
+ import { Construct } from 'constructs';
6
+ /**
7
+ * CDK Construct that synthesises one Lambda per registered webhook, one shared DynamoDB dedupe table, and adds webhook routes to the HttpApi.
8
+ */
9
+ export class WebhookConstruct extends Construct {
10
+ /** Shared webhook deduplication table. */
11
+ dedupeTable;
12
+ /**
13
+ * Create a new WebhookConstruct instance.
14
+ * @param scope - Parent CDK scope.
15
+ * @param id - Construct identifier.
16
+ * @param props - Construct properties.
17
+ */
18
+ constructor(scope, id, props) {
19
+ super(scope, id);
20
+ this.dedupeTable = new dynamodb.Table(this, 'DedupeTable', {
21
+ partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
22
+ billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
23
+ timeToLiveAttribute: 'expiresAt',
24
+ removalPolicy: cdk.RemovalPolicy.DESTROY,
25
+ });
26
+ for (const entry of props.registry.webhooks) {
27
+ const fn = props.lambdaFactory.createFunction(entry, entry.deployment);
28
+ props.iamBuilder.forWebhook({ dedupeTableArn: this.dedupeTable.tableArn }).forEach((statement) => {
29
+ fn.addToRolePolicy(statement);
30
+ });
31
+ this.dedupeTable.grantReadWriteData(fn);
32
+ props.httpApi.addRoutes({
33
+ path: entry.path,
34
+ methods: [apigwv2.HttpMethod.POST],
35
+ integration: new apigwv2integrations.HttpLambdaIntegration(`${id}${toPascalCase(entry.id)}Integration`, fn),
36
+ });
37
+ }
38
+ }
39
+ }
40
+ /**
41
+ * Convert kebab-case or snake_case string to PascalCase.
42
+ * @param s - Input string.
43
+ * @returns PascalCase string.
44
+ */
45
+ function toPascalCase(s) {
46
+ return s
47
+ .split(/[-_]/)
48
+ .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
49
+ .join('');
50
+ }
@@ -0,0 +1,78 @@
1
+ /** Plain JSON-serialisable mirror of FlowStep types from domain-runtime. */
2
+ export interface SerialDomainActionStep {
3
+ type: 'domain-action';
4
+ name: string;
5
+ domainId: string;
6
+ actionId: string;
7
+ parameters?: Record<string, unknown>;
8
+ next?: string;
9
+ }
10
+ export interface SerialDomainApiStep {
11
+ type: 'domain-api';
12
+ name: string;
13
+ domainId: string;
14
+ apiId: string;
15
+ parameters?: Record<string, unknown>;
16
+ next?: string;
17
+ }
18
+ export interface SerialDomainEventStep {
19
+ type: 'domain-event';
20
+ name: string;
21
+ eventId: string;
22
+ payload: Record<string, unknown>;
23
+ version: number;
24
+ next?: string;
25
+ }
26
+ export type SerialFlowControlStep = {
27
+ type: 'flow-control';
28
+ control: 'choice';
29
+ name: string;
30
+ choices: Array<{
31
+ when: string;
32
+ next: string;
33
+ }>;
34
+ default?: string;
35
+ } | {
36
+ type: 'flow-control';
37
+ control: 'parallel';
38
+ name: string;
39
+ branches: SerialFlowStep[][];
40
+ next?: string;
41
+ } | {
42
+ type: 'flow-control';
43
+ control: 'wait';
44
+ name: string;
45
+ seconds: number;
46
+ next?: string;
47
+ } | {
48
+ type: 'flow-control';
49
+ control: 'succeed';
50
+ name: string;
51
+ } | {
52
+ type: 'flow-control';
53
+ control: 'fail';
54
+ name: string;
55
+ cause?: string;
56
+ error?: string;
57
+ } | {
58
+ type: 'flow-control';
59
+ control: 'pass';
60
+ name: string;
61
+ result?: unknown;
62
+ next?: string;
63
+ };
64
+ export type SerialFlowStep = SerialDomainActionStep | SerialDomainApiStep | SerialDomainEventStep | SerialFlowControlStep;
65
+ export interface FlowRegistryEntry {
66
+ id: string;
67
+ name: string;
68
+ steps: SerialFlowStep[];
69
+ trigger?: {
70
+ type: 'event';
71
+ eventId: string;
72
+ semverRange: string;
73
+ };
74
+ }
75
+ export interface FlowRegistry {
76
+ schemaVersion: '1';
77
+ flows: FlowRegistryEntry[];
78
+ }
@@ -0,0 +1,2 @@
1
+ /** Plain JSON-serialisable mirror of FlowStep types from domain-runtime. */
2
+ export {};
@@ -0,0 +1,34 @@
1
+ import * as lambda from 'aws-cdk-lib/aws-lambda';
2
+ import { Construct } from 'constructs';
3
+ /** Primitive types that can be grouped into a single Lambda. */
4
+ export type PrimitiveType = 'api' | 'subscriber' | 'schedule' | 'job' | 'webhook' | 'action';
5
+ /** A single handler entry within a grouped Lambda. */
6
+ export interface HandlerEntry {
7
+ /** Unique handler ID within the domain + primitive type. */
8
+ id: string;
9
+ /** Path to the handler file relative to the domain's dist directory. */
10
+ handlerFile: string;
11
+ }
12
+ /** Props for creating grouped or dedicated Lambdas for a primitive type. */
13
+ export interface GroupedLambdaProps {
14
+ /** Domain ID this Lambda belongs to. */
15
+ domainId: string;
16
+ /** The primitive type being handled (api, subscriber, etc.). */
17
+ primitiveType: PrimitiveType;
18
+ /** All handler entries for this primitive type within the domain. */
19
+ handlerEntries: HandlerEntry[];
20
+ /** Environment variables injected into the Lambda(s). */
21
+ environment: Record<string, string>;
22
+ /** ARN of the project-scoped EventBridge bus. */
23
+ eventBusArn: string;
24
+ /** When true, creates one dedicated Lambda per handler instead of a single grouped Lambda. */
25
+ dedicated?: boolean;
26
+ }
27
+ /**
28
+ * Creates either a single grouped Lambda (default) or per-handler dedicated Lambdas.
29
+ *
30
+ * Grouped Lambdas use an internal dispatch router: TIB_HANDLER_MAP lists all handler IDs,
31
+ * and the incoming event/request carries a handler ID to route to the correct function.
32
+ * When dedicated=true (escape hatch for hot/critical handlers), each handler gets its own Lambda.
33
+ */
34
+ export declare function createGroupedLambdas(scope: Construct, props: GroupedLambdaProps): lambda.Function[];
@@ -0,0 +1,40 @@
1
+ import * as lambda from 'aws-cdk-lib/aws-lambda';
2
+ import * as cdk from 'aws-cdk-lib';
3
+ /**
4
+ * Creates either a single grouped Lambda (default) or per-handler dedicated Lambdas.
5
+ *
6
+ * Grouped Lambdas use an internal dispatch router: TIB_HANDLER_MAP lists all handler IDs,
7
+ * and the incoming event/request carries a handler ID to route to the correct function.
8
+ * When dedicated=true (escape hatch for hot/critical handlers), each handler gets its own Lambda.
9
+ */
10
+ export function createGroupedLambdas(scope, props) {
11
+ if (props.dedicated) {
12
+ return props.handlerEntries.map(entry => new lambda.Function(scope, `${props.domainId}-${props.primitiveType}-${entry.id}`, {
13
+ runtime: lambda.Runtime.NODEJS_20_X,
14
+ handler: 'index.handler',
15
+ code: lambda.Code.fromAsset(`dist/domains/${props.domainId}/${props.primitiveType}/${entry.id}`),
16
+ environment: {
17
+ ...props.environment,
18
+ TIB_HANDLER_ID: entry.id,
19
+ TIB_EVENT_BUS_ARN: props.eventBusArn,
20
+ },
21
+ timeout: cdk.Duration.seconds(30),
22
+ memorySize: 256,
23
+ }));
24
+ }
25
+ // Single grouped Lambda — all handlers for this primitive type bundled together
26
+ return [
27
+ new lambda.Function(scope, `${props.domainId}-${props.primitiveType}`, {
28
+ runtime: lambda.Runtime.NODEJS_20_X,
29
+ handler: 'index.handler',
30
+ code: lambda.Code.fromAsset(`dist/domains/${props.domainId}/${props.primitiveType}`),
31
+ environment: {
32
+ ...props.environment,
33
+ TIB_HANDLER_MAP: JSON.stringify(props.handlerEntries.map(e => e.id)),
34
+ TIB_EVENT_BUS_ARN: props.eventBusArn,
35
+ },
36
+ timeout: cdk.Duration.seconds(30),
37
+ memorySize: 256,
38
+ }),
39
+ ];
40
+ }
@@ -0,0 +1,64 @@
1
+ import * as iam from 'aws-cdk-lib/aws-iam';
2
+ import type { RegistryEntryKind } from '../registry.js';
3
+ /**
4
+ * Parameters for webhook IAM policy construction.
5
+ */
6
+ export interface WebhookPolicyParams {
7
+ /** ARN of the DynamoDB deduplication table. */
8
+ dedupeTableArn: string;
9
+ }
10
+ /**
11
+ * Parameters for queue-based IAM policy construction (subscriber and job).
12
+ */
13
+ export interface QueuePolicyParams {
14
+ /** ARN of the SQS queue. */
15
+ queueArn: string;
16
+ /** ARN of the SQS dead-letter queue. */
17
+ dlqArn: string;
18
+ }
19
+ /**
20
+ * Generates least-privilege IAM policy statements per handler kind.
21
+ * Used by CDK constructs to build policies for Lambda execution roles.
22
+ */
23
+ export declare class IamPolicyBuilder {
24
+ /**
25
+ * Returns IAM policy statements for API handlers.
26
+ * @returns Array of policy statements for Secrets Manager and EventBridge access.
27
+ */
28
+ forApi(): iam.PolicyStatement[];
29
+ /**
30
+ * Returns IAM policy statements for webhook handlers.
31
+ * @param params - Webhook policy parameters including deduplication table ARN.
32
+ * @returns Array of policy statements for Secrets Manager, DynamoDB, and EventBridge access.
33
+ */
34
+ forWebhook(params: WebhookPolicyParams): iam.PolicyStatement[];
35
+ /**
36
+ * Returns IAM policy statements for event subscriber handlers.
37
+ * @param params - Queue policy parameters including queue and dead-letter queue ARNs.
38
+ * @returns Array of policy statements for SQS message receive/delete and DLQ send access.
39
+ */
40
+ forSubscriber(params: QueuePolicyParams): iam.PolicyStatement[];
41
+ /**
42
+ * Returns IAM policy statements for schedule (cron) handlers.
43
+ * @returns Array of policy statements for EventBridge and Secrets Manager access.
44
+ */
45
+ forSchedule(): iam.PolicyStatement[];
46
+ /**
47
+ * Returns IAM policy statements for background job handlers.
48
+ * @param params - Queue policy parameters including queue and dead-letter queue ARNs.
49
+ * @returns Array of policy statements for SQS message receive/delete and DLQ send access.
50
+ */
51
+ forJob(params: QueuePolicyParams): iam.PolicyStatement[];
52
+ /**
53
+ * Returns IAM policy statements for callable action handlers.
54
+ * @returns Array of policy statements for Secrets Manager access.
55
+ */
56
+ forAction(): iam.PolicyStatement[];
57
+ /**
58
+ * Returns IAM policy statements based on handler kind.
59
+ * @param kind - The registry entry kind discriminant.
60
+ * @param params - Optional parameters required for certain kinds (webhook, subscriber, job).
61
+ * @returns Array of policy statements appropriate for the handler kind.
62
+ */
63
+ forKind(kind: RegistryEntryKind, params?: WebhookPolicyParams | QueuePolicyParams): iam.PolicyStatement[];
64
+ }
@@ -0,0 +1,132 @@
1
+ import * as iam from 'aws-cdk-lib/aws-iam';
2
+ /**
3
+ * Generates least-privilege IAM policy statements per handler kind.
4
+ * Used by CDK constructs to build policies for Lambda execution roles.
5
+ */
6
+ export class IamPolicyBuilder {
7
+ /**
8
+ * Returns IAM policy statements for API handlers.
9
+ * @returns Array of policy statements for Secrets Manager and EventBridge access.
10
+ */
11
+ forApi() {
12
+ return [
13
+ new iam.PolicyStatement({
14
+ actions: ['secretsmanager:GetSecretValue'],
15
+ resources: ['*'],
16
+ }),
17
+ new iam.PolicyStatement({
18
+ actions: ['events:PutEvents'],
19
+ resources: ['*'],
20
+ }),
21
+ ];
22
+ }
23
+ /**
24
+ * Returns IAM policy statements for webhook handlers.
25
+ * @param params - Webhook policy parameters including deduplication table ARN.
26
+ * @returns Array of policy statements for Secrets Manager, DynamoDB, and EventBridge access.
27
+ */
28
+ forWebhook(params) {
29
+ return [
30
+ new iam.PolicyStatement({
31
+ actions: ['secretsmanager:GetSecretValue'],
32
+ resources: ['*'],
33
+ }),
34
+ new iam.PolicyStatement({
35
+ actions: ['dynamodb:PutItem', 'dynamodb:GetItem', 'dynamodb:DeleteItem'],
36
+ resources: [params.dedupeTableArn],
37
+ }),
38
+ new iam.PolicyStatement({
39
+ actions: ['events:PutEvents'],
40
+ resources: ['*'],
41
+ }),
42
+ ];
43
+ }
44
+ /**
45
+ * Returns IAM policy statements for event subscriber handlers.
46
+ * @param params - Queue policy parameters including queue and dead-letter queue ARNs.
47
+ * @returns Array of policy statements for SQS message receive/delete and DLQ send access.
48
+ */
49
+ forSubscriber(params) {
50
+ return [
51
+ new iam.PolicyStatement({
52
+ actions: ['sqs:ReceiveMessage', 'sqs:DeleteMessage', 'sqs:GetQueueAttributes'],
53
+ resources: [params.queueArn],
54
+ }),
55
+ new iam.PolicyStatement({
56
+ actions: ['sqs:SendMessage'],
57
+ resources: [params.dlqArn],
58
+ }),
59
+ ];
60
+ }
61
+ /**
62
+ * Returns IAM policy statements for schedule (cron) handlers.
63
+ * @returns Array of policy statements for EventBridge and Secrets Manager access.
64
+ */
65
+ forSchedule() {
66
+ return [
67
+ new iam.PolicyStatement({
68
+ actions: ['events:PutEvents'],
69
+ resources: ['*'],
70
+ }),
71
+ new iam.PolicyStatement({
72
+ actions: ['secretsmanager:GetSecretValue'],
73
+ resources: ['*'],
74
+ }),
75
+ ];
76
+ }
77
+ /**
78
+ * Returns IAM policy statements for background job handlers.
79
+ * @param params - Queue policy parameters including queue and dead-letter queue ARNs.
80
+ * @returns Array of policy statements for SQS message receive/delete and DLQ send access.
81
+ */
82
+ forJob(params) {
83
+ return [
84
+ new iam.PolicyStatement({
85
+ actions: ['sqs:ReceiveMessage', 'sqs:DeleteMessage', 'sqs:GetQueueAttributes'],
86
+ resources: [params.queueArn],
87
+ }),
88
+ new iam.PolicyStatement({
89
+ actions: ['sqs:SendMessage'],
90
+ resources: [params.dlqArn],
91
+ }),
92
+ ];
93
+ }
94
+ /**
95
+ * Returns IAM policy statements for callable action handlers.
96
+ * @returns Array of policy statements for Secrets Manager access.
97
+ */
98
+ forAction() {
99
+ return [
100
+ new iam.PolicyStatement({
101
+ actions: ['secretsmanager:GetSecretValue'],
102
+ resources: ['*'],
103
+ }),
104
+ ];
105
+ }
106
+ /**
107
+ * Returns IAM policy statements based on handler kind.
108
+ * @param kind - The registry entry kind discriminant.
109
+ * @param params - Optional parameters required for certain kinds (webhook, subscriber, job).
110
+ * @returns Array of policy statements appropriate for the handler kind.
111
+ */
112
+ forKind(kind, params) {
113
+ switch (kind) {
114
+ case 'integration':
115
+ case 'event':
116
+ case 'domain':
117
+ return [];
118
+ case 'webhook':
119
+ return this.forWebhook(params);
120
+ case 'subscriber':
121
+ return this.forSubscriber(params);
122
+ case 'job':
123
+ return this.forJob(params);
124
+ case 'api':
125
+ return this.forApi();
126
+ case 'schedule':
127
+ return this.forSchedule();
128
+ case 'action':
129
+ return this.forAction();
130
+ }
131
+ }
132
+ }
@@ -0,0 +1,28 @@
1
+ export type { DomainRegistry, RegistryEntry, RegistryEntryKind, BaseRegistryEntry, SerialDeploymentConfig, ApiRegistryEntry, WebhookRegistryEntry, SubscriberRegistryEntry, ScheduleRegistryEntry, JobRegistryEntry, ActionRegistryEntry, IntegrationRegistryEntry, EventRegistryEntry, DomainRegistryEntry, SchemaSnapshot, } from './registry.js';
2
+ export { LambdaFactory } from './lambda-factory.js';
3
+ export type { LambdaFactoryProps } from './lambda-factory.js';
4
+ export { createGroupedLambdas } from './grouped-lambda-factory.js';
5
+ export type { PrimitiveType, HandlerEntry, GroupedLambdaProps } from './grouped-lambda-factory.js';
6
+ export { IamPolicyBuilder } from './iam/iam-policy-builder.js';
7
+ export type { WebhookPolicyParams, QueuePolicyParams } from './iam/iam-policy-builder.js';
8
+ export { ApiConstruct } from './constructs/api-construct.js';
9
+ export type { ApiConstructProps } from './constructs/api-construct.js';
10
+ export { WebhookConstruct } from './constructs/webhook-construct.js';
11
+ export type { WebhookConstructProps } from './constructs/webhook-construct.js';
12
+ export { SubscriberConstruct } from './constructs/subscriber-construct.js';
13
+ export type { SubscriberConstructProps } from './constructs/subscriber-construct.js';
14
+ export { ScheduleConstruct } from './constructs/schedule-construct.js';
15
+ export type { ScheduleConstructProps } from './constructs/schedule-construct.js';
16
+ export { JobConstruct } from './constructs/job-construct.js';
17
+ export type { JobConstructProps } from './constructs/job-construct.js';
18
+ export { ActionConstruct } from './constructs/action-construct.js';
19
+ export type { ActionConstructProps } from './constructs/action-construct.js';
20
+ export { DomainStack } from './DomainStack.js';
21
+ export type { DomainStackProps } from './DomainStack.js';
22
+ export { packDomain } from './pack-domain.js';
23
+ export type { PackDomainOptions } from './pack-domain.js';
24
+ export { StepFunctionsCodegen } from './step-functions-codegen.js';
25
+ export type { DomainActionFlowNode, StepFunctionsTaskState } from './step-functions-codegen.js';
26
+ export type { FlowRegistry, FlowRegistryEntry, SerialFlowStep, SerialDomainActionStep, SerialDomainApiStep, SerialDomainEventStep, SerialFlowControlStep } from './flow-registry.js';
27
+ export { FlowsStack, packFlows } from './pack-flows.js';
28
+ export type { PackFlowsOptions } from './pack-flows.js';
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ export { LambdaFactory } from './lambda-factory.js';
2
+ export { createGroupedLambdas } from './grouped-lambda-factory.js';
3
+ export { IamPolicyBuilder } from './iam/iam-policy-builder.js';
4
+ export { ApiConstruct } from './constructs/api-construct.js';
5
+ export { WebhookConstruct } from './constructs/webhook-construct.js';
6
+ export { SubscriberConstruct } from './constructs/subscriber-construct.js';
7
+ export { ScheduleConstruct } from './constructs/schedule-construct.js';
8
+ export { JobConstruct } from './constructs/job-construct.js';
9
+ export { ActionConstruct } from './constructs/action-construct.js';
10
+ export { DomainStack } from './DomainStack.js';
11
+ export { packDomain } from './pack-domain.js';
12
+ export { StepFunctionsCodegen } from './step-functions-codegen.js';
13
+ export { FlowsStack, packFlows } from './pack-flows.js';
@@ -0,0 +1,46 @@
1
+ import * as lambdaNode from 'aws-cdk-lib/aws-lambda-nodejs';
2
+ import { Construct } from 'constructs';
3
+ import type { BaseRegistryEntry, SerialDeploymentConfig, DomainRegistry } from './registry.js';
4
+ /**
5
+ * Configuration properties for LambdaFactory.
6
+ */
7
+ export interface LambdaFactoryProps {
8
+ /** Parent CDK scope */
9
+ scope: Construct;
10
+ /** Full domain registry */
11
+ registry: DomainRegistry;
12
+ /** Absolute path to domain root (= registry.domainRoot) */
13
+ domainRoot: string;
14
+ /** Extra env vars injected into all Lambdas */
15
+ sharedEnv?: Record<string, string>;
16
+ }
17
+ /**
18
+ * Factory for creating CDK NodejsFunction instances from domain registry entries with consistent defaults.
19
+ */
20
+ export declare class LambdaFactory {
21
+ private scope;
22
+ private registry;
23
+ private domainRoot;
24
+ private sharedEnv?;
25
+ /**
26
+ * Create a new LambdaFactory instance.
27
+ * @param props - Factory configuration
28
+ */
29
+ constructor(props: LambdaFactoryProps);
30
+ /**
31
+ * Convert a kebab-case or snake_case string to PascalCase.
32
+ * @param s - Input string
33
+ * @returns PascalCase string
34
+ */
35
+ private toPascalCase;
36
+ /**
37
+ * Create a NodejsFunction from a registry entry.
38
+ * @param entry - Registry entry with handlerFile property
39
+ * @param overrides - Optional deployment configuration overrides
40
+ * @param extraEnv - Optional extra environment variables
41
+ * @returns Created NodejsFunction
42
+ */
43
+ createFunction(entry: BaseRegistryEntry & {
44
+ handlerFile: string;
45
+ }, overrides?: SerialDeploymentConfig, extraEnv?: Record<string, string>): lambdaNode.NodejsFunction;
46
+ }