@byaga/cdk-patterns 0.11.5 → 0.11.7

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.
Files changed (111) hide show
  1. package/LICENSE.md +20 -20
  2. package/README.md +42 -42
  3. package/eslint.config.mjs +12 -0
  4. package/lib/build/copy-files.d.ts +4 -5
  5. package/lib/build/copy-files.js +26 -21
  6. package/lib/build/generate-hash.d.ts +2 -3
  7. package/lib/build/generate-hash.js +3 -5
  8. package/lib/build/get-files.d.ts +3 -3
  9. package/lib/build/get-files.js +3 -3
  10. package/lib/build/get-source-directory.d.ts +8 -8
  11. package/lib/build/get-source-directory.js +13 -13
  12. package/lib/build/hash-file.js +4 -5
  13. package/lib/build/index.d.ts +2 -0
  14. package/lib/build/index.js +21 -0
  15. package/lib/build/nodejs/build-ecmascript.d.ts +3 -3
  16. package/lib/build/nodejs/build-ecmascript.js +4 -5
  17. package/lib/build/nodejs/build-node-source.d.ts +9 -3
  18. package/lib/build/nodejs/build-node-source.js +10 -11
  19. package/lib/build/nodejs/build-typescript.d.ts +3 -3
  20. package/lib/build/nodejs/build-typescript.js +7 -10
  21. package/lib/build/nodejs/index.d.ts +1 -0
  22. package/lib/build/nodejs/index.js +5 -0
  23. package/lib/build/nodejs/install-node-modules.d.ts +4 -3
  24. package/lib/build/nodejs/install-node-modules.js +6 -6
  25. package/lib/cloud-formation/DeployStack.d.ts +11 -0
  26. package/lib/cloud-formation/DeployStack.js +2 -0
  27. package/lib/cloud-formation/create-stack.d.ts +20 -0
  28. package/lib/cloud-formation/create-stack.js +31 -0
  29. package/lib/cloud-formation/current-stack.d.ts +10 -0
  30. package/lib/cloud-formation/current-stack.js +19 -0
  31. package/lib/{generate-identifier.js → cloud-formation/generate-identifier.js} +7 -8
  32. package/lib/cloud-formation/index.d.ts +5 -0
  33. package/lib/cloud-formation/index.js +14 -0
  34. package/lib/cloud-formation/output.d.ts +2 -0
  35. package/lib/cloud-formation/output.js +12 -0
  36. package/lib/cloud-front/distribution.d.ts +16 -0
  37. package/lib/cloud-front/distribution.js +43 -0
  38. package/lib/cloud-front/index.d.ts +1 -0
  39. package/lib/cloud-front/index.js +5 -0
  40. package/lib/cloud-watch/create-log-group.js +4 -6
  41. package/lib/cloud-watch/index.d.ts +1 -0
  42. package/lib/cloud-watch/index.js +5 -0
  43. package/lib/cloud-watch/set-log-retention.d.ts +2 -0
  44. package/lib/cloud-watch/set-log-retention.js +14 -0
  45. package/lib/index.d.ts +11 -8
  46. package/lib/index.js +13 -29
  47. package/lib/lambda/create-function.d.ts +4 -2
  48. package/lib/lambda/create-function.js +15 -23
  49. package/lib/lambda/create-nodejs-lambda.d.ts +2 -2
  50. package/lib/lambda/create-nodejs-lambda.js +3 -4
  51. package/lib/lambda/index.d.ts +1 -0
  52. package/lib/lambda/index.js +5 -0
  53. package/lib/lambda-layer/apply-honeycomb-to-lambda.d.ts +1 -1
  54. package/lib/lambda-layer/apply-honeycomb-to-lambda.js +4 -5
  55. package/lib/lambda-layer/get-layer.js +4 -6
  56. package/lib/lambda-layer/index.d.ts +2 -0
  57. package/lib/lambda-layer/index.js +7 -0
  58. package/lib/lambda-layer/layer-cache.d.ts +3 -3
  59. package/lib/lambda-layer/layer-cache.js +3 -9
  60. package/lib/load-configuration.d.ts +3 -8
  61. package/lib/load-configuration.js +20 -11
  62. package/lib/recipes/ICorsConfig.d.ts +5 -0
  63. package/lib/recipes/ICorsConfig.js +2 -0
  64. package/lib/recipes/index.d.ts +1 -0
  65. package/lib/recipes/index.js +5 -0
  66. package/lib/recipes/staticWebSite.d.ts +13 -0
  67. package/lib/recipes/staticWebSite.js +54 -0
  68. package/lib/route53/IDomainConfig.d.ts +7 -0
  69. package/lib/route53/IDomainConfig.js +2 -0
  70. package/lib/route53/IHostedZoneConfig.d.ts +5 -0
  71. package/lib/route53/IHostedZoneConfig.js +2 -0
  72. package/lib/route53/apiCertificate.d.ts +13 -0
  73. package/lib/route53/apiCertificate.js +30 -0
  74. package/lib/route53/index.d.ts +3 -0
  75. package/lib/route53/index.js +5 -0
  76. package/lib/s3/bucket.d.ts +8 -0
  77. package/lib/s3/bucket.js +21 -0
  78. package/lib/s3/index.d.ts +1 -0
  79. package/lib/s3/index.js +5 -0
  80. package/lib/ssm/SsmParameter.d.ts +2 -2
  81. package/lib/ssm/StringParameter.d.ts +9 -0
  82. package/lib/ssm/StringParameter.js +15 -0
  83. package/lib/ssm/get-existing-parameter.js +4 -6
  84. package/lib/ssm/grant-read.js +1 -2
  85. package/lib/ssm/index.d.ts +1 -0
  86. package/lib/ssm/index.js +3 -1
  87. package/lib/ssm/parameter-cache.js +2 -3
  88. package/lib/ssm/string-value.js +1 -2
  89. package/lib/tools/index.d.ts +3 -0
  90. package/lib/tools/index.js +10 -0
  91. package/package.json +21 -15
  92. package/tsconfig.json +2 -2
  93. package/.fleet/run.json +0 -11
  94. package/archive/ApiAttachPoint.ts +0 -9
  95. package/archive/ApiCertificate.ts +0 -32
  96. package/archive/CognitoApiGatewayAuthorizer.ts +0 -25
  97. package/archive/DynamoDbTable.ts +0 -40
  98. package/archive/ICorsConfig.ts +0 -5
  99. package/archive/IDomainConfig.ts +0 -8
  100. package/archive/IHostedZoneConfig.ts +0 -5
  101. package/archive/NodeJsLambdaLayer.ts +0 -42
  102. package/archive/Output.ts +0 -11
  103. package/archive/RestApi.ts +0 -180
  104. package/archive/Role.ts +0 -165
  105. package/archive/StaticWebSite.ts +0 -158
  106. package/archive/index.ts +0 -18
  107. package/archive/methods/apply-schema-to-method-options.ts +0 -38
  108. package/archive/methods/attach-function-to-api.ts +0 -69
  109. package/lib/create-stack.d.ts +0 -40
  110. package/lib/create-stack.js +0 -48
  111. /package/lib/{generate-identifier.d.ts → cloud-formation/generate-identifier.d.ts} +0 -0
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLayer = exports.applyHoneycombToLambda = void 0;
4
+ var apply_honeycomb_to_lambda_1 = require("./apply-honeycomb-to-lambda");
5
+ Object.defineProperty(exports, "applyHoneycombToLambda", { enumerable: true, get: function () { return apply_honeycomb_to_lambda_1.applyHoneycombToLambda; } });
6
+ var get_layer_1 = require("./get-layer");
7
+ Object.defineProperty(exports, "getLayer", { enumerable: true, get: function () { return get_layer_1.getLayer; } });
@@ -1,3 +1,3 @@
1
- import { ILayerVersion } from "aws-cdk-lib/aws-lambda";
2
- export declare function get(name: string): ILayerVersion;
3
- export declare function store(name: string, param: ILayerVersion): void;
1
+ import type { ILayerVersion } from "aws-cdk-lib/aws-lambda";
2
+ export declare const get: (key: string) => ILayerVersion | undefined;
3
+ export declare const store: (key: string, value: ILayerVersion) => Map<string, ILayerVersion>;
@@ -1,12 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.store = exports.get = void 0;
4
- const layerCache = {};
5
- function get(name) {
6
- return layerCache[name];
7
- }
8
- exports.get = get;
9
- function store(name, param) {
10
- layerCache[name] = param;
11
- }
12
- exports.store = store;
4
+ const layerCache = new Map();
5
+ exports.get = layerCache.get;
6
+ exports.store = layerCache.set;
@@ -1,12 +1,7 @@
1
- /**
2
- * Interface for the stack configuration.
3
- */
4
- export interface StackConfiguration {
5
- }
6
1
  /**
7
2
  * Loads the configuration for a given stage.
8
3
  * If the configuration file does not exist, an empty object is returned.
9
- * @param {string} stage - The stage for which to load the configuration. Defaults to the value of the STAGE environment variable, or "develop" if STAGE is not set.
10
- * @returns {StackConfiguration} The loaded configuration.
4
+ * @param stage - The stage for which to load the configuration. Defaults to the value of the STAGE environment variable, or "develop" if STAGE is not set.
5
+ * @returns The loaded configuration.
11
6
  */
12
- export declare function loadConfiguration<T extends StackConfiguration>(stage?: string): Partial<T>;
7
+ export declare function loadConfiguration<T extends object>(stage?: string): T;
@@ -15,22 +15,32 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.loadConfiguration = void 0;
36
+ exports.loadConfiguration = loadConfiguration;
27
37
  const yaml = __importStar(require("js-yaml"));
28
38
  const fs = __importStar(require("fs-extra"));
29
39
  /**
30
40
  * Loads the configuration for a given stage.
31
41
  * If the configuration file does not exist, an empty object is returned.
32
- * @param {string} stage - The stage for which to load the configuration. Defaults to the value of the STAGE environment variable, or "develop" if STAGE is not set.
33
- * @returns {StackConfiguration} The loaded configuration.
42
+ * @param stage - The stage for which to load the configuration. Defaults to the value of the STAGE environment variable, or "develop" if STAGE is not set.
43
+ * @returns The loaded configuration.
34
44
  */
35
45
  function loadConfiguration(stage = process.env.STAGE || "develop") {
36
46
  const path = `config/${stage}.yml`;
@@ -39,4 +49,3 @@ function loadConfiguration(stage = process.env.STAGE || "develop") {
39
49
  }
40
50
  return {};
41
51
  }
42
- exports.loadConfiguration = loadConfiguration;
@@ -0,0 +1,5 @@
1
+ export interface ICorsConfig {
2
+ maxAge?: number;
3
+ exposeHeaders?: string[];
4
+ allowOrigin?: string | string[];
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export { staticWebSite } from './staticWebSite';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.staticWebSite = void 0;
4
+ var staticWebSite_1 = require("./staticWebSite");
5
+ Object.defineProperty(exports, "staticWebSite", { enumerable: true, get: function () { return staticWebSite_1.staticWebSite; } });
@@ -0,0 +1,13 @@
1
+ import { type IDomainConfig } from "../route53";
2
+ /**
3
+ * Configuration interface for the StaticWebSite class.
4
+ */
5
+ export interface StaticWebSiteConfig {
6
+ domain: IDomainConfig;
7
+ env?: NodeJS.ProcessEnv;
8
+ shouldCache?: boolean;
9
+ }
10
+ /**
11
+ * Sets up a basic static website in AWS with an S3 Bucket, CloudFront Distribution, and Route53 A-Name Record.
12
+ */
13
+ export declare function staticWebSite(id: string, props: StaticWebSiteConfig): void;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.staticWebSite = staticWebSite;
4
+ const child_process_1 = require("child_process");
5
+ const aws_s3_deployment_1 = require("aws-cdk-lib/aws-s3-deployment");
6
+ const aws_route53_1 = require("aws-cdk-lib/aws-route53");
7
+ const aws_route53_targets_1 = require("aws-cdk-lib/aws-route53-targets");
8
+ const cloud_formation_1 = require("../cloud-formation");
9
+ const build_1 = require("../build");
10
+ const s3_1 = require("../s3");
11
+ const route53_1 = require("../route53");
12
+ const tools_1 = require("../tools");
13
+ const cloud_front_1 = require("../cloud-front");
14
+ /**
15
+ * Sets up a basic static website in AWS with an S3 Bucket, CloudFront Distribution, and Route53 A-Name Record.
16
+ */
17
+ function staticWebSite(id, props) {
18
+ console.log('Deploying Static Web Site', id);
19
+ const { stack } = (0, cloud_formation_1.getCurrentStack)();
20
+ const done = (0, tools_1.duration)();
21
+ const buildDir = (0, build_1.getBuildDirectory)('web', id);
22
+ const cwd = (0, build_1.getSourceDirectory)('web', id);
23
+ (0, child_process_1.spawnSync)('npm i', { cwd });
24
+ console.log('Building UI Source', id);
25
+ (0, child_process_1.spawnSync)('npm run export', { cwd });
26
+ console.log('Total Build Duration (ms)', done());
27
+ const certificate = (0, route53_1.apiCertificate)(id + '-certificate', props.domain);
28
+ const s3BucketSource = (0, s3_1.createBucket)(`${id}-content`, {
29
+ bucketName: certificate.domain
30
+ });
31
+ const distribution = (0, cloud_front_1.createDistribution)(id, {
32
+ shouldCache: props.shouldCache,
33
+ s3BucketSource,
34
+ certificate,
35
+ errorResponses: [{
36
+ httpStatus: 404,
37
+ responseHttpStatus: 200,
38
+ responsePagePath: '/index.html'
39
+ }]
40
+ });
41
+ new aws_s3_deployment_1.BucketDeployment(stack, (0, cloud_formation_1.genId)(id, 'bucket-deployment'), {
42
+ sources: [aws_s3_deployment_1.Source.asset(buildDir)],
43
+ destinationBucket: s3BucketSource,
44
+ distribution,
45
+ distributionPaths: props.shouldCache ? ['/*'] : undefined,
46
+ memoryLimit: 2048
47
+ });
48
+ console.log('Configuring Route53 A-Name Record', props.domain.domainName);
49
+ new aws_route53_1.ARecord(stack, (0, cloud_formation_1.genId)('alias'), {
50
+ zone: certificate.hostedZone,
51
+ recordName: certificate.domain,
52
+ target: aws_route53_1.RecordTarget.fromAlias(new aws_route53_targets_1.CloudFrontTarget(distribution))
53
+ });
54
+ }
@@ -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,13 @@
1
+ import { Certificate } from "aws-cdk-lib/aws-certificatemanager";
2
+ import { IHostedZone } from "aws-cdk-lib/aws-route53";
3
+ import IDomainConfig from "./IDomainConfig";
4
+ export interface CertificateDetails {
5
+ domain: string;
6
+ hostedZone: IHostedZone;
7
+ certificate: Certificate;
8
+ }
9
+ export declare function apiCertificate(id: string, domain: IDomainConfig): {
10
+ domain: string;
11
+ hostedZone: IHostedZone;
12
+ certificate: Certificate;
13
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apiCertificate = apiCertificate;
4
+ const aws_certificatemanager_1 = require("aws-cdk-lib/aws-certificatemanager");
5
+ const aws_route53_1 = require("aws-cdk-lib/aws-route53");
6
+ const cloud_formation_1 = require("../cloud-formation");
7
+ function apiCertificate(id, domain) {
8
+ console.log('Defining HTTPS Certificate', id + '-certificate');
9
+ const { stack } = (0, cloud_formation_1.getCurrentStack)();
10
+ const certDomain = [domain.domainName];
11
+ if (domain.subdomain)
12
+ certDomain.splice(0, 0, domain.subdomain);
13
+ const domainName = certDomain.join('.');
14
+ console.log('Getting Hosted Zone', domain.hostedZone.name);
15
+ const hostedZone = aws_route53_1.HostedZone.fromHostedZoneAttributes(stack, (0, cloud_formation_1.genId)(id, 'hosted-zone'), {
16
+ hostedZoneId: domain.hostedZone.id,
17
+ zoneName: domain.hostedZone.name
18
+ });
19
+ console.log('Defining Certificate For', domainName);
20
+ const certificate = new aws_certificatemanager_1.Certificate(stack, (0, cloud_formation_1.genId)(id), {
21
+ domainName,
22
+ validation: aws_certificatemanager_1.CertificateValidation.fromDns(hostedZone)
23
+ });
24
+ (0, cloud_formation_1.output)(id, certificate.certificateArn);
25
+ return {
26
+ domain: domainName,
27
+ hostedZone,
28
+ certificate
29
+ };
30
+ }
@@ -0,0 +1,3 @@
1
+ export { apiCertificate, type CertificateDetails } from './apiCertificate';
2
+ export { IDomainConfig } from './IDomainConfig';
3
+ export { IHostedZoneConfig } from './IHostedZoneConfig';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apiCertificate = void 0;
4
+ var apiCertificate_1 = require("./apiCertificate");
5
+ Object.defineProperty(exports, "apiCertificate", { enumerable: true, get: function () { return apiCertificate_1.apiCertificate; } });
@@ -0,0 +1,8 @@
1
+ import { Bucket } from "aws-cdk-lib/aws-s3";
2
+ import { RemovalPolicy } from "aws-cdk-lib";
3
+ export interface BucketConfig {
4
+ bucketName: string;
5
+ versioned?: boolean;
6
+ removalPolicy?: RemovalPolicy;
7
+ }
8
+ export declare function createBucket(id: string, config?: BucketConfig): Bucket;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createBucket = createBucket;
4
+ const aws_s3_1 = require("aws-cdk-lib/aws-s3");
5
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
6
+ const cloud_formation_1 = require("../cloud-formation");
7
+ function createBucket(id, config) {
8
+ console.log('Defining S3 Bucket', (0, cloud_formation_1.genId)(id, "bucket"));
9
+ const bucket = new aws_s3_1.Bucket((0, cloud_formation_1.getCurrentStack)().stack, (0, cloud_formation_1.genId)(id, 'bucket'), {
10
+ bucketName: config?.bucketName ?? (0, cloud_formation_1.genName)(id, 'bucket'),
11
+ blockPublicAccess: aws_s3_1.BlockPublicAccess.BLOCK_ALL,
12
+ accessControl: aws_s3_1.BucketAccessControl.PRIVATE,
13
+ publicReadAccess: false,
14
+ removalPolicy: config?.removalPolicy ?? aws_cdk_lib_1.RemovalPolicy.DESTROY,
15
+ autoDeleteObjects: true,
16
+ enforceSSL: true,
17
+ versioned: config?.versioned ?? false
18
+ });
19
+ (0, cloud_formation_1.output)((0, cloud_formation_1.genName)(id, 'bucket'), bucket.bucketName);
20
+ return bucket;
21
+ }
@@ -0,0 +1 @@
1
+ export { createBucket } from './bucket';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createBucket = void 0;
4
+ var bucket_1 = require("./bucket");
5
+ Object.defineProperty(exports, "createBucket", { enumerable: true, get: function () { return bucket_1.createBucket; } });
@@ -1,5 +1,5 @@
1
- import { IStringParameter } from "aws-cdk-lib/aws-ssm";
2
- import { IKey } from "aws-cdk-lib/aws-kms";
1
+ import type { IStringParameter } from "aws-cdk-lib/aws-ssm";
2
+ import type { IKey } from "aws-cdk-lib/aws-kms";
3
3
  export interface SsmParameterOptions {
4
4
  decryptWithKey?: IKey;
5
5
  parameterGroup?: string;
@@ -0,0 +1,9 @@
1
+ import { Construct, type IConstruct } from "constructs";
2
+ export interface StringParameterProps {
3
+ readonly stringValue: string;
4
+ }
5
+ export declare class StringParameter extends Construct {
6
+ stringValue: string;
7
+ static fromStringParameterName(scope: IConstruct, id: string, parameterName: string): StringParameter;
8
+ constructor(scope: IConstruct, id: string, props: StringParameterProps);
9
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringParameter = void 0;
4
+ const constructs_1 = require("constructs");
5
+ class StringParameter extends constructs_1.Construct {
6
+ stringValue;
7
+ static fromStringParameterName(scope, id, parameterName) {
8
+ return new StringParameter(scope, id, { stringValue: parameterName });
9
+ }
10
+ constructor(scope, id, props) {
11
+ super(scope, id);
12
+ this.stringValue = props.stringValue;
13
+ }
14
+ }
15
+ exports.StringParameter = StringParameter;
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getExistingParameter = void 0;
3
+ exports.getExistingParameter = getExistingParameter;
4
4
  const aws_ssm_1 = require("aws-cdk-lib/aws-ssm");
5
5
  const parameter_cache_1 = require("./parameter-cache");
6
- const create_stack_1 = require("../create-stack");
7
- const generate_identifier_1 = require("../generate-identifier");
6
+ const cloud_formation_1 = require("../cloud-formation");
8
7
  /**
9
8
  * Retrieves an existing SSM parameter.
10
9
  * If the parameter is not in the cache, it references the parameter and stores it in the cache.
@@ -20,7 +19,6 @@ function getExistingParameter(name, options) {
20
19
  }
21
20
  return param;
22
21
  }
23
- exports.getExistingParameter = getExistingParameter;
24
22
  /**
25
23
  * References an SSM parameter and returns it.
26
24
  * @param {string} name - The name of the parameter.
@@ -30,12 +28,12 @@ exports.getExistingParameter = getExistingParameter;
30
28
  function referenceParameter(name, options) {
31
29
  if (name[0] !== '/')
32
30
  name = '/' + name;
33
- const { stack } = (0, create_stack_1.getCurrentStack)();
31
+ const { stack } = (0, cloud_formation_1.getCurrentStack)();
34
32
  const parameterName = `/${options?.parameterGroup ?? stack.stackName}${name}`;
35
33
  return {
36
34
  shortName: name,
37
35
  parameterArn: `arn:aws:ssm:${stack.region}:${stack.account}:parameter${parameterName}`,
38
36
  decryptWithKey: options?.decryptWithKey,
39
- parameter: aws_ssm_1.StringParameter.fromStringParameterName(stack, (0, generate_identifier_1.genStackResourceId)(parameterName), parameterName)
37
+ parameter: aws_ssm_1.StringParameter.fromStringParameterName(stack, (0, cloud_formation_1.genStackResourceId)(parameterName), parameterName)
40
38
  };
41
39
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.grantRead = void 0;
3
+ exports.grantRead = grantRead;
4
4
  const aws_iam_1 = require("aws-cdk-lib/aws-iam");
5
5
  const parameter_cache_1 = require("./parameter-cache");
6
6
  /**
@@ -21,4 +21,3 @@ function grantRead(name, grantee) {
21
21
  if (grantor.decryptWithKey)
22
22
  grantor.decryptWithKey.grantDecrypt(grantee);
23
23
  }
24
- exports.grantRead = grantRead;
@@ -1,3 +1,4 @@
1
+ export { StringParameter } from "aws-cdk-lib/aws-ssm";
1
2
  export { getExistingParameter } from './get-existing-parameter';
2
3
  export { grantRead } from './grant-read';
3
4
  export { stringValue } from './string-value';
package/lib/ssm/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringValue = exports.grantRead = exports.getExistingParameter = void 0;
3
+ exports.stringValue = exports.grantRead = exports.getExistingParameter = exports.StringParameter = void 0;
4
+ var aws_ssm_1 = require("aws-cdk-lib/aws-ssm");
5
+ Object.defineProperty(exports, "StringParameter", { enumerable: true, get: function () { return aws_ssm_1.StringParameter; } });
4
6
  var get_existing_parameter_1 = require("./get-existing-parameter");
5
7
  Object.defineProperty(exports, "getExistingParameter", { enumerable: true, get: function () { return get_existing_parameter_1.getExistingParameter; } });
6
8
  var grant_read_1 = require("./grant-read");
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.store = exports.get = void 0;
3
+ exports.get = get;
4
+ exports.store = store;
4
5
  // Cache for storing SSM parameters
5
6
  const paramCache = {};
6
7
  /**
@@ -11,7 +12,6 @@ const paramCache = {};
11
12
  function get(name) {
12
13
  return paramCache[name];
13
14
  }
14
- exports.get = get;
15
15
  /**
16
16
  * Stores an SSM parameter in the cache.
17
17
  * @param {string} name - The name of the SSM parameter.
@@ -20,4 +20,3 @@ exports.get = get;
20
20
  function store(name, param) {
21
21
  paramCache[name] = param;
22
22
  }
23
- exports.store = store;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringValue = void 0;
3
+ exports.stringValue = stringValue;
4
4
  const get_existing_parameter_1 = require("./get-existing-parameter");
5
5
  /**
6
6
  * Retrieves the string value of an existing SSM parameter.
@@ -11,4 +11,3 @@ const get_existing_parameter_1 = require("./get-existing-parameter");
11
11
  function stringValue(name, options) {
12
12
  return (0, get_existing_parameter_1.getExistingParameter)(name, options).parameter.stringValue;
13
13
  }
14
- exports.stringValue = stringValue;
@@ -0,0 +1,3 @@
1
+ import duration from './duration';
2
+ export { hrDuration } from './duration';
3
+ export { duration };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.duration = exports.hrDuration = void 0;
7
+ const duration_1 = __importDefault(require("./duration"));
8
+ exports.duration = duration_1.default;
9
+ var duration_2 = require("./duration");
10
+ Object.defineProperty(exports, "hrDuration", { enumerable: true, get: function () { return duration_2.hrDuration; } });
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@byaga/cdk-patterns",
3
- "version": "0.11.5",
3
+ "version": "0.11.7",
4
4
  "description": "Collection of common patterns used when making AWS CloudFormation templates using CDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "scripts": {
8
8
  "clean": "rimraf ./lib",
9
- "build": "npm run clean && tsc",
10
- "lint": "eslint . --ext .ts",
9
+ "build": "npm run clean && tsc -p tsconfig.json",
10
+ "lint": "eslint src",
11
11
  "test": "jest ./src",
12
12
  "preversion": "npm run lint && npm test && npm run build"
13
13
  },
@@ -19,28 +19,34 @@
19
19
  "author": "VeryFineHat",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "aws-cdk": "^2.122.0",
23
- "aws-cdk-lib": "^2.122.0",
24
- "constructs": "^10.3.0",
22
+ "aws-cdk": "^2.173.1",
23
+ "aws-cdk-lib": "^2.173.1",
24
+ "constructs": "^10.4.2",
25
25
  "fs-extra": "^11.2.0",
26
- "glob": "^10.3.10",
27
- "ignore": "^5.3.0",
26
+ "glob": "^11.0.0",
27
+ "ignore": "^6.0.2",
28
28
  "js-yaml": "^4.1.0"
29
29
  },
30
30
  "devDependencies": {
31
+ "@eslint/js": "^9.17.0",
31
32
  "@types/fs-extra": "^11.0.4",
32
33
  "@types/glob": "^8.1.0",
33
- "@types/jest": "^29.5.11",
34
+ "@types/jest": "^29.5.14",
34
35
  "@types/js-yaml": "^4.0.9",
35
- "@types/node": "^20.11.5",
36
- "@typescript-eslint/eslint-plugin": "^6.19.0",
37
- "@typescript-eslint/parser": "^6.19.0",
38
- "eslint": "^8.56.0",
36
+ "@types/node": "^22.10.2",
37
+ "eslint": "^9.17.0",
38
+ "globals": "^15.13.0",
39
39
  "jest": "^29.7.0",
40
40
  "jest-html-reporters": "^3.1.7",
41
41
  "jest-junit": "^16.0.0",
42
- "ts-jest": "^29.1.1",
43
- "typescript": "^5.3.3"
42
+ "rimraf": "^6.0.1",
43
+ "ts-jest": "^29.2.5",
44
+ "ts-node": "^10.9.2",
45
+ "typescript": "^5.7.2",
46
+ "typescript-eslint": "^8.18.1"
47
+ },
48
+ "exports": {
49
+ ".": "./lib/index.js"
44
50
  },
45
51
  "repository": {
46
52
  "type": "git",
package/tsconfig.json CHANGED
@@ -30,6 +30,6 @@
30
30
  "./node_modules/@types"
31
31
  ]
32
32
  },
33
- "include": ["src/**/*"],
34
- "exclude": [ "node_modules", "*.spec.ts" ]
33
+ "include": ["src/**/*.ts"],
34
+ "exclude": [ "node_modules", "**/*.spec.ts", "**/__mocks__" ]
35
35
  }
package/.fleet/run.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "configurations": [
3
- {
4
- "type": "npm",
5
- "name": "cdk-patterns build",
6
- "command": "run",
7
- "scripts": "build",
8
- },
9
-
10
- ]
11
- }
@@ -1,9 +0,0 @@
1
- import { Method } from "aws-cdk-lib/aws-apigateway";
2
-
3
- /**
4
- * Interface for the API attach point.
5
- */
6
- export interface ApiAttachPoint {
7
- method: Method
8
- resourceArn: string
9
- }
@@ -1,32 +0,0 @@
1
- import {Certificate, CertificateValidation} from "aws-cdk-lib/aws-certificatemanager";
2
- import {HostedZone, IHostedZone} from "aws-cdk-lib/aws-route53";
3
- import {Output} from "./Output";
4
- import DeployStack from "./DeployStack";
5
- import IDomainConfig from "./IDomainConfig";
6
-
7
- export class ApiCertificate extends Certificate {
8
- hostedZone: IHostedZone
9
- domain: string
10
-
11
- constructor(stack: DeployStack, id: string, domain: IDomainConfig) {
12
- const certDomain = [domain.domainName]
13
- if (domain.subdomain) certDomain.splice(0, 0, domain.subdomain)
14
- const domainName = certDomain.join('.')
15
-
16
- console.log('Getting Hosted Zone', domain.hostedZone.name)
17
- const hostedZone: IHostedZone = HostedZone.fromHostedZoneAttributes(stack, stack.genId(id, 'hosted-zone'), {
18
- hostedZoneId: domain.hostedZone.id,
19
- zoneName: domain.hostedZone.name
20
- })
21
- console.log('Defining Certificate For', domainName)
22
- super(stack, stack.genId(id), {
23
- domainName,
24
- validation: CertificateValidation.fromDns(hostedZone)
25
- });
26
-
27
- this.domain = domainName
28
- new Output(stack, id, this.certificateArn)
29
- this.hostedZone = hostedZone
30
- }
31
- }
32
- export default ApiCertificate
@@ -1,25 +0,0 @@
1
- import { Construct } from 'constructs'
2
- import { CfnAuthorizer, IAuthorizer } from 'aws-cdk-lib/aws-apigateway'
3
- import { CfnAuthorizerProps } from 'aws-cdk-lib/aws-apigateway/lib/apigateway.generated'
4
-
5
- /**
6
- * Custom construct that implements a Cognito based API Gateway Authorizer.
7
- *
8
- * @see https://docs.aws.amazon.com/cdk/latest/guide/constructs.html#constructs_author
9
- *
10
- * @see https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.CfnAuthorizer.html
11
- * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-authorizer.html
12
- * @see https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-integrate-with-cognito.html
13
- * @see https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-enable-cognito-user-pool.html
14
- *
15
- * @see https://github.com/aws/aws-cdk/issues/5618#issuecomment-666922559
16
- */
17
- export class CognitoApiGatewayAuthorizer extends CfnAuthorizer implements IAuthorizer {
18
- public readonly authorizerId: string
19
-
20
- constructor(scope: Construct, id: string, props: CfnAuthorizerProps) {
21
- super(scope, id, props)
22
-
23
- this.authorizerId = this.ref
24
- }
25
- }