# neverlose-api

> Modern neverlose.cc market framework

Latest version **1.0.1** (published 2022-01-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install neverlose-api
pnpm add neverlose-api
yarn add neverlose-api
bun add neverlose-api
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-01-13 |
| First published | 2022-01-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 23.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Teselka |
| Maintainers | teselka |

## Links

- npm: https://www.npmjs.com/package/neverlose-api
- Repository: https://github.com/Teselka/node-neverlose-api
- Homepage: https://github.com/Teselka/node-neverlose-api#readme
- Issues: https://github.com/Teselka/node-neverlose-api/issues
- npm.io page: https://npm.io/package/neverlose-api

## Recent versions

- 1.0.1 (latest) — 2022-01-13
- 1.0.0 — 2022-01-13

## README

# Neverlose api
This is the neverlose.cc market api wrapper written on node.js

## Getting started
First of all, you should to get your userid and client secret from site (https://neverlose.cc/market/api)

And setup callback url's

![alt preview](https://i.imgur.com/br0wiSF.jpg)

Then create market class and an http/https server

```js
const { NeverloseMarket } = require('neverlose');

const market = new NeverloseMarket({
    'userid': 1337,
    'secret': 'your_secret'
});

market.create_http_server();
// or
market.create_https_server({
    key: 'key',
    cert: 'cert'
});

```

Then create an event handler
```js
market.on('balance_transfer', ctx => {
    console.info(`${ctx.username} transfered to you ${ctx.amount} NLE`); 
});

```

Or use any of POST methods
```js
market.give_for_free('my_item', 'Teselka', ctx => {
    if (ctx.err) {
        console.error(`Failed to give market item ${ctx.code} to user ${ctx.username}, reason: ${ctx.err}`);
        return;
    }
    
    console.log(`${ctx.user} successfully got market item ${ctx.code}`);
});
```


## Available events
### balance_transfer - When user transfered money to your account
```js
market.on('balance_transfer', ctx => {
    console.info(`${ctx.username} transfered to you ${ctx.amount} NLE`); 
});
```

### item_purchase - When user purchased your market item
```js
market.on('item_purchase', ctx => {
    console.info(`${ctx.username} purchased your market item ${ctx.item_id} for ${ctx.amount} NLE`);
});
```

## Available POST requests
### transfer_money - Transferring money to user
```js
market.transfer_money('Teselka', 0.01, ctx => {
    if (ctx.err) {
        console.error(`Failed to transfer ${ctx.amount} NLE to user ${ctx.username}`);
        return;
    }

    console.log(`Successfully transferred ${ctx.amount} NLE to user ${ctx.username}`);
});
```

### gift_product - Gifting product to user
```js
market.gift_product('Teselka', 'csgo', ctx => {
    if (ctx.err) {
        console.error(`Failed to gift product ${ctx.product} to user ${ctx.username}`);
        return;
    }

    console.log(`${ctx.user} successfully got product ${ctx.product} (${ctx.cnt})`);
});
```

## Avilable utils
### generate_signature - Generating signature
```js
const sig = market.generate_signature({
    "amount": 0.9,
    "username": "A49",
    "unique_id": 89968,
    "item_id": "E3yugw",
});
console.log(sig);
```

### validate_signature - Validating signature
```js
const sig = market.validate_signature({
    "amount": 0.9,
    "username": "A49",
    "unique_id": 89968,
    "item_id": "E3yugw",
    "signature": "454174f972a7b044289fb932ee65a86f41ea389807ff303686da496597289510"
});
console.log(sig); // true
```

---
_Source: https://npm.io/package/neverlose-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
