@jaypie/constructs 1.2.2 → 1.2.4

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.
@@ -1,9 +1,10 @@
1
1
  import { Construct } from "constructs";
2
2
  import { Duration, Stack, RemovalPolicy } from "aws-cdk-lib";
3
- import * as lambda from "aws-cdk-lib/aws-lambda";
4
3
  import * as cloudwatch from "aws-cdk-lib/aws-cloudwatch";
4
+ import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
5
5
  import * as ec2 from "aws-cdk-lib/aws-ec2";
6
6
  import * as iam from "aws-cdk-lib/aws-iam";
7
+ import * as lambda from "aws-cdk-lib/aws-lambda";
7
8
  import * as logs from "aws-cdk-lib/aws-logs";
8
9
  import * as secretsmanager from "aws-cdk-lib/aws-secretsmanager";
9
10
  import { EnvironmentInput, SecretsArrayItem } from "./helpers/index.js";
@@ -17,6 +18,10 @@ export interface JaypieLambdaProps {
17
18
  deadLetterQueueEnabled?: boolean;
18
19
  deadLetterTopic?: import("aws-cdk-lib/aws-sns").ITopic;
19
20
  description?: string;
21
+ /**
22
+ * DynamoDB tables to grant read/write access to the Lambda function.
23
+ */
24
+ dynamoTables?: dynamodb.ITable[];
20
25
  /**
21
26
  * Environment variables for the Lambda function.
22
27
  *
@@ -1,3 +1,4 @@
1
+ import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
1
2
  import { IHostedZone } from "aws-cdk-lib/aws-route53";
2
3
  import * as secretsmanager from "aws-cdk-lib/aws-secretsmanager";
3
4
  import { Construct } from "constructs";
@@ -19,6 +20,10 @@ export interface JaypieNextjsProps {
19
20
  * - { component, domain, env, subdomain }
20
21
  */
21
22
  domainName?: string | DomainNameConfig;
23
+ /**
24
+ * DynamoDB tables to grant read/write access to the Next.js server function.
25
+ */
26
+ dynamoTables?: dynamodb.ITable[];
22
27
  /**
23
28
  * Environment variables for the Next.js application.
24
29
  *
@@ -45,6 +50,29 @@ export interface JaypieNextjsProps {
45
50
  secrets?: SecretsArrayItem[];
46
51
  }
47
52
  export declare class JaypieNextJs extends Construct {
53
+ private readonly _nextjs;
48
54
  readonly domainName: string;
49
55
  constructor(scope: Construct, id: string, props?: JaypieNextjsProps);
56
+ /** S3 bucket for static assets */
57
+ get bucket(): import("aws-cdk-lib/aws-s3").IBucket;
58
+ /** CloudFront distribution */
59
+ get distribution(): import("cdk-nextjs-standalone").NextjsDistribution;
60
+ /** Route53 domain configuration */
61
+ get domain(): import("cdk-nextjs-standalone").NextjsDomain | undefined;
62
+ /** Image optimization Lambda function */
63
+ get imageOptimizationFunction(): import("cdk-nextjs-standalone").NextjsImage;
64
+ /** Image optimization Lambda function URL */
65
+ get imageOptimizationLambdaFunctionUrl(): import("aws-cdk-lib/aws-lambda").FunctionUrl;
66
+ /** Server Lambda function URL */
67
+ get lambdaFunctionUrl(): import("aws-cdk-lib/aws-lambda").FunctionUrl;
68
+ /** Next.js build output */
69
+ get nextBuild(): import("cdk-nextjs-standalone").NextjsBuild;
70
+ /** ISR revalidation configuration */
71
+ get revalidation(): import("cdk-nextjs-standalone").NextjsRevalidation;
72
+ /** Next.js server function */
73
+ get serverFunction(): import("cdk-nextjs-standalone").NextjsServer;
74
+ /** Static assets configuration */
75
+ get staticAssets(): import("cdk-nextjs-standalone").NextjsStaticAssets;
76
+ /** CloudFront distribution URL */
77
+ get url(): string;
50
78
  }
package/dist/esm/index.js CHANGED
@@ -363,10 +363,17 @@ function envHostname({ component, domain, env, subdomain, } = {}) {
363
363
  const resolvedSubdomain = providedSubdomain || process.env.CDK_ENV_SUBDOMAIN;
364
364
  const resolvedEnv = env || process.env.PROJECT_ENV;
365
365
  const filteredEnv = resolvedEnv === CDK$2.ENV.PRODUCTION ? undefined : resolvedEnv;
366
+ // Check if parts are already contained in the domain to avoid duplication
367
+ const domainParts = resolvedDomain.split(".");
368
+ const isPartInDomain = (part) => {
369
+ if (!part)
370
+ return false;
371
+ return domainParts.includes(part);
372
+ };
366
373
  const parts = [
367
- resolvedComponent,
368
- resolvedSubdomain,
369
- filteredEnv,
374
+ isPartInDomain(resolvedComponent) ? undefined : resolvedComponent,
375
+ isPartInDomain(resolvedSubdomain) ? undefined : resolvedSubdomain,
376
+ isPartInDomain(filteredEnv) ? undefined : filteredEnv,
370
377
  resolvedDomain,
371
378
  ].filter((part) => part);
372
379
  return parts.join(".");
@@ -1170,7 +1177,7 @@ class JaypieAppStack extends JaypieStack {
1170
1177
  class JaypieLambda extends Construct {
1171
1178
  constructor(scope, id, props) {
1172
1179
  super(scope, id);
1173
- const { allowAllOutbound, allowPublicSubnet, architecture = lambda.Architecture.X86_64, code, datadogApiKeyArn, deadLetterQueue, deadLetterQueueEnabled, deadLetterTopic, description, environment: environmentInput, envSecrets = {}, ephemeralStorageSize, filesystem, handler = "index.handler", initialPolicy, layers = [], logGroup, logRetention = CDK$2.LAMBDA.LOG_RETENTION, maxEventAge, memorySize = CDK$2.LAMBDA.MEMORY_SIZE, paramsAndSecrets, paramsAndSecretsOptions, profiling, profilingGroup, provisionedConcurrentExecutions, reservedConcurrentExecutions, retryAttempts, roleTag = CDK$2.ROLE.PROCESSING, runtime = new lambda.Runtime("nodejs24.x", lambda.RuntimeFamily.NODEJS, {
1180
+ const { allowAllOutbound, allowPublicSubnet, architecture = lambda.Architecture.X86_64, code, datadogApiKeyArn, deadLetterQueue, deadLetterQueueEnabled, deadLetterTopic, description, dynamoTables = [], environment: environmentInput, envSecrets = {}, ephemeralStorageSize, filesystem, handler = "index.handler", initialPolicy, layers = [], logGroup, logRetention = CDK$2.LAMBDA.LOG_RETENTION, maxEventAge, memorySize = CDK$2.LAMBDA.MEMORY_SIZE, paramsAndSecrets, paramsAndSecretsOptions, profiling, profilingGroup, provisionedConcurrentExecutions, reservedConcurrentExecutions, retryAttempts, roleTag = CDK$2.ROLE.PROCESSING, runtime = new lambda.Runtime("nodejs24.x", lambda.RuntimeFamily.NODEJS, {
1174
1181
  supportsInlineCode: true,
1175
1182
  }), runtimeManagementMode, secrets: secretsInput = [], securityGroups, timeout = Duration.seconds(CDK$2.DURATION.LAMBDA_WORKER), tracing, vendorTag, vpc, vpcSubnets, } = props;
1176
1183
  // Resolve environment from array or object syntax
@@ -1261,6 +1268,14 @@ class JaypieLambda extends Construct {
1261
1268
  secrets.forEach((secret) => {
1262
1269
  secret.grantRead(this._lambda);
1263
1270
  });
1271
+ // Grant read/write permissions for DynamoDB tables
1272
+ dynamoTables.forEach((table) => {
1273
+ table.grantReadWriteData(this._lambda);
1274
+ });
1275
+ // Add table name to environment if there's exactly one table
1276
+ if (dynamoTables.length === 1) {
1277
+ this._lambda.addEnvironment("CDK_ENV_DYNAMO_TABLE", dynamoTables[0].tableName);
1278
+ }
1264
1279
  // Configure provisioned concurrency if specified
1265
1280
  if (provisionedConcurrentExecutions !== undefined) {
1266
1281
  // Use currentVersion which is auto-published with proper configuration
@@ -2653,6 +2668,62 @@ class JaypieNextJs extends Construct {
2653
2668
  secrets.forEach((secret) => {
2654
2669
  secret.grantRead(nextjs.serverFunction.lambdaFunction);
2655
2670
  });
2671
+ // Grant read/write permissions for DynamoDB tables
2672
+ const dynamoTables = props?.dynamoTables || [];
2673
+ dynamoTables.forEach((table) => {
2674
+ table.grantReadWriteData(nextjs.serverFunction.lambdaFunction);
2675
+ });
2676
+ // Add table name to environment if there's exactly one table
2677
+ if (dynamoTables.length === 1) {
2678
+ nextjs.serverFunction.lambdaFunction.addEnvironment("CDK_ENV_DYNAMO_TABLE", dynamoTables[0].tableName);
2679
+ }
2680
+ // Store reference to nextjs for property exposure
2681
+ this._nextjs = nextjs;
2682
+ }
2683
+ // Expose Nextjs construct properties
2684
+ /** S3 bucket for static assets */
2685
+ get bucket() {
2686
+ return this._nextjs.bucket;
2687
+ }
2688
+ /** CloudFront distribution */
2689
+ get distribution() {
2690
+ return this._nextjs.distribution;
2691
+ }
2692
+ /** Route53 domain configuration */
2693
+ get domain() {
2694
+ return this._nextjs.domain;
2695
+ }
2696
+ /** Image optimization Lambda function */
2697
+ get imageOptimizationFunction() {
2698
+ return this._nextjs.imageOptimizationFunction;
2699
+ }
2700
+ /** Image optimization Lambda function URL */
2701
+ get imageOptimizationLambdaFunctionUrl() {
2702
+ return this._nextjs.imageOptimizationLambdaFunctionUrl;
2703
+ }
2704
+ /** Server Lambda function URL */
2705
+ get lambdaFunctionUrl() {
2706
+ return this._nextjs.lambdaFunctionUrl;
2707
+ }
2708
+ /** Next.js build output */
2709
+ get nextBuild() {
2710
+ return this._nextjs.nextBuild;
2711
+ }
2712
+ /** ISR revalidation configuration */
2713
+ get revalidation() {
2714
+ return this._nextjs.revalidation;
2715
+ }
2716
+ /** Next.js server function */
2717
+ get serverFunction() {
2718
+ return this._nextjs.serverFunction;
2719
+ }
2720
+ /** Static assets configuration */
2721
+ get staticAssets() {
2722
+ return this._nextjs.staticAssets;
2723
+ }
2724
+ /** CloudFront distribution URL */
2725
+ get url() {
2726
+ return this._nextjs.url;
2656
2727
  }
2657
2728
  }
2658
2729