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