@jaypie/constructs 1.2.0-rc.0 → 1.2.0-rc.2
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/JaypieLambda.d.ts +20 -5
- package/dist/cjs/JaypieNextJs.d.ts +20 -2
- package/dist/cjs/helpers/__tests__/resolveEnvironment.spec.d.ts +1 -0
- package/dist/cjs/helpers/__tests__/resolveSecrets.spec.d.ts +1 -0
- package/dist/cjs/helpers/index.d.ts +2 -0
- package/dist/cjs/helpers/resolveEnvironment.d.ts +47 -0
- package/dist/cjs/helpers/resolveSecrets.d.ts +52 -0
- package/dist/cjs/index.cjs +315 -147
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/esm/JaypieLambda.d.ts +20 -5
- package/dist/esm/JaypieNextJs.d.ts +20 -2
- package/dist/esm/helpers/__tests__/resolveEnvironment.spec.d.ts +1 -0
- package/dist/esm/helpers/__tests__/resolveSecrets.spec.d.ts +1 -0
- package/dist/esm/helpers/index.d.ts +2 -0
- package/dist/esm/helpers/resolveEnvironment.d.ts +47 -0
- package/dist/esm/helpers/resolveSecrets.d.ts +52 -0
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +313 -149
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -6,7 +6,7 @@ import * as ec2 from "aws-cdk-lib/aws-ec2";
|
|
|
6
6
|
import * as iam from "aws-cdk-lib/aws-iam";
|
|
7
7
|
import * as logs from "aws-cdk-lib/aws-logs";
|
|
8
8
|
import * as secretsmanager from "aws-cdk-lib/aws-secretsmanager";
|
|
9
|
-
import {
|
|
9
|
+
import { EnvironmentInput, SecretsArrayItem } from "./helpers/index.js";
|
|
10
10
|
export interface JaypieLambdaProps {
|
|
11
11
|
allowAllOutbound?: boolean;
|
|
12
12
|
allowPublicSubnet?: boolean;
|
|
@@ -17,9 +17,16 @@ export interface JaypieLambdaProps {
|
|
|
17
17
|
deadLetterQueueEnabled?: boolean;
|
|
18
18
|
deadLetterTopic?: import("aws-cdk-lib/aws-sns").ITopic;
|
|
19
19
|
description?: string;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Environment variables for the Lambda function.
|
|
22
|
+
*
|
|
23
|
+
* Supports both legacy object syntax and new array syntax:
|
|
24
|
+
* - Object: { KEY: "value" } - directly sets environment variables
|
|
25
|
+
* - Array: ["KEY1", "KEY2", { KEY3: "value" }]
|
|
26
|
+
* - Strings: lookup value from process.env
|
|
27
|
+
* - Objects: merge key-value pairs directly
|
|
28
|
+
*/
|
|
29
|
+
environment?: EnvironmentInput;
|
|
23
30
|
envSecrets?: {
|
|
24
31
|
[key: string]: secretsmanager.ISecret;
|
|
25
32
|
};
|
|
@@ -47,7 +54,15 @@ export interface JaypieLambdaProps {
|
|
|
47
54
|
roleTag?: string;
|
|
48
55
|
runtime?: lambda.Runtime;
|
|
49
56
|
runtimeManagementMode?: lambda.RuntimeManagementMode;
|
|
50
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Secrets to make available to the Lambda function.
|
|
59
|
+
*
|
|
60
|
+
* Supports both JaypieEnvSecret instances and strings:
|
|
61
|
+
* - JaypieEnvSecret: used directly
|
|
62
|
+
* - String: creates a JaypieEnvSecret with the string as envKey
|
|
63
|
+
* (reuses existing secrets within the same scope)
|
|
64
|
+
*/
|
|
65
|
+
secrets?: SecretsArrayItem[];
|
|
51
66
|
securityGroups?: ec2.ISecurityGroup[];
|
|
52
67
|
timeout?: Duration | number;
|
|
53
68
|
tracing?: lambda.Tracing;
|
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
import { IHostedZone } from "aws-cdk-lib/aws-route53";
|
|
2
2
|
import * as secretsmanager from "aws-cdk-lib/aws-secretsmanager";
|
|
3
3
|
import { Construct } from "constructs";
|
|
4
|
-
import {
|
|
4
|
+
import { EnvironmentInput, SecretsArrayItem } from "./helpers";
|
|
5
5
|
export interface JaypieNextjsProps {
|
|
6
6
|
datadogApiKeyArn?: string;
|
|
7
7
|
domainName?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Environment variables for the Next.js application.
|
|
10
|
+
*
|
|
11
|
+
* Supports both legacy object syntax and new array syntax:
|
|
12
|
+
* - Object: { KEY: "value" } - directly sets environment variables
|
|
13
|
+
* - Array: ["KEY1", "KEY2", { KEY3: "value" }]
|
|
14
|
+
* - Strings: lookup value from process.env
|
|
15
|
+
* - Objects: merge key-value pairs directly
|
|
16
|
+
*/
|
|
17
|
+
environment?: EnvironmentInput;
|
|
8
18
|
envSecrets?: {
|
|
9
19
|
[key: string]: secretsmanager.ISecret;
|
|
10
20
|
};
|
|
11
21
|
hostedZone?: IHostedZone | string;
|
|
12
22
|
nextjsPath?: string;
|
|
13
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Secrets to make available to the Next.js application.
|
|
25
|
+
*
|
|
26
|
+
* Supports both JaypieEnvSecret instances and strings:
|
|
27
|
+
* - JaypieEnvSecret: used directly
|
|
28
|
+
* - String: creates a JaypieEnvSecret with the string as envKey
|
|
29
|
+
* (reuses existing secrets within the same scope)
|
|
30
|
+
*/
|
|
31
|
+
secrets?: SecretsArrayItem[];
|
|
14
32
|
}
|
|
15
33
|
export declare class JaypieNextJs extends Construct {
|
|
16
34
|
readonly domainName: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -12,5 +12,7 @@ export { mergeDomain } from "./mergeDomain";
|
|
|
12
12
|
export { resolveDatadogForwarderFunction } from "./resolveDatadogForwarderFunction";
|
|
13
13
|
export { resolveDatadogLayers } from "./resolveDatadogLayers";
|
|
14
14
|
export { resolveDatadogLoggingDestination } from "./resolveDatadogLoggingDestination";
|
|
15
|
+
export { resolveEnvironment, EnvironmentArrayItem, EnvironmentInput, } from "./resolveEnvironment";
|
|
15
16
|
export { resolveHostedZone } from "./resolveHostedZone";
|
|
16
17
|
export { resolveParamsAndSecrets } from "./resolveParamsAndSecrets";
|
|
18
|
+
export { resolveSecrets, SecretsArrayItem, clearSecretsCache, clearAllSecretsCaches, } from "./resolveSecrets";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment value type for the new array syntax
|
|
3
|
+
* - string: key to lookup in process.env
|
|
4
|
+
* - object: key-value pairs to include directly
|
|
5
|
+
*/
|
|
6
|
+
export type EnvironmentArrayItem = string | {
|
|
7
|
+
[key: string]: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Environment type that supports both legacy object syntax and new array syntax
|
|
11
|
+
*/
|
|
12
|
+
export type EnvironmentInput = {
|
|
13
|
+
[key: string]: string;
|
|
14
|
+
} | EnvironmentArrayItem[];
|
|
15
|
+
/**
|
|
16
|
+
* Resolves environment input to a plain object.
|
|
17
|
+
*
|
|
18
|
+
* When environment is an object (legacy syntax), returns it as-is.
|
|
19
|
+
* When environment is an array:
|
|
20
|
+
* - Strings are treated as keys to lookup in process.env
|
|
21
|
+
* - Objects have their key-value pairs merged in
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Legacy object syntax
|
|
25
|
+
* resolveEnvironment({ FOO: "bar" })
|
|
26
|
+
* // => { FOO: "bar" }
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Array syntax with process.env lookup
|
|
30
|
+
* // Given process.env.MY_VAR = "hello"
|
|
31
|
+
* resolveEnvironment(["MY_VAR"])
|
|
32
|
+
* // => { MY_VAR: "hello" }
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // Array syntax with objects
|
|
36
|
+
* resolveEnvironment([{ FOO: "bar", BAZ: "qux" }])
|
|
37
|
+
* // => { FOO: "bar", BAZ: "qux" }
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // Mixed array syntax
|
|
41
|
+
* // Given process.env.MY_VAR = "hello"
|
|
42
|
+
* resolveEnvironment(["MY_VAR", { FOO: "bar" }])
|
|
43
|
+
* // => { MY_VAR: "hello", FOO: "bar" }
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveEnvironment(environment?: EnvironmentInput, env?: Record<string, string | undefined>): {
|
|
46
|
+
[key: string]: string;
|
|
47
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Construct } from "constructs";
|
|
2
|
+
import { JaypieEnvSecret } from "../JaypieEnvSecret.js";
|
|
3
|
+
/**
|
|
4
|
+
* Secrets input type that supports both JaypieEnvSecret instances and strings
|
|
5
|
+
* - JaypieEnvSecret: passed through as-is
|
|
6
|
+
* - string: converted to JaypieEnvSecret with the string as envKey
|
|
7
|
+
*/
|
|
8
|
+
export type SecretsArrayItem = JaypieEnvSecret | string;
|
|
9
|
+
/**
|
|
10
|
+
* Resolves secrets input to an array of JaypieEnvSecret instances.
|
|
11
|
+
*
|
|
12
|
+
* When an item is already a JaypieEnvSecret, it's passed through as-is.
|
|
13
|
+
* When an item is a string, a JaypieEnvSecret is created (or reused from cache)
|
|
14
|
+
* with the string as the envKey.
|
|
15
|
+
*
|
|
16
|
+
* Secrets are cached per scope to avoid creating duplicate secrets when
|
|
17
|
+
* multiple constructs in the same scope reference the same secret.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // JaypieEnvSecret instances pass through
|
|
21
|
+
* const secret = new JaypieEnvSecret(scope, "MySecret", { envKey: "MY_KEY" });
|
|
22
|
+
* resolveSecrets(scope, [secret])
|
|
23
|
+
* // => [secret]
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Strings create JaypieEnvSecret instances
|
|
27
|
+
* resolveSecrets(scope, ["AUTH0_SECRET", "MONGODB_URI"])
|
|
28
|
+
* // => [JaypieEnvSecret(envKey: "AUTH0_SECRET"), JaypieEnvSecret(envKey: "MONGODB_URI")]
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Mixed input
|
|
32
|
+
* const existingSecret = new JaypieEnvSecret(scope, "Existing", { envKey: "EXISTING" });
|
|
33
|
+
* resolveSecrets(scope, [existingSecret, "NEW_SECRET"])
|
|
34
|
+
* // => [existingSecret, JaypieEnvSecret(envKey: "NEW_SECRET")]
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // Secrets are shared across calls with the same scope
|
|
38
|
+
* const secrets1 = resolveSecrets(scope, ["SHARED_SECRET"]);
|
|
39
|
+
* const secrets2 = resolveSecrets(scope, ["SHARED_SECRET"]);
|
|
40
|
+
* // secrets1[0] === secrets2[0] (same instance)
|
|
41
|
+
*/
|
|
42
|
+
export declare function resolveSecrets(scope: Construct, secrets?: SecretsArrayItem[]): JaypieEnvSecret[];
|
|
43
|
+
/**
|
|
44
|
+
* Clears the secrets cache for a given scope.
|
|
45
|
+
* Primarily useful for testing.
|
|
46
|
+
*/
|
|
47
|
+
export declare function clearSecretsCache(scope: Construct): void;
|
|
48
|
+
/**
|
|
49
|
+
* Clears all secrets caches.
|
|
50
|
+
* Primarily useful for testing.
|
|
51
|
+
*/
|
|
52
|
+
export declare function clearAllSecretsCaches(): void;
|