feat(workflow): expand manual-trigger runtime payload with payload + _metadata (#21676)
## Summary
Step 1 (**expand**) of restructuring the manual-trigger output so record
fields live under a `payload` key and trigger-level metadata (the
running workspace member) lives alongside it. This step is **additive
and runtime-only** — no behavior changes for existing workflows, and
nothing new is surfaced in the variable picker yet.
The manual-trigger runtime payload now additively carries:
- `payload`: a mirror of the incoming record fields, reachable at
`{{trigger.payload.*}}`
- `_metadata.workspaceMemberId`: the member who ran the workflow,
reachable at `{{trigger._metadata.workspaceMemberId}}`
Record fields are still served at the trigger root, so existing
`{{trigger.id}}` references keep working unchanged. The output schema /
variable picker is intentionally left untouched here.
### Why `_metadata` (underscore)
During the transition, record fields still sit at the `trigger` root
next to the injected keys. Field API names can't start with `_`, so
`_metadata` is collision-proof against any record field; picking the
name now avoids a later variable-path rename migration.
### Phasing
- **Step 1 (this PR):** write `payload` + `_metadata` at runtime; keep
using direct `trigger.*`; don't display the new paths.
- **Step 2:** surface `payload` + `_metadata` in the variable picker.
- **Step 3:** migrate existing variables to `trigger.payload.*` and
contract the root record fields.
## Test plan
- [x] `twenty-shared` builds, `twenty-server` typechecks, lint clean on
changed files
- [x] Manual: run a manually-triggered (SINGLE_RECORD) workflow and
confirm the run's trigger payload contains `payload.*` mirroring the
record and `_metadata.workspaceMemberId`
- [x] Manual: confirm existing `{{trigger.id}}` references still resolve
<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/21676?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:
+13
-1
@@ -2,6 +2,11 @@ import { UseFilters, UseGuards, UsePipes } from '@nestjs/common';
|
||||
import { Args, Mutation } from '@nestjs/graphql';
|
||||
|
||||
import { PermissionFlagType } from 'twenty-shared/constants';
|
||||
import {
|
||||
WORKFLOW_TRIGGER_METADATA_KEY,
|
||||
WORKFLOW_TRIGGER_METADATA_WORKSPACE_MEMBER_ID_KEY,
|
||||
WORKFLOW_TRIGGER_PAYLOAD_KEY,
|
||||
} from 'twenty-shared/workflow';
|
||||
|
||||
import { CoreResolver } from 'src/engine/api/graphql/graphql-config/decorators/core-resolver.decorator';
|
||||
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
|
||||
@@ -98,7 +103,14 @@ export class WorkflowTriggerResolver {
|
||||
return this.workflowTriggerWorkspaceService.runWorkflowVersion({
|
||||
workflowVersionId,
|
||||
workflowRunId: workflowRunId ?? undefined,
|
||||
payload: payload ?? {},
|
||||
payload: {
|
||||
...(payload ?? {}),
|
||||
[WORKFLOW_TRIGGER_PAYLOAD_KEY]: { ...(payload ?? {}) },
|
||||
[WORKFLOW_TRIGGER_METADATA_KEY]: {
|
||||
[WORKFLOW_TRIGGER_METADATA_WORKSPACE_MEMBER_ID_KEY]:
|
||||
workspaceMember.id,
|
||||
},
|
||||
},
|
||||
createdBy: buildCreatedByFromFullNameMetadata({
|
||||
fullNameMetadata: {
|
||||
firstName: workspaceMember.name.firstName,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export const WORKFLOW_TRIGGER_METADATA_KEY = 'metadata';
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export const WORKFLOW_TRIGGER_METADATA_WORKSPACE_MEMBER_ID_KEY =
|
||||
'workspaceMemberId';
|
||||
@@ -0,0 +1 @@
|
||||
export const WORKFLOW_TRIGGER_PAYLOAD_KEY = 'payload';
|
||||
@@ -12,6 +12,9 @@ export { CONTENT_TYPE_VALUES_HTTP_REQUEST } from './constants/ContentTypeValuesH
|
||||
export { IF_ELSE_BRANCH_POSITION_OFFSETS } from './constants/IfElseBranchPositionOffsets';
|
||||
export { OBJECTS_BLOCKED_FROM_AUTOMATION } from './constants/ObjectsBlockedFromAutomation';
|
||||
export { TRIGGER_STEP_ID } from './constants/TriggerStepId';
|
||||
export { WORKFLOW_TRIGGER_METADATA_KEY } from './constants/WorkflowTriggerMetadataKey';
|
||||
export { WORKFLOW_TRIGGER_METADATA_WORKSPACE_MEMBER_ID_KEY } from './constants/WorkflowTriggerMetadataWorkspaceMemberIdKey';
|
||||
export { WORKFLOW_TRIGGER_PAYLOAD_KEY } from './constants/WorkflowTriggerPayloadKey';
|
||||
export { workflowAiAgentActionSchema } from './schemas/ai-agent-action-schema';
|
||||
export { workflowAiAgentActionSettingsSchema } from './schemas/ai-agent-action-settings-schema';
|
||||
export { baseTriggerSchema } from './schemas/base-trigger-schema';
|
||||
|
||||
Reference in New Issue
Block a user