@bck-inc/nsl-core
v1.0.37
Published
SDK officiel pour l'API NSL (Néon Spinellia LuckyScale) - 100 % fetch natif
Readme
@bck-inc/nsl-core
SDK TypeScript / Node.js pour l’API NSL (Néon Spinellia LuckyScale)
TL;DR :
import { NSLCore } from '@bck-inc/nsl-core'→ appelez votre premier endpoint en 10 lignes.
✨ Caractéristiques principales
| | |
| :--------------------- | :------------------------------------------------------------------------------------------- |
| Fetch natif | Aucun client HTTP externe — Node ≥ 18 requis (polyfill possible). |
| ESM & CJS | Fonctionne avec import et require. |
| Type safe | Déclarations .d.ts + type‑guards runtime. |
| Cache TTL (1,5 s) | Réponses GET mises en cache pour amortir les floods. |
| Rate‑limit intégré | Token‑bucket 200 ms entre requêtes. |
| Errors typées | NSLError, NSLHTTPError pour des catch ciblés. |
| Évènements | request, response, cacheHit, validationError, moduleStateChanged, ping, error. |
| Zéro config | Instanciez, appelez : headers et baseURL gérés pour vous. |
🚀 Installation
npm i @bck-inc/nsl-core # pnpm add @bck-inc/nsl-core / yarn add @bck-inc/nsl-coreNode ≥ 18 recommandé pour
fetchetURLglobaux. Sur Node 16 :import fetch from 'node-fetch'; // @ts-ignore globalThis.fetch = fetch;
⚡ Exemple rapide (TS / ESM)
import { NSLCore, NSLCodes, NSLState } from '@bck-inc/nsl-core';
const core = new NSLCore({
token: process.env.NSL_TOKEN!,
botId: process.env.BOT_ID!,
debug: true,
});
core.on('cacheHit', ({ url }) => console.log('⚡ cache', url))
.on('ping', ({ rtt }) => console.log('ping', rtt, 'ms'))
.on('error', console.error);
// Active le module "welcome" sur un serveur
const res = await core.setModuleState({
bot_id: core['botId']!,
server_id: '987654321098765432',
module_name:'welcome',
newState: NSLState.enabled,
});
if (res.code === NSLCodes.VALID) console.log('Module OK');📚 API en bref
Constructeur
new NSLCore({ token, botId, baseURL?, debug? });Méthodes
| Méthode | Effet |
| ------------------------------------------- | ------------------------------------------------- |
| fetchModules(query?) | GET /modules/get + cache TTL |
| insertModule(body) / updateModule(body) | CRUD module |
| setModuleState(params) | Insert ou update + événement moduleStateChanged |
| enableModule() / disableModule() | Sucrage autour de setModuleState |
| isStandardized(name) | Vérifie si « standard » côté API |
| getPing() | Retourne la latence (ms) et émet ping |
Évènements (auto‑complétés dans VS Code)
| Event | Payload |
| :------------------- | :--------------------------- |
| request | { url, method } |
| response | { url, status } |
| cacheHit | { url, ttlLeft } |
| validationError | { url, issues } |
| moduleStateChanged | { module, type, newState } |
| ping | { rtt } (‑1 si timeout) |
| error | unknown |
Types & enums détaillés dans src/types.ts.
🧪 Tests
pnpm test # Vitest en CI
pnpm test:watch # watch mode🤝 Contribuer
- Fork puis
git checkout -b feat/ma-feature pnpm i && pnpm test- PR + description claire.
Toute idée ou bug ? Ouvrez une Issue — on répond vite !
📜 Licence
MIT — © BCK Inc. 2025
