@xube/kit-aws-hooks-infrastructure 0.0.22 → 0.0.24

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,3 @@
1
+ import { APIGatewayProxyResult, APIGatewayProxyWithCognitoAuthorizerEvent } from "aws-lambda";
2
+ export declare const webhookTableName: string;
3
+ export declare const handler: (event: APIGatewayProxyWithCognitoAuthorizerEvent) => Promise<APIGatewayProxyResult>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.webhookTableName = void 0;
4
+ const kit_aws_hooks_1 = require("@xube/kit-aws-hooks");
5
+ const kit_constants_1 = require("@xube/kit-constants");
6
+ const kit_log_1 = require("@xube/kit-log");
7
+ exports.webhookTableName = process.env.WEBHOOK_TABLE_NAME_ENV_VAR || "";
8
+ const handler = async (event) => {
9
+ if (!exports.webhookTableName) {
10
+ return {
11
+ body: `Could not find webhook table name in environment variables`,
12
+ statusCode: kit_constants_1.StatusCode.InternalError,
13
+ };
14
+ }
15
+ if (!event.body) {
16
+ return {
17
+ body: `No body provided`,
18
+ statusCode: kit_constants_1.StatusCode.BadRequest,
19
+ };
20
+ }
21
+ const request = JSON.parse(event.body);
22
+ if (!(0, kit_aws_hooks_1.isCreateWebhookForAccountRequest)(request)) {
23
+ return {
24
+ body: `Request body is not a valid Webhook Endpoint creation request`,
25
+ statusCode: kit_constants_1.StatusCode.BadRequest,
26
+ };
27
+ }
28
+ const response = await (0, kit_aws_hooks_1.createWebhookForAccount)(request, exports.webhookTableName, kit_log_1.XubeLog.getInstance());
29
+ return {
30
+ body: JSON.stringify(response),
31
+ statusCode: response.statusCode,
32
+ };
33
+ };
34
+ exports.handler = handler;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,2 @@
1
+ export * from "./webhook-management";
2
+ export * from "./functions/add-webhook-endpoints";
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./webhook-management"), exports);
18
+ __exportStar(require("./functions/add-webhook-endpoints"), exports);
19
+ // export * from "./functions/get-webhook-endpoints";
20
+ // export * from "./functions/remove-webhook-endpoints";
@@ -3,22 +3,22 @@ import { ICertificate } from "aws-cdk-lib/aws-certificatemanager";
3
3
  import { ITable } from "aws-cdk-lib/aws-dynamodb";
4
4
  import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
5
5
  import { Construct } from "constructs";
6
- export declare const ADD_WEBHOOK_ENDPOINT_FUNCTION_NAME = "add-webhook-endpoint";
7
- export declare const REMOVE_WEBHOOK_ENDPOINT_FUNCTION_NAME = "remove-webhook-endpoint";
6
+ export declare const ADD_WEBHOOK_ENDPOINTS_FUNCTION_NAME = "add-webhook-endpoints";
7
+ export declare const REMOVE_WEBHOOK_ENDPOINTS_FUNCTION_NAME = "remove-webhook-endpoints";
8
8
  export declare const GET_WEBHOOK_ENDPOINTS_FUNCTION_NAME = "get-webhook-endpoints";
9
9
  export interface WebhookManagementProps {
10
10
  table?: ITable;
11
11
  name?: string;
12
- domainName: IDomainName;
13
- certificate: ICertificate;
14
- authorizer: IAuthorizer;
12
+ domainName?: IDomainName;
13
+ certificate?: ICertificate;
14
+ authorizer?: IAuthorizer;
15
15
  basePath?: string;
16
16
  stage?: string;
17
17
  corsOptions?: CorsOptions;
18
18
  }
19
19
  export declare class WebhookManagement extends Construct {
20
20
  table: ITable;
21
- addWebhookEndpoint: NodejsFunction;
21
+ addWebhookEndpoints: NodejsFunction;
22
22
  removeWebhookEndpoint: NodejsFunction;
23
23
  getWebhookEndpoints: NodejsFunction;
24
24
  webhookAPI: RestApi;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebhookManagement = exports.GET_WEBHOOK_ENDPOINTS_FUNCTION_NAME = exports.REMOVE_WEBHOOK_ENDPOINT_FUNCTION_NAME = exports.ADD_WEBHOOK_ENDPOINT_FUNCTION_NAME = void 0;
3
+ exports.WebhookManagement = exports.GET_WEBHOOK_ENDPOINTS_FUNCTION_NAME = exports.REMOVE_WEBHOOK_ENDPOINTS_FUNCTION_NAME = exports.ADD_WEBHOOK_ENDPOINTS_FUNCTION_NAME = void 0;
4
4
  const kit_aws_1 = require("@xube/kit-aws");
5
5
  const kit_aws_2 = require("@xube/kit-aws");
6
6
  const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
@@ -8,12 +8,12 @@ const aws_dynamodb_1 = require("aws-cdk-lib/aws-dynamodb");
8
8
  const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
9
9
  const aws_lambda_nodejs_1 = require("aws-cdk-lib/aws-lambda-nodejs");
10
10
  const constructs_1 = require("constructs");
11
- exports.ADD_WEBHOOK_ENDPOINT_FUNCTION_NAME = "add-webhook-endpoint";
12
- exports.REMOVE_WEBHOOK_ENDPOINT_FUNCTION_NAME = "remove-webhook-endpoint";
11
+ exports.ADD_WEBHOOK_ENDPOINTS_FUNCTION_NAME = "add-webhook-endpoints";
12
+ exports.REMOVE_WEBHOOK_ENDPOINTS_FUNCTION_NAME = "remove-webhook-endpoints";
13
13
  exports.GET_WEBHOOK_ENDPOINTS_FUNCTION_NAME = "get-webhook-endpoints";
14
14
  class WebhookManagement extends constructs_1.Construct {
15
15
  table;
16
- addWebhookEndpoint;
16
+ addWebhookEndpoints;
17
17
  removeWebhookEndpoint;
18
18
  getWebhookEndpoints;
19
19
  webhookAPI;
@@ -32,16 +32,16 @@ class WebhookManagement extends constructs_1.Construct {
32
32
  type: aws_dynamodb_1.AttributeType.STRING,
33
33
  },
34
34
  });
35
- this.addWebhookEndpoint = new aws_lambda_nodejs_1.NodejsFunction(this, id + "-add-hook-function", {
36
- entry: __dirname + "./functions/" + exports.ADD_WEBHOOK_ENDPOINT_FUNCTION_NAME,
37
- functionName: (props.name ?? "webhook") + "-add-hook",
35
+ this.addWebhookEndpoints = new aws_lambda_nodejs_1.NodejsFunction(this, id + "-add-hooks-function", {
36
+ entry: __dirname + "./functions/" + exports.ADD_WEBHOOK_ENDPOINTS_FUNCTION_NAME,
37
+ functionName: (props.name ?? "webhook") + "-add-hooks",
38
38
  environment: {
39
39
  WEBHOOK_TABLE_NAME_ENV_VAR: this.table.tableName,
40
40
  },
41
41
  });
42
- this.removeWebhookEndpoint = new aws_lambda_nodejs_1.NodejsFunction(this, id + "-remove-hook-function", {
43
- entry: __dirname + "./functions/" + exports.REMOVE_WEBHOOK_ENDPOINT_FUNCTION_NAME,
44
- functionName: (props.name ?? "webhook") + "-remove-hook",
42
+ this.removeWebhookEndpoint = new aws_lambda_nodejs_1.NodejsFunction(this, id + "-remove-hooks-function", {
43
+ entry: __dirname + "./functions/" + exports.REMOVE_WEBHOOK_ENDPOINTS_FUNCTION_NAME,
44
+ functionName: (props.name ?? "webhook") + "-remove-hooks",
45
45
  environment: {
46
46
  WEBHOOK_TABLE_NAME_ENV_VAR: this.table.tableName,
47
47
  },
@@ -60,7 +60,8 @@ class WebhookManagement extends constructs_1.Construct {
60
60
  allowHeaders: ["*"],
61
61
  allowMethods: ["*"],
62
62
  },
63
- domainName: {
63
+ domainName: props.domainName &&
64
+ props.certificate && {
64
65
  domainName: props.domainName.domainName,
65
66
  certificate: props.certificate,
66
67
  basePath: props.basePath ?? "webhooks",
@@ -73,12 +74,12 @@ class WebhookManagement extends constructs_1.Construct {
73
74
  stageName: props.stage ?? "production",
74
75
  },
75
76
  });
76
- const addWebhookEndpointTarget = new aws_apigateway_1.LambdaIntegration(this.addWebhookEndpoint);
77
- const removeWebhookEndpointTarget = new aws_apigateway_1.LambdaIntegration(this.removeWebhookEndpoint);
77
+ const addWebhookEndpointsTarget = new aws_apigateway_1.LambdaIntegration(this.addWebhookEndpoints);
78
+ const removeWebhookEndpointsTarget = new aws_apigateway_1.LambdaIntegration(this.removeWebhookEndpoint);
78
79
  const getWebhookEndpointsTarget = new aws_apigateway_1.LambdaIntegration(this.getWebhookEndpoints);
79
80
  this.webhookAPI.root.addMethod(aws_lambda_1.HttpMethod.GET, getWebhookEndpointsTarget);
80
- this.webhookAPI.root.addMethod(aws_lambda_1.HttpMethod.POST, addWebhookEndpointTarget);
81
- this.webhookAPI.root.addMethod(aws_lambda_1.HttpMethod.DELETE, removeWebhookEndpointTarget);
81
+ this.webhookAPI.root.addMethod(aws_lambda_1.HttpMethod.POST, addWebhookEndpointsTarget);
82
+ this.webhookAPI.root.addMethod(aws_lambda_1.HttpMethod.DELETE, removeWebhookEndpointsTarget);
82
83
  }
83
84
  }
84
85
  exports.WebhookManagement = WebhookManagement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xube/kit-aws-hooks-infrastructure",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -17,14 +17,14 @@
17
17
  },
18
18
  "homepage": "https://github.com/XubeLtd/dev-kit#readme",
19
19
  "devDependencies": {
20
- "@xube/kit-build": "^0.0.22"
20
+ "@xube/kit-build": "^0.0.24"
21
21
  },
22
22
  "dependencies": {
23
- "@xube/kit-aws": "^0.0.22",
24
- "@xube/kit-aws-hooks": "^0.0.22",
25
- "@xube/kit-aws-infrastructure": "^0.0.22",
26
- "@xube/kit-constants": "^0.0.22",
27
- "@xube/kit-log": "^0.0.22",
23
+ "@xube/kit-aws": "^0.0.24",
24
+ "@xube/kit-aws-hooks": "^0.0.24",
25
+ "@xube/kit-aws-infrastructure": "^0.0.24",
26
+ "@xube/kit-constants": "^0.0.24",
27
+ "@xube/kit-log": "^0.0.24",
28
28
  "aws-cdk-lib": "^2.100.0",
29
29
  "aws-lambda": "^1.0.7",
30
30
  "constructs": "^10.3.0"
File without changes
File without changes
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./webhook-management";
2
+ export * from "./functions/add-webhook-endpoints";
3
+ // export * from "./functions/get-webhook-endpoints";
4
+ // export * from "./functions/remove-webhook-endpoints";
@@ -14,16 +14,17 @@ import { HttpMethod } from "aws-cdk-lib/aws-lambda";
14
14
  import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
15
15
  import { Construct } from "constructs";
16
16
 
17
- export const ADD_WEBHOOK_ENDPOINT_FUNCTION_NAME = "add-webhook-endpoint";
18
- export const REMOVE_WEBHOOK_ENDPOINT_FUNCTION_NAME = "remove-webhook-endpoint";
17
+ export const ADD_WEBHOOK_ENDPOINTS_FUNCTION_NAME = "add-webhook-endpoints";
18
+ export const REMOVE_WEBHOOK_ENDPOINTS_FUNCTION_NAME =
19
+ "remove-webhook-endpoints";
19
20
  export const GET_WEBHOOK_ENDPOINTS_FUNCTION_NAME = "get-webhook-endpoints";
20
21
 
21
22
  export interface WebhookManagementProps {
22
23
  table?: ITable;
23
24
  name?: string;
24
- domainName: IDomainName;
25
- certificate: ICertificate;
26
- authorizer: IAuthorizer;
25
+ domainName?: IDomainName;
26
+ certificate?: ICertificate;
27
+ authorizer?: IAuthorizer;
27
28
  basePath?: string;
28
29
  stage?: string;
29
30
  corsOptions?: CorsOptions;
@@ -31,7 +32,7 @@ export interface WebhookManagementProps {
31
32
 
32
33
  export class WebhookManagement extends Construct {
33
34
  table: ITable;
34
- addWebhookEndpoint: NodejsFunction;
35
+ addWebhookEndpoints: NodejsFunction;
35
36
  removeWebhookEndpoint: NodejsFunction;
36
37
  getWebhookEndpoints: NodejsFunction;
37
38
 
@@ -54,12 +55,12 @@ export class WebhookManagement extends Construct {
54
55
  },
55
56
  });
56
57
 
57
- this.addWebhookEndpoint = new NodejsFunction(
58
+ this.addWebhookEndpoints = new NodejsFunction(
58
59
  this,
59
- id + "-add-hook-function",
60
+ id + "-add-hooks-function",
60
61
  {
61
- entry: __dirname + "./functions/" + ADD_WEBHOOK_ENDPOINT_FUNCTION_NAME,
62
- functionName: (props.name ?? "webhook") + "-add-hook",
62
+ entry: __dirname + "./functions/" + ADD_WEBHOOK_ENDPOINTS_FUNCTION_NAME,
63
+ functionName: (props.name ?? "webhook") + "-add-hooks",
63
64
  environment: {
64
65
  WEBHOOK_TABLE_NAME_ENV_VAR: this.table.tableName,
65
66
  },
@@ -67,11 +68,11 @@ export class WebhookManagement extends Construct {
67
68
  );
68
69
  this.removeWebhookEndpoint = new NodejsFunction(
69
70
  this,
70
- id + "-remove-hook-function",
71
+ id + "-remove-hooks-function",
71
72
  {
72
73
  entry:
73
- __dirname + "./functions/" + REMOVE_WEBHOOK_ENDPOINT_FUNCTION_NAME,
74
- functionName: (props.name ?? "webhook") + "-remove-hook",
74
+ __dirname + "./functions/" + REMOVE_WEBHOOK_ENDPOINTS_FUNCTION_NAME,
75
+ functionName: (props.name ?? "webhook") + "-remove-hooks",
75
76
  environment: {
76
77
  WEBHOOK_TABLE_NAME_ENV_VAR: this.table.tableName,
77
78
  },
@@ -96,11 +97,12 @@ export class WebhookManagement extends Construct {
96
97
  allowHeaders: ["*"],
97
98
  allowMethods: ["*"],
98
99
  },
99
- domainName: {
100
- domainName: props.domainName.domainName,
101
- certificate: props.certificate,
102
- basePath: props.basePath ?? "webhooks",
103
- },
100
+ domainName: props.domainName &&
101
+ props.certificate && {
102
+ domainName: props.domainName.domainName,
103
+ certificate: props.certificate,
104
+ basePath: props.basePath ?? "webhooks",
105
+ },
104
106
  restApiName: props.name,
105
107
  defaultMethodOptions: {
106
108
  authorizer: props.authorizer,
@@ -110,11 +112,11 @@ export class WebhookManagement extends Construct {
110
112
  },
111
113
  });
112
114
 
113
- const addWebhookEndpointTarget = new LambdaIntegration(
114
- this.addWebhookEndpoint
115
+ const addWebhookEndpointsTarget = new LambdaIntegration(
116
+ this.addWebhookEndpoints
115
117
  );
116
118
 
117
- const removeWebhookEndpointTarget = new LambdaIntegration(
119
+ const removeWebhookEndpointsTarget = new LambdaIntegration(
118
120
  this.removeWebhookEndpoint
119
121
  );
120
122
 
@@ -123,10 +125,10 @@ export class WebhookManagement extends Construct {
123
125
  );
124
126
 
125
127
  this.webhookAPI.root.addMethod(HttpMethod.GET, getWebhookEndpointsTarget);
126
- this.webhookAPI.root.addMethod(HttpMethod.POST, addWebhookEndpointTarget);
128
+ this.webhookAPI.root.addMethod(HttpMethod.POST, addWebhookEndpointsTarget);
127
129
  this.webhookAPI.root.addMethod(
128
130
  HttpMethod.DELETE,
129
- removeWebhookEndpointTarget
131
+ removeWebhookEndpointsTarget
130
132
  );
131
133
  }
132
134
  }