|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +import { defineFlow } from '@objectstack/spec'; |
| 4 | + |
| 5 | +/** |
| 6 | + * #3447 P2 dogfood: dynamic approver routing end to end. |
| 7 | + * |
| 8 | + * Two-stage approval where the FIRST approver picks the second stage's |
| 9 | + * approvers in their decision (`decisionOutputs`), and the second stage |
| 10 | + * resolves them at node entry from an `expression` approver over `vars.*` — |
| 11 | + * no record-field detour. Trigger: retitling an announcement (an otherwise |
| 12 | + * approval-free object, so this demo never collides with the expense/invoice/ |
| 13 | + * project approval flows — the service dedupes pending requests per record). |
| 14 | + */ |
| 15 | +export const DynamicApprovalFlow = defineFlow({ |
| 16 | + name: 'showcase_dynamic_approval', |
| 17 | + label: 'Announcement Dynamic Approval', |
| 18 | + description: 'Lead reviewer picks the co-signers in their decision; the co-sign step resolves them at entry.', |
| 19 | + type: 'autolaunched', |
| 20 | + status: 'active', |
| 21 | + nodes: [ |
| 22 | + { |
| 23 | + id: 'start', |
| 24 | + type: 'start', |
| 25 | + label: 'On Announcement Retitled', |
| 26 | + config: { |
| 27 | + objectName: 'showcase_announcement', |
| 28 | + triggerType: 'record-after-update', |
| 29 | + condition: 'title != previous.title', |
| 30 | + }, |
| 31 | + }, |
| 32 | + { |
| 33 | + id: 'lead_review', |
| 34 | + type: 'approval', |
| 35 | + label: 'Lead Review', |
| 36 | + config: { |
| 37 | + // The seeded admin holds the org-membership `owner` tier, so the demo |
| 38 | + // routes stage 1 to them without hard-coding a user id. |
| 39 | + approvers: [{ type: 'org_membership_level', value: 'owner' }], |
| 40 | + behavior: 'first_response', |
| 41 | + lockRecord: true, |
| 42 | + // The lead hands the co-signers to the flow with their decision. |
| 43 | + decisionOutputs: ['next_reviewers'], |
| 44 | + }, |
| 45 | + }, |
| 46 | + { |
| 47 | + id: 'co_sign', |
| 48 | + type: 'approval', |
| 49 | + label: 'Co-sign', |
| 50 | + config: { |
| 51 | + // Resolved at node entry from the lead's decision outputs (#3447 P2). |
| 52 | + approvers: [{ type: 'expression', value: 'vars.lead_review.next_reviewers' }], |
| 53 | + behavior: 'unanimous', |
| 54 | + lockRecord: true, |
| 55 | + onEmptyApprovers: 'fail', |
| 56 | + }, |
| 57 | + }, |
| 58 | + { id: 'approved', type: 'end', label: 'Approved' }, |
| 59 | + { id: 'rejected', type: 'end', label: 'Rejected' }, |
| 60 | + ], |
| 61 | + edges: [ |
| 62 | + { id: 'e1', source: 'start', target: 'lead_review' }, |
| 63 | + { id: 'e2', source: 'lead_review', target: 'co_sign', label: 'approve' }, |
| 64 | + { id: 'e3', source: 'lead_review', target: 'rejected', label: 'reject' }, |
| 65 | + { id: 'e4', source: 'co_sign', target: 'approved', label: 'approve' }, |
| 66 | + { id: 'e5', source: 'co_sign', target: 'rejected', label: 'reject' }, |
| 67 | + ], |
| 68 | +}); |
0 commit comments