@contember/engine-actions 2.1.0-alpha.36 → 2.1.0-alpha.39
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.
- package/dist/development/index.cjs +118 -0
- package/dist/development/index.cjs.map +1 -0
- package/dist/development/index.js +118 -0
- package/dist/development/index.js.map +1 -0
- package/dist/development/src/ActionsExecutionContainerHookFactory.cjs +42 -0
- package/dist/development/src/ActionsExecutionContainerHookFactory.cjs.map +1 -0
- package/dist/development/src/ActionsExecutionContainerHookFactory.js +42 -0
- package/dist/development/src/ActionsExecutionContainerHookFactory.js.map +1 -0
- package/dist/development/src/ImplementationException.cjs +6 -0
- package/dist/development/src/ImplementationException.cjs.map +1 -0
- package/dist/development/src/ImplementationException.js +6 -0
- package/dist/development/src/ImplementationException.js.map +1 -0
- package/dist/development/src/ListenerStoreProvider.cjs +25 -0
- package/dist/development/src/ListenerStoreProvider.cjs.map +1 -0
- package/dist/development/src/ListenerStoreProvider.js +25 -0
- package/dist/development/src/ListenerStoreProvider.js.map +1 -0
- package/dist/development/src/authorization/ActionsAuthorizationActions.cjs +17 -0
- package/dist/development/src/authorization/ActionsAuthorizationActions.cjs.map +1 -0
- package/dist/development/src/authorization/ActionsAuthorizationActions.js +18 -0
- package/dist/development/src/authorization/ActionsAuthorizationActions.js.map +1 -0
- package/dist/development/src/authorization/ActionsPermissionsFactory.cjs +16 -0
- package/dist/development/src/authorization/ActionsPermissionsFactory.cjs.map +1 -0
- package/dist/development/src/authorization/ActionsPermissionsFactory.js +16 -0
- package/dist/development/src/authorization/ActionsPermissionsFactory.js.map +1 -0
- package/dist/development/src/dispatch/DispatchWorkerSupervisor.cjs +127 -0
- package/dist/development/src/dispatch/DispatchWorkerSupervisor.cjs.map +1 -0
- package/dist/development/src/dispatch/DispatchWorkerSupervisor.js +127 -0
- package/dist/development/src/dispatch/DispatchWorkerSupervisor.js.map +1 -0
- package/dist/development/src/dispatch/EventDispatcher.cjs +43 -0
- package/dist/development/src/dispatch/EventDispatcher.cjs.map +1 -0
- package/dist/development/src/dispatch/EventDispatcher.js +43 -0
- package/dist/development/src/dispatch/EventDispatcher.js.map +1 -0
- package/dist/development/src/dispatch/EventsRepository.cjs +122 -0
- package/dist/development/src/dispatch/EventsRepository.cjs.map +1 -0
- package/dist/development/src/dispatch/EventsRepository.js +122 -0
- package/dist/development/src/dispatch/EventsRepository.js.map +1 -0
- package/dist/development/src/dispatch/ProjectDispatcher.cjs +99 -0
- package/dist/development/src/dispatch/ProjectDispatcher.cjs.map +1 -0
- package/dist/development/src/dispatch/ProjectDispatcher.js +99 -0
- package/dist/development/src/dispatch/ProjectDispatcher.js.map +1 -0
- package/dist/development/src/dispatch/TargetHandlerResolver.cjs +16 -0
- package/dist/development/src/dispatch/TargetHandlerResolver.cjs.map +1 -0
- package/dist/development/src/dispatch/TargetHandlerResolver.js +16 -0
- package/dist/development/src/dispatch/TargetHandlerResolver.js.map +1 -0
- package/dist/development/src/dispatch/WebhookFetcher.cjs +16 -0
- package/dist/development/src/dispatch/WebhookFetcher.cjs.map +1 -0
- package/dist/development/src/dispatch/WebhookFetcher.js +16 -0
- package/dist/development/src/dispatch/WebhookFetcher.js.map +1 -0
- package/dist/development/src/dispatch/WebhookTargetHandler.cjs +198 -0
- package/dist/development/src/dispatch/WebhookTargetHandler.cjs.map +1 -0
- package/dist/development/src/dispatch/WebhookTargetHandler.js +181 -0
- package/dist/development/src/dispatch/WebhookTargetHandler.js.map +1 -0
- package/dist/development/src/graphql/http/ActionsApiMiddlewareFactory.cjs +39 -0
- package/dist/development/src/graphql/http/ActionsApiMiddlewareFactory.cjs.map +1 -0
- package/dist/development/src/graphql/http/ActionsApiMiddlewareFactory.js +39 -0
- package/dist/development/src/graphql/http/ActionsApiMiddlewareFactory.js.map +1 -0
- package/dist/development/src/graphql/http/ActionsContextResolver.cjs +36 -0
- package/dist/development/src/graphql/http/ActionsContextResolver.cjs.map +1 -0
- package/dist/development/src/graphql/http/ActionsContextResolver.js +36 -0
- package/dist/development/src/graphql/http/ActionsContextResolver.js.map +1 -0
- package/dist/development/src/graphql/http/ActionsGraphQLHandlerFactory.cjs +20 -0
- package/dist/development/src/graphql/http/ActionsGraphQLHandlerFactory.cjs.map +1 -0
- package/dist/development/src/graphql/http/ActionsGraphQLHandlerFactory.js +20 -0
- package/dist/development/src/graphql/http/ActionsGraphQLHandlerFactory.js.map +1 -0
- package/dist/development/src/graphql/http/ActionsWebsocketControllerFactory.cjs +152 -0
- package/dist/development/src/graphql/http/ActionsWebsocketControllerFactory.cjs.map +1 -0
- package/dist/development/src/graphql/http/ActionsWebsocketControllerFactory.js +135 -0
- package/dist/development/src/graphql/http/ActionsWebsocketControllerFactory.js.map +1 -0
- package/dist/development/src/graphql/resolvers/ResolversFactory.cjs +36 -0
- package/dist/development/src/graphql/resolvers/ResolversFactory.cjs.map +1 -0
- package/dist/development/src/graphql/resolvers/ResolversFactory.js +36 -0
- package/dist/development/src/graphql/resolvers/ResolversFactory.js.map +1 -0
- package/dist/development/src/graphql/resolvers/mutation/ProcessBatchMutationResolver.cjs +19 -0
- package/dist/development/src/graphql/resolvers/mutation/ProcessBatchMutationResolver.cjs.map +1 -0
- package/dist/development/src/graphql/resolvers/mutation/ProcessBatchMutationResolver.js +19 -0
- package/dist/development/src/graphql/resolvers/mutation/ProcessBatchMutationResolver.js.map +1 -0
- package/dist/development/src/graphql/resolvers/mutation/RetryEventMutationResolver.cjs +21 -0
- package/dist/development/src/graphql/resolvers/mutation/RetryEventMutationResolver.cjs.map +1 -0
- package/dist/development/src/graphql/resolvers/mutation/RetryEventMutationResolver.js +21 -0
- package/dist/development/src/graphql/resolvers/mutation/RetryEventMutationResolver.js.map +1 -0
- package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs +19 -0
- package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs.map +1 -0
- package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js +19 -0
- package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js.map +1 -0
- package/dist/development/src/graphql/resolvers/mutation/StopEventMutationResolver.cjs +19 -0
- package/dist/development/src/graphql/resolvers/mutation/StopEventMutationResolver.cjs.map +1 -0
- package/dist/development/src/graphql/resolvers/mutation/StopEventMutationResolver.js +19 -0
- package/dist/development/src/graphql/resolvers/mutation/StopEventMutationResolver.js.map +1 -0
- package/dist/development/src/graphql/resolvers/query/EventsQueryResolver.cjs +61 -0
- package/dist/development/src/graphql/resolvers/query/EventsQueryResolver.cjs.map +1 -0
- package/dist/development/src/graphql/resolvers/query/EventsQueryResolver.js +61 -0
- package/dist/development/src/graphql/resolvers/query/EventsQueryResolver.js.map +1 -0
- package/dist/development/src/graphql/resolvers/query/VariablesQueryResolver.cjs +19 -0
- package/dist/development/src/graphql/resolvers/query/VariablesQueryResolver.cjs.map +1 -0
- package/dist/development/src/graphql/resolvers/query/VariablesQueryResolver.js +19 -0
- package/dist/development/src/graphql/resolvers/query/VariablesQueryResolver.js.map +1 -0
- package/dist/development/src/graphql/schema/actions.graphql.cjs +107 -0
- package/dist/development/src/graphql/schema/actions.graphql.cjs.map +1 -0
- package/dist/development/src/graphql/schema/actions.graphql.js +107 -0
- package/dist/development/src/graphql/schema/actions.graphql.js.map +1 -0
- package/dist/development/src/migrations/2023-03-10-145000-actions-variables.cjs +16 -0
- package/dist/development/src/migrations/2023-03-10-145000-actions-variables.cjs.map +1 -0
- package/dist/development/src/migrations/2023-03-10-145000-actions-variables.js +17 -0
- package/dist/development/src/migrations/2023-03-10-145000-actions-variables.js.map +1 -0
- package/dist/development/src/migrations/2025-05-28-160000-action-event-user.cjs +16 -0
- package/dist/development/src/migrations/2025-05-28-160000-action-event-user.cjs.map +1 -0
- package/dist/development/src/migrations/2025-05-28-160000-action-event-user.js +17 -0
- package/dist/development/src/migrations/2025-05-28-160000-action-event-user.js.map +1 -0
- package/dist/development/src/migrations/index.cjs +12 -0
- package/dist/development/src/migrations/index.cjs.map +1 -0
- package/dist/development/src/migrations/index.js +12 -0
- package/dist/development/src/migrations/index.js.map +1 -0
- package/dist/development/src/migrations/snapshot.cjs +51 -0
- package/dist/development/src/migrations/snapshot.cjs.map +1 -0
- package/dist/development/src/migrations/snapshot.js +52 -0
- package/dist/development/src/migrations/snapshot.js.map +1 -0
- package/dist/development/src/model/EventByIdQuery.cjs +17 -0
- package/dist/development/src/model/EventByIdQuery.cjs.map +1 -0
- package/dist/development/src/model/EventByIdQuery.js +17 -0
- package/dist/development/src/model/EventByIdQuery.js.map +1 -0
- package/dist/development/src/model/EventsInProcessingQuery.cjs +14 -0
- package/dist/development/src/model/EventsInProcessingQuery.cjs.map +1 -0
- package/dist/development/src/model/EventsInProcessingQuery.js +14 -0
- package/dist/development/src/model/EventsInProcessingQuery.js.map +1 -0
- package/dist/development/src/model/EventsToProcessQuery.cjs +15 -0
- package/dist/development/src/model/EventsToProcessQuery.cjs.map +1 -0
- package/dist/development/src/model/EventsToProcessQuery.js +15 -0
- package/dist/development/src/model/EventsToProcessQuery.js.map +1 -0
- package/dist/development/src/model/EventsToProcessSpecification.cjs +8 -0
- package/dist/development/src/model/EventsToProcessSpecification.cjs.map +1 -0
- package/dist/development/src/model/EventsToProcessSpecification.js +8 -0
- package/dist/development/src/model/EventsToProcessSpecification.js.map +1 -0
- package/dist/development/src/model/FailedEventsQuery.cjs +14 -0
- package/dist/development/src/model/FailedEventsQuery.cjs.map +1 -0
- package/dist/development/src/model/FailedEventsQuery.js +14 -0
- package/dist/development/src/model/FailedEventsQuery.js.map +1 -0
- package/dist/development/src/model/SetVariableCommand.cjs +21 -0
- package/dist/development/src/model/SetVariableCommand.cjs.map +1 -0
- package/dist/development/src/model/SetVariableCommand.js +21 -0
- package/dist/development/src/model/SetVariableCommand.js.map +1 -0
- package/dist/development/src/model/VariablesManager.cjs +41 -0
- package/dist/development/src/model/VariablesManager.cjs.map +1 -0
- package/dist/development/src/model/VariablesManager.js +41 -0
- package/dist/development/src/model/VariablesManager.js.map +1 -0
- package/dist/development/src/model/VariablesQuery.cjs +10 -0
- package/dist/development/src/model/VariablesQuery.cjs.map +1 -0
- package/dist/development/src/model/VariablesQuery.js +10 -0
- package/dist/development/src/model/VariablesQuery.js.map +1 -0
- package/dist/development/src/triggers/TriggerHandler.cjs +129 -0
- package/dist/development/src/triggers/TriggerHandler.cjs.map +1 -0
- package/dist/development/src/triggers/TriggerHandler.js +129 -0
- package/dist/development/src/triggers/TriggerHandler.js.map +1 -0
- package/dist/development/src/triggers/TriggerIndirectChangesFetcher.cjs +63 -0
- package/dist/development/src/triggers/TriggerIndirectChangesFetcher.cjs.map +1 -0
- package/dist/development/src/triggers/TriggerIndirectChangesFetcher.js +63 -0
- package/dist/development/src/triggers/TriggerIndirectChangesFetcher.js.map +1 -0
- package/dist/development/src/triggers/TriggerListenersBuilder.cjs +169 -0
- package/dist/development/src/triggers/TriggerListenersBuilder.cjs.map +1 -0
- package/dist/development/src/triggers/TriggerListenersBuilder.js +169 -0
- package/dist/development/src/triggers/TriggerListenersBuilder.js.map +1 -0
- package/dist/development/src/triggers/TriggerListenersFactory.cjs +17 -0
- package/dist/development/src/triggers/TriggerListenersFactory.cjs.map +1 -0
- package/dist/development/src/triggers/TriggerListenersFactory.js +17 -0
- package/dist/development/src/triggers/TriggerListenersFactory.js.map +1 -0
- package/dist/development/src/triggers/TriggerListenersStore.cjs +24 -0
- package/dist/development/src/triggers/TriggerListenersStore.cjs.map +1 -0
- package/dist/development/src/triggers/TriggerListenersStore.js +24 -0
- package/dist/development/src/triggers/TriggerListenersStore.js.map +1 -0
- package/dist/development/src/triggers/TriggerPayloadBuilder.cjs +163 -0
- package/dist/development/src/triggers/TriggerPayloadBuilder.cjs.map +1 -0
- package/dist/development/src/triggers/TriggerPayloadBuilder.js +163 -0
- package/dist/development/src/triggers/TriggerPayloadBuilder.js.map +1 -0
- package/dist/development/src/triggers/TriggerPayloadManager.cjs +27 -0
- package/dist/development/src/triggers/TriggerPayloadManager.cjs.map +1 -0
- package/dist/development/src/triggers/TriggerPayloadManager.js +27 -0
- package/dist/development/src/triggers/TriggerPayloadManager.js.map +1 -0
- package/dist/development/src/triggers/TriggerPayloadPersister.cjs +47 -0
- package/dist/development/src/triggers/TriggerPayloadPersister.cjs.map +1 -0
- package/dist/development/src/triggers/TriggerPayloadPersister.js +47 -0
- package/dist/development/src/triggers/TriggerPayloadPersister.js.map +1 -0
- package/dist/development/src/utils/assertNever.cjs +7 -0
- package/dist/development/src/utils/assertNever.cjs.map +1 -0
- package/dist/development/src/utils/assertNever.js +7 -0
- package/dist/development/src/utils/assertNever.js.map +1 -0
- package/dist/development/src/utils/map.cjs +13 -0
- package/dist/development/src/utils/map.cjs.map +1 -0
- package/dist/development/src/utils/map.js +13 -0
- package/dist/development/src/utils/map.js.map +1 -0
- package/dist/development/src/utils/notifyChannel.cjs +9 -0
- package/dist/development/src/utils/notifyChannel.cjs.map +1 -0
- package/dist/development/src/utils/notifyChannel.js +9 -0
- package/dist/development/src/utils/notifyChannel.js.map +1 -0
- package/dist/production/index.cjs +118 -0
- package/dist/production/index.cjs.map +1 -0
- package/dist/production/index.js +118 -0
- package/dist/production/index.js.map +1 -0
- package/dist/production/src/ActionsExecutionContainerHookFactory.cjs +42 -0
- package/dist/production/src/ActionsExecutionContainerHookFactory.cjs.map +1 -0
- package/dist/production/src/ActionsExecutionContainerHookFactory.js +42 -0
- package/dist/production/src/ActionsExecutionContainerHookFactory.js.map +1 -0
- package/dist/production/src/ImplementationException.cjs +6 -0
- package/dist/production/src/ImplementationException.cjs.map +1 -0
- package/dist/production/src/ImplementationException.js +6 -0
- package/dist/production/src/ImplementationException.js.map +1 -0
- package/dist/production/src/ListenerStoreProvider.cjs +25 -0
- package/dist/production/src/ListenerStoreProvider.cjs.map +1 -0
- package/dist/production/src/ListenerStoreProvider.js +25 -0
- package/dist/production/src/ListenerStoreProvider.js.map +1 -0
- package/dist/production/src/authorization/ActionsAuthorizationActions.cjs +17 -0
- package/dist/production/src/authorization/ActionsAuthorizationActions.cjs.map +1 -0
- package/dist/production/src/authorization/ActionsAuthorizationActions.js +18 -0
- package/dist/production/src/authorization/ActionsAuthorizationActions.js.map +1 -0
- package/dist/production/src/authorization/ActionsPermissionsFactory.cjs +16 -0
- package/dist/production/src/authorization/ActionsPermissionsFactory.cjs.map +1 -0
- package/dist/production/src/authorization/ActionsPermissionsFactory.js +16 -0
- package/dist/production/src/authorization/ActionsPermissionsFactory.js.map +1 -0
- package/dist/production/src/dispatch/DispatchWorkerSupervisor.cjs +127 -0
- package/dist/production/src/dispatch/DispatchWorkerSupervisor.cjs.map +1 -0
- package/dist/production/src/dispatch/DispatchWorkerSupervisor.js +127 -0
- package/dist/production/src/dispatch/DispatchWorkerSupervisor.js.map +1 -0
- package/dist/production/src/dispatch/EventDispatcher.cjs +43 -0
- package/dist/production/src/dispatch/EventDispatcher.cjs.map +1 -0
- package/dist/production/src/dispatch/EventDispatcher.js +43 -0
- package/dist/production/src/dispatch/EventDispatcher.js.map +1 -0
- package/dist/production/src/dispatch/EventsRepository.cjs +122 -0
- package/dist/production/src/dispatch/EventsRepository.cjs.map +1 -0
- package/dist/production/src/dispatch/EventsRepository.js +122 -0
- package/dist/production/src/dispatch/EventsRepository.js.map +1 -0
- package/dist/production/src/dispatch/ProjectDispatcher.cjs +99 -0
- package/dist/production/src/dispatch/ProjectDispatcher.cjs.map +1 -0
- package/dist/production/src/dispatch/ProjectDispatcher.js +99 -0
- package/dist/production/src/dispatch/ProjectDispatcher.js.map +1 -0
- package/dist/production/src/dispatch/TargetHandlerResolver.cjs +16 -0
- package/dist/production/src/dispatch/TargetHandlerResolver.cjs.map +1 -0
- package/dist/production/src/dispatch/TargetHandlerResolver.js +16 -0
- package/dist/production/src/dispatch/TargetHandlerResolver.js.map +1 -0
- package/dist/production/src/dispatch/WebhookFetcher.cjs +16 -0
- package/dist/production/src/dispatch/WebhookFetcher.cjs.map +1 -0
- package/dist/production/src/dispatch/WebhookFetcher.js +16 -0
- package/dist/production/src/dispatch/WebhookFetcher.js.map +1 -0
- package/dist/production/src/dispatch/WebhookTargetHandler.cjs +198 -0
- package/dist/production/src/dispatch/WebhookTargetHandler.cjs.map +1 -0
- package/dist/production/src/dispatch/WebhookTargetHandler.js +181 -0
- package/dist/production/src/dispatch/WebhookTargetHandler.js.map +1 -0
- package/dist/production/src/graphql/http/ActionsApiMiddlewareFactory.cjs +39 -0
- package/dist/production/src/graphql/http/ActionsApiMiddlewareFactory.cjs.map +1 -0
- package/dist/production/src/graphql/http/ActionsApiMiddlewareFactory.js +39 -0
- package/dist/production/src/graphql/http/ActionsApiMiddlewareFactory.js.map +1 -0
- package/dist/production/src/graphql/http/ActionsContextResolver.cjs +36 -0
- package/dist/production/src/graphql/http/ActionsContextResolver.cjs.map +1 -0
- package/dist/production/src/graphql/http/ActionsContextResolver.js +36 -0
- package/dist/production/src/graphql/http/ActionsContextResolver.js.map +1 -0
- package/dist/production/src/graphql/http/ActionsGraphQLHandlerFactory.cjs +20 -0
- package/dist/production/src/graphql/http/ActionsGraphQLHandlerFactory.cjs.map +1 -0
- package/dist/production/src/graphql/http/ActionsGraphQLHandlerFactory.js +20 -0
- package/dist/production/src/graphql/http/ActionsGraphQLHandlerFactory.js.map +1 -0
- package/dist/production/src/graphql/http/ActionsWebsocketControllerFactory.cjs +152 -0
- package/dist/production/src/graphql/http/ActionsWebsocketControllerFactory.cjs.map +1 -0
- package/dist/production/src/graphql/http/ActionsWebsocketControllerFactory.js +135 -0
- package/dist/production/src/graphql/http/ActionsWebsocketControllerFactory.js.map +1 -0
- package/dist/production/src/graphql/resolvers/ResolversFactory.cjs +36 -0
- package/dist/production/src/graphql/resolvers/ResolversFactory.cjs.map +1 -0
- package/dist/production/src/graphql/resolvers/ResolversFactory.js +36 -0
- package/dist/production/src/graphql/resolvers/ResolversFactory.js.map +1 -0
- package/dist/production/src/graphql/resolvers/mutation/ProcessBatchMutationResolver.cjs +19 -0
- package/dist/production/src/graphql/resolvers/mutation/ProcessBatchMutationResolver.cjs.map +1 -0
- package/dist/production/src/graphql/resolvers/mutation/ProcessBatchMutationResolver.js +19 -0
- package/dist/production/src/graphql/resolvers/mutation/ProcessBatchMutationResolver.js.map +1 -0
- package/dist/production/src/graphql/resolvers/mutation/RetryEventMutationResolver.cjs +21 -0
- package/dist/production/src/graphql/resolvers/mutation/RetryEventMutationResolver.cjs.map +1 -0
- package/dist/production/src/graphql/resolvers/mutation/RetryEventMutationResolver.js +21 -0
- package/dist/production/src/graphql/resolvers/mutation/RetryEventMutationResolver.js.map +1 -0
- package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs +19 -0
- package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs.map +1 -0
- package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js +19 -0
- package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js.map +1 -0
- package/dist/production/src/graphql/resolvers/mutation/StopEventMutationResolver.cjs +19 -0
- package/dist/production/src/graphql/resolvers/mutation/StopEventMutationResolver.cjs.map +1 -0
- package/dist/production/src/graphql/resolvers/mutation/StopEventMutationResolver.js +19 -0
- package/dist/production/src/graphql/resolvers/mutation/StopEventMutationResolver.js.map +1 -0
- package/dist/production/src/graphql/resolvers/query/EventsQueryResolver.cjs +61 -0
- package/dist/production/src/graphql/resolvers/query/EventsQueryResolver.cjs.map +1 -0
- package/dist/production/src/graphql/resolvers/query/EventsQueryResolver.js +61 -0
- package/dist/production/src/graphql/resolvers/query/EventsQueryResolver.js.map +1 -0
- package/dist/production/src/graphql/resolvers/query/VariablesQueryResolver.cjs +19 -0
- package/dist/production/src/graphql/resolvers/query/VariablesQueryResolver.cjs.map +1 -0
- package/dist/production/src/graphql/resolvers/query/VariablesQueryResolver.js +19 -0
- package/dist/production/src/graphql/resolvers/query/VariablesQueryResolver.js.map +1 -0
- package/dist/production/src/graphql/schema/actions.graphql.cjs +107 -0
- package/dist/production/src/graphql/schema/actions.graphql.cjs.map +1 -0
- package/dist/production/src/graphql/schema/actions.graphql.js +107 -0
- package/dist/production/src/graphql/schema/actions.graphql.js.map +1 -0
- package/dist/production/src/migrations/2023-03-10-145000-actions-variables.cjs +16 -0
- package/dist/production/src/migrations/2023-03-10-145000-actions-variables.cjs.map +1 -0
- package/dist/production/src/migrations/2023-03-10-145000-actions-variables.js +17 -0
- package/dist/production/src/migrations/2023-03-10-145000-actions-variables.js.map +1 -0
- package/dist/production/src/migrations/2025-05-28-160000-action-event-user.cjs +16 -0
- package/dist/production/src/migrations/2025-05-28-160000-action-event-user.cjs.map +1 -0
- package/dist/production/src/migrations/2025-05-28-160000-action-event-user.js +17 -0
- package/dist/production/src/migrations/2025-05-28-160000-action-event-user.js.map +1 -0
- package/dist/production/src/migrations/index.cjs +12 -0
- package/dist/production/src/migrations/index.cjs.map +1 -0
- package/dist/production/src/migrations/index.js +12 -0
- package/dist/production/src/migrations/index.js.map +1 -0
- package/dist/production/src/migrations/snapshot.cjs +51 -0
- package/dist/production/src/migrations/snapshot.cjs.map +1 -0
- package/dist/production/src/migrations/snapshot.js +52 -0
- package/dist/production/src/migrations/snapshot.js.map +1 -0
- package/dist/production/src/model/EventByIdQuery.cjs +17 -0
- package/dist/production/src/model/EventByIdQuery.cjs.map +1 -0
- package/dist/production/src/model/EventByIdQuery.js +17 -0
- package/dist/production/src/model/EventByIdQuery.js.map +1 -0
- package/dist/production/src/model/EventsInProcessingQuery.cjs +14 -0
- package/dist/production/src/model/EventsInProcessingQuery.cjs.map +1 -0
- package/dist/production/src/model/EventsInProcessingQuery.js +14 -0
- package/dist/production/src/model/EventsInProcessingQuery.js.map +1 -0
- package/dist/production/src/model/EventsToProcessQuery.cjs +15 -0
- package/dist/production/src/model/EventsToProcessQuery.cjs.map +1 -0
- package/dist/production/src/model/EventsToProcessQuery.js +15 -0
- package/dist/production/src/model/EventsToProcessQuery.js.map +1 -0
- package/dist/production/src/model/EventsToProcessSpecification.cjs +8 -0
- package/dist/production/src/model/EventsToProcessSpecification.cjs.map +1 -0
- package/dist/production/src/model/EventsToProcessSpecification.js +8 -0
- package/dist/production/src/model/EventsToProcessSpecification.js.map +1 -0
- package/dist/production/src/model/FailedEventsQuery.cjs +14 -0
- package/dist/production/src/model/FailedEventsQuery.cjs.map +1 -0
- package/dist/production/src/model/FailedEventsQuery.js +14 -0
- package/dist/production/src/model/FailedEventsQuery.js.map +1 -0
- package/dist/production/src/model/SetVariableCommand.cjs +21 -0
- package/dist/production/src/model/SetVariableCommand.cjs.map +1 -0
- package/dist/production/src/model/SetVariableCommand.js +21 -0
- package/dist/production/src/model/SetVariableCommand.js.map +1 -0
- package/dist/production/src/model/VariablesManager.cjs +41 -0
- package/dist/production/src/model/VariablesManager.cjs.map +1 -0
- package/dist/production/src/model/VariablesManager.js +41 -0
- package/dist/production/src/model/VariablesManager.js.map +1 -0
- package/dist/production/src/model/VariablesQuery.cjs +10 -0
- package/dist/production/src/model/VariablesQuery.cjs.map +1 -0
- package/dist/production/src/model/VariablesQuery.js +10 -0
- package/dist/production/src/model/VariablesQuery.js.map +1 -0
- package/dist/production/src/triggers/TriggerHandler.cjs +129 -0
- package/dist/production/src/triggers/TriggerHandler.cjs.map +1 -0
- package/dist/production/src/triggers/TriggerHandler.js +129 -0
- package/dist/production/src/triggers/TriggerHandler.js.map +1 -0
- package/dist/production/src/triggers/TriggerIndirectChangesFetcher.cjs +63 -0
- package/dist/production/src/triggers/TriggerIndirectChangesFetcher.cjs.map +1 -0
- package/dist/production/src/triggers/TriggerIndirectChangesFetcher.js +63 -0
- package/dist/production/src/triggers/TriggerIndirectChangesFetcher.js.map +1 -0
- package/dist/production/src/triggers/TriggerListenersBuilder.cjs +169 -0
- package/dist/production/src/triggers/TriggerListenersBuilder.cjs.map +1 -0
- package/dist/production/src/triggers/TriggerListenersBuilder.js +169 -0
- package/dist/production/src/triggers/TriggerListenersBuilder.js.map +1 -0
- package/dist/production/src/triggers/TriggerListenersFactory.cjs +17 -0
- package/dist/production/src/triggers/TriggerListenersFactory.cjs.map +1 -0
- package/dist/production/src/triggers/TriggerListenersFactory.js +17 -0
- package/dist/production/src/triggers/TriggerListenersFactory.js.map +1 -0
- package/dist/production/src/triggers/TriggerListenersStore.cjs +24 -0
- package/dist/production/src/triggers/TriggerListenersStore.cjs.map +1 -0
- package/dist/production/src/triggers/TriggerListenersStore.js +24 -0
- package/dist/production/src/triggers/TriggerListenersStore.js.map +1 -0
- package/dist/production/src/triggers/TriggerPayloadBuilder.cjs +163 -0
- package/dist/production/src/triggers/TriggerPayloadBuilder.cjs.map +1 -0
- package/dist/production/src/triggers/TriggerPayloadBuilder.js +163 -0
- package/dist/production/src/triggers/TriggerPayloadBuilder.js.map +1 -0
- package/dist/production/src/triggers/TriggerPayloadManager.cjs +27 -0
- package/dist/production/src/triggers/TriggerPayloadManager.cjs.map +1 -0
- package/dist/production/src/triggers/TriggerPayloadManager.js +27 -0
- package/dist/production/src/triggers/TriggerPayloadManager.js.map +1 -0
- package/dist/production/src/triggers/TriggerPayloadPersister.cjs +47 -0
- package/dist/production/src/triggers/TriggerPayloadPersister.cjs.map +1 -0
- package/dist/production/src/triggers/TriggerPayloadPersister.js +47 -0
- package/dist/production/src/triggers/TriggerPayloadPersister.js.map +1 -0
- package/dist/production/src/utils/assertNever.cjs +7 -0
- package/dist/production/src/utils/assertNever.cjs.map +1 -0
- package/dist/production/src/utils/assertNever.js +7 -0
- package/dist/production/src/utils/assertNever.js.map +1 -0
- package/dist/production/src/utils/map.cjs +13 -0
- package/dist/production/src/utils/map.cjs.map +1 -0
- package/dist/production/src/utils/map.js +13 -0
- package/dist/production/src/utils/map.js.map +1 -0
- package/dist/production/src/utils/notifyChannel.cjs +9 -0
- package/dist/production/src/utils/notifyChannel.cjs.map +1 -0
- package/dist/production/src/utils/notifyChannel.js +9 -0
- package/dist/production/src/utils/notifyChannel.js.map +1 -0
- package/dist/tests/cases/unit/generator.test.d.ts +2 -0
- package/dist/tests/cases/unit/generator.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/webhookHandler.test.d.ts +2 -0
- package/dist/tests/cases/unit/webhookHandler.test.d.ts.map +1 -0
- package/dist/tests/src/gql.d.ts +2 -0
- package/dist/tests/src/gql.d.ts.map +1 -0
- package/dist/tests/src/uuid.d.ts +3 -0
- package/dist/tests/src/uuid.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -0
- package/dist/types/ActionsExecutionContainerHookFactory.d.ts +8 -0
- package/dist/types/ActionsExecutionContainerHookFactory.d.ts.map +1 -0
- package/dist/types/ImplementationException.d.ts +3 -0
- package/dist/types/ImplementationException.d.ts.map +1 -0
- package/dist/types/ListenerStoreProvider.d.ts +7 -0
- package/dist/types/ListenerStoreProvider.d.ts.map +1 -0
- package/dist/types/authorization/ActionsAuthorizationActions.d.ts +38 -0
- package/dist/types/authorization/ActionsAuthorizationActions.d.ts.map +1 -0
- package/dist/types/authorization/ActionsPermissionsFactory.d.ts +5 -0
- package/dist/types/authorization/ActionsPermissionsFactory.d.ts.map +1 -0
- package/dist/types/authorization/Identity.d.ts +5 -0
- package/dist/types/authorization/Identity.d.ts.map +1 -0
- package/dist/types/authorization/index.d.ts +4 -0
- package/dist/types/authorization/index.d.ts.map +1 -0
- package/dist/types/dispatch/DispatchWorkerSupervisor.d.ts +17 -0
- package/dist/types/dispatch/DispatchWorkerSupervisor.d.ts.map +1 -0
- package/dist/types/dispatch/EventDispatcher.d.ts +25 -0
- package/dist/types/dispatch/EventDispatcher.d.ts.map +1 -0
- package/dist/types/dispatch/EventsRepository.d.ts +23 -0
- package/dist/types/dispatch/EventsRepository.d.ts.map +1 -0
- package/dist/types/dispatch/ProjectDispatcher.d.ts +22 -0
- package/dist/types/dispatch/ProjectDispatcher.d.ts.map +1 -0
- package/dist/types/dispatch/TargetHandlerResolver.d.ts +9 -0
- package/dist/types/dispatch/TargetHandlerResolver.d.ts.map +1 -0
- package/dist/types/dispatch/WebhookFetcher.d.ts +14 -0
- package/dist/types/dispatch/WebhookFetcher.d.ts.map +1 -0
- package/dist/types/dispatch/WebhookTargetHandler.d.ts +16 -0
- package/dist/types/dispatch/WebhookTargetHandler.d.ts.map +1 -0
- package/dist/types/dispatch/types.d.ts +27 -0
- package/dist/types/dispatch/types.d.ts.map +1 -0
- package/dist/types/graphql/http/ActionsApiMiddlewareFactory.d.ts +13 -0
- package/dist/types/graphql/http/ActionsApiMiddlewareFactory.d.ts.map +1 -0
- package/dist/types/graphql/http/ActionsContextResolver.d.ts +14 -0
- package/dist/types/graphql/http/ActionsContextResolver.d.ts.map +1 -0
- package/dist/types/graphql/http/ActionsGraphQLHandlerFactory.d.ts +8 -0
- package/dist/types/graphql/http/ActionsGraphQLHandlerFactory.d.ts.map +1 -0
- package/dist/types/graphql/http/ActionsWebsocketControllerFactory.d.ts +11 -0
- package/dist/types/graphql/http/ActionsWebsocketControllerFactory.d.ts.map +1 -0
- package/dist/types/graphql/resolvers/ActionsContext.d.ts +14 -0
- package/dist/types/graphql/resolvers/ActionsContext.d.ts.map +1 -0
- package/dist/types/graphql/resolvers/ResolversFactory.d.ts +15 -0
- package/dist/types/graphql/resolvers/ResolversFactory.d.ts.map +1 -0
- package/dist/types/graphql/resolvers/index.d.ts +3 -0
- package/dist/types/graphql/resolvers/index.d.ts.map +1 -0
- package/dist/types/graphql/resolvers/mutation/ProcessBatchMutationResolver.d.ts +11 -0
- package/dist/types/graphql/resolvers/mutation/ProcessBatchMutationResolver.d.ts.map +1 -0
- package/dist/types/graphql/resolvers/mutation/RetryEventMutationResolver.d.ts +11 -0
- package/dist/types/graphql/resolvers/mutation/RetryEventMutationResolver.d.ts.map +1 -0
- package/dist/types/graphql/resolvers/mutation/SetVariablesMutationResolver.d.ts +11 -0
- package/dist/types/graphql/resolvers/mutation/SetVariablesMutationResolver.d.ts.map +1 -0
- package/dist/types/graphql/resolvers/mutation/StopEventMutationResolver.d.ts +11 -0
- package/dist/types/graphql/resolvers/mutation/StopEventMutationResolver.d.ts.map +1 -0
- package/dist/types/graphql/resolvers/mutation/index.d.ts +5 -0
- package/dist/types/graphql/resolvers/mutation/index.d.ts.map +1 -0
- package/dist/types/graphql/resolvers/query/EventsQueryResolver.d.ts +14 -0
- package/dist/types/graphql/resolvers/query/EventsQueryResolver.d.ts.map +1 -0
- package/dist/types/graphql/resolvers/query/VariablesQueryResolver.d.ts +12 -0
- package/dist/types/graphql/resolvers/query/VariablesQueryResolver.d.ts.map +1 -0
- package/dist/types/graphql/resolvers/query/index.d.ts +2 -0
- package/dist/types/graphql/resolvers/query/index.d.ts.map +1 -0
- package/dist/types/graphql/schema/actions.graphql.d.ts +3 -0
- package/dist/types/graphql/schema/actions.graphql.d.ts.map +1 -0
- package/dist/types/graphql/schema/index.d.ts +299 -0
- package/dist/types/graphql/schema/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/migrations/2023-03-10-145000-actions-variables.d.ts +3 -0
- package/dist/types/migrations/2023-03-10-145000-actions-variables.d.ts.map +1 -0
- package/dist/types/migrations/2025-05-28-160000-action-event-user.d.ts +3 -0
- package/dist/types/migrations/2025-05-28-160000-action-event-user.d.ts.map +1 -0
- package/dist/types/migrations/index.d.ts +3 -0
- package/dist/types/migrations/index.d.ts.map +1 -0
- package/dist/types/migrations/snapshot.d.ts +3 -0
- package/dist/types/migrations/snapshot.d.ts.map +1 -0
- package/dist/types/model/EventByIdQuery.d.ts +8 -0
- package/dist/types/model/EventByIdQuery.d.ts.map +1 -0
- package/dist/types/model/EventsInProcessingQuery.d.ts +9 -0
- package/dist/types/model/EventsInProcessingQuery.d.ts.map +1 -0
- package/dist/types/model/EventsToProcessQuery.d.ts +9 -0
- package/dist/types/model/EventsToProcessQuery.d.ts.map +1 -0
- package/dist/types/model/EventsToProcessSpecification.d.ts +4 -0
- package/dist/types/model/EventsToProcessSpecification.d.ts.map +1 -0
- package/dist/types/model/FailedEventsQuery.d.ts +9 -0
- package/dist/types/model/FailedEventsQuery.d.ts.map +1 -0
- package/dist/types/model/SetVariableCommand.d.ts +8 -0
- package/dist/types/model/SetVariableCommand.d.ts.map +1 -0
- package/dist/types/model/VariablesManager.d.ts +8 -0
- package/dist/types/model/VariablesManager.d.ts.map +1 -0
- package/dist/types/model/VariablesQuery.d.ts +12 -0
- package/dist/types/model/VariablesQuery.d.ts.map +1 -0
- package/dist/types/model/types.d.ts +22 -0
- package/dist/types/model/types.d.ts.map +1 -0
- package/dist/types/triggers/TriggerHandler.d.ts +26 -0
- package/dist/types/triggers/TriggerHandler.d.ts.map +1 -0
- package/dist/types/triggers/TriggerIndirectChangesFetcher.d.ts +19 -0
- package/dist/types/triggers/TriggerIndirectChangesFetcher.d.ts.map +1 -0
- package/dist/types/triggers/TriggerListeners.d.ts +9 -0
- package/dist/types/triggers/TriggerListeners.d.ts.map +1 -0
- package/dist/types/triggers/TriggerListenersBuilder.d.ts +15 -0
- package/dist/types/triggers/TriggerListenersBuilder.d.ts.map +1 -0
- package/dist/types/triggers/TriggerListenersFactory.d.ts +8 -0
- package/dist/types/triggers/TriggerListenersFactory.d.ts.map +1 -0
- package/dist/types/triggers/TriggerListenersStore.d.ts +48 -0
- package/dist/types/triggers/TriggerListenersStore.d.ts.map +1 -0
- package/dist/types/triggers/TriggerPayloadBuilder.d.ts +14 -0
- package/dist/types/triggers/TriggerPayloadBuilder.d.ts.map +1 -0
- package/dist/types/triggers/TriggerPayloadManager.d.ts +22 -0
- package/dist/types/triggers/TriggerPayloadManager.d.ts.map +1 -0
- package/dist/types/triggers/TriggerPayloadPersister.d.ts +21 -0
- package/dist/types/triggers/TriggerPayloadPersister.d.ts.map +1 -0
- package/dist/types/triggers/index.d.ts +8 -0
- package/dist/types/triggers/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/dist/types/utils/assertNever.d.ts +2 -0
- package/dist/types/utils/assertNever.d.ts.map +1 -0
- package/dist/types/utils/map.d.ts +2 -0
- package/dist/types/utils/map.d.ts.map +1 -0
- package/dist/types/utils/notifyChannel.d.ts +4 -0
- package/dist/types/utils/notifyChannel.d.ts.map +1 -0
- package/package.json +22 -22
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { SelectBuilder, UpdateBuilder as UpdateBuilder$1, LockType, LockModifier, Literal, Connection, Operator } from "@contember/database";
|
|
2
|
+
import { eventsToProcessStateSpecification, eventsToProcessSpecification } from "../model/EventsToProcessSpecification.js";
|
|
3
|
+
const ACK_TIMEOUT_MS = 1e3 * 60 * 10;
|
|
4
|
+
const DEFAULT_REPEAT_INTERVAL_MS = 5e3;
|
|
5
|
+
const DEFAULT_MAX_ATTEMPTS = 10;
|
|
6
|
+
const DEFAULT_BATCH_SIZE = 1;
|
|
7
|
+
class EventsRepository {
|
|
8
|
+
async fetchBatch(actions, db) {
|
|
9
|
+
const primaryEvent = (await this.fetchInternal(db, 1))[0];
|
|
10
|
+
if (!primaryEvent) {
|
|
11
|
+
return { ok: false, backoffMs: await this.fetchBackOff(db) };
|
|
12
|
+
}
|
|
13
|
+
const target = actions.targets[primaryEvent.target];
|
|
14
|
+
if (!target) {
|
|
15
|
+
await this.markFailedOnUnknownTarget(db, primaryEvent.target, primaryEvent.id);
|
|
16
|
+
return await this.fetchBatch(actions, db);
|
|
17
|
+
}
|
|
18
|
+
const batchSize = (target.batchSize ?? DEFAULT_BATCH_SIZE) - 1;
|
|
19
|
+
const batch = batchSize > 0 ? await this.fetchInternal(db, batchSize) : [];
|
|
20
|
+
return { ok: true, events: [primaryEvent, ...batch], target };
|
|
21
|
+
}
|
|
22
|
+
async fetchBackOff(db) {
|
|
23
|
+
const result = await SelectBuilder.create().from("actions_event").match(eventsToProcessStateSpecification).select((it) => it.raw("ceil(extract(epoch from visible_at - now()) * 1000)"), "ms").orderBy("visible_at", "asc").limit(1).getResult(db);
|
|
24
|
+
return result.length ? Math.max(0, result[0].ms) : void 0;
|
|
25
|
+
}
|
|
26
|
+
async fetchInternal(db, limit, targetName) {
|
|
27
|
+
const visibleAt = /* @__PURE__ */ new Date();
|
|
28
|
+
visibleAt.setTime(visibleAt.getTime() + ACK_TIMEOUT_MS);
|
|
29
|
+
return await UpdateBuilder$1.create().table("actions_event").with("events", (qb) => qb.select((it) => it.raw("*")).from("actions_event").match(eventsToProcessSpecification).where(targetName ? { target: targetName } : {}).limit(limit).lock(LockType.forNoKeyUpdate, LockModifier.skipLocked)).values({
|
|
30
|
+
state: "processing",
|
|
31
|
+
last_state_change: /* @__PURE__ */ new Date(),
|
|
32
|
+
visible_at: visibleAt
|
|
33
|
+
}).from((it) => it.from("events").where((it2) => it2.columnsEq(["events", "id"], ["actions_event", "id"]))).returning(new Literal("*")).execute(db);
|
|
34
|
+
}
|
|
35
|
+
async persistProcessed(db, events) {
|
|
36
|
+
return await db.transaction(async (trx) => {
|
|
37
|
+
await trx.query(Connection.REPEATABLE_READ);
|
|
38
|
+
const succeed = events.filter((it) => it.result.ok);
|
|
39
|
+
await this.markSucceed(trx, succeed.map((it) => it.row));
|
|
40
|
+
for (const event of events) {
|
|
41
|
+
if (!event.result.ok) {
|
|
42
|
+
await this.markFailed(trx, event);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return [succeed.length, events.length - succeed.length];
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async requeue(db, events) {
|
|
49
|
+
await UpdateBuilder$1.create().table("actions_event").values({
|
|
50
|
+
state: (it) => it.raw(
|
|
51
|
+
`
|
|
52
|
+
CASE
|
|
53
|
+
WHEN num_retries = 0 THEN
|
|
54
|
+
?::__SCHEMA__.actions_trigger_state
|
|
55
|
+
ELSE
|
|
56
|
+
?::__SCHEMA__.actions_trigger_state END
|
|
57
|
+
`,
|
|
58
|
+
"created",
|
|
59
|
+
"retrying"
|
|
60
|
+
),
|
|
61
|
+
last_state_change: /* @__PURE__ */ new Date(),
|
|
62
|
+
visible_at: /* @__PURE__ */ new Date()
|
|
63
|
+
}).where((it) => it.in("id", events)).execute(db);
|
|
64
|
+
}
|
|
65
|
+
async markStopped(db, events) {
|
|
66
|
+
await UpdateBuilder$1.create().table("actions_event").values({
|
|
67
|
+
state: "stopped",
|
|
68
|
+
last_state_change: /* @__PURE__ */ new Date(),
|
|
69
|
+
resolved_at: /* @__PURE__ */ new Date()
|
|
70
|
+
}).where((it) => it.in("id", events)).execute(db);
|
|
71
|
+
}
|
|
72
|
+
async markSucceed(db, rows) {
|
|
73
|
+
const now = /* @__PURE__ */ new Date();
|
|
74
|
+
await UpdateBuilder$1.create().table("actions_event").values({
|
|
75
|
+
state: "succeed",
|
|
76
|
+
num_retries: (it) => it.raw("num_retries + 1"),
|
|
77
|
+
resolved_at: now,
|
|
78
|
+
last_state_change: now
|
|
79
|
+
}).where((it) => it.in("id", rows.map((it2) => it2.id))).execute(db);
|
|
80
|
+
}
|
|
81
|
+
async markFailed(db, event) {
|
|
82
|
+
const numRetries = event.row.num_retries + 1;
|
|
83
|
+
const now = /* @__PURE__ */ new Date();
|
|
84
|
+
const nextAttempt = /* @__PURE__ */ new Date();
|
|
85
|
+
nextAttempt.setTime(
|
|
86
|
+
nextAttempt.getTime() + (event.target?.initialRepeatIntervalMs ?? DEFAULT_REPEAT_INTERVAL_MS) * Math.pow(2, event.row.num_retries)
|
|
87
|
+
);
|
|
88
|
+
await UpdateBuilder$1.create().table("actions_event").values({
|
|
89
|
+
last_state_change: now,
|
|
90
|
+
num_retries: numRetries,
|
|
91
|
+
log: JSON.stringify([...event.row.log, event.result]),
|
|
92
|
+
...numRetries < (event.target?.maxAttempts ?? DEFAULT_MAX_ATTEMPTS) ? {
|
|
93
|
+
state: "retrying",
|
|
94
|
+
visible_at: nextAttempt
|
|
95
|
+
} : {
|
|
96
|
+
state: "failed"
|
|
97
|
+
}
|
|
98
|
+
}).where({ id: event.row.id }).execute(db);
|
|
99
|
+
}
|
|
100
|
+
async markFailedOnUnknownTarget(db, targetName, primaryEventId) {
|
|
101
|
+
await UpdateBuilder$1.create().table("actions_event").where(
|
|
102
|
+
(it) => it.or(
|
|
103
|
+
(it2) => it2.and(
|
|
104
|
+
(it3) => it3.in("state", ["retrying", "created", "processing"]).compare("visible_at", Operator.lte, "now").compare("target", Operator.eq, targetName)
|
|
105
|
+
).and(
|
|
106
|
+
(it3) => it3.compare("id", Operator.eq, primaryEventId)
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
).values({
|
|
110
|
+
// intentionally not retrying
|
|
111
|
+
last_state_change: /* @__PURE__ */ new Date(),
|
|
112
|
+
num_retries: (it) => it.raw("num_retries + 1"),
|
|
113
|
+
log: (it) => it.raw("log || ?::jsonb", { ok: false, errorMessage: `Event target ${targetName} not found, stopping.` }),
|
|
114
|
+
state: "failed",
|
|
115
|
+
resolved_at: /* @__PURE__ */ new Date()
|
|
116
|
+
}).execute(db);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export {
|
|
120
|
+
EventsRepository
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=EventsRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventsRepository.js","sources":["../../../../../packages/engine-actions/src/dispatch/EventsRepository.ts"],"sourcesContent":["import { Client, Connection, Literal, LockModifier, LockType, Operator, SelectBuilder, UpdateBuilder } from '@contember/database'\nimport { EventRow, HandledEvent } from './types'\nimport { Actions } from '@contember/schema'\nimport { eventsToProcessSpecification, eventsToProcessStateSpecification } from '../model/EventsToProcessSpecification'\nimport { notify } from '../utils/notifyChannel'\n\nconst ACK_TIMEOUT_MS = 1_000 * 60 * 10 // 10 minutes\nconst DEFAULT_REPEAT_INTERVAL_MS = 5_000 // 5 seconds\nconst DEFAULT_MAX_ATTEMPTS = 10\nconst DEFAULT_BATCH_SIZE = 1\n\nexport class EventsRepository {\n\tpublic async fetchBatch(actions: Actions.Schema, db: Client): Promise<FetchBatchResult> {\n\t\tconst primaryEvent = (await this.fetchInternal(db, 1))[0]\n\t\tif (!primaryEvent) {\n\t\t\treturn { ok: false, backoffMs: await this.fetchBackOff(db) }\n\t\t}\n\t\tconst target = actions.targets[primaryEvent.target]\n\t\tif (!target) {\n\t\t\tawait this.markFailedOnUnknownTarget(db, primaryEvent.target, primaryEvent.id)\n\t\t\treturn await this.fetchBatch(actions, db)\n\t\t}\n\t\tconst batchSize = (target.batchSize ?? DEFAULT_BATCH_SIZE) - 1\n\t\tconst batch = batchSize > 0 ? await this.fetchInternal(db, batchSize) : []\n\t\treturn { ok: true, events: [primaryEvent, ...batch], target }\n\t}\n\n\tprivate async fetchBackOff(db: Client): Promise<number | undefined> {\n\t\tconst result = await SelectBuilder.create<{ ms: number }>()\n\t\t\t.from('actions_event')\n\t\t\t.match(eventsToProcessStateSpecification)\n\t\t\t.select(it => it.raw('ceil(extract(epoch from visible_at - now()) * 1000)'), 'ms')\n\t\t\t.orderBy('visible_at', 'asc')\n\t\t\t.limit(1)\n\t\t\t.getResult(db)\n\n\t\treturn result.length ? Math.max(0, result[0].ms) : undefined\n\t}\n\n\tprivate async fetchInternal(db: Client, limit: number, targetName?: string): Promise<EventRow[]> {\n\t\tconst visibleAt = new Date()\n\t\tvisibleAt.setTime(visibleAt.getTime() + ACK_TIMEOUT_MS)\n\t\treturn await UpdateBuilder.create()\n\t\t\t.table('actions_event')\n\t\t\t.with('events', qb =>\n\t\t\t\tqb\n\t\t\t\t\t.select(it => it.raw('*'))\n\t\t\t\t\t.from('actions_event')\n\t\t\t\t\t.match(eventsToProcessSpecification)\n\t\t\t\t\t.where(targetName ? { target: targetName } : {})\n\t\t\t\t\t.limit(limit)\n\t\t\t\t\t.lock(LockType.forNoKeyUpdate, LockModifier.skipLocked))\n\t\t\t.values<EventRow>({\n\t\t\t\tstate: 'processing',\n\t\t\t\tlast_state_change: new Date(),\n\t\t\t\tvisible_at: visibleAt,\n\t\t\t})\n\t\t\t.from(it => it.from('events').where(it => it.columnsEq(['events', 'id'], ['actions_event', 'id'])))\n\t\t\t.returning<EventRow>(new Literal('*'))\n\t\t\t.execute(db)\n\t}\n\n\tpublic async persistProcessed(db: Client, events: HandledEvent[]): Promise<[number, number]> {\n\t\treturn await db.transaction(async trx => {\n\t\t\tawait trx.query(Connection.REPEATABLE_READ)\n\t\t\tconst succeed = events.filter(it => it.result.ok)\n\t\t\tawait this.markSucceed(trx, succeed.map(it => it.row))\n\n\t\t\tfor (const event of events) {\n\t\t\t\tif (!event.result.ok) {\n\t\t\t\t\tawait this.markFailed(trx, event)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn [succeed.length, events.length - succeed.length]\n\t\t})\n\t}\n\n\tpublic async requeue(db: Client, events: string[]): Promise<void> {\n\t\tawait UpdateBuilder.create()\n\t\t\t.table('actions_event')\n\t\t\t.values<EventRow>({\n\t\t\t\tstate: it =>\n\t\t\t\t\tit.raw(\n\t\t\t\t\t\t`\n\t\t\t\t\tCASE \n\t\t\t\t\tWHEN num_retries = 0 THEN \n\t\t\t\t\t\t?::__SCHEMA__.actions_trigger_state \n\t\t\t\t\tELSE \n\t\t\t\t\t?::__SCHEMA__.actions_trigger_state END\n\t\t\t\t`,\n\t\t\t\t\t\t'created',\n\t\t\t\t\t\t'retrying',\n\t\t\t\t\t),\n\t\t\t\tlast_state_change: new Date(),\n\t\t\t\tvisible_at: new Date(),\n\t\t\t})\n\t\t\t.where(it => it.in('id', events))\n\t\t\t.execute(db)\n\t}\n\n\tpublic async markStopped(db: Client, events: string[]): Promise<void> {\n\t\tawait UpdateBuilder.create()\n\t\t\t.table('actions_event')\n\t\t\t.values<EventRow>({\n\t\t\t\tstate: 'stopped',\n\t\t\t\tlast_state_change: new Date(),\n\t\t\t\tresolved_at: new Date(),\n\t\t\t})\n\t\t\t.where(it => it.in('id', events))\n\t\t\t.execute(db)\n\t}\n\n\tprivate async markSucceed(db: Client, rows: EventRow[]): Promise<void> {\n\t\tconst now = new Date()\n\t\tawait UpdateBuilder.create()\n\t\t\t.table('actions_event')\n\t\t\t.values<EventRow>({\n\t\t\t\tstate: 'succeed',\n\t\t\t\tnum_retries: it => it.raw('num_retries + 1'),\n\t\t\t\tresolved_at: now,\n\t\t\t\tlast_state_change: now,\n\t\t\t})\n\t\t\t.where(it => it.in('id', rows.map(it => it.id)))\n\t\t\t.execute(db)\n\t}\n\n\tprivate async markFailed(db: Client, event: HandledEvent): Promise<void> {\n\t\tconst numRetries = event.row.num_retries + 1\n\t\tconst now = new Date()\n\t\tconst nextAttempt = new Date()\n\t\tnextAttempt.setTime(\n\t\t\tnextAttempt.getTime() + (event.target?.initialRepeatIntervalMs ?? DEFAULT_REPEAT_INTERVAL_MS) * Math.pow(2, event.row.num_retries),\n\t\t)\n\t\tawait UpdateBuilder.create()\n\t\t\t.table('actions_event')\n\t\t\t.values<EventRow>({\n\t\t\t\tlast_state_change: now,\n\t\t\t\tnum_retries: numRetries,\n\t\t\t\tlog: JSON.stringify([...event.row.log, event.result]) as any,\n\t\t\t\t...(numRetries < (event.target?.maxAttempts ?? DEFAULT_MAX_ATTEMPTS)\n\t\t\t\t\t? {\n\t\t\t\t\t\tstate: 'retrying',\n\t\t\t\t\t\tvisible_at: nextAttempt,\n\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\tstate: 'failed',\n\t\t\t\t\t}),\n\t\t\t})\n\t\t\t.where({ id: event.row.id })\n\t\t\t.execute(db)\n\t}\n\n\tprivate async markFailedOnUnknownTarget(db: Client, targetName: string, primaryEventId: string) {\n\t\tawait UpdateBuilder.create()\n\t\t\t.table('actions_event')\n\t\t\t.where(it =>\n\t\t\t\tit.or(it =>\n\t\t\t\t\tit\n\t\t\t\t\t\t.and(it =>\n\t\t\t\t\t\t\tit\n\t\t\t\t\t\t\t\t.in('state', ['retrying', 'created', 'processing'])\n\t\t\t\t\t\t\t\t.compare('visible_at', Operator.lte, 'now')\n\t\t\t\t\t\t\t\t.compare('target', Operator.eq, targetName)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.and(it =>\n\t\t\t\t\t\t\tit\n\t\t\t\t\t\t\t\t.compare('id', Operator.eq, primaryEventId)\n\t\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t)\n\t\t\t.values<EventRow>({\n\t\t\t\t// intentionally not retrying\n\t\t\t\tlast_state_change: new Date(),\n\t\t\t\tnum_retries: it => it.raw('num_retries + 1'),\n\t\t\t\tlog: it => it.raw('log || ?::jsonb', { ok: false, errorMessage: `Event target ${targetName} not found, stopping.` }),\n\t\t\t\tstate: 'failed',\n\t\t\t\tresolved_at: new Date(),\n\t\t\t})\n\t\t\t.execute(db)\n\t}\n}\n\nexport type FetchBatchResult =\n\t| { ok: true; events: EventRow[]; target: Actions.AnyTarget }\n\t| { ok: false; backoffMs?: number }\n"],"names":["UpdateBuilder","it"],"mappings":"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"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const Database = require("@contember/database");
|
|
4
|
+
const notifyChannel = require("../utils/notifyChannel.cjs");
|
|
5
|
+
class ProjectDispatcherFactory {
|
|
6
|
+
constructor(dispatcher) {
|
|
7
|
+
this.dispatcher = dispatcher;
|
|
8
|
+
}
|
|
9
|
+
create({ db, contentSchemaResolver, projectSlug }) {
|
|
10
|
+
return new ProjectDispatcher(this.dispatcher, db, contentSchemaResolver, projectSlug);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
class ProjectDispatcher {
|
|
14
|
+
constructor(dispatcher, db, contentSchemaResolver, projectSlug) {
|
|
15
|
+
this.dispatcher = dispatcher;
|
|
16
|
+
this.db = db;
|
|
17
|
+
this.contentSchemaResolver = contentSchemaResolver;
|
|
18
|
+
this.projectSlug = projectSlug;
|
|
19
|
+
}
|
|
20
|
+
async run({ logger, onError, onClose }) {
|
|
21
|
+
return await new Promise(async (resolve, reject) => {
|
|
22
|
+
let resolvePending = () => {
|
|
23
|
+
};
|
|
24
|
+
let rejectPending = (e) => {
|
|
25
|
+
};
|
|
26
|
+
const resolvePendingRef = () => {
|
|
27
|
+
resolvePending();
|
|
28
|
+
};
|
|
29
|
+
let pendingError;
|
|
30
|
+
const rejectPendingRef = (e) => {
|
|
31
|
+
pendingError = e;
|
|
32
|
+
rejectPending(e);
|
|
33
|
+
};
|
|
34
|
+
let succeedTotal = 0;
|
|
35
|
+
let failedTotal = 0;
|
|
36
|
+
let aborted = false;
|
|
37
|
+
try {
|
|
38
|
+
await this.db.scope(async (db) => {
|
|
39
|
+
const listener = await new Database.Listener(db.client, notifyChannel.NOTIFY_CHANNEL_NAME, (project) => {
|
|
40
|
+
if (project === this.projectSlug) {
|
|
41
|
+
resolvePendingRef();
|
|
42
|
+
}
|
|
43
|
+
}).run({ onError: rejectPendingRef, onClose: resolvePendingRef });
|
|
44
|
+
resolve({
|
|
45
|
+
end: async () => {
|
|
46
|
+
aborted = true;
|
|
47
|
+
await listener.end();
|
|
48
|
+
logger.info("Worker terminated", {
|
|
49
|
+
succeed: succeedTotal,
|
|
50
|
+
failed: failedTotal
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
while (!aborted) {
|
|
56
|
+
const { succeed, failed, backoffMs } = await this.dispatcher.processBatch({
|
|
57
|
+
db,
|
|
58
|
+
contentSchemaResolver: this.contentSchemaResolver,
|
|
59
|
+
logger
|
|
60
|
+
});
|
|
61
|
+
succeedTotal += succeed;
|
|
62
|
+
failedTotal += failed;
|
|
63
|
+
if (pendingError) {
|
|
64
|
+
throw pendingError;
|
|
65
|
+
}
|
|
66
|
+
if (backoffMs !== 0) {
|
|
67
|
+
await new Promise((resolve2, reject2) => {
|
|
68
|
+
let cleanup = () => {
|
|
69
|
+
};
|
|
70
|
+
if (backoffMs !== void 0) {
|
|
71
|
+
const timeoutHandle = setTimeout(resolve2, backoffMs);
|
|
72
|
+
cleanup = () => clearTimeout(timeoutHandle);
|
|
73
|
+
}
|
|
74
|
+
resolvePending = () => {
|
|
75
|
+
resolve2();
|
|
76
|
+
cleanup();
|
|
77
|
+
};
|
|
78
|
+
rejectPending = (e) => {
|
|
79
|
+
reject2(e);
|
|
80
|
+
cleanup();
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
onClose?.();
|
|
86
|
+
} catch (e) {
|
|
87
|
+
await listener.end();
|
|
88
|
+
onError(e);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
} catch (e) {
|
|
92
|
+
reject(e);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.ProjectDispatcher = ProjectDispatcher;
|
|
98
|
+
exports.ProjectDispatcherFactory = ProjectDispatcherFactory;
|
|
99
|
+
//# sourceMappingURL=ProjectDispatcher.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProjectDispatcher.cjs","sources":["../../../../../packages/engine-actions/src/dispatch/ProjectDispatcher.ts"],"sourcesContent":["import { DatabaseContext } from '@contember/engine-system-api'\nimport { EventDispatcher } from './EventDispatcher'\nimport { ContentSchemaResolver } from '@contember/engine-http'\nimport { Runnable, RunnableArgs, Running } from '@contember/engine-common'\nimport { Listener } from '@contember/database'\nimport { NOTIFY_CHANNEL_NAME } from '../utils/notifyChannel'\n\nexport class ProjectDispatcherFactory {\n\tconstructor(\n\t\tprivate readonly dispatcher: EventDispatcher,\n\t) {\n\t}\n\n\tpublic create(\n\t\t{ db, contentSchemaResolver, projectSlug }: { db: DatabaseContext; contentSchemaResolver: ContentSchemaResolver; projectSlug: string },\n\t): ProjectDispatcher {\n\t\treturn new ProjectDispatcher(this.dispatcher, db, contentSchemaResolver, projectSlug)\n\t}\n}\n\nexport class ProjectDispatcher implements Runnable {\n\tconstructor(\n\t\tprivate readonly dispatcher: EventDispatcher,\n\t\tprivate readonly db: DatabaseContext,\n\t\tprivate readonly contentSchemaResolver: ContentSchemaResolver,\n\t\tprivate readonly projectSlug: string,\n\t) {\n\t}\n\n\tpublic async run({ logger, onError, onClose }: RunnableArgs): Promise<Running> {\n\t\treturn await new Promise<Running>(async (resolve, reject) => {\n\t\t\tlet resolvePending = () => {}\n\t\t\tlet rejectPending = (e: any) => {}\n\n\t\t\tconst resolvePendingRef = () => {\n\t\t\t\tresolvePending()\n\t\t\t}\n\t\t\tlet pendingError: any\n\t\t\tconst rejectPendingRef = (e: any) => {\n\t\t\t\tpendingError = e\n\t\t\t\trejectPending(e)\n\t\t\t}\n\n\t\t\tlet succeedTotal = 0\n\t\t\tlet failedTotal = 0\n\t\t\tlet aborted = false\n\n\t\t\ttry {\n\t\t\t\tawait this.db.scope(async db => {\n\t\t\t\t\tconst listener = await new Listener<string>(db.client, NOTIFY_CHANNEL_NAME, project => {\n\t\t\t\t\t\tif (project === this.projectSlug) {\n\t\t\t\t\t\t\tresolvePendingRef()\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t\t\t.run({ onError: rejectPendingRef, onClose: resolvePendingRef })\n\n\t\t\t\t\tresolve({\n\t\t\t\t\t\tend: async () => {\n\t\t\t\t\t\t\taborted = true\n\t\t\t\t\t\t\tawait listener.end()\n\t\t\t\t\t\t\tlogger.info('Worker terminated', {\n\t\t\t\t\t\t\t\tsucceed: succeedTotal,\n\t\t\t\t\t\t\t\tfailed: failedTotal,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\twhile (!aborted) {\n\t\t\t\t\t\t\tconst { succeed, failed, backoffMs } = await this.dispatcher.processBatch({\n\t\t\t\t\t\t\t\tdb,\n\t\t\t\t\t\t\t\tcontentSchemaResolver: this.contentSchemaResolver,\n\t\t\t\t\t\t\t\tlogger,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tsucceedTotal += succeed\n\t\t\t\t\t\t\tfailedTotal += failed\n\n\t\t\t\t\t\t\t// listener error occurred during batch processing, rethrow\n\t\t\t\t\t\t\tif (pendingError) {\n\t\t\t\t\t\t\t\tthrow pendingError\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// queue is empty, wait\n\t\t\t\t\t\t\tif (backoffMs !== 0) {\n\t\t\t\t\t\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\t\t\t\t\t\tlet cleanup = () => {\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (backoffMs !== undefined) {\n\t\t\t\t\t\t\t\t\t\tconst timeoutHandle = setTimeout(resolve, backoffMs)\n\t\t\t\t\t\t\t\t\t\tcleanup = () => clearTimeout(timeoutHandle)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tresolvePending = () => {\n\t\t\t\t\t\t\t\t\t\tresolve()\n\t\t\t\t\t\t\t\t\t\tcleanup()\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\trejectPending = e => {\n\t\t\t\t\t\t\t\t\t\treject(e)\n\t\t\t\t\t\t\t\t\t\tcleanup()\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonClose?.()\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tawait listener.end()\n\t\t\t\t\t\tonError(e)\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t} catch (e) {\n\t\t\t\treject(e)\n\t\t\t}\n\t\t})\n\t}\n}\n"],"names":["Listener","NOTIFY_CHANNEL_NAME","resolve","reject"],"mappings":";;;;AAOO,MAAM,yBAAyB;AAAA,EACrC,YACkB,YAChB;AADgB,SAAA,aAAA;AAAA,EAElB;AAAA,EAEO,OACN,EAAE,IAAI,uBAAuB,eACT;AACpB,WAAO,IAAI,kBAAkB,KAAK,YAAY,IAAI,uBAAuB,WAAW;AAAA,EACrF;AACD;AAEO,MAAM,kBAAsC;AAAA,EAClD,YACkB,YACA,IACA,uBACA,aAChB;AAJgB,SAAA,aAAA;AACA,SAAA,KAAA;AACA,SAAA,wBAAA;AACA,SAAA,cAAA;AAAA,EAElB;AAAA,EAEA,MAAa,IAAI,EAAE,QAAQ,SAAS,WAA2C;AAC9E,WAAO,MAAM,IAAI,QAAiB,OAAO,SAAS,WAAW;AAC5D,UAAI,iBAAiB,MAAM;AAAA,MAAC;AAC5B,UAAI,gBAAgB,CAAC,MAAW;AAAA,MAAC;AAEjC,YAAM,oBAAoB,MAAM;AAC/B,uBAAA;AAAA,MACD;AACA,UAAI;AACJ,YAAM,mBAAmB,CAAC,MAAW;AACpC,uBAAe;AACf,sBAAc,CAAC;AAAA,MAChB;AAEA,UAAI,eAAe;AACnB,UAAI,cAAc;AAClB,UAAI,UAAU;AAEd,UAAI;AACH,cAAM,KAAK,GAAG,MAAM,OAAM,OAAM;AAC/B,gBAAM,WAAW,MAAM,IAAIA,SAAAA,SAAiB,GAAG,QAAQC,cAAAA,qBAAqB,CAAA,YAAW;AACtF,gBAAI,YAAY,KAAK,aAAa;AACjC,gCAAA;AAAA,YACD;AAAA,UACD,CAAC,EACC,IAAI,EAAE,SAAS,kBAAkB,SAAS,mBAAmB;AAE/D,kBAAQ;AAAA,YACP,KAAK,YAAY;AAChB,wBAAU;AACV,oBAAM,SAAS,IAAA;AACf,qBAAO,KAAK,qBAAqB;AAAA,gBAChC,SAAS;AAAA,gBACT,QAAQ;AAAA,cAAA,CACR;AAAA,YACF;AAAA,UAAA,CACA;AAED,cAAI;AACH,mBAAO,CAAC,SAAS;AAChB,oBAAM,EAAE,SAAS,QAAQ,UAAA,IAAc,MAAM,KAAK,WAAW,aAAa;AAAA,gBACzE;AAAA,gBACA,uBAAuB,KAAK;AAAA,gBAC5B;AAAA,cAAA,CACA;AACD,8BAAgB;AAChB,6BAAe;AAGf,kBAAI,cAAc;AACjB,sBAAM;AAAA,cACP;AAGA,kBAAI,cAAc,GAAG;AACpB,sBAAM,IAAI,QAAc,CAACC,UAASC,YAAW;AAC5C,sBAAI,UAAU,MAAM;AAAA,kBACpB;AACA,sBAAI,cAAc,QAAW;AAC5B,0BAAM,gBAAgB,WAAWD,UAAS,SAAS;AACnD,8BAAU,MAAM,aAAa,aAAa;AAAA,kBAC3C;AACA,mCAAiB,MAAM;AACtBA,6BAAAA;AACA,4BAAA;AAAA,kBACD;AACA,kCAAgB,CAAA,MAAK;AACpBC,4BAAO,CAAC;AACR,4BAAA;AAAA,kBACD;AAAA,gBACD,CAAC;AAAA,cACF;AAAA,YACD;AACA,sBAAA;AAAA,UACD,SAAS,GAAG;AACX,kBAAM,SAAS,IAAA;AACf,oBAAQ,CAAC;AAAA,UACV;AAAA,QACD,CAAC;AAAA,MACF,SAAS,GAAG;AACX,eAAO,CAAC;AAAA,MACT;AAAA,IACD,CAAC;AAAA,EACF;AACD;;;"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Listener } from "@contember/database";
|
|
2
|
+
import { NOTIFY_CHANNEL_NAME } from "../utils/notifyChannel.js";
|
|
3
|
+
class ProjectDispatcherFactory {
|
|
4
|
+
constructor(dispatcher) {
|
|
5
|
+
this.dispatcher = dispatcher;
|
|
6
|
+
}
|
|
7
|
+
create({ db, contentSchemaResolver, projectSlug }) {
|
|
8
|
+
return new ProjectDispatcher(this.dispatcher, db, contentSchemaResolver, projectSlug);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
class ProjectDispatcher {
|
|
12
|
+
constructor(dispatcher, db, contentSchemaResolver, projectSlug) {
|
|
13
|
+
this.dispatcher = dispatcher;
|
|
14
|
+
this.db = db;
|
|
15
|
+
this.contentSchemaResolver = contentSchemaResolver;
|
|
16
|
+
this.projectSlug = projectSlug;
|
|
17
|
+
}
|
|
18
|
+
async run({ logger, onError, onClose }) {
|
|
19
|
+
return await new Promise(async (resolve, reject) => {
|
|
20
|
+
let resolvePending = () => {
|
|
21
|
+
};
|
|
22
|
+
let rejectPending = (e) => {
|
|
23
|
+
};
|
|
24
|
+
const resolvePendingRef = () => {
|
|
25
|
+
resolvePending();
|
|
26
|
+
};
|
|
27
|
+
let pendingError;
|
|
28
|
+
const rejectPendingRef = (e) => {
|
|
29
|
+
pendingError = e;
|
|
30
|
+
rejectPending(e);
|
|
31
|
+
};
|
|
32
|
+
let succeedTotal = 0;
|
|
33
|
+
let failedTotal = 0;
|
|
34
|
+
let aborted = false;
|
|
35
|
+
try {
|
|
36
|
+
await this.db.scope(async (db) => {
|
|
37
|
+
const listener = await new Listener(db.client, NOTIFY_CHANNEL_NAME, (project) => {
|
|
38
|
+
if (project === this.projectSlug) {
|
|
39
|
+
resolvePendingRef();
|
|
40
|
+
}
|
|
41
|
+
}).run({ onError: rejectPendingRef, onClose: resolvePendingRef });
|
|
42
|
+
resolve({
|
|
43
|
+
end: async () => {
|
|
44
|
+
aborted = true;
|
|
45
|
+
await listener.end();
|
|
46
|
+
logger.info("Worker terminated", {
|
|
47
|
+
succeed: succeedTotal,
|
|
48
|
+
failed: failedTotal
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
try {
|
|
53
|
+
while (!aborted) {
|
|
54
|
+
const { succeed, failed, backoffMs } = await this.dispatcher.processBatch({
|
|
55
|
+
db,
|
|
56
|
+
contentSchemaResolver: this.contentSchemaResolver,
|
|
57
|
+
logger
|
|
58
|
+
});
|
|
59
|
+
succeedTotal += succeed;
|
|
60
|
+
failedTotal += failed;
|
|
61
|
+
if (pendingError) {
|
|
62
|
+
throw pendingError;
|
|
63
|
+
}
|
|
64
|
+
if (backoffMs !== 0) {
|
|
65
|
+
await new Promise((resolve2, reject2) => {
|
|
66
|
+
let cleanup = () => {
|
|
67
|
+
};
|
|
68
|
+
if (backoffMs !== void 0) {
|
|
69
|
+
const timeoutHandle = setTimeout(resolve2, backoffMs);
|
|
70
|
+
cleanup = () => clearTimeout(timeoutHandle);
|
|
71
|
+
}
|
|
72
|
+
resolvePending = () => {
|
|
73
|
+
resolve2();
|
|
74
|
+
cleanup();
|
|
75
|
+
};
|
|
76
|
+
rejectPending = (e) => {
|
|
77
|
+
reject2(e);
|
|
78
|
+
cleanup();
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
onClose?.();
|
|
84
|
+
} catch (e) {
|
|
85
|
+
await listener.end();
|
|
86
|
+
onError(e);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
} catch (e) {
|
|
90
|
+
reject(e);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export {
|
|
96
|
+
ProjectDispatcher,
|
|
97
|
+
ProjectDispatcherFactory
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=ProjectDispatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProjectDispatcher.js","sources":["../../../../../packages/engine-actions/src/dispatch/ProjectDispatcher.ts"],"sourcesContent":["import { DatabaseContext } from '@contember/engine-system-api'\nimport { EventDispatcher } from './EventDispatcher'\nimport { ContentSchemaResolver } from '@contember/engine-http'\nimport { Runnable, RunnableArgs, Running } from '@contember/engine-common'\nimport { Listener } from '@contember/database'\nimport { NOTIFY_CHANNEL_NAME } from '../utils/notifyChannel'\n\nexport class ProjectDispatcherFactory {\n\tconstructor(\n\t\tprivate readonly dispatcher: EventDispatcher,\n\t) {\n\t}\n\n\tpublic create(\n\t\t{ db, contentSchemaResolver, projectSlug }: { db: DatabaseContext; contentSchemaResolver: ContentSchemaResolver; projectSlug: string },\n\t): ProjectDispatcher {\n\t\treturn new ProjectDispatcher(this.dispatcher, db, contentSchemaResolver, projectSlug)\n\t}\n}\n\nexport class ProjectDispatcher implements Runnable {\n\tconstructor(\n\t\tprivate readonly dispatcher: EventDispatcher,\n\t\tprivate readonly db: DatabaseContext,\n\t\tprivate readonly contentSchemaResolver: ContentSchemaResolver,\n\t\tprivate readonly projectSlug: string,\n\t) {\n\t}\n\n\tpublic async run({ logger, onError, onClose }: RunnableArgs): Promise<Running> {\n\t\treturn await new Promise<Running>(async (resolve, reject) => {\n\t\t\tlet resolvePending = () => {}\n\t\t\tlet rejectPending = (e: any) => {}\n\n\t\t\tconst resolvePendingRef = () => {\n\t\t\t\tresolvePending()\n\t\t\t}\n\t\t\tlet pendingError: any\n\t\t\tconst rejectPendingRef = (e: any) => {\n\t\t\t\tpendingError = e\n\t\t\t\trejectPending(e)\n\t\t\t}\n\n\t\t\tlet succeedTotal = 0\n\t\t\tlet failedTotal = 0\n\t\t\tlet aborted = false\n\n\t\t\ttry {\n\t\t\t\tawait this.db.scope(async db => {\n\t\t\t\t\tconst listener = await new Listener<string>(db.client, NOTIFY_CHANNEL_NAME, project => {\n\t\t\t\t\t\tif (project === this.projectSlug) {\n\t\t\t\t\t\t\tresolvePendingRef()\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t\t\t.run({ onError: rejectPendingRef, onClose: resolvePendingRef })\n\n\t\t\t\t\tresolve({\n\t\t\t\t\t\tend: async () => {\n\t\t\t\t\t\t\taborted = true\n\t\t\t\t\t\t\tawait listener.end()\n\t\t\t\t\t\t\tlogger.info('Worker terminated', {\n\t\t\t\t\t\t\t\tsucceed: succeedTotal,\n\t\t\t\t\t\t\t\tfailed: failedTotal,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\twhile (!aborted) {\n\t\t\t\t\t\t\tconst { succeed, failed, backoffMs } = await this.dispatcher.processBatch({\n\t\t\t\t\t\t\t\tdb,\n\t\t\t\t\t\t\t\tcontentSchemaResolver: this.contentSchemaResolver,\n\t\t\t\t\t\t\t\tlogger,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tsucceedTotal += succeed\n\t\t\t\t\t\t\tfailedTotal += failed\n\n\t\t\t\t\t\t\t// listener error occurred during batch processing, rethrow\n\t\t\t\t\t\t\tif (pendingError) {\n\t\t\t\t\t\t\t\tthrow pendingError\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// queue is empty, wait\n\t\t\t\t\t\t\tif (backoffMs !== 0) {\n\t\t\t\t\t\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\t\t\t\t\t\tlet cleanup = () => {\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (backoffMs !== undefined) {\n\t\t\t\t\t\t\t\t\t\tconst timeoutHandle = setTimeout(resolve, backoffMs)\n\t\t\t\t\t\t\t\t\t\tcleanup = () => clearTimeout(timeoutHandle)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tresolvePending = () => {\n\t\t\t\t\t\t\t\t\t\tresolve()\n\t\t\t\t\t\t\t\t\t\tcleanup()\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\trejectPending = e => {\n\t\t\t\t\t\t\t\t\t\treject(e)\n\t\t\t\t\t\t\t\t\t\tcleanup()\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonClose?.()\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tawait listener.end()\n\t\t\t\t\t\tonError(e)\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t} catch (e) {\n\t\t\t\treject(e)\n\t\t\t}\n\t\t})\n\t}\n}\n"],"names":["resolve","reject"],"mappings":";;AAOO,MAAM,yBAAyB;AAAA,EACrC,YACkB,YAChB;AADgB,SAAA,aAAA;AAAA,EAElB;AAAA,EAEO,OACN,EAAE,IAAI,uBAAuB,eACT;AACpB,WAAO,IAAI,kBAAkB,KAAK,YAAY,IAAI,uBAAuB,WAAW;AAAA,EACrF;AACD;AAEO,MAAM,kBAAsC;AAAA,EAClD,YACkB,YACA,IACA,uBACA,aAChB;AAJgB,SAAA,aAAA;AACA,SAAA,KAAA;AACA,SAAA,wBAAA;AACA,SAAA,cAAA;AAAA,EAElB;AAAA,EAEA,MAAa,IAAI,EAAE,QAAQ,SAAS,WAA2C;AAC9E,WAAO,MAAM,IAAI,QAAiB,OAAO,SAAS,WAAW;AAC5D,UAAI,iBAAiB,MAAM;AAAA,MAAC;AAC5B,UAAI,gBAAgB,CAAC,MAAW;AAAA,MAAC;AAEjC,YAAM,oBAAoB,MAAM;AAC/B,uBAAA;AAAA,MACD;AACA,UAAI;AACJ,YAAM,mBAAmB,CAAC,MAAW;AACpC,uBAAe;AACf,sBAAc,CAAC;AAAA,MAChB;AAEA,UAAI,eAAe;AACnB,UAAI,cAAc;AAClB,UAAI,UAAU;AAEd,UAAI;AACH,cAAM,KAAK,GAAG,MAAM,OAAM,OAAM;AAC/B,gBAAM,WAAW,MAAM,IAAI,SAAiB,GAAG,QAAQ,qBAAqB,CAAA,YAAW;AACtF,gBAAI,YAAY,KAAK,aAAa;AACjC,gCAAA;AAAA,YACD;AAAA,UACD,CAAC,EACC,IAAI,EAAE,SAAS,kBAAkB,SAAS,mBAAmB;AAE/D,kBAAQ;AAAA,YACP,KAAK,YAAY;AAChB,wBAAU;AACV,oBAAM,SAAS,IAAA;AACf,qBAAO,KAAK,qBAAqB;AAAA,gBAChC,SAAS;AAAA,gBACT,QAAQ;AAAA,cAAA,CACR;AAAA,YACF;AAAA,UAAA,CACA;AAED,cAAI;AACH,mBAAO,CAAC,SAAS;AAChB,oBAAM,EAAE,SAAS,QAAQ,UAAA,IAAc,MAAM,KAAK,WAAW,aAAa;AAAA,gBACzE;AAAA,gBACA,uBAAuB,KAAK;AAAA,gBAC5B;AAAA,cAAA,CACA;AACD,8BAAgB;AAChB,6BAAe;AAGf,kBAAI,cAAc;AACjB,sBAAM;AAAA,cACP;AAGA,kBAAI,cAAc,GAAG;AACpB,sBAAM,IAAI,QAAc,CAACA,UAASC,YAAW;AAC5C,sBAAI,UAAU,MAAM;AAAA,kBACpB;AACA,sBAAI,cAAc,QAAW;AAC5B,0BAAM,gBAAgB,WAAWD,UAAS,SAAS;AACnD,8BAAU,MAAM,aAAa,aAAa;AAAA,kBAC3C;AACA,mCAAiB,MAAM;AACtBA,6BAAAA;AACA,4BAAA;AAAA,kBACD;AACA,kCAAgB,CAAA,MAAK;AACpBC,4BAAO,CAAC;AACR,4BAAA;AAAA,kBACD;AAAA,gBACD,CAAC;AAAA,cACF;AAAA,YACD;AACA,sBAAA;AAAA,UACD,SAAS,GAAG;AACX,kBAAM,SAAS,IAAA;AACf,oBAAQ,CAAC;AAAA,UACV;AAAA,QACD,CAAC;AAAA,MACF,SAAS,GAAG;AACX,eAAO,CAAC;AAAA,MACT;AAAA,IACD,CAAC;AAAA,EACF;AACD;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const ImplementationException = require("../ImplementationException.cjs");
|
|
4
|
+
class TargetHandlerResolver {
|
|
5
|
+
constructor(webhookHandler) {
|
|
6
|
+
this.webhookHandler = webhookHandler;
|
|
7
|
+
}
|
|
8
|
+
resolveHandler(target) {
|
|
9
|
+
if (target.type !== "webhook") {
|
|
10
|
+
throw new ImplementationException.ImplementationException("Invalid trigger invocation type");
|
|
11
|
+
}
|
|
12
|
+
return this.webhookHandler;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.TargetHandlerResolver = TargetHandlerResolver;
|
|
16
|
+
//# sourceMappingURL=TargetHandlerResolver.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TargetHandlerResolver.cjs","sources":["../../../../../packages/engine-actions/src/dispatch/TargetHandlerResolver.ts"],"sourcesContent":["import { Actions } from '@contember/schema'\nimport { WebhookTargetHandler } from './WebhookTargetHandler'\nimport { ImplementationException } from '../ImplementationException'\nimport { InvokeHandler } from './types'\n\nexport class TargetHandlerResolver {\n\tconstructor(\n\t\tprivate readonly webhookHandler: WebhookTargetHandler,\n\t) {\n\t}\n\n\tpublic resolveHandler<T extends Actions.AnyTarget>(target: T): InvokeHandler<T> {\n\t\tif (target.type !== 'webhook') {\n\t\t\tthrow new ImplementationException('Invalid trigger invocation type')\n\t\t}\n\t\treturn this.webhookHandler\n\t}\n}\n"],"names":["ImplementationException"],"mappings":";;;AAKO,MAAM,sBAAsB;AAAA,EAClC,YACkB,gBAChB;AADgB,SAAA,iBAAA;AAAA,EAElB;AAAA,EAEO,eAA4C,QAA6B;AAC/E,QAAI,OAAO,SAAS,WAAW;AAC9B,YAAM,IAAIA,wBAAAA,wBAAwB,iCAAiC;AAAA,IACpE;AACA,WAAO,KAAK;AAAA,EACb;AACD;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ImplementationException } from "../ImplementationException.js";
|
|
2
|
+
class TargetHandlerResolver {
|
|
3
|
+
constructor(webhookHandler) {
|
|
4
|
+
this.webhookHandler = webhookHandler;
|
|
5
|
+
}
|
|
6
|
+
resolveHandler(target) {
|
|
7
|
+
if (target.type !== "webhook") {
|
|
8
|
+
throw new ImplementationException("Invalid trigger invocation type");
|
|
9
|
+
}
|
|
10
|
+
return this.webhookHandler;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
TargetHandlerResolver
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=TargetHandlerResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TargetHandlerResolver.js","sources":["../../../../../packages/engine-actions/src/dispatch/TargetHandlerResolver.ts"],"sourcesContent":["import { Actions } from '@contember/schema'\nimport { WebhookTargetHandler } from './WebhookTargetHandler'\nimport { ImplementationException } from '../ImplementationException'\nimport { InvokeHandler } from './types'\n\nexport class TargetHandlerResolver {\n\tconstructor(\n\t\tprivate readonly webhookHandler: WebhookTargetHandler,\n\t) {\n\t}\n\n\tpublic resolveHandler<T extends Actions.AnyTarget>(target: T): InvokeHandler<T> {\n\t\tif (target.type !== 'webhook') {\n\t\t\tthrow new ImplementationException('Invalid trigger invocation type')\n\t\t}\n\t\treturn this.webhookHandler\n\t}\n}\n"],"names":[],"mappings":";AAKO,MAAM,sBAAsB;AAAA,EAClC,YACkB,gBAChB;AADgB,SAAA,iBAAA;AAAA,EAElB;AAAA,EAEO,eAA4C,QAA6B;AAC/E,QAAI,OAAO,SAAS,WAAW;AAC9B,YAAM,IAAI,wBAAwB,iCAAiC;AAAA,IACpE;AACA,WAAO,KAAK;AAAA,EACb;AACD;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
class WebhookFetcherNative {
|
|
4
|
+
async fetch(url, init) {
|
|
5
|
+
const response = await fetch(url, init);
|
|
6
|
+
return {
|
|
7
|
+
ok: response.ok,
|
|
8
|
+
headers: response.headers,
|
|
9
|
+
status: response.status,
|
|
10
|
+
statusText: response.statusText,
|
|
11
|
+
responseText: await response.text()
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.WebhookFetcherNative = WebhookFetcherNative;
|
|
16
|
+
//# sourceMappingURL=WebhookFetcher.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebhookFetcher.cjs","sources":["../../../../../packages/engine-actions/src/dispatch/WebhookFetcher.ts"],"sourcesContent":["export type FetcherResponse = {\n\treadonly headers: Headers\n\treadonly ok: boolean\n\treadonly status: number\n\treadonly statusText: string\n\treadonly responseText: string\n}\n\nexport interface WebhookFetcher {\n\tfetch(url: string, init: RequestInit): Promise<FetcherResponse>\n}\n\nexport class WebhookFetcherNative implements WebhookFetcher {\n\tasync fetch(url: string, init: RequestInit): Promise<FetcherResponse> {\n\t\tconst response = await fetch(url, init)\n\t\treturn {\n\t\t\tok: response.ok,\n\t\t\theaders: response.headers,\n\t\t\tstatus: response.status,\n\t\t\tstatusText: response.statusText,\n\t\t\tresponseText: await response.text(),\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;AAYO,MAAM,qBAA+C;AAAA,EAC3D,MAAM,MAAM,KAAa,MAA6C;AACrE,UAAM,WAAW,MAAM,MAAM,KAAK,IAAI;AACtC,WAAO;AAAA,MACN,IAAI,SAAS;AAAA,MACb,SAAS,SAAS;AAAA,MAClB,QAAQ,SAAS;AAAA,MACjB,YAAY,SAAS;AAAA,MACrB,cAAc,MAAM,SAAS,KAAA;AAAA,IAAK;AAAA,EAEpC;AACD;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class WebhookFetcherNative {
|
|
2
|
+
async fetch(url, init) {
|
|
3
|
+
const response = await fetch(url, init);
|
|
4
|
+
return {
|
|
5
|
+
ok: response.ok,
|
|
6
|
+
headers: response.headers,
|
|
7
|
+
status: response.status,
|
|
8
|
+
statusText: response.statusText,
|
|
9
|
+
responseText: await response.text()
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
WebhookFetcherNative
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=WebhookFetcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebhookFetcher.js","sources":["../../../../../packages/engine-actions/src/dispatch/WebhookFetcher.ts"],"sourcesContent":["export type FetcherResponse = {\n\treadonly headers: Headers\n\treadonly ok: boolean\n\treadonly status: number\n\treadonly statusText: string\n\treadonly responseText: string\n}\n\nexport interface WebhookFetcher {\n\tfetch(url: string, init: RequestInit): Promise<FetcherResponse>\n}\n\nexport class WebhookFetcherNative implements WebhookFetcher {\n\tasync fetch(url: string, init: RequestInit): Promise<FetcherResponse> {\n\t\tconst response = await fetch(url, init)\n\t\treturn {\n\t\t\tok: response.ok,\n\t\t\theaders: response.headers,\n\t\t\tstatus: response.status,\n\t\t\tstatusText: response.statusText,\n\t\t\tresponseText: await response.text(),\n\t\t}\n\t}\n}\n"],"names":[],"mappings":"AAYO,MAAM,qBAA+C;AAAA,EAC3D,MAAM,MAAM,KAAa,MAA6C;AACrE,UAAM,WAAW,MAAM,MAAM,KAAK,IAAI;AACtC,WAAO;AAAA,MACN,IAAI,SAAS;AAAA,MACb,SAAS,SAAS;AAAA,MAClB,QAAQ,SAAS;AAAA,MACjB,YAAY,SAAS;AAAA,MACrB,cAAc,MAAM,SAAS,KAAA;AAAA,IAAK;AAAA,EAEpC;AACD;"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const Typesafe = require("@contember/typesafe");
|
|
4
|
+
function _interopNamespaceDefault(e) {
|
|
5
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
6
|
+
if (e) {
|
|
7
|
+
for (const k in e) {
|
|
8
|
+
if (k !== "default") {
|
|
9
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
10
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: () => e[k]
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
n.default = e;
|
|
18
|
+
return Object.freeze(n);
|
|
19
|
+
}
|
|
20
|
+
const Typesafe__namespace = /* @__PURE__ */ _interopNamespaceDefault(Typesafe);
|
|
21
|
+
const DEFAULT_TIMEOUT_MS = 3e4;
|
|
22
|
+
const ResponseType = Typesafe__namespace.noExtraProps(Typesafe__namespace.object({
|
|
23
|
+
failures: Typesafe__namespace.array(
|
|
24
|
+
Typesafe__namespace.intersection(
|
|
25
|
+
Typesafe__namespace.object({
|
|
26
|
+
eventId: Typesafe__namespace.string
|
|
27
|
+
}),
|
|
28
|
+
Typesafe__namespace.partial({
|
|
29
|
+
error: Typesafe__namespace.string
|
|
30
|
+
})
|
|
31
|
+
)
|
|
32
|
+
)
|
|
33
|
+
}));
|
|
34
|
+
class WebhookTargetHandler {
|
|
35
|
+
constructor(fetcher) {
|
|
36
|
+
this.fetcher = fetcher;
|
|
37
|
+
}
|
|
38
|
+
async handle({ target, events, logger, variables }) {
|
|
39
|
+
const timeoutMs = target.timeoutMs;
|
|
40
|
+
const start = process.hrtime.bigint();
|
|
41
|
+
const getDuration = () => Math.floor(Number((process.hrtime.bigint() - start) / BigInt(1e6)));
|
|
42
|
+
let eventResponseFactory;
|
|
43
|
+
try {
|
|
44
|
+
const response = await this.fetch(timeoutMs ?? DEFAULT_TIMEOUT_MS, target, variables, events);
|
|
45
|
+
eventResponseFactory = this.createResponseFactory({
|
|
46
|
+
response,
|
|
47
|
+
events
|
|
48
|
+
});
|
|
49
|
+
} catch (e) {
|
|
50
|
+
logger.warn(e);
|
|
51
|
+
const errorMessages = this.extractErrorMessages(e);
|
|
52
|
+
const result = {
|
|
53
|
+
ok: false,
|
|
54
|
+
errorMessage: errorMessages.length ? errorMessages.join("; ") : void 0,
|
|
55
|
+
durationMs: getDuration()
|
|
56
|
+
};
|
|
57
|
+
eventResponseFactory = () => ({ ok: false, errorMessage: errorMessages.length ? errorMessages.join("; ") : void 0 });
|
|
58
|
+
return events.map((it) => ({ target, row: it, result }));
|
|
59
|
+
}
|
|
60
|
+
const durationMs = getDuration();
|
|
61
|
+
return events.map((it) => ({ target, row: it, result: { durationMs, ...eventResponseFactory(it) } }));
|
|
62
|
+
}
|
|
63
|
+
createResponseFactory({ response, events }) {
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
return () => ({
|
|
66
|
+
ok: false,
|
|
67
|
+
code: response.status,
|
|
68
|
+
response: response.responseText,
|
|
69
|
+
errorMessage: response.statusText
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (response.responseText.trim() === "" || !response.headers.get("content-type")?.toLowerCase().includes("json")) {
|
|
73
|
+
return () => ({
|
|
74
|
+
ok: true,
|
|
75
|
+
code: response.status
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const parsedJson = JSON.parse(response.responseText);
|
|
80
|
+
if (parsedJson === null || typeof parsedJson !== "object" || !("failures" in parsedJson)) {
|
|
81
|
+
return () => ({
|
|
82
|
+
ok: true,
|
|
83
|
+
code: response.status
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const responseData = ResponseType(parsedJson);
|
|
87
|
+
const eventsInBatch = new Set(events.map((it) => it.id));
|
|
88
|
+
const failedEvents = Object.fromEntries(responseData.failures?.map((it) => [it.eventId, it]) ?? []);
|
|
89
|
+
const missingEvents = Object.keys(failedEvents).filter((it) => !eventsInBatch.has(it));
|
|
90
|
+
if (missingEvents.length) {
|
|
91
|
+
return () => ({
|
|
92
|
+
ok: false,
|
|
93
|
+
code: response.status,
|
|
94
|
+
response: response.responseText,
|
|
95
|
+
errorMessage: "Invalid response: undefined events IDs: " + missingEvents.join("; ")
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return (it) => {
|
|
99
|
+
if (!failedEvents[it.id]) {
|
|
100
|
+
return { ok: true, code: response.status };
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
ok: false,
|
|
104
|
+
code: response.status,
|
|
105
|
+
errorMessage: failedEvents[it.id].error
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
} catch (e) {
|
|
109
|
+
return () => ({
|
|
110
|
+
ok: false,
|
|
111
|
+
code: response.status,
|
|
112
|
+
response: response.responseText,
|
|
113
|
+
errorMessage: "Invalid response: " + e.message
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
extractErrorMessages(e) {
|
|
118
|
+
const errorMessages = [];
|
|
119
|
+
let err = e;
|
|
120
|
+
while (typeof err === "object" && err !== null && "message" in err && typeof err.message === "string") {
|
|
121
|
+
errorMessages.push(err.message);
|
|
122
|
+
err = err.cause;
|
|
123
|
+
}
|
|
124
|
+
return errorMessages;
|
|
125
|
+
}
|
|
126
|
+
async fetch(timeoutMs, target, variables, events) {
|
|
127
|
+
return await withTimeout(timeoutMs, async (abortController) => {
|
|
128
|
+
return await this.doFetch(target, variables, abortController, events);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
async doFetch(target, variables, abortController, events) {
|
|
132
|
+
const resolvedUrl = this.resolveVariables(target.url, variables);
|
|
133
|
+
const resolvedHeaders = Object.fromEntries(
|
|
134
|
+
Object.entries(target.headers ?? {}).map(([key, value]) => [key, this.resolveVariables(value, variables)])
|
|
135
|
+
);
|
|
136
|
+
return await this.fetcher.fetch(resolvedUrl, {
|
|
137
|
+
method: "POST",
|
|
138
|
+
headers: {
|
|
139
|
+
["User-Agent"]: "Contember Actions",
|
|
140
|
+
...resolvedHeaders,
|
|
141
|
+
["Content-type"]: "application/json"
|
|
142
|
+
},
|
|
143
|
+
signal: abortController.signal,
|
|
144
|
+
body: this.formatBody(events, target)
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
formatBody(events, target) {
|
|
148
|
+
var _a;
|
|
149
|
+
const body = target.body ?? {};
|
|
150
|
+
const path = target.payloadPath ?? [];
|
|
151
|
+
let current = body;
|
|
152
|
+
for (let i = 0; i < path.length; i++) {
|
|
153
|
+
current[_a = path[i]] ?? (current[_a] = {});
|
|
154
|
+
current = current[path[i]];
|
|
155
|
+
}
|
|
156
|
+
current["events"] = events.map(this.formatEventPayload);
|
|
157
|
+
return JSON.stringify(body);
|
|
158
|
+
}
|
|
159
|
+
formatEventPayload(it) {
|
|
160
|
+
return {
|
|
161
|
+
meta: {
|
|
162
|
+
eventId: it.id,
|
|
163
|
+
transactionId: it.transaction_id,
|
|
164
|
+
identityId: it.identity_id ?? null,
|
|
165
|
+
ipAddress: it.ip_address ?? null,
|
|
166
|
+
userAgent: it.user_agent ?? null,
|
|
167
|
+
createdAt: it.created_at.toISOString(),
|
|
168
|
+
lastStateChange: it.last_state_change.toISOString(),
|
|
169
|
+
numRetries: it.num_retries,
|
|
170
|
+
trigger: it.trigger,
|
|
171
|
+
target: it.target
|
|
172
|
+
// todo: add stage and schema version
|
|
173
|
+
},
|
|
174
|
+
...it.payload
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
resolveVariables(subject, variables) {
|
|
178
|
+
return subject.replace(/\{\{([\w_]+)}}/gm, (_, name) => {
|
|
179
|
+
if (!variables[name]) {
|
|
180
|
+
throw new Error(`Undefined variable ${name}`);
|
|
181
|
+
}
|
|
182
|
+
return variables[name];
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const withTimeout = async (timeoutMs, cb) => {
|
|
187
|
+
const abortController = new AbortController();
|
|
188
|
+
const timeoutId = setTimeout(() => {
|
|
189
|
+
abortController.abort();
|
|
190
|
+
}, timeoutMs);
|
|
191
|
+
try {
|
|
192
|
+
return await cb(abortController);
|
|
193
|
+
} finally {
|
|
194
|
+
clearTimeout(timeoutId);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
exports.WebhookTargetHandler = WebhookTargetHandler;
|
|
198
|
+
//# sourceMappingURL=WebhookTargetHandler.cjs.map
|