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

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":"ImportExecutor.cjs","sources":["../../../../../packages/engine-http/src/transfer/ImportExecutor.ts"],"sourcesContent":["import { Client, Connection, ConstraintHelper, DatabaseMetadataResolver, wrapIdentifier } from '@contember/database'\nimport { Model, Schema } from '@contember/schema'\nimport * as Typesafe from '@contember/typesafe'\nimport { ParseError } from '@contember/typesafe'\nimport { Command, CommandArgsMap, CommandName } from './Command.js'\nimport { DatabaseContext, StageBySlugQuery } from '@contember/engine-system-api'\nimport { DbColumnSchema, TransferMapping, TransferTableMapping } from './TransferMapping.js'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory.js'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory.js'\nimport { AuthResult, HttpErrorResponse } from '../common/index.js'\nimport { ProjectGroupContainer } from '../projectGroup/ProjectGroupContainer.js'\n\ntype Cell = boolean | number | string | readonly string[] | readonly number[] | readonly boolean[] | null\ntype Row = readonly Cell[]\n\ntype InsertContext = {\n\ttableName: string\n\tinsertStartFragment: string\n\trowFragment: string\n\trowParser: Typesafe.Type<Row>\n\trows: Array<Row>\n\tinsertedRowCount: number\n}\n\nexport class ImportError extends Error {\n}\n\nconst parsePgTextArray = (value: string): string[] => {\n\tif (value === '{}') return []\n\tif (!value.startsWith('{') || !value.endsWith('}')) {\n\t\tthrow new ParseError([], `invalid PostgreSQL array literal: ${value}`)\n\t}\n\tconst inner = value.slice(1, -1)\n\tconst result: string[] = []\n\tlet current = ''\n\tlet inQuotes = false\n\tlet escaped = false\n\tfor (const ch of inner) {\n\t\tif (escaped) {\n\t\t\tcurrent += ch\n\t\t\tescaped = false\n\t\t} else if (ch === '\\\\') {\n\t\t\tescaped = true\n\t\t} else if (ch === '\"') {\n\t\t\tinQuotes = !inQuotes\n\t\t} else if (ch === ',' && !inQuotes) {\n\t\t\tresult.push(current)\n\t\t\tcurrent = ''\n\t\t} else {\n\t\t\tcurrent += ch\n\t\t}\n\t}\n\tresult.push(current)\n\treturn result\n}\n\nconst listType = <T extends Typesafe.Json>(arrayType: Typesafe.Type<T>): Typesafe.Type<T> => {\n\treturn (input: unknown, path: PropertyKey[] = []) => {\n\t\tif (Array.isArray(input)) {\n\t\t\treturn arrayType(input, path)\n\t\t}\n\t\tif (typeof input === 'string' && input.startsWith('{')) {\n\t\t\treturn arrayType(parsePgTextArray(input), path)\n\t\t}\n\t\treturn arrayType(input, path)\n\t}\n}\n\ntype CommandProcessor<T extends CommandName> = (it: CommandIterator<T>) => Promise<CommandIterator | null>\ntype CommandProcessorMap<T extends CommandName> = { [N in CommandName]?: N extends T ? CommandProcessor<N> : undefined }\n\nclass CommandIterator<T extends CommandName = CommandName> {\n\tprivate constructor(\n\t\tpublic readonly commandName: T,\n\t\tpublic readonly commandArgs: CommandArgsMap[T],\n\t\tprivate readonly commandIterator: AsyncIterator<Command>,\n\t) {\n\t}\n\n\tpublic static async create(commands: AsyncIterable<Command>): Promise<CommandIterator | null> {\n\t\tconst commandIterator = commands[Symbol.asyncIterator]()\n\t\tconst result = await commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, commandIterator)\n\t}\n\n\tasync next(): Promise<CommandIterator | null> {\n\t\tconst result = await this.commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, this.commandIterator)\n\t}\n}\n\nexport class ImportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t\tprivate readonly databaseMetadataResolver: DatabaseMetadataResolver,\n\t) {\n\t}\n\n\tasync import(groupContainer: ProjectGroupContainer, authResult: AuthResult, commands: AsyncIterable<Command>) {\n\t\tconst it = await CommandIterator.create(commands)\n\n\t\tconst final = await this.match(it, {\n\t\t\timportContentSchemaBegin: it => this.importContentSchemaBegin(groupContainer, authResult, it),\n\t\t\timportSystemSchemaBegin: it => this.importSystemSchemaBegin(groupContainer, authResult, it),\n\t\t})\n\n\t\tif (final !== null) {\n\t\t\tthrow new ImportError(`Unexpected ${final.commandName}`)\n\t\t}\n\t}\n\n\tprivate async match<T extends CommandName>(it: CommandIterator<T> | null, processors: CommandProcessorMap<T>) {\n\t\tlet next: CommandIterator | null = it\n\n\t\twhile (next !== null) {\n\t\t\tconst processor = processors[next.commandName]\n\n\t\t\tif (processor) {\n\t\t\t\tnext = await processor(next as any)\n\t\t\t} else {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\treturn next\n\t}\n\n\tprivate async importContentSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importContentSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst stage = await this.fetchStageBySlug(systemDatabaseContext, options.project, options.stage)\n\n\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemDatabaseContext, stage: stage.slug, normalize: true })\n\n\t\tif (contentSchema.meta.version !== options.schemaVersion) {\n\t\t\tthrow new ImportError(\n\t\t\t\t`Incompatible schema version (import version ${options.schemaVersion} does not match server version ${contentSchema.meta.version})`,\n\t\t\t)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, contentSchema.schema, authResult, options.project, 'content')\n\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\t\tconst mapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema)\n\n\t\treturn await contentDatabaseClient.transaction(async db => {\n\t\t\tawait this.disableTimeouts(db)\n\t\t\tawait this.disableTriggers(db, options.tables)\n\t\t\tawait this.lockTables(db, options.tables)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\tconst result = await this.match(await it.next(), {\n\t\t\t\timportSequence: it => this.importSequence(db, mapping, it),\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\n\t\t\tawait constraintHelper.setConstraintsImmediate('foreignKey')\n\t\t\tawait this.enableTriggers(db, options.tables)\n\n\t\t\treturn result\n\t\t})\n\t}\n\n\tprivate async importSystemSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importSystemSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst schema = await groupContainer.projectSchemaResolver.getSchema(options.project)\n\n\t\tif (schema === undefined) {\n\t\t\tthrow new ImportError(`Project ${options.project} does not have schema`)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, schema, authResult, options.project, 'system')\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst mapping = this.systemSchemaTransferMappingFactory.build()\n\n\t\treturn await systemDatabaseContext.client.transaction(async db => {\n\t\t\tawait this.disableTimeouts(db)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\treturn await this.match(await it.next(), {\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async importSequence(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'importSequence'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\n\t\tawait db.query(\n\t\t\t'SELECT setval(pg_get_serial_sequence(?, ?), ?)',\n\t\t\t[`${db.schema}.${options.table}`, options.column, options.value],\n\t\t)\n\n\t\treturn it.next()\n\t}\n\n\tprivate async insertBegin(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'insertBegin'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\t\tconst insertContext = await this.buildInsertContext(db, mapping, db.schema, options.table, options.columns)\n\t\tlet insertRowsPromise: Promise<Connection.Result> | null = null\n\n\t\t// postgresql has a limit of 65535 parameters per query\n\t\tconst batchSize = Math.max(1, Math.min(1000, Math.floor(65500 / options.columns.length)))\n\n\t\tconst result = await this.match(await it.next(), {\n\t\t\tinsertRow: async it => {\n\t\t\t\tconst [values] = it.commandArgs\n\n\t\t\t\ttry {\n\t\t\t\t\tinsertContext.rows.push(insertContext.rowParser(values))\n\t\t\t\t} catch (e) {\n\t\t\t\t\tif (e instanceof ParseError) {\n\t\t\t\t\t\tthrow new ImportError(`Invalid row ${JSON.stringify(values)} for table ${options.table}: ${e.message}`)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow e\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (insertContext.rows.length === batchSize) {\n\t\t\t\t\tawait insertRowsPromise\n\t\t\t\t\tinsertRowsPromise = this.insertRows(db, insertContext)\n\t\t\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\t\t\tinsertContext.rows = []\n\t\t\t\t}\n\n\t\t\t\treturn await it.next()\n\t\t\t},\n\t\t})\n\n\t\tif (insertContext.rows.length > 0) {\n\t\t\tawait insertRowsPromise\n\t\t\tawait this.insertRows(db, insertContext)\n\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\tinsertContext.rows = []\n\t\t}\n\n\t\tif (result === null || result.commandName !== 'insertEnd') {\n\t\t\tthrow new ImportError(`Missing insertEnd command`)\n\t\t}\n\n\t\treturn await result.next()\n\t}\n\n\tprivate async createProjectContainer(groupContainer: ProjectGroupContainer, projectSlug: string) {\n\t\tconst projectContainerResolver = groupContainer.projectContainerResolver\n\t\tconst projectContainer = await projectContainerResolver.getProjectContainer(projectSlug, { alias: true })\n\n\t\tif (projectContainer === undefined) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not exists.`)\n\t\t}\n\n\t\treturn projectContainer\n\t}\n\n\tprivate async requireImportAccess(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tschema: Schema,\n\t\tauthResult: AuthResult,\n\t\tprojectSlug: string,\n\t\tkind: 'content' | 'system',\n\t) {\n\t\tconst { effective: memberships } = await groupContainer.projectMembershipResolver.resolveMemberships({\n\t\t\trequest: { get: () => '' },\n\t\t\tacl: schema.acl,\n\t\t\tprojectSlug: projectSlug,\n\t\t\tidentity: {\n\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\troles: authResult.roles,\n\t\t\t},\n\t\t})\n\n\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\tif (!projectRoles.some(role => schema.acl.roles[role]?.[kind]?.import)) {\n\t\t\tthrow new HttpErrorResponse(403, `You are not allowed to import ${kind} in ${projectSlug}`)\n\t\t}\n\t}\n\n\tprivate async fetchStageBySlug(systemDatabaseContext: DatabaseContext, projectSlug: string, stageSlug: string) {\n\t\tconst stage = await systemDatabaseContext.queryHandler.fetch(new StageBySlugQuery(stageSlug))\n\n\t\tif (stage === null) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not have stage ${stageSlug}.`)\n\t\t}\n\n\t\treturn stage\n\t}\n\n\tprivate async disableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} DISABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async enableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} ENABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async lockTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`LOCK ${tableNamesQuoted.join(', ')} IN EXCLUSIVE MODE`)\n\t}\n\n\tprivate async truncateTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`TRUNCATE ${tableNamesQuoted.join(', ')}`)\n\t}\n\n\tprivate async disableTimeouts(db: Client) {\n\t\tawait db.query('SET LOCAL statement_timeout = 0')\n\t\tawait db.query('SET LOCAL lock_timeout = 0')\n\t}\n\n\tprivate async insertRows(db: Client, context: InsertContext) {\n\t\tconst rowsFragment = context.rows.map(_ => context.rowFragment).join(',\\n')\n\t\tconst sql = context.insertStartFragment + rowsFragment\n\t\tconst parameters: Cell[] = []\n\n\t\tfor (const row of context.rows) {\n\t\t\tfor (const cell of row) {\n\t\t\t\tparameters.push(cell)\n\t\t\t}\n\t\t}\n\n\t\treturn await db.query(sql, parameters)\n\t}\n\n\tprivate async buildInsertContext(\n\t\tdb: Client,\n\t\tmapping: TransferMapping,\n\t\tschema: string,\n\t\ttableName: string,\n\t\tcolumnNames: readonly string[],\n\t): Promise<InsertContext> {\n\t\tconst tableMapping = mapping.tables[tableName]\n\t\tconst columns = []\n\n\t\tif (tableMapping === undefined) {\n\t\t\tthrow new ImportError(`Unknown table ${tableName}`)\n\t\t}\n\n\t\tfor (const columnName of columnNames) {\n\t\t\tconst column = tableMapping.columns[columnName]\n\n\t\t\tif (column === undefined) {\n\t\t\t\tthrow new ImportError(`Unknown column ${tableName}.${columnName}`)\n\t\t\t}\n\n\t\t\tcolumns.push(column)\n\t\t}\n\n\t\tconst insertStartFragment = (tableMapping.createInsertStartFragment ?? this.createInsertStartFragment)(schema, tableName, columnNames)\n\t\tconst rowFragment = '(' + columns.map(_ => '?').join(', ') + ')'\n\t\tconst rowParser = await this.buildRowParser(db, tableMapping, columns)\n\n\t\treturn {\n\t\t\ttableName,\n\t\t\tinsertStartFragment,\n\t\t\trowFragment,\n\t\t\trowParser,\n\t\t\trows: [],\n\t\t\tinsertedRowCount: 0,\n\t\t}\n\t}\n\n\tprivate createInsertStartFragment(schema: string, tableName: string, columnNames: readonly string[]): string {\n\t\tconst tableQuoted = `${wrapIdentifier(schema)}.${wrapIdentifier(tableName)}`\n\t\tconst columnsQuoted = '(' + columnNames.map(it => wrapIdentifier(it)).join(', ') + ')'\n\t\treturn `INSERT INTO ${tableQuoted} ${columnsQuoted} VALUES\\n`\n\t}\n\n\tprivate async buildRowParser(db: Client, tableMapping: TransferTableMapping, columns: DbColumnSchema[]): Promise<Typesafe.Type<readonly Cell[]>> {\n\t\tconst baseType = Typesafe.tuple(...columns.map(it => {\n\t\t\tconst base = this.buildColumnRuntimeType(it)\n\t\t\treturn it.nullable ? Typesafe.nullable(base) : base\n\t\t}))\n\n\t\tif (tableMapping.createRowParser === undefined) {\n\t\t\treturn baseType\n\t\t}\n\n\t\treturn await tableMapping.createRowParser(db, columns.map(it => it.name), baseType)\n\t}\n\n\tprivate buildColumnRuntimeType(column: DbColumnSchema): Typesafe.Type<Exclude<Cell, null>> {\n\t\tswitch (column.type) {\n\t\t\tcase Model.ColumnType.Uuid:\n\t\t\tcase Model.ColumnType.String:\n\t\t\tcase Model.ColumnType.Enum:\n\t\t\tcase Model.ColumnType.DateTime:\n\t\t\tcase Model.ColumnType.Time:\n\t\t\tcase Model.ColumnType.Date:\n\t\t\tcase Model.ColumnType.Json:\n\t\t\t// Numeric is transferred as a string to avoid JS float precision loss.\n\t\t\tcase Model.ColumnType.Numeric:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.string)) : Typesafe.string\n\t\t\tcase Model.ColumnType.Int:\n\t\t\tcase Model.ColumnType.Double:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.number)) : Typesafe.number\n\t\t\tcase Model.ColumnType.Bool:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.boolean)) : Typesafe.boolean\n\t\t}\n\t}\n}\n"],"names":["ParseError","it","ConstraintHelper","schema","HttpErrorResponse","StageBySlugQuery","wrapIdentifier","Typesafe","Model"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwBO,MAAM,oBAAoB,MAAM;AACvC;AAEA,MAAM,mBAAmB,CAAC,UAA4B;AACrD,MAAI,UAAU,KAAM,QAAO,CAAA;AAC3B,MAAI,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,SAAS,GAAG,GAAG;AACnD,UAAM,IAAIA,SAAAA,WAAW,CAAA,GAAI,qCAAqC,KAAK,EAAE;AAAA,EACtE;AACA,QAAM,QAAQ,MAAM,MAAM,GAAG,EAAE;AAC/B,QAAM,SAAmB,CAAA;AACzB,MAAI,UAAU;AACd,MAAI,WAAW;AACf,MAAI,UAAU;AACd,aAAW,MAAM,OAAO;AACvB,QAAI,SAAS;AACZ,iBAAW;AACX,gBAAU;AAAA,IACX,WAAW,OAAO,MAAM;AACvB,gBAAU;AAAA,IACX,WAAW,OAAO,KAAK;AACtB,iBAAW,CAAC;AAAA,IACb,WAAW,OAAO,OAAO,CAAC,UAAU;AACnC,aAAO,KAAK,OAAO;AACnB,gBAAU;AAAA,IACX,OAAO;AACN,iBAAW;AAAA,IACZ;AAAA,EACD;AACA,SAAO,KAAK,OAAO;AACnB,SAAO;AACR;AAEA,MAAM,WAAW,CAA0B,cAAkD;AAC5F,SAAO,CAAC,OAAgB,OAAsB,OAAO;AACpD,QAAI,MAAM,QAAQ,KAAK,GAAG;AACz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MAAc,eAAe,IAAY,cAAoC,SAAoE;AAChJ,UAAM,WAAWC,oBAAS,MAAM,GAAG,QAAQ,IAAI,CAAA,OAAM;AACpD,YAAM,OAAO,KAAK,uBAAuB,EAAE;AAC3C,aAAO,GAAG,WAAWA,oBAAS,SAAS,IAAI,IAAI;AAAA,IAChD,CAAC,CAAC;AAEF,QAAI,aAAa,oBAAoB,QAAW;AAC/C,aAAO;AAAA,IACR;AAEA,WAAO,MAAM,aAAa,gBAAgB,IAAI,QAAQ,IAAI,CAAA,OAAM,GAAG,IAAI,GAAG,QAAQ;AAAA,EACnF;AAAA,EAEQ,uBAAuB,QAA4D;AAC1F,YAAQ,OAAO,MAAA;AAAA,MACd,KAAKC,OAAAA,MAAM,WAAW;AAAA,MACtB,KAAKA,OAAAA,MAAM,WAAW;AAAA,MACtB,KAAKA,OAAAA,MAAM,WAAW;AAAA,MACtB,KAAKA,OAAAA,MAAM,WAAW;AAAA,MACtB,KAAKA,OAAAA,MAAM,WAAW;AAAA,MACtB,KAAKA,OAAAA,MAAM,WAAW;AAAA,MACtB,KAAKA,OAAAA,MAAM,WAAW;AAAA;AAAA,MAEtB,KAAKA,OAAAA,MAAM,WAAW;AACrB,eAAO,OAAO,OAAO,SAASD,oBAAS,MAAMA,oBAAS,MAAM,CAAC,IAAIA,oBAAS;AAAA,MAC3E,KAAKC,OAAAA,MAAM,WAAW;AAAA,MACtB,KAAKA,OAAAA,MAAM,WAAW;AACrB,eAAO,OAAO,OAAO,SAASD,oBAAS,MAAMA,oBAAS,MAAM,CAAC,IAAIA,oBAAS;AAAA,MAC3E,KAAKC,OAAAA,MAAM,WAAW;AACrB,eAAO,OAAO,OAAO,SAASD,oBAAS,MAAMA,oBAAS,OAAO,CAAC,IAAIA,oBAAS;AAAA,IAAA;AAAA,EAE9E;AACD;;;"}
1
+ {"version":3,"file":"ImportExecutor.cjs","sources":["../../../../../packages/engine-http/src/transfer/ImportExecutor.ts"],"sourcesContent":["import { Client, Connection, ConstraintHelper, DatabaseMetadataResolver, wrapIdentifier } from '@contember/database'\nimport { Model, Schema } from '@contember/schema'\nimport * as Typesafe from '@contember/typesafe'\nimport { ParseError } from '@contember/typesafe'\nimport { Command, CommandArgsMap, CommandName } from './Command.js'\nimport { DatabaseContext, StageBySlugQuery } from '@contember/engine-system-api'\nimport { isImpossibleCalendarDate } from '@contember/engine-content-api'\nimport { DbColumnSchema, TransferMapping, TransferTableMapping } from './TransferMapping.js'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory.js'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory.js'\nimport { AuthResult, HttpErrorResponse } from '../common/index.js'\nimport { ProjectGroupContainer } from '../projectGroup/ProjectGroupContainer.js'\n\ntype Cell = boolean | number | string | readonly string[] | readonly number[] | readonly boolean[] | null\ntype Row = readonly Cell[]\n\ntype InsertContext = {\n\ttableName: string\n\tinsertStartFragment: string\n\trowFragment: string\n\trowParser: Typesafe.Type<Row>\n\trows: Array<Row>\n\tinsertedRowCount: number\n}\n\nexport class ImportError extends Error {\n}\n\nconst parsePgTextArray = (value: string): string[] => {\n\tif (value === '{}') return []\n\tif (!value.startsWith('{') || !value.endsWith('}')) {\n\t\tthrow new ParseError([], `invalid PostgreSQL array literal: ${value}`)\n\t}\n\tconst inner = value.slice(1, -1)\n\tconst result: string[] = []\n\tlet current = ''\n\tlet inQuotes = false\n\tlet escaped = false\n\tfor (const ch of inner) {\n\t\tif (escaped) {\n\t\t\tcurrent += ch\n\t\t\tescaped = false\n\t\t} else if (ch === '\\\\') {\n\t\t\tescaped = true\n\t\t} else if (ch === '\"') {\n\t\t\tinQuotes = !inQuotes\n\t\t} else if (ch === ',' && !inQuotes) {\n\t\t\tresult.push(current)\n\t\t\tcurrent = ''\n\t\t} else {\n\t\t\tcurrent += ch\n\t\t}\n\t}\n\tresult.push(current)\n\treturn result\n}\n\nconst listType = <T extends Typesafe.Json>(arrayType: Typesafe.Type<T>): Typesafe.Type<T> => {\n\treturn (input: unknown, path: PropertyKey[] = []) => {\n\t\tif (Array.isArray(input)) {\n\t\t\treturn arrayType(input, path)\n\t\t}\n\t\tif (typeof input === 'string' && input.startsWith('{')) {\n\t\t\treturn arrayType(parsePgTextArray(input), path)\n\t\t}\n\t\treturn arrayType(input, path)\n\t}\n}\n\n// PostgreSQL would fail the whole batch insert on an impossible date with a server error that names neither column nor row.\nconst calendarDate: Typesafe.Type<string> = (input: unknown, path: PropertyKey[] = []) => {\n\tconst value = Typesafe.string(input, path)\n\tif (isImpossibleCalendarDate(value)) {\n\t\tthrow new ParseError(path, `${JSON.stringify(value)} is not a valid date`)\n\t}\n\treturn value\n}\n\ntype CommandProcessor<T extends CommandName> = (it: CommandIterator<T>) => Promise<CommandIterator | null>\ntype CommandProcessorMap<T extends CommandName> = { [N in CommandName]?: N extends T ? CommandProcessor<N> : undefined }\n\nclass CommandIterator<T extends CommandName = CommandName> {\n\tprivate constructor(\n\t\tpublic readonly commandName: T,\n\t\tpublic readonly commandArgs: CommandArgsMap[T],\n\t\tprivate readonly commandIterator: AsyncIterator<Command>,\n\t) {\n\t}\n\n\tpublic static async create(commands: AsyncIterable<Command>): Promise<CommandIterator | null> {\n\t\tconst commandIterator = commands[Symbol.asyncIterator]()\n\t\tconst result = await commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, commandIterator)\n\t}\n\n\tasync next(): Promise<CommandIterator | null> {\n\t\tconst result = await this.commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, this.commandIterator)\n\t}\n}\n\nexport class ImportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t\tprivate readonly databaseMetadataResolver: DatabaseMetadataResolver,\n\t) {\n\t}\n\n\tasync import(groupContainer: ProjectGroupContainer, authResult: AuthResult, commands: AsyncIterable<Command>) {\n\t\tconst it = await CommandIterator.create(commands)\n\n\t\tconst final = await this.match(it, {\n\t\t\timportContentSchemaBegin: it => this.importContentSchemaBegin(groupContainer, authResult, it),\n\t\t\timportSystemSchemaBegin: it => this.importSystemSchemaBegin(groupContainer, authResult, it),\n\t\t})\n\n\t\tif (final !== null) {\n\t\t\tthrow new ImportError(`Unexpected ${final.commandName}`)\n\t\t}\n\t}\n\n\tprivate async match<T extends CommandName>(it: CommandIterator<T> | null, processors: CommandProcessorMap<T>) {\n\t\tlet next: CommandIterator | null = it\n\n\t\twhile (next !== null) {\n\t\t\tconst processor = processors[next.commandName]\n\n\t\t\tif (processor) {\n\t\t\t\tnext = await processor(next as any)\n\t\t\t} else {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\treturn next\n\t}\n\n\tprivate async importContentSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importContentSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst stage = await this.fetchStageBySlug(systemDatabaseContext, options.project, options.stage)\n\n\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemDatabaseContext, stage: stage.slug, normalize: true })\n\n\t\tif (contentSchema.meta.version !== options.schemaVersion) {\n\t\t\tthrow new ImportError(\n\t\t\t\t`Incompatible schema version (import version ${options.schemaVersion} does not match server version ${contentSchema.meta.version})`,\n\t\t\t)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, contentSchema.schema, authResult, options.project, 'content')\n\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\t\tconst mapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema)\n\t\tthis.requireMappedTables(mapping, options.tables, `content schema of project ${options.project}`)\n\n\t\treturn await contentDatabaseClient.transaction(async db => {\n\t\t\tawait this.disableTimeouts(db)\n\t\t\tawait this.disableTriggers(db, options.tables)\n\t\t\tawait this.lockTables(db, options.tables)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\tconst result = await this.match(await it.next(), {\n\t\t\t\timportSequence: it => this.importSequence(db, mapping, it),\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\n\t\t\tawait constraintHelper.setConstraintsImmediate('foreignKey')\n\t\t\tawait this.enableTriggers(db, options.tables)\n\n\t\t\treturn result\n\t\t})\n\t}\n\n\tprivate async importSystemSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importSystemSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst schema = await groupContainer.projectSchemaResolver.getSchema(options.project)\n\n\t\tif (schema === undefined) {\n\t\t\tthrow new ImportError(`Project ${options.project} does not have schema`)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, schema, authResult, options.project, 'system')\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst mapping = this.systemSchemaTransferMappingFactory.build()\n\t\tthis.requireMappedTables(mapping, options.tables, `system schema of project ${options.project}`)\n\n\t\treturn await systemDatabaseContext.client.transaction(async db => {\n\t\t\tawait this.disableTimeouts(db)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\treturn await this.match(await it.next(), {\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async importSequence(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'importSequence'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\t\tif (!Object.hasOwn(mapping.tables, options.table) || !Object.hasOwn(mapping.tables[options.table].columns, options.column)) {\n\t\t\tthrow new ImportError(`Unknown column ${options.table}.${options.column}`)\n\t\t}\n\n\t\tawait db.query(\n\t\t\t'SELECT setval(pg_get_serial_sequence(?, ?), ?)',\n\t\t\t[`${db.schema}.${options.table}`, options.column, options.value],\n\t\t)\n\n\t\treturn it.next()\n\t}\n\n\tprivate async insertBegin(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'insertBegin'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\t\tconst insertContext = await this.buildInsertContext(db, mapping, db.schema, options.table, options.columns)\n\t\tlet insertRowsPromise: Promise<Connection.Result> | null = null\n\n\t\t// postgresql has a limit of 65535 parameters per query\n\t\tconst batchSize = Math.max(1, Math.min(1000, Math.floor(65500 / options.columns.length)))\n\n\t\tconst result = await this.match(await it.next(), {\n\t\t\tinsertRow: async it => {\n\t\t\t\tconst [values] = it.commandArgs\n\n\t\t\t\ttry {\n\t\t\t\t\tinsertContext.rows.push(insertContext.rowParser(values))\n\t\t\t\t} catch (e) {\n\t\t\t\t\tif (e instanceof ParseError) {\n\t\t\t\t\t\tconst rowNumber = insertContext.insertedRowCount + insertContext.rows.length + 1\n\t\t\t\t\t\t// The row parser is a tuple over the insertBegin columns, so the first path segment is the column index.\n\t\t\t\t\t\tconst [columnIndex, ...valuePath] = e.path\n\t\t\t\t\t\tconst columnName = columnIndex !== undefined ? options.columns[Number(columnIndex)] : undefined\n\t\t\t\t\t\tconst elementLocation = valuePath.length > 0 ? `, element /${valuePath.map(String).join('/')}` : ''\n\t\t\t\t\t\tconst location = columnName !== undefined ? `table ${options.table}, column ${columnName}${elementLocation}` : `table ${options.table}`\n\t\t\t\t\t\tconst reason = columnName !== undefined ? e.reason : e.message\n\t\t\t\t\t\tthrow new ImportError(`Invalid row #${rowNumber} ${JSON.stringify(values)} for ${location}: ${reason}`)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow e\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (insertContext.rows.length === batchSize) {\n\t\t\t\t\tawait insertRowsPromise\n\t\t\t\t\tinsertRowsPromise = this.insertRows(db, insertContext)\n\t\t\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\t\t\tinsertContext.rows = []\n\t\t\t\t}\n\n\t\t\t\treturn await it.next()\n\t\t\t},\n\t\t})\n\n\t\tif (insertContext.rows.length > 0) {\n\t\t\tawait insertRowsPromise\n\t\t\tawait this.insertRows(db, insertContext)\n\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\tinsertContext.rows = []\n\t\t}\n\n\t\tif (result === null || result.commandName !== 'insertEnd') {\n\t\t\tthrow new ImportError(`Missing insertEnd command`)\n\t\t}\n\n\t\treturn await result.next()\n\t}\n\n\tprivate async createProjectContainer(groupContainer: ProjectGroupContainer, projectSlug: string) {\n\t\tconst projectContainerResolver = groupContainer.projectContainerResolver\n\t\tconst projectContainer = await projectContainerResolver.getProjectContainer(projectSlug, { alias: true })\n\n\t\tif (projectContainer === undefined) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not exists.`)\n\t\t}\n\n\t\treturn projectContainer\n\t}\n\n\tprivate async requireImportAccess(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tschema: Schema,\n\t\tauthResult: AuthResult,\n\t\tprojectSlug: string,\n\t\tkind: 'content' | 'system',\n\t) {\n\t\tconst { effective: memberships } = await groupContainer.projectMembershipResolver.resolveMemberships({\n\t\t\trequest: { get: () => '' },\n\t\t\tacl: schema.acl,\n\t\t\tprojectSlug: projectSlug,\n\t\t\tidentity: {\n\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\troles: authResult.roles,\n\t\t\t},\n\t\t})\n\n\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\tif (!projectRoles.some(role => schema.acl.roles[role]?.[kind]?.import)) {\n\t\t\tthrow new HttpErrorResponse(403, `You are not allowed to import ${kind} in ${projectSlug}`)\n\t\t}\n\t}\n\n\t/** The tables an import truncates must come from the same mapping an export of this schema lists. */\n\tprivate requireMappedTables(mapping: TransferMapping, tableNames: readonly string[], target: string) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tif (!Object.hasOwn(mapping.tables, tableName)) {\n\t\t\t\tthrow new ImportError(`Table ${tableName} is not part of the ${target}`)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async fetchStageBySlug(systemDatabaseContext: DatabaseContext, projectSlug: string, stageSlug: string) {\n\t\tconst stage = await systemDatabaseContext.queryHandler.fetch(new StageBySlugQuery(stageSlug))\n\n\t\tif (stage === null) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not have stage ${stageSlug}.`)\n\t\t}\n\n\t\treturn stage\n\t}\n\n\tprivate async disableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} DISABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async enableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} ENABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async lockTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`LOCK ${tableNamesQuoted.join(', ')} IN EXCLUSIVE MODE`)\n\t}\n\n\tprivate async truncateTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`TRUNCATE ${tableNamesQuoted.join(', ')}`)\n\t}\n\n\tprivate async disableTimeouts(db: Client) {\n\t\tawait db.query('SET LOCAL statement_timeout = 0')\n\t\tawait db.query('SET LOCAL lock_timeout = 0')\n\t}\n\n\tprivate async insertRows(db: Client, context: InsertContext) {\n\t\tconst rowsFragment = context.rows.map(_ => context.rowFragment).join(',\\n')\n\t\tconst sql = context.insertStartFragment + rowsFragment\n\t\tconst parameters: Cell[] = []\n\n\t\tfor (const row of context.rows) {\n\t\t\tfor (const cell of row) {\n\t\t\t\tparameters.push(cell)\n\t\t\t}\n\t\t}\n\n\t\treturn await db.query(sql, parameters)\n\t}\n\n\tprivate async buildInsertContext(\n\t\tdb: Client,\n\t\tmapping: TransferMapping,\n\t\tschema: string,\n\t\ttableName: string,\n\t\tcolumnNames: readonly string[],\n\t): Promise<InsertContext> {\n\t\tconst tableMapping = Object.hasOwn(mapping.tables, tableName) ? mapping.tables[tableName] : undefined\n\t\tconst columns = []\n\n\t\tif (tableMapping === undefined) {\n\t\t\tthrow new ImportError(`Unknown table ${tableName}`)\n\t\t}\n\n\t\tfor (const columnName of columnNames) {\n\t\t\tconst column = Object.hasOwn(tableMapping.columns, columnName) ? tableMapping.columns[columnName] : undefined\n\n\t\t\tif (column === undefined) {\n\t\t\t\tthrow new ImportError(`Unknown column ${tableName}.${columnName}`)\n\t\t\t}\n\n\t\t\tcolumns.push(column)\n\t\t}\n\n\t\tconst insertStartFragment = (tableMapping.createInsertStartFragment ?? this.createInsertStartFragment)(schema, tableName, columnNames)\n\t\tconst rowFragment = '(' + columns.map(_ => '?').join(', ') + ')'\n\t\tconst rowParser = await this.buildRowParser(db, tableMapping, columns)\n\n\t\treturn {\n\t\t\ttableName,\n\t\t\tinsertStartFragment,\n\t\t\trowFragment,\n\t\t\trowParser,\n\t\t\trows: [],\n\t\t\tinsertedRowCount: 0,\n\t\t}\n\t}\n\n\tprivate createInsertStartFragment(schema: string, tableName: string, columnNames: readonly string[]): string {\n\t\tconst tableQuoted = `${wrapIdentifier(schema)}.${wrapIdentifier(tableName)}`\n\t\tconst columnsQuoted = '(' + columnNames.map(it => wrapIdentifier(it)).join(', ') + ')'\n\t\treturn `INSERT INTO ${tableQuoted} ${columnsQuoted} VALUES\\n`\n\t}\n\n\tprivate async buildRowParser(db: Client, tableMapping: TransferTableMapping, columns: DbColumnSchema[]): Promise<Typesafe.Type<readonly Cell[]>> {\n\t\tconst baseType = Typesafe.tuple(...columns.map(it => {\n\t\t\tconst base = this.buildColumnRuntimeType(it)\n\t\t\treturn it.nullable ? Typesafe.nullable(base) : base\n\t\t}))\n\n\t\tif (tableMapping.createRowParser === undefined) {\n\t\t\treturn baseType\n\t\t}\n\n\t\treturn await tableMapping.createRowParser(db, columns.map(it => it.name), baseType)\n\t}\n\n\tprivate buildColumnRuntimeType(column: DbColumnSchema): Typesafe.Type<Exclude<Cell, null>> {\n\t\tswitch (column.type) {\n\t\t\tcase Model.ColumnType.Uuid:\n\t\t\tcase Model.ColumnType.String:\n\t\t\tcase Model.ColumnType.Enum:\n\t\t\tcase Model.ColumnType.Time:\n\t\t\tcase Model.ColumnType.Json:\n\t\t\t// Numeric is transferred as a string to avoid JS float precision loss.\n\t\t\tcase Model.ColumnType.Numeric:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.string)) : Typesafe.string\n\t\t\tcase Model.ColumnType.Date:\n\t\t\tcase Model.ColumnType.DateTime:\n\t\t\t\treturn column.list ? listType(Typesafe.array(calendarDate)) : calendarDate\n\t\t\tcase Model.ColumnType.Int:\n\t\t\tcase Model.ColumnType.Double:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.number)) : Typesafe.number\n\t\t\tcase Model.ColumnType.Bool:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.boolean)) : Typesafe.boolean\n\t\t}\n\t}\n}\n"],"names":["ParseError","Typesafe","isImpossibleCalendarDate","it","ConstraintHelper","schema","HttpErrorResponse","StageBySlugQuery","wrapIdentifier","Model"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBO,MAAM,oBAAoB,MAAM;AACvC;AAEA,MAAM,mBAAmB,CAAC,UAA4B;AACrD,MAAI,UAAU,KAAM,QAAO,CAAA;AAC3B,MAAI,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,SAAS,GAAG,GAAG;AACnD,UAAM,IAAIA,SAAAA,WAAW,CAAA,GAAI,qCAAqC,KAAK,EAAE;AAAA,EACtE;AACA,QAAM,QAAQ,MAAM,MAAM,GAAG,EAAE;AAC/B,QAAM,SAAmB,CAAA;AACzB,MAAI,UAAU;AACd,MAAI,WAAW;AACf,MAAI,UAAU;AACd,aAAW,MAAM,OAAO;AACvB,QAAI,SAAS;AACZ,iBAAW;AACX,gBAAU;AAAA,IACX,WAAW,OAAO,MAAM;AACvB,gBAAU;AAAA,IACX,WAAW,OAAO,KAAK;AACtB,iBAAW,CAAC;AAAA,IACb,WAAW,OAAO,OAAO,CAAC,UAAU;AACnC,aAAO,KAAK,OAAO;AACnB,gBAAU;AAAA,IACX,OAAO;AACN,iBAAW;AAAA,IACZ;AAAA,EACD;AACA,SAAO,KAAK,OAAO;AACnB,SAAO;AACR;AAEA,MAAM,WAAW,CAA0B,cAAkD;AAC5F,SAAO,CAAC,OAAgB,OAAsB,OAAO;AACpD,QAAI,MAAM,QAAQ,KAAK,GAAG;AACzB,aAAO,UAAU,OAAO,IAAI;AAAA,IAC7B;AACA,QAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAAG,GAAG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contember/schema";
3
3
  import * as Typesafe from "@contember/typesafe";
4
4
  import { ParseError } from "@contember/typesafe";
5
5
  import { StageBySlugQuery } from "@contember/engine-system-api";
6
+ import { isImpossibleCalendarDate } from "@contember/engine-content-api";
6
7
  import { HttpErrorResponse } from "../common/HttpResponse.js";
7
8
  import "ipaddr.js";
9
+ import "@contember/engine-tenant-api";
8
10
  class ImportError extends Error {
9
11
  }
10
12
  const parsePgTextArray = (value) => {
@@ -46,6 +48,13 @@ const listType = (arrayType) => {
46
48
  return arrayType(input, path);
47
49
  };
48
50
  };
51
+ const calendarDate = (input, path = []) => {
52
+ const value = Typesafe.string(input, path);
53
+ if (isImpossibleCalendarDate(value)) {
54
+ throw new ParseError(path, `${JSON.stringify(value)} is not a valid date`);
55
+ }
56
+ return value;
57
+ };
49
58
  class CommandIterator {
50
59
  constructor(commandName, commandArgs, commandIterator) {
51
60
  this.commandName = commandName;
@@ -112,6 +121,7 @@ class ImportExecutor {
112
121
  await this.requireImportAccess(groupContainer, contentSchema.schema, authResult, options.project, "content");
113
122
  const contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {});
114
123
  const mapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema);
124
+ this.requireMappedTables(mapping, options.tables, `content schema of project ${options.project}`);
115
125
  return await contentDatabaseClient.transaction(async (db) => {
116
126
  await this.disableTimeouts(db);
117
127
  await this.disableTriggers(db, options.tables);
@@ -139,6 +149,7 @@ class ImportExecutor {
139
149
  await this.requireImportAccess(groupContainer, schema, authResult, options.project, "system");
140
150
  const systemDatabaseContext = projectContainer.systemDatabaseContext;
141
151
  const mapping = this.systemSchemaTransferMappingFactory.build();
152
+ this.requireMappedTables(mapping, options.tables, `system schema of project ${options.project}`);
142
153
  return await systemDatabaseContext.client.transaction(async (db) => {
143
154
  await this.disableTimeouts(db);
144
155
  await this.truncateTables(db, options.tables);
@@ -152,6 +163,9 @@ class ImportExecutor {
152
163
  }
153
164
  async importSequence(db, mapping, it) {
154
165
  const [options] = it.commandArgs;
166
+ if (!Object.hasOwn(mapping.tables, options.table) || !Object.hasOwn(mapping.tables[options.table].columns, options.column)) {
167
+ throw new ImportError(`Unknown column ${options.table}.${options.column}`);
168
+ }
155
169
  await db.query(
156
170
  "SELECT setval(pg_get_serial_sequence(?, ?), ?)",
157
171
  [`${db.schema}.${options.table}`, options.column, options.value]
@@ -170,7 +184,13 @@ class ImportExecutor {
170
184
  insertContext.rows.push(insertContext.rowParser(values));
171
185
  } catch (e) {
172
186
  if (e instanceof ParseError) {
173
- throw new ImportError(`Invalid row ${JSON.stringify(values)} for table ${options.table}: ${e.message}`);
187
+ const rowNumber = insertContext.insertedRowCount + insertContext.rows.length + 1;
188
+ const [columnIndex, ...valuePath] = e.path;
189
+ const columnName = columnIndex !== void 0 ? options.columns[Number(columnIndex)] : void 0;
190
+ const elementLocation = valuePath.length > 0 ? `, element /${valuePath.map(String).join("/")}` : "";
191
+ const location = columnName !== void 0 ? `table ${options.table}, column ${columnName}${elementLocation}` : `table ${options.table}`;
192
+ const reason = columnName !== void 0 ? e.reason : e.message;
193
+ throw new ImportError(`Invalid row #${rowNumber} ${JSON.stringify(values)} for ${location}: ${reason}`);
174
194
  } else {
175
195
  throw e;
176
196
  }
@@ -218,6 +238,14 @@ class ImportExecutor {
218
238
  throw new HttpErrorResponse(403, `You are not allowed to import ${kind} in ${projectSlug}`);
219
239
  }
220
240
  }
241
+ /** The tables an import truncates must come from the same mapping an export of this schema lists. */
242
+ requireMappedTables(mapping, tableNames, target) {
243
+ for (const tableName of tableNames) {
244
+ if (!Object.hasOwn(mapping.tables, tableName)) {
245
+ throw new ImportError(`Table ${tableName} is not part of the ${target}`);
246
+ }
247
+ }
248
+ }
221
249
  async fetchStageBySlug(systemDatabaseContext, projectSlug, stageSlug) {
222
250
  const stage = await systemDatabaseContext.queryHandler.fetch(new StageBySlugQuery(stageSlug));
223
251
  if (stage === null) {
@@ -261,13 +289,13 @@ class ImportExecutor {
261
289
  return await db.query(sql, parameters);
262
290
  }
263
291
  async buildInsertContext(db, mapping, schema, tableName, columnNames) {
264
- const tableMapping = mapping.tables[tableName];
292
+ const tableMapping = Object.hasOwn(mapping.tables, tableName) ? mapping.tables[tableName] : void 0;
265
293
  const columns = [];
266
294
  if (tableMapping === void 0) {
267
295
  throw new ImportError(`Unknown table ${tableName}`);
268
296
  }
269
297
  for (const columnName of columnNames) {
270
- const column = tableMapping.columns[columnName];
298
+ const column = Object.hasOwn(tableMapping.columns, columnName) ? tableMapping.columns[columnName] : void 0;
271
299
  if (column === void 0) {
272
300
  throw new ImportError(`Unknown column ${tableName}.${columnName}`);
273
301
  }
@@ -306,13 +334,14 @@ class ImportExecutor {
306
334
  case Model.ColumnType.Uuid:
307
335
  case Model.ColumnType.String:
308
336
  case Model.ColumnType.Enum:
309
- case Model.ColumnType.DateTime:
310
337
  case Model.ColumnType.Time:
311
- case Model.ColumnType.Date:
312
338
  case Model.ColumnType.Json:
313
339
  // Numeric is transferred as a string to avoid JS float precision loss.
314
340
  case Model.ColumnType.Numeric:
315
341
  return column.list ? listType(Typesafe.array(Typesafe.string)) : Typesafe.string;
342
+ case Model.ColumnType.Date:
343
+ case Model.ColumnType.DateTime:
344
+ return column.list ? listType(Typesafe.array(calendarDate)) : calendarDate;
316
345
  case Model.ColumnType.Int:
317
346
  case Model.ColumnType.Double:
318
347
  return column.list ? listType(Typesafe.array(Typesafe.number)) : Typesafe.number;
@@ -1 +1 @@
1
- {"version":3,"file":"ImportExecutor.js","sources":["../../../../../packages/engine-http/src/transfer/ImportExecutor.ts"],"sourcesContent":["import { Client, Connection, ConstraintHelper, DatabaseMetadataResolver, wrapIdentifier } from '@contember/database'\nimport { Model, Schema } from '@contember/schema'\nimport * as Typesafe from '@contember/typesafe'\nimport { ParseError } from '@contember/typesafe'\nimport { Command, CommandArgsMap, CommandName } from './Command.js'\nimport { DatabaseContext, StageBySlugQuery } from '@contember/engine-system-api'\nimport { DbColumnSchema, TransferMapping, TransferTableMapping } from './TransferMapping.js'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory.js'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory.js'\nimport { AuthResult, HttpErrorResponse } from '../common/index.js'\nimport { ProjectGroupContainer } from '../projectGroup/ProjectGroupContainer.js'\n\ntype Cell = boolean | number | string | readonly string[] | readonly number[] | readonly boolean[] | null\ntype Row = readonly Cell[]\n\ntype InsertContext = {\n\ttableName: string\n\tinsertStartFragment: string\n\trowFragment: string\n\trowParser: Typesafe.Type<Row>\n\trows: Array<Row>\n\tinsertedRowCount: number\n}\n\nexport class ImportError extends Error {\n}\n\nconst parsePgTextArray = (value: string): string[] => {\n\tif (value === '{}') return []\n\tif (!value.startsWith('{') || !value.endsWith('}')) {\n\t\tthrow new ParseError([], `invalid PostgreSQL array literal: ${value}`)\n\t}\n\tconst inner = value.slice(1, -1)\n\tconst result: string[] = []\n\tlet current = ''\n\tlet inQuotes = false\n\tlet escaped = false\n\tfor (const ch of inner) {\n\t\tif (escaped) {\n\t\t\tcurrent += ch\n\t\t\tescaped = false\n\t\t} else if (ch === '\\\\') {\n\t\t\tescaped = true\n\t\t} else if (ch === '\"') {\n\t\t\tinQuotes = !inQuotes\n\t\t} else if (ch === ',' && !inQuotes) {\n\t\t\tresult.push(current)\n\t\t\tcurrent = ''\n\t\t} else {\n\t\t\tcurrent += ch\n\t\t}\n\t}\n\tresult.push(current)\n\treturn result\n}\n\nconst listType = <T extends Typesafe.Json>(arrayType: Typesafe.Type<T>): Typesafe.Type<T> => {\n\treturn (input: unknown, path: PropertyKey[] = []) => {\n\t\tif (Array.isArray(input)) {\n\t\t\treturn arrayType(input, path)\n\t\t}\n\t\tif (typeof input === 'string' && input.startsWith('{')) {\n\t\t\treturn arrayType(parsePgTextArray(input), path)\n\t\t}\n\t\treturn arrayType(input, path)\n\t}\n}\n\ntype CommandProcessor<T extends CommandName> = (it: CommandIterator<T>) => Promise<CommandIterator | null>\ntype CommandProcessorMap<T extends CommandName> = { [N in CommandName]?: N extends T ? CommandProcessor<N> : undefined }\n\nclass CommandIterator<T extends CommandName = CommandName> {\n\tprivate constructor(\n\t\tpublic readonly commandName: T,\n\t\tpublic readonly commandArgs: CommandArgsMap[T],\n\t\tprivate readonly commandIterator: AsyncIterator<Command>,\n\t) {\n\t}\n\n\tpublic static async create(commands: AsyncIterable<Command>): Promise<CommandIterator | null> {\n\t\tconst commandIterator = commands[Symbol.asyncIterator]()\n\t\tconst result = await commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, commandIterator)\n\t}\n\n\tasync next(): Promise<CommandIterator | null> {\n\t\tconst result = await this.commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, this.commandIterator)\n\t}\n}\n\nexport class ImportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t\tprivate readonly databaseMetadataResolver: DatabaseMetadataResolver,\n\t) {\n\t}\n\n\tasync import(groupContainer: ProjectGroupContainer, authResult: AuthResult, commands: AsyncIterable<Command>) {\n\t\tconst it = await CommandIterator.create(commands)\n\n\t\tconst final = await this.match(it, {\n\t\t\timportContentSchemaBegin: it => this.importContentSchemaBegin(groupContainer, authResult, it),\n\t\t\timportSystemSchemaBegin: it => this.importSystemSchemaBegin(groupContainer, authResult, it),\n\t\t})\n\n\t\tif (final !== null) {\n\t\t\tthrow new ImportError(`Unexpected ${final.commandName}`)\n\t\t}\n\t}\n\n\tprivate async match<T extends CommandName>(it: CommandIterator<T> | null, processors: CommandProcessorMap<T>) {\n\t\tlet next: CommandIterator | null = it\n\n\t\twhile (next !== null) {\n\t\t\tconst processor = processors[next.commandName]\n\n\t\t\tif (processor) {\n\t\t\t\tnext = await processor(next as any)\n\t\t\t} else {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\treturn next\n\t}\n\n\tprivate async importContentSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importContentSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst stage = await this.fetchStageBySlug(systemDatabaseContext, options.project, options.stage)\n\n\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemDatabaseContext, stage: stage.slug, normalize: true })\n\n\t\tif (contentSchema.meta.version !== options.schemaVersion) {\n\t\t\tthrow new ImportError(\n\t\t\t\t`Incompatible schema version (import version ${options.schemaVersion} does not match server version ${contentSchema.meta.version})`,\n\t\t\t)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, contentSchema.schema, authResult, options.project, 'content')\n\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\t\tconst mapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema)\n\n\t\treturn await contentDatabaseClient.transaction(async db => {\n\t\t\tawait this.disableTimeouts(db)\n\t\t\tawait this.disableTriggers(db, options.tables)\n\t\t\tawait this.lockTables(db, options.tables)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\tconst result = await this.match(await it.next(), {\n\t\t\t\timportSequence: it => this.importSequence(db, mapping, it),\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\n\t\t\tawait constraintHelper.setConstraintsImmediate('foreignKey')\n\t\t\tawait this.enableTriggers(db, options.tables)\n\n\t\t\treturn result\n\t\t})\n\t}\n\n\tprivate async importSystemSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importSystemSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst schema = await groupContainer.projectSchemaResolver.getSchema(options.project)\n\n\t\tif (schema === undefined) {\n\t\t\tthrow new ImportError(`Project ${options.project} does not have schema`)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, schema, authResult, options.project, 'system')\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst mapping = this.systemSchemaTransferMappingFactory.build()\n\n\t\treturn await systemDatabaseContext.client.transaction(async db => {\n\t\t\tawait this.disableTimeouts(db)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\treturn await this.match(await it.next(), {\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async importSequence(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'importSequence'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\n\t\tawait db.query(\n\t\t\t'SELECT setval(pg_get_serial_sequence(?, ?), ?)',\n\t\t\t[`${db.schema}.${options.table}`, options.column, options.value],\n\t\t)\n\n\t\treturn it.next()\n\t}\n\n\tprivate async insertBegin(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'insertBegin'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\t\tconst insertContext = await this.buildInsertContext(db, mapping, db.schema, options.table, options.columns)\n\t\tlet insertRowsPromise: Promise<Connection.Result> | null = null\n\n\t\t// postgresql has a limit of 65535 parameters per query\n\t\tconst batchSize = Math.max(1, Math.min(1000, Math.floor(65500 / options.columns.length)))\n\n\t\tconst result = await this.match(await it.next(), {\n\t\t\tinsertRow: async it => {\n\t\t\t\tconst [values] = it.commandArgs\n\n\t\t\t\ttry {\n\t\t\t\t\tinsertContext.rows.push(insertContext.rowParser(values))\n\t\t\t\t} catch (e) {\n\t\t\t\t\tif (e instanceof ParseError) {\n\t\t\t\t\t\tthrow new ImportError(`Invalid row ${JSON.stringify(values)} for table ${options.table}: ${e.message}`)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow e\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (insertContext.rows.length === batchSize) {\n\t\t\t\t\tawait insertRowsPromise\n\t\t\t\t\tinsertRowsPromise = this.insertRows(db, insertContext)\n\t\t\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\t\t\tinsertContext.rows = []\n\t\t\t\t}\n\n\t\t\t\treturn await it.next()\n\t\t\t},\n\t\t})\n\n\t\tif (insertContext.rows.length > 0) {\n\t\t\tawait insertRowsPromise\n\t\t\tawait this.insertRows(db, insertContext)\n\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\tinsertContext.rows = []\n\t\t}\n\n\t\tif (result === null || result.commandName !== 'insertEnd') {\n\t\t\tthrow new ImportError(`Missing insertEnd command`)\n\t\t}\n\n\t\treturn await result.next()\n\t}\n\n\tprivate async createProjectContainer(groupContainer: ProjectGroupContainer, projectSlug: string) {\n\t\tconst projectContainerResolver = groupContainer.projectContainerResolver\n\t\tconst projectContainer = await projectContainerResolver.getProjectContainer(projectSlug, { alias: true })\n\n\t\tif (projectContainer === undefined) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not exists.`)\n\t\t}\n\n\t\treturn projectContainer\n\t}\n\n\tprivate async requireImportAccess(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tschema: Schema,\n\t\tauthResult: AuthResult,\n\t\tprojectSlug: string,\n\t\tkind: 'content' | 'system',\n\t) {\n\t\tconst { effective: memberships } = await groupContainer.projectMembershipResolver.resolveMemberships({\n\t\t\trequest: { get: () => '' },\n\t\t\tacl: schema.acl,\n\t\t\tprojectSlug: projectSlug,\n\t\t\tidentity: {\n\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\troles: authResult.roles,\n\t\t\t},\n\t\t})\n\n\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\tif (!projectRoles.some(role => schema.acl.roles[role]?.[kind]?.import)) {\n\t\t\tthrow new HttpErrorResponse(403, `You are not allowed to import ${kind} in ${projectSlug}`)\n\t\t}\n\t}\n\n\tprivate async fetchStageBySlug(systemDatabaseContext: DatabaseContext, projectSlug: string, stageSlug: string) {\n\t\tconst stage = await systemDatabaseContext.queryHandler.fetch(new StageBySlugQuery(stageSlug))\n\n\t\tif (stage === null) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not have stage ${stageSlug}.`)\n\t\t}\n\n\t\treturn stage\n\t}\n\n\tprivate async disableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} DISABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async enableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} ENABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async lockTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`LOCK ${tableNamesQuoted.join(', ')} IN EXCLUSIVE MODE`)\n\t}\n\n\tprivate async truncateTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`TRUNCATE ${tableNamesQuoted.join(', ')}`)\n\t}\n\n\tprivate async disableTimeouts(db: Client) {\n\t\tawait db.query('SET LOCAL statement_timeout = 0')\n\t\tawait db.query('SET LOCAL lock_timeout = 0')\n\t}\n\n\tprivate async insertRows(db: Client, context: InsertContext) {\n\t\tconst rowsFragment = context.rows.map(_ => context.rowFragment).join(',\\n')\n\t\tconst sql = context.insertStartFragment + rowsFragment\n\t\tconst parameters: Cell[] = []\n\n\t\tfor (const row of context.rows) {\n\t\t\tfor (const cell of row) {\n\t\t\t\tparameters.push(cell)\n\t\t\t}\n\t\t}\n\n\t\treturn await db.query(sql, parameters)\n\t}\n\n\tprivate async buildInsertContext(\n\t\tdb: Client,\n\t\tmapping: TransferMapping,\n\t\tschema: string,\n\t\ttableName: string,\n\t\tcolumnNames: readonly string[],\n\t): Promise<InsertContext> {\n\t\tconst tableMapping = mapping.tables[tableName]\n\t\tconst columns = []\n\n\t\tif (tableMapping === undefined) {\n\t\t\tthrow new ImportError(`Unknown table ${tableName}`)\n\t\t}\n\n\t\tfor (const columnName of columnNames) {\n\t\t\tconst column = tableMapping.columns[columnName]\n\n\t\t\tif (column === undefined) {\n\t\t\t\tthrow new ImportError(`Unknown column ${tableName}.${columnName}`)\n\t\t\t}\n\n\t\t\tcolumns.push(column)\n\t\t}\n\n\t\tconst insertStartFragment = (tableMapping.createInsertStartFragment ?? this.createInsertStartFragment)(schema, tableName, columnNames)\n\t\tconst rowFragment = '(' + columns.map(_ => '?').join(', ') + ')'\n\t\tconst rowParser = await this.buildRowParser(db, tableMapping, columns)\n\n\t\treturn {\n\t\t\ttableName,\n\t\t\tinsertStartFragment,\n\t\t\trowFragment,\n\t\t\trowParser,\n\t\t\trows: [],\n\t\t\tinsertedRowCount: 0,\n\t\t}\n\t}\n\n\tprivate createInsertStartFragment(schema: string, tableName: string, columnNames: readonly string[]): string {\n\t\tconst tableQuoted = `${wrapIdentifier(schema)}.${wrapIdentifier(tableName)}`\n\t\tconst columnsQuoted = '(' + columnNames.map(it => wrapIdentifier(it)).join(', ') + ')'\n\t\treturn `INSERT INTO ${tableQuoted} ${columnsQuoted} VALUES\\n`\n\t}\n\n\tprivate async buildRowParser(db: Client, tableMapping: TransferTableMapping, columns: DbColumnSchema[]): Promise<Typesafe.Type<readonly Cell[]>> {\n\t\tconst baseType = Typesafe.tuple(...columns.map(it => {\n\t\t\tconst base = this.buildColumnRuntimeType(it)\n\t\t\treturn it.nullable ? Typesafe.nullable(base) : base\n\t\t}))\n\n\t\tif (tableMapping.createRowParser === undefined) {\n\t\t\treturn baseType\n\t\t}\n\n\t\treturn await tableMapping.createRowParser(db, columns.map(it => it.name), baseType)\n\t}\n\n\tprivate buildColumnRuntimeType(column: DbColumnSchema): Typesafe.Type<Exclude<Cell, null>> {\n\t\tswitch (column.type) {\n\t\t\tcase Model.ColumnType.Uuid:\n\t\t\tcase Model.ColumnType.String:\n\t\t\tcase Model.ColumnType.Enum:\n\t\t\tcase Model.ColumnType.DateTime:\n\t\t\tcase Model.ColumnType.Time:\n\t\t\tcase Model.ColumnType.Date:\n\t\t\tcase Model.ColumnType.Json:\n\t\t\t// Numeric is transferred as a string to avoid JS float precision loss.\n\t\t\tcase Model.ColumnType.Numeric:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.string)) : Typesafe.string\n\t\t\tcase Model.ColumnType.Int:\n\t\t\tcase Model.ColumnType.Double:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.number)) : Typesafe.number\n\t\t\tcase Model.ColumnType.Bool:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.boolean)) : Typesafe.boolean\n\t\t}\n\t}\n}\n"],"names":["it"],"mappings":";;;;;;;AA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AK,MAAM,WAAW;AAAA,MACtB,KAAK,MAAM,WAAW;AAAA,MACtB,KAAK,MAAM,WAAW;AAAA;AAAA,MAEtB,KAAK,MAAM,WAAW;AACrB,eAAO,OAAO,OAAO,SAAS,SAAS,MAAM,SAAS,MAAM,CAAC,IAAI,SAAS;AAAA,MAC3E,KAAK,MAAM,WAAW;AAAA,MACtB,KAAK,MAAM,WAAW;AACrB,eAAO,OAAO,OAAO,SAAS,SAAS,MAAM,SAAS,MAAM,CAAC,IAAI,SAAS;AAAA,MAC3E,KAAK,MAAM,WAAW;AACrB,eAAO,OAAO,OAAO,SAAS,SAAS,MAAM,SAAS,OAAO,CAAC,IAAI,SAAS;AAAA,IAAA;AAAA,EAE9E;AACD;"}
1
+ {"version":3,"file":"ImportExecutor.js","sources":["../../../../../packages/engine-http/src/transfer/ImportExecutor.ts"],"sourcesContent":["import { Client, Connection, ConstraintHelper, DatabaseMetadataResolver, wrapIdentifier } from '@contember/database'\nimport { Model, Schema } from '@contember/schema'\nimport * as Typesafe from '@contember/typesafe'\nimport { ParseError } from '@contember/typesafe'\nimport { Command, CommandArgsMap, CommandName } from './Command.js'\nimport { DatabaseContext, StageBySlugQuery } from '@contember/engine-system-api'\nimport { isImpossibleCalendarDate } from '@contember/engine-content-api'\nimport { DbColumnSchema, TransferMapping, TransferTableMapping } from './TransferMapping.js'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory.js'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory.js'\nimport { AuthResult, HttpErrorResponse } from '../common/index.js'\nimport { ProjectGroupContainer } from '../projectGroup/ProjectGroupContainer.js'\n\ntype Cell = boolean | number | string | readonly string[] | readonly number[] | readonly boolean[] | null\ntype Row = readonly Cell[]\n\ntype InsertContext = {\n\ttableName: string\n\tinsertStartFragment: string\n\trowFragment: string\n\trowParser: Typesafe.Type<Row>\n\trows: Array<Row>\n\tinsertedRowCount: number\n}\n\nexport class ImportError extends Error {\n}\n\nconst parsePgTextArray = (value: string): string[] => {\n\tif (value === '{}') return []\n\tif (!value.startsWith('{') || !value.endsWith('}')) {\n\t\tthrow new ParseError([], `invalid PostgreSQL array literal: ${value}`)\n\t}\n\tconst inner = value.slice(1, -1)\n\tconst result: string[] = []\n\tlet current = ''\n\tlet inQuotes = false\n\tlet escaped = false\n\tfor (const ch of inner) {\n\t\tif (escaped) {\n\t\t\tcurrent += ch\n\t\t\tescaped = false\n\t\t} else if (ch === '\\\\') {\n\t\t\tescaped = true\n\t\t} else if (ch === '\"') {\n\t\t\tinQuotes = !inQuotes\n\t\t} else if (ch === ',' && !inQuotes) {\n\t\t\tresult.push(current)\n\t\t\tcurrent = ''\n\t\t} else {\n\t\t\tcurrent += ch\n\t\t}\n\t}\n\tresult.push(current)\n\treturn result\n}\n\nconst listType = <T extends Typesafe.Json>(arrayType: Typesafe.Type<T>): Typesafe.Type<T> => {\n\treturn (input: unknown, path: PropertyKey[] = []) => {\n\t\tif (Array.isArray(input)) {\n\t\t\treturn arrayType(input, path)\n\t\t}\n\t\tif (typeof input === 'string' && input.startsWith('{')) {\n\t\t\treturn arrayType(parsePgTextArray(input), path)\n\t\t}\n\t\treturn arrayType(input, path)\n\t}\n}\n\n// PostgreSQL would fail the whole batch insert on an impossible date with a server error that names neither column nor row.\nconst calendarDate: Typesafe.Type<string> = (input: unknown, path: PropertyKey[] = []) => {\n\tconst value = Typesafe.string(input, path)\n\tif (isImpossibleCalendarDate(value)) {\n\t\tthrow new ParseError(path, `${JSON.stringify(value)} is not a valid date`)\n\t}\n\treturn value\n}\n\ntype CommandProcessor<T extends CommandName> = (it: CommandIterator<T>) => Promise<CommandIterator | null>\ntype CommandProcessorMap<T extends CommandName> = { [N in CommandName]?: N extends T ? CommandProcessor<N> : undefined }\n\nclass CommandIterator<T extends CommandName = CommandName> {\n\tprivate constructor(\n\t\tpublic readonly commandName: T,\n\t\tpublic readonly commandArgs: CommandArgsMap[T],\n\t\tprivate readonly commandIterator: AsyncIterator<Command>,\n\t) {\n\t}\n\n\tpublic static async create(commands: AsyncIterable<Command>): Promise<CommandIterator | null> {\n\t\tconst commandIterator = commands[Symbol.asyncIterator]()\n\t\tconst result = await commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, commandIterator)\n\t}\n\n\tasync next(): Promise<CommandIterator | null> {\n\t\tconst result = await this.commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, this.commandIterator)\n\t}\n}\n\nexport class ImportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t\tprivate readonly databaseMetadataResolver: DatabaseMetadataResolver,\n\t) {\n\t}\n\n\tasync import(groupContainer: ProjectGroupContainer, authResult: AuthResult, commands: AsyncIterable<Command>) {\n\t\tconst it = await CommandIterator.create(commands)\n\n\t\tconst final = await this.match(it, {\n\t\t\timportContentSchemaBegin: it => this.importContentSchemaBegin(groupContainer, authResult, it),\n\t\t\timportSystemSchemaBegin: it => this.importSystemSchemaBegin(groupContainer, authResult, it),\n\t\t})\n\n\t\tif (final !== null) {\n\t\t\tthrow new ImportError(`Unexpected ${final.commandName}`)\n\t\t}\n\t}\n\n\tprivate async match<T extends CommandName>(it: CommandIterator<T> | null, processors: CommandProcessorMap<T>) {\n\t\tlet next: CommandIterator | null = it\n\n\t\twhile (next !== null) {\n\t\t\tconst processor = processors[next.commandName]\n\n\t\t\tif (processor) {\n\t\t\t\tnext = await processor(next as any)\n\t\t\t} else {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\treturn next\n\t}\n\n\tprivate async importContentSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importContentSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst stage = await this.fetchStageBySlug(systemDatabaseContext, options.project, options.stage)\n\n\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemDatabaseContext, stage: stage.slug, normalize: true })\n\n\t\tif (contentSchema.meta.version !== options.schemaVersion) {\n\t\t\tthrow new ImportError(\n\t\t\t\t`Incompatible schema version (import version ${options.schemaVersion} does not match server version ${contentSchema.meta.version})`,\n\t\t\t)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, contentSchema.schema, authResult, options.project, 'content')\n\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\t\tconst mapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema)\n\t\tthis.requireMappedTables(mapping, options.tables, `content schema of project ${options.project}`)\n\n\t\treturn await contentDatabaseClient.transaction(async db => {\n\t\t\tawait this.disableTimeouts(db)\n\t\t\tawait this.disableTriggers(db, options.tables)\n\t\t\tawait this.lockTables(db, options.tables)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\tconst result = await this.match(await it.next(), {\n\t\t\t\timportSequence: it => this.importSequence(db, mapping, it),\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\n\t\t\tawait constraintHelper.setConstraintsImmediate('foreignKey')\n\t\t\tawait this.enableTriggers(db, options.tables)\n\n\t\t\treturn result\n\t\t})\n\t}\n\n\tprivate async importSystemSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importSystemSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst schema = await groupContainer.projectSchemaResolver.getSchema(options.project)\n\n\t\tif (schema === undefined) {\n\t\t\tthrow new ImportError(`Project ${options.project} does not have schema`)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, schema, authResult, options.project, 'system')\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst mapping = this.systemSchemaTransferMappingFactory.build()\n\t\tthis.requireMappedTables(mapping, options.tables, `system schema of project ${options.project}`)\n\n\t\treturn await systemDatabaseContext.client.transaction(async db => {\n\t\t\tawait this.disableTimeouts(db)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\treturn await this.match(await it.next(), {\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async importSequence(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'importSequence'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\t\tif (!Object.hasOwn(mapping.tables, options.table) || !Object.hasOwn(mapping.tables[options.table].columns, options.column)) {\n\t\t\tthrow new ImportError(`Unknown column ${options.table}.${options.column}`)\n\t\t}\n\n\t\tawait db.query(\n\t\t\t'SELECT setval(pg_get_serial_sequence(?, ?), ?)',\n\t\t\t[`${db.schema}.${options.table}`, options.column, options.value],\n\t\t)\n\n\t\treturn it.next()\n\t}\n\n\tprivate async insertBegin(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'insertBegin'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\t\tconst insertContext = await this.buildInsertContext(db, mapping, db.schema, options.table, options.columns)\n\t\tlet insertRowsPromise: Promise<Connection.Result> | null = null\n\n\t\t// postgresql has a limit of 65535 parameters per query\n\t\tconst batchSize = Math.max(1, Math.min(1000, Math.floor(65500 / options.columns.length)))\n\n\t\tconst result = await this.match(await it.next(), {\n\t\t\tinsertRow: async it => {\n\t\t\t\tconst [values] = it.commandArgs\n\n\t\t\t\ttry {\n\t\t\t\t\tinsertContext.rows.push(insertContext.rowParser(values))\n\t\t\t\t} catch (e) {\n\t\t\t\t\tif (e instanceof ParseError) {\n\t\t\t\t\t\tconst rowNumber = insertContext.insertedRowCount + insertContext.rows.length + 1\n\t\t\t\t\t\t// The row parser is a tuple over the insertBegin columns, so the first path segment is the column index.\n\t\t\t\t\t\tconst [columnIndex, ...valuePath] = e.path\n\t\t\t\t\t\tconst columnName = columnIndex !== undefined ? options.columns[Number(columnIndex)] : undefined\n\t\t\t\t\t\tconst elementLocation = valuePath.length > 0 ? `, element /${valuePath.map(String).join('/')}` : ''\n\t\t\t\t\t\tconst location = columnName !== undefined ? `table ${options.table}, column ${columnName}${elementLocation}` : `table ${options.table}`\n\t\t\t\t\t\tconst reason = columnName !== undefined ? e.reason : e.message\n\t\t\t\t\t\tthrow new ImportError(`Invalid row #${rowNumber} ${JSON.stringify(values)} for ${location}: ${reason}`)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow e\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (insertContext.rows.length === batchSize) {\n\t\t\t\t\tawait insertRowsPromise\n\t\t\t\t\tinsertRowsPromise = this.insertRows(db, insertContext)\n\t\t\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\t\t\tinsertContext.rows = []\n\t\t\t\t}\n\n\t\t\t\treturn await it.next()\n\t\t\t},\n\t\t})\n\n\t\tif (insertContext.rows.length > 0) {\n\t\t\tawait insertRowsPromise\n\t\t\tawait this.insertRows(db, insertContext)\n\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\tinsertContext.rows = []\n\t\t}\n\n\t\tif (result === null || result.commandName !== 'insertEnd') {\n\t\t\tthrow new ImportError(`Missing insertEnd command`)\n\t\t}\n\n\t\treturn await result.next()\n\t}\n\n\tprivate async createProjectContainer(groupContainer: ProjectGroupContainer, projectSlug: string) {\n\t\tconst projectContainerResolver = groupContainer.projectContainerResolver\n\t\tconst projectContainer = await projectContainerResolver.getProjectContainer(projectSlug, { alias: true })\n\n\t\tif (projectContainer === undefined) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not exists.`)\n\t\t}\n\n\t\treturn projectContainer\n\t}\n\n\tprivate async requireImportAccess(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tschema: Schema,\n\t\tauthResult: AuthResult,\n\t\tprojectSlug: string,\n\t\tkind: 'content' | 'system',\n\t) {\n\t\tconst { effective: memberships } = await groupContainer.projectMembershipResolver.resolveMemberships({\n\t\t\trequest: { get: () => '' },\n\t\t\tacl: schema.acl,\n\t\t\tprojectSlug: projectSlug,\n\t\t\tidentity: {\n\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\troles: authResult.roles,\n\t\t\t},\n\t\t})\n\n\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\tif (!projectRoles.some(role => schema.acl.roles[role]?.[kind]?.import)) {\n\t\t\tthrow new HttpErrorResponse(403, `You are not allowed to import ${kind} in ${projectSlug}`)\n\t\t}\n\t}\n\n\t/** The tables an import truncates must come from the same mapping an export of this schema lists. */\n\tprivate requireMappedTables(mapping: TransferMapping, tableNames: readonly string[], target: string) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tif (!Object.hasOwn(mapping.tables, tableName)) {\n\t\t\t\tthrow new ImportError(`Table ${tableName} is not part of the ${target}`)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async fetchStageBySlug(systemDatabaseContext: DatabaseContext, projectSlug: string, stageSlug: string) {\n\t\tconst stage = await systemDatabaseContext.queryHandler.fetch(new StageBySlugQuery(stageSlug))\n\n\t\tif (stage === null) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not have stage ${stageSlug}.`)\n\t\t}\n\n\t\treturn stage\n\t}\n\n\tprivate async disableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} DISABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async enableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} ENABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async lockTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`LOCK ${tableNamesQuoted.join(', ')} IN EXCLUSIVE MODE`)\n\t}\n\n\tprivate async truncateTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`TRUNCATE ${tableNamesQuoted.join(', ')}`)\n\t}\n\n\tprivate async disableTimeouts(db: Client) {\n\t\tawait db.query('SET LOCAL statement_timeout = 0')\n\t\tawait db.query('SET LOCAL lock_timeout = 0')\n\t}\n\n\tprivate async insertRows(db: Client, context: InsertContext) {\n\t\tconst rowsFragment = context.rows.map(_ => context.rowFragment).join(',\\n')\n\t\tconst sql = context.insertStartFragment + rowsFragment\n\t\tconst parameters: Cell[] = []\n\n\t\tfor (const row of context.rows) {\n\t\t\tfor (const cell of row) {\n\t\t\t\tparameters.push(cell)\n\t\t\t}\n\t\t}\n\n\t\treturn await db.query(sql, parameters)\n\t}\n\n\tprivate async buildInsertContext(\n\t\tdb: Client,\n\t\tmapping: TransferMapping,\n\t\tschema: string,\n\t\ttableName: string,\n\t\tcolumnNames: readonly string[],\n\t): Promise<InsertContext> {\n\t\tconst tableMapping = Object.hasOwn(mapping.tables, tableName) ? mapping.tables[tableName] : undefined\n\t\tconst columns = []\n\n\t\tif (tableMapping === undefined) {\n\t\t\tthrow new ImportError(`Unknown table ${tableName}`)\n\t\t}\n\n\t\tfor (const columnName of columnNames) {\n\t\t\tconst column = Object.hasOwn(tableMapping.columns, columnName) ? tableMapping.columns[columnName] : undefined\n\n\t\t\tif (column === undefined) {\n\t\t\t\tthrow new ImportError(`Unknown column ${tableName}.${columnName}`)\n\t\t\t}\n\n\t\t\tcolumns.push(column)\n\t\t}\n\n\t\tconst insertStartFragment = (tableMapping.createInsertStartFragment ?? this.createInsertStartFragment)(schema, tableName, columnNames)\n\t\tconst rowFragment = '(' + columns.map(_ => '?').join(', ') + ')'\n\t\tconst rowParser = await this.buildRowParser(db, tableMapping, columns)\n\n\t\treturn {\n\t\t\ttableName,\n\t\t\tinsertStartFragment,\n\t\t\trowFragment,\n\t\t\trowParser,\n\t\t\trows: [],\n\t\t\tinsertedRowCount: 0,\n\t\t}\n\t}\n\n\tprivate createInsertStartFragment(schema: string, tableName: string, columnNames: readonly string[]): string {\n\t\tconst tableQuoted = `${wrapIdentifier(schema)}.${wrapIdentifier(tableName)}`\n\t\tconst columnsQuoted = '(' + columnNames.map(it => wrapIdentifier(it)).join(', ') + ')'\n\t\treturn `INSERT INTO ${tableQuoted} ${columnsQuoted} VALUES\\n`\n\t}\n\n\tprivate async buildRowParser(db: Client, tableMapping: TransferTableMapping, columns: DbColumnSchema[]): Promise<Typesafe.Type<readonly Cell[]>> {\n\t\tconst baseType = Typesafe.tuple(...columns.map(it => {\n\t\t\tconst base = this.buildColumnRuntimeType(it)\n\t\t\treturn it.nullable ? Typesafe.nullable(base) : base\n\t\t}))\n\n\t\tif (tableMapping.createRowParser === undefined) {\n\t\t\treturn baseType\n\t\t}\n\n\t\treturn await tableMapping.createRowParser(db, columns.map(it => it.name), baseType)\n\t}\n\n\tprivate buildColumnRuntimeType(column: DbColumnSchema): Typesafe.Type<Exclude<Cell, null>> {\n\t\tswitch (column.type) {\n\t\t\tcase Model.ColumnType.Uuid:\n\t\t\tcase Model.ColumnType.String:\n\t\t\tcase Model.ColumnType.Enum:\n\t\t\tcase Model.ColumnType.Time:\n\t\t\tcase Model.ColumnType.Json:\n\t\t\t// Numeric is transferred as a string to avoid JS float precision loss.\n\t\t\tcase Model.ColumnType.Numeric:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.string)) : Typesafe.string\n\t\t\tcase Model.ColumnType.Date:\n\t\t\tcase Model.ColumnType.DateTime:\n\t\t\t\treturn column.list ? listType(Typesafe.array(calendarDate)) : calendarDate\n\t\t\tcase Model.ColumnType.Int:\n\t\t\tcase Model.ColumnType.Double:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.number)) : Typesafe.number\n\t\t\tcase Model.ColumnType.Bool:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.boolean)) : Typesafe.boolean\n\t\t}\n\t}\n}\n"],"names":["it"],"mappings":";;;;;;;;;AAyBO,MAAM,oBAAoB,MAAM;AACvC;AAEA,MAAM,mBAAmB,CAAC,UAA4B;AACrD,MAAI,UAAU,KAAM,QAAO,CAAA;AAC3B,MAAI,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,SAAS,GAAG,GAAG;AACnD,UAAM,IAAI,WAAW,CAAA,GAAI,qCAAqC,KAAK,EAAE;AAAA,EACtE;AACA,QAAM,QAAQ,MAAM,MAAM,GAAG,EAAE;AAC/B,QAAM,SAAmB,CAAA;AACzB,MAAI,UAAU;AACd,MAAI,WAAW;AACf,MAAI,UAAU;AACd,aAAW,MAAM,OAAO;AACvB,QAAI,SAAS;AACZ,iBAAW;AACX,gBAAU;AAAA,IACX,WAAW,O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,IAAI,SAAS;AAAA,MAC3E,KAAK,MAAM,WAAW;AACrB,eAAO,OAAO,OAAO,SAAS,SAAS,MAAM,SAAS,OAAO,CAAC,IAAI,SAAS;AAAA,IAAA;AAAA,EAE9E;AACD;"}
@@ -40,6 +40,17 @@ const _CryptoWrapper = class _CryptoWrapper2 {
40
40
  version: _CryptoWrapper2.cryptoVersion
41
41
  };
42
42
  }
43
+ /**
44
+ * HMAC-SHA256 under a key derived (HKDF) from the encryption key for `purpose`, so signatures never use the
45
+ * encryption key itself and a signature made for one purpose does not verify for another.
46
+ */
47
+ sign(purpose, value) {
48
+ if (!this.encryptionKey) {
49
+ throw new Error("encryption key not provided");
50
+ }
51
+ const signingKey = Buffer.from(crypto__namespace.hkdfSync("sha256", this.encryptionKey, Buffer.alloc(0), `contember-signing:${purpose}`, 32));
52
+ return crypto__namespace.createHmac("sha256", signingKey).update(value).digest();
53
+ }
43
54
  async decrypt(value, version) {
44
55
  if (!this.encryptionKey) {
45
56
  throw new Error("encryption key not provided");
@@ -1 +1 @@
1
- {"version":3,"file":"CryptoWrapper.cjs","sources":["../../../../../packages/engine-http/src/utils/CryptoWrapper.ts"],"sourcesContent":["import * as crypto from 'node:crypto'\n\nexport class CryptoWrapper {\n\tpublic static cryptoAlgo = 'aes-256-gcm' as const\n\tpublic static cryptoVersion = 2\n\n\tconstructor(\n\t\tprivate readonly encryptionKey?: crypto.KeyObject,\n\t) {\n\t}\n\n\t/** Whether an encryption key is configured (i.e. `encrypt`/`decrypt` will work). */\n\tget enabled(): boolean {\n\t\treturn this.encryptionKey !== undefined\n\t}\n\n\tasync encrypt(value: Buffer): Promise<{ value: Buffer; version: number }> {\n\t\tif (!this.encryptionKey) {\n\t\t\tthrow new Error('encryption key not provided')\n\t\t}\n\n\t\tconst iv = crypto.randomBytes(16)\n\t\tconst cipher = crypto.createCipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, iv)\n\t\treturn {\n\t\t\tvalue: Buffer.concat([cipher.update(value), cipher.final(), iv, cipher.getAuthTag()]),\n\t\t\tversion: CryptoWrapper.cryptoVersion,\n\t\t}\n\t}\n\n\tasync decrypt(value: Buffer, version: number): Promise<{ value: Buffer; needsReEncrypt: boolean }> {\n\t\tif (!this.encryptionKey) {\n\t\t\tthrow new Error('encryption key not provided')\n\t\t}\n\t\tif (version === 1) {\n\t\t\tconst decipher = crypto.createDecipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, value.subarray(-16))\n\t\t\treturn {\n\t\t\t\tvalue: decipher.update(value.subarray(0, -16)),\n\t\t\t\tneedsReEncrypt: true,\n\t\t\t}\n\t\t} else if (version === 2) {\n\t\t\tconst decipher = crypto.createDecipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, value.subarray(-32, -16))\n\t\t\tdecipher.setAuthTag(value.subarray(-16))\n\t\t\treturn {\n\t\t\t\tvalue: Buffer.concat([decipher.update(value.subarray(0, -32)), decipher.final()]),\n\t\t\t\tneedsReEncrypt: false,\n\t\t\t}\n\t\t}\n\t\tthrow new Error('unsupported version')\n\t}\n}\n"],"names":["_CryptoWrapper","crypto"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEO,MAAM,iBAAN,MAAMA,gBAAc;AAAA,EAI1B,YACkB,eAChB;AADgB,SAAA,gBAAA;AAAA,EAElB;AAAA;AAAA,EAGA,IAAI,UAAmB;AACtB,WAAO,KAAK,kBAAkB;AAAA,EAC/B;AAAA,EAEA,MAAM,QAAQ,OAA4D;AACzE,QAAI,CAAC,KAAK,eAAe;AACxB,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC9C;AAEA,UAAM,KAAKC,kBAAO,YAAY,EAAE;AAChC,UAAM,SAASA,kBAAO,eAAeD,gBAAc,YAAY,KAAK,eAAe,EAAE;AACrF,WAAO;AAAA,MACN,OAAO,OAAO,OAAO,CAAC,OAAO,OAAO,KAAK,GAAG,OAAO,SAAS,IAAI,OAAO,WAAA,CAAY,CAAC;AAAA,MACpF,SAASA,gBAAc;AAAA,IAAA;AAAA,EAEzB;AAAA,EAEA,MAAM,QAAQ,OAAe,SAAsE;AAClG,QAAI,CAAC,KAAK,eAAe;AACxB,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC9C;AACA,QAAI,YAAY,GAAG;AAClB,YAAM,WAAWC,kBAAO,iBAAiBD,gBAAc,YAAY,KAAK,eAAe,MAAM,SAAS,GAAG,CAAC;AAC1G,aAAO;AAAA,QACN,OAAO,SAAS,OAAO,MAAM,SAAS,GAAG,GAAG,CAAC;AAAA,QAC7C,gBAAgB;AAAA,MAAA;AAAA,IAElB,WAAW,YAAY,GAAG;AACzB,YAAM,WAAWC,kBAAO,iBAAiBD,gBAAc,YAAY,KAAK,eAAe,MAAM,SAAS,KAAK,GAAG,CAAC;AAC/G,eAAS,WAAW,MAAM,SAAS,GAAG,CAAC;AACvC,aAAO;AAAA,QACN,OAAO,OAAO,OAAO,CAAC,SAAS,OAAO,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,SAAS,MAAA,CAAO,CAAC;AAAA,QAChF,gBAAgB;AAAA,MAAA;AAAA,IAElB;AACA,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACtC;AACD;AA9CC,cADY,gBACE,cAAa,aAAA;AAC3B,cAFY,gBAEE,iBAAgB,CAAA;AAFxB,IAAM,gBAAN;;"}
1
+ {"version":3,"file":"CryptoWrapper.cjs","sources":["../../../../../packages/engine-http/src/utils/CryptoWrapper.ts"],"sourcesContent":["import * as crypto from 'node:crypto'\n\nexport class CryptoWrapper {\n\tpublic static cryptoAlgo = 'aes-256-gcm' as const\n\tpublic static cryptoVersion = 2\n\n\tconstructor(\n\t\tprivate readonly encryptionKey?: crypto.KeyObject,\n\t) {\n\t}\n\n\t/** Whether an encryption key is configured (i.e. `encrypt`/`decrypt` will work). */\n\tget enabled(): boolean {\n\t\treturn this.encryptionKey !== undefined\n\t}\n\n\tasync encrypt(value: Buffer): Promise<{ value: Buffer; version: number }> {\n\t\tif (!this.encryptionKey) {\n\t\t\tthrow new Error('encryption key not provided')\n\t\t}\n\n\t\tconst iv = crypto.randomBytes(16)\n\t\tconst cipher = crypto.createCipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, iv)\n\t\treturn {\n\t\t\tvalue: Buffer.concat([cipher.update(value), cipher.final(), iv, cipher.getAuthTag()]),\n\t\t\tversion: CryptoWrapper.cryptoVersion,\n\t\t}\n\t}\n\n\t/**\n\t * HMAC-SHA256 under a key derived (HKDF) from the encryption key for `purpose`, so signatures never use the\n\t * encryption key itself and a signature made for one purpose does not verify for another.\n\t */\n\tsign(purpose: string, value: Buffer): Buffer {\n\t\tif (!this.encryptionKey) {\n\t\t\tthrow new Error('encryption key not provided')\n\t\t}\n\t\tconst signingKey = Buffer.from(crypto.hkdfSync('sha256', this.encryptionKey, Buffer.alloc(0), `contember-signing:${purpose}`, 32))\n\t\treturn crypto.createHmac('sha256', signingKey).update(value).digest()\n\t}\n\n\tasync decrypt(value: Buffer, version: number): Promise<{ value: Buffer; needsReEncrypt: boolean }> {\n\t\tif (!this.encryptionKey) {\n\t\t\tthrow new Error('encryption key not provided')\n\t\t}\n\t\tif (version === 1) {\n\t\t\tconst decipher = crypto.createDecipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, value.subarray(-16))\n\t\t\treturn {\n\t\t\t\tvalue: decipher.update(value.subarray(0, -16)),\n\t\t\t\tneedsReEncrypt: true,\n\t\t\t}\n\t\t} else if (version === 2) {\n\t\t\tconst decipher = crypto.createDecipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, value.subarray(-32, -16))\n\t\t\tdecipher.setAuthTag(value.subarray(-16))\n\t\t\treturn {\n\t\t\t\tvalue: Buffer.concat([decipher.update(value.subarray(0, -32)), decipher.final()]),\n\t\t\t\tneedsReEncrypt: false,\n\t\t\t}\n\t\t}\n\t\tthrow new Error('unsupported version')\n\t}\n}\n"],"names":["_CryptoWrapper","crypto"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEO,MAAM,iBAA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AAO,iBAAiBD,gBAAc,YAAY,KAAK,eAAe,MAAM,SAAS,KAAK,GAAG,CAAC;AAC/G,eAAS,WAAW,MAAM,SAAS,GAAG,CAAC;AACvC,aAAO;AAAA,QACN,OAAO,OAAO,OAAO,CAAC,SAAS,OAAO,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,SAAS,MAAA,CAAO,CAAC;AAAA,QAChF,gBAAgB;AAAA,MAAA;AAAA,IAElB;AACA,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACtC;AACD;AA1DC,cADY,gBACE,cAAa,aAAA;AAC3B,cAFY,gBAEE,iBAAgB,CAAA;AAFxB,IAAM,gBAAN;;"}
@@ -21,6 +21,17 @@ const _CryptoWrapper = class _CryptoWrapper2 {
21
21
  version: _CryptoWrapper2.cryptoVersion
22
22
  };
23
23
  }
24
+ /**
25
+ * HMAC-SHA256 under a key derived (HKDF) from the encryption key for `purpose`, so signatures never use the
26
+ * encryption key itself and a signature made for one purpose does not verify for another.
27
+ */
28
+ sign(purpose, value) {
29
+ if (!this.encryptionKey) {
30
+ throw new Error("encryption key not provided");
31
+ }
32
+ const signingKey = Buffer.from(crypto.hkdfSync("sha256", this.encryptionKey, Buffer.alloc(0), `contember-signing:${purpose}`, 32));
33
+ return crypto.createHmac("sha256", signingKey).update(value).digest();
34
+ }
24
35
  async decrypt(value, version) {
25
36
  if (!this.encryptionKey) {
26
37
  throw new Error("encryption key not provided");
@@ -1 +1 @@
1
- {"version":3,"file":"CryptoWrapper.js","sources":["../../../../../packages/engine-http/src/utils/CryptoWrapper.ts"],"sourcesContent":["import * as crypto from 'node:crypto'\n\nexport class CryptoWrapper {\n\tpublic static cryptoAlgo = 'aes-256-gcm' as const\n\tpublic static cryptoVersion = 2\n\n\tconstructor(\n\t\tprivate readonly encryptionKey?: crypto.KeyObject,\n\t) {\n\t}\n\n\t/** Whether an encryption key is configured (i.e. `encrypt`/`decrypt` will work). */\n\tget enabled(): boolean {\n\t\treturn this.encryptionKey !== undefined\n\t}\n\n\tasync encrypt(value: Buffer): Promise<{ value: Buffer; version: number }> {\n\t\tif (!this.encryptionKey) {\n\t\t\tthrow new Error('encryption key not provided')\n\t\t}\n\n\t\tconst iv = crypto.randomBytes(16)\n\t\tconst cipher = crypto.createCipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, iv)\n\t\treturn {\n\t\t\tvalue: Buffer.concat([cipher.update(value), cipher.final(), iv, cipher.getAuthTag()]),\n\t\t\tversion: CryptoWrapper.cryptoVersion,\n\t\t}\n\t}\n\n\tasync decrypt(value: Buffer, version: number): Promise<{ value: Buffer; needsReEncrypt: boolean }> {\n\t\tif (!this.encryptionKey) {\n\t\t\tthrow new Error('encryption key not provided')\n\t\t}\n\t\tif (version === 1) {\n\t\t\tconst decipher = crypto.createDecipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, value.subarray(-16))\n\t\t\treturn {\n\t\t\t\tvalue: decipher.update(value.subarray(0, -16)),\n\t\t\t\tneedsReEncrypt: true,\n\t\t\t}\n\t\t} else if (version === 2) {\n\t\t\tconst decipher = crypto.createDecipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, value.subarray(-32, -16))\n\t\t\tdecipher.setAuthTag(value.subarray(-16))\n\t\t\treturn {\n\t\t\t\tvalue: Buffer.concat([decipher.update(value.subarray(0, -32)), decipher.final()]),\n\t\t\t\tneedsReEncrypt: false,\n\t\t\t}\n\t\t}\n\t\tthrow new Error('unsupported version')\n\t}\n}\n"],"names":["_CryptoWrapper"],"mappings":";;;;AAEO,MAAM,iBAAN,MAAMA,gBAAc;AAAA,EAI1B,YACkB,eAChB;AADgB,SAAA,gBAAA;AAAA,EAElB;AAAA;AAAA,EAGA,IAAI,UAAmB;AACtB,WAAO,KAAK,kBAAkB;AAAA,EAC/B;AAAA,EAEA,MAAM,QAAQ,OAA4D;AACzE,QAAI,CAAC,KAAK,eAAe;AACxB,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC9C;AAEA,UAAM,KAAK,OAAO,YAAY,EAAE;AAChC,UAAM,SAAS,OAAO,eAAeA,gBAAc,YAAY,KAAK,eAAe,EAAE;AACrF,WAAO;AAAA,MACN,OAAO,OAAO,OAAO,CAAC,OAAO,OAAO,KAAK,GAAG,OAAO,SAAS,IAAI,OAAO,WAAA,CAAY,CAAC;AAAA,MACpF,SAASA,gBAAc;AAAA,IAAA;AAAA,EAEzB;AAAA,EAEA,MAAM,QAAQ,OAAe,SAAsE;AAClG,QAAI,CAAC,KAAK,eAAe;AACxB,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC9C;AACA,QAAI,YAAY,GAAG;AAClB,YAAM,WAAW,OAAO,iBAAiBA,gBAAc,YAAY,KAAK,eAAe,MAAM,SAAS,GAAG,CAAC;AAC1G,aAAO;AAAA,QACN,OAAO,SAAS,OAAO,MAAM,SAAS,GAAG,GAAG,CAAC;AAAA,QAC7C,gBAAgB;AAAA,MAAA;AAAA,IAElB,WAAW,YAAY,GAAG;AACzB,YAAM,WAAW,OAAO,iBAAiBA,gBAAc,YAAY,KAAK,eAAe,MAAM,SAAS,KAAK,GAAG,CAAC;AAC/G,eAAS,WAAW,MAAM,SAAS,GAAG,CAAC;AACvC,aAAO;AAAA,QACN,OAAO,OAAO,OAAO,CAAC,SAAS,OAAO,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,SAAS,MAAA,CAAO,CAAC;AAAA,QAChF,gBAAgB;AAAA,MAAA;AAAA,IAElB;AACA,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACtC;AACD;AA9CC,cADY,gBACE,cAAa,aAAA;AAC3B,cAFY,gBAEE,iBAAgB,CAAA;AAFxB,IAAM,gBAAN;"}
1
+ {"version":3,"file":"CryptoWrapper.js","sources":["../../../../../packages/engine-http/src/utils/CryptoWrapper.ts"],"sourcesContent":["import * as crypto from 'node:crypto'\n\nexport class CryptoWrapper {\n\tpublic static cryptoAlgo = 'aes-256-gcm' as const\n\tpublic static cryptoVersion = 2\n\n\tconstructor(\n\t\tprivate readonly encryptionKey?: crypto.KeyObject,\n\t) {\n\t}\n\n\t/** Whether an encryption key is configured (i.e. `encrypt`/`decrypt` will work). */\n\tget enabled(): boolean {\n\t\treturn this.encryptionKey !== undefined\n\t}\n\n\tasync encrypt(value: Buffer): Promise<{ value: Buffer; version: number }> {\n\t\tif (!this.encryptionKey) {\n\t\t\tthrow new Error('encryption key not provided')\n\t\t}\n\n\t\tconst iv = crypto.randomBytes(16)\n\t\tconst cipher = crypto.createCipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, iv)\n\t\treturn {\n\t\t\tvalue: Buffer.concat([cipher.update(value), cipher.final(), iv, cipher.getAuthTag()]),\n\t\t\tversion: CryptoWrapper.cryptoVersion,\n\t\t}\n\t}\n\n\t/**\n\t * HMAC-SHA256 under a key derived (HKDF) from the encryption key for `purpose`, so signatures never use the\n\t * encryption key itself and a signature made for one purpose does not verify for another.\n\t */\n\tsign(purpose: string, value: Buffer): Buffer {\n\t\tif (!this.encryptionKey) {\n\t\t\tthrow new Error('encryption key not provided')\n\t\t}\n\t\tconst signingKey = Buffer.from(crypto.hkdfSync('sha256', this.encryptionKey, Buffer.alloc(0), `contember-signing:${purpose}`, 32))\n\t\treturn crypto.createHmac('sha256', signingKey).update(value).digest()\n\t}\n\n\tasync decrypt(value: Buffer, version: number): Promise<{ value: Buffer; needsReEncrypt: boolean }> {\n\t\tif (!this.encryptionKey) {\n\t\t\tthrow new Error('encryption key not provided')\n\t\t}\n\t\tif (version === 1) {\n\t\t\tconst decipher = crypto.createDecipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, value.subarray(-16))\n\t\t\treturn {\n\t\t\t\tvalue: decipher.update(value.subarray(0, -16)),\n\t\t\t\tneedsReEncrypt: true,\n\t\t\t}\n\t\t} else if (version === 2) {\n\t\t\tconst decipher = crypto.createDecipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, value.subarray(-32, -16))\n\t\t\tdecipher.setAuthTag(value.subarray(-16))\n\t\t\treturn {\n\t\t\t\tvalue: Buffer.concat([decipher.update(value.subarray(0, -32)), decipher.final()]),\n\t\t\t\tneedsReEncrypt: false,\n\t\t\t}\n\t\t}\n\t\tthrow new Error('unsupported version')\n\t}\n}\n"],"names":["_CryptoWrapper"],"mappings":";;;;AAEO,MAAM,iBAAN,MAAMA,gBAAc;AAAA,EAI1B,YACkB,eAChB;AADgB,SAAA,gBAAA;AAAA,EAElB;AAAA;AAAA,EAGA,IAAI,UAAmB;AACtB,WAAO,KAAK,kBAAkB;AAAA,EAC/B;AAAA,EAEA,MAAM,QAAQ,OAA4D;AACzE,QAAI,CAAC,KAAK,eAAe;AACxB,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC9C;AAEA,UAAM,KAAK,OAAO,YAAY,EAAE;AAChC,UAAM,SAAS,OAAO,eAAeA,gBAAc,YAAY,KAAK,eAAe,EAAE;AACrF,WAAO;AAAA,MACN,OAAO,OAAO,OAAO,CAAC,OAAO,OAAO,KAAK,GAAG,OAAO,SAAS,IAAI,OAAO,WAAA,CAAY,CAAC;AAAA,MACpF,SAASA,gBAAc;AAAA,IAAA;AAAA,EAEzB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,KAAK,SAAiB,OAAuB;AAC5C,QAAI,CAAC,KAAK,eAAe;AACxB,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC9C;AACA,UAAM,aAAa,OAAO,KAAK,OAAO,SAAS,UAAU,KAAK,eAAe,OAAO,MAAM,CAAC,GAAG,qBAAqB,OAAO,IAAI,EAAE,CAAC;AACjI,WAAO,OAAO,WAAW,UAAU,UAAU,EAAE,OAAO,KAAK,EAAE,OAAA;AAAA,EAC9D;AAAA,EAEA,MAAM,QAAQ,OAAe,SAAsE;AAClG,QAAI,CAAC,KAAK,eAAe;AACxB,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC9C;AACA,QAAI,YAAY,GAAG;AAClB,YAAM,WAAW,OAAO,iBAAiBA,gBAAc,YAAY,KAAK,eAAe,MAAM,SAAS,GAAG,CAAC;AAC1G,aAAO;AAAA,QACN,OAAO,SAAS,OAAO,MAAM,SAAS,GAAG,GAAG,CAAC;AAAA,QAC7C,gBAAgB;AAAA,MAAA;AAAA,IAElB,WAAW,YAAY,GAAG;AACzB,YAAM,WAAW,OAAO,iBAAiBA,gBAAc,YAAY,KAAK,eAAe,MAAM,SAAS,KAAK,GAAG,CAAC;AAC/G,eAAS,WAAW,MAAM,SAAS,GAAG,CAAC;AACvC,aAAO;AAAA,QACN,OAAO,OAAO,OAAO,CAAC,SAAS,OAAO,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,SAAS,MAAA,CAAO,CAAC;AAAA,QAChF,gBAAgB;AAAA,MAAA;AAAA,IAElB;AACA,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACtC;AACD;AA1DC,cADY,gBACE,cAAa,aAAA;AAC3B,cAFY,gBAEE,iBAAgB,CAAA;AAFxB,IAAM,gBAAN;"}
@@ -27,7 +27,14 @@ function isInCIDR(ip, cidrs) {
27
27
  }
28
28
  return cidrs.some((c) => {
29
29
  try {
30
- return addr.match(ipaddr.parseCIDR(c));
30
+ const cidr = ipaddr.parseCIDR(c);
31
+ if (addr.kind() === cidr[0].kind()) {
32
+ return addr.match(cidr);
33
+ }
34
+ if (addr instanceof ipaddr.IPv6 && addr.isIPv4MappedAddress() && cidr[0] instanceof ipaddr.IPv4) {
35
+ return addr.toIPv4Address().match(cidr);
36
+ }
37
+ return false;
31
38
  } catch {
32
39
  return false;
33
40
  }
@@ -54,4 +61,5 @@ function getClientIP(req, trustedProxies) {
54
61
  return remote;
55
62
  }
56
63
  exports.getClientIP = getClientIP;
64
+ exports.isInCIDR = isInCIDR;
57
65
  //# sourceMappingURL=remoteAddress.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"remoteAddress.cjs","sources":["../../../../../packages/engine-http/src/utils/remoteAddress.ts"],"sourcesContent":["import { IncomingMessage } from 'node:http'\nimport ipaddr from 'ipaddr.js'\n\nfunction isPrivate(ip: string): boolean {\n\tlet addr: ipaddr.IPv4 | ipaddr.IPv6\n\ttry {\n\t\taddr = ipaddr.parse(ip)\n\t} catch {\n\t\treturn false\n\t}\n\n\tconst r = addr.range()\n\tif (r === 'ipv4Mapped') {\n\t\tconst mapped = (addr as ipaddr.IPv6).toIPv4Address().range()\n\t\treturn mapped === 'private' || mapped === 'loopback'\n\t}\n\n\treturn r === 'private' // IPv4 RFC1918\n\t\t|| r === 'loopback' // 127.0.0.0/8, ::1\n\t\t|| r === 'uniqueLocal' // IPv6 fc00::/7\n\t\t|| r === 'linkLocal' // IPv6 fe80::/10\n}\n\nfunction isInCIDR(ip: string, cidrs: string[]): boolean {\n\tif (!cidrs || cidrs.length === 0) {\n\t\treturn false\n\t}\n\n\tlet addr: ipaddr.IPv4 | ipaddr.IPv6\n\ttry {\n\t\taddr = ipaddr.parse(ip)\n\t} catch {\n\t\treturn false\n\t}\n\treturn cidrs.some(c => {\n\t\ttry {\n\t\t\treturn addr.match(ipaddr.parseCIDR(c))\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t})\n}\n\nexport function getClientIP(req: IncomingMessage, trustedProxies?: string[]): string {\n\tconst remote = req.socket.remoteAddress || ''\n\n\tif (!isPrivate(remote) && !isInCIDR(remote, trustedProxies || [])) {\n\t\treturn remote\n\t}\n\n\tconst xffHeader = req.headers['x-forwarded-for']\n\tlet xffList: string[] = []\n\n\tif (Array.isArray(xffHeader)) {\n\t\txffHeader.forEach(h => xffList.push(...h.split(',').map(ip => ip.trim()).filter(Boolean)))\n\t} else if (typeof xffHeader === 'string') {\n\t\txffList = xffHeader.split(',').map(ip => ip.trim()).filter(Boolean)\n\t}\n\n\tfor (let i = xffList.length - 1; i >= 0; i--) {\n\t\tconst ip = xffList[i]\n\t\tif (!isPrivate(ip) && !isInCIDR(ip, trustedProxies || [])) {\n\t\t\treturn ip\n\t\t}\n\t}\n\n\treturn remote\n}\n"],"names":[],"mappings":";;;AAGA,SAAS,UAAU,IAAqB;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GAAG,KAAK,GAAG,KAAK;AAC7C,UAAM,KAAK,QAAQ,CAAC;AACpB,QAAI,CAAC,UAAU,EAAE,KAAK,CAAC,SAAS,IAAI,kBAAkB,CAAA,CAAE,GAAG;AAC1D,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO;AACR;;"}
1
+ {"version":3,"file":"remoteAddress.cjs","sources":["../../../../../packages/engine-http/src/utils/remoteAddress.ts"],"sourcesContent":["import { IncomingMessage } from 'node:http'\nimport ipaddr from 'ipaddr.js'\n\nfunction isPrivate(ip: string): boolean {\n\tlet addr: ipaddr.IPv4 | ipaddr.IPv6\n\ttry {\n\t\taddr = ipaddr.parse(ip)\n\t} catch {\n\t\treturn false\n\t}\n\n\tconst r = addr.range()\n\tif (r === 'ipv4Mapped') {\n\t\tconst mapped = (addr as ipaddr.IPv6).toIPv4Address().range()\n\t\treturn mapped === 'private' || mapped === 'loopback'\n\t}\n\n\treturn r === 'private' // IPv4 RFC1918\n\t\t|| r === 'loopback' // 127.0.0.0/8, ::1\n\t\t|| r === 'uniqueLocal' // IPv6 fc00::/7\n\t\t|| r === 'linkLocal' // IPv6 fe80::/10\n}\n\nexport function isInCIDR(ip: string, cidrs: readonly string[]): boolean {\n\tif (!cidrs || cidrs.length === 0) {\n\t\treturn false\n\t}\n\n\tlet addr: ipaddr.IPv4 | ipaddr.IPv6\n\ttry {\n\t\taddr = ipaddr.parse(ip)\n\t} catch {\n\t\treturn false\n\t}\n\treturn cidrs.some(c => {\n\t\ttry {\n\t\t\tconst cidr = ipaddr.parseCIDR(c)\n\t\t\tif (addr.kind() === cidr[0].kind()) {\n\t\t\t\treturn addr.match(cidr)\n\t\t\t}\n\t\t\tif (addr instanceof ipaddr.IPv6 && addr.isIPv4MappedAddress() && cidr[0] instanceof ipaddr.IPv4) {\n\t\t\t\treturn addr.toIPv4Address().match(cidr)\n\t\t\t}\n\t\t\treturn false\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t})\n}\n\nexport function getClientIP(req: IncomingMessage, trustedProxies?: string[]): string {\n\tconst remote = req.socket.remoteAddress || ''\n\n\tif (!isPrivate(remote) && !isInCIDR(remote, trustedProxies || [])) {\n\t\treturn remote\n\t}\n\n\tconst xffHeader = req.headers['x-forwarded-for']\n\tlet xffList: string[] = []\n\n\tif (Array.isArray(xffHeader)) {\n\t\txffHeader.forEach(h => xffList.push(...h.split(',').map(ip => ip.trim()).filter(Boolean)))\n\t} else if (typeof xffHeader === 'string') {\n\t\txffList = xffHeader.split(',').map(ip => ip.trim()).filter(Boolean)\n\t}\n\n\tfor (let i = xffList.length - 1; i >= 0; i--) {\n\t\tconst ip = xffList[i]\n\t\tif (!isPrivate(ip) && !isInCIDR(ip, trustedProxies || [])) {\n\t\t\treturn ip\n\t\t}\n\t}\n\n\treturn remote\n}\n"],"names":[],"mappings":";;;AAGA,SAAS,UAAU,IAAqB;AACvC,MAAI;AACJ,MAAI;AACH,WAAO,OAAO,MAAM,EAAE;AAAA,EACvB,QAAQ;AACP,WAAO;AAAA,EACR;AAEA,QAAM,IAAI,KAAK,MAAA;AACf,MAAI,MAAM,cAAc;AACvB,UAAM,SAAU,KAAqB,cAAA,EAAgB,MAAA;AACrD,WAAO,WAAW,aAAa,WAAW;AAAA,EAC3C;AAEA,SAAO,MAAM,aACT,MAAM,cACN,MAAM,iBACN,MAAM;AACX;AAEO,SAAS,SAAS,IAAY,OAAmC;AACvE,MAAI,CAAC,SAAS,MAAM,WAAW,GAAG;AACjC,WAAO;AAAA,EACR;AAEA,MAAI;AACJ,MAAI;AACH,WAAO,OAAO,MAAM,EAAE;AAAA,EACvB,QAAQ;AACP,WAAO;AAAA,EACR;AACA,SAAO,MAAM,KAAK,CAAA,MAAK;AACtB,QAAI;AACH,YAAM,OAAO,OAAO,UAAU,CAAC;AAC/B,UAAI,KAAK,KAAA,MAAW,KAAK,CAAC,EAAE,QAAQ;AACnC,eAAO,KAAK,MAAM,IAAI;AAAA,MACvB;AACA,UAAI,gBAAgB,OAAO,QAAQ,KAAK,yBAAyB,KAAK,CAAC,aAAa,OAAO,MAAM;AAChG,eAAO,KAAK,gBAAgB,MAAM,IAAI;AAAA,MACvC;AACA,aAAO;AAAA,IACR,QAAQ;AACP,aAAO;AAAA,IACR;AAAA,EACD,CAAC;AACF;AAEO,SAAS,YAAY,KAAsB,gBAAmC;AACpF,QAAM,SAAS,IAAI,OAAO,iBAAiB;AAE3C,MAAI,CAAC,UAAU,MAAM,KAAK,CAAC,SAAS,QAAQ,kBAAkB,CAAA,CAAE,GAAG;AAClE,WAAO;AAAA,EACR;AAEA,QAAM,YAAY,IAAI,QAAQ,iBAAiB;AAC/C,MAAI,UAAoB,CAAA;AAExB,MAAI,MAAM,QAAQ,SAAS,GAAG;AAC7B,cAAU,QAAQ,CAAA,MAAK,QAAQ,KAAK,GAAG,EAAE,MAAM,GAAG,EAAE,IAAI,CAAA,OAAM,GAAG,KAAA,CAAM,EAAE,OAAO,OAAO,CAAC,CAAC;AAAA,EAC1F,WAAW,OAAO,cAAc,UAAU;AACzC,cAAU,UAAU,MAAM,GAAG,EAAE,IAAI,CAAA,OAAM,GAAG,KAAA,CAAM,EAAE,OAAO,OAAO;AAAA,EACnE;AAEA,WAAS,IAAI,QAAQ,SAAS,GAAG,KAAK,GAAG,KAAK;AAC7C,UAAM,KAAK,QAAQ,CAAC;AACpB,QAAI,CAAC,UAAU,EAAE,KAAK,CAAC,SAAS,IAAI,kBAAkB,CAAA,CAAE,GAAG;AAC1D,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO;AACR;;;"}
@@ -25,7 +25,14 @@ function isInCIDR(ip, cidrs) {
25
25
  }
26
26
  return cidrs.some((c) => {
27
27
  try {
28
- return addr.match(ipaddr.parseCIDR(c));
28
+ const cidr = ipaddr.parseCIDR(c);
29
+ if (addr.kind() === cidr[0].kind()) {
30
+ return addr.match(cidr);
31
+ }
32
+ if (addr instanceof ipaddr.IPv6 && addr.isIPv4MappedAddress() && cidr[0] instanceof ipaddr.IPv4) {
33
+ return addr.toIPv4Address().match(cidr);
34
+ }
35
+ return false;
29
36
  } catch {
30
37
  return false;
31
38
  }
@@ -52,6 +59,7 @@ function getClientIP(req, trustedProxies) {
52
59
  return remote;
53
60
  }
54
61
  export {
55
- getClientIP
62
+ getClientIP,
63
+ isInCIDR
56
64
  };
57
65
  //# sourceMappingURL=remoteAddress.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"remoteAddress.js","sources":["../../../../../packages/engine-http/src/utils/remoteAddress.ts"],"sourcesContent":["import { IncomingMessage } from 'node:http'\nimport ipaddr from 'ipaddr.js'\n\nfunction isPrivate(ip: string): boolean {\n\tlet addr: ipaddr.IPv4 | ipaddr.IPv6\n\ttry {\n\t\taddr = ipaddr.parse(ip)\n\t} catch {\n\t\treturn false\n\t}\n\n\tconst r = addr.range()\n\tif (r === 'ipv4Mapped') {\n\t\tconst mapped = (addr as ipaddr.IPv6).toIPv4Address().range()\n\t\treturn mapped === 'private' || mapped === 'loopback'\n\t}\n\n\treturn r === 'private' // IPv4 RFC1918\n\t\t|| r === 'loopback' // 127.0.0.0/8, ::1\n\t\t|| r === 'uniqueLocal' // IPv6 fc00::/7\n\t\t|| r === 'linkLocal' // IPv6 fe80::/10\n}\n\nfunction isInCIDR(ip: string, cidrs: string[]): boolean {\n\tif (!cidrs || cidrs.length === 0) {\n\t\treturn false\n\t}\n\n\tlet addr: ipaddr.IPv4 | ipaddr.IPv6\n\ttry {\n\t\taddr = ipaddr.parse(ip)\n\t} catch {\n\t\treturn false\n\t}\n\treturn cidrs.some(c => {\n\t\ttry {\n\t\t\treturn addr.match(ipaddr.parseCIDR(c))\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t})\n}\n\nexport function getClientIP(req: IncomingMessage, trustedProxies?: string[]): string {\n\tconst remote = req.socket.remoteAddress || ''\n\n\tif (!isPrivate(remote) && !isInCIDR(remote, trustedProxies || [])) {\n\t\treturn remote\n\t}\n\n\tconst xffHeader = req.headers['x-forwarded-for']\n\tlet xffList: string[] = []\n\n\tif (Array.isArray(xffHeader)) {\n\t\txffHeader.forEach(h => xffList.push(...h.split(',').map(ip => ip.trim()).filter(Boolean)))\n\t} else if (typeof xffHeader === 'string') {\n\t\txffList = xffHeader.split(',').map(ip => ip.trim()).filter(Boolean)\n\t}\n\n\tfor (let i = xffList.length - 1; i >= 0; i--) {\n\t\tconst ip = xffList[i]\n\t\tif (!isPrivate(ip) && !isInCIDR(ip, trustedProxies || [])) {\n\t\t\treturn ip\n\t\t}\n\t}\n\n\treturn remote\n}\n"],"names":[],"mappings":";AAGA,SAAS,UAAU,IAAqB;AACvC,MAAI;AACJ,MAAI;AACH,WAAO,OAAO,MAAM,EAAE;AAAA,EACvB,QAAQ;AACP,WAAO;AAAA,EACR;AAEA,QAAM,IAAI,KAAK,MAAA;AACf,MAAI,MAAM,cAAc;AACvB,UAAM,SAAU,KAAqB,cAAA,EAAgB,MAAA;AACrD,WAAO,WAAW,aAAa,WAAW;AAAA,EAC3C;AAEA,SAAO,MAAM,aACT,MAAM,cACN,MAAM,iBACN,MAAM;AACX;AAEA,SAAS,SAAS,IAAY,OAA0B;AACvD,MAAI,CAAC,SAAS,MAAM,WAAW,GAAG;AACjC,WAAO;AAAA,EACR;AAEA,MAAI;AACJ,MAAI;AACH,WAAO,OAAO,MAAM,EAAE;AAAA,EACvB,QAAQ;AACP,WAAO;AAAA,EACR;AACA,SAAO,MAAM,KAAK,CAAA,MAAK;AACtB,QAAI;AACH,aAAO,KAAK,MAAM,OAAO,UAAU,CAAC,CAAC;AAAA,IACtC,QAAQ;AACP,aAAO;AAAA,IACR;AAAA,EACD,CAAC;AACF;AAEO,SAAS,YAAY,KAAsB,gBAAmC;AACpF,QAAM,SAAS,IAAI,OAAO,iBAAiB;AAE3C,MAAI,CAAC,UAAU,MAAM,KAAK,CAAC,SAAS,QAAQ,kBAAkB,CAAA,CAAE,GAAG;AAClE,WAAO;AAAA,EACR;AAEA,QAAM,YAAY,IAAI,QAAQ,iBAAiB;AAC/C,MAAI,UAAoB,CAAA;AAExB,MAAI,MAAM,QAAQ,SAAS,GAAG;AAC7B,cAAU,QAAQ,CAAA,MAAK,QAAQ,KAAK,GAAG,EAAE,MAAM,GAAG,EAAE,IAAI,CAAA,OAAM,GAAG,KAAA,CAAM,EAAE,OAAO,OAAO,CAAC,CAAC;AAAA,EAC1F,WAAW,OAAO,cAAc,UAAU;AACzC,cAAU,UAAU,MAAM,GAAG,EAAE,IAAI,CAAA,OAAM,GAAG,KAAA,CAAM,EAAE,OAAO,OAAO;AAAA,EACnE;AAEA,WAAS,IAAI,QAAQ,SAAS,GAAG,KAAK,GAAG,KAAK;AAC7C,UAAM,KAAK,QAAQ,CAAC;AACpB,QAAI,CAAC,UAAU,EAAE,KAAK,CAAC,SAAS,IAAI,kBAAkB,CAAA,CAAE,GAAG;AAC1D,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO;AACR;"}
1
+ {"version":3,"file":"remoteAddress.js","sources":["../../../../../packages/engine-http/src/utils/remoteAddress.ts"],"sourcesContent":["import { IncomingMessage } from 'node:http'\nimport ipaddr from 'ipaddr.js'\n\nfunction isPrivate(ip: string): boolean {\n\tlet addr: ipaddr.IPv4 | ipaddr.IPv6\n\ttry {\n\t\taddr = ipaddr.parse(ip)\n\t} catch {\n\t\treturn false\n\t}\n\n\tconst r = addr.range()\n\tif (r === 'ipv4Mapped') {\n\t\tconst mapped = (addr as ipaddr.IPv6).toIPv4Address().range()\n\t\treturn mapped === 'private' || mapped === 'loopback'\n\t}\n\n\treturn r === 'private' // IPv4 RFC1918\n\t\t|| r === 'loopback' // 127.0.0.0/8, ::1\n\t\t|| r === 'uniqueLocal' // IPv6 fc00::/7\n\t\t|| r === 'linkLocal' // IPv6 fe80::/10\n}\n\nexport function isInCIDR(ip: string, cidrs: readonly string[]): boolean {\n\tif (!cidrs || cidrs.length === 0) {\n\t\treturn false\n\t}\n\n\tlet addr: ipaddr.IPv4 | ipaddr.IPv6\n\ttry {\n\t\taddr = ipaddr.parse(ip)\n\t} catch {\n\t\treturn false\n\t}\n\treturn cidrs.some(c => {\n\t\ttry {\n\t\t\tconst cidr = ipaddr.parseCIDR(c)\n\t\t\tif (addr.kind() === cidr[0].kind()) {\n\t\t\t\treturn addr.match(cidr)\n\t\t\t}\n\t\t\tif (addr instanceof ipaddr.IPv6 && addr.isIPv4MappedAddress() && cidr[0] instanceof ipaddr.IPv4) {\n\t\t\t\treturn addr.toIPv4Address().match(cidr)\n\t\t\t}\n\t\t\treturn false\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t})\n}\n\nexport function getClientIP(req: IncomingMessage, trustedProxies?: string[]): string {\n\tconst remote = req.socket.remoteAddress || ''\n\n\tif (!isPrivate(remote) && !isInCIDR(remote, trustedProxies || [])) {\n\t\treturn remote\n\t}\n\n\tconst xffHeader = req.headers['x-forwarded-for']\n\tlet xffList: string[] = []\n\n\tif (Array.isArray(xffHeader)) {\n\t\txffHeader.forEach(h => xffList.push(...h.split(',').map(ip => ip.trim()).filter(Boolean)))\n\t} else if (typeof xffHeader === 'string') {\n\t\txffList = xffHeader.split(',').map(ip => ip.trim()).filter(Boolean)\n\t}\n\n\tfor (let i = xffList.length - 1; i >= 0; i--) {\n\t\tconst ip = xffList[i]\n\t\tif (!isPrivate(ip) && !isInCIDR(ip, trustedProxies || [])) {\n\t\t\treturn ip\n\t\t}\n\t}\n\n\treturn remote\n}\n"],"names":[],"mappings":";AAGA,SAAS,UAAU,IAAqB;AACvC,MAAI;AACJ,MAAI;AACH,WAAO,OAAO,MAAM,EAAE;AAAA,EACvB,QAAQ;AACP,WAAO;AAAA,EACR;AAEA,QAAM,IAAI,KAAK,MAAA;AACf,MAAI,MAAM,cAAc;AACvB,UAAM,SAAU,KAAqB,cAAA,EAAgB,MAAA;AACrD,WAAO,WAAW,aAAa,WAAW;AAAA,EAC3C;AAEA,SAAO,MAAM,aACT,MAAM,cACN,MAAM,iBACN,MAAM;AACX;AAEO,SAAS,SAAS,IAAY,OAAmC;AACv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