@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/esm/index.js
CHANGED
|
@@ -21,7 +21,6 @@ import * as lambdaEventSources from 'aws-cdk-lib/aws-lambda-event-sources';
|
|
|
21
21
|
import { Rule, RuleTargetInput } from 'aws-cdk-lib/aws-events';
|
|
22
22
|
import { LambdaFunction } from 'aws-cdk-lib/aws-events-targets';
|
|
23
23
|
import { LogGroup, RetentionDays, FilterPattern } from 'aws-cdk-lib/aws-logs';
|
|
24
|
-
import { envHostname as envHostname$1, jaypieLambdaEnv as jaypieLambdaEnv$1, resolveHostedZone as resolveHostedZone$1 } from '@jaypie/constructs';
|
|
25
24
|
import { Nextjs } from 'cdk-nextjs-standalone';
|
|
26
25
|
import * as path from 'path';
|
|
27
26
|
import { Trail, ReadWriteType } from 'aws-cdk-lib/aws-cloudtrail';
|
|
@@ -362,10 +361,11 @@ function envHostname({ component, domain, env, subdomain, } = {}) {
|
|
|
362
361
|
const resolvedComponent = component === "@" || component === "" ? undefined : component;
|
|
363
362
|
const resolvedSubdomain = subdomain || process.env.CDK_ENV_SUBDOMAIN;
|
|
364
363
|
const resolvedEnv = env || process.env.PROJECT_ENV;
|
|
364
|
+
const filteredEnv = resolvedEnv === CDK$2.ENV.PRODUCTION ? undefined : resolvedEnv;
|
|
365
365
|
const parts = [
|
|
366
366
|
resolvedComponent,
|
|
367
367
|
resolvedSubdomain,
|
|
368
|
-
|
|
368
|
+
filteredEnv,
|
|
369
369
|
resolvedDomain,
|
|
370
370
|
].filter((part) => part);
|
|
371
371
|
return parts.join(".");
|
|
@@ -2167,27 +2167,72 @@ class JaypieMongoDbSecret extends JaypieEnvSecret {
|
|
|
2167
2167
|
class JaypieNextJs extends Construct {
|
|
2168
2168
|
constructor(scope, id, props) {
|
|
2169
2169
|
super(scope, id);
|
|
2170
|
-
const domainName = props?.domainName || envHostname
|
|
2170
|
+
const domainName = props?.domainName || envHostname();
|
|
2171
|
+
this.domainName = domainName;
|
|
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
|
+
}, {});
|
|
2196
|
+
// Process NEXT_PUBLIC_ environment variables
|
|
2197
|
+
const nextPublicEnv = Object.entries(process.env).reduce((acc, [key, value]) => {
|
|
2198
|
+
if (key.startsWith("NEXT_PUBLIC_") && value) {
|
|
2199
|
+
return {
|
|
2200
|
+
...acc,
|
|
2201
|
+
[key]: value,
|
|
2202
|
+
};
|
|
2203
|
+
}
|
|
2204
|
+
return acc;
|
|
2205
|
+
}, {});
|
|
2175
2206
|
const nextjs = new Nextjs(this, "NextJsApp", {
|
|
2176
2207
|
nextjsPath,
|
|
2177
2208
|
domainProps: {
|
|
2178
2209
|
domainName,
|
|
2179
|
-
hostedZone: resolveHostedZone
|
|
2210
|
+
hostedZone: resolveHostedZone(this, {
|
|
2180
2211
|
zone: props?.hostedZone,
|
|
2181
2212
|
}),
|
|
2182
2213
|
},
|
|
2183
|
-
environment:
|
|
2214
|
+
environment: {
|
|
2215
|
+
...jaypieLambdaEnv(),
|
|
2216
|
+
...secretsEnvironment,
|
|
2217
|
+
...jaypieSecretsEnvironment,
|
|
2218
|
+
...nextPublicEnv,
|
|
2219
|
+
NEXT_PUBLIC_SITE_URL: `https://${domainName}`,
|
|
2220
|
+
},
|
|
2184
2221
|
overrides: {
|
|
2185
|
-
|
|
2222
|
+
nextjsDistribution: {
|
|
2223
|
+
imageCachePolicyProps: {
|
|
2224
|
+
cachePolicyName: `NextJsImageCachePolicy-${domainNameSanitized}`,
|
|
2225
|
+
},
|
|
2226
|
+
serverCachePolicyProps: {
|
|
2227
|
+
cachePolicyName: `NextJsServerCachePolicy-${domainNameSanitized}`,
|
|
2228
|
+
},
|
|
2229
|
+
},
|
|
2230
|
+
nextjsImage: {
|
|
2186
2231
|
functionProps: {
|
|
2187
2232
|
paramsAndSecrets,
|
|
2188
2233
|
},
|
|
2189
2234
|
},
|
|
2190
|
-
|
|
2235
|
+
nextjsServer: {
|
|
2191
2236
|
functionProps: {
|
|
2192
2237
|
paramsAndSecrets,
|
|
2193
2238
|
},
|
|
@@ -2196,6 +2241,14 @@ class JaypieNextJs extends Construct {
|
|
|
2196
2241
|
});
|
|
2197
2242
|
addDatadogLayers(nextjs.imageOptimizationFunction);
|
|
2198
2243
|
addDatadogLayers(nextjs.serverFunction.lambdaFunction);
|
|
2244
|
+
// Grant secret read permissions
|
|
2245
|
+
Object.values(envSecrets).forEach((secret) => {
|
|
2246
|
+
secret.grantRead(nextjs.serverFunction.lambdaFunction);
|
|
2247
|
+
});
|
|
2248
|
+
// Grant read permissions for JaypieEnvSecrets
|
|
2249
|
+
secrets.forEach((secret) => {
|
|
2250
|
+
secret.grantRead(nextjs.serverFunction.lambdaFunction);
|
|
2251
|
+
});
|
|
2199
2252
|
}
|
|
2200
2253
|
}
|
|
2201
2254
|
|