Let server route resolvers answer the caller synchronously (#23233)
## Problem
A server route resolver can only return a dispatch target (`{
workspaceId, targetLogicFunctionUniversalIdentifier, payload }`), and
`ServerRouteTriggerService` always acks `202 {queued:true}`. The target
function runs off the queue, after the response has been sent, so its
return value can never reach the caller.
That makes it impossible to integrate a provider whose webhook URL has
to be proven with a handshake on the same response. Slack's Events API
is the case that surfaced it: `url_verification` sends `{ type,
challenge }` and will not accept the Request URL unless the challenge
comes back on that POST.
## Change
A resolver may now return a `Response` (the existing
`LogicFunctionHttpResponse`) instead of a dispatch target. The route
sends it as-is via `buildRouteTriggerResponse` and enqueues nothing.
- Reuses the marker and builder that HTTP route triggers already use, so
there is no new response shape.
- Dispatch results behave exactly as before; the resolver error path is
unchanged, just hoisted out of `parseResolverResult` so it runs before
the branch.
- SDK: `ServerRouteResolverResult` becomes `ServerRouteDispatchResult |
LogicFunctionHttpResponse`.
Additive: a resolver that returns a dispatch target sees no behavior
change. Previously, returning this shape threw
`RESOLVER_INVALID_RESULT`.
## Testing
`server-route-trigger.service.spec.ts` gains a case asserting the
resolver's response is sent verbatim and nothing is enqueued. 15/15
pass.
## Context
Split out of #22984 (Slack conversational assistant), which needs this
to complete the Slack Events URL verification. That PR depends on this
one merging first.
<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/23233?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
This commit is contained in:
@@ -92,7 +92,9 @@ export type {
|
||||
export type {
|
||||
LogicFunctionConfig,
|
||||
LogicFunctionHandler,
|
||||
ServerRouteResolverResult,
|
||||
} from '@/sdk/define/logic-functions/logic-function-config';
|
||||
export type { ServerRouteDispatchResult } from 'twenty-shared/application';
|
||||
export type { CronPayload } from '@/sdk/define/logic-functions/triggers/cron-payload-type';
|
||||
export type {
|
||||
DatabaseEventPayload,
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
import {
|
||||
type LogicFunctionManifest,
|
||||
type ServerRouteDispatchResult,
|
||||
type ServerRouteTriggerSettings,
|
||||
} from 'twenty-shared/application';
|
||||
import { type LogicFunctionHttpResponse } from 'twenty-shared/types';
|
||||
|
||||
export type LogicFunctionHandler = (...args: any[]) => any | Promise<any>;
|
||||
|
||||
// A resolver function attached to `serverRouteTriggerSettings` runs in the
|
||||
// owner workspace and must return BOTH the target workspace and the target
|
||||
// logic function to dispatch to. The server contract is
|
||||
// `{ workspaceId: string; targetLogicFunctionUniversalIdentifier: string;
|
||||
// payload?: object }`. The resolver is the single point of authorization —
|
||||
// the URL only carries the resolver's universalIdentifier.
|
||||
export type ServerRouteResolverResult = {
|
||||
workspaceId: string;
|
||||
targetLogicFunctionUniversalIdentifier: string;
|
||||
payload?: object;
|
||||
};
|
||||
// A resolver attached to `serverRouteTriggerSettings` runs in the owner workspace and is the single
|
||||
// point of authorization: the URL only carries the resolver's universalIdentifier. Returning a
|
||||
// dispatch result enqueues the target, returning a `Response` answers the caller synchronously
|
||||
// instead, for providers whose webhook URL requires a handshake reply.
|
||||
export type ServerRouteResolverResult =
|
||||
| ServerRouteDispatchResult
|
||||
| LogicFunctionHttpResponse;
|
||||
|
||||
export type ServerRouteResolverHandler = (
|
||||
...args: any[]
|
||||
|
||||
@@ -13,7 +13,9 @@
|
||||
export type {
|
||||
LogicFunctionConfig,
|
||||
LogicFunctionHandler,
|
||||
ServerRouteResolverResult,
|
||||
} from '@/sdk/define/logic-functions/logic-function-config';
|
||||
export type { ServerRouteDispatchResult } from 'twenty-shared/application';
|
||||
|
||||
export type {
|
||||
InstallHandler,
|
||||
|
||||
Reference in New Issue
Block a user