@h4ad/serverless-adapter 2.10.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 +0 -1
- package/lib/adapters/aws/lambda-edge.adapter.d.ts +0 -1
- package/lib/adapters/aws/s3.adapter.d.ts +0 -1
- 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/s3.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
|
|
@@ -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
|
|
@@ -68,4 +68,3 @@ export declare class S3Adapter implements AdapterContract<S3Event, Context, IEmp
|
|
|
68
68
|
onErrorWhileForwarding({ error, delegatedResolver, }: OnErrorProps<S3Event, IEmptyResponse>): void;
|
|
69
69
|
}
|
|
70
70
|
export declare type __ΩS3AdapterOptions = any[];
|
|
71
|
-
//# sourceMappingURL=s3.adapter.d.ts.map
|
|
@@ -68,4 +68,3 @@ export declare class SNSAdapter implements AdapterContract<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/stream.ts"],"names":[],"mappings":";;;;;;;AAIA,YAAY;AAEZ;;;;;;;GAOG;AACH,SAAgB,aAAa,CAAC,MAA2B;IACvD,IAAI,eAAe,IAAI,MAAM,IAAI,MAAM,CAAC,aAAa;QAAE,OAAO,IAAI,CAAC;IAEnE,IAAI,eAAe,IAAI,MAAM,IAAI,MAAM,CAAC,aAAa;QAAE,OAAO,IAAI,CAAC;IAEnE,OAAO,KAAK,CAAC;AACf,CAAC;AAND,sCAMC;;AAED;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CACnC,MAAe;IAEf,IAAI,aAAa,CAAC,MAAM,CAAC;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAE1D,OAAO,IAAI,OAAO,cAAU,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9C,0GAA0G;QAC1G,sIAAsI;QACtI,mIAAmI;QACnI,IAAI,UAAU,GAAG,KAAK,CAAC;QAEvB,SAAS,QAAQ,CAAC,GAAG;YACnB,0BAA0B;YAC1B,IAAI,UAAU;gBAAE,OAAO;YAEvB,UAAU,GAAG,IAAI,CAAC;YAElB,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACzC,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YACvC,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAE1C,IAAI,GAAG;gBAAE,MAAM,CAAC,GAAG,CAAC,CAAC;;gBAChB,OAAO,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;;QAED,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC/B,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC7B,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC,2CAAC,CAAC;AACL,CAAC;AA7BD,sDA6BC"}
|
|
@@ -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[];
|
|
@@ -0,0 +1,145 @@
|
|
|
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.CorsFramework = exports.__ΩCorsFrameworkOptions = void 0;
|
|
7
|
+
const { __ΩFrameworkContract } = require('../../contracts');
|
|
8
|
+
function __assignType(fn, args) {
|
|
9
|
+
fn.__type = args;
|
|
10
|
+
return fn;
|
|
11
|
+
}
|
|
12
|
+
const __ΩReturnType = ['T', 'args', '', 'l>e"!R"RPde#!P"@2"h"!/#qk#\'QRb!Pde"!p)'];
|
|
13
|
+
const cors_1 = __importDefault(require("cors"));
|
|
14
|
+
const core_1 = require("../../core");
|
|
15
|
+
const __ΩCorsFrameworkOptions = ['forbiddenOnInvalidOriginOrMethod', 'P!P)4!8MK'];
|
|
16
|
+
exports.__ΩCorsFrameworkOptions = __ΩCorsFrameworkOptions;
|
|
17
|
+
/**
|
|
18
|
+
* The framework that handles cors for your api without relying on internals of the framework
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import express from 'express';
|
|
23
|
+
* import { ServerlessAdapter } from '@h4ad/serverless-adapter';
|
|
24
|
+
* import { ExpressFramework } from '@h4ad/serverless-adapter/lib/frameworks/express';
|
|
25
|
+
* import { CorsFramework } from '@h4ad/serverless-adapter/lib/frameworks/cors';
|
|
26
|
+
*
|
|
27
|
+
* const expressFramework = new ExpressFramework();
|
|
28
|
+
* const options: CorsOptions = {}; // customize the options
|
|
29
|
+
* const framework = new CorsFramework(expressFramework, options);
|
|
30
|
+
*
|
|
31
|
+
* export const handler = ServerlessAdapter.new(null)
|
|
32
|
+
* .setFramework(framework)
|
|
33
|
+
* // set other configurations and then build
|
|
34
|
+
* .build();
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @breadcrumb Frameworks / CorsFramework
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
class CorsFramework {
|
|
41
|
+
//#region Constructor
|
|
42
|
+
/**
|
|
43
|
+
* Default Constructor
|
|
44
|
+
*/
|
|
45
|
+
constructor(framework, options) {
|
|
46
|
+
this.framework = framework;
|
|
47
|
+
this.options = options;
|
|
48
|
+
//#endregion
|
|
49
|
+
/**
|
|
50
|
+
* All cors headers that can be added by cors package
|
|
51
|
+
*/
|
|
52
|
+
this.corsHeaders = [
|
|
53
|
+
'Access-Control-Max-Age',
|
|
54
|
+
'Access-Control-Expose-Headers',
|
|
55
|
+
'Access-Control-Allow-Headers',
|
|
56
|
+
'Access-Control-Request-Headers',
|
|
57
|
+
'Access-Control-Allow-Credentials',
|
|
58
|
+
'Access-Control-Allow-Methods',
|
|
59
|
+
'Access-Control-Allow-Origin',
|
|
60
|
+
];
|
|
61
|
+
this.cachedCorsInstance = (0, cors_1.default)(this.options);
|
|
62
|
+
}
|
|
63
|
+
//#region Public Methods
|
|
64
|
+
/**
|
|
65
|
+
* {@inheritDoc}
|
|
66
|
+
*/
|
|
67
|
+
sendRequest(app, request, response) {
|
|
68
|
+
this.cachedCorsInstance(request, response, this.onCorsNext(app, request, response));
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region Protected Methods
|
|
72
|
+
/**
|
|
73
|
+
* Handle next execution called by the cors package
|
|
74
|
+
*/
|
|
75
|
+
onCorsNext(app, request, response) {
|
|
76
|
+
return () => {
|
|
77
|
+
var _a;
|
|
78
|
+
this.formatHeaderValuesAddedByCorsPackage(response);
|
|
79
|
+
const errorOnInvalidOrigin = (0, core_1.getDefaultIfUndefined)((_a = this.options) === null || _a === void 0 ? void 0 : _a.forbiddenOnInvalidOriginOrMethod, true);
|
|
80
|
+
if (errorOnInvalidOrigin) {
|
|
81
|
+
const allowedOrigin = response.getHeader('access-control-allow-origin');
|
|
82
|
+
const isInvalidOrigin = this.isInvalidOriginOrMethodIsNotAllowed(request, allowedOrigin);
|
|
83
|
+
if (isInvalidOrigin) {
|
|
84
|
+
response.statusCode = 403;
|
|
85
|
+
response.setHeader('Content-Type', 'text/plain');
|
|
86
|
+
response.end([
|
|
87
|
+
'Invalid HTTP Access Control (CORS) request:',
|
|
88
|
+
` Origin: ${request.headers.origin}`,
|
|
89
|
+
` Method: ${request.method}`,
|
|
90
|
+
].join('\n'));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
this.framework.sendRequest(app, request, response);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Format the headers to be standardized with the rest of the library, such as ApiGatewayV2.
|
|
99
|
+
* Also, some frameworks don't support headers as an array, so we need to format the values.
|
|
100
|
+
*/
|
|
101
|
+
formatHeaderValuesAddedByCorsPackage(response) {
|
|
102
|
+
for (const corsHeader of this.corsHeaders) {
|
|
103
|
+
const value = response.getHeader(corsHeader);
|
|
104
|
+
if (value === undefined)
|
|
105
|
+
continue;
|
|
106
|
+
response.removeHeader(corsHeader);
|
|
107
|
+
response.setHeader(corsHeader.toLowerCase(), Array.isArray(value) ? value.join(',') : value);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Check if the origin is invalid or if the method is not allowed.
|
|
112
|
+
* Highly inspired by [access-control](https://github.com/primus/access-control/blob/master/index.js#L95-L115)
|
|
113
|
+
*/
|
|
114
|
+
isInvalidOriginOrMethodIsNotAllowed(request, allowedOrigin) {
|
|
115
|
+
var _a;
|
|
116
|
+
if (!allowedOrigin)
|
|
117
|
+
return true;
|
|
118
|
+
if (!!request.headers.origin &&
|
|
119
|
+
allowedOrigin !== '*' &&
|
|
120
|
+
request.headers.origin !== allowedOrigin)
|
|
121
|
+
return true;
|
|
122
|
+
const notPermitedInMethods = this.options &&
|
|
123
|
+
Array.isArray(this.options.methods) &&
|
|
124
|
+
this.options.methods.every(__assignType(m => { var _a; return m.toLowerCase() !== ((_a = request.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()); }, ['m', '', 'P"2!"/"']));
|
|
125
|
+
const differentMethod = this.options &&
|
|
126
|
+
typeof this.options.methods === 'string' &&
|
|
127
|
+
this.options.methods
|
|
128
|
+
.split(',')
|
|
129
|
+
.every(__assignType(m => { var _a; return m.trim().toLowerCase() !== ((_a = request.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()); }, ['m', '', 'P"2!"/"']));
|
|
130
|
+
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.methods) && (notPermitedInMethods || differentMethod))
|
|
131
|
+
return true;
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.CorsFramework = CorsFramework;
|
|
136
|
+
CorsFramework.__type = ['TApp', () => __ΩFrameworkContract, 'framework', () => __ΩCorsFrameworkOptions, 'options', 'constructor', 'corsHeaders', function () { return [
|
|
137
|
+
'Access-Control-Max-Age',
|
|
138
|
+
'Access-Control-Expose-Headers',
|
|
139
|
+
'Access-Control-Allow-Headers',
|
|
140
|
+
'Access-Control-Request-Headers',
|
|
141
|
+
'Access-Control-Allow-Credentials',
|
|
142
|
+
'Access-Control-Allow-Methods',
|
|
143
|
+
'Access-Control-Allow-Origin',
|
|
144
|
+
]; }, () => __ΩReturnType, () => cors_1.default, 'cachedCorsInstance', 'app', 'request', 'response', 'sendRequest', '', 'onCorsNext', 'formatHeaderValuesAddedByCorsPackage', 'allowedOrigin', 'isInvalidOriginOrMethodIsNotAllowed', 'b!Pe"!o""2#<9n$2%8<9"0&&F3\'9<>(i*o)"3+9<Pe"!2,!2-!2.$0/Pe"!2,!2-!2.P$/001<P!2.$02<P!2-P\'&&F-J23)04<5e!!6"'];
|
|
145
|
+
//# sourceMappingURL=cors.framework.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cors.framework.js","sourceRoot":"","sources":["../../../src/frameworks/cors/cors.framework.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cors.framework';
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./cors.framework"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/frameworks/cors/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC"}
|