@wumx-labs/noxaeapi-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # @wumx-labs/noxaeapi-sdk
2
+
3
+ Typed JS/TS SDK for [NoxAeApi](https://github.com), a REST + WebSocket API plugin/mod for Minecraft servers — ships for both Fabric and Bukkit/Spigot/PaperMC. The REST surface is identical across platforms, so this SDK works against either without any platform-specific configuration.
4
+
5
+ Zero runtime dependencies — uses native `fetch` and `WebSocket`.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @wumx-labs/noxaeapi-sdk
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { NoxAeApiClient } from "@wumx-labs/noxaeapi-sdk";
17
+
18
+ const client = new NoxAeApiClient({
19
+ baseUrl: "http://localhost:8080",
20
+ apiKey: "your-api-key",
21
+ });
22
+
23
+ const players = await client.players.list();
24
+ const balance = await client.economy.getBalance(players[0].uuid);
25
+ await client.server.broadcast("Hello from the SDK!");
26
+ ```
27
+
28
+ ### From environment variables
29
+
30
+ ```ts
31
+ // Reads NOXAEAPI_BASE_URL and NOXAEAPI_KEY from process.env.
32
+ // If you keep those in a .env file, load it yourself first (e.g. with `dotenv`) —
33
+ // the SDK never reads .env files or process.env implicitly outside this method.
34
+ const client = NoxAeApiClient.fromEnv();
35
+ ```
36
+
37
+ ### Realtime (console tail / events)
38
+
39
+ ```ts
40
+ const ws = client.connect({ route: "console" });
41
+ ws.on("console", (line) => console.log(line));
42
+ ws.on("close", () => console.log("disconnected"));
43
+ ```
44
+
45
+ The socket auto-reconnects with exponential backoff on unexpected disconnects.
46
+
47
+ ## Error handling
48
+
49
+ All non-2xx responses throw a subclass of `NoxAeApiError`:
50
+
51
+ - `NoxAeApiUnauthorizedError` — 401, missing/invalid API key
52
+ - `NoxAeApiForbiddenError` — 403, key valid but not permitted for this endpoint
53
+ - `NoxAeApiNotFoundError` — 404
54
+ - `NoxAeApiRateLimitError` — 429 (SDK auto-retries these by default; thrown only once retries are exhausted)
55
+ - `NoxAeApiServerError` — 5xx (also auto-retried by default)
56
+ - `NoxAeApiNetworkError` — request never completed (timeout, DNS, connection refused)
57
+
58
+ ```ts
59
+ import { NoxAeApiForbiddenError } from "@wumx-labs/noxaeapi-sdk";
60
+
61
+ try {
62
+ await client.server.restart();
63
+ } catch (err) {
64
+ if (err instanceof NoxAeApiForbiddenError) {
65
+ console.error("This API key isn't allowed to restart the server.");
66
+ } else {
67
+ throw err;
68
+ }
69
+ }
70
+ ```
71
+
72
+ ## Optional modules
73
+
74
+ Some modules only work depending on the target server's setup:
75
+
76
+ - `client.luckperms.*` — requires the LuckPerms mod to be loaded on the server
77
+ - `client.noxauth.*` — requires `noxauth.enabled: true` in the server's `noxaeapi-config.yml`
78
+
79
+ Calling these against a server without the corresponding feature enabled will fail (typically 404).
80
+
81
+ ## Configuration
82
+
83
+ ```ts
84
+ new NoxAeApiClient({
85
+ baseUrl: "https://mc.example.com",
86
+ apiKey: "...",
87
+ timeoutMs: 10_000, // per-request timeout, default 10s
88
+ retry: {
89
+ attempts: 3, // total attempts including the first, default 3
90
+ baseDelayMs: 300,
91
+ maxDelayMs: 5000,
92
+ },
93
+ // retry: false, // disable retries entirely
94
+ headers: { "X-Extra": "..." },
95
+ });
96
+ ```
97
+
98
+ ## License
99
+
100
+ MIT