@ohos-ports/layer0-prefetch 4.20.0-beta.0 → 4.20.0-beta.1

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 (281) hide show
  1. package/node_modules/@layer0/core/README.md +50 -0
  2. package/node_modules/@layer0/core/build.d.ts +5 -0
  3. package/node_modules/@layer0/core/build.js +17 -0
  4. package/node_modules/@layer0/core/cache/Cache.d.ts +56 -0
  5. package/node_modules/@layer0/core/cache/Cache.js +138 -0
  6. package/node_modules/@layer0/core/cache/CacheKey.d.ts +52 -0
  7. package/node_modules/@layer0/core/cache/CacheKey.js +95 -0
  8. package/node_modules/@layer0/core/config.d.ts +53 -0
  9. package/node_modules/@layer0/core/config.js +113 -0
  10. package/node_modules/@layer0/core/constants.d.ts +214 -0
  11. package/node_modules/@layer0/core/constants.js +216 -0
  12. package/node_modules/@layer0/core/context.d.ts +38 -0
  13. package/node_modules/@layer0/core/context.js +98 -0
  14. package/node_modules/@layer0/core/default-app/all/layer0.config.js +60 -0
  15. package/node_modules/@layer0/core/default-app/js/routes.js +27 -0
  16. package/node_modules/@layer0/core/default-app/ts/routes.ts +27 -0
  17. package/node_modules/@layer0/core/deploy/DeploymentBuilder.d.ts +177 -0
  18. package/node_modules/@layer0/core/deploy/DeploymentBuilder.js +543 -0
  19. package/node_modules/@layer0/core/deploy/bundle-esbuild.d.ts +11 -0
  20. package/node_modules/@layer0/core/deploy/bundle-esbuild.js +67 -0
  21. package/node_modules/@layer0/core/deploy/bundle-ncc.d.ts +8 -0
  22. package/node_modules/@layer0/core/deploy/bundle-ncc.js +30 -0
  23. package/node_modules/@layer0/core/deploy/bundle-nft.d.ts +7 -0
  24. package/node_modules/@layer0/core/deploy/bundle-nft.js +41 -0
  25. package/node_modules/@layer0/core/deploy/bundle-webpack.d.ts +11 -0
  26. package/node_modules/@layer0/core/deploy/bundle-webpack.js +127 -0
  27. package/node_modules/@layer0/core/deploy/index.d.ts +19 -0
  28. package/node_modules/@layer0/core/deploy/index.js +6 -0
  29. package/node_modules/@layer0/core/deploy/listSources.d.ts +11 -0
  30. package/node_modules/@layer0/core/deploy/listSources.js +18 -0
  31. package/node_modules/@layer0/core/deploy/paths.d.ts +27 -0
  32. package/node_modules/@layer0/core/deploy/paths.js +33 -0
  33. package/node_modules/@layer0/core/deploy/resolveInPackage.d.ts +7 -0
  34. package/node_modules/@layer0/core/deploy/resolveInPackage.js +21 -0
  35. package/node_modules/@layer0/core/deploy/routeToFiles.d.ts +14 -0
  36. package/node_modules/@layer0/core/deploy/routeToFiles.js +24 -0
  37. package/node_modules/@layer0/core/dev/DevServerOptions.d.ts +33 -0
  38. package/node_modules/@layer0/core/dev/DevServerOptions.js +2 -0
  39. package/node_modules/@layer0/core/dev/createDevServer.d.ts +8 -0
  40. package/node_modules/@layer0/core/dev/createDevServer.js +114 -0
  41. package/node_modules/@layer0/core/dev/index.d.ts +3 -0
  42. package/node_modules/@layer0/core/dev/index.js +6 -0
  43. package/node_modules/@layer0/core/dev/runLocalApp.d.ts +8 -0
  44. package/node_modules/@layer0/core/dev/runLocalApp.js +73 -0
  45. package/node_modules/@layer0/core/dev/serverlessCompatibilityMiddleware.d.ts +11 -0
  46. package/node_modules/@layer0/core/dev/serverlessCompatibilityMiddleware.js +30 -0
  47. package/node_modules/@layer0/core/edge/EdgeErrorPageResponseWriter.d.ts +12 -0
  48. package/node_modules/@layer0/core/edge/EdgeErrorPageResponseWriter.js +22 -0
  49. package/node_modules/@layer0/core/edge/EdgeResponseWriter.d.ts +122 -0
  50. package/node_modules/@layer0/core/edge/EdgeResponseWriter.js +451 -0
  51. package/node_modules/@layer0/core/edge/createEdgeConfig.d.ts +16 -0
  52. package/node_modules/@layer0/core/edge/createEdgeConfig.js +284 -0
  53. package/node_modules/@layer0/core/environment.d.ts +24 -0
  54. package/node_modules/@layer0/core/environment.js +42 -0
  55. package/node_modules/@layer0/core/errors/BackendFetchError.d.ts +11 -0
  56. package/node_modules/@layer0/core/errors/BackendFetchError.js +17 -0
  57. package/node_modules/@layer0/core/errors/FrameworkBuildError.d.ts +7 -0
  58. package/node_modules/@layer0/core/errors/FrameworkBuildError.js +26 -0
  59. package/node_modules/@layer0/core/index.d.ts +3 -0
  60. package/node_modules/@layer0/core/index.js +9 -0
  61. package/node_modules/@layer0/core/init/addToPackageJson.d.ts +7 -0
  62. package/node_modules/@layer0/core/init/addToPackageJson.js +22 -0
  63. package/node_modules/@layer0/core/init/index.d.ts +2 -0
  64. package/node_modules/@layer0/core/init/index.js +6 -0
  65. package/node_modules/@layer0/core/init/init.d.ts +5 -0
  66. package/node_modules/@layer0/core/init/init.js +17 -0
  67. package/node_modules/@layer0/core/lambda/JSBackend.d.ts +30 -0
  68. package/node_modules/@layer0/core/lambda/JSBackend.js +51 -0
  69. package/node_modules/@layer0/core/lambda/RequestListenerJSBackend.d.ts +8 -0
  70. package/node_modules/@layer0/core/lambda/RequestListenerJSBackend.js +19 -0
  71. package/node_modules/@layer0/core/lambda/adaptResponseEncodingToDownstream.d.ts +17 -0
  72. package/node_modules/@layer0/core/lambda/adaptResponseEncodingToDownstream.js +132 -0
  73. package/node_modules/@layer0/core/lambda/consoleWrapper.d.ts +16 -0
  74. package/node_modules/@layer0/core/lambda/consoleWrapper.js +127 -0
  75. package/node_modules/@layer0/core/lambda/getBodyLoggingData.d.ts +10 -0
  76. package/node_modules/@layer0/core/lambda/getBodyLoggingData.js +108 -0
  77. package/node_modules/@layer0/core/lambda/handler.d.ts +1 -0
  78. package/node_modules/@layer0/core/lambda/handler.js +91 -0
  79. package/node_modules/@layer0/core/lambda/handler.js.map +7 -0
  80. package/node_modules/@layer0/core/lambda/innerHandler.d.ts +7 -0
  81. package/node_modules/@layer0/core/lambda/innerHandler.js +181 -0
  82. package/node_modules/@layer0/core/lambda/lambdaInstance.d.ts +29 -0
  83. package/node_modules/@layer0/core/lambda/lambdaInstance.js +71 -0
  84. package/node_modules/@layer0/core/lambda/reqResMapper.d.ts +24 -0
  85. package/node_modules/@layer0/core/lambda/reqResMapper.js +286 -0
  86. package/node_modules/@layer0/core/lambda/stdStreamsWrapper.d.ts +31 -0
  87. package/node_modules/@layer0/core/lambda/stdStreamsWrapper.js +196 -0
  88. package/node_modules/@layer0/core/lambda/toJSBackend.d.ts +10 -0
  89. package/node_modules/@layer0/core/lambda/toJSBackend.js +23 -0
  90. package/node_modules/@layer0/core/node_modules/esbuild/LICENSE.md +21 -0
  91. package/node_modules/@layer0/core/node_modules/esbuild/README.md +3 -0
  92. package/node_modules/@layer0/core/node_modules/esbuild/bin/esbuild +223 -0
  93. package/node_modules/@layer0/core/node_modules/esbuild/install.js +301 -0
  94. package/node_modules/@layer0/core/node_modules/esbuild/lib/main.d.ts +716 -0
  95. package/node_modules/@layer0/core/node_modules/esbuild/lib/main.js +2532 -0
  96. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/README.md +3 -0
  97. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/bin/esbuild +0 -0
  98. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/esbuild.wasm +0 -0
  99. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/package.json +28 -0
  100. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/wasm_exec.js +575 -0
  101. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/wasm_exec_node.js +40 -0
  102. package/node_modules/@layer0/core/node_modules/esbuild/package.json +78 -0
  103. package/node_modules/@layer0/core/package.json +132 -0
  104. package/node_modules/@layer0/core/parser/parseRouter.d.ts +13 -0
  105. package/node_modules/@layer0/core/parser/parseRouter.js +77 -0
  106. package/node_modules/@layer0/core/plugins/PluginBase.d.ts +18 -0
  107. package/node_modules/@layer0/core/plugins/PluginBase.js +19 -0
  108. package/node_modules/@layer0/core/router/Backend.d.ts +69 -0
  109. package/node_modules/@layer0/core/router/Backend.js +176 -0
  110. package/node_modules/@layer0/core/router/BackendOptions.d.ts +11 -0
  111. package/node_modules/@layer0/core/router/BackendOptions.js +2 -0
  112. package/node_modules/@layer0/core/router/BaseResponseWriter.d.ts +65 -0
  113. package/node_modules/@layer0/core/router/BaseResponseWriter.js +81 -0
  114. package/node_modules/@layer0/core/router/BehindEdgeResponseWriterProxy.d.ts +4 -0
  115. package/node_modules/@layer0/core/router/BehindEdgeResponseWriterProxy.js +89 -0
  116. package/node_modules/@layer0/core/router/CacheManifest.d.ts +80 -0
  117. package/node_modules/@layer0/core/router/CacheManifest.js +83 -0
  118. package/node_modules/@layer0/core/router/CacheOptions.d.ts +171 -0
  119. package/node_modules/@layer0/core/router/CacheOptions.js +2 -0
  120. package/node_modules/@layer0/core/router/CustomCacheKey.d.ts +140 -0
  121. package/node_modules/@layer0/core/router/CustomCacheKey.js +272 -0
  122. package/node_modules/@layer0/core/router/GroupConfig.d.ts +7 -0
  123. package/node_modules/@layer0/core/router/GroupConfig.js +20 -0
  124. package/node_modules/@layer0/core/router/Groups.d.ts +7 -0
  125. package/node_modules/@layer0/core/router/Groups.js +21 -0
  126. package/node_modules/@layer0/core/router/Headers.d.ts +3 -0
  127. package/node_modules/@layer0/core/router/Headers.js +2 -0
  128. package/node_modules/@layer0/core/router/PathMatcher.d.ts +51 -0
  129. package/node_modules/@layer0/core/router/PathMatcher.js +73 -0
  130. package/node_modules/@layer0/core/router/Preload.d.ts +16 -0
  131. package/node_modules/@layer0/core/router/Preload.js +2 -0
  132. package/node_modules/@layer0/core/router/PreloadRequests.d.ts +23 -0
  133. package/node_modules/@layer0/core/router/PreloadRequests.js +66 -0
  134. package/node_modules/@layer0/core/router/Request.d.ts +74 -0
  135. package/node_modules/@layer0/core/router/Request.js +2 -0
  136. package/node_modules/@layer0/core/router/RequestContext.d.ts +12 -0
  137. package/node_modules/@layer0/core/router/RequestContext.js +11 -0
  138. package/node_modules/@layer0/core/router/Response.d.ts +55 -0
  139. package/node_modules/@layer0/core/router/Response.js +2 -0
  140. package/node_modules/@layer0/core/router/ResponseWriter.d.ts +1011 -0
  141. package/node_modules/@layer0/core/router/ResponseWriter.js +1341 -0
  142. package/node_modules/@layer0/core/router/Route.d.ts +124 -0
  143. package/node_modules/@layer0/core/router/Route.js +280 -0
  144. package/node_modules/@layer0/core/router/RouteCriteria.d.ts +68 -0
  145. package/node_modules/@layer0/core/router/RouteCriteria.js +2 -0
  146. package/node_modules/@layer0/core/router/RouteGroup.d.ts +157 -0
  147. package/node_modules/@layer0/core/router/RouteGroup.js +223 -0
  148. package/node_modules/@layer0/core/router/RouteGroupList.d.ts +45 -0
  149. package/node_modules/@layer0/core/router/RouteGroupList.js +73 -0
  150. package/node_modules/@layer0/core/router/Router.d.ts +439 -0
  151. package/node_modules/@layer0/core/router/Router.js +907 -0
  152. package/node_modules/@layer0/core/router/addBuiltInRoutes.d.ts +2 -0
  153. package/node_modules/@layer0/core/router/addBuiltInRoutes.js +58 -0
  154. package/node_modules/@layer0/core/router/addPreloadHeaders.d.ts +7 -0
  155. package/node_modules/@layer0/core/router/addPreloadHeaders.js +57 -0
  156. package/node_modules/@layer0/core/router/cacheManifestFromRouter.d.ts +6 -0
  157. package/node_modules/@layer0/core/router/cacheManifestFromRouter.js +85 -0
  158. package/node_modules/@layer0/core/router/createCustomCacheKey.d.ts +27 -0
  159. package/node_modules/@layer0/core/router/createCustomCacheKey.js +35 -0
  160. package/node_modules/@layer0/core/router/deriveSurrogateKeysFromJson.d.ts +36 -0
  161. package/node_modules/@layer0/core/router/deriveSurrogateKeysFromJson.js +70 -0
  162. package/node_modules/@layer0/core/router/index.d.ts +11 -0
  163. package/node_modules/@layer0/core/router/index.js +17 -0
  164. package/node_modules/@layer0/core/router/interpolateParams.d.ts +21 -0
  165. package/node_modules/@layer0/core/router/interpolateParams.js +150 -0
  166. package/node_modules/@layer0/core/router/loadRouter.d.ts +13 -0
  167. package/node_modules/@layer0/core/router/loadRouter.js +29 -0
  168. package/node_modules/@layer0/core/router/mergeQueryString.d.ts +1 -0
  169. package/node_modules/@layer0/core/router/mergeQueryString.js +23 -0
  170. package/node_modules/@layer0/core/router/normalizeCriteria.d.ts +6 -0
  171. package/node_modules/@layer0/core/router/normalizeCriteria.js +20 -0
  172. package/node_modules/@layer0/core/router/stream.d.ts +12 -0
  173. package/node_modules/@layer0/core/router/stream.js +30 -0
  174. package/node_modules/@layer0/core/router/universalRouteUtils.d.ts +55 -0
  175. package/node_modules/@layer0/core/router/universalRouteUtils.js +114 -0
  176. package/node_modules/@layer0/core/router/validateWriter.d.ts +41 -0
  177. package/node_modules/@layer0/core/router/validateWriter.js +120 -0
  178. package/node_modules/@layer0/core/serverless.yml +30 -0
  179. package/node_modules/@layer0/core/source.d.ts +9 -0
  180. package/node_modules/@layer0/core/source.js +17 -0
  181. package/node_modules/@layer0/core/test-utils/MockRequest.d.ts +15 -0
  182. package/node_modules/@layer0/core/test-utils/MockRequest.js +36 -0
  183. package/node_modules/@layer0/core/test-utils/MockResponse.d.ts +7 -0
  184. package/node_modules/@layer0/core/test-utils/MockResponse.js +24 -0
  185. package/node_modules/@layer0/core/test-utils/expect-extend.d.ts +1 -0
  186. package/node_modules/@layer0/core/test-utils/expect-extend.js +11 -0
  187. package/node_modules/@layer0/core/test-utils/index.d.ts +4 -0
  188. package/node_modules/@layer0/core/test-utils/index.js +11 -0
  189. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheBrowser.d.ts +19 -0
  190. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheBrowser.js +45 -0
  191. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheEdge.d.ts +19 -0
  192. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheEdge.js +38 -0
  193. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheServiceWorker.d.ts +19 -0
  194. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheServiceWorker.js +45 -0
  195. package/node_modules/@layer0/core/test-utils/matchers/toBeServedStale.d.ts +20 -0
  196. package/node_modules/@layer0/core/test-utils/matchers/toBeServedStale.js +50 -0
  197. package/node_modules/@layer0/core/test-utils/matchers/toHaveBody.d.ts +18 -0
  198. package/node_modules/@layer0/core/test-utils/matchers/toHaveBody.js +40 -0
  199. package/node_modules/@layer0/core/test-utils/matchers/toHaveHeader.d.ts +19 -0
  200. package/node_modules/@layer0/core/test-utils/matchers/toHaveHeader.js +43 -0
  201. package/node_modules/@layer0/core/test-utils/matchers.d.ts +6 -0
  202. package/node_modules/@layer0/core/test-utils/matchers.js +18 -0
  203. package/node_modules/@layer0/core/test-utils/utils/createRouteMock.d.ts +21 -0
  204. package/node_modules/@layer0/core/test-utils/utils/createRouteMock.js +27 -0
  205. package/node_modules/@layer0/core/test-utils/utils/getBackend.d.ts +13 -0
  206. package/node_modules/@layer0/core/test-utils/utils/getBackend.js +30 -0
  207. package/node_modules/@layer0/core/test-utils/utils/getMessage.d.ts +1 -0
  208. package/node_modules/@layer0/core/test-utils/utils/getMessage.js +16 -0
  209. package/node_modules/@layer0/core/test-utils/utils/runRoute.d.ts +10 -0
  210. package/node_modules/@layer0/core/test-utils/utils/runRoute.js +39 -0
  211. package/node_modules/@layer0/core/timing.d.ts +115 -0
  212. package/node_modules/@layer0/core/timing.js +200 -0
  213. package/node_modules/@layer0/core/transform/index.d.ts +1 -0
  214. package/node_modules/@layer0/core/transform/index.js +4 -0
  215. package/node_modules/@layer0/core/transform/transformMethod.d.ts +40 -0
  216. package/node_modules/@layer0/core/transform/transformMethod.js +58 -0
  217. package/node_modules/@layer0/core/types.d.ts +102 -0
  218. package/node_modules/@layer0/core/types.js +30 -0
  219. package/node_modules/@layer0/core/utils/Tasks.d.ts +32 -0
  220. package/node_modules/@layer0/core/utils/Tasks.js +80 -0
  221. package/node_modules/@layer0/core/utils/Validator.d.ts +18 -0
  222. package/node_modules/@layer0/core/utils/Validator.js +178 -0
  223. package/node_modules/@layer0/core/utils/bindParamsToPath.d.ts +15 -0
  224. package/node_modules/@layer0/core/utils/bindParamsToPath.js +49 -0
  225. package/node_modules/@layer0/core/utils/convertParamsToBackReferences.d.ts +16 -0
  226. package/node_modules/@layer0/core/utils/convertParamsToBackReferences.js +45 -0
  227. package/node_modules/@layer0/core/utils/convertStringMatcherToRegex.d.ts +7 -0
  228. package/node_modules/@layer0/core/utils/convertStringMatcherToRegex.js +26 -0
  229. package/node_modules/@layer0/core/utils/decode.d.ts +9 -0
  230. package/node_modules/@layer0/core/utils/decode.js +44 -0
  231. package/node_modules/@layer0/core/utils/esImport.d.ts +1 -0
  232. package/node_modules/@layer0/core/utils/esImport.js +9 -0
  233. package/node_modules/@layer0/core/utils/fs.d.ts +1 -0
  234. package/node_modules/@layer0/core/utils/fs.js +7 -0
  235. package/node_modules/@layer0/core/utils/get.d.ts +6 -0
  236. package/node_modules/@layer0/core/utils/get.js +19 -0
  237. package/node_modules/@layer0/core/utils/getPackageVersion.d.ts +7 -0
  238. package/node_modules/@layer0/core/utils/getPackageVersion.js +19 -0
  239. package/node_modules/@layer0/core/utils/has.d.ts +6 -0
  240. package/node_modules/@layer0/core/utils/has.js +15 -0
  241. package/node_modules/@layer0/core/utils/identity.d.ts +7 -0
  242. package/node_modules/@layer0/core/utils/identity.js +12 -0
  243. package/node_modules/@layer0/core/utils/index.d.ts +1 -0
  244. package/node_modules/@layer0/core/utils/index.js +4 -0
  245. package/node_modules/@layer0/core/utils/isEmpty.d.ts +6 -0
  246. package/node_modules/@layer0/core/utils/isEmpty.js +20 -0
  247. package/node_modules/@layer0/core/utils/isString.d.ts +1 -0
  248. package/node_modules/@layer0/core/utils/isString.js +6 -0
  249. package/node_modules/@layer0/core/utils/logo.d.ts +5 -0
  250. package/node_modules/@layer0/core/utils/logo.js +27 -0
  251. package/node_modules/@layer0/core/utils/mapValues.d.ts +7 -0
  252. package/node_modules/@layer0/core/utils/mapValues.js +16 -0
  253. package/node_modules/@layer0/core/utils/minBy.d.ts +8 -0
  254. package/node_modules/@layer0/core/utils/minBy.js +41 -0
  255. package/node_modules/@layer0/core/utils/nonWebpackRequire.d.ts +11 -0
  256. package/node_modules/@layer0/core/utils/nonWebpackRequire.js +28 -0
  257. package/node_modules/@layer0/core/utils/packageUtils.d.ts +12 -0
  258. package/node_modules/@layer0/core/utils/packageUtils.js +22 -0
  259. package/node_modules/@layer0/core/utils/ports.d.ts +5 -0
  260. package/node_modules/@layer0/core/utils/ports.js +7 -0
  261. package/node_modules/@layer0/core/utils/readBody.d.ts +7 -0
  262. package/node_modules/@layer0/core/utils/readBody.js +15 -0
  263. package/node_modules/@layer0/core/utils/readRawBody.d.ts +9 -0
  264. package/node_modules/@layer0/core/utils/readRawBody.js +21 -0
  265. package/node_modules/@layer0/core/utils/regExpEscape.d.ts +12 -0
  266. package/node_modules/@layer0/core/utils/regExpEscape.js +20 -0
  267. package/node_modules/@layer0/core/utils/requireInternal.d.ts +7 -0
  268. package/node_modules/@layer0/core/utils/requireInternal.js +24 -0
  269. package/node_modules/@layer0/core/utils/set.d.ts +10 -0
  270. package/node_modules/@layer0/core/utils/set.js +21 -0
  271. package/node_modules/@layer0/core/utils/toEdgeRegex.d.ts +11 -0
  272. package/node_modules/@layer0/core/utils/toEdgeRegex.js +23 -0
  273. package/node_modules/@layer0/core/utils/toHttpMethodMatchRegex.d.ts +12 -0
  274. package/node_modules/@layer0/core/utils/toHttpMethodMatchRegex.js +17 -0
  275. package/node_modules/@layer0/core/utils/toLower.d.ts +1 -0
  276. package/node_modules/@layer0/core/utils/toLower.js +9 -0
  277. package/node_modules/@layer0/core/utils/validateBackends.d.ts +5 -0
  278. package/node_modules/@layer0/core/utils/validateBackends.js +30 -0
  279. package/node_modules/@layer0/core/utils/watch.d.ts +10 -0
  280. package/node_modules/@layer0/core/utils/watch.js +17 -0
  281. package/package.json +47 -3
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ // This module has connascence of behavior with the module of the same name in XBP.
3
+ // There are differences in the actual implementation, most notably the use of asynchronous
4
+ // compression which relies on the threadpool rather than blocking the main thread.
5
+ // In lambda we are free to block the main thread as lambda processes the requests serially.
6
+ // In XBP we are not free to block the main thread as it processes many requests concurrently.
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ const zlib_1 = require("zlib");
12
+ const constants_1 = require("../constants");
13
+ const content_type_1 = require("content-type");
14
+ const isEmpty_1 = __importDefault(require("../utils/isEmpty"));
15
+ const isString_1 = __importDefault(require("../utils/isString"));
16
+ const decode_1 = __importDefault(require("../utils/decode"));
17
+ /**
18
+ * Those content types that will be gzipped are generated from the lists in:
19
+ * our Layer0 v1 production Nginx + Layer0 v1 production Varnish + default CDN gzip policy
20
+ *
21
+ * Set is not always optimal but in the benchmarks came out on top the most times.
22
+ * It is also the easiest to read and check for correctness.
23
+ */
24
+ const COMPRESSIBLE_TYPES = new Set([
25
+ 'application/atom_xml',
26
+ 'application/javascript',
27
+ 'application/json',
28
+ 'application/rss+xml',
29
+ 'application/vnd.ms-fontobject',
30
+ 'application/x-font-opentype',
31
+ 'application/x-font-ttf',
32
+ 'application/x-javascript',
33
+ 'application/xhtml+xml',
34
+ 'application/xml',
35
+ 'application/xml+rss',
36
+ 'font/eot',
37
+ 'font/opentype',
38
+ 'font/otf',
39
+ 'image/svg+xml',
40
+ 'image/x-icon',
41
+ 'text/css',
42
+ 'text/html',
43
+ 'text/javascript',
44
+ 'text/js',
45
+ 'text/plain',
46
+ ]);
47
+ /**
48
+ * Adapts the response body to the downstream accept encoding. This may mean:
49
+ * a) Not doing anything if the downstream accept encoding the content encoding are compatible.
50
+ * b) Compressing the response body to a downstream compatible encoding, if response body has no encoding.
51
+ * c) Decompressing the response body from downstream incompatible encoding and optionally re-compressing it
52
+ * to downstream compatible encoding.
53
+ *
54
+ * If any compression is done by this function, then the content-encoding and content-length headers will
55
+ * correspond to the new encoding/length of the response body.
56
+ *
57
+ * @param acceptEncoding Value of downstream accept-encoding header
58
+ * @param res HttpResponse object
59
+ * @param response Lambda response object
60
+ */
61
+ const adaptResponseEncodingToDownstream = (acceptEncoding, res, response) => {
62
+ let contentEncoding = res.getHeader(constants_1.HTTP_HEADERS.contentEncoding);
63
+ // Figure out if we first need to encode anything.
64
+ if (isEmpty_1.default(acceptEncoding)) {
65
+ if (!isEmpty_1.default(contentEncoding)) {
66
+ // Best effort to decode and return the decoded body.
67
+ decode_1.default(res);
68
+ response.body = res.body;
69
+ }
70
+ return;
71
+ }
72
+ const BROTLI_ENCODING_REGEX = /\bbr\b/;
73
+ const GZIP_ENCODING_REGEX = /\bgzip\b/;
74
+ const downstreamIsGzipCompatible = GZIP_ENCODING_REGEX.test(acceptEncoding);
75
+ const downstreamIsBrotliCompatible = BROTLI_ENCODING_REGEX.test(acceptEncoding);
76
+ if (downstreamIsGzipCompatible && contentEncoding === constants_1.GZIP_ENCODING) {
77
+ return;
78
+ }
79
+ if (downstreamIsBrotliCompatible && contentEncoding === constants_1.BROTLI_ENCODING) {
80
+ return;
81
+ }
82
+ // Try to decode the content. If we cannot decode then we will pass the content
83
+ // as-is and on the edge we will refuse to cache it (see the logic in upstream
84
+ // response handling on the edge and specifically the bad-encoding caching status)
85
+ if (!decode_1.default(res)) {
86
+ return;
87
+ }
88
+ // Since AWS lambda holds multiValueHeaders as array convert string to array
89
+ let contentType = res.getHeader(constants_1.HTTP_HEADERS.contentType);
90
+ contentType = isString_1.default(contentType) ? [contentType] : contentType;
91
+ // Return body if content-type does not exist or match the list of mimes
92
+ if (!contentType ||
93
+ !COMPRESSIBLE_TYPES.has(content_type_1.parse(contentType[0]).type.toLowerCase())) {
94
+ return;
95
+ }
96
+ // If request accepts a gzip response, then encode it with gzip.
97
+ // If request accepts a brotli response, then encoding it with brotli.
98
+ // If both are acceptable then use gzip which we prefer gzip compression in lambda because
99
+ // while the lambdas can scale (unlike the edge) the throughout for small un-cached objects
100
+ // has been observed to drop by 40%.
101
+ // End developers can work around this default behavior by doing the Brotli compression
102
+ // themselves and correctly setting the `content-encoding`.
103
+ let targetContentEncoding;
104
+ if (downstreamIsGzipCompatible) {
105
+ targetContentEncoding = constants_1.GZIP_ENCODING;
106
+ }
107
+ else if (downstreamIsBrotliCompatible) {
108
+ targetContentEncoding = constants_1.BROTLI_ENCODING;
109
+ }
110
+ // Encode the body.
111
+ let encodedBody;
112
+ switch (targetContentEncoding) {
113
+ case constants_1.BROTLI_ENCODING: {
114
+ encodedBody = zlib_1.brotliCompressSync(Buffer.from(response.body));
115
+ break;
116
+ }
117
+ case constants_1.GZIP_ENCODING: {
118
+ encodedBody = zlib_1.gzipSync(Buffer.from(response.body));
119
+ break;
120
+ }
121
+ default: {
122
+ // We only support gzip and brotli so if neither is supported we just return
123
+ // the un-encoded response.
124
+ return;
125
+ }
126
+ }
127
+ // Set the response headers and body.
128
+ res.setHeader(constants_1.HTTP_HEADERS.contentLength, Buffer.byteLength(encodedBody));
129
+ res.setHeader(constants_1.HTTP_HEADERS.contentEncoding, targetContentEncoding);
130
+ response.body = encodedBody;
131
+ };
132
+ exports.default = adaptResponseEncodingToDownstream;
@@ -0,0 +1,16 @@
1
+ export declare const awsCloudWatchTag: {
2
+ awsTag: string;
3
+ };
4
+ export default class ConsoleWrapper {
5
+ static _assert(condition: boolean | undefined, ...args: any[]): void;
6
+ static _dir(...args: any[]): void;
7
+ static _time(label: string): void;
8
+ static _timeEnd(label: string): void;
9
+ static _timeLog(label: string, ...args: any[]): void;
10
+ static enable({ clientIp, requestId, wi, }?: {
11
+ clientIp?: string;
12
+ requestId?: string;
13
+ wi?: string;
14
+ }): void;
15
+ static disable(): void;
16
+ }
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ /*
3
+ * Wrap the console logging functions with 'pino' JSON logger
4
+ * when we are running as a lambda
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.awsCloudWatchTag = { awsTag: 'userLogs' };
8
+ const util = require('util');
9
+ const pino = require('pino');
10
+ // The following console function write to stdout,
11
+ // but we do not support them when running as Lambda.
12
+ // console.count
13
+ // console.countReset
14
+ // console.dirxml
15
+ // console.group
16
+ // console.table
17
+ // Because the enable() and disable() functions can
18
+ // be called multiple, overlapping times, we need to
19
+ // put these two variables into a global.
20
+ // istanbul ignore else
21
+ const layer0OriginalConsole = {
22
+ assert: console.assert,
23
+ debug: console.debug,
24
+ dir: console.dir,
25
+ error: console.error,
26
+ info: console.info,
27
+ log: console.log,
28
+ time: console.time,
29
+ timeEnd: console.timeEnd,
30
+ timeLog: console.timeLog,
31
+ trace: console.trace,
32
+ warn: console.warn,
33
+ };
34
+ let _timers = {};
35
+ /**
36
+ * A function set as `logMethod` in Pino options in order to concatenate
37
+ * trailing parameters to logging functions. This emulates the behavior
38
+ * of console.log family of methods.
39
+ *
40
+ * More at https://github.com/pinojs/pino/blob/HEAD/docs/api.md#interpolationvalues-any
41
+ */
42
+ function pinoLogArgConcatenationMethod(args, method) {
43
+ if (args.length >= 2) {
44
+ // interpolate all non-string arguments with %j which serializes objects properly
45
+ // @ts-ignore
46
+ method.apply(this, [
47
+ args.map(arg => (typeof arg === 'string' ? '%s' : '%j')).join(' '),
48
+ ...args,
49
+ ]);
50
+ }
51
+ else {
52
+ // @ts-ignore
53
+ method.apply(this, args);
54
+ }
55
+ }
56
+ class ConsoleWrapper {
57
+ static _assert(condition, ...args) {
58
+ if (!condition) {
59
+ console.info(...args);
60
+ }
61
+ }
62
+ static _dir(...args) {
63
+ console.info(util.inspect(...args));
64
+ }
65
+ static _time(label) {
66
+ _timers[label] = Date.now();
67
+ }
68
+ static _timeEnd(label) {
69
+ ConsoleWrapper._timeLog(label);
70
+ }
71
+ static _timeLog(label, ...args) {
72
+ if (!_timers[label]) {
73
+ console.warn(`Warning: No such label '${label}' for console.timeEnd()`);
74
+ return;
75
+ }
76
+ const deltaTime = Date.now() - _timers[label];
77
+ _timers[label] = Date.now();
78
+ console.info(`${label}: ${deltaTime}ms`, ...args);
79
+ }
80
+ static enable({ clientIp, requestId, wi, } = {}) {
81
+ _timers = {};
82
+ let logger = pino({
83
+ base: {
84
+ ...exports.awsCloudWatchTag,
85
+ ...{ wi },
86
+ },
87
+ // Changing this to true because we are getting rid of cloudwatch
88
+ // which used to add timestamps automatically. We should use the log generation time over
89
+ // log ingestion time anyway because the former is more accurate.
90
+ timestamp: true,
91
+ hooks: {
92
+ logMethod: pinoLogArgConcatenationMethod,
93
+ },
94
+ });
95
+ if (clientIp) {
96
+ logger = logger.child({ clientIp });
97
+ }
98
+ if (requestId) {
99
+ logger = logger.child({ requestId });
100
+ }
101
+ console.assert = ConsoleWrapper._assert;
102
+ console.debug = logger.debug.bind(logger);
103
+ console.dir = ConsoleWrapper._dir;
104
+ console.error = logger.error.bind(logger);
105
+ console.info = logger.info.bind(logger);
106
+ console.log = logger.info.bind(logger);
107
+ console.time = ConsoleWrapper._time;
108
+ console.timeEnd = ConsoleWrapper._timeEnd;
109
+ console.timeLog = ConsoleWrapper._timeLog;
110
+ console.trace = logger.trace.bind(logger);
111
+ console.warn = logger.warn.bind(logger);
112
+ }
113
+ static disable() {
114
+ console.assert = layer0OriginalConsole.assert;
115
+ console.debug = layer0OriginalConsole.debug;
116
+ console.dir = layer0OriginalConsole.dir;
117
+ console.error = layer0OriginalConsole.error;
118
+ console.info = layer0OriginalConsole.info;
119
+ console.log = layer0OriginalConsole.log;
120
+ console.time = layer0OriginalConsole.time;
121
+ console.timeEnd = layer0OriginalConsole.timeEnd;
122
+ console.timeLog = layer0OriginalConsole.timeLog;
123
+ console.trace = layer0OriginalConsole.trace;
124
+ console.warn = layer0OriginalConsole.warn;
125
+ }
126
+ }
127
+ exports.default = ConsoleWrapper;
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" />
2
+ export default function getBodyLoggingData(rawBody: string | Buffer[], headers?: any): {
3
+ body?: undefined;
4
+ bodyLength?: undefined;
5
+ bodyTruncated?: undefined;
6
+ } | {
7
+ body: string;
8
+ bodyLength: any;
9
+ bodyTruncated: boolean;
10
+ };
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const zlib_1 = require("zlib");
4
+ const constants_1 = require("../constants");
5
+ // We limit the logged body due to CloudWatch 256Kb per line limitation,
6
+ // CloudWatch costs and, last but not least, websocket exploding on
7
+ // larger sizes.
8
+ // Tests have shown that 8Kb length results in responsive UI with enough
9
+ // captured information.
10
+ const MAX_BODY_LENGTH = 8 * 1024;
11
+ function base64encode(str) {
12
+ return Buffer.from(str).toString('base64');
13
+ }
14
+ // Gets the content encoding value from the given headers, no matter
15
+ // what case the header has been passed through.
16
+ function getContentEncoding(headers) {
17
+ if (!headers) {
18
+ return undefined;
19
+ }
20
+ let encoding = headers[constants_1.HTTP_HEADERS.contentEncoding];
21
+ if (!encoding) {
22
+ for (let name of Object.keys(headers)) {
23
+ if (name.toLowerCase() === constants_1.HTTP_HEADERS.contentEncoding) {
24
+ encoding = headers[name];
25
+ break;
26
+ }
27
+ }
28
+ }
29
+ if (Array.isArray(encoding)) {
30
+ if (encoding.length) {
31
+ encoding = encoding[0];
32
+ }
33
+ else {
34
+ encoding = undefined;
35
+ }
36
+ }
37
+ return encoding;
38
+ }
39
+ // For the purposes of HTTP request and response logging we log the body.
40
+ // This function returns an object with possibly truncated body, full body
41
+ // length and a flag set to true if the body was truncated.
42
+ // The object is directly included in the HTTP request logging result.
43
+ // This functionn never throws as it is just related to logging and we don't
44
+ // want a request to ever fail due to logging issues.
45
+ function getBodyLoggingData(rawBody, headers) {
46
+ var _a;
47
+ try {
48
+ if (!rawBody || rawBody.length === 0) {
49
+ return {};
50
+ }
51
+ let body;
52
+ if (typeof rawBody === 'string') {
53
+ body = Buffer.from(rawBody, 'base64');
54
+ }
55
+ else if (Buffer.isBuffer(rawBody)) {
56
+ body = rawBody;
57
+ }
58
+ else if (Array.isArray(rawBody)) {
59
+ body = Buffer.concat(rawBody);
60
+ }
61
+ else {
62
+ // We don't know what we have so the best we can do is return a user visible error.
63
+ return {
64
+ body: base64encode(`Unknown body format: ${typeof rawBody}`),
65
+ // @ts-ignore
66
+ bodyLength: rawBody.length,
67
+ bodyTruncated: true,
68
+ };
69
+ }
70
+ let encoding = (_a = getContentEncoding(headers)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
71
+ try {
72
+ switch (encoding) {
73
+ case constants_1.GZIP_ENCODING: {
74
+ body = zlib_1.gunzipSync(body);
75
+ break;
76
+ }
77
+ case constants_1.BROTLI_ENCODING: {
78
+ body = zlib_1.brotliDecompressSync(body);
79
+ break;
80
+ }
81
+ default: {
82
+ // Nothing to do.
83
+ }
84
+ }
85
+ }
86
+ catch (e) {
87
+ return {
88
+ body: base64encode(`Error while decompressing the body [${encoding}]: ${e.message}`),
89
+ bodyLength: body.length,
90
+ bodyTruncated: true,
91
+ };
92
+ }
93
+ return {
94
+ body: body.slice(0, MAX_BODY_LENGTH).toString('base64'),
95
+ bodyLength: body.length,
96
+ bodyTruncated: body.length > MAX_BODY_LENGTH,
97
+ };
98
+ }
99
+ catch (e) {
100
+ // istanbul ignore next
101
+ return {
102
+ body: base64encode(`Error while getting body logging data: ${e && e.message}`),
103
+ bodyLength: rawBody.length,
104
+ bodyTruncated: true,
105
+ };
106
+ }
107
+ }
108
+ exports.default = getBodyLoggingData;
@@ -0,0 +1 @@
1
+ export declare function handler(event: any): Promise<any>;