mowojang 0.4.1 → 0.4.3-dev.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 +16 -0
- package/dist/{src/client.d.ts → index.d.ts} +87 -2
- package/dist/index.js +1021 -0
- package/package.json +12 -7
- package/dist/package.json +0 -42
- package/dist/src/axiosInstance.d.ts +0 -5
- package/dist/src/axiosInstance.js +0 -47
- package/dist/src/client.js +0 -258
- package/dist/src/index.d.ts +0 -16
- package/dist/src/index.js +0 -18
- package/dist/src/utils.d.ts +0 -11
- package/dist/src/utils.js +0 -10
- package/dist/src/validators.d.ts +0 -19
- package/dist/src/validators.js +0 -38
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.js +0 -1
- package/dist/types/misc.d.ts +0 -29
- package/dist/types/misc.js +0 -1
- package/dist/types/player.d.ts +0 -18
- package/dist/types/player.js +0 -1
- package/dist/types/structures.d.ts +0 -23
- package/dist/types/structures.js +0 -1
package/README.md
CHANGED
|
@@ -18,6 +18,22 @@ const UUID = await Mowojang.getUUID("Pixelic")
|
|
|
18
18
|
const username = await Mowojang.getUsername("14727fae-fbdc-4aff-848c-d2713eb9939e")
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
## ⚙️ Configuration
|
|
22
|
+
|
|
23
|
+
The `Client` constructor accepts an **optional** configuration object.
|
|
24
|
+
|
|
25
|
+
```TS
|
|
26
|
+
const Mowojang = new MowojangClient({
|
|
27
|
+
baseURL: "https://mowojang.matdoes.dev", // The base URL for the Mowojang API
|
|
28
|
+
fallback: true, // Whether to fallback to mowojang.seraph.si if the default baseURL is down
|
|
29
|
+
timeout: 10000, // Request timeout in milliseconds
|
|
30
|
+
validation: {
|
|
31
|
+
enabled: true, // Enable automatic validation for inputs (UUIDs and Usernames)
|
|
32
|
+
minimumUsernameLength: 1, // Minimum username length required to pass validation (1 or 2), default is 3.
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
21
37
|
> [!TIP]
|
|
22
38
|
> If you plan on using this in a long-running process with heavy usage check out this guide on how to setup custom caching to prevent memory leaks.
|
|
23
39
|
> Guide: [Custom-Caching](docs/custom-caching.md)
|
|
@@ -1,5 +1,74 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { LoggerConfig } from '@pixelic/logger';
|
|
2
|
+
import { CacheOptions, CacheRequestConfig, buildStorage, buildMemoryStorage } from 'axios-cache-interceptor';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Minecraft Username or UUIDv4 (both undashed and dashed will be accepted)
|
|
6
|
+
*
|
|
7
|
+
* @example "Technoblade" or "b876ec32-e396-476b-a115-8438d83c67d4"
|
|
8
|
+
*/
|
|
9
|
+
type Player = string | UUID;
|
|
10
|
+
/**
|
|
11
|
+
* Minecraft Username
|
|
12
|
+
*
|
|
13
|
+
* @example "Pixelic"
|
|
14
|
+
*/
|
|
15
|
+
type Username = string;
|
|
16
|
+
/**
|
|
17
|
+
* Minecraft UUIDv4 (both undashed and dashed will be accepted)
|
|
18
|
+
*
|
|
19
|
+
* @example b876ec32e396476ba1158438d83c67d4
|
|
20
|
+
*/
|
|
21
|
+
type UUID = string;
|
|
22
|
+
|
|
23
|
+
type ClientOptions = {
|
|
24
|
+
logger?: LoggerConfig;
|
|
25
|
+
validation?: ValidationOptions;
|
|
26
|
+
timeout?: number;
|
|
27
|
+
cache?: CacheOptions;
|
|
28
|
+
baseURL?: string;
|
|
29
|
+
fallback?: boolean;
|
|
30
|
+
};
|
|
31
|
+
type ValidationOptions = {
|
|
32
|
+
enabled?: boolean;
|
|
33
|
+
minimumUsernameLength?: 1 | 2;
|
|
34
|
+
};
|
|
35
|
+
type MowojangRequestConfig = {
|
|
36
|
+
validation?: ValidationOptions;
|
|
37
|
+
cache?: CacheRequestConfig<any, any>["cache"];
|
|
38
|
+
};
|
|
39
|
+
type MowojangError = "INVALID_PLAYER";
|
|
40
|
+
type MowojangResponse<D, E extends MowojangError | undefined> = Promise<{
|
|
41
|
+
data: D;
|
|
42
|
+
error: null;
|
|
43
|
+
} | {
|
|
44
|
+
data: null;
|
|
45
|
+
error: E extends undefined ? "UNKNOWN_ERROR" | "INVALID_INPUT" : E | "UNKNOWN_ERROR" | "INVALID_INPUT";
|
|
46
|
+
}>;
|
|
47
|
+
|
|
48
|
+
type MowojangProfile = {
|
|
49
|
+
UUID: UUID;
|
|
50
|
+
username: Username;
|
|
51
|
+
};
|
|
52
|
+
type MowojangSession = {
|
|
53
|
+
UUID: UUID;
|
|
54
|
+
username: Username;
|
|
55
|
+
skin: MowojangSkin;
|
|
56
|
+
cape: MowojangCape;
|
|
57
|
+
actions: ("FORCED_NAME_CHANGE" | "USING_BANNED_SKIN")[];
|
|
58
|
+
};
|
|
59
|
+
type MowojangSkin = null | {
|
|
60
|
+
url: string;
|
|
61
|
+
hash: string;
|
|
62
|
+
metadata: {
|
|
63
|
+
slim: boolean;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
type MowojangCape = null | {
|
|
67
|
+
url: string;
|
|
68
|
+
hash: string;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
declare class Client {
|
|
3
72
|
private logger;
|
|
4
73
|
private axios;
|
|
5
74
|
private validation;
|
|
@@ -62,3 +131,19 @@ export default class Client {
|
|
|
62
131
|
*/
|
|
63
132
|
getCapeBuffer(player: Player, config?: MowojangRequestConfig): Promise<null | Buffer>;
|
|
64
133
|
}
|
|
134
|
+
|
|
135
|
+
declare const validate: {
|
|
136
|
+
player: (player: Player, minimumUsernameLength?: 1 | 2) => boolean;
|
|
137
|
+
UUID: (UUID: UUID) => boolean;
|
|
138
|
+
username: (username: string, minimumLength?: 1 | 2) => boolean;
|
|
139
|
+
};
|
|
140
|
+
declare const utils: {
|
|
141
|
+
dashUUID: (UUID: UUID) => UUID;
|
|
142
|
+
undashUUID: (UUID: UUID) => UUID;
|
|
143
|
+
};
|
|
144
|
+
declare const cache: {
|
|
145
|
+
buildStorage: typeof buildStorage;
|
|
146
|
+
buildMemoryStorage: typeof buildMemoryStorage;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export { Client, cache, utils, validate };
|