@decohere/http 0.0.1-dev.125 → 0.0.1-dev.5

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 (292) hide show
  1. package/package.json +4 -13
  2. package/src/app/app.ts +147 -0
  3. package/src/app/module.ts +19 -0
  4. package/src/auth/ability.ts +56 -0
  5. package/src/auth/auth.config.ts +34 -0
  6. package/src/auth/auth.extensions.ts +115 -0
  7. package/src/auth/auth.types.ts +124 -0
  8. package/src/auth/casl-authorization.service.ts +62 -0
  9. package/{types/src/auth/principal-provider.d.ts → src/auth/principal-provider.ts} +13 -5
  10. package/src/auth/safe-outbound-url.ts +117 -0
  11. package/src/auth/token-service.ts +192 -0
  12. package/src/builder/builder.ts +118 -0
  13. package/{es6/src/const.js → src/const.ts} +25 -17
  14. package/src/health/health.controller.ts +34 -0
  15. package/src/health/health.extensions.ts +53 -0
  16. package/src/health/readiness.service.ts +33 -0
  17. package/{types/src/health/readiness.types.d.ts → src/health/readiness.types.ts} +4 -8
  18. package/src/hosting/hosted-service-host.ts +102 -0
  19. package/src/hosting/hosted-service.ts +31 -0
  20. package/src/http/http.compression.ts +38 -0
  21. package/src/http/http.extensions.ts +244 -0
  22. package/{types/src/http/http.options.store.d.ts → src/http/http.options.store.ts} +11 -1
  23. package/src/http/http.options.ts +41 -0
  24. package/{types/src/http/http.security.d.ts → src/http/http.security.ts} +16 -10
  25. package/src/http/http.static.ts +359 -0
  26. package/{es6/src/index.js → src/index.ts} +1 -0
  27. package/src/openapi/index.ts +22 -0
  28. package/src/openapi/openapi.generator.ts +78 -0
  29. package/src/openapi/openapi.types.ts +60 -0
  30. package/src/openapi/request-schema.ts +155 -0
  31. package/src/openapi/request-validator.ts +95 -0
  32. package/src/providers/fastify.provider.ts +454 -0
  33. package/src/routing/anvil.types.ts +150 -0
  34. package/src/routing/decorators/argument.decorator.ts +33 -0
  35. package/src/routing/decorators/auth.decorator.ts +79 -0
  36. package/src/routing/decorators/controller.decorator.ts +9 -0
  37. package/src/routing/decorators/field.decorator.ts +15 -0
  38. package/src/routing/decorators/request.decorator.ts +34 -0
  39. package/src/routing/decorators/response.decorator.ts +18 -0
  40. package/src/routing/decorators/route.decorator.ts +52 -0
  41. package/src/routing/filters/exception-filter-host.ts +90 -0
  42. package/src/routing/filters/exception-filter.ts +29 -0
  43. package/src/routing/middleware/http-access-log.middleware.ts +36 -0
  44. package/src/routing/middleware/middleware.ts +26 -0
  45. package/src/routing/middleware/request-id.ts +18 -0
  46. package/src/routing/path.util.ts +38 -0
  47. package/src/routing/pipes/pipes.ts +132 -0
  48. package/src/routing/services/route-argument-resolver.ts +92 -0
  49. package/src/routing/services/route-registry.ts +229 -0
  50. package/src/routing/services/router.ts +166 -0
  51. package/src/sse/sse.decorator.ts +41 -0
  52. package/src/sse/sse.encoder.ts +86 -0
  53. package/src/sse/sse.types.ts +47 -0
  54. package/src/sse/sse.wire.ts +34 -0
  55. package/src/testing/boot-module.ts +63 -0
  56. package/src/testing/sse-reader.ts +120 -0
  57. package/tests/app.hosted-services.spec.ts +292 -0
  58. package/tests/app.shutdown.integration.spec.ts +160 -0
  59. package/tests/app.spec.ts +132 -0
  60. package/tests/auth.ability.spec.ts +48 -0
  61. package/tests/auth.decorators.spec.ts +20 -0
  62. package/tests/auth.fail-closed.pentest.spec.ts +77 -0
  63. package/tests/auth.integration.spec.ts +234 -0
  64. package/tests/auth.jwks-cache.spec.ts +52 -0
  65. package/tests/auth.missing-auth.pentest.spec.ts +56 -0
  66. package/tests/auth.oidc-ssrf.pentest.spec.ts +72 -0
  67. package/tests/auth.oidc.integration.spec.ts +161 -0
  68. package/tests/auth.token-service.spec.ts +251 -0
  69. package/tests/builder.spec.ts +12 -0
  70. package/tests/health.integration.spec.ts +111 -0
  71. package/tests/helpers/listen-ephemeral.ts +13 -0
  72. package/tests/helpers/local-oidc-server.ts +100 -0
  73. package/tests/http.access-log.integration.spec.ts +111 -0
  74. package/tests/http.boolean-query.integration.spec.ts +59 -0
  75. package/tests/http.compression.integration.spec.ts +604 -0
  76. package/tests/http.date-query.integration.spec.ts +71 -0
  77. package/tests/http.global-prefix.integration.spec.ts +284 -0
  78. package/tests/http.number-query.integration.spec.ts +65 -0
  79. package/tests/http.pino-roll-hmr.integration.spec.ts +79 -0
  80. package/tests/http.pipeline-order.integration.spec.ts +95 -0
  81. package/tests/http.request-cleanup.integration.spec.ts +57 -0
  82. package/tests/http.request-id-scope.pentest.spec.ts +50 -0
  83. package/tests/http.security.integration.spec.ts +106 -0
  84. package/tests/http.static.integration.spec.ts +847 -0
  85. package/tests/http.static.spec.ts +111 -0
  86. package/tests/http.surface.integration.spec.ts +167 -0
  87. package/tests/openapi.integration.spec.ts +193 -0
  88. package/tests/openapi.validator-cache.integration.spec.ts +55 -0
  89. package/tests/routing.decorators.spec.ts +15 -0
  90. package/tests/routing.registry.spec.ts +44 -0
  91. package/tests/routing.resolver.spec.ts +92 -0
  92. package/tests/sse.integration.spec.ts +421 -0
  93. package/tests/sse.wire.spec.ts +33 -0
  94. package/LICENSE +0 -15
  95. package/commonjs/src/app/app.js +0 -166
  96. package/commonjs/src/app/index.js +0 -19
  97. package/commonjs/src/app/module.js +0 -17
  98. package/commonjs/src/auth/ability.js +0 -54
  99. package/commonjs/src/auth/auth.config.js +0 -23
  100. package/commonjs/src/auth/auth.extensions.js +0 -106
  101. package/commonjs/src/auth/auth.types.js +0 -65
  102. package/commonjs/src/auth/casl-authorization.service.js +0 -36
  103. package/commonjs/src/auth/index.js +0 -23
  104. package/commonjs/src/auth/principal-provider.js +0 -19
  105. package/commonjs/src/auth/safe-outbound-url.js +0 -102
  106. package/commonjs/src/auth/token-service.js +0 -151
  107. package/commonjs/src/builder/builder.js +0 -95
  108. package/commonjs/src/builder/index.js +0 -18
  109. package/commonjs/src/const.js +0 -87
  110. package/commonjs/src/health/health.controller.js +0 -75
  111. package/commonjs/src/health/health.extensions.js +0 -50
  112. package/commonjs/src/health/index.js +0 -21
  113. package/commonjs/src/health/readiness.service.js +0 -67
  114. package/commonjs/src/health/readiness.types.js +0 -7
  115. package/commonjs/src/hosting/hosted-service-host.js +0 -88
  116. package/commonjs/src/hosting/hosted-service.js +0 -11
  117. package/commonjs/src/hosting/index.js +0 -19
  118. package/commonjs/src/http/http.compression.js +0 -27
  119. package/commonjs/src/http/http.extensions.js +0 -269
  120. package/commonjs/src/http/http.options.js +0 -26
  121. package/commonjs/src/http/http.options.store.js +0 -20
  122. package/commonjs/src/http/http.security.js +0 -27
  123. package/commonjs/src/http/http.static.js +0 -248
  124. package/commonjs/src/http/index.js +0 -22
  125. package/commonjs/src/index.js +0 -27
  126. package/commonjs/src/openapi/index.js +0 -45
  127. package/commonjs/src/openapi/openapi.generator.js +0 -103
  128. package/commonjs/src/openapi/openapi.types.js +0 -4
  129. package/commonjs/src/openapi/request-schema.js +0 -187
  130. package/commonjs/src/openapi/request-validator.js +0 -85
  131. package/commonjs/src/providers/fastify.provider.js +0 -391
  132. package/commonjs/src/providers/index.js +0 -18
  133. package/commonjs/src/routing/anvil.types.js +0 -99
  134. package/commonjs/src/routing/decorators/argument.decorator.js +0 -49
  135. package/commonjs/src/routing/decorators/auth.decorator.js +0 -70
  136. package/commonjs/src/routing/decorators/controller.decorator.js +0 -16
  137. package/commonjs/src/routing/decorators/field.decorator.js +0 -25
  138. package/commonjs/src/routing/decorators/index.js +0 -24
  139. package/commonjs/src/routing/decorators/request.decorator.js +0 -30
  140. package/commonjs/src/routing/decorators/response.decorator.js +0 -34
  141. package/commonjs/src/routing/decorators/route.decorator.js +0 -67
  142. package/commonjs/src/routing/filters/exception-filter-host.js +0 -145
  143. package/commonjs/src/routing/filters/exception-filter.js +0 -28
  144. package/commonjs/src/routing/index.js +0 -25
  145. package/commonjs/src/routing/middleware/http-access-log.middleware.js +0 -47
  146. package/commonjs/src/routing/middleware/middleware.js +0 -20
  147. package/commonjs/src/routing/middleware/request-id.js +0 -30
  148. package/commonjs/src/routing/path.util.js +0 -51
  149. package/commonjs/src/routing/pipes/index.js +0 -18
  150. package/commonjs/src/routing/pipes/pipes.js +0 -145
  151. package/commonjs/src/routing/services/index.js +0 -18
  152. package/commonjs/src/routing/services/route-argument-resolver.js +0 -77
  153. package/commonjs/src/routing/services/route-registry.js +0 -194
  154. package/commonjs/src/routing/services/router.js +0 -158
  155. package/commonjs/src/sse/index.js +0 -26
  156. package/commonjs/src/sse/sse.decorator.js +0 -42
  157. package/commonjs/src/sse/sse.encoder.js +0 -73
  158. package/commonjs/src/sse/sse.types.js +0 -36
  159. package/commonjs/src/sse/sse.wire.js +0 -40
  160. package/commonjs/src/testing/boot-module.js +0 -38
  161. package/commonjs/src/testing/index.js +0 -20
  162. package/commonjs/src/testing/sse-reader.js +0 -98
  163. package/es6/src/app/app.js +0 -148
  164. package/es6/src/app/index.js +0 -2
  165. package/es6/src/app/module.js +0 -7
  166. package/es6/src/auth/ability.js +0 -45
  167. package/es6/src/auth/auth.config.js +0 -19
  168. package/es6/src/auth/auth.extensions.js +0 -83
  169. package/es6/src/auth/auth.types.js +0 -35
  170. package/es6/src/auth/casl-authorization.service.js +0 -40
  171. package/es6/src/auth/index.js +0 -6
  172. package/es6/src/auth/principal-provider.js +0 -14
  173. package/es6/src/auth/safe-outbound-url.js +0 -99
  174. package/es6/src/auth/token-service.js +0 -141
  175. package/es6/src/builder/builder.js +0 -85
  176. package/es6/src/builder/index.js +0 -1
  177. package/es6/src/health/health.controller.js +0 -65
  178. package/es6/src/health/health.extensions.js +0 -40
  179. package/es6/src/health/index.js +0 -4
  180. package/es6/src/health/readiness.service.js +0 -57
  181. package/es6/src/health/readiness.types.js +0 -4
  182. package/es6/src/hosting/hosted-service-host.js +0 -81
  183. package/es6/src/hosting/hosted-service.js +0 -8
  184. package/es6/src/hosting/index.js +0 -2
  185. package/es6/src/http/http.compression.js +0 -9
  186. package/es6/src/http/http.extensions.js +0 -259
  187. package/es6/src/http/http.options.js +0 -16
  188. package/es6/src/http/http.options.store.js +0 -13
  189. package/es6/src/http/http.security.js +0 -9
  190. package/es6/src/http/http.static.js +0 -224
  191. package/es6/src/http/index.js +0 -5
  192. package/es6/src/openapi/index.js +0 -3
  193. package/es6/src/openapi/openapi.generator.js +0 -82
  194. package/es6/src/openapi/openapi.types.js +0 -1
  195. package/es6/src/openapi/request-schema.js +0 -160
  196. package/es6/src/openapi/request-validator.js +0 -71
  197. package/es6/src/providers/fastify.provider.js +0 -376
  198. package/es6/src/providers/index.js +0 -1
  199. package/es6/src/routing/anvil.types.js +0 -57
  200. package/es6/src/routing/decorators/argument.decorator.js +0 -28
  201. package/es6/src/routing/decorators/auth.decorator.js +0 -58
  202. package/es6/src/routing/decorators/controller.decorator.js +0 -6
  203. package/es6/src/routing/decorators/field.decorator.js +0 -15
  204. package/es6/src/routing/decorators/index.js +0 -7
  205. package/es6/src/routing/decorators/request.decorator.js +0 -24
  206. package/es6/src/routing/decorators/response.decorator.js +0 -16
  207. package/es6/src/routing/decorators/route.decorator.js +0 -37
  208. package/es6/src/routing/filters/exception-filter-host.js +0 -127
  209. package/es6/src/routing/filters/exception-filter.js +0 -10
  210. package/es6/src/routing/index.js +0 -8
  211. package/es6/src/routing/middleware/http-access-log.middleware.js +0 -37
  212. package/es6/src/routing/middleware/middleware.js +0 -10
  213. package/es6/src/routing/middleware/request-id.js +0 -14
  214. package/es6/src/routing/path.util.js +0 -33
  215. package/es6/src/routing/pipes/index.js +0 -1
  216. package/es6/src/routing/pipes/pipes.js +0 -118
  217. package/es6/src/routing/services/index.js +0 -1
  218. package/es6/src/routing/services/route-argument-resolver.js +0 -67
  219. package/es6/src/routing/services/route-registry.js +0 -184
  220. package/es6/src/routing/services/router.js +0 -148
  221. package/es6/src/sse/index.js +0 -2
  222. package/es6/src/sse/sse.decorator.js +0 -31
  223. package/es6/src/sse/sse.encoder.js +0 -67
  224. package/es6/src/sse/sse.types.js +0 -22
  225. package/es6/src/sse/sse.wire.js +0 -30
  226. package/es6/src/testing/boot-module.js +0 -35
  227. package/es6/src/testing/index.js +0 -2
  228. package/es6/src/testing/sse-reader.js +0 -91
  229. package/types/src/app/app.d.ts +0 -41
  230. package/types/src/app/module.d.ts +0 -15
  231. package/types/src/auth/ability.d.ts +0 -19
  232. package/types/src/auth/auth.config.d.ts +0 -28
  233. package/types/src/auth/auth.extensions.d.ts +0 -53
  234. package/types/src/auth/auth.types.d.ts +0 -73
  235. package/types/src/auth/casl-authorization.service.d.ts +0 -28
  236. package/types/src/auth/safe-outbound-url.d.ts +0 -9
  237. package/types/src/auth/token-service.d.ts +0 -31
  238. package/types/src/builder/builder.d.ts +0 -36
  239. package/types/src/const.d.ts +0 -32
  240. package/types/src/health/health.controller.d.ts +0 -16
  241. package/types/src/health/health.extensions.d.ts +0 -31
  242. package/types/src/health/readiness.service.d.ts +0 -9
  243. package/types/src/hosting/hosted-service-host.d.ts +0 -37
  244. package/types/src/hosting/hosted-service.d.ts +0 -31
  245. package/types/src/http/http.compression.d.ts +0 -32
  246. package/types/src/http/http.extensions.d.ts +0 -79
  247. package/types/src/http/http.options.d.ts +0 -39
  248. package/types/src/http/http.static.d.ts +0 -160
  249. package/types/src/index.d.ts +0 -10
  250. package/types/src/openapi/index.d.ts +0 -6
  251. package/types/src/openapi/openapi.generator.d.ts +0 -6
  252. package/types/src/openapi/openapi.types.d.ts +0 -58
  253. package/types/src/openapi/request-schema.d.ts +0 -21
  254. package/types/src/openapi/request-validator.d.ts +0 -9
  255. package/types/src/providers/fastify.provider.d.ts +0 -56
  256. package/types/src/routing/anvil.types.d.ts +0 -119
  257. package/types/src/routing/decorators/argument.decorator.d.ts +0 -11
  258. package/types/src/routing/decorators/auth.decorator.d.ts +0 -30
  259. package/types/src/routing/decorators/controller.decorator.d.ts +0 -3
  260. package/types/src/routing/decorators/field.decorator.d.ts +0 -2
  261. package/types/src/routing/decorators/request.decorator.d.ts +0 -8
  262. package/types/src/routing/decorators/response.decorator.d.ts +0 -4
  263. package/types/src/routing/decorators/route.decorator.d.ts +0 -7
  264. package/types/src/routing/filters/exception-filter-host.d.ts +0 -19
  265. package/types/src/routing/filters/exception-filter.d.ts +0 -16
  266. package/types/src/routing/middleware/http-access-log.middleware.d.ts +0 -8
  267. package/types/src/routing/middleware/middleware.d.ts +0 -10
  268. package/types/src/routing/middleware/request-id.d.ts +0 -6
  269. package/types/src/routing/path.util.d.ts +0 -9
  270. package/types/src/routing/pipes/pipes.d.ts +0 -21
  271. package/types/src/routing/services/route-argument-resolver.d.ts +0 -10
  272. package/types/src/routing/services/route-registry.d.ts +0 -20
  273. package/types/src/routing/services/router.d.ts +0 -22
  274. package/types/src/sse/sse.decorator.d.ts +0 -17
  275. package/types/src/sse/sse.encoder.d.ts +0 -16
  276. package/types/src/sse/sse.types.d.ts +0 -37
  277. package/types/src/sse/sse.wire.d.ts +0 -9
  278. package/types/src/testing/boot-module.d.ts +0 -34
  279. package/types/src/testing/sse-reader.d.ts +0 -29
  280. /package/{types/src/app/index.d.ts → src/app/index.ts} +0 -0
  281. /package/{types/src/auth/index.d.ts → src/auth/index.ts} +0 -0
  282. /package/{types/src/builder/index.d.ts → src/builder/index.ts} +0 -0
  283. /package/{types/src/health/index.d.ts → src/health/index.ts} +0 -0
  284. /package/{types/src/hosting/index.d.ts → src/hosting/index.ts} +0 -0
  285. /package/{types/src/http/index.d.ts → src/http/index.ts} +0 -0
  286. /package/{types/src/providers/index.d.ts → src/providers/index.ts} +0 -0
  287. /package/{types/src/routing/decorators/index.d.ts → src/routing/decorators/index.ts} +0 -0
  288. /package/{types/src/routing/index.d.ts → src/routing/index.ts} +0 -0
  289. /package/{types/src/routing/pipes/index.d.ts → src/routing/pipes/index.ts} +0 -0
  290. /package/{types/src/routing/services/index.d.ts → src/routing/services/index.ts} +0 -0
  291. /package/{types/src/sse/index.d.ts → src/sse/index.ts} +0 -0
  292. /package/{types/src/testing/index.d.ts → src/testing/index.ts} +0 -0
@@ -1,269 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "BuilderExtensions", {
6
- enumerable: true,
7
- get: function() {
8
- return BuilderExtensions;
9
- }
10
- });
11
- const _extensibility = require("@decohere/core/extensibility");
12
- const _scribe = require("@decohere/scribe");
13
- const _principalprovider = require("../auth/principal-provider.js");
14
- const _builder = require("../builder/builder.js");
15
- const _const = require("../const.js");
16
- const _exceptionfilterhost = require("../routing/filters/exception-filter-host.js");
17
- const _httpaccesslogmiddleware = require("../routing/middleware/http-access-log.middleware.js");
18
- const _routeregistry = require("../routing/services/route-registry.js");
19
- const _router = require("../routing/services/router.js");
20
- const _httpoptionsstore = require("./http.options.store.js");
21
- const _httpstatic = require("./http.static.js");
22
- function _ts_decorate(decorators, target, key, desc) {
23
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
24
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
25
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
26
- return c > 3 && r && Object.defineProperty(target, key, r), r;
27
- }
28
- function _ts_metadata(k, v) {
29
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
30
- }
31
- const httpProviderStore = new WeakMap();
32
- const controllersStore = new WeakMap();
33
- class BuilderExtensions {
34
- static withHttpProvider(builder, type) {
35
- httpProviderStore.set(builder, type);
36
- const httpOptions = (0, _httpoptionsstore.getOrCreateHttpOptions)(builder);
37
- builder.withServices((containerBuilder)=>{
38
- const logger = _scribe.scribe.logger("BuilderExtensions");
39
- logger.trace("Configuring Http Provider");
40
- const http = httpProviderStore.get(builder);
41
- if (!http) {
42
- return;
43
- }
44
- containerBuilder.registerSingleton(_const.HttpOptionsToken, httpOptions);
45
- containerBuilder.registerSingleton(_const.HttpProviderToken, http);
46
- containerBuilder.registerSingleton(_const.RouterToken, _router.Router);
47
- containerBuilder.registerSingleton(_const.RouteRegistryToken, _routeregistry.RouteRegistry);
48
- containerBuilder.registerSingleton(_const.ExceptionFilterHostToken, _exceptionfilterhost.ExceptionFilterHost);
49
- containerBuilder.registerRequestScoped(_const.IPrincipalProviderToken, _principalprovider.PrincipalProvider);
50
- for (const middlewareType of httpOptions.middlewareTypes){
51
- containerBuilder.registerSingleton(middlewareType);
52
- }
53
- for (const filterType of httpOptions.filterTypes){
54
- containerBuilder.registerSingleton(filterType);
55
- }
56
- const controllers = controllersStore.get(builder) || [];
57
- for (const controllerFn of controllers){
58
- containerBuilder.registerRequestScoped(controllerFn);
59
- }
60
- });
61
- builder.registerPostBuildStep((container)=>{
62
- const logger = _scribe.scribe.logger("BuilderExtensions");
63
- const registry = container.resolve(_const.RouteRegistryToken);
64
- const controllers = controllersStore.get(builder) || [];
65
- for (const controllerFn of controllers){
66
- logger.trace(`Add routes from ${controllerFn.name}`);
67
- registry.addController(controllerFn);
68
- }
69
- });
70
- return builder;
71
- }
72
- static withHttp(builder, type, options) {
73
- const accessLog = options?.accessLog !== false;
74
- if (accessLog) {
75
- const httpOptions = (0, _httpoptionsstore.getOrCreateHttpOptions)(builder);
76
- if (!httpOptions.middlewareTypes.includes(_httpaccesslogmiddleware.HttpAccessLogMiddleware)) {
77
- httpOptions.middlewareTypes = [
78
- ...httpOptions.middlewareTypes,
79
- _httpaccesslogmiddleware.HttpAccessLogMiddleware
80
- ];
81
- }
82
- }
83
- return BuilderExtensions.withHttpProvider(builder, type);
84
- }
85
- static withControllers(builder, ...controllers) {
86
- const existing = controllersStore.get(builder) || [];
87
- controllersStore.set(builder, [
88
- ...existing,
89
- ...controllers
90
- ]);
91
- return builder;
92
- }
93
- static withGlobalPrefix(builder, prefix) {
94
- (0, _httpoptionsstore.getOrCreateHttpOptions)(builder).globalPrefix = prefix;
95
- return builder;
96
- }
97
- static withCors(builder, options) {
98
- (0, _httpoptionsstore.getOrCreateHttpOptions)(builder).cors = options;
99
- return builder;
100
- }
101
- static withHelmet(builder, options = {}) {
102
- (0, _httpoptionsstore.getOrCreateHttpOptions)(builder).helmet = options;
103
- return builder;
104
- }
105
- static withRateLimit(builder, options = {}) {
106
- (0, _httpoptionsstore.getOrCreateHttpOptions)(builder).rateLimit = options;
107
- return builder;
108
- }
109
- static withCompression(builder, options = {}) {
110
- (0, _httpoptionsstore.getOrCreateHttpOptions)(builder).compression = options;
111
- return builder;
112
- }
113
- static withBodyLimit(builder, bytes) {
114
- (0, _httpoptionsstore.getOrCreateHttpOptions)(builder).bodyLimit = bytes;
115
- return builder;
116
- }
117
- static withMiddleware(builder, ...middlewares) {
118
- const httpOptions = (0, _httpoptionsstore.getOrCreateHttpOptions)(builder);
119
- httpOptions.middlewareTypes = [
120
- ...httpOptions.middlewareTypes,
121
- ...middlewares
122
- ];
123
- return builder;
124
- }
125
- static withExceptionFilters(builder, ...filters) {
126
- const httpOptions = (0, _httpoptionsstore.getOrCreateHttpOptions)(builder);
127
- httpOptions.filterTypes = [
128
- ...httpOptions.filterTypes,
129
- ...filters
130
- ];
131
- return builder;
132
- }
133
- static withOpenApi(builder, options) {
134
- (0, _httpoptionsstore.getOrCreateHttpOptions)(builder).openapi = {
135
- validateRequests: true,
136
- path: "/openapi.json",
137
- ...options
138
- };
139
- return builder;
140
- }
141
- static withStatic(builder, prefix, directory, options) {
142
- const httpOptions = (0, _httpoptionsstore.getOrCreateHttpOptions)(builder);
143
- httpOptions.statics = [
144
- ...httpOptions.statics,
145
- _httpstatic.staticFiles.toMount(prefix, directory, options)
146
- ];
147
- return builder;
148
- }
149
- }
150
- _ts_decorate([
151
- (0, _extensibility.extension)(_builder.Builder),
152
- _ts_metadata("design:type", Function),
153
- _ts_metadata("design:paramtypes", [
154
- typeof _builder.Builder === "undefined" ? Object : _builder.Builder,
155
- typeof Thttp === "undefined" ? Object : Thttp
156
- ]),
157
- _ts_metadata("design:returntype", void 0)
158
- ], BuilderExtensions, "withHttpProvider", null);
159
- _ts_decorate([
160
- (0, _extensibility.extension)(_builder.Builder),
161
- _ts_metadata("design:type", Function),
162
- _ts_metadata("design:paramtypes", [
163
- typeof _builder.Builder === "undefined" ? Object : _builder.Builder,
164
- typeof Thttp === "undefined" ? Object : Thttp,
165
- typeof WithHttpOptions === "undefined" ? Object : WithHttpOptions
166
- ]),
167
- _ts_metadata("design:returntype", void 0)
168
- ], BuilderExtensions, "withHttp", null);
169
- _ts_decorate([
170
- (0, _extensibility.extension)(_builder.Builder),
171
- _ts_metadata("design:type", Function),
172
- _ts_metadata("design:paramtypes", [
173
- typeof _builder.Builder === "undefined" ? Object : _builder.Builder,
174
- Array
175
- ]),
176
- _ts_metadata("design:returntype", void 0)
177
- ], BuilderExtensions, "withControllers", null);
178
- _ts_decorate([
179
- (0, _extensibility.extension)(_builder.Builder),
180
- _ts_metadata("design:type", Function),
181
- _ts_metadata("design:paramtypes", [
182
- typeof _builder.Builder === "undefined" ? Object : _builder.Builder,
183
- String
184
- ]),
185
- _ts_metadata("design:returntype", void 0)
186
- ], BuilderExtensions, "withGlobalPrefix", null);
187
- _ts_decorate([
188
- (0, _extensibility.extension)(_builder.Builder),
189
- _ts_metadata("design:type", Function),
190
- _ts_metadata("design:paramtypes", [
191
- typeof _builder.Builder === "undefined" ? Object : _builder.Builder,
192
- typeof CorsOptions === "undefined" ? Object : CorsOptions
193
- ]),
194
- _ts_metadata("design:returntype", void 0)
195
- ], BuilderExtensions, "withCors", null);
196
- _ts_decorate([
197
- (0, _extensibility.extension)(_builder.Builder),
198
- _ts_metadata("design:type", Function),
199
- _ts_metadata("design:paramtypes", [
200
- typeof _builder.Builder === "undefined" ? Object : _builder.Builder,
201
- typeof HelmetOptions === "undefined" ? Object : HelmetOptions
202
- ]),
203
- _ts_metadata("design:returntype", void 0)
204
- ], BuilderExtensions, "withHelmet", null);
205
- _ts_decorate([
206
- (0, _extensibility.extension)(_builder.Builder),
207
- _ts_metadata("design:type", Function),
208
- _ts_metadata("design:paramtypes", [
209
- typeof _builder.Builder === "undefined" ? Object : _builder.Builder,
210
- typeof RateLimitOptions === "undefined" ? Object : RateLimitOptions
211
- ]),
212
- _ts_metadata("design:returntype", void 0)
213
- ], BuilderExtensions, "withRateLimit", null);
214
- _ts_decorate([
215
- (0, _extensibility.extension)(_builder.Builder),
216
- _ts_metadata("design:type", Function),
217
- _ts_metadata("design:paramtypes", [
218
- typeof _builder.Builder === "undefined" ? Object : _builder.Builder,
219
- typeof CompressionOptions === "undefined" ? Object : CompressionOptions
220
- ]),
221
- _ts_metadata("design:returntype", void 0)
222
- ], BuilderExtensions, "withCompression", null);
223
- _ts_decorate([
224
- (0, _extensibility.extension)(_builder.Builder),
225
- _ts_metadata("design:type", Function),
226
- _ts_metadata("design:paramtypes", [
227
- typeof _builder.Builder === "undefined" ? Object : _builder.Builder,
228
- Number
229
- ]),
230
- _ts_metadata("design:returntype", void 0)
231
- ], BuilderExtensions, "withBodyLimit", null);
232
- _ts_decorate([
233
- (0, _extensibility.extension)(_builder.Builder),
234
- _ts_metadata("design:type", Function),
235
- _ts_metadata("design:paramtypes", [
236
- typeof _builder.Builder === "undefined" ? Object : _builder.Builder,
237
- Array
238
- ]),
239
- _ts_metadata("design:returntype", void 0)
240
- ], BuilderExtensions, "withMiddleware", null);
241
- _ts_decorate([
242
- (0, _extensibility.extension)(_builder.Builder),
243
- _ts_metadata("design:type", Function),
244
- _ts_metadata("design:paramtypes", [
245
- typeof _builder.Builder === "undefined" ? Object : _builder.Builder,
246
- Array
247
- ]),
248
- _ts_metadata("design:returntype", void 0)
249
- ], BuilderExtensions, "withExceptionFilters", null);
250
- _ts_decorate([
251
- (0, _extensibility.extension)(_builder.Builder),
252
- _ts_metadata("design:type", Function),
253
- _ts_metadata("design:paramtypes", [
254
- typeof _builder.Builder === "undefined" ? Object : _builder.Builder,
255
- typeof OpenApiOptions === "undefined" ? Object : OpenApiOptions
256
- ]),
257
- _ts_metadata("design:returntype", void 0)
258
- ], BuilderExtensions, "withOpenApi", null);
259
- _ts_decorate([
260
- (0, _extensibility.extension)(_builder.Builder),
261
- _ts_metadata("design:type", Function),
262
- _ts_metadata("design:paramtypes", [
263
- typeof _builder.Builder === "undefined" ? Object : _builder.Builder,
264
- String,
265
- String,
266
- typeof StaticOptions === "undefined" ? Object : StaticOptions
267
- ]),
268
- _ts_metadata("design:returntype", void 0)
269
- ], BuilderExtensions, "withStatic", null);
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "HttpOptions", {
6
- enumerable: true,
7
- get: function() {
8
- return HttpOptions;
9
- }
10
- });
11
- class HttpOptions {
12
- globalPrefix = "";
13
- /**
14
- * Controllers put under the global prefix although they declare `globalPrefix: false`
15
- * (`withHealth({ underGlobalPrefix: true })`).
16
- */ underGlobalPrefix = new Set();
17
- cors;
18
- openapi;
19
- /** `undefined` = helmet on with defaults; `false` = off; object = plugin options. */ helmet;
20
- /** `undefined` = rate-limit on with defaults; `false` = off; object = plugin options. */ rateLimit;
21
- /** `undefined` = compression on with defaults; `false` = off; object = options. See `withCompression`. */ compression;
22
- /** Request body size limit in bytes; `undefined` uses the 1 MiB default. */ bodyLimit;
23
- /** Built UIs served from this API, see `withStatic`. */ statics = [];
24
- middlewareTypes = [];
25
- filterTypes = [];
26
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "getOrCreateHttpOptions", {
6
- enumerable: true,
7
- get: function() {
8
- return getOrCreateHttpOptions;
9
- }
10
- });
11
- const _httpoptions = require("./http.options.js");
12
- const httpOptionsStore = new WeakMap();
13
- function getOrCreateHttpOptions(builder) {
14
- let options = httpOptionsStore.get(builder);
15
- if (options == null) {
16
- options = new _httpoptions.HttpOptions();
17
- httpOptionsStore.set(builder, options);
18
- }
19
- return options;
20
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * Default HTTP security settings applied by {@link FastifyProvider} when
3
- * `withHttpProvider` is used. Override via `withHelmet` / `withRateLimit` /
4
- * `withBodyLimit` (pass `false` to disable helmet or rate-limit).
5
- */ /** Fastify body size limit (bytes). Matches Fastify's built-in default, made explicit and overridable. */ "use strict";
6
- Object.defineProperty(exports, "__esModule", {
7
- value: true
8
- });
9
- function _export(target, all) {
10
- for(var name in all)Object.defineProperty(target, name, {
11
- enumerable: true,
12
- get: Object.getOwnPropertyDescriptor(all, name).get
13
- });
14
- }
15
- _export(exports, {
16
- get DEFAULT_HTTP_BODY_LIMIT () {
17
- return DEFAULT_HTTP_BODY_LIMIT;
18
- },
19
- get DEFAULT_HTTP_RATE_LIMIT () {
20
- return DEFAULT_HTTP_RATE_LIMIT;
21
- }
22
- });
23
- const DEFAULT_HTTP_BODY_LIMIT = 1_048_576;
24
- const DEFAULT_HTTP_RATE_LIMIT = {
25
- max: 100,
26
- timeWindow: "1 minute"
27
- };
@@ -1,248 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: Object.getOwnPropertyDescriptor(all, name).get
9
- });
10
- }
11
- _export(exports, {
12
- get STATIC_DEFAULT_CACHE_CONTROL () {
13
- return STATIC_DEFAULT_CACHE_CONTROL;
14
- },
15
- get STATIC_DEFAULT_IMMUTABLE () {
16
- return STATIC_DEFAULT_IMMUTABLE;
17
- },
18
- get STATIC_DEFAULT_NO_CACHE () {
19
- return STATIC_DEFAULT_NO_CACHE;
20
- },
21
- get STATIC_IMMUTABLE_CACHE_CONTROL () {
22
- return STATIC_IMMUTABLE_CACHE_CONTROL;
23
- },
24
- get STATIC_NO_CACHE_CONTROL () {
25
- return STATIC_NO_CACHE_CONTROL;
26
- },
27
- get staticFiles () {
28
- return staticFiles;
29
- }
30
- });
31
- const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
32
- const _picomatch = /*#__PURE__*/ _interop_require_default(require("picomatch"));
33
- const _authtypes = require("../auth/auth.types.js");
34
- function _interop_require_default(obj) {
35
- return obj && obj.__esModule ? obj : {
36
- default: obj
37
- };
38
- }
39
- const STATIC_IMMUTABLE_CACHE_CONTROL = "public, max-age=31536000, immutable";
40
- const STATIC_NO_CACHE_CONTROL = "no-cache";
41
- const STATIC_DEFAULT_CACHE_CONTROL = "public, max-age=0, must-revalidate";
42
- const STATIC_DEFAULT_NO_CACHE = [
43
- "index.html",
44
- "remoteEntry.js"
45
- ];
46
- const STATIC_DEFAULT_IMMUTABLE = /[.-](?=[A-Za-z0-9_]*(?:\d|[a-z][A-Z]))[A-Za-z0-9_]{8,}\.[A-Za-z0-9]+(?:\.map)?$/;
47
- /** `"ui"`, `"/ui"` and `"/ui/"` all mean `/ui/`; `"/"` is the root. Refuses an empty prefix. */ function normalizePrefix(prefix) {
48
- const segments = prefix.split("/").filter((segment)=>segment !== "");
49
- if (segments.length === 0) {
50
- if (prefix.trim() === "") {
51
- throw new Error('withStatic needs a prefix, such as "/ui/" or "/" for the root.');
52
- }
53
- return "/";
54
- }
55
- if (segments.some((segment)=>segment === "." || segment === ".." || /[*:?]/.test(segment))) {
56
- throw new Error(`withStatic prefix "${prefix}" must be plain path segments, such as "/ui/".`);
57
- }
58
- return `/${segments.join("/")}/`;
59
- }
60
- function toMount(prefix, directory, options = {}) {
61
- if (directory.trim() === "") {
62
- throw new Error(`withStatic("${prefix}") needs the directory that holds the built files.`);
63
- }
64
- return {
65
- prefix: normalizePrefix(prefix),
66
- directory,
67
- options
68
- };
69
- }
70
- /**
71
- * Checks every mount at start. Returns the ones that can be served; a missing directory fails or
72
- * warns according to the mount's `onMissingDirectory`. Two mounts on one prefix always fail.
73
- */ async function resolve(mounts, env) {
74
- const cwd = env.cwd ?? process.cwd();
75
- const resolved = [];
76
- const seen = new Set();
77
- for (const mount of mounts){
78
- if (seen.has(mount.prefix)) {
79
- throw new Error(`withStatic: ${mount.prefix} is mounted twice.`);
80
- }
81
- seen.add(mount.prefix);
82
- const root = _nodepath.default.resolve(cwd, mount.directory);
83
- if (!await env.directoryExists(root)) {
84
- const policy = mount.options.onMissingDirectory ?? ((0, _authtypes.isDevelopmentNodeEnv)(env.nodeEnv) ? "warn" : "fail");
85
- const message = `withStatic("${mount.prefix}", "${mount.directory}"): ${root} does not exist. ` + "Build the UI first, or run the app from the folder that holds it.";
86
- if (policy === "fail") {
87
- throw new Error(message);
88
- }
89
- env.warn(`${message} ${mount.prefix} will answer 404 until it is built and the app restarts.`);
90
- continue;
91
- }
92
- const options = mount.options;
93
- resolved.push({
94
- prefix: mount.prefix,
95
- root,
96
- spaFallback: options.spaFallback ?? true,
97
- index: options.index ?? "index.html",
98
- noCache: options.noCache ?? STATIC_DEFAULT_NO_CACHE,
99
- immutable: options.immutable ?? STATIC_DEFAULT_IMMUTABLE,
100
- cacheControl: options.cacheControl ?? STATIC_DEFAULT_CACHE_CONTROL,
101
- exclude: options.exclude ?? []
102
- });
103
- }
104
- return resolved;
105
- }
106
- /** `Cache-Control` for a file, given its path relative to the mount's directory. */ function cacheControlFor(mount, relativePath) {
107
- const posix = relativePath.split(_nodepath.default.sep).join("/");
108
- const name = _nodepath.default.posix.basename(posix);
109
- if (mount.noCache.some((entry)=>entry === name || entry === posix)) {
110
- return STATIC_NO_CACHE_CONTROL;
111
- }
112
- if (mount.immutable !== false && mount.immutable.test(posix)) {
113
- return STATIC_IMMUTABLE_CACHE_CONTROL;
114
- }
115
- return mount.cacheControl;
116
- }
117
- /**
118
- * Does this path look like a file: an extension on the last segment, or a dotfile anywhere?
119
- * Then a miss is a real 404, not a client-side route.
120
- */ function looksLikeFile(pathname) {
121
- const segments = pathname.split("/").filter((segment)=>segment !== "");
122
- if (segments.some((segment)=>segment.startsWith("."))) {
123
- return true;
124
- }
125
- const last = pathname.endsWith("/") ? undefined : segments.at(-1);
126
- return last?.includes(".") === true;
127
- }
128
- /** The request path as the mount sees it: no query, decoded, repeated slashes collapsed. */ function normalizePathname(url) {
129
- const raw = url.split("?")[0] ?? "";
130
- let decoded = raw;
131
- try {
132
- decoded = decodeURIComponent(raw);
133
- } catch {
134
- // Keep the raw text: a malformed escape is matched as written.
135
- }
136
- return decoded.replace(/\/{2,}/g, "/");
137
- }
138
- /** Builds the test for a mount's `exclude` patterns. Matches on the normalised path. */ function excluder(patterns) {
139
- if (patterns.length === 0) {
140
- return ()=>false;
141
- }
142
- const matches = (0, _picomatch.default)([
143
- ...patterns
144
- ], {
145
- dot: true
146
- });
147
- return (pathname)=>matches(pathname);
148
- }
149
- /**
150
- * The first path segment of every registered route, for {@link isUnderRoute}. A segment that is a
151
- * parameter or wildcard (`:id`, `*`) says nothing about the path and is skipped.
152
- */ function routeSegments(routePaths) {
153
- const segments = new Set();
154
- for (const routePath of routePaths){
155
- const first = routePath.split("/").find((segment)=>segment !== "");
156
- if (first != null && !/[:*]/.test(first)) {
157
- segments.add(first);
158
- }
159
- }
160
- return segments;
161
- }
162
- /**
163
- * Is this path under one of the app's own routes? True when its first segment is the first
164
- * segment of a registered route: with a controller route `/lp/portfolio`, `/lp/portfolo` and
165
- * `/lp/anything/else` belong to the API and keep the JSON 404, while `/lpx` does not.
166
- */ function isUnderRoute(pathname, segments) {
167
- const first = pathname.split("/").find((segment)=>segment !== "");
168
- return first != null && segments.has(first);
169
- }
170
- /** Is `pathname` the path `base` or below it? `/api` holds `/api` and `/api/x`, not `/apiary`. */ function isWithin(pathname, base) {
171
- const trimmed = base.replace(/\/+$/, "");
172
- return pathname === trimmed || pathname.startsWith(`${trimmed}/`);
173
- }
174
- /**
175
- * The literal start of a route path, up to its first parameter or wildcard: `/webhooks/:id` gives
176
- * `/webhooks`, `/:id` gives `""`.
177
- */ function staticStem(routePath) {
178
- const stem = [];
179
- for (const segment of routePath.split("/")){
180
- if (segment.startsWith(":") || segment.includes("*")) {
181
- break;
182
- }
183
- if (segment !== "") {
184
- stem.push(segment);
185
- }
186
- }
187
- return stem.length === 0 ? "" : `/${stem.join("/")}`;
188
- }
189
- /**
190
- * What the fallback treats as the API, as a test on the normalised path. With a global prefix it
191
- * is the prefix, the OpenAPI path and every route left outside the prefix
192
- * (`@Controller({ globalPrefix: false })`, such as `/health`), each with the paths below it, so a
193
- * client route may share a first segment with a controller. Without a prefix it is
194
- * {@link isUnderRoute} (the first segment of every registered route), the safe guess when nothing
195
- * says where the API lives.
196
- */ function apiBoundary(boundary) {
197
- if (boundary.globalPrefix === "") {
198
- const segments = routeSegments([
199
- ...boundary.routePaths,
200
- ...boundary.openApiPath == null ? [] : [
201
- boundary.openApiPath
202
- ]
203
- ]);
204
- return (pathname)=>isUnderRoute(pathname, segments);
205
- }
206
- const outside = [
207
- ...boundary.routePaths
208
- ].filter((routePath)=>!isWithin(routePath, boundary.globalPrefix)).map(staticStem).filter((stem)=>stem !== "");
209
- const bases = [
210
- boundary.globalPrefix,
211
- boundary.openApiPath,
212
- ...outside
213
- ].filter((base)=>base != null);
214
- return (pathname)=>bases.some((base)=>isWithin(pathname, base));
215
- }
216
- /** Does the `Accept` header ask for HTML (a browser navigation)? `text/html;q=0` does not. */ function acceptsHtml(accept) {
217
- if (accept == null) {
218
- return false;
219
- }
220
- return accept.split(",").some((entry)=>{
221
- const [type = "", ...params] = entry.split(";").map((part)=>part.trim().toLowerCase());
222
- if (type !== "text/html") {
223
- return false;
224
- }
225
- const quality = params.find((param)=>param.startsWith("q="));
226
- return quality == null || Number.parseFloat(quality.slice(2)) > 0;
227
- });
228
- }
229
- /**
230
- * Should an unknown path get the app's `index.html`? Only a browser navigation: GET or HEAD, no
231
- * file extension and no dotfile in the path, an `Accept` that includes `text/html`, and not under
232
- * the API (see {@link apiBoundary}). Everything else keeps the normal JSON 404.
233
- */ function shouldFallBack(request, belongsToApi) {
234
- return (request.method === "GET" || request.method === "HEAD") && acceptsHtml(request.accept) && !looksLikeFile(request.pathname) && !belongsToApi(request.pathname);
235
- }
236
- const staticFiles = {
237
- toMount,
238
- resolve,
239
- cacheControlFor,
240
- looksLikeFile,
241
- normalizePathname,
242
- excluder,
243
- routeSegments,
244
- isUnderRoute,
245
- apiBoundary,
246
- acceptsHtml,
247
- shouldFallBack
248
- };
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- _export_star(require("./http.compression.js"), exports);
6
- _export_star(require("./http.extensions.js"), exports);
7
- _export_star(require("./http.options.js"), exports);
8
- _export_star(require("./http.security.js"), exports);
9
- _export_star(require("./http.static.js"), exports);
10
- function _export_star(from, to) {
11
- Object.keys(from).forEach(function(k) {
12
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
13
- Object.defineProperty(to, k, {
14
- enumerable: true,
15
- get: function() {
16
- return from[k];
17
- }
18
- });
19
- }
20
- });
21
- return from;
22
- }
@@ -1,27 +0,0 @@
1
- // Resolve StartOptions re-export ambiguity (app vs routing) — prefer app's shape
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- _export_star(require("./app/index.js"), exports);
7
- _export_star(require("./auth/index.js"), exports);
8
- _export_star(require("./builder/index.js"), exports);
9
- _export_star(require("./const.js"), exports);
10
- _export_star(require("./health/index.js"), exports);
11
- _export_star(require("./hosting/index.js"), exports);
12
- _export_star(require("./openapi/index.js"), exports);
13
- _export_star(require("./routing/index.js"), exports);
14
- _export_star(require("./sse/index.js"), exports);
15
- function _export_star(from, to) {
16
- Object.keys(from).forEach(function(k) {
17
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
18
- Object.defineProperty(to, k, {
19
- enumerable: true,
20
- get: function() {
21
- return from[k];
22
- }
23
- });
24
- }
25
- });
26
- return from;
27
- }