@jaypie/constructs 1.1.58 → 1.1.60
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.
- package/dist/cjs/JaypieNextJs.d.ts +8 -1
- package/dist/cjs/index.cjs +60 -7
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/JaypieNextJs.d.ts +8 -1
- package/dist/esm/index.js +60 -7
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,11 +1,18 @@
|
|
|
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 {
|
|
16
|
+
readonly domainName: string;
|
|
10
17
|
constructor(scope: Construct, id: string, props?: JaypieNextjsProps);
|
|
11
18
|
}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -19,7 +19,6 @@ var lambdaEventSources = require('aws-cdk-lib/aws-lambda-event-sources');
|
|
|
19
19
|
var awsEvents = require('aws-cdk-lib/aws-events');
|
|
20
20
|
var awsEventsTargets = require('aws-cdk-lib/aws-events-targets');
|
|
21
21
|
var awsLogs = require('aws-cdk-lib/aws-logs');
|
|
22
|
-
var constructs$1 = require('@jaypie/constructs');
|
|
23
22
|
var cdkNextjsStandalone = require('cdk-nextjs-standalone');
|
|
24
23
|
var path = require('path');
|
|
25
24
|
var awsCloudtrail = require('aws-cdk-lib/aws-cloudtrail');
|
|
@@ -393,10 +392,11 @@ function envHostname({ component, domain, env, subdomain, } = {}) {
|
|
|
393
392
|
const resolvedComponent = component === "@" || component === "" ? undefined : component;
|
|
394
393
|
const resolvedSubdomain = subdomain || process.env.CDK_ENV_SUBDOMAIN;
|
|
395
394
|
const resolvedEnv = env || process.env.PROJECT_ENV;
|
|
395
|
+
const filteredEnv = resolvedEnv === CDK$2.ENV.PRODUCTION ? undefined : resolvedEnv;
|
|
396
396
|
const parts = [
|
|
397
397
|
resolvedComponent,
|
|
398
398
|
resolvedSubdomain,
|
|
399
|
-
|
|
399
|
+
filteredEnv,
|
|
400
400
|
resolvedDomain,
|
|
401
401
|
].filter((part) => part);
|
|
402
402
|
return parts.join(".");
|
|
@@ -2198,27 +2198,72 @@ class JaypieMongoDbSecret extends JaypieEnvSecret {
|
|
|
2198
2198
|
class JaypieNextJs extends constructs.Construct {
|
|
2199
2199
|
constructor(scope, id, props) {
|
|
2200
2200
|
super(scope, id);
|
|
2201
|
-
const domainName = props?.domainName ||
|
|
2201
|
+
const domainName = props?.domainName || envHostname();
|
|
2202
|
+
this.domainName = domainName;
|
|
2203
|
+
const domainNameSanitized = domainName
|
|
2204
|
+
.replace(/\./g, "-")
|
|
2205
|
+
.replace(/[^a-zA-Z0-9]/g, "_");
|
|
2206
|
+
const envSecrets = props?.envSecrets || {};
|
|
2202
2207
|
const nextjsPath = props?.nextjsPath?.startsWith("..")
|
|
2203
2208
|
? path__namespace.join(process.cwd(), props.nextjsPath)
|
|
2204
2209
|
: props?.nextjsPath || path__namespace.join(process.cwd(), "..", "nextjs");
|
|
2205
2210
|
const paramsAndSecrets = resolveParamsAndSecrets();
|
|
2211
|
+
const secrets = props?.secrets || [];
|
|
2212
|
+
// Process secrets environment variables
|
|
2213
|
+
const secretsEnvironment = Object.entries(envSecrets).reduce((acc, [key, secret]) => ({
|
|
2214
|
+
...acc,
|
|
2215
|
+
[`SECRET_${key}`]: secret.secretName,
|
|
2216
|
+
}), {});
|
|
2217
|
+
// Process JaypieEnvSecret array
|
|
2218
|
+
const jaypieSecretsEnvironment = secrets.reduce((acc, secret) => {
|
|
2219
|
+
if (secret.envKey) {
|
|
2220
|
+
return {
|
|
2221
|
+
...acc,
|
|
2222
|
+
[`SECRET_${secret.envKey}`]: secret.secretName,
|
|
2223
|
+
};
|
|
2224
|
+
}
|
|
2225
|
+
return acc;
|
|
2226
|
+
}, {});
|
|
2227
|
+
// Process NEXT_PUBLIC_ environment variables
|
|
2228
|
+
const nextPublicEnv = Object.entries(process.env).reduce((acc, [key, value]) => {
|
|
2229
|
+
if (key.startsWith("NEXT_PUBLIC_") && value) {
|
|
2230
|
+
return {
|
|
2231
|
+
...acc,
|
|
2232
|
+
[key]: value,
|
|
2233
|
+
};
|
|
2234
|
+
}
|
|
2235
|
+
return acc;
|
|
2236
|
+
}, {});
|
|
2206
2237
|
const nextjs = new cdkNextjsStandalone.Nextjs(this, "NextJsApp", {
|
|
2207
2238
|
nextjsPath,
|
|
2208
2239
|
domainProps: {
|
|
2209
2240
|
domainName,
|
|
2210
|
-
hostedZone:
|
|
2241
|
+
hostedZone: resolveHostedZone(this, {
|
|
2211
2242
|
zone: props?.hostedZone,
|
|
2212
2243
|
}),
|
|
2213
2244
|
},
|
|
2214
|
-
environment:
|
|
2245
|
+
environment: {
|
|
2246
|
+
...jaypieLambdaEnv(),
|
|
2247
|
+
...secretsEnvironment,
|
|
2248
|
+
...jaypieSecretsEnvironment,
|
|
2249
|
+
...nextPublicEnv,
|
|
2250
|
+
NEXT_PUBLIC_SITE_URL: `https://${domainName}`,
|
|
2251
|
+
},
|
|
2215
2252
|
overrides: {
|
|
2216
|
-
|
|
2253
|
+
nextjsDistribution: {
|
|
2254
|
+
imageCachePolicyProps: {
|
|
2255
|
+
cachePolicyName: `NextJsImageCachePolicy-${domainNameSanitized}`,
|
|
2256
|
+
},
|
|
2257
|
+
serverCachePolicyProps: {
|
|
2258
|
+
cachePolicyName: `NextJsServerCachePolicy-${domainNameSanitized}`,
|
|
2259
|
+
},
|
|
2260
|
+
},
|
|
2261
|
+
nextjsImage: {
|
|
2217
2262
|
functionProps: {
|
|
2218
2263
|
paramsAndSecrets,
|
|
2219
2264
|
},
|
|
2220
2265
|
},
|
|
2221
|
-
|
|
2266
|
+
nextjsServer: {
|
|
2222
2267
|
functionProps: {
|
|
2223
2268
|
paramsAndSecrets,
|
|
2224
2269
|
},
|
|
@@ -2227,6 +2272,14 @@ class JaypieNextJs extends constructs.Construct {
|
|
|
2227
2272
|
});
|
|
2228
2273
|
addDatadogLayers(nextjs.imageOptimizationFunction);
|
|
2229
2274
|
addDatadogLayers(nextjs.serverFunction.lambdaFunction);
|
|
2275
|
+
// Grant secret read permissions
|
|
2276
|
+
Object.values(envSecrets).forEach((secret) => {
|
|
2277
|
+
secret.grantRead(nextjs.serverFunction.lambdaFunction);
|
|
2278
|
+
});
|
|
2279
|
+
// Grant read permissions for JaypieEnvSecrets
|
|
2280
|
+
secrets.forEach((secret) => {
|
|
2281
|
+
secret.grantRead(nextjs.serverFunction.lambdaFunction);
|
|
2282
|
+
});
|
|
2230
2283
|
}
|
|
2231
2284
|
}
|
|
2232
2285
|
|