@bck-inc/nsl-core
Version:
SDK officiel pour l'API NSL (Néon Spinellia LuckyScale) - 100 % fetch natif
156 lines (155 loc) • 4.15 kB
TypeScript
import { Guild } from "discord.js";
/** Miroir des codes HTTP utilisés par l’API NSL */
export declare enum NSLCodes {
VALID = 200,
NOT_UPDATED = 304,
SYNTAX_ERROR = 400,
UNAUTHENTICATED = 401,
ACCESS_DENIED = 403,
NOT_FOUND = 404,
INTERN_ERROR = 500
}
/** Structure générique de réponse */
export interface NSLData<T = any> {
rep: {
message: string;
code: NSLCodes;
};
data?: T;
}
export declare enum NSLState {
"enabled" = "enabled",
"disabled" = "disabled"
}
/** Champ(s) modifiable(s) pour un module existant. */
export interface NSLModuleField {
state: NSLState;
description?: string;
color?: string;
coexist?: boolean;
}
export interface NSLFetchBody {
bot_id?: string;
server_id?: string;
module_name?: string;
coexist?: boolean;
description?: string;
color?: string;
}
export interface NSLInsertBody {
bot_id: string;
server_id: string;
module_name: string;
coexist?: boolean;
description?: string;
color?: string;
state?: NSLState;
}
export interface NSLUpdateBody {
bot_id: string;
server_id: string;
module_name: string;
fields: NSLModuleField[] | NSLModuleField;
}
export interface NSLIsStandardizedParams {
module_name: string;
}
export interface NSLSetModuleStateParams {
bot_id: string;
server_id: string;
module_name: string;
newState: NSLState;
coexist?: boolean;
description?: string;
color?: string;
guild?: Guild;
}
export interface NSLSetModuleStateReturn {
module_name: string;
type: 'INSERT' | 'UPDATE';
code: NSLCodes;
message: string;
}
/**
* Ensemble des évènements émis par {@link NSLCore}.
* Chaque clé correspond à la string d’évènement, et la valeur
* est un tuple décrivant les paramètres passés au listener.
*/
export interface NSLCoreEvents {
/**
* Émis juste **avant** l’envoi de `fetch`.
*
* @event NSLCore#request
* @typeParam url URL finale (après concat' de la query‑string)
* @typeParam method Méthode HTTP (`GET`, `POST`…)
*/
request: [{
url: string;
method: string;
}];
/**
* Émis dès réception du statut HTTP (avant le parsing JSON).
*
* @event NSLCore#response
* @typeParam url URL appelée
* @typeParam status Code HTTP (`200`, `404`, `429`, …)
*/
response: [{
url: string;
status: NSLCodes;
}];
/**
* Émis pour **toute erreur** : réseau, HTTP ≥ 400, validation…
*
* @event NSLCore#error
* @typeParam err Instance d’`Error`, `NSLHTTPError`, ou toute valeur rejetée
*/
error: [unknown];
/**
* Émis quand la réponse provient du cache mémoire (TTL non expiré).
*
* @event NSLCore#cacheHit
* @typeParam url Clé d’URL concernée
* @typeParam ttlLeft Millisecondes restantes avant expiration
*/
cacheHit: [{
url: string;
ttlLeft: number;
}];
/**
* Émis quand un type‑guard runtime rejette la structure JSON.
*
* @event NSLCore#validationError
* @typeParam url Endpoint concerné
* @typeParam issues Liste courte d’anomalies repérées
*/
validationError: [{
url: string;
issues: string[];
}];
/**
* Émis à la fin de {@link NSLCore.setModuleState setModuleState()}
* **uniquement si** l’insert ou l’update a réussi.
*
* @event NSLCore#moduleStateChanged
* @typeParam module Nom du module concerné
* @typeParam type `'INSERT'` ou `'UPDATE'`
* @typeParam newState Nouvel état appliqué (`enabled` / `disabled`)
*/
moduleStateChanged: [
{
module: string;
type: 'INSERT' | 'UPDATE';
newState: NSLState;
}
];
/**
* Émis à chaque appel de {@link NSLCore.getPing getPing()}.
*
* @event NSLCore#ping
* @typeParam rtt Round‑Trip‑Time en ms ; `‑1` si timeout / échec
*/
ping: [{
rtt: number;
}];
}