openapi: 3.1.1
info:
  title: AuthX
  description: API for managing Auth0 services in Google Apps Script.
  version: 1.0.0
servers:
  - url: https://script.google.com/a/macros/sonymusic-pde.com/s/AKfycbxEm0Bu-LJtHQXlAekWK-BGPusXelZec4ilChsrfP49fq3Pd0ZeIsA1BQePz0dt1jpxlw/exec/api/v1
    description: Prod
  - url: https://script.google.com/a/macros/sonymusic-pde.com/s/AKfycbws8P-pVVBlAHc4cEx6mu7mBndTD6JJyL3SvhD3Mpkryp4hbn300xn9os2KrhXk95zpYw/exec/api/v1
    description: QA
  - url: https://script.google.com/a/macros/sonymusic-pde.com/s/AKfycbzU81ru-Wv23WBn3DWP03gj_wIvekW5ffUUoiaxxEW169S_SPy95AwuCVyqrx4KuZzYIw/exec/api/v1
    description: Dev
paths:
  /me:
    get:
      summary: Get current user profile
      operationId: getUser
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserResponse"
  /me/delete:
    post:
      summary: Logout all clients and clear user data
      operationId: deleteUser
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserDeleteResponse"
  /services:
    get:
      summary: List available services
      operationId: getServices
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ServicesResponse"
  /services/{serviceName}:
    get:
      summary: Get service information
      operationId: getService
      parameters:
        - name: serviceName
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ServiceResponse"
        "404":
          description: Service not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /services/{serviceName}/status:
    get:
      summary: Get service connection status
      operationId: getServiceStatus
      parameters:
        - name: serviceName
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ServiceStatusResponse"
        "404":
          description: Service not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /services/{serviceName}/logout:
    post:
      summary: Logout from a service
      operationId: logoutService
      parameters:
        - name: serviceName
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ServiceLogoutResponse"
        "404":
          description: Service not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

components:
  schemas:
    BaseResponse:
      type: object
      properties:
        statusCode:
          type: integer
          example: 200
      required:
        - statusCode
    ErrorResponse:
      type: object
      properties:
        statusCode:
          type: integer
          example: 404
        error:
          type: string
      required:
        - error
        - statusCode
    User:
      type: object
      properties:
        avatarUrl:
          type: string
        displayName:
          type: string
        email:
          type: string
        firstName:
          type: string
        lastName:
          type: string
    UserResponseData:
      type: object
      properties:
        user:
          $ref: "#/components/schemas/User"
      required:
        - user
    UserResponse:
      allOf:
        - $ref: "#/components/schemas/BaseResponse"
        - type: object
          properties:
            data:
              $ref: "#/components/schemas/UserResponseData"
          required:
            - data
    UserDeleteResponseData:
      type: object
    UserDeleteResponse:
      allOf:
        - $ref: "#/components/schemas/BaseResponse"
        - type: object
          properties:
            data:
              $ref: "#/components/schemas/UserDeleteResponseData"
          required:
            - data
    Service:
      type: object
      properties:
        id:
          type: string
      required:
        - id
    ServicePartial:
      type: object
      properties:
        id:
          type: string
      required:
        - id
    ServicesResponseData:
      type: object
      properties:
        services:
          type: array
          items:
            $ref: "#/components/schemas/ServicePartial"
      required:
        - services
    ServicesResponse:
      allOf:
        - $ref: "#/components/schemas/BaseResponse"
        - type: object
          properties:
            data:
              $ref: "#/components/schemas/ServicesResponseData"
          required:
            - data
    ServiceResponseData:
      type: object
      properties:
        service:
          $ref: "#/components/schemas/Service"
      required:
        - service
    ServiceResponse:
      allOf:
        - $ref: "#/components/schemas/BaseResponse"
        - type: object
          properties:
            data:
              $ref: "#/components/schemas/ServiceResponseData"
          required:
            - data
    ServiceStatusConnected:
      type: object
      properties:
        connected:
          type: boolean
          const: true
        accessToken:
          type: string
        expiresAt:
          type: number
        tokenType:
          type: string
      required:
        - connected
        - accessToken
        - expiresAt
        - tokenType
    ServiceStatusDisconnected:
      type: object
      properties:
        connected:
          type: boolean
          const: false
        authUrl:
          type: string
        timeoutAt:
          type: number
      required:
        - connected
        - authUrl
        - timeoutAt
    ServiceStatus:
      oneOf:
        - $ref: "#/components/schemas/ServiceStatusConnected"
        - $ref: "#/components/schemas/ServiceStatusDisconnected"
    ServiceStatusResponseData:
      type: object
      properties:
        service:
          $ref: "#/components/schemas/ServicePartial"
        status:
          $ref: "#/components/schemas/ServiceStatus"
      required:
        - service
        - status
    ServiceStatusResponse:
      allOf:
        - $ref: "#/components/schemas/BaseResponse"
        - type: object
          properties:
            data:
              $ref: "#/components/schemas/ServiceStatusResponseData"
          required:
            - data
    ServiceLogoutResponseData:
      type: object
      properties:
        service:
          $ref: "#/components/schemas/ServicePartial"
      required:
        - service
    ServiceLogoutResponse:
      allOf:
        - $ref: "#/components/schemas/BaseResponse"
        - type: object
          properties:
            data:
              $ref: "#/components/schemas/ServiceLogoutResponseData"
          required:
            - data