@h4ad/serverless-adapter 2.9.0 → 2.10.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.
@@ -4,6 +4,7 @@ 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
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
@@ -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"}
@@ -0,0 +1,71 @@
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[];
71
+ //# sourceMappingURL=s3.adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3.adapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws/s3.adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAEL,cAAc,EAGf,MAAM,YAAY,CAAC;AAIpB;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,SACX,YAAW,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,CAAC;IAShD,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC;IALvC;;;;OAIG;gBAC4B,OAAO,CAAC,8BAAkB;IAMzD;;OAEG;IACI,cAAc,IAAI,MAAM;IAI/B;;OAEG;IACI,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO;IAUlD;;OAEG;IACI,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc;IAuBjD;;OAEG;IACI,WAAW,IAAI,cAAc;IAIpC;;OAEG;IACI,sBAAsB,CAAC,EAC5B,KAAK,EACL,iBAAiB,GAClB,EAAE,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,GAAG,IAAI;CAKhD"}
@@ -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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C,aAAa,CAAC;SACxC,CAAC;QAEF,OAAO;YACL,MAAM;YACN,OAAO;YACP,IAAI;YACJ,IAAI;SACL,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,WAAW;QAChB,OAAO,oBAAa,CAAC;IACvB,CAAC;IAED;;OAEG;IACI,sBAAsB,CAAC,EAC5B,KAAK,EACL,iBAAiB,GACqB;QACtC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;;AA7EH,8BAgFC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h4ad/serverless-adapter",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
4
4
  "description": "Run REST APIs and other web applications using your existing Node.js application framework (NestJS, Express, Koa, Hapi, Fastify and many others), on top of AWS, Azure, Huawei and many other clouds.",
5
5
  "main": "./lib/index.js",
6
6
  "files": [