Registry

November 22, 2019 · View on GitHub

version Maintenance MIT dep size Known Vulnerabilities Build Status Greenkeeper badge

Registry is an HTTP API whose main purpose is to manage SlimIO Addons. The API let you create your own account and manage an organisation to publish and edit your personal and/or company addon(s).

This project has been inspired by npm Registry.

Requirements

  • Node.js v12 or higher
  • A local MariaDB database (else setup the project for SQLite).

Getting Started

$ git clone https://github.com/SlimIO/Registry.git
$ cd Registry
$ npm ci
$ npm start

Environment Variables

The server can be configured by setting up environment variables. This project is capable to load these variables from local .env file too.

$ touch .env

Add these environment variables and save them, you can change the values ​​of these keys according to your needs

SECRET_KEY=your_secret_key
PORT=1337

DB_DIALECT=sqlite
DB_NAME=registry
DB_USER=root
DB_PASSWORD=ROOT

Supported DB dialect are: mysql, sqlite, postgres, mssql.

DB Schema

Endpoints

For all request with a body data, you need to set your headers with:

  • Content-Type: application/json
icondescription
🔑⚠️ You need to be authenticated to use this route: see /login

Meta endpoints

GET ·/

Return service metadata.

NameValueKindRequired?Notes
{
    uptime: 3403
}

User endpoints

POST ·/login

Authenticate a user and get an AccessToken. The account must be activated before to success.

NameValueKindRequired?Notes
usernameStringBodyUser name
passwordStringBodyUser password

Return an AccessToken which will be required for some endpoints.

{
    access_token: string;
}
POST ·/users

Create a new inactive user. The account will be deleted after 24 hours if no activation occur.

NameValueKindRequired?Notes
usernameStringBodyUser name
passwordStringBodyUser password

Return an empty JSON on success with a code 201.

{}
POST ·/users/activeAccount

Activate an account with the activation token received by email.

NameValueKindRequired?Notes
tokenStringBodyActivation token

Return an empty JSON on success with code 200.

{}

Addon endpoints

GET ·/addon

Get all available addons.

NameValueKindRequired?Notes
[
    "cpu",
    "memory"
]
GET ·/addon/{addonName}

Get a given addon by his name.

NameValueKindRequired?Notes
addonNameStringPathAddon name

Return a data structure described by the following interface:

{
    name: string,
    description: string,
    git: string,
    createdAt: Date,
    updatedAt: Date,
    author: {
        username: string,
        description: string
    },
    organisation: {
        name: string,
        createdAt: Date,
        updatedAt: Date
    },
    versions: [
        {
            version: string,
            createdAt: string
        }
    ]
}
🔑 POST ·/addon/publish

Create or update an Addon release. This endpoint require an AccessToken.

NameValueKindRequired?Notes
nameStringBodyAddon name
descriptionStringBodyAddon description
versionStringBodySemver
gitStringBodyGIT Url
organisationStringBodyOrganisation (if any)

Return the addon id.

{
    addonId: 1
}

Organisation endpoints

GET ·/organisation

Get all organisations.

NameValueKindRequired?Notes

Return an JavaScript Object described by the following interface:

{
    [name: string]: {
        description: string,
        owner: string,
        users: string[]
        addons: string[]
    }
}

GET ·/organisation/{name}

Get an organisation by his name.

NameValueKindRequired?Notes
nameStringPathOrganisation name

Return a data structure like:

{
    name: string,
    description: string,
    createdAt: Date,
    updatedAt: Date,
    owner: {
        username: string,
        createdAt: Date,
        updatedAt: Date
    },
    users: [
        {
            username: string,
            createdAt: Date,
            updatedAt: Date
        }
    ]
    addons: [
        {
            name: string,
            description: string,
            git: string,
            createdAt: Date,
            updatedAt: Date
        }
    ]
}

🔑 POST : /organisation/:orgaName/:userName

Add a user to an organisation. This endpoint require an AccessToken.

NameValueKindRequired?Notes
orgaNameStringPathOrganisation name
userNameStringPathUser name

⚠️ Only Organisation owner can use this endpoint.

Return the following interface:

{
    createdAt: date,
    updatedAt: date,
    organisationId: number,
    userId: number
}

Dependencies

NameRefactoringSecurity RiskUsage
@polka/send-typeMinorLowTBC
@slimio/isMinorLowType Checker
argon2⚠️MajorHighCrypto package
body-parserMinorHighBody Parser
dotenvMinorLowLoad local .env in process.env
indicativeMinorLowValidator
jsonwebtoken⚠️MajorHighJWT Token
kleurMinorLowColors for TTY
make-promises-safe⚠️MajorMediumForce Node.js DEP00018
polka⚠️MajorLowHTTP Server
semverMinorLowSemVer validation
semver-sortMinorLowSort SemVer versions
sequelize⚠️MajorHighORM
sqlite3⚠️MajorHighSQLite

License

MIT