@h4ad/serverless-adapter 2.9.0 → 2.11.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/lib/@types/binary-settings.d.ts +0 -1
- package/lib/@types/digital-ocean/digital-ocean-http-event.d.ts +0 -1
- package/lib/@types/digital-ocean/digital-ocean-http-response.d.ts +0 -1
- package/lib/@types/digital-ocean/index.d.ts +0 -1
- package/lib/@types/headers.d.ts +0 -1
- package/lib/@types/helpers.d.ts +0 -1
- package/lib/@types/huawei/huawei-api-gateway-event.d.ts +0 -1
- package/lib/@types/huawei/huawei-api-gateway-response.d.ts +0 -1
- package/lib/@types/huawei/huawei-context.d.ts +0 -1
- package/lib/@types/huawei/index.d.ts +0 -1
- package/lib/@types/index.d.ts +0 -1
- package/lib/adapters/aws/alb.adapter.d.ts +0 -1
- package/lib/adapters/aws/api-gateway-v1.adapter.d.ts +0 -1
- package/lib/adapters/aws/api-gateway-v2.adapter.d.ts +0 -1
- package/lib/adapters/aws/dynamodb.adapter.d.ts +0 -1
- package/lib/adapters/aws/event-bridge.adapter.d.ts +0 -1
- package/lib/adapters/aws/index.d.ts +1 -1
- package/lib/adapters/aws/index.js +1 -0
- package/lib/adapters/aws/index.js.map +1 -1
- package/lib/adapters/aws/lambda-edge.adapter.d.ts +0 -1
- package/lib/adapters/aws/s3.adapter.d.ts +70 -0
- package/lib/adapters/aws/s3.adapter.js +91 -0
- package/lib/adapters/aws/s3.adapter.js.map +1 -0
- package/lib/adapters/aws/sns.adapter.d.ts +0 -1
- package/lib/adapters/aws/sqs.adapter.d.ts +0 -1
- package/lib/adapters/azure/http-trigger-v4.adapter.d.ts +0 -1
- package/lib/adapters/azure/index.d.ts +0 -1
- package/lib/adapters/digital-ocean/http-function.adapter.d.ts +0 -1
- package/lib/adapters/digital-ocean/index.d.ts +0 -1
- package/lib/adapters/dummy/dummy.adapter.d.ts +0 -1
- package/lib/adapters/dummy/index.d.ts +0 -1
- package/lib/adapters/huawei/huawei-api-gateway.adapter.d.ts +0 -1
- package/lib/adapters/huawei/index.d.ts +0 -1
- package/lib/contracts/adapter.contract.d.ts +0 -1
- package/lib/contracts/framework.contract.d.ts +0 -1
- package/lib/contracts/handler.contract.d.ts +0 -1
- package/lib/contracts/index.d.ts +0 -1
- package/lib/contracts/resolver.contract.d.ts +0 -1
- package/lib/core/base-handler.d.ts +0 -1
- package/lib/core/constants.d.ts +0 -1
- package/lib/core/current-invoke.d.ts +0 -1
- package/lib/core/event-body.d.ts +0 -1
- package/lib/core/headers.d.ts +0 -1
- package/lib/core/index.d.ts +0 -1
- package/lib/core/is-binary.d.ts +0 -1
- package/lib/core/logger.d.ts +0 -1
- package/lib/core/no-op.d.ts +0 -1
- package/lib/core/optional.d.ts +0 -1
- package/lib/core/path.d.ts +0 -1
- package/lib/core/stream.d.ts +9 -1
- package/lib/core/stream.js +19 -4
- package/lib/core/stream.js.map +1 -1
- package/lib/frameworks/cors/cors.framework.d.ts +78 -0
- package/lib/frameworks/cors/cors.framework.js +145 -0
- package/lib/frameworks/cors/cors.framework.js.map +1 -0
- package/lib/frameworks/cors/index.d.ts +1 -0
- package/lib/frameworks/cors/index.js +18 -0
- package/lib/frameworks/cors/index.js.map +1 -0
- package/lib/frameworks/deepkit/http-deepkit.framework.d.ts +0 -1
- package/lib/frameworks/deepkit/index.d.ts +0 -1
- package/lib/frameworks/express/express.framework.d.ts +0 -1
- package/lib/frameworks/express/index.d.ts +0 -1
- package/lib/frameworks/fastify/fastify.framework.d.ts +0 -1
- package/lib/frameworks/fastify/index.d.ts +0 -1
- package/lib/frameworks/hapi/hapi.framework.d.ts +0 -1
- package/lib/frameworks/hapi/index.d.ts +0 -1
- package/lib/frameworks/koa/index.d.ts +0 -1
- package/lib/frameworks/koa/koa.framework.d.ts +0 -1
- package/lib/frameworks/lazy/index.d.ts +0 -1
- package/lib/frameworks/lazy/lazy.framework.d.ts +0 -1
- package/lib/frameworks/trpc/index.d.ts +0 -1
- package/lib/frameworks/trpc/trpc.framework.d.ts +0 -1
- package/lib/handlers/azure/azure.handler.d.ts +0 -1
- package/lib/handlers/azure/index.d.ts +0 -1
- package/lib/handlers/default/default.handler.d.ts +0 -1
- package/lib/handlers/default/index.d.ts +0 -1
- package/lib/handlers/digital-ocean/digital-ocean.handler.d.ts +0 -1
- package/lib/handlers/digital-ocean/index.d.ts +0 -1
- package/lib/handlers/firebase/http-firebase.handler.d.ts +0 -1
- package/lib/handlers/firebase/index.d.ts +0 -1
- package/lib/handlers/huawei/http-huawei.handler.d.ts +0 -1
- package/lib/handlers/huawei/index.d.ts +0 -1
- package/lib/index.d.ts +0 -1
- package/lib/network/index.d.ts +0 -1
- package/lib/network/request.d.ts +0 -1
- package/lib/network/response.d.ts +0 -1
- package/lib/resolvers/aws-context/aws-context.resolver.d.ts +0 -1
- package/lib/resolvers/aws-context/index.d.ts +0 -1
- package/lib/resolvers/callback/callback.resolver.d.ts +0 -1
- package/lib/resolvers/callback/index.d.ts +0 -1
- package/lib/resolvers/dummy/dummy.resolver.d.ts +0 -1
- package/lib/resolvers/dummy/index.d.ts +0 -1
- package/lib/resolvers/promise/index.d.ts +0 -1
- package/lib/resolvers/promise/promise.resolver.d.ts +0 -1
- package/lib/serverless-adapter.d.ts +0 -1
- package/package.json +5 -1
- package/lib/@types/binary-settings.d.ts.map +0 -1
- package/lib/@types/digital-ocean/digital-ocean-http-event.d.ts.map +0 -1
- package/lib/@types/digital-ocean/digital-ocean-http-response.d.ts.map +0 -1
- package/lib/@types/digital-ocean/index.d.ts.map +0 -1
- package/lib/@types/headers.d.ts.map +0 -1
- package/lib/@types/helpers.d.ts.map +0 -1
- package/lib/@types/huawei/huawei-api-gateway-event.d.ts.map +0 -1
- package/lib/@types/huawei/huawei-api-gateway-response.d.ts.map +0 -1
- package/lib/@types/huawei/huawei-context.d.ts.map +0 -1
- package/lib/@types/huawei/index.d.ts.map +0 -1
- package/lib/@types/index.d.ts.map +0 -1
- package/lib/adapters/aws/alb.adapter.d.ts.map +0 -1
- package/lib/adapters/aws/api-gateway-v1.adapter.d.ts.map +0 -1
- package/lib/adapters/aws/api-gateway-v2.adapter.d.ts.map +0 -1
- package/lib/adapters/aws/dynamodb.adapter.d.ts.map +0 -1
- package/lib/adapters/aws/event-bridge.adapter.d.ts.map +0 -1
- package/lib/adapters/aws/index.d.ts.map +0 -1
- package/lib/adapters/aws/lambda-edge.adapter.d.ts.map +0 -1
- package/lib/adapters/aws/sns.adapter.d.ts.map +0 -1
- package/lib/adapters/aws/sqs.adapter.d.ts.map +0 -1
- package/lib/adapters/azure/http-trigger-v4.adapter.d.ts.map +0 -1
- package/lib/adapters/azure/index.d.ts.map +0 -1
- package/lib/adapters/digital-ocean/http-function.adapter.d.ts.map +0 -1
- package/lib/adapters/digital-ocean/index.d.ts.map +0 -1
- package/lib/adapters/dummy/dummy.adapter.d.ts.map +0 -1
- package/lib/adapters/dummy/index.d.ts.map +0 -1
- package/lib/adapters/huawei/huawei-api-gateway.adapter.d.ts.map +0 -1
- package/lib/adapters/huawei/index.d.ts.map +0 -1
- package/lib/contracts/adapter.contract.d.ts.map +0 -1
- package/lib/contracts/framework.contract.d.ts.map +0 -1
- package/lib/contracts/handler.contract.d.ts.map +0 -1
- package/lib/contracts/index.d.ts.map +0 -1
- package/lib/contracts/resolver.contract.d.ts.map +0 -1
- package/lib/core/base-handler.d.ts.map +0 -1
- package/lib/core/constants.d.ts.map +0 -1
- package/lib/core/current-invoke.d.ts.map +0 -1
- package/lib/core/event-body.d.ts.map +0 -1
- package/lib/core/headers.d.ts.map +0 -1
- package/lib/core/index.d.ts.map +0 -1
- package/lib/core/is-binary.d.ts.map +0 -1
- package/lib/core/logger.d.ts.map +0 -1
- package/lib/core/no-op.d.ts.map +0 -1
- package/lib/core/optional.d.ts.map +0 -1
- package/lib/core/path.d.ts.map +0 -1
- package/lib/core/stream.d.ts.map +0 -1
- package/lib/frameworks/deepkit/http-deepkit.framework.d.ts.map +0 -1
- package/lib/frameworks/deepkit/index.d.ts.map +0 -1
- package/lib/frameworks/express/express.framework.d.ts.map +0 -1
- package/lib/frameworks/express/index.d.ts.map +0 -1
- package/lib/frameworks/fastify/fastify.framework.d.ts.map +0 -1
- package/lib/frameworks/fastify/index.d.ts.map +0 -1
- package/lib/frameworks/hapi/hapi.framework.d.ts.map +0 -1
- package/lib/frameworks/hapi/index.d.ts.map +0 -1
- package/lib/frameworks/koa/index.d.ts.map +0 -1
- package/lib/frameworks/koa/koa.framework.d.ts.map +0 -1
- package/lib/frameworks/lazy/index.d.ts.map +0 -1
- package/lib/frameworks/lazy/lazy.framework.d.ts.map +0 -1
- package/lib/frameworks/trpc/index.d.ts.map +0 -1
- package/lib/frameworks/trpc/trpc.framework.d.ts.map +0 -1
- package/lib/handlers/azure/azure.handler.d.ts.map +0 -1
- package/lib/handlers/azure/index.d.ts.map +0 -1
- package/lib/handlers/default/default.handler.d.ts.map +0 -1
- package/lib/handlers/default/index.d.ts.map +0 -1
- package/lib/handlers/digital-ocean/digital-ocean.handler.d.ts.map +0 -1
- package/lib/handlers/digital-ocean/index.d.ts.map +0 -1
- package/lib/handlers/firebase/http-firebase.handler.d.ts.map +0 -1
- package/lib/handlers/firebase/index.d.ts.map +0 -1
- package/lib/handlers/huawei/http-huawei.handler.d.ts.map +0 -1
- package/lib/handlers/huawei/index.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/network/index.d.ts.map +0 -1
- package/lib/network/request.d.ts.map +0 -1
- package/lib/network/response.d.ts.map +0 -1
- package/lib/resolvers/aws-context/aws-context.resolver.d.ts.map +0 -1
- package/lib/resolvers/aws-context/index.d.ts.map +0 -1
- package/lib/resolvers/callback/callback.resolver.d.ts.map +0 -1
- package/lib/resolvers/callback/index.d.ts.map +0 -1
- package/lib/resolvers/dummy/dummy.resolver.d.ts.map +0 -1
- package/lib/resolvers/dummy/index.d.ts.map +0 -1
- package/lib/resolvers/promise/index.d.ts.map +0 -1
- package/lib/resolvers/promise/promise.resolver.d.ts.map +0 -1
- package/lib/serverless-adapter.d.ts.map +0 -1
|
@@ -41,4 +41,3 @@ export declare type BinarySettings = BinarySettingsFunction | BinarySettingsCont
|
|
|
41
41
|
export declare type __ΩBinarySettingsFunction = any[];
|
|
42
42
|
export declare type __ΩBinarySettingsContentHeaders = any[];
|
|
43
43
|
export declare type __ΩBinarySettings = any[];
|
|
44
|
-
//# sourceMappingURL=binary-settings.d.ts.map
|
package/lib/@types/headers.d.ts
CHANGED
|
@@ -37,4 +37,3 @@ export declare type BothValueHeaders = Record<string, string | string[] | undefi
|
|
|
37
37
|
export declare type __ΩSingleValueHeaders = any[];
|
|
38
38
|
export declare type __ΩMultiValueHeaders = any[];
|
|
39
39
|
export declare type __ΩBothValueHeaders = any[];
|
|
40
|
-
//# sourceMappingURL=headers.d.ts.map
|
package/lib/@types/helpers.d.ts
CHANGED
|
@@ -82,4 +82,3 @@ export declare type __ΩHuaweiApiGatewayEvent = any[];
|
|
|
82
82
|
export declare type __ΩHuaweiRequestPathParameters = any[];
|
|
83
83
|
export declare type __ΩHuaweiRequestQueryStringParameters = any[];
|
|
84
84
|
export declare type __ΩHuaweiRequestContext = any[];
|
|
85
|
-
//# sourceMappingURL=huawei-api-gateway-event.d.ts.map
|
package/lib/@types/index.d.ts
CHANGED
|
@@ -68,4 +68,3 @@ export declare class DynamoDBAdapter implements AdapterContract<DynamoDBStreamEv
|
|
|
68
68
|
onErrorWhileForwarding({ error, delegatedResolver, }: OnErrorProps<DynamoDBStreamEvent, IEmptyResponse>): void;
|
|
69
69
|
}
|
|
70
70
|
export declare type __ΩDynamoDBAdapterOptions = any[];
|
|
71
|
-
//# sourceMappingURL=dynamodb.adapter.d.ts.map
|
|
@@ -4,6 +4,6 @@ export * from './api-gateway-v2.adapter';
|
|
|
4
4
|
export * from './dynamodb.adapter';
|
|
5
5
|
export * from './event-bridge.adapter';
|
|
6
6
|
export * from './lambda-edge.adapter';
|
|
7
|
+
export * from './s3.adapter';
|
|
7
8
|
export * from './sns.adapter';
|
|
8
9
|
export * from './sqs.adapter';
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -20,6 +20,7 @@ __exportStar(require("./api-gateway-v2.adapter"), exports);
|
|
|
20
20
|
__exportStar(require("./dynamodb.adapter"), exports);
|
|
21
21
|
__exportStar(require("./event-bridge.adapter"), exports);
|
|
22
22
|
__exportStar(require("./lambda-edge.adapter"), exports);
|
|
23
|
+
__exportStar(require("./s3.adapter"), exports);
|
|
23
24
|
__exportStar(require("./sns.adapter"), exports);
|
|
24
25
|
__exportStar(require("./sqs.adapter"), exports);
|
|
25
26
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/aws/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,2DAAyC;AACzC,2DAAyC;AACzC,qDAAmC;AACnC,yDAAuC;AACvC,wDAAsC;AACtC,gDAA8B;AAC9B,gDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/aws/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,2DAAyC;AACzC,2DAAyC;AACzC,qDAAmC;AACnC,yDAAuC;AACvC,wDAAsC;AACtC,+CAA6B;AAC7B,gDAA8B;AAC9B,gDAA8B"}
|
|
@@ -211,4 +211,3 @@ export declare type __ΩDefaultForwardPath = any[];
|
|
|
211
211
|
export declare type __ΩNewLambdaEdgeBody = any[];
|
|
212
212
|
export declare type __ΩOldLambdaEdgeBody = any[];
|
|
213
213
|
export declare type __ΩLambdaEdgeAdapterOptions = any[];
|
|
214
|
-
//# sourceMappingURL=lambda-edge.adapter.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Context, S3Event } from 'aws-lambda';
|
|
2
|
+
import { AdapterContract, AdapterRequest, OnErrorProps } from '../../contracts';
|
|
3
|
+
import { IEmptyResponse } from '../../core';
|
|
4
|
+
/**
|
|
5
|
+
* The options to customize the {@link S3Adapter}
|
|
6
|
+
*
|
|
7
|
+
* @breadcrumb Adapters / AWS / S3Adapter
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export interface S3AdapterOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The path that will be used to create a request to be forwarded to the framework.
|
|
13
|
+
*
|
|
14
|
+
* @defaultValue /s3
|
|
15
|
+
*/
|
|
16
|
+
s3ForwardPath?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The http method that will be used to create a request to be forwarded to the framework.
|
|
19
|
+
*
|
|
20
|
+
* @defaultValue POST
|
|
21
|
+
*/
|
|
22
|
+
s3ForwardMethod?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The adapter to handle requests from AWS S3.
|
|
26
|
+
*
|
|
27
|
+
* The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error.
|
|
28
|
+
*
|
|
29
|
+
* {@link https://docs.aws.amazon.com/pt_br/lambda/latest/dg/with-s3.html | Event Reference}
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const s3ForwardPath = '/your/route/s3'; // default /s3
|
|
34
|
+
* const s3ForwardMethod = 'POST'; // default POST
|
|
35
|
+
* const adapter = new S3Adapter({ s3ForwardPath, s3ForwardMethod });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @breadcrumb Adapters / AWS / S3Adapter
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export declare class S3Adapter implements AdapterContract<S3Event, Context, IEmptyResponse> {
|
|
42
|
+
protected readonly options?: S3AdapterOptions | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Default constructor
|
|
45
|
+
*
|
|
46
|
+
* @param options - The options to customize the {@link S3Adapter}
|
|
47
|
+
*/
|
|
48
|
+
constructor(options?: S3AdapterOptions | undefined);
|
|
49
|
+
/**
|
|
50
|
+
* {@inheritDoc}
|
|
51
|
+
*/
|
|
52
|
+
getAdapterName(): string;
|
|
53
|
+
/**
|
|
54
|
+
* {@inheritDoc}
|
|
55
|
+
*/
|
|
56
|
+
canHandle(event: unknown): event is S3Event;
|
|
57
|
+
/**
|
|
58
|
+
* {@inheritDoc}
|
|
59
|
+
*/
|
|
60
|
+
getRequest(event: S3Event): AdapterRequest;
|
|
61
|
+
/**
|
|
62
|
+
* {@inheritDoc}
|
|
63
|
+
*/
|
|
64
|
+
getResponse(): IEmptyResponse;
|
|
65
|
+
/**
|
|
66
|
+
* {@inheritDoc}
|
|
67
|
+
*/
|
|
68
|
+
onErrorWhileForwarding({ error, delegatedResolver, }: OnErrorProps<S3Event, IEmptyResponse>): void;
|
|
69
|
+
}
|
|
70
|
+
export declare type __ΩS3AdapterOptions = any[];
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.S3Adapter = exports.__ΩS3AdapterOptions = void 0;
|
|
4
|
+
const { __ΩAdapterRequest } = require('../../contracts');
|
|
5
|
+
const { __ΩIEmptyResponse } = require('../../core');
|
|
6
|
+
const { __ΩOnErrorProps } = require('../../contracts');
|
|
7
|
+
const core_1 = require("../../core");
|
|
8
|
+
const __ΩS3AdapterOptions = ['s3ForwardPath', 's3ForwardMethod', 'P&4!8&4"8M'];
|
|
9
|
+
exports.__ΩS3AdapterOptions = __ΩS3AdapterOptions;
|
|
10
|
+
/**
|
|
11
|
+
* The adapter to handle requests from AWS S3.
|
|
12
|
+
*
|
|
13
|
+
* The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error.
|
|
14
|
+
*
|
|
15
|
+
* {@link https://docs.aws.amazon.com/pt_br/lambda/latest/dg/with-s3.html | Event Reference}
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const s3ForwardPath = '/your/route/s3'; // default /s3
|
|
20
|
+
* const s3ForwardMethod = 'POST'; // default POST
|
|
21
|
+
* const adapter = new S3Adapter({ s3ForwardPath, s3ForwardMethod });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @breadcrumb Adapters / AWS / S3Adapter
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
class S3Adapter {
|
|
28
|
+
//#region Constructor
|
|
29
|
+
/**
|
|
30
|
+
* Default constructor
|
|
31
|
+
*
|
|
32
|
+
* @param options - The options to customize the {@link S3Adapter}
|
|
33
|
+
*/
|
|
34
|
+
constructor(options) {
|
|
35
|
+
this.options = options;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region Public Methods
|
|
39
|
+
/**
|
|
40
|
+
* {@inheritDoc}
|
|
41
|
+
*/
|
|
42
|
+
getAdapterName() {
|
|
43
|
+
return S3Adapter.name;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* {@inheritDoc}
|
|
47
|
+
*/
|
|
48
|
+
canHandle(event) {
|
|
49
|
+
var _a;
|
|
50
|
+
const s3Event = event;
|
|
51
|
+
if (!Array.isArray(s3Event === null || s3Event === void 0 ? void 0 : s3Event.Records))
|
|
52
|
+
return false;
|
|
53
|
+
const eventSource = (_a = s3Event.Records[0]) === null || _a === void 0 ? void 0 : _a.eventSource;
|
|
54
|
+
return eventSource === 'aws:s3';
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* {@inheritDoc}
|
|
58
|
+
*/
|
|
59
|
+
getRequest(event) {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
const path = (0, core_1.getDefaultIfUndefined)((_a = this.options) === null || _a === void 0 ? void 0 : _a.s3ForwardPath, '/s3');
|
|
62
|
+
const method = (0, core_1.getDefaultIfUndefined)((_b = this.options) === null || _b === void 0 ? void 0 : _b.s3ForwardMethod, 'POST');
|
|
63
|
+
const [body, contentLength] = (0, core_1.getEventBodyAsBuffer)(JSON.stringify(event), false);
|
|
64
|
+
const headers = {
|
|
65
|
+
host: 's3.amazonaws.com',
|
|
66
|
+
'content-type': 'application/json',
|
|
67
|
+
'content-length': String(contentLength),
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
method,
|
|
71
|
+
headers,
|
|
72
|
+
body,
|
|
73
|
+
path,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* {@inheritDoc}
|
|
78
|
+
*/
|
|
79
|
+
getResponse() {
|
|
80
|
+
return core_1.EmptyResponse;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* {@inheritDoc}
|
|
84
|
+
*/
|
|
85
|
+
onErrorWhileForwarding({ error, delegatedResolver, }) {
|
|
86
|
+
delegatedResolver.fail(error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.S3Adapter = S3Adapter;
|
|
90
|
+
S3Adapter.__type = [() => __ΩS3AdapterOptions, 'options', 'constructor', 'getAdapterName', 'event', 'canHandle', () => __ΩAdapterRequest, 'getRequest', () => __ΩIEmptyResponse, 'getResponse', () => __ΩOnErrorProps, () => __ΩIEmptyResponse, 'param0', 'onErrorWhileForwarding', () => __ΩIEmptyResponse, 'Pn!2"8<9"0#P&0$P#2%!0&P"2%n\'0(Pn)0*P"n,o+#2-$0.5""n/6$'];
|
|
91
|
+
//# sourceMappingURL=s3.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.adapter.js","sourceRoot":"","sources":["../../../src/adapters/aws/s3.adapter.ts"],"names":[],"mappings":";;;sCAG8D,iBAAiB;sCAMxE,YAAY;oCAN2C,iBAAiB;AAC/E,qCAKoB;;;AA0BpB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,SAAS;IAGpB,qBAAqB;IAErB;;;;OAIG;IACH,YAA+B,OAA0B;QAA1B,YAAO,GAAP,OAAO,CAAmB;IAAG,CAAC;IAE7D,YAAY;IAEZ,wBAAwB;IAExB;;OAEG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SNSEvent, Context, IE
|
|
|
68
68
|
onErrorWhileForwarding({ error, delegatedResolver, }: OnErrorProps<SNSEvent, IEmptyResponse>): void;
|
|
69
69
|
}
|
|
70
70
|
export declare type __ΩSNSAdapterOptions = any[];
|
|
71
|
-
//# sourceMappingURL=sns.adapter.d.ts.map
|
|
@@ -68,4 +68,3 @@ export declare class SQSAdapter implements AdapterContract<SQSEvent, Context, IE
|
|
|
68
68
|
onErrorWhileForwarding({ error, delegatedResolver, }: OnErrorProps<SQSEvent, IEmptyResponse>): void;
|
|
69
69
|
}
|
|
70
70
|
export declare type __ΩSQSAdapterOptions = any[];
|
|
71
|
-
//# sourceMappingURL=sqs.adapter.d.ts.map
|
|
@@ -63,4 +63,3 @@ export declare class HttpFunctionAdapter implements AdapterContract<DigitalOcean
|
|
|
63
63
|
protected getPathFromEvent(event: DigitalOceanHttpEvent): string;
|
|
64
64
|
}
|
|
65
65
|
export declare type __ΩHttpFunctionAdapterOptions = any[];
|
|
66
|
-
//# sourceMappingURL=http-function.adapter.d.ts.map
|
|
@@ -64,4 +64,3 @@ export declare class HuaweiApiGatewayAdapter implements AdapterContract<HuaweiAp
|
|
|
64
64
|
protected getPathFromEvent(event: HuaweiApiGatewayEvent): string;
|
|
65
65
|
}
|
|
66
66
|
export declare type __ΩHuaweiApiGatewayOptions = any[];
|
|
67
|
-
//# sourceMappingURL=huawei-api-gateway.adapter.d.ts.map
|
package/lib/contracts/index.d.ts
CHANGED
|
@@ -29,4 +29,3 @@ export declare abstract class BaseHandler<TApp, TEvent, TContext, TCallback, TRe
|
|
|
29
29
|
*/
|
|
30
30
|
protected getServerlessRequestResponseFromAdapterRequest(requestValues: AdapterRequest): [request: ServerlessRequest, response: ServerlessResponse];
|
|
31
31
|
}
|
|
32
|
-
//# sourceMappingURL=base-handler.d.ts.map
|
package/lib/core/constants.d.ts
CHANGED
|
@@ -46,4 +46,3 @@ export declare function getCurrentInvoke<TEvent = any, TContext = any>(): Curren
|
|
|
46
46
|
*/
|
|
47
47
|
export declare function setCurrentInvoke<TEvent = any, TContext = any>({ event, context, }: CurrentInvoke<TEvent, TContext>): void;
|
|
48
48
|
export declare type __ΩCurrentInvoke = any[];
|
|
49
|
-
//# sourceMappingURL=current-invoke.d.ts.map
|
package/lib/core/event-body.d.ts
CHANGED
package/lib/core/headers.d.ts
CHANGED
package/lib/core/index.d.ts
CHANGED
package/lib/core/is-binary.d.ts
CHANGED
package/lib/core/logger.d.ts
CHANGED
package/lib/core/no-op.d.ts
CHANGED
package/lib/core/optional.d.ts
CHANGED
package/lib/core/path.d.ts
CHANGED
|
@@ -34,4 +34,3 @@ export declare function getPathWithQueryStringParams(path: string, queryParams:
|
|
|
34
34
|
* @public
|
|
35
35
|
*/
|
|
36
36
|
export declare function getQueryParamsStringFromRecord(queryParamsRecord: Record<string, string | string[] | undefined> | undefined | null): string;
|
|
37
|
-
//# sourceMappingURL=path.d.ts.map
|
package/lib/core/stream.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Readable, Writable } from 'stream';
|
|
3
|
+
/**
|
|
4
|
+
* Check if stream already ended
|
|
5
|
+
*
|
|
6
|
+
* @param stream - The stream
|
|
7
|
+
*
|
|
8
|
+
* @breadcrumb Core / Stream
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare function isStreamEnded(stream: Readable | Writable): boolean;
|
|
3
12
|
/**
|
|
4
13
|
* Wait asynchronous the stream to complete
|
|
5
14
|
*
|
|
@@ -9,4 +18,3 @@ import { Readable, Writable } from 'stream';
|
|
|
9
18
|
* @public
|
|
10
19
|
*/
|
|
11
20
|
export declare function waitForStreamComplete<TStream extends Readable | Writable>(stream: TStream): Promise<TStream>;
|
|
12
|
-
//# sourceMappingURL=stream.d.ts.map
|
package/lib/core/stream.js
CHANGED
|
@@ -1,23 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.waitForStreamComplete = void 0;
|
|
3
|
+
exports.waitForStreamComplete = exports.isStreamEnded = void 0;
|
|
4
4
|
function __assignType(fn, args) {
|
|
5
5
|
fn.__type = args;
|
|
6
6
|
return fn;
|
|
7
7
|
}
|
|
8
8
|
//#endregion
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Check if stream already ended
|
|
11
11
|
*
|
|
12
12
|
* @param stream - The stream
|
|
13
13
|
*
|
|
14
14
|
* @breadcrumb Core / Stream
|
|
15
15
|
* @public
|
|
16
16
|
*/
|
|
17
|
-
function
|
|
17
|
+
function isStreamEnded(stream) {
|
|
18
18
|
if ('readableEnded' in stream && stream.readableEnded)
|
|
19
|
-
return
|
|
19
|
+
return true;
|
|
20
20
|
if ('writableEnded' in stream && stream.writableEnded)
|
|
21
|
+
return true;
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
exports.isStreamEnded = isStreamEnded;
|
|
25
|
+
isStreamEnded.__type = ['stream', 'isStreamEnded', 'PP!!J2!)/"'];
|
|
26
|
+
/**
|
|
27
|
+
* Wait asynchronous the stream to complete
|
|
28
|
+
*
|
|
29
|
+
* @param stream - The stream
|
|
30
|
+
*
|
|
31
|
+
* @breadcrumb Core / Stream
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
function waitForStreamComplete(stream) {
|
|
35
|
+
if (isStreamEnded(stream))
|
|
21
36
|
return Promise.resolve(stream);
|
|
22
37
|
return new Promise(__assignType((resolve, reject) => {
|
|
23
38
|
// Reading the {@link https://github.com/nodejs/node/blob/v12.22.9/lib/events.js#L262 | emit source code},
|
package/lib/core/stream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/core/stream.ts"],"names":[],"mappings":";;;;;;;AAIA,YAAY;AAEZ;;;;;;;GAOG;AACH,SAAgB,
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/core/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}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import cors, { CorsOptions } from 'cors';
|
|
4
|
+
import { FrameworkContract } from '../../contracts';
|
|
5
|
+
/**
|
|
6
|
+
* The options to customize {@link CorsFramework}
|
|
7
|
+
*
|
|
8
|
+
* @breadcrumb Frameworks / CorsFramework
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare type CorsFrameworkOptions = CorsOptions & {
|
|
12
|
+
/**
|
|
13
|
+
* Send error 403 when cors is invalid. From what I read in `cors`, `fastify/cors` and [this problem](https://stackoverflow.com/questions/57212248/why-is-http-request-been-processed-in-action-even-when-cors-is-not-enabled)
|
|
14
|
+
* it is normal to process the request even if the origin is invalid.
|
|
15
|
+
* So this option will respond with error if this method was called from an invalid origin (or not allowed method) like [access control lib](https://github.com/primus/access-control/blob/master/index.js#L95-L115) .
|
|
16
|
+
*
|
|
17
|
+
* @defaultValue true
|
|
18
|
+
*/
|
|
19
|
+
forbiddenOnInvalidOriginOrMethod?: boolean;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The framework that handles cors for your api without relying on internals of the framework
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import express from 'express';
|
|
27
|
+
* import { ServerlessAdapter } from '@h4ad/serverless-adapter';
|
|
28
|
+
* import { ExpressFramework } from '@h4ad/serverless-adapter/lib/frameworks/express';
|
|
29
|
+
* import { CorsFramework } from '@h4ad/serverless-adapter/lib/frameworks/cors';
|
|
30
|
+
*
|
|
31
|
+
* const expressFramework = new ExpressFramework();
|
|
32
|
+
* const options: CorsOptions = {}; // customize the options
|
|
33
|
+
* const framework = new CorsFramework(expressFramework, options);
|
|
34
|
+
*
|
|
35
|
+
* export const handler = ServerlessAdapter.new(null)
|
|
36
|
+
* .setFramework(framework)
|
|
37
|
+
* // set other configurations and then build
|
|
38
|
+
* .build();
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @breadcrumb Frameworks / CorsFramework
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare class CorsFramework<TApp> implements FrameworkContract<TApp> {
|
|
45
|
+
protected readonly framework: FrameworkContract<TApp>;
|
|
46
|
+
protected readonly options?: CorsFrameworkOptions | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Default Constructor
|
|
49
|
+
*/
|
|
50
|
+
constructor(framework: FrameworkContract<TApp>, options?: CorsFrameworkOptions | undefined);
|
|
51
|
+
/**
|
|
52
|
+
* All cors headers that can be added by cors package
|
|
53
|
+
*/
|
|
54
|
+
protected readonly corsHeaders: string[];
|
|
55
|
+
/**
|
|
56
|
+
* The cached instance of cors
|
|
57
|
+
*/
|
|
58
|
+
protected readonly cachedCorsInstance: ReturnType<typeof cors>;
|
|
59
|
+
/**
|
|
60
|
+
* {@inheritDoc}
|
|
61
|
+
*/
|
|
62
|
+
sendRequest(app: TApp, request: IncomingMessage, response: ServerResponse): void;
|
|
63
|
+
/**
|
|
64
|
+
* Handle next execution called by the cors package
|
|
65
|
+
*/
|
|
66
|
+
protected onCorsNext(app: TApp, request: IncomingMessage, response: ServerResponse): () => void;
|
|
67
|
+
/**
|
|
68
|
+
* Format the headers to be standardized with the rest of the library, such as ApiGatewayV2.
|
|
69
|
+
* Also, some frameworks don't support headers as an array, so we need to format the values.
|
|
70
|
+
*/
|
|
71
|
+
protected formatHeaderValuesAddedByCorsPackage(response: ServerResponse): void;
|
|
72
|
+
/**
|
|
73
|
+
* Check if the origin is invalid or if the method is not allowed.
|
|
74
|
+
* Highly inspired by [access-control](https://github.com/primus/access-control/blob/master/index.js#L95-L115)
|
|
75
|
+
*/
|
|
76
|
+
protected isInvalidOriginOrMethodIsNotAllowed(request: IncomingMessage, allowedOrigin: number | string | string[] | undefined): boolean;
|
|
77
|
+
}
|
|
78
|
+
export declare type __ΩCorsFrameworkOptions = any[];
|