# OpenSeal public API, version 1 (docs/40). The contract: the server's route table
# (server/casual-sign-server/src/routes.rs) and this document are kept equal by the
# contract tests (server/casual-sign-server/tests/contract.rs), operation by operation,
# with each operation's `x-permission` (the catalogue action it needs, or `public`, `signing-in`, or
# `""` for any authenticated caller; SEC-A05, ORG-07) and, for an action, its `x-level`
# (`workspace`: held through the caller's permission profile; `organization`: through
# the caller's organization role; docs/23 §2.2).
openapi: 3.1.0
info:
  title: OpenSeal API
  version: 1.0.0-alpha
  license:
    name: Apache-2.0
    identifier: Apache-2.0
  description: |
    Envelope-centric REST API (docs/40). Errors are RFC 9457 problem details with a
    stable `code` (docs/20) and a `request_id`. Every POST accepts `Idempotency-Key`;
    replays within 24 hours return the first response. Envelopes carry an `ETag`
    (`"v<version>"`); edits of drafts and corrections need `If-Match`. Lists page with
    `cursor` and `limit`. Times are RFC 3339 UTC; ids are UUIDv7. Objects of another
    account answer exactly as missing ones: `404 CS-API-0002`.
    The `/s/{token}` endpoints are the recipient ceremony, not public API (docs/40 §6).
servers:
  - url: /
security:
  - bearer: []
  - session: []
components:
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      description: A personal API key (`osk_…`) or an access token from `/api/v1/oauth/token` (ES256 JWT, one hour).
    session:
      type: apiKey
      in: cookie
      name: __Host-os_session
      description: Staff session from `/api/v1/auth/login` (named `os_session` only on a plain-HTTP development server); changing requests also send `X-CSRF-Token`. Every request body is `application/json` (else `415 CS-API-0007`).
  parameters:
    ifMatch:
      name: If-Match
      in: header
      required: true
      description: The envelope's `ETag` as read (`"v<version>"`); a stale one is `412 CS-WF-0002`, none is `428 CS-API-0008`.
      schema: {type: string}
    idempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: Up to 255 printable ASCII characters; a replay within 24 hours returns the first response.
      schema: {type: string, maxLength: 255}
    cursor:
      name: cursor
      in: query
      required: false
      schema: {type: string}
    limit:
      name: limit
      in: query
      required: false
      schema: {type: integer, minimum: 1, maximum: 200, default: 50}
    status:
      name: status
      in: query
      required: false
      schema: {$ref: '#/components/schemas/EnvelopeStatus'}
    search:
      name: q
      in: query
      required: false
      description: Text the subject, or a recipient's name or email, contains (ignoring case); at most 200 characters, no control characters.
      schema: {type: string, maxLength: 200}
    version:
      name: version
      in: query
      required: false
      description: "`current` (WEB-06): the sealed version once sealed, else a preview of the values completed so far with a not-signed banner on every page, made on request and never stored; the `X-OpenSeal-Document` header says `sealed` or `preview`."
      schema: {type: string, enum: [original, normalized, sealed, current], default: normalized}
    recipientId:
      name: recipient_id
      in: query
      required: false
      schema: {type: string}
    documentId:
      name: document_id
      in: query
      required: false
      schema: {type: string}
  responses:
    Problem:
      description: RFC 9457 problem details
      content:
        application/problem+json:
          schema: {$ref: '#/components/schemas/Problem'}
  schemas:
    Problem:
      type: object
      required: [type, title, status, code]
      properties:
        type: {type: string}
        title: {type: string}
        status: {type: integer}
        code: {type: string, pattern: '^CS-[A-Z]+-[0-9]{4}$'}
        detail: {type: string}
        request_id: {type: string}
        errors:
          type: array
          items:
            type: object
            properties:
              pointer: {type: string}
              code: {type: string}
        meter:
          type: string
          description: The plan meter that refused (`CS-PLAN-0002` to `CS-PLAN-0004`; docs/23 §7.3).
        limit: {type: integer, format: int64, minimum: 0}
        used: {type: integer, format: int64, minimum: 0}
        period_end:
          type: string
          format: date-time
          description: When the refusing quota's period ends; absent for gauges and standing quotas.
    Object:
      type: object
      additionalProperties: true
    EnvelopeStatus:
      type: string
      enum: [draft, sent, delivered, completing, completed, declined, voided, expired]
    RecipientType:
      type: string
      enum: [signer, in_person_signer, approver, viewer, cc, editor, intermediary, agent, witness, seal, notary]
    AuthMethod:
      type: string
      enum: [email_link, access_code, sms_otp, voice_otp, kba, id_verification, sso, account_login, host_asserted, email_otp]
    DeviceLocation:
      description: The browser's Geolocation fix, or a decline (row GEO-01).
      oneOf:
        - type: object
          required: [latitude, longitude, accuracy_m]
          properties:
            latitude: {type: number, minimum: -90, maximum: 90}
            longitude: {type: number, minimum: -180, maximum: 180}
            accuracy_m: {type: number, minimum: 0}
        - type: object
          required: [declined]
          properties:
            declined: {type: boolean}
    SigningOptions:
      type: object
      additionalProperties: false
      properties:
        allow_reassign: {type: boolean, default: true}
        allow_decline: {type: boolean, default: true}
        allow_finish_later: {type: boolean, default: true}
        capture_location:
          type: boolean
          default: false
          description: >-
            Record where each recipient was on every recipient action (row GEO-01, docs/32 §2):
            the device's location when the signer agrees, else an approximation from the
            request's IP address with the reason. Absent when off.
        stamp_envelope_id:
          type: boolean
          default: false
          description: >-
            Stamp "Envelope ID: <id>" in the top margin of every page (FG-009, ADR-045): the
            signing page shows it and the sealed document carries it. Absent when off. On
            `POST /envelopes`, left out it takes the account's `stamp_envelope_id` setting.
            Changeable only while a draft (a correction that changes it is `409 CS-WF-0001`).
        allow_sign_on_paper:
          type: boolean
          default: false
          description: >-
            A signer may sign on paper instead (FG-013, ADR-043): print the documents, sign by
            hand and upload the scan (`POST /s/{token}/paper`). Absent when off.
    LocationRequest:
      type: object
      additionalProperties: false
      properties:
        location: {$ref: '#/components/schemas/DeviceLocation'}
    LoginRequest:
      type: object
      required: [email, password]
      additionalProperties: false
      properties:
        email: {type: string}
        password: {type: string}
        account_id: {type: string}
    LoginResponse:
      type: object
      properties:
        account_id: {type: string}
        user_id: {type: string}
        csrf_token: {type: string}
        expires_at: {type: string, format: date-time}
    SessionInfo:
      type: object
      properties:
        account_id: {type: string}
        user_id: {type: string}
        credential: {type: string, enum: [session, api_key, access_token]}
        client_id: {type: [string, 'null']}
        scopes: {type: array, items: {type: string}}
        admin: {type: boolean}
        actions:
          type: array
          description: The workspace actions held (ORG-07, docs/23 §2.2), narrowed by a key's scopes
          items: {$ref: '#/components/schemas/ActionName'}
        second_factor: {type: string, enum: [none, passed, verify, enrol]}
        factors:
          type: [object, 'null']
          description: >-
            A staff session's own second factors (CON-13, ASVS-32), so the sign-in step
            and step-up offer the right ones; null for API keys and tokens and for users
            who sign in through an identity provider
          properties:
            totp: {type: boolean}
            passkeys: {type: integer}
            recovery_codes_left: {type: integer}
            reset_by_admin:
              type: boolean
              description: An administrator reset the factors; a new one must be enrolled
            passkeys_available:
              type: boolean
              description: False when the server's public URL cannot be a WebAuthn RP id
        sandbox: {type: boolean, description: 'A sandbox workspace (ADR-041, `VS-08D`): fixed at creation; its envelopes are sealed with the sandbox key and marked as not for agreements, nothing it does is metered, its API keys start `osk_test_`'}
        reauthenticated_until:
          type: [string, 'null']
          format: date-time
          description: >-
            Until when a staff session's sensitive actions are served without proving the
            password again (ASVS-07); null when they need it now, and for API keys and
            tokens, which are never asked
    PasskeyAssertion:
      type: object
      description: >-
        A WebAuthn assertion (`navigator.credentials.get`), each part base64url without
        padding (CON-13)
      additionalProperties: false
      required: [credential_id, client_data_json, authenticator_data, signature]
      properties:
        credential_id: {type: string, description: "`rawId`"}
        client_data_json: {type: string}
        authenticator_data: {type: string}
        signature: {type: string}
        user_handle: {type: string}
    Passkey:
      type: object
      description: One of the person's passkeys (CON-13)
      properties:
        id: {type: string}
        name: {type: string}
        created_at: {type: string, format: date-time}
        last_used_at: {type: [string, 'null'], format: date-time}
        backup_eligible: {type: boolean, description: A synced passkey}
    OwnSession:
      type: object
      description: One of the caller's own sessions (ASVS-06)
      properties:
        id: {type: string}
        workspace:
          type: object
          properties:
            id: {type: string}
            name: {type: string}
        method: {type: string, enum: [password, oidc, webauthn]}
        client: {type: [string, 'null'], description: 'Browser and system, from a closed list ("Firefox on macOS")'}
        created_at: {type: string, format: date-time}
        last_seen_at: {type: string, format: date-time}
        idle_expires_at: {type: [string, 'null'], format: date-time}
        expires_at: {type: string, format: date-time}
        current: {type: boolean}
    MyWorkspaces:
      type: object
      properties:
        current: {type: string}
        organizations:
          type: array
          items:
            type: object
            properties:
              id: {type: string}
              name: {type: string}
              workspaces:
                type: array
                items:
                  type: object
                  properties:
                    id: {type: string}
                    name: {type: string}
                    status: {type: string, enum: [active, archived]}
                    current: {type: boolean}
    SwitchRequest:
      type: object
      required: [account_id]
      additionalProperties: false
      properties:
        account_id: {type: string}
    TokenRequest:
      type: object
      required: [grant_type]
      description: >-
        Also accepted as application/x-www-form-urlencoded. `client_credentials`,
        `authorization_code` and `refresh_token` authenticate the OAuth app by HTTP Basic
        or `client_id` and `client_secret` in the body; the JWT bearer grant
        (`urn:ietf:params:oauth:grant-type:jwt-bearer`, RFC 7523) authenticates by the
        `assertion` alone, signed (ES256 or RS256) with the integration's registered key:
        `iss` its id, `sub` the member, `aud` this server's URL or this endpoint's,
        `exp` in the future and at most an hour after `iat`, `scope` optional.
      properties:
        grant_type: {type: string, enum: [client_credentials, authorization_code, refresh_token, 'urn:ietf:params:oauth:grant-type:jwt-bearer']}
        client_id: {type: string}
        client_secret: {type: string}
        scope: {type: string}
        code: {type: string, description: authorization_code}
        redirect_uri: {type: string, description: 'authorization_code: the URI the code was issued to'}
        code_verifier: {type: string, minLength: 43, maxLength: 128, description: 'authorization_code: the PKCE verifier'}
        refresh_token: {type: string, description: 'refresh_token: rotated on every use; one spent twice revokes its family'}
        assertion: {type: string, description: 'The JWT bearer grant''s signed assertion'}
    TokenResponse:
      type: object
      properties:
        access_token: {type: string}
        token_type: {type: string, const: Bearer}
        expires_in: {type: integer}
        scope: {type: string}
        refresh_token: {type: string, description: 'authorization_code and refresh_token only (`osr_`), 30 days unused'}
    AuthorizeRequest:
      type: object
      required: [response_type, client_id, redirect_uri, scope, code_challenge, code_challenge_method]
      additionalProperties: false
      properties:
        response_type: {type: string, const: code}
        client_id: {type: string}
        redirect_uri: {type: string, description: "One of the client's registered redirect URIs, exactly"}
        scope: {type: string, description: Space-separated; each within the client's scopes and the member's own}
        state: {type: string, maxLength: 512}
        code_challenge: {type: string, minLength: 43, maxLength: 128}
        code_challenge_method: {type: string, const: S256}
        decision: {type: string, enum: [allow, deny], description: '`POST` only'}
    Consent:
      type: object
      properties:
        id: {type: string}
        client:
          type: object
          properties:
            id: {type: string}
            name: {type: string}
        scopes: {type: array, items: {type: string}}
        granted_at: {type: string, format: date-time}
    Jwks:
      type: object
      properties:
        keys: {type: array, items: {type: object}}
    Account:
      type: object
      properties:
        id: {type: string}
        name: {type: string}
        settings: {type: object}
        data_region: {type: [string, 'null']}
        created_at: {type: string, format: date-time}
        sandbox: {type: boolean, description: 'A sandbox workspace (ADR-041, `VS-08D`): fixed at creation; its envelopes are sealed with the sandbox key and marked as not for agreements, nothing it does is metered, its API keys start `osk_test_`'}
        organization_policy:
          type: object
          description: >-
            ORG-08 (docs/23 §3): the workspace settings its organization's policy governs,
            under `settings` by setting path (`mfa_policy`, `first_reminder_days`,
            `workflow_policy.date_format`, `branding`), each `{key, value, locked,
            from_organization}`: the organization key, the effective value, locked ("Set
            by your organization"), and whether the organization's value is the one in force.
    AccountPatch:
      type: object
      required: [settings]
      additionalProperties: false
      properties:
        settings: {type: object, description: 'Merged; `null` removes a key. `workflow_policy` must be a valid policy. `stamp_envelope_id` (FG-009) is a boolean: whether a new envelope whose request does not say stamps its id on every page. `mfa_policy` (ASVS-01) is `administrators` (the default, also when unset; ASVS-31), `everyone` or `optional`: who must sign in with a second factor; requiring one is `409 CS-API-0009` while the server has no `OPENSEAL_MFA_KEY`. A setting the organization''s policy governs (ORG-08) that changes to a locked or looser value is `422 CS-ORG-0002`, naming the setting and the key.'}
    User:
      type: object
      properties:
        id: {type: string}
        email: {type: string}
        name: {type: string}
        login_kind: {type: string}
        permission_profile_id: {type: string}
        disabled: {type: boolean, description: Disabled in this account}
        invitation:
          type: [string, 'null']
          enum: [pending, sent, expired, accepted, revoked, null]
          description: The latest invitation's state (single-user reads and invites only; WEB-06)
    UserList:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/User'}}
    AdminEvent:
      type: object
      required: [seq, at, action, hash, prev, event]
      properties:
        seq: {type: integer, minimum: 0}
        at: {type: string, format: date-time}
        action: {type: string, description: "`workspace.settings_changed`, `member.added`, `member.profile_changed`, `member.disabled`, `member.enabled`, `member.removed`, `member.renamed`, `member.password_set`, `profile.created`, ..."}
        hash: {type: string, description: "SHA-256 of the canonical bytes, hex"}
        prev: {type: [string, 'null'], description: "The previous event's hash, hex; null for the first"}
        event: {type: object, description: "The canonical event: v, account, seq, prev, at (ms), actor, action, target, changes (key, old, new; secrets as \"rotated\"), request_id, ip"}
    AdminEventList:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/AdminEvent'}}
        next_cursor: {type: [integer, 'null']}
    Organization:
      type: object
      properties:
        id: {type: string}
        name: {type: string}
        status: {type: string, enum: [active, suspended, closed]}
        role: {type: string, enum: [owner, admin, delegated], description: "The caller's role (GET only)"}
        created_at: {type: string, format: date-time}
        policy: {$ref: '#/components/schemas/OrganizationPolicy'}
    OrganizationPolicy:
      type: object
      description: >-
        ORG-08 (docs/23 §3): `{key: {value, locked}}` for the keys of docs/23 §3
        (`login.mfa_required`, `session.max_age`, `recipient.allowed_auth_methods`,
        `sending.min_seal_profile`, `locale.date_format`, `reminders.default`, ...).
        `locked` defaults to true for `login.sso_required` and `login.allowed_methods`,
        false otherwise. Security and evidence keys are tighten-only in a workspace.
      additionalProperties:
        type: object
        required: [value]
        additionalProperties: false
        properties:
          value: {description: 'Typed per key; validated by casual-sign-policy::org'}
          locked: {type: boolean}
    OrganizationPatch:
      type: object
      minProperties: 1
      additionalProperties: false
      properties:
        name: {type: string, minLength: 1, maxLength: 255}
        policy: {$ref: '#/components/schemas/OrganizationPolicy'}
    OrgWorkspace:
      type: object
      properties:
        id: {type: string}
        name: {type: string}
        status: {type: string, enum: [active, archived]}
        sandbox: {type: boolean, description: 'A sandbox workspace (ADR-041, `VS-08D`): fixed at creation; its envelopes are sealed with the sandbox key and marked as not for agreements, nothing it does is metered, its API keys start `osk_test_`'}
    OrgWorkspaceList:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/OrgWorkspace'}}
    OrgWorkspaceCreate:
      type: object
      required: [name]
      additionalProperties: false
      properties:
        name: {type: string, minLength: 1, maxLength: 255}
        sandbox: {type: boolean, default: false, description: 'Make a sandbox workspace, for good (ADR-041)'}
    OrgWorkspaceJoin:
      type: object
      required: [profile]
      additionalProperties: false
      properties:
        profile: {type: string, description: '`admin`, `sender`, `viewer`, or a permission profile id of that workspace'}
    OrgWorkspaceMembership:
      type: object
      properties:
        workspace_id: {type: string}
        user_id: {type: string}
        permission_profile_id: {type: string}
    OrgAdmin:
      type: object
      properties:
        user_id: {type: string}
        role: {type: string, enum: [owner, admin, delegated]}
        permission_set_id: {type: [string, 'null']}
        workspace_scope: {type: [array, 'null'], items: {type: string}}
        created_at: {type: string, format: date-time}
    OrgAdminList:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/OrgAdmin'}}
    OrgAdminCreate:
      type: object
      required: [user_id, role]
      additionalProperties: false
      properties:
        user_id: {type: string, description: An enabled member of a workspace of this organization}
        role: {type: string, enum: [owner, admin], description: Delegated admins need a permission set (ORG-07)}
    OrgAdminPatch:
      type: object
      required: [role]
      additionalProperties: false
      properties:
        role: {type: string, enum: [owner, admin]}
    UserCreate:
      type: object
      required: [email, name, profile]
      additionalProperties: false
      properties:
        email: {type: string}
        name: {type: string, maxLength: 255}
        profile: {type: string, description: '`admin`, `sender`, `viewer`, or a permission profile id'}
        password: {type: string, minLength: 12, maxLength: 256, description: "Not on the bundled list of breached passwords, case ignored (422 `common_password` at /password, ASVS-02); setting it emails the user a notice (ASVS-04)"}
        invite: {type: boolean, default: false, description: "Email a one-time link to set a password, valid 7 days (WEB-06); not with `password`"}
    UserPatch:
      type: object
      additionalProperties: false
      properties:
        name: {type: string, maxLength: 255}
        password: {type: string, minLength: 12, maxLength: 256, description: "Not on the bundled list of breached passwords, case ignored (422 `common_password` at /password, ASVS-02); setting it emails the user a notice (ASVS-04)"}
        profile: {type: string, description: "`admin`, `sender`, `viewer`, or a permission profile id; not your own (WEB-06)"}
        disabled: {type: boolean, description: "Disable (ending their sessions and open invitations) or enable the member in this account only; not yourself (WEB-06)"}
    AcceptInvite:
      type: object
      required: [token, password]
      additionalProperties: false
      properties:
        token: {type: string, maxLength: 128, description: The token from the invitation link}
        password: {type: string, minLength: 12, maxLength: 256, description: "Not on the bundled list of breached passwords, case ignored (422 `common_password` at /password, ASVS-02); setting it emails the user a notice (ASVS-04)"}
    ApiClient:
      type: object
      properties:
        id: {type: string}
        kind: {type: string, enum: [api_key, oauth_app, jwt_integration]}
        name: {type: string}
        owner_user_id: {type: [string, 'null']}
        key_prefix: {type: [string, 'null']}
        scopes: {type: array, items: {type: string}}
        expires_at: {type: [string, 'null'], format: date-time}
        revoked: {type: boolean}
        redirect_uris: {type: array, items: {type: string}}
        has_public_key: {type: boolean, description: A JWT integration's registered key; the key itself is never answered}
    ApiClientList:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/ApiClient'}}
    ApiClientCreate:
      type: object
      required: [name, kind, scopes]
      additionalProperties: false
      properties:
        name: {type: string, maxLength: 255}
        kind: {type: string, enum: [api_key, oauth_app, jwt_integration]}
        scopes: {type: array, items: {type: string}}
        owner_user_id: {type: string}
        expires_in_days: {type: integer, minimum: 1, maximum: 3650}
        redirect_uris:
          type: array
          maxItems: 10
          description: "OAuth apps and JWT integrations: where authorization codes go after consent; `https://`, or `http://` to localhost, 127.0.0.1 or [::1]; no fragment (`422` at `/redirect_uris/{i}`)"
          items: {type: string, maxLength: 2048}
        public_key: {type: string, maxLength: 8192, description: 'JWT integrations only, and required: a `-----BEGIN PUBLIC KEY-----` PEM, EC P-256 (ES256) or RSA (RS256); a private key is refused (`422` at `/public_key`)'}
    ApiClientCreated:
      allOf:
        - $ref: '#/components/schemas/ApiClient'
        - type: object
          properties:
            key: {type: string, description: 'API key, shown once'}
            client_id: {type: string}
            client_secret: {type: string, description: 'Shown once'}
    Recipient:
      type: object
      properties:
        id: {type: string}
        type: {$ref: '#/components/schemas/RecipientType'}
        routing_order: {type: integer}
        name: {type: string}
        email: {type: string}
        status: {type: string}
        delivery: {type: string, enum: [email, sms, none]}
        auth: {type: array, items: {$ref: '#/components/schemas/AuthMethod'}}
        embedded_client_user_id: {type: [string, 'null']}
        excluded_documents: {type: array, items: {type: string}, description: 'Documents hidden from this recipient (WF-02): never listed or served to them'}
        route_delay_hours: {type: integer, minimum: 0, maximum: 720, description: 'Delayed routing (WF-02): hours routing waits, once this recipient''s turn comes, before inviting them'}
        held_until: {type: [string, 'null'], format: date-time, description: 'Delayed routing (WF-02): their turn came and they are invited at this time; until then their link does not open (`409 CS-WF-0007`)'}
        signature:
          oneOf: [{$ref: '#/components/schemas/SignatureType'}, {type: 'null'}]
          description: 'How they sign (ADR-046): `null` for a simple signature'
        remote_signing:
          type: [object, 'null']
          description: 'Their open remote signing session (ADR-046 §3.4), if any'
          properties:
            session: {type: string}
            provider_id: {type: string}
            prepared: {type: boolean}
    SignatureType:
      type: object
      required: [type]
      additionalProperties: false
      description: >-
        How a signer signs (ADR-046 §3.1, `RSP-01`). Absent or `{"type": "simple"}`: an adopted mark under the
        platform seal. `{"type": "remote", "provider_id": "…"}`: the signer signs with their own certificate at a
        provider the account enabled (`GET /signing-providers`); only for a `signer`, and two remote signers never
        share a routing order (`422 CS-RSP-0007`). A provider not in the operator's catalogue, not offered to the
        account or not enabled is `422 CS-RSP-0001`; changing the type while the recipient's session is open is
        `409 CS-RSP-0007`.
      properties:
        type: {type: string, enum: [simple, remote]}
        provider_id: {type: string, pattern: '^[a-z0-9][a-z0-9-]{0,31}$'}
    SigningProvider:
      type: object
      properties:
        id: {type: string}
        name: {type: string}
        kind: {type: string, enum: [csc]}
        enabled: {type: boolean}
    SigningProviderList:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/SigningProvider'}}
    SigningProviderSettings:
      type: object
      properties:
        id: {type: string}
        name: {type: string}
        kind: {type: string, enum: [csc]}
        enabled: {type: boolean}
        required_qualifiers: {type: array, items: {type: string}, description: 'signatureQualifier values one of which a credential must state, as the provider states them'}
        refuse_name_mismatch: {type: boolean, description: 'A certificate name that differs from the recipient name refuses the signature (default: recorded)'}
        session_minutes: {type: integer, minimum: 5, maximum: 60}
        own_client_secret: {type: boolean, description: 'The account set its own OAuth client secret (never returned)'}
    SigningProviderIn:
      type: object
      required: [enabled]
      additionalProperties: false
      properties:
        enabled: {type: boolean}
        required_qualifiers: {type: array, maxItems: 8, items: {type: string, pattern: '^[a-z0-9_-]{1,64}$'}}
        refuse_name_mismatch: {type: boolean}
        session_minutes: {type: integer, minimum: 5, maximum: 60}
        client_secret:
          type: [string, 'null']
          writeOnly: true
          maxLength: 2048
          description: 'The account''s own OAuth client secret for this provider: stored sealed with AES-256-GCM, never returned; `null` removes it'
    RecipientList:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/Recipient'}}
    RecipientIn:
      type: object
      required: [type, name]
      additionalProperties: false
      properties:
        ref: {type: string, description: 'Name for fields in the same request'}
        type: {$ref: '#/components/schemas/RecipientType'}
        name: {type: string, maxLength: 255}
        email: {type: string}
        phone: {type: string}
        routing_order: {type: integer, minimum: 1, maximum: 999, default: 1}
        delivery: {type: string, enum: [email, sms, none]}
        auth: {type: array, items: {$ref: '#/components/schemas/AuthMethod'}}
        access_code: {type: string, description: 'With `auth: [access_code]`; stored as Argon2id only'}
        embedded_client_user_id: {type: string}
        time_zone_offset_minutes: {type: integer}
        date_format: {type: string}
        excluded_documents:
          type: array
          items: {oneOf: [{type: string}, {type: integer, minimum: 0}]}
          description: "Documents hidden from this recipient (WF-02): document ids, or in a create the index of a document of the same request. A recipient sees at least one document (`422 CS-WF-0004`), never a field on a hidden one (`422 CS-WF-0021`)."
        route_delay_hours: {type: integer, minimum: 0, maximum: 65535, default: 0, description: "Delayed routing (WF-02): hours routing waits, once this recipient's turn comes, before inviting them. At most 720 at send (`422 CS-WF-0023`); not on a carbon copy (`422 CS-WF-0004`)."}
        signature: {$ref: '#/components/schemas/SignatureType'}
    RecipientCreate:
      oneOf:
        - $ref: '#/components/schemas/RecipientIn'
        - type: object
          required: [items]
          properties:
            items: {type: array, items: {$ref: '#/components/schemas/RecipientIn'}}
    RecipientPatch:
      type: object
      additionalProperties: false
      properties:
        name: {type: string}
        email: {type: string}
        routing_order: {type: integer}
        type:
          allOf: [{$ref: '#/components/schemas/RecipientType'}]
          description: "A new type (UX-12), on a draft only; a correction keeps the type and is refused `409`."
        auth: {type: array, items: {$ref: '#/components/schemas/AuthMethod'}}
        access_code:
          type: string
          maxLength: 255
          writeOnly: true
          description: "A new access code, stored only as Argon2id. Needed when `auth` gains `access_code`; refused when the resulting `auth` lacks it. Removing `access_code` from `auth` deletes the stored code. Draft or correcting envelopes only."
        excluded_documents: {type: array, items: {type: string}, description: 'Document ids hidden from this recipient (WF-02); `[]` shows every document'}
        route_delay_hours: {type: integer, minimum: 0, maximum: 65535, description: 'Delayed routing (WF-02): hours to wait once their turn comes; `0` invites at once'}
        signature: {$ref: '#/components/schemas/SignatureType'}
    Field:
      type: object
      description: The model's field (docs/22 §6); `placement` in displayed page points, origin top-left.
      additionalProperties: true
      properties:
        id: {type: string}
        document_id: {type: string}
        recipient_id: {type: string}
        type: {type: string}
        shared_with: {type: array, items: {type: string}, description: 'VS-04D: other recipients who may also fill this field; the last value is kept'}
        placement:
          type: object
          properties:
            page: {type: integer}
            x: {type: string}
            y: {type: string}
            width: {type: string}
            height: {type: string}
    FieldIn:
      type: object
      description: 'A field without ids: `recipient` (id or ref), `document` (id, or index in the same request), `type`, and `page`, `x`, `y`, `width`, `height` flat or as `placement`; or, in place of `page`, `x` and `y`, an `anchor` (VS-04E): a field is placed at each match of its text in the delivered document (CS-FLD-0010 when absent unless `ignore_if_absent`). `shared_with` (VS-04D): other recipients (ids or refs) who may also fill it.'
      additionalProperties: true
      properties:
        anchor:
          type: object
          required: [text]
          additionalProperties: false
          properties:
            text: {type: string}
            offset_x: {type: string, description: 'Decimal, in units; to the right'}
            offset_y: {type: string, description: 'Decimal, in units; downwards'}
            units: {type: string, enum: [points, inches, millimetres, centimetres, pixels]}
            ignore_if_absent: {type: boolean}
            case_sensitive: {type: boolean}
            whole_word: {type: boolean}
            matching: {type: string, enum: [first, all]}
        shared_with: {type: array, maxItems: 100, items: {type: string}}
    FieldList:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/Field'}}
    FieldCreate:
      oneOf:
        - $ref: '#/components/schemas/FieldIn'
        - type: object
          required: [items]
          properties:
            items: {type: array, items: {$ref: '#/components/schemas/FieldIn'}}
    Document:
      type: object
      properties:
        id: {type: string}
        name: {type: string}
        pages: {type: integer}
        bytes: {type: integer}
        upload_sha256: {type: string}
        delivered_sha256: {type: string}
        admission_findings: {type: integer}
        fixed: {type: boolean}
    DocumentList:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/Document'}}
    DocumentIn:
      type: object
      required: [name, content_base64]
      additionalProperties: false
      properties:
        name: {type: string, maxLength: 255}
        content_base64: {type: string, contentEncoding: base64, description: 'At most 50 MiB decoded (docs/21)'}
    DocumentUpload:
      description: 'JSON, or the PDF itself as `application/pdf` with `?name=`.'
      $ref: '#/components/schemas/DocumentIn'
    Envelope:
      type: object
      properties:
        id: {type: string}
        status: {$ref: '#/components/schemas/EnvelopeStatus'}
        version: {type: integer}
        sender_user_id: {type: string}
        subject: {type: string}
        message: {type: string}
        created_at: {type: string, format: date-time}
        sent_at: {type: [string, 'null'], format: date-time}
        send_at: {type: [string, 'null'], format: date-time, description: 'A draft scheduled to send itself at this time (WF-02)'}
        ended_at: {type: [string, 'null'], format: date-time}
        expires_at: {type: [string, 'null'], format: date-time}
        deleted_at: {type: [string, 'null'], format: date-time, description: 'When it was removed from the lists (WEB-08); null once restored (ADR-031)'}
        reminders: {type: object}
        signing_options: {$ref: '#/components/schemas/SigningOptions'}
        seal_profile: {type: string, enum: [pades-b-t, pades-b-lt, pades-b-lta]}
        documents: {type: array, items: {$ref: '#/components/schemas/Document'}}
        recipients: {type: array, items: {$ref: '#/components/schemas/Recipient'}}
        fields: {type: array, items: {$ref: '#/components/schemas/Field'}}
    EnvelopeSummary:
      type: object
      properties:
        id: {type: string}
        status: {$ref: '#/components/schemas/EnvelopeStatus'}
        subject: {type: string}
        sender_user_id: {type: string}
        created_at: {type: string, format: date-time}
        updated_at: {type: string, format: date-time, description: "Last change (WEB-08)"}
        sent_at: {type: [string, 'null'], format: date-time}
        completed_at: {type: [string, 'null'], format: date-time}
        expires_at: {type: [string, 'null'], format: date-time}
        folder_id: {type: [string, 'null'], description: "The caller's own folder it is filed in (UXW-02)"}
        deleted_at: {type: [string, 'null'], format: date-time, description: 'Set in the Deleted view (`deleted=true`): when it was removed from the lists'}
        my_recipient_id: {type: [string, 'null'], description: "With waiting_for=me only: the recipient the caller is (UXW-01)"}
    BulkSendCreate:
      type: object
      additionalProperties: false
      required: [template_id]
      properties:
        template_id: {type: string, description: "A template of the caller's account with a document and a role"}
        name: {type: string, maxLength: 255, description: "Defaults to the template's name"}
        csv: {type: string, description: "The list as CSV text; exactly one of csv and rows"}
        rows:
          type: array
          maxItems: 1000
          items: {type: object, additionalProperties: {type: string}, description: "Column to value"}
        validate_only: {type: boolean, default: false}
    BulkSendProblem:
      type: object
      properties:
        column: {type: [string, 'null'], description: "The column, or null for the whole row"}
        code: {type: string, description: "CS-BLK-0001 to 0003, 0006"}
    BulkSendRow:
      type: object
      properties:
        row: {type: integer, minimum: 0}
        status: {type: string, enum: [pending, sent, failed, cancelled]}
        envelope_id: {type: [string, 'null']}
        error_code: {type: [string, 'null'], description: "A row problem's code, or the code the server refused its envelope with"}
        recipients:
          type: array
          items:
            type: object
            properties:
              role: {type: string}
              name: {type: string}
              email: {type: string}
        problems: {type: array, items: {$ref: '#/components/schemas/BulkSendProblem'}}
    BulkSend:
      type: object
      properties:
        id: {type: string}
        name: {type: string}
        template_id: {type: string}
        sender_user_id: {type: string}
        status: {type: string, enum: [queued, sending, completed, cancelled]}
        row_count: {type: integer}
        counts:
          type: object
          properties:
            pending: {type: integer}
            sent: {type: integer}
            failed: {type: integer}
            cancelled: {type: integer}
        created_at: {type: string, format: date-time}
        finished_at: {type: [string, 'null'], format: date-time}
    BulkSendWithRows:
      allOf:
        - $ref: '#/components/schemas/BulkSend'
        - type: object
          properties:
            rows: {type: array, items: {$ref: '#/components/schemas/BulkSendRow'}}
    BulkSendCheck:
      type: object
      properties:
        columns: {type: array, items: {type: string}, description: "The template's columns, in order"}
        row_count: {type: integer}
        valid: {type: integer}
        rows: {type: array, items: {$ref: '#/components/schemas/BulkSendRow'}}
    Folder:
      type: object
      properties:
        id: {type: string}
        name: {type: string, maxLength: 100}
        kind: {type: string, enum: [envelopes, templates], description: "What it holds (TSH-03)"}
        count: {type: integer, description: "Envelopes (or, in a template folder, templates the owner may still use) the owner filed in it that are not deleted"}
    FolderName:
      type: object
      additionalProperties: false
      required: [name]
      properties:
        name: {type: string, minLength: 1, maxLength: 100, description: "Trimmed; unique among the caller's folders of its kind ignoring case (422 `exists` at /name)"}
        kind: {type: string, enum: [envelopes, templates], description: "On create only (422 at /kind on a rename): `envelopes` (default) or `templates` (TSH-03)"}
    FolderMove:
      type: object
      additionalProperties: false
      required: [envelope_ids]
      properties:
        envelope_ids: {type: array, minItems: 1, maxItems: 200, items: {type: string}}
    FolderTemplateMove:
      type: object
      additionalProperties: false
      required: [template_ids]
      properties:
        template_ids: {type: array, minItems: 1, maxItems: 200, items: {type: string}}
    EnvelopeFromTemplates:
      type: object
      additionalProperties: false
      required: [template_ids]
      description: >-
        One envelope from one template or several (composite templates, FG-097). The
        documents are each template's, in the order named; roles are matched by name
        ignoring case across the templates (one recipient per name, with the type and
        routing order of the first template naming it; the same name with another type is
        422 at /template_ids/{i}); every role is filled by exactly one person; people with
        no `role` follow every role, as a copy (default) or a signer.
      properties:
        template_ids: {type: array, minItems: 1, maxItems: 10, items: {type: string}, description: "Templates the caller may use (another account's, or one not shared with the caller, is 422 at /template_ids/{i}); each once"}
        recipients:
          type: array
          maxItems: 100
          items:
            type: object
            additionalProperties: false
            required: [name]
            properties:
              role: {type: string, description: "The role this person fills (422 at /recipients/{i}/role if no template has it or it is filled twice)"}
              name: {type: string}
              email: {type: string}
              type: {type: string, enum: [cc, signer], description: "Only for a person with no role"}
        subject: {type: string, description: "Default: the first template's email subject, else its name"}
        message: {type: string, description: "Default: the first template's message"}
        status: {type: string, enum: [draft, sent], description: "draft (default) or sent (needs envelopes.send)"}
    DetectedField:
      type: object
      properties:
        document_id: {type: string}
        type: {type: string, description: "signature, initials, date_signed, name, title, company or text; any field type for an AcroForm field"}
        page: {type: integer, minimum: 1}
        x: {type: string, description: Decimal points}
        y: {type: string}
        width: {type: string}
        height: {type: string}
        source: {type: string, enum: [underline, label, box, acroform]}
        cue: {type: string, description: "The text cue (at most 64 characters), or the form field's data label"}
        confidence: {type: integer, minimum: 0, maximum: 100}
    MlSettings:
      type: object
      description: >-
        A workspace's document-analysis switches (docs/33 §6, §7). A feature is in effect only
        when the model service is installed, the plan entitles it and an administrator turned
        it on; every level is off by default.
      properties:
        ocr: {type: boolean}
        template_matching: {type: boolean}
        extraction: {type: boolean}
        personal_data: {type: boolean}
        personal_data_model: {type: [string, 'null'], pattern: '^[A-Za-z0-9._-]{1,64}$'}
        ocr_scripts: {type: array, maxItems: 16, items: {type: string, enum: [latin, cyrillic, greek, cjk, arabic, devanagari]}}
        reread_scanner_text: {type: boolean}
        not_in_plan: {type: array, readOnly: true, items: {type: string, enum: [ocr, template_matching, extraction, personal_data]}}
        installed: {type: boolean, readOnly: true, description: false when this server has no model service}
    ErsdPublish:
      type: object
      additionalProperties: false
      required: [text]
      properties:
        text: {type: string, minLength: 1, maxLength: 100000, description: "The disclosure recipients read and consent to; at most 100,000 bytes of UTF-8, not blank, no NUL"}
        language: {type: string, pattern: '^[A-Za-z][A-Za-z0-9-]{1,34}$', default: en}
    ErsdVersion:
      type: object
      description: A published disclosure, without its text.
      properties:
        id: {type: string}
        version: {type: integer, minimum: 1}
        label: {type: string, description: "The version as the policy and consent name it"}
        language: {type: string}
        sha256: {type: string, description: "`sha256:<hex>` of the text's UTF-8"}
        published_at: {type: string, format: date-time}
    ErsdVersions:
      type: object
      properties:
        current:
          type: [object, 'null']
          properties:
            label: {type: string}
            sha256: {type: string}
            version: {type: [integer, 'null']}
            language: {type: [string, 'null']}
            published_at: {type: [string, 'null'], format: date-time}
            text: {type: [string, 'null']}
        items: {type: array, items: {$ref: '#/components/schemas/ErsdVersion'}}
    MlSettingsPatch:
      type: object
      additionalProperties: false
      properties:
        ocr: {type: boolean}
        template_matching: {type: boolean}
        extraction: {type: boolean}
        personal_data: {type: boolean}
        personal_data_model: {type: [string, 'null'], pattern: '^[A-Za-z0-9._-]{1,64}$'}
        ocr_scripts: {type: array, maxItems: 16, items: {type: string, enum: [latin, cyrillic, greek, cjk, arabic, devanagari]}}
        reread_scanner_text: {type: boolean}
    Analysis:
      type: object
      description: One analysis of one stored document (docs/33 §2). Advisory; never evidence.
      properties:
        id: {type: string}
        document_id: {type: string}
        status: {type: string, enum: [queued, running, done, failed, unavailable]}
        uses: {type: array, items: {type: string, enum: [ocr, template, entities, personal_data]}}
        ocr_pages: {type: array, description: 1-based pages read by OCR, items: {type: integer, minimum: 1}}
        truncated: {type: boolean}
        bundle_id: {type: [string, 'null']}
        code: {type: string, description: Why it failed (CS-ML-*)}
        created_at: {type: string, format: date-time}
        finished_at: {type: string, format: date-time}
    Suggestion:
      type: object
      description: >-
        What an analysis suggests; a person accepts or dismisses it (docs/33 §6). `value` is
        read from the stored document when listed and is document content.
      properties:
        id: {type: string}
        kind: {type: string, enum: [template, entity, personal_data]}
        document_id: {type: string}
        page: {type: [integer, 'null'], minimum: 1}
        rect: {type: [object, 'null']}
        label: {type: string}
        value: {type: [string, 'null']}
        normalized: {type: [string, 'null']}
        score: {type: number, minimum: 0, maximum: 1}
        model:
          type: object
          properties:
            id: {type: string}
            sha256: {type: string}
        state: {type: string, enum: [open, accepted, dismissed]}
        template_id: {type: string, description: The matched template (kind template)}
        pages_matched: {type: [integer, 'null']}
        pages_total: {type: [integer, 'null']}
        decided_by: {type: string}
        decided_at: {type: string, format: date-time}
    SuggestionPage:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/Suggestion'}}
        next_cursor: {type: [string, 'null']}
    DetectedFields:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/DetectedField'}}
        truncated: {type: boolean}
    Contact:
      type: object
      description: A past recipient (personal data); the name last used with this address.
      properties:
        name: {type: string}
        email: {type: string}
        last_used_at: {type: string, format: date-time}
    ContactList:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/Contact'}}
    EnvelopePage:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/EnvelopeSummary'}}
        next_cursor: {type: [string, 'null']}
    EnvelopeCreate:
      type: object
      additionalProperties: false
      properties:
        subject: {type: string, maxLength: 255}
        message: {type: string, maxLength: 10000}
        status: {type: string, enum: [draft, sent], default: draft}
        documents: {type: array, items: {$ref: '#/components/schemas/DocumentIn'}}
        recipients: {type: array, items: {$ref: '#/components/schemas/RecipientIn'}}
        fields: {type: array, items: {$ref: '#/components/schemas/FieldIn'}}
        reminders:
          type: object
          properties:
            first_after_days: {type: integer, maximum: 999}
            then_every_days: {type: integer, maximum: 999}
        expires_in_days: {type: integer}
        signing_options: {$ref: '#/components/schemas/SigningOptions'}
        seal_profile: {type: string, enum: [pades-b-t, pades-b-lt, pades-b-lta]}
        text_tags: {type: boolean, description: 'VS-04E: place a field at each {{type:recipient[:req][:label][:WxH]}} tag in the documents; the recipient is a request ref. A malformed tag refuses the request (CS-FLD-0011).'}
    EnvelopePatch:
      type: object
      additionalProperties: false
      properties:
        subject: {type: string}
        message: {type: string}
        reminders: {type: object}
        expires_in_days: {type: [integer, 'null']}
        signing_options: {$ref: '#/components/schemas/SigningOptions'}
        seal_profile: {type: string}
    EnvelopeStatusInfo:
      type: object
      properties:
        id: {type: string}
        status: {$ref: '#/components/schemas/EnvelopeStatus'}
        version: {type: integer}
        recipients: {type: array, items: {type: object}}
    CustomFields:
      type: object
      additionalProperties: false
      required: [items]
      properties:
        items:
          type: array
          maxItems: 100
          items:
            type: object
            additionalProperties: false
            required: [name, value]
            properties:
              name: {type: string, minLength: 1, maxLength: 100}
              value: {type: string, maxLength: 1000}
    TransferRequest:
      type: object
      required: [to_user]
      additionalProperties: false
      properties:
        to_user: {type: string, description: 'An enabled member of this workspace'}
        to_workspace: {type: string, description: 'Only this workspace; another is 422 CS-ORG-0009'}
    ScheduleRequest:
      type: object
      required: [send_at]
      additionalProperties: false
      properties:
        send_at: {type: string, format: date-time, description: 'After now, at most 365 days ahead, before the expiry'}
    VoidRequest:
      type: object
      required: [reason]
      additionalProperties: false
      properties:
        reason: {type: string, maxLength: 10000}
    CorrectRequest:
      type: object
      required: [changes]
      additionalProperties: false
      properties:
        changes: {type: array, items: {type: object, description: 'The engine change list (casual-sign-workflow `Change`), tagged by `op`'}}
    ResendRequest:
      type: object
      additionalProperties: false
      properties:
        recipient_ids: {type: array, items: {type: string}}
    AuditEvents:
      type: object
      properties:
        items:
          type: array
          items:
            type: object
            properties:
              seq: {type: integer}
              type: {type: string}
              at: {type: string, format: date-time}
              hash: {type: string}
              prev: {type: [string, 'null']}
              event: {type: object, description: 'The event as chained (RFC 8785); its `context` holds the client address and user agent'}
        chain_head: {type: [string, 'null']}
    AnchorProof:
      type: object
      description: >-
        An envelope's anchor proof (`openseal.anchor-proof` v1, docs/32 §5, FG-158),
        canonical JSON (RFC 8785): the chain head (`head`, the hash of event `seq`) is
        leaf `leaf_index` of the anchor's Merkle tree, by the audit `path`; the anchor's
        RFC 3161 token is over its `statement`. Check it offline with `openseal anchor
        verify` or the Verify page, against the TSA's root and, with the audit trail,
        against the chain.
      required: [format, v, envelope_id, seq, head, leaf_index, path, anchor]
      additionalProperties: false
      properties:
        format: {type: string, const: openseal.anchor-proof}
        v: {type: integer, const: 1}
        envelope_id: {type: string}
        seq: {type: integer, minimum: 0, description: The sequence number of the anchored event}
        head: {type: string, description: "The anchored event's hash, `sha256:` and 64 hex digits"}
        leaf_index: {type: integer, minimum: 0}
        path: {type: array, items: {type: string}, description: The audit path from the leaf up (RFC 9162 §2.1.3)}
        anchor:
          type: object
          required: [format, v, id, period, tree_size, root, statement, tsa_time, timestamp_token]
          additionalProperties: false
          properties:
            format: {type: string, const: openseal.anchor}
            v: {type: integer, const: 1}
            id: {type: string}
            period: {type: string, format: date, description: The UTC day whose changed heads the tree covers}
            tree_size: {type: integer, minimum: 1}
            root: {type: string}
            statement: {type: string, description: "SHA-256 of `openseal.anchor.v1`, 0x00, the size and the root: what the token is over"}
            tsa_time: {type: string, format: date-time, description: "The token's genTime as the server read it (informative; a verifier reads the token)"}
            timestamp_token: {type: string, description: The DER TimeStampToken in lower-case hex}
    SigningViewRequest:
      type: object
      required: [recipient_id]
      additionalProperties: false
      properties:
        recipient_id: {type: string}
        auth_asserted: {type: string, description: "The host's statement of how it authenticated the signer"}
        frame_origin: {type: string, description: "VS-09: the origin of the page that frames the view (`https://host[:port]`), one of the workspace's `embedding_origins`; the view page's `frame-ancestors` and the only origin its events are posted to. Not on the list: `422 CS-EMB-0001`"}
        return_url: {type: string, description: "VS-09: where the browser goes when the view ends, with `event` and `state` added to its query; its origin must be one of the workspace's `embedding_origins` (`422 CS-EMB-0001`)"}
        state: {type: string, maxLength: 1024, description: "VS-09: an opaque value given back with every event and on the return URL"}
    SigningView:
      type: object
      properties:
        url: {type: string, description: "Single use, valid for `expires_at` (five minutes)"}
        expires_at: {type: string, format: date-time}
    EditorViewRequest:
      type: object
      additionalProperties: false
      description: "VS-09: where an embedded prepare or correct view's host page is; every member optional, each checked as for the signing view"
      properties:
        frame_origin: {type: string}
        return_url: {type: string}
        state: {type: string, maxLength: 1024}
    EmbedTarget:
      type: object
      description: "VS-09: where an embedded view posts its events (`frame_origin`), returns to (`return_url`) and the host's `state`; each null when the view named none"
      properties:
        frame_origin: {type: [string, 'null']}
        return_url: {type: [string, 'null']}
        state: {type: [string, 'null']}
    EmbedSession:
      type: object
      description: "VS-09: the session an embedded prepare or correct page authenticates with (`Authorization: Bearer osv_…`), on its envelope only, with its editor's operations only (`403 CS-EMB-0002` otherwise), until `expires_at` (one hour)"
      properties:
        session: {type: string}
        envelope_id: {type: string}
        kind: {type: string, enum: [prepare, correct]}
        expires_at: {type: string, format: date-time}
        embed: {$ref: '#/components/schemas/EmbedTarget'}
    Template:
      type: object
      properties:
        id: {type: string}
        name: {type: string}
        version: {type: integer}
        email_subject: {type: [string, 'null']}
        email_message: {type: [string, 'null']}
        roles: {type: array, items: {type: object}}
        documents: {type: array, items: {type: object}, description: "Single-template reads only: id, name, ord, pages, page_geometry, sha256"}
        fields: {type: array, items: {$ref: '#/components/schemas/TemplateField'}, description: Single-template reads only}
        access: {type: string, enum: [owner, edit, use], description: "What the caller may do with it (UXW-06): owner (its owner or an administrator: also delete, restore and share), edit, or use"}
        favourite: {type: boolean, description: "Starred by the caller (UXW-06)"}
        shared: {type: boolean, description: "List reads only: shared with anyone (UXW-06)"}
        folder_id: {type: [string, 'null'], description: "List reads only: the caller's template folder it is filed in, or null (TSH-03)"}
    TemplateList:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/Template'}}
    TemplateCreate:
      type: object
      required: [name]
      additionalProperties: false
      properties:
        name: {type: string}
        email_subject: {type: string}
        email_message: {type: string}
        roles:
          type: array
          items:
            type: object
            required: [name, type]
            properties:
              name: {type: string}
              routing_order: {type: integer}
              type: {$ref: '#/components/schemas/RecipientType'}
    TemplateShares:
      type: object
      properties:
        items:
          type: array
          items:
            type: object
            properties:
              id: {type: string}
              can_edit: {type: boolean}
              user: {type: object, description: "A member: id, name, email"}
              group: {type: object, description: "A group: id, name"}
              account: {type: boolean, description: "The whole account"}
    TemplateSharesIn:
      type: object
      required: [items]
      additionalProperties: false
      properties:
        items:
          type: array
          maxItems: 500
          items:
            type: object
            additionalProperties: false
            description: "Exactly one of user_id, email, group_id or account: true"
            properties:
              user_id: {type: string}
              email: {type: string, minLength: 3, maxLength: 320}
              group_id: {type: string}
              account: {type: boolean, enum: [true]}
              can_edit: {type: boolean, default: false}
    GroupList:
      type: object
      properties:
        items:
          type: array
          items:
            type: object
            properties:
              id: {type: string}
              name: {type: string}
              members: {type: integer}
    GroupName:
      type: object
      additionalProperties: false
      required: [name]
      properties:
        name: {type: string, minLength: 1, maxLength: 255}
    Group:
      type: object
      properties:
        id: {type: string}
        name: {type: string}
        members: {type: integer}
        user_ids: {type: array, items: {type: string}}
    GroupMembers:
      type: object
      additionalProperties: false
      required: [user_ids]
      properties:
        user_ids: {type: array, items: {type: string}}
    PermissionName:
      type: string
      description: A scope of docs/40 §2 (every action it covers), `view_all_envelopes`, or a workspace action (ORG-07)
      enum: [envelopes:read, envelopes:write, envelopes:send, templates:read, templates:write, bulk:send, webhooks:manage, admin:users, admin:account, audit:read, view_all_envelopes, envelopes.read, envelopes.write, envelopes.send, templates.read, templates.write, bulk.send, audit.read, users.read, users.invite, users.update, users.disable, users.remove, groups.manage, profiles.manage, settings.sending, settings.signing, ersd.manage, settings.security, brands.manage, retention.manage, api_clients.manage, webhooks.manage, envelopes.read_all, envelopes.transfer, templates.share_workspace, reports.read, usage.read, admin_audit.read]
    ActionName:
      type: string
      description: A workspace action of the catalogue (docs/23 §2.2; server authz.rs)
      enum: [envelopes.read, envelopes.write, envelopes.send, templates.read, templates.write, bulk.send, audit.read, users.read, users.invite, users.update, users.disable, users.remove, groups.manage, profiles.manage, settings.sending, settings.signing, ersd.manage, settings.security, brands.manage, retention.manage, api_clients.manage, webhooks.manage, envelopes.read_all, envelopes.transfer, templates.share_workspace, reports.read, usage.read, admin_audit.read]
    PermissionProfile:
      type: object
      properties:
        id: {type: string}
        name: {type: string}
        kind: {type: string, enum: [admin, sender, viewer, custom]}
        builtin: {type: boolean}
        permissions:
          type: array
          description: What it grants; a built-in profile's are its kind's scopes, a custom profile's the names it stores
          items: {$ref: '#/components/schemas/PermissionName'}
        actions:
          type: array
          description: The workspace actions it holds (ORG-07)
          items: {$ref: '#/components/schemas/ActionName'}
        admin_scope_group_ids:
          type: [array, 'null']
          description: A delegated workspace admin's groups; null for the whole workspace (ORG-07)
          items: {type: string}
        members: {type: integer, description: How many members hold it}
    PermissionProfileList:
      type: object
      properties:
        items:
          type: array
          items: {$ref: '#/components/schemas/PermissionProfile'}
    PermissionProfileCreate:
      type: object
      additionalProperties: false
      required: [name, permissions]
      properties:
        name: {type: string, minLength: 1, maxLength: 255}
        permissions:
          type: array
          items: {$ref: '#/components/schemas/PermissionName'}
        admin_scope_group_ids:
          type: [array, 'null']
          description: >-
            Groups of this account its holders administer (a delegated workspace admin,
            ORG-07); absent or null for the whole workspace. Never with a sensitive action.
          minItems: 1
          items: {type: string}
    PermissionProfilePatch:
      type: object
      additionalProperties: false
      properties:
        name: {type: string, minLength: 1, maxLength: 255}
        permissions:
          type: array
          items: {$ref: '#/components/schemas/PermissionName'}
        admin_scope_group_ids:
          type: [array, 'null']
          description: Absent unchanged; null the whole workspace; a list those groups (ORG-07)
          minItems: 1
          items: {type: string}
    TemplatePatch:
      type: object
      additionalProperties: false
      properties:
        name: {type: string, maxLength: 255}
        email_subject: {type: [string, 'null'], maxLength: 255}
        email_message: {type: [string, 'null'], maxLength: 10000}
    TemplateRoleIn:
      type: object
      required: [name, type]
      additionalProperties: false
      properties:
        name: {type: string, maxLength: 255}
        type: {type: string}
        routing_order: {type: integer, minimum: 1, maximum: 999, default: 1}
    TemplateRolePatch:
      type: object
      additionalProperties: false
      properties:
        name: {type: string, maxLength: 255}
        type: {type: string}
        routing_order: {type: integer, minimum: 1, maximum: 999}
    TemplateField:
      type: object
      description: >-
        A field as on an envelope (docs/22 §6), bound to `role_id` instead of a recipient;
        input takes `role_id` (or `role`), `document_id`, and the flat `page`, `x`, `y`,
        `width`, `height` or `placement` (WEB-06).
      additionalProperties: true
    TemplateFieldList:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/TemplateField'}}
    Webhook:
      type: object
      properties:
        id: {type: string}
        envelope_id: {type: [string, 'null']}
        url: {type: string}
        event_types: {type: array, items: {type: string}}
        secret_refs: {type: array, items: {type: string}}
        active: {type: boolean}
    WebhookList:
      type: object
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/Webhook'}}
    WebhookCreate:
      type: object
      required: [url, event_types, secret_refs]
      additionalProperties: false
      properties:
        url: {type: string, description: 'https:// to a public address (SEC-W01)'}
        event_types: {type: array, items: {type: string}}
        secret_refs: {type: array, minItems: 1, maxItems: 4, items: {type: string}}
        envelope_id: {type: string}
    CeremonyView:
      type: object
      properties:
        envelope:
          type: object
          description: '`id`, `status`, `subject`, `message`, `signing_options`, `documents`, and `expires_at` (when it expires, or null; UXW-34)'
        recipient: {$ref: '#/components/schemas/Recipient'}
        fields: {type: array, items: {$ref: '#/components/schemas/Field'}}
        rules:
          type: [object, 'null']
          description: 'VS-04C: the server''s own evaluation of this recipient''s fields (casual_sign_fields::evaluate_envelope): hidden (field ids a condition hides), computed (formula field id to {ok} or {error}), values (field id to the value it will be sealed with where not the one stored, a linked field''s). Null until the recipient has authenticated.'
          properties:
            hidden: {type: array, items: {type: string}}
            computed: {type: object}
            values: {type: object}
        capture_location: {type: boolean, description: 'Whether the page asks the device for its location (GEO-01)'}
        adoption_id: {type: string, description: 'After adopt: the capture a signature or initials field value names ({"signature": "<adoption_id>"})'}
        consent_required:
          type: [object, 'null']
          description: The account's disclosure the recipient must accept, or null when it requires none.
          properties:
            version: {type: string, description: 'The label `POST /s/{token}/consent` takes'}
            sha256: {type: string, description: '`sha256:<hex>` over the text''s UTF-8, the hash consent records'}
            url: {type: string, description: '`/s/{token}/disclosure`, present only when the account has published that text (UXW-34)'}
        sandbox: {type: boolean, description: 'The envelope is a sandbox workspace''s (ADR-041): the page says it is a test, not an agreement'}
        auth_required: {type: [array, 'null'], items: {$ref: '#/components/schemas/AuthMethod'}}
        embed: {$ref: '#/components/schemas/EmbedTarget'}
        binding:
          type: string
          description: 'VS-09: an embedded signing view only, in the answer that bound the link: the secret the page sends back in `X-OpenSeal-Binding` on every later call, since a browser sends a cross-site frame no first-party cookie. Kept in memory only'

        later_recipients:
          type: array
          description: >-
            Only for an agent, intermediary or editor who has authenticated (VS-02): the
            recipients later in the routing order not yet reached, which
            `POST /s/{token}/recipients` may name. Absent for every other recipient.
          items:
            type: object
            properties:
              id: {type: string}
              type: {type: string}
              routing_order: {type: integer}
              name: {type: string}
              email: {type: string}
              phone: {type: [string, 'null']}
              auth: {type: array, items: {$ref: '#/components/schemas/AuthMethod'}, description: 'VS-06A: the methods asked of them; an access code itself is never shown'}
        strikes:
          type: array
          description: 'FG-080 (ADR-044): every strike-through on a document this recipient sees, whoever drew it, as the seal will draw it; once authenticated'
          items:
            type: object
            properties:
              id: {type: string}
              document_id: {type: string}
              placement: {type: object}
              recipient_id: {type: string}
        editable_fields:
          type: array
          description: >-
            Only for an editor who has authenticated (VS-06A): the fields of recipients
            later in the routing order not yet reached, which `PATCH` and `DELETE
            /s/{token}/editor/fields/{field}` may change (the editor's own are in `fields`).
            Absent for every other recipient.
          items: {type: object}
        sso_providers:
          type: array
          description: 'While `sso` is still to pass (RAUTH-01): the identity providers the signer may sign in with; empty when the server has none'
          items:
            type: object
            properties:
              id: {type: string}
              name: {type: string}
        sso_authorization_url: {type: string, description: 'After `POST /s/{token}/sso`: where the page sends the browser to sign in (RAUTH-01)'}
        remote_provider_name: {type: string, description: 'RSP-01: a remote signer''s provider, by its catalogue name, for "Sign with <provider>"'}
        remote_authorization_url: {type: string, description: 'RSP-01: after `POST /s/{token}/remote-signing` or `…/authorize`: where the page sends the browser, top level, to the provider (scope `service`, then `credential`)'}
        remote_signing: {$ref: '#/components/schemas/RemoteSigningState'}
        sender:
          type: object
          description: Who sent the envelope, so the recipient can judge whether the request is genuine (UXW-34).
          properties:
            name: {type: [string, 'null'], description: "The sending user's name as the account holds it now; null once they are no longer a member"}
            email: {type: [string, 'null'], description: "The sending user's email address; null once they are no longer a member"}
            organisation: {type: string, description: "The account's brand name (`settings.branding.name`), else the account's name"}
    NameRecipientsRequest:
      type: object
      required: [recipients]
      additionalProperties: false
      properties:
        recipients:
          type: array
          minItems: 1
          maxItems: 100
          items:
            type: object
            required: [id]
            additionalProperties: false
            properties:
              id: {type: string, description: 'A recipient in `later_recipients`'}
              name: {type: string, minLength: 1, maxLength: 255}
              email: {type: string, minLength: 3, maxLength: 320}
              phone: {type: string, description: 'VS-06A: an intermediary or editor sets the number (E.164) a code by SMS or voice call is sent to'}
              auth:
                type: array
                items: {$ref: '#/components/schemas/AuthMethod'}
                description: 'VS-06A: an intermediary or editor replaces the authentication the recipient must pass (an agent is refused, 403). An emailed code or sso needs an email, sms_otp or voice_otp a phone (422 at /recipients/{i}/auth)'
              access_code: {type: string, maxLength: 255, description: 'VS-06A: a new access code, stored only as Argon2id and never answered; required when auth gains access_code and none was set, refused without it (422 at /recipients/{i}/access_code); dropping access_code from auth deletes the stored code'}
        location: {$ref: '#/components/schemas/DeviceLocation'}
    CeremonyDisclosure:
      type: object
      required: [version, sha256, text]
      properties:
        version: {type: string, description: 'The label `POST /s/{token}/consent` takes'}
        sha256: {type: string, description: '`sha256:<hex>` over the text''s UTF-8, re-checked as it is read'}
        text: {type: string}
    ConsentRequest:
      type: object
      required: [ersd_version]
      properties:
        ersd_version: {type: string}
        location: {$ref: '#/components/schemas/DeviceLocation'}
    AuthenticateRequest:
      type: object
      required: [method, code]
      properties:
        method: {$ref: '#/components/schemas/AuthMethod'}
        code: {type: string}
    OtpSendRequest:
      description: Which one-time code to send (SEC-A02); `email_otp` when absent.
      type: object
      additionalProperties: false
      properties:
        method: {type: string, enum: [email_otp, sms_otp, voice_otp]}
        location: {$ref: '#/components/schemas/DeviceLocation'}
    OtpVerifyRequest:
      description: A one-time code sent by email, SMS or voice call (SEC-A02), six digits.
      type: object
      additionalProperties: false
      required: [code]
      properties:
        code: {type: string, pattern: '^[0-9]{6}$'}
        method: {type: string, enum: [email_otp, sms_otp, voice_otp]}
    SsoStartRequest:
      description: Which of the server's identity providers to sign in with (RAUTH-01).
      type: object
      additionalProperties: false
      required: [provider]
      properties:
        provider: {type: string, pattern: '^[a-z0-9-]{1,32}$'}
    RemoteSigningState:
      description: >-
        RSP-01: the recipient's latest remote signing session, or null. `status` is
        `authorizing_service`, `preparing`, `choosing`, `prepared`, `authorizing_credential`,
        `signing`, `completed` or `failed`; `failure` the reason a failed one ended
        (`cancelled`, `expired`, `provider_unavailable`, `provider_refused`,
        `no_eligible_credential`, `response_invalid`, `placeholder_overflow`, ...);
        `documents` the documents prepared for signing (their exact bytes at
        `GET /s/{token}/remote-signing/documents/{id}`).
      type: [object, 'null']
      properties:
        session: {type: string}
        status: {type: string}
        failure: {type: [string, 'null']}
        provider: {type: [string, 'null']}
        documents: {type: array, items: {type: string}}
        esign:
          description: >-
            RSP-02, answered by `POST …/remote-signing/authorize` for an India eSign
            session: where the hand-off page is and which document it hands off.
          type: object
          properties:
            handoff: {type: string}
            document: {type: integer}
            of: {type: integer}
    RemoteStartRequest:
      description: >-
        RSP-01. Values given with the start, as at finish; usually none (each was saved as
        filled). RSP-02: for an India eSign provider, `esign` is required: the consent
        version the page showed (the view's `remote_esign.consent_version`), `accepted`
        true (the signer ticked it; unticked by default), and the authentication chosen
        among `remote_esign.auth_modes`. `422` without it.
      type: object
      additionalProperties: false
      properties:
        values:
          type: array
          items:
            type: object
            additionalProperties: false
            required: [field, value]
            properties:
              field: {type: string}
              value: {type: object}
        location: {$ref: '#/components/schemas/DeviceLocation'}
        esign:
          type: object
          additionalProperties: false
          required: [consent, accepted]
          properties:
            consent: {type: string}
            accepted: {type: boolean}
            auth_mode: {type: string, enum: [otp, face, fingerprint, iris]}
    RemoteCallbackRequest:
      description: >-
        RSP-01: what the provider sent the browser back with (to the provider's redirect
        URI, `{OPENSEAL_PUBLIC_URL}/s/rsp`): `state` and either `code` or `error`.
      type: object
      additionalProperties: false
      required: [state]
      properties:
        state: {type: string, maxLength: 256}
        code: {type: string, maxLength: 900}
        error: {type: string, maxLength: 256}
    SsoVerifyRequest:
      description: What the identity provider sent the browser back with (RAUTH-01).
      type: object
      additionalProperties: false
      required: [state, code]
      properties:
        state: {type: string, maxLength: 256}
        code: {type: string, maxLength: 2048}
    ViewedRequest:
      type: object
      required: [pages_seen]
      properties:
        pages_seen: {type: array, items: {type: integer, minimum: 1}}
        location: {$ref: '#/components/schemas/DeviceLocation'}
    AdoptRequest:
      type: object
      required: [mark, method, image_base64]
      properties:
        mark: {type: string, enum: [signature, initials, stamp, drawing], description: 'A stamp or drawing capture fills only a field of its own kind (VS-04A)'}
        method: {type: string, enum: [draw, type, upload]}
        image_base64: {type: string, description: 'PNG or JPEG, at most 5 MiB'}
        location: {$ref: '#/components/schemas/DeviceLocation'}
    FieldValue:
      type: object
      description: 'Externally tagged: {"text": "…"}, {"checked": true}, {"choice": "…"}, {"signature": "<id>"}, {"attachment": "<id>"}'
    FillRequest:
      type: object
      required: [value]
      properties:
        value: {$ref: '#/components/schemas/FieldValue'}
    FinishRequest:
      type: object
      properties:
        values:
          type: array
          items:
            type: object
            required: [field, value]
            properties:
              field: {type: string}
              value: {$ref: '#/components/schemas/FieldValue'}
        location: {$ref: '#/components/schemas/DeviceLocation'}
    DeclineRequest:
      type: object
      properties:
        reason: {type: string}
        location: {$ref: '#/components/schemas/DeviceLocation'}
    ReassignRequest:
      type: object
      required: [name, email]
      additionalProperties: false
      properties:
        name: {type: string, maxLength: 255}
        email: {type: string, maxLength: 320}
        reason: {type: string, maxLength: 10000}
        location: {$ref: '#/components/schemas/DeviceLocation'}
    CeremonyHistory:
      type: object
      properties:
        events:
          type: array
          items:
            type: object
            properties:
              seq: {type: integer}
              type: {type: string, description: "The audit event type (docs/32 §3)"}
              at: {type: string, format: date-time}
              by: {type: string, enum: [you, sender, recipient, user, host, system]}

paths:
  /api/v1/auth/login:
    post:
      operationId: login
      summary: "Local password login: session cookie and CSRF token"
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/LoginRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/LoginResponse'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/accept-invite:
    post:
      operationId: acceptInvite
      summary: "Spend a user invitation's one-time link and set the password (WEB-06)"
      description: >-
        An unknown, expired, spent or revoked link, or a member disabled meanwhile, is
        `401 CS-AUTH-0002`, all alike. Setting the password ends the member's sessions
        in every account they belong to (SEC-ID-01). The member then logs in with
        `/auth/login`. Rate-limited as login.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/AcceptInvite'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  account_id: {type: string}
                  user_id: {type: string}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/logout:
    post:
      operationId: logout
      summary: "End the current staff session"
      description: >-
        Also for a session that still owes its second factor (`x-permission: signing-in`).
      x-permission: signing-in
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      responses:
        '204': {description: Done}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/password-reset:
    post:
      operationId: requestPasswordReset
      summary: "Ask for a password-reset email (UXW-38)"
      description: >-
        No session. `202 {}` for any well-formed address, whether or not it has an
        account (no enumeration). For a local, enabled user the worker emails a one-time
        link that expires in an hour; only the SHA-256 of its token is stored. At most
        one email a minute per user; rate-limited as login, per address and per client.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [email]
              properties:
                email: {type: string}
      responses:
        '202':
          description: Accepted
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/password-reset/confirm:
    post:
      operationId: confirmPasswordReset
      summary: "Spend a password-reset link and set a new password (UXW-38)"
      description: >-
        An unknown, expired, spent or revoked link is `401 CS-AUTH-0002`, all alike.
        Setting the password ends the user's sessions in every account and revokes their
        other open resets. Rate-limited as login.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/AcceptInvite'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  account_id: {type: string}
                  user_id: {type: string}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/providers:
    get:
      operationId: authProviders
      summary: "SSO identity providers offered on sign-in (UXW-39)"
      description: "No session. `{items: [{id, name, url}]}`; empty until SSO is built (FG-173)."
      security: []
      x-permission: public
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/workspaces:
    get:
      operationId: listMyWorkspaces
      summary: "The caller's workspaces, grouped by organization (ORG-04)"
      description: >-
        Every workspace the signed-in person holds an enabled membership in, by
        organization, with the session's own workspace marked `current`. Metadata only.
        A staff session only: an API key or access token belongs to one workspace and
        gets `422 CS-API-0001`.
      x-permission: ""
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/MyWorkspaces'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/reauthenticate:
    post:
      operationId: reauthenticate
      summary: "Prove the password again before a sensitive action (ASVS-07)"
      description: >-
        `password`, and when the user has a second factor also `code` (single use),
        `recovery_code` (spent), or `passkey`, an assertion answering a `reauthenticate`
        challenge from `POST /auth/mfa/passkeys/options` (CON-13). Opens a five-minute window in which the session's
        sensitive actions are served; outside it they answer `403 CS-AUTH-0013` and the
        client asks for this and repeats the request. `401 CS-AUTH-0007` for a wrong
        password, `401 CS-AUTH-0012` for a wrong or reused code, `422 CS-API-0001`
        (`/code`) when a factor is needed and none was sent. Rate-limited per user as
        login is. A staff session only.
      x-permission: ""
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [password]
              properties:
                password: {type: string}
                code: {type: string}
                recovery_code: {type: string}
                passkey: {$ref: '#/components/schemas/PasskeyAssertion'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  reauthenticated_until: {type: string, format: date-time}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/sessions:
    get:
      operationId: listMySessions
      summary: "The caller's own live sessions, in every workspace of theirs (ASVS-06)"
      description: >-
        Each workspace's idle and absolute limits applied; the calling session is marked
        `current`. Another user's sessions are never listed. A staff session only.
      x-permission: ""
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items: {$ref: '#/components/schemas/OwnSession'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/sessions/end-others:
    post:
      operationId: endMyOtherSessions
      summary: "End every other session of the caller (ASVS-06)"
      description: >-
        In every workspace. Needs a re-authentication within five minutes
        (`403 CS-AUTH-0013`).
      x-permission: ""
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ended: {type: integer}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/sessions/{id}:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    delete:
      operationId: endMySession
      summary: "End one of the caller's other sessions (ASVS-06)"
      description: >-
        `404` for a session that is not the caller's, has ended, or does not exist; the
        calling session itself is `422` (use `POST /auth/logout`). Needs a
        re-authentication within five minutes (`403 CS-AUTH-0013`).
      x-permission: ""
      responses:
        '204': {description: Ended}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/switch:
    post:
      operationId: switchWorkspace
      summary: "Move the session to another workspace of the caller (ORG-04)"
      description: >-
        Ends the current session and issues a new one in `account_id`, carrying the same
        sign-in (method, time and expiry), so a switch never extends a session. The
        caller must hold an enabled membership there: otherwise, or for an id that does
        not exist, `403 CS-ORG-0001`. A staff session with its CSRF token only. The
        workspace always comes from the session; no header or parameter chooses
        another (SEC-O05).
      x-permission: ""
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/SwitchRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/LoginResponse'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/session:
    get:
      operationId: getSession
      summary: "Who the credential is"
      description: >-
        Also for a session that still owes its second factor: `second_factor` says what
        it owes (`verify` or `enrol`), or `passed` or `none` (ASVS-01).
      x-permission: signing-in
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/SessionInfo'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/mfa/verify:
    post:
      operationId: verifySecondFactor
      summary: "Pass the session's second factor (ASVS-01)"
      description: >-
        With `code`, six digits from the user's authenticator (RFC 6238, 30-second steps,
        one step of drift either way); or with `recovery_code`, one of the ten codes shown
        at enrolment, which is spent (case, spaces and dashes do not matter). Each TOTP
        code is accepted once: a code for a step no later than the last accepted one is
        refused. `401 CS-AUTH-0012` for a wrong, replayed or spent code. Rate-limited per
        user as login is. Until a session that owes a factor passes it, every other
        `/api/v1` call but `GET /auth/session` and `POST /auth/logout` answers
        `403 CS-AUTH-0011`. With `passkey`, an assertion answering the session's
        `verify` challenge (CON-13): refused (`401 CS-AUTH-0012`) for another purpose's,
        an expired or a spent challenge, another origin or RP id, a credential not the
        user's, a bad signature, or a signature counter that did not move past the
        stored one (a cloned authenticator; logged with `reason: counter`).
      x-permission: signing-in
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              properties:
                code: {type: string}
                recovery_code: {type: string}
                passkey: {$ref: '#/components/schemas/PasskeyAssertion'}
      responses:
        '200':
          description: Passed
          content:
            application/json:
              schema:
                type: object
                properties:
                  second_factor: {type: string, enum: [passed]}
                  recovery_codes_left: {type: integer}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/mfa/totp/enrol:
    post:
      operationId: enrolTotp
      summary: "Start TOTP enrolment for the session's own user (ASVS-01)"
      description: >-
        A new 160-bit seed, shown once as an `otpauth://` URI (for a QR code; labelled
        with the user id, never the email) and as base32 `secret`; stored only sealed
        (AES-256-GCM under `OPENSEAL_MFA_KEY`). Calling again before confirming draws a
        new seed. `409 CS-API-0009` once a factor is confirmed, or when the server has no
        sealing key. Staff sessions only (`422` for an API key or token).
      x-permission: signing-in
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      responses:
        '200':
          description: "The seed, shown once (`Cache-Control: no-store`)"
          content:
            application/json:
              schema:
                type: object
                properties:
                  otpauth_uri: {type: string}
                  secret: {type: string}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/mfa/totp/confirm:
    post:
      operationId: confirmTotp
      summary: "Confirm TOTP enrolment with a first code (ASVS-01)"
      description: >-
        A code from the new authenticator confirms the enrolment; the session has then
        passed its second factor, and the answer shows ten one-time recovery codes once
        (112 random bits each; only their SHA-256 is stored). `401 CS-AUTH-0012` for a
        wrong code; `409 CS-API-0009` before `enrol` or after a confirmation.
      x-permission: signing-in
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [code]
              properties:
                code: {type: string}
      responses:
        '200':
          description: "Confirmed (`Cache-Control: no-store`)"
          content:
            application/json:
              schema:
                type: object
                properties:
                  second_factor: {type: string, enum: [passed]}
                  recovery_codes: {type: array, items: {type: string}, minItems: 10, maxItems: 10}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/mfa/passkeys/options:
    post:
      operationId: passkeyOptions
      summary: "Options and a challenge for one passkey ceremony (CON-13)"
      description: >-
        `purpose` is `register` (`navigator.credentials.create`), `verify` (the sign-in
        step) or `reauthenticate` (step-up, `navigator.credentials.get`). The 32-byte
        challenge is kept on the session for five minutes, one at a time, and spent by
        the call that answers it, whatever the outcome. The RP id is the public URL's
        host (or `OPENSEAL_WEBAUTHN_RP_ID`); attestation `none`; ES256, EdDSA and RS256.
        `register` beside an existing factor needs a session that passed it and
        re-authenticated within five minutes (`403 CS-AUTH-0011`, `403 CS-AUTH-0013`);
        at most 10 passkeys (`409 CS-API-0009`). `verify` and `reauthenticate` without a
        passkey: `409 CS-API-0009`. `409 CS-API-0014` when the public URL's host cannot be
        an RP id. A staff session only.
      x-permission: signing-in
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [purpose]
              properties:
                purpose: {type: string, enum: [register, verify, reauthenticate]}
      responses:
        '200':
          description: "The options (`Cache-Control: no-store`), binary members base64url"
          content:
            application/json:
              schema:
                type: object
                properties:
                  purpose: {type: string}
                  public_key: {type: object}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/mfa/passkeys:
    post:
      operationId: registerPasskey
      summary: "Register a passkey as a second factor (CON-13, ASVS 2.3.2)"
      description: >-
        The browser's registration answering a `register` challenge: `id` (`rawId`),
        `client_data_json`, `authenticator_data` (`getAuthenticatorData()`), `public_key`
        (`getPublicKey()`, SubjectPublicKeyInfo DER), `public_key_algorithm` and
        `transports`, base64url. Checked per WebAuthn Level 2 §7.1: type, challenge,
        origin, RP id hash, user presence, the attested credential id. As the first
        factor it is the enrolment a policy asks for: the session has passed, and the
        answer shows ten recovery codes once. Beside another factor, only from a session
        that passed it and re-authenticated within five minutes. `401 CS-AUTH-0012` for a
        refused registration; `409 CS-API-0009` for a credential already registered or
        an eleventh passkey. The user is told by email.
      x-permission: signing-in
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [credential]
              properties:
                name: {type: string, maxLength: 64}
                credential:
                  type: object
                  additionalProperties: false
                  required: [id, client_data_json, authenticator_data, public_key, public_key_algorithm]
                  properties:
                    id: {type: string}
                    client_data_json: {type: string}
                    authenticator_data: {type: string}
                    public_key: {type: string}
                    public_key_algorithm: {type: integer, enum: [-7, -8, -257]}
                    transports: {type: array, items: {type: string}}
      responses:
        '201':
          description: "Registered (`Cache-Control: no-store`)"
          content:
            application/json:
              schema:
                type: object
                properties:
                  passkey: {$ref: '#/components/schemas/Passkey'}
                  second_factor: {type: string, enum: [passed]}
                  recovery_codes: {type: array, items: {type: string}, minItems: 10, maxItems: 10}
        default: {$ref: '#/components/responses/Problem'}
    get:
      operationId: listPasskeys
      summary: "The caller's passkeys (CON-13)"
      description: In every workspace of theirs. A staff session only.
      x-permission: ""
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items: {$ref: '#/components/schemas/Passkey'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/mfa/passkeys/{id}:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    patch:
      operationId: renamePasskey
      summary: "Rename one of the caller's passkeys (CON-13)"
      description: >-
        1 to 64 characters. Needs a re-authentication within five minutes
        (`403 CS-AUTH-0013`). `404` for a passkey that is not the caller's.
      x-permission: ""
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [name]
              properties:
                name: {type: string, maxLength: 64}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Passkey'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: removePasskey
      summary: "Remove one of the caller's passkeys (CON-13)"
      description: >-
        Needs a re-authentication within five minutes (`403 CS-AUTH-0013`); `404` for a
        passkey that is not the caller's. With it the last factor, the recovery codes go
        too and the workspace's policy applies at once. The user is told by email.
      x-permission: ""
      responses:
        '204': {description: Removed}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/mfa/totp:
    delete:
      operationId: removeTotp
      summary: "Remove the caller's TOTP authenticator, to replace it (ASVS-32)"
      description: >-
        Needs a re-authentication within five minutes, which proved the current factor
        (`403 CS-AUTH-0013`). `409 CS-API-0009` when there is none. With it the last
        factor, the recovery codes go too and the workspace's policy applies at once.
        The user is told by email.
      x-permission: ""
      responses:
        '204': {description: Removed}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/auth/mfa/recovery-codes:
    post:
      operationId: replaceRecoveryCodes
      summary: "Ten new recovery codes, replacing the earlier ones (ASVS-32)"
      description: >-
        Needs a re-authentication within five minutes (`403 CS-AUTH-0013`). `409
        CS-API-0009` without a second factor. Shown once; only their SHA-256 is stored.
        The user is told by email.
      x-permission: ""
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      responses:
        '200':
          description: "The codes (`Cache-Control: no-store`)"
          content:
            application/json:
              schema:
                type: object
                properties:
                  recovery_codes: {type: array, items: {type: string}, minItems: 10, maxItems: 10}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/oauth/token:
    post:
      operationId: token
      summary: "OAuth 2.1 token endpoint: client credentials, authorization code with PKCE, refresh token, JWT bearer grant (VS-08A, VS-08B)"
      description: >-
        RFC 6749 §5.2 errors, with the `CS-*` code as `error_description`:
        `invalid_client` (`CS-AUTH-0007`), `invalid_grant` (`CS-AUTH-0014`: a code or
        refresh token unknown, spent, expired or not this client's, a wrong PKCE verifier or
        redirect URI, an assertion with a bad signature, audience or lifetime;
        `CS-AUTH-0005`: the member has not consented to the JWT integration),
        `invalid_scope` (`CS-AUTH-0006`), `unsupported_grant_type`.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/TokenRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/TokenResponse'}
        default: {$ref: '#/components/responses/Problem'}
  /.well-known/oauth-authorization-server:
    get:
      operationId: oauthMetadata
      summary: "OAuth authorization server metadata (RFC 8414)"
      security: []
      x-permission: public
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {type: object}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/oauth/authorize:
    get:
      operationId: authorizeRedirect
      summary: "Authorization endpoint: hands the request to the web app's consent screen"
      description: >-
        `303` to `/app.html#/authorize?<the same query>`; the screen signs the member in
        if needed, reads the checked request and posts the answer. Nothing is checked or
        recorded here.
      security: []
      x-permission: public
      responses:
        '303': {description: To the consent screen}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: authorize
      summary: "The member's answer to an authorization request (VS-08A)"
      description: >-
        A staff session only (`422` at `/credential` otherwise). `allow` records the
        member's consent (widening a live one) and answers the redirect with a one-time
        code (ten minutes), `state` and `iss`; `deny` answers it with
        `error=access_denied`. Refusals are problems at the request's member
        (`/client_id`, `/redirect_uri`, `/response_type`, `/code_challenge`, `/scope`,
        `/state`, `/decision`), never a redirect to an unregistered URI.
      x-permission: ""
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/AuthorizeRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  redirect_to: {type: string}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/oauth/authorize/request:
    get:
      operationId: authorizeRequest
      summary: "An authorization request, checked, for the consent screen to show"
      description: >-
        The query of `GET /oauth/authorize`, checked against the client and the signed-in
        member as `POST /oauth/authorize` checks it; answers the client's name and the
        scopes asked.
      x-permission: ""
      parameters:
        - {name: response_type, in: query, required: true, schema: {type: string}}
        - {name: client_id, in: query, required: true, schema: {type: string}}
        - {name: redirect_uri, in: query, required: true, schema: {type: string}}
        - {name: scope, in: query, required: true, schema: {type: string}}
        - {name: state, in: query, schema: {type: string}}
        - {name: code_challenge, in: query, required: true, schema: {type: string}}
        - {name: code_challenge_method, in: query, required: true, schema: {type: string}}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  client: {type: object, properties: {id: {type: string}, name: {type: string}, kind: {type: string}}}
                  scopes: {type: array, items: {type: string}}
                  redirect_uri: {type: string}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/oauth/consents:
    get:
      operationId: listConsents
      summary: "The apps the caller let act as them (VS-08A)"
      x-permission: ""
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  items: {type: array, items: {$ref: '#/components/schemas/Consent'}}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/oauth/consents/{id}:
    delete:
      operationId: revokeConsent
      summary: "Withdraw a consent: its refresh tokens stop at once, its access tokens on their next request"
      x-permission: ""
      parameters:
        - {name: id, in: path, required: true, schema: {type: string}}
      responses:
        '204': {description: Withdrawn}
        default: {$ref: '#/components/responses/Problem'}
  /.well-known/jwks.json:
    get:
      operationId: jwks
      summary: "Keys that verify access tokens"
      security: []
      x-permission: public
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Jwks'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/accounts/me:
    get:
      operationId: getAccount
      summary: "The caller's account"
      x-permission: ""
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Account'}
        default: {$ref: '#/components/responses/Problem'}
    patch:
      operationId: patchAccount
      summary: "Merge into the account's settings"
      x-permission: "settings.sending"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/AccountPatch'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/account/settings/ml:
    get:
      operationId: getMlSettings
      summary: "The workspace's document-analysis settings (docs/33 §6, WEB-19)"
      x-permission: "settings.sending"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/MlSettings'}
        default: {$ref: '#/components/responses/Problem'}
    patch:
      operationId: patchMlSettings
      summary: "Turn document-analysis features on or off"
      description: >-
        Turning on a feature the plan lacks, or any feature while the model service is not
        installed, is `403 CS-ML-0011`; turning one off is always allowed.
      x-permission: "settings.sending"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/MlSettingsPatch'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/MlSettings'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/ersd-versions:
    get:
      operationId: listErsdVersions
      summary: "The account's electronic disclosure: the one the workflow policy names, with its text, and the published versions (ERSD-01)"
      description: >-
        `current` is the disclosure `settings.workflow_policy.ersd` names, with its published
        text (`text` null when no intact published row has that hash), or null when the
        account requires none. `items` are the published versions, newest first, at most 100,
        without their text.
      x-permission: "ersd.manage"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/ErsdVersions'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: publishErsdVersion
      summary: "Publish disclosure text as the next version and require it, in one step (ERSD-01)"
      description: >-
        Writes the next version of `language` (one more than its highest), its `ersd.published`
        admin event, and `settings.workflow_policy.ersd = {version, hash}` with its
        `workspace.settings_changed` event, in one transaction. Envelopes already sent then ask
        for consent to the new version. Published rows are never changed: a new text is a new
        version. An empty or blank text, one with a NUL, or a bad language tag is
        `422 CS-API-0001`; a text over 100,000 bytes is `413 CS-API-0006`.
      x-permission: "ersd.manage"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/ErsdPublish'}
      responses:
        '201':
          description: Published and required
          content:
            application/json:
              schema: {$ref: '#/components/schemas/ErsdVersion'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/admin-events:
    get:
      operationId: listAdminEvents
      summary: "The workspace's admin audit log (ORG-05), oldest first, verified before it is answered"
      description: >-
        Every settings, member, profile and workspace change, hash-chained per workspace.
        Each item carries its `seq`, `hash`, `prev` and the event as its RFC 8785 canonical
        JSON; `hash` is SHA-256 of those bytes. Each page is verified as it is read: linked
        to the event at its cursor, the last page to the stored head, and each `at` to its
        bytes, so walking the log by cursor checks every link once. `verify=full` re-verifies
        the whole log first. A broken chain is `500 CS-DB-0014`. `format=csv` answers `text/csv` with columns
        `seq,at,action,hash,prev,event` and the next cursor in `X-Next-Cursor`.
      x-permission: "admin_audit.read"
      x-level: workspace
      parameters:
        - {name: cursor, in: query, required: false, description: "The `seq` after which to start", schema: {type: integer, minimum: 0}}
        - {name: limit, in: query, required: false, schema: {type: integer, minimum: 1, maximum: 1000, default: 100}}
        - {name: format, in: query, required: false, schema: {type: string, enum: [json, csv], default: json}}
        - {name: verify, in: query, required: false, description: "`page` verifies the page read; `full` re-verifies the whole log first; another value is `422 CS-API-0001`", schema: {type: string, enum: [page, full], default: page}}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/AdminEventList'}
            text/csv:
              schema: {type: string}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/organizations/me:
    get:
      operationId: getOrganization
      summary: "The caller's organization and their role in it (ORG-03)"
      description: >-
        Organization metadata only; no role confers access to agreements (SEC-O07).
        The caller's organization is the session's workspace's; the role is read from
        `organization_admins` on every request (no role, or an action it does not hold:
        `403 CS-AUTH-0006`; a non-session credential: `403 CS-AUTH-0006`). Another
        organization's ids answer `404 CS-API-0002`.
      x-permission: "org.read"
      x-level: organization
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Organization'}
        default: {$ref: '#/components/responses/Problem'}
    patch:
      operationId: patchOrganization
      summary: "Rename the organization or replace its policy (`org.settings.update`), logged as `organization.renamed` and `organization.policy_changed`"
      description: >-
        The policy is the whole document (ORG-08, docs/23 §3); an invalid key or value is
        `422 CS-API-0001` at `/policy/<key>`. Loosening, unlocking or removing a security
        key is an owner's alone (`403 CS-ORG-0013`, SEC-O11); tightening is any holder's.
        Workspace rows are never rewritten: each workspace's effective policy is
        recomputed per request.
      x-permission: "org.settings.update"
      x-level: organization
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/OrganizationPatch'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Organization'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/organizations/me/workspaces:
    get:
      operationId: listOrgWorkspaces
      summary: "The organization's workspaces, by name (metadata only)"
      x-permission: "org.read"
      x-level: organization
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/OrgWorkspaceList'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: createOrgWorkspace
      summary: "Create a workspace (`org.workspaces.create`) with its built-in profiles and no member, logged as `workspace.created`"
      x-permission: "org.workspaces.create"
      x-level: organization
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/OrgWorkspaceCreate'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/OrgWorkspace'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/organizations/me/workspaces/{id}:
    parameters:
      - name: id
        in: path
        required: true
        description: Workspace id (UUIDv7)
        schema: {type: string}
    get:
      operationId: getOrgWorkspace
      summary: "A workspace of the organization (metadata only)"
      x-permission: "org.read"
      x-level: organization
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/OrgWorkspace'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/organizations/me/workspaces/{id}/archive:
    parameters:
      - name: id
        in: path
        required: true
        description: Workspace id (UUIDv7)
        schema: {type: string}
    post:
      operationId: archiveOrgWorkspace
      summary: "Archive a workspace (`org.workspaces.archive`, idempotent), logged as `workspace.archived`"
      x-permission: "org.workspaces.archive"
      x-level: organization
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/OrgWorkspace'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/organizations/me/workspaces/{id}/join:
    parameters:
      - name: id
        in: path
        required: true
        description: Workspace id (UUIDv7)
        schema: {type: string}
    post:
      operationId: joinOrgWorkspace
      summary: "Become a member of a workspace (`org.workspaces.join`, owners and admins only)"
      description: >-
        The only way an organization role reaches agreements: one transaction writes the membership,
        `member.added` (`via: organization`) in the workspace's log and `org.workspace_joined` in the
        organization's. A delegated admin gets `403 CS-AUTH-0006`; an archived workspace `409 CS-ORG-0010`.
      x-permission: "org.workspaces.join"
      x-level: organization
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/OrgWorkspaceJoin'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/OrgWorkspaceMembership'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/organizations/me/admins:
    get:
      operationId: listOrgAdmins
      summary: "The organization's owners and admins"
      x-permission: "org.read"
      x-level: organization
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/OrgAdminList'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: addOrgAdmin
      summary: "Make a user an owner or admin (`org.admins.manage`, owners only), logged as `organization.admin_added`"
      description: >-
        The user must be an enabled member of a workspace of this organization, else `422 CS-ORG-0018`
        (also for an id the organization cannot see); never oneself (`403 CS-ORG-0005`).
      x-permission: "org.admins.manage"
      x-level: organization
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/OrgAdminCreate'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/OrgAdmin'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/organizations/me/admins/{user}:
    parameters:
      - name: user
        in: path
        required: true
        description: User id (UUIDv7)
        schema: {type: string}
    patch:
      operationId: patchOrgAdmin
      summary: "Change an administrator's role (owners only; never one's own), logged as `organization.admin_role_changed`"
      description: >-
        A delegated admin made an owner or admin loses its permission set and workspace
        scope; the same role again changes and logs nothing. Leaving no enabled owner is
        `409 CS-ORG-0008`.
      x-permission: "org.admins.manage"
      x-level: organization
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/OrgAdminPatch'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/OrgAdmin'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: removeOrgAdmin
      summary: "Remove an administrator (owners only), logged as `organization.admin_removed`"
      description: >-
        An owner may resign; the last enabled owner may not (`409 CS-ORG-0008`).
      x-permission: "org.admins.manage"
      x-level: organization
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {type: object, properties: {user_id: {type: string}}}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/organizations/me/audit:
    get:
      operationId: listOrgAdminEvents
      summary: "The organization's admin audit log (`org.audit.read`), oldest first, verified as read"
      description: >-
        As `GET /admin-events`, over the organization's chain: workspace creation and archiving,
        joins, administrator changes, renames, and the platform's `operator.*` copies (CON-16).
      x-permission: "org.audit.read"
      x-level: organization
      parameters:
        - {name: cursor, in: query, required: false, description: "The `seq` after which to start", schema: {type: integer, minimum: 0}}
        - {name: limit, in: query, required: false, schema: {type: integer, minimum: 1, maximum: 1000, default: 100}}
        - {name: format, in: query, required: false, schema: {type: string, enum: [json, csv], default: json}}
        - {name: verify, in: query, required: false, schema: {type: string, enum: [page, full], default: page}}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/AdminEventList'}
            text/csv:
              schema: {type: string}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/users/me:
    get:
      operationId: getMe
      summary: "The signed-in user's own profile (UXW-37)"
      description: >-
        `{id, name, email, notifications {completed, declined, viewed}, signature,
        initials}`; each mark is `{image_base64}` or null. Notices and marks are this
        account's.
      x-permission: ""
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
    patch:
      operationId: patchMe
      summary: "Change one's own profile (UXW-37)"
      description: >-
        `{name?, notifications?, signature?, initials?, password?, current_password?}`.
        A mark is `{image_base64}` (PNG or JPEG, at most 5 MiB) or null to remove it.
        The name and password are the user's in every account and change only through
        their own session (`422` with another credential). A new password needs the
        current one (`401 CS-AUTH-0007` when wrong) and ends every other session of the
        user in every account; this session stays.
      x-permission: ""
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/Object'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: eraseMe
      summary: "Erase one's own identity in this workspace (ASVS-16)"
      description: >-
        After a recent re-authentication (`403 CS-AUTH-0013` otherwise), from a session of
        the person (`422` with another credential): name and email replaced by a marker,
        login binding, password and second factor removed, sessions here ended, saved
        signature, notices, invitations and password resets deleted, owned API clients
        revoked; recorded as the admin event `member.erased`. Audit events, admin logs,
        tombstones and sealed documents are never altered (docs/32). `403 CS-API-0015`
        for a member of another workspace too; `409 CS-API-0018` for the workspace's last
        administrator or an organization administrator.
      x-permission: ""
      responses:
        '204': {description: Erased}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/users/me/export:
    get:
      operationId: exportMe
      summary: "Export one's own data in this workspace (ASVS-16)"
      description: >-
        One JSON document `{format: "openseal.personal-data-export", v: 1, exported_at,
        workspace, user, login_kind, profile, sessions, api_clients, envelopes, templates,
        kept}`. Each envelope the caller sent lists the routes serving its documents,
        certificate and audit trail, each authorized and logged per object. Nothing of
        another workspace or member. At most 3 a minute per user (`429`); logged as a
        `data.document_read` security event.
      x-permission: ""
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/users:
    get:
      operationId: listUsers
      summary: "Members of the account"
      x-permission: "users.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/UserList'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: createUser
      summary: "Add a local member"
      x-permission: "users.invite"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/UserCreate'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/User'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/users/{id}/erase:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string, format: uuid}
    post:
      operationId: eraseUser
      summary: "Erase a member's identity (ASVS-16)"
      description: >-
        As `DELETE /users/me`, by an administrator after a recent re-authentication:
        never their own (`422`), never a member above them (`403 CS-ORG-0005`), never a
        member of another workspace too (`403 CS-API-0015`), never the last administrator
        or an organization administrator (`409 CS-API-0018`).
      x-permission: "users.remove"
      x-level: workspace
      responses:
        '204': {description: Erased}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/retention:
    get:
      operationId: getRetention
      summary: "The account's retention rules (ASVS-18)"
      description: >-
        `{keep_days: {draft, ended, completed, sessions}, max_keep_days}`: days a record of
        each class is kept after its last change (completion, for completed envelopes),
        or `null` to keep it for ever (the default).
      x-permission: "retention.manage"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
    put:
      operationId: setRetention
      summary: "Set or remove retention rules (ASVS-18)"
      description: >-
        `{keep_days: {class: days | null}}`, days 1 to 36500; classes left out are
        unchanged. After a recent re-authentication. Each change is the admin event
        `retention.rule_set`. The daily retention job then purges what a rule expires,
        never an envelope under legal hold or in flight.
      x-permission: "retention.manage"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/Object'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/retention/preview:
    get:
      operationId: previewRetention
      summary: "Dry run of the retention job (ASVS-18)"
      description: >-
        What the job would delete now, changing nothing: `{at, counts {draft, ended,
        completed}, sessions, held, envelopes [{id, class, since}]}` (at most 100 listed,
        oldest first; `held` counts expired envelopes a legal hold keeps).
      x-permission: "retention.manage"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/legal-hold:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string, format: uuid}
    put:
      operationId: setLegalHold
      summary: "Place an envelope under legal hold (ASVS-18)"
      description: >-
        No retention rule or purge request removes it until released. Admin event
        `envelope.legal_hold_set`. Answers `{envelope_id, legal_hold, since}`.
      x-permission: "retention.manage"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: releaseLegalHold
      summary: "Release an envelope's legal hold (ASVS-18)"
      description: Admin event `envelope.legal_hold_released`. Answers as `PUT`.
      x-permission: "retention.manage"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/purge:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string, format: uuid}
    post:
      operationId: purgeEnvelope
      summary: "Purge an envelope now, at the controller's request (ASVS-16, ASVS-18)"
      description: >-
        For an envelope that completed, ended or was never sent, after a recent
        re-authentication: appends `envelope.purged` with the policy `request` and queues
        the purge of its documents and personal data; its audit chain and a tombstone
        stay (docs/32 §7). `409 CS-API-0019` under legal hold; `409 CS-WF-0001` in flight
        or already purged. How a signer's erasure request is carried out by the account
        that holds their envelope.
      x-permission: "retention.manage"
      x-level: workspace
      responses:
        '202':
          description: Purged; the records follow by job
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/users/{id}:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: getUser
      summary: "A member"
      x-permission: "users.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/User'}
        default: {$ref: '#/components/responses/Problem'}
    patch:
      operationId: patchUser
      summary: "Rename a member, set their password, change their profile, disable or enable them"
      description: >-
        The name and password belong to the user in every account (SEC-ID-01). An
        administrator, or any API key (the user's own included), changes them only for a
        user whose one membership is this account; for a user who also belongs to another
        account it is `403 CS-API-0015` and nothing in the request is applied. The user
        changes their own name and password through their own session; a new password
        ends their sessions in every account. Profile fields and disabling apply to this
        account's membership only.
      x-permission: "users.update"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/UserPatch'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/User'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: deleteUser
      summary: "Remove a member from the account"
      x-permission: "users.remove"
      x-level: workspace
      responses:
        '204': {description: Done}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/users/{id}/second-factor/reset:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    post:
      operationId: resetMemberSecondFactor
      summary: "Reset the second factors of a member who lost them (ASVS-32, ASVS 2.5.7)"
      description: >-
        For an administrator of the workspace (or of its organization) signed in with a
        staff session that re-authenticated within five minutes (`403 CS-AUTH-0013`);
        never an API key or token, never oneself (`422`). `identity_verified_by` records
        how the person's identity was proved out of band. The member must belong to this
        workspace alone (`403 CS-API-0015`). Their TOTP authenticator, passkeys and
        recovery codes are removed, their sessions end, and their next sign-in must enrol
        a new factor before anything else, whatever the policy. Recorded in the
        administrative log (`member.factors_reset`) and the security log
        (`auth.mfa_remove`); the member is told by email.
      x-permission: "users.update"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [identity_verified_by]
              properties:
                identity_verified_by:
                  type: string
                  enum: [in_person, video_call, phone_callback, manager_confirmation, identity_document]
      responses:
        '200':
          description: Reset
          content:
            application/json:
              schema:
                type: object
                properties:
                  user_id: {type: string}
                  removed:
                    type: object
                    properties:
                      totp: {type: boolean}
                      passkeys: {type: integer}
                  identity_verified_by: {type: string}
                  enrol_at_next_sign_in: {type: boolean}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/users/{id}/invite:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    post:
      operationId: inviteUser
      summary: "Email the member a new one-time set-password link; earlier links stop working (WEB-06)"
      x-permission: "users.invite"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      responses:
        '202':
          description: Queued
          content:
            application/json:
              schema: {$ref: '#/components/schemas/User'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/api-clients:
    get:
      operationId: listApiClients
      summary: "API keys and OAuth clients"
      x-permission: "api_clients.manage"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/ApiClientList'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: createApiClient
      summary: "New API key or OAuth client; the secret is shown once"
      x-permission: "api_clients.manage"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/ApiClientCreate'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/ApiClientCreated'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/api-clients/{id}:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: getApiClient
      summary: "An API client"
      x-permission: "api_clients.manage"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/ApiClient'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: revokeApiClient
      summary: "Revoke an API client"
      x-permission: "api_clients.manage"
      x-level: workspace
      responses:
        '204': {description: Done}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/insights:
    get:
      operationId: getInsights
      summary: "The Insights dashboard's figures over the envelopes created in a window (FG-141)"
      description: >-
        DocuSign's Insights. Over the envelopes created in `[from, to)` (any time by default),
        Deleted left out: counts by how they stand, the median and 90th percentile of the
        time from sent to completed (seconds, continuous percentiles), envelopes sent and
        completed per day in the caller's day (`utc_offset_minutes`, -840 to 840, default 0;
        days with neither are absent), and the ten senders who sent most. A holder of
        `reports.read` sees the workspace (`scope: workspace`), of `sender` when given;
        anyone else sees their own envelopes (`scope: own`), and naming another sender is
        `403 CS-AUTH-0006`. Aggregates only: no subject, name or address.
      x-permission: "envelopes.read"
      x-level: workspace
      parameters:
        - {name: from, in: query, required: false, schema: {type: string, format: date-time}}
        - {name: to, in: query, required: false, schema: {type: string, format: date-time}}
        - {name: sender, in: query, required: false, description: "A user id, or `me`", schema: {type: string}}
        - {name: utc_offset_minutes, in: query, required: false, schema: {type: integer, minimum: -840, maximum: 840, default: 0}}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                required: [scope, totals, time_to_complete, days, top_senders]
                properties:
                  scope: {type: string, enum: [workspace, own]}
                  from: {type: [string, 'null'], format: date-time}
                  to: {type: [string, 'null'], format: date-time}
                  sender: {type: [string, 'null']}
                  utc_offset_minutes: {type: integer}
                  totals:
                    type: object
                    properties:
                      created: {type: integer}
                      sent: {type: integer}
                      completed: {type: integer}
                      declined: {type: integer}
                      voided: {type: integer}
                      expired: {type: integer}
                      in_progress: {type: integer}
                  time_to_complete:
                    type: object
                    properties:
                      completed: {type: integer}
                      median_seconds: {type: [number, 'null']}
                      p90_seconds: {type: [number, 'null']}
                  days:
                    type: array
                    items:
                      type: object
                      properties:
                        day: {type: string, format: date}
                        sent: {type: integer}
                        completed: {type: integer}
                  top_senders:
                    type: array
                    items:
                      type: object
                      properties:
                        sender_user_id: {type: string}
                        sent: {type: integer}
                        completed: {type: integer}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/reports/{kind}:
    parameters:
      - name: kind
        in: path
        required: true
        description: "`envelopes` (one row per envelope), `recipients` (one row per recipient) or `usage` (one row per sender); another is `404`"
        schema: {type: string, enum: [envelopes, recipients, usage]}
    get:
      operationId: getReport
      summary: "A workspace report over the envelopes created in a window (VS-06, UXW-25)"
      description: >-
        DocuSign's envelope, recipient and usage reports. Envelopes created in `[from, to)`
        (any time by default), of `sender` when given, newest first, at most `limit`;
        `truncated` (or the `x-truncated` header on CSV) says the limit was reached.
        Envelopes in the Deleted view are left out. `format=csv` answers `text/csv`
        (RFC 4180, CRLF); a cell a spreadsheet would read as a formula starts with `'`.
      x-permission: "reports.read"
      x-level: workspace
      parameters:
        - {name: from, in: query, required: false, schema: {type: string, format: date-time}}
        - {name: to, in: query, required: false, schema: {type: string, format: date-time}}
        - {name: sender, in: query, required: false, description: "A user id, or `me`", schema: {type: string}}
        - {name: format, in: query, required: false, schema: {type: string, enum: [json, csv], default: json}}
        - {name: limit, in: query, required: false, schema: {type: integer, minimum: 1, maximum: 10000, default: 10000}}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                required: [items, truncated]
                properties:
                  items: {type: array, items: {type: object}}
                  truncated: {type: boolean}
            text/csv:
              schema: {type: string}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/contacts:
    get:
      operationId: listContacts
      summary: "Past recipients for autocomplete: one per email address, most recently used first (WEB-06)"
      description: >-
        From the envelopes the caller may see (their own without `view_all`), never another
        account's. `q` matches the name or email, ignoring case; `limit` is 1 to 50 (default 10).
      x-permission: "envelopes.read"
      x-level: workspace
      parameters:
        - name: q
          in: query
          required: false
          description: Text the name or email contains (ignoring case); at most 200 characters, no control characters.
          schema: {type: string, maxLength: 200}
        - name: limit
          in: query
          required: false
          schema: {type: integer, minimum: 1, maximum: 50, default: 10}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/ContactList'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes:
    get:
      operationId: listEnvelopes
      summary: "Envelopes, sorted and filtered, cursor-paginated (WEB-08)"
      description: >-
        The envelopes the caller may see (their own without `view_all`), never another
        account's, and never those removed from the lists (`DELETE` of an envelope that
        ended without completing) unless `deleted=true` asks for exactly those (the
        Deleted view, UXW-02). `waiting_for=me` is the Inbox (UXW-01): sent envelopes of
        this account, whoever sent them, in which the caller is, by their account email, a
        recipient whose turn it is and who acts through a link (not a copy, an in-person
        or an embedded signer); each item then has `my_recipient_id`. Every item has
        `folder_id`, the caller's own folder it is filed in, or null. Newest first by
        default. Keyset paging: a cursor belongs to the sort and order it was issued for
        (another is `422`), and pages stay stable under inserts.
      x-permission: "envelopes.read"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/cursor'
        - $ref: '#/components/parameters/limit'
        - name: status
          in: query
          required: false
          description: One status, or several separated by commas (any of them).
          schema: {type: string, example: "sent,delivered"}
        - $ref: '#/components/parameters/search'
        - name: sort
          in: query
          required: false
          description: >-
            `created_at` (default), `updated_at` (last change: the last command that
            changed the envelope; downloads are not changes), `expires_at` (never
            expiring after every date), `subject` (ignoring case) or `status` (lifecycle
            order: draft, sent, delivered, completing, completed, declined, voided,
            expired). Ties are broken by id.
          schema: {type: string, enum: [created_at, updated_at, expires_at, subject, status], default: created_at}
        - name: order
          in: query
          required: false
          description: Default `desc` for the times, `asc` for subject and status.
          schema: {type: string, enum: [asc, desc]}
        - name: sender
          in: query
          required: false
          description: >-
            A sender's user id, or `me`. Without `view_all` another sender's id answers an
            empty page.
          schema: {type: string}
        - name: from
          in: query
          required: false
          description: "`date_field` at or after this instant (RFC 3339)."
          schema: {type: string, format: date-time}
        - name: to
          in: query
          required: false
          description: "`date_field` before this instant (RFC 3339)."
          schema: {type: string, format: date-time}
        - name: date_field
          in: query
          required: false
          description: >-
            Which date `from` and `to` bound (UXW-03): the last change (default), creation,
            sending or completion. An envelope without that date is outside any range.
          schema: {type: string, enum: [updated_at, created_at, sent_at, completed_at], default: updated_at}
        - name: recipient
          in: query
          required: false
          description: >-
            Text a recipient's name or email contains, ignoring case (UXW-03); at most 200
            characters.
          schema: {type: string, maxLength: 200}
        - name: folder
          in: query
          required: false
          description: >-
            One of the caller's folders (another member's matches nothing), or `none`: in
            none of the caller's folders (UXW-02).
          schema: {type: string}
        - name: deleted
          in: query
          required: false
          description: "`true`: only the envelopes removed from the lists, the Deleted view (UXW-02)."
          schema: {type: string, enum: ["true", "false"], default: "false"}
        - name: waiting_for
          in: query
          required: false
          description: "`me`: the Inbox (UXW-01)."
          schema: {type: string, enum: [me]}
        - name: auth_failed
          in: query
          required: false
          description: >-
            `true`: the Authentication failed quick view (VS-06): envelopes in progress in
            which a recipient is locked out after failed authentication, or failed it and has
            not passed since. A resend clears it.
          schema: {type: string, enum: ["true", "false"], default: "false"}
        - name: expires_before
          in: query
          required: false
          description: "RFC 3339: only envelopes expiring before it, the Expiring soon quick view (VS-06); one that never expires is outside it."
          schema: {type: string, format: date-time}
        - name: custom_field
          in: query
          required: false
          description: "Only envelopes with a custom field of exactly this name (VS-06, FG-132)."
          schema: {type: string, maxLength: 100}
        - name: custom_value
          in: query
          required: false
          description: "With `custom_field`: text that field's value contains, ignoring case; `%` and `_` match themselves."
          schema: {type: string, maxLength: 200}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/EnvelopePage'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: createEnvelope
      summary: "Create a draft, or create and send in one call"
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/EnvelopeCreate'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Envelope'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/from-templates:
    post:
      operationId: createEnvelopeFromTemplates
      summary: "One envelope from one template or several (composite templates), as a draft or sent (slice 3)"
      description: >-
        Made on the server from the templates' stored documents (scanned again, ASVS-11)
        through the same path as `POST /envelopes`, so it is checked, audited and sent the
        same way. Needs `templates.read` as well; `status: sent` needs `envelopes.send`.
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/EnvelopeFromTemplates'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Envelope'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: getEnvelope
      summary: "An envelope with its documents, recipients and fields"
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Envelope'}
        default: {$ref: '#/components/responses/Problem'}
    patch:
      operationId: patchEnvelope
      summary: "Change a draft's or a correction's settings (If-Match required)"
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/EnvelopePatch'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Envelope'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: deleteEnvelope
      summary: "Delete a draft, or remove an envelope that ended without completing from the lists (If-Match required)"
      description: >-
        A draft is deleted (`envelope.purged`, policy `draft_deleted`). A declined, voided
        or expired envelope is removed from the lists only (WEB-08): `envelope.deleted` is
        recorded; its documents, audit chain and evidence stay and it can still be read by
        id. A completed envelope, or one in flight, is `409`.
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
      responses:
        '204': {description: Done}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/status:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: getEnvelopeStatus
      summary: "Envelope and recipient statuses"
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/EnvelopeStatusInfo'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/send:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    post:
      operationId: sendEnvelope
      summary: "Send a draft"
      x-permission: "envelopes.send"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Envelope'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/schedule:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    put:
      operationId: scheduleEnvelope
      summary: "Schedule a draft to send itself (WF-02)"
      description: "The draft must be sendable now (`422 CS-WF-0004`); `send_at` after now, at most 365 days ahead and before the expiry (`422 CS-WF-0023`). A scheduled draft cannot be edited (`409 CS-WF-0022`) until the schedule is cancelled; sending by hand drops it. Recorded as a draft edit of `send_at`; the send itself is `envelope.sent` by the platform."
      x-permission: "envelopes.send"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/ScheduleRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Envelope'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: unscheduleEnvelope
      summary: "Cancel a draft's scheduled send (WF-02)"
      x-permission: "envelopes.send"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Envelope'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/void:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    post:
      operationId: voidEnvelope
      summary: "Void with a reason"
      x-permission: "envelopes.send"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/VoidRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Envelope'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/custom-fields:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: getEnvelopeCustomFields
      summary: "The envelope's custom fields, by name (VS-06, FG-139)"
      description: >-
        Sender and integrator metadata, searchable with `GET /envelopes?custom_field=`. Not
        part of the agreement: never shown to a recipient, never in the audit chain, the
        sealed PDF or the certificate.
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CustomFields'}
        default: {$ref: '#/components/responses/Problem'}
    put:
      operationId: setEnvelopeCustomFields
      summary: "Replace the envelope's custom fields (VS-06)"
      description: >-
        At most 100; a name is 1 to 100 characters, a value at most 1,000, neither with
        control characters; a repeated name is `422` with the member code `exists`. A
        purged envelope is `409 CS-API-0009`. Nothing is recorded in the audit chain.
      x-permission: "envelopes.write"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/CustomFields'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CustomFields'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/transfer:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    post:
      operationId: transferEnvelope
      summary: "Pass the envelope's ownership to another member of this workspace (ORG-09)"
      description: >-
        Any state but purged; records `envelope.transferred {from_user, to_user}` in the
        envelope's chain. Envelopes never move between workspaces (docs/23 §2.4): a
        `to_workspace` other than this one, or a `to_user` who is not an enabled member
        here, is `422 CS-ORG-0009`. An API key or OAuth token also needs
        `envelopes:send` granted, else `403 CS-AUTH-0006`.
      x-permission: "envelopes.transfer"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/TransferRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Envelope'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/restore:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    post:
      operationId: restoreEnvelope
      summary: "Bring a deleted envelope back to the lists (ADR-031)"
      description: >-
        An envelope removed from the lists by `DELETE` (declined, voided or expired; in the
        Deleted view, `GET /envelopes?deleted=true`) is listed again. Records
        `envelope.restored` in its chain, after the `envelope.deleted` that removed it;
        nothing in the agreement changes. `If-Match` is checked when sent. One that is
        not deleted, or was purged meanwhile (past its retention), is `409 CS-WF-0001`.
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - name: If-Match
          in: header
          required: false
          description: The envelope's `ETag` as read; a stale one is `412 CS-WF-0002`.
          schema: {type: string}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Envelope'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/correct:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    post:
      operationId: correctEnvelope
      summary: "Correct a sent envelope, all changes or none (If-Match required)"
      x-permission: "envelopes.send"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/CorrectRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Envelope'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/resend:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    post:
      operationId: resendEnvelope
      summary: "Re-send invitations"
      x-permission: "envelopes.send"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/ResendRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Envelope'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/audit:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: getAudit
      summary: "Hash-chained audit events, re-verified on read"
      x-permission: "audit.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/AuditEvents'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/anchor-proof:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: getAnchorProof
      summary: "The anchor proof of the envelope's latest anchored chain head (FG-158)"
      description: >-
        The proof file (`openseal.anchor-proof` v1, canonical JSON) of the envelope's latest
        audit chain head that the daily anchor job anchored (docs/32 §5): the head, its
        leaf index and audit path, and that day's anchor with its RFC 3161 token. Check it
        offline with `openseal anchor verify` or the Verify page. `404 CS-API-0017` while
        no head of the envelope is anchored yet (the job runs after each UTC day closes).
        A read of evidence (security log); not recorded in the chain.
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: The proof file, as an attachment named anchor-proof.json
          content:
            application/json:
              schema: {$ref: '#/components/schemas/AnchorProof'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/certificate:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: getCertificate
      summary: "Certificate of completion PDF (made by the seal job), or a declined, voided or expired envelope's envelope certificate (UXW-30)"
      description: >-
        A completed envelope's certificate of completion. A declined, voided or expired
        envelope's envelope certificate says how it ended and never claims completion;
        the worker makes and seals it when the envelope ends. `409 CS-API-0009` before
        either exists (an ended envelope without one asks the worker for it then).
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: PDF
          content:
            application/pdf:
              schema: {type: string, format: binary}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/evidence-package:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: getEvidencePackage
      summary: "One ZIP with everything that proves the agreement (VS-06D), recorded as envelope.exported"
      description: >-
        For an envelope that is over (completed, or declined, voided or expired): a ZIP of
        stored entries holding `manifest.json`, each document as sealed (as it ended, with
        the "not signed" banner, for one that ended without completing) under
        `documents/`, `certificate.pdf` (the certificate of completion, or the envelope
        certificate of UXW-30) and `audit-trail.json` (the events as `GET …/audit` gives
        them, with `chain_head`). The manifest (`format: openseal.evidence-package`,
        `version: 1`) names every other entry with its `sha256` and `size`, and the chain
        head. The export is recorded first as `envelope.exported` (ORG-09), so the trail
        in the package ends with it. In flight, a draft, or purged is `409 CS-WF-0001`; a
        certificate not made yet `409 CS-API-0009` (an ended envelope asks the worker for
        it, as `GET …/certificate` does).
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: ZIP
          content:
            application/zip:
              schema: {type: string, format: binary}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/attachments/{sha256}:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
      - {name: sha256, in: path, required: true, description: "The attachment's SHA-256, 64 lower-case hex digits (an attachment field's value)", schema: {type: string, pattern: '^[0-9a-f]{64}$'}}
    get:
      operationId: getAttachment
      summary: "A signer's attachment (WEB-08), recorded as attachment.downloaded"
      description: >-
        The file an attachment field's value names, checked against its hash, served as an
        attachment of the type its leading bytes show (PDF, PNG or JPEG). Recorded in the
        chain as `attachment.downloaded` with the field and the hash. Any other hash is
        `404`.
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: The file
          content:
            application/pdf:
              schema: {type: string, format: binary}
            image/png:
              schema: {type: string, format: binary}
            image/jpeg:
              schema: {type: string, format: binary}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/documents/combined:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: getCombined
      summary: "Sealed documents and certificate as one PDF (made by the seal job)"
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: PDF
          content:
            application/pdf:
              schema: {type: string, format: binary}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/documents:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: listDocuments
      summary: "Documents in order"
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/DocumentList'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: addDocument
      summary: "Upload a document, a PDF or a Word document (.docx, converted to PDF, ADR-042): admitted and normalized; JSON, or the file itself with ?name="
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
        - {name: name, in: query, required: false, description: "The document's name, when the body is the file itself", schema: {type: string}}
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/DocumentUpload'}
          application/pdf:
            schema: {type: string, format: binary}
          application/vnd.openxmlformats-officedocument.wordprocessingml.document:
            schema: {type: string, format: binary}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Document'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/conversions:
    post:
      operationId: convertDocument
      summary: "Convert a Word document (.docx) to PDF and admit it as an upload would be, nothing stored: the editor's preview (ADR-042)"
      x-permission: "envelopes.write"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/vnd.openxmlformats-officedocument.wordprocessingml.document:
            schema: {type: string, format: binary}
      responses:
        '200':
          description: The admitted PDF
          content:
            application/pdf:
              schema: {type: string, format: binary}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/documents/{doc}:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
      - name: doc
        in: path
        required: true
        description: Document id
        schema: {type: string}
    get:
      operationId: getDocument
      summary: "A document's metadata"
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Document'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: deleteDocument
      summary: "Remove a document (If-Match required)"
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
      responses:
        '204': {description: Done}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/documents/{doc}/content:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
      - name: doc
        in: path
        required: true
        description: Document id
        schema: {type: string}
    get:
      operationId: getDocumentContent
      summary: "Document bytes: original (a converted upload's original is its Word document), normalized or sealed"
      x-permission: "envelopes.read"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/version'
      responses:
        '200':
          description: PDF (or, for the original of a converted upload, the Word document)
          content:
            application/pdf:
              schema: {type: string, format: binary}
            application/vnd.openxmlformats-officedocument.wordprocessingml.document:
              schema: {type: string, format: binary}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/documents/{doc}/detect-fields:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
      - name: doc
        in: path
        required: true
        description: Document id
        schema: {type: string}
    post:
      operationId: detectFields
      summary: "Suggested fields from the document's lines, boxes, labels and form fields (WEB-06)"
      description: >-
        Nothing is changed or recorded. Each suggestion is in the field endpoints' geometry
        (displayed page space, points, origin top-left, ADR-019); add one by posting it to
        `/fields` with a `recipient_id`. At most 500, ordered by page, top, left; `truncated`
        says a bound was reached.
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/DetectedFields'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/documents/{doc}/analysis:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
      - {name: doc, in: path, required: true, description: Document id, schema: {type: string}}
    post:
      operationId: requestAnalysis
      summary: "Ask for a draft's document to be analysed (docs/33 §6, WEB-19)"
      description: >-
        Idempotent on the job key (account, document, its SHA-256, the features, the model
        bundle). `403 CS-ML-0011` with no feature in effect; `409 CS-WF-0001` once the
        envelope is no longer a draft; `404` once it is purged (a deleted draft). The
        envelope's sender or an administrator.
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      responses:
        '202':
          description: Accepted
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Analysis'}
        default: {$ref: '#/components/responses/Problem'}
    get:
      operationId: getAnalysis
      summary: "The document's newest analysis"
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Analysis'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/suggestions:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
    get:
      operationId: listSuggestions
      summary: "Suggestions of the envelope's analyses (docs/33 §6, WEB-19)"
      description: >-
        Only kinds whose feature is in effect, only for documents still in the envelope.
        `403 CS-ML-0011` with no feature in effect; `404` once the envelope is purged.
      x-permission: "envelopes.read"
      x-level: workspace
      parameters:
        - {name: kind, in: query, schema: {type: string, enum: [template, entity, personal_data]}}
        - {name: state, in: query, schema: {type: string, enum: [open, accepted, dismissed]}}
        - {name: cursor, in: query, schema: {type: string}}
        - {name: limit, in: query, schema: {type: integer, minimum: 1, maximum: 200, default: 50}}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/SuggestionPage'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/suggestions/{s}/accept:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
      - {name: s, in: path, required: true, description: Suggestion id, schema: {type: string}}
    post:
      operationId: acceptSuggestion
      summary: "Accept a suggestion"
      description: >-
        Records who accepted it and when. The action it suggests (applying a template, adding
        a field) is the person's own, through the ordinary endpoints. `409 CS-ML-0012` when
        already decided or its document left the envelope.
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Suggestion'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/suggestions/{s}/dismiss:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
      - {name: s, in: path, required: true, description: Suggestion id, schema: {type: string}}
    post:
      operationId: dismissSuggestion
      summary: "Dismiss a suggestion"
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Suggestion'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/recipients:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: listRecipients
      summary: "Recipients"
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/RecipientList'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: addRecipients
      summary: "Add one recipient, or {items: [...]}"
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/RecipientCreate'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/RecipientList'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/recipients/{r}:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
      - name: r
        in: path
        required: true
        description: Recipient id
        schema: {type: string}
    get:
      operationId: getRecipient
      summary: "A recipient"
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Recipient'}
        default: {$ref: '#/components/responses/Problem'}
    patch:
      operationId: patchRecipient
      summary: "Change a recipient (If-Match required)"
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/RecipientPatch'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Recipient'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: deleteRecipient
      summary: "Remove a recipient (If-Match required)"
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
      responses:
        '204': {description: Done}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/fields:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: listFields
      summary: "Fields, optionally of one recipient or document"
      x-permission: "envelopes.read"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/recipientId'
        - $ref: '#/components/parameters/documentId'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/FieldList'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: addFields
      summary: "Add one field, or {items: [...]}"
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/FieldCreate'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/FieldList'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/fields/{f}:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
      - name: f
        in: path
        required: true
        description: Field id
        schema: {type: string}
    get:
      operationId: getField
      summary: "A field"
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Field'}
        default: {$ref: '#/components/responses/Problem'}
    patch:
      operationId: patchField
      summary: "Merge into a field (If-Match required)"
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/Object'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Field'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: deleteField
      summary: "Remove a field (If-Match required)"
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
      responses:
        '204': {description: Done}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/form-data:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: getFormData
      summary: "Every labelled field's value by data label"
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/recipients/{r}/host:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
      - name: r
        in: path
        required: true
        description: Recipient id
        schema: {type: string}
    post:
      operationId: hostInPersonSigner
      summary: "Host an in-person signer: records recipient.in_person_hosted and returns a one-hour signing link that acts as the caller hosting the signer (UXW-36)"
      x-permission: "envelopes.send"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/SigningView'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/sign-link:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    post:
      operationId: createSignLink
      summary: "The Inbox (UXW-01): a five-minute signing link for the signed-in member, as the recipient they are"
      description: >-
        For a member signed in with a session (an API key or OAuth client is `403`) who
        is, by their account email, a recipient of this envelope whose turn it is and
        who acts through a link. The ceremony records the member's sign-in
        (`account_login`) as how the link was obtained and applies every authentication
        the sender required. `404` when the caller neither may see the envelope nor is a
        recipient of it; `409 CS-WF-0007` when routing has not reached them or has passed.
        The body is empty or `{}`.
      x-permission: ""
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/SigningView'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/views/signing:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    post:
      operationId: createSigningView
      summary: "Five-minute embedded signing link (the creating API client only)"
      x-permission: "envelopes.send"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/SigningViewRequest'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/SigningView'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/views/prepare:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    post:
      operationId: createPrepareView
      summary: "Five-minute embedded prepare (sender) link for a draft, an API client only (VS-09)"
      description: >-
        A single-use link to the editor for this draft, for the page at `frame_origin` to
        frame: recipients, documents and fields, then send. Only an API key or an OAuth
        access token may ask (`403 CS-AUTH-0010` to a staff session); the envelope must
        be a draft (`409 CS-WF-0001`). Opening it (`POST /e/{token}/session`) spends it.
      x-permission: "envelopes.send"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: false
        content:
          application/json:
            schema: {$ref: '#/components/schemas/EditorViewRequest'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/SigningView'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/envelopes/{id}/views/correct:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    post:
      operationId: createCorrectView
      summary: "Five-minute embedded correct link for a sent envelope, an API client only (VS-09)"
      description: >-
        As `createPrepareView`, for an envelope in flight (sent or delivered, else `409
        CS-WF-0001`): the correct editor (recipients, authentication, expiry and
        reminders).
      x-permission: "envelopes.send"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: false
        content:
          application/json:
            schema: {$ref: '#/components/schemas/EditorViewRequest'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/SigningView'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/templates:
    get:
      operationId: listTemplates
      summary: "Templates the caller may use, by view; with deleted=true the Deleted view (UXW-02, UXW-06)"
      description: >-
        The live templates the caller may use, by name: their own, those shared with
        them (directly, through a group, or with the whole account) and, for an
        administrator, every one (UXW-06). `view` narrows the list: `owned`, `shared`
        (Shared with me: another member's templates a share reaches the caller by) or
        `favourites` (the caller's starred ones). With `deleted=true`, the deleted
        templates the caller owns (every one for an administrator), kept whole and
        restorable, most recently deleted first. Any other value is `422`.
      x-permission: "templates.read"
      x-level: workspace
      parameters:
        - name: deleted
          in: query
          required: false
          description: "`true`: the Deleted view (UXW-02)."
          schema: {type: string, enum: ['true', 'false']}
        - name: view
          in: query
          required: false
          description: "`all` (default), `owned`, `shared` (Shared with me) or `favourites` (UXW-06)."
          schema: {type: string, enum: [all, owned, shared, favourites]}
        - name: folder
          in: query
          required: false
          description: "One of the caller's template folders (another member's matches nothing), or `none`: in none of the caller's folders (TSH-03). Each item carries the caller's `folder_id` (or null)."
          schema: {type: string}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/TemplateList'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: createTemplate
      summary: "Create a template with roles"
      x-permission: "templates.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/TemplateCreate'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Template'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/templates/{id}:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: getTemplate
      summary: "A template and its roles"
      x-permission: "templates.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Template'}
        default: {$ref: '#/components/responses/Problem'}
    patch:
      operationId: patchTemplate
      summary: "Rename a template or change its email subject and message (If-Match required)"
      x-permission: "templates.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/TemplatePatch'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Template'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: deleteTemplate
      summary: "Move a live template to the Deleted view, kept whole (UXW-02); delete one already there for good, with its roles, documents and fields; envelopes made from it keep their copies (WEB-06)"
      x-permission: "templates.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
      responses:
        '204': {description: Done}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/templates/{id}/restore:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
    post:
      operationId: restoreTemplate
      summary: "Bring a template of the Deleted view back, with everything it had (UXW-02)"
      description: >-
        `If-Match` is honoured when given. A live template, or none, is `404`. The body
        is empty or `{}`.
      x-permission: "templates.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
        - {name: If-Match, in: header, required: false, description: "\"v<version>\"", schema: {type: string}}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Template'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/templates/{id}/shares:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
    get:
      operationId: listTemplateShares
      summary: "Whom a template is shared with (UXW-06); its owner's or an administrator's"
      x-permission: "templates.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/TemplateShares'}
        default: {$ref: '#/components/responses/Problem'}
    put:
      operationId: replaceTemplateShares
      summary: "Replace a template's shares with members, groups or the whole account (UXW-06)"
      description: >-
        The whole set of shares. A user is a member of this account, named by id or
        email; a group is one of its groups. Sharing with the owner, or naming one target
        twice, is `422`. A share lets its members use the template, and edit it with
        `can_edit`; deleting, restoring and sharing stay with the owner and
        administrators. Anyone without access is answered `404`, too little access `403`.
      x-permission: "templates.write"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/TemplateSharesIn'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/TemplateShares'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/templates/{id}/favourite:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
    put:
      operationId: favouriteTemplate
      summary: "Star a template for the caller (Favourites, UXW-06); idempotent"
      x-permission: "templates.read"
      x-level: workspace
      responses:
        '204': {description: Starred}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: unfavouriteTemplate
      summary: "Unstar a template for the caller (UXW-06); idempotent"
      x-permission: "templates.read"
      x-level: workspace
      responses:
        '204': {description: Unstarred}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/templates/{id}/duplicate:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
    post:
      operationId: duplicateTemplate
      summary: "A copy owned by the caller, with new ids, sharing the stored PDFs (WEB-06)"
      x-permission: "templates.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              properties:
                name: {type: string, maxLength: 255, description: "Default `Copy of <name>`"}
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Template'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/templates/{id}/documents:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
    post:
      operationId: addTemplateDocument
      summary: "Add a document {name, content_base64}, a PDF or a Word document (converted, ADR-042), admitted and normalized as an upload (WEB-06)"
      x-permission: "templates.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/DocumentIn'}
      responses:
        '201':
          description: The template
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Template'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/templates/{id}/documents/{doc}:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
      - {name: doc, in: path, required: true, description: Template document id, schema: {type: string}}
    delete:
      operationId: deleteTemplateDocument
      summary: "Remove a document and the fields on it (WEB-06)"
      x-permission: "templates.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
      responses:
        '204': {description: Done}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/templates/{id}/documents/{doc}/content:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
      - {name: doc, in: path, required: true, description: Template document id, schema: {type: string}}
    get:
      operationId: getTemplateDocumentContent
      summary: "The template document's normalized PDF (WEB-06)"
      x-permission: "templates.read"
      x-level: workspace
      responses:
        '200':
          description: PDF
          content:
            application/pdf:
              schema: {type: string, format: binary}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/templates/{id}/documents/{doc}/analysis:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
      - {name: doc, in: path, required: true, description: Template document id, schema: {type: string}}
    post:
      operationId: requestTemplateAnalysis
      summary: "Ask for a template document's page hashes, for matching uploads (docs/33 §6)"
      description: "`403 CS-ML-0011` unless template matching is in effect."
      x-permission: "templates.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      responses:
        '202':
          description: Accepted
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Analysis'}
        default: {$ref: '#/components/responses/Problem'}
    get:
      operationId: getTemplateAnalysis
      summary: "The template document's newest analysis"
      x-permission: "templates.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Analysis'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/templates/{id}/roles:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
    post:
      operationId: addTemplateRole
      summary: "Add a role (WEB-06)"
      x-permission: "templates.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/TemplateRoleIn'}
      responses:
        '201':
          description: The template
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Template'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/templates/{id}/roles/{role}:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
      - {name: role, in: path, required: true, description: Role id, schema: {type: string}}
    patch:
      operationId: patchTemplateRole
      summary: "Rename a role or change its type or routing order (WEB-06)"
      x-permission: "templates.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/TemplateRolePatch'}
      responses:
        '200':
          description: The template
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Template'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: deleteTemplateRole
      summary: "Remove a role and its fields (WEB-06)"
      x-permission: "templates.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
      responses:
        '204': {description: Done}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/templates/{id}/fields:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
    get:
      operationId: listTemplateFields
      summary: "A template's fields (WEB-06)"
      x-permission: "templates.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/TemplateFieldList'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: addTemplateFields
      summary: "Add one field, or {items: [...]}, bound to roles (WEB-06)"
      x-permission: "templates.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {type: object}
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema: {$ref: '#/components/schemas/TemplateFieldList'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/templates/{id}/fields/{f}:
    parameters:
      - {name: id, in: path, required: true, description: Object id (UUIDv7), schema: {type: string}}
      - {name: f, in: path, required: true, description: Field id, schema: {type: string}}
    patch:
      operationId: patchTemplateField
      summary: "Change a field: the members given replace its own, null removes one (UX-11); checked whole again (WEB-06)"
      x-permission: "templates.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
      requestBody:
        required: true
        content:
          application/json:
            schema: {type: object}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/TemplateField'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: deleteTemplateField
      summary: "Remove a field (WEB-06)"
      x-permission: "templates.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/ifMatch'
      responses:
        '204': {description: Done}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/folders:
    get:
      operationId: listFolders
      summary: "The caller's own envelope (or template) folders, by name, with counts (UXW-02, TSH-03)"
      x-permission: "envelopes.read"
      x-level: workspace
      parameters:
        - name: kind
          in: query
          required: false
          description: "`envelopes` (default) or `templates` (TSH-03); any other is 422."
          schema: {type: string, enum: [envelopes, templates]}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  items: {type: array, items: {$ref: '#/components/schemas/Folder'}}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: createFolder
      summary: "A new folder of the caller's (at most 500)"
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/FolderName'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Folder'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/folders/{id}:
    parameters:
      - name: id
        in: path
        required: true
        description: One of the caller's folders (another member's or account's is 404)
        schema: {type: string}
    patch:
      operationId: renameFolder
      summary: "Rename one of the caller's folders"
      x-permission: "envelopes.write"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/FolderName'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Folder'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: deleteFolder
      summary: "Remove one of the caller's folders; what was filed in it is in no folder"
      x-permission: "envelopes.write"
      x-level: workspace
      responses:
        '204': {description: Removed}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/folders/{id}/envelopes:
    parameters:
      - name: id
        in: path
        required: true
        description: One of the caller's folders, or `none` to file the envelopes in no folder
        schema: {type: string}
    post:
      operationId: moveEnvelopes
      summary: "File 1 to 200 envelopes the caller may see in a folder of theirs, or in none, all or nothing"
      description: >-
        Filing is the caller's own view of their lists: the envelopes, their `updated_at`
        and their audit chains are untouched. An envelope the caller may not see is `404`
        and nothing moves.
      x-permission: "envelopes.write"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/FolderMove'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  moved: {type: integer}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/folders/{id}/templates:
    parameters:
      - name: id
        in: path
        required: true
        description: One of the caller's template folders (an envelope folder is 404), or `none` to file the templates in no folder
        schema: {type: string}
    post:
      operationId: moveTemplates
      summary: "File 1 to 200 templates the caller may use in a template folder of theirs, or in none, all or nothing (TSH-03)"
      description: >-
        Filing is the caller's own view of their template list: the templates and their
        versions are untouched. A template the caller may not use, or another account's,
        is `404` and nothing moves.
      x-permission: "templates.read"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/FolderTemplateMove'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  moved: {type: integer}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/bulk-sends:
    get:
      operationId: listBulkSends
      summary: "The caller's bulk sends, newest first, without rows (every member's for an administrator or a member who sees every envelope) (UXW-04)"
      x-permission: "envelopes.read"
      x-level: workspace
      parameters:
        - name: limit
          in: query
          schema: {type: integer, minimum: 1, maximum: 100, default: 50}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  items: {type: array, items: {$ref: '#/components/schemas/BulkSend'}}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: createBulkSend
      summary: "Check a list of recipient sets against a template, and make a bulk send of it (UXW-04)"
      description: >-
        The list is CSV text (a header, then one row per envelope) or JSON rows; its
        columns are two per template role, in role order: `<role>::name` and
        `<role>::email`, matched ignoring case and surrounding spaces. A header that does
        not fit the template is 422 (`CS-BLK-0004` missing columns at `/columns`,
        `CS-BLK-0005` an unknown or repeated column at `/columns/{i}`); no row, more than
        1000, or CSV that cannot be read is 422 `CS-BLK-0007`. Each row is checked:
        `CS-BLK-0001` a missing value, `CS-BLK-0002` an email that cannot be one,
        `CS-BLK-0003` a name over 255 characters or with control characters,
        `CS-BLK-0006` more values than columns. A row with a problem is stored `failed`
        and never sent. With `validate_only` nothing is stored: the answer is 200 with
        each row's check. Send the batch with `POST …/send`. Also needs `envelopes:write`
        and `envelopes:send`, as `POST /envelopes` with `status: sent` does. A line with
        no value in any cell is skipped.
      x-permission: "bulk.send"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/BulkSendCreate'}
      responses:
        '200':
          description: "validate_only: each row's check; nothing stored"
          content:
            application/json:
              schema: {$ref: '#/components/schemas/BulkSendCheck'}
        '201':
          description: Made, queued
          content:
            application/json:
              schema: {$ref: '#/components/schemas/BulkSendWithRows'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/bulk-sends/{id}:
    parameters:
      - name: id
        in: path
        required: true
        description: A bulk send the caller may see (another member's or account's is 404)
        schema: {type: string}
    get:
      operationId: getBulkSend
      summary: "A bulk send: its progress counts and every row"
      x-permission: "envelopes.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/BulkSendWithRows'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/bulk-sends/{id}/send:
    parameters:
      - name: id
        in: path
        required: true
        description: One of the caller's own bulk sends
        schema: {type: string}
    post:
      operationId: sendBulkSendRows
      summary: "Send the next pending rows, at most 10, one envelope each; repeat until none is pending"
      description: >-
        Each row is made and sent as `POST /envelopes` makes and sends one, in its own
        transaction; a row the server refuses is `failed` with the refusal's code and the
        others go on. Once no row is pending the bulk send is `completed`. Only its
        sender sends it (403 otherwise). Also needs `envelopes:write` and `envelopes:send`.
      x-permission: "bulk.send"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/BulkSendWithRows'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/bulk-sends/{id}/cancel:
    parameters:
      - name: id
        in: path
        required: true
        description: A bulk send of the caller's (or, for an administrator, any)
        schema: {type: string}
    post:
      operationId: cancelBulkSend
      summary: "Cancel a bulk send: its pending rows are not sent; sent envelopes stay (409 CS-WF-0001 once finished)"
      x-permission: "bulk.send"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/BulkSendWithRows'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/groups:
    get:
      operationId: listGroups
      summary: "The account's groups with member counts, for sharing templates (UXW-06)"
      x-permission: "templates.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/GroupList'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: createGroup
      summary: "Make a group of members (UXW-07); a name the account uses is 422 `exists` at /name"
      x-permission: "groups.manage"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/GroupName'}
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Group'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/groups/{id}:
    parameters:
      - name: id
        in: path
        required: true
        description: A group of this account (another account's is 404)
        schema: {type: string}
    get:
      operationId: getGroup
      summary: "A group with its members' user ids"
      x-permission: "groups.manage"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Group'}
        default: {$ref: '#/components/responses/Problem'}
    patch:
      operationId: renameGroup
      summary: "Rename a group"
      x-permission: "groups.manage"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/GroupName'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Group'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: deleteGroup
      summary: "Delete a group; its template shares go with it"
      x-permission: "groups.manage"
      x-level: workspace
      responses:
        '204': {description: Deleted}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/groups/{id}/members:
    parameters:
      - name: id
        in: path
        required: true
        description: A group of this account (another account's is 404)
        schema: {type: string}
    put:
      operationId: setGroupMembers
      summary: "Make the group's members exactly these members of the account"
      description: >-
        Each id must be a member of this account (422 at `/user_ids/{i}` otherwise);
        a repeated id counts once. Each member added or removed is its own admin event.
      x-permission: "groups.manage"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/GroupMembers'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Group'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/permission-profiles:
    get:
      operationId: listPermissionProfiles
      summary: "The built-in profiles, then the custom ones, with what each grants and how many members hold it (UXW-07)"
      x-permission: "users.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/PermissionProfileList'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: createPermissionProfile
      summary: "Make a custom permission profile"
      description: >-
        Its permissions are scopes of docs/40 §2, `view_all_envelopes` and workspace
        actions (ORG-07); none may go beyond the caller's own, nor its group scope beyond
        the caller's, nor a sensitive action with a group scope (403 CS-ORG-0005). A name
        the account uses is 422 `exists` at /name.
      x-permission: "profiles.manage"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/PermissionProfileCreate'}
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema: {$ref: '#/components/schemas/PermissionProfile'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/permission-profiles/{id}:
    parameters:
      - name: id
        in: path
        required: true
        description: A permission profile of this account (another account's is 404)
        schema: {type: string}
    get:
      operationId: getPermissionProfile
      summary: "A permission profile"
      x-permission: "users.read"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/PermissionProfile'}
        default: {$ref: '#/components/responses/Problem'}
    patch:
      operationId: updatePermissionProfile
      summary: "Change a custom profile; its members hold the new permissions from their next request"
      description: >-
        A built-in profile is 409 CS-WF-0001. The profile as it was and as it becomes
        must both be within the caller's rights and scope, and never the caller's own
        profile (403 CS-ORG-0005). Giving sending to
        more members is checked against the plan's seats (CS-PLAN-0003).
      x-permission: "profiles.manage"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/PermissionProfilePatch'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/PermissionProfile'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: deletePermissionProfile
      summary: "Delete a custom profile no member holds (409 CS-WF-0001 for a built-in or a held one)"
      x-permission: "profiles.manage"
      x-level: workspace
      responses:
        '204': {description: Deleted}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/signing-providers:
    get:
      operationId: listSigningProviders
      summary: "Signing providers the operator offers this account (RSP-01, ADR-046)"
      description: >-
        The providers of the operator's catalogue offered to this account, each with whether the account
        enabled it. A sender may name an enabled one as a signer's `signature.provider_id`.
      x-permission: "envelopes.write"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/SigningProviderList'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/signing-providers/{id}:
    parameters:
      - name: id
        in: path
        required: true
        description: The catalogue's provider id
        schema: {type: string}
    get:
      operationId: getSigningProvider
      summary: "A provider's settings for this account (404 when not offered)"
      x-permission: "settings.signing"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/SigningProviderSettings'}
        default: {$ref: '#/components/responses/Problem'}
    put:
      operationId: putSigningProvider
      summary: "Enable or disable a provider and set its options"
      description: >-
        Each change is a `workspace.signing_provider_changed` admin event; an own client secret is recorded only as
        `rotated` or `removed`.
      x-permission: "settings.signing"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/SigningProviderIn'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/SigningProviderSettings'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/webhooks:
    get:
      operationId: listWebhooks
      summary: "Webhook subscriptions"
      x-permission: "webhooks.manage"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/WebhookList'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: createWebhook
      summary: "Subscribe (public HTTPS URLs only)"
      x-permission: "webhooks.manage"
      x-level: workspace
      parameters:
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/WebhookCreate'}
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Webhook'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/webhooks/{id}:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: getWebhook
      summary: "A subscription"
      x-permission: "webhooks.manage"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Webhook'}
        default: {$ref: '#/components/responses/Problem'}
    patch:
      operationId: patchWebhook
      summary: "Edit, pause or resume a subscription (UXW-31)"
      description: >-
        `{url?, event_types?, active?}`; `active: false` pauses, `true` resumes. A new URL
        must be public HTTPS (`422 CS-API-0013`, SEC-W01).
      x-permission: "webhooks.manage"
      x-level: workspace
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/Object'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Webhook'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: deleteWebhook
      summary: "Disable a subscription"
      x-permission: "webhooks.manage"
      x-level: workspace
      responses:
        '204': {description: Done}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/webhooks/{id}/deliveries:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    get:
      operationId: listDeliveries
      summary: "A subscription's deliveries"
      x-permission: "webhooks.manage"
      x-level: workspace
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/webhooks/{id}/test:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
    post:
      operationId: testWebhook
      summary: "Send a test event through the worker (UXW-32)"
      description: >-
        Records a `webhook.test` delivery (ids only) and queues it; the worker signs and
        sends it as any delivery (SEC-W01 at connect time) and records the answer in the
        delivery log. `202` with the delivery as recorded; a paused or disabled
        subscription is `409 CS-API-0009`.
      x-permission: "webhooks.manage"
      x-level: workspace
      responses:
        '202':
          description: Accepted
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
  /api/v1/webhooks/{id}/deliveries/{delivery}/redeliver:
    parameters:
      - name: id
        in: path
        required: true
        description: Object id (UUIDv7)
        schema: {type: string}
      - name: delivery
        in: path
        required: true
        description: Delivery id (UUIDv7)
        schema: {type: string}
    post:
      operationId: redeliverWebhook
      summary: "Deliver one delivery's event again (UXW-33)"
      description: >-
        The same event id and payload, through the worker; the URL is checked again
        (SEC-W01). `202` with the delivery back to `pending`; a paused or disabled
        subscription is `409 CS-API-0009`.
      x-permission: "webhooks.manage"
      x-level: workspace
      responses:
        '202':
          description: Accepted
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Object'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    get:
      operationId: ceremonyView
      summary: "Recipient's view (ceremony; not public API)"
      description: "With `Accept: text/html` and not `application/json` (a browser opening the link), the web app's signing page, which checks nothing and records nothing; otherwise the view as JSON."
      security: []
      x-permission: public
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
            text/html:
              schema: {type: string}
        default: {$ref: '#/components/responses/Problem'}
  /e/{token}:
    parameters:
      - name: token
        in: path
        required: true
        description: Embedded view link token (secret)
        schema: {type: string}
    get:
      operationId: embedViewPage
      summary: "The embedded prepare or correct page (VS-09)"
      description: >-
        `embed.html`, whose `frame-ancestors` is the view's frame origin while it is
        among the workspace's `embedding_origins` (else the list, else `'none'`). Serving
        it spends nothing.
      security: []
      x-permission: public
      responses:
        '200':
          description: The page
          content:
            text/html:
              schema: {type: string}
        default: {$ref: '#/components/responses/Problem'}
  /e/{token}/session:
    parameters:
      - name: token
        in: path
        required: true
        description: Embedded view link token (secret)
        schema: {type: string}
    post:
      operationId: embedViewSession
      summary: "Spend the view link once and get its session (VS-09)"
      description: >-
        An unknown, expired or already spent link, a revoked client or a removed member
        is `401 CS-AUTH-0002`.
      security: []
      x-permission: public
      requestBody:
        required: false
        content:
          application/json:
            schema: {type: object}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/EmbedSession'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/session:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonySession
      summary: "Bind the link to this browser and record the opening"
      security: []
      x-permission: public
      requestBody:
        required: false
        content:
          application/json:
            schema: {$ref: '#/components/schemas/LocationRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/consent:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyConsent
      summary: "Accept the electronic record disclosure"
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/ConsentRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/authenticate:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyAuthenticate
      summary: "Access code"
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/AuthenticateRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/otp:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyOtpSend
      summary: "Send a one-time code"
      description: >-
        Sends the recipient a 6-digit code (SEC-A02) for `method`: by email (`email_otp`,
        the default), by SMS (`sms_otp`) or read aloud in a voice call (`voice_otp`) to
        the recipient's phone (slice 5), when the sender required that method. The
        worker draws the code and stores only its Argon2id hash; it works once, for 10
        minutes, and asking again (by any method) replaces it. Limited per link and per
        address or phone number (3 a minute) and per recipient (30 seconds apart, 5 an
        hour): `CS-API-0003` with `Retry-After`. `CS-API-0014` when the recipient does
        not require that method; `CS-API-0009` once it has passed. Without an SMS and
        voice provider on the worker such a code is never sent (`CS-WRK-0013`).
      security: []
      x-permission: public
      requestBody:
        required: false
        content:
          application/json:
            schema: {$ref: '#/components/schemas/OtpSendRequest'}
      responses:
        '202':
          description: Accepted; the code is on its way
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/otp/verify:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyOtpVerify
      summary: "Check a one-time code"
      description: >-
        `200` with the view when the code matches the open, unexpired code, whichever
        method sent it (the code is then spent and that method passed); a `method` other
        than the open code's fails; `403` with the view otherwise (wrong, expired, replaced or already used),
        recorded as a failed attempt. The account's `max_auth_attempts` failures lock the
        recipient and revoke the link (`CS-AUTH-0004`, then `CS-AUTH-0002`); five wrong
        tries spend a code.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/OtpVerifyRequest'}
      responses:
        '200':
          description: Passed
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        '403':
          description: Not passed
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/remote-signing:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    get:
      operationId: ceremonyRemoteSigningStatus
      summary: "The recipient's remote signing session"
      description: >-
        RSP-01 (ADR-046): the view with `remote_signing`, the recipient's latest session
        (null when none). A session open past its time is failed `expired` first. The
        signing page polls it while the worker prepares and signs.
      security: []
      x-permission: public
      responses:
        '200':
          description: The view with `remote_signing`
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
    post:
      operationId: ceremonyRemoteSigningStart
      summary: "Start signing with the recipient's remote signing provider"
      description: >-
        RSP-01 (ADR-046 §3.4): for a signer whose signature type is `remote`, once every
        required field has its value. Records `recipient.remote_signing_started` (values
        frozen while the session is open), opens a session with a new `state` (kept only
        as SHA-256) and a PKCE S256 verifier (sealed under the provider secrets key), and
        answers the view with `remote_authorization_url`, the provider's authorization
        endpoint with scope `service`. The session ends after the provider's
        `session_minutes` (15 by default). `409 CS-RSP-0007` for a recipient who is not a
        remote signer or while another remote session is open in the envelope;
        `409 CS-RSP-0001` when the provider is no longer offered or enabled;
        `CS-API-0003` past 5 a minute per link.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/RemoteStartRequest'}
      responses:
        '200':
          description: Started; send the browser to `remote_authorization_url`
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/remote-signing/callback:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyRemoteSigningCallback
      summary: "The provider's answer, brought back by the signing page"
      description: >-
        RSP-01: the `state` must be the open session's, for the step it was sent for
        (`authorizing_service` or `authorizing_credential`), within its time; it is spent
        once. The code is sealed with the PKCE verifier for the worker, which is queued
        (`remote_signing`: prepare after the first, sign after the second). An `error`
        fails the session (`access_denied`: `cancelled`; otherwise `provider_refused`).
        Anything else is `409 CS-RSP-0003` and nothing is kept.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/RemoteCallbackRequest'}
      responses:
        '200':
          description: Taken; the view with `remote_signing`
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/remote-signing/authorize:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyRemoteSigningAuthorize
      summary: "Authorize the prepared documents at the provider"
      description: >-
        RSP-01: once the session is `prepared`, a new `state` and PKCE verifier and the
        view with `remote_authorization_url`, scope `credential`, binding the chosen
        credential, the number of signatures and the exact hashes to be signed (SCAL2).
        `409 CS-RSP-0003` in any other step.
      security: []
      x-permission: public
      responses:
        '200':
          description: Send the browser to `remote_authorization_url`
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/remote-signing/cancel:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyRemoteSigningCancel
      summary: "Stop the open remote signing session"
      description: >-
        RSP-01: fails the open session `cancelled` (`recipient.remote_signing_failed`);
        the recipient's values are free again and they may start again. Nothing is ever
        signed another way. `409 CS-RSP-0003` when no session is open.
      security: []
      x-permission: public
      responses:
        '200':
          description: Cancelled; the view with `remote_signing`
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/remote-signing/documents/{id}:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
      - name: id
        in: path
        required: true
        description: Document id
        schema: {type: string}
    get:
      operationId: ceremonyRemoteSigningDocument
      summary: "A prepared document's exact bytes"
      description: >-
        RSP-01 (ADR-046 §3.3): while the session is open and prepared, the exact bytes
        whose hash the signer authorizes (the document with the signature slot, before the
        signature is embedded). `409 CS-RSP-0003` with no open session; `404` for a
        document not prepared.
      security: []
      x-permission: public
      responses:
        '200':
          description: The prepared PDF
          content:
            application/pdf:
              schema: {type: string, format: binary}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/remote-signing/esign:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    get:
      operationId: ceremonyEsignHandoff
      summary: "Hand the signed eSign request to the ESP"
      description: >-
        RSP-02 (ADR-047 §3.1): once `POST …/remote-signing/authorize` armed a document, a
        small page whose form posts the ASP's signed request to the ESP in a top-level
        navigation (its Content Security Policy lets the form reach that ESP only). The
        signer gives their Aadhaar number or VID and OTP or biometrics to the ESP on the
        ESP's page; OpenSeal never receives them. `409 CS-RSP-0003` with no armed session.
      security: []
      x-permission: public
      responses:
        '200':
          description: The hand-off page
          content:
            text/html:
              schema: {type: string}
        default: {$ref: '#/components/responses/Problem'}
  /rsp/esign/{provider}/response:
    parameters:
      - name: provider
        in: path
        required: true
        description: The catalogue's eSign provider id
        schema: {type: string, pattern: '^[a-z0-9][a-z0-9-]{0,31}$'}
    post:
      operationId: esignResponse
      summary: "An ESP's answer"
      description: >-
        RSP-02 (ADR-047 §3.4, §3.6): where the ESP sends the browser (v2.1) with its
        `EsignResp`, in the form field the catalogue names or as `application/xml`. Public:
        it is rate-limited per provider and address, refuses a body over 1 MiB, reads the
        answer within the eSign limits (512 KiB, depth 16, 256 elements, no DTD or
        entities) and verifies its XML Signature under the ESP's configured certificate;
        the `txn` must name an open session's armed document, whose single-use state the
        answer spends. A forged, wrapped, late, replayed or duplicate answer changes
        nothing and is logged as a security event. Every case answers `303` to
        `{OPENSEAL_PUBLIC_URL}/s/rsp?state=esign`, the same for a known `txn` or not.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema: {type: object, additionalProperties: {type: string}}
          application/xml:
            schema: {type: string}
      responses:
        '303':
          description: Back to the signing page
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/sso:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonySsoStart
      summary: "Start signing in through an identity provider"
      description: >-
        For a recipient whose sender required `sso` (slice 5, RAUTH-01): opens a sign-in
        at one of the operator's OpenID Connect providers (listed in the view's
        `sso_providers`) and answers the view with `sso_authorization_url`, the
        provider's authorization endpoint with `state`, `nonce` and a PKCE S256
        challenge. The server keeps the nonce and verifier, and `state` only as a hash;
        a newer sign-in replaces an open one, and each works for 10 minutes. Records
        `recipient.auth_challenged` (`sso`). `CS-API-0014` when `sso` is not required or
        the server has no provider; `422` for a provider it does not list; `CS-API-0009`
        once `sso` has passed; `CS-API-0003` past 5 a minute per link.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/SsoStartRequest'}
      responses:
        '200':
          description: Started; send the browser to `sso_authorization_url`
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/sso/verify:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonySsoVerify
      summary: "Finish signing in through an identity provider"
      description: >-
        Takes the `state` and `code` the provider sent the browser back with (to the
        redirect URI, `/s/oidc` by default). The sign-in for that `state` closes whatever
        happens, so a replay fails. The code is exchanged with the PKCE verifier, and the
        ID token must be signed by a key in the provider's JWKS with an asymmetric
        algorithm, name the provider as issuer and the server's client as audience, be
        unexpired, carry the sign-in's nonce, and assert a verified email equal to the
        recipient's. `200` with the view on a pass, recorded as `recipient.auth_passed`
        (`sso`) with the issuer and the SHA-256 of the subject; `403` with the view
        otherwise, recorded as a failed attempt and counted to the account's
        `max_auth_attempts`. `502 CS-API-0016` when the provider cannot be reached; that
        counts nothing.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/SsoVerifyRequest'}
      responses:
        '200':
          description: Passed
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        '403':
          description: Not passed
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/documents/{doc}/content:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
      - name: doc
        in: path
        required: true
        description: Document id
        schema: {type: string}
    get:
      operationId: ceremonyDocument
      summary: "The document as delivered"
      description: >-
        Only in the browser the link is bound to, once the recipient has passed every
        authentication they need and, when the account requires a disclosure, consented
        to it (403 CS-AUTH-0003, CS-AUTH-0004 or CS-AUTH-0005 before; SEC-CER-01).
      security: []
      x-permission: public
      responses:
        '200':
          description: PDF
          content:
            application/pdf:
              schema: {type: string, format: binary}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/document:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    get:
      operationId: ceremonyDownload
      summary: "After finishing: the sealed document once complete, else a preview of the values so far (WEB-06)"
      description: >-
        Only for a recipient who has finished (`409 CS-API-0009` before), in the browser the
        link is bound to, while the link is valid. `doc` may be left out when the envelope has
        one document. Recorded as `document.downloaded`; `X-OpenSeal-Document` says `sealed`
        or `preview`.
      security: []
      x-permission: public
      parameters:
        - name: doc
          in: query
          required: false
          description: Document id
          schema: {type: string}
      responses:
        '200':
          description: PDF
          content:
            application/pdf:
              schema: {type: string, format: binary}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/certificate:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    get:
      operationId: ceremonyCertificate
      summary: "After completion: the certificate of completion, the same sealed PDF the sender downloads (VS-01)"
      description: >-
        Only for a recipient who has finished, once the envelope is `completed` (`409
        CS-API-0009` before), in the browser the link is bound to, while the link is valid
        (the completion email's link is a fresh one). Recorded as `certificate.downloaded`.
      security: []
      x-permission: public
      responses:
        '200':
          description: PDF
          content:
            application/pdf:
              schema: {type: string, format: binary}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/documents/{doc}/viewed:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
      - name: doc
        in: path
        required: true
        description: Document id
        schema: {type: string}
    post:
      operationId: ceremonyViewed
      summary: "Pages viewed"
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/ViewedRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/adopt:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyAdopt
      summary: "Adopt a signature or initials"
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/AdoptRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/editor/fields:
    parameters:
      - {name: token, in: path, required: true, description: Ceremony link token (secret), schema: {type: string}}
    post:
      operationId: ceremonyPlaceFields
      summary: "Add fields (editor, VS-06A)"
      description: >-
        An editor ("Allow to edit") adds fields during their turn, each in the API's
        wire form (`recipient_id`, `document_id`, `type`, the rectangle), for themself or
        for a recipient later in the routing order not yet reached (the view's
        `later_recipients`), on a document they see; at most 100 per call. Recorded as
        `envelope.corrected` with the recipient as actor. Any other recipient type, or a
        field for a recipient routing has reached, is refused (`409 CS-WF-0001`).
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [fields]
              additionalProperties: false
              properties:
                fields: {type: array, minItems: 1, maxItems: 100, items: {type: object}}
                location: {type: object}
      responses:
        '201':
          description: The ceremony view
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/editor/fields/{field}:
    parameters:
      - {name: token, in: path, required: true, description: Ceremony link token (secret), schema: {type: string}}
      - {name: field, in: path, required: true, description: Field id, schema: {type: string}}
    patch:
      operationId: ceremonyEditField
      summary: "Move or change a field (editor, VS-06A)"
      description: >-
        An editor ("Allow to edit") moves, resizes or changes a field of their own or of
        a recipient later in the routing order not yet reached, as a JSON merge of the
        field's wire form; `page`, `x`, `y`, `width` and `height` may be given flat and
        merge into the placement. Recorded as `envelope.corrected` with the recipient as
        actor. Any other recipient type, or a field naming a recipient routing has
        reached, is refused (`409 CS-WF-0001`); a field not found or on a document hidden
        from them is `404`.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {type: object}
      responses:
        '200':
          description: The ceremony view
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
    delete:
      operationId: ceremonyRemoveField
      summary: "Remove a field (editor, VS-06A)"
      description: >-
        An editor removes a field of their own or of a recipient later in the routing
        order not yet reached; refused as `PATCH` is. `application/json` like every
        ceremony write; the body may be `{}`.
      security: []
      x-permission: public
      responses:
        '200':
          description: The ceremony view
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/fields/{field}:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
      - name: field
        in: path
        required: true
        description: Field id
        schema: {type: string}
    put:
      operationId: ceremonyFill
      summary: "Set a field's value"
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/FillRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/fields/{field}/attachment:
    parameters:
      - {name: token, in: path, required: true, description: Ceremony link token (secret), schema: {type: string}}
      - {name: field, in: path, required: true, description: The recipient's attachment field, schema: {type: string}}
    put:
      operationId: ceremonyAttach
      summary: "Attach a file (PDF, PNG or JPEG, at most 10 MiB) to an attachment field (WEB-06)"
      description: >-
        A PDF is admitted by the bounded reader (nothing in it run or followed); images by
        their signature. Stored write-once; the field's value is `{"attachment": "<sha256 hex>"}`,
        which the chain's `recipient.field_completed` binds and the certificate of completion
        lists. The sealed document is not changed by it. An attachment value can be given
        to `/fields/{field}` or `/finish` only as uploaded here.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [content_base64]
              additionalProperties: false
              properties:
                content_base64: {type: string}
      responses:
        '200':
          description: The ceremony view
          content:
            application/json:
              schema: {type: object}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/finish:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyFinish
      summary: "Sign or complete"
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/FinishRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/paper:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonySignOnPaper
      summary: "Sign on paper: upload the scan of the documents signed by hand (FG-013, ADR-043)"
      description: >-
        On an envelope whose `signing_options.allow_sign_on_paper` is on, a signer whose turn
        it is, authenticated and consented, uploads the scan of the documents they printed
        and signed by hand (a PDF, at most the document size limit). It is screened,
        admitted and normalized like any upload and added to the envelope as a fixed
        document named "Signed on paper.pdf", so the seal covers it; the chain records
        `document.added`, `document.admitted`, `document.fixed`, then
        `recipient.signed_on_paper {recipient_id, documents, document_id, upload_hash}` and
        `recipient.completed`. Off is `409 CS-WF-0012`; not a signer, not their turn or
        already finished `409`; not a PDF `422`.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [content_base64]
              properties:
                content_base64: {type: string, description: 'The scan, a PDF, base64'}
                location: {$ref: '#/components/schemas/LocationRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/recipients:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyNameRecipients
      summary: "Name later recipients (agent, intermediary, editor; VS-02)"
      description: >-
        An agent supplies the name and email of recipients later in the routing order who
        have not been reached yet (the view's `later_recipients`), then finishes with
        `POST /s/{token}/finish`. An intermediary or editor may call it too. Any other
        recipient type is refused (`409`); a recipient of the caller's own order or
        earlier, or one already reached, is refused by the workflow (`403`). An
        intermediary or editor may also set `phone`, `auth` and an `access_code` (VS-06A;
        the code stored as Argon2id, never answered). The change is
        recorded as `envelope.corrected` with the recipient as actor. At most 100
        recipients per call.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/NameRecipientsRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/approve:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyApprove
      summary: "Approve"
      security: []
      x-permission: public
      requestBody:
        required: false
        content:
          application/json:
            schema: {$ref: '#/components/schemas/LocationRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/decline:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyDecline
      summary: "Decline"
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/DeclineRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/withdraw-consent:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyWithdrawConsent
      summary: "Withdraw consent to electronic records (declines a required action)"
      security: []
      x-permission: public
      requestBody:
        required: false
        content:
          application/json:
            schema: {$ref: '#/components/schemas/LocationRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/finish-later:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyFinishLater
      summary: "Finish later"
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/Object'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/reassign:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    post:
      operationId: ceremonyReassign
      summary: "Hand the part to someone else (when allow_reassign; WEB-07)"
      description: >-
        Only while the envelope's `signing_options.allow_reassign` is on and this recipient
        has a required action not yet finished (`409` otherwise). The new recipient takes
        the same routing order and fields (values cleared) and is invited when their turn
        comes; this link stops working at once; `recipient.reassigned` is recorded with
        the reason and, when the envelope captures location, where.
      security: []
      x-permission: public
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/ReassignRequest'}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyView'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/history:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    get:
      operationId: ceremonyHistory
      summary: "The envelope's history as this recipient may see it (WEB-07)"
      description: >-
        Events this recipient acted in or that concern them, and the envelope's milestones
        (sent, corrected, voided, declined, expired, completing, completed) from the first
        `envelope.sent` on, so a draft's own edits never show as a correction, oldest first,
        as `{seq, type, at, by}` only: no other person's name, address, IP, user agent or
        location, and no values. Only in the bound browser, after every required
        authentication and, when the account has a disclosure, consent (`403` before).
        Records nothing.
      security: []
      x-permission: public
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyHistory'}
        default: {$ref: '#/components/responses/Problem'}
  /s/{token}/disclosure:
    parameters:
      - name: token
        in: path
        required: true
        description: Ceremony link token (secret)
        schema: {type: string}
    get:
      operationId: ceremonyDisclosure
      summary: "The full disclosure (ERSD) the view's consent_required names (UXW-34)"
      description: >-
        The account's published text for its current disclosure, found by the hash consent
        records and re-checked as it is read. `404` when the account requires no disclosure
        or has published no text for it. Only in the bound browser, after every required
        authentication (`403` before), as consent; still readable after finishing or
        declining while the link is valid. Records nothing.
      security: []
      x-permission: public
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CeremonyDisclosure'}
        default: {$ref: '#/components/responses/Problem'}
