@jaypie/constructs 1.2.8 → 1.2.10

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.
@@ -0,0 +1,116 @@
1
+ import { RemovalPolicy, Stack } from "aws-cdk-lib";
2
+ import * as acm from "aws-cdk-lib/aws-certificatemanager";
3
+ import * as route53 from "aws-cdk-lib/aws-route53";
4
+ import { Construct } from "constructs";
5
+ export interface JaypieCertificateProps {
6
+ /**
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
10
+ */
11
+ consumer?: boolean;
12
+ /**
13
+ * The domain name for the certificate.
14
+ * @default Derived from CDK_ENV_API_HOST_NAME or CDK_ENV_API_SUBDOMAIN + CDK_ENV_API_HOSTED_ZONE
15
+ */
16
+ domainName?: string;
17
+ /**
18
+ * Export name override for cross-stack sharing.
19
+ * @default Generated from environment and domain
20
+ */
21
+ export?: string;
22
+ /**
23
+ * Construct ID override. When not provided, ID is auto-generated from domain.
24
+ * Use this to align with certificates created by other constructs.
25
+ * @default Auto-generated as "Certificate-{sanitized-domain}"
26
+ */
27
+ id?: string;
28
+ /**
29
+ * Export certificate ARN for other stacks to import.
30
+ * Auto-detected from PROJECT_ENV (sandbox = provider).
31
+ * @default auto-detected from environment
32
+ */
33
+ provider?: boolean;
34
+ /**
35
+ * Role tag for tagging the certificate.
36
+ * @default CDK.ROLE.API
37
+ */
38
+ roleTag?: string;
39
+ /**
40
+ * The hosted zone for DNS validation.
41
+ * @default CDK_ENV_API_HOSTED_ZONE || CDK_ENV_HOSTED_ZONE
42
+ */
43
+ zone?: string | route53.IHostedZone;
44
+ }
45
+ /**
46
+ * A standalone certificate construct that can be shared across constructs.
47
+ *
48
+ * Key feature: Uses the same `resolveCertificate()` helper as JaypieDistribution,
49
+ * JaypieApiGateway, etc. This means:
50
+ * - Certificates are created at the stack level and cached by domain
51
+ * - You can "take over" a certificate from another construct by using the same domain
52
+ * - Swapping between JaypieDistribution and JaypieApiGateway won't recreate certs
53
+ *
54
+ * Supports flexible constructor signatures:
55
+ * - `new JaypieCertificate(scope)` - uses environment defaults
56
+ * - `new JaypieCertificate(scope, props)` - ID auto-generated from domain
57
+ * - `new JaypieCertificate(scope, id, props)` - explicit ID
58
+ *
59
+ * @example
60
+ * // Minimal - uses environment variables for domain/zone
61
+ * const cert = new JaypieCertificate(this);
62
+ *
63
+ * @example
64
+ * // With options - ID auto-generated as "JaypieCert-api-example-com"
65
+ * const cert = new JaypieCertificate(this, {
66
+ * domainName: "api.example.com",
67
+ * zone: "example.com",
68
+ * });
69
+ *
70
+ * @example
71
+ * // Explicit ID - useful when you need a specific construct ID
72
+ * const cert = new JaypieCertificate(this, "MyApiCert", {
73
+ * domainName: "api.example.com",
74
+ * zone: "example.com",
75
+ * });
76
+ *
77
+ * @example
78
+ * // Take over from JaypieDistribution (uses same ID format)
79
+ * // After removing JaypieDistribution with certificate: true
80
+ * const cert = new JaypieCertificate(this, {
81
+ * domainName: "api.example.com",
82
+ * zone: "example.com",
83
+ * });
84
+ *
85
+ * @example
86
+ * // Provider/consumer pattern for cross-stack sharing
87
+ * // In sandbox stack:
88
+ * new JaypieCertificate(this, { provider: true });
89
+ *
90
+ * // In personal build:
91
+ * new JaypieCertificate(this, { consumer: true });
92
+ */
93
+ export declare class JaypieCertificate extends Construct implements acm.ICertificate {
94
+ readonly certificate: acm.ICertificate;
95
+ readonly certificateArn: string;
96
+ readonly domainName: string;
97
+ /**
98
+ * Create a certificate with environment defaults.
99
+ */
100
+ constructor(scope: Construct);
101
+ /**
102
+ * Create a certificate with options (ID auto-generated from domain).
103
+ */
104
+ constructor(scope: Construct, props: JaypieCertificateProps);
105
+ /**
106
+ * Create a certificate with explicit ID.
107
+ */
108
+ constructor(scope: Construct, id: string, props?: JaypieCertificateProps);
109
+ get stack(): Stack;
110
+ get env(): {
111
+ account: string;
112
+ region: string;
113
+ };
114
+ applyRemovalPolicy(policy: RemovalPolicy): void;
115
+ metricDaysToExpiry(props?: import("aws-cdk-lib/aws-cloudwatch").MetricOptions): import("aws-cdk-lib/aws-cloudwatch").Metric;
116
+ }
@@ -44,8 +44,8 @@ export interface JaypieDistributionProps extends Omit<cloudfront.DistributionPro
44
44
  /**
45
45
  * Origin read timeout - how long CloudFront waits for a response from the origin.
46
46
  * This is the maximum time allowed for the origin to respond.
47
- * @default CDK.DURATION.CLOUDFRONT_API (180 seconds)
48
- * @max Duration.seconds(180)
47
+ * @default CDK.DURATION.CLOUDFRONT_API (120 seconds)
48
+ * @max Duration.seconds(120)
49
49
  */
50
50
  originReadTimeout?: Duration;
51
51
  /**
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -4,6 +4,7 @@ export { constructStackName } from "./constructStackName";
4
4
  export { constructTagger } from "./constructTagger";
5
5
  export { envHostname } from "./envHostname";
6
6
  export { extendDatadogRole, ExtendDatadogRoleOptions, } from "./extendDatadogRole";
7
+ export { clearAllCertificateCaches, clearCertificateCache, resolveCertificate, ResolveCertificateOptions, } from "./resolveCertificate";
7
8
  export { isEnv, isProductionEnv, isSandboxEnv } from "./isEnv";
8
9
  export { isValidHostname } from "./isValidHostname";
9
10
  export { isValidSubdomain } from "./isValidSubdomain";
@@ -0,0 +1,63 @@
1
+ import { Stack } from "aws-cdk-lib";
2
+ import * as acm from "aws-cdk-lib/aws-certificatemanager";
3
+ import * as route53 from "aws-cdk-lib/aws-route53";
4
+ import { Construct } from "constructs";
5
+ export interface ResolveCertificateOptions {
6
+ /** Certificate input - true creates at stack level, false skips, ICertificate uses as-is, string imports from ARN */
7
+ certificate?: boolean | acm.ICertificate | string;
8
+ /** Domain name for the certificate (required if certificate is true) */
9
+ domainName: string;
10
+ /** Construct ID name prefix (defaults to "Certificate") */
11
+ name?: string;
12
+ /** Role tag for tagging (defaults to CDK.ROLE.API) */
13
+ roleTag?: string;
14
+ /** Hosted zone for DNS validation (required if certificate is true) */
15
+ zone: route53.IHostedZone;
16
+ }
17
+ /**
18
+ * Resolves a certificate based on input type.
19
+ *
20
+ * Key behavior: When certificate is `true`, the certificate is created at the
21
+ * STACK level (not construct level) and cached by domain name. This allows
22
+ * swapping between constructs (e.g., JaypieDistribution to JaypieApiGateway)
23
+ * without recreating the certificate.
24
+ *
25
+ * @param scope - The construct scope (used to find the stack)
26
+ * @param options - Certificate resolution options
27
+ * @returns The resolved certificate, or undefined if certificate is false
28
+ *
29
+ * @example
30
+ * // Create or get cached certificate at stack level
31
+ * const cert = resolveCertificate(this, {
32
+ * certificate: true,
33
+ * domainName: "api.example.com",
34
+ * zone: hostedZone,
35
+ * });
36
+ *
37
+ * @example
38
+ * // Use existing certificate
39
+ * const cert = resolveCertificate(this, {
40
+ * certificate: existingCert,
41
+ * domainName: "api.example.com",
42
+ * zone: hostedZone,
43
+ * });
44
+ *
45
+ * @example
46
+ * // Import certificate from ARN
47
+ * const cert = resolveCertificate(this, {
48
+ * certificate: "arn:aws:acm:us-east-1:123456789:certificate/abc-123",
49
+ * domainName: "api.example.com",
50
+ * zone: hostedZone,
51
+ * });
52
+ */
53
+ export declare function resolveCertificate(scope: Construct, options: ResolveCertificateOptions): acm.ICertificate | undefined;
54
+ /**
55
+ * Clears the certificate cache for a specific stack.
56
+ * Primarily useful for testing.
57
+ */
58
+ export declare function clearCertificateCache(stack: Stack): void;
59
+ /**
60
+ * Clears all certificate caches.
61
+ * Primarily useful for testing.
62
+ */
63
+ export declare function clearAllCertificateCaches(): void;