(triggerId: string)
| 68 | * are merged into a single block (e.g., ...getTrigger('a').subBlocks, ...getTrigger('b').subBlocks). |
| 69 | */ |
| 70 | export function getTrigger(triggerId: string): TriggerConfig { |
| 71 | const trigger = TRIGGER_REGISTRY[triggerId] |
| 72 | if (!trigger) { |
| 73 | throw new Error(`Trigger not found: ${triggerId}`) |
| 74 | } |
| 75 | |
| 76 | // Filter out deprecated trigger-save subblocks from legacy stored data |
| 77 | const subBlocks = trigger.subBlocks |
| 78 | .filter( |
| 79 | (subBlock) => subBlock.id !== 'triggerSave' && (subBlock.type as string) !== 'trigger-save' |
| 80 | ) |
| 81 | .map((subBlock) => namespaceSubBlockId(subBlock, triggerId)) |
| 82 | |
| 83 | const clonedTrigger = { ...trigger, subBlocks } |
| 84 | |
| 85 | // Inject samplePayload for webhooks/pollers with condition |
| 86 | if (trigger.webhook || trigger.id.includes('webhook') || trigger.id.includes('poller')) { |
| 87 | const samplePayloadExists = clonedTrigger.subBlocks.some( |
| 88 | (sb) => sb.id === 'samplePayload' || sb.id === `samplePayload_${triggerId}` |
| 89 | ) |
| 90 | |
| 91 | if (!samplePayloadExists && trigger.outputs) { |
| 92 | const mockPayload = generateMockPayloadFromOutputsDefinition(trigger.outputs) |
| 93 | const generatedPayload = JSON.stringify(mockPayload, null, 2) |
| 94 | |
| 95 | const samplePayloadSubBlock: SubBlockConfig = { |
| 96 | id: `samplePayload_${triggerId}`, |
| 97 | title: 'Event Payload Example', |
| 98 | type: 'code', |
| 99 | language: 'json', |
| 100 | defaultValue: generatedPayload, |
| 101 | readOnly: true, |
| 102 | collapsible: true, |
| 103 | defaultCollapsed: true, |
| 104 | hideFromPreview: true, |
| 105 | mode: 'trigger', |
| 106 | condition: { |
| 107 | field: 'selectedTriggerId', |
| 108 | value: trigger.id, |
| 109 | }, |
| 110 | } |
| 111 | |
| 112 | clonedTrigger.subBlocks.push(samplePayloadSubBlock) |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return clonedTrigger |
| 117 | } |
| 118 | |
| 119 | export function getTriggersByProvider(provider: string): TriggerConfig[] { |
| 120 | return Object.values(TRIGGER_REGISTRY) |
no test coverage detected