@jaypie/constructs 1.1.64 → 1.1.66
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 +3 -1
- 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 +3 -1
- 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 +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -688,6 +688,66 @@ function resolveDatadogLoggingDestination(scope, options) {
|
|
|
688
688
|
return datadogLoggingDestination;
|
|
689
689
|
}
|
|
690
690
|
|
|
691
|
+
/**
|
|
692
|
+
* Resolves environment input to a plain object.
|
|
693
|
+
*
|
|
694
|
+
* When environment is an object (legacy syntax), returns it as-is.
|
|
695
|
+
* When environment is an array:
|
|
696
|
+
* - Strings are treated as keys to lookup in process.env
|
|
697
|
+
* - Objects have their key-value pairs merged in
|
|
698
|
+
*
|
|
699
|
+
* @example
|
|
700
|
+
* // Legacy object syntax
|
|
701
|
+
* resolveEnvironment({ FOO: "bar" })
|
|
702
|
+
* // => { FOO: "bar" }
|
|
703
|
+
*
|
|
704
|
+
* @example
|
|
705
|
+
* // Array syntax with process.env lookup
|
|
706
|
+
* // Given process.env.MY_VAR = "hello"
|
|
707
|
+
* resolveEnvironment(["MY_VAR"])
|
|
708
|
+
* // => { MY_VAR: "hello" }
|
|
709
|
+
*
|
|
710
|
+
* @example
|
|
711
|
+
* // Array syntax with objects
|
|
712
|
+
* resolveEnvironment([{ FOO: "bar", BAZ: "qux" }])
|
|
713
|
+
* // => { FOO: "bar", BAZ: "qux" }
|
|
714
|
+
*
|
|
715
|
+
* @example
|
|
716
|
+
* // Mixed array syntax
|
|
717
|
+
* // Given process.env.MY_VAR = "hello"
|
|
718
|
+
* resolveEnvironment(["MY_VAR", { FOO: "bar" }])
|
|
719
|
+
* // => { MY_VAR: "hello", FOO: "bar" }
|
|
720
|
+
*/
|
|
721
|
+
function resolveEnvironment(environment, env = process.env) {
|
|
722
|
+
if (!environment) {
|
|
723
|
+
return {};
|
|
724
|
+
}
|
|
725
|
+
// Legacy object syntax - return as-is
|
|
726
|
+
if (!Array.isArray(environment)) {
|
|
727
|
+
return environment;
|
|
728
|
+
}
|
|
729
|
+
// Array syntax - process each item
|
|
730
|
+
return environment.reduce((acc, item) => {
|
|
731
|
+
if (typeof item === "string") {
|
|
732
|
+
// String: lookup in process.env
|
|
733
|
+
const value = env[item];
|
|
734
|
+
if (value !== undefined) {
|
|
735
|
+
return {
|
|
736
|
+
...acc,
|
|
737
|
+
[item]: value,
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
// Skip if not found in process.env
|
|
741
|
+
return acc;
|
|
742
|
+
}
|
|
743
|
+
// Object: merge key-value pairs
|
|
744
|
+
return {
|
|
745
|
+
...acc,
|
|
746
|
+
...item,
|
|
747
|
+
};
|
|
748
|
+
}, {});
|
|
749
|
+
}
|
|
750
|
+
|
|
691
751
|
function resolveHostedZone(scope, { name = "HostedZone", zone = process.env.CDK_ENV_HOSTED_ZONE, } = {}) {
|
|
692
752
|
if (!zone) {
|
|
693
753
|
throw new errors.ConfigurationError("No `zone` provided. Set CDK_ENV_HOSTED_ZONE to use environment zone");
|
|
@@ -720,6 +780,246 @@ const resolveParamsAndSecrets = ({ paramsAndSecrets, options, } = {}) => {
|
|
|
720
780
|
return resolvedParamsAndSecrets;
|
|
721
781
|
};
|
|
722
782
|
|
|
783
|
+
// It is a consumer if the environment is ephemeral
|
|
784
|
+
function checkEnvIsConsumer(env = process.env) {
|
|
785
|
+
return (env.PROJECT_ENV === CDK$2.ENV.PERSONAL ||
|
|
786
|
+
!!env.CDK_ENV_PERSONAL ||
|
|
787
|
+
/** @deprecated */ env.PROJECT_ENV === "ephemeral" ||
|
|
788
|
+
/** @deprecated */ !!env.CDK_ENV_EPHEMERAL);
|
|
789
|
+
}
|
|
790
|
+
function checkEnvIsProvider(env = process.env) {
|
|
791
|
+
return env.PROJECT_ENV === CDK$2.ENV.SANDBOX;
|
|
792
|
+
}
|
|
793
|
+
function cleanName(name) {
|
|
794
|
+
return name.replace(/[^a-zA-Z0-9:-]/g, "");
|
|
795
|
+
}
|
|
796
|
+
function exportEnvName(name, env = process.env) {
|
|
797
|
+
let rawName;
|
|
798
|
+
if (checkEnvIsProvider(env)) {
|
|
799
|
+
rawName = `env-${env.PROJECT_ENV}-${env.PROJECT_KEY}-${name}`;
|
|
800
|
+
// Clean the entire name to only allow alphanumeric, colons, and hyphens
|
|
801
|
+
return cleanName(rawName);
|
|
802
|
+
}
|
|
803
|
+
else {
|
|
804
|
+
if (checkEnvIsConsumer(env)) {
|
|
805
|
+
rawName = `env-${CDK$2.ENV.SANDBOX}-${env.PROJECT_KEY}-${name}`;
|
|
806
|
+
}
|
|
807
|
+
else {
|
|
808
|
+
rawName = `env-${env.PROJECT_ENV}-${env.PROJECT_KEY}-${name}`;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
return cleanName(rawName);
|
|
812
|
+
}
|
|
813
|
+
class JaypieEnvSecret extends constructs.Construct {
|
|
814
|
+
constructor(scope, idOrEnvKey, props) {
|
|
815
|
+
// Check if idOrEnvKey should be treated as envKey:
|
|
816
|
+
// - No props provided OR props.envKey is not set
|
|
817
|
+
// - AND idOrEnvKey exists as a non-empty string in process.env
|
|
818
|
+
const treatAsEnvKey = (!props || props.envKey === undefined) &&
|
|
819
|
+
typeof process.env[idOrEnvKey] === "string" &&
|
|
820
|
+
process.env[idOrEnvKey] !== "";
|
|
821
|
+
const id = treatAsEnvKey ? `EnvSecret_${idOrEnvKey}` : idOrEnvKey;
|
|
822
|
+
super(scope, id);
|
|
823
|
+
const { consumer = checkEnvIsConsumer(), envKey: envKeyProp, export: exportParam, generateSecretString, provider = checkEnvIsProvider(), roleTag, vendorTag, value, } = props || {};
|
|
824
|
+
const envKey = treatAsEnvKey ? idOrEnvKey : envKeyProp;
|
|
825
|
+
this._envKey = envKey;
|
|
826
|
+
let exportName;
|
|
827
|
+
if (!exportParam) {
|
|
828
|
+
exportName = exportEnvName(id);
|
|
829
|
+
}
|
|
830
|
+
else {
|
|
831
|
+
exportName = cleanName(exportParam);
|
|
832
|
+
}
|
|
833
|
+
if (consumer) {
|
|
834
|
+
const secretName = cdk.Fn.importValue(exportName);
|
|
835
|
+
this._secret = secretsmanager__namespace.Secret.fromSecretNameV2(this, id, secretName);
|
|
836
|
+
// Add CfnOutput for consumer secrets
|
|
837
|
+
new cdk.CfnOutput(this, `ConsumedName`, {
|
|
838
|
+
value: this._secret.secretName,
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
else {
|
|
842
|
+
const secretValue = envKey && process.env[envKey] ? process.env[envKey] : value;
|
|
843
|
+
const secretProps = {
|
|
844
|
+
generateSecretString,
|
|
845
|
+
secretStringValue: !generateSecretString && secretValue
|
|
846
|
+
? cdk.SecretValue.unsafePlainText(secretValue)
|
|
847
|
+
: undefined,
|
|
848
|
+
};
|
|
849
|
+
this._secret = new secretsmanager__namespace.Secret(this, id, secretProps);
|
|
850
|
+
if (roleTag) {
|
|
851
|
+
cdk.Tags.of(this._secret).add(CDK$2.TAG.ROLE, roleTag);
|
|
852
|
+
}
|
|
853
|
+
if (vendorTag) {
|
|
854
|
+
cdk.Tags.of(this._secret).add(CDK$2.TAG.VENDOR, vendorTag);
|
|
855
|
+
}
|
|
856
|
+
if (provider) {
|
|
857
|
+
new cdk.CfnOutput(this, `ProvidedName`, {
|
|
858
|
+
value: this._secret.secretName,
|
|
859
|
+
exportName,
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
else {
|
|
863
|
+
new cdk.CfnOutput(this, `CreatedName`, {
|
|
864
|
+
value: this._secret.secretName,
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
// IResource implementation
|
|
870
|
+
get stack() {
|
|
871
|
+
return cdk.Stack.of(this);
|
|
872
|
+
}
|
|
873
|
+
get env() {
|
|
874
|
+
return {
|
|
875
|
+
account: cdk.Stack.of(this).account,
|
|
876
|
+
region: cdk.Stack.of(this).region,
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
applyRemovalPolicy(policy) {
|
|
880
|
+
this._secret.applyRemovalPolicy(policy);
|
|
881
|
+
}
|
|
882
|
+
// ISecret implementation
|
|
883
|
+
get secretArn() {
|
|
884
|
+
return this._secret.secretArn;
|
|
885
|
+
}
|
|
886
|
+
get secretName() {
|
|
887
|
+
return this._secret.secretName;
|
|
888
|
+
}
|
|
889
|
+
get secretFullArn() {
|
|
890
|
+
return this._secret.secretFullArn;
|
|
891
|
+
}
|
|
892
|
+
get encryptionKey() {
|
|
893
|
+
return this._secret.encryptionKey;
|
|
894
|
+
}
|
|
895
|
+
get secretValue() {
|
|
896
|
+
return this._secret.secretValue;
|
|
897
|
+
}
|
|
898
|
+
secretValueFromJson(key) {
|
|
899
|
+
return this._secret.secretValueFromJson(key);
|
|
900
|
+
}
|
|
901
|
+
grantRead(grantee, versionStages) {
|
|
902
|
+
return this._secret.grantRead(grantee, versionStages);
|
|
903
|
+
}
|
|
904
|
+
grantWrite(grantee) {
|
|
905
|
+
return this._secret.grantWrite(grantee);
|
|
906
|
+
}
|
|
907
|
+
addRotationSchedule(id, options) {
|
|
908
|
+
return this._secret.addRotationSchedule(id, options);
|
|
909
|
+
}
|
|
910
|
+
addToResourcePolicy(statement) {
|
|
911
|
+
return this._secret.addToResourcePolicy(statement);
|
|
912
|
+
}
|
|
913
|
+
denyAccountRootDelete() {
|
|
914
|
+
this._secret.denyAccountRootDelete();
|
|
915
|
+
}
|
|
916
|
+
attach(target) {
|
|
917
|
+
return this._secret.attach(target);
|
|
918
|
+
}
|
|
919
|
+
cfnDynamicReferenceKey(options) {
|
|
920
|
+
return this._secret.cfnDynamicReferenceKey(options);
|
|
921
|
+
}
|
|
922
|
+
get envKey() {
|
|
923
|
+
return this._envKey;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* Cache for secrets by scope to avoid creating duplicates.
|
|
929
|
+
* Uses WeakMap to allow garbage collection when scopes are no longer referenced.
|
|
930
|
+
*/
|
|
931
|
+
const secretsByScope = new WeakMap();
|
|
932
|
+
/**
|
|
933
|
+
* Gets or creates the secrets cache for a given scope.
|
|
934
|
+
*/
|
|
935
|
+
function getSecretsCache(scope) {
|
|
936
|
+
let cache = secretsByScope.get(scope);
|
|
937
|
+
if (!cache) {
|
|
938
|
+
cache = new Map();
|
|
939
|
+
secretsByScope.set(scope, cache);
|
|
940
|
+
}
|
|
941
|
+
return cache;
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Gets an existing secret from the cache or creates a new one.
|
|
945
|
+
* This ensures that multiple constructs within the same scope share secrets.
|
|
946
|
+
*/
|
|
947
|
+
function getOrCreateSecret(scope, envKey, props) {
|
|
948
|
+
const cache = getSecretsCache(scope);
|
|
949
|
+
const existingSecret = cache.get(envKey);
|
|
950
|
+
if (existingSecret) {
|
|
951
|
+
return existingSecret;
|
|
952
|
+
}
|
|
953
|
+
// Create new secret - JaypieEnvSecret's smart constructor handles envKey detection
|
|
954
|
+
const secret = new JaypieEnvSecret(scope, envKey, {
|
|
955
|
+
...props,
|
|
956
|
+
envKey,
|
|
957
|
+
});
|
|
958
|
+
cache.set(envKey, secret);
|
|
959
|
+
return secret;
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Resolves secrets input to an array of JaypieEnvSecret instances.
|
|
963
|
+
*
|
|
964
|
+
* When an item is already a JaypieEnvSecret, it's passed through as-is.
|
|
965
|
+
* When an item is a string, a JaypieEnvSecret is created (or reused from cache)
|
|
966
|
+
* with the string as the envKey.
|
|
967
|
+
*
|
|
968
|
+
* Secrets are cached per scope to avoid creating duplicate secrets when
|
|
969
|
+
* multiple constructs in the same scope reference the same secret.
|
|
970
|
+
*
|
|
971
|
+
* @example
|
|
972
|
+
* // JaypieEnvSecret instances pass through
|
|
973
|
+
* const secret = new JaypieEnvSecret(scope, "MySecret", { envKey: "MY_KEY" });
|
|
974
|
+
* resolveSecrets(scope, [secret])
|
|
975
|
+
* // => [secret]
|
|
976
|
+
*
|
|
977
|
+
* @example
|
|
978
|
+
* // Strings create JaypieEnvSecret instances
|
|
979
|
+
* resolveSecrets(scope, ["AUTH0_SECRET", "MONGODB_URI"])
|
|
980
|
+
* // => [JaypieEnvSecret(envKey: "AUTH0_SECRET"), JaypieEnvSecret(envKey: "MONGODB_URI")]
|
|
981
|
+
*
|
|
982
|
+
* @example
|
|
983
|
+
* // Mixed input
|
|
984
|
+
* const existingSecret = new JaypieEnvSecret(scope, "Existing", { envKey: "EXISTING" });
|
|
985
|
+
* resolveSecrets(scope, [existingSecret, "NEW_SECRET"])
|
|
986
|
+
* // => [existingSecret, JaypieEnvSecret(envKey: "NEW_SECRET")]
|
|
987
|
+
*
|
|
988
|
+
* @example
|
|
989
|
+
* // Secrets are shared across calls with the same scope
|
|
990
|
+
* const secrets1 = resolveSecrets(scope, ["SHARED_SECRET"]);
|
|
991
|
+
* const secrets2 = resolveSecrets(scope, ["SHARED_SECRET"]);
|
|
992
|
+
* // secrets1[0] === secrets2[0] (same instance)
|
|
993
|
+
*/
|
|
994
|
+
function resolveSecrets(scope, secrets) {
|
|
995
|
+
if (!secrets || secrets.length === 0) {
|
|
996
|
+
return [];
|
|
997
|
+
}
|
|
998
|
+
return secrets.map((item) => {
|
|
999
|
+
if (typeof item === "string") {
|
|
1000
|
+
return getOrCreateSecret(scope, item);
|
|
1001
|
+
}
|
|
1002
|
+
// Already a JaypieEnvSecret instance
|
|
1003
|
+
return item;
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Clears the secrets cache for a given scope.
|
|
1008
|
+
* Primarily useful for testing.
|
|
1009
|
+
*/
|
|
1010
|
+
function clearSecretsCache(scope) {
|
|
1011
|
+
secretsByScope.delete(scope);
|
|
1012
|
+
}
|
|
1013
|
+
/**
|
|
1014
|
+
* Clears all secrets caches.
|
|
1015
|
+
* Primarily useful for testing.
|
|
1016
|
+
*/
|
|
1017
|
+
function clearAllSecretsCaches() {
|
|
1018
|
+
// WeakMap doesn't have a clear() method, so we create a new one
|
|
1019
|
+
// This relies on the module being reloaded or the function being called
|
|
1020
|
+
// between test runs. For testing, use clearSecretsCache(scope) instead.
|
|
1021
|
+
}
|
|
1022
|
+
|
|
723
1023
|
class JaypieApiGateway extends constructs.Construct {
|
|
724
1024
|
constructor(scope, id, props) {
|
|
725
1025
|
super(scope, id);
|
|
@@ -901,11 +1201,15 @@ class JaypieAppStack extends JaypieStack {
|
|
|
901
1201
|
class JaypieLambda extends constructs.Construct {
|
|
902
1202
|
constructor(scope, id, props) {
|
|
903
1203
|
super(scope, id);
|
|
904
|
-
const { allowAllOutbound, allowPublicSubnet, architecture = lambda__namespace.Architecture.X86_64, code, datadogApiKeyArn, deadLetterQueue, deadLetterQueueEnabled, deadLetterTopic, description, environment:
|
|
1204
|
+
const { allowAllOutbound, allowPublicSubnet, architecture = lambda__namespace.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__namespace.Runtime("nodejs24.x", lambda__namespace.RuntimeFamily.NODEJS, {
|
|
905
1205
|
supportsInlineCode: true,
|
|
906
|
-
}), runtimeManagementMode, secrets = [], securityGroups, timeout = cdk.Duration.seconds(CDK$2.DURATION.LAMBDA_WORKER), tracing, vendorTag, vpc, vpcSubnets, } = props;
|
|
1206
|
+
}), runtimeManagementMode, secrets: secretsInput = [], securityGroups, timeout = cdk.Duration.seconds(CDK$2.DURATION.LAMBDA_WORKER), tracing, vendorTag, vpc, vpcSubnets, } = props;
|
|
1207
|
+
// Resolve environment from array or object syntax
|
|
1208
|
+
const initialEnvironment = resolveEnvironment(environmentInput);
|
|
907
1209
|
// Get base environment with defaults
|
|
908
1210
|
const environment = jaypieLambdaEnv({ initialEnvironment });
|
|
1211
|
+
// Resolve secrets from mixed array (strings and JaypieEnvSecret instances)
|
|
1212
|
+
const secrets = resolveSecrets(scope, secretsInput);
|
|
909
1213
|
const codeAsset = typeof code === "string" ? lambda__namespace.Code.fromAsset(code) : code;
|
|
910
1214
|
// Create a working copy of layers
|
|
911
1215
|
const resolvedLayers = [...layers];
|
|
@@ -1886,150 +2190,6 @@ class JaypieDistribution extends constructs.Construct {
|
|
|
1886
2190
|
}
|
|
1887
2191
|
}
|
|
1888
2192
|
|
|
1889
|
-
// It is a consumer if the environment is ephemeral
|
|
1890
|
-
function checkEnvIsConsumer(env = process.env) {
|
|
1891
|
-
return (env.PROJECT_ENV === CDK$2.ENV.PERSONAL ||
|
|
1892
|
-
!!env.CDK_ENV_PERSONAL ||
|
|
1893
|
-
/** @deprecated */ env.PROJECT_ENV === "ephemeral" ||
|
|
1894
|
-
/** @deprecated */ !!env.CDK_ENV_EPHEMERAL);
|
|
1895
|
-
}
|
|
1896
|
-
function checkEnvIsProvider(env = process.env) {
|
|
1897
|
-
return env.PROJECT_ENV === CDK$2.ENV.SANDBOX;
|
|
1898
|
-
}
|
|
1899
|
-
function cleanName(name) {
|
|
1900
|
-
return name.replace(/[^a-zA-Z0-9:-]/g, "");
|
|
1901
|
-
}
|
|
1902
|
-
function exportEnvName(name, env = process.env) {
|
|
1903
|
-
let rawName;
|
|
1904
|
-
if (checkEnvIsProvider(env)) {
|
|
1905
|
-
rawName = `env-${env.PROJECT_ENV}-${env.PROJECT_KEY}-${name}`;
|
|
1906
|
-
// Clean the entire name to only allow alphanumeric, colons, and hyphens
|
|
1907
|
-
return cleanName(rawName);
|
|
1908
|
-
}
|
|
1909
|
-
else {
|
|
1910
|
-
if (checkEnvIsConsumer(env)) {
|
|
1911
|
-
rawName = `env-${CDK$2.ENV.SANDBOX}-${env.PROJECT_KEY}-${name}`;
|
|
1912
|
-
}
|
|
1913
|
-
else {
|
|
1914
|
-
rawName = `env-${env.PROJECT_ENV}-${env.PROJECT_KEY}-${name}`;
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
return cleanName(rawName);
|
|
1918
|
-
}
|
|
1919
|
-
class JaypieEnvSecret extends constructs.Construct {
|
|
1920
|
-
constructor(scope, idOrEnvKey, props) {
|
|
1921
|
-
// Check if idOrEnvKey should be treated as envKey:
|
|
1922
|
-
// - No props provided OR props.envKey is not set
|
|
1923
|
-
// - AND idOrEnvKey exists as a non-empty string in process.env
|
|
1924
|
-
const treatAsEnvKey = (!props || props.envKey === undefined) &&
|
|
1925
|
-
typeof process.env[idOrEnvKey] === "string" &&
|
|
1926
|
-
process.env[idOrEnvKey] !== "";
|
|
1927
|
-
const id = treatAsEnvKey ? `EnvSecret_${idOrEnvKey}` : idOrEnvKey;
|
|
1928
|
-
super(scope, id);
|
|
1929
|
-
const { consumer = checkEnvIsConsumer(), envKey: envKeyProp, export: exportParam, generateSecretString, provider = checkEnvIsProvider(), roleTag, vendorTag, value, } = props || {};
|
|
1930
|
-
const envKey = treatAsEnvKey ? idOrEnvKey : envKeyProp;
|
|
1931
|
-
this._envKey = envKey;
|
|
1932
|
-
let exportName;
|
|
1933
|
-
if (!exportParam) {
|
|
1934
|
-
exportName = exportEnvName(id);
|
|
1935
|
-
}
|
|
1936
|
-
else {
|
|
1937
|
-
exportName = cleanName(exportParam);
|
|
1938
|
-
}
|
|
1939
|
-
if (consumer) {
|
|
1940
|
-
const secretName = cdk.Fn.importValue(exportName);
|
|
1941
|
-
this._secret = secretsmanager__namespace.Secret.fromSecretNameV2(this, id, secretName);
|
|
1942
|
-
// Add CfnOutput for consumer secrets
|
|
1943
|
-
new cdk.CfnOutput(this, `ConsumedName`, {
|
|
1944
|
-
value: this._secret.secretName,
|
|
1945
|
-
});
|
|
1946
|
-
}
|
|
1947
|
-
else {
|
|
1948
|
-
const secretValue = envKey && process.env[envKey] ? process.env[envKey] : value;
|
|
1949
|
-
const secretProps = {
|
|
1950
|
-
generateSecretString,
|
|
1951
|
-
secretStringValue: !generateSecretString && secretValue
|
|
1952
|
-
? cdk.SecretValue.unsafePlainText(secretValue)
|
|
1953
|
-
: undefined,
|
|
1954
|
-
};
|
|
1955
|
-
this._secret = new secretsmanager__namespace.Secret(this, id, secretProps);
|
|
1956
|
-
if (roleTag) {
|
|
1957
|
-
cdk.Tags.of(this._secret).add(CDK$2.TAG.ROLE, roleTag);
|
|
1958
|
-
}
|
|
1959
|
-
if (vendorTag) {
|
|
1960
|
-
cdk.Tags.of(this._secret).add(CDK$2.TAG.VENDOR, vendorTag);
|
|
1961
|
-
}
|
|
1962
|
-
if (provider) {
|
|
1963
|
-
new cdk.CfnOutput(this, `ProvidedName`, {
|
|
1964
|
-
value: this._secret.secretName,
|
|
1965
|
-
exportName,
|
|
1966
|
-
});
|
|
1967
|
-
}
|
|
1968
|
-
else {
|
|
1969
|
-
new cdk.CfnOutput(this, `CreatedName`, {
|
|
1970
|
-
value: this._secret.secretName,
|
|
1971
|
-
});
|
|
1972
|
-
}
|
|
1973
|
-
}
|
|
1974
|
-
}
|
|
1975
|
-
// IResource implementation
|
|
1976
|
-
get stack() {
|
|
1977
|
-
return cdk.Stack.of(this);
|
|
1978
|
-
}
|
|
1979
|
-
get env() {
|
|
1980
|
-
return {
|
|
1981
|
-
account: cdk.Stack.of(this).account,
|
|
1982
|
-
region: cdk.Stack.of(this).region,
|
|
1983
|
-
};
|
|
1984
|
-
}
|
|
1985
|
-
applyRemovalPolicy(policy) {
|
|
1986
|
-
this._secret.applyRemovalPolicy(policy);
|
|
1987
|
-
}
|
|
1988
|
-
// ISecret implementation
|
|
1989
|
-
get secretArn() {
|
|
1990
|
-
return this._secret.secretArn;
|
|
1991
|
-
}
|
|
1992
|
-
get secretName() {
|
|
1993
|
-
return this._secret.secretName;
|
|
1994
|
-
}
|
|
1995
|
-
get secretFullArn() {
|
|
1996
|
-
return this._secret.secretFullArn;
|
|
1997
|
-
}
|
|
1998
|
-
get encryptionKey() {
|
|
1999
|
-
return this._secret.encryptionKey;
|
|
2000
|
-
}
|
|
2001
|
-
get secretValue() {
|
|
2002
|
-
return this._secret.secretValue;
|
|
2003
|
-
}
|
|
2004
|
-
secretValueFromJson(key) {
|
|
2005
|
-
return this._secret.secretValueFromJson(key);
|
|
2006
|
-
}
|
|
2007
|
-
grantRead(grantee, versionStages) {
|
|
2008
|
-
return this._secret.grantRead(grantee, versionStages);
|
|
2009
|
-
}
|
|
2010
|
-
grantWrite(grantee) {
|
|
2011
|
-
return this._secret.grantWrite(grantee);
|
|
2012
|
-
}
|
|
2013
|
-
addRotationSchedule(id, options) {
|
|
2014
|
-
return this._secret.addRotationSchedule(id, options);
|
|
2015
|
-
}
|
|
2016
|
-
addToResourcePolicy(statement) {
|
|
2017
|
-
return this._secret.addToResourcePolicy(statement);
|
|
2018
|
-
}
|
|
2019
|
-
denyAccountRootDelete() {
|
|
2020
|
-
this._secret.denyAccountRootDelete();
|
|
2021
|
-
}
|
|
2022
|
-
attach(target) {
|
|
2023
|
-
return this._secret.attach(target);
|
|
2024
|
-
}
|
|
2025
|
-
cfnDynamicReferenceKey(options) {
|
|
2026
|
-
return this._secret.cfnDynamicReferenceKey(options);
|
|
2027
|
-
}
|
|
2028
|
-
get envKey() {
|
|
2029
|
-
return this._envKey;
|
|
2030
|
-
}
|
|
2031
|
-
}
|
|
2032
|
-
|
|
2033
2193
|
class JaypieDatadogSecret extends JaypieEnvSecret {
|
|
2034
2194
|
constructor(scope, id = "MongoConnectionString", props) {
|
|
2035
2195
|
const defaultProps = {
|
|
@@ -2441,12 +2601,15 @@ class JaypieNextJs extends constructs.Construct {
|
|
|
2441
2601
|
const domainNameSanitized = domainName
|
|
2442
2602
|
.replace(/\./g, "-")
|
|
2443
2603
|
.replace(/[^a-zA-Z0-9]/g, "_");
|
|
2604
|
+
// Resolve environment from array or object syntax
|
|
2605
|
+
const environment = resolveEnvironment(props?.environment);
|
|
2444
2606
|
const envSecrets = props?.envSecrets || {};
|
|
2445
2607
|
const nextjsPath = props?.nextjsPath?.startsWith("..")
|
|
2446
2608
|
? path__namespace.join(process.cwd(), props.nextjsPath)
|
|
2447
2609
|
: props?.nextjsPath || path__namespace.join(process.cwd(), "..", "nextjs");
|
|
2448
2610
|
const paramsAndSecrets = resolveParamsAndSecrets();
|
|
2449
|
-
|
|
2611
|
+
// Resolve secrets from mixed array (strings and JaypieEnvSecret instances)
|
|
2612
|
+
const secrets = resolveSecrets(scope, props?.secrets);
|
|
2450
2613
|
// Process secrets environment variables
|
|
2451
2614
|
const secretsEnvironment = Object.entries(envSecrets).reduce((acc, [key, secret]) => ({
|
|
2452
2615
|
...acc,
|
|
@@ -2482,6 +2645,7 @@ class JaypieNextJs extends constructs.Construct {
|
|
|
2482
2645
|
},
|
|
2483
2646
|
environment: {
|
|
2484
2647
|
...jaypieLambdaEnv(),
|
|
2648
|
+
...environment,
|
|
2485
2649
|
...secretsEnvironment,
|
|
2486
2650
|
...jaypieSecretsEnvironment,
|
|
2487
2651
|
...nextPublicEnv,
|
|
@@ -3315,6 +3479,8 @@ exports.JaypieStaticWebBucket = JaypieStaticWebBucket;
|
|
|
3315
3479
|
exports.JaypieTraceSigningKeySecret = JaypieTraceSigningKeySecret;
|
|
3316
3480
|
exports.JaypieWebDeploymentBucket = JaypieWebDeploymentBucket;
|
|
3317
3481
|
exports.addDatadogLayers = addDatadogLayers;
|
|
3482
|
+
exports.clearAllSecretsCaches = clearAllSecretsCaches;
|
|
3483
|
+
exports.clearSecretsCache = clearSecretsCache;
|
|
3318
3484
|
exports.constructEnvName = constructEnvName;
|
|
3319
3485
|
exports.constructStackName = constructStackName;
|
|
3320
3486
|
exports.constructTagger = constructTagger;
|
|
@@ -3330,6 +3496,8 @@ exports.mergeDomain = mergeDomain;
|
|
|
3330
3496
|
exports.resolveDatadogForwarderFunction = resolveDatadogForwarderFunction;
|
|
3331
3497
|
exports.resolveDatadogLayers = resolveDatadogLayers;
|
|
3332
3498
|
exports.resolveDatadogLoggingDestination = resolveDatadogLoggingDestination;
|
|
3499
|
+
exports.resolveEnvironment = resolveEnvironment;
|
|
3333
3500
|
exports.resolveHostedZone = resolveHostedZone;
|
|
3334
3501
|
exports.resolveParamsAndSecrets = resolveParamsAndSecrets;
|
|
3502
|
+
exports.resolveSecrets = resolveSecrets;
|
|
3335
3503
|
//# sourceMappingURL=index.cjs.map
|