openapi: 3.1.0
info:
  title: CPAPI optional provider demo module
  version: 1.0.0
  summary: Provider-owned virtual play on the studio's registered Control origin
  description: |
    A studio may adopt cpapi-demo.v1 for a specific environment, endpoint revision
    and active Control credential revision. A title is eligible only when its
    current published catalog entry explicitly declares has_demo true.
    The studio owns the virtual balance and display units. The platform supplies
    no wallet, player, currency, amount or Money authorization.
    Requests use the existing HMAC-SHA256 Control signing credential, including
    nonce and environment binding. Operation and exact raw path select the covered fields.
    Responses use authenticated HTTPS. No response signature is specified.
security:
  - ControlSignature: []
paths:
  /v1/demo-sessions:
    post:
      operationId: createDemoSession
      summary: Open a virtual-play session
      description: |
        The authenticated Control key identifies the studio and environment.
        Reject a command for another integration, environment or ineligible game.
        Atomically bind the exact key to this typed command and demo UUID before
        issuing a launch URL. An exact active replay returns the existing receipt.
        During the module's retention window, a conflicting command or a new key
        for the same ID conflicts. A closed or expired record cannot be reopened.
      x-cpapi-covered-components: ['@method', '@authority', '@path', content-digest, idempotency-key]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/DemoCommand' }
      responses:
        '201':
          description: An active demo on a registered launch host
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ActiveDemo' }
        '400': { $ref: '#/components/responses/Problem' }
        '401': { $ref: '#/components/responses/Problem' }
        '403': { $ref: '#/components/responses/Problem' }
        '404': { $ref: '#/components/responses/Problem' }
        '409':
          description: idempotency_fingerprint_conflict or idempotency_window_expired
          content:
            application/problem+json:
              schema: { $ref: '#/components/schemas/Problem' }
        default: { $ref: '#/components/responses/Problem' }
  /v1/demo-session-recovery:
    get:
      operationId: recoverDemoSession
      summary: Recover by the exact original signed key
      description: |
        Send a bodyless GET with a fresh nonce after an uncertain POST. Return
        the recorded demo in this credential's scope, or session_invalid for a
        known absence. An absence, timeout or malformed receipt never grants
        permission to submit the original create again automatically.
      x-cpapi-covered-components: ['@method', '@authority', '@path', idempotency-key]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      responses:
        '200': { $ref: '#/components/responses/Receipt' }
        '404': { $ref: '#/components/responses/Absent' }
        default: { $ref: '#/components/responses/Problem' }
  /v1/demo-sessions/{demo_session_id}:
    get:
      operationId: readDemoSession
      summary: Read one demo in the credential's studio and environment
      x-cpapi-covered-components: ['@method', '@authority', '@path']
      parameters:
        - name: demo_session_id
          in: path
          required: true
          schema: { $ref: '#/components/schemas/DemoId' }
      responses:
        '200': { $ref: '#/components/responses/Receipt' }
        '404': { $ref: '#/components/responses/Absent' }
        default: { $ref: '#/components/responses/Problem' }
components:
  securitySchemes:
    ControlSignature:
      type: apiKey
      in: header
      name: Signature
      description: RFC 9421 HMAC-SHA256 Control signature with Signature-Input and a signed RFC 9530 Content-Digest on POST.
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: true
      description: Exactly one field occurrence. Accept its exact visible ASCII bytes without normalization.
      schema: { type: string, minLength: 1, maxLength: 255, pattern: '^[!-~]{1,255}(?![\s\S])' }
  responses:
    Receipt:
      description: Current state of the exact requested demo
      content:
        application/json:
          schema:
            oneOf:
              - $ref: '#/components/schemas/ActiveDemo'
              - $ref: '#/components/schemas/InactiveDemo'
    Absent:
      description: Registered session_invalid problem for absence in the authenticated module scope
      content:
        application/problem+json:
          schema:
            allOf:
              - $ref: '#/components/schemas/Problem'
              - properties: { code: { const: session_invalid }, status: { const: 404 } }
                required: [code, status]
    Problem:
      description: Registered CPAPI problem
      content:
        application/problem+json:
          schema: { $ref: '#/components/schemas/Problem' }
  schemas:
    Problem:
      $ref: '../../../p0/machine-schemas/schemas/problem.schema.json#/$defs/Problem'
    DemoId:
      type: string
      format: uuid
      pattern: '^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}(?![\s\S])'
    WireId:
      type: string
      pattern: '^[A-Za-z0-9._:-]{1,128}(?![\s\S])'
    Scope:
      type: object
      required: [module, demo_session_id, integration_id, environment, game_id]
      properties:
        module: { const: cpapi-demo.v1 }
        demo_session_id: { $ref: '#/components/schemas/DemoId' }
        integration_id: { $ref: '#/components/schemas/WireId', description: Registered provider integration identity }
        environment: { type: string, enum: [certification, live] }
        game_id: { $ref: '#/components/schemas/WireId', description: Case-sensitive upstream catalog game identifier }
    DemoCommand:
      type: object
      allOf: [{ $ref: '#/components/schemas/Scope' }]
      unevaluatedProperties: false
      properties:
        locale:
          type: string
          minLength: 1
          maxLength: 64
          pattern: '^(?![\s\S]*[\u0000-\u001f\u007f-\u009f\uD800-\uDFFF])(?=[\s\S]*[\S\uFEFF])'
          description: Optional nonblank display-language preference, carried verbatim as Unicode scalar values.
    Timestamp:
      type: string
      format: date-time
      pattern: '^\d{4}-\d\d-\d\dT(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d{1,6})?Z(?![\s\S])'
      description: A valid UTC calendar instant. The expiry cannot exceed the platform's original issue instant plus 15 minutes.
    ActiveDemo:
      type: object
      allOf: [{ $ref: '#/components/schemas/Scope' }]
      unevaluatedProperties: false
      required: [state, expires_at, launch_url]
      properties:
        state: { const: active }
        expires_at: { $ref: '#/components/schemas/Timestamp' }
        launch_url:
          type: string
          format: uri
          minLength: 12
          maxLength: 2048
          pattern: '^https://'
          description: |
            An HTTPS URL on an exact registered DNS launch host. Reject userinfo,
            IP literals, fragments, whitespace, controls and backslashes. Apply
            the 2048-byte limit before exposing it to the caller. The studio
            expires the launcher at expires_at. Active receipts must still be valid.
    InactiveDemo:
      type: object
      allOf: [{ $ref: '#/components/schemas/Scope' }]
      unevaluatedProperties: false
      required: [state, expires_at]
      properties:
        state: { type: string, enum: [expired, closed] }
        expires_at: { $ref: '#/components/schemas/Timestamp' }
