@byaga/cdk-patterns 0.3.0 → 0.5.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.
@@ -0,0 +1,10 @@
1
+ import { Certificate } from "aws-cdk-lib/aws-certificatemanager";
2
+ import { IHostedZone } from "aws-cdk-lib/aws-route53";
3
+ import IDeployStack from "./IDeployStack";
4
+ import IDomainConfig from "./IDomainConfig";
5
+ export declare class ApiCertificate extends Certificate {
6
+ hostedZone: IHostedZone;
7
+ domain: string;
8
+ constructor(stack: IDeployStack, id: string, domain: IDomainConfig);
9
+ }
10
+ export default ApiCertificate;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiCertificate = void 0;
4
+ const aws_certificatemanager_1 = require("aws-cdk-lib/aws-certificatemanager");
5
+ const aws_route53_1 = require("aws-cdk-lib/aws-route53");
6
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
7
+ class ApiCertificate extends aws_certificatemanager_1.Certificate {
8
+ hostedZone;
9
+ domain;
10
+ constructor(stack, id, domain) {
11
+ const certDomain = [domain.domainName];
12
+ if (domain.subdomain)
13
+ certDomain.splice(0, 0, domain.subdomain);
14
+ const domainName = certDomain.join('.');
15
+ const hostedZone = aws_route53_1.HostedZone.fromHostedZoneAttributes(stack, stack.genId(id, 'hosted-zone'), {
16
+ hostedZoneId: domain.hostedZone.id,
17
+ zoneName: domain.hostedZone.name
18
+ });
19
+ super(stack, stack.genId(id), {
20
+ domainName,
21
+ validation: aws_certificatemanager_1.CertificateValidation.fromDns(hostedZone)
22
+ });
23
+ this.domain = domainName;
24
+ new aws_cdk_lib_1.CfnOutput(this, stack.genId(id, "certificate-output"), {
25
+ value: this.certificateArn,
26
+ exportName: stack.genName(id)
27
+ });
28
+ this.hostedZone = hostedZone;
29
+ }
30
+ }
31
+ exports.ApiCertificate = ApiCertificate;
32
+ exports.default = ApiCertificate;
@@ -0,0 +1,20 @@
1
+ import { Stack } from 'aws-cdk-lib';
2
+ import IStackArguments from './IStackArguments';
3
+ import { IConstruct } from "constructs";
4
+ export declare class IDeployStack extends Stack {
5
+ registry: {
6
+ [t: string]: {
7
+ [n: string]: any;
8
+ };
9
+ };
10
+ stage: string;
11
+ name: string;
12
+ genName(...name: string[]): string;
13
+ genId(...name: string[]): string;
14
+ static genStackResourceName(stackName: string, resource: string, stage?: string): string;
15
+ static genStackResourceId(stackName: string, resource: string, stage?: string): string;
16
+ constructor(scope: IConstruct, props: IStackArguments);
17
+ get(type: string, name: string): any;
18
+ set(type: string, name: string, instance: any): any;
19
+ }
20
+ export default IDeployStack;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IDeployStack = void 0;
4
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
5
+ class IDeployStack extends aws_cdk_lib_1.Stack {
6
+ registry = {};
7
+ stage;
8
+ name;
9
+ genName(...name) {
10
+ return IDeployStack.genStackResourceName(this.name, this.stage, name.filter(n => !!n).join('-'));
11
+ }
12
+ genId(...name) {
13
+ return IDeployStack.genStackResourceId(this.name, this.stage, name.filter(n => !!n).join('-'));
14
+ }
15
+ static genStackResourceName(stackName, resource, stage = 'develop') {
16
+ let name = stackName[0].toLowerCase() + stackName.substr(1);
17
+ name = name.replace(/[A-Z]/g, v => '-' + v.toLowerCase());
18
+ return `${name}-${resource}-${stage}`.toLowerCase();
19
+ }
20
+ static genStackResourceId(stackName, resource, stage = 'develop') {
21
+ const constructName = `${stackName}-${resource}-${stage}`;
22
+ return constructName[0].toUpperCase() + constructName.substr(1).replace(/-./g, v => (v[1] || '').toUpperCase());
23
+ }
24
+ constructor(scope, props) {
25
+ const options = (props || {});
26
+ const { stage = 'develop' } = options;
27
+ super(scope, props.stackName + '-' + stage, {
28
+ ...props,
29
+ stackName: props.stackName + '-' + stage
30
+ });
31
+ const stack = this;
32
+ stack.name = props.stackName || '';
33
+ stack.stage = stage;
34
+ stack.tags.setTag('Stage', stage);
35
+ stack.tags.setTag('Stack', this.genName('ui-stack'));
36
+ }
37
+ get(type, name) {
38
+ const items = this.registry[type];
39
+ return (items && items[name]) || null;
40
+ }
41
+ set(type, name, instance) {
42
+ this.registry[type] = this.registry[type] || {};
43
+ this.registry[type][name] = instance;
44
+ return instance;
45
+ }
46
+ }
47
+ exports.IDeployStack = IDeployStack;
48
+ exports.default = IDeployStack;
@@ -0,0 +1,7 @@
1
+ import IHostedZoneConfig from "./IHostedZoneConfig";
2
+ export interface IDomainConfig {
3
+ domainName: string;
4
+ subdomain?: string;
5
+ hostedZone: IHostedZoneConfig;
6
+ }
7
+ export default IDomainConfig;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export interface IHostedZoneConfig {
2
+ name: string;
3
+ id: string;
4
+ }
5
+ export default IHostedZoneConfig;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import { StackProps } from 'aws-cdk-lib/core';
2
+ export interface IStackArguments extends StackProps {
3
+ stage: string;
4
+ project: string;
5
+ owner: string;
6
+ }
7
+ export default IStackArguments;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { ApiCertificate } from "./ApiCertificate";
2
+ export { IDeployStack } from "./IDeployStack";
3
+ export { IDomainConfig } from "./IDomainConfig";
4
+ export { IHostedZoneConfig } from "./IHostedZoneConfig";
5
+ export { IStackArguments } from "./IStackArguments";
package/lib/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IDeployStack = exports.ApiCertificate = void 0;
4
+ var ApiCertificate_1 = require("./ApiCertificate");
5
+ Object.defineProperty(exports, "ApiCertificate", { enumerable: true, get: function () { return ApiCertificate_1.ApiCertificate; } });
6
+ var IDeployStack_1 = require("./IDeployStack");
7
+ Object.defineProperty(exports, "IDeployStack", { enumerable: true, get: function () { return IDeployStack_1.IDeployStack; } });
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@byaga/cdk-patterns",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Collection of common patterns used when making AWS CloudFormation templates using CDK",
5
- "main": " ",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
6
7
  "scripts": {
7
- "test": " "
8
+ "build": "tsc"
8
9
  },
9
10
  "keywords": [
10
11
  "CDK",
@@ -19,5 +20,8 @@
19
20
  "fs-extra": "^11.1.1",
20
21
  "glob": "^10.3.3",
21
22
  "js-yaml": "^4.1.0"
23
+ },
24
+ "devDependencies": {
25
+ "typescript": "^5.1.6"
22
26
  }
23
27
  }
@@ -1,10 +1,10 @@
1
- import {IDeployStack} from "./IDeployStack";
2
- import {DnsValidatedCertificate} from "aws-cdk-lib/aws-certificatemanager";
1
+ import {Certificate, CertificateValidation} from "aws-cdk-lib/aws-certificatemanager";
3
2
  import {HostedZone, IHostedZone} from "aws-cdk-lib/aws-route53";
4
3
  import {CfnOutput} from "aws-cdk-lib";
5
- import {IDomainConfig} from "./IDomainConfig";
4
+ import IDeployStack from "./IDeployStack";
5
+ import IDomainConfig from "./IDomainConfig";
6
6
 
7
- export default class ApiCertificate extends DnsValidatedCertificate {
7
+ export class ApiCertificate extends Certificate {
8
8
  hostedZone: IHostedZone
9
9
  domain: string
10
10
 
@@ -13,14 +13,13 @@ export default class ApiCertificate extends DnsValidatedCertificate {
13
13
  if (domain.subdomain) certDomain.splice(0, 0, domain.subdomain)
14
14
  const domainName = certDomain.join('.')
15
15
 
16
- console.log(1, domainName, domain)
17
16
  const hostedZone: IHostedZone = HostedZone.fromHostedZoneAttributes(stack, stack.genId(id, 'hosted-zone'), {
18
17
  hostedZoneId: domain.hostedZone.id,
19
18
  zoneName: domain.hostedZone.name
20
19
  })
21
20
  super(stack, stack.genId(id), {
22
21
  domainName,
23
- hostedZone
22
+ validation: CertificateValidation.fromDns(hostedZone)
24
23
  });
25
24
 
26
25
  this.domain = domainName
@@ -29,4 +28,5 @@ export default class ApiCertificate extends DnsValidatedCertificate {
29
28
  exportName: stack.genName(id)})
30
29
  this.hostedZone = hostedZone
31
30
  }
32
- }
31
+ }
32
+ export default ApiCertificate
@@ -1,5 +1,5 @@
1
1
  import {Stack} from 'aws-cdk-lib';
2
- import {IStackArguments} from './IStackArguments'
2
+ import IStackArguments from './IStackArguments'
3
3
  import {IConstruct} from "constructs";
4
4
 
5
5
  export class IDeployStack extends Stack {
@@ -53,3 +53,4 @@ export class IDeployStack extends Stack {
53
53
  return instance;
54
54
  }
55
55
  }
56
+ export default IDeployStack
@@ -0,0 +1,8 @@
1
+ import IHostedZoneConfig from "./IHostedZoneConfig";
2
+
3
+ export interface IDomainConfig {
4
+ domainName: string,
5
+ subdomain?: string,
6
+ hostedZone: IHostedZoneConfig
7
+ }
8
+ export default IDomainConfig
@@ -0,0 +1,5 @@
1
+ export interface IHostedZoneConfig {
2
+ name: string,
3
+ id: string
4
+ }
5
+ export default IHostedZoneConfig
@@ -1,7 +1,8 @@
1
- import {StackProps} from '@aws-cdk/core';
1
+ import {StackProps} from 'aws-cdk-lib/core';
2
2
 
3
3
  export interface IStackArguments extends StackProps {
4
4
  stage: string,
5
5
  project: string,
6
6
  owner: string
7
7
  }
8
+ export default IStackArguments
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export {ApiCertificate} from "./ApiCertificate";
2
+ export {IDeployStack} from "./IDeployStack";
3
+ export {IDomainConfig} from "./IDomainConfig";
4
+ export {IHostedZoneConfig} from "./IHostedZoneConfig";
5
+ export {IStackArguments} from "./IStackArguments";
package/tsconfig.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "commonjs",
5
+ "lib": [ "es2022" ],
6
+
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+
12
+ "outDir": "lib",
13
+ "declaration": true,
14
+
15
+
16
+
17
+ "noImplicitAny": true,
18
+ "strictNullChecks": true,
19
+ "noImplicitThis": true,
20
+ "alwaysStrict": true,
21
+ "noUnusedLocals": false,
22
+ "noUnusedParameters": false,
23
+ "noImplicitReturns": true,
24
+ "noFallthroughCasesInSwitch": false,
25
+ "inlineSourceMap": false,
26
+ "inlineSources": false,
27
+ "experimentalDecorators": true,
28
+ "strictPropertyInitialization": false,
29
+ "typeRoots": [
30
+ "./node_modules/@types"
31
+ ]
32
+ },
33
+ "include": ["src/**/*"],
34
+ "exclude": [ "node_modules" ]
35
+ }