openapi: 3.1.0
info:
  title: seal.club API
  version: 0.1.0-demo
  summary: Demo API contract for PDF sealing jobs.
  description: |
    Rudimentary OpenAPI description for the sandbox docs demo. Payloads and schemas
    are illustrative until the production API and generated SDKs are finalized.
servers:
  - url: https://api.sandbox.example.com/v1
    description: Sandbox example domain
  - url: https://api.example.com/v1
    description: Production example domain
security:
  - bearerAuth: []
paths:
  /jobs/seal:
    post:
      operationId: createSealJob
      summary: Create a PDF sealing job
      description: Upload a PDF or reference a hardened source URL, then queue a sealing job.
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - file
                - visibility
              properties:
                file:
                  type: string
                  format: binary
                  description: PDF to seal. Mutually exclusive with `source_url`.
                visibility:
                  $ref: '#/components/schemas/Visibility'
                purpose:
                  type: string
                  description: Free-form label used for quotas, analytics, and support.
                preserve_metadata:
                  type: boolean
                  default: false
                customer_reference:
                  type: string
                  description: Opaque value echoed in receipts and webhooks.
                mode:
                  $ref: '#/components/schemas/JobMode'
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSealJobRequest'
      responses:
        '202':
          description: Job accepted for asynchronous sealing.
          headers:
            Seal-Trace-Id:
              schema:
                type: string
              description: Correlation id for support and logging.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SealJob'
        '400':
          $ref: '#/components/responses/Error'
        '401':
          $ref: '#/components/responses/Error'
        '409':
          $ref: '#/components/responses/Error'
        '429':
          $ref: '#/components/responses/Error'
        '503':
          $ref: '#/components/responses/Error'
  /jobs/{job_id}:
    get:
      operationId: getSealJob
      summary: Fetch sealing job status
      parameters:
        - $ref: '#/components/parameters/JobId'
      responses:
        '200':
          description: Current job state.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SealJob'
        '404':
          $ref: '#/components/responses/Error'
  /jobs/{job_id}/receipt.json:
    get:
      operationId: getSealReceipt
      summary: Download sealing receipt
      parameters:
        - $ref: '#/components/parameters/JobId'
      responses:
        '200':
          description: Tamper-evident JSON receipt for a completed job.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SealReceipt'
        '404':
          $ref: '#/components/responses/Error'
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: seal.club API key
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema:
        type: string
        minLength: 8
        maxLength: 128
      description: Replay-safe key retained for forty-eight hours.
    JobId:
      name: job_id
      in: path
      required: true
      schema:
        type: string
        pattern: '^job_[A-Za-z0-9]+$'
  responses:
    Error:
      description: Machine-readable error envelope.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
  schemas:
    CreateSealJobRequest:
      type: object
      required:
        - source_url
        - checksum_sha256
        - visibility
      properties:
        source_url:
          type: string
          format: uri
        checksum_sha256:
          type: string
          pattern: '^[A-Fa-f0-9]{64}$'
        visibility:
          $ref: '#/components/schemas/Visibility'
        purpose:
          type: string
        preserve_metadata:
          type: boolean
          default: false
        customer_reference:
          type: string
        mode:
          $ref: '#/components/schemas/JobMode'
    JobMode:
      type: string
      enum:
        - async
        - blocking
      default: async
    Visibility:
      type: string
      enum:
        - private
        - organization
        - partner
    SealJob:
      type: object
      required:
        - id
        - phase
        - environment
        - trace_id
      properties:
        id:
          type: string
          examples:
            - job_014b7c
        phase:
          type: string
          enum:
            - queued
            - hashing
            - sealing
            - completed
            - failed
        environment:
          type: string
          examples:
            - env_sandbox_01
        trace_id:
          type: string
        receipt_url:
          type: string
          format: uri
        capabilities:
          type: array
          items:
            type: string
    SealReceipt:
      type: object
      required:
        - job_id
        - algorithm
        - document_sha256
        - receipt_sha512
        - sealed_at
      properties:
        job_id:
          type: string
        algorithm:
          type: string
          examples:
            - sealclub-pdf-v1
        document_sha256:
          type: string
        receipt_sha512:
          type: string
        kms_key_id:
          type: string
        sealed_at:
          type: string
          format: date-time
        customer_reference:
          type: string
    ErrorEnvelope:
      type: object
      required:
        - request_id
        - error
      properties:
        request_id:
          type: string
        error:
          type: object
          required:
            - type
            - code
            - message
          properties:
            type:
              type: string
            code:
              type: string
            message:
              type: string
            doc_url:
              type: string
              format: uri-reference
