@jaypie/constructs 1.2.9 → 1.2.11
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/JaypieCertificate.d.ts +117 -0
- package/dist/cjs/__tests__/JaypieCertificate.spec.d.ts +1 -0
- package/dist/cjs/__tests__/resolveCertificate.spec.d.ts +1 -0
- package/dist/cjs/helpers/index.d.ts +1 -0
- package/dist/cjs/helpers/resolveCertificate.d.ts +63 -0
- package/dist/cjs/index.cjs +376 -44
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/esm/JaypieCertificate.d.ts +117 -0
- package/dist/esm/__tests__/JaypieCertificate.spec.d.ts +1 -0
- package/dist/esm/__tests__/resolveCertificate.spec.d.ts +1 -0
- package/dist/esm/helpers/index.d.ts +1 -0
- package/dist/esm/helpers/resolveCertificate.d.ts +63 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +372 -44
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,117 @@
|
|
|
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
|
+
* When true, imports the certificate ARN via CloudFormation export.
|
|
9
|
+
* @default false
|
|
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
|
+
* Only used when provider is true.
|
|
20
|
+
* @default Generated from environment and domain
|
|
21
|
+
*/
|
|
22
|
+
export?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Construct ID override. When not provided, ID is auto-generated from domain.
|
|
25
|
+
* Use this to align with certificates created by other constructs.
|
|
26
|
+
* @default Auto-generated as "JaypieCert-{sanitized-domain}"
|
|
27
|
+
*/
|
|
28
|
+
id?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Export certificate ARN for other stacks to import.
|
|
31
|
+
* When true, creates a CloudFormation export that consumer stacks can import.
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
provider?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Role tag for tagging the certificate.
|
|
37
|
+
* @default CDK.ROLE.API
|
|
38
|
+
*/
|
|
39
|
+
roleTag?: string;
|
|
40
|
+
/**
|
|
41
|
+
* The hosted zone for DNS validation.
|
|
42
|
+
* @default CDK_ENV_API_HOSTED_ZONE || CDK_ENV_HOSTED_ZONE
|
|
43
|
+
*/
|
|
44
|
+
zone?: string | route53.IHostedZone;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A standalone certificate construct that can be shared across constructs.
|
|
48
|
+
*
|
|
49
|
+
* Key feature: Uses the same `resolveCertificate()` helper as JaypieDistribution,
|
|
50
|
+
* JaypieApiGateway, etc. This means:
|
|
51
|
+
* - Certificates are created at the stack level and cached by domain
|
|
52
|
+
* - You can "take over" a certificate from another construct by using the same domain
|
|
53
|
+
* - Swapping between JaypieDistribution and JaypieApiGateway won't recreate certs
|
|
54
|
+
*
|
|
55
|
+
* Supports flexible constructor signatures:
|
|
56
|
+
* - `new JaypieCertificate(scope)` - uses environment defaults
|
|
57
|
+
* - `new JaypieCertificate(scope, props)` - ID auto-generated from domain
|
|
58
|
+
* - `new JaypieCertificate(scope, id, props)` - explicit ID
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* // Minimal - uses environment variables for domain/zone
|
|
62
|
+
* const cert = new JaypieCertificate(this);
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // With options - ID auto-generated as "JaypieCert-api-example-com"
|
|
66
|
+
* const cert = new JaypieCertificate(this, {
|
|
67
|
+
* domainName: "api.example.com",
|
|
68
|
+
* zone: "example.com",
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // Explicit ID - useful when you need a specific construct ID
|
|
73
|
+
* const cert = new JaypieCertificate(this, "MyApiCert", {
|
|
74
|
+
* domainName: "api.example.com",
|
|
75
|
+
* zone: "example.com",
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* // Take over from JaypieDistribution (uses same ID format)
|
|
80
|
+
* // After removing JaypieDistribution with certificate: true
|
|
81
|
+
* const cert = new JaypieCertificate(this, {
|
|
82
|
+
* domainName: "api.example.com",
|
|
83
|
+
* zone: "example.com",
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* // Optional: Provider/consumer pattern for cross-stack sharing
|
|
88
|
+
* // In sandbox stack (explicitly export):
|
|
89
|
+
* new JaypieCertificate(this, { provider: true });
|
|
90
|
+
*
|
|
91
|
+
* // In personal build (explicitly import):
|
|
92
|
+
* new JaypieCertificate(this, { consumer: true });
|
|
93
|
+
*/
|
|
94
|
+
export declare class JaypieCertificate extends Construct implements acm.ICertificate {
|
|
95
|
+
readonly certificate: acm.ICertificate;
|
|
96
|
+
readonly certificateArn: string;
|
|
97
|
+
readonly domainName: string;
|
|
98
|
+
/**
|
|
99
|
+
* Create a certificate with environment defaults.
|
|
100
|
+
*/
|
|
101
|
+
constructor(scope: Construct);
|
|
102
|
+
/**
|
|
103
|
+
* Create a certificate with options (ID auto-generated from domain).
|
|
104
|
+
*/
|
|
105
|
+
constructor(scope: Construct, props: JaypieCertificateProps);
|
|
106
|
+
/**
|
|
107
|
+
* Create a certificate with explicit ID.
|
|
108
|
+
*/
|
|
109
|
+
constructor(scope: Construct, id: string, props?: JaypieCertificateProps);
|
|
110
|
+
get stack(): Stack;
|
|
111
|
+
get env(): {
|
|
112
|
+
account: string;
|
|
113
|
+
region: string;
|
|
114
|
+
};
|
|
115
|
+
applyRemovalPolicy(policy: RemovalPolicy): void;
|
|
116
|
+
metricDaysToExpiry(props?: import("aws-cdk-lib/aws-cloudwatch").MetricOptions): import("aws-cdk-lib/aws-cloudwatch").Metric;
|
|
117
|
+
}
|
|
@@ -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;
|