@decohere/http 0.0.1-dev.126 → 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 (293) hide show
  1. package/README.md +2 -2
  2. package/package.json +4 -13
  3. package/src/app/app.ts +147 -0
  4. package/src/app/module.ts +19 -0
  5. package/src/auth/ability.ts +56 -0
  6. package/src/auth/auth.config.ts +34 -0
  7. package/src/auth/auth.extensions.ts +115 -0
  8. package/src/auth/auth.types.ts +124 -0
  9. package/src/auth/casl-authorization.service.ts +62 -0
  10. package/{types/src/auth/principal-provider.d.ts → src/auth/principal-provider.ts} +13 -5
  11. package/src/auth/safe-outbound-url.ts +117 -0
  12. package/src/auth/token-service.ts +192 -0
  13. package/src/builder/builder.ts +118 -0
  14. package/{es6/src/const.js → src/const.ts} +25 -17
  15. package/src/health/health.controller.ts +34 -0
  16. package/src/health/health.extensions.ts +53 -0
  17. package/src/health/readiness.service.ts +33 -0
  18. package/{types/src/health/readiness.types.d.ts → src/health/readiness.types.ts} +4 -8
  19. package/src/hosting/hosted-service-host.ts +102 -0
  20. package/src/hosting/hosted-service.ts +31 -0
  21. package/src/http/http.compression.ts +38 -0
  22. package/src/http/http.extensions.ts +244 -0
  23. package/{types/src/http/http.options.store.d.ts → src/http/http.options.store.ts} +11 -1
  24. package/src/http/http.options.ts +41 -0
  25. package/{types/src/http/http.security.d.ts → src/http/http.security.ts} +16 -10
  26. package/src/http/http.static.ts +359 -0
  27. package/{es6/src/index.js → src/index.ts} +1 -0
  28. package/src/openapi/index.ts +22 -0
  29. package/src/openapi/openapi.generator.ts +78 -0
  30. package/src/openapi/openapi.types.ts +60 -0
  31. package/src/openapi/request-schema.ts +155 -0
  32. package/src/openapi/request-validator.ts +95 -0
  33. package/src/providers/fastify.provider.ts +454 -0
  34. package/src/routing/anvil.types.ts +150 -0
  35. package/src/routing/decorators/argument.decorator.ts +33 -0
  36. package/src/routing/decorators/auth.decorator.ts +79 -0
  37. package/src/routing/decorators/controller.decorator.ts +9 -0
  38. package/src/routing/decorators/field.decorator.ts +15 -0
  39. package/src/routing/decorators/request.decorator.ts +34 -0
  40. package/src/routing/decorators/response.decorator.ts +18 -0
  41. package/src/routing/decorators/route.decorator.ts +52 -0
  42. package/src/routing/filters/exception-filter-host.ts +90 -0
  43. package/src/routing/filters/exception-filter.ts +29 -0
  44. package/src/routing/middleware/http-access-log.middleware.ts +36 -0
  45. package/src/routing/middleware/middleware.ts +26 -0
  46. package/src/routing/middleware/request-id.ts +18 -0
  47. package/src/routing/path.util.ts +38 -0
  48. package/src/routing/pipes/pipes.ts +132 -0
  49. package/src/routing/services/route-argument-resolver.ts +92 -0
  50. package/src/routing/services/route-registry.ts +229 -0
  51. package/src/routing/services/router.ts +166 -0
  52. package/src/sse/sse.decorator.ts +41 -0
  53. package/src/sse/sse.encoder.ts +86 -0
  54. package/src/sse/sse.types.ts +47 -0
  55. package/src/sse/sse.wire.ts +34 -0
  56. package/src/testing/boot-module.ts +63 -0
  57. package/src/testing/sse-reader.ts +120 -0
  58. package/tests/app.hosted-services.spec.ts +292 -0
  59. package/tests/app.shutdown.integration.spec.ts +160 -0
  60. package/tests/app.spec.ts +132 -0
  61. package/tests/auth.ability.spec.ts +48 -0
  62. package/tests/auth.decorators.spec.ts +20 -0
  63. package/tests/auth.fail-closed.pentest.spec.ts +77 -0
  64. package/tests/auth.integration.spec.ts +234 -0
  65. package/tests/auth.jwks-cache.spec.ts +52 -0
  66. package/tests/auth.missing-auth.pentest.spec.ts +56 -0
  67. package/tests/auth.oidc-ssrf.pentest.spec.ts +72 -0
  68. package/tests/auth.oidc.integration.spec.ts +161 -0
  69. package/tests/auth.token-service.spec.ts +251 -0
  70. package/tests/builder.spec.ts +12 -0
  71. package/tests/health.integration.spec.ts +111 -0
  72. package/tests/helpers/listen-ephemeral.ts +13 -0
  73. package/tests/helpers/local-oidc-server.ts +100 -0
  74. package/tests/http.access-log.integration.spec.ts +111 -0
  75. package/tests/http.boolean-query.integration.spec.ts +59 -0
  76. package/tests/http.compression.integration.spec.ts +604 -0
  77. package/tests/http.date-query.integration.spec.ts +71 -0
  78. package/tests/http.global-prefix.integration.spec.ts +284 -0
  79. package/tests/http.number-query.integration.spec.ts +65 -0
  80. package/tests/http.pino-roll-hmr.integration.spec.ts +79 -0
  81. package/tests/http.pipeline-order.integration.spec.ts +95 -0
  82. package/tests/http.request-cleanup.integration.spec.ts +57 -0
  83. package/tests/http.request-id-scope.pentest.spec.ts +50 -0
  84. package/tests/http.security.integration.spec.ts +106 -0
  85. package/tests/http.static.integration.spec.ts +847 -0
  86. package/tests/http.static.spec.ts +111 -0
  87. package/tests/http.surface.integration.spec.ts +167 -0
  88. package/tests/openapi.integration.spec.ts +193 -0
  89. package/tests/openapi.validator-cache.integration.spec.ts +55 -0
  90. package/tests/routing.decorators.spec.ts +15 -0
  91. package/tests/routing.registry.spec.ts +44 -0
  92. package/tests/routing.resolver.spec.ts +92 -0
  93. package/tests/sse.integration.spec.ts +421 -0
  94. package/tests/sse.wire.spec.ts +33 -0
  95. package/LICENSE +0 -15
  96. package/commonjs/src/app/app.js +0 -166
  97. package/commonjs/src/app/index.js +0 -19
  98. package/commonjs/src/app/module.js +0 -17
  99. package/commonjs/src/auth/ability.js +0 -54
  100. package/commonjs/src/auth/auth.config.js +0 -23
  101. package/commonjs/src/auth/auth.extensions.js +0 -106
  102. package/commonjs/src/auth/auth.types.js +0 -65
  103. package/commonjs/src/auth/casl-authorization.service.js +0 -36
  104. package/commonjs/src/auth/index.js +0 -23
  105. package/commonjs/src/auth/principal-provider.js +0 -19
  106. package/commonjs/src/auth/safe-outbound-url.js +0 -102
  107. package/commonjs/src/auth/token-service.js +0 -151
  108. package/commonjs/src/builder/builder.js +0 -95
  109. package/commonjs/src/builder/index.js +0 -18
  110. package/commonjs/src/const.js +0 -87
  111. package/commonjs/src/health/health.controller.js +0 -75
  112. package/commonjs/src/health/health.extensions.js +0 -50
  113. package/commonjs/src/health/index.js +0 -21
  114. package/commonjs/src/health/readiness.service.js +0 -67
  115. package/commonjs/src/health/readiness.types.js +0 -7
  116. package/commonjs/src/hosting/hosted-service-host.js +0 -88
  117. package/commonjs/src/hosting/hosted-service.js +0 -11
  118. package/commonjs/src/hosting/index.js +0 -19
  119. package/commonjs/src/http/http.compression.js +0 -27
  120. package/commonjs/src/http/http.extensions.js +0 -269
  121. package/commonjs/src/http/http.options.js +0 -26
  122. package/commonjs/src/http/http.options.store.js +0 -20
  123. package/commonjs/src/http/http.security.js +0 -27
  124. package/commonjs/src/http/http.static.js +0 -248
  125. package/commonjs/src/http/index.js +0 -22
  126. package/commonjs/src/index.js +0 -27
  127. package/commonjs/src/openapi/index.js +0 -45
  128. package/commonjs/src/openapi/openapi.generator.js +0 -103
  129. package/commonjs/src/openapi/openapi.types.js +0 -4
  130. package/commonjs/src/openapi/request-schema.js +0 -187
  131. package/commonjs/src/openapi/request-validator.js +0 -85
  132. package/commonjs/src/providers/fastify.provider.js +0 -391
  133. package/commonjs/src/providers/index.js +0 -18
  134. package/commonjs/src/routing/anvil.types.js +0 -99
  135. package/commonjs/src/routing/decorators/argument.decorator.js +0 -49
  136. package/commonjs/src/routing/decorators/auth.decorator.js +0 -70
  137. package/commonjs/src/routing/decorators/controller.decorator.js +0 -16
  138. package/commonjs/src/routing/decorators/field.decorator.js +0 -25
  139. package/commonjs/src/routing/decorators/index.js +0 -24
  140. package/commonjs/src/routing/decorators/request.decorator.js +0 -30
  141. package/commonjs/src/routing/decorators/response.decorator.js +0 -34
  142. package/commonjs/src/routing/decorators/route.decorator.js +0 -67
  143. package/commonjs/src/routing/filters/exception-filter-host.js +0 -145
  144. package/commonjs/src/routing/filters/exception-filter.js +0 -28
  145. package/commonjs/src/routing/index.js +0 -25
  146. package/commonjs/src/routing/middleware/http-access-log.middleware.js +0 -47
  147. package/commonjs/src/routing/middleware/middleware.js +0 -20
  148. package/commonjs/src/routing/middleware/request-id.js +0 -30
  149. package/commonjs/src/routing/path.util.js +0 -51
  150. package/commonjs/src/routing/pipes/index.js +0 -18
  151. package/commonjs/src/routing/pipes/pipes.js +0 -145
  152. package/commonjs/src/routing/services/index.js +0 -18
  153. package/commonjs/src/routing/services/route-argument-resolver.js +0 -77
  154. package/commonjs/src/routing/services/route-registry.js +0 -194
  155. package/commonjs/src/routing/services/router.js +0 -158
  156. package/commonjs/src/sse/index.js +0 -26
  157. package/commonjs/src/sse/sse.decorator.js +0 -42
  158. package/commonjs/src/sse/sse.encoder.js +0 -73
  159. package/commonjs/src/sse/sse.types.js +0 -36
  160. package/commonjs/src/sse/sse.wire.js +0 -40
  161. package/commonjs/src/testing/boot-module.js +0 -38
  162. package/commonjs/src/testing/index.js +0 -20
  163. package/commonjs/src/testing/sse-reader.js +0 -98
  164. package/es6/src/app/app.js +0 -148
  165. package/es6/src/app/index.js +0 -2
  166. package/es6/src/app/module.js +0 -7
  167. package/es6/src/auth/ability.js +0 -45
  168. package/es6/src/auth/auth.config.js +0 -19
  169. package/es6/src/auth/auth.extensions.js +0 -83
  170. package/es6/src/auth/auth.types.js +0 -35
  171. package/es6/src/auth/casl-authorization.service.js +0 -40
  172. package/es6/src/auth/index.js +0 -6
  173. package/es6/src/auth/principal-provider.js +0 -14
  174. package/es6/src/auth/safe-outbound-url.js +0 -99
  175. package/es6/src/auth/token-service.js +0 -141
  176. package/es6/src/builder/builder.js +0 -85
  177. package/es6/src/builder/index.js +0 -1
  178. package/es6/src/health/health.controller.js +0 -65
  179. package/es6/src/health/health.extensions.js +0 -40
  180. package/es6/src/health/index.js +0 -4
  181. package/es6/src/health/readiness.service.js +0 -57
  182. package/es6/src/health/readiness.types.js +0 -4
  183. package/es6/src/hosting/hosted-service-host.js +0 -81
  184. package/es6/src/hosting/hosted-service.js +0 -8
  185. package/es6/src/hosting/index.js +0 -2
  186. package/es6/src/http/http.compression.js +0 -9
  187. package/es6/src/http/http.extensions.js +0 -259
  188. package/es6/src/http/http.options.js +0 -16
  189. package/es6/src/http/http.options.store.js +0 -13
  190. package/es6/src/http/http.security.js +0 -9
  191. package/es6/src/http/http.static.js +0 -224
  192. package/es6/src/http/index.js +0 -5
  193. package/es6/src/openapi/index.js +0 -3
  194. package/es6/src/openapi/openapi.generator.js +0 -82
  195. package/es6/src/openapi/openapi.types.js +0 -1
  196. package/es6/src/openapi/request-schema.js +0 -160
  197. package/es6/src/openapi/request-validator.js +0 -71
  198. package/es6/src/providers/fastify.provider.js +0 -376
  199. package/es6/src/providers/index.js +0 -1
  200. package/es6/src/routing/anvil.types.js +0 -57
  201. package/es6/src/routing/decorators/argument.decorator.js +0 -28
  202. package/es6/src/routing/decorators/auth.decorator.js +0 -58
  203. package/es6/src/routing/decorators/controller.decorator.js +0 -6
  204. package/es6/src/routing/decorators/field.decorator.js +0 -15
  205. package/es6/src/routing/decorators/index.js +0 -7
  206. package/es6/src/routing/decorators/request.decorator.js +0 -24
  207. package/es6/src/routing/decorators/response.decorator.js +0 -16
  208. package/es6/src/routing/decorators/route.decorator.js +0 -37
  209. package/es6/src/routing/filters/exception-filter-host.js +0 -127
  210. package/es6/src/routing/filters/exception-filter.js +0 -10
  211. package/es6/src/routing/index.js +0 -8
  212. package/es6/src/routing/middleware/http-access-log.middleware.js +0 -37
  213. package/es6/src/routing/middleware/middleware.js +0 -10
  214. package/es6/src/routing/middleware/request-id.js +0 -14
  215. package/es6/src/routing/path.util.js +0 -33
  216. package/es6/src/routing/pipes/index.js +0 -1
  217. package/es6/src/routing/pipes/pipes.js +0 -118
  218. package/es6/src/routing/services/index.js +0 -1
  219. package/es6/src/routing/services/route-argument-resolver.js +0 -67
  220. package/es6/src/routing/services/route-registry.js +0 -184
  221. package/es6/src/routing/services/router.js +0 -148
  222. package/es6/src/sse/index.js +0 -2
  223. package/es6/src/sse/sse.decorator.js +0 -31
  224. package/es6/src/sse/sse.encoder.js +0 -67
  225. package/es6/src/sse/sse.types.js +0 -22
  226. package/es6/src/sse/sse.wire.js +0 -30
  227. package/es6/src/testing/boot-module.js +0 -35
  228. package/es6/src/testing/index.js +0 -2
  229. package/es6/src/testing/sse-reader.js +0 -91
  230. package/types/src/app/app.d.ts +0 -41
  231. package/types/src/app/module.d.ts +0 -15
  232. package/types/src/auth/ability.d.ts +0 -19
  233. package/types/src/auth/auth.config.d.ts +0 -28
  234. package/types/src/auth/auth.extensions.d.ts +0 -53
  235. package/types/src/auth/auth.types.d.ts +0 -73
  236. package/types/src/auth/casl-authorization.service.d.ts +0 -28
  237. package/types/src/auth/safe-outbound-url.d.ts +0 -9
  238. package/types/src/auth/token-service.d.ts +0 -31
  239. package/types/src/builder/builder.d.ts +0 -36
  240. package/types/src/const.d.ts +0 -32
  241. package/types/src/health/health.controller.d.ts +0 -16
  242. package/types/src/health/health.extensions.d.ts +0 -31
  243. package/types/src/health/readiness.service.d.ts +0 -9
  244. package/types/src/hosting/hosted-service-host.d.ts +0 -37
  245. package/types/src/hosting/hosted-service.d.ts +0 -31
  246. package/types/src/http/http.compression.d.ts +0 -32
  247. package/types/src/http/http.extensions.d.ts +0 -79
  248. package/types/src/http/http.options.d.ts +0 -39
  249. package/types/src/http/http.static.d.ts +0 -160
  250. package/types/src/index.d.ts +0 -10
  251. package/types/src/openapi/index.d.ts +0 -6
  252. package/types/src/openapi/openapi.generator.d.ts +0 -6
  253. package/types/src/openapi/openapi.types.d.ts +0 -58
  254. package/types/src/openapi/request-schema.d.ts +0 -21
  255. package/types/src/openapi/request-validator.d.ts +0 -9
  256. package/types/src/providers/fastify.provider.d.ts +0 -56
  257. package/types/src/routing/anvil.types.d.ts +0 -119
  258. package/types/src/routing/decorators/argument.decorator.d.ts +0 -11
  259. package/types/src/routing/decorators/auth.decorator.d.ts +0 -30
  260. package/types/src/routing/decorators/controller.decorator.d.ts +0 -3
  261. package/types/src/routing/decorators/field.decorator.d.ts +0 -2
  262. package/types/src/routing/decorators/request.decorator.d.ts +0 -8
  263. package/types/src/routing/decorators/response.decorator.d.ts +0 -4
  264. package/types/src/routing/decorators/route.decorator.d.ts +0 -7
  265. package/types/src/routing/filters/exception-filter-host.d.ts +0 -19
  266. package/types/src/routing/filters/exception-filter.d.ts +0 -16
  267. package/types/src/routing/middleware/http-access-log.middleware.d.ts +0 -8
  268. package/types/src/routing/middleware/middleware.d.ts +0 -10
  269. package/types/src/routing/middleware/request-id.d.ts +0 -6
  270. package/types/src/routing/path.util.d.ts +0 -9
  271. package/types/src/routing/pipes/pipes.d.ts +0 -21
  272. package/types/src/routing/services/route-argument-resolver.d.ts +0 -10
  273. package/types/src/routing/services/route-registry.d.ts +0 -20
  274. package/types/src/routing/services/router.d.ts +0 -22
  275. package/types/src/sse/sse.decorator.d.ts +0 -17
  276. package/types/src/sse/sse.encoder.d.ts +0 -16
  277. package/types/src/sse/sse.types.d.ts +0 -37
  278. package/types/src/sse/sse.wire.d.ts +0 -9
  279. package/types/src/testing/boot-module.d.ts +0 -34
  280. package/types/src/testing/sse-reader.d.ts +0 -29
  281. /package/{types/src/app/index.d.ts → src/app/index.ts} +0 -0
  282. /package/{types/src/auth/index.d.ts → src/auth/index.ts} +0 -0
  283. /package/{types/src/builder/index.d.ts → src/builder/index.ts} +0 -0
  284. /package/{types/src/health/index.d.ts → src/health/index.ts} +0 -0
  285. /package/{types/src/hosting/index.d.ts → src/hosting/index.ts} +0 -0
  286. /package/{types/src/http/index.d.ts → src/http/index.ts} +0 -0
  287. /package/{types/src/providers/index.d.ts → src/providers/index.ts} +0 -0
  288. /package/{types/src/routing/decorators/index.d.ts → src/routing/decorators/index.ts} +0 -0
  289. /package/{types/src/routing/index.d.ts → src/routing/index.ts} +0 -0
  290. /package/{types/src/routing/pipes/index.d.ts → src/routing/pipes/index.ts} +0 -0
  291. /package/{types/src/routing/services/index.d.ts → src/routing/services/index.ts} +0 -0
  292. /package/{types/src/sse/index.d.ts → src/sse/index.ts} +0 -0
  293. /package/{types/src/testing/index.d.ts → src/testing/index.ts} +0 -0
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- _export_star(require("./argument.decorator.js"), exports);
6
- _export_star(require("./auth.decorator.js"), exports);
7
- _export_star(require("./controller.decorator.js"), exports);
8
- _export_star(require("./field.decorator.js"), exports);
9
- _export_star(require("./request.decorator.js"), exports);
10
- _export_star(require("./response.decorator.js"), exports);
11
- _export_star(require("./route.decorator.js"), exports);
12
- function _export_star(from, to) {
13
- Object.keys(from).forEach(function(k) {
14
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
15
- Object.defineProperty(to, k, {
16
- enumerable: true,
17
- get: function() {
18
- return from[k];
19
- }
20
- });
21
- }
22
- });
23
- return from;
24
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "Request", {
6
- enumerable: true,
7
- get: function() {
8
- return Request;
9
- }
10
- });
11
- const _reflection = require("@decohere/core/reflection");
12
- const _const = require("../../const.js");
13
- function Request(mappingKey) {
14
- return (target)=>{
15
- const inst = new target();
16
- const fieldMap = (0, _reflection.getMeta)(_const.MetadataKeys.fieldMap, target.prototype) ?? new Map();
17
- const fields = (0, _reflection.getFields)(inst);
18
- for (const field of fields){
19
- const fieldType = (0, _reflection.getFieldType)(target.prototype, field.key);
20
- const overrides = fieldMap.get(field.key);
21
- fieldMap.set(field.key, {
22
- fieldKey: field.key,
23
- mappingKey: overrides?.mappingKey ?? field.key,
24
- fieldType: overrides?.fieldType ?? fieldType,
25
- fieldLocation: overrides?.fieldLocation ?? mappingKey
26
- });
27
- }
28
- (0, _reflection.defineMeta)(_const.MetadataKeys.fieldMap, fieldMap, target.prototype);
29
- };
30
- }
@@ -1,34 +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 Header () {
13
- return Header;
14
- },
15
- get HttpCode () {
16
- return HttpCode;
17
- }
18
- });
19
- const _reflection = require("@decohere/core/reflection");
20
- const _const = require("../../const.js");
21
- function HttpCode(statusCode) {
22
- return (_target, _methodName, descriptor)=>{
23
- (0, _reflection.defineMeta)(_const.MetadataKeys.httpCode, statusCode, descriptor.value);
24
- };
25
- }
26
- function Header(name, value) {
27
- return (_target, _methodName, descriptor)=>{
28
- const existing = (0, _reflection.getMeta)(_const.MetadataKeys.headers, descriptor.value) ?? {};
29
- (0, _reflection.defineMeta)(_const.MetadataKeys.headers, {
30
- ...existing,
31
- [name]: value
32
- }, descriptor.value);
33
- };
34
- }
@@ -1,67 +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 Delete () {
13
- return Delete;
14
- },
15
- get Get () {
16
- return Get;
17
- },
18
- get Patch () {
19
- return Patch;
20
- },
21
- get Post () {
22
- return Post;
23
- },
24
- get Put () {
25
- return Put;
26
- },
27
- get Route () {
28
- return Route;
29
- }
30
- });
31
- const _reflection = require("@decohere/core/reflection");
32
- const _const = require("../../const.js");
33
- const _anviltypes = require("../anvil.types.js");
34
- function Get(path) {
35
- return routeDecorator(_const.HTTPMethods.GET, path);
36
- }
37
- function Post(path) {
38
- return routeDecorator(_const.HTTPMethods.POST, path);
39
- }
40
- function Put(path) {
41
- return routeDecorator(_const.HTTPMethods.PUT, path);
42
- }
43
- function Patch(path) {
44
- return routeDecorator(_const.HTTPMethods.PATCH, path);
45
- }
46
- function Delete(path) {
47
- return routeDecorator(_const.HTTPMethods.DELETE, path);
48
- }
49
- function Route(method, path) {
50
- return routeDecorator(method, path);
51
- }
52
- /**
53
- * Store method + relative path only. Controller / global prefixes are applied
54
- * at registration time in RouteRegistry (avoids TS decorator-order issues).
55
- */ function routeDecorator(method, path = "") {
56
- return (targetClass, functionName, descriptor)=>{
57
- if (path !== "" && !path.startsWith("/")) {
58
- throw new _anviltypes.RouteConfigurationError(`Error configuring routes. Path defined in controller ${targetClass.constructor.name}.${functionName}() should start '/'`);
59
- }
60
- const { value: handler } = descriptor;
61
- const routeConfig = {
62
- method,
63
- path
64
- };
65
- (0, _reflection.defineMeta)(_const.MetadataKeys.route, routeConfig, handler);
66
- };
67
- }
@@ -1,145 +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 DefaultHttpExceptionFilter () {
13
- return DefaultHttpExceptionFilter;
14
- },
15
- get ExceptionFilterHost () {
16
- return ExceptionFilterHost;
17
- }
18
- });
19
- const _crucible = require("@decohere/crucible");
20
- const _decorators = require("@decohere/crucible/decorators");
21
- const _scribe = require("@decohere/scribe");
22
- const _const = require("../../const.js");
23
- const _anviltypes = require("../anvil.types.js");
24
- const _exceptionfilter = require("./exception-filter.js");
25
- function _ts_decorate(decorators, target, key, desc) {
26
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
27
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
28
- 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;
29
- return c > 3 && r && Object.defineProperty(target, key, r), r;
30
- }
31
- function _ts_metadata(k, v) {
32
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
- }
34
- function _ts_param(paramIndex, decorator) {
35
- return function(target, key) {
36
- decorator(target, key, paramIndex);
37
- };
38
- }
39
- class DefaultHttpExceptionFilter {
40
- logger = _scribe.scribe.logger(DefaultHttpExceptionFilter.name);
41
- catch(error, _ctx) {
42
- if (error instanceof _anviltypes.ValidationError) {
43
- return {
44
- status: 400,
45
- body: {
46
- statusCode: 400,
47
- error: "Bad Request",
48
- message: error.message,
49
- errors: error.errors
50
- }
51
- };
52
- }
53
- if (error instanceof _anviltypes.HttpError) {
54
- // Never expose internal auth failure details (header shape, issuer, etc.) to clients.
55
- if (error.status === 401) {
56
- this.logger.warn(error.message);
57
- return {
58
- status: 401,
59
- body: {
60
- message: "Unauthorized"
61
- }
62
- };
63
- }
64
- // Sanitize only true 500s. Keep intentional 503 probe messages (e.g. /ready).
65
- if (error.status === 500) {
66
- this.logger.error(error.message);
67
- return {
68
- status: 500,
69
- body: {
70
- message: "Internal Server Error"
71
- }
72
- };
73
- }
74
- return {
75
- status: error.status,
76
- body: {
77
- message: error.message
78
- }
79
- };
80
- }
81
- if (error instanceof Error) {
82
- this.logger.error(error.message, error.stack);
83
- return {
84
- status: 500,
85
- body: {
86
- message: "Internal Server Error"
87
- }
88
- };
89
- }
90
- return {
91
- status: 500,
92
- body: {
93
- message: "Internal Server Error"
94
- }
95
- };
96
- }
97
- }
98
- DefaultHttpExceptionFilter = _ts_decorate([
99
- (0, _decorators.injectable)()
100
- ], DefaultHttpExceptionFilter);
101
- class ExceptionFilterHost {
102
- options;
103
- scope;
104
- filters;
105
- constructor(options, scope){
106
- this.options = options;
107
- this.scope = scope;
108
- }
109
- async handle(error, ctx) {
110
- for (const filter of this.getFilters()){
111
- const filterType = filter.constructor;
112
- const types = (0, _exceptionfilter.getCatchTypes)(filterType);
113
- if (types.length === 0 || types.some((t)=>error instanceof t)) {
114
- return await filter.catch(error, ctx);
115
- }
116
- }
117
- return new DefaultHttpExceptionFilter().catch(error, ctx);
118
- }
119
- getFilters() {
120
- if (this.filters != null) {
121
- return this.filters;
122
- }
123
- const custom = this.options?.filterTypes.map((type)=>{
124
- if (this.scope == null) {
125
- return new type();
126
- }
127
- return this.scope.resolve(type);
128
- }) ?? [];
129
- this.filters = [
130
- ...custom,
131
- new DefaultHttpExceptionFilter()
132
- ];
133
- return this.filters;
134
- }
135
- }
136
- ExceptionFilterHost = _ts_decorate([
137
- (0, _decorators.injectable)(),
138
- _ts_param(0, (0, _decorators.inject)(_const.HttpOptionsToken)),
139
- _ts_param(1, (0, _decorators.inject)(_crucible.LifetimeScopeToken)),
140
- _ts_metadata("design:type", Function),
141
- _ts_metadata("design:paramtypes", [
142
- typeof HttpOptions === "undefined" ? Object : HttpOptions,
143
- typeof LifetimeScope === "undefined" ? Object : LifetimeScope
144
- ])
145
- ], ExceptionFilterHost);
@@ -1,28 +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 Catch () {
13
- return Catch;
14
- },
15
- get getCatchTypes () {
16
- return getCatchTypes;
17
- }
18
- });
19
- const _reflection = require("@decohere/core/reflection");
20
- const _const = require("../../const.js");
21
- function Catch(...types) {
22
- return (target)=>{
23
- (0, _reflection.defineMeta)(_const.MetadataKeys.catch, types, target);
24
- };
25
- }
26
- function getCatchTypes(filterType) {
27
- return (0, _reflection.getMeta)(_const.MetadataKeys.catch, filterType) ?? [];
28
- }
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- _export_star(require("./anvil.types.js"), exports);
6
- _export_star(require("./decorators/index.js"), exports);
7
- _export_star(require("./filters/exception-filter.js"), exports);
8
- _export_star(require("./filters/exception-filter-host.js"), exports);
9
- _export_star(require("./middleware/http-access-log.middleware.js"), exports);
10
- _export_star(require("./middleware/middleware.js"), exports);
11
- _export_star(require("./middleware/request-id.js"), exports);
12
- _export_star(require("./pipes/index.js"), exports);
13
- function _export_star(from, to) {
14
- Object.keys(from).forEach(function(k) {
15
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
16
- Object.defineProperty(to, k, {
17
- enumerable: true,
18
- get: function() {
19
- return from[k];
20
- }
21
- });
22
- }
23
- });
24
- return from;
25
- }
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "HttpAccessLogMiddleware", {
6
- enumerable: true,
7
- get: function() {
8
- return HttpAccessLogMiddleware;
9
- }
10
- });
11
- const _decorators = require("@decohere/crucible/decorators");
12
- const _scribe = require("@decohere/scribe");
13
- const _anviltypes = require("../anvil.types.js");
14
- const _requestid = require("./request-id.js");
15
- function _ts_decorate(decorators, target, key, desc) {
16
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
17
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
18
- 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;
19
- return c > 3 && r && Object.defineProperty(target, key, r), r;
20
- }
21
- class HttpAccessLogMiddleware {
22
- async use(ctx, next) {
23
- const logger = _scribe.scribe.logger(HttpAccessLogMiddleware.name);
24
- const start = performance.now();
25
- ctx.request.responseHeaders[_requestid.REQUEST_ID_HEADER] = ctx.request.requestId;
26
- let status = ctx.route.httpCode ?? 200;
27
- try {
28
- return await next();
29
- } catch (error) {
30
- status = error instanceof _anviltypes.HttpError ? error.status : 500;
31
- throw error;
32
- } finally{
33
- const durationMs = Math.round(performance.now() - start);
34
- logger.info({
35
- msg: "access",
36
- method: ctx.request.method,
37
- path: ctx.request.url,
38
- status,
39
- durationMs,
40
- requestId: ctx.request.requestId
41
- });
42
- }
43
- }
44
- }
45
- HttpAccessLogMiddleware = _ts_decorate([
46
- (0, _decorators.injectable)()
47
- ], HttpAccessLogMiddleware);
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "composeMiddleware", {
6
- enumerable: true,
7
- get: function() {
8
- return composeMiddleware;
9
- }
10
- });
11
- function composeMiddleware(middlewares, handler, ctx) {
12
- const dispatch = (index)=>{
13
- if (index >= middlewares.length) {
14
- return handler();
15
- }
16
- const middleware = middlewares[index];
17
- return middleware.use(ctx, ()=>dispatch(index + 1));
18
- };
19
- return dispatch(0);
20
- }
@@ -1,30 +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 REQUEST_ID_HEADER () {
13
- return REQUEST_ID_HEADER;
14
- },
15
- get resolveRequestId () {
16
- return resolveRequestId;
17
- }
18
- });
19
- const _nodecrypto = require("node:crypto");
20
- const REQUEST_ID_HEADER = "x-request-id";
21
- function resolveRequestId(headers, fallback) {
22
- const fromHeader = headers[REQUEST_ID_HEADER]?.trim();
23
- if (fromHeader) {
24
- return fromHeader;
25
- }
26
- if (fallback?.trim()) {
27
- return fallback.trim();
28
- }
29
- return (0, _nodecrypto.randomUUID)();
30
- }
@@ -1,51 +0,0 @@
1
- /** Normalize a prefix to `/foo` form with no trailing slash. Empty → `""`. */ "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 applyGlobalPrefix () {
13
- return applyGlobalPrefix;
14
- },
15
- get joinRoutePath () {
16
- return joinRoutePath;
17
- },
18
- get normalizePrefix () {
19
- return normalizePrefix;
20
- }
21
- });
22
- function normalizePrefix(prefix) {
23
- if (prefix == null || prefix === "" || prefix === "/") {
24
- return "";
25
- }
26
- const withSlash = prefix.startsWith("/") ? prefix : `/${prefix}`;
27
- return withSlash.replace(/\/+$/, "");
28
- }
29
- function joinRoutePath(prefix, routePath) {
30
- const p = normalizePrefix(prefix);
31
- if (routePath === "" || routePath == null) {
32
- return p === "" ? "/" : p;
33
- }
34
- if (routePath === "/") {
35
- return p === "" ? "/" : `${p}/`;
36
- }
37
- if (!routePath.startsWith("/")) {
38
- throw new Error(`Route path must start with '/': ${routePath}`);
39
- }
40
- return `${p}${routePath}`;
41
- }
42
- function applyGlobalPrefix(globalPrefix, path) {
43
- const g = normalizePrefix(globalPrefix);
44
- if (g === "") {
45
- return path === "" ? "/" : path;
46
- }
47
- if (path === "/") {
48
- return `${g}/`;
49
- }
50
- return `${g}${path.startsWith("/") ? path : `/${path}`}`;
51
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- _export_star(require("./pipes.js"), exports);
6
- function _export_star(from, to) {
7
- Object.keys(from).forEach(function(k) {
8
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
- Object.defineProperty(to, k, {
10
- enumerable: true,
11
- get: function() {
12
- return from[k];
13
- }
14
- });
15
- }
16
- });
17
- return from;
18
- }
@@ -1,145 +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 BooleanPipe () {
13
- return BooleanPipe;
14
- },
15
- get DatePipe () {
16
- return DatePipe;
17
- },
18
- get JsonPipe () {
19
- return JsonPipe;
20
- },
21
- get NumberPipe () {
22
- return NumberPipe;
23
- },
24
- get Pipe () {
25
- return Pipe;
26
- }
27
- });
28
- const _reflection = require("@decohere/core/reflection");
29
- const _anviltypes = require("../anvil.types.js");
30
- const invalidBooleanIssue = {
31
- path: "/value",
32
- message: "Invalid boolean",
33
- keyword: "type"
34
- };
35
- const invalidNumberIssue = {
36
- path: "/value",
37
- message: "Invalid number",
38
- keyword: "type"
39
- };
40
- const invalidDateIssue = {
41
- path: "/value",
42
- message: "Invalid date",
43
- keyword: "format"
44
- };
45
- class Pipe {
46
- }
47
- class BooleanPipe extends Pipe {
48
- transform(value, _context) {
49
- if (typeof value === "boolean") {
50
- return value;
51
- }
52
- const normalized = typeof value === "string" ? value.trim().toLowerCase() : value;
53
- switch(normalized){
54
- case "true":
55
- case "1":
56
- case 1:
57
- return true;
58
- case "false":
59
- case "0":
60
- case 0:
61
- return false;
62
- default:
63
- throw new _anviltypes.ValidationError("Validation failed", [
64
- invalidBooleanIssue
65
- ]);
66
- }
67
- }
68
- }
69
- class DatePipe extends Pipe {
70
- transform(value, _context) {
71
- if (value instanceof Date) {
72
- if (Number.isNaN(value.getTime())) {
73
- throw new _anviltypes.ValidationError("Validation failed", [
74
- invalidDateIssue
75
- ]);
76
- }
77
- return value;
78
- }
79
- if (typeof value === "string") {
80
- const trimmed = value.trim();
81
- if (trimmed === "") {
82
- throw new _anviltypes.ValidationError("Validation failed", [
83
- invalidDateIssue
84
- ]);
85
- }
86
- if (/^-?\d+(\.\d+)?$/.test(trimmed)) {
87
- return new Date(Number(trimmed));
88
- }
89
- const parsed = new Date(trimmed);
90
- if (Number.isNaN(parsed.getTime())) {
91
- throw new _anviltypes.ValidationError("Validation failed", [
92
- invalidDateIssue
93
- ]);
94
- }
95
- return parsed;
96
- }
97
- if (typeof value === "number" && !Number.isNaN(value)) {
98
- return new Date(value);
99
- }
100
- throw new _anviltypes.ValidationError("Validation failed", [
101
- invalidDateIssue
102
- ]);
103
- }
104
- }
105
- class JsonPipe extends Pipe {
106
- transform(value, context) {
107
- try {
108
- const obj = JSON.parse(value, (fieldKey, fieldValue)=>{
109
- const val = this.reviver(context?.fieldTypes, fieldKey, fieldValue);
110
- return val;
111
- });
112
- return obj;
113
- } catch (err) {
114
- throw new _anviltypes.TransformError(`Error parsing json ${err}`);
115
- }
116
- }
117
- reviver(fieldTypes, fieldKey, value) {
118
- if (!fieldKey) {
119
- return value;
120
- }
121
- if (!fieldTypes) {
122
- return value;
123
- }
124
- const fieldType = fieldTypes[fieldKey];
125
- if (fieldType == null) {
126
- return value;
127
- }
128
- if (!(0, _reflection.isDateType)(fieldType)) {
129
- return value;
130
- }
131
- return new Date(value.toString());
132
- }
133
- }
134
- class NumberPipe extends Pipe {
135
- /** Finite numbers only. Blank or non-numeric input is a 400, not `undefined`. */ transform(value, _context) {
136
- const text = typeof value === "number" ? null : String(value).trim();
137
- const number = text == null ? value : text === "" ? Number.NaN : Number(text);
138
- if (!Number.isFinite(number)) {
139
- throw new _anviltypes.ValidationError("Validation failed", [
140
- invalidNumberIssue
141
- ]);
142
- }
143
- return number;
144
- }
145
- }