# Proposed event contract, version 1 (AsyncAPI 3.0): the events this system publishes, their consumers, payloads and delivery
# guarantees, and the events it consumes. Status: proposal for review, not confirmed design.
asyncapi: 3.0.0
info:
  title: News Events
  version: 1.0.0
  description: 'Articles published, changed and unpublished. Inside news they start the build of the public site.
    Envelope, delivery guarantees and webhook headers: `common/v1/events.yaml`. Status: proposal for review, not
    confirmed design.'
defaultContentType: application/cloudevents+json
servers:
  prod:
    host: pubsub.googleapis.com
    protocol: googlepubsub
    description: Pub/Sub in the project that hosts the system, prod.
  stage:
    host: pubsub.googleapis.com
    protocol: googlepubsub
    description: Pub/Sub in the project that hosts the system, stage.
channels:
  news.events.v1:
    address: news.events.v1
    description: Every event news publishes. Consumers filter by the `ce-type` attribute.
    messages:
      article_published_v1:
        $ref: '#/components/messages/article_published_v1'
      article_updated_v1:
        $ref: '#/components/messages/article_updated_v1'
      article_unpublished_v1:
        $ref: '#/components/messages/article_unpublished_v1'
    bindings:
      googlepubsub:
        messageRetentionDuration: 604800s
        schemaSettings:
          encoding: json
          name: projects/moonitoring-<env>-<project>/schemas/news.events.v1
operations:
  publish_article_published_v1:
    action: send
    channel:
      $ref: '#/channels/news.events.v1'
    messages:
    - $ref: '#/channels/news.events.v1/messages/article_published_v1'
    summary: An article was published, or its scheduled time came; the site is rebuilt with it.
    x-moonitoring-producer: news
    x-moonitoring-consumers: []
    x-moonitoring-webhook: false
    x-moonitoring-requirements:
    - '147.2'
    - '147.7'
  publish_article_updated_v1:
    action: send
    channel:
      $ref: '#/channels/news.events.v1'
    messages:
    - $ref: '#/channels/news.events.v1/messages/article_updated_v1'
    summary: A published article changed in a way readers can see; the site is rebuilt.
    x-moonitoring-producer: news
    x-moonitoring-consumers: []
    x-moonitoring-webhook: false
    x-moonitoring-requirements:
    - '147.8'
    - '148'
  publish_article_unpublished_v1:
    action: send
    channel:
      $ref: '#/channels/news.events.v1'
    messages:
    - $ref: '#/channels/news.events.v1/messages/article_unpublished_v1'
    summary: An article was unpublished; its pages answer 410 Gone after the next build.
    x-moonitoring-producer: news
    x-moonitoring-consumers: []
    x-moonitoring-webhook: false
    x-moonitoring-requirements:
    - '147.2'
components:
  messages:
    article_published_v1:
      name: article.published.v1
      title: article.published.v1
      summary: An article was published, or its scheduled time came; the site is rebuilt with it.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: article.published.v1
            subject:
              type: string
              description: The article id.
            data:
              $ref: '#/components/schemas/ArticleChangeV1Data'
    article_updated_v1:
      name: article.updated.v1
      title: article.updated.v1
      summary: A published article changed in a way readers can see; the site is rebuilt.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: article.updated.v1
            subject:
              type: string
              description: The article id.
            data:
              $ref: '#/components/schemas/ArticleChangeV1Data'
    article_unpublished_v1:
      name: article.unpublished.v1
      title: article.unpublished.v1
      summary: An article was unpublished; its pages answer 410 Gone after the next build.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: article.unpublished.v1
            subject:
              type: string
              description: The article id.
            data:
              $ref: '#/components/schemas/ArticleChangeV1Data'
  schemas:
    ArticleChangeV1Data:
      type: object
      properties:
        article:
          type: string
          format: uuid
        locales:
          type: array
          items:
            type: string
            enum:
            - it
            - en
          description: The translations readers can see after the change.
      required:
      - article
      - locales
x-moonitoring-consumes:
- event: staff_membership.changed.v1, staff_role.updated.v1
  producer: access
  why: Authorizes the staff who write and publish, and shows authors by their public name.
