@jaypie/constructs 1.1.58 → 1.1.59

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,10 +1,16 @@
1
1
  import { IHostedZone } from "aws-cdk-lib/aws-route53";
2
+ import * as secretsmanager from "aws-cdk-lib/aws-secretsmanager";
2
3
  import { Construct } from "constructs";
4
+ import { JaypieEnvSecret } from "./JaypieEnvSecret.js";
3
5
  export interface JaypieNextjsProps {
4
- domainName?: string;
5
6
  datadogApiKeyArn?: string;
7
+ domainName?: string;
8
+ envSecrets?: {
9
+ [key: string]: secretsmanager.ISecret;
10
+ };
6
11
  hostedZone?: IHostedZone | string;
7
12
  nextjsPath?: string;
13
+ secrets?: JaypieEnvSecret[];
8
14
  }
9
15
  export declare class JaypieNextJs extends Construct {
10
16
  constructor(scope: Construct, id: string, props?: JaypieNextjsProps);
package/dist/esm/index.js CHANGED
@@ -362,10 +362,11 @@ function envHostname({ component, domain, env, subdomain, } = {}) {
362
362
  const resolvedComponent = component === "@" || component === "" ? undefined : component;
363
363
  const resolvedSubdomain = subdomain || process.env.CDK_ENV_SUBDOMAIN;
364
364
  const resolvedEnv = env || process.env.PROJECT_ENV;
365
+ const filteredEnv = resolvedEnv === CDK$2.ENV.PRODUCTION ? undefined : resolvedEnv;
365
366
  const parts = [
366
367
  resolvedComponent,
367
368
  resolvedSubdomain,
368
- resolvedEnv,
369
+ filteredEnv,
369
370
  resolvedDomain,
370
371
  ].filter((part) => part);
371
372
  return parts.join(".");
@@ -2168,10 +2169,30 @@ class JaypieNextJs extends Construct {
2168
2169
  constructor(scope, id, props) {
2169
2170
  super(scope, id);
2170
2171
  const domainName = props?.domainName || envHostname$1();
2172
+ const domainNameSanitized = domainName
2173
+ .replace(/\./g, "-")
2174
+ .replace(/[^a-zA-Z0-9]/g, "_");
2175
+ const envSecrets = props?.envSecrets || {};
2171
2176
  const nextjsPath = props?.nextjsPath?.startsWith("..")
2172
2177
  ? path.join(process.cwd(), props.nextjsPath)
2173
2178
  : props?.nextjsPath || path.join(process.cwd(), "..", "nextjs");
2174
2179
  const paramsAndSecrets = resolveParamsAndSecrets();
2180
+ const secrets = props?.secrets || [];
2181
+ // Process secrets environment variables
2182
+ const secretsEnvironment = Object.entries(envSecrets).reduce((acc, [key, secret]) => ({
2183
+ ...acc,
2184
+ [`SECRET_${key}`]: secret.secretName,
2185
+ }), {});
2186
+ // Process JaypieEnvSecret array
2187
+ const jaypieSecretsEnvironment = secrets.reduce((acc, secret) => {
2188
+ if (secret.envKey) {
2189
+ return {
2190
+ ...acc,
2191
+ [`SECRET_${secret.envKey}`]: secret.secretName,
2192
+ };
2193
+ }
2194
+ return acc;
2195
+ }, {});
2175
2196
  const nextjs = new Nextjs(this, "NextJsApp", {
2176
2197
  nextjsPath,
2177
2198
  domainProps: {
@@ -2180,14 +2201,26 @@ class JaypieNextJs extends Construct {
2180
2201
  zone: props?.hostedZone,
2181
2202
  }),
2182
2203
  },
2183
- environment: jaypieLambdaEnv$1(),
2204
+ environment: {
2205
+ ...jaypieLambdaEnv$1(),
2206
+ ...secretsEnvironment,
2207
+ ...jaypieSecretsEnvironment,
2208
+ },
2184
2209
  overrides: {
2185
- nextjsServer: {
2210
+ nextjsDistribution: {
2211
+ imageCachePolicyProps: {
2212
+ cachePolicyName: `NextJsImageCachePolicy-${domainNameSanitized}`,
2213
+ },
2214
+ serverCachePolicyProps: {
2215
+ cachePolicyName: `NextJsServerCachePolicy-${domainNameSanitized}`,
2216
+ },
2217
+ },
2218
+ nextjsImage: {
2186
2219
  functionProps: {
2187
2220
  paramsAndSecrets,
2188
2221
  },
2189
2222
  },
2190
- nextjsImage: {
2223
+ nextjsServer: {
2191
2224
  functionProps: {
2192
2225
  paramsAndSecrets,
2193
2226
  },
@@ -2196,6 +2229,14 @@ class JaypieNextJs extends Construct {
2196
2229
  });
2197
2230
  addDatadogLayers(nextjs.imageOptimizationFunction);
2198
2231
  addDatadogLayers(nextjs.serverFunction.lambdaFunction);
2232
+ // Grant secret read permissions
2233
+ Object.values(envSecrets).forEach((secret) => {
2234
+ secret.grantRead(nextjs.serverFunction.lambdaFunction);
2235
+ });
2236
+ // Grant read permissions for JaypieEnvSecrets
2237
+ secrets.forEach((secret) => {
2238
+ secret.grantRead(nextjs.serverFunction.lambdaFunction);
2239
+ });
2199
2240
  }
2200
2241
  }
2201
2242