@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.
- package/dist/cjs/JaypieNextJs.d.ts +7 -1
- package/dist/cjs/index.cjs +45 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/JaypieNextJs.d.ts +7 -1
- package/dist/esm/index.js +45 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -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/cjs/index.cjs
CHANGED
|
@@ -393,10 +393,11 @@ function envHostname({ component, domain, env, subdomain, } = {}) {
|
|
|
393
393
|
const resolvedComponent = component === "@" || component === "" ? undefined : component;
|
|
394
394
|
const resolvedSubdomain = subdomain || process.env.CDK_ENV_SUBDOMAIN;
|
|
395
395
|
const resolvedEnv = env || process.env.PROJECT_ENV;
|
|
396
|
+
const filteredEnv = resolvedEnv === CDK$2.ENV.PRODUCTION ? undefined : resolvedEnv;
|
|
396
397
|
const parts = [
|
|
397
398
|
resolvedComponent,
|
|
398
399
|
resolvedSubdomain,
|
|
399
|
-
|
|
400
|
+
filteredEnv,
|
|
400
401
|
resolvedDomain,
|
|
401
402
|
].filter((part) => part);
|
|
402
403
|
return parts.join(".");
|
|
@@ -2199,10 +2200,30 @@ class JaypieNextJs extends constructs.Construct {
|
|
|
2199
2200
|
constructor(scope, id, props) {
|
|
2200
2201
|
super(scope, id);
|
|
2201
2202
|
const domainName = props?.domainName || constructs$1.envHostname();
|
|
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
|
+
}, {});
|
|
2206
2227
|
const nextjs = new cdkNextjsStandalone.Nextjs(this, "NextJsApp", {
|
|
2207
2228
|
nextjsPath,
|
|
2208
2229
|
domainProps: {
|
|
@@ -2211,14 +2232,26 @@ class JaypieNextJs extends constructs.Construct {
|
|
|
2211
2232
|
zone: props?.hostedZone,
|
|
2212
2233
|
}),
|
|
2213
2234
|
},
|
|
2214
|
-
environment:
|
|
2235
|
+
environment: {
|
|
2236
|
+
...constructs$1.jaypieLambdaEnv(),
|
|
2237
|
+
...secretsEnvironment,
|
|
2238
|
+
...jaypieSecretsEnvironment,
|
|
2239
|
+
},
|
|
2215
2240
|
overrides: {
|
|
2216
|
-
|
|
2241
|
+
nextjsDistribution: {
|
|
2242
|
+
imageCachePolicyProps: {
|
|
2243
|
+
cachePolicyName: `NextJsImageCachePolicy-${domainNameSanitized}`,
|
|
2244
|
+
},
|
|
2245
|
+
serverCachePolicyProps: {
|
|
2246
|
+
cachePolicyName: `NextJsServerCachePolicy-${domainNameSanitized}`,
|
|
2247
|
+
},
|
|
2248
|
+
},
|
|
2249
|
+
nextjsImage: {
|
|
2217
2250
|
functionProps: {
|
|
2218
2251
|
paramsAndSecrets,
|
|
2219
2252
|
},
|
|
2220
2253
|
},
|
|
2221
|
-
|
|
2254
|
+
nextjsServer: {
|
|
2222
2255
|
functionProps: {
|
|
2223
2256
|
paramsAndSecrets,
|
|
2224
2257
|
},
|
|
@@ -2227,6 +2260,14 @@ class JaypieNextJs extends constructs.Construct {
|
|
|
2227
2260
|
});
|
|
2228
2261
|
addDatadogLayers(nextjs.imageOptimizationFunction);
|
|
2229
2262
|
addDatadogLayers(nextjs.serverFunction.lambdaFunction);
|
|
2263
|
+
// Grant secret read permissions
|
|
2264
|
+
Object.values(envSecrets).forEach((secret) => {
|
|
2265
|
+
secret.grantRead(nextjs.serverFunction.lambdaFunction);
|
|
2266
|
+
});
|
|
2267
|
+
// Grant read permissions for JaypieEnvSecrets
|
|
2268
|
+
secrets.forEach((secret) => {
|
|
2269
|
+
secret.grantRead(nextjs.serverFunction.lambdaFunction);
|
|
2270
|
+
});
|
|
2230
2271
|
}
|
|
2231
2272
|
}
|
|
2232
2273
|
|