@h4ad/serverless-adapter 2.2.0 → 2.3.2

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.
Files changed (264) hide show
  1. package/README.md +4 -253
  2. package/lib/@types/binary-settings.d.ts +24 -6
  3. package/lib/@types/binary-settings.d.ts.map +1 -0
  4. package/lib/@types/binary-settings.js +1 -0
  5. package/lib/@types/binary-settings.js.map +1 -0
  6. package/lib/@types/headers.d.ts +16 -3
  7. package/lib/@types/headers.d.ts.map +1 -0
  8. package/lib/@types/headers.js +1 -0
  9. package/lib/@types/headers.js.map +1 -0
  10. package/lib/@types/helpers.d.ts +4 -0
  11. package/lib/@types/helpers.d.ts.map +1 -0
  12. package/lib/@types/helpers.js +1 -0
  13. package/lib/@types/helpers.js.map +1 -0
  14. package/lib/@types/huawei/huawei-api-gateway-event.d.ts +62 -0
  15. package/lib/@types/huawei/huawei-api-gateway-event.d.ts.map +1 -0
  16. package/lib/@types/huawei/huawei-api-gateway-event.js +2 -0
  17. package/lib/@types/huawei/huawei-api-gateway-event.js.map +1 -0
  18. package/lib/@types/huawei/huawei-api-gateway-response.d.ts +20 -0
  19. package/lib/@types/huawei/huawei-api-gateway-response.d.ts.map +1 -0
  20. package/lib/@types/huawei/huawei-api-gateway-response.js +2 -0
  21. package/lib/@types/huawei/huawei-api-gateway-response.js.map +1 -0
  22. package/lib/@types/huawei/huawei-context.d.ts +157 -0
  23. package/lib/@types/huawei/huawei-context.d.ts.map +1 -0
  24. package/lib/@types/huawei/huawei-context.js +1 -0
  25. package/lib/@types/huawei/huawei-context.js.map +1 -0
  26. package/lib/@types/huawei/index.d.ts +1 -0
  27. package/lib/@types/huawei/index.d.ts.map +1 -0
  28. package/lib/@types/huawei/index.js +6 -1
  29. package/lib/@types/huawei/index.js.map +1 -0
  30. package/lib/@types/index.d.ts +2 -1
  31. package/lib/@types/index.d.ts.map +1 -0
  32. package/lib/@types/index.js +7 -2
  33. package/lib/@types/index.js.map +1 -0
  34. package/lib/adapters/aws/alb.adapter.d.ts +18 -10
  35. package/lib/adapters/aws/alb.adapter.d.ts.map +1 -0
  36. package/lib/adapters/aws/alb.adapter.js +14 -9
  37. package/lib/adapters/aws/alb.adapter.js.map +1 -0
  38. package/lib/adapters/aws/api-gateway-v1.adapter.d.ts +20 -12
  39. package/lib/adapters/aws/api-gateway-v1.adapter.d.ts.map +1 -0
  40. package/lib/adapters/aws/api-gateway-v1.adapter.js +19 -14
  41. package/lib/adapters/aws/api-gateway-v1.adapter.js.map +1 -0
  42. package/lib/adapters/aws/api-gateway-v2.adapter.d.ts +19 -11
  43. package/lib/adapters/aws/api-gateway-v2.adapter.d.ts.map +1 -0
  44. package/lib/adapters/aws/api-gateway-v2.adapter.js +15 -10
  45. package/lib/adapters/aws/api-gateway-v2.adapter.js.map +1 -0
  46. package/lib/adapters/aws/dynamodb.adapter.d.ts +18 -10
  47. package/lib/adapters/aws/dynamodb.adapter.d.ts.map +1 -0
  48. package/lib/adapters/aws/dynamodb.adapter.js +13 -8
  49. package/lib/adapters/aws/dynamodb.adapter.js.map +1 -0
  50. package/lib/adapters/aws/event-bridge.adapter.d.ts +21 -10
  51. package/lib/adapters/aws/event-bridge.adapter.d.ts.map +1 -0
  52. package/lib/adapters/aws/event-bridge.adapter.js +13 -8
  53. package/lib/adapters/aws/event-bridge.adapter.js.map +1 -0
  54. package/lib/adapters/aws/index.d.ts +1 -0
  55. package/lib/adapters/aws/index.d.ts.map +1 -0
  56. package/lib/adapters/aws/index.js +6 -1
  57. package/lib/adapters/aws/index.js.map +1 -0
  58. package/lib/adapters/aws/lambda-edge.adapter.d.ts +76 -46
  59. package/lib/adapters/aws/lambda-edge.adapter.d.ts.map +1 -0
  60. package/lib/adapters/aws/lambda-edge.adapter.js +40 -24
  61. package/lib/adapters/aws/lambda-edge.adapter.js.map +1 -0
  62. package/lib/adapters/aws/sns.adapter.d.ts +18 -10
  63. package/lib/adapters/aws/sns.adapter.d.ts.map +1 -0
  64. package/lib/adapters/aws/sns.adapter.js +13 -8
  65. package/lib/adapters/aws/sns.adapter.js.map +1 -0
  66. package/lib/adapters/aws/sqs.adapter.d.ts +18 -10
  67. package/lib/adapters/aws/sqs.adapter.d.ts.map +1 -0
  68. package/lib/adapters/aws/sqs.adapter.js +13 -8
  69. package/lib/adapters/aws/sqs.adapter.js.map +1 -0
  70. package/lib/adapters/dummy/dummy.adapter.d.ts +9 -5
  71. package/lib/adapters/dummy/dummy.adapter.d.ts.map +1 -0
  72. package/lib/adapters/dummy/dummy.adapter.js +9 -5
  73. package/lib/adapters/dummy/dummy.adapter.js.map +1 -0
  74. package/lib/adapters/dummy/index.d.ts +1 -0
  75. package/lib/adapters/dummy/index.d.ts.map +1 -0
  76. package/lib/adapters/dummy/index.js +6 -1
  77. package/lib/adapters/dummy/index.js.map +1 -0
  78. package/lib/adapters/huawei/huawei-api-gateway.adapter.d.ts +19 -12
  79. package/lib/adapters/huawei/huawei-api-gateway.adapter.d.ts.map +1 -0
  80. package/lib/adapters/huawei/huawei-api-gateway.adapter.js +14 -9
  81. package/lib/adapters/huawei/huawei-api-gateway.adapter.js.map +1 -0
  82. package/lib/adapters/huawei/index.d.ts +1 -0
  83. package/lib/adapters/huawei/index.d.ts.map +1 -0
  84. package/lib/adapters/huawei/index.js +6 -1
  85. package/lib/adapters/huawei/index.js.map +1 -0
  86. package/lib/contracts/adapter.contract.d.ts +30 -30
  87. package/lib/contracts/adapter.contract.d.ts.map +1 -0
  88. package/lib/contracts/adapter.contract.js +2 -0
  89. package/lib/contracts/adapter.contract.js.map +1 -0
  90. package/lib/contracts/framework.contract.d.ts +7 -3
  91. package/lib/contracts/framework.contract.d.ts.map +1 -0
  92. package/lib/contracts/framework.contract.js +1 -0
  93. package/lib/contracts/framework.contract.js.map +1 -0
  94. package/lib/contracts/handler.contract.d.ts +7 -0
  95. package/lib/contracts/handler.contract.d.ts.map +1 -0
  96. package/lib/contracts/handler.contract.js +1 -0
  97. package/lib/contracts/handler.contract.js.map +1 -0
  98. package/lib/contracts/index.d.ts +1 -0
  99. package/lib/contracts/index.d.ts.map +1 -0
  100. package/lib/contracts/index.js +6 -1
  101. package/lib/contracts/index.js.map +1 -0
  102. package/lib/contracts/resolver.contract.d.ts +17 -4
  103. package/lib/contracts/resolver.contract.d.ts.map +1 -0
  104. package/lib/contracts/resolver.contract.js +1 -0
  105. package/lib/contracts/resolver.contract.js.map +1 -0
  106. package/lib/core/base-handler.d.ts +9 -5
  107. package/lib/core/base-handler.d.ts.map +1 -0
  108. package/lib/core/base-handler.js +9 -5
  109. package/lib/core/base-handler.js.map +1 -0
  110. package/lib/core/constants.d.ts +27 -0
  111. package/lib/core/constants.d.ts.map +1 -0
  112. package/lib/core/constants.js +21 -0
  113. package/lib/core/constants.js.map +1 -0
  114. package/lib/core/current-invoke.d.ts +17 -6
  115. package/lib/core/current-invoke.d.ts.map +1 -0
  116. package/lib/core/current-invoke.js +12 -4
  117. package/lib/core/current-invoke.js.map +1 -0
  118. package/lib/core/event-body.d.ts +9 -3
  119. package/lib/core/event-body.d.ts.map +1 -0
  120. package/lib/core/event-body.js +9 -3
  121. package/lib/core/event-body.js.map +1 -0
  122. package/lib/core/headers.d.ts +17 -6
  123. package/lib/core/headers.d.ts.map +1 -0
  124. package/lib/core/headers.js +17 -6
  125. package/lib/core/headers.js.map +1 -0
  126. package/lib/core/index.d.ts +1 -0
  127. package/lib/core/index.d.ts.map +1 -0
  128. package/lib/core/index.js +6 -1
  129. package/lib/core/index.js.map +1 -0
  130. package/lib/core/is-binary.d.ts +29 -11
  131. package/lib/core/is-binary.d.ts.map +1 -0
  132. package/lib/core/is-binary.js +29 -11
  133. package/lib/core/is-binary.js.map +1 -0
  134. package/lib/core/logger.d.ts +22 -5
  135. package/lib/core/logger.d.ts.map +1 -0
  136. package/lib/core/logger.js +8 -3
  137. package/lib/core/logger.js.map +1 -0
  138. package/lib/core/no-op.d.ts +4 -0
  139. package/lib/core/no-op.d.ts.map +1 -0
  140. package/lib/core/no-op.js +4 -0
  141. package/lib/core/no-op.js.map +1 -0
  142. package/lib/core/optional.d.ts +8 -3
  143. package/lib/core/optional.d.ts.map +1 -0
  144. package/lib/core/optional.js +8 -3
  145. package/lib/core/optional.js.map +1 -0
  146. package/lib/core/path.d.ts +14 -5
  147. package/lib/core/path.d.ts.map +1 -0
  148. package/lib/core/path.js +14 -5
  149. package/lib/core/path.js.map +1 -0
  150. package/lib/core/stream.d.ts +5 -1
  151. package/lib/core/stream.d.ts.map +1 -0
  152. package/lib/core/stream.js +6 -2
  153. package/lib/core/stream.js.map +1 -0
  154. package/lib/frameworks/express/express.framework.d.ts +5 -1
  155. package/lib/frameworks/express/express.framework.d.ts.map +1 -0
  156. package/lib/frameworks/express/express.framework.js +5 -1
  157. package/lib/frameworks/express/express.framework.js.map +1 -0
  158. package/lib/frameworks/express/index.d.ts +1 -0
  159. package/lib/frameworks/express/index.d.ts.map +1 -0
  160. package/lib/frameworks/express/index.js +6 -1
  161. package/lib/frameworks/express/index.js.map +1 -0
  162. package/lib/frameworks/fastify/fastify.framework.d.ts +5 -1
  163. package/lib/frameworks/fastify/fastify.framework.d.ts.map +1 -0
  164. package/lib/frameworks/fastify/fastify.framework.js +5 -1
  165. package/lib/frameworks/fastify/fastify.framework.js.map +1 -0
  166. package/lib/frameworks/fastify/index.d.ts +1 -0
  167. package/lib/frameworks/fastify/index.d.ts.map +1 -0
  168. package/lib/frameworks/fastify/index.js +6 -1
  169. package/lib/frameworks/fastify/index.js.map +1 -0
  170. package/lib/frameworks/hapi/hapi.framework.d.ts +5 -1
  171. package/lib/frameworks/hapi/hapi.framework.d.ts.map +1 -0
  172. package/lib/frameworks/hapi/hapi.framework.js +5 -1
  173. package/lib/frameworks/hapi/hapi.framework.js.map +1 -0
  174. package/lib/frameworks/hapi/index.d.ts +1 -0
  175. package/lib/frameworks/hapi/index.d.ts.map +1 -0
  176. package/lib/frameworks/hapi/index.js +6 -1
  177. package/lib/frameworks/hapi/index.js.map +1 -0
  178. package/lib/frameworks/koa/index.d.ts +1 -0
  179. package/lib/frameworks/koa/index.d.ts.map +1 -0
  180. package/lib/frameworks/koa/index.js +6 -1
  181. package/lib/frameworks/koa/index.js.map +1 -0
  182. package/lib/frameworks/koa/koa.framework.d.ts +5 -1
  183. package/lib/frameworks/koa/koa.framework.d.ts.map +1 -0
  184. package/lib/frameworks/koa/koa.framework.js +5 -1
  185. package/lib/frameworks/koa/koa.framework.js.map +1 -0
  186. package/lib/frameworks/lazy/index.d.ts +2 -0
  187. package/lib/frameworks/lazy/index.d.ts.map +1 -0
  188. package/lib/frameworks/lazy/index.js +18 -0
  189. package/lib/frameworks/lazy/index.js.map +1 -0
  190. package/lib/frameworks/lazy/lazy.framework.d.ts +56 -0
  191. package/lib/frameworks/lazy/lazy.framework.d.ts.map +1 -0
  192. package/lib/frameworks/lazy/lazy.framework.js +75 -0
  193. package/lib/frameworks/lazy/lazy.framework.js.map +1 -0
  194. package/lib/handlers/default/default.handler.d.ts +36 -32
  195. package/lib/handlers/default/default.handler.d.ts.map +1 -0
  196. package/lib/handlers/default/default.handler.js +36 -32
  197. package/lib/handlers/default/default.handler.js.map +1 -0
  198. package/lib/handlers/default/index.d.ts +1 -0
  199. package/lib/handlers/default/index.d.ts.map +1 -0
  200. package/lib/handlers/default/index.js +6 -1
  201. package/lib/handlers/default/index.js.map +1 -0
  202. package/lib/handlers/huawei/http-huawei.handler.d.ts +14 -4
  203. package/lib/handlers/huawei/http-huawei.handler.d.ts.map +1 -0
  204. package/lib/handlers/huawei/http-huawei.handler.js +15 -4
  205. package/lib/handlers/huawei/http-huawei.handler.js.map +1 -0
  206. package/lib/handlers/huawei/index.d.ts +1 -0
  207. package/lib/handlers/huawei/index.d.ts.map +1 -0
  208. package/lib/handlers/huawei/index.js +6 -1
  209. package/lib/handlers/huawei/index.js.map +1 -0
  210. package/lib/index.d.ts +1 -0
  211. package/lib/index.d.ts.map +1 -0
  212. package/lib/index.js +6 -1
  213. package/lib/index.js.map +1 -0
  214. package/lib/network/index.d.ts +1 -0
  215. package/lib/network/index.d.ts.map +1 -0
  216. package/lib/network/index.js +6 -1
  217. package/lib/network/index.js.map +1 -0
  218. package/lib/network/request.d.ts +28 -0
  219. package/lib/network/request.d.ts.map +1 -0
  220. package/lib/network/request.js +7 -0
  221. package/lib/network/request.js.map +1 -0
  222. package/lib/network/response.d.ts +18 -1
  223. package/lib/network/response.d.ts.map +1 -0
  224. package/lib/network/response.js +9 -1
  225. package/lib/network/response.js.map +1 -0
  226. package/lib/resolvers/aws-context/aws-context.resolver.d.ts +7 -9
  227. package/lib/resolvers/aws-context/aws-context.resolver.d.ts.map +1 -0
  228. package/lib/resolvers/aws-context/aws-context.resolver.js +7 -9
  229. package/lib/resolvers/aws-context/aws-context.resolver.js.map +1 -0
  230. package/lib/resolvers/aws-context/index.d.ts +1 -0
  231. package/lib/resolvers/aws-context/index.d.ts.map +1 -0
  232. package/lib/resolvers/aws-context/index.js +6 -1
  233. package/lib/resolvers/aws-context/index.js.map +1 -0
  234. package/lib/resolvers/callback/callback.resolver.d.ts +9 -2
  235. package/lib/resolvers/callback/callback.resolver.d.ts.map +1 -0
  236. package/lib/resolvers/callback/callback.resolver.js +6 -2
  237. package/lib/resolvers/callback/callback.resolver.js.map +1 -0
  238. package/lib/resolvers/callback/index.d.ts +1 -0
  239. package/lib/resolvers/callback/index.d.ts.map +1 -0
  240. package/lib/resolvers/callback/index.js +6 -1
  241. package/lib/resolvers/callback/index.js.map +1 -0
  242. package/lib/resolvers/dummy/dummy.resolver.d.ts +5 -1
  243. package/lib/resolvers/dummy/dummy.resolver.d.ts.map +1 -0
  244. package/lib/resolvers/dummy/dummy.resolver.js +5 -1
  245. package/lib/resolvers/dummy/dummy.resolver.js.map +1 -0
  246. package/lib/resolvers/dummy/index.d.ts +1 -0
  247. package/lib/resolvers/dummy/index.d.ts.map +1 -0
  248. package/lib/resolvers/dummy/index.js +6 -1
  249. package/lib/resolvers/dummy/index.js.map +1 -0
  250. package/lib/resolvers/promise/index.d.ts +1 -0
  251. package/lib/resolvers/promise/index.d.ts.map +1 -0
  252. package/lib/resolvers/promise/index.js +6 -1
  253. package/lib/resolvers/promise/index.js.map +1 -0
  254. package/lib/resolvers/promise/promise.resolver.d.ts +5 -1
  255. package/lib/resolvers/promise/promise.resolver.d.ts.map +1 -0
  256. package/lib/resolvers/promise/promise.resolver.js +5 -1
  257. package/lib/resolvers/promise/promise.resolver.js.map +1 -0
  258. package/lib/serverless-adapter.d.ts +17 -12
  259. package/lib/serverless-adapter.d.ts.map +1 -0
  260. package/lib/serverless-adapter.js +17 -12
  261. package/lib/serverless-adapter.js.map +1 -0
  262. package/package.json +22 -2
  263. package/lib/@types/proxy-params.d.ts +0 -8
  264. package/lib/@types/proxy-params.js +0 -2
package/README.md CHANGED
@@ -23,7 +23,7 @@ Run REST APIs and other web applications using your existing Node.js application
23
23
  Fastify), on top of AWS Lambda, Huawei and many other clouds.
24
24
 
25
25
  This library was a refactored version of [@vendia/serverless-express](https://github.com/vendia/serverless-express), I
26
- created a new way to interact and extend event sources by creating contracts to abstract the integrations between each
26
+ create a new way to interact and extend event sources by creating contracts to abstract the integrations between each
27
27
  library layer.
28
28
 
29
29
  Why you would use this libray instead of [@vendia/serverless-express](https://github.com/vendia/serverless-express)?
@@ -35,266 +35,17 @@ Why you would use this libray instead of [@vendia/serverless-express](https://gi
35
35
  - This is important because if you find a bug, you can quickly resolve it by extending the class, _and then you can
36
36
  submit a PR to fix the bug_.
37
37
  - All code was written in Typescript.
38
+ - Well documented, any method, class, or interface has comments to explain the behavior.
38
39
  - We have >99% coverage.
39
40
 
40
- # Install
41
+ # Documentation
41
42
 
42
- Using NPM:
43
-
44
- ```bash
45
- npm install --save @h4ad/serverless-adapter
46
- ```
47
-
48
- Using Yarn:
49
-
50
- ```bash
51
- yarn add @h4ad/serverless-adapter
52
- ```
53
-
54
- # Usage
55
-
56
- You can quickly use this library as follows:
57
-
58
- ```ts
59
- import { ServerlessAdapter } from '@h4ad/serverless-adapter';
60
- import { ApiGatewayV2Adapter, AlbAdapter, SQSAdapter, SNSAdapter } from '@h4ad/serverless-adapter/lib/adapters/aws';
61
- import { ExpressFramework } from '@h4ad/serverless-adapter/lib/frameworks/express';
62
- import { DefaultHandler } from '@h4ad/serverless-adapter/lib/handlers/default';
63
- import { PromiseResolver } from '@h4ad/serverless-adapter/lib/resolvers/promise';
64
- import app from './app';
65
-
66
- export const handler = ServerlessAdapter.new(app)
67
- .setFramework(new ExpressFramework())
68
- .setHandler(new DefaultHandler())
69
- .setResolver(new PromiseResolver())
70
- .addAdapter(new AlbAdapter())
71
- .addAdapter(new SQSAdapter())
72
- .addAdapter(new SNSAdapter())
73
- .build();
74
- ```
75
-
76
- Too fast? Ok, I can explain.
77
-
78
- First, you need to create an instance of the builder with `ServerlessAdapter.new(app)`. The variable `app` is the
79
- instance of your framework (Express, Fastify, Koa, etc).
80
-
81
- So you need to specify for this library which `framework` you will use to handle the `request` with `setFramework`, you
82
- can only use one. If you use express in our backend, use [ExpressFramework](src/frameworks/express/express.framework.ts)
83
- , see more in [support](#support).
84
-
85
- Then you specify which `handler` you will use to interact with the serverless cloud with `setHandler`, currently we only
86
- have one, the [DefaultHandler](src/handlers/default/default.handler.ts). In the next releases, maybe we will add support
87
- for Azure, Huawei and others, for now, you can use this default.
88
-
89
- Then you specify with `setResolver` which `resolver` you will use to wait for the library to forward the request to
90
- your `framework`, and then get the `response` back to your cloud. I recommend you
91
- use [PromiseResolver](src/resolvers/promise/promise.resolver.ts), it's the most cloud-agnostic `resolver`.
92
-
93
- By now, you've already added the basic abstractions of this library, now, you can add the `adapters` that will add
94
- support for receiving and processing different sources of `addAdapter` events. In the example I
95
- added [AlbAdapter](./src/adapters/aws/alb.adapter.ts), [SQSAdapter](./src/adapters/aws/sqs.adapter.ts)
96
- and [SNSAdapter](./src/adapters/aws/sns.adapter.ts). With these adapters you can connect your lambda to three different
97
- event sources and you can add more if you wish.
98
-
99
- Finally, we call `build` which will assemble your handler that you can expose directly to your cloud.
100
-
101
- Final thoughts:
102
-
103
- - You can set the `framework` only once.
104
- - You can set the `handler` only once.
105
- - You can set the `resolver` only once.
106
- - You can have as many `adapters` as you like, use and extend as you wish.
107
-
108
- # Support
109
-
110
- > We are in beta, so some adapters may not work as expected, feel free to create an issue or provide feedback on current behavior.
111
-
112
- By design we have these contracts that define the layers of the library: Frameworks, Adapters, Resolvers and Handlers.
113
-
114
- > If you don't know what each thing means, see [Architecture](#architecture).
115
-
116
- Currently, we support these frameworks:
117
-
118
- - [Express](https://expressjs.com/) by using ([ExpressFramework](src/frameworks/express/express.framework.ts))
119
- - [Fastify](https://www.fastify.io/) by using ([FastifyFramework](src/frameworks/fastify/fastify.framework.ts))
120
- - [Hapi](https://hapi.dev/) by using ([HapiFramework](src/frameworks/hapi/hapi.framework.ts))
121
- - [Koa](https://koajs.com/) by using ([KoaFramework](src/frameworks/koa/koa.framework.ts))
122
-
123
- We support these event sources:
124
-
125
- - AWS
126
- - [AWS Load Balancer](https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html) by
127
- using ([AlbAdapter](./src/adapters/aws/alb.adapter.ts))
128
- - [AWS Api Gateway V1](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html)
129
- by using ([ApiGatewayV1Adapter](./src/adapters/aws/api-gateway-v1.adapter.ts))
130
- - [AWS Api Gateway V2](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html)
131
- by using ([ApiGatewayV2Adapter](./src/adapters/aws/api-gateway-v2.adapter.ts))
132
- - [AWS DynamoDB](https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html) by
133
- using ([DynamoDBAdapter](./src/adapters/aws/dynamodb.adapter.ts))
134
- - [AWS Event Bridge / CloudWatch Events](https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents.html)
135
- by using ([EventBridgeAdapter](./src/adapters/aws/event-bridge.adapter.ts))
136
- - [AWS Lambda Edge](https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html) by
137
- using ([LambdaEdgeAdapter](./src/adapters/aws/lambda-edge.adapter.ts))
138
- - [AWS SNS](https://docs.aws.amazon.com/pt_br/lambda/latest/dg/with-sns.html) by
139
- using ([SNSAdapter](./src/adapters/aws/sns.adapter.ts))
140
- - [AWS SQS](https://docs.aws.amazon.com/pt_br/lambda/latest/dg/with-sqs.html) by
141
- using ([SQSAdapter](./src/adapters/aws/sqs.adapter.ts))
142
- - Huawei
143
- - [Http Function](https://support.huaweicloud.com/intl/en-us/usermanual-functiongraph/functiongraph_01_1442.html): Look [this section](#huawei-http-function) about Huawei support for Http Function.
144
- - [Event Function](https://support.huaweicloud.com/intl/en-us/usermanual-functiongraph/functiongraph_01_1441.html):
145
- - [Api Gateway](https://support.huaweicloud.com/intl/en-us/devg-functiongraph/functiongraph_02_0102.html#functiongraph_02_0102__li5178638110137) by using ([HuaweiApiGatewayAdapter](src/adapters/huawei/huawei-api-gateway.adapter.ts)).
146
- - Azure
147
- - [The support is coming soon.](https://github.com/H4ad/serverless-adapter/issues/3)
148
- - Firebase
149
- - The support is coming soon.
150
- - GCP
151
- - The support is coming soon.
152
-
153
- We support these resolvers:
154
-
155
- - Promise by using ([PromiseResolver](src/resolvers/promise/promise.resolver.ts))
156
- - Callback by using ([CallbackResolver](src/resolvers/callback/callback.resolver.ts))
157
- - AWS Context by using ([AwsContextResolver](src/resolvers/aws-context/aws-context.resolver.ts))
158
-
159
- We support these handlers:
160
-
161
- - Default by using ([DefaultHandler](src/handlers/default/default.handler.ts))
162
- - Huawei by using ([HttpHuaweiHandler](src/handlers/huawei/http-huawei.handler.ts)) and ([EventHuaweiHandler](#huawei-event-function))
163
-
164
- ## Huawei
165
-
166
- In Huawei, we added support to FunctionGraphV2 with Http Function and Event Function.
167
-
168
- The difference between Http Function and Event Function is that in Http Function you must expose port 8000 and Huawei will proxy Api Gateway requests to your application.
169
- So, on implementation, this library will create an http server to listen on port 8000 and forward the request to your framework.
170
-
171
- In Event Function, you will receive the event from event source in the same way you receive in AWS, an object with some structure, you can see the supported event sources [here](https://support.huaweicloud.com/intl/en-us/devg-functiongraph/functiongraph_02_0102.html).
172
-
173
- ### Huawei Http Function
174
-
175
- To integrate your app with Huawei FunctionGrapth with the Http Function type, you must do the following:
176
-
177
- ```ts
178
- import { ServerlessAdapter } from '@h4ad/serverless-adapter';
179
- import { ExpressFramework } from '@h4ad/serverless-adapter/lib/frameworks/express';
180
- import { HttpHuaweiHandler } from '@h4ad/serverless-adapter/lib/handlers/huawei';
181
- import { DummyResolver } from '@h4ad/serverless-adapter/lib/resolvers/dummy';
182
- import { DummyAdapter } from '@h4ad/serverless-adapter/lib/adapters/dummy';
183
- import app from './app';
184
-
185
- // instead exposing handler, you have the dispose function
186
- // this dispose function is never called
187
- // but you can to close the http server created with him
188
- const dispose = ServerlessAdapter.new(app)
189
- .setHandler(new HttpHuaweiHandler())
190
- .setFramework(new ExpressFramework())
191
- // dummy resolver and adapter is used because
192
- // they are necessary in the core of the library to build
193
- // but is optional to make huawei http function works.
194
- .setResolver(new DummyResolver())
195
- .addAdapter(new DummyAdapter())
196
- .build();
197
- ```
198
-
199
- > You don't need to expose a variable called `handler` when you choose Http Function, you just need to call build to the library create a http server.
200
-
201
- By the way of Huawei architecture in Http Function, they have no use for Resolvers and Adapters, so you need to use the dummy versions because the library requires it.
202
-
203
- #### ONE IMPORTANT THING
204
-
205
- You need to configure a file called `bootstrap` in the root of folder that you upload to Huawei, is like the file `Procfile` but for Huawei.
206
-
207
- In my setup, I configure like:
208
- ```
209
- node /opt/function/code/index.js
210
- ```
211
-
212
- The path `/opt/function/code` is where your code is uploaded when you deploy something and `index.js` is the file that contains the `ServerlessAdapter`.
213
-
214
- In the end, the structure of the zip file you upload looks like this:
215
-
216
- - `bootstrap`
217
- - `index.js`
218
-
219
- ### Huawei Event Function
220
-
221
- With Http Function you need to use [HttpHuaweiHandler](src/handlers/huawei/http-huawei.handler.ts),
222
- but with Event Function you should use [DefaultHandler](src/handlers/default/default.handler.ts).
223
-
224
- So, to add support to Api Gateway you do the following:
225
-
226
- ```ts
227
- import { ServerlessAdapter } from '@h4ad/serverless-adapter';
228
- import { HuaweiApiGatewayAdapter } from '@h4ad/serverless-adapter/lib/adapters/huawei';
229
- import { ExpressFramework } from '@h4ad/serverless-adapter/lib/frameworks/express';
230
- import { DefaultHandler } from '@h4ad/serverless-adapter/lib/handlers/default';
231
- import { CallbackResolver } from '@h4ad/serverless-adapter/lib/resolvers/callback';
232
- import app from './app';
233
-
234
- export const handler = ServerlessAdapter.new(app)
235
- .setFramework(new ExpressFramework())
236
- .setHandler(new DefaultHandler())
237
- .setResolver(new CallbackResolver())
238
- .addAdapter(new HuaweiApiGatewayAdapter())
239
- .build();
240
- ```
241
-
242
- #### One important thing
243
-
244
- You must use the callback resolver because I couldn't get it to work with the PromiseResolver.
245
- Maybe it's a bug in the library or something specific in Huawei, if you have a tip please create an issue.
43
+ See how to use this library [here](https://viniciusl.com.br/serverless-adapter/docs/category/getting-started).
246
44
 
247
45
  # Examples
248
46
 
249
47
  You can see some examples of how to use this library [here](https://github.com/H4ad/serverless-adapter-examples).
250
48
 
251
- # Architecture
252
-
253
- The main purpose of this library is to allow the developer to add support for any cloud and as many event sources as he
254
- wants, without having to create an issue to request the feature or copy the library code because the library doesn't
255
- expose good APIs for you to extend its functionality
256
-
257
- So I refactored [@vendia/serverless-express](https://github.com/vendia/serverless-express) with 4 layers of abstraction:
258
- Framework, Handler, Resolver and Adapter.
259
-
260
- The [FrameworkContract](./src/contracts/framework.contract.ts) is responsible for forwarding
261
- to [IncomingMessage](https://nodejs.org/api/http.html#class-httpincomingmessage)
262
- and [ServerResponse](https://nodejs.org/api/http.html#class-httpserverresponse) for your application instance. With this
263
- abstraction you can implement any framework you want, they just need to accept both parameters and
264
- call [end](https://nodejs.org/api/http.html#class-httpserverresponse)
265
- in [ServerResponse](https://nodejs.org/api/http.html#class-httpserverresponse), so the library knows when to continue
266
- and return the response.
267
-
268
- The [HandlerContract](./src/contracts/handler.contract.ts) is responsible to get the input from the serverless and then
269
- manage to call each layer of abstraction to return a response. With this abstraction, you can implement different ways
270
- to receive input from your serverless environment. They usually have the same structure, but if you need to deal with a
271
- very different cloud, you can use this abstraction to add support for that cloud.
272
-
273
- > Handler is a good choice for implementing (~~monsters~~) ways to receive input.
274
- > For example, we can create an http server as its handler to test our serverless code without having to launch the framework. Because? I don't know, but you can.
275
-
276
- The [ResolverContract](./src/contracts/resolver.contract.ts) is responsible for waiting for the framework to handle the
277
- request and then returning the response to the cloud. Using AWS for example, you have three ways to wait for the
278
- response: returning a promise, calling the callback, and ~~using in-context methods~~, each option has its own benefits,
279
- but generally the promise option will be the better because any good cloud provider will support promises.
280
-
281
- Finally, the masterpiece of this library, the [AdapterContract](./src/contracts/adapter.contract.ts) is responsible for
282
- handling the received event, transforming the request in a way that your application can understand and then
283
- transforming the response in a way your cloud can understand.
284
-
285
- Well, with these four contracts, you'll be able to add support to any cloud that exists (no more excuses not to use
286
- cloud X with NodeJS).
287
-
288
- ## Why you create this library?
289
-
290
- The real reason I created this library was because I wanted to add API Gateway and SQS support at the same time to save
291
- some money. But, [@vendia/serverless-express](https://github.com/vendia/serverless-express) was not supported, so
292
- I [created a PR](https://github.com/vendia/serverless-express/pull/483), but until I finished this library, that PR was
293
- never accepted.
294
-
295
- So I build my own library based on that library with better APIs so I never have to wait for the maintainer to accept my
296
- PR just to extend the library's functionality :)
297
-
298
49
  # Credits
299
50
 
300
51
  Honestly, I just refactored all the code that the @vendia team and many other contributors wrote, thanks so much to them
@@ -1,17 +1,25 @@
1
1
  /**
2
- * The interface representing the settings for whether the response should be treated as binary or not
2
+ * The interface representing the binary settings implementation by function
3
3
  *
4
- * @note Encoded as binary means the response body will be converted to base64
4
+ * @breadcrumb Types / BinarySettings
5
+ * @public
5
6
  */
6
- export declare type BinarySettings = {
7
+ export interface BinarySettingsFunction {
7
8
  /**
8
9
  * This property can be a function that receives the response headers and returns whether that response should be encoded as binary.
9
10
  * Otherwise, you can specify not to treat any response as binary by putting `false` in this property.
10
11
  *
11
- * @note Setting this property prevents the `contentTypes` and `contentEncodings` properties from being used.
12
+ * @remarks Setting this property prevents the `contentTypes` and `contentEncodings` properties from being used.
12
13
  */
13
14
  isBinary: ((headers: Record<string, string | string[] | undefined>) => boolean) | false;
14
- } | {
15
+ }
16
+ /**
17
+ * The interface representing the binary settings implementation by looking inside the headers
18
+ *
19
+ * @breadcrumb Types / BinarySettings
20
+ * @public
21
+ */
22
+ export interface BinarySettingsContentHeaders {
15
23
  /**
16
24
  * The list of content types that will be treated as binary
17
25
  */
@@ -20,4 +28,14 @@ export declare type BinarySettings = {
20
28
  * The list of content encodings that will be treated as binary
21
29
  */
22
30
  contentEncodings: string[];
23
- };
31
+ }
32
+ /**
33
+ * The interface representing the settings for whether the response should be treated as binary or not
34
+ *
35
+ * @remarks Encoded as binary means the response body will be converted to base64
36
+ *
37
+ * @breadcrumb Types / BinarySettings
38
+ * @public
39
+ */
40
+ export declare type BinarySettings = BinarySettingsFunction | BinarySettingsContentHeaders;
41
+ //# sourceMappingURL=binary-settings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary-settings.d.ts","sourceRoot":"","sources":["../../src/@types/binary-settings.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,QAAQ,EACJ,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,KAAK,OAAO,CAAC,GACrE,KAAK,CAAC;CACX;AAED;;;;;GAKG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,YAAY,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAElC;;OAEG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,oBAAY,cAAc,GACtB,sBAAsB,GACtB,4BAA4B,CAAC"}
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=binary-settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary-settings.js","sourceRoot":"","sources":["../../src/@types/binary-settings.ts"],"names":[],"mappings":""}
@@ -1,24 +1,37 @@
1
1
  /**
2
2
  * The record that represents the headers that doesn't have multiple values in the value
3
3
  *
4
- * @example```typescript
4
+ * @example
5
+ * ```typescript
5
6
  * { 'Accept-Encoding': 'gzip, deflate, br' }
6
7
  * ```
8
+ *
9
+ * @breadcrumb Types
10
+ * @public
7
11
  */
8
12
  export declare type SingleValueHeaders = Record<string, string | undefined>;
9
13
  /**
10
14
  * The record that represents the headers that have multiple values in the value
11
15
  *
12
- * @example```typescript
16
+ * @example
17
+ * ```typescript
13
18
  * { 'Accept-Encoding': ['gzip', 'deflate', 'br'] }
14
19
  * ```
20
+ *
21
+ * @breadcrumb Types
22
+ * @public
15
23
  */
16
24
  export declare type MultiValueHeaders = Record<string, string[] | undefined>;
17
25
  /**
18
26
  * The record that represents the headers that can both single or multiple values in the value
19
27
  *
20
- * @example```typescript
28
+ * @example
29
+ * ```typescript
21
30
  * { 'Accept-Encoding': ['gzip', 'deflate', 'br'], 'Host': 'xyz.execute-api.us-east-1.amazonaws.com' }
22
31
  * ```
32
+ *
33
+ * @breadcrumb Types
34
+ * @public
23
35
  */
24
36
  export declare type BothValueHeaders = Record<string, string | string[] | undefined>;
37
+ //# sourceMappingURL=headers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../src/@types/headers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,oBAAY,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAEpE;;;;;;;;;;GAUG;AACH,oBAAY,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;AAErE;;;;;;;;;;GAUG;AACH,oBAAY,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC"}
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=headers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/@types/headers.ts"],"names":[],"mappings":""}
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * Removes 'optional' attributes from a type's properties
3
+ *
4
+ * @breadcrumb Types
5
+ * @public
3
6
  */
4
7
  export declare type Concrete<Type> = {
5
8
  [Property in keyof Type]-?: Type[Property];
6
9
  };
10
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/@types/helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,oBAAY,QAAQ,CAAC,IAAI,IAAI;KAC1B,QAAQ,IAAI,MAAM,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;CAC3C,CAAC"}
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/@types/helpers.ts"],"names":[],"mappings":""}
@@ -1,19 +1,81 @@
1
1
  import { BothValueHeaders } from '../index';
2
+ /**
3
+ * The interface that represents the Api Gateway Event of Huawei when integrate with Function Graph of Event Type.
4
+ * See more in {@link https://support.huaweicloud.com/intl/en-us/devg-functiongraph/functiongraph_02_0102.html#functiongraph_02_0102__li5178638110137 | Reference}.
5
+ *
6
+ * @public
7
+ * @breadcrumb Types / Huawei / HuaweiApiGatewayEvent
8
+ */
2
9
  export interface HuaweiApiGatewayEvent {
10
+ /**
11
+ * The body value with the content of this event serialized in JSON
12
+ */
3
13
  body: string;
14
+ /**
15
+ * The headers of the request which this event represents
16
+ */
4
17
  headers: BothValueHeaders;
18
+ /**
19
+ * The HTTP Method of the request which this event represents
20
+ */
5
21
  httpMethod: string;
22
+ /**
23
+ * Tells if the body is base64 encoded
24
+ */
6
25
  isBase64Encoded: boolean;
26
+ /**
27
+ * The path of the request which this event represents
28
+ */
7
29
  path: string;
30
+ /**
31
+ * The path parameters of the request which this event represents
32
+ */
8
33
  pathParameters: HuaweiRequestPathParameters;
34
+ /**
35
+ * The query strings of the request which this event represents
36
+ */
9
37
  queryStringParameters: HuaweiRequestQueryStringParameters;
38
+ /**
39
+ * The request context with information about the stage, api and requestId
40
+ */
10
41
  requestContext: HuaweiRequestContext;
42
+ /**
43
+ * It can have more properties that I could not discover yet
44
+ */
11
45
  [key: string]: any;
12
46
  }
47
+ /**
48
+ * The path parameters of the request, usually is the name of the wildcard you create in FunctionGraph, such as /\{proxy\}.
49
+ *
50
+ * @public
51
+ * @breadcrumb Types / Huawei / HuaweiApiGatewayEvent
52
+ */
13
53
  export declare type HuaweiRequestPathParameters = Record<string, string>;
54
+ /**
55
+ * The query strings of the request
56
+ *
57
+ * @public
58
+ * @breadcrumb Types / Huawei / HuaweiApiGatewayEvent
59
+ */
14
60
  export declare type HuaweiRequestQueryStringParameters = Record<string, string | string[]>;
61
+ /**
62
+ * The interface that represents the values you can get inside request context.
63
+ *
64
+ * @public
65
+ * @breadcrumb Types / Huawei / HuaweiApiGatewayEvent
66
+ */
15
67
  export interface HuaweiRequestContext {
68
+ /**
69
+ * The ID of your API inside Api Gateway
70
+ */
16
71
  apiId: string;
72
+ /**
73
+ * The ID of this request
74
+ */
17
75
  requestId: string;
76
+ /**
77
+ * The name of the stage running this Function Graph
78
+ */
18
79
  stage: string;
19
80
  }
81
+ //# sourceMappingURL=huawei-api-gateway-event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huawei-api-gateway-event.d.ts","sourceRoot":"","sources":["../../../src/@types/huawei/huawei-api-gateway-event.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAI5C;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,gBAAgB,CAAC;IAE1B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,eAAe,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,cAAc,EAAE,2BAA2B,CAAC;IAE5C;;OAEG;IACH,qBAAqB,EAAE,kCAAkC,CAAC;IAE1D;;OAEG;IACH,cAAc,EAAE,oBAAoB,CAAC;IAErC;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;;;;GAKG;AACH,oBAAY,2BAA2B,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjE;;;;;GAKG;AACH,oBAAY,kCAAkC,GAAG,MAAM,CACrD,MAAM,EACN,MAAM,GAAG,MAAM,EAAE,CAClB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf"}
@@ -1,2 +1,4 @@
1
1
  "use strict";
2
+ //#region Imports
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=huawei-api-gateway-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huawei-api-gateway-event.js","sourceRoot":"","sources":["../../../src/@types/huawei/huawei-api-gateway-event.ts"],"names":[],"mappings":";AAAA,iBAAiB"}
@@ -1,7 +1,27 @@
1
1
  import { MultiValueHeaders } from '../headers';
2
+ /**
3
+ * The interface that represents the Api Gateway Response of Huawei when integrate with Function Graph of Event Type.
4
+ * See more in {@link https://support.huaweicloud.com/intl/en-us/devg-functiongraph/functiongraph_02_0102.html#functiongraph_02_0102__li5178638110137 | Reference}.
5
+ *
6
+ * @public
7
+ * @breadcrumb Types / Huawei / HuaweiApiGatewayResponse
8
+ */
2
9
  export interface HuaweiApiGatewayResponse {
10
+ /**
11
+ * Tells if the body was encoded as base64
12
+ */
3
13
  isBase64Encoded: boolean;
14
+ /**
15
+ * The HTTP Status code of this response
16
+ */
4
17
  statusCode: number;
18
+ /**
19
+ * The headers sent with this response
20
+ */
5
21
  headers: MultiValueHeaders;
22
+ /**
23
+ * The body value with the content of this response serialized in JSON
24
+ */
6
25
  body: string;
7
26
  }
27
+ //# sourceMappingURL=huawei-api-gateway-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huawei-api-gateway-response.d.ts","sourceRoot":"","sources":["../../../src/@types/huawei/huawei-api-gateway-response.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAI/C;;;;;;GAMG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,eAAe,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,OAAO,EAAE,iBAAiB,CAAC;IAE3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd"}
@@ -1,2 +1,4 @@
1
1
  "use strict";
2
+ //#region Imports
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=huawei-api-gateway-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huawei-api-gateway-response.js","sourceRoot":"","sources":["../../../src/@types/huawei/huawei-api-gateway-response.ts"],"names":[],"mappings":";AAAA,iBAAiB"}