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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/CLAUDE.md +95 -0
  2. package/dist/development/index.cjs +28 -13
  3. package/dist/development/index.cjs.map +1 -1
  4. package/dist/development/index.js +29 -14
  5. package/dist/development/index.js.map +1 -1
  6. package/dist/development/src/ActionsExecutionContainerHookFactory.cjs +14 -2
  7. package/dist/development/src/ActionsExecutionContainerHookFactory.cjs.map +1 -1
  8. package/dist/development/src/ActionsExecutionContainerHookFactory.js +14 -2
  9. package/dist/development/src/ActionsExecutionContainerHookFactory.js.map +1 -1
  10. package/dist/development/src/ActionsMetrics.cjs +98 -0
  11. package/dist/development/src/ActionsMetrics.cjs.map +1 -0
  12. package/dist/development/src/ActionsMetrics.js +98 -0
  13. package/dist/development/src/ActionsMetrics.js.map +1 -0
  14. package/dist/development/src/dispatch/EventDispatcher.cjs +93 -24
  15. package/dist/development/src/dispatch/EventDispatcher.cjs.map +1 -1
  16. package/dist/development/src/dispatch/EventDispatcher.js +93 -24
  17. package/dist/development/src/dispatch/EventDispatcher.js.map +1 -1
  18. package/dist/development/src/dispatch/EventsRepository.cjs +87 -22
  19. package/dist/development/src/dispatch/EventsRepository.cjs.map +1 -1
  20. package/dist/development/src/dispatch/EventsRepository.js +87 -22
  21. package/dist/development/src/dispatch/EventsRepository.js.map +1 -1
  22. package/dist/development/src/dispatch/ProjectDispatcher.cjs +63 -21
  23. package/dist/development/src/dispatch/ProjectDispatcher.cjs.map +1 -1
  24. package/dist/development/src/dispatch/ProjectDispatcher.js +63 -21
  25. package/dist/development/src/dispatch/ProjectDispatcher.js.map +1 -1
  26. package/dist/development/src/dispatch/WebhookFetcher.cjs +6 -1
  27. package/dist/development/src/dispatch/WebhookFetcher.cjs.map +1 -1
  28. package/dist/development/src/dispatch/WebhookFetcher.js +7 -2
  29. package/dist/development/src/dispatch/WebhookFetcher.js.map +1 -1
  30. package/dist/development/src/dispatch/WebhookTargetHandler.cjs +154 -25
  31. package/dist/development/src/dispatch/WebhookTargetHandler.cjs.map +1 -1
  32. package/dist/development/src/dispatch/WebhookTargetHandler.js +154 -25
  33. package/dist/development/src/dispatch/WebhookTargetHandler.js.map +1 -1
  34. package/dist/development/src/dispatch/redactRequestError.cjs +49 -0
  35. package/dist/development/src/dispatch/redactRequestError.cjs.map +1 -0
  36. package/dist/development/src/dispatch/redactRequestError.js +49 -0
  37. package/dist/development/src/dispatch/redactRequestError.js.map +1 -0
  38. package/dist/development/src/dispatch/truncateText.cjs +12 -0
  39. package/dist/development/src/dispatch/truncateText.cjs.map +1 -0
  40. package/dist/development/src/dispatch/truncateText.js +12 -0
  41. package/dist/development/src/dispatch/truncateText.js.map +1 -0
  42. package/dist/development/src/graphql/http/ActionsGraphQLHandlerFactory.cjs +1 -1
  43. package/dist/development/src/graphql/http/ActionsGraphQLHandlerFactory.cjs.map +1 -1
  44. package/dist/development/src/graphql/http/ActionsGraphQLHandlerFactory.js +2 -2
  45. package/dist/development/src/graphql/http/ActionsGraphQLHandlerFactory.js.map +1 -1
  46. package/dist/development/src/graphql/http/ActionsWebsocketControllerFactory.cjs +68 -28
  47. package/dist/development/src/graphql/http/ActionsWebsocketControllerFactory.cjs.map +1 -1
  48. package/dist/development/src/graphql/http/ActionsWebsocketControllerFactory.js +68 -28
  49. package/dist/development/src/graphql/http/ActionsWebsocketControllerFactory.js.map +1 -1
  50. package/dist/development/src/graphql/resolvers/ResolversFactory.cjs +1 -1
  51. package/dist/development/src/graphql/resolvers/ResolversFactory.cjs.map +1 -1
  52. package/dist/development/src/graphql/resolvers/ResolversFactory.js +1 -1
  53. package/dist/development/src/graphql/resolvers/ResolversFactory.js.map +1 -1
  54. package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs +7 -2
  55. package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs.map +1 -1
  56. package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js +7 -2
  57. package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js.map +1 -1
  58. package/dist/development/src/graphql/resolvers/query/EventsQueryResolver.cjs +1 -1
  59. package/dist/development/src/graphql/resolvers/query/EventsQueryResolver.cjs.map +1 -1
  60. package/dist/development/src/graphql/resolvers/query/EventsQueryResolver.js +1 -1
  61. package/dist/development/src/graphql/resolvers/query/EventsQueryResolver.js.map +1 -1
  62. package/dist/development/src/graphql/resolvers/query/VariablesQueryResolver.cjs +1 -4
  63. package/dist/development/src/graphql/resolvers/query/VariablesQueryResolver.cjs.map +1 -1
  64. package/dist/development/src/graphql/resolvers/query/VariablesQueryResolver.js +1 -4
  65. package/dist/development/src/graphql/resolvers/query/VariablesQueryResolver.js.map +1 -1
  66. package/dist/development/src/graphql/schema/actions.graphql.cjs +27 -11
  67. package/dist/development/src/graphql/schema/actions.graphql.cjs.map +1 -1
  68. package/dist/development/src/graphql/schema/actions.graphql.js +27 -11
  69. package/dist/development/src/graphql/schema/actions.graphql.js.map +1 -1
  70. package/dist/development/src/model/VariablesManager.cjs +59 -5
  71. package/dist/development/src/model/VariablesManager.cjs.map +1 -1
  72. package/dist/development/src/model/VariablesManager.js +60 -6
  73. package/dist/development/src/model/VariablesManager.js.map +1 -1
  74. package/dist/development/src/triggers/TriggerPayloadPersister.cjs +3 -1
  75. package/dist/development/src/triggers/TriggerPayloadPersister.cjs.map +1 -1
  76. package/dist/development/src/triggers/TriggerPayloadPersister.js +3 -1
  77. package/dist/development/src/triggers/TriggerPayloadPersister.js.map +1 -1
  78. package/dist/production/index.cjs +28 -13
  79. package/dist/production/index.cjs.map +1 -1
  80. package/dist/production/index.js +29 -14
  81. package/dist/production/index.js.map +1 -1
  82. package/dist/production/src/ActionsExecutionContainerHookFactory.cjs +14 -2
  83. package/dist/production/src/ActionsExecutionContainerHookFactory.cjs.map +1 -1
  84. package/dist/production/src/ActionsExecutionContainerHookFactory.js +14 -2
  85. package/dist/production/src/ActionsExecutionContainerHookFactory.js.map +1 -1
  86. package/dist/production/src/ActionsMetrics.cjs +98 -0
  87. package/dist/production/src/ActionsMetrics.cjs.map +1 -0
  88. package/dist/production/src/ActionsMetrics.js +98 -0
  89. package/dist/production/src/ActionsMetrics.js.map +1 -0
  90. package/dist/production/src/dispatch/EventDispatcher.cjs +93 -24
  91. package/dist/production/src/dispatch/EventDispatcher.cjs.map +1 -1
  92. package/dist/production/src/dispatch/EventDispatcher.js +93 -24
  93. package/dist/production/src/dispatch/EventDispatcher.js.map +1 -1
  94. package/dist/production/src/dispatch/EventsRepository.cjs +87 -22
  95. package/dist/production/src/dispatch/EventsRepository.cjs.map +1 -1
  96. package/dist/production/src/dispatch/EventsRepository.js +87 -22
  97. package/dist/production/src/dispatch/EventsRepository.js.map +1 -1
  98. package/dist/production/src/dispatch/ProjectDispatcher.cjs +63 -21
  99. package/dist/production/src/dispatch/ProjectDispatcher.cjs.map +1 -1
  100. package/dist/production/src/dispatch/ProjectDispatcher.js +63 -21
  101. package/dist/production/src/dispatch/ProjectDispatcher.js.map +1 -1
  102. package/dist/production/src/dispatch/WebhookFetcher.cjs +6 -1
  103. package/dist/production/src/dispatch/WebhookFetcher.cjs.map +1 -1
  104. package/dist/production/src/dispatch/WebhookFetcher.js +7 -2
  105. package/dist/production/src/dispatch/WebhookFetcher.js.map +1 -1
  106. package/dist/production/src/dispatch/WebhookTargetHandler.cjs +154 -25
  107. package/dist/production/src/dispatch/WebhookTargetHandler.cjs.map +1 -1
  108. package/dist/production/src/dispatch/WebhookTargetHandler.js +154 -25
  109. package/dist/production/src/dispatch/WebhookTargetHandler.js.map +1 -1
  110. package/dist/production/src/dispatch/redactRequestError.cjs +49 -0
  111. package/dist/production/src/dispatch/redactRequestError.cjs.map +1 -0
  112. package/dist/production/src/dispatch/redactRequestError.js +49 -0
  113. package/dist/production/src/dispatch/redactRequestError.js.map +1 -0
  114. package/dist/production/src/dispatch/truncateText.cjs +12 -0
  115. package/dist/production/src/dispatch/truncateText.cjs.map +1 -0
  116. package/dist/production/src/dispatch/truncateText.js +12 -0
  117. package/dist/production/src/dispatch/truncateText.js.map +1 -0
  118. package/dist/production/src/graphql/http/ActionsGraphQLHandlerFactory.cjs +1 -1
  119. package/dist/production/src/graphql/http/ActionsGraphQLHandlerFactory.cjs.map +1 -1
  120. package/dist/production/src/graphql/http/ActionsGraphQLHandlerFactory.js +2 -2
  121. package/dist/production/src/graphql/http/ActionsGraphQLHandlerFactory.js.map +1 -1
  122. package/dist/production/src/graphql/http/ActionsWebsocketControllerFactory.cjs +68 -28
  123. package/dist/production/src/graphql/http/ActionsWebsocketControllerFactory.cjs.map +1 -1
  124. package/dist/production/src/graphql/http/ActionsWebsocketControllerFactory.js +68 -28
  125. package/dist/production/src/graphql/http/ActionsWebsocketControllerFactory.js.map +1 -1
  126. package/dist/production/src/graphql/resolvers/ResolversFactory.cjs +1 -1
  127. package/dist/production/src/graphql/resolvers/ResolversFactory.cjs.map +1 -1
  128. package/dist/production/src/graphql/resolvers/ResolversFactory.js +1 -1
  129. package/dist/production/src/graphql/resolvers/ResolversFactory.js.map +1 -1
  130. package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs +7 -2
  131. package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs.map +1 -1
  132. package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js +7 -2
  133. package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js.map +1 -1
  134. package/dist/production/src/graphql/resolvers/query/EventsQueryResolver.cjs +1 -1
  135. package/dist/production/src/graphql/resolvers/query/EventsQueryResolver.cjs.map +1 -1
  136. package/dist/production/src/graphql/resolvers/query/EventsQueryResolver.js +1 -1
  137. package/dist/production/src/graphql/resolvers/query/EventsQueryResolver.js.map +1 -1
  138. package/dist/production/src/graphql/resolvers/query/VariablesQueryResolver.cjs +1 -4
  139. package/dist/production/src/graphql/resolvers/query/VariablesQueryResolver.cjs.map +1 -1
  140. package/dist/production/src/graphql/resolvers/query/VariablesQueryResolver.js +1 -4
  141. package/dist/production/src/graphql/resolvers/query/VariablesQueryResolver.js.map +1 -1
  142. package/dist/production/src/graphql/schema/actions.graphql.cjs +27 -11
  143. package/dist/production/src/graphql/schema/actions.graphql.cjs.map +1 -1
  144. package/dist/production/src/graphql/schema/actions.graphql.js +27 -11
  145. package/dist/production/src/graphql/schema/actions.graphql.js.map +1 -1
  146. package/dist/production/src/model/VariablesManager.cjs +59 -5
  147. package/dist/production/src/model/VariablesManager.cjs.map +1 -1
  148. package/dist/production/src/model/VariablesManager.js +60 -6
  149. package/dist/production/src/model/VariablesManager.js.map +1 -1
  150. package/dist/production/src/triggers/TriggerPayloadPersister.cjs +3 -1
  151. package/dist/production/src/triggers/TriggerPayloadPersister.cjs.map +1 -1
  152. package/dist/production/src/triggers/TriggerPayloadPersister.js +3 -1
  153. package/dist/production/src/triggers/TriggerPayloadPersister.js.map +1 -1
  154. package/dist/tests/cases/unit/actionsMetrics.test.d.ts +2 -0
  155. package/dist/tests/cases/unit/actionsMetrics.test.d.ts.map +1 -0
  156. package/dist/tests/cases/unit/actionsWebsocketController.test.d.ts +2 -0
  157. package/dist/tests/cases/unit/actionsWebsocketController.test.d.ts.map +1 -0
  158. package/dist/tests/cases/unit/dispatchTracing.test.d.ts +2 -0
  159. package/dist/tests/cases/unit/dispatchTracing.test.d.ts.map +1 -0
  160. package/dist/tests/cases/unit/eventsRepository.test.d.ts +2 -0
  161. package/dist/tests/cases/unit/eventsRepository.test.d.ts.map +1 -0
  162. package/dist/tests/cases/unit/projectDispatcher.test.d.ts +2 -0
  163. package/dist/tests/cases/unit/projectDispatcher.test.d.ts.map +1 -0
  164. package/dist/tests/cases/unit/redactRequestError.test.d.ts +2 -0
  165. package/dist/tests/cases/unit/redactRequestError.test.d.ts.map +1 -0
  166. package/dist/tests/cases/unit/truncateText.test.d.ts +2 -0
  167. package/dist/tests/cases/unit/truncateText.test.d.ts.map +1 -0
  168. package/dist/tests/cases/unit/variablesManager.test.d.ts +2 -0
  169. package/dist/tests/cases/unit/variablesManager.test.d.ts.map +1 -0
  170. package/dist/tests/cases/unit/webhookEgress.test.d.ts +2 -0
  171. package/dist/tests/cases/unit/webhookEgress.test.d.ts.map +1 -0
  172. package/dist/tests/cases/unit/webhookTracing.test.d.ts +2 -0
  173. package/dist/tests/cases/unit/webhookTracing.test.d.ts.map +1 -0
  174. package/dist/tests/src/event.d.ts +4 -0
  175. package/dist/tests/src/event.d.ts.map +1 -0
  176. package/dist/tests/src/gql.d.ts.map +1 -1
  177. package/dist/tests/src/tracer.d.ts +7 -0
  178. package/dist/tests/src/tracer.d.ts.map +1 -0
  179. package/dist/tests/src/utils.d.ts +6 -0
  180. package/dist/tests/src/utils.d.ts.map +1 -0
  181. package/dist/tests/src/uuid.d.ts.map +1 -1
  182. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  183. package/dist/types/ActionsExecutionContainerHookFactory.d.ts +3 -1
  184. package/dist/types/ActionsExecutionContainerHookFactory.d.ts.map +1 -1
  185. package/dist/types/ActionsMetrics.d.ts +59 -0
  186. package/dist/types/ActionsMetrics.d.ts.map +1 -0
  187. package/dist/types/ListenerStoreProvider.d.ts.map +1 -1
  188. package/dist/types/authorization/ActionsPermissionsFactory.d.ts.map +1 -1
  189. package/dist/types/dispatch/DispatchWorkerSupervisor.d.ts.map +1 -1
  190. package/dist/types/dispatch/EventDispatcher.d.ts +15 -4
  191. package/dist/types/dispatch/EventDispatcher.d.ts.map +1 -1
  192. package/dist/types/dispatch/EventsRepository.d.ts +34 -3
  193. package/dist/types/dispatch/EventsRepository.d.ts.map +1 -1
  194. package/dist/types/dispatch/LazyDispatchWorker.d.ts.map +1 -1
  195. package/dist/types/dispatch/ProjectDispatcher.d.ts +10 -2
  196. package/dist/types/dispatch/ProjectDispatcher.d.ts.map +1 -1
  197. package/dist/types/dispatch/TargetHandlerResolver.d.ts.map +1 -1
  198. package/dist/types/dispatch/WebhookFetcher.d.ts +7 -2
  199. package/dist/types/dispatch/WebhookFetcher.d.ts.map +1 -1
  200. package/dist/types/dispatch/WebhookTargetHandler.d.ts +14 -1
  201. package/dist/types/dispatch/WebhookTargetHandler.d.ts.map +1 -1
  202. package/dist/types/dispatch/redactRequestError.d.ts +8 -0
  203. package/dist/types/dispatch/redactRequestError.d.ts.map +1 -0
  204. package/dist/types/dispatch/truncateText.d.ts +6 -0
  205. package/dist/types/dispatch/truncateText.d.ts.map +1 -0
  206. package/dist/types/graphql/http/ActionsApiMiddlewareFactory.d.ts.map +1 -1
  207. package/dist/types/graphql/http/ActionsContextResolver.d.ts.map +1 -1
  208. package/dist/types/graphql/http/ActionsGraphQLHandlerFactory.d.ts.map +1 -1
  209. package/dist/types/graphql/http/ActionsWebsocketControllerFactory.d.ts +7 -5
  210. package/dist/types/graphql/http/ActionsWebsocketControllerFactory.d.ts.map +1 -1
  211. package/dist/types/graphql/resolvers/ResolversFactory.d.ts.map +1 -1
  212. package/dist/types/graphql/resolvers/mutation/ProcessBatchMutationResolver.d.ts.map +1 -1
  213. package/dist/types/graphql/resolvers/mutation/RetryEventMutationResolver.d.ts.map +1 -1
  214. package/dist/types/graphql/resolvers/mutation/SetVariablesMutationResolver.d.ts +3 -1
  215. package/dist/types/graphql/resolvers/mutation/SetVariablesMutationResolver.d.ts.map +1 -1
  216. package/dist/types/graphql/resolvers/mutation/StopEventMutationResolver.d.ts.map +1 -1
  217. package/dist/types/graphql/resolvers/query/EventsQueryResolver.d.ts.map +1 -1
  218. package/dist/types/graphql/resolvers/query/VariablesQueryResolver.d.ts +1 -4
  219. package/dist/types/graphql/resolvers/query/VariablesQueryResolver.d.ts.map +1 -1
  220. package/dist/types/graphql/schema/actions.graphql.d.ts.map +1 -1
  221. package/dist/types/graphql/schema/index.d.ts +27 -17
  222. package/dist/types/graphql/schema/index.d.ts.map +1 -1
  223. package/dist/types/index.d.ts +6 -0
  224. package/dist/types/index.d.ts.map +1 -1
  225. package/dist/types/model/EventByIdQuery.d.ts.map +1 -1
  226. package/dist/types/model/EventsInProcessingQuery.d.ts.map +1 -1
  227. package/dist/types/model/EventsToProcessQuery.d.ts.map +1 -1
  228. package/dist/types/model/FailedEventsQuery.d.ts.map +1 -1
  229. package/dist/types/model/SetVariableCommand.d.ts.map +1 -1
  230. package/dist/types/model/VariablesManager.d.ts +18 -3
  231. package/dist/types/model/VariablesManager.d.ts.map +1 -1
  232. package/dist/types/model/VariablesQuery.d.ts.map +1 -1
  233. package/dist/types/triggers/TriggerHandler.d.ts.map +1 -1
  234. package/dist/types/triggers/TriggerIndirectChangesFetcher.d.ts.map +1 -1
  235. package/dist/types/triggers/TriggerListenersBuilder.d.ts.map +1 -1
  236. package/dist/types/triggers/TriggerListenersFactory.d.ts.map +1 -1
  237. package/dist/types/triggers/TriggerListenersStore.d.ts.map +1 -1
  238. package/dist/types/triggers/TriggerPayloadBuilder.d.ts.map +1 -1
  239. package/dist/types/triggers/TriggerPayloadManager.d.ts.map +1 -1
  240. package/dist/types/triggers/TriggerPayloadPersister.d.ts +3 -1
  241. package/dist/types/triggers/TriggerPayloadPersister.d.ts.map +1 -1
  242. package/dist/types/tsconfig.tsbuildinfo +1 -1
  243. package/dist/types/utils/map.d.ts.map +1 -1
  244. package/dist/types/utils/notifyChannel.d.ts.map +1 -1
  245. package/graphql.codegen.yml +1 -1
  246. package/package.json +18 -16
  247. package/src/ActionsExecutionContainerHookFactory.ts +19 -2
  248. package/src/ActionsMetrics.ts +135 -0
  249. package/src/dispatch/EventDispatcher.ts +104 -26
  250. package/src/dispatch/EventsRepository.ts +146 -28
  251. package/src/dispatch/ProjectDispatcher.ts +79 -19
  252. package/src/dispatch/WebhookFetcher.ts +11 -3
  253. package/src/dispatch/WebhookTargetHandler.ts +182 -28
  254. package/src/dispatch/redactRequestError.ts +65 -0
  255. package/src/dispatch/truncateText.ts +13 -0
  256. package/src/graphql/http/ActionsGraphQLHandlerFactory.ts +2 -2
  257. package/src/graphql/http/ActionsWebsocketControllerFactory.ts +73 -30
  258. package/src/graphql/resolvers/ResolversFactory.ts +1 -1
  259. package/src/graphql/resolvers/mutation/SetVariablesMutationResolver.ts +8 -1
  260. package/src/graphql/resolvers/query/EventsQueryResolver.ts +1 -1
  261. package/src/graphql/resolvers/query/VariablesQueryResolver.ts +1 -4
  262. package/src/graphql/schema/actions.graphql.ts +26 -12
  263. package/src/graphql/schema/index.ts +30 -17
  264. package/src/index.ts +37 -12
  265. package/src/model/VariablesManager.ts +72 -6
  266. package/src/triggers/TriggerPayloadPersister.ts +6 -0
  267. package/src/tsconfig.json +1 -0
  268. package/tests/cases/unit/actionsMetrics.test.ts +76 -0
  269. package/tests/cases/unit/actionsWebsocketController.test.ts +270 -0
  270. package/tests/cases/unit/dispatchTracing.test.ts +277 -0
  271. package/tests/cases/unit/eventsRepository.test.ts +158 -0
  272. package/tests/cases/unit/projectDispatcher.test.ts +114 -0
  273. package/tests/cases/unit/redactRequestError.test.ts +66 -0
  274. package/tests/cases/unit/truncateText.test.ts +25 -0
  275. package/tests/cases/unit/variablesManager.test.ts +154 -0
  276. package/tests/cases/unit/webhookEgress.test.ts +80 -0
  277. package/tests/cases/unit/webhookHandler.test.ts +328 -33
  278. package/tests/cases/unit/webhookTracing.test.ts +163 -0
  279. package/tests/src/event.ts +27 -0
  280. package/tests/src/tracer.ts +11 -0
  281. package/tests/src/utils.ts +5 -0
@@ -1,10 +1,18 @@
1
1
  import { Actions, ActionsPayload } from '@contember/schema'
2
2
  import { EventRow, HandledEvent, InvokeHandler, InvokeHandlerArgs } from './types.js'
3
- import { VariablesMap } from '../model/VariablesManager.js'
3
+ import { resolveVariable, VariablesMap } from '../model/VariablesManager.js'
4
4
  import * as Typesafe from '@contember/typesafe'
5
5
  import { FetcherResponse, WebhookFetcher } from './WebhookFetcher.js'
6
+ import { Logger } from '@contember/logger'
7
+ import { formatTraceparent, INVALID_TRACE_ID, Tracer } from '@contember/telemetry'
8
+ import { replaceActionsVariables } from '@contember/schema-utils'
9
+ import { redactRequestError } from './redactRequestError.js'
10
+ import { truncateText } from './truncateText.js'
6
11
 
7
12
  const DEFAULT_TIMEOUT_MS = 30_000 // 30 seconds
13
+ const LOGGED_RESPONSE_MAX_LENGTH = 500
14
+ // keeps an HTML error page from bloating actions_event.log, which gains one attempt per retry
15
+ const STORED_RESPONSE_MAX_LENGTH = 4_096
8
16
 
9
17
  const ResponseType = Typesafe.noExtraProps(Typesafe.object({
10
18
  failures: Typesafe.array(
@@ -21,35 +29,114 @@ const ResponseType = Typesafe.noExtraProps(Typesafe.object({
21
29
 
22
30
  type EventResponseFactory = (eventRow: EventRow) => { ok: boolean; code?: number; response?: string; errorMessage?: string; durationMs?: number }
23
31
 
32
+ /** Carries the name and code of a failed request, and a reason only when it was redacted. Never the cause, which may quote credentials. */
33
+ class WebhookRequestError extends Error {
34
+ public readonly code?: string | number
35
+
36
+ constructor(error: unknown, redactedReason?: string) {
37
+ super(redactedReason === undefined ? 'Webhook request failed' : `Webhook request failed: ${redactedReason}`)
38
+ try {
39
+ if (error instanceof Error) {
40
+ this.name = error.name
41
+ }
42
+ } catch {
43
+ }
44
+ const seen = new Set<object>()
45
+ let current = error
46
+ while (typeof current === 'object' && current !== null && !seen.has(current)) {
47
+ seen.add(current)
48
+ try {
49
+ const code = 'code' in current ? current.code : undefined
50
+ if (typeof code === 'string' || typeof code === 'number') {
51
+ this.code = code
52
+ break
53
+ }
54
+ current = 'cause' in current ? current.cause : undefined
55
+ } catch {
56
+ break
57
+ }
58
+ }
59
+ }
60
+ }
61
+
62
+ /** The target interpolates a variable that has no value, so no request was made. */
63
+ export class UndefinedVariableError extends Error {
64
+ constructor(public readonly variables: readonly string[]) {
65
+ super(`Undefined variable ${variables.join(', ')}`)
66
+ }
67
+ }
68
+
69
+ type ResolvedRequest = {
70
+ url: string
71
+ headers: Record<string, string>
72
+ /** The resolved URL, header values and interpolated variable values, which an error message must not quote. */
73
+ secrets: ReadonlySet<string>
74
+ }
75
+
76
+ export type WebhookTargetHandlerOptions = {
77
+ propagateToWebhooks: boolean
78
+ }
79
+
24
80
  export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget> {
25
81
  constructor(
26
82
  private readonly fetcher: WebhookFetcher,
83
+ private readonly tracer: Tracer,
84
+ private readonly options: WebhookTargetHandlerOptions,
27
85
  ) {
28
86
  }
29
87
 
30
88
  public async handle({ target, events, logger, variables }: InvokeHandlerArgs<Actions.WebhookTarget>): Promise<HandledEvent[]> {
31
89
  const timeoutMs = target.timeoutMs
90
+ // Outside the try below: an undefined variable is no failed delivery, the dispatcher holds the target back instead.
91
+ const request = this.resolveVariables(target, variables)
32
92
 
33
93
  const start = process.hrtime.bigint()
34
94
  const getDuration = () => Math.floor(Number((process.hrtime.bigint() - start) / BigInt(1_000_000)))
35
95
 
36
96
  let eventResponseFactory: EventResponseFactory
37
97
  try {
38
- const response = await this.fetch(timeoutMs ?? DEFAULT_TIMEOUT_MS, target, variables, events)
98
+ // The target is identified by name only: its URL and headers may carry credentials.
99
+ const span = this.tracer.startSpan('webhook', {
100
+ kind: 'client',
101
+ attributes: {
102
+ 'contember.actions.target': target.name,
103
+ 'contember.actions.events': events.length,
104
+ },
105
+ })
106
+ const response = await this.tracer.withSpan(span, async () => {
107
+ try {
108
+ const response = await this.fetch(timeoutMs ?? DEFAULT_TIMEOUT_MS, target, request, events)
109
+ span.setAttribute('http.response.status_code', response.status)
110
+ if (!response.ok) {
111
+ span.setStatus('error')
112
+ }
113
+ return response
114
+ } catch (error) {
115
+ span.recordException(new WebhookRequestError(error))
116
+ span.setStatus('error', 'Webhook request failed')
117
+ throw error
118
+ } finally {
119
+ span.end()
120
+ }
121
+ })
39
122
 
40
123
  eventResponseFactory = this.createResponseFactory({
41
124
  response: response,
42
125
  events,
126
+ target,
127
+ logger,
128
+ secrets: request.secrets,
43
129
  })
44
130
  } catch (e) {
45
- logger.warn(e)
46
- const errorMessages = this.extractErrorMessages(e)
131
+ // Request errors may quote the resolved URL or a header value, so only a redacted reason is logged and stored.
132
+ const errorMessages = this.extractErrorMessages(e).map(it => redactRequestError(it, request.secrets))
133
+ const errorMessage = errorMessages.length ? errorMessages.join('; ') : undefined
134
+ logger.warn(new WebhookRequestError(e, errorMessage), { target: target.name })
47
135
  const result = {
48
136
  ok: false,
49
- errorMessage: errorMessages.length ? errorMessages.join('; ') : undefined,
137
+ errorMessage,
50
138
  durationMs: getDuration(),
51
139
  }
52
- eventResponseFactory = () => ({ ok: false, errorMessage: errorMessages.length ? errorMessages.join('; ') : undefined })
53
140
 
54
141
  return events.map(it => ({ target, row: it, result }))
55
142
  }
@@ -58,15 +145,28 @@ export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget
58
145
  return events.map(it => ({ target, row: it, result: { durationMs, ...eventResponseFactory(it) } }))
59
146
  }
60
147
 
61
- private createResponseFactory({ response, events }: {
148
+ private createResponseFactory({ response, events, target, logger, secrets }: {
62
149
  response: FetcherResponse
63
150
  events: EventRow[]
151
+ target: Actions.WebhookTarget
152
+ logger: Logger
153
+ secrets: ReadonlySet<string>
64
154
  }): EventResponseFactory {
155
+ const storedResponse = truncateText(response.responseText, STORED_RESPONSE_MAX_LENGTH)
65
156
  if (!response.ok) {
157
+ // The target is identified by name only: its URL and headers may carry credentials.
158
+ // The one target payload that is logged: the error body, redacted (it may echo the request) and then cut short.
159
+ logger.warn('Webhook target responded with an error status', {
160
+ target: target.name,
161
+ status: response.status,
162
+ statusText: response.statusText,
163
+ response: truncateText(redactRequestError(response.responseText, secrets), LOGGED_RESPONSE_MAX_LENGTH),
164
+ events: events.map(it => it.id),
165
+ })
66
166
  return () => ({
67
167
  ok: false,
68
168
  code: response.status,
69
- response: response.responseText,
169
+ response: storedResponse,
70
170
  errorMessage: response.statusText,
71
171
  })
72
172
  }
@@ -95,14 +195,31 @@ export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget
95
195
  const missingEvents = Object.keys(failedEvents).filter(it => !eventsInBatch.has(it))
96
196
 
97
197
  if (missingEvents.length) {
198
+ // Only the count of unknown ids: they are strings the target chose, not ours.
199
+ logger.warn('Webhook target reported failures for event ids outside the batch', {
200
+ target: target.name,
201
+ status: response.status,
202
+ unknownEventIds: missingEvents.length,
203
+ events: events.map(it => it.id),
204
+ })
98
205
  return () => ({
99
206
  ok: false,
100
207
  code: response.status,
101
- response: response.responseText,
208
+ response: storedResponse,
102
209
  errorMessage: 'Invalid response: undefined events IDs: ' + missingEvents.join('; '),
103
210
  })
104
211
  }
105
212
 
213
+ const failedIds = events.filter(it => failedEvents[it.id]).map(it => it.id)
214
+ if (failedIds.length) {
215
+ // Per-event errors come from a 2xx payload, which stays in the event log; only an error-status body is logged.
216
+ logger.warn('Webhook target reported failed events', {
217
+ target: target.name,
218
+ status: response.status,
219
+ events: failedIds,
220
+ })
221
+ }
222
+
106
223
  return it => {
107
224
  if (!failedEvents[it.id]) {
108
225
  return { ok: true, code: response.status }
@@ -114,10 +231,16 @@ export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget
114
231
  }
115
232
  }
116
233
  } catch (e: any) {
234
+ // The parser message quotes a 2xx payload, so it stays in the event log; only an error-status body is logged.
235
+ logger.warn('Webhook target returned a malformed response', {
236
+ target: target.name,
237
+ status: response.status,
238
+ events: events.map(it => it.id),
239
+ })
117
240
  return () => ({
118
241
  ok: false,
119
242
  code: response.status,
120
- response: response.responseText,
243
+ response: storedResponse,
121
244
  errorMessage: 'Invalid response: ' + e.message,
122
245
  })
123
246
  }
@@ -133,29 +256,24 @@ export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget
133
256
  return errorMessages
134
257
  }
135
258
 
136
- private async fetch(timeoutMs: number, target: Actions.WebhookTarget, variables: VariablesMap, events: EventRow[]): Promise<FetcherResponse> {
259
+ private async fetch(timeoutMs: number, target: Actions.WebhookTarget, request: ResolvedRequest, events: EventRow[]): Promise<FetcherResponse> {
137
260
  return await withTimeout(timeoutMs, async abortController => {
138
- return await this.doFetch(target, variables, abortController, events)
261
+ return await this.doFetch(target, request, abortController, events)
139
262
  })
140
263
  }
141
264
 
142
265
  private async doFetch(
143
266
  target: Actions.WebhookTarget,
144
- variables: VariablesMap,
267
+ request: ResolvedRequest,
145
268
  abortController: AbortController,
146
269
  events: EventRow[],
147
270
  ): Promise<FetcherResponse> {
148
- const resolvedUrl = this.resolveVariables(target.url, variables)
149
- const resolvedHeaders = Object.fromEntries(
150
- Object.entries(target.headers ?? {})
151
- .map(([key, value]) => [key, this.resolveVariables(value, variables)]),
152
- )
153
-
154
- return await this.fetcher.fetch(resolvedUrl, {
271
+ return await this.fetcher.fetch(request.url, {
155
272
  method: 'POST',
156
273
  headers: {
157
274
  ['User-Agent']: 'Contember Actions',
158
- ...resolvedHeaders,
275
+ ...this.createTraceHeaders(request.headers),
276
+ ...request.headers,
159
277
  ['Content-type']: 'application/json',
160
278
  },
161
279
  signal: abortController.signal,
@@ -163,6 +281,25 @@ export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget
163
281
  })
164
282
  }
165
283
 
284
+ private createTraceHeaders(resolvedHeaders: Record<string, string>): Record<string, string> {
285
+ if (this.options.propagateToWebhooks === false) {
286
+ return {}
287
+ }
288
+ const activeContext = this.tracer.activeSpanContext()
289
+ if (activeContext === undefined || activeContext.traceId === INVALID_TRACE_ID) {
290
+ return {}
291
+ }
292
+ // A target-configured header wins, in whatever case it was written.
293
+ if (Object.keys(resolvedHeaders).some(it => it.toLowerCase() === 'traceparent')) {
294
+ return {}
295
+ }
296
+ const traceState = activeContext.traceState
297
+ return {
298
+ traceparent: formatTraceparent(activeContext),
299
+ ...(traceState !== undefined ? { tracestate: traceState } : {}),
300
+ }
301
+ }
302
+
166
303
  private formatBody(events: EventRow[], target: Actions.WebhookTarget): string {
167
304
  const body = target.body ?? {}
168
305
  const path = target.payloadPath ?? []
@@ -194,13 +331,30 @@ export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget
194
331
  }
195
332
  }
196
333
 
197
- private resolveVariables(subject: string, variables: VariablesMap) {
198
- return subject.replace(/\{\{([\w_]+)}}/gm, (_, name) => {
199
- if (!variables[name]) {
200
- throw new Error(`Undefined variable ${name}`)
201
- }
202
- return variables[name]
203
- })
334
+ /** Throws {@link UndefinedVariableError} naming every variable without a value, an empty one included. */
335
+ private resolveVariables(target: Actions.WebhookTarget, variables: VariablesMap): ResolvedRequest {
336
+ const undefinedVariables = new Set<string>()
337
+ const secrets = new Set<string>()
338
+ const resolve = (subject: string) =>
339
+ replaceActionsVariables(subject, name => {
340
+ const value = resolveVariable(variables, name)
341
+ if (value === undefined) {
342
+ undefinedVariables.add(name)
343
+ return ''
344
+ }
345
+ secrets.add(value)
346
+ return value
347
+ })
348
+ const url = resolve(target.url)
349
+ const headers = Object.fromEntries(Object.entries(target.headers ?? {}).map(([key, value]) => [key, resolve(value)]))
350
+ if (undefinedVariables.size > 0) {
351
+ throw new UndefinedVariableError([...undefinedVariables])
352
+ }
353
+ secrets.add(url)
354
+ for (const value of Object.values(headers)) {
355
+ secrets.add(value)
356
+ }
357
+ return { url, headers, secrets }
204
358
  }
205
359
  }
206
360
 
@@ -0,0 +1,65 @@
1
+ // scheme, optional userinfo up to the last @ of the authority, host and port, then path, query and fragment;
2
+ // a URL ends at whitespace or a quote, and starts only where a run of scheme characters starts, which keeps the scan linear
3
+ const urlPattern = /(?<![a-z\d+.-])([a-z][a-z\d+.-]*:\/\/)(?:([^\s/?#"'`<>]*)@)?([^\s/?#"'`<>]*)([^\s"'`<>]*)/gi
4
+
5
+ const redactedMarker = '[redacted]'
6
+
7
+ // fetch strips HTTP whitespace around a header value before quoting it in an error
8
+ const trimHttpWhitespace = (value: string): string => value.replace(/^[\t\n\r ]+/, '').replace(/[\t\n\r ]+$/, '')
9
+
10
+ // a server quoting the request often names only its path or query, where a token written into the target URL lives
11
+ const urlParts = (value: string): string[] => {
12
+ let url: URL
13
+ try {
14
+ url = new URL(value)
15
+ } catch {
16
+ return []
17
+ }
18
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
19
+ return []
20
+ }
21
+ // the query without its ? only as key=value pairs, so a bare-word query does not redact that word everywhere
22
+ const query = url.search.includes('=') ? [url.search.slice(1)] : []
23
+ return [url.pathname + url.search, url.pathname, url.search, ...query, ...url.searchParams.values()].filter(it => it.length > 1)
24
+ }
25
+
26
+ const percentEncode = (value: string): string[] => {
27
+ try {
28
+ return [encodeURIComponent(value)]
29
+ } catch {
30
+ // a lone surrogate cannot be encoded, so it cannot be quoted encoded either
31
+ return []
32
+ }
33
+ }
34
+
35
+ const variantsOf = (secret: string): string[] => {
36
+ const forms = [secret, trimHttpWhitespace(secret), ...urlParts(secret)]
37
+ // JSON encoders may escape a slash as \/
38
+ return [...forms, ...forms.flatMap(percentEncode), ...forms.map(it => it.replaceAll('/', '\\/'))]
39
+ }
40
+
41
+ /**
42
+ * Removes what may carry a credential from a message about a failed webhook request, or from a target's error response:
43
+ * every occurrence of the given secrets, also with surrounding HTTP whitespace stripped, percent-encoded or with escaped slashes,
44
+ * the path, query and query values of a secret URL on their own, and then the userinfo, path, query and fragment of every URL still quoted.
45
+ * The scheme, host and port of such a URL stay for diagnostics.
46
+ */
47
+ export const redactRequestError = (message: string, secrets: Iterable<string>): string => {
48
+ const variants = new Set<string>()
49
+ for (const secret of secrets) {
50
+ for (const variant of variantsOf(secret)) {
51
+ variants.add(variant)
52
+ }
53
+ }
54
+ // the longest first, so a secret containing a shorter one is not left partly visible
55
+ const sortedSecrets = [...variants].filter(it => it !== '').sort((a, b) => b.length - a.length)
56
+ let redacted = message
57
+ for (const secret of sortedSecrets) {
58
+ redacted = redacted.replaceAll(secret, redactedMarker)
59
+ }
60
+ return redacted.replace(urlPattern, (_, scheme: string, userinfo: string | undefined, host: string, rest: string) => {
61
+ const redactedUserinfo = userinfo === undefined ? '' : `${redactedMarker}@`
62
+ const redactedRest = rest === '' || rest === '/' ? rest : `/${redactedMarker}`
63
+ return `${scheme}${redactedUserinfo}${host}${redactedRest}`
64
+ })
65
+ }
@@ -0,0 +1,13 @@
1
+ const isHighSurrogate = (code: number): boolean => code >= 0xd800 && code <= 0xdbff
2
+
3
+ /**
4
+ * Keeps at most `maxLength` UTF-16 code units of the text and appends a marker with the original length.
5
+ * A surrogate pair is never split: jsonb rejects a lone surrogate, which would fail the whole event log write.
6
+ */
7
+ export const truncateText = (text: string, maxLength: number): string => {
8
+ if (text.length <= maxLength) {
9
+ return text
10
+ }
11
+ const end = maxLength > 0 && isHighSurrogate(text.charCodeAt(maxLength - 1)) ? maxLength - 1 : maxLength
12
+ return `${text.slice(0, end)}… [truncated, ${text.length} characters in total]`
13
+ }
@@ -1,5 +1,5 @@
1
1
  import { makeExecutableSchema } from '@graphql-tools/schema'
2
- import { createGraphQLQueryHandler, GraphQLQueryHandler } from '@contember/engine-http'
2
+ import { createGraphQLJsExecutor, createGraphQLQueryHandler, GraphQLQueryHandler } from '@contember/engine-http'
3
3
  import { ResolversFactory } from '../resolvers/ResolversFactory.js'
4
4
  // biome-ignore lint/correctness/useImportExtensions: .graphql files are resolved by the bundler loader, not as JS modules
5
5
  import { schema as graphqlDocument } from '../schema/actions.graphql'
@@ -16,7 +16,7 @@ export class ActionsGraphQLHandlerFactory {
16
16
  })
17
17
 
18
18
  return createGraphQLQueryHandler<ActionsContext>({
19
- schema,
19
+ executor: createGraphQLJsExecutor(schema),
20
20
  listeners: [],
21
21
  })
22
22
  }
@@ -1,9 +1,7 @@
1
- import { HttpErrorResponse, WebSocketController } from '@contember/engine-http'
2
- import { ActionsContextResolver } from './ActionsContextResolver.js'
3
- import { DispatchWorkerSupervisorFactory } from '../../dispatch/DispatchWorkerSupervisor.js'
1
+ import { HttpErrorResponse, ProjectGroupContainer, WebSocketController } from '@contember/engine-http'
4
2
  import * as Typesafe from '@contember/typesafe'
5
3
  import { TenantRole } from '@contember/engine-tenant-api'
6
- import { Running } from '@contember/engine-common'
4
+ import { Runnable, Running } from '@contember/engine-common'
7
5
 
8
6
  const IncomingMessage = Typesafe.discriminatedUnion(
9
7
  'type',
@@ -41,11 +39,14 @@ const OutgoingMessage = Typesafe.discriminatedUnion(
41
39
 
42
40
  type OutgoingMessage = ReturnType<typeof OutgoingMessage>
43
41
 
42
+ type DispatchWorkerFactory = {
43
+ create(projectGroup: ProjectGroupContainer): Runnable
44
+ }
45
+
44
46
  export class ActionsWebsocketControllerFactory {
45
47
  constructor(
46
48
  private readonly debug: boolean,
47
- private readonly actionsContextResolver: ActionsContextResolver,
48
- private readonly dispatchWorkerSupervisorFactory: DispatchWorkerSupervisorFactory,
49
+ private readonly dispatchWorkerSupervisorFactory: DispatchWorkerFactory,
49
50
  ) {
50
51
  }
51
52
 
@@ -67,24 +68,44 @@ export class ActionsWebsocketControllerFactory {
67
68
  }
68
69
 
69
70
  let workers: { id: string; running: Promise<Running> }[] = []
71
+ let stopAllPromise: Promise<void> | undefined
72
+ let connectionClosing = false
70
73
  const abortListener = async () => {
71
- send({ type: 'message', message: 'shutting down' })
72
- await stopAll()
73
- send({ type: 'message', message: 'closing connection' })
74
- ws.close(1012) // Service Restart
74
+ connectionClosing = true
75
+ try {
76
+ send({ type: 'message', message: 'shutting down' })
77
+ await stopAll()
78
+ } catch (error) {
79
+ logger.error(error, { message: 'Websocket worker cleanup failed' })
80
+ } finally {
81
+ try {
82
+ send({ type: 'message', message: 'closing connection' })
83
+ } finally {
84
+ ws.close(1012) // Service Restart
85
+ }
86
+ }
75
87
  }
76
88
  ctx.abortSignal.addEventListener('abort', abortListener)
77
89
 
78
- const stopAll = async () => {
79
- const currentWorkers = workers.map(async it => {
80
- await (await it.running).end()
81
- send({
82
- type: 'workedStopped',
83
- workerId: it.id,
84
- })
90
+ const stopAll = (): Promise<void> => {
91
+ stopAllPromise ??= (async () => {
92
+ // a worker stays tracked until its own end() resolves, so a failed cleanup is not forgotten
93
+ const results = await Promise.allSettled(workers.map(async it => {
94
+ await (await it.running).end()
95
+ workers = workers.filter(worker => worker !== it)
96
+ send({
97
+ type: 'workedStopped',
98
+ workerId: it.id,
99
+ })
100
+ }))
101
+ const errors = results.flatMap(it => it.status === 'rejected' ? [it.reason] : [])
102
+ if (errors.length > 0) {
103
+ throw new AggregateError(errors, 'Worker cleanup failed')
104
+ }
105
+ })().finally(() => {
106
+ stopAllPromise = undefined
85
107
  })
86
- workers = []
87
- await Promise.all(currentWorkers)
108
+ return stopAllPromise
88
109
  }
89
110
  send({ type: 'ready' })
90
111
 
@@ -110,27 +131,41 @@ export class ActionsWebsocketControllerFactory {
110
131
 
111
132
  switch (data.type) {
112
133
  case 'startWorker':
134
+ if (connectionClosing || stopAllPromise !== undefined) {
135
+ send({ type: 'error', message: 'Workers are stopping' })
136
+ break
137
+ }
113
138
  const workerId = Math.random().toString().substring(2)
114
139
  const dispatchSupervisor = this.dispatchWorkerSupervisorFactory.create(projectGroup)
115
- try {
116
- const running = dispatchSupervisor.run({
140
+ const running = Promise.resolve().then(() =>
141
+ dispatchSupervisor.run({
117
142
  logger,
118
143
  onError: () => {
119
144
  send({ type: 'workerCrashed', workerId })
120
145
  },
121
146
  })
122
- workers.push({ id: workerId, running })
147
+ )
148
+ const worker = { id: workerId, running }
149
+ workers.push(worker)
150
+ try {
123
151
  await running
124
- send({ type: 'workerStarted', workerId })
125
152
  } catch (e) {
153
+ workers = workers.filter(it => it !== worker)
126
154
  logger.error(e, { message: 'Worker failed to start' })
127
155
  send({ type: 'workerFailedToStart', workerId })
156
+ break
128
157
  }
158
+ send({ type: 'workerStarted', workerId })
129
159
  break
130
160
  case 'stopAllWorkers':
131
161
  send({ type: 'message', message: 'stopping' })
132
- await stopAll()
133
- send({ type: 'message', message: 'all stopped' })
162
+ try {
163
+ await stopAll()
164
+ send({ type: 'message', message: 'all stopped' })
165
+ } catch (error) {
166
+ logger.error(error, { message: 'Websocket worker cleanup failed' })
167
+ send({ type: 'error', message: 'Worker cleanup failed' })
168
+ }
134
169
  break
135
170
  }
136
171
  })
@@ -139,11 +174,19 @@ export class ActionsWebsocketControllerFactory {
139
174
  ws.ping()
140
175
  }, 5000)
141
176
 
142
- ws.addEventListener('close', async () => {
143
- ctx.abortSignal.removeEventListener('abort', abortListener)
144
- clearInterval(pingHandle)
145
- await stopAll()
146
- })
177
+ ctx.waitUntil(
178
+ new Promise<void>(resolve => {
179
+ ws.addEventListener('close', () => {
180
+ connectionClosing = true
181
+ ctx.abortSignal.removeEventListener('abort', abortListener)
182
+ clearInterval(pingHandle)
183
+ void stopAll().then(resolve, error => {
184
+ logger.error(error, { message: 'Websocket worker cleanup failed' })
185
+ resolve()
186
+ })
187
+ })
188
+ }),
189
+ )
147
190
  }
148
191
  }
149
192
  }
@@ -27,7 +27,7 @@ export class ResolversFactory {
27
27
  } = {
28
28
  Json: JSONType,
29
29
  DateTime: DateTimeType,
30
- Uuid: UuidType,
30
+ UUID: UuidType,
31
31
  Mutation: {
32
32
  processBatch: this.processBatchMutationResolver.processBatch.bind(this.processBatchMutationResolver),
33
33
  setVariables: this.setVariablesMutationResolver.setVariables.bind(this.setVariablesMutationResolver),
@@ -2,17 +2,24 @@ import { MutationResolvers, MutationSetVariablesArgs } from '../../schema/index.
2
2
  import { ActionsContext } from '../ActionsContext.js'
3
3
  import { VariablesManager } from '../../../model/VariablesManager.js'
4
4
  import { ActionsAuthorizationActions } from '../../../authorization/index.js'
5
+ import { EventsRepository } from '../../../dispatch/EventsRepository.js'
6
+ import { notify } from '../../../utils/notifyChannel.js'
5
7
 
6
8
  export class SetVariablesMutationResolver implements MutationResolvers<ActionsContext> {
7
9
  constructor(
8
10
  private readonly variablesManager: VariablesManager,
11
+ private readonly eventsRepository: EventsRepository,
9
12
  ) {
10
13
  }
11
14
 
12
15
  async setVariables(parent: unknown, { args }: MutationSetVariablesArgs, ctx: ActionsContext) {
13
16
  await ctx.requireAccess(ActionsAuthorizationActions.VARIABLES_SET)
14
17
 
15
- await this.variablesManager.setVariables(ctx.db, args)
18
+ await this.variablesManager.setVariables(ctx.db, args, ctx.project.slug)
19
+ // After the variables are committed, so the worker re-checks held events against the new values.
20
+ if (await this.eventsRepository.resumeHeldForUndefinedVariables(ctx.db.client) > 0) {
21
+ await notify(ctx.db.client, ctx.project.slug)
22
+ }
16
23
 
17
24
  return {
18
25
  ok: true,
@@ -51,7 +51,7 @@ export class EventsQueryResolver implements QueryResolvers<ActionsContext> {
51
51
  return rows.map(row => ({
52
52
  id: row.id,
53
53
  createdAt: row.created_at,
54
- resolvedAt: row.created_at,
54
+ resolvedAt: row.resolved_at ?? undefined,
55
55
  lastStateChange: row.last_state_change,
56
56
  visibleAt: row.visible_at,
57
57
  log: row.log,
@@ -12,9 +12,6 @@ export class VariablesQueryResolver implements QueryResolvers<ActionsContext> {
12
12
  async variables(parent: unknown, args: unknown, ctx: ActionsContext) {
13
13
  await ctx.requireAccess(ActionsAuthorizationActions.VARIABLES_VIEW)
14
14
 
15
- return Object.entries(await this.variablesManager.fetchVariables(ctx.db)).map(([name, value]) => ({
16
- name,
17
- value,
18
- }))
15
+ return await this.variablesManager.listVariables(ctx.db, ctx.project.slug)
19
16
  }
20
17
  }