@cumulusds/aws-apig-bypass 1.0.0 → 1.1.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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Bypass the API Gateway by directly invoking the Lambda handler that backs an endpoint.
4
4
 
5
- We often build externally accessible REST endpoints using API Gateway and Lambda. Sometimes we have an endpoint with both internal and external (outside of AWS) clients. The API Gateway provides some value to external clients, since it helps authorize and rate-limit requests. However, it is a hinderance to internal clients, where we have other means of rate-limiting. Access control is often more consistent if we rely on IAM policies. The API Gateway adds cost and reduces convenience for internal clients.
5
+ We often build externally accessible REST endpoints using API Gateway and Lambda. Sometimes we have an endpoint with both internal and external (outside of AWS) clients. The API Gateway provides some value to external clients, since it helps authorize and rate-limit requests. However, it is a hindrance to internal clients, where we have other means of rate-limiting. Access control is often more consistent if we rely on IAM policies. The API Gateway adds cost and reduces convenience for internal clients.
6
6
 
7
7
  This library provides an adapter for the Lambda SDK to make it easy to directly invoke the handler.
8
8
 
@@ -0,0 +1,54 @@
1
+ import type { APIGatewayEvent } from "aws-lambda";
2
+ export type PathParameters = {
3
+ [name: string]: string;
4
+ } | null;
5
+ export type QueryStringParameters = {
6
+ [name: string]: string;
7
+ } | null;
8
+ declare const defaultRequestContext: {
9
+ accountId: string;
10
+ apiId: string;
11
+ httpMethod: string;
12
+ identity: {
13
+ accessKey: null;
14
+ accountId: null;
15
+ apiKey: null;
16
+ caller: null;
17
+ cognitoAuthenticationProvider: null;
18
+ cognitoAuthenticationType: null;
19
+ cognitoIdentityId: null;
20
+ cognitoIdentityPoolId: null;
21
+ sourceIp: string;
22
+ user: null;
23
+ userAgent: null;
24
+ userArn: null;
25
+ };
26
+ stage: string;
27
+ requestId: string;
28
+ resourceId: string;
29
+ resourcePath: string;
30
+ };
31
+ export type CreateAPIGatewayEventOptions = {
32
+ body?: string | null;
33
+ headers?: {
34
+ [name: string]: string;
35
+ };
36
+ multiValueHeaders?: {
37
+ [name: string]: string[];
38
+ };
39
+ httpMethod?: string;
40
+ isBase64Encoded?: boolean;
41
+ path?: string;
42
+ pathParameters?: PathParameters;
43
+ queryStringParameters?: QueryStringParameters;
44
+ multiValueQueryStringParameters?: {
45
+ [name: string]: string[];
46
+ };
47
+ stageVariables?: {
48
+ [name: string]: string;
49
+ };
50
+ requestContext?: typeof defaultRequestContext;
51
+ resource?: string;
52
+ };
53
+ export default function createAPIGatewayEvent({ body, headers, multiValueHeaders, httpMethod, isBase64Encoded, pathParameters, path, queryStringParameters, multiValueQueryStringParameters, stageVariables, requestContext, resource, }?: CreateAPIGatewayEventOptions): APIGatewayEvent;
54
+ export {};
@@ -1,58 +1,42 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.default = createAPIGatewayEvent;
7
4
  const defaultRequestContext = {
8
- accountId: "",
9
- apiId: "",
10
- httpMethod: "",
11
- identity: {
12
- accessKey: null,
13
- accountId: null,
14
- apiKey: null,
15
- caller: null,
16
- cognitoAuthenticationProvider: null,
17
- cognitoAuthenticationType: null,
18
- cognitoIdentityId: null,
19
- cognitoIdentityPoolId: null,
20
- sourceIp: "",
21
- user: null,
22
- userAgent: null,
23
- userArn: null
24
- },
25
- stage: "",
26
- requestId: "",
27
- resourceId: "",
28
- resourcePath: ""
5
+ accountId: "",
6
+ apiId: "",
7
+ httpMethod: "",
8
+ identity: {
9
+ accessKey: null,
10
+ accountId: null,
11
+ apiKey: null,
12
+ caller: null,
13
+ cognitoAuthenticationProvider: null,
14
+ cognitoAuthenticationType: null,
15
+ cognitoIdentityId: null,
16
+ cognitoIdentityPoolId: null,
17
+ sourceIp: "",
18
+ user: null,
19
+ userAgent: null,
20
+ userArn: null,
21
+ },
22
+ stage: "",
23
+ requestId: "",
24
+ resourceId: "",
25
+ resourcePath: "",
29
26
  };
30
- function createAPIGatewayEvent({
31
- body = null,
32
- headers = {},
33
- multiValueHeaders = {},
34
- httpMethod = "",
35
- isBase64Encoded = false,
36
- pathParameters = null,
37
- path = "",
38
- queryStringParameters = null,
39
- multiValueQueryStringParameters = null,
40
- stageVariables = null,
41
- requestContext = defaultRequestContext,
42
- resource = ""
43
- } = {}) {
44
- return {
45
- body,
46
- headers,
47
- multiValueHeaders,
48
- httpMethod,
49
- isBase64Encoded,
50
- path,
51
- pathParameters,
52
- queryStringParameters,
53
- multiValueQueryStringParameters,
54
- stageVariables,
55
- requestContext,
56
- resource
57
- };
58
- }
27
+ function createAPIGatewayEvent({ body = null, headers = {}, multiValueHeaders = {}, httpMethod = "", isBase64Encoded = false, pathParameters = null, path = "", queryStringParameters = null, multiValueQueryStringParameters = {}, stageVariables = {}, requestContext = defaultRequestContext, resource = "", } = {}) {
28
+ return {
29
+ body,
30
+ headers,
31
+ multiValueHeaders,
32
+ httpMethod,
33
+ isBase64Encoded,
34
+ path,
35
+ pathParameters,
36
+ queryStringParameters,
37
+ multiValueQueryStringParameters,
38
+ stageVariables,
39
+ requestContext,
40
+ resource,
41
+ };
42
+ }
@@ -1,14 +1,21 @@
1
- // @flow
1
+ /**
2
+ * Flowtype definitions for create-api-gateway-event
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
2
7
 
3
- import type { APIGatewayEvent } from "@cumulusds/flow-aws-lambda";
4
-
5
- export type PathParameters = { [name: string]: string } | null;
6
- export type QueryStringParameters = { [name: string]: string } | null;
7
-
8
- const defaultRequestContext = {
9
- accountId: "",
10
- apiId: "",
11
- httpMethod: "",
8
+ import type { APIGatewayEvent } from "aws-lambda";
9
+ export type PathParameters = {
10
+ [name: string]: string,
11
+ } | null;
12
+ export type QueryStringParameters = {
13
+ [name: string]: string,
14
+ } | null;
15
+ declare var defaultRequestContext: {
16
+ accountId: string,
17
+ apiId: string,
18
+ httpMethod: string,
12
19
  identity: {
13
20
  accessKey: null,
14
21
  accountId: null,
@@ -18,58 +25,41 @@ const defaultRequestContext = {
18
25
  cognitoAuthenticationType: null,
19
26
  cognitoIdentityId: null,
20
27
  cognitoIdentityPoolId: null,
21
- sourceIp: "",
28
+ sourceIp: string,
22
29
  user: null,
23
30
  userAgent: null,
24
- userArn: null
31
+ userArn: null,
32
+ ...
25
33
  },
26
- stage: "",
27
- requestId: "",
28
- resourceId: "",
29
- resourcePath: ""
34
+ stage: string,
35
+ requestId: string,
36
+ resourceId: string,
37
+ resourcePath: string,
38
+ ...
30
39
  };
31
-
32
40
  export type CreateAPIGatewayEventOptions = {
33
- body?: string,
34
- headers?: { [name: string]: string },
35
- multiValueHeaders?: { [name: string]: string[] },
41
+ body?: string | null,
42
+ headers?: {
43
+ [name: string]: string,
44
+ },
45
+ multiValueHeaders?: {
46
+ [name: string]: string[],
47
+ },
36
48
  httpMethod?: string,
37
49
  isBase64Encoded?: boolean,
38
50
  path?: string,
39
51
  pathParameters?: PathParameters,
40
52
  queryStringParameters?: QueryStringParameters,
41
- multiValueQueryStringParameters?: { [name: string]: string[] },
42
- stageVariables?: { [name: string]: string },
53
+ multiValueQueryStringParameters?: {
54
+ [name: string]: string[],
55
+ },
56
+ stageVariables?: {
57
+ [name: string]: string,
58
+ },
43
59
  requestContext?: typeof defaultRequestContext,
44
- resource?: string
60
+ resource?: string,
61
+ ...
45
62
  };
46
-
47
- export default function createAPIGatewayEvent({
48
- body = null,
49
- headers = {},
50
- multiValueHeaders = {},
51
- httpMethod = "",
52
- isBase64Encoded = false,
53
- pathParameters = null,
54
- path = "",
55
- queryStringParameters = null,
56
- multiValueQueryStringParameters = null,
57
- stageVariables = null,
58
- requestContext = defaultRequestContext,
59
- resource = ""
60
- }: CreateAPIGatewayEventOptions = {}): APIGatewayEvent<string> {
61
- return {
62
- body,
63
- headers,
64
- multiValueHeaders,
65
- httpMethod,
66
- isBase64Encoded,
67
- path,
68
- pathParameters,
69
- queryStringParameters,
70
- multiValueQueryStringParameters,
71
- stageVariables,
72
- requestContext,
73
- resource
74
- };
75
- }
63
+ declare export default function createAPIGatewayEvent(
64
+ x?: CreateAPIGatewayEventOptions
65
+ ): APIGatewayEvent;
@@ -0,0 +1,19 @@
1
+ import { APIGatewayEvent } from "aws-lambda";
2
+ import type { Response } from "./response";
3
+ import type { LambdaInvoke } from "./lambda-invoke";
4
+ /**
5
+ * Client that directly invokes an API Gateway handler, bypassing the gateway. The client handles packing and unpacking messages for invoking the handler.
6
+ */
7
+ export type APIGatewayHandlerClient<T> = (event: APIGatewayEvent) => Promise<Response<T>>;
8
+ export type CreateClientOptions<T> = {
9
+ Lambda: LambdaInvoke;
10
+ FunctionName: string;
11
+ Validate?: (arg1: T) => void;
12
+ };
13
+ /**
14
+ * Create an APIGatewayHandlerClient. The client invokes an API Gateway handler, bypassing the gateway. It adapts the AWS SDK by packing and unpacking messages for invoking the handler.
15
+ *
16
+ * @param options
17
+ * @returns {APIGatewayHandlerClient<T>}
18
+ */
19
+ export default function createClient<T>(options: CreateClientOptions<T>): APIGatewayHandlerClient<T>;
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
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
6
  exports.default = createClient;
7
- var _createLambdaClient = _interopRequireDefault(require("./create-lambda-client"));
8
- var _jsonStringify = _interopRequireDefault(require("./json-stringify"));
9
- var _parsePayload = _interopRequireDefault(require("./parse-payload"));
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- /**
12
- * Client that directly invokes an API Gateway handler, bypassing the gateway. The client handles packing and unpacking messages for invoking the handler.
13
- */
7
+ const create_lambda_client_1 = __importDefault(require("./create-lambda-client"));
8
+ const json_stringify_1 = __importDefault(require("./json-stringify"));
9
+ const parse_payload_1 = __importDefault(require("./parse-payload"));
14
10
  /**
15
11
  * Create an APIGatewayHandlerClient. The client invokes an API Gateway handler, bypassing the gateway. It adapts the AWS SDK by packing and unpacking messages for invoking the handler.
16
12
  *
@@ -18,6 +14,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
18
14
  * @returns {APIGatewayHandlerClient<T>}
19
15
  */
20
16
  function createClient(options) {
21
- const client = (0, _createLambdaClient.default)(options);
22
- return async event => (0, _parsePayload.default)(await client((0, _jsonStringify.default)(event)));
23
- }
17
+ const client = (0, create_lambda_client_1.default)(options);
18
+ return async (event) => (0, parse_payload_1.default)(await client((0, json_stringify_1.default)(event)));
19
+ }
@@ -1,30 +1,31 @@
1
- // @flow
1
+ /**
2
+ * Flowtype definitions for create-client
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
2
7
 
3
- import type { APIGatewayEvent } from "@cumulusds/flow-aws-lambda";
4
- import createLambdaClient from "./create-lambda-client";
8
+ import { APIGatewayEvent } from "aws-lambda";
5
9
  import type { Response } from "./response";
6
- import jsonStringify from "./json-stringify";
7
- import parsePayload from "./parse-payload";
8
10
  import type { LambdaInvoke } from "./lambda-invoke";
9
11
 
10
12
  /**
11
13
  * Client that directly invokes an API Gateway handler, bypassing the gateway. The client handles packing and unpacking messages for invoking the handler.
12
14
  */
13
- export type APIGatewayHandlerClient<T> = (event: APIGatewayEvent<string>) => Promise<Response<T>>;
14
-
15
+ export type APIGatewayHandlerClient<T> = (
16
+ event: APIGatewayEvent
17
+ ) => Promise<Response<T>>;
15
18
  export type CreateClientOptions<T> = {
16
19
  Lambda: LambdaInvoke,
17
20
  FunctionName: string,
18
- Validate?: T => void
21
+ Validate?: (arg1: T) => void,
22
+ ...
19
23
  };
20
-
21
24
  /**
22
25
  * Create an APIGatewayHandlerClient. The client invokes an API Gateway handler, bypassing the gateway. It adapts the AWS SDK by packing and unpacking messages for invoking the handler.
23
- *
24
26
  * @param options
25
27
  * @returns {APIGatewayHandlerClient<T>}
26
28
  */
27
- export default function createClient<T>(options: CreateClientOptions<T>): APIGatewayHandlerClient<T> {
28
- const client = createLambdaClient(options);
29
- return async (event: APIGatewayEvent<string>) => parsePayload<T>(await client(jsonStringify(event)));
30
- }
29
+ declare export default function createClient<T>(
30
+ options: CreateClientOptions<T>
31
+ ): APIGatewayHandlerClient<T>;
@@ -0,0 +1,39 @@
1
+ import { Lambda } from "aws-sdk";
2
+ import type { LambdaInvoke } from "./lambda-invoke";
3
+ type _Blob = Buffer | Uint8Array | Blob | string;
4
+ type LambdaClientType = (event: _Blob) => Promise<string>;
5
+ export type CreateLambdaClientOptions = {
6
+ Lambda: LambdaInvoke;
7
+ FunctionName: string;
8
+ };
9
+ export type Lambda$InvocationResponse = {
10
+ /**
11
+ * The HTTP status code is in the 200 range for a successful request. For the RequestResponse invocation type, this status code is 200. For the Event invocation type, this status code is 202. For the DryRun invocation type, the status code is 204.
12
+ */
13
+ StatusCode?: number;
14
+ /**
15
+ * If present, indicates that an error occurred during function execution. Details about the error are included in the response payload.
16
+ */
17
+ FunctionError?: string;
18
+ /**
19
+ * The last 4 KB of the execution log, which is base64 encoded.
20
+ */
21
+ LogResult?: string;
22
+ /**
23
+ * The response from the function, or an error object.
24
+ */
25
+ Payload?: Buffer | Uint8Array | Blob | string;
26
+ /**
27
+ * The version of the function that executed. When you invoke a function with an alias, this indicates which version the alias resolved to.
28
+ */
29
+ ExecutedVersion?: string;
30
+ };
31
+ export declare class LambdaInvokeError extends Error {
32
+ code: string;
33
+ constructor(response: Lambda.InvocationResponse);
34
+ }
35
+ /**
36
+ * AWS Lambda SDK adapter for createClient.
37
+ */
38
+ export default function createLambdaClient({ Lambda: LambdaShadow, FunctionName, }: CreateLambdaClientOptions): LambdaClientType;
39
+ export {};
@@ -1,37 +1,39 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = createLambdaClient;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
7
3
  exports.LambdaInvokeError = void 0;
4
+ exports.default = createLambdaClient;
8
5
  class LambdaInvokeError extends Error {
9
- constructor(response) {
10
- var _response$FunctionErr;
11
- super(["Invocation Failed", response.ExecutedVersion, response.StatusCode, response.FunctionError, response.Payload, response.LogResult != null ? Buffer.from(response.LogResult, "base64").toString("utf-8") : null].filter(x => x != null).join(": "));
12
- this.code = (_response$FunctionErr = response.FunctionError) !== null && _response$FunctionErr !== void 0 ? _response$FunctionErr : "";
13
- }
6
+ code;
7
+ constructor(response) {
8
+ super([
9
+ "Invocation Failed",
10
+ response.ExecutedVersion,
11
+ response.StatusCode,
12
+ response.FunctionError,
13
+ response.Payload,
14
+ response.LogResult != null ? Buffer.from(response.LogResult, "base64").toString("utf-8") : null,
15
+ ]
16
+ .filter((x) => x != null)
17
+ .join(": "));
18
+ this.code = response.FunctionError ?? "";
19
+ }
14
20
  }
15
-
21
+ exports.LambdaInvokeError = LambdaInvokeError;
16
22
  /**
17
23
  * AWS Lambda SDK adapter for createClient.
18
24
  */
19
- exports.LambdaInvokeError = LambdaInvokeError;
20
- function createLambdaClient({
21
- Lambda,
22
- FunctionName
23
- }) {
24
- return async Payload => {
25
- const invocationResponse = await Lambda.invoke({
26
- FunctionName,
27
- Payload
28
- }).promise();
29
- if (invocationResponse.StatusCode !== 200 || invocationResponse.FunctionError != null) {
30
- throw new LambdaInvokeError(invocationResponse);
31
- }
32
- if (typeof invocationResponse.Payload !== "string") {
33
- throw new Error(`AWS Lambda invocation API returned the wrong payload type '${typeof invocationResponse.Payload}'; expected 'string'`);
34
- }
35
- return invocationResponse.Payload;
36
- };
37
- }
25
+ function createLambdaClient({ Lambda: LambdaShadow, FunctionName, }) {
26
+ return async (Payload) => {
27
+ const invocationResponse = await LambdaShadow.invoke({
28
+ FunctionName,
29
+ Payload,
30
+ }).promise();
31
+ if (invocationResponse.StatusCode !== 200 || invocationResponse.FunctionError != null) {
32
+ throw new LambdaInvokeError(invocationResponse);
33
+ }
34
+ if (typeof invocationResponse.Payload !== "string") {
35
+ throw new Error(`AWS Lambda invocation API returned the wrong payload type '${typeof invocationResponse.Payload}'; expected 'string'`);
36
+ }
37
+ return invocationResponse.Payload;
38
+ };
39
+ }
@@ -1,16 +1,19 @@
1
- // @flow
1
+ /**
2
+ * Flowtype definitions for create-lambda-client
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
2
7
 
8
+ import { Lambda } from "aws-sdk";
3
9
  import type { LambdaInvoke } from "./lambda-invoke";
4
-
5
- interface Blob {}
6
- type _Blob = Buffer | Uint8Array | Blob | string;
7
- type LambdaClientType = (event: _Blob) => Promise<string>;
8
-
10
+ declare type _Blob = Buffer | Uint8Array | Blob | string;
11
+ declare type LambdaClientType = (event: _Blob) => Promise<string>;
9
12
  export type CreateLambdaClientOptions = {
10
13
  Lambda: LambdaInvoke,
11
- FunctionName: string
14
+ FunctionName: string,
15
+ ...
12
16
  };
13
-
14
17
  export type Lambda$InvocationResponse = {
15
18
  /**
16
19
  * The HTTP status code is in the 200 range for a successful request. For the RequestResponse invocation type, this status code is 200. For the Event invocation type, this status code is 202. For the DryRun invocation type, the status code is 204.
@@ -35,46 +38,16 @@ export type Lambda$InvocationResponse = {
35
38
  /**
36
39
  * The version of the function that executed. When you invoke a function with an alias, this indicates which version the alias resolved to.
37
40
  */
38
- ExecutedVersion?: string
41
+ ExecutedVersion?: string,
42
+ ...
39
43
  };
40
-
41
- export class LambdaInvokeError extends Error {
44
+ declare export class LambdaInvokeError mixins Error {
42
45
  code: string;
43
-
44
- constructor(response: Lambda$InvocationResponse) {
45
- super(
46
- [
47
- "Invocation Failed",
48
- response.ExecutedVersion,
49
- response.StatusCode,
50
- response.FunctionError,
51
- response.Payload,
52
- response.LogResult != null ? Buffer.from(response.LogResult, "base64").toString("utf-8") : null
53
- ]
54
- .filter(x => x != null)
55
- .join(": ")
56
- );
57
- this.code = response.FunctionError ?? "";
58
- }
46
+ constructor(response: Lambda.InvocationResponse): this;
59
47
  }
60
-
61
48
  /**
62
49
  * AWS Lambda SDK adapter for createClient.
63
50
  */
64
- export default function createLambdaClient({ Lambda, FunctionName }: CreateLambdaClientOptions): LambdaClientType {
65
- return async (Payload: _Blob) => {
66
- const invocationResponse = await Lambda.invoke({
67
- FunctionName,
68
- Payload
69
- }).promise();
70
- if (invocationResponse.StatusCode !== 200 || invocationResponse.FunctionError != null) {
71
- throw new LambdaInvokeError(invocationResponse);
72
- }
73
- if (typeof invocationResponse.Payload !== "string") {
74
- throw new Error(
75
- `AWS Lambda invocation API returned the wrong payload type '${typeof invocationResponse.Payload}'; expected 'string'`
76
- );
77
- }
78
- return invocationResponse.Payload;
79
- };
80
- }
51
+ declare export default function createLambdaClient(
52
+ x: CreateLambdaClientOptions
53
+ ): LambdaClientType;
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { default as createClient } from "./create-client";
2
+ export type { APIGatewayHandlerClient } from "./create-client";
3
+ export { default as createAPIGatewayEvent } from "./create-api-gateway-event";
package/lib/index.js CHANGED
@@ -1,20 +1,10 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "createClient", {
7
- enumerable: true,
8
- get: function () {
9
- return _createClient.default;
10
- }
11
- });
12
- Object.defineProperty(exports, "createAPIGatewayEvent", {
13
- enumerable: true,
14
- get: function () {
15
- return _createApiGatewayEvent.default;
16
- }
17
- });
18
- var _createClient = _interopRequireDefault(require("./create-client"));
19
- var _createApiGatewayEvent = _interopRequireDefault(require("./create-api-gateway-event"));
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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.createAPIGatewayEvent = exports.createClient = void 0;
7
+ var create_client_1 = require("./create-client");
8
+ Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return __importDefault(create_client_1).default; } });
9
+ var create_api_gateway_event_1 = require("./create-api-gateway-event");
10
+ Object.defineProperty(exports, "createAPIGatewayEvent", { enumerable: true, get: function () { return __importDefault(create_api_gateway_event_1).default; } });
package/lib/index.js.flow CHANGED
@@ -1,5 +1,10 @@
1
- // @flow
1
+ /**
2
+ * Flowtype definitions for index
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
2
7
 
3
- export { default as createClient } from "./create-client";
8
+ declare export { default as createClient } from "./create-client";
4
9
  export type { APIGatewayHandlerClient } from "./create-client";
5
- export { default as createAPIGatewayEvent } from "./create-api-gateway-event";
10
+ declare export { default as createAPIGatewayEvent } from "./create-api-gateway-event";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Stringify to JSON, returning a string or else throwing an exception because of unserializable input.
3
+ *
4
+ * @param value
5
+ * @returns {string}
6
+ */
7
+ export default function jsonStringify(value: unknown): string;
@@ -1,8 +1,5 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.default = jsonStringify;
7
4
  /**
8
5
  * Stringify to JSON, returning a string or else throwing an exception because of unserializable input.
@@ -10,11 +7,10 @@ exports.default = jsonStringify;
10
7
  * @param value
11
8
  * @returns {string}
12
9
  */
13
- // flowlint-next-line unclear-type:off
14
10
  function jsonStringify(value) {
15
- const result = JSON.stringify(value);
16
- if (result == null) {
17
- throw new Error("Cannot stringify value");
18
- }
19
- return result;
20
- }
11
+ const result = JSON.stringify(value);
12
+ if (result == null) {
13
+ throw new Error("Cannot stringify value");
14
+ }
15
+ return result;
16
+ }
@@ -1,16 +1,13 @@
1
- // @flow
1
+ /**
2
+ * Flowtype definitions for json-stringify
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
2
7
 
3
8
  /**
4
9
  * Stringify to JSON, returning a string or else throwing an exception because of unserializable input.
5
- *
6
10
  * @param value
7
11
  * @returns {string}
8
12
  */
9
- // flowlint-next-line unclear-type:off
10
- export default function jsonStringify(value: any): string {
11
- const result = JSON.stringify(value);
12
- if (result == null) {
13
- throw new Error("Cannot stringify value");
14
- }
15
- return result;
16
- }
13
+ declare export default function jsonStringify(value: mixed): string;
@@ -0,0 +1,7 @@
1
+ import type { Lambda } from "aws-sdk";
2
+ /**
3
+ * This library only needs the invoke method from aws-sdk Lambda client.
4
+ */
5
+ export type LambdaInvoke = {
6
+ readonly invoke: Lambda["invoke"];
7
+ };
@@ -1 +1,2 @@
1
- "use strict";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,9 @@
1
- // @flow
1
+ /**
2
+ * Flowtype definitions for lambda-invoke
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
2
7
 
3
8
  import type { Lambda } from "aws-sdk";
4
9
 
@@ -6,5 +11,6 @@ import type { Lambda } from "aws-sdk";
6
11
  * This library only needs the invoke method from aws-sdk Lambda client.
7
12
  */
8
13
  export type LambdaInvoke = {
9
- +invoke: $PropertyType<Lambda, "invoke">
14
+ +invoke: $PropertyType<Lambda, "invoke">,
15
+ ...
10
16
  };
@@ -0,0 +1,9 @@
1
+ import type { Response } from "./response";
2
+ /**
3
+ * Decode the handler response
4
+ *
5
+ * @param payload
6
+ * @param validate if given, the validate function is called on the parsed response body. The function should throw an exception if the response is invalid.
7
+ * @returns {{headers: {[p: string]: boolean|number|string}, data: *, status: number}}
8
+ */
9
+ export default function parsePayload<T>(payload: string, validate?: (arg1: T) => void): Response<T>;
@@ -1,8 +1,5 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.default = parsePayload;
7
4
  /**
8
5
  * Decode the handler response
@@ -12,16 +9,15 @@ exports.default = parsePayload;
12
9
  * @returns {{headers: {[p: string]: boolean|number|string}, data: *, status: number}}
13
10
  */
14
11
  function parsePayload(payload, validate) {
15
- var _proxyResult$headers;
16
- const proxyResult = JSON.parse(payload);
17
- if (proxyResult.isBase64Encoded === true) {
18
- throw new Error("A base64 encoded response from API Gateway handler was received, but is not supported.");
19
- }
20
- const data = JSON.parse(proxyResult.body);
21
- validate === null || validate === void 0 ? void 0 : validate(data);
22
- return {
23
- data,
24
- status: proxyResult.statusCode,
25
- headers: (_proxyResult$headers = proxyResult.headers) !== null && _proxyResult$headers !== void 0 ? _proxyResult$headers : {}
26
- };
27
- }
12
+ const proxyResult = JSON.parse(payload);
13
+ if (proxyResult.isBase64Encoded === true) {
14
+ throw new Error("A base64 encoded response from API Gateway handler was received, but is not supported.");
15
+ }
16
+ const data = JSON.parse(proxyResult.body);
17
+ validate?.(data);
18
+ return {
19
+ data,
20
+ status: proxyResult.statusCode,
21
+ headers: proxyResult.headers ?? {},
22
+ };
23
+ }
@@ -1,25 +1,25 @@
1
- // @flow
1
+ /**
2
+ * Flowtype definitions for parse-payload
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
2
7
 
3
- import type { ProxyResult } from "@cumulusds/flow-aws-lambda";
4
8
  import type { Response } from "./response";
5
9
 
6
10
  /**
7
11
  * Decode the handler response
8
- *
9
12
  * @param payload
10
13
  * @param validate if given, the validate function is called on the parsed response body. The function should throw an exception if the response is invalid.
11
- * @returns {{headers: {[p: string]: boolean|number|string}, data: *, status: number}}
14
+ * @returns {{
15
+ headers: {
16
+ [p: string]: boolean | number | string,
17
+ },
18
+ data: *,
19
+ status: number,...
20
+ }}
12
21
  */
13
- export default function parsePayload<T>(payload: string, validate?: T => void): Response<T> {
14
- const proxyResult: ProxyResult = JSON.parse(payload);
15
- if (proxyResult.isBase64Encoded === true) {
16
- throw new Error("A base64 encoded response from API Gateway handler was received, but is not supported.");
17
- }
18
- const data: T = JSON.parse(proxyResult.body);
19
- validate?.(data);
20
- return {
21
- data,
22
- status: proxyResult.statusCode,
23
- headers: proxyResult.headers ?? {}
24
- };
25
- }
22
+ declare export default function parsePayload<T>(
23
+ payload: string,
24
+ validate?: (arg1: T) => void
25
+ ): Response<T>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Decoded handler response
3
+ */
4
+ export type Response<T> = {
5
+ data: T;
6
+ status: number;
7
+ headers: {
8
+ [header: string]: boolean | number | string;
9
+ };
10
+ };
package/lib/response.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,15 +1,18 @@
1
- // @flow
1
+ /**
2
+ * Flowtype definitions for response
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
2
7
 
3
8
  /**
4
9
  * Decoded handler response
5
10
  */
6
- export type Response<T> = {|
7
- // the response provided by the handler
11
+ export type Response<T> = {
8
12
  data: T,
9
-
10
- // the HTTP status code
11
13
  status: number,
12
-
13
- // response headers
14
- headers: { [header: string]: boolean | number | string }
15
- |};
14
+ headers: {
15
+ [header: string]: boolean | number | string,
16
+ },
17
+ ...
18
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cumulusds/aws-apig-bypass",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Client for API Gateway handlers, bypassing API Gateway by directly invoking the Lambda",
5
5
  "repository": "https://github.com/CumulusDS/aws-apig-bypass",
6
6
  "author": "Cumulus Digital Systems",
@@ -12,23 +12,21 @@
12
12
  "files": [
13
13
  "README.md",
14
14
  "lib/*",
15
- "lib/dynamodb/**",
16
- "lib/services/**",
17
15
  "package.json"
18
16
  ],
19
17
  "scripts": {
20
- "build": "yarn run build:babel && yarn run build:flow-copy-source && yarn run build:license-checker",
21
- "build:babel": "babel src --out-dir lib --ignore test.js",
22
- "build:flow-copy-source": "flow-copy-source --ignore test.js src lib",
18
+ "build": "yarn run build:license-checker && tsc",
19
+ "build:flowtypes": "find lib -type f -name '*.d.ts' -exec sh -c 'yarn flowgen --add-flow-header $1 -o ${1%.*.*}.js.flow' _ '{}' \\;",
23
20
  "build:license-checker": "license-checker --csv --out var/licenses.csv",
24
21
  "clean": "shx rm -rf lib",
22
+ "flow": "echo this is not a flow project",
25
23
  "git:commit": "git add package.json .yarn/versions && git commit -m v${npm_package_version}",
26
24
  "git:commit:publish": "git add package.json .yarn/versions/* && git commit -m v${npm_package_version}",
27
25
  "git:commit:version": "git add .yarn/versions/* && git commit -m 'Deferred version bump'",
28
26
  "git:push": "git push --follow-tags",
29
27
  "git:tag": "git tag -a v${npm_package_version} -m v${npm_package_version}",
30
28
  "npm:tag:remove": "yarn npm tag remove ${npm_package_name} $0",
31
- "prepack": "yarn run build",
29
+ "prepack": "yarn run build && yarn run build:flowtypes",
32
30
  "prerelease": "yarn version apply && yarn run version:feature $0",
33
31
  "publish:patch": "yarn version patch && yarn publish:sync",
34
32
  "publish:minor": "yarn version minor && yarn publish:sync",
@@ -36,14 +34,10 @@
36
34
  "publish:prepatch": "yarn run version:prepatch && yarn run git:push",
37
35
  "publish:prerelease": "yarn npm publish",
38
36
  "publish:sync": "yarn run git:commit && yarn run git:tag && yarn git:push",
39
- "sites": "node bin/sites.js",
40
- "test": "yarn run test:flow && yarn run test:jest && yarn run test:lint && yarn run test:prettier",
41
- "test:flow": "yarn run test:flow:coverage-report && yarn run test:flow:status",
42
- "test:flow:coverage-report": "flow-coverage-report -i '{src,test}/**/*.js' -t html -t text --threshold 99 --output-dir var/coverage/flow",
43
- "test:flow:status": "flow status",
37
+ "test": "yarn run test:jest && yarn run test:lint && yarn run test:prettier",
44
38
  "test:jest": "jest --color",
45
- "test:lint": "eslint *.js src test",
46
- "test:prettier": "prettier --list-different \"{src,test}/**/*.{js,jsx,yml}\" \"*.{js,yml}\"",
39
+ "test:lint": "eslint src/**/*.ts test/**/*.ts",
40
+ "test:prettier": "prettier --list-different \"{src,test}/**/*.ts\"",
47
41
  "version:patch": "yarn version --new-version patch",
48
42
  "version:minor": "yarn version --new-version minor",
49
43
  "version:major": "yarn version --new-version major",
@@ -55,7 +49,7 @@
55
49
  "verbose": true,
56
50
  "collectCoverage": true,
57
51
  "collectCoverageFrom": [
58
- "src/**/*.js"
52
+ "src/**/*.ts"
59
53
  ],
60
54
  "testEnvironment": "node",
61
55
  "coverageDirectory": "var/coverage/test",
@@ -69,35 +63,35 @@
69
63
  }
70
64
  },
71
65
  "dependencies": {
72
- "@cumulusds/flow-aws-lambda": "^1.0.0"
66
+ "aws-lambda": "^1.0.7",
67
+ "aws-sdk": "^2.1460.0"
73
68
  },
74
69
  "devDependencies": {
75
- "@babel/cli": "^7.22.15",
70
+ "@babel/cli": "^7.24.7",
76
71
  "@babel/core": "^7.7.4",
77
72
  "@babel/plugin-proposal-nullish-coalescing-operator": "^7.7.4",
78
73
  "@babel/plugin-proposal-optional-chaining": "^7.12.7",
79
74
  "@babel/preset-env": "^7.0.0",
80
- "@babel/preset-flow": "^7.0.0",
81
- "@cumulusds/flow-aws-sdk": "^2.818.3",
82
- "@cumulusds/flow-coverage-report": "^0.8.1",
83
- "aws-sdk": "^2.1460.0",
84
- "babel-eslint": "10.0.3",
85
- "babel-jest": "^24.9.0",
86
- "eslint": "^7.5.0",
75
+ "@babel/preset-typescript": "^7.24.7",
76
+ "@types/aws-lambda": "^8.10.145",
77
+ "@types/jest": "^29.5.13",
78
+ "@typescript-eslint/eslint-plugin": "^8.7.0",
79
+ "@typescript-eslint/parser": "^8.7.0",
80
+ "babel-eslint": "^10.1.0",
81
+ "babel-jest": "^29.7.0",
82
+ "eslint": "^8.57.1",
87
83
  "eslint-config-airbnb-base": "14.0.0",
88
- "eslint-config-prettier": "^2.9.0",
89
- "eslint-plugin-flowtype": "^2.49.3",
90
- "eslint-plugin-import": "2.18.2",
91
- "eslint-plugin-jest": "^21.15.1",
92
- "eslint-plugin-prettier": "^2.6.0",
93
- "flow-bin": "^0.142.0",
94
- "flow-copy-source": "^2.0.9",
95
- "flow-typed": "^3.9.0",
84
+ "eslint-config-prettier": "^8.10.0",
85
+ "eslint-plugin-import": "^2.18.2",
86
+ "eslint-plugin-jest": "^28.8.3",
87
+ "eslint-plugin-prettier": "^5.2.1",
88
+ "flowgen": "^1.21.0",
96
89
  "git-describe": "^4.0.4",
97
90
  "jest": "^29.7.0",
98
91
  "license-checker": "^25.0.1",
99
- "prettier": "^1.14.0",
100
- "shx": "^0.3.2"
92
+ "prettier": "^3.3.3",
93
+ "shx": "^0.3.2",
94
+ "typescript": "^5.6.2"
101
95
  },
102
96
  "packageManager": "yarn@3.5.0"
103
97
  }