@jaypie/constructs 1.2.17 → 1.2.19

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.
@@ -93,7 +93,7 @@ export declare class JaypieDynamoDb extends Construct implements dynamodb.ITable
93
93
  * Default Jaypie GSI definitions from @jaypie/fabric.
94
94
  * Pass to `indexes` prop to create all standard GSIs.
95
95
  */
96
- static readonly DEFAULT_INDEXES: any;
96
+ static readonly DEFAULT_INDEXES: IndexDefinition[];
97
97
  private readonly _table;
98
98
  constructor(scope: Construct, id: string, props?: JaypieDynamoDbProps);
99
99
  /**
@@ -16,8 +16,16 @@ export interface JaypieNextjsProps {
16
16
  * - String: used directly as the domain name
17
17
  * - Object: passed to envHostname() to construct the domain name
18
18
  * - { component, domain, env, subdomain }
19
+ *
20
+ * To deploy without a domain (CloudFront URL only), set domainProps: false
19
21
  */
20
22
  domainName?: string | DomainNameConfig;
23
+ /**
24
+ * Set to false to deploy without a custom domain.
25
+ * When false, the application will only be accessible via CloudFront URL.
26
+ * This overrides any domainName configuration.
27
+ */
28
+ domainProps?: false;
21
29
  /**
22
30
  * DynamoDB tables to grant read/write access to the Next.js server function.
23
31
  * Each table is granted read/write access and if exactly one table is provided,
@@ -51,7 +59,7 @@ export interface JaypieNextjsProps {
51
59
  }
52
60
  export declare class JaypieNextJs extends Construct {
53
61
  private readonly _nextjs;
54
- readonly domainName: string;
62
+ readonly domainName?: string;
55
63
  constructor(scope: Construct, id: string, props?: JaypieNextjsProps);
56
64
  /** S3 bucket for static assets */
57
65
  get bucket(): import("aws-cdk-lib/aws-s3").IBucket;
@@ -0,0 +1,115 @@
1
+ import { Construct } from "constructs";
2
+ import * as acm from "aws-cdk-lib/aws-certificatemanager";
3
+ import * as apigatewayv2 from "aws-cdk-lib/aws-apigatewayv2";
4
+ import * as iam from "aws-cdk-lib/aws-iam";
5
+ import * as lambda from "aws-cdk-lib/aws-lambda";
6
+ import * as logs from "aws-cdk-lib/aws-logs";
7
+ import * as route53 from "aws-cdk-lib/aws-route53";
8
+ import { HostConfig } from "./helpers";
9
+ export interface JaypieWebSocketProps {
10
+ /**
11
+ * Certificate configuration.
12
+ * - true: Create certificate at stack level (default, reusable)
13
+ * - false: No certificate (use regional endpoint)
14
+ * - ICertificate: Use provided certificate
15
+ * - string: Import certificate from ARN
16
+ */
17
+ certificate?: boolean | acm.ICertificate | string;
18
+ /**
19
+ * Lambda handler for $connect route (connection established).
20
+ * Use this to validate connections (e.g., auth tokens) and store connection IDs.
21
+ */
22
+ connect?: lambda.IFunction;
23
+ /**
24
+ * Lambda handler for $default route (catches unmatched messages).
25
+ * Use this as the main message handler.
26
+ */
27
+ default?: lambda.IFunction;
28
+ /**
29
+ * Lambda handler for $disconnect route (connection closed).
30
+ * Use this to clean up connection IDs from storage.
31
+ */
32
+ disconnect?: lambda.IFunction;
33
+ /**
34
+ * Single Lambda handler for all routes.
35
+ * Alternative to providing separate connect/disconnect/default handlers.
36
+ * The handler receives routeKey in the context to determine which route was invoked.
37
+ */
38
+ handler?: lambda.IFunction;
39
+ /**
40
+ * The domain name for the WebSocket API.
41
+ *
42
+ * Supports both string and config object:
43
+ * - String: used directly as the domain name (e.g., "ws.example.com")
44
+ * - Object: passed to envHostname() to construct the domain name
45
+ * - { subdomain, domain, env, component }
46
+ *
47
+ * @example
48
+ * // Direct string
49
+ * host: "ws.example.com"
50
+ *
51
+ * @example
52
+ * // Config object - resolves using envHostname()
53
+ * host: { component: "ws" }
54
+ */
55
+ host?: string | HostConfig;
56
+ /**
57
+ * Log retention for WebSocket API access logs.
58
+ * @default logs.RetentionDays.THREE_MONTHS
59
+ */
60
+ logRetention?: logs.RetentionDays;
61
+ /**
62
+ * Construct name (used for resource naming).
63
+ */
64
+ name?: string;
65
+ /**
66
+ * Role tag for tagging resources.
67
+ * @default CDK.ROLE.API
68
+ */
69
+ roleTag?: string;
70
+ /**
71
+ * Additional named routes beyond $connect, $disconnect, and $default.
72
+ * Keys are route keys (e.g., "sendMessage", "subscribe").
73
+ */
74
+ routes?: Record<string, lambda.IFunction>;
75
+ /**
76
+ * Stage name for the WebSocket API.
77
+ * @default "production"
78
+ */
79
+ stageName?: string;
80
+ /**
81
+ * Route53 hosted zone for DNS records.
82
+ * - string: Zone domain name (looked up or imported)
83
+ * - IHostedZone: Use provided hosted zone
84
+ */
85
+ zone?: string | route53.IHostedZone;
86
+ }
87
+ export declare class JaypieWebSocket extends Construct {
88
+ private readonly _api;
89
+ private readonly _certificate?;
90
+ private readonly _domainName?;
91
+ private readonly _host?;
92
+ private readonly _stage;
93
+ constructor(scope: Construct, id: string, props?: JaypieWebSocketProps);
94
+ get api(): apigatewayv2.WebSocketApi;
95
+ get apiId(): string;
96
+ get certificate(): acm.ICertificate | undefined;
97
+ get domainName(): string | undefined;
98
+ /**
99
+ * The WebSocket endpoint URL.
100
+ * Uses custom domain if configured, otherwise returns the default stage URL.
101
+ */
102
+ get endpoint(): string;
103
+ get host(): string | undefined;
104
+ get stage(): apigatewayv2.WebSocketStage;
105
+ /**
106
+ * The callback URL for API Gateway Management API.
107
+ * Use this URL to send messages to connected clients.
108
+ */
109
+ get callbackUrl(): string;
110
+ /**
111
+ * Grant a Lambda function permission to manage WebSocket connections
112
+ * (post to connections, delete connections).
113
+ */
114
+ grantManageConnections(grantee: lambda.IFunction): iam.Grant;
115
+ }
@@ -0,0 +1,26 @@
1
+ import { Construct } from "constructs";
2
+ import { JaypieLambda, JaypieLambdaProps } from "./JaypieLambda.js";
3
+ /**
4
+ * JaypieWebSocketLambda - A Lambda function optimized for WebSocket handlers.
5
+ *
6
+ * Provides sensible defaults for WebSocket event handling:
7
+ * - 30 second timeout (same as API handlers)
8
+ * - API role tag
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const handler = new JaypieWebSocketLambda(this, "ChatHandler", {
13
+ * code: "dist/handlers",
14
+ * handler: "chat.handler",
15
+ * secrets: ["MONGODB_URI"],
16
+ * });
17
+ *
18
+ * new JaypieWebSocket(this, "Chat", {
19
+ * host: "ws.example.com",
20
+ * handler,
21
+ * });
22
+ * ```
23
+ */
24
+ export declare class JaypieWebSocketLambda extends JaypieLambda {
25
+ constructor(scope: Construct, id: string, props: JaypieLambdaProps);
26
+ }
@@ -0,0 +1,100 @@
1
+ import { Construct } from "constructs";
2
+ import { Duration } from "aws-cdk-lib";
3
+ import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
4
+ import * as iam from "aws-cdk-lib/aws-iam";
5
+ import * as lambda from "aws-cdk-lib/aws-lambda";
6
+ export interface JaypieWebSocketTableProps {
7
+ /**
8
+ * Explicit table name. If not provided, uses CDK-generated name.
9
+ */
10
+ tableName?: string;
11
+ /**
12
+ * Time-to-live duration for connections.
13
+ * Connections will be automatically deleted after this duration.
14
+ * @default Duration.hours(24)
15
+ */
16
+ ttl?: Duration;
17
+ /**
18
+ * Whether to create a GSI for looking up connections by user ID.
19
+ * @default false
20
+ */
21
+ userIndex?: boolean;
22
+ /**
23
+ * Role tag for tagging resources.
24
+ * @default CDK.ROLE.STORAGE
25
+ */
26
+ roleTag?: string;
27
+ }
28
+ /**
29
+ * JaypieWebSocketTable - DynamoDB table for storing WebSocket connection IDs.
30
+ *
31
+ * Provides a simple table structure for tracking active WebSocket connections:
32
+ * - Partition key: connectionId (String)
33
+ * - TTL attribute: expiresAt (for automatic cleanup)
34
+ * - Optional GSI: userId-index (for looking up connections by user)
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const connectionTable = new JaypieWebSocketTable(this, "Connections");
39
+ *
40
+ * const ws = new JaypieWebSocket(this, "Chat", {
41
+ * host: "ws.example.com",
42
+ * handler: chatHandler,
43
+ * });
44
+ *
45
+ * // Grant Lambda access to the table
46
+ * connectionTable.grantReadWriteData(chatHandler);
47
+ *
48
+ * // Pass table name to Lambda
49
+ * chatHandler.addEnvironment("CONNECTION_TABLE", connectionTable.tableName);
50
+ * ```
51
+ *
52
+ * @example
53
+ * // With user index for looking up all connections for a user
54
+ * const connectionTable = new JaypieWebSocketTable(this, "Connections", {
55
+ * userIndex: true,
56
+ * ttl: Duration.hours(12),
57
+ * });
58
+ */
59
+ export declare class JaypieWebSocketTable extends Construct {
60
+ private readonly _table;
61
+ private readonly _ttlDuration;
62
+ constructor(scope: Construct, id: string, props?: JaypieWebSocketTableProps);
63
+ /**
64
+ * The underlying DynamoDB TableV2 construct.
65
+ */
66
+ get table(): dynamodb.TableV2;
67
+ /**
68
+ * The name of the DynamoDB table.
69
+ */
70
+ get tableName(): string;
71
+ /**
72
+ * The ARN of the DynamoDB table.
73
+ */
74
+ get tableArn(): string;
75
+ /**
76
+ * TTL duration for connections in seconds.
77
+ * Use this to calculate expiresAt when storing connections.
78
+ */
79
+ get ttlSeconds(): number;
80
+ /**
81
+ * Grant read permissions to the table.
82
+ */
83
+ grantReadData(grantee: iam.IGrantable): iam.Grant;
84
+ /**
85
+ * Grant write permissions to the table.
86
+ */
87
+ grantWriteData(grantee: iam.IGrantable): iam.Grant;
88
+ /**
89
+ * Grant read and write permissions to the table.
90
+ */
91
+ grantReadWriteData(grantee: iam.IGrantable): iam.Grant;
92
+ /**
93
+ * Add the table name to a Lambda function's environment variables.
94
+ * Also grants read/write access to the table.
95
+ */
96
+ connectLambda(lambdaFunction: lambda.IFunction, options?: {
97
+ envKey?: string;
98
+ readOnly?: boolean;
99
+ }): void;
100
+ }
@@ -0,0 +1 @@
1
+ export {};