@slimio/registry-sdk v0.3.0
Registry-SDK
Registry-SDK is a bunch of methods to query the SlimIO Registry API.
Requirements
- Node.js version 12 or higher
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
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
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);
Create a new user account on the registry.
const { createAccount } = require("@slimio/registry-sdk");
await createAccount("newUsername", "newPassword", "yourmail@dot.com");
Addons methods
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.
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);
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
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.
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.
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