{
  "openapi": "3.1.0",
  "info": {
    "title": "DocFlow API",
    "version": "1.0.0-poc",
    "description": "DocFlow is an upload-and-sign service with end-to-end encrypted e-signature. The API is ciphertext-only: bots hold the AES-256-GCM key, the server can never read documents. Documents are purged 7 days after delivery; the minimal audit log (who signed, when, SHA-256) is kept 12 months. Hosted on Cloudflare (global network — not EU-pinned hosting, no EU-only storage claim); GDPR-aligned practices: data minimisation, no document storage, minimal 12-month audit log, processors under data processing terms. Feature requests are proposals reviewed and approved personally by the owner — never auto-implemented.",
    "contact": {
      "name": "DocFlow",
      "url": "https://getdocflow.eu"
    },
    "license": {
      "name": "POC — beta, provided as-is"
    }
  },
  "servers": [
    {
      "url": "https://getdocflow.eu/api/v1",
      "description": "DocFlow POC"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key from Settings → API: df_live_... for live processes, df_test_... for the test environment (a key only sees its own environment)."
      }
    },
    "schemas": {
      "Process": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "proc_9f2c41ab77e0d"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "sent",
              "in_progress",
              "completed",
              "delivered",
              "cancelled",
              "declined",
              "expired",
              "purged"
            ]
          },
          "signing_mode": {
            "type": "string",
            "enum": [
              "sequential",
              "parallel"
            ]
          },
          "environment": {
            "type": "string",
            "enum": [
              "live",
              "test"
            ]
          },
          "expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "language": {
            "type": "string",
            "enum": [
              "en",
              "pt",
              "es"
            ]
          },
          "document_sha256": {
            "type": [
              "string",
              "null"
            ]
          },
          "content_fingerprint": {
            "type": [
              "string",
              "null"
            ],
            "description": "SHA-256 of the signed pages, printed inside the delivered PDF's verification page"
          },
          "signers": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "email": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "description": "Signer email, when registered by email"
                },
                "phone": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "description": "Signer phone (international format), when registered by phone"
                },
                "contact_type": {
                  "type": "string",
                  "enum": [
                    "email",
                    "phone"
                  ]
                },
                "contact": {
                  "type": "string",
                  "description": "The contact used for this signer (email or phone)"
                },
                "role": {
                  "type": "string",
                  "enum": [
                    "signer",
                    "approver",
                    "copy"
                  ]
                },
                "order": {
                  "type": "integer"
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "waiting",
                    "sent",
                    "opened",
                    "signed",
                    "approved",
                    "declined"
                  ]
                },
                "signed_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "field_values_cipher_text": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "description": "Ciphertext of this signer's fillable-field values (AES-GCM, your key); null until they sign"
                }
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "delivered_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "purge_after": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/processes": {
      "post": {
        "summary": "Create a document and start a signing process",
        "description": "Send AES-GCM ciphertext only — encrypt in your client with a key you keep. Sequential mode (default): participants act in array order, one at a time. Parallel mode: everyone can act in any order.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title",
                  "source_type",
                  "cipher_text",
                  "cipher_iv",
                  "signers"
                ],
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "source_type": {
                    "type": "string",
                    "enum": [
                      "upload"
                    ]
                  },
                  "file_name": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "cipher_text": {
                    "type": "string",
                    "description": "Base64 AES-256-GCM ciphertext of the document payload JSON"
                  },
                  "cipher_iv": {
                    "type": "string",
                    "description": "Base64 GCM IV"
                  },
                  "signing_mode": {
                    "type": "string",
                    "enum": [
                      "sequential",
                      "parallel"
                    ],
                    "description": "Default sequential"
                  },
                  "expires_at": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time",
                    "description": "Deadline; links stop working after it"
                  },
                  "language": {
                    "type": "string",
                    "enum": [
                      "en",
                      "pt",
                      "es"
                    ],
                    "description": "Signing-page language"
                  },
                  "message": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "General note shown to every participant"
                  },
                  "signers": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 25,
                    "description": "You choose how many participants (1–25 in the POC). Each takes a name plus exactly one contact: an email or a phone in international format. At least one must have role 'signer'.",
                    "items": {
                      "type": "object",
                      "required": [
                        "name"
                      ],
                      "properties": {
                        "name": {
                          "type": "string"
                        },
                        "email": {
                          "type": "string",
                          "format": "email"
                        },
                        "phone": {
                          "type": "string",
                          "description": "International format, e.g. +12145550123"
                        },
                        "role": {
                          "type": "string",
                          "enum": [
                            "signer",
                            "approver",
                            "copy"
                          ],
                          "description": "signer (default) signs; approver approves without signing; copy only receives the final document"
                        },
                        "access_mode": {
                          "type": "string",
                          "enum": [
                            "none",
                            "code",
                            "otp"
                          ],
                          "description": "code requires access_code (stored only as SHA-256); otp is a one-time 6-digit code, email participants only"
                        },
                        "access_code": {
                          "type": "string",
                          "description": "Required when access_mode is 'code'"
                        },
                        "private_message": {
                          "type": "string",
                          "description": "Note shown only to this participant"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Process created and sent; returns per-signer link tokens",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or revoked API key"
          },
          "403": {
            "description": "SUSPENDED — the account is suspended by the owner; all its keys are rejected until reactivation"
          },
          "429": {
            "description": "Rate limit (per key: 120/min human accounts, 60/min bot accounts) or QUOTA_EXCEEDED — a bot plan cap was hit (50 test processes/day, 10 live documents/month on bot_free, max signers per document, 10 MB document cap); the message names the cap and when it resets"
          }
        }
      },
      "get": {
        "summary": "List processes (metadata only)",
        "responses": {
          "200": {
            "description": "Array of Process objects without ciphertext"
          }
        }
      }
    },
    "/processes/{id}": {
      "get": {
        "summary": "Get process status and, before purge, the encrypted final PDF",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Process object; final_cipher_text present only while delivered and inside the 7-day window"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/processes/{id}/cancel": {
      "post": {
        "summary": "Cancel an in-flight process (wipes ciphertext immediately)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ ok: true }"
          },
          "409": {
            "description": "Delivered processes cannot be cancelled"
          }
        }
      }
    },
    "/processes/{id}/remind": {
      "post": {
        "summary": "Record a reminder for a participant who hasn't acted",
        "description": "The reminder lands in the audit trail and fires the process.reminder webhook; re-send the participant's link yourself (the POC has no mail/SMS gateway). An automatic reminder is also recorded after 3 days without opening/signing.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "position"
                ],
                "properties": {
                  "position": {
                    "type": "integer",
                    "description": "0-based participant position"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "{ ok: true, reminder_count }"
          },
          "409": {
            "description": "Participant already finished or process closed"
          }
        }
      }
    },
    "/processes/{id}/replace-signer": {
      "post": {
        "summary": "Replace a participant who hasn't acted yet (fresh link, same position)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "position",
                  "name"
                ],
                "properties": {
                  "position": {
                    "type": "integer",
                    "description": "0-based participant position"
                  },
                  "name": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "phone": {
                    "type": "string",
                    "description": "International format"
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "signer",
                      "approver",
                      "copy"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "{ replaced: true, signing_link: { token, ... } } — the old link stops working"
          },
          "409": {
            "description": "Participant already signed/approved or process closed"
          }
        }
      }
    },
    "/signup": {
      "post": {
        "summary": "Bot self-service signup — create a bot account + df_test_ key (no human, no web form)",
        "description": "A bot sends an email + agent name and immediately receives a bot account (flagged as a bot account, plan tier bot_free) and a df_test_ API key that works in the full test flow. Guards: max 3 signups per source IP per day; known disposable email domains rejected (422 DISPOSABLE_EMAIL); one account per email. The account is API-only (no usable web password). Live keys unlock only after identity verification (email code or DNS TXT proof). Caps are applied, not just measured: 50 test processes/day, documents up to 10 MB.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "agent_name"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "The bot account's email — verification for the live tier happens through this address or its domain."
                  },
                  "agent_name": {
                    "type": "string",
                    "description": "The agent/product name shown in the owner's panel."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Account created. Returns the df_test_ key (shown once), the plan caps, and the DNS TXT record for domain verification",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "email": {
                      "type": "string"
                    },
                    "agent_name": {
                      "type": "string"
                    },
                    "api_key": {
                      "type": "string",
                      "description": "df_test_... — shown once, stored only as a hash"
                    },
                    "key_prefix": {
                      "type": "string"
                    },
                    "plan": {
                      "type": "object",
                      "properties": {
                        "tier": {
                          "type": "string",
                          "example": "bot_free"
                        },
                        "test_per_day": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "example": 50
                        },
                        "live_per_month": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "example": 10
                        },
                        "max_signers": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "example": 5
                        },
                        "max_doc_bytes": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "example": 10485760
                        },
                        "key_rate_per_min": {
                          "type": "integer",
                          "example": 60
                        }
                      }
                    },
                    "dns_verification": {
                      "type": "object",
                      "properties": {
                        "host": {
                          "type": "string",
                          "example": "_docflow-verify.example.com"
                        },
                        "record_type": {
                          "type": "string",
                          "example": "TXT"
                        },
                        "value": {
                          "type": "string",
                          "example": "docflow-verify=dfverify_..."
                        }
                      }
                    },
                    "next_steps": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Validation — including DISPOSABLE_EMAIL for known disposable domains, or an email that already has an account"
          },
          "429": {
            "description": "RATE_LIMITED — more than 3 signups from this source IP today"
          }
        }
      }
    },
    "/keys": {
      "post": {
        "summary": "Create another API key for your own account (bot door: how a verified bot gets its df_live_ key)",
        "description": "Authenticated with any existing key of the account. environment 'test' is always allowed; environment 'live' requires a VERIFIED bot account (email code or DNS proof) — before verification it fails with 422 VERIFICATION_REQUIRED. Human accounts are unrestricted.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "label",
                  "environment"
                ],
                "properties": {
                  "label": {
                    "type": "string"
                  },
                  "environment": {
                    "type": "string",
                    "enum": [
                      "live",
                      "test"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "{ key (shown once), prefix, environment }"
          },
          "401": {
            "description": "Invalid or revoked API key"
          },
          "403": {
            "description": "SUSPENDED — the account is suspended; all its keys are rejected"
          },
          "422": {
            "description": "VERIFICATION_REQUIRED — bot account not verified yet"
          }
        }
      }
    },
    "/bot/verify-email/request": {
      "post": {
        "summary": "Start email verification for your bot account (6-digit code)",
        "description": "Generates a 6-digit verification code for the key's bot account (only its SHA-256 is stored; 30-minute validity). POC: with no mail gateway connected, the code is returned in the response as poc_code — the same pattern as signer OTP codes; in production it is emailed to the account address and never returned.",
        "responses": {
          "200": {
            "description": "{ ok: true, already_verified, poc_code }"
          },
          "401": {
            "description": "Invalid or revoked API key"
          },
          "403": {
            "description": "SUSPENDED — the account is suspended"
          }
        }
      }
    },
    "/bot/verify-email/confirm": {
      "post": {
        "summary": "Confirm the email verification code — unlocks live keys",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "code"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "description": "The 6-digit code"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "{ ok: true, verified: true, method: 'email' }"
          },
          "401": {
            "description": "Invalid or revoked API key"
          },
          "422": {
            "description": "Code missing, expired or not matching"
          }
        }
      }
    },
    "/bot/verify-dns": {
      "get": {
        "summary": "Read the DNS TXT record your bot account must publish (domain proof)",
        "responses": {
          "200": {
            "description": "{ host: '_docflow-verify.<domain>', record_type: 'TXT', value: 'docflow-verify=<token>', verified }"
          },
          "401": {
            "description": "Invalid or revoked API key"
          }
        }
      }
    },
    "/bot/verify-dns/check": {
      "post": {
        "summary": "Check the DNS TXT proof — on a match the account is verified (method 'dns')",
        "responses": {
          "200": {
            "description": "{ ok: true, verified, records_seen }"
          },
          "401": {
            "description": "Invalid or revoked API key"
          },
          "403": {
            "description": "SUSPENDED — the account is suspended"
          }
        }
      }
    },
    "/feature-requests": {
      "post": {
        "summary": "Tell DocFlow what capability you are missing",
        "description": "For bots and humans. Auth optional (API key raises the rate limit). Requests are PROPOSALS: the owner personally reviews and approves every feature; submission does not guarantee implementation. Never include document content.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "trying_to_do",
                  "missing_capability",
                  "use_case"
                ],
                "properties": {
                  "trying_to_do": {
                    "type": "string"
                  },
                  "missing_capability": {
                    "type": "string"
                  },
                  "use_case": {
                    "type": "string"
                  },
                  "requester_label": {
                    "type": "string",
                    "description": "Your agent/product name"
                  },
                  "contact": {
                    "type": "string",
                    "description": "Optional contact email"
                  },
                  "channel": {
                    "type": "string",
                    "enum": [
                      "api"
                    ],
                    "description": "Bots calling this endpoint send 'api' so the owner's inbox can tell agent demand from human form submissions"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Request recorded in the owner's inbox"
          },
          "429": {
            "description": "Rate limit: 30/min with key, 5/min anonymous"
          }
        }
      }
    }
  }
}