@fy-stack/apigateway-construct 0.0.125 → 0.0.127

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/README.md CHANGED
@@ -1,7 +1,20 @@
1
- # apigateway-construct
1
+ # API Gateway Construct Documentation
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ ## `ApiGatewayConstruct`
4
4
 
5
- ## Building
5
+ The `ApiGatewayConstruct` class is a custom AWS CDK construct that sets up an API Gateway with defined routes and integrations. The constructor initializes the API Gateway with default and additional integrations based on the provided properties. It also configures CORS to allow headers, origins, and methods from any source.
6
6
 
7
- Run `nx build apigateway-construct` to build the library.
7
+ - **Properties**
8
+ - `api: HttpApi`
9
+ - The API Gateway instance managed by this construct.
10
+
11
+ - **Constructor**
12
+ - `constructor(scope: Construct, id: string, props: ApiGatewayConstructProps)`
13
+ - Initializes the API Gateway construct with a unique identifier and configuration options defined by `ApiGatewayConstructProps`.
14
+ - **Parameters**
15
+ - `scope`: The scope in which this construct is defined.
16
+ - `id`: The unique identifier for this construct.
17
+ - `props`: Properties required to set up the API Gateway construct, including route mappings and resource configurations.
18
+
19
+ - **Error Handling**
20
+ - Throws an error if the base route or default integration is missing.
@@ -1,6 +1,14 @@
1
- import { HttpApi } from "aws-cdk-lib/aws-apigatewayv2";
1
+ import { HttpApi } from 'aws-cdk-lib/aws-apigatewayv2';
2
2
  import { Construct } from "constructs";
3
3
  import { ApiGatewayConstructProps } from "./types";
4
+ /**
5
+ * ApiGatewayConstruct is a construct class for creating an API Gateway with defined routes and integrations.
6
+ *
7
+ * The constructor initializes the API Gateway with default and additional integrations based on the provided props.
8
+ * It sets up CORS preflight options to allow headers, origins, and methods from any source.
9
+ *
10
+ * @throws {Error} Throws an error if the base route is not found.
11
+ */
4
12
  export declare class ApiGatewayConstruct extends Construct {
5
13
  readonly api: HttpApi;
6
14
  constructor(scope: Construct, id: string, props: ApiGatewayConstructProps);
@@ -1 +1 @@
1
- {"version":3,"file":"apigateway-construct.d.ts","sourceRoot":"","sources":["../../src/lib/apigateway-construct.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAc,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEnD,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,SAAgB,GAAG,EAAE,OAAO,CAAC;gBAEjB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,wBAAwB;CAuC1E"}
1
+ {"version":3,"file":"apigateway-construct.d.ts","sourceRoot":"","sources":["../../src/lib/apigateway-construct.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,OAAO,EAAc,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;GAOG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,SAAgB,GAAG,EAAE,OAAO,CAAC;gBAEjB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,wBAAwB;CA8C1E"}
@@ -3,6 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiGatewayConstruct = void 0;
4
4
  const aws_apigatewayv2_1 = require("aws-cdk-lib/aws-apigatewayv2");
5
5
  const constructs_1 = require("constructs");
6
+ /**
7
+ * ApiGatewayConstruct is a construct class for creating an API Gateway with defined routes and integrations.
8
+ *
9
+ * The constructor initializes the API Gateway with default and additional integrations based on the provided props.
10
+ * It sets up CORS preflight options to allow headers, origins, and methods from any source.
11
+ *
12
+ * @throws {Error} Throws an error if the base route is not found.
13
+ */
6
14
  class ApiGatewayConstruct extends constructs_1.Construct {
7
15
  api;
8
16
  constructor(scope, id, props) {
@@ -24,7 +32,14 @@ class ApiGatewayConstruct extends constructs_1.Construct {
24
32
  for (const i in otherRoutes) {
25
33
  Object.assign(additionalIntegrations, otherRoutes[i]?.api(i));
26
34
  }
27
- this.api = new aws_apigatewayv2_1.HttpApi(this, "Api", { defaultIntegration });
35
+ this.api = new aws_apigatewayv2_1.HttpApi(this, "Api", {
36
+ defaultIntegration,
37
+ corsPreflight: {
38
+ allowHeaders: ["*"],
39
+ allowOrigins: ["*"],
40
+ allowMethods: [aws_apigatewayv2_1.CorsHttpMethod.ANY],
41
+ }
42
+ });
28
43
  for (const i in additionalIntegrations) {
29
44
  this.api.addRoutes({
30
45
  integration: additionalIntegrations[i],
@@ -1,6 +1,15 @@
1
1
  import type { ApiResource, ResourceRef } from '@fy-stack/types';
2
2
  export type ApiGatewayConstructProps = {
3
+ /**
4
+ * A map of route names to their respective resource references.
5
+ * Each key in the record represents a unique route name, and the associated value is an instance of ResourceRef.
6
+ */
3
7
  routes: Record<string, ResourceRef>;
8
+ /**
9
+ * An optional object mapping resource names to their corresponding `ApiResource` objects.
10
+ * Each key in this object represents a unique resource identifier, and the associated
11
+ * value implements `ApiResource`
12
+ */
4
13
  resources?: Record<string, ApiResource | undefined>;
5
14
  };
6
15
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAC,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE/D,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC;CACrD,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAC,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE/D,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC;CACrD,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@fy-stack/apigateway-construct",
3
- "version": "0.0.125",
3
+ "version": "0.0.127",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.0",
6
- "@fy-stack/types": "0.0.125"
6
+ "@fy-stack/types": "0.0.127"
7
7
  },
8
8
  "peerDependencies": {
9
- "aws-cdk-lib": "2.164.1",
9
+ "aws-cdk-lib": "2.166.0",
10
10
  "constructs": "10.4.2"
11
11
  },
12
12
  "type": "commonjs",