type: object
required:
  - version
  - files
additionalProperties: false
properties:
  extension:
    type: string
    description: |
      A reference to the extension this version applies to.
  version:
    type: string
    pattern: ^\d+\.\d+\.\d+$
    description: |
      A semantic version identifying the extension version.
  permissions:
    description: |
      A list of SDK calls; and if needed, additional information.
    type: array
    items:
      type: object
      required:
        - rpc
      additionalProperties: false
      properties:
        rpc:
          type: string
          pattern: ^[a-z]+[a-z/]*[a-z]+#[a-zA-Z]+$
          description: |
            The Appsemble RPC made through the Appsemble SDK.

            The possible values are available in the Appsemble SDK
            documentation.
        app:
          type: string
          description: |
            The Appsemble app this RPC is used by.

            This is needed to maintain as little as possible permissions for
            the Appsemble user apps.
          enum:
            - user
            - bootstrap
            - both
          default: bootstrap
        permissions:
          description: |
            A list of additional permisssions.

            This is needed when the extensions needs to have certain
            permissions in external APIs (such as Facebook's) in order to
            function.
          type: array
          items:
            type: string
        endpoints:
          description: |
            The endpoints of a external API.

            These are required to be specified when you want to make use of the
            external APIs provided by Appsemble.

            These can either be plain text or a escaped regular expression.

            The prepending slash should be omitted. Instead of specifying an
            endpoint as ``/foo/bar`` you ought to specify it as ``foo/bar``.

            Keep in mind that the endpoint will be checked in its entierty;
            meaning that an endpoint 'foo\/\\d+\/bar' asserts that the actual
            endpoint looks like ``foo/1/bar``.
          type: array
          items:
            type: string
            pattern: ^(?!(\/))
  resources:
    type: object
    description: |
      A number of resources that the extension will use.

      These resources will be exposed by the Appsemble RESTful API.
    additionalProperties: false
    patternProperties:
      ^[a-z]+$:
        type: object
        additionalProperties: false
        required:
          - actions
          - schema
        properties:
          schema:
            type: object
            description: |
              A JSON schema to verify entities of this resource.
          indices:
            type: array
            description: |
              An array of property names that should be indexed.

              If a property name is in this array, this means it queries can be
              sorted and filtered by values of this property.
            items:
              type: string
          singleton:
            type: boolean
            default: false
            description: |
              Wether or not the entity is a singleton.
          actions:
            type: object
            description: |
              All actions that are allowed.
            properties:
              create: &ACTION
                type: object
                additionalProperties: false
                properties:
                  permissions:
                    description: |
                      Required permissions for the actions.

                      For now this is unused.
                    type: string
              get: *ACTION
              query: *ACTION
              update: *ACTION
              delete: *ACTION
  files:
    type: object
    description: |
      A mapping of files contained by an extension version.

      The key is the file path. The value is the blob to serve.

      At least an `index.html` must be included. This is the entry point
      for the extension.
    required:
      - index.html
    patternProperties:
      .+:
        type: string
        format: binary
