@jaypie/constructs 1.1.61 → 1.1.62-rc.0

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,6 +5,7 @@ export { JaypieAppStack } from "./JaypieAppStack";
5
5
  export { JaypieBucketQueuedLambda } from "./JaypieBucketQueuedLambda";
6
6
  export { JaypieDatadogBucket, JaypieDatadogBucketProps, } from "./JaypieDatadogBucket";
7
7
  export { JaypieDatadogForwarder, JaypieDatadogForwarderProps, } from "./JaypieDatadogForwarder";
8
+ export { JaypieDistribution, JaypieDistributionProps, } from "./JaypieDistribution";
8
9
  export { JaypieDatadogSecret } from "./JaypieDatadogSecret";
9
10
  export { JaypieDnsRecord, JaypieDnsRecordProps } from "./JaypieDnsRecord";
10
11
  export { JaypieEnvSecret } from "./JaypieEnvSecret";
@@ -0,0 +1,65 @@
1
+ import { RemovalPolicy, Stack } from "aws-cdk-lib";
2
+ import * as acm from "aws-cdk-lib/aws-certificatemanager";
3
+ import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
4
+ import * as lambda from "aws-cdk-lib/aws-lambda";
5
+ import * as route53 from "aws-cdk-lib/aws-route53";
6
+ import { Construct } from "constructs";
7
+ export interface JaypieDistributionProps extends Omit<cloudfront.DistributionProps, "certificate" | "defaultBehavior"> {
8
+ /**
9
+ * SSL certificate for the CloudFront distribution
10
+ * @default true (creates a new certificate)
11
+ */
12
+ certificate?: boolean | acm.ICertificate;
13
+ /**
14
+ * Override default behavior (optional if handler is provided)
15
+ */
16
+ defaultBehavior?: cloudfront.BehaviorOptions;
17
+ /**
18
+ * The origin handler - can be an IOrigin, IFunctionUrl, or IFunction
19
+ * If IFunction, a FunctionUrl will be created with auth NONE
20
+ */
21
+ handler?: cloudfront.IOrigin | lambda.IFunctionUrl | lambda.IFunction;
22
+ /**
23
+ * The domain name for the distribution
24
+ * @default mergeDomain(CDK_ENV_API_SUBDOMAIN, CDK_ENV_API_HOSTED_ZONE || CDK_ENV_HOSTED_ZONE)
25
+ */
26
+ host?: string;
27
+ /**
28
+ * Invoke mode for Lambda Function URLs
29
+ * @default InvokeMode.BUFFERED
30
+ */
31
+ invokeMode?: lambda.InvokeMode;
32
+ /**
33
+ * Role tag for tagging resources
34
+ * @default CDK.ROLE.HOSTING
35
+ */
36
+ roleTag?: string;
37
+ /**
38
+ * The hosted zone for DNS records
39
+ * @default CDK_ENV_API_HOSTED_ZONE || CDK_ENV_HOSTED_ZONE
40
+ */
41
+ zone?: string | route53.IHostedZone;
42
+ }
43
+ export declare class JaypieDistribution extends Construct implements cloudfront.IDistribution {
44
+ readonly certificate?: acm.ICertificate;
45
+ readonly distribution: cloudfront.Distribution;
46
+ readonly distributionArn: string;
47
+ readonly distributionDomainName: string;
48
+ readonly distributionId: string;
49
+ readonly domainName: string;
50
+ readonly functionUrl?: lambda.FunctionUrl;
51
+ readonly host?: string;
52
+ constructor(scope: Construct, id: string, props: JaypieDistributionProps);
53
+ private isIOrigin;
54
+ private isIFunctionUrl;
55
+ private isIFunction;
56
+ get env(): {
57
+ account: string;
58
+ region: string;
59
+ };
60
+ get stack(): Stack;
61
+ applyRemovalPolicy(policy: RemovalPolicy): void;
62
+ grant(identity: import("aws-cdk-lib/aws-iam").IGrantable, ...actions: string[]): import("aws-cdk-lib/aws-iam").Grant;
63
+ grantCreateInvalidation(identity: import("aws-cdk-lib/aws-iam").IGrantable): import("aws-cdk-lib/aws-iam").Grant;
64
+ get distributionRef(): cloudfront.DistributionReference;
65
+ }
@@ -0,0 +1,121 @@
1
+ import { Construct } from "constructs";
2
+ import * as sso from "aws-cdk-lib/aws-sso";
3
+ /**
4
+ * Account categories for SSO group assignments
5
+ */
6
+ export interface JaypieSsoAccountMap {
7
+ development: string[];
8
+ management: string[];
9
+ operations: string[];
10
+ production: string[];
11
+ sandbox: string[];
12
+ security: string[];
13
+ stage: string[];
14
+ }
15
+ /**
16
+ * Mapping of group types to Google Workspace group GUIDs
17
+ */
18
+ export interface JaypieSsoGroupMap {
19
+ administrators: string;
20
+ analysts: string;
21
+ developers: string;
22
+ }
23
+ /**
24
+ * IAM Policy Statement structure for inline policies
25
+ */
26
+ export interface PolicyStatement {
27
+ Effect: "Allow" | "Deny";
28
+ Action: string[] | string;
29
+ Resource: string[] | string;
30
+ Condition?: Record<string, unknown>;
31
+ }
32
+ /**
33
+ * Properties for the JaypieSsoGroups construct
34
+ */
35
+ export interface JaypieSsoGroupsProps {
36
+ /**
37
+ * ARN of the IAM Identity Center instance
38
+ */
39
+ instanceArn: string;
40
+ /**
41
+ * Mapping of account categories to AWS account IDs
42
+ */
43
+ accountMap: JaypieSsoAccountMap;
44
+ /**
45
+ * Mapping of group types to Google Workspace group GUIDs
46
+ */
47
+ groupMap: JaypieSsoGroupMap;
48
+ /**
49
+ * Additional inline policy statements to append to each group's permission set
50
+ * Each group can have its own set of policy statements that will be merged
51
+ * with the default policies.
52
+ */
53
+ inlinePolicyStatements?: {
54
+ administrators?: PolicyStatement[];
55
+ analysts?: PolicyStatement[];
56
+ developers?: PolicyStatement[];
57
+ };
58
+ }
59
+ /**
60
+ * Permission set types with corresponding AWS managed policies
61
+ */
62
+ export declare enum PermissionSetType {
63
+ ADMINISTRATOR = "Administrator",
64
+ ANALYST = "Analyst",
65
+ DEVELOPER = "Developer"
66
+ }
67
+ /**
68
+ * Construct to simplify AWS SSO group management.
69
+ * This construct encapsulates the complexity of creating permission sets
70
+ * and assigning them to groups across multiple AWS accounts.
71
+ */
72
+ export declare class JaypieSsoGroups extends Construct {
73
+ private readonly permissionSets;
74
+ private readonly instanceArn;
75
+ private readonly props;
76
+ constructor(scope: Construct, id: string, props: JaypieSsoGroupsProps);
77
+ /**
78
+ * Creates the Administrator permission set with AdministratorAccess policy
79
+ * and billing access
80
+ */
81
+ private createAdministratorPermissionSet;
82
+ /**
83
+ * Creates the Analyst permission set with ReadOnlyAccess policy
84
+ * and limited write access
85
+ */
86
+ private createAnalystPermissionSet;
87
+ /**
88
+ * Creates the Developer permission set with SystemAdministrator policy
89
+ * and expanded write access
90
+ */
91
+ private createDeveloperPermissionSet;
92
+ /**
93
+ * Gets the permission set for the specified type
94
+ */
95
+ getPermissionSet(type: PermissionSetType): sso.CfnPermissionSet;
96
+ /**
97
+ * Merges default inline policies with additional user-provided policy statements
98
+ *
99
+ * @param defaultPolicy - The default policy object with Version and Statement properties
100
+ * @param additionalStatements - Optional additional policy statements to merge
101
+ * @returns The merged policy object
102
+ */
103
+ private mergeInlinePolicies;
104
+ /**
105
+ * Creates assignments between permission sets, groups, and accounts
106
+ * based on the provided configuration
107
+ */
108
+ private createPermissionSetAssignments;
109
+ /**
110
+ * Assigns Administrator permissions to appropriate accounts
111
+ */
112
+ private assignAdministratorPermissions;
113
+ /**
114
+ * Assigns Analyst permissions to appropriate accounts
115
+ */
116
+ private assignAnalystPermissions;
117
+ /**
118
+ * Assigns Developer permissions to appropriate accounts
119
+ */
120
+ private assignDeveloperPermissions;
121
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import * as lambda from "aws-cdk-lib/aws-lambda";
2
+ export interface AddDatadogLayerOptions {
3
+ datadogApiKeyArn?: string;
4
+ }
5
+ export declare function addDatadogLayer(lambdaFunction: lambda.Function, options?: AddDatadogLayerOptions): boolean;
@@ -0,0 +1,12 @@
1
+ import { Duration } from "aws-cdk-lib";
2
+ import * as lambda from "aws-cdk-lib/aws-lambda";
3
+ export interface AddParamsAndSecretsOptions {
4
+ paramsAndSecrets?: lambda.ParamsAndSecretsLayerVersion | boolean;
5
+ paramsAndSecretsOptions?: {
6
+ cacheSize?: number;
7
+ logLevel?: lambda.ParamsAndSecretsLogLevel;
8
+ parameterStoreTtl?: Duration;
9
+ secretsManagerTtl?: Duration;
10
+ };
11
+ }
12
+ export declare function addParamsAndSecrets(lambdaFunction: lambda.Function, options?: AddParamsAndSecretsOptions): boolean;
@@ -0,0 +1,5 @@
1
+ export declare function projectEnvName(name: string, opts?: {
2
+ env?: string;
3
+ key?: string;
4
+ nonce?: string;
5
+ }): string;
@@ -0,0 +1,4 @@
1
+ import { Stack } from "aws-cdk-lib";
2
+ export declare function stackTagger(stack: Stack, { name }?: {
3
+ name?: string;
4
+ }): boolean;
@@ -5,6 +5,7 @@ export { JaypieAppStack } from "./JaypieAppStack";
5
5
  export { JaypieBucketQueuedLambda } from "./JaypieBucketQueuedLambda";
6
6
  export { JaypieDatadogBucket, JaypieDatadogBucketProps, } from "./JaypieDatadogBucket";
7
7
  export { JaypieDatadogForwarder, JaypieDatadogForwarderProps, } from "./JaypieDatadogForwarder";
8
+ export { JaypieDistribution, JaypieDistributionProps, } from "./JaypieDistribution";
8
9
  export { JaypieDatadogSecret } from "./JaypieDatadogSecret";
9
10
  export { JaypieDnsRecord, JaypieDnsRecordProps } from "./JaypieDnsRecord";
10
11
  export { JaypieEnvSecret } from "./JaypieEnvSecret";
package/dist/esm/index.js CHANGED
@@ -20,14 +20,14 @@ import * as sqs from 'aws-cdk-lib/aws-sqs';
20
20
  import * as lambdaEventSources from 'aws-cdk-lib/aws-lambda-event-sources';
21
21
  import { Rule, RuleTargetInput } from 'aws-cdk-lib/aws-events';
22
22
  import { LambdaFunction } from 'aws-cdk-lib/aws-events-targets';
23
+ import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
24
+ import * as origins from 'aws-cdk-lib/aws-cloudfront-origins';
23
25
  import { LogGroup, RetentionDays, FilterPattern } from 'aws-cdk-lib/aws-logs';
24
26
  import { Nextjs } from 'cdk-nextjs-standalone';
25
27
  import * as path from 'path';
26
28
  import { Trail, ReadWriteType } from 'aws-cdk-lib/aws-cloudtrail';
27
29
  import { CfnPermissionSet, CfnAssignment } from 'aws-cdk-lib/aws-sso';
28
30
  import { CfnApplication } from 'aws-cdk-lib/aws-sam';
29
- import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
30
- import * as origins from 'aws-cdk-lib/aws-cloudfront-origins';
31
31
 
32
32
  const CDK$2 = {
33
33
  ACCOUNT: {
@@ -1628,6 +1628,180 @@ class JaypieDatadogForwarder extends Construct {
1628
1628
  }
1629
1629
  }
1630
1630
 
1631
+ class JaypieDistribution extends Construct {
1632
+ constructor(scope, id, props) {
1633
+ super(scope, id);
1634
+ const { certificate: certificateProp = true, handler, host: propsHost, invokeMode = lambda.InvokeMode.BUFFERED, roleTag = CDK$2.ROLE.HOSTING, zone: propsZone, defaultBehavior: propsDefaultBehavior, ...distributionProps } = props;
1635
+ // Validate environment variables
1636
+ if (process.env.CDK_ENV_API_SUBDOMAIN &&
1637
+ !isValidSubdomain(process.env.CDK_ENV_API_SUBDOMAIN)) {
1638
+ throw new Error("CDK_ENV_API_SUBDOMAIN is not a valid subdomain");
1639
+ }
1640
+ if (process.env.CDK_ENV_API_HOSTED_ZONE &&
1641
+ !isValidHostname$1(process.env.CDK_ENV_API_HOSTED_ZONE)) {
1642
+ throw new Error("CDK_ENV_API_HOSTED_ZONE is not a valid hostname");
1643
+ }
1644
+ if (process.env.CDK_ENV_HOSTED_ZONE &&
1645
+ !isValidHostname$1(process.env.CDK_ENV_HOSTED_ZONE)) {
1646
+ throw new Error("CDK_ENV_HOSTED_ZONE is not a valid hostname");
1647
+ }
1648
+ // Determine host from props or environment
1649
+ let host = propsHost;
1650
+ if (!host) {
1651
+ try {
1652
+ if (process.env.CDK_ENV_API_HOST_NAME) {
1653
+ host = process.env.CDK_ENV_API_HOST_NAME;
1654
+ }
1655
+ else if (process.env.CDK_ENV_API_SUBDOMAIN) {
1656
+ host = mergeDomain(process.env.CDK_ENV_API_SUBDOMAIN, process.env.CDK_ENV_API_HOSTED_ZONE ||
1657
+ process.env.CDK_ENV_HOSTED_ZONE ||
1658
+ "");
1659
+ }
1660
+ }
1661
+ catch {
1662
+ host = undefined;
1663
+ }
1664
+ }
1665
+ if (host && !isValidHostname$1(host)) {
1666
+ throw new Error("Host is not a valid hostname");
1667
+ }
1668
+ this.host = host;
1669
+ // Determine zone from props or environment
1670
+ const zone = propsZone ||
1671
+ process.env.CDK_ENV_API_HOSTED_ZONE ||
1672
+ process.env.CDK_ENV_HOSTED_ZONE;
1673
+ // Resolve the origin from handler
1674
+ // Check order matters: IFunctionUrl before IOrigin (FunctionUrl also has bind method)
1675
+ // IFunction before IFunctionUrl (IFunction doesn't have functionUrlId)
1676
+ let origin;
1677
+ if (handler) {
1678
+ if (this.isIFunction(handler)) {
1679
+ // Create FunctionUrl for the Lambda function
1680
+ const functionUrl = new lambda.FunctionUrl(this, "FunctionUrl", {
1681
+ function: handler,
1682
+ authType: lambda.FunctionUrlAuthType.NONE,
1683
+ invokeMode,
1684
+ });
1685
+ this.functionUrl = functionUrl;
1686
+ origin = new origins.FunctionUrlOrigin(functionUrl);
1687
+ }
1688
+ else if (this.isIFunctionUrl(handler)) {
1689
+ origin = new origins.FunctionUrlOrigin(handler);
1690
+ }
1691
+ else if (this.isIOrigin(handler)) {
1692
+ origin = handler;
1693
+ }
1694
+ }
1695
+ // Build default behavior
1696
+ let defaultBehavior;
1697
+ if (propsDefaultBehavior) {
1698
+ defaultBehavior = propsDefaultBehavior;
1699
+ }
1700
+ else if (origin) {
1701
+ defaultBehavior = {
1702
+ cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
1703
+ origin,
1704
+ originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
1705
+ viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
1706
+ };
1707
+ }
1708
+ else {
1709
+ throw new Error("Either handler or defaultBehavior must be provided to JaypieDistribution");
1710
+ }
1711
+ // Resolve hosted zone and certificate
1712
+ // Only resolve zone when we need it (for certificate or DNS)
1713
+ let hostedZone;
1714
+ let certificateToUse;
1715
+ if (host && zone && certificateProp !== false) {
1716
+ hostedZone = resolveHostedZone(this, { zone });
1717
+ if (certificateProp === true) {
1718
+ certificateToUse = new acm.Certificate(this, constructEnvName("Certificate"), {
1719
+ domainName: host,
1720
+ validation: acm.CertificateValidation.fromDns(hostedZone),
1721
+ });
1722
+ Tags.of(certificateToUse).add(CDK$2.TAG.ROLE, roleTag);
1723
+ }
1724
+ else if (typeof certificateProp === "object") {
1725
+ certificateToUse = certificateProp;
1726
+ }
1727
+ this.certificate = certificateToUse;
1728
+ }
1729
+ // Create the CloudFront distribution
1730
+ this.distribution = new cloudfront.Distribution(this, constructEnvName("Distribution"), {
1731
+ defaultBehavior,
1732
+ ...(host && certificateToUse
1733
+ ? {
1734
+ certificate: certificateToUse,
1735
+ domainNames: [host],
1736
+ }
1737
+ : {}),
1738
+ ...distributionProps,
1739
+ });
1740
+ Tags.of(this.distribution).add(CDK$2.TAG.ROLE, roleTag);
1741
+ this.distributionArn = `arn:aws:cloudfront::${Stack.of(this).account}:distribution/${this.distribution.distributionId}`;
1742
+ this.distributionDomainName = this.distribution.distributionDomainName;
1743
+ this.distributionId = this.distribution.distributionId;
1744
+ this.domainName = this.distribution.domainName;
1745
+ // Create DNS record if we have host and zone
1746
+ if (host && hostedZone) {
1747
+ const record = new route53.ARecord(this, "AliasRecord", {
1748
+ recordName: host,
1749
+ target: route53.RecordTarget.fromAlias(new route53Targets.CloudFrontTarget(this.distribution)),
1750
+ zone: hostedZone,
1751
+ });
1752
+ Tags.of(record).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
1753
+ }
1754
+ }
1755
+ // Type guards for handler types
1756
+ isIOrigin(handler) {
1757
+ return (typeof handler === "object" &&
1758
+ handler !== null &&
1759
+ "bind" in handler &&
1760
+ typeof handler.bind === "function");
1761
+ }
1762
+ isIFunctionUrl(handler) {
1763
+ // FunctionUrl has 'url' property which is the function URL string
1764
+ // IFunction does not have 'url' property
1765
+ return (typeof handler === "object" &&
1766
+ handler !== null &&
1767
+ "url" in handler &&
1768
+ "functionArn" in handler);
1769
+ }
1770
+ isIFunction(handler) {
1771
+ // IFunction has functionArn and functionName but NOT 'url'
1772
+ // (FunctionUrl also has functionArn but also has 'url')
1773
+ return (typeof handler === "object" &&
1774
+ handler !== null &&
1775
+ "functionArn" in handler &&
1776
+ "functionName" in handler &&
1777
+ !("url" in handler));
1778
+ }
1779
+ // Implement IDistribution interface
1780
+ get env() {
1781
+ return {
1782
+ account: Stack.of(this).account,
1783
+ region: Stack.of(this).region,
1784
+ };
1785
+ }
1786
+ get stack() {
1787
+ return this.distribution.stack;
1788
+ }
1789
+ applyRemovalPolicy(policy) {
1790
+ this.distribution.applyRemovalPolicy(policy);
1791
+ }
1792
+ grant(identity, ...actions) {
1793
+ return this.distribution.grant(identity, ...actions);
1794
+ }
1795
+ grantCreateInvalidation(identity) {
1796
+ return this.distribution.grantCreateInvalidation(identity);
1797
+ }
1798
+ get distributionRef() {
1799
+ return {
1800
+ distributionId: this.distribution.distributionId,
1801
+ };
1802
+ }
1803
+ }
1804
+
1631
1805
  // It is a consumer if the environment is ephemeral
1632
1806
  function checkEnvIsConsumer(env = process.env) {
1633
1807
  return (env.PROJECT_ENV === CDK$2.ENV.PERSONAL ||
@@ -2981,5 +3155,5 @@ class JaypieWebDeploymentBucket extends Construct {
2981
3155
  }
2982
3156
  }
2983
3157
 
2984
- export { CDK$2 as CDK, JaypieAccountLoggingBucket, JaypieApiGateway, JaypieAppStack, JaypieBucketQueuedLambda, JaypieDatadogBucket, JaypieDatadogForwarder, JaypieDatadogSecret, JaypieDnsRecord, JaypieEnvSecret, JaypieEventsRule, JaypieExpressLambda, JaypieGitHubDeployRole, JaypieHostedZone, JaypieInfrastructureStack, JaypieLambda, JaypieMongoDbSecret, JaypieNextJs, JaypieOpenAiSecret, JaypieOrganizationTrail, JaypieQueuedLambda, JaypieSsoPermissions, JaypieSsoSyncApplication, JaypieStack, JaypieTraceSigningKeySecret, JaypieWebDeploymentBucket, addDatadogLayers, constructEnvName, constructStackName, constructTagger, envHostname, extendDatadogRole, isEnv, isProductionEnv, isSandboxEnv, isValidHostname$1 as isValidHostname, isValidSubdomain, jaypieLambdaEnv, mergeDomain, resolveDatadogForwarderFunction, resolveDatadogLayers, resolveDatadogLoggingDestination, resolveHostedZone, resolveParamsAndSecrets };
3158
+ export { CDK$2 as CDK, JaypieAccountLoggingBucket, JaypieApiGateway, JaypieAppStack, JaypieBucketQueuedLambda, JaypieDatadogBucket, JaypieDatadogForwarder, JaypieDatadogSecret, JaypieDistribution, JaypieDnsRecord, JaypieEnvSecret, JaypieEventsRule, JaypieExpressLambda, JaypieGitHubDeployRole, JaypieHostedZone, JaypieInfrastructureStack, JaypieLambda, JaypieMongoDbSecret, JaypieNextJs, JaypieOpenAiSecret, JaypieOrganizationTrail, JaypieQueuedLambda, JaypieSsoPermissions, JaypieSsoSyncApplication, JaypieStack, JaypieTraceSigningKeySecret, JaypieWebDeploymentBucket, addDatadogLayers, constructEnvName, constructStackName, constructTagger, envHostname, extendDatadogRole, isEnv, isProductionEnv, isSandboxEnv, isValidHostname$1 as isValidHostname, isValidSubdomain, jaypieLambdaEnv, mergeDomain, resolveDatadogForwarderFunction, resolveDatadogLayers, resolveDatadogLoggingDestination, resolveHostedZone, resolveParamsAndSecrets };
2985
3159
  //# sourceMappingURL=index.js.map