@jaypie/constructs 1.2.10 → 1.2.12

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.
@@ -5,8 +5,8 @@ import { Construct } from "constructs";
5
5
  export interface JaypieCertificateProps {
6
6
  /**
7
7
  * Import certificate from a provider stack instead of creating one.
8
- * Auto-detected from PROJECT_ENV (personal/ephemeral = consumer).
9
- * @default auto-detected from environment
8
+ * When true, imports the certificate ARN via CloudFormation export.
9
+ * @default false
10
10
  */
11
11
  consumer?: boolean;
12
12
  /**
@@ -16,19 +16,20 @@ export interface JaypieCertificateProps {
16
16
  domainName?: string;
17
17
  /**
18
18
  * Export name override for cross-stack sharing.
19
+ * Only used when provider is true.
19
20
  * @default Generated from environment and domain
20
21
  */
21
22
  export?: string;
22
23
  /**
23
24
  * Construct ID override. When not provided, ID is auto-generated from domain.
24
25
  * Use this to align with certificates created by other constructs.
25
- * @default Auto-generated as "Certificate-{sanitized-domain}"
26
+ * @default Auto-generated as "JaypieCert-{sanitized-domain}"
26
27
  */
27
28
  id?: string;
28
29
  /**
29
30
  * Export certificate ARN for other stacks to import.
30
- * Auto-detected from PROJECT_ENV (sandbox = provider).
31
- * @default auto-detected from environment
31
+ * When true, creates a CloudFormation export that consumer stacks can import.
32
+ * @default false
32
33
  */
33
34
  provider?: boolean;
34
35
  /**
@@ -83,11 +84,11 @@ export interface JaypieCertificateProps {
83
84
  * });
84
85
  *
85
86
  * @example
86
- * // Provider/consumer pattern for cross-stack sharing
87
- * // In sandbox stack:
87
+ * // Optional: Provider/consumer pattern for cross-stack sharing
88
+ * // In sandbox stack (explicitly export):
88
89
  * new JaypieCertificate(this, { provider: true });
89
90
  *
90
- * // In personal build:
91
+ * // In personal build (explicitly import):
91
92
  * new JaypieCertificate(this, { consumer: true });
92
93
  */
93
94
  export declare class JaypieCertificate extends Construct implements acm.ICertificate {
@@ -6,7 +6,7 @@ import * as route53 from "aws-cdk-lib/aws-route53";
6
6
  import * as s3 from "aws-cdk-lib/aws-s3";
7
7
  import { LambdaDestination } from "aws-cdk-lib/aws-s3-notifications";
8
8
  import { Construct } from "constructs";
9
- export interface JaypieDistributionProps extends Omit<cloudfront.DistributionProps, "certificate" | "defaultBehavior"> {
9
+ export interface JaypieDistributionProps extends Omit<cloudfront.DistributionProps, "certificate" | "defaultBehavior" | "logBucket"> {
10
10
  /**
11
11
  * SSL certificate for the CloudFront distribution
12
12
  * @default true (creates a new certificate)
@@ -20,10 +20,21 @@ export interface JaypieDistributionProps extends Omit<cloudfront.DistributionPro
20
20
  * Log destination configuration for CloudFront access logs
21
21
  * - LambdaDestination: Use a specific Lambda destination for S3 notifications
22
22
  * - true: Use Datadog forwarder for S3 notifications (default)
23
- * - false: Disable logging entirely
23
+ * - false: Disable S3 notifications (logging still occurs if logBucket is set)
24
24
  * @default true
25
25
  */
26
26
  destination?: LambdaDestination | boolean;
27
+ /**
28
+ * External log bucket for CloudFront access logs.
29
+ * - IBucket: Use existing bucket directly
30
+ * - string: Bucket name to import
31
+ * - { exportName: string }: CloudFormation export name to import
32
+ * - true: Use account logging bucket (CDK.IMPORT.LOG_BUCKET)
33
+ * @default undefined (creates new bucket if destination !== false)
34
+ */
35
+ logBucket?: s3.IBucket | string | {
36
+ exportName: string;
37
+ } | true;
27
38
  /**
28
39
  * The origin handler - can be an IOrigin, IFunctionUrl, or IFunction
29
40
  * If IFunction, a FunctionUrl will be created with auth NONE
@@ -74,6 +85,8 @@ export declare class JaypieDistribution extends Construct implements cloudfront.
74
85
  private isIFunctionUrl;
75
86
  private isIFunction;
76
87
  private hasInvokeMode;
88
+ private isExportNameObject;
89
+ private resolveLogBucket;
77
90
  get env(): {
78
91
  account: string;
79
92
  region: string;
package/dist/esm/index.js CHANGED
@@ -1999,11 +1999,11 @@ function sanitizeDomain(domain) {
1999
1999
  * });
2000
2000
  *
2001
2001
  * @example
2002
- * // Provider/consumer pattern for cross-stack sharing
2003
- * // In sandbox stack:
2002
+ * // Optional: Provider/consumer pattern for cross-stack sharing
2003
+ * // In sandbox stack (explicitly export):
2004
2004
  * new JaypieCertificate(this, { provider: true });
2005
2005
  *
2006
- * // In personal build:
2006
+ * // In personal build (explicitly import):
2007
2007
  * new JaypieCertificate(this, { consumer: true });
2008
2008
  */
2009
2009
  class JaypieCertificate extends Construct {
@@ -2040,7 +2040,7 @@ class JaypieCertificate extends Construct {
2040
2040
  }
2041
2041
  }
2042
2042
  super(scope, id);
2043
- const { consumer = checkEnvIsConsumer(), domainName: propsDomainName, export: exportParam, provider = checkEnvIsProvider(), roleTag = CDK$2.ROLE.API, zone: propsZone, } = props;
2043
+ const { consumer = false, domainName: propsDomainName, export: exportParam, provider = false, roleTag = CDK$2.ROLE.API, zone: propsZone, } = props;
2044
2044
  // Validate environment variables
2045
2045
  if (process.env.CDK_ENV_API_SUBDOMAIN &&
2046
2046
  !isValidSubdomain(process.env.CDK_ENV_API_SUBDOMAIN)) {
@@ -2325,7 +2325,7 @@ class JaypieDatadogSecret extends JaypieEnvSecret {
2325
2325
  class JaypieDistribution extends Construct {
2326
2326
  constructor(scope, id, props) {
2327
2327
  super(scope, id);
2328
- const { certificate: certificateProp = true, defaultBehavior: propsDefaultBehavior, destination: destinationProp = true, handler, host: propsHost, invokeMode = lambda.InvokeMode.BUFFERED, originReadTimeout = Duration.seconds(CDK$2.DURATION.CLOUDFRONT_API), roleTag = CDK$2.ROLE.API, zone: propsZone, ...distributionProps } = props;
2328
+ const { certificate: certificateProp = true, defaultBehavior: propsDefaultBehavior, destination: destinationProp = true, handler, host: propsHost, invokeMode = lambda.InvokeMode.BUFFERED, logBucket: logBucketProp, originReadTimeout = Duration.seconds(CDK$2.DURATION.CLOUDFRONT_API), roleTag = CDK$2.ROLE.API, zone: propsZone, ...distributionProps } = props;
2329
2329
  // Validate environment variables
2330
2330
  if (process.env.CDK_ENV_API_SUBDOMAIN &&
2331
2331
  !isValidSubdomain(process.env.CDK_ENV_API_SUBDOMAIN)) {
@@ -2427,12 +2427,16 @@ class JaypieDistribution extends Construct {
2427
2427
  });
2428
2428
  this.certificate = certificateToUse;
2429
2429
  }
2430
- // Create log bucket if logging is enabled
2430
+ // Resolve or create log bucket
2431
2431
  let logBucket;
2432
- if (destinationProp !== false) {
2433
- logBucket = new s3.Bucket(this, constructEnvName("LogBucket"), {
2434
- objectOwnership: s3.ObjectOwnership.OBJECT_WRITER,
2435
- removalPolicy: RemovalPolicy.DESTROY,
2432
+ const isExternalBucket = logBucketProp !== undefined;
2433
+ if (logBucketProp !== undefined) {
2434
+ // Use external bucket
2435
+ logBucket = this.resolveLogBucket(logBucketProp);
2436
+ }
2437
+ else if (destinationProp !== false) {
2438
+ // Create new bucket (original behavior)
2439
+ const createdBucket = new s3.Bucket(this, constructEnvName("LogBucket"), {
2436
2440
  autoDeleteObjects: true,
2437
2441
  lifecycleRules: [
2438
2442
  {
@@ -2445,15 +2449,21 @@ class JaypieDistribution extends Construct {
2445
2449
  ],
2446
2450
  },
2447
2451
  ],
2452
+ objectOwnership: s3.ObjectOwnership.OBJECT_WRITER,
2453
+ removalPolicy: RemovalPolicy.DESTROY,
2448
2454
  });
2449
- Tags.of(logBucket).add(CDK$2.TAG.ROLE, CDK$2.ROLE.STORAGE);
2450
- // Add S3 notification to Datadog forwarder
2455
+ Tags.of(createdBucket).add(CDK$2.TAG.ROLE, CDK$2.ROLE.STORAGE);
2456
+ logBucket = createdBucket;
2457
+ }
2458
+ // Add S3 notifications if we have a bucket and destination is not false
2459
+ if (logBucket && destinationProp !== false && !isExternalBucket) {
2460
+ // Only add notifications to buckets we created (not external buckets)
2451
2461
  const lambdaDestination = destinationProp === true
2452
2462
  ? new LambdaDestination(resolveDatadogForwarderFunction(this))
2453
2463
  : destinationProp;
2454
2464
  logBucket.addEventNotification(s3.EventType.OBJECT_CREATED, lambdaDestination);
2455
- this.logBucket = logBucket;
2456
2465
  }
2466
+ this.logBucket = logBucket;
2457
2467
  // Create the CloudFront distribution
2458
2468
  this.distribution = new cloudfront.Distribution(this, constructEnvName("Distribution"), {
2459
2469
  defaultBehavior,
@@ -2524,6 +2534,30 @@ class JaypieDistribution extends Construct {
2524
2534
  "invokeMode" in handler &&
2525
2535
  typeof handler.invokeMode === "string");
2526
2536
  }
2537
+ isExportNameObject(value) {
2538
+ return (typeof value === "object" &&
2539
+ value !== null &&
2540
+ "exportName" in value &&
2541
+ typeof value.exportName === "string");
2542
+ }
2543
+ resolveLogBucket(logBucketProp) {
2544
+ // true = use account logging bucket
2545
+ if (logBucketProp === true) {
2546
+ const bucketName = Fn.importValue(CDK$2.IMPORT.LOG_BUCKET);
2547
+ return s3.Bucket.fromBucketName(this, "ImportedLogBucket", bucketName);
2548
+ }
2549
+ // { exportName: string } = import from CloudFormation export
2550
+ if (this.isExportNameObject(logBucketProp)) {
2551
+ const bucketName = Fn.importValue(logBucketProp.exportName);
2552
+ return s3.Bucket.fromBucketName(this, "ImportedLogBucket", bucketName);
2553
+ }
2554
+ // string = bucket name
2555
+ if (typeof logBucketProp === "string") {
2556
+ return s3.Bucket.fromBucketName(this, "ImportedLogBucket", logBucketProp);
2557
+ }
2558
+ // IBucket = use directly
2559
+ return logBucketProp;
2560
+ }
2527
2561
  // Implement IDistribution interface
2528
2562
  get env() {
2529
2563
  return {