> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Workflow Import/Export & Portability — Integration

> Feature ID: FW-52 Status: 📋 Specification Spec Reference: FW-52-workflow-import-export-portability.md Last Updated: 2026-03-22

**Feature ID:** FW-52\
**Status:** 📋 Specification\
**Spec Reference:** [FW-52-workflow-import-export-portability.md](../../../specs/fw/specs/FW-52-workflow-import-export-portability.md)\
**Last Updated:** 2026-03-22

***

## Overview

FW-52 adds **portable JSON/YAML packages** for workflow definitions with optional bundled **forms** (FW-01) and **decision tables** (FW-45). Export strips tenant UUIDs; import performs validation, dry-run analysis, conflict resolution, and **transactional** apply via a **SECURITY DEFINER** RPC. **Automation rules are not bundled in Phase 1.**

***

## Integration Points (from Spec)

| Dependency    | Type          | Purpose                                                                |
| ------------- | ------------- | ---------------------------------------------------------------------- |
| FW-06         | FW            | `fw_workflow_definitions` JSONB graph                                  |
| FW-07         | FW            | Version metadata for filenames / compatibility notes                   |
| FW-01 / PF-08 | Platform / FW | Form definitions in bundle                                             |
| FW-45         | FW            | Decision tables in bundle                                              |
| PF-04         | Platform      | `logAuditEvent` on successful import apply (`workflow_import_applied`) |

***

## API / Edge Functions

| Slug                 | Method | Purpose                                                 |
| -------------------- | ------ | ------------------------------------------------------- |
| `fw-workflow-export` | POST   | Build export package; `bundle?: boolean`                |
| `fw-workflow-import` | POST   | `mode: 'dry_run' \| 'apply'` + payload + resolution map |

**Shared requirements:** `getCorsHeaders`, `verifyOrgAccess`, `createLogger`; `verify_jwt: true`.

**AuthZ:** `fw.workflows.export` (export), `fw.workflows.import` (import/dry-run/apply).

***

## Platform Integration Layer

| Layer                    | Usage                                                |
| ------------------------ | ---------------------------------------------------- |
| `@/platform/permissions` | `useHasPermission('fw.workflows.export')` / `import` |
| `@/platform/audit`       | `logAuditEvent` after successful apply (see §Audit)  |

***

## Security and Tenant Isolation

* No PHI in packages or logs (definitions only).
* All DB writes scoped to `organization_id`; RPC runs as **SECURITY DEFINER** with explicit `p_organization_id` checks.
* RLS on `fw_import_logs` via `fw_has_org_access` + `pf_has_permission`.

***

## UI Routes (canonical)

| Path                           | Permission            | Purpose                                            |
| ------------------------------ | --------------------- | -------------------------------------------------- |
| `/fw/workflows/import`         | `fw.workflows.import` | Import wizard (upload → dry-run → resolve → apply) |
| `/fw/workflows/import/history` | `fw.workflows.view`   | Import history (`fw_import_logs`)                  |

Register in `src/routes/fw.tsx`; labels in `src/platform/navigation/route-labels.ts`. Workflow **export** remains in-context on `/fw/automations/:id/workflow` (and other existing workflow surfaces).

***

## Audit (PF-04)

On successful apply (client after RPC returns, or edge after RPC succeeds): `logAuditEvent` with `action: 'workflow_import_applied'`, `resource: 'fw_import_logs'`, `module: 'fw'`, and count-only `metadata` (see spec FR-8.1). No cross-core event required for MVP.

***

## Event Contracts

* **None required** for MVP (audit via `pf_audit_logs` through `logAuditEvent`).

***

## Related Docs

* [FW-52 Spec](../../../specs/fw/specs/FW-52-workflow-import-export-portability.md)
* [FW-45 Integration](./decision-tables-integration.md)
* [Edge functions rule](../../../.cursor/rules/edge-functions.md)
