@contember/engine-http 2.2.0-alpha.2 → 2.2.0-alpha.20

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 (716) hide show
  1. package/CLAUDE.md +5 -1
  2. package/dist/development/index.cjs +40 -0
  3. package/dist/development/index.cjs.map +1 -1
  4. package/dist/development/index.js +41 -4
  5. package/dist/development/index.js.map +1 -1
  6. package/dist/development/src/MasterContainer.cjs +76 -35
  7. package/dist/development/src/MasterContainer.cjs.map +1 -1
  8. package/dist/development/src/MasterContainer.js +76 -35
  9. package/dist/development/src/MasterContainer.js.map +1 -1
  10. package/dist/development/src/application/PanelApiMount.cjs +8 -0
  11. package/dist/development/src/application/PanelApiMount.cjs.map +1 -0
  12. package/dist/development/src/application/PanelApiMount.js +8 -0
  13. package/dist/development/src/application/PanelApiMount.js.map +1 -0
  14. package/dist/development/src/application/application.cjs +320 -86
  15. package/dist/development/src/application/application.cjs.map +1 -1
  16. package/dist/development/src/application/application.js +322 -88
  17. package/dist/development/src/application/application.js.map +1 -1
  18. package/dist/development/src/application/compression.cjs +99 -0
  19. package/dist/development/src/application/compression.cjs.map +1 -0
  20. package/dist/development/src/application/compression.js +82 -0
  21. package/dist/development/src/application/compression.js.map +1 -0
  22. package/dist/development/src/application/cors.cjs +52 -0
  23. package/dist/development/src/application/cors.cjs.map +1 -0
  24. package/dist/development/src/application/cors.js +52 -0
  25. package/dist/development/src/application/cors.js.map +1 -0
  26. package/dist/development/src/application/forceHttpOk.cjs +2 -9
  27. package/dist/development/src/application/forceHttpOk.cjs.map +1 -1
  28. package/dist/development/src/application/forceHttpOk.js +2 -9
  29. package/dist/development/src/application/forceHttpOk.js.map +1 -1
  30. package/dist/development/src/application/requestBody.cjs +242 -0
  31. package/dist/development/src/application/requestBody.cjs.map +1 -0
  32. package/dist/development/src/application/requestBody.js +242 -0
  33. package/dist/development/src/application/requestBody.js.map +1 -0
  34. package/dist/development/src/application/requestBodyMasking.cjs +97 -0
  35. package/dist/development/src/application/requestBodyMasking.cjs.map +1 -0
  36. package/dist/development/src/application/requestBodyMasking.js +97 -0
  37. package/dist/development/src/application/requestBodyMasking.js.map +1 -0
  38. package/dist/development/src/common/Authorizator.cjs +22 -19
  39. package/dist/development/src/common/Authorizator.cjs.map +1 -1
  40. package/dist/development/src/common/Authorizator.js +22 -19
  41. package/dist/development/src/common/Authorizator.js.map +1 -1
  42. package/dist/development/src/common/HttpResponse.cjs +5 -3
  43. package/dist/development/src/common/HttpResponse.cjs.map +1 -1
  44. package/dist/development/src/common/HttpResponse.js +5 -3
  45. package/dist/development/src/common/HttpResponse.js.map +1 -1
  46. package/dist/development/src/config/config.cjs +2 -1
  47. package/dist/development/src/config/config.cjs.map +1 -1
  48. package/dist/development/src/config/config.js +2 -1
  49. package/dist/development/src/config/config.js.map +1 -1
  50. package/dist/development/src/config/configSchema.cjs +180 -1
  51. package/dist/development/src/config/configSchema.cjs.map +1 -1
  52. package/dist/development/src/config/configSchema.js +180 -1
  53. package/dist/development/src/config/configSchema.js.map +1 -1
  54. package/dist/development/src/config/configTemplate.cjs +53 -1
  55. package/dist/development/src/config/configTemplate.cjs.map +1 -1
  56. package/dist/development/src/config/configTemplate.js +53 -1
  57. package/dist/development/src/config/configTemplate.js.map +1 -1
  58. package/dist/development/src/config/projectConfigResolver.cjs +1 -0
  59. package/dist/development/src/config/projectConfigResolver.cjs.map +1 -1
  60. package/dist/development/src/config/projectConfigResolver.js +2 -1
  61. package/dist/development/src/config/projectConfigResolver.js.map +1 -1
  62. package/dist/development/src/content/ContentApiControllerFactory.cjs +41 -4
  63. package/dist/development/src/content/ContentApiControllerFactory.cjs.map +1 -1
  64. package/dist/development/src/content/ContentApiControllerFactory.js +41 -4
  65. package/dist/development/src/content/ContentApiControllerFactory.js.map +1 -1
  66. package/dist/development/src/content/ContentApiSpecificCache.cjs +62 -19
  67. package/dist/development/src/content/ContentApiSpecificCache.cjs.map +1 -1
  68. package/dist/development/src/content/ContentApiSpecificCache.js +62 -19
  69. package/dist/development/src/content/ContentApiSpecificCache.js.map +1 -1
  70. package/dist/development/src/content/ContentGraphQLEngine.cjs +17 -0
  71. package/dist/development/src/content/ContentGraphQLEngine.cjs.map +1 -0
  72. package/dist/development/src/content/ContentGraphQLEngine.js +17 -0
  73. package/dist/development/src/content/ContentGraphQLEngine.js.map +1 -0
  74. package/dist/development/src/content/ContentQueryHandlerFactory.cjs +6 -2
  75. package/dist/development/src/content/ContentQueryHandlerFactory.cjs.map +1 -1
  76. package/dist/development/src/content/ContentQueryHandlerFactory.js +7 -3
  77. package/dist/development/src/content/ContentQueryHandlerFactory.js.map +1 -1
  78. package/dist/development/src/content/ContentRequestLog.cjs +97 -0
  79. package/dist/development/src/content/ContentRequestLog.cjs.map +1 -0
  80. package/dist/development/src/content/ContentRequestLog.js +97 -0
  81. package/dist/development/src/content/ContentRequestLog.js.map +1 -0
  82. package/dist/development/src/content/GraphQlSchemaFactory.cjs +145 -46
  83. package/dist/development/src/content/GraphQlSchemaFactory.cjs.map +1 -1
  84. package/dist/development/src/content/GraphQlSchemaFactory.js +146 -47
  85. package/dist/development/src/content/GraphQlSchemaFactory.js.map +1 -1
  86. package/dist/development/src/content/ProjectMembershipResolver.cjs +13 -9
  87. package/dist/development/src/content/ProjectMembershipResolver.cjs.map +1 -1
  88. package/dist/development/src/content/ProjectMembershipResolver.js +13 -9
  89. package/dist/development/src/content/ProjectMembershipResolver.js.map +1 -1
  90. package/dist/development/src/graphql/execution.cjs +39 -17
  91. package/dist/development/src/graphql/execution.cjs.map +1 -1
  92. package/dist/development/src/graphql/execution.js +40 -18
  93. package/dist/development/src/graphql/execution.js.map +1 -1
  94. package/dist/development/src/misc/HomepageMiddlewareFactory.cjs +1 -0
  95. package/dist/development/src/misc/HomepageMiddlewareFactory.cjs.map +1 -1
  96. package/dist/development/src/misc/HomepageMiddlewareFactory.js +1 -0
  97. package/dist/development/src/misc/HomepageMiddlewareFactory.js.map +1 -1
  98. package/dist/development/src/project/ProjectContainer.cjs +16 -9
  99. package/dist/development/src/project/ProjectContainer.cjs.map +1 -1
  100. package/dist/development/src/project/ProjectContainer.js +16 -9
  101. package/dist/development/src/project/ProjectContainer.js.map +1 -1
  102. package/dist/development/src/project/ProjectContainerResolver.cjs +23 -8
  103. package/dist/development/src/project/ProjectContainerResolver.cjs.map +1 -1
  104. package/dist/development/src/project/ProjectContainerResolver.js +23 -8
  105. package/dist/development/src/project/ProjectContainerResolver.js.map +1 -1
  106. package/dist/development/src/project/ProjectContainerStore.cjs +3 -0
  107. package/dist/development/src/project/ProjectContainerStore.cjs.map +1 -1
  108. package/dist/development/src/project/ProjectContainerStore.js +3 -0
  109. package/dist/development/src/project/ProjectContainerStore.js.map +1 -1
  110. package/dist/development/src/project-common/ProjectContextResolver.cjs +1 -0
  111. package/dist/development/src/project-common/ProjectContextResolver.cjs.map +1 -1
  112. package/dist/development/src/project-common/ProjectContextResolver.js +1 -0
  113. package/dist/development/src/project-common/ProjectContextResolver.js.map +1 -1
  114. package/dist/development/src/projectGroup/ProjectGroupContainer.cjs +42 -30
  115. package/dist/development/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
  116. package/dist/development/src/projectGroup/ProjectGroupContainer.js +42 -30
  117. package/dist/development/src/projectGroup/ProjectGroupContainer.js.map +1 -1
  118. package/dist/development/src/projectGroup/ProjectGroupContainerResolver.cjs +1 -3
  119. package/dist/development/src/projectGroup/ProjectGroupContainerResolver.cjs.map +1 -1
  120. package/dist/development/src/projectGroup/ProjectGroupContainerResolver.js +1 -3
  121. package/dist/development/src/projectGroup/ProjectGroupContainerResolver.js.map +1 -1
  122. package/dist/development/src/projectGroup/ProjectGroupResolver.cjs +1 -0
  123. package/dist/development/src/projectGroup/ProjectGroupResolver.cjs.map +1 -1
  124. package/dist/development/src/projectGroup/ProjectGroupResolver.js +1 -0
  125. package/dist/development/src/projectGroup/ProjectGroupResolver.js.map +1 -1
  126. package/dist/development/src/prometheus/dbMetrics.cjs +5 -2
  127. package/dist/development/src/prometheus/dbMetrics.cjs.map +1 -1
  128. package/dist/development/src/prometheus/dbMetrics.js +6 -3
  129. package/dist/development/src/prometheus/dbMetrics.js.map +1 -1
  130. package/dist/development/src/providers.cjs +2 -2
  131. package/dist/development/src/providers.cjs.map +1 -1
  132. package/dist/development/src/providers.js +2 -2
  133. package/dist/development/src/providers.js.map +1 -1
  134. package/dist/development/src/system/ContentQueryExecutor.cjs +23 -6
  135. package/dist/development/src/system/ContentQueryExecutor.cjs.map +1 -1
  136. package/dist/development/src/system/ContentQueryExecutor.js +25 -8
  137. package/dist/development/src/system/ContentQueryExecutor.js.map +1 -1
  138. package/dist/development/src/system/SystemApiMiddlewareFactory.cjs +1 -0
  139. package/dist/development/src/system/SystemApiMiddlewareFactory.cjs.map +1 -1
  140. package/dist/development/src/system/SystemApiMiddlewareFactory.js +1 -0
  141. package/dist/development/src/system/SystemApiMiddlewareFactory.js.map +1 -1
  142. package/dist/development/src/system/SystemGraphQLHandlerFactory.cjs +1 -1
  143. package/dist/development/src/system/SystemGraphQLHandlerFactory.cjs.map +1 -1
  144. package/dist/development/src/system/SystemGraphQLHandlerFactory.js +2 -2
  145. package/dist/development/src/system/SystemGraphQLHandlerFactory.js.map +1 -1
  146. package/dist/development/src/system/migrationLockOptions.cjs +14 -0
  147. package/dist/development/src/system/migrationLockOptions.cjs.map +1 -0
  148. package/dist/development/src/system/migrationLockOptions.js +14 -0
  149. package/dist/development/src/system/migrationLockOptions.js.map +1 -0
  150. package/dist/development/src/telemetry/FilteringSpanProcessor.cjs +15 -0
  151. package/dist/development/src/telemetry/FilteringSpanProcessor.cjs.map +1 -0
  152. package/dist/development/src/telemetry/FilteringSpanProcessor.js +15 -0
  153. package/dist/development/src/telemetry/FilteringSpanProcessor.js.map +1 -0
  154. package/dist/development/src/telemetry/ProjectGroupContainerTelemetryHook.cjs +59 -0
  155. package/dist/development/src/telemetry/ProjectGroupContainerTelemetryHook.cjs.map +1 -0
  156. package/dist/development/src/telemetry/ProjectGroupContainerTelemetryHook.js +59 -0
  157. package/dist/development/src/telemetry/ProjectGroupContainerTelemetryHook.js.map +1 -0
  158. package/dist/development/src/telemetry/TelemetryFactory.cjs +87 -0
  159. package/dist/development/src/telemetry/TelemetryFactory.cjs.map +1 -0
  160. package/dist/development/src/telemetry/TelemetryFactory.js +87 -0
  161. package/dist/development/src/telemetry/TelemetryFactory.js.map +1 -0
  162. package/dist/development/src/telemetry/incomingTrace.cjs +32 -0
  163. package/dist/development/src/telemetry/incomingTrace.cjs.map +1 -0
  164. package/dist/development/src/telemetry/incomingTrace.js +32 -0
  165. package/dist/development/src/telemetry/incomingTrace.js.map +1 -0
  166. package/dist/development/src/telemetry/sqlSpans.cjs +59 -0
  167. package/dist/development/src/telemetry/sqlSpans.cjs.map +1 -0
  168. package/dist/development/src/telemetry/sqlSpans.js +59 -0
  169. package/dist/development/src/telemetry/sqlSpans.js.map +1 -0
  170. package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs +1 -0
  171. package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs.map +1 -1
  172. package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js +1 -0
  173. package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js.map +1 -1
  174. package/dist/development/src/tenant/TenantApiMiddlewareFactory.cjs +13 -14
  175. package/dist/development/src/tenant/TenantApiMiddlewareFactory.cjs.map +1 -1
  176. package/dist/development/src/tenant/TenantApiMiddlewareFactory.js +13 -14
  177. package/dist/development/src/tenant/TenantApiMiddlewareFactory.js.map +1 -1
  178. package/dist/development/src/tenant/TenantGraphQLHandlerFactory.cjs +1 -1
  179. package/dist/development/src/tenant/TenantGraphQLHandlerFactory.cjs.map +1 -1
  180. package/dist/development/src/tenant/TenantGraphQLHandlerFactory.js +2 -2
  181. package/dist/development/src/tenant/TenantGraphQLHandlerFactory.js.map +1 -1
  182. package/dist/development/src/testing/TestTransactions.cjs +21 -11
  183. package/dist/development/src/testing/TestTransactions.cjs.map +1 -1
  184. package/dist/development/src/testing/TestTransactions.js +21 -11
  185. package/dist/development/src/testing/TestTransactions.js.map +1 -1
  186. package/dist/development/src/transfer/ExportApiControllerFactory.cjs +1 -0
  187. package/dist/development/src/transfer/ExportApiControllerFactory.cjs.map +1 -1
  188. package/dist/development/src/transfer/ExportApiControllerFactory.js +1 -0
  189. package/dist/development/src/transfer/ExportApiControllerFactory.js.map +1 -1
  190. package/dist/development/src/transfer/ImportApiMiddlewareFactory.cjs +9 -2
  191. package/dist/development/src/transfer/ImportApiMiddlewareFactory.cjs.map +1 -1
  192. package/dist/development/src/transfer/ImportApiMiddlewareFactory.js +9 -2
  193. package/dist/development/src/transfer/ImportApiMiddlewareFactory.js.map +1 -1
  194. package/dist/development/src/transfer/ImportExecutor.cjs +34 -5
  195. package/dist/development/src/transfer/ImportExecutor.cjs.map +1 -1
  196. package/dist/development/src/transfer/ImportExecutor.js +34 -5
  197. package/dist/development/src/transfer/ImportExecutor.js.map +1 -1
  198. package/dist/development/src/utils/CryptoWrapper.cjs +11 -0
  199. package/dist/development/src/utils/CryptoWrapper.cjs.map +1 -1
  200. package/dist/development/src/utils/CryptoWrapper.js +11 -0
  201. package/dist/development/src/utils/CryptoWrapper.js.map +1 -1
  202. package/dist/development/src/utils/remoteAddress.cjs +9 -1
  203. package/dist/development/src/utils/remoteAddress.cjs.map +1 -1
  204. package/dist/development/src/utils/remoteAddress.js +10 -2
  205. package/dist/development/src/utils/remoteAddress.js.map +1 -1
  206. package/dist/development/src/utils/sentry.cjs +32 -45
  207. package/dist/development/src/utils/sentry.cjs.map +1 -1
  208. package/dist/development/src/utils/sentry.js +32 -28
  209. package/dist/development/src/utils/sentry.js.map +1 -1
  210. package/dist/development/src/utils/serverStartup.cjs +5 -3
  211. package/dist/development/src/utils/serverStartup.cjs.map +1 -1
  212. package/dist/development/src/utils/serverStartup.js +5 -3
  213. package/dist/development/src/utils/serverStartup.js.map +1 -1
  214. package/dist/development/src/utils/serverTermination.cjs +21 -3
  215. package/dist/development/src/utils/serverTermination.cjs.map +1 -1
  216. package/dist/development/src/utils/serverTermination.js +21 -3
  217. package/dist/development/src/utils/serverTermination.js.map +1 -1
  218. package/dist/development/src/utils/truthyHeader.cjs +13 -0
  219. package/dist/development/src/utils/truthyHeader.cjs.map +1 -0
  220. package/dist/development/src/utils/truthyHeader.js +13 -0
  221. package/dist/development/src/utils/truthyHeader.js.map +1 -0
  222. package/dist/production/index.cjs +40 -0
  223. package/dist/production/index.cjs.map +1 -1
  224. package/dist/production/index.js +41 -4
  225. package/dist/production/index.js.map +1 -1
  226. package/dist/production/src/MasterContainer.cjs +76 -35
  227. package/dist/production/src/MasterContainer.cjs.map +1 -1
  228. package/dist/production/src/MasterContainer.js +76 -35
  229. package/dist/production/src/MasterContainer.js.map +1 -1
  230. package/dist/production/src/application/PanelApiMount.cjs +8 -0
  231. package/dist/production/src/application/PanelApiMount.cjs.map +1 -0
  232. package/dist/production/src/application/PanelApiMount.js +8 -0
  233. package/dist/production/src/application/PanelApiMount.js.map +1 -0
  234. package/dist/production/src/application/application.cjs +320 -86
  235. package/dist/production/src/application/application.cjs.map +1 -1
  236. package/dist/production/src/application/application.js +322 -88
  237. package/dist/production/src/application/application.js.map +1 -1
  238. package/dist/production/src/application/compression.cjs +99 -0
  239. package/dist/production/src/application/compression.cjs.map +1 -0
  240. package/dist/production/src/application/compression.js +82 -0
  241. package/dist/production/src/application/compression.js.map +1 -0
  242. package/dist/production/src/application/cors.cjs +52 -0
  243. package/dist/production/src/application/cors.cjs.map +1 -0
  244. package/dist/production/src/application/cors.js +52 -0
  245. package/dist/production/src/application/cors.js.map +1 -0
  246. package/dist/production/src/application/forceHttpOk.cjs +2 -9
  247. package/dist/production/src/application/forceHttpOk.cjs.map +1 -1
  248. package/dist/production/src/application/forceHttpOk.js +2 -9
  249. package/dist/production/src/application/forceHttpOk.js.map +1 -1
  250. package/dist/production/src/application/requestBody.cjs +242 -0
  251. package/dist/production/src/application/requestBody.cjs.map +1 -0
  252. package/dist/production/src/application/requestBody.js +242 -0
  253. package/dist/production/src/application/requestBody.js.map +1 -0
  254. package/dist/production/src/application/requestBodyMasking.cjs +97 -0
  255. package/dist/production/src/application/requestBodyMasking.cjs.map +1 -0
  256. package/dist/production/src/application/requestBodyMasking.js +97 -0
  257. package/dist/production/src/application/requestBodyMasking.js.map +1 -0
  258. package/dist/production/src/common/Authorizator.cjs +22 -19
  259. package/dist/production/src/common/Authorizator.cjs.map +1 -1
  260. package/dist/production/src/common/Authorizator.js +22 -19
  261. package/dist/production/src/common/Authorizator.js.map +1 -1
  262. package/dist/production/src/common/HttpResponse.cjs +5 -3
  263. package/dist/production/src/common/HttpResponse.cjs.map +1 -1
  264. package/dist/production/src/common/HttpResponse.js +5 -3
  265. package/dist/production/src/common/HttpResponse.js.map +1 -1
  266. package/dist/production/src/config/config.cjs +2 -1
  267. package/dist/production/src/config/config.cjs.map +1 -1
  268. package/dist/production/src/config/config.js +2 -1
  269. package/dist/production/src/config/config.js.map +1 -1
  270. package/dist/production/src/config/configSchema.cjs +180 -1
  271. package/dist/production/src/config/configSchema.cjs.map +1 -1
  272. package/dist/production/src/config/configSchema.js +180 -1
  273. package/dist/production/src/config/configSchema.js.map +1 -1
  274. package/dist/production/src/config/configTemplate.cjs +53 -1
  275. package/dist/production/src/config/configTemplate.cjs.map +1 -1
  276. package/dist/production/src/config/configTemplate.js +53 -1
  277. package/dist/production/src/config/configTemplate.js.map +1 -1
  278. package/dist/production/src/config/projectConfigResolver.cjs +1 -0
  279. package/dist/production/src/config/projectConfigResolver.cjs.map +1 -1
  280. package/dist/production/src/config/projectConfigResolver.js +2 -1
  281. package/dist/production/src/config/projectConfigResolver.js.map +1 -1
  282. package/dist/production/src/content/ContentApiControllerFactory.cjs +41 -4
  283. package/dist/production/src/content/ContentApiControllerFactory.cjs.map +1 -1
  284. package/dist/production/src/content/ContentApiControllerFactory.js +41 -4
  285. package/dist/production/src/content/ContentApiControllerFactory.js.map +1 -1
  286. package/dist/production/src/content/ContentApiSpecificCache.cjs +62 -19
  287. package/dist/production/src/content/ContentApiSpecificCache.cjs.map +1 -1
  288. package/dist/production/src/content/ContentApiSpecificCache.js +62 -19
  289. package/dist/production/src/content/ContentApiSpecificCache.js.map +1 -1
  290. package/dist/production/src/content/ContentGraphQLEngine.cjs +17 -0
  291. package/dist/production/src/content/ContentGraphQLEngine.cjs.map +1 -0
  292. package/dist/production/src/content/ContentGraphQLEngine.js +17 -0
  293. package/dist/production/src/content/ContentGraphQLEngine.js.map +1 -0
  294. package/dist/production/src/content/ContentQueryHandlerFactory.cjs +6 -2
  295. package/dist/production/src/content/ContentQueryHandlerFactory.cjs.map +1 -1
  296. package/dist/production/src/content/ContentQueryHandlerFactory.js +7 -3
  297. package/dist/production/src/content/ContentQueryHandlerFactory.js.map +1 -1
  298. package/dist/production/src/content/ContentRequestLog.cjs +97 -0
  299. package/dist/production/src/content/ContentRequestLog.cjs.map +1 -0
  300. package/dist/production/src/content/ContentRequestLog.js +97 -0
  301. package/dist/production/src/content/ContentRequestLog.js.map +1 -0
  302. package/dist/production/src/content/GraphQlSchemaFactory.cjs +145 -46
  303. package/dist/production/src/content/GraphQlSchemaFactory.cjs.map +1 -1
  304. package/dist/production/src/content/GraphQlSchemaFactory.js +146 -47
  305. package/dist/production/src/content/GraphQlSchemaFactory.js.map +1 -1
  306. package/dist/production/src/content/ProjectMembershipResolver.cjs +13 -9
  307. package/dist/production/src/content/ProjectMembershipResolver.cjs.map +1 -1
  308. package/dist/production/src/content/ProjectMembershipResolver.js +13 -9
  309. package/dist/production/src/content/ProjectMembershipResolver.js.map +1 -1
  310. package/dist/production/src/graphql/execution.cjs +39 -17
  311. package/dist/production/src/graphql/execution.cjs.map +1 -1
  312. package/dist/production/src/graphql/execution.js +40 -18
  313. package/dist/production/src/graphql/execution.js.map +1 -1
  314. package/dist/production/src/misc/HomepageMiddlewareFactory.cjs +1 -0
  315. package/dist/production/src/misc/HomepageMiddlewareFactory.cjs.map +1 -1
  316. package/dist/production/src/misc/HomepageMiddlewareFactory.js +1 -0
  317. package/dist/production/src/misc/HomepageMiddlewareFactory.js.map +1 -1
  318. package/dist/production/src/project/ProjectContainer.cjs +16 -9
  319. package/dist/production/src/project/ProjectContainer.cjs.map +1 -1
  320. package/dist/production/src/project/ProjectContainer.js +16 -9
  321. package/dist/production/src/project/ProjectContainer.js.map +1 -1
  322. package/dist/production/src/project/ProjectContainerResolver.cjs +23 -8
  323. package/dist/production/src/project/ProjectContainerResolver.cjs.map +1 -1
  324. package/dist/production/src/project/ProjectContainerResolver.js +23 -8
  325. package/dist/production/src/project/ProjectContainerResolver.js.map +1 -1
  326. package/dist/production/src/project/ProjectContainerStore.cjs +3 -0
  327. package/dist/production/src/project/ProjectContainerStore.cjs.map +1 -1
  328. package/dist/production/src/project/ProjectContainerStore.js +3 -0
  329. package/dist/production/src/project/ProjectContainerStore.js.map +1 -1
  330. package/dist/production/src/project-common/ProjectContextResolver.cjs +1 -0
  331. package/dist/production/src/project-common/ProjectContextResolver.cjs.map +1 -1
  332. package/dist/production/src/project-common/ProjectContextResolver.js +1 -0
  333. package/dist/production/src/project-common/ProjectContextResolver.js.map +1 -1
  334. package/dist/production/src/projectGroup/ProjectGroupContainer.cjs +42 -30
  335. package/dist/production/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
  336. package/dist/production/src/projectGroup/ProjectGroupContainer.js +42 -30
  337. package/dist/production/src/projectGroup/ProjectGroupContainer.js.map +1 -1
  338. package/dist/production/src/projectGroup/ProjectGroupContainerResolver.cjs +1 -3
  339. package/dist/production/src/projectGroup/ProjectGroupContainerResolver.cjs.map +1 -1
  340. package/dist/production/src/projectGroup/ProjectGroupContainerResolver.js +1 -3
  341. package/dist/production/src/projectGroup/ProjectGroupContainerResolver.js.map +1 -1
  342. package/dist/production/src/projectGroup/ProjectGroupResolver.cjs +1 -0
  343. package/dist/production/src/projectGroup/ProjectGroupResolver.cjs.map +1 -1
  344. package/dist/production/src/projectGroup/ProjectGroupResolver.js +1 -0
  345. package/dist/production/src/projectGroup/ProjectGroupResolver.js.map +1 -1
  346. package/dist/production/src/prometheus/dbMetrics.cjs +5 -2
  347. package/dist/production/src/prometheus/dbMetrics.cjs.map +1 -1
  348. package/dist/production/src/prometheus/dbMetrics.js +6 -3
  349. package/dist/production/src/prometheus/dbMetrics.js.map +1 -1
  350. package/dist/production/src/providers.cjs +2 -2
  351. package/dist/production/src/providers.cjs.map +1 -1
  352. package/dist/production/src/providers.js +2 -2
  353. package/dist/production/src/providers.js.map +1 -1
  354. package/dist/production/src/system/ContentQueryExecutor.cjs +23 -6
  355. package/dist/production/src/system/ContentQueryExecutor.cjs.map +1 -1
  356. package/dist/production/src/system/ContentQueryExecutor.js +25 -8
  357. package/dist/production/src/system/ContentQueryExecutor.js.map +1 -1
  358. package/dist/production/src/system/SystemApiMiddlewareFactory.cjs +1 -0
  359. package/dist/production/src/system/SystemApiMiddlewareFactory.cjs.map +1 -1
  360. package/dist/production/src/system/SystemApiMiddlewareFactory.js +1 -0
  361. package/dist/production/src/system/SystemApiMiddlewareFactory.js.map +1 -1
  362. package/dist/production/src/system/SystemGraphQLHandlerFactory.cjs +1 -1
  363. package/dist/production/src/system/SystemGraphQLHandlerFactory.cjs.map +1 -1
  364. package/dist/production/src/system/SystemGraphQLHandlerFactory.js +2 -2
  365. package/dist/production/src/system/SystemGraphQLHandlerFactory.js.map +1 -1
  366. package/dist/production/src/system/migrationLockOptions.cjs +14 -0
  367. package/dist/production/src/system/migrationLockOptions.cjs.map +1 -0
  368. package/dist/production/src/system/migrationLockOptions.js +14 -0
  369. package/dist/production/src/system/migrationLockOptions.js.map +1 -0
  370. package/dist/production/src/telemetry/FilteringSpanProcessor.cjs +15 -0
  371. package/dist/production/src/telemetry/FilteringSpanProcessor.cjs.map +1 -0
  372. package/dist/production/src/telemetry/FilteringSpanProcessor.js +15 -0
  373. package/dist/production/src/telemetry/FilteringSpanProcessor.js.map +1 -0
  374. package/dist/production/src/telemetry/ProjectGroupContainerTelemetryHook.cjs +59 -0
  375. package/dist/production/src/telemetry/ProjectGroupContainerTelemetryHook.cjs.map +1 -0
  376. package/dist/production/src/telemetry/ProjectGroupContainerTelemetryHook.js +59 -0
  377. package/dist/production/src/telemetry/ProjectGroupContainerTelemetryHook.js.map +1 -0
  378. package/dist/production/src/telemetry/TelemetryFactory.cjs +87 -0
  379. package/dist/production/src/telemetry/TelemetryFactory.cjs.map +1 -0
  380. package/dist/production/src/telemetry/TelemetryFactory.js +87 -0
  381. package/dist/production/src/telemetry/TelemetryFactory.js.map +1 -0
  382. package/dist/production/src/telemetry/incomingTrace.cjs +32 -0
  383. package/dist/production/src/telemetry/incomingTrace.cjs.map +1 -0
  384. package/dist/production/src/telemetry/incomingTrace.js +32 -0
  385. package/dist/production/src/telemetry/incomingTrace.js.map +1 -0
  386. package/dist/production/src/telemetry/sqlSpans.cjs +59 -0
  387. package/dist/production/src/telemetry/sqlSpans.cjs.map +1 -0
  388. package/dist/production/src/telemetry/sqlSpans.js +59 -0
  389. package/dist/production/src/telemetry/sqlSpans.js.map +1 -0
  390. package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs +1 -0
  391. package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs.map +1 -1
  392. package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js +1 -0
  393. package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js.map +1 -1
  394. package/dist/production/src/tenant/TenantApiMiddlewareFactory.cjs +13 -14
  395. package/dist/production/src/tenant/TenantApiMiddlewareFactory.cjs.map +1 -1
  396. package/dist/production/src/tenant/TenantApiMiddlewareFactory.js +13 -14
  397. package/dist/production/src/tenant/TenantApiMiddlewareFactory.js.map +1 -1
  398. package/dist/production/src/tenant/TenantGraphQLHandlerFactory.cjs +1 -1
  399. package/dist/production/src/tenant/TenantGraphQLHandlerFactory.cjs.map +1 -1
  400. package/dist/production/src/tenant/TenantGraphQLHandlerFactory.js +2 -2
  401. package/dist/production/src/tenant/TenantGraphQLHandlerFactory.js.map +1 -1
  402. package/dist/production/src/testing/TestTransactions.cjs +21 -11
  403. package/dist/production/src/testing/TestTransactions.cjs.map +1 -1
  404. package/dist/production/src/testing/TestTransactions.js +21 -11
  405. package/dist/production/src/testing/TestTransactions.js.map +1 -1
  406. package/dist/production/src/transfer/ExportApiControllerFactory.cjs +1 -0
  407. package/dist/production/src/transfer/ExportApiControllerFactory.cjs.map +1 -1
  408. package/dist/production/src/transfer/ExportApiControllerFactory.js +1 -0
  409. package/dist/production/src/transfer/ExportApiControllerFactory.js.map +1 -1
  410. package/dist/production/src/transfer/ImportApiMiddlewareFactory.cjs +9 -2
  411. package/dist/production/src/transfer/ImportApiMiddlewareFactory.cjs.map +1 -1
  412. package/dist/production/src/transfer/ImportApiMiddlewareFactory.js +9 -2
  413. package/dist/production/src/transfer/ImportApiMiddlewareFactory.js.map +1 -1
  414. package/dist/production/src/transfer/ImportExecutor.cjs +34 -5
  415. package/dist/production/src/transfer/ImportExecutor.cjs.map +1 -1
  416. package/dist/production/src/transfer/ImportExecutor.js +34 -5
  417. package/dist/production/src/transfer/ImportExecutor.js.map +1 -1
  418. package/dist/production/src/utils/CryptoWrapper.cjs +11 -0
  419. package/dist/production/src/utils/CryptoWrapper.cjs.map +1 -1
  420. package/dist/production/src/utils/CryptoWrapper.js +11 -0
  421. package/dist/production/src/utils/CryptoWrapper.js.map +1 -1
  422. package/dist/production/src/utils/remoteAddress.cjs +9 -1
  423. package/dist/production/src/utils/remoteAddress.cjs.map +1 -1
  424. package/dist/production/src/utils/remoteAddress.js +10 -2
  425. package/dist/production/src/utils/remoteAddress.js.map +1 -1
  426. package/dist/production/src/utils/sentry.cjs +32 -45
  427. package/dist/production/src/utils/sentry.cjs.map +1 -1
  428. package/dist/production/src/utils/sentry.js +32 -28
  429. package/dist/production/src/utils/sentry.js.map +1 -1
  430. package/dist/production/src/utils/serverStartup.cjs +5 -3
  431. package/dist/production/src/utils/serverStartup.cjs.map +1 -1
  432. package/dist/production/src/utils/serverStartup.js +5 -3
  433. package/dist/production/src/utils/serverStartup.js.map +1 -1
  434. package/dist/production/src/utils/serverTermination.cjs +21 -3
  435. package/dist/production/src/utils/serverTermination.cjs.map +1 -1
  436. package/dist/production/src/utils/serverTermination.js +21 -3
  437. package/dist/production/src/utils/serverTermination.js.map +1 -1
  438. package/dist/production/src/utils/truthyHeader.cjs +13 -0
  439. package/dist/production/src/utils/truthyHeader.cjs.map +1 -0
  440. package/dist/production/src/utils/truthyHeader.js +13 -0
  441. package/dist/production/src/utils/truthyHeader.js.map +1 -0
  442. package/dist/tests/cases/integration/requestMemoryBudget.test.d.ts +2 -0
  443. package/dist/tests/cases/integration/requestMemoryBudget.test.d.ts.map +1 -0
  444. package/dist/tests/cases/unit/applicationShutdown.test.d.ts +2 -0
  445. package/dist/tests/cases/unit/applicationShutdown.test.d.ts.map +1 -0
  446. package/dist/tests/cases/unit/compression.test.d.ts +2 -0
  447. package/dist/tests/cases/unit/compression.test.d.ts.map +1 -0
  448. package/dist/tests/cases/unit/contentApiSpecificCacheLimit.test.d.ts +2 -0
  449. package/dist/tests/cases/unit/contentApiSpecificCacheLimit.test.d.ts.map +1 -0
  450. package/dist/tests/cases/unit/contentGraphqlCompat.test.d.ts +2 -0
  451. package/dist/tests/cases/unit/contentGraphqlCompat.test.d.ts.map +1 -0
  452. package/dist/tests/cases/unit/contentRequestLog.test.d.ts +2 -0
  453. package/dist/tests/cases/unit/contentRequestLog.test.d.ts.map +1 -0
  454. package/dist/tests/cases/unit/cors.test.d.ts +2 -0
  455. package/dist/tests/cases/unit/cors.test.d.ts.map +1 -0
  456. package/dist/tests/cases/unit/dbMetrics.test.d.ts +2 -0
  457. package/dist/tests/cases/unit/dbMetrics.test.d.ts.map +1 -0
  458. package/dist/tests/cases/unit/forcePrimary.test.d.ts +2 -0
  459. package/dist/tests/cases/unit/forcePrimary.test.d.ts.map +1 -0
  460. package/dist/tests/cases/unit/graphQlSchemaFactory.test.d.ts +2 -0
  461. package/dist/tests/cases/unit/graphQlSchemaFactory.test.d.ts.map +1 -0
  462. package/dist/tests/cases/unit/importClientAbort.fixture.d.ts +2 -0
  463. package/dist/tests/cases/unit/importClientAbort.fixture.d.ts.map +1 -0
  464. package/dist/tests/cases/unit/importClientAbort.test.d.ts +2 -0
  465. package/dist/tests/cases/unit/importClientAbort.test.d.ts.map +1 -0
  466. package/dist/tests/cases/unit/incomingTrace.test.d.ts +2 -0
  467. package/dist/tests/cases/unit/incomingTrace.test.d.ts.map +1 -0
  468. package/dist/tests/cases/unit/projectContainerResolver.test.d.ts +2 -0
  469. package/dist/tests/cases/unit/projectContainerResolver.test.d.ts.map +1 -0
  470. package/dist/tests/cases/unit/requestBody.test.d.ts +2 -0
  471. package/dist/tests/cases/unit/requestBody.test.d.ts.map +1 -0
  472. package/dist/tests/cases/unit/requestBodyLogging.test.d.ts +2 -0
  473. package/dist/tests/cases/unit/requestBodyLogging.test.d.ts.map +1 -0
  474. package/dist/tests/cases/unit/requestBodyMasking.test.d.ts +2 -0
  475. package/dist/tests/cases/unit/requestBodyMasking.test.d.ts.map +1 -0
  476. package/dist/tests/cases/unit/requestMemoryBudget.test.d.ts +2 -0
  477. package/dist/tests/cases/unit/requestMemoryBudget.test.d.ts.map +1 -0
  478. package/dist/tests/cases/unit/requestTracing.test.d.ts +2 -0
  479. package/dist/tests/cases/unit/requestTracing.test.d.ts.map +1 -0
  480. package/dist/tests/cases/unit/sentryLoggerHandler.test.d.ts +2 -0
  481. package/dist/tests/cases/unit/sentryLoggerHandler.test.d.ts.map +1 -0
  482. package/dist/tests/cases/unit/serverTermination.fixture.d.ts +2 -0
  483. package/dist/tests/cases/unit/serverTermination.fixture.d.ts.map +1 -0
  484. package/dist/tests/cases/unit/serverTermination.test.d.ts +2 -0
  485. package/dist/tests/cases/unit/serverTermination.test.d.ts.map +1 -0
  486. package/dist/tests/cases/unit/spanFiltering.test.d.ts +2 -0
  487. package/dist/tests/cases/unit/spanFiltering.test.d.ts.map +1 -0
  488. package/dist/tests/cases/unit/sqlSpans.test.d.ts +2 -0
  489. package/dist/tests/cases/unit/sqlSpans.test.d.ts.map +1 -0
  490. package/dist/tests/cases/unit/telemetryConfig.test.d.ts +2 -0
  491. package/dist/tests/cases/unit/telemetryConfig.test.d.ts.map +1 -0
  492. package/dist/tests/cases/unit/timerFacade.test.d.ts +2 -0
  493. package/dist/tests/cases/unit/timerFacade.test.d.ts.map +1 -0
  494. package/dist/tests/contentControllerHarness.d.ts +29 -0
  495. package/dist/tests/contentControllerHarness.d.ts.map +1 -0
  496. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  497. package/dist/types/MasterContainer.d.ts +89 -8
  498. package/dist/types/MasterContainer.d.ts.map +1 -1
  499. package/dist/types/application/PanelApiMount.d.ts +31 -0
  500. package/dist/types/application/PanelApiMount.d.ts.map +1 -0
  501. package/dist/types/application/application.d.ts +26 -2
  502. package/dist/types/application/application.d.ts.map +1 -1
  503. package/dist/types/application/compression.d.ts +19 -0
  504. package/dist/types/application/compression.d.ts.map +1 -0
  505. package/dist/types/application/cors.d.ts +10 -0
  506. package/dist/types/application/cors.d.ts.map +1 -0
  507. package/dist/types/application/forceHttpOk.d.ts.map +1 -1
  508. package/dist/types/application/index.d.ts +2 -0
  509. package/dist/types/application/index.d.ts.map +1 -1
  510. package/dist/types/application/requestBody.d.ts +45 -0
  511. package/dist/types/application/requestBody.d.ts.map +1 -0
  512. package/dist/types/application/requestBodyMasking.d.ts +10 -0
  513. package/dist/types/application/requestBodyMasking.d.ts.map +1 -0
  514. package/dist/types/bootstrap/Initializer.d.ts.map +1 -1
  515. package/dist/types/common/Authorizator.d.ts +9 -1
  516. package/dist/types/common/Authorizator.d.ts.map +1 -1
  517. package/dist/types/common/HttpResponse.d.ts +6 -2
  518. package/dist/types/common/HttpResponse.d.ts.map +1 -1
  519. package/dist/types/common/ModuleInfoMiddleware.d.ts.map +1 -1
  520. package/dist/types/common/index.d.ts +2 -0
  521. package/dist/types/common/index.d.ts.map +1 -1
  522. package/dist/types/config/config.d.ts +3 -1
  523. package/dist/types/config/config.d.ts.map +1 -1
  524. package/dist/types/config/configSchema.d.ts +391 -14
  525. package/dist/types/config/configSchema.d.ts.map +1 -1
  526. package/dist/types/config/configTemplate.d.ts.map +1 -1
  527. package/dist/types/config/projectConfigResolver.d.ts +1 -0
  528. package/dist/types/config/projectConfigResolver.d.ts.map +1 -1
  529. package/dist/types/config/tenantConfigResolver.d.ts.map +1 -1
  530. package/dist/types/content/ContentApiControllerFactory.d.ts +6 -1
  531. package/dist/types/content/ContentApiControllerFactory.d.ts.map +1 -1
  532. package/dist/types/content/ContentApiSpecificCache.d.ts +7 -0
  533. package/dist/types/content/ContentApiSpecificCache.d.ts.map +1 -1
  534. package/dist/types/content/ContentGraphQLEngine.d.ts +18 -0
  535. package/dist/types/content/ContentGraphQLEngine.d.ts.map +1 -0
  536. package/dist/types/content/ContentGraphqlContext.d.ts +2 -0
  537. package/dist/types/content/ContentGraphqlContext.d.ts.map +1 -1
  538. package/dist/types/content/ContentQueryHandlerFactory.d.ts +3 -2
  539. package/dist/types/content/ContentQueryHandlerFactory.d.ts.map +1 -1
  540. package/dist/types/content/ContentRequestLog.d.ts +49 -0
  541. package/dist/types/content/ContentRequestLog.d.ts.map +1 -0
  542. package/dist/types/content/ContentSchemaResolver.d.ts.map +1 -1
  543. package/dist/types/content/GraphQLSchemaContributor.d.ts +4 -0
  544. package/dist/types/content/GraphQLSchemaContributor.d.ts.map +1 -1
  545. package/dist/types/content/GraphQlSchemaFactory.d.ts +16 -4
  546. package/dist/types/content/GraphQlSchemaFactory.d.ts.map +1 -1
  547. package/dist/types/content/NotModifiedChecker.d.ts.map +1 -1
  548. package/dist/types/content/ProjectMembershipFetcher.d.ts.map +1 -1
  549. package/dist/types/content/ProjectMembershipResolver.d.ts.map +1 -1
  550. package/dist/types/content/index.d.ts +2 -0
  551. package/dist/types/content/index.d.ts.map +1 -1
  552. package/dist/types/graphql/dbQueriesListener.d.ts.map +1 -1
  553. package/dist/types/graphql/execution.d.ts +24 -3
  554. package/dist/types/graphql/execution.d.ts.map +1 -1
  555. package/dist/types/index.d.ts +2 -0
  556. package/dist/types/index.d.ts.map +1 -1
  557. package/dist/types/project/ProjectContainer.d.ts.map +1 -1
  558. package/dist/types/project/ProjectContainerResolver.d.ts +7 -1
  559. package/dist/types/project/ProjectContainerResolver.d.ts.map +1 -1
  560. package/dist/types/project/ProjectContainerStore.d.ts +1 -0
  561. package/dist/types/project/ProjectContainerStore.d.ts.map +1 -1
  562. package/dist/types/project/ProjectDatabaseMetadataResolver.d.ts.map +1 -1
  563. package/dist/types/project/ProjectInitializer.d.ts.map +1 -1
  564. package/dist/types/project/ProjectSchemaResolver.d.ts.map +1 -1
  565. package/dist/types/project-common/ProjectContextResolver.d.ts.map +1 -1
  566. package/dist/types/projectGroup/ProjectGroupContainer.d.ts.map +1 -1
  567. package/dist/types/projectGroup/ProjectGroupContainerResolver.d.ts.map +1 -1
  568. package/dist/types/projectGroup/ProjectGroupResolver.d.ts.map +1 -1
  569. package/dist/types/prometheus/CollectHttpMetricsMiddelware.d.ts.map +1 -1
  570. package/dist/types/prometheus/CustomMetric.d.ts.map +1 -1
  571. package/dist/types/prometheus/ProjectGroupContainerMetricsHook.d.ts.map +1 -1
  572. package/dist/types/prometheus/PrometheusRegistryFactory.d.ts.map +1 -1
  573. package/dist/types/prometheus/ShowMetricsMiddleware.d.ts.map +1 -1
  574. package/dist/types/prometheus/contemberEngineInfoMetric.d.ts.map +1 -1
  575. package/dist/types/prometheus/dbMetrics.d.ts.map +1 -1
  576. package/dist/types/providers.d.ts.map +1 -1
  577. package/dist/types/system/ContentQueryExecutor.d.ts +4 -1
  578. package/dist/types/system/ContentQueryExecutor.d.ts.map +1 -1
  579. package/dist/types/system/SystemApiMiddlewareFactory.d.ts.map +1 -1
  580. package/dist/types/system/SystemGraphQLContextFactory.d.ts.map +1 -1
  581. package/dist/types/system/SystemGraphQLHandlerFactory.d.ts.map +1 -1
  582. package/dist/types/system/migrationLockOptions.d.ts +4 -0
  583. package/dist/types/system/migrationLockOptions.d.ts.map +1 -0
  584. package/dist/types/telemetry/FilteringSpanProcessor.d.ts +8 -0
  585. package/dist/types/telemetry/FilteringSpanProcessor.d.ts.map +1 -0
  586. package/dist/types/telemetry/ProjectGroupContainerTelemetryHook.d.ts +18 -0
  587. package/dist/types/telemetry/ProjectGroupContainerTelemetryHook.d.ts.map +1 -0
  588. package/dist/types/telemetry/TelemetryFactory.d.ts +19 -0
  589. package/dist/types/telemetry/TelemetryFactory.d.ts.map +1 -0
  590. package/dist/types/telemetry/incomingTrace.d.ts +18 -0
  591. package/dist/types/telemetry/incomingTrace.d.ts.map +1 -0
  592. package/dist/types/telemetry/index.d.ts +6 -0
  593. package/dist/types/telemetry/index.d.ts.map +1 -0
  594. package/dist/types/telemetry/sqlSpans.d.ts +16 -0
  595. package/dist/types/telemetry/sqlSpans.d.ts.map +1 -0
  596. package/dist/types/tenant/OidcBackchannelLogoutMiddlewareFactory.d.ts.map +1 -1
  597. package/dist/types/tenant/TenantApiMiddlewareFactory.d.ts.map +1 -1
  598. package/dist/types/tenant/TenantGraphQLHandlerFactory.d.ts.map +1 -1
  599. package/dist/types/testing/TestTransactions.d.ts.map +1 -1
  600. package/dist/types/transfer/Command.d.ts +5 -5
  601. package/dist/types/transfer/Command.d.ts.map +1 -1
  602. package/dist/types/transfer/ContentSchemaTransferMappingFactory.d.ts.map +1 -1
  603. package/dist/types/transfer/ExportApiControllerFactory.d.ts.map +1 -1
  604. package/dist/types/transfer/ExportExecutor.d.ts.map +1 -1
  605. package/dist/types/transfer/ImportApiMiddlewareFactory.d.ts +3 -0
  606. package/dist/types/transfer/ImportApiMiddlewareFactory.d.ts.map +1 -1
  607. package/dist/types/transfer/ImportExecutor.d.ts +2 -0
  608. package/dist/types/transfer/ImportExecutor.d.ts.map +1 -1
  609. package/dist/types/transfer/SystemSchemaTransferMappingFactory.d.ts.map +1 -1
  610. package/dist/types/tsconfig.tsbuildinfo +1 -1
  611. package/dist/types/utils/CryptoWrapper.d.ts +6 -1
  612. package/dist/types/utils/CryptoWrapper.d.ts.map +1 -1
  613. package/dist/types/utils/memoizeObject.d.ts.map +1 -1
  614. package/dist/types/utils/remoteAddress.d.ts +1 -0
  615. package/dist/types/utils/remoteAddress.d.ts.map +1 -1
  616. package/dist/types/utils/sentry.d.ts +13 -2
  617. package/dist/types/utils/sentry.d.ts.map +1 -1
  618. package/dist/types/utils/serverStartup.d.ts +1 -0
  619. package/dist/types/utils/serverStartup.d.ts.map +1 -1
  620. package/dist/types/utils/serverTermination.d.ts +13 -1
  621. package/dist/types/utils/serverTermination.d.ts.map +1 -1
  622. package/dist/types/utils/strings.d.ts.map +1 -1
  623. package/dist/types/utils/truthyHeader.d.ts +3 -0
  624. package/dist/types/utils/truthyHeader.d.ts.map +1 -0
  625. package/dist/types/workers/ApplicationWorkerManager.d.ts.map +1 -1
  626. package/package.json +21 -23
  627. package/src/MasterContainer.ts +89 -35
  628. package/src/application/PanelApiMount.ts +35 -0
  629. package/src/application/application.ts +347 -89
  630. package/src/application/compression.ts +118 -0
  631. package/src/application/cors.ts +61 -0
  632. package/src/application/forceHttpOk.ts +2 -10
  633. package/src/application/index.ts +2 -0
  634. package/src/application/requestBody.ts +295 -0
  635. package/src/application/requestBodyMasking.ts +117 -0
  636. package/src/common/Authorizator.ts +41 -21
  637. package/src/common/HttpResponse.ts +4 -0
  638. package/src/common/index.ts +2 -0
  639. package/src/config/config.ts +4 -1
  640. package/src/config/configSchema.ts +197 -1
  641. package/src/config/configTemplate.ts +52 -0
  642. package/src/config/projectConfigResolver.ts +1 -1
  643. package/src/content/ContentApiControllerFactory.ts +47 -6
  644. package/src/content/ContentApiSpecificCache.ts +73 -19
  645. package/src/content/ContentGraphQLEngine.ts +24 -0
  646. package/src/content/ContentGraphqlContext.ts +2 -0
  647. package/src/content/ContentQueryHandlerFactory.ts +17 -4
  648. package/src/content/ContentRequestLog.ts +138 -0
  649. package/src/content/GraphQLSchemaContributor.ts +4 -0
  650. package/src/content/GraphQlSchemaFactory.ts +203 -54
  651. package/src/content/ProjectMembershipResolver.ts +18 -11
  652. package/src/content/index.ts +2 -0
  653. package/src/graphql/execution.ts +64 -19
  654. package/src/index.ts +2 -0
  655. package/src/project/ProjectContainer.ts +12 -8
  656. package/src/project/ProjectContainerResolver.ts +27 -9
  657. package/src/project/ProjectContainerStore.ts +4 -0
  658. package/src/projectGroup/ProjectGroupContainer.ts +40 -31
  659. package/src/projectGroup/ProjectGroupContainerResolver.ts +1 -4
  660. package/src/prometheus/dbMetrics.ts +6 -3
  661. package/src/providers.ts +2 -2
  662. package/src/system/ContentQueryExecutor.ts +43 -10
  663. package/src/system/SystemGraphQLHandlerFactory.ts +8 -2
  664. package/src/system/migrationLockOptions.ts +13 -0
  665. package/src/telemetry/FilteringSpanProcessor.ts +22 -0
  666. package/src/telemetry/ProjectGroupContainerTelemetryHook.ts +67 -0
  667. package/src/telemetry/TelemetryFactory.ts +118 -0
  668. package/src/telemetry/incomingTrace.ts +47 -0
  669. package/src/telemetry/index.ts +5 -0
  670. package/src/telemetry/sqlSpans.ts +76 -0
  671. package/src/tenant/TenantApiMiddlewareFactory.ts +14 -14
  672. package/src/tenant/TenantGraphQLHandlerFactory.ts +2 -2
  673. package/src/testing/TestTransactions.ts +21 -11
  674. package/src/transfer/ImportApiMiddlewareFactory.ts +9 -1
  675. package/src/transfer/ImportExecutor.ts +37 -5
  676. package/src/tsconfig.json +5 -1
  677. package/src/utils/CryptoWrapper.ts +12 -0
  678. package/src/utils/remoteAddress.ts +9 -2
  679. package/src/utils/sentry.ts +43 -29
  680. package/src/utils/serverStartup.ts +7 -5
  681. package/src/utils/serverTermination.ts +41 -3
  682. package/src/utils/truthyHeader.ts +12 -0
  683. package/tests/cases/integration/requestMemoryBudget.test.ts +88 -0
  684. package/tests/cases/unit/__snapshots__/contentGraphqlCompat.test.ts.snap +14295 -0
  685. package/tests/cases/unit/applicationShutdown.test.ts +149 -0
  686. package/tests/cases/unit/compression.test.ts +172 -0
  687. package/tests/cases/unit/contentApiSpecificCache.tst.js +22 -0
  688. package/tests/cases/unit/contentApiSpecificCacheLimit.test.ts +63 -0
  689. package/tests/cases/unit/contentGraphqlCompat.test.ts +372 -0
  690. package/tests/cases/unit/contentRequestLog.test.ts +141 -0
  691. package/tests/cases/unit/cors.test.ts +106 -0
  692. package/tests/cases/unit/crypto.test.ts +16 -0
  693. package/tests/cases/unit/dbMetrics.test.ts +40 -0
  694. package/tests/cases/unit/forcePrimary.test.ts +104 -0
  695. package/tests/cases/unit/graphQlSchemaFactory.test.ts +322 -0
  696. package/tests/cases/unit/importClientAbort.fixture.ts +43 -0
  697. package/tests/cases/unit/importClientAbort.test.ts +24 -0
  698. package/tests/cases/unit/incomingTrace.test.ts +100 -0
  699. package/tests/cases/unit/projectContainerResolver.test.ts +150 -0
  700. package/tests/cases/unit/projectMembershipResolver.test.ts +94 -0
  701. package/tests/cases/unit/remoteAddress.test.ts +13 -1
  702. package/tests/cases/unit/requestBody.test.ts +333 -0
  703. package/tests/cases/unit/requestBodyLogging.test.ts +89 -0
  704. package/tests/cases/unit/requestBodyMasking.test.ts +102 -0
  705. package/tests/cases/unit/requestMemoryBudget.test.ts +190 -0
  706. package/tests/cases/unit/requestTracing.test.ts +241 -0
  707. package/tests/cases/unit/sentryLoggerHandler.test.ts +85 -0
  708. package/tests/cases/unit/serverConfig.test.ts +247 -0
  709. package/tests/cases/unit/serverTermination.fixture.ts +13 -0
  710. package/tests/cases/unit/serverTermination.test.ts +97 -0
  711. package/tests/cases/unit/spanFiltering.test.ts +71 -0
  712. package/tests/cases/unit/sqlSpans.test.ts +198 -0
  713. package/tests/cases/unit/telemetryConfig.test.ts +186 -0
  714. package/tests/cases/unit/timerFacade.test.ts +78 -0
  715. package/tests/contentControllerHarness.ts +222 -0
  716. package/tests/tsconfig.json +3 -1
@@ -1 +1 @@
1
- {"version":3,"file":"application.js","sources":["../../../../../packages/engine-http/src/application/application.ts"],"sourcesContent":["import { pathToRegexp } from 'path-to-regexp'\nimport { KoaContext, KoaMiddleware } from './types.js'\nimport { AuthResult, HttpErrorResponse, HttpResponse } from '../common/index.js'\nimport Koa from 'koa'\nimport * as http from 'node:http'\nimport { IncomingMessage, Server, ServerResponse } from 'node:http'\nimport { WebSocket, WebSocketServer } from 'ws'\nimport { FingerCrossedLoggerHandler, Logger } from '@contember/logger'\nimport koaCompress from 'koa-compress'\nimport bodyParser from 'koa-bodyparser'\nimport { ServerConfig } from '../config/config.js'\nimport corsMiddleware from '@koa/cors'\nimport stream, { Duplex, Readable } from 'node:stream'\nimport { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver.js'\nimport { ProjectGroupContainer } from '../projectGroup/ProjectGroupContainer.js'\nimport { URL } from 'node:url'\nimport { cpuUsage, memoryUsage } from 'node:process'\nimport { performance } from 'node:perf_hooks'\nimport { getClientIP } from '../utils/remoteAddress.js'\nimport { isForceHttpOkRequested, shouldForceHttpOk } from './forceHttpOk.js'\n\ntype Route<C> = { match: RequestMatcher; controller: C; module: string }\nexport class Application {\n\tprivate middlewares: KoaMiddleware<any>[] = []\n\n\tprivate routes: Route<HttpController>[] = []\n\tprivate internalRoutes: Route<InternalHttpController>[] = []\n\tprivate websocketRoutes: Route<WebSocketController>[] = []\n\n\tprivate suppressAccessLog: boolean | RegExp\n\tprivate trustedProxies: string[]\n\tprivate forceHttpOkEnabled: boolean\n\n\tconstructor(\n\t\tprivate readonly projectGroupResolver: ProjectGroupResolver,\n\t\tprivate readonly serverConfig: ServerConfig,\n\t\tprivate readonly debugMode: boolean,\n\t\tprivate readonly version: string | undefined,\n\t\tprivate readonly logger: Logger,\n\t) {\n\t\tconst suppressAccessLogRaw = serverConfig.http?.suppressAccessLog\n\t\tthis.suppressAccessLog = suppressAccessLogRaw === true ? true : suppressAccessLogRaw ? new RegExp(suppressAccessLogRaw) : false\n\t\tthis.trustedProxies = serverConfig.http?.trustedProxies ?? []\n\t\tthis.forceHttpOkEnabled = serverConfig.http?.responseStatusHeader ?? true\n\t}\n\n\taddMiddleware(middleware: KoaMiddleware<any>) {\n\t\tthis.middlewares.push(middleware)\n\t}\n\n\tpublic addRoute(module: string, mask: string, controller: HttpController): void {\n\t\tthis.routes.push({\n\t\t\tmodule,\n\t\t\tcontroller,\n\t\t\tmatch: createRequestMatcher(mask),\n\t\t})\n\t}\n\n\tpublic addInternalRoute(module: string, mask: string, controller: InternalHttpController): void {\n\t\tthis.internalRoutes.push({\n\t\t\tmodule,\n\t\t\tcontroller,\n\t\t\tmatch: createRequestMatcher(mask),\n\t\t})\n\t}\n\n\tpublic addWebsocketRoute(module: string, mask: string, controller: WebSocketController): void {\n\t\tthis.websocketRoutes.push({\n\t\t\tmodule,\n\t\t\tcontroller,\n\t\t\tmatch: createRequestMatcher(mask),\n\t\t})\n\t}\n\n\tasync listen(): Promise<RunningApplication> {\n\t\tconst koa = new Koa()\n\t\tconst wss = new WebSocketServer({ noServer: true })\n\t\tfor (const middleware of this.middlewares) {\n\t\t\tkoa.use(middleware)\n\t\t}\n\t\tkoa.use(koaCompress({\n\t\t\tbr: false,\n\t\t}))\n\t\tkoa.use(bodyParser({\n\t\t\tjsonLimit: this.serverConfig.http?.requestBodySize || '1mb',\n\t\t}))\n\t\tkoa.use(corsMiddleware())\n\t\tconst versionMatch = this.version?.match(/^(0\\.\\d+|\\d+)/)\n\t\tconst versionSimplified = versionMatch?.[1] ?? 'unknown'\n\t\tkoa.use(async ctx => {\n\t\t\tctx.response.set('X-Powered-By', `Contember ${versionSimplified}` + (this.debugMode ? '-dev' : ''))\n\t\t\tawait this.handleHttpRequest(ctx)\n\t\t})\n\n\t\tconst server = http.createServer(koa.callback())\n\t\tconst abortController = new AbortController()\n\n\t\tconst wsRequests: (Promise<void>)[] = []\n\t\tserver.on('upgrade', (req, socket, head) => {\n\t\t\twsRequests.push(this.handleWebsocketRequest(wss, abortController.signal, req, socket, head))\n\t\t})\n\t\tawait new Promise<void>(resolve => {\n\t\t\tserver.listen(this.serverConfig.port, () => resolve())\n\t\t})\n\n\t\treturn {\n\t\t\tserver,\n\t\t\tclose: async () => {\n\t\t\t\tabortController.abort()\n\t\t\t\tawait Promise.all(wsRequests)\n\t\t\t\tawait new Promise(resolve => server.close(resolve))\n\t\t\t},\n\t\t}\n\t}\n\n\tprivate async handleWebsocketRequest(\n\t\twss: WebSocketServer,\n\t\tabortSignal: AbortSignal,\n\t\treq: IncomingMessage,\n\t\tsocket: stream.Duplex,\n\t\thead: Buffer,\n\t): Promise<void> {\n\t\tlet webSocketContext: WebSocketContext | null = null\n\t\tlet requestLogger = this.logger\n\t\tconst { timer, send: sendTimer } = this.createTimer()\n\t\tconst clientIp = getClientIP(req, this.trustedProxies)\n\t\ttry {\n\t\t\tconst url = new URL(req.url ?? '/', `http://${req.headers.host}`)\n\t\t\tconst matchedRequest = this.matchRequest(this.websocketRoutes, url)\n\t\t\tif (!matchedRequest) {\n\t\t\t\tthrow new HttpErrorResponse(404, 'Route not found')\n\t\t\t}\n\t\t\trequestLogger = this.createRequestLogger(req, undefined, matchedRequest.module, clientIp)\n\n\t\t\tconst groupContainer = await this.projectGroupResolver.resolveContainer({ request: req })\n\n\t\t\trequestLogger = requestLogger.child({\n\t\t\t\tprojectGroup: groupContainer.slug,\n\t\t\t})\n\n\t\t\tconst authResult = await groupContainer.authenticator.authenticate({ request: req, timer, clientIp })\n\t\t\trequestLogger.debug('User authenticated', { authResult })\n\t\t\trequestLogger = requestLogger.child({\n\t\t\t\tuser: authResult?.identityId,\n\t\t\t})\n\n\t\t\tconst effectiveClientIp = authResult?.clientIp ?? clientIp\n\n\t\t\tconst ws = await new Promise<WebSocket>(resolve =>\n\t\t\t\twss.handleUpgrade(req, socket, head, (ws, request) => {\n\t\t\t\t\tresolve(ws)\n\t\t\t\t})\n\t\t\t)\n\t\t\tconst wsEstablished = performance.now()\n\t\t\twebSocketContext = {\n\t\t\t\tws,\n\t\t\t\tabortSignal,\n\t\t\t\tlogger: requestLogger,\n\t\t\t\ttimer,\n\t\t\t\turl,\n\t\t\t\trequest: req,\n\t\t\t\tclientIp: effectiveClientIp,\n\t\t\t\tauthResult,\n\t\t\t\tparams: matchedRequest.params,\n\t\t\t\tprojectGroup: groupContainer,\n\t\t\t}\n\t\t\tawait matchedRequest.controller(webSocketContext)\n\t\t\trequestLogger.debug('Websocket connection established')\n\t\t\tws.on('error', e => {\n\t\t\t\trequestLogger.error(e, {\n\t\t\t\t\twebsocketOpenMs: performance.now() - wsEstablished,\n\t\t\t\t})\n\t\t\t})\n\n\t\t\treturn new Promise<void>(resolve => {\n\t\t\t\tws.on('close', () => {\n\t\t\t\t\trequestLogger.debug('Websocket connection closed', {\n\t\t\t\t\t\twebsocketOpenMs: performance.now() - wsEstablished,\n\t\t\t\t\t})\n\t\t\t\t\tresolve()\n\t\t\t\t})\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tif (e instanceof HttpResponse) {\n\t\t\t\tthis.sendRawHttpResponse(socket, e)\n\t\t\t} else {\n\t\t\t\tthis.sendRawHttpResponse(socket, new HttpErrorResponse(500, 'Internal server error'))\n\t\t\t\trequestLogger.error(e)\n\t\t\t}\n\t\t\trequestLogger.debug('Websocket connection failed')\n\t\t} finally {\n\t\t\tsendTimer({\n\t\t\t\treq,\n\t\t\t\trequestDebugMode: false,\n\t\t\t\tlogger: requestLogger,\n\t\t\t})\n\t\t}\n\t}\n\n\tprivate async handleHttpRequest(ctx: KoaContext<{ module?: string; projectGroup?: string; project?: string }>) {\n\t\tconst matchedRequest = this.matchRequest(this.routes, ctx.request.URL)\n\t\tif (!matchedRequest) {\n\t\t\tconst internalMatchedRequest = this.matchRequest(this.internalRoutes, ctx.request.URL)\n\t\t\tif (internalMatchedRequest) {\n\t\t\t\treturn await this.handleInternalRequest(internalMatchedRequest, ctx)\n\t\t\t}\n\t\t}\n\t\tlet httpContext: HttpContext | null = null\n\t\tconst clientIp = getClientIP(ctx.req, this.trustedProxies)\n\t\tlet requestLogger = this.createRequestLogger(ctx.req, ctx.request.body, matchedRequest?.module, clientIp)\n\t\tconst { timer, send: sendTimer } = this.createTimer()\n\n\t\ttry {\n\t\t\tif (!matchedRequest) {\n\t\t\t\treturn this.sendHttpResponse(ctx, new HttpErrorResponse(404, 'Route not found'))\n\t\t\t}\n\t\t\trequestLogger.debug('Request processing started', {\n\t\t\t\tbody: ctx.request.body,\n\t\t\t\tquery: ctx.request.query,\n\t\t\t})\n\n\t\t\t// todo: solve without koa context (required by prom metrics)\n\t\t\tctx.state.module = matchedRequest.module\n\n\t\t\tconst groupContainer = await this.projectGroupResolver.resolveContainer({ request: ctx.req })\n\t\t\trequestLogger = requestLogger.child({\n\t\t\t\tprojectGroup: groupContainer.slug,\n\t\t\t})\n\t\t\tctx.state.projectGroup = groupContainer.slug\n\t\t\tctx.state.project = matchedRequest.params.projectSlug\n\n\t\t\tconst authResult = await groupContainer.authenticator.authenticate({ request: ctx.req, timer, clientIp })\n\t\t\trequestLogger.debug('User authenticated', { authResult })\n\t\t\trequestLogger = requestLogger.child({\n\t\t\t\tuser: authResult?.identityId,\n\t\t\t})\n\n\t\t\tconst effectiveClientIp = authResult?.clientIp ?? clientIp\n\n\t\t\tconst response = await requestLogger.scope(async logger => {\n\t\t\t\thttpContext = {\n\t\t\t\t\tkoa: ctx,\n\t\t\t\t\tbody: ctx.request.body,\n\t\t\t\t\turl: ctx.request.URL,\n\t\t\t\t\tclientIp: effectiveClientIp,\n\t\t\t\t\tlogger,\n\t\t\t\t\ttimer,\n\t\t\t\t\trequest: ctx.req,\n\t\t\t\t\tresponse: ctx.res,\n\t\t\t\t\trequestDebugMode: false,\n\t\t\t\t\tauthResult,\n\t\t\t\t\tparams: matchedRequest.params,\n\t\t\t\t\tprojectGroup: groupContainer,\n\t\t\t\t}\n\t\t\t\treturn await matchedRequest.controller(httpContext)\n\t\t\t})\n\t\t\tif (response) {\n\t\t\t\tthis.sendHttpResponse(ctx, response)\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (e instanceof HttpResponse) {\n\t\t\t\tthis.sendHttpResponse(ctx, e)\n\t\t\t} else {\n\t\t\t\tthis.sendHttpResponse(ctx, new HttpErrorResponse(500, 'Internal server error'))\n\t\t\t\trequestLogger.error(e)\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.maybeForceHttpOk(ctx, matchedRequest?.module)\n\t\t\tsendTimer({\n\t\t\t\treq: ctx.req,\n\t\t\t\tresponse: ctx.res,\n\t\t\t\tbody: ctx.response.body,\n\t\t\t\trequestDebugMode: (httpContext as HttpContext | null)?.requestDebugMode ?? false,\n\t\t\t\tlogger: requestLogger,\n\t\t\t})\n\t\t\trequestLogger.debug('Request processing finished')\n\t\t}\n\t}\n\n\tprivate async handleInternalRequest(matchedRequest: MatchedRequest<InternalHttpController>, ctx: KoaContext<{ module?: string }>) {\n\t\ttry {\n\t\t\tconst response = await this.logger.scope(async logger => {\n\t\t\t\treturn await matchedRequest.controller({\n\t\t\t\t\tkoa: ctx,\n\t\t\t\t\tclientIp: getClientIP(ctx.req, this.trustedProxies),\n\t\t\t\t\tbody: ctx.request.body,\n\t\t\t\t\turl: ctx.request.URL,\n\t\t\t\t\tlogger,\n\t\t\t\t\trequest: ctx.req,\n\t\t\t\t\tresponse: ctx.res,\n\t\t\t\t\tparams: matchedRequest.params,\n\t\t\t\t})\n\t\t\t})\n\t\t\tif (response) {\n\t\t\t\tthis.sendHttpResponse(ctx, response)\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (e instanceof HttpResponse) {\n\t\t\t\tthis.sendHttpResponse(ctx, e)\n\t\t\t} else {\n\t\t\t\tthis.sendHttpResponse(ctx, new HttpErrorResponse(500, 'Internal server error'))\n\t\t\t\tthis.logger.error(e)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * When the X-Contember-Force-Ok header is present (and the capability is enabled in config),\n\t * coerce the HTTP status of a GraphQL API response (content/tenant/system) to 200, keeping the\n\t * error information in the JSON body. Scoped to those modules so non-JSON / non-GraphQL responses\n\t * are not mislabeled. Default behavior (real status codes) is preserved when the header is absent.\n\t */\n\tprivate maybeForceHttpOk(ctx: KoaContext<{}>, module: string | undefined) {\n\t\tconst coerce = shouldForceHttpOk({\n\t\t\tenabled: this.forceHttpOkEnabled,\n\t\t\tstatus: ctx.status,\n\t\t\tmodule,\n\t\t\thasBody: ctx.body !== undefined && ctx.body !== null,\n\t\t\theaderRequested: isForceHttpOkRequested(ctx.req),\n\t\t})\n\t\tif (!coerce) {\n\t\t\treturn\n\t\t}\n\t\tctx.set('X-Contember-Original-Status', String(ctx.status))\n\t\tctx.status = 200\n\t}\n\n\tprivate sendHttpResponse(ctx: KoaContext<{}>, response: HttpResponse) {\n\t\tif (response.contentType) {\n\t\t\tctx.set('Content-type', response.contentType)\n\t\t}\n\t\tctx.status = response.code\n\t\tif (response.body !== undefined) {\n\t\t\tctx.body = response.body\n\t\t}\n\t}\n\n\tprivate sendRawHttpResponse(socket: Duplex, response: HttpResponse) {\n\t\tconst headers: Record<string, string> = {\n\t\t\t'Connection': 'close',\n\t\t\t'Content-Type': response.contentType ?? 'text/plain',\n\t\t\t'Content-Length': String(response.body?.length ?? 0),\n\t\t}\n\n\t\tsocket.once('finish', socket.destroy)\n\n\t\tsocket.end(\n\t\t\t`HTTP/1.1 ${response.code} ${http.STATUS_CODES[response.code]}\\r\\n`\n\t\t\t\t+ Object.keys(headers)\n\t\t\t\t\t.map(h => `${h}: ${headers[h]}`)\n\t\t\t\t\t.join('\\r\\n')\n\t\t\t\t+ '\\r\\n\\r\\n'\n\t\t\t\t+ (response.body ?? ''),\n\t\t)\n\t}\n\n\tprivate createRequestLogger(request: IncomingMessage, body: any, module?: string, remoteAddress?: string): Logger {\n\t\treturn this.logger.child({\n\t\t\tmethod: request.method,\n\t\t\turi: request.url,\n\t\t\trequestId: Math.random().toString().substring(2),\n\t\t\tmodule,\n\t\t\tremoteAddress,\n\t\t\t[LoggerRequestBody]: body,\n\t\t}, {\n\t\t\thandler: FingerCrossedLoggerHandler.factory(),\n\t\t})\n\t}\n\n\tprivate createTimer() {\n\t\tconst times: EventTime[] = []\n\t\tconst globalStart = performance.now()\n\t\tconst cpuUsageStart = cpuUsage()\n\t\tconst memoryUsageStart = memoryUsage()\n\t\tconst timer: Timer = (name: string, cb) => {\n\t\t\tconst start = performance.now()\n\t\t\tconst time: EventTime = { label: name, start: Math.round(start - globalStart) }\n\t\t\ttimes.push(time)\n\t\t\tconst res = cb()\n\n\t\t\tif (res instanceof Promise) {\n\t\t\t\t;(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait res\n\t\t\t\t\t} catch {\n\t\t\t\t\t} finally {\n\t\t\t\t\t\ttime.duration = Math.round(performance.now() - start)\n\t\t\t\t\t}\n\t\t\t\t})()\n\t\t\t}\n\t\t\treturn res\n\t\t}\n\n\t\tconst send = (ctx: { req: IncomingMessage; response?: ServerResponse; body?: unknown; requestDebugMode: boolean; logger: Logger }) => {\n\t\t\tif (ctx.response && !ctx.response.headersSent && (ctx.requestDebugMode || this.debugMode) && times.length) {\n\t\t\t\tctx.response.setHeader('server-timing', times.map(it => `${it.label};desc=\"${it.label} T+${it.start}\";dur=${it.duration ?? -1}`).join(', '))\n\t\t\t}\n\n\t\t\tconst emit = () => {\n\t\t\t\tconst total = performance.now() - globalStart\n\t\t\t\tconst timeLabel = total > 500 ? 'TIME_SLOW' : 'TIME_OK'\n\t\t\t\tconst shouldSuppress = this.suppressAccessLog === true || !ctx.req.url\n\t\t\t\t\t|| (this.suppressAccessLog !== false && this.suppressAccessLog.test(ctx.req.url))\n\n\t\t\t\tconst cpuUsageEnd = cpuUsage()\n\t\t\t\tconst memoryUsageEnd = memoryUsage()\n\n\t\t\t\tconst cpuUsageDiffMs = (cpuUsageEnd.user - cpuUsageStart.user) / 1000\n\t\t\t\tconst memoryUsageDiff = memoryUsageEnd.heapUsed - memoryUsageStart.heapUsed\n\t\t\t\tconst level = shouldSuppress ? 'debug' : 'info'\n\t\t\t\tctx.logger.log(level, !ctx.response ? 'Connection established' : ctx.response.statusCode < 400 ? `Request successful` : 'Request failed', {\n\t\t\t\t\tstatus: ctx.response?.statusCode,\n\t\t\t\t\ttimeLabel: timeLabel,\n\t\t\t\t\ttotalTimeMs: Math.round(total),\n\t\t\t\t\tevents: times,\n\t\t\t\t\tcpuUsageDiffMs,\n\t\t\t\t\tmemoryUsageDiff,\n\t\t\t\t\tresponseBodySize: ctx.body && typeof ctx.body === 'string' ? ctx.body.length : undefined,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tif (ctx.body instanceof Readable) {\n\t\t\t\tconst body = ctx.body\n\t\t\t\tconst streamTimer = timer('Stream', () => {\n\t\t\t\t\treturn new Promise(resolve => {\n\t\t\t\t\t\tbody.addListener('close', () => {\n\t\t\t\t\t\t\tresolve(null)\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t})\n\n\t\t\t\tstreamTimer.then(emit).catch(emit)\n\t\t\t} else {\n\t\t\t\temit()\n\t\t\t}\n\t\t}\n\t\treturn { timer, send }\n\t}\n\n\tprivate matchRequest<C>(routes: Route<C>[], url: URL): MatchedRequest<C> | null {\n\t\tfor (const route of routes) {\n\t\t\tconst params = route.match({ url })\n\t\t\tif (params !== null) {\n\t\t\t\treturn { params, controller: route.controller, module: route.module }\n\t\t\t}\n\t\t}\n\t\treturn null\n\t}\n}\n\ntype EventTime = { label: string; start: number; duration?: number }\n\nexport type Timer = <T>(event: string, cb: () => T) => T\n\nexport type MatchedRequest<C> = { params: Params; controller: C; module: string }\n\nexport type BaseRequestContext = {\n\tlogger: Logger\n\trequest: IncomingMessage\n\turl: URL\n\tparams: Params\n\tclientIp: string\n}\n\nexport type ApplicationContext =\n\t& BaseRequestContext\n\t& {\n\t\tprojectGroup: ProjectGroupContainer\n\t\tauthResult: AuthResult | null\n\t\ttimer: Timer\n\t}\n\nexport type BaseHttpRequestContext = {\n\tkoa: KoaContext<{}>\n\tbody: unknown\n\tresponse: ServerResponse\n}\n\nexport type HttpContext =\n\t& ApplicationContext\n\t& BaseHttpRequestContext\n\t& {\n\t\trequestDebugMode: boolean\n\t}\n\nexport type InternalHttpContext =\n\t& BaseRequestContext\n\t& BaseHttpRequestContext\n\nexport type WebSocketContext =\n\t& ApplicationContext\n\t& {\n\t\tws: WebSocket\n\t\tabortSignal: AbortSignal\n\t}\n\nexport type HttpControllerResponse = Promise<HttpErrorResponse | undefined | void> | HttpErrorResponse | undefined | void\nexport type HttpController = (context: HttpContext) => HttpControllerResponse\nexport type InternalHttpController = (context: InternalHttpContext) => HttpControllerResponse\n\nexport type WebSocketController = (context: WebSocketContext) => void\n\ntype Params = { [param: string]: string }\n\ntype RequestMatcher = (args: { url: URL }) => Params | null\nconst createRequestMatcher = (\n\tmask: string,\n): RequestMatcher => {\n\tconst { regexp, keys } = pathToRegexp(mask)\n\n\tconst match = function(url: string): Params | null {\n\t\tconst match = regexp.exec(url)\n\t\tif (match) {\n\t\t\treturn match.slice(1).reduce((acc, value, i) => ({ ...acc, [keys[i].name]: value }), {})\n\t\t}\n\t\treturn null\n\t}\n\n\treturn request => {\n\t\treturn match(request.url.pathname)\n\t}\n}\n\nexport const LoggerRequestBody = Symbol('RequestBody')\n\nexport interface RunningApplication {\n\tclose(): Promise<void>\n\treadonly server: Server\n}\n"],"names":["ws","match"],"mappings":";;;;;;;;;;;;;;;;;;;AAsBO,MAAM,YAAY;AAAA,EAWxB,YACkB,sBACA,cACA,WACA,SACA,QAChB;AALgB,SAAA,uBAAA;AACA,SAAA,eAAA;AACA,SAAA,YAAA;AACA,SAAA,UAAA;AACA,SAAA,SAAA;AAflB,kBAAA,MAAQ,eAAoC,EAAC;AAE7C,kBAAA,MAAQ,UAAkC,EAAC;AAC3C,kBAAA,MAAQ,kBAAkD,EAAC;AAC3D,kBAAA,MAAQ,mBAAgD,EAAC;AAEzD,kBAAA,MAAQ,mBAAA;AACR,kBAAA,MAAQ,gBAAA;AACR,kBAAA,MAAQ,oB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B,QAAoB,KAAoC;AAC/E,eAAW,SAAS,QAAQ;AAC3B,YAAM,SAAS,MAAM,MAAM,EAAE,KAAK;AAClC,UAAI,WAAW,MAAM;AACpB,eAAO,EAAE,QAAQ,YAAY,MAAM,YAAY,QAAQ,MAAM,OAAA;AAAA,MAC9D;AAAA,IACD;AACA,WAAO;AAAA,EACR;AACD;AAyDA,MAAM,uBAAuB,CAC5B,SACoB;AACpB,QAAM,EAAE,QAAQ,SAAS,aAAa,IAAI;AAE1C,QAAM,QAAQ,SAAS,KAA4B;AAClD,UAAMC,SAAQ,OAAO,KAAK,GAAG;AAC7B,QAAIA,QAAO;AACV,aAAOA,OAAM,MAAM,CAAC,EAAE,OAAO,CAAC,KAAK,OAAO,OAAO,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,GAAG,MAAA,IAAU,EAAE;AAAA,IACxF;AACA,WAAO;AAAA,EACR;AAEA,SAAO,CAAA,YAAW;AACjB,WAAO,MAAM,QAAQ,IAAI,QAAQ;AAAA,EAClC;AACD;AAEO,MAAM,2CAA2B,aAAa;"}
1
+ {"version":3,"file":"application.js","sources":["../../../../../packages/engine-http/src/application/application.ts"],"sourcesContent":["import { pathToRegexp } from 'path-to-regexp'\nimport { KoaContext, KoaMiddleware } from './types.js'\nimport { AuthResult, HttpErrorResponse, HttpResponse } from '../common/index.js'\nimport Koa from 'koa'\nimport * as http from 'node:http'\nimport { IncomingMessage, Server, ServerResponse } from 'node:http'\nimport { WebSocket, WebSocketServer } from 'ws'\nimport { FingerCrossedLoggerHandler, Logger } from '@contember/logger'\nimport { ServerConfig } from '../config/config.js'\nimport { createCompressionMiddleware } from './compression.js'\nimport { createCorsMiddleware } from './cors.js'\nimport { createRequestBodyMiddleware, defaultFormBodyLimit, defaultJsonBodyLimit } from './requestBody.js'\nimport stream, { Duplex, Readable } from 'node:stream'\nimport { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver.js'\nimport { ProjectGroupContainer } from '../projectGroup/ProjectGroupContainer.js'\nimport { URL } from 'node:url'\nimport { cpuUsage, memoryUsage } from 'node:process'\nimport { performance } from 'node:perf_hooks'\nimport { getClientIP } from '../utils/remoteAddress.js'\nimport { isForceHttpOkRequested, shouldForceHttpOk } from './forceHttpOk.js'\nimport { INVALID_TRACE_ID, noopTracer, Span, SpanContext, Tracer, withSpanContext } from '@contember/telemetry'\nimport { AcceptIncomingTraceMode, resolveIncomingSpanContext } from '../telemetry/incomingTrace.js'\nimport { maskRequestBody, maskRequestUri } from './requestBodyMasking.js'\n\nconst websocketCloseTimeoutMs = 5_000\n\ntype Route<C> = { match: RequestMatcher; controller: C; module: string; mask: string; carriesCredentials: boolean }\n\nexport type RouteOptions = {\n\t/** The route receives engine credentials (passwords, OTP codes, tokens), so its body and URI are masked in logs. */\n\treadonly carriesCredentials?: boolean\n}\nexport class Application {\n\tprivate middlewares: KoaMiddleware<any>[] = []\n\n\tprivate routes: Route<HttpController>[] = []\n\tprivate internalRoutes: Route<InternalHttpController>[] = []\n\tprivate websocketRoutes: Route<WebSocketController>[] = []\n\n\tprivate suppressAccessLog: boolean | RegExp\n\tprivate trustedProxies: string[]\n\tprivate forceHttpOkEnabled: boolean\n\tprivate acceptIncomingTrace: AcceptIncomingTraceMode\n\tprivate traceIdResponseHeader: boolean\n\n\tconstructor(\n\t\tprivate readonly projectGroupResolver: ProjectGroupResolver,\n\t\tprivate readonly serverConfig: ServerConfig,\n\t\tprivate readonly debugMode: boolean,\n\t\tprivate readonly version: string | undefined,\n\t\tprivate readonly logger: Logger,\n\t\tprivate readonly tracer: Tracer = noopTracer,\n\t) {\n\t\tconst suppressAccessLogRaw = serverConfig.http?.suppressAccessLog\n\t\tthis.suppressAccessLog = suppressAccessLogRaw === true ? true : suppressAccessLogRaw ? new RegExp(suppressAccessLogRaw) : false\n\t\tthis.trustedProxies = serverConfig.http?.trustedProxies ?? []\n\t\tthis.forceHttpOkEnabled = serverConfig.http?.responseStatusHeader ?? true\n\t\tthis.acceptIncomingTrace = serverConfig.telemetry?.traces?.acceptIncoming ?? 'trusted-proxies'\n\t\tthis.traceIdResponseHeader = serverConfig.telemetry?.traces?.traceIdResponseHeader ?? false\n\t}\n\n\taddMiddleware(middleware: KoaMiddleware<any>) {\n\t\tthis.middlewares.push(middleware)\n\t}\n\n\tpublic addRoute(module: string, mask: string, controller: HttpController, options: RouteOptions = {}): void {\n\t\tthis.routes.push({\n\t\t\tmodule,\n\t\t\tcontroller,\n\t\t\tmask,\n\t\t\tmatch: createRequestMatcher(mask),\n\t\t\tcarriesCredentials: options.carriesCredentials ?? false,\n\t\t})\n\t}\n\n\tpublic addInternalRoute(module: string, mask: string, controller: InternalHttpController): void {\n\t\tthis.internalRoutes.push({\n\t\t\tmodule,\n\t\t\tcontroller,\n\t\t\tmask,\n\t\t\tmatch: createRequestMatcher(mask),\n\t\t\tcarriesCredentials: false,\n\t\t})\n\t}\n\n\tpublic addWebsocketRoute(module: string, mask: string, controller: WebSocketController): void {\n\t\tthis.websocketRoutes.push({\n\t\t\tmodule,\n\t\t\tcontroller,\n\t\t\tmask,\n\t\t\tmatch: createRequestMatcher(mask),\n\t\t\tcarriesCredentials: false,\n\t\t})\n\t}\n\n\tasync listen(): Promise<RunningApplication> {\n\t\tconst koa = new Koa()\n\t\tconst wss = new WebSocketServer({ noServer: true })\n\t\tlet closing = false\n\t\tkoa.use(async (ctx, next) => {\n\t\t\tif (closing) {\n\t\t\t\tctx.status = 503\n\t\t\t\tctx.set('Connection', 'close')\n\t\t\t\treturn\n\t\t\t}\n\t\t\tawait next()\n\t\t})\n\t\tfor (const middleware of this.middlewares) {\n\t\t\tkoa.use(middleware)\n\t\t}\n\t\tkoa.use(createCompressionMiddleware())\n\t\tkoa.use(createRequestBodyMiddleware({\n\t\t\tjson: this.serverConfig.http?.requestBodySize ?? defaultJsonBodyLimit,\n\t\t\tform: defaultFormBodyLimit,\n\t\t}))\n\t\tkoa.use(createCorsMiddleware({ exposeHeaders: ['X-Contember-Mutation'] }))\n\t\tconst versionMatch = this.version?.match(/^(0\\.\\d+|\\d+)/)\n\t\tconst versionSimplified = versionMatch?.[1] ?? 'unknown'\n\t\tkoa.use(async ctx => {\n\t\t\tctx.response.set('X-Powered-By', `Contember ${versionSimplified}` + (this.debugMode ? '-dev' : ''))\n\t\t\tawait this.handleHttpRequest(ctx)\n\t\t})\n\n\t\tconst activeHttpRequests = new Set<Promise<void>>()\n\t\tconst handleHttpRequest = koa.callback()\n\t\tconst server = http.createServer((request, response) => {\n\t\t\tif (closing) {\n\t\t\t\thandleHttpRequest(request, response)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tlet resolveRequest = () => {}\n\t\t\tconst completed = new Promise<void>(resolve => {\n\t\t\t\tresolveRequest = resolve\n\t\t\t})\n\t\t\tactiveHttpRequests.add(completed)\n\t\t\tconst complete = () => {\n\t\t\t\tresponse.off('finish', complete)\n\t\t\t\tresponse.off('close', complete)\n\t\t\t\tactiveHttpRequests.delete(completed)\n\t\t\t\tresolveRequest()\n\t\t\t}\n\t\t\tresponse.once('finish', complete)\n\t\t\tresponse.once('close', complete)\n\t\t\thandleHttpRequest(request, response)\n\t\t})\n\t\tconst abortController = new AbortController()\n\n\t\tconst wsRequests: (Promise<void>)[] = []\n\t\tserver.on('upgrade', (req, socket, head) => {\n\t\t\tif (closing) {\n\t\t\t\tthis.sendRawHttpResponse(socket, new HttpErrorResponse(503, 'Server is shutting down'))\n\t\t\t\treturn\n\t\t\t}\n\t\t\twsRequests.push(this.handleWebsocketRequest(wss, abortController.signal, req, socket, head).finally(() => socket.destroy()))\n\t\t})\n\t\tawait new Promise<void>(resolve => {\n\t\t\tserver.listen(this.serverConfig.port, () => resolve())\n\t\t})\n\n\t\treturn {\n\t\t\tserver,\n\t\t\tclose: async () => {\n\t\t\t\tclosing = true\n\t\t\t\tabortController.abort()\n\t\t\t\tawait Promise.all([...wsRequests, ...activeHttpRequests])\n\t\t\t\tif (process.versions.bun !== undefined) {\n\t\t\t\t\t// Bun does not finish server.close() after a WebSocket upgrade unless all connections are closed first.\n\t\t\t\t\tserver.closeAllConnections()\n\t\t\t\t} else {\n\t\t\t\t\tserver.closeIdleConnections()\n\t\t\t\t}\n\t\t\t\tif (server.listening) {\n\t\t\t\t\tawait new Promise<void>(resolve =>\n\t\t\t\t\t\tserver.close(error => {\n\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\tthis.logger.error(error)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tresolve()\n\t\t\t\t\t\t})\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\t}\n\n\tprivate async handleWebsocketRequest(\n\t\twss: WebSocketServer,\n\t\tabortSignal: AbortSignal,\n\t\treq: IncomingMessage,\n\t\tsocket: stream.Duplex,\n\t\thead: Buffer,\n\t): Promise<void> {\n\t\tlet requestLogger = this.logger\n\t\tconst { timer, send: sendTimer } = this.createTimer()\n\t\tconst clientIp = getClientIP(req, this.trustedProxies)\n\t\ttry {\n\t\t\tconst url = new URL(req.url ?? '/', `http://${req.headers.host}`)\n\t\t\tconst matchedRequest = this.matchRequest(this.websocketRoutes, url)\n\t\t\tif (!matchedRequest) {\n\t\t\t\tthrow new HttpErrorResponse(404, 'Route not found')\n\t\t\t}\n\t\t\tconst established = await this.withIncomingTrace(req, async () => {\n\t\t\t\tconst span = this.tracer.startSpan(`WS ${matchedRequest.mask}`, {\n\t\t\t\t\tkind: 'server',\n\t\t\t\t\tattributes: {\n\t\t\t\t\t\t'http.request.method': req.method ?? 'GET',\n\t\t\t\t\t\t'url.path': url.pathname,\n\t\t\t\t\t\t'contember.module': matchedRequest.module,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\treturn await this.tracer.withSpan(span, async () => {\n\t\t\t\t\tconst pendingWork: Promise<void>[] = []\n\t\t\t\t\ttry {\n\t\t\t\t\t\trequestLogger = this.createRequestLogger(req, undefined, false, matchedRequest.module, clientIp, span.context)\n\t\t\t\t\t\tconst groupContainer = await this.projectGroupResolver.resolveContainer({ request: req })\n\t\t\t\t\t\trequestLogger = requestLogger.child({ projectGroup: groupContainer.slug, project: matchedRequest.params.projectSlug })\n\t\t\t\t\t\tspan.setAttribute('contember.project_group', groupContainer.slug ?? 'unknown')\n\t\t\t\t\t\tif (matchedRequest.params.projectSlug !== undefined) {\n\t\t\t\t\t\t\tspan.setAttribute('contember.project', matchedRequest.params.projectSlug)\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst authResult = await groupContainer.authenticator.authenticate({ request: req, timer, clientIp })\n\t\t\t\t\t\trequestLogger.debug('User authenticated', { authResult })\n\t\t\t\t\t\trequestLogger = requestLogger.child({ user: authResult?.identityId })\n\t\t\t\t\t\tif (authResult) {\n\t\t\t\t\t\t\tspan.setAttribute('contember.identity_id', authResult.identityId)\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (abortSignal.aborted) {\n\t\t\t\t\t\t\tthrow new HttpErrorResponse(503, 'Server is shutting down')\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst ws = await new Promise<WebSocket>(resolve => wss.handleUpgrade(req, socket, head, ws => resolve(ws)))\n\t\t\t\t\t\tconst establishedAt = performance.now()\n\t\t\t\t\t\tconst closed = new Promise<void>(resolve => ws.once('close', () => resolve()))\n\t\t\t\t\t\tws.on('error', e => {\n\t\t\t\t\t\t\trequestLogger.error(e, {\n\t\t\t\t\t\t\t\twebsocketOpenMs: performance.now() - establishedAt,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t})\n\t\t\t\t\t\tspan.setAttribute('http.response.status_code', 101)\n\t\t\t\t\t\tif (abortSignal.aborted) {\n\t\t\t\t\t\t\tawait this.closeWebsocket(ws)\n\t\t\t\t\t\t\treturn undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst context: WebSocketContext = {\n\t\t\t\t\t\t\tws,\n\t\t\t\t\t\t\tabortSignal,\n\t\t\t\t\t\t\tlogger: requestLogger,\n\t\t\t\t\t\t\ttimer,\n\t\t\t\t\t\t\ttracer: this.tracer,\n\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t\trequest: req,\n\t\t\t\t\t\t\tclientIp: authResult?.clientIp ?? clientIp,\n\t\t\t\t\t\t\tauthResult,\n\t\t\t\t\t\t\tparams: matchedRequest.params,\n\t\t\t\t\t\t\tprojectGroup: groupContainer,\n\t\t\t\t\t\t\twaitUntil: promise => pendingWork.push(promise),\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait matchedRequest.controller(context)\n\t\t\t\t\t\tif (abortSignal.aborted && ws.readyState === WebSocket.OPEN) {\n\t\t\t\t\t\t\tws.close(1012)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn { closed, pendingWork, establishedAt }\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconst response = error instanceof HttpResponse ? error : new HttpErrorResponse(500, 'Internal server error')\n\t\t\t\t\t\tspan.setAttribute('http.response.status_code', response.code)\n\t\t\t\t\t\tif (response.code >= 500) {\n\t\t\t\t\t\t\tspan.setStatus('error')\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!(error instanceof HttpResponse)) {\n\t\t\t\t\t\t\tspan.recordException(error)\n\t\t\t\t\t\t\trequestLogger.error(error)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.sendRawHttpResponse(socket, response)\n\t\t\t\t\t\trequestLogger.debug('Websocket connection failed')\n\t\t\t\t\t\treturn undefined\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tspan.end()\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t})\n\t\t\tif (established === undefined) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst { closed, pendingWork, establishedAt } = established\n\t\t\trequestLogger.debug('Websocket connection established')\n\n\t\t\tawait closed\n\t\t\tawait Promise.allSettled(pendingWork)\n\t\t\trequestLogger.debug('Websocket connection closed', {\n\t\t\t\twebsocketOpenMs: performance.now() - establishedAt,\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tif (e instanceof HttpResponse) {\n\t\t\t\tthis.sendRawHttpResponse(socket, e)\n\t\t\t} else {\n\t\t\t\tthis.sendRawHttpResponse(socket, new HttpErrorResponse(500, 'Internal server error'))\n\t\t\t\trequestLogger.error(e)\n\t\t\t}\n\t\t\trequestLogger.debug('Websocket connection failed')\n\t\t} finally {\n\t\t\tsendTimer({\n\t\t\t\treq,\n\t\t\t\trequestDebugMode: false,\n\t\t\t\tlogger: requestLogger,\n\t\t\t})\n\t\t}\n\t}\n\n\tprivate async handleHttpRequest(ctx: KoaContext<{ module?: string; projectGroup?: string; project?: string }>) {\n\t\tconst matchedRequest = this.matchRequest(this.routes, ctx.request.URL)\n\t\tif (!matchedRequest) {\n\t\t\tconst internalMatchedRequest = this.matchRequest(this.internalRoutes, ctx.request.URL)\n\t\t\tif (internalMatchedRequest) {\n\t\t\t\treturn await this.handleInternalRequest(internalMatchedRequest, ctx)\n\t\t\t}\n\t\t\treturn await this.processHttpRequest(ctx, null)\n\t\t}\n\t\treturn await this.withIncomingTrace(ctx.req, async () => {\n\t\t\tconst span = this.tracer.startSpan(`HTTP ${ctx.request.method} ${matchedRequest.mask}`, {\n\t\t\t\tkind: 'server',\n\t\t\t\tattributes: {\n\t\t\t\t\t'http.request.method': ctx.request.method,\n\t\t\t\t\t'url.path': ctx.request.URL.pathname,\n\t\t\t\t\t'contember.module': matchedRequest.module,\n\t\t\t\t},\n\t\t\t})\n\t\t\tif (span.context.traceId === INVALID_TRACE_ID) {\n\t\t\t\treturn await this.processHttpRequest(ctx, matchedRequest, span)\n\t\t\t}\n\t\t\tconst endSpan = () => {\n\t\t\t\tctx.res.off('finish', endSpan)\n\t\t\t\tctx.res.off('close', closeSpan)\n\t\t\t\tspan.end()\n\t\t\t}\n\t\t\tconst closeSpan = () => {\n\t\t\t\tif (!ctx.res.writableFinished) {\n\t\t\t\t\tspan.setStatus('error', 'Response closed before completion')\n\t\t\t\t}\n\t\t\t\tendSpan()\n\t\t\t}\n\t\t\tctx.res.once('finish', endSpan)\n\t\t\tctx.res.once('close', closeSpan)\n\t\t\ttry {\n\t\t\t\treturn await this.tracer.withSpan(span, () => this.processHttpRequest(ctx, matchedRequest, span))\n\t\t\t} catch (error) {\n\t\t\t\tspan.recordException(error)\n\t\t\t\tspan.setStatus('error')\n\t\t\t\tendSpan()\n\t\t\t\tthrow error\n\t\t\t} finally {\n\t\t\t\tif (ctx.res.writableFinished) {\n\t\t\t\t\tendSpan()\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async processHttpRequest(\n\t\tctx: KoaContext<{ module?: string; projectGroup?: string; project?: string }>,\n\t\tmatchedRequest: MatchedRequest<HttpController> | null,\n\t\tspan?: Span,\n\t) {\n\t\tlet httpContext: HttpContext | null = null\n\t\tconst clientIp = getClientIP(ctx.req, this.trustedProxies)\n\t\tconst carriesCredentials = matchedRequest?.carriesCredentials ?? false\n\t\tconst loggedBody = maskRequestBody(ctx.request.body, carriesCredentials)\n\t\tlet requestLogger = this.createRequestLogger(ctx.req, loggedBody, carriesCredentials, matchedRequest?.module, clientIp, span?.context)\n\t\tconst { timer, send: sendTimer } = this.createTimer()\n\n\t\ttry {\n\t\t\tif (!matchedRequest) {\n\t\t\t\treturn this.sendHttpResponse(ctx, new HttpErrorResponse(404, 'Route not found'))\n\t\t\t}\n\t\t\trequestLogger.debug('Request processing started', {\n\t\t\t\tbody: loggedBody,\n\t\t\t\tquery: maskRequestBody(ctx.request.query, carriesCredentials),\n\t\t\t})\n\n\t\t\t// todo: solve without koa context (required by prom metrics)\n\t\t\tctx.state.module = matchedRequest.module\n\n\t\t\tconst groupContainer = await this.projectGroupResolver.resolveContainer({ request: ctx.req })\n\t\t\trequestLogger = requestLogger.child({\n\t\t\t\tprojectGroup: groupContainer.slug,\n\t\t\t\tproject: matchedRequest.params.projectSlug,\n\t\t\t})\n\t\t\tctx.state.projectGroup = groupContainer.slug\n\t\t\tctx.state.project = matchedRequest.params.projectSlug\n\t\t\tspan?.setAttribute('contember.project_group', groupContainer.slug ?? 'unknown')\n\t\t\tif (matchedRequest.params.projectSlug !== undefined) {\n\t\t\t\tspan?.setAttribute('contember.project', matchedRequest.params.projectSlug)\n\t\t\t}\n\n\t\t\tconst authResult = await groupContainer.authenticator.authenticate({ request: ctx.req, timer, clientIp })\n\t\t\trequestLogger.debug('User authenticated', { authResult })\n\t\t\trequestLogger = requestLogger.child({\n\t\t\t\tuser: authResult?.identityId,\n\t\t\t})\n\t\t\tif (authResult) {\n\t\t\t\tspan?.setAttribute('contember.identity_id', authResult.identityId)\n\t\t\t}\n\n\t\t\tconst effectiveClientIp = authResult?.clientIp ?? clientIp\n\n\t\t\tconst response = await requestLogger.scope(async logger => {\n\t\t\t\thttpContext = {\n\t\t\t\t\tkoa: ctx,\n\t\t\t\t\tbody: ctx.request.body,\n\t\t\t\t\turl: ctx.request.URL,\n\t\t\t\t\tclientIp: effectiveClientIp,\n\t\t\t\t\tlogger,\n\t\t\t\t\ttimer,\n\t\t\t\t\ttracer: this.tracer,\n\t\t\t\t\trequest: ctx.req,\n\t\t\t\t\tresponse: ctx.res,\n\t\t\t\t\trequestDebugMode: false,\n\t\t\t\t\tauthResult,\n\t\t\t\t\tparams: matchedRequest.params,\n\t\t\t\t\tprojectGroup: groupContainer,\n\t\t\t\t}\n\t\t\t\treturn await matchedRequest.controller(httpContext)\n\t\t\t})\n\t\t\tif (response) {\n\t\t\t\tthis.sendHttpResponse(ctx, response)\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (e instanceof HttpResponse) {\n\t\t\t\tthis.sendHttpResponse(ctx, e)\n\t\t\t} else {\n\t\t\t\tthis.sendHttpResponse(ctx, new HttpErrorResponse(500, 'Internal server error'))\n\t\t\t\tspan?.recordException(e)\n\t\t\t\tspan?.setStatus('error')\n\t\t\t\trequestLogger.error(e)\n\t\t\t}\n\t\t} finally {\n\t\t\tconst responseStatus = ctx.status\n\t\t\tif (responseStatus >= 500) {\n\t\t\t\tspan?.setStatus('error')\n\t\t\t}\n\t\t\tthis.maybeForceHttpOk(ctx, matchedRequest?.module)\n\t\t\tconst requestDebugMode = (httpContext as HttpContext | null)?.requestDebugMode ?? false\n\t\t\tspan?.setAttribute('http.response.status_code', ctx.status)\n\t\t\tthis.sendTraceIdHeader(ctx, span, requestDebugMode)\n\t\t\tif (span !== undefined && span.context.traceId !== INVALID_TRACE_ID && ctx.response.body instanceof Readable) {\n\t\t\t\tconst contentLength = ctx.response.get('Content-Length')\n\t\t\t\tctx.body = createTracedReadable(ctx.response.body, this.tracer, span)\n\t\t\t\tif (contentLength !== '') {\n\t\t\t\t\tctx.set('Content-Length', contentLength)\n\t\t\t\t}\n\t\t\t}\n\t\t\tsendTimer({\n\t\t\t\treq: ctx.req,\n\t\t\t\tresponse: ctx.res,\n\t\t\t\tbody: ctx.response.body,\n\t\t\t\trequestDebugMode,\n\t\t\t\tlogger: requestLogger,\n\t\t\t})\n\t\t\trequestLogger.debug('Request processing finished')\n\t\t}\n\t}\n\n\tprivate withIncomingTrace<T>(request: IncomingMessage, cb: () => T): T {\n\t\tconst incoming = resolveIncomingSpanContext(request, { mode: this.acceptIncomingTrace, trustedProxies: this.trustedProxies })\n\t\treturn incoming === undefined ? cb() : withSpanContext(incoming, cb)\n\t}\n\n\tprivate sendTraceIdHeader(ctx: KoaContext<{}>, span: Span | undefined, requestDebugMode: boolean): void {\n\t\tif (span === undefined || ctx.res.headersSent || span.context.traceId === INVALID_TRACE_ID) {\n\t\t\treturn\n\t\t}\n\t\tif (!this.traceIdResponseHeader && !this.debugMode && !requestDebugMode) {\n\t\t\treturn\n\t\t}\n\t\tctx.set('x-contember-trace-id', span.context.traceId)\n\t}\n\n\tprivate async handleInternalRequest(matchedRequest: MatchedRequest<InternalHttpController>, ctx: KoaContext<{ module?: string }>) {\n\t\ttry {\n\t\t\tconst response = await this.logger.scope(async logger => {\n\t\t\t\treturn await matchedRequest.controller({\n\t\t\t\t\tkoa: ctx,\n\t\t\t\t\tclientIp: getClientIP(ctx.req, this.trustedProxies),\n\t\t\t\t\tbody: ctx.request.body,\n\t\t\t\t\turl: ctx.request.URL,\n\t\t\t\t\tlogger,\n\t\t\t\t\trequest: ctx.req,\n\t\t\t\t\tresponse: ctx.res,\n\t\t\t\t\tparams: matchedRequest.params,\n\t\t\t\t})\n\t\t\t})\n\t\t\tif (response) {\n\t\t\t\tthis.sendHttpResponse(ctx, response)\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (e instanceof HttpResponse) {\n\t\t\t\tthis.sendHttpResponse(ctx, e)\n\t\t\t} else {\n\t\t\t\tthis.sendHttpResponse(ctx, new HttpErrorResponse(500, 'Internal server error'))\n\t\t\t\tthis.logger.error(e)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * When the X-Contember-Force-Ok header is present (and the capability is enabled in config),\n\t * coerce the HTTP status of a GraphQL API response (content/tenant/system) to 200, keeping the\n\t * error information in the JSON body. Scoped to those modules so non-JSON / non-GraphQL responses\n\t * are not mislabeled. Default behavior (real status codes) is preserved when the header is absent.\n\t */\n\tprivate maybeForceHttpOk(ctx: KoaContext<{}>, module: string | undefined) {\n\t\tconst coerce = shouldForceHttpOk({\n\t\t\tenabled: this.forceHttpOkEnabled,\n\t\t\tstatus: ctx.status,\n\t\t\tmodule,\n\t\t\thasBody: ctx.body !== undefined && ctx.body !== null,\n\t\t\theaderRequested: isForceHttpOkRequested(ctx.req),\n\t\t})\n\t\tif (!coerce) {\n\t\t\treturn\n\t\t}\n\t\tctx.set('X-Contember-Original-Status', String(ctx.status))\n\t\tctx.status = 200\n\t}\n\n\tprivate sendHttpResponse(ctx: KoaContext<{}>, response: HttpResponse) {\n\t\tif (response.contentType) {\n\t\t\tctx.set('Content-type', response.contentType)\n\t\t}\n\t\tfor (const [name, value] of Object.entries(response.headers ?? {})) {\n\t\t\tctx.set(name, value)\n\t\t}\n\t\tctx.status = response.code\n\t\tif (response.body !== undefined) {\n\t\t\tctx.body = response.body\n\t\t}\n\t}\n\n\tprivate async closeWebsocket(ws: WebSocket): Promise<void> {\n\t\tif (ws.readyState === WebSocket.CLOSED) {\n\t\t\treturn\n\t\t}\n\t\tws.close(1012) // Service Restart\n\t\tawait new Promise<void>(resolve => {\n\t\t\t// ws only gives up on the close handshake after 30 s, which outlives a typical shutdown grace period\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tws.terminate()\n\t\t\t\tresolve()\n\t\t\t}, websocketCloseTimeoutMs)\n\t\t\tws.once('close', () => {\n\t\t\t\tclearTimeout(timeout)\n\t\t\t\tresolve()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate sendRawHttpResponse(socket: Duplex, response: HttpResponse) {\n\t\tconst headers: Record<string, string> = {\n\t\t\t...response.headers,\n\t\t\t'Connection': 'close',\n\t\t\t'Content-Type': response.contentType ?? 'text/plain',\n\t\t\t'Content-Length': String(response.body?.length ?? 0),\n\t\t}\n\n\t\tsocket.once('finish', socket.destroy)\n\n\t\tsocket.end(\n\t\t\t`HTTP/1.1 ${response.code} ${http.STATUS_CODES[response.code]}\\r\\n`\n\t\t\t\t+ Object.keys(headers)\n\t\t\t\t\t.map(h => `${h}: ${headers[h]}`)\n\t\t\t\t\t.join('\\r\\n')\n\t\t\t\t+ '\\r\\n\\r\\n'\n\t\t\t\t+ (response.body ?? ''),\n\t\t)\n\t}\n\n\t/** `loggedBody` must already be masked (`maskRequestBody`): it reaches logs and error reports. */\n\tprivate createRequestLogger(\n\t\trequest: IncomingMessage,\n\t\tloggedBody: unknown,\n\t\tcarriesCredentials: boolean,\n\t\tmodule?: string,\n\t\tremoteAddress?: string,\n\t\tspanContext?: SpanContext,\n\t): Logger {\n\t\tconst traceAttributes = spanContext === undefined || spanContext.traceId === INVALID_TRACE_ID\n\t\t\t? {}\n\t\t\t: { traceId: spanContext.traceId, spanId: spanContext.spanId }\n\t\treturn this.logger.child({\n\t\t\tmethod: request.method,\n\t\t\turi: maskRequestUri(request.url, carriesCredentials),\n\t\t\trequestId: Math.random().toString().substring(2),\n\t\t\tmodule,\n\t\t\tremoteAddress,\n\t\t\t...traceAttributes,\n\t\t\t[LoggerRequestBody]: loggedBody,\n\t\t}, {\n\t\t\thandler: FingerCrossedLoggerHandler.factory(),\n\t\t})\n\t}\n\n\tprivate createTimer() {\n\t\tconst times: EventTime[] = []\n\t\tconst globalStart = performance.now()\n\t\tconst cpuUsageStart = cpuUsage()\n\t\tconst memoryUsageStart = memoryUsage()\n\t\tconst timer = createEventTimer(this.tracer, times, globalStart)\n\n\t\tconst send = (ctx: { req: IncomingMessage; response?: ServerResponse; body?: unknown; requestDebugMode: boolean; logger: Logger }) => {\n\t\t\tif (ctx.response && !ctx.response.headersSent && (ctx.requestDebugMode || this.debugMode) && times.length) {\n\t\t\t\tctx.response.setHeader('server-timing', times.map(it => `${it.label};desc=\"${it.label} T+${it.start}\";dur=${it.duration ?? -1}`).join(', '))\n\t\t\t}\n\n\t\t\tconst emit = () => {\n\t\t\t\tconst total = performance.now() - globalStart\n\t\t\t\tconst timeLabel = total > 500 ? 'TIME_SLOW' : 'TIME_OK'\n\t\t\t\tconst shouldSuppress = this.suppressAccessLog === true || !ctx.req.url\n\t\t\t\t\t|| (this.suppressAccessLog !== false && this.suppressAccessLog.test(ctx.req.url))\n\n\t\t\t\tconst cpuUsageEnd = cpuUsage()\n\t\t\t\tconst memoryUsageEnd = memoryUsage()\n\n\t\t\t\tconst cpuUsageDiffMs = (cpuUsageEnd.user - cpuUsageStart.user) / 1000\n\t\t\t\tconst memoryUsageDiff = memoryUsageEnd.heapUsed - memoryUsageStart.heapUsed\n\t\t\t\tconst level = shouldSuppress ? 'debug' : 'info'\n\t\t\t\tctx.logger.log(level, !ctx.response ? 'Connection established' : ctx.response.statusCode < 400 ? `Request successful` : 'Request failed', {\n\t\t\t\t\tstatus: ctx.response?.statusCode,\n\t\t\t\t\ttimeLabel: timeLabel,\n\t\t\t\t\ttotalTimeMs: Math.round(total),\n\t\t\t\t\tevents: times,\n\t\t\t\t\tcpuUsageDiffMs,\n\t\t\t\t\tmemoryUsageDiff,\n\t\t\t\t\tresponseBodySize: ctx.body && typeof ctx.body === 'string' ? ctx.body.length : undefined,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tif (ctx.body instanceof Readable) {\n\t\t\t\tconst body = ctx.body\n\t\t\t\tconst streamTimer = timer('Stream', () => {\n\t\t\t\t\treturn new Promise(resolve => {\n\t\t\t\t\t\tbody.addListener('close', () => {\n\t\t\t\t\t\t\tresolve(null)\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t})\n\n\t\t\t\tstreamTimer.then(emit).catch(emit)\n\t\t\t} else {\n\t\t\t\temit()\n\t\t\t}\n\t\t}\n\t\treturn { timer, send }\n\t}\n\n\tprivate matchRequest<C>(routes: Route<C>[], url: URL): MatchedRequest<C> | null {\n\t\tfor (const route of routes) {\n\t\t\tconst params = route.match({ url })\n\t\t\tif (params !== null) {\n\t\t\t\treturn { params, controller: route.controller, module: route.module, mask: route.mask, carriesCredentials: route.carriesCredentials }\n\t\t\t}\n\t\t}\n\t\treturn null\n\t}\n}\n\nexport type EventTime = { label: string; start: number; duration?: number }\n\nexport const createEventTimer = (tracer: Tracer, times: EventTime[], globalStart: number): Timer => (name, cb) => {\n\tconst start = performance.now()\n\tconst time: EventTime = { label: name, start: Math.round(start - globalStart) }\n\ttimes.push(time)\n\tconst res = tracer.span(name, () => cb())\n\n\tif (res instanceof Promise) {\n\t\t;(async () => {\n\t\t\ttry {\n\t\t\t\tawait res\n\t\t\t} catch {\n\t\t\t} finally {\n\t\t\t\ttime.duration = Math.round(performance.now() - start)\n\t\t\t}\n\t\t})()\n\t}\n\treturn res\n}\n\nconst createTracedReadable = (body: Readable, tracer: Tracer, span: Span): Readable => {\n\tconst iterator = body[Symbol.asyncIterator]()\n\treturn Readable.from((async function*() {\n\t\tlet completed = false\n\t\ttry {\n\t\t\twhile (true) {\n\t\t\t\tconst next = await tracer.withSpan(span, () => iterator.next())\n\t\t\t\tif (next.done) {\n\t\t\t\t\tcompleted = true\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tyield next.value\n\t\t\t}\n\t\t} finally {\n\t\t\tif (!completed && iterator.return !== undefined) {\n\t\t\t\tawait tracer.withSpan(span, () => iterator.return?.())\n\t\t\t}\n\t\t}\n\t})())\n}\n\n/** @deprecated use `tracer` from the request context instead */\nexport type Timer = <T>(event: string, cb: () => T) => T\n\nexport type MatchedRequest<C> = { params: Params; controller: C; module: string; mask: string; carriesCredentials: boolean }\n\nexport type BaseRequestContext = {\n\tlogger: Logger\n\trequest: IncomingMessage\n\turl: URL\n\tparams: Params\n\tclientIp: string\n}\n\nexport type ApplicationContext =\n\t& BaseRequestContext\n\t& {\n\t\tprojectGroup: ProjectGroupContainer\n\t\tauthResult: AuthResult | null\n\t\ttimer: Timer\n\t\ttracer: Tracer\n\t}\n\nexport type BaseHttpRequestContext = {\n\tkoa: KoaContext<{}>\n\tbody: unknown\n\tresponse: ServerResponse\n}\n\nexport type HttpContext =\n\t& ApplicationContext\n\t& BaseHttpRequestContext\n\t& {\n\t\trequestDebugMode: boolean\n\t}\n\nexport type InternalHttpContext =\n\t& BaseRequestContext\n\t& BaseHttpRequestContext\n\nexport type WebSocketContext =\n\t& ApplicationContext\n\t& {\n\t\tws: WebSocket\n\t\tabortSignal: AbortSignal\n\t\twaitUntil(promise: Promise<void>): void\n\t}\n\nexport type HttpControllerResponse = Promise<HttpErrorResponse | undefined | void> | HttpErrorResponse | undefined | void\nexport type HttpController = (context: HttpContext) => HttpControllerResponse\nexport type InternalHttpController = (context: InternalHttpContext) => HttpControllerResponse\n\nexport type WebSocketController = (context: WebSocketContext) => void\n\ntype Params = { [param: string]: string }\n\ntype RequestMatcher = (args: { url: URL }) => Params | null\nconst createRequestMatcher = (\n\tmask: string,\n): RequestMatcher => {\n\tconst { regexp, keys } = pathToRegexp(mask)\n\n\tconst match = function(url: string): Params | null {\n\t\tconst match = regexp.exec(url)\n\t\tif (match) {\n\t\t\treturn match.slice(1).reduce((acc, value, i) => ({ ...acc, [keys[i].name]: value }), {})\n\t\t}\n\t\treturn null\n\t}\n\n\treturn request => {\n\t\treturn match(request.url.pathname)\n\t}\n}\n\nexport const LoggerRequestBody = Symbol('RequestBody')\n\nexport interface RunningApplication {\n\tclose(): Promise<void>\n\treadonly server: Server\n}\n"],"names":["pendingWork","ws","establishedAt","closed","match"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,0BAA0B;AAQzB,MAAM,YAAY;AAAA,EAaxB,YACkB,sBACA,cACA,WACA,SACA,QACA,SAAiB,YACjC;AANgB,SAAA,uBAAA;AACA,SAAA,eAAA;AACA,SAAA,YAAA;AACA,SAAA,UAAA;AACA,SAAA,SAAA;AACA,SAAA,SAAA;AAlBlB,kBAAA,MAAQ,eAAoC,EAAC;AAE7C,kBAAA,MAAQ,UAAkC,EAAC;AAC3C,kBAAA,MAAQ,kBAAkD,EAAC;AAC3D,kBAAA,MAAQ,mBAAgD,EAAC;AAEzD,kBAAA,MAAQ,mBAAA;AACR,kBAAA,MAAQ,gBAAA;AACR,kBAAA,MAAQ,oBAAA;AACR,kBAAA,MAAQ,qBAAA;AACR,kBAAA,MAAQ,uBAAA;AAUP,UAAM,uBAAuB,aAAa,MAAM;AAChD,SAAK,oBAAoB,yBAAyB,OAAO,OAAO,uBAAuB,IAAI,OAAO,oBAAoB,IAAI;AAC1H,SAAK,iBAAiB,aAAa,MAAM,kBAAkB,CAAA;AAC3D,SAAK,qBAAqB,aAAa,MAAM,wBAAwB;AACrE,SAAK,sBAAsB,aAAa,WAAW,QAAQ,kBAAkB;AAC7E,SAAK,wBAAwB,aAAa,WAAW,QAAQ,yBAAyB;AAAA,EACvF;AAAA,EAEA,cAAc,YAAgC;AAC7C,SAAK,YAAY,KAAK,UAAU;AAAA,EACjC;AAAA,EAEO,SAAS,QAAgB,MAAc,YAA4B,UAAwB,CAAA,GAAU;AAC3G,SAAK,OAAO,KAAK;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO,qBAAqB,IAAI;AAAA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M,OAAO,SAAS,MAAM,MAAM,SAAS,UAAU;AAAA,MACtD;AAAA,IACD;AAAA,EACD,IAAI;AACL;AA0DA,MAAM,uBAAuB,CAC5B,SACoB;AACpB,QAAM,EAAE,QAAQ,SAAS,aAAa,IAAI;AAE1C,QAAM,QAAQ,SAAS,KAA4B;AAClD,UAAME,SAAQ,OAAO,KAAK,GAAG;AAC7B,QAAIA,QAAO;AACV,aAAOA,OAAM,MAAM,CAAC,EAAE,OAAO,CAAC,KAAK,OAAO,OAAO,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,GAAG,MAAA,IAAU,EAAE;AAAA,IACxF;AACA,WAAO;AAAA,EACR;AAEA,SAAO,CAAA,YAAW;AACjB,WAAO,MAAM,QAAQ,IAAI,QAAQ;AAAA,EAClC;AACD;AAEO,MAAM,2CAA2B,aAAa;"}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const node_stream = require("node:stream");
4
+ const zlib = require("node:zlib");
5
+ function _interopNamespaceDefault(e) {
6
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
7
+ if (e) {
8
+ for (const k in e) {
9
+ if (k !== "default") {
10
+ const d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: () => e[k]
14
+ });
15
+ }
16
+ }
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+ const zlib__namespace = /* @__PURE__ */ _interopNamespaceDefault(zlib);
22
+ const compressors = {
23
+ zstd: () => zlib__namespace.createZstdCompress(),
24
+ gzip: () => zlib__namespace.createGzip(),
25
+ deflate: () => zlib__namespace.createDeflate()
26
+ };
27
+ const offeredEncodings = typeof zlib__namespace.createZstdCompress === "function" ? ["zstd", "gzip", "deflate"] : ["gzip", "deflate"];
28
+ const parseAcceptEncoding = (header) => header.split(",").flatMap((item) => {
29
+ const match = /^\s*([^\s;]+)\s*(?:;(.*))?$/.exec(item.trim());
30
+ if (!match) {
31
+ return [];
32
+ }
33
+ const qualityParameter = (match[2] ?? "").split(";").map((it) => it.trim().split("=")).find(([name]) => name === "q");
34
+ const quality = qualityParameter ? Number.parseFloat(qualityParameter[1]) : 1;
35
+ return [{ name: match[1].toLowerCase(), quality: Number.isNaN(quality) ? 0 : quality }];
36
+ });
37
+ const negotiateEncoding = (header) => {
38
+ if (header === "") {
39
+ return void 0;
40
+ }
41
+ if (header === "*") {
42
+ return "gzip";
43
+ }
44
+ const accepted = parseAcceptEncoding(header);
45
+ const quality = (name) => {
46
+ const exact = accepted.filter((it) => it.name === name);
47
+ const matching = exact.length > 0 ? exact : accepted.filter((it) => it.name === "*");
48
+ return matching.length > 0 ? Math.max(...matching.map((it) => it.quality)) : void 0;
49
+ };
50
+ const identityQuality = quality("identity") ?? Math.min(1, ...accepted.map((it) => it.quality || 1));
51
+ let best = { encoding: void 0, quality: identityQuality > 0 ? identityQuality : 0 };
52
+ for (const encoding of offeredEncodings) {
53
+ const encodingQuality = quality(encoding) ?? 0;
54
+ if (encodingQuality > 0 && (encodingQuality > best.quality || encodingQuality === best.quality && best.encoding === void 0)) {
55
+ best = { encoding, quality: encodingQuality };
56
+ }
57
+ }
58
+ return best.encoding;
59
+ };
60
+ const compressibleTypes = /* @__PURE__ */ new Set(["application/json", "application/javascript", "application/xml", "application/wasm"]);
61
+ const isCompressibleType = (type) => {
62
+ const normalized = type.toLowerCase();
63
+ return compressibleTypes.has(normalized) || /^text\/|\+(?:json|text|xml)$/.test(normalized);
64
+ };
65
+ const threshold = 1024;
66
+ const emptyBodyStatuses = /* @__PURE__ */ new Set([204, 205, 304]);
67
+ const noTransform = /(?:^|,)\s*?no-transform\s*?(?:,|$)/;
68
+ const shouldCompress = (ctx) => {
69
+ const response = ctx.response;
70
+ if (!ctx.body || ctx.res.headersSent || !ctx.writable || ctx.compress === false || ctx.method === "HEAD" || emptyBodyStatuses.has(response.status) || response.get("Content-Encoding") || !(ctx.compress === true || isCompressibleType(response.type)) || noTransform.test(response.get("Cache-Control"))) {
71
+ return false;
72
+ }
73
+ return response.length === void 0 || response.length >= threshold;
74
+ };
75
+ const createCompressionMiddleware = () => async (ctx, next) => {
76
+ ctx.vary("Accept-Encoding");
77
+ await next();
78
+ if (!shouldCompress(ctx)) {
79
+ return;
80
+ }
81
+ const encoding = negotiateEncoding(ctx.get("Accept-Encoding"));
82
+ if (encoding === void 0) {
83
+ return;
84
+ }
85
+ const body = ctx.body;
86
+ const compressed = compressors[encoding]();
87
+ ctx.set("Content-Encoding", encoding);
88
+ ctx.res.removeHeader("Content-Length");
89
+ ctx.body = compressed;
90
+ if (body instanceof node_stream.Stream) {
91
+ body.pipe(compressed);
92
+ } else {
93
+ compressed.end(typeof body === "string" || Buffer.isBuffer(body) ? body : JSON.stringify(body));
94
+ }
95
+ };
96
+ exports.createCompressionMiddleware = createCompressionMiddleware;
97
+ exports.isCompressibleType = isCompressibleType;
98
+ exports.negotiateEncoding = negotiateEncoding;
99
+ //# sourceMappingURL=compression.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.cjs","sources":["../../../../../packages/engine-http/src/application/compression.ts"],"sourcesContent":["import { Stream, Transform } from 'node:stream'\nimport * as zlib from 'node:zlib'\nimport type * as Koa from 'koa'\n\ndeclare module 'koa' {\n\tinterface DefaultContext {\n\t\t/** `true` compresses a response whose type is not compressible by default, `false` never compresses it. */\n\t\tcompress?: boolean\n\t}\n}\n\ntype Encoding = 'zstd' | 'gzip' | 'deflate'\n\nconst compressors: Readonly<Record<Encoding, () => Transform>> = {\n\tzstd: () => zlib.createZstdCompress(),\n\tgzip: () => zlib.createGzip(),\n\tdeflate: () => zlib.createDeflate(),\n}\n\n// zstd needs Node 22.15 or 23.8; a tie in quality goes to the first listed. Brotli stays off, as it was.\nconst offeredEncodings: readonly Encoding[] = typeof zlib.createZstdCompress === 'function' ? ['zstd', 'gzip', 'deflate'] : ['gzip', 'deflate']\n\ntype AcceptedEncoding = { readonly name: string; readonly quality: number }\n\nconst parseAcceptEncoding = (header: string): AcceptedEncoding[] =>\n\theader.split(',').flatMap(item => {\n\t\tconst match = /^\\s*([^\\s;]+)\\s*(?:;(.*))?$/.exec(item.trim())\n\t\tif (!match) {\n\t\t\treturn []\n\t\t}\n\t\tconst qualityParameter = (match[2] ?? '').split(';').map(it => it.trim().split('=')).find(([name]) => name === 'q')\n\t\tconst quality = qualityParameter ? Number.parseFloat(qualityParameter[1]) : 1\n\t\treturn [{ name: match[1].toLowerCase(), quality: Number.isNaN(quality) ? 0 : quality }]\n\t})\n\n/**\n * The best encoding the client accepts (RFC 9110 §12.5.3), or `undefined` for identity. An exact entry outranks `*`,\n * and identity, unless listed, is acceptable at the lowest quality given. No header means identity, a bare `*` gzip.\n */\nexport const negotiateEncoding = (header: string): Encoding | undefined => {\n\tif (header === '') {\n\t\treturn undefined\n\t}\n\tif (header === '*') {\n\t\treturn 'gzip'\n\t}\n\tconst accepted = parseAcceptEncoding(header)\n\tconst quality = (name: string): number | undefined => {\n\t\tconst exact = accepted.filter(it => it.name === name)\n\t\tconst matching = exact.length > 0 ? exact : accepted.filter(it => it.name === '*')\n\t\treturn matching.length > 0 ? Math.max(...matching.map(it => it.quality)) : undefined\n\t}\n\tconst identityQuality = quality('identity') ?? Math.min(1, ...accepted.map(it => it.quality || 1))\n\tlet best: { encoding: Encoding | undefined; quality: number } = { encoding: undefined, quality: identityQuality > 0 ? identityQuality : 0 }\n\tfor (const encoding of offeredEncodings) {\n\t\tconst encodingQuality = quality(encoding) ?? 0\n\t\t// identity is the last preference, so an encoding wins a tie with it\n\t\tif (encodingQuality > 0 && (encodingQuality > best.quality || (encodingQuality === best.quality && best.encoding === undefined))) {\n\t\t\tbest = { encoding, quality: encodingQuality }\n\t\t}\n\t}\n\treturn best.encoding\n}\n\nconst compressibleTypes: ReadonlySet<string> = new Set(['application/json', 'application/javascript', 'application/xml', 'application/wasm'])\n\n/** The media types the engine serves as text: JSON, HTML, plain text, scripts, styles, SVG. */\nexport const isCompressibleType = (type: string): boolean => {\n\tconst normalized = type.toLowerCase()\n\treturn compressibleTypes.has(normalized) || /^text\\/|\\+(?:json|text|xml)$/.test(normalized)\n}\n\nconst threshold = 1024\nconst emptyBodyStatuses: ReadonlySet<number> = new Set([204, 205, 304])\nconst noTransform = /(?:^|,)\\s*?no-transform\\s*?(?:,|$)/\n\nconst shouldCompress = (ctx: Koa.Context): boolean => {\n\tconst response = ctx.response\n\tif (\n\t\t!ctx.body\n\t\t|| ctx.res.headersSent\n\t\t|| !ctx.writable\n\t\t|| ctx.compress === false\n\t\t|| ctx.method === 'HEAD'\n\t\t|| emptyBodyStatuses.has(response.status)\n\t\t|| response.get('Content-Encoding')\n\t\t|| !(ctx.compress === true || isCompressibleType(response.type))\n\t\t|| noTransform.test(response.get('Cache-Control'))\n\t) {\n\t\treturn false\n\t}\n\t// a stream has no known length and is always compressed\n\treturn response.length === undefined || response.length >= threshold\n}\n\n/** Compresses responses of 1 KiB and more, or of unknown length, with zstd, gzip or deflate, as the client accepts. */\nexport const createCompressionMiddleware = (): Koa.Middleware => async (ctx, next) => {\n\tctx.vary('Accept-Encoding')\n\tawait next()\n\n\tif (!shouldCompress(ctx)) {\n\t\treturn\n\t}\n\tconst encoding = negotiateEncoding(ctx.get('Accept-Encoding'))\n\tif (encoding === undefined) {\n\t\treturn\n\t}\n\tconst body: unknown = ctx.body\n\tconst compressed = compressors[encoding]()\n\tctx.set('Content-Encoding', encoding)\n\tctx.res.removeHeader('Content-Length')\n\tctx.body = compressed\n\tif (body instanceof Stream) {\n\t\tbody.pipe(compressed)\n\t} else {\n\t\tcompressed.end(typeof body === 'string' || Buffer.isBuffer(body) ? body : JSON.stringify(body))\n\t}\n}\n"],"names":["zlib","Stream"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAaA,MAAM,cAA2D;AAAA,EAChE,MAAM,MAAMA,gBAAK,mBAAA;AAAA,EACjB,MAAM,MAAMA,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ACD;AACA,QAAM,OAAgB,IAAI;AAC1B,QAAM,aAAa,YAAY,QAAQ,EAAA;AACvC,MAAI,IAAI,oBAAoB,QAAQ;AACpC,MAAI,IAAI,aAAa,gBAAgB;AACrC,MAAI,OAAO;AACX,MAAI,gBAAgBC,YAAAA,QAAQ;AAC3B,SAAK,KAAK,UAAU;AAAA,EACrB,OAAO;AACN,eAAW,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,IAAI,IAAI,OAAO,KAAK,UAAU,IAAI,CAAC;AAAA,EAC/F;AACD;;;;"}
@@ -0,0 +1,82 @@
1
+ import { Stream } from "node:stream";
2
+ import * as zlib from "node:zlib";
3
+ const compressors = {
4
+ zstd: () => zlib.createZstdCompress(),
5
+ gzip: () => zlib.createGzip(),
6
+ deflate: () => zlib.createDeflate()
7
+ };
8
+ const offeredEncodings = typeof zlib.createZstdCompress === "function" ? ["zstd", "gzip", "deflate"] : ["gzip", "deflate"];
9
+ const parseAcceptEncoding = (header) => header.split(",").flatMap((item) => {
10
+ const match = /^\s*([^\s;]+)\s*(?:;(.*))?$/.exec(item.trim());
11
+ if (!match) {
12
+ return [];
13
+ }
14
+ const qualityParameter = (match[2] ?? "").split(";").map((it) => it.trim().split("=")).find(([name]) => name === "q");
15
+ const quality = qualityParameter ? Number.parseFloat(qualityParameter[1]) : 1;
16
+ return [{ name: match[1].toLowerCase(), quality: Number.isNaN(quality) ? 0 : quality }];
17
+ });
18
+ const negotiateEncoding = (header) => {
19
+ if (header === "") {
20
+ return void 0;
21
+ }
22
+ if (header === "*") {
23
+ return "gzip";
24
+ }
25
+ const accepted = parseAcceptEncoding(header);
26
+ const quality = (name) => {
27
+ const exact = accepted.filter((it) => it.name === name);
28
+ const matching = exact.length > 0 ? exact : accepted.filter((it) => it.name === "*");
29
+ return matching.length > 0 ? Math.max(...matching.map((it) => it.quality)) : void 0;
30
+ };
31
+ const identityQuality = quality("identity") ?? Math.min(1, ...accepted.map((it) => it.quality || 1));
32
+ let best = { encoding: void 0, quality: identityQuality > 0 ? identityQuality : 0 };
33
+ for (const encoding of offeredEncodings) {
34
+ const encodingQuality = quality(encoding) ?? 0;
35
+ if (encodingQuality > 0 && (encodingQuality > best.quality || encodingQuality === best.quality && best.encoding === void 0)) {
36
+ best = { encoding, quality: encodingQuality };
37
+ }
38
+ }
39
+ return best.encoding;
40
+ };
41
+ const compressibleTypes = /* @__PURE__ */ new Set(["application/json", "application/javascript", "application/xml", "application/wasm"]);
42
+ const isCompressibleType = (type) => {
43
+ const normalized = type.toLowerCase();
44
+ return compressibleTypes.has(normalized) || /^text\/|\+(?:json|text|xml)$/.test(normalized);
45
+ };
46
+ const threshold = 1024;
47
+ const emptyBodyStatuses = /* @__PURE__ */ new Set([204, 205, 304]);
48
+ const noTransform = /(?:^|,)\s*?no-transform\s*?(?:,|$)/;
49
+ const shouldCompress = (ctx) => {
50
+ const response = ctx.response;
51
+ if (!ctx.body || ctx.res.headersSent || !ctx.writable || ctx.compress === false || ctx.method === "HEAD" || emptyBodyStatuses.has(response.status) || response.get("Content-Encoding") || !(ctx.compress === true || isCompressibleType(response.type)) || noTransform.test(response.get("Cache-Control"))) {
52
+ return false;
53
+ }
54
+ return response.length === void 0 || response.length >= threshold;
55
+ };
56
+ const createCompressionMiddleware = () => async (ctx, next) => {
57
+ ctx.vary("Accept-Encoding");
58
+ await next();
59
+ if (!shouldCompress(ctx)) {
60
+ return;
61
+ }
62
+ const encoding = negotiateEncoding(ctx.get("Accept-Encoding"));
63
+ if (encoding === void 0) {
64
+ return;
65
+ }
66
+ const body = ctx.body;
67
+ const compressed = compressors[encoding]();
68
+ ctx.set("Content-Encoding", encoding);
69
+ ctx.res.removeHeader("Content-Length");
70
+ ctx.body = compressed;
71
+ if (body instanceof Stream) {
72
+ body.pipe(compressed);
73
+ } else {
74
+ compressed.end(typeof body === "string" || Buffer.isBuffer(body) ? body : JSON.stringify(body));
75
+ }
76
+ };
77
+ export {
78
+ createCompressionMiddleware,
79
+ isCompressibleType,
80
+ negotiateEncoding
81
+ };
82
+ //# sourceMappingURL=compression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.js","sources":["../../../../../packages/engine-http/src/application/compression.ts"],"sourcesContent":["import { Stream, Transform } from 'node:stream'\nimport * as zlib from 'node:zlib'\nimport type * as Koa from 'koa'\n\ndeclare module 'koa' {\n\tinterface DefaultContext {\n\t\t/** `true` compresses a response whose type is not compressible by default, `false` never compresses it. */\n\t\tcompress?: boolean\n\t}\n}\n\ntype Encoding = 'zstd' | 'gzip' | 'deflate'\n\nconst compressors: Readonly<Record<Encoding, () => Transform>> = {\n\tzstd: () => zlib.createZstdCompress(),\n\tgzip: () => zlib.createGzip(),\n\tdeflate: () => zlib.createDeflate(),\n}\n\n// zstd needs Node 22.15 or 23.8; a tie in quality goes to the first listed. Brotli stays off, as it was.\nconst offeredEncodings: readonly Encoding[] = typeof zlib.createZstdCompress === 'function' ? ['zstd', 'gzip', 'deflate'] : ['gzip', 'deflate']\n\ntype AcceptedEncoding = { readonly name: string; readonly quality: number }\n\nconst parseAcceptEncoding = (header: string): AcceptedEncoding[] =>\n\theader.split(',').flatMap(item => {\n\t\tconst match = /^\\s*([^\\s;]+)\\s*(?:;(.*))?$/.exec(item.trim())\n\t\tif (!match) {\n\t\t\treturn []\n\t\t}\n\t\tconst qualityParameter = (match[2] ?? '').split(';').map(it => it.trim().split('=')).find(([name]) => name === 'q')\n\t\tconst quality = qualityParameter ? Number.parseFloat(qualityParameter[1]) : 1\n\t\treturn [{ name: match[1].toLowerCase(), quality: Number.isNaN(quality) ? 0 : quality }]\n\t})\n\n/**\n * The best encoding the client accepts (RFC 9110 §12.5.3), or `undefined` for identity. An exact entry outranks `*`,\n * and identity, unless listed, is acceptable at the lowest quality given. No header means identity, a bare `*` gzip.\n */\nexport const negotiateEncoding = (header: string): Encoding | undefined => {\n\tif (header === '') {\n\t\treturn undefined\n\t}\n\tif (header === '*') {\n\t\treturn 'gzip'\n\t}\n\tconst accepted = parseAcceptEncoding(header)\n\tconst quality = (name: string): number | undefined => {\n\t\tconst exact = accepted.filter(it => it.name === name)\n\t\tconst matching = exact.length > 0 ? exact : accepted.filter(it => it.name === '*')\n\t\treturn matching.length > 0 ? Math.max(...matching.map(it => it.quality)) : undefined\n\t}\n\tconst identityQuality = quality('identity') ?? Math.min(1, ...accepted.map(it => it.quality || 1))\n\tlet best: { encoding: Encoding | undefined; quality: number } = { encoding: undefined, quality: identityQuality > 0 ? identityQuality : 0 }\n\tfor (const encoding of offeredEncodings) {\n\t\tconst encodingQuality = quality(encoding) ?? 0\n\t\t// identity is the last preference, so an encoding wins a tie with it\n\t\tif (encodingQuality > 0 && (encodingQuality > best.quality || (encodingQuality === best.quality && best.encoding === undefined))) {\n\t\t\tbest = { encoding, quality: encodingQuality }\n\t\t}\n\t}\n\treturn best.encoding\n}\n\nconst compressibleTypes: ReadonlySet<string> = new Set(['application/json', 'application/javascript', 'application/xml', 'application/wasm'])\n\n/** The media types the engine serves as text: JSON, HTML, plain text, scripts, styles, SVG. */\nexport const isCompressibleType = (type: string): boolean => {\n\tconst normalized = type.toLowerCase()\n\treturn compressibleTypes.has(normalized) || /^text\\/|\\+(?:json|text|xml)$/.test(normalized)\n}\n\nconst threshold = 1024\nconst emptyBodyStatuses: ReadonlySet<number> = new Set([204, 205, 304])\nconst noTransform = /(?:^|,)\\s*?no-transform\\s*?(?:,|$)/\n\nconst shouldCompress = (ctx: Koa.Context): boolean => {\n\tconst response = ctx.response\n\tif (\n\t\t!ctx.body\n\t\t|| ctx.res.headersSent\n\t\t|| !ctx.writable\n\t\t|| ctx.compress === false\n\t\t|| ctx.method === 'HEAD'\n\t\t|| emptyBodyStatuses.has(response.status)\n\t\t|| response.get('Content-Encoding')\n\t\t|| !(ctx.compress === true || isCompressibleType(response.type))\n\t\t|| noTransform.test(response.get('Cache-Control'))\n\t) {\n\t\treturn false\n\t}\n\t// a stream has no known length and is always compressed\n\treturn response.length === undefined || response.length >= threshold\n}\n\n/** Compresses responses of 1 KiB and more, or of unknown length, with zstd, gzip or deflate, as the client accepts. */\nexport const createCompressionMiddleware = (): Koa.Middleware => async (ctx, next) => {\n\tctx.vary('Accept-Encoding')\n\tawait next()\n\n\tif (!shouldCompress(ctx)) {\n\t\treturn\n\t}\n\tconst encoding = negotiateEncoding(ctx.get('Accept-Encoding'))\n\tif (encoding === undefined) {\n\t\treturn\n\t}\n\tconst body: unknown = ctx.body\n\tconst compressed = compressors[encoding]()\n\tctx.set('Content-Encoding', encoding)\n\tctx.res.removeHeader('Content-Length')\n\tctx.body = compressed\n\tif (body instanceof Stream) {\n\t\tbody.pipe(compressed)\n\t} else {\n\t\tcompressed.end(typeof body === 'string' || Buffer.isBuffer(body) ? body : JSON.stringify(body))\n\t}\n}\n"],"names":[],"mappings":";;AAaA,MAAM,cAA2D;AAAA,EAChE,MAAM,MAAM,KAAK,mBAAA;AAAA,EACjB,MAAM,MAAM,KAAK,WAAA;AAAA,EACjB,SAAS,MAAM,KAAK,cAAA;AACrB;AAGA,MAAM,mBAAwC,OAAO,KAAK,uBAAuB,aAAa,CAAC,QAAQ,QAAQ,SAAS,IAAI,CAAC,QAAQ,SAAS;AAI9I,MAAM,sBAAsB,CAAC,WAC5B,OAAO,MAAM,GAAG,EAAE,QAAQ,CAAA,SAAQ;AACjC,QAAM,QAAQ,8BAA8B,KAAK,KAAK,MAAM;AAC5D,MAAI,CAAC,OAAO;AACX,WAAO,CAAA;AAAA,EACR;AACA,QAAM,oBAAoB,MAAM,CAAC,KAAK,IAAI,MAAM,GAAG,EAAE,IAAI,CAAA,OAAM,GAAG,OAAO,MAAM,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,MAAM,SAAS,GAAG;AAClH,QAAM,UAAU,mBAAmB,OAAO,WAAW,iBAAiB,CAAC,CAAC,IAAI;AAC5E,SAAO,CAAC,EAAE,MAAM,MAAM,CAAC,EAAE,YAAA,GAAe,SAAS,OAAO,MAAM,OAAO,IAAI,IAAI,SAAS;AACvF,CAAC;A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rB,MACC,CAAC,IAAI,QACF,IAAI,IAAI,eACR,CAAC,IAAI,YACL,IAAI,aAAa,SACjB,IAAI,WAAW,UACf,kBAAkB,IAAI,SAAS,MAAM,KACrC,SAAS,IAAI,kBAAkB,KAC/B,EAAE,IAAI,aAAa,QAAQ,mBAAmB,SAAS,IAAI,MAC3D,YAAY,KAAK,SAAS,IAAI,eAAe,CAAC,GAChD;AACD,WAAO;AAAA,EACR;AAEA,SAAO,SAAS,WAAW,UAAa,SAAS,UAAU;AAC5D;AAGO,MAAM,8BAA8B,MAAsB,OAAO,KAAK,SAAS;AACrF,MAAI,KAAK,iBAAiB;AAC1B,QAAM,KAAA;AAEN,MAAI,CAAC,eAAe,GAAG,GAAG;AACzB;AAAA,EACD;AACA,QAAM,WAAW,kBAAkB,IAAI,IAAI,iBAAiB,CAAC;AAC7D,MAAI,aAAa,QAAW;AAC3B;AAAA,EACD;AACA,QAAM,OAAgB,IAAI;AAC1B,QAAM,aAAa,YAAY,QAAQ,EAAA;AACvC,MAAI,IAAI,oBAAoB,QAAQ;AACpC,MAAI,IAAI,aAAa,gBAAgB;AACrC,MAAI,OAAO;AACX,MAAI,gBAAgB,QAAQ;AAC3B,SAAK,KAAK,UAAU;AAAA,EACrB,OAAO;AACN,eAAW,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,IAAI,IAAI,OAAO,KAAK,UAAU,IAAI,CAAC;AAAA,EAC/F;AACD;"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const allowMethods = "GET,HEAD,PUT,POST,DELETE,PATCH";
4
+ const appendVary = (current, field) => {
5
+ const fields = current.split(",").map((it) => it.trim().toLowerCase());
6
+ if (fields.includes("*") || fields.includes(field.toLowerCase())) {
7
+ return current;
8
+ }
9
+ return current.trim() ? `${current}, ${field}` : field;
10
+ };
11
+ const createCorsMiddleware = ({ exposeHeaders }) => {
12
+ const exposeHeadersValue = exposeHeaders.join(",");
13
+ return async (ctx, next) => {
14
+ ctx.vary("Origin");
15
+ if (ctx.method === "OPTIONS") {
16
+ if (!ctx.get("Access-Control-Request-Method")) {
17
+ return await next();
18
+ }
19
+ ctx.set("Access-Control-Allow-Origin", "*");
20
+ ctx.set("Access-Control-Allow-Methods", allowMethods);
21
+ const requestHeaders = ctx.get("Access-Control-Request-Headers");
22
+ if (requestHeaders) {
23
+ ctx.set("Access-Control-Allow-Headers", requestHeaders);
24
+ }
25
+ ctx.status = 204;
26
+ return;
27
+ }
28
+ const corsHeaders = { "Access-Control-Allow-Origin": "*" };
29
+ if (exposeHeadersValue) {
30
+ corsHeaders["Access-Control-Expose-Headers"] = exposeHeadersValue;
31
+ }
32
+ ctx.set(corsHeaders);
33
+ try {
34
+ return await next();
35
+ } catch (error) {
36
+ if (typeof error === "object" && error !== null) {
37
+ const errorHeaders = Reflect.get(error, "headers");
38
+ const headers = typeof errorHeaders === "object" && errorHeaders !== null ? { ...errorHeaders } : {};
39
+ const vary = headers.vary ?? headers.Vary;
40
+ delete headers.Vary;
41
+ Reflect.set(error, "headers", {
42
+ ...headers,
43
+ ...corsHeaders,
44
+ vary: appendVary(typeof vary === "string" ? vary : "", "Origin")
45
+ });
46
+ }
47
+ throw error;
48
+ }
49
+ };
50
+ };
51
+ exports.createCorsMiddleware = createCorsMiddleware;
52
+ //# sourceMappingURL=cors.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cors.cjs","sources":["../../../../../packages/engine-http/src/application/cors.ts"],"sourcesContent":["import { KoaMiddleware } from './types.js'\n\nconst allowMethods = 'GET,HEAD,PUT,POST,DELETE,PATCH'\n\nconst appendVary = (current: string, field: string): string => {\n\tconst fields = current.split(',').map(it => it.trim().toLowerCase())\n\tif (fields.includes('*') || fields.includes(field.toLowerCase())) {\n\t\treturn current\n\t}\n\treturn current.trim() ? `${current}, ${field}` : field\n}\n\n/**\n * Permissive CORS for any origin without credentials. Preflights (OPTIONS with\n * Access-Control-Request-Method) are answered with 204 and echo the requested headers.\n * The CORS headers survive an error thrown by the downstream handler.\n */\nexport const createCorsMiddleware = ({ exposeHeaders }: { exposeHeaders: readonly string[] }): KoaMiddleware<unknown> => {\n\tconst exposeHeadersValue = exposeHeaders.join(',')\n\n\treturn async (ctx, next) => {\n\t\tctx.vary('Origin')\n\n\t\tif (ctx.method === 'OPTIONS') {\n\t\t\tif (!ctx.get('Access-Control-Request-Method')) {\n\t\t\t\treturn await next()\n\t\t\t}\n\t\t\tctx.set('Access-Control-Allow-Origin', '*')\n\t\t\tctx.set('Access-Control-Allow-Methods', allowMethods)\n\t\t\tconst requestHeaders = ctx.get('Access-Control-Request-Headers')\n\t\t\tif (requestHeaders) {\n\t\t\t\tctx.set('Access-Control-Allow-Headers', requestHeaders)\n\t\t\t}\n\t\t\tctx.status = 204\n\t\t\treturn\n\t\t}\n\n\t\tconst corsHeaders: Record<string, string> = { 'Access-Control-Allow-Origin': '*' }\n\t\tif (exposeHeadersValue) {\n\t\t\tcorsHeaders['Access-Control-Expose-Headers'] = exposeHeadersValue\n\t\t}\n\t\tctx.set(corsHeaders)\n\t\ttry {\n\t\t\treturn await next()\n\t\t} catch (error) {\n\t\t\t// Koa's error handler resets the response headers and applies `error.headers` instead.\n\t\t\tif (typeof error === 'object' && error !== null) {\n\t\t\t\tconst errorHeaders: unknown = Reflect.get(error, 'headers')\n\t\t\t\tconst headers: Record<string, unknown> = typeof errorHeaders === 'object' && errorHeaders !== null ? { ...errorHeaders } : {}\n\t\t\t\tconst vary = headers.vary ?? headers.Vary\n\t\t\t\tdelete headers.Vary\n\t\t\t\tReflect.set(error, 'headers', {\n\t\t\t\t\t...headers,\n\t\t\t\t\t...corsHeaders,\n\t\t\t\t\tvary: appendVary(typeof vary === 'string' ? vary : '', 'Origin'),\n\t\t\t\t})\n\t\t\t}\n\t\t\tthrow error\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;AAEA,MAAM,eAAe;AAErB,MAAM,aAAa,CAAC,SAAiB,UAA0B;AA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AO,IAAI,QAAQ;AAAA,QAAA,CAC/D;AAAA,MACF;AACA,YAAM;AAAA,IACP;AAAA,EACD;AACD;;"}
@@ -0,0 +1,52 @@
1
+ const allowMethods = "GET,HEAD,PUT,POST,DELETE,PATCH";
2
+ const appendVary = (current, field) => {
3
+ const fields = current.split(",").map((it) => it.trim().toLowerCase());
4
+ if (fields.includes("*") || fields.includes(field.toLowerCase())) {
5
+ return current;
6
+ }
7
+ return current.trim() ? `${current}, ${field}` : field;
8
+ };
9
+ const createCorsMiddleware = ({ exposeHeaders }) => {
10
+ const exposeHeadersValue = exposeHeaders.join(",");
11
+ return async (ctx, next) => {
12
+ ctx.vary("Origin");
13
+ if (ctx.method === "OPTIONS") {
14
+ if (!ctx.get("Access-Control-Request-Method")) {
15
+ return await next();
16
+ }
17
+ ctx.set("Access-Control-Allow-Origin", "*");
18
+ ctx.set("Access-Control-Allow-Methods", allowMethods);
19
+ const requestHeaders = ctx.get("Access-Control-Request-Headers");
20
+ if (requestHeaders) {
21
+ ctx.set("Access-Control-Allow-Headers", requestHeaders);
22
+ }
23
+ ctx.status = 204;
24
+ return;
25
+ }
26
+ const corsHeaders = { "Access-Control-Allow-Origin": "*" };
27
+ if (exposeHeadersValue) {
28
+ corsHeaders["Access-Control-Expose-Headers"] = exposeHeadersValue;
29
+ }
30
+ ctx.set(corsHeaders);
31
+ try {
32
+ return await next();
33
+ } catch (error) {
34
+ if (typeof error === "object" && error !== null) {
35
+ const errorHeaders = Reflect.get(error, "headers");
36
+ const headers = typeof errorHeaders === "object" && errorHeaders !== null ? { ...errorHeaders } : {};
37
+ const vary = headers.vary ?? headers.Vary;
38
+ delete headers.Vary;
39
+ Reflect.set(error, "headers", {
40
+ ...headers,
41
+ ...corsHeaders,
42
+ vary: appendVary(typeof vary === "string" ? vary : "", "Origin")
43
+ });
44
+ }
45
+ throw error;
46
+ }
47
+ };
48
+ };
49
+ export {
50
+ createCorsMiddleware
51
+ };
52
+ //# sourceMappingURL=cors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cors.js","sources":["../../../../../packages/engine-http/src/application/cors.ts"],"sourcesContent":["import { KoaMiddleware } from './types.js'\n\nconst allowMethods = 'GET,HEAD,PUT,POST,DELETE,PATCH'\n\nconst appendVary = (current: string, field: string): string => {\n\tconst fields = current.split(',').map(it => it.trim().toLowerCase())\n\tif (fields.includes('*') || fields.includes(field.toLowerCase())) {\n\t\treturn current\n\t}\n\treturn current.trim() ? `${current}, ${field}` : field\n}\n\n/**\n * Permissive CORS for any origin without credentials. Preflights (OPTIONS with\n * Access-Control-Request-Method) are answered with 204 and echo the requested headers.\n * The CORS headers survive an error thrown by the downstream handler.\n */\nexport const createCorsMiddleware = ({ exposeHeaders }: { exposeHeaders: readonly string[] }): KoaMiddleware<unknown> => {\n\tconst exposeHeadersValue = exposeHeaders.join(',')\n\n\treturn async (ctx, next) => {\n\t\tctx.vary('Origin')\n\n\t\tif (ctx.method === 'OPTIONS') {\n\t\t\tif (!ctx.get('Access-Control-Request-Method')) {\n\t\t\t\treturn await next()\n\t\t\t}\n\t\t\tctx.set('Access-Control-Allow-Origin', '*')\n\t\t\tctx.set('Access-Control-Allow-Methods', allowMethods)\n\t\t\tconst requestHeaders = ctx.get('Access-Control-Request-Headers')\n\t\t\tif (requestHeaders) {\n\t\t\t\tctx.set('Access-Control-Allow-Headers', requestHeaders)\n\t\t\t}\n\t\t\tctx.status = 204\n\t\t\treturn\n\t\t}\n\n\t\tconst corsHeaders: Record<string, string> = { 'Access-Control-Allow-Origin': '*' }\n\t\tif (exposeHeadersValue) {\n\t\t\tcorsHeaders['Access-Control-Expose-Headers'] = exposeHeadersValue\n\t\t}\n\t\tctx.set(corsHeaders)\n\t\ttry {\n\t\t\treturn await next()\n\t\t} catch (error) {\n\t\t\t// Koa's error handler resets the response headers and applies `error.headers` instead.\n\t\t\tif (typeof error === 'object' && error !== null) {\n\t\t\t\tconst errorHeaders: unknown = Reflect.get(error, 'headers')\n\t\t\t\tconst headers: Record<string, unknown> = typeof errorHeaders === 'object' && errorHeaders !== null ? { ...errorHeaders } : {}\n\t\t\t\tconst vary = headers.vary ?? headers.Vary\n\t\t\t\tdelete headers.Vary\n\t\t\t\tReflect.set(error, 'headers', {\n\t\t\t\t\t...headers,\n\t\t\t\t\t...corsHeaders,\n\t\t\t\t\tvary: appendVary(typeof vary === 'string' ? vary : '', 'Origin'),\n\t\t\t\t})\n\t\t\t}\n\t\t\tthrow error\n\t\t}\n\t}\n}\n"],"names":[],"mappings":"AAEA,MAAM,eAAe;AAErB,MAAM,aAAa,CAAC,SAAiB,UAA0B;AAC9D,QAAM,SAAS,QAAQ,MAAM,GAAG,EAAE,IAAI,CAAA,OAAM,GAAG,KAAA,EAAO,YAAA,CAAa;AACnE,MAAI,OAAO,SAAS,GAAG,KAAK,OAAO,SAAS,MAAM,YAAA,CAAa,GAAG;AACjE,WAAO;AAAA,EACR;AACA,SAAO,QAAQ,KAAA,IAAS,GAAG,OAAO,KAAK,KAAK,KAAK;AAClD;AAOO,MAAM,uBAAuB,CAAC,EAAE,oBAAkF;AACxH,QAAM,qBAAqB,cAAc,KAAK,GAAG;AAEjD,SAAO,OAAO,KAAK,SAAS;AAC3B,QAAI,KAAK,QAAQ;AAEjB,QAAI,IAAI,WAAW,WAAW;AAC7B,UAAI,CAAC,IAAI,IAAI,+BAA+B,GAAG;AAC9C,eAAO,MAAM,KAAA;AAAA,MACd;AACA,UAAI,IAAI,+BAA+B,GAAG;AAC1C,UAAI,IAAI,gCAAgC,YAAY;AACpD,YAAM,iBAAiB,IAAI,IAAI,gCAAgC;AAC/D,UAAI,gBAAgB;AACnB,YAAI,IAAI,gCAAgC,cAAc;AAAA,MACvD;AACA,UAAI,SAAS;AACb;AAAA,IACD;AAEA,UAAM,cAAsC,EAAE,+BAA+B,IAAA;AAC7E,QAAI,oBAAoB;AACvB,kBAAY,+BAA+B,IAAI;AAAA,IAChD;AACA,QAAI,IAAI,WAAW;AACnB,QAAI;AACH,aAAO,MAAM,KAAA;AAAA,IACd,SAAS,OAAO;AAEf,UAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAChD,cAAM,eAAwB,QAAQ,IAAI,OAAO,SAAS;AAC1D,cAAM,UAAmC,OAAO,iBAAiB,YAAY,iBAAiB,OAAO,EAAE,GAAG,aAAA,IAAiB,CAAA;AAC3H,cAAM,OAAO,QAAQ,QAAQ,QAAQ;AACrC,eAAO,QAAQ;AACf,gBAAQ,IAAI,OAAO,WAAW;AAAA,UAC7B,GAAG;AAAA,UACH,GAAG;AAAA,UACH,MAAM,WAAW,OAAO,SAAS,WAAW,OAAO,IAAI,QAAQ;AAAA,QAAA,CAC/D;AAAA,MACF;AACA,YAAM;AAAA,IACP;AAAA,EACD;AACD;"}
@@ -1,16 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const truthyHeader = require("../utils/truthyHeader.cjs");
3
4
  const forceHttpOkHeader = "x-contember-force-ok";
4
5
  const graphqlModules = /* @__PURE__ */ new Set(["content", "tenant", "system"]);
5
- const truthyValues = /* @__PURE__ */ new Set(["1", "true", "on", "yes"]);
6
- const isForceHttpOkRequested = (request) => {
7
- const raw = request.headers[forceHttpOkHeader];
8
- const value = Array.isArray(raw) ? raw[0] : raw;
9
- if (value === void 0) {
10
- return false;
11
- }
12
- return truthyValues.has(value.trim().toLowerCase());
13
- };
6
+ const isForceHttpOkRequested = (request) => truthyHeader.isTruthyHeader(request, forceHttpOkHeader);
14
7
  const isGraphqlModule = (module2) => module2 !== void 0 && graphqlModules.has(module2);
15
8
  const shouldForceHttpOk = ({ enabled, status, module: module2, hasBody, headerRequested }) => {
16
9
  if (!enabled) {
@@ -1 +1 @@
1
- {"version":3,"file":"forceHttpOk.cjs","sources":["../../../../../packages/engine-http/src/application/forceHttpOk.ts"],"sourcesContent":["import { IncomingMessage } from 'node:http'\n\n/**\n * Opt-in mechanism to coerce the HTTP status of a GraphQL API response to 200.\n *\n * Some GraphQL clients cannot properly handle non-200 HTTP status codes (e.g. on\n * authentication failure). When a request carries the `X-Contember-Force-Ok` header\n * with a truthy value, the response status is forced to 200 while the error information\n * remains in the JSON body.\n *\n * This is scoped to the GraphQL API endpoints (content/tenant/system) where a JSON body\n * with `errors`/`data` is returned, so that fatal/non-JSON responses are not mislabeled.\n *\n * The capability can be disabled globally via the `http.responseStatusHeader` config flag.\n */\nexport const forceHttpOkHeader = 'x-contember-force-ok'\n\nconst graphqlModules = new Set(['content', 'tenant', 'system'])\n\nconst truthyValues = new Set(['1', 'true', 'on', 'yes'])\n\nexport const isForceHttpOkRequested = (request: IncomingMessage): boolean => {\n\tconst raw = request.headers[forceHttpOkHeader]\n\tconst value = Array.isArray(raw) ? raw[0] : raw\n\tif (value === undefined) {\n\t\treturn false\n\t}\n\treturn truthyValues.has(value.trim().toLowerCase())\n}\n\nexport const isGraphqlModule = (module: string | undefined): boolean => module !== undefined && graphqlModules.has(module)\n\nexport interface ForceHttpOkDecisionInput {\n\t/** Whether the capability is enabled in config (http.responseStatusHeader). */\n\tenabled: boolean\n\t/** The current HTTP response status. */\n\tstatus: number\n\t/** The matched route module, if any. */\n\tmodule: string | undefined\n\t/** Whether the response carries a (JSON) body. */\n\thasBody: boolean\n\t/** Whether the client requested coercion via the X-Contember-Force-Ok header. */\n\theaderRequested: boolean\n}\n\n/**\n * Pure decision for whether a response status should be coerced to 200.\n *\n * Coercion happens only when ALL of the following hold:\n * - the capability is enabled in config (kill-switch off),\n * - the status is not already 200,\n * - the matched module is a GraphQL API module (content/tenant/system),\n * - the response has a body (so non-JSON / transport responses are not mislabeled),\n * - the client opted in via the X-Contember-Force-Ok header.\n */\nexport const shouldForceHttpOk = ({ enabled, status, module, hasBody, headerRequested }: ForceHttpOkDecisionInput): boolean => {\n\tif (!enabled) {\n\t\treturn false\n\t}\n\tif (status === 200) {\n\t\treturn false\n\t}\n\tif (!isGraphqlModule(module)) {\n\t\treturn false\n\t}\n\tif (!hasBody) {\n\t\treturn false\n\t}\n\treturn headerRequested\n}\n"],"names":["module"],"mappings":";;AAeO,MAAM,oBAAoB;AAEjC,MAAM,iBAAiB,oBAAI,IAAI,CAAC,WAAW,UAAU,QAAQ,CAAC;AAE9D,MAAM,mCAAmB,IAAI,CAAC,KAAK,QAAQ,MAAM,KAAK,CAAC;AAEhD,MAAM,yBAAyB,CAAC,YAAsC;AAC5E,QAAM,MAAM,QAAQ,QAAQ,iBAAiB;AAC7C,QAAM,QAAQ,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI;AAC5C,MAAI,UAAU,QAAW;AACxB,WAAO;AAAA,EACR;AACA,SAAO,aAAa,IAAI,MAAM,KAAA,EAAO,aAAa;AACnD;AAEO,MAAM,kBAAkB,CAACA,YAAwCA,YAAW,UAAa,eAAe,IAAIA,OAAM;AAyBlH,MAAM,oBAAoB,CAAC,EAAE,SAAS,QAAQ,QAAAA,SAAQ,SAAS,sBAAyD;AAC9H,MAAI,CAAC,SAAS;AACb,WAAO;AAAA,EACR;AACA,MAAI,WAAW,KAAK;AACnB,WAAO;AAAA,EACR;AACA,MAAI,CAAC,gBAAgBA,OAAM,GAAG;AAC7B,WAAO;AAAA,EACR;AACA,MAAI,CAAC,SAAS;AACb,WAAO;AAAA,EACR;AACA,SAAO;AACR;;;;;"}
1
+ {"version":3,"file":"forceHttpOk.cjs","sources":["../../../../../packages/engine-http/src/application/forceHttpOk.ts"],"sourcesContent":["import { IncomingMessage } from 'node:http'\nimport { isTruthyHeader } from '../utils/truthyHeader.js'\n\n/**\n * Opt-in mechanism to coerce the HTTP status of a GraphQL API response to 200.\n *\n * Some GraphQL clients cannot properly handle non-200 HTTP status codes (e.g. on\n * authentication failure). When a request carries the `X-Contember-Force-Ok` header\n * with a truthy value, the response status is forced to 200 while the error information\n * remains in the JSON body.\n *\n * This is scoped to the GraphQL API endpoints (content/tenant/system) where a JSON body\n * with `errors`/`data` is returned, so that fatal/non-JSON responses are not mislabeled.\n *\n * The capability can be disabled globally via the `http.responseStatusHeader` config flag.\n */\nexport const forceHttpOkHeader = 'x-contember-force-ok'\n\nconst graphqlModules = new Set(['content', 'tenant', 'system'])\n\nexport const isForceHttpOkRequested = (request: IncomingMessage): boolean => isTruthyHeader(request, forceHttpOkHeader)\n\nexport const isGraphqlModule = (module: string | undefined): boolean => module !== undefined && graphqlModules.has(module)\n\nexport interface ForceHttpOkDecisionInput {\n\t/** Whether the capability is enabled in config (http.responseStatusHeader). */\n\tenabled: boolean\n\t/** The current HTTP response status. */\n\tstatus: number\n\t/** The matched route module, if any. */\n\tmodule: string | undefined\n\t/** Whether the response carries a (JSON) body. */\n\thasBody: boolean\n\t/** Whether the client requested coercion via the X-Contember-Force-Ok header. */\n\theaderRequested: boolean\n}\n\n/**\n * Pure decision for whether a response status should be coerced to 200.\n *\n * Coercion happens only when ALL of the following hold:\n * - the capability is enabled in config (kill-switch off),\n * - the status is not already 200,\n * - the matched module is a GraphQL API module (content/tenant/system),\n * - the response has a body (so non-JSON / transport responses are not mislabeled),\n * - the client opted in via the X-Contember-Force-Ok header.\n */\nexport const shouldForceHttpOk = ({ enabled, status, module, hasBody, headerRequested }: ForceHttpOkDecisionInput): boolean => {\n\tif (!enabled) {\n\t\treturn false\n\t}\n\tif (status === 200) {\n\t\treturn false\n\t}\n\tif (!isGraphqlModule(module)) {\n\t\treturn false\n\t}\n\tif (!hasBody) {\n\t\treturn false\n\t}\n\treturn headerRequested\n}\n"],"names":["isTruthyHeader","module"],"mappings":";;;AAgBO,MAAM,oBAAoB;AAEjC,MAAM,iBAAiB,oBAAI,IAAI,CAAC,WAAW,UAAU,QAAQ,CAAC;AAEvD,MAAM,yBAAyB,CAAC,YAAsCA,aAAAA,eAAe,SAAS,iBAAiB;AAE/G,MAAM,kBAAkB,CAACC,YAAwCA,YAAW,UAAa,eAAe,IAAIA,OAAM;AAyBlH,MAAM,oBAAoB,CAAC,EAAE,SAAS,QAAQ,QAAAA,SAAQ,SAAS,sBAAyD;AAC9H,MAAI,CAAC,SAAS;AACb,WAAO;AAAA,EACR;AACA,MAAI,WAAW,KAAK;AACnB,WAAO;AAAA,EACR;AACA,MAAI,CAAC,gBAAgBA,OAAM,GAAG;AAC7B,WAAO;AAAA,EACR;AACA,MAAI,CAAC,SAAS;AACb,WAAO;AAAA,EACR;AACA,SAAO;AACR;;;;;"}
@@ -1,14 +1,7 @@
1
+ import { isTruthyHeader } from "../utils/truthyHeader.js";
1
2
  const forceHttpOkHeader = "x-contember-force-ok";
2
3
  const graphqlModules = /* @__PURE__ */ new Set(["content", "tenant", "system"]);
3
- const truthyValues = /* @__PURE__ */ new Set(["1", "true", "on", "yes"]);
4
- const isForceHttpOkRequested = (request) => {
5
- const raw = request.headers[forceHttpOkHeader];
6
- const value = Array.isArray(raw) ? raw[0] : raw;
7
- if (value === void 0) {
8
- return false;
9
- }
10
- return truthyValues.has(value.trim().toLowerCase());
11
- };
4
+ const isForceHttpOkRequested = (request) => isTruthyHeader(request, forceHttpOkHeader);
12
5
  const isGraphqlModule = (module) => module !== void 0 && graphqlModules.has(module);
13
6
  const shouldForceHttpOk = ({ enabled, status, module, hasBody, headerRequested }) => {
14
7
  if (!enabled) {
@@ -1 +1 @@
1
- {"version":3,"file":"forceHttpOk.js","sources":["../../../../../packages/engine-http/src/application/forceHttpOk.ts"],"sourcesContent":["import { IncomingMessage } from 'node:http'\n\n/**\n * Opt-in mechanism to coerce the HTTP status of a GraphQL API response to 200.\n *\n * Some GraphQL clients cannot properly handle non-200 HTTP status codes (e.g. on\n * authentication failure). When a request carries the `X-Contember-Force-Ok` header\n * with a truthy value, the response status is forced to 200 while the error information\n * remains in the JSON body.\n *\n * This is scoped to the GraphQL API endpoints (content/tenant/system) where a JSON body\n * with `errors`/`data` is returned, so that fatal/non-JSON responses are not mislabeled.\n *\n * The capability can be disabled globally via the `http.responseStatusHeader` config flag.\n */\nexport const forceHttpOkHeader = 'x-contember-force-ok'\n\nconst graphqlModules = new Set(['content', 'tenant', 'system'])\n\nconst truthyValues = new Set(['1', 'true', 'on', 'yes'])\n\nexport const isForceHttpOkRequested = (request: IncomingMessage): boolean => {\n\tconst raw = request.headers[forceHttpOkHeader]\n\tconst value = Array.isArray(raw) ? raw[0] : raw\n\tif (value === undefined) {\n\t\treturn false\n\t}\n\treturn truthyValues.has(value.trim().toLowerCase())\n}\n\nexport const isGraphqlModule = (module: string | undefined): boolean => module !== undefined && graphqlModules.has(module)\n\nexport interface ForceHttpOkDecisionInput {\n\t/** Whether the capability is enabled in config (http.responseStatusHeader). */\n\tenabled: boolean\n\t/** The current HTTP response status. */\n\tstatus: number\n\t/** The matched route module, if any. */\n\tmodule: string | undefined\n\t/** Whether the response carries a (JSON) body. */\n\thasBody: boolean\n\t/** Whether the client requested coercion via the X-Contember-Force-Ok header. */\n\theaderRequested: boolean\n}\n\n/**\n * Pure decision for whether a response status should be coerced to 200.\n *\n * Coercion happens only when ALL of the following hold:\n * - the capability is enabled in config (kill-switch off),\n * - the status is not already 200,\n * - the matched module is a GraphQL API module (content/tenant/system),\n * - the response has a body (so non-JSON / transport responses are not mislabeled),\n * - the client opted in via the X-Contember-Force-Ok header.\n */\nexport const shouldForceHttpOk = ({ enabled, status, module, hasBody, headerRequested }: ForceHttpOkDecisionInput): boolean => {\n\tif (!enabled) {\n\t\treturn false\n\t}\n\tif (status === 200) {\n\t\treturn false\n\t}\n\tif (!isGraphqlModule(module)) {\n\t\treturn false\n\t}\n\tif (!hasBody) {\n\t\treturn false\n\t}\n\treturn headerRequested\n}\n"],"names":[],"mappings":"AAeO,MAAM,oBAAoB;AAEjC,MAAM,iBAAiB,oBAAI,IAAI,CAAC,WAAW,UAAU,QAAQ,CAAC;AAE9D,MAAM,mCAAmB,IAAI,CAAC,KAAK,QAAQ,MAAM,KAAK,CAAC;AAEhD,MAAM,yBAAyB,CAAC,YAAsC;AAC5E,QAAM,MAAM,QAAQ,QAAQ,iBAAiB;AAC7C,QAAM,QAAQ,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI;AAC5C,MAAI,UAAU,QAAW;AACxB,WAAO;AAAA,EACR;AACA,SAAO,aAAa,IAAI,MAAM,KAAA,EAAO,aAAa;AACnD;AAEO,MAAM,kBAAkB,CAAC,WAAwC,WAAW,UAAa,eAAe,IAAI,MAAM;AAyBlH,MAAM,oBAAoB,CAAC,EAAE,SAAS,QAAQ,QAAQ,SAAS,sBAAyD;AAC9H,MAAI,CAAC,SAAS;AACb,WAAO;AAAA,EACR;AACA,MAAI,WAAW,KAAK;AACnB,WAAO;AAAA,EACR;AACA,MAAI,CAAC,gBAAgB,MAAM,GAAG;AAC7B,WAAO;AAAA,EACR;AACA,MAAI,CAAC,SAAS;AACb,WAAO;AAAA,EACR;AACA,SAAO;AACR;"}
1
+ {"version":3,"file":"forceHttpOk.js","sources":["../../../../../packages/engine-http/src/application/forceHttpOk.ts"],"sourcesContent":["import { IncomingMessage } from 'node:http'\nimport { isTruthyHeader } from '../utils/truthyHeader.js'\n\n/**\n * Opt-in mechanism to coerce the HTTP status of a GraphQL API response to 200.\n *\n * Some GraphQL clients cannot properly handle non-200 HTTP status codes (e.g. on\n * authentication failure). When a request carries the `X-Contember-Force-Ok` header\n * with a truthy value, the response status is forced to 200 while the error information\n * remains in the JSON body.\n *\n * This is scoped to the GraphQL API endpoints (content/tenant/system) where a JSON body\n * with `errors`/`data` is returned, so that fatal/non-JSON responses are not mislabeled.\n *\n * The capability can be disabled globally via the `http.responseStatusHeader` config flag.\n */\nexport const forceHttpOkHeader = 'x-contember-force-ok'\n\nconst graphqlModules = new Set(['content', 'tenant', 'system'])\n\nexport const isForceHttpOkRequested = (request: IncomingMessage): boolean => isTruthyHeader(request, forceHttpOkHeader)\n\nexport const isGraphqlModule = (module: string | undefined): boolean => module !== undefined && graphqlModules.has(module)\n\nexport interface ForceHttpOkDecisionInput {\n\t/** Whether the capability is enabled in config (http.responseStatusHeader). */\n\tenabled: boolean\n\t/** The current HTTP response status. */\n\tstatus: number\n\t/** The matched route module, if any. */\n\tmodule: string | undefined\n\t/** Whether the response carries a (JSON) body. */\n\thasBody: boolean\n\t/** Whether the client requested coercion via the X-Contember-Force-Ok header. */\n\theaderRequested: boolean\n}\n\n/**\n * Pure decision for whether a response status should be coerced to 200.\n *\n * Coercion happens only when ALL of the following hold:\n * - the capability is enabled in config (kill-switch off),\n * - the status is not already 200,\n * - the matched module is a GraphQL API module (content/tenant/system),\n * - the response has a body (so non-JSON / transport responses are not mislabeled),\n * - the client opted in via the X-Contember-Force-Ok header.\n */\nexport const shouldForceHttpOk = ({ enabled, status, module, hasBody, headerRequested }: ForceHttpOkDecisionInput): boolean => {\n\tif (!enabled) {\n\t\treturn false\n\t}\n\tif (status === 200) {\n\t\treturn false\n\t}\n\tif (!isGraphqlModule(module)) {\n\t\treturn false\n\t}\n\tif (!hasBody) {\n\t\treturn false\n\t}\n\treturn headerRequested\n}\n"],"names":[],"mappings":";AAgBO,MAAM,oBAAoB;AAEjC,MAAM,iBAAiB,oBAAI,IAAI,CAAC,WAAW,UAAU,QAAQ,CAAC;AAEvD,MAAM,yBAAyB,CAAC,YAAsC,eAAe,SAAS,iBAAiB;AAE/G,MAAM,kBAAkB,CAAC,WAAwC,WAAW,UAAa,eAAe,IAAI,MAAM;AAyBlH,MAAM,oBAAoB,CAAC,EAAE,SAAS,QAAQ,QAAQ,SAAS,sBAAyD;AAC9H,MAAI,CAAC,SAAS;AACb,WAAO;AAAA,EACR;AACA,MAAI,WAAW,KAAK;AACnB,WAAO;AAAA,EACR;AACA,MAAI,CAAC,gBAAgB,MAAM,GAAG;AAC7B,WAAO;AAAA,EACR;AACA,MAAI,CAAC,SAAS;AACb,WAAO;AAAA,EACR;AACA,SAAO;AACR;"}