Skip to content
This repository has been archived by the owner on Dec 4, 2022. It is now read-only.

Publish plugin #5

Open
Tracked by #4
coffeeispower opened this issue Oct 13, 2022 · 22 comments · May be fixed by #8
Open
Tracked by #4

Publish plugin #5

coffeeispower opened this issue Oct 13, 2022 · 22 comments · May be fixed by #8
Assignees
Labels
Feature New feature or request High priority Extra attention is needed

Comments

@coffeeispower
Copy link
Contributor

coffeeispower commented Oct 13, 2022

The development of this issue is being made on #8.

@coffeeispower coffeeispower self-assigned this Oct 13, 2022
@dzhou121
Copy link
Contributor

We eventually want a cli to publish the plugin but for a first step, it could be only the API, e.g.

POST /volts and the body would be the zip file. We'll check the volt.toml file to see if it's valid, put the version, name, etc to the database, and put the wasm/theme files to storage.

@coffeeispower
Copy link
Contributor Author

coffeeispower commented Oct 13, 2022 via email

@dzhou121
Copy link
Contributor

I thought this would be the very first API?

@coffeeispower
Copy link
Contributor Author

But the API I will do now

@coffeeispower
Copy link
Contributor Author

POST /volts seems good enough

@coffeeispower
Copy link
Contributor Author

coffeeispower commented Oct 13, 2022

This will be the first api, doing a cli now is not a great idea because the API is in development, and we have to change the cli everytime that API changes

@coffeeispower
Copy link
Contributor Author

Can I add support for icons too? I mean, I already have to store files, so what's adding one more to the mix?

@dzhou121
Copy link
Contributor

Can I add support for icons too? I mean, I already have to store files, so what's adding one more to the mix?

Yes please. Let's add icons.

@coffeeispower
Copy link
Contributor Author

this LGTM
image
I made this using open api

openapi: 3.0.0
servers:
  - url: https://lapce-extensions.herokuapp.com
    description: Production server
  - url: http://localhost:8000
    description: Local server
info:
  description: |
    This is the lapce registry API, nothing fancy here
  version: v1
  title: Lapce Plugin Registry
  license:
    name: MIT
tags:
  - name: repository
    description: Publish, manage and search plugins
    externalDocs:
      description: Find out more
      url: http://registry.lapce.dev
  - name: login
    description: Start and destroy sessions
  - name: user
    description: Operations about user
paths:
  /api/volt/{name}/{version}:
    delete:
      parameters:
        - in: path
          schema:
            type: string
          name: name
          required: true
        - in: path
          schema:
            type: string
          name: version
          required: true
      tags: [repository]
      description: Yanks a plugin version
      responses:
        "204":
          description: The version was successfully yanked
        "404":
          description: The plugin/version does not exist or is yanked already
        "401": 
          description: Not Logged In
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                error:
                  value:
                    kind: NotLoggedIn
                    action: "Send a `token` cookie."
                    message: "You're already logged out"
  /api/volt/{name}:
    delete:
      parameters:
        - in: path
          schema:
            type: string
          name: name
          required: true
      tags: [repository]
      description: Unpublishes a plugin
      responses:
        "204":
          description: The plugin was successfully unpublished
        "404":
          description: The plugin does not exist
        "401": 
          description: Not Logged In
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                error:
                  value:
                    kind: NotLoggedIn
                    action: "Send a `token` cookie."
                    message: "You're already logged out"
      security:
        - tokenAuth: []
  /api/volt:
    patch:
      description: Updates a plugin, creating a new version
      tags: [repository]
      requestBody:
        required: true
        content:
          application/zip:
            schema: 
              format: binary
              type: string
      responses:
        "201":
          description: The new version was successfully published
          content:
            application/json:
                schema:
                  $ref: "#/components/schemas/Volt"
        "400":
          description: The zip was malformed or the files were missing or incorrect
        "401": 
          description: Not Logged In
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                error:
                  value:
                    kind: NotLoggedIn
                    action: "Send a `token` cookie."
                    message: "You're already logged out"
        "404":
          description: The specified plugin does not exist
        "409":
          description: The version is already published or a newer version already exists
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                error:
                  value:
                    kind: AlreadyExists
                    action: "Use a version greater than 1.0.0"
                    message: "A greater or equal version exists."
      security:
        - tokenAuth: []
        
    post:
      description: Creates a new plugin
      tags: [repository]
      requestBody:
        required: true
        content:
          application/zip:
            schema: 
              format: binary
              type: string
      responses:
        "201":
          description: The volt was successfully published
          content:
            application/json:
                schema:
                  $ref: "#/components/schemas/Volt"
        "400":
          description: The zip was malformed or the files were missing or incorrect
        "401": 
          description: Not Logged In
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                error:
                  value:
                    kind: NotLoggedIn
                    action: "Send a `token` cookie."
                    message: "You're already logged out"
        "409":
          description: The plugin is already published
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                error:
                  value:
                    kind: AlreadyExists
                    action: "Use a different name, or if you're trying to update, use PATCH /api/volt/{name} instead"
                    message: "A plugin with the same name is already published"
      security:
        - tokenAuth: []
  /api/session:
    delete:
      security:
        - tokenAuth: []
      tags:
        - login
      summary: Invalidates the token, logging out
      operationId: deleteSession
      responses:
        "200":
          description: Session Invalidated
        "401": 
          description: Not Logged In
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                error:
                  value:
                    kind: NotLoggedIn
                    action: "Send a `token` cookie."
                    message: "You're already logged out"
  /api/user:
    get:
      security:
        - tokenAuth: []
      tags:
        - user
      summary: Get the current logged in user
      operationId: getUser
      responses:
        "200":
          description: Ok
          content:
            application/json:
              examples:
                user:
                  description: A user example
                  value: 
                    id: 92828847
                    name: "coffee-is-power"
                    username: "Tiago Dinis"
                    avatar_url: "https://avatars.githubusercontent.com/u/92828847?v=4"
              schema:
                $ref: "#/components/schemas/User"
        "401": 
          description: Not Logged In
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                error:
                  value:
                    kind: NotLoggedIn
                    action: "Send a `token` cookie."
                    message: Unauthorized
                  
  /login/github:
    get:
      tags:
        - login
      summary: Redirects to the github authorize page
      operationId: startLogin
      responses:
        "300":
          description: Ok
components:
  securitySchemes:
    tokenAuth:
      type: apiKey
      in: cookie
      name: token
  schemas:
    Volt:
      type: object
      discriminator:
        propertyName: id
      properties:
        id: {type: number}
        name: {type: string}
        publisher: {type: string}
        display_name: {type: string}
        icon: {type: string}
        versions: 
          type: array
          items:
            type: string
        author: {type: string}
        description: {type: string}
    Error:
      type: object
      discriminator:
        propertyName: kind
      properties:
        kind: 
          description: Useful to check and match errors programatically
          type: string
        action:
          description: A message that suggests the user to do things to try to fix the error (e.g verify the password)
          type: string
        message:
          type: string
          description: Describes what went wrong
    User:
      type: object
      discriminator:
        propertyName: id
      properties:
        id:
          description: User ID
          type: number
        name:
          type: string
          description: login name
        username:
          description: Display name
          type: string
        avatar_url:
          type: string

@coffeeispower
Copy link
Contributor Author

I'll integrate this into the pipeline, so it generates the HTML from the Open API specs and then rocket serves it, but I'll do that later

@coffeeispower
Copy link
Contributor Author

You can even test and play around with the API on your browser, which I think is really cool

@coffeeispower
Copy link
Contributor Author

I'll also make a yank version system similar to what cargo does, probably you've seen the delete endpoint

@coffeeispower
Copy link
Contributor Author

coffeeispower commented Oct 14, 2022

I'll store all the versions of the plugins so it would be cool if people could choose the version they want to download. People do dumb stuff and break their code quite frequently, so adding the ability to go back do older versions is important

@coffeeispower
Copy link
Contributor Author

So, the design I'm thinking is that, plugins are basically containers that contain versions.

Versions contain the plugin data like themes and the code.
So when you publish a plugin, it will create a plugin and create a new version with the data you sent.
For me it seems a good design.

@coffeeispower coffeeispower linked a pull request Oct 14, 2022 that will close this issue
@panekj
Copy link

panekj commented Oct 15, 2022

draft/preview plugin versions

@coffeeispower
Copy link
Contributor Author

@panekj What do you mean?

@coffeeispower
Copy link
Contributor Author

Do you mean like adding a option to mark a version as a preview release?

@panekj
Copy link

panekj commented Oct 15, 2022

yes

@coffeeispower
Copy link
Contributor Author

i'm going to use semantic versioning on the registry, so what if adding a -alpha/beta/rc* tag to the version marks it as a preview release?

@coffeeispower
Copy link
Contributor Author

But thinking well that can generate false positives/negatives, so its a trade-off, its easier to use, though it's not always reliable.

@coffeeispower
Copy link
Contributor Author

TO simplify the implementation, i'll let the user decide whether its a pre-release or not

@coffeeispower
Copy link
Contributor Author

coffeeispower commented Oct 15, 2022

Implemented: 5539616...9d53e35

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Feature New feature or request High priority Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants