Skip to content

SlimIO/Registry-SDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

3a0f02c · Jun 2, 2020
Apr 24, 2019
Jun 2, 2020
Apr 8, 2019
Jul 29, 2019
Apr 24, 2019
Jun 3, 2019
May 27, 2020
Apr 8, 2019
Apr 8, 2019
May 15, 2020
Jul 29, 2019
Jan 19, 2020
Jul 29, 2019
May 30, 2019
Jun 2, 2020
Jun 2, 2020
Jan 19, 2020

Repository files navigation

Registry-SDK

version Maintenance MIT dep size Known Vulnerabilities Build Status

Registry-SDK is a bunch of methods to query the SlimIO Registry API.

Requirements

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @slimio/registry-sdk
# or
$ yarn add @slimio/registry-sdk

Usage example

require("dotenv").config();
const { login } = require("@slimio/registry-sdk");

async function main() {
    // Note: Never store your credentials in clear in the code (use a local .env file).
    const accessToken = await login(process.env.LOGIN, process.env.PASSWORD);
    console.log(accessToken);
}
main().catch(console.error);

API

This section describe the SDK methods. For a complete type definition, take a look at index.d.ts ! For more information see the documentation of the Registry.

⚠️ In the following examples, we often use top-level await

meta(): Promise< MetaData >

Return the registry metadata. For the moment only the uptime property is available.

const { meta } = require("@slimio/registry-sdk");

const { uptime } = await meta();
console.log(uptime);

Users methods

login(username: string, password: string): Promise< string >

Authenticate a user and return an AccessToken string. This token will be required as argument by some of the SDK methods.

require("dotenv").config();
const { login, publishAddon } = require("@slimio/registry-sdk");

async function main() {
    // Note: Never store your credentials in clear in the code (use a local .env file).
    const accessToken = await login(process.env.LOGIN, process.env.PASSWORD);
    console.log("Your access token: ", accessToken);

    await publishAddon("./addonDir", accessToken);
}
main().catch(console.error);
createAccount(username: string, password: string, email: string): Promise< void >

Create a new user account on the registry.

const { createAccount } = require("@slimio/registry-sdk");

await createAccount("newUsername", "newPassword", "[email protected]");

Addons methods

getOneAddon(addonName: string): Promise< addonInfos >

Get a given addon by his name.

const { getOneAddon } = require("@slimio/registry-sdk");

// Example
const { description, updateAt } = await getOneAddon("memory");

console.log(description, updateAt);

This method return an object with all addon's informations. See Registry for more details.

getAllAddons(): Promise< string[] >

Get all available addons on the requested registry. This method return an Array of string containing addons names.

const { getAllAddons } = require("@slimio/registry-sdk");

const addons = await getAllAddons();
console.log(addons);
publishAddon(addonDirectory: string, token: string): Promise< addonId >

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

⚠️ publishAddon() to need that your main directory must contain package.json and slimio.toml files !

// Example :

const { login, publishAddon } = require("@slimio/registry-sdk");

const myToken = await login("admin", "admin147");
const { addonId } = await publishAddon(__dirname, myToken);

// Return the Id of the new addon
console.log(addonId);

Organizations methods

getAllOrganizations(): Promise< listOrgas >

Get all organisations.

const { getAllOrganizations } = require("@slimio/registry-sdk");

// Example
const organisations = await getAllOrganizations();

// List organisations
console.log(Object.keys(organisations));

This method returns an object where each key represents an organization.

getOneOrganization(orgaName: string): Promise< orgaInfos >

Get an organisation by his name.

const { getOneOrganization } = require("@slimio/registry-sdk");

// Example
const { users } = await getOneOrganization("SlimIO");

console.log("SlimIO Users:");
for (const user of users) {
    console.log(`- ${user.username}`);
}

This method return an object with all organisation's informations. See Registry for more details.

orgaAddUser(organame: string, username: string, token: string): Promise< orgaUserinfos >

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

const { users, login, orgaAddUser } = require("@slimio/registry-sdk");

// (!) If the user doesn't exist on the Registry
await createAccount("newUsername", "newPassword");

const myToken = await login("myUsername", "myPassword");
const { createdAt, userId } = await orgaAddUser("orgaName", "newUsername", myToken);

console.log(createdAt, userId);

⚠️ Only Organisation owner can use this method.

This method return an object with the registration informations.

Dependencies

Name Refactoring Security Risk Usage
@slimio/manifest Minor Low SlimIO Manifest
httpie Minor Low HTTP Request

License

MIT