# NodeJS

Требуемые библиотеки:

| Библиотека | Версия |
| ---------- | ------ |
| axios      | ^1.6.5 |

Код SDK:

```javascript
const axios = require('axios');

class PureServers {
    constructor(email, password) {
        this.email = email;
        this.password = password;
        this.session = null;
    }

    async request(url, method, data = {}, secured = false) {
        try {
            const res = await axios({
                url: `https://cp.pureservers.org/api/${url}`,
                method,
                ...(method === 'POST' ? { data } : {}),
                ...(secured && this.session ? {
                    headers: {
                        session: this.session
                    }
                } : {})
            });

            return { data: res?.data, headers: res?.headers, success: true };
        } catch(err) {
            return { data: err?.response?.data, headers: err?.response?.headers, success: false };
        }
    }

    async login() {
        const res = await this.request('auth/login', 'POST', { email: this.email, password: this.password });
        if(res.success) {
            this.session = res.headers.session;
            return true;
        }

        return res;
    }
}
```

Пример использования с получением списка серверов:

```javascript
async function main() {
    const api = new PureServers('<email>', '<password>');
    const login = await api.login();
    if(login) console.log(await api.request('servers/list', 'GET', {}, true));
    else console.log('Failed to login', login);
}

main();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pureservers.org/sdk/nodejs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
