@jaypie/constructs 1.2.0-rc.1 → 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
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as cdk from 'aws-cdk-lib';
|
|
2
|
-
import { Tags, Stack,
|
|
2
|
+
import { Tags, Stack, Fn, CfnOutput, SecretValue, Duration, RemovalPolicy, CfnStack } from 'aws-cdk-lib';
|
|
3
3
|
import * as s3 from 'aws-cdk-lib/aws-s3';
|
|
4
4
|
import { Bucket, StorageClass, BucketAccessControl, EventType } from 'aws-cdk-lib/aws-s3';
|
|
5
5
|
import { Construct } from 'constructs';
|
|
@@ -656,6 +656,66 @@ function resolveDatadogLoggingDestination(scope, options) {
|
|
|
656
656
|
return datadogLoggingDestination;
|
|
657
657
|
}
|
|
658
658
|
|
|
659
|
+
/**
|
|
660
|
+
* Resolves environment input to a plain object.
|
|
661
|
+
*
|
|
662
|
+
* When environment is an object (legacy syntax), returns it as-is.
|
|
663
|
+
* When environment is an array:
|
|
664
|
+
* - Strings are treated as keys to lookup in process.env
|
|
665
|
+
* - Objects have their key-value pairs merged in
|
|
666
|
+
*
|
|
667
|
+
* @example
|
|
668
|
+
* // Legacy object syntax
|
|
669
|
+
* resolveEnvironment({ FOO: "bar" })
|
|
670
|
+
* // => { FOO: "bar" }
|
|
671
|
+
*
|
|
672
|
+
* @example
|
|
673
|
+
* // Array syntax with process.env lookup
|
|
674
|
+
* // Given process.env.MY_VAR = "hello"
|
|
675
|
+
* resolveEnvironment(["MY_VAR"])
|
|
676
|
+
* // => { MY_VAR: "hello" }
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* // Array syntax with objects
|
|
680
|
+
* resolveEnvironment([{ FOO: "bar", BAZ: "qux" }])
|
|
681
|
+
* // => { FOO: "bar", BAZ: "qux" }
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* // Mixed array syntax
|
|
685
|
+
* // Given process.env.MY_VAR = "hello"
|
|
686
|
+
* resolveEnvironment(["MY_VAR", { FOO: "bar" }])
|
|
687
|
+
* // => { MY_VAR: "hello", FOO: "bar" }
|
|
688
|
+
*/
|
|
689
|
+
function resolveEnvironment(environment, env = process.env) {
|
|
690
|
+
if (!environment) {
|
|
691
|
+
return {};
|
|
692
|
+
}
|
|
693
|
+
// Legacy object syntax - return as-is
|
|
694
|
+
if (!Array.isArray(environment)) {
|
|
695
|
+
return environment;
|
|
696
|
+
}
|
|
697
|
+
// Array syntax - process each item
|
|
698
|
+
return environment.reduce((acc, item) => {
|
|
699
|
+
if (typeof item === "string") {
|
|
700
|
+
// String: lookup in process.env
|
|
701
|
+
const value = env[item];
|
|
702
|
+
if (value !== undefined) {
|
|
703
|
+
return {
|
|
704
|
+
...acc,
|
|
705
|
+
[item]: value,
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
// Skip if not found in process.env
|
|
709
|
+
return acc;
|
|
710
|
+
}
|
|
711
|
+
// Object: merge key-value pairs
|
|
712
|
+
return {
|
|
713
|
+
...acc,
|
|
714
|
+
...item,
|
|
715
|
+
};
|
|
716
|
+
}, {});
|
|
717
|
+
}
|
|
718
|
+
|
|
659
719
|
function resolveHostedZone(scope, { name = "HostedZone", zone = process.env.CDK_ENV_HOSTED_ZONE, } = {}) {
|
|
660
720
|
if (!zone) {
|
|
661
721
|
throw new ConfigurationError("No `zone` provided. Set CDK_ENV_HOSTED_ZONE to use environment zone");
|
|
@@ -688,6 +748,246 @@ const resolveParamsAndSecrets = ({ paramsAndSecrets, options, } = {}) => {
|
|
|
688
748
|
return resolvedParamsAndSecrets;
|
|
689
749
|
};
|
|
690
750
|
|
|
751
|
+
// It is a consumer if the environment is ephemeral
|
|
752
|
+
function checkEnvIsConsumer(env = process.env) {
|
|
753
|
+
return (env.PROJECT_ENV === CDK$2.ENV.PERSONAL ||
|
|
754
|
+
!!env.CDK_ENV_PERSONAL ||
|
|
755
|
+
/** @deprecated */ env.PROJECT_ENV === "ephemeral" ||
|
|
756
|
+
/** @deprecated */ !!env.CDK_ENV_EPHEMERAL);
|
|
757
|
+
}
|
|
758
|
+
function checkEnvIsProvider(env = process.env) {
|
|
759
|
+
return env.PROJECT_ENV === CDK$2.ENV.SANDBOX;
|
|
760
|
+
}
|
|
761
|
+
function cleanName(name) {
|
|
762
|
+
return name.replace(/[^a-zA-Z0-9:-]/g, "");
|
|
763
|
+
}
|
|
764
|
+
function exportEnvName(name, env = process.env) {
|
|
765
|
+
let rawName;
|
|
766
|
+
if (checkEnvIsProvider(env)) {
|
|
767
|
+
rawName = `env-${env.PROJECT_ENV}-${env.PROJECT_KEY}-${name}`;
|
|
768
|
+
// Clean the entire name to only allow alphanumeric, colons, and hyphens
|
|
769
|
+
return cleanName(rawName);
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
if (checkEnvIsConsumer(env)) {
|
|
773
|
+
rawName = `env-${CDK$2.ENV.SANDBOX}-${env.PROJECT_KEY}-${name}`;
|
|
774
|
+
}
|
|
775
|
+
else {
|
|
776
|
+
rawName = `env-${env.PROJECT_ENV}-${env.PROJECT_KEY}-${name}`;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
return cleanName(rawName);
|
|
780
|
+
}
|
|
781
|
+
class JaypieEnvSecret extends Construct {
|
|
782
|
+
constructor(scope, idOrEnvKey, props) {
|
|
783
|
+
// Check if idOrEnvKey should be treated as envKey:
|
|
784
|
+
// - No props provided OR props.envKey is not set
|
|
785
|
+
// - AND idOrEnvKey exists as a non-empty string in process.env
|
|
786
|
+
const treatAsEnvKey = (!props || props.envKey === undefined) &&
|
|
787
|
+
typeof process.env[idOrEnvKey] === "string" &&
|
|
788
|
+
process.env[idOrEnvKey] !== "";
|
|
789
|
+
const id = treatAsEnvKey ? `EnvSecret_${idOrEnvKey}` : idOrEnvKey;
|
|
790
|
+
super(scope, id);
|
|
791
|
+
const { consumer = checkEnvIsConsumer(), envKey: envKeyProp, export: exportParam, generateSecretString, provider = checkEnvIsProvider(), roleTag, vendorTag, value, } = props || {};
|
|
792
|
+
const envKey = treatAsEnvKey ? idOrEnvKey : envKeyProp;
|
|
793
|
+
this._envKey = envKey;
|
|
794
|
+
let exportName;
|
|
795
|
+
if (!exportParam) {
|
|
796
|
+
exportName = exportEnvName(id);
|
|
797
|
+
}
|
|
798
|
+
else {
|
|
799
|
+
exportName = cleanName(exportParam);
|
|
800
|
+
}
|
|
801
|
+
if (consumer) {
|
|
802
|
+
const secretName = Fn.importValue(exportName);
|
|
803
|
+
this._secret = secretsmanager.Secret.fromSecretNameV2(this, id, secretName);
|
|
804
|
+
// Add CfnOutput for consumer secrets
|
|
805
|
+
new CfnOutput(this, `ConsumedName`, {
|
|
806
|
+
value: this._secret.secretName,
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
else {
|
|
810
|
+
const secretValue = envKey && process.env[envKey] ? process.env[envKey] : value;
|
|
811
|
+
const secretProps = {
|
|
812
|
+
generateSecretString,
|
|
813
|
+
secretStringValue: !generateSecretString && secretValue
|
|
814
|
+
? SecretValue.unsafePlainText(secretValue)
|
|
815
|
+
: undefined,
|
|
816
|
+
};
|
|
817
|
+
this._secret = new secretsmanager.Secret(this, id, secretProps);
|
|
818
|
+
if (roleTag) {
|
|
819
|
+
Tags.of(this._secret).add(CDK$2.TAG.ROLE, roleTag);
|
|
820
|
+
}
|
|
821
|
+
if (vendorTag) {
|
|
822
|
+
Tags.of(this._secret).add(CDK$2.TAG.VENDOR, vendorTag);
|
|
823
|
+
}
|
|
824
|
+
if (provider) {
|
|
825
|
+
new CfnOutput(this, `ProvidedName`, {
|
|
826
|
+
value: this._secret.secretName,
|
|
827
|
+
exportName,
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
else {
|
|
831
|
+
new CfnOutput(this, `CreatedName`, {
|
|
832
|
+
value: this._secret.secretName,
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
// IResource implementation
|
|
838
|
+
get stack() {
|
|
839
|
+
return Stack.of(this);
|
|
840
|
+
}
|
|
841
|
+
get env() {
|
|
842
|
+
return {
|
|
843
|
+
account: Stack.of(this).account,
|
|
844
|
+
region: Stack.of(this).region,
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
applyRemovalPolicy(policy) {
|
|
848
|
+
this._secret.applyRemovalPolicy(policy);
|
|
849
|
+
}
|
|
850
|
+
// ISecret implementation
|
|
851
|
+
get secretArn() {
|
|
852
|
+
return this._secret.secretArn;
|
|
853
|
+
}
|
|
854
|
+
get secretName() {
|
|
855
|
+
return this._secret.secretName;
|
|
856
|
+
}
|
|
857
|
+
get secretFullArn() {
|
|
858
|
+
return this._secret.secretFullArn;
|
|
859
|
+
}
|
|
860
|
+
get encryptionKey() {
|
|
861
|
+
return this._secret.encryptionKey;
|
|
862
|
+
}
|
|
863
|
+
get secretValue() {
|
|
864
|
+
return this._secret.secretValue;
|
|
865
|
+
}
|
|
866
|
+
secretValueFromJson(key) {
|
|
867
|
+
return this._secret.secretValueFromJson(key);
|
|
868
|
+
}
|
|
869
|
+
grantRead(grantee, versionStages) {
|
|
870
|
+
return this._secret.grantRead(grantee, versionStages);
|
|
871
|
+
}
|
|
872
|
+
grantWrite(grantee) {
|
|
873
|
+
return this._secret.grantWrite(grantee);
|
|
874
|
+
}
|
|
875
|
+
addRotationSchedule(id, options) {
|
|
876
|
+
return this._secret.addRotationSchedule(id, options);
|
|
877
|
+
}
|
|
878
|
+
addToResourcePolicy(statement) {
|
|
879
|
+
return this._secret.addToResourcePolicy(statement);
|
|
880
|
+
}
|
|
881
|
+
denyAccountRootDelete() {
|
|
882
|
+
this._secret.denyAccountRootDelete();
|
|
883
|
+
}
|
|
884
|
+
attach(target) {
|
|
885
|
+
return this._secret.attach(target);
|
|
886
|
+
}
|
|
887
|
+
cfnDynamicReferenceKey(options) {
|
|
888
|
+
return this._secret.cfnDynamicReferenceKey(options);
|
|
889
|
+
}
|
|
890
|
+
get envKey() {
|
|
891
|
+
return this._envKey;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Cache for secrets by scope to avoid creating duplicates.
|
|
897
|
+
* Uses WeakMap to allow garbage collection when scopes are no longer referenced.
|
|
898
|
+
*/
|
|
899
|
+
const secretsByScope = new WeakMap();
|
|
900
|
+
/**
|
|
901
|
+
* Gets or creates the secrets cache for a given scope.
|
|
902
|
+
*/
|
|
903
|
+
function getSecretsCache(scope) {
|
|
904
|
+
let cache = secretsByScope.get(scope);
|
|
905
|
+
if (!cache) {
|
|
906
|
+
cache = new Map();
|
|
907
|
+
secretsByScope.set(scope, cache);
|
|
908
|
+
}
|
|
909
|
+
return cache;
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* Gets an existing secret from the cache or creates a new one.
|
|
913
|
+
* This ensures that multiple constructs within the same scope share secrets.
|
|
914
|
+
*/
|
|
915
|
+
function getOrCreateSecret(scope, envKey, props) {
|
|
916
|
+
const cache = getSecretsCache(scope);
|
|
917
|
+
const existingSecret = cache.get(envKey);
|
|
918
|
+
if (existingSecret) {
|
|
919
|
+
return existingSecret;
|
|
920
|
+
}
|
|
921
|
+
// Create new secret - JaypieEnvSecret's smart constructor handles envKey detection
|
|
922
|
+
const secret = new JaypieEnvSecret(scope, envKey, {
|
|
923
|
+
...props,
|
|
924
|
+
envKey,
|
|
925
|
+
});
|
|
926
|
+
cache.set(envKey, secret);
|
|
927
|
+
return secret;
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* Resolves secrets input to an array of JaypieEnvSecret instances.
|
|
931
|
+
*
|
|
932
|
+
* When an item is already a JaypieEnvSecret, it's passed through as-is.
|
|
933
|
+
* When an item is a string, a JaypieEnvSecret is created (or reused from cache)
|
|
934
|
+
* with the string as the envKey.
|
|
935
|
+
*
|
|
936
|
+
* Secrets are cached per scope to avoid creating duplicate secrets when
|
|
937
|
+
* multiple constructs in the same scope reference the same secret.
|
|
938
|
+
*
|
|
939
|
+
* @example
|
|
940
|
+
* // JaypieEnvSecret instances pass through
|
|
941
|
+
* const secret = new JaypieEnvSecret(scope, "MySecret", { envKey: "MY_KEY" });
|
|
942
|
+
* resolveSecrets(scope, [secret])
|
|
943
|
+
* // => [secret]
|
|
944
|
+
*
|
|
945
|
+
* @example
|
|
946
|
+
* // Strings create JaypieEnvSecret instances
|
|
947
|
+
* resolveSecrets(scope, ["AUTH0_SECRET", "MONGODB_URI"])
|
|
948
|
+
* // => [JaypieEnvSecret(envKey: "AUTH0_SECRET"), JaypieEnvSecret(envKey: "MONGODB_URI")]
|
|
949
|
+
*
|
|
950
|
+
* @example
|
|
951
|
+
* // Mixed input
|
|
952
|
+
* const existingSecret = new JaypieEnvSecret(scope, "Existing", { envKey: "EXISTING" });
|
|
953
|
+
* resolveSecrets(scope, [existingSecret, "NEW_SECRET"])
|
|
954
|
+
* // => [existingSecret, JaypieEnvSecret(envKey: "NEW_SECRET")]
|
|
955
|
+
*
|
|
956
|
+
* @example
|
|
957
|
+
* // Secrets are shared across calls with the same scope
|
|
958
|
+
* const secrets1 = resolveSecrets(scope, ["SHARED_SECRET"]);
|
|
959
|
+
* const secrets2 = resolveSecrets(scope, ["SHARED_SECRET"]);
|
|
960
|
+
* // secrets1[0] === secrets2[0] (same instance)
|
|
961
|
+
*/
|
|
962
|
+
function resolveSecrets(scope, secrets) {
|
|
963
|
+
if (!secrets || secrets.length === 0) {
|
|
964
|
+
return [];
|
|
965
|
+
}
|
|
966
|
+
return secrets.map((item) => {
|
|
967
|
+
if (typeof item === "string") {
|
|
968
|
+
return getOrCreateSecret(scope, item);
|
|
969
|
+
}
|
|
970
|
+
// Already a JaypieEnvSecret instance
|
|
971
|
+
return item;
|
|
972
|
+
});
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Clears the secrets cache for a given scope.
|
|
976
|
+
* Primarily useful for testing.
|
|
977
|
+
*/
|
|
978
|
+
function clearSecretsCache(scope) {
|
|
979
|
+
secretsByScope.delete(scope);
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* Clears all secrets caches.
|
|
983
|
+
* Primarily useful for testing.
|
|
984
|
+
*/
|
|
985
|
+
function clearAllSecretsCaches() {
|
|
986
|
+
// WeakMap doesn't have a clear() method, so we create a new one
|
|
987
|
+
// This relies on the module being reloaded or the function being called
|
|
988
|
+
// between test runs. For testing, use clearSecretsCache(scope) instead.
|
|
989
|
+
}
|
|
990
|
+
|
|
691
991
|
class JaypieApiGateway extends Construct {
|
|
692
992
|
constructor(scope, id, props) {
|
|
693
993
|
super(scope, id);
|
|
@@ -869,11 +1169,15 @@ class JaypieAppStack extends JaypieStack {
|
|
|
869
1169
|
class JaypieLambda extends Construct {
|
|
870
1170
|
constructor(scope, id, props) {
|
|
871
1171
|
super(scope, id);
|
|
872
|
-
const { allowAllOutbound, allowPublicSubnet, architecture = lambda.Architecture.X86_64, code, datadogApiKeyArn, deadLetterQueue, deadLetterQueueEnabled, deadLetterTopic, description, environment:
|
|
1172
|
+
const { allowAllOutbound, allowPublicSubnet, architecture = lambda.Architecture.X86_64, code, datadogApiKeyArn, deadLetterQueue, deadLetterQueueEnabled, deadLetterTopic, description, environment: environmentInput, envSecrets = {}, ephemeralStorageSize, filesystem, handler = "index.handler", initialPolicy, layers = [], logGroup, logRetention = CDK$2.LAMBDA.LOG_RETENTION, maxEventAge, memorySize = CDK$2.LAMBDA.MEMORY_SIZE, paramsAndSecrets, paramsAndSecretsOptions, profiling, profilingGroup, provisionedConcurrentExecutions, reservedConcurrentExecutions, retryAttempts, roleTag = CDK$2.ROLE.PROCESSING, runtime = new lambda.Runtime("nodejs24.x", lambda.RuntimeFamily.NODEJS, {
|
|
873
1173
|
supportsInlineCode: true,
|
|
874
|
-
}), runtimeManagementMode, secrets = [], securityGroups, timeout = Duration.seconds(CDK$2.DURATION.LAMBDA_WORKER), tracing, vendorTag, vpc, vpcSubnets, } = props;
|
|
1174
|
+
}), runtimeManagementMode, secrets: secretsInput = [], securityGroups, timeout = Duration.seconds(CDK$2.DURATION.LAMBDA_WORKER), tracing, vendorTag, vpc, vpcSubnets, } = props;
|
|
1175
|
+
// Resolve environment from array or object syntax
|
|
1176
|
+
const initialEnvironment = resolveEnvironment(environmentInput);
|
|
875
1177
|
// Get base environment with defaults
|
|
876
1178
|
const environment = jaypieLambdaEnv({ initialEnvironment });
|
|
1179
|
+
// Resolve secrets from mixed array (strings and JaypieEnvSecret instances)
|
|
1180
|
+
const secrets = resolveSecrets(scope, secretsInput);
|
|
877
1181
|
const codeAsset = typeof code === "string" ? lambda.Code.fromAsset(code) : code;
|
|
878
1182
|
// Create a working copy of layers
|
|
879
1183
|
const resolvedLayers = [...layers];
|
|
@@ -1854,150 +2158,6 @@ class JaypieDistribution extends Construct {
|
|
|
1854
2158
|
}
|
|
1855
2159
|
}
|
|
1856
2160
|
|
|
1857
|
-
// It is a consumer if the environment is ephemeral
|
|
1858
|
-
function checkEnvIsConsumer(env = process.env) {
|
|
1859
|
-
return (env.PROJECT_ENV === CDK$2.ENV.PERSONAL ||
|
|
1860
|
-
!!env.CDK_ENV_PERSONAL ||
|
|
1861
|
-
/** @deprecated */ env.PROJECT_ENV === "ephemeral" ||
|
|
1862
|
-
/** @deprecated */ !!env.CDK_ENV_EPHEMERAL);
|
|
1863
|
-
}
|
|
1864
|
-
function checkEnvIsProvider(env = process.env) {
|
|
1865
|
-
return env.PROJECT_ENV === CDK$2.ENV.SANDBOX;
|
|
1866
|
-
}
|
|
1867
|
-
function cleanName(name) {
|
|
1868
|
-
return name.replace(/[^a-zA-Z0-9:-]/g, "");
|
|
1869
|
-
}
|
|
1870
|
-
function exportEnvName(name, env = process.env) {
|
|
1871
|
-
let rawName;
|
|
1872
|
-
if (checkEnvIsProvider(env)) {
|
|
1873
|
-
rawName = `env-${env.PROJECT_ENV}-${env.PROJECT_KEY}-${name}`;
|
|
1874
|
-
// Clean the entire name to only allow alphanumeric, colons, and hyphens
|
|
1875
|
-
return cleanName(rawName);
|
|
1876
|
-
}
|
|
1877
|
-
else {
|
|
1878
|
-
if (checkEnvIsConsumer(env)) {
|
|
1879
|
-
rawName = `env-${CDK$2.ENV.SANDBOX}-${env.PROJECT_KEY}-${name}`;
|
|
1880
|
-
}
|
|
1881
|
-
else {
|
|
1882
|
-
rawName = `env-${env.PROJECT_ENV}-${env.PROJECT_KEY}-${name}`;
|
|
1883
|
-
}
|
|
1884
|
-
}
|
|
1885
|
-
return cleanName(rawName);
|
|
1886
|
-
}
|
|
1887
|
-
class JaypieEnvSecret extends Construct {
|
|
1888
|
-
constructor(scope, idOrEnvKey, props) {
|
|
1889
|
-
// Check if idOrEnvKey should be treated as envKey:
|
|
1890
|
-
// - No props provided OR props.envKey is not set
|
|
1891
|
-
// - AND idOrEnvKey exists as a non-empty string in process.env
|
|
1892
|
-
const treatAsEnvKey = (!props || props.envKey === undefined) &&
|
|
1893
|
-
typeof process.env[idOrEnvKey] === "string" &&
|
|
1894
|
-
process.env[idOrEnvKey] !== "";
|
|
1895
|
-
const id = treatAsEnvKey ? `EnvSecret_${idOrEnvKey}` : idOrEnvKey;
|
|
1896
|
-
super(scope, id);
|
|
1897
|
-
const { consumer = checkEnvIsConsumer(), envKey: envKeyProp, export: exportParam, generateSecretString, provider = checkEnvIsProvider(), roleTag, vendorTag, value, } = props || {};
|
|
1898
|
-
const envKey = treatAsEnvKey ? idOrEnvKey : envKeyProp;
|
|
1899
|
-
this._envKey = envKey;
|
|
1900
|
-
let exportName;
|
|
1901
|
-
if (!exportParam) {
|
|
1902
|
-
exportName = exportEnvName(id);
|
|
1903
|
-
}
|
|
1904
|
-
else {
|
|
1905
|
-
exportName = cleanName(exportParam);
|
|
1906
|
-
}
|
|
1907
|
-
if (consumer) {
|
|
1908
|
-
const secretName = Fn.importValue(exportName);
|
|
1909
|
-
this._secret = secretsmanager.Secret.fromSecretNameV2(this, id, secretName);
|
|
1910
|
-
// Add CfnOutput for consumer secrets
|
|
1911
|
-
new CfnOutput(this, `ConsumedName`, {
|
|
1912
|
-
value: this._secret.secretName,
|
|
1913
|
-
});
|
|
1914
|
-
}
|
|
1915
|
-
else {
|
|
1916
|
-
const secretValue = envKey && process.env[envKey] ? process.env[envKey] : value;
|
|
1917
|
-
const secretProps = {
|
|
1918
|
-
generateSecretString,
|
|
1919
|
-
secretStringValue: !generateSecretString && secretValue
|
|
1920
|
-
? SecretValue.unsafePlainText(secretValue)
|
|
1921
|
-
: undefined,
|
|
1922
|
-
};
|
|
1923
|
-
this._secret = new secretsmanager.Secret(this, id, secretProps);
|
|
1924
|
-
if (roleTag) {
|
|
1925
|
-
Tags.of(this._secret).add(CDK$2.TAG.ROLE, roleTag);
|
|
1926
|
-
}
|
|
1927
|
-
if (vendorTag) {
|
|
1928
|
-
Tags.of(this._secret).add(CDK$2.TAG.VENDOR, vendorTag);
|
|
1929
|
-
}
|
|
1930
|
-
if (provider) {
|
|
1931
|
-
new CfnOutput(this, `ProvidedName`, {
|
|
1932
|
-
value: this._secret.secretName,
|
|
1933
|
-
exportName,
|
|
1934
|
-
});
|
|
1935
|
-
}
|
|
1936
|
-
else {
|
|
1937
|
-
new CfnOutput(this, `CreatedName`, {
|
|
1938
|
-
value: this._secret.secretName,
|
|
1939
|
-
});
|
|
1940
|
-
}
|
|
1941
|
-
}
|
|
1942
|
-
}
|
|
1943
|
-
// IResource implementation
|
|
1944
|
-
get stack() {
|
|
1945
|
-
return Stack.of(this);
|
|
1946
|
-
}
|
|
1947
|
-
get env() {
|
|
1948
|
-
return {
|
|
1949
|
-
account: Stack.of(this).account,
|
|
1950
|
-
region: Stack.of(this).region,
|
|
1951
|
-
};
|
|
1952
|
-
}
|
|
1953
|
-
applyRemovalPolicy(policy) {
|
|
1954
|
-
this._secret.applyRemovalPolicy(policy);
|
|
1955
|
-
}
|
|
1956
|
-
// ISecret implementation
|
|
1957
|
-
get secretArn() {
|
|
1958
|
-
return this._secret.secretArn;
|
|
1959
|
-
}
|
|
1960
|
-
get secretName() {
|
|
1961
|
-
return this._secret.secretName;
|
|
1962
|
-
}
|
|
1963
|
-
get secretFullArn() {
|
|
1964
|
-
return this._secret.secretFullArn;
|
|
1965
|
-
}
|
|
1966
|
-
get encryptionKey() {
|
|
1967
|
-
return this._secret.encryptionKey;
|
|
1968
|
-
}
|
|
1969
|
-
get secretValue() {
|
|
1970
|
-
return this._secret.secretValue;
|
|
1971
|
-
}
|
|
1972
|
-
secretValueFromJson(key) {
|
|
1973
|
-
return this._secret.secretValueFromJson(key);
|
|
1974
|
-
}
|
|
1975
|
-
grantRead(grantee, versionStages) {
|
|
1976
|
-
return this._secret.grantRead(grantee, versionStages);
|
|
1977
|
-
}
|
|
1978
|
-
grantWrite(grantee) {
|
|
1979
|
-
return this._secret.grantWrite(grantee);
|
|
1980
|
-
}
|
|
1981
|
-
addRotationSchedule(id, options) {
|
|
1982
|
-
return this._secret.addRotationSchedule(id, options);
|
|
1983
|
-
}
|
|
1984
|
-
addToResourcePolicy(statement) {
|
|
1985
|
-
return this._secret.addToResourcePolicy(statement);
|
|
1986
|
-
}
|
|
1987
|
-
denyAccountRootDelete() {
|
|
1988
|
-
this._secret.denyAccountRootDelete();
|
|
1989
|
-
}
|
|
1990
|
-
attach(target) {
|
|
1991
|
-
return this._secret.attach(target);
|
|
1992
|
-
}
|
|
1993
|
-
cfnDynamicReferenceKey(options) {
|
|
1994
|
-
return this._secret.cfnDynamicReferenceKey(options);
|
|
1995
|
-
}
|
|
1996
|
-
get envKey() {
|
|
1997
|
-
return this._envKey;
|
|
1998
|
-
}
|
|
1999
|
-
}
|
|
2000
|
-
|
|
2001
2161
|
class JaypieDatadogSecret extends JaypieEnvSecret {
|
|
2002
2162
|
constructor(scope, id = "MongoConnectionString", props) {
|
|
2003
2163
|
const defaultProps = {
|
|
@@ -2409,12 +2569,15 @@ class JaypieNextJs extends Construct {
|
|
|
2409
2569
|
const domainNameSanitized = domainName
|
|
2410
2570
|
.replace(/\./g, "-")
|
|
2411
2571
|
.replace(/[^a-zA-Z0-9]/g, "_");
|
|
2572
|
+
// Resolve environment from array or object syntax
|
|
2573
|
+
const environment = resolveEnvironment(props?.environment);
|
|
2412
2574
|
const envSecrets = props?.envSecrets || {};
|
|
2413
2575
|
const nextjsPath = props?.nextjsPath?.startsWith("..")
|
|
2414
2576
|
? path.join(process.cwd(), props.nextjsPath)
|
|
2415
2577
|
: props?.nextjsPath || path.join(process.cwd(), "..", "nextjs");
|
|
2416
2578
|
const paramsAndSecrets = resolveParamsAndSecrets();
|
|
2417
|
-
|
|
2579
|
+
// Resolve secrets from mixed array (strings and JaypieEnvSecret instances)
|
|
2580
|
+
const secrets = resolveSecrets(scope, props?.secrets);
|
|
2418
2581
|
// Process secrets environment variables
|
|
2419
2582
|
const secretsEnvironment = Object.entries(envSecrets).reduce((acc, [key, secret]) => ({
|
|
2420
2583
|
...acc,
|
|
@@ -2450,6 +2613,7 @@ class JaypieNextJs extends Construct {
|
|
|
2450
2613
|
},
|
|
2451
2614
|
environment: {
|
|
2452
2615
|
...jaypieLambdaEnv(),
|
|
2616
|
+
...environment,
|
|
2453
2617
|
...secretsEnvironment,
|
|
2454
2618
|
...jaypieSecretsEnvironment,
|
|
2455
2619
|
...nextPublicEnv,
|
|
@@ -3254,5 +3418,5 @@ class JaypieTraceSigningKeySecret extends JaypieEnvSecret {
|
|
|
3254
3418
|
}
|
|
3255
3419
|
}
|
|
3256
3420
|
|
|
3257
|
-
export { CDK$2 as CDK, JaypieAccountLoggingBucket, JaypieApiGateway, JaypieAppStack, JaypieBucketQueuedLambda, JaypieDatadogBucket, JaypieDatadogForwarder, JaypieDatadogSecret, JaypieDistribution, JaypieDnsRecord, JaypieEnvSecret, JaypieEventsRule, JaypieExpressLambda, JaypieGitHubDeployRole, JaypieHostedZone, JaypieInfrastructureStack, JaypieLambda, JaypieMongoDbSecret, JaypieNextJs, JaypieOpenAiSecret, JaypieOrganizationTrail, JaypieQueuedLambda, JaypieSsoPermissions, JaypieSsoSyncApplication, JaypieStack, JaypieStaticWebBucket, JaypieTraceSigningKeySecret, JaypieWebDeploymentBucket, addDatadogLayers, constructEnvName, constructStackName, constructTagger, envHostname, extendDatadogRole, isEnv, isProductionEnv, isSandboxEnv, isValidHostname$1 as isValidHostname, isValidSubdomain, jaypieLambdaEnv, mergeDomain, resolveDatadogForwarderFunction, resolveDatadogLayers, resolveDatadogLoggingDestination, resolveHostedZone, resolveParamsAndSecrets };
|
|
3421
|
+
export { CDK$2 as CDK, JaypieAccountLoggingBucket, JaypieApiGateway, JaypieAppStack, JaypieBucketQueuedLambda, JaypieDatadogBucket, JaypieDatadogForwarder, JaypieDatadogSecret, JaypieDistribution, JaypieDnsRecord, JaypieEnvSecret, JaypieEventsRule, JaypieExpressLambda, JaypieGitHubDeployRole, JaypieHostedZone, JaypieInfrastructureStack, JaypieLambda, JaypieMongoDbSecret, JaypieNextJs, JaypieOpenAiSecret, JaypieOrganizationTrail, JaypieQueuedLambda, JaypieSsoPermissions, JaypieSsoSyncApplication, JaypieStack, JaypieStaticWebBucket, JaypieTraceSigningKeySecret, JaypieWebDeploymentBucket, addDatadogLayers, clearAllSecretsCaches, clearSecretsCache, constructEnvName, constructStackName, constructTagger, envHostname, extendDatadogRole, isEnv, isProductionEnv, isSandboxEnv, isValidHostname$1 as isValidHostname, isValidSubdomain, jaypieLambdaEnv, mergeDomain, resolveDatadogForwarderFunction, resolveDatadogLayers, resolveDatadogLoggingDestination, resolveEnvironment, resolveHostedZone, resolveParamsAndSecrets, resolveSecrets };
|
|
3258
3422
|
//# sourceMappingURL=index.js.map
|