@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,124 @@
1
+ import { RouteHandler } from './Router';
2
+ import PathMatcher from './PathMatcher';
3
+ import Request from './Request';
4
+ import RouteCriteria from './RouteCriteria';
5
+ import Response from './Response';
6
+ /**
7
+ * @private
8
+ */
9
+ export default class Route {
10
+ readonly criteria: RouteCriteria;
11
+ readonly matcher?: PathMatcher;
12
+ readonly handler: RouteHandler;
13
+ readonly options?: RouteOptions;
14
+ /**
15
+ * Creates a new Route
16
+ * @param criteria A string or an object with `path`, `headers`, and `method`.
17
+ * @param handler A route handler
18
+ * @param options A route options
19
+ */
20
+ constructor(criteria: string | RouteCriteria | null, handler: RouteHandler, options: RouteOptions);
21
+ /**
22
+ * Returns params if route matches the request's method, headers, cookies and path.
23
+ * @param req
24
+ * @return The path params if the route matches the current request, otherwise false
25
+ */
26
+ match(req: Request): {};
27
+ /**
28
+ * Matches response. This is used for error routes and each route that contains response matcher is considered as
29
+ * a route for handling the error pages. Each error route must send a response.
30
+ * @param res Response
31
+ * @returns
32
+ */
33
+ matchResponse(res: Response): boolean;
34
+ private matchResponseStatus;
35
+ private matchPath;
36
+ private matchMethod;
37
+ /**
38
+ * Run thru criteria headers and match with request headers.
39
+ *
40
+ * Header names are *not* case-sensitive and they are all lower-cased per Node behavior we pass `toLower` to matcher function.
41
+ *
42
+ * @param req Request object
43
+ */
44
+ private matchHeaders;
45
+ /**
46
+ * Matches JSON body based on given criteria
47
+ *
48
+ * @param req Request object
49
+ *
50
+ * @returns Boolean
51
+ */
52
+ private matchBody;
53
+ /**
54
+ * Run thru criteria query and match with request query parameters.
55
+ *
56
+ * Query string names are case-sensitive so we use the default behaviour of
57
+ * `matchCriteriaRegexObjectWithRequestObject`.
58
+ *
59
+ * @param req Request object
60
+ */
61
+ private matchQueryParams;
62
+ /**
63
+ * Run thru criteria cookies and match with request cookies.
64
+ *
65
+ * Cookie names are case-sensitive so we use the default behaviour of
66
+ * `matchCriteriaRegexObjectWithRequestObject`.
67
+ *
68
+ * @param req Request object
69
+ */
70
+ private matchCookies;
71
+ /**
72
+ * Match the protocol for the request. All routes have the implicit `https` protocol
73
+ * unless explicitly specified as something else.
74
+ *
75
+ * Because HTTP is a subset of HTTPS we make sure that when strings are used we match
76
+ * the whole value rather than just a part of it.
77
+ *
78
+ * @param req Request object
79
+ */
80
+ private matchProtocol;
81
+ toString(): string;
82
+ toRegex(): RegExp;
83
+ /**
84
+ * Returns criteria json
85
+ * This is consumed by cache metrics that will transform the route to be as similar as in routes file
86
+ */
87
+ toJson(): string;
88
+ /**
89
+ * Returns a string with the regex representation of the route.
90
+ * @returns Regexp string representation of the route
91
+ */
92
+ toRegexString(): string;
93
+ /**
94
+ * Returns a regex string compatible with the edge regular express parser
95
+ */
96
+ toEdgeRegexString(): string;
97
+ /**
98
+ * Returns if the route should match response criteria.
99
+ *
100
+ * @returns
101
+ */
102
+ isRespRoute(): boolean;
103
+ static toRegexp(path?: string): RegExp;
104
+ static toEdgeRegexString(path?: string): string;
105
+ /**
106
+ * Generate a path-to-regexp comptible path that includes query strings
107
+ * In path-to-regexp, '?' is a special character so it needs to be escaped
108
+ *
109
+ * Note that we prevent querystring from escaping ':', which is used to inject
110
+ * matched params from the path
111
+ *
112
+ * @param path
113
+ * @param query
114
+ */
115
+ static pathWithQueryString(path: string, query: {
116
+ [key: string]: string;
117
+ }): string;
118
+ }
119
+ export interface RouteOptions {
120
+ /**
121
+ * Adds the label for static routes
122
+ */
123
+ label?: string;
124
+ }
@@ -0,0 +1,280 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var __importStar = (this && this.__importStar) || function (mod) {
6
+ if (mod && mod.__esModule) return mod;
7
+ var result = {};
8
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
9
+ result["default"] = mod;
10
+ return result;
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ const constants_1 = require("../constants");
14
+ const universalRouteUtils_1 = require("./universalRouteUtils");
15
+ const cookie_1 = require("cookie");
16
+ const path_to_regexp_1 = require("path-to-regexp");
17
+ const normalizeCriteria_1 = __importDefault(require("./normalizeCriteria"));
18
+ const PathMatcher_1 = __importStar(require("./PathMatcher"));
19
+ const querystring_1 = __importDefault(require("querystring"));
20
+ const toEdgeRegex_1 = __importDefault(require("../utils/toEdgeRegex"));
21
+ const toLower_1 = __importDefault(require("../utils/toLower"));
22
+ /**
23
+ * @private
24
+ */
25
+ class Route {
26
+ /**
27
+ * Creates a new Route
28
+ * @param criteria A string or an object with `path`, `headers`, and `method`.
29
+ * @param handler A route handler
30
+ * @param options A route options
31
+ */
32
+ constructor(criteria, handler, options) {
33
+ this.criteria = normalizeCriteria_1.default(criteria);
34
+ this.handler = handler;
35
+ this.options = options;
36
+ if (this.criteria.path) {
37
+ this.matcher = new PathMatcher_1.default(this.criteria.path);
38
+ }
39
+ }
40
+ /**
41
+ * Returns params if route matches the request's method, headers, cookies and path.
42
+ * @param req
43
+ * @return The path params if the route matches the current request, otherwise false
44
+ */
45
+ match(req) {
46
+ // Params are mostly extracted from path, but in they can also be extracted from query string, header, cookie, etc.
47
+ // although that would need to be implemented at EDGE too, which in general is not trivial.
48
+ // As of now, on EDGE, this is only implemented for query string params to inject in redirect()
49
+ const matchParamsFns = [
50
+ this.matchPath,
51
+ this.matchProtocol,
52
+ this.matchMethod,
53
+ this.matchHeaders,
54
+ this.matchQueryParams,
55
+ this.matchCookies,
56
+ this.matchBody,
57
+ ];
58
+ const mergedParams = {};
59
+ for (const matchParamsFn of matchParamsFns) {
60
+ const paramsOrBoolean = matchParamsFn.bind(this)(req);
61
+ if (!paramsOrBoolean) {
62
+ // One matcher failed, no need to go further
63
+ return false;
64
+ }
65
+ Object.assign(mergedParams, paramsOrBoolean);
66
+ }
67
+ // We wait until now before assigning params to the request so we are sure the route actually matched the request.
68
+ req.params = mergedParams;
69
+ return mergedParams;
70
+ }
71
+ /**
72
+ * Matches response. This is used for error routes and each route that contains response matcher is considered as
73
+ * a route for handling the error pages. Each error route must send a response.
74
+ * @param res Response
75
+ * @returns
76
+ */
77
+ matchResponse(res) {
78
+ return this.matchResponseStatus(res);
79
+ }
80
+ matchResponseStatus(res) {
81
+ var _a, _b, _c;
82
+ if ((_b = (_a = this.criteria) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.statusCode) {
83
+ return !!((_c = res.statusCode) === null || _c === void 0 ? void 0 : _c.toString().match(this.criteria.response.statusCode));
84
+ }
85
+ return false;
86
+ }
87
+ // Match criteria path to request url
88
+ matchPath(req) {
89
+ if (this.matcher) {
90
+ return this.matcher.match(req.path);
91
+ }
92
+ else {
93
+ return {}; // return a match with no params
94
+ }
95
+ }
96
+ // Match criteria method to request method
97
+ matchMethod(req) {
98
+ if (!this.criteria.method || !req.method) {
99
+ return true;
100
+ }
101
+ return new RegExp(this.criteria.method, 'i').test(req.method);
102
+ }
103
+ /**
104
+ * Run thru criteria headers and match with request headers.
105
+ *
106
+ * Header names are *not* case-sensitive and they are all lower-cased per Node behavior we pass `toLower` to matcher function.
107
+ *
108
+ * @param req Request object
109
+ */
110
+ matchHeaders(req) {
111
+ if (this.criteria.headers) {
112
+ return universalRouteUtils_1.matchCriteriaRegexObjectWithRequestObject(this.criteria.headers, req.headers, toLower_1.default);
113
+ }
114
+ return true;
115
+ }
116
+ /**
117
+ * Matches JSON body based on given criteria
118
+ *
119
+ * @param req Request object
120
+ *
121
+ * @returns Boolean
122
+ */
123
+ matchBody(req) {
124
+ if (this.criteria.body && this.criteria.body.parse == 'json' && req.body) {
125
+ let bodyObject;
126
+ try {
127
+ bodyObject = JSON.parse(req.body);
128
+ }
129
+ catch {
130
+ return false;
131
+ }
132
+ return universalRouteUtils_1.deepMatchObject(bodyObject, this.criteria.body.criteria);
133
+ }
134
+ return true;
135
+ }
136
+ /**
137
+ * Run thru criteria query and match with request query parameters.
138
+ *
139
+ * Query string names are case-sensitive so we use the default behaviour of
140
+ * `matchCriteriaRegexObjectWithRequestObject`.
141
+ *
142
+ * @param req Request object
143
+ */
144
+ matchQueryParams(req) {
145
+ if (this.criteria.query) {
146
+ // When there's no query params it means there's no way it's a match when criteria is set
147
+ if (!req.query) {
148
+ return false;
149
+ }
150
+ return universalRouteUtils_1.matchCriteriaRegexObjectWithRequestObject(this.criteria.query, req.query);
151
+ }
152
+ return true;
153
+ }
154
+ /**
155
+ * Run thru criteria cookies and match with request cookies.
156
+ *
157
+ * Cookie names are case-sensitive so we use the default behaviour of
158
+ * `matchCriteriaRegexObjectWithRequestObject`.
159
+ *
160
+ * @param req Request object
161
+ */
162
+ matchCookies(req) {
163
+ if (this.criteria.cookies) {
164
+ const cookieHeader = req.headers['cookie'];
165
+ if (cookieHeader == null) {
166
+ // When there is no cookie header, we return true only if all matchers
167
+ // on cookies are null meaning "cookie not present".
168
+ return Object.values(this.criteria.cookies).every(regex => regex === null);
169
+ }
170
+ const cookieValue = Array.isArray(cookieHeader) ? cookieHeader.join('; ') : cookieHeader;
171
+ const reqCookies = cookie_1.parse(cookieValue);
172
+ return universalRouteUtils_1.matchCriteriaRegexObjectWithRequestObject(this.criteria.cookies, reqCookies);
173
+ }
174
+ return true;
175
+ }
176
+ /**
177
+ * Match the protocol for the request. All routes have the implicit `https` protocol
178
+ * unless explicitly specified as something else.
179
+ *
180
+ * Because HTTP is a subset of HTTPS we make sure that when strings are used we match
181
+ * the whole value rather than just a part of it.
182
+ *
183
+ * @param req Request object
184
+ */
185
+ matchProtocol(req) {
186
+ const protocol = (req.headers && req.headers[constants_1.HTTP_HEADERS.x0Protocol]) || 'https';
187
+ let criteriaProtocolRegex;
188
+ if (typeof this.criteria.protocol === 'string') {
189
+ criteriaProtocolRegex = new RegExp(`^${this.criteria.protocol}$`, 'i');
190
+ }
191
+ else {
192
+ criteriaProtocolRegex = new RegExp(this.criteria.protocol || '^https$', 'i');
193
+ }
194
+ return universalRouteUtils_1.testRegExp(criteriaProtocolRegex, protocol);
195
+ }
196
+ toString() {
197
+ const { path, ...criteria } = this.criteria;
198
+ if (Object.keys(criteria).length) {
199
+ return JSON.stringify(this.criteria);
200
+ }
201
+ else if (path) {
202
+ return path;
203
+ }
204
+ else {
205
+ return 'fallback';
206
+ }
207
+ }
208
+ toRegex() {
209
+ return Route.toRegexp(this.criteria.path);
210
+ }
211
+ /**
212
+ * Returns criteria json
213
+ * This is consumed by cache metrics that will transform the route to be as similar as in routes file
214
+ */
215
+ toJson() {
216
+ var _a;
217
+ return JSON.stringify({ ...this.criteria, label: (_a = this.options) === null || _a === void 0 ? void 0 : _a.label }, (_, value) => {
218
+ // We have to convert regular expressions to string otherwise it will not be logged
219
+ if (value instanceof RegExp) {
220
+ return value.toString();
221
+ }
222
+ return value;
223
+ });
224
+ }
225
+ /**
226
+ * Returns a string with the regex representation of the route.
227
+ * @returns Regexp string representation of the route
228
+ */
229
+ toRegexString() {
230
+ return this.toRegex().source;
231
+ }
232
+ /**
233
+ * Returns a regex string compatible with the edge regular express parser
234
+ */
235
+ toEdgeRegexString() {
236
+ return Route.toEdgeRegexString(this.criteria.path);
237
+ }
238
+ /**
239
+ * Returns if the route should match response criteria.
240
+ *
241
+ * @returns
242
+ */
243
+ isRespRoute() {
244
+ return !!this.criteria.response;
245
+ }
246
+ static toRegexp(path) {
247
+ if (path) {
248
+ try {
249
+ return path_to_regexp_1.pathToRegexp(path);
250
+ }
251
+ catch (e) {
252
+ throw new PathMatcher_1.PathMatcherError(path);
253
+ }
254
+ }
255
+ else {
256
+ // For fallbacks we want everything matched so that we can replace everything if needed.
257
+ // We insist on total matching with `^` and `$` because some regex replacement algorithms
258
+ // have issues with correctly applying `.*` in completely greedy manner (e.g. Fastly's `regsuball`)
259
+ return /^.*$/;
260
+ }
261
+ }
262
+ static toEdgeRegexString(path) {
263
+ return toEdgeRegex_1.default(Route.toRegexp(path));
264
+ }
265
+ /**
266
+ * Generate a path-to-regexp comptible path that includes query strings
267
+ * In path-to-regexp, '?' is a special character so it needs to be escaped
268
+ *
269
+ * Note that we prevent querystring from escaping ':', which is used to inject
270
+ * matched params from the path
271
+ *
272
+ * @param path
273
+ * @param query
274
+ */
275
+ static pathWithQueryString(path, query) {
276
+ const queryString = querystring_1.default.stringify(query).replace(/%3A/g, ':');
277
+ return path + (queryString && `\\?${queryString}`);
278
+ }
279
+ }
280
+ exports.default = Route;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Criteria for response. Note that all routes that are having this will restart and will eventually be evaluated twice. First response and then request.
3
+ * This route will only be evaluated when we have x-0-error header present. This header will be set once this criteria matches and the router will be restarted.
4
+ */
5
+ interface RouteCriteriaResponse {
6
+ statusCode: RegExp;
7
+ }
8
+ /**
9
+ * Criteria for matching a request.
10
+ */
11
+ export default interface RouteCriteria {
12
+ /**
13
+ * Matches a request based on its protocol. Unless explicitly specified then `https`
14
+ * is the default. To serve a route on both HTTPS and HTTP you can specify `/https?/`
15
+ * regex. If an HTTP request is not matched against any route, Layer0 will
16
+ * automatically issue a redirect to equivalent HTTPS URL.
17
+ */
18
+ protocol?: string | RegExp;
19
+ /**
20
+ * Matches a request based on one or more header values. Keys are
21
+ * case-insensitive header names, values are regular expressions to match or null.
22
+ * When value is null then requests are matched for the header not being present.
23
+ */
24
+ headers?: {
25
+ [name: string]: string | RegExp | null;
26
+ };
27
+ /**
28
+ * Matches a request based on one or more cookie values. Keys are
29
+ * case-sensitive cookie names, values are regular expressions to match or null.
30
+ * When value is null then requests are matched for the cookie not being present.
31
+ */
32
+ cookies?: {
33
+ [name: string]: string | RegExp | null;
34
+ };
35
+ /**
36
+ * Matches a request based on one or more query parameter values. Keys are
37
+ * case-sensitive names, values are regular expressions to match or null.
38
+ * When value is null then requests are matched for the query parameter not being present.
39
+ */
40
+ query?: {
41
+ [name: string]: string | RegExp | null;
42
+ };
43
+ /**
44
+ * Matches a request based on the HTTP method. Instead of this, prefer using
45
+ * `get`, `post`, `put`, `delete`, `options`, and `patch` methods.
46
+ */
47
+ method?: string | RegExp;
48
+ /**
49
+ * Matches a request based on the path. The same path syntax is used by
50
+ * the simple form of the Router class's `match` method.
51
+ */
52
+ path?: string;
53
+ /**
54
+ * Matches a request response. This is used by error pages to make edge aware of a matching error route.
55
+ * This will issue a restart on a edge with specific header that matches the error route on next eval.
56
+ */
57
+ response?: RouteCriteriaResponse;
58
+ /**
59
+ * Matches a request based on criteria matching a JSON body
60
+ */
61
+ body?: {
62
+ parse: string;
63
+ criteria: {
64
+ [name: string]: string | RegExp;
65
+ };
66
+ };
67
+ }
68
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,157 @@
1
+ import Route, { RouteOptions } from './Route';
2
+ import { RouteHandler } from './Router';
3
+ import RouteCriteria from './RouteCriteria';
4
+ /**
5
+ * The contents to be written to static-asset-manifest.json
6
+ * @private
7
+ */
8
+ export declare const staticAssetManifest: {
9
+ [key: string]: string[];
10
+ };
11
+ /**
12
+ * The static asset manifest file name
13
+ * @private
14
+ */
15
+ export declare const STATIC_ASSET_MANIFEST_FILE = "static-asset-manifest.json";
16
+ /**
17
+ * This class is needed for creating a route group that holds a routes that can
18
+ * be dynamically updated on a local env.
19
+ * @private
20
+ */
21
+ export default class RouteGroup {
22
+ readonly name: string;
23
+ private _routes;
24
+ /**
25
+ * @param name Name of the route group - **required**
26
+ */
27
+ constructor(name: string);
28
+ /**
29
+ * Adds route to group.
30
+ * @param criteria The criteria to match.
31
+ * @param handler The handler to use for the route.
32
+ */
33
+ match(criteria: RouteCriteria | string | null, handler: RouteHandler, { index, label }?: AddRouteOptions): this;
34
+ /**
35
+ * Adds routes for all files in a directory tree.
36
+ * @private
37
+ * @param sourcePath The path to a directory containing static assets relative to the root of your project.
38
+ * @param options
39
+ * @returns A self-reference, suitable for chaining.
40
+ */
41
+ dir(sourcePath: string, options: StaticOptions): this;
42
+ /**
43
+ * Adds routes for all static assets in a directory tree.
44
+ * @param sourcePath The path to a directory containing static assets relative to the root of your project.
45
+ * @param options
46
+ * @returns A self-reference, suitable for chaining.
47
+ */
48
+ static(sourcePath: string, options: StaticOptions): this;
49
+ /**
50
+ * Adds Basic Authentication.
51
+ *
52
+ * **example**
53
+ *
54
+ * ```js
55
+ * router
56
+ * .requireBasicAuth({ username: 'user', password: 's3cr3t!' })
57
+ * // ...include additional routes below...
58
+ * ```
59
+ *
60
+ * You can also require basic auth for a subset of URLs using the criteria option:
61
+ *
62
+ * ```js
63
+ * router
64
+ * .requireBasicAuth({ criteria: '/secret/:path*' username: 'user', password: 's3cr3t!' })
65
+ * // ...include additional routes below...
66
+ * ```
67
+ *
68
+ * The criteria option accepts a path pattern as a string, or a RouteCriteria object.
69
+ *
70
+ * @param options
71
+ * @returns A self-reference, suitable for chaining.
72
+ */
73
+ requireBasicAuth(options: BasicAuthOptions): this;
74
+ /**
75
+ * Since the files are now on S3, we can no longer crawl the file system to
76
+ * determine the routes, so we use the manifest file.
77
+ * We also prevent webpack from trying to bundle the manifest, which will fail.
78
+ */
79
+ private staticAssetsForPath;
80
+ /**
81
+ * Clears all routes in group.
82
+ * Used for updating routes dynamically for development purpose.
83
+ */
84
+ clear(): this;
85
+ /**
86
+ * Returns the routes in group.
87
+ * @returns Routes in group
88
+ */
89
+ get routes(): Route[];
90
+ /**
91
+ * Returns number of routes in group.
92
+ * @returns Number of routes in the group.
93
+ */
94
+ get length(): number;
95
+ }
96
+ export interface DirOptions {
97
+ /**
98
+ * The handler to call when each resulting route is matched.
99
+ */
100
+ handler: (dest: string) => RouteHandler;
101
+ /**
102
+ * Limits the files served to only those matching the specified glob pattern.
103
+ * See https://github.com/isaacs/node-glob#glob-primer for the syntax supported.
104
+ */
105
+ glob?: string;
106
+ /**
107
+ * By default the path on which files are served corresponds to the path within the directory, so for example, public/css/main.css would be served at '/css/main.css',
108
+ * you can override this using the `paths` option. For each file, the function is passed the path to the file within the directory. The function
109
+ * should return the URL paths on which the file should be served.
110
+ */
111
+ paths?: (file: string) => string[];
112
+ /**
113
+ * An optional function to sort the files before mapping them to routes
114
+ */
115
+ sort?: (files: string[]) => string[];
116
+ /**
117
+ * Glob pattern of files to exclude
118
+ */
119
+ ignore?: string | string[];
120
+ /**
121
+ * Adds the label for static routes
122
+ */
123
+ label?: string;
124
+ }
125
+ export interface StaticOptions extends Partial<DirOptions> {
126
+ /**
127
+ * Add caching or other additional route handling logic here. The function is passed a ResponseWriter, the same as any other route handler would be.
128
+ */
129
+ handler?: (dest: string) => RouteHandler;
130
+ }
131
+ /**
132
+ * Options for Router#requireBasicAuth
133
+ */
134
+ export interface BasicAuthOptions {
135
+ /**
136
+ * The route pattern to which to apply basic authentication
137
+ */
138
+ route?: RouteCriteria;
139
+ /**
140
+ * The username
141
+ */
142
+ username?: string;
143
+ /**
144
+ * The password to check
145
+ */
146
+ password?: string;
147
+ /**
148
+ * The realm name for the browser's basic auth prompt
149
+ */
150
+ realm?: string;
151
+ }
152
+ export interface AddRouteOptions extends RouteOptions {
153
+ /**
154
+ * Adds the route at the specified index
155
+ */
156
+ index?: number;
157
+ }