mowojang 0.4.3 → 0.4.4

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/dist/index.js ADDED
@@ -0,0 +1,1021 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/client.ts
5
+ import { isAxiosError } from "axios";
6
+
7
+ // src/axiosInstance.ts
8
+ import axios from "axios";
9
+ import { setupCache } from "axios-cache-interceptor";
10
+
11
+ // package.json
12
+ var package_default = {
13
+ name: "mowojang",
14
+ version: "0.4.4",
15
+ description: "A simple JavaScript and TypeScript compatible wrapper for the Mowojang-API.",
16
+ exports: {
17
+ ".": {
18
+ types: "./dist/index.d.ts",
19
+ import: "./dist/index.js"
20
+ }
21
+ },
22
+ files: [
23
+ "dist"
24
+ ],
25
+ type: "module",
26
+ scripts: {
27
+ build: "tsup",
28
+ test: "node test test/index.js",
29
+ "prettier:check": "pnpm dlx prettier . --check",
30
+ "prettier:write": "pnpm dlx prettier . --write",
31
+ prepare: "pnpm build"
32
+ },
33
+ repository: {
34
+ type: "git",
35
+ url: "https://github.com/Pixelicc/mowojang-js"
36
+ },
37
+ keywords: [
38
+ "Minecraft",
39
+ "Mowojang",
40
+ "Wrapper",
41
+ "API"
42
+ ],
43
+ author: "Pixelic",
44
+ license: "MIT",
45
+ engines: {
46
+ node: ">=22.0.0"
47
+ },
48
+ dependencies: {
49
+ axios: "^1.16.1",
50
+ "axios-cache-interceptor": "^1.12.0"
51
+ },
52
+ devDependencies: {
53
+ "@types/node": "^25.9.1",
54
+ "@pixelic/logger": "npm:@jsr/pixelic__logger@^0.0.6",
55
+ tsup: "^8.5.1",
56
+ typescript: "^6.0.3"
57
+ }
58
+ };
59
+
60
+ // src/axiosInstance.ts
61
+ var axiosInstance_default = /* @__PURE__ */ __name((options, logger) => {
62
+ const instance = setupCache(
63
+ axios.create({
64
+ timeout: options?.timeout ?? 1e4,
65
+ maxRedirects: 0,
66
+ headers: {
67
+ "User-Agent": `axios/${axios.VERSION} mowojang/${package_default.version} (https://www.npmjs.com/package/mowojang)`,
68
+ Accept: "application/json"
69
+ }
70
+ }),
71
+ {
72
+ methods: ["get", "post"],
73
+ cacheTakeover: false,
74
+ ...options?.cache
75
+ }
76
+ );
77
+ instance.interceptors.request.use((req) => {
78
+ req.internalId = Math.random().toString(16).slice(2, 10).padEnd(8, "0");
79
+ logger.debug("Mowojang", `(${req.internalId}) ${req.method?.toUpperCase()} ${axios.getUri(req)}`);
80
+ return req;
81
+ });
82
+ instance.interceptors.response.use(
83
+ (res) => {
84
+ if (res.cached) {
85
+ logger.debug(
86
+ "Mowojang",
87
+ // @ts-expect-error
88
+ `(${res.config.internalId}) ${res.stale ? "GET-CACHE-STALE" : "GET-CACHE"} ${axios.getUri(res.config)}`
89
+ );
90
+ }
91
+ return res;
92
+ },
93
+ (err) => {
94
+ const isConnectionError = err.code === "ECONNRESET" || err.code === "ETIMEDOUT" || (err?.response?.status ?? 0) >= 500;
95
+ if (isConnectionError) {
96
+ const fullURL = axios.getUri(err.config);
97
+ const host = new URL(fullURL).host;
98
+ if (host === "mowojang.matdoes.dev" && !err.config._retry) {
99
+ err.config._retry = true;
100
+ err.config.url = fullURL.replace("mowojang.matdoes.dev", "mowojang.seraph.si");
101
+ if (err.config.baseURL) delete err.config.baseURL;
102
+ logger.critical(
103
+ "Mowojang",
104
+ `(${err.config.internalId}) Failed to establish connection to mowojang.matdoes.dev`
105
+ );
106
+ if (options.fallback) {
107
+ logger.info("Mowojang", `(${err.config.internalId}) Retrying request with fallback of mowojang.seraph.si`);
108
+ }
109
+ logger.info("Mowojang", `Check Status of Mowojang on: https://mowojang-status.pixelic.dev`);
110
+ if (options.fallback) return instance(err.config);
111
+ } else if (host === "mowojang.seraph.si") {
112
+ logger.critical(
113
+ "Mowojang",
114
+ `(${err.config.internalId}) Failed to establish connection to mowojang.seraph.si`
115
+ );
116
+ logger.info("Mowojang", `Check Status of Seraph on: https://mowojang-status.pixelic.dev`);
117
+ } else {
118
+ logger.critical("Mowojang", `(${err.config.internalId}) Failed to establish connection to ${host}`);
119
+ }
120
+ }
121
+ return Promise.reject(err);
122
+ }
123
+ );
124
+ return instance;
125
+ }, "default");
126
+
127
+ // src/utils.ts
128
+ var undashUUID = /* @__PURE__ */ __name((UUID) => UUID.replace(/-/g, "").toLowerCase(), "undashUUID");
129
+ var dashUUID = /* @__PURE__ */ __name((UUID) => undashUUID(UUID).replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5"), "dashUUID");
130
+
131
+ // src/validators.ts
132
+ var validateUUID = /* @__PURE__ */ __name((UUID) => {
133
+ if (typeof UUID !== "string") return false;
134
+ UUID = undashUUID(UUID);
135
+ if (UUID.length !== 32) return false;
136
+ return /[0-9a-f]{12}4[0-9a-f]{19}/.test(UUID);
137
+ }, "validateUUID");
138
+ var validateUsername = /* @__PURE__ */ __name((username, minimumLength) => {
139
+ if (typeof username !== "string") return false;
140
+ if (minimumLength === 1) return /^[a-zA-Z0-9_]{1,16}$/.test(username);
141
+ if (minimumLength === 2) return /^[a-zA-Z0-9_]{2,16}$/.test(username);
142
+ return /^[a-zA-Z0-9_]{3,16}$/.test(username);
143
+ }, "validateUsername");
144
+ var validatePlayer = /* @__PURE__ */ __name((player, minimumUsernameLength) => validateUUID(player) || validateUsername(player, minimumUsernameLength), "validatePlayer");
145
+ var validateArray = /* @__PURE__ */ __name((array, validatorFunction, ...params) => {
146
+ if (!Array.isArray(array)) return false;
147
+ return array.every((item) => validatorFunction(item, ...params));
148
+ }, "validateArray");
149
+
150
+ // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
151
+ var ANSI_BACKGROUND_OFFSET = 10;
152
+ var wrapAnsi16 = /* @__PURE__ */ __name((offset = 0) => (code) => `\x1B[${code + offset}m`, "wrapAnsi16");
153
+ var wrapAnsi256 = /* @__PURE__ */ __name((offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`, "wrapAnsi256");
154
+ var wrapAnsi16m = /* @__PURE__ */ __name((offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`, "wrapAnsi16m");
155
+ var styles = {
156
+ modifier: {
157
+ reset: [0, 0],
158
+ // 21 isn't widely supported and 22 does the same thing
159
+ bold: [1, 22],
160
+ dim: [2, 22],
161
+ italic: [3, 23],
162
+ underline: [4, 24],
163
+ overline: [53, 55],
164
+ inverse: [7, 27],
165
+ hidden: [8, 28],
166
+ strikethrough: [9, 29]
167
+ },
168
+ color: {
169
+ black: [30, 39],
170
+ red: [31, 39],
171
+ green: [32, 39],
172
+ yellow: [33, 39],
173
+ blue: [34, 39],
174
+ magenta: [35, 39],
175
+ cyan: [36, 39],
176
+ white: [37, 39],
177
+ // Bright color
178
+ blackBright: [90, 39],
179
+ gray: [90, 39],
180
+ // Alias of `blackBright`
181
+ grey: [90, 39],
182
+ // Alias of `blackBright`
183
+ redBright: [91, 39],
184
+ greenBright: [92, 39],
185
+ yellowBright: [93, 39],
186
+ blueBright: [94, 39],
187
+ magentaBright: [95, 39],
188
+ cyanBright: [96, 39],
189
+ whiteBright: [97, 39]
190
+ },
191
+ bgColor: {
192
+ bgBlack: [40, 49],
193
+ bgRed: [41, 49],
194
+ bgGreen: [42, 49],
195
+ bgYellow: [43, 49],
196
+ bgBlue: [44, 49],
197
+ bgMagenta: [45, 49],
198
+ bgCyan: [46, 49],
199
+ bgWhite: [47, 49],
200
+ // Bright color
201
+ bgBlackBright: [100, 49],
202
+ bgGray: [100, 49],
203
+ // Alias of `bgBlackBright`
204
+ bgGrey: [100, 49],
205
+ // Alias of `bgBlackBright`
206
+ bgRedBright: [101, 49],
207
+ bgGreenBright: [102, 49],
208
+ bgYellowBright: [103, 49],
209
+ bgBlueBright: [104, 49],
210
+ bgMagentaBright: [105, 49],
211
+ bgCyanBright: [106, 49],
212
+ bgWhiteBright: [107, 49]
213
+ }
214
+ };
215
+ var modifierNames = Object.keys(styles.modifier);
216
+ var foregroundColorNames = Object.keys(styles.color);
217
+ var backgroundColorNames = Object.keys(styles.bgColor);
218
+ var colorNames = [...foregroundColorNames, ...backgroundColorNames];
219
+ function assembleStyles() {
220
+ const codes = /* @__PURE__ */ new Map();
221
+ for (const [groupName, group] of Object.entries(styles)) {
222
+ for (const [styleName, style] of Object.entries(group)) {
223
+ styles[styleName] = {
224
+ open: `\x1B[${style[0]}m`,
225
+ close: `\x1B[${style[1]}m`
226
+ };
227
+ group[styleName] = styles[styleName];
228
+ codes.set(style[0], style[1]);
229
+ }
230
+ Object.defineProperty(styles, groupName, {
231
+ value: group,
232
+ enumerable: false
233
+ });
234
+ }
235
+ Object.defineProperty(styles, "codes", {
236
+ value: codes,
237
+ enumerable: false
238
+ });
239
+ styles.color.close = "\x1B[39m";
240
+ styles.bgColor.close = "\x1B[49m";
241
+ styles.color.ansi = wrapAnsi16();
242
+ styles.color.ansi256 = wrapAnsi256();
243
+ styles.color.ansi16m = wrapAnsi16m();
244
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
245
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
246
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
247
+ Object.defineProperties(styles, {
248
+ rgbToAnsi256: {
249
+ value(red, green, blue) {
250
+ if (red === green && green === blue) {
251
+ if (red < 8) {
252
+ return 16;
253
+ }
254
+ if (red > 248) {
255
+ return 231;
256
+ }
257
+ return Math.round((red - 8) / 247 * 24) + 232;
258
+ }
259
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
260
+ },
261
+ enumerable: false
262
+ },
263
+ hexToRgb: {
264
+ value(hex) {
265
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
266
+ if (!matches) {
267
+ return [0, 0, 0];
268
+ }
269
+ let [colorString] = matches;
270
+ if (colorString.length === 3) {
271
+ colorString = [...colorString].map((character) => character + character).join("");
272
+ }
273
+ const integer = Number.parseInt(colorString, 16);
274
+ return [
275
+ /* eslint-disable no-bitwise */
276
+ integer >> 16 & 255,
277
+ integer >> 8 & 255,
278
+ integer & 255
279
+ /* eslint-enable no-bitwise */
280
+ ];
281
+ },
282
+ enumerable: false
283
+ },
284
+ hexToAnsi256: {
285
+ value: /* @__PURE__ */ __name((hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)), "value"),
286
+ enumerable: false
287
+ },
288
+ ansi256ToAnsi: {
289
+ value(code) {
290
+ if (code < 8) {
291
+ return 30 + code;
292
+ }
293
+ if (code < 16) {
294
+ return 90 + (code - 8);
295
+ }
296
+ let red;
297
+ let green;
298
+ let blue;
299
+ if (code >= 232) {
300
+ red = ((code - 232) * 10 + 8) / 255;
301
+ green = red;
302
+ blue = red;
303
+ } else {
304
+ code -= 16;
305
+ const remainder = code % 36;
306
+ red = Math.floor(code / 36) / 5;
307
+ green = Math.floor(remainder / 6) / 5;
308
+ blue = remainder % 6 / 5;
309
+ }
310
+ const value = Math.max(red, green, blue) * 2;
311
+ if (value === 0) {
312
+ return 30;
313
+ }
314
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
315
+ if (value === 2) {
316
+ result += 60;
317
+ }
318
+ return result;
319
+ },
320
+ enumerable: false
321
+ },
322
+ rgbToAnsi: {
323
+ value: /* @__PURE__ */ __name((red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)), "value"),
324
+ enumerable: false
325
+ },
326
+ hexToAnsi: {
327
+ value: /* @__PURE__ */ __name((hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)), "value"),
328
+ enumerable: false
329
+ }
330
+ });
331
+ return styles;
332
+ }
333
+ __name(assembleStyles, "assembleStyles");
334
+ var ansiStyles = assembleStyles();
335
+ var ansi_styles_default = ansiStyles;
336
+
337
+ // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js
338
+ import process from "process";
339
+ import os from "os";
340
+ import tty from "tty";
341
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process.argv) {
342
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
343
+ const position = argv.indexOf(prefix + flag);
344
+ const terminatorPosition = argv.indexOf("--");
345
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
346
+ }
347
+ __name(hasFlag, "hasFlag");
348
+ var { env } = process;
349
+ var flagForceColor;
350
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
351
+ flagForceColor = 0;
352
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
353
+ flagForceColor = 1;
354
+ }
355
+ function envForceColor() {
356
+ if ("FORCE_COLOR" in env) {
357
+ if (env.FORCE_COLOR === "true") {
358
+ return 1;
359
+ }
360
+ if (env.FORCE_COLOR === "false") {
361
+ return 0;
362
+ }
363
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
364
+ }
365
+ }
366
+ __name(envForceColor, "envForceColor");
367
+ function translateLevel(level) {
368
+ if (level === 0) {
369
+ return false;
370
+ }
371
+ return {
372
+ level,
373
+ hasBasic: true,
374
+ has256: level >= 2,
375
+ has16m: level >= 3
376
+ };
377
+ }
378
+ __name(translateLevel, "translateLevel");
379
+ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
380
+ const noFlagForceColor = envForceColor();
381
+ if (noFlagForceColor !== void 0) {
382
+ flagForceColor = noFlagForceColor;
383
+ }
384
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
385
+ if (forceColor === 0) {
386
+ return 0;
387
+ }
388
+ if (sniffFlags) {
389
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
390
+ return 3;
391
+ }
392
+ if (hasFlag("color=256")) {
393
+ return 2;
394
+ }
395
+ }
396
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) {
397
+ return 1;
398
+ }
399
+ if (haveStream && !streamIsTTY && forceColor === void 0) {
400
+ return 0;
401
+ }
402
+ const min = forceColor || 0;
403
+ if (env.TERM === "dumb") {
404
+ return min;
405
+ }
406
+ if (process.platform === "win32") {
407
+ const osRelease = os.release().split(".");
408
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
409
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
410
+ }
411
+ return 1;
412
+ }
413
+ if ("CI" in env) {
414
+ if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
415
+ return 3;
416
+ }
417
+ if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
418
+ return 1;
419
+ }
420
+ return min;
421
+ }
422
+ if ("TEAMCITY_VERSION" in env) {
423
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
424
+ }
425
+ if (env.COLORTERM === "truecolor") {
426
+ return 3;
427
+ }
428
+ if (env.TERM === "xterm-kitty") {
429
+ return 3;
430
+ }
431
+ if (env.TERM === "xterm-ghostty") {
432
+ return 3;
433
+ }
434
+ if (env.TERM === "wezterm") {
435
+ return 3;
436
+ }
437
+ if ("TERM_PROGRAM" in env) {
438
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
439
+ switch (env.TERM_PROGRAM) {
440
+ case "iTerm.app": {
441
+ return version >= 3 ? 3 : 2;
442
+ }
443
+ case "Apple_Terminal": {
444
+ return 2;
445
+ }
446
+ }
447
+ }
448
+ if (/-256(color)?$/i.test(env.TERM)) {
449
+ return 2;
450
+ }
451
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
452
+ return 1;
453
+ }
454
+ if ("COLORTERM" in env) {
455
+ return 1;
456
+ }
457
+ return min;
458
+ }
459
+ __name(_supportsColor, "_supportsColor");
460
+ function createSupportsColor(stream, options = {}) {
461
+ const level = _supportsColor(stream, {
462
+ streamIsTTY: stream && stream.isTTY,
463
+ ...options
464
+ });
465
+ return translateLevel(level);
466
+ }
467
+ __name(createSupportsColor, "createSupportsColor");
468
+ var supportsColor = {
469
+ stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
470
+ stderr: createSupportsColor({ isTTY: tty.isatty(2) })
471
+ };
472
+ var supports_color_default = supportsColor;
473
+
474
+ // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js
475
+ function stringReplaceAll(string, substring, replacer) {
476
+ let index = string.indexOf(substring);
477
+ if (index === -1) {
478
+ return string;
479
+ }
480
+ const substringLength = substring.length;
481
+ let endIndex = 0;
482
+ let returnValue = "";
483
+ do {
484
+ returnValue += string.slice(endIndex, index) + substring + replacer;
485
+ endIndex = index + substringLength;
486
+ index = string.indexOf(substring, endIndex);
487
+ } while (index !== -1);
488
+ returnValue += string.slice(endIndex);
489
+ return returnValue;
490
+ }
491
+ __name(stringReplaceAll, "stringReplaceAll");
492
+ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
493
+ let endIndex = 0;
494
+ let returnValue = "";
495
+ do {
496
+ const gotCR = string[index - 1] === "\r";
497
+ returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
498
+ endIndex = index + 1;
499
+ index = string.indexOf("\n", endIndex);
500
+ } while (index !== -1);
501
+ returnValue += string.slice(endIndex);
502
+ return returnValue;
503
+ }
504
+ __name(stringEncaseCRLFWithFirstIndex, "stringEncaseCRLFWithFirstIndex");
505
+
506
+ // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
507
+ var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
508
+ var GENERATOR = /* @__PURE__ */ Symbol("GENERATOR");
509
+ var STYLER = /* @__PURE__ */ Symbol("STYLER");
510
+ var IS_EMPTY = /* @__PURE__ */ Symbol("IS_EMPTY");
511
+ var levelMapping = [
512
+ "ansi",
513
+ "ansi",
514
+ "ansi256",
515
+ "ansi16m"
516
+ ];
517
+ var styles2 = /* @__PURE__ */ Object.create(null);
518
+ var applyOptions = /* @__PURE__ */ __name((object, options = {}) => {
519
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
520
+ throw new Error("The `level` option should be an integer from 0 to 3");
521
+ }
522
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
523
+ object.level = options.level === void 0 ? colorLevel : options.level;
524
+ }, "applyOptions");
525
+ var chalkFactory = /* @__PURE__ */ __name((options) => {
526
+ const chalk2 = /* @__PURE__ */ __name((...strings) => strings.join(" "), "chalk");
527
+ applyOptions(chalk2, options);
528
+ Object.setPrototypeOf(chalk2, createChalk.prototype);
529
+ return chalk2;
530
+ }, "chalkFactory");
531
+ function createChalk(options) {
532
+ return chalkFactory(options);
533
+ }
534
+ __name(createChalk, "createChalk");
535
+ Object.setPrototypeOf(createChalk.prototype, Function.prototype);
536
+ for (const [styleName, style] of Object.entries(ansi_styles_default)) {
537
+ styles2[styleName] = {
538
+ get() {
539
+ const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
540
+ Object.defineProperty(this, styleName, { value: builder });
541
+ return builder;
542
+ }
543
+ };
544
+ }
545
+ styles2.visible = {
546
+ get() {
547
+ const builder = createBuilder(this, this[STYLER], true);
548
+ Object.defineProperty(this, "visible", { value: builder });
549
+ return builder;
550
+ }
551
+ };
552
+ var getModelAnsi = /* @__PURE__ */ __name((model, level, type, ...arguments_) => {
553
+ if (model === "rgb") {
554
+ if (level === "ansi16m") {
555
+ return ansi_styles_default[type].ansi16m(...arguments_);
556
+ }
557
+ if (level === "ansi256") {
558
+ return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
559
+ }
560
+ return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
561
+ }
562
+ if (model === "hex") {
563
+ return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
564
+ }
565
+ return ansi_styles_default[type][model](...arguments_);
566
+ }, "getModelAnsi");
567
+ var usedModels = ["rgb", "hex", "ansi256"];
568
+ for (const model of usedModels) {
569
+ styles2[model] = {
570
+ get() {
571
+ const { level } = this;
572
+ return function(...arguments_) {
573
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
574
+ return createBuilder(this, styler, this[IS_EMPTY]);
575
+ };
576
+ }
577
+ };
578
+ const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
579
+ styles2[bgModel] = {
580
+ get() {
581
+ const { level } = this;
582
+ return function(...arguments_) {
583
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
584
+ return createBuilder(this, styler, this[IS_EMPTY]);
585
+ };
586
+ }
587
+ };
588
+ }
589
+ var proto = Object.defineProperties(() => {
590
+ }, {
591
+ ...styles2,
592
+ level: {
593
+ enumerable: true,
594
+ get() {
595
+ return this[GENERATOR].level;
596
+ },
597
+ set(level) {
598
+ this[GENERATOR].level = level;
599
+ }
600
+ }
601
+ });
602
+ var createStyler = /* @__PURE__ */ __name((open, close, parent) => {
603
+ let openAll;
604
+ let closeAll;
605
+ if (parent === void 0) {
606
+ openAll = open;
607
+ closeAll = close;
608
+ } else {
609
+ openAll = parent.openAll + open;
610
+ closeAll = close + parent.closeAll;
611
+ }
612
+ return {
613
+ open,
614
+ close,
615
+ openAll,
616
+ closeAll,
617
+ parent
618
+ };
619
+ }, "createStyler");
620
+ var createBuilder = /* @__PURE__ */ __name((self, _styler, _isEmpty) => {
621
+ const builder = /* @__PURE__ */ __name((...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" ")), "builder");
622
+ Object.setPrototypeOf(builder, proto);
623
+ builder[GENERATOR] = self;
624
+ builder[STYLER] = _styler;
625
+ builder[IS_EMPTY] = _isEmpty;
626
+ return builder;
627
+ }, "createBuilder");
628
+ var applyStyle = /* @__PURE__ */ __name((self, string) => {
629
+ if (self.level <= 0 || !string) {
630
+ return self[IS_EMPTY] ? "" : string;
631
+ }
632
+ let styler = self[STYLER];
633
+ if (styler === void 0) {
634
+ return string;
635
+ }
636
+ const { openAll, closeAll } = styler;
637
+ if (string.includes("\x1B")) {
638
+ while (styler !== void 0) {
639
+ string = stringReplaceAll(string, styler.close, styler.open);
640
+ styler = styler.parent;
641
+ }
642
+ }
643
+ const lfIndex = string.indexOf("\n");
644
+ if (lfIndex !== -1) {
645
+ string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
646
+ }
647
+ return openAll + string + closeAll;
648
+ }, "applyStyle");
649
+ Object.defineProperties(createChalk.prototype, styles2);
650
+ var chalk = createChalk();
651
+ var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
652
+ var source_default = chalk;
653
+
654
+ // node_modules/.pnpm/@jsr+pixelic__logger@0.0.6/node_modules/@jsr/pixelic__logger/src/index.js
655
+ var LogLevels = /* @__PURE__ */ (function(LogLevels2) {
656
+ LogLevels2[LogLevels2["TRACE"] = 1] = "TRACE";
657
+ LogLevels2[LogLevels2["DEBUG"] = 2] = "DEBUG";
658
+ LogLevels2[LogLevels2["INFO"] = 3] = "INFO";
659
+ LogLevels2[LogLevels2["WARNING"] = 4] = "WARNING";
660
+ LogLevels2[LogLevels2["ERROR"] = 5] = "ERROR";
661
+ LogLevels2[LogLevels2["CRITICAL"] = 6] = "CRITICAL";
662
+ return LogLevels2;
663
+ })({});
664
+ var Logger = class {
665
+ static {
666
+ __name(this, "Logger");
667
+ }
668
+ minLevel = "INFO";
669
+ /**
670
+ * @constructor Creates a Logger Instance
671
+ */
672
+ constructor(config) {
673
+ if (config?.minLevel) this.minLevel = config.minLevel;
674
+ }
675
+ /**
676
+ * @private Checks whether the given Log Level satisfies the set `minLevel` of the constructor
677
+ *
678
+ * @param level Log Level to check against the `minLevel`
679
+ */
680
+ satisfiesMinLevel(level) {
681
+ return LogLevels[level] >= LogLevels[this.minLevel];
682
+ }
683
+ /**
684
+ * @public Logs a message to the console using the runtime's default console implementation
685
+ *
686
+ * @param service Service that emitted the log call
687
+ * @param msg Message to log
688
+ * @param level Log Level
689
+ */
690
+ log(service, msg, level) {
691
+ if (!this.satisfiesMinLevel(level)) return;
692
+ const chalkedDate = source_default.white(`${String((/* @__PURE__ */ new Date()).getHours()).padStart(2, "0")}:${String((/* @__PURE__ */ new Date()).getMinutes()).padStart(2, "0")}:${String((/* @__PURE__ */ new Date()).getSeconds()).padStart(2, "0")}`);
693
+ switch (level) {
694
+ case "CRITICAL":
695
+ console.error(`[${chalkedDate}] [${source_default.greenBright(service)}] [${source_default.bgRed(level)}] \xBB ${source_default.bgRed(msg)}`);
696
+ break;
697
+ case "ERROR":
698
+ console.error(`[${chalkedDate}] [${source_default.greenBright(service)}] [${source_default.red(level)}] \xBB ${source_default.red(msg)}`);
699
+ break;
700
+ case "WARNING":
701
+ console.warn(`[${chalkedDate}] [${source_default.greenBright(service)}] [${source_default.yellow(level)}] \xBB ${source_default.yellow(msg)}`);
702
+ break;
703
+ case "INFO":
704
+ console.log(`[${chalkedDate}] [${source_default.greenBright(service)}] [${source_default.blue(level)}] \xBB ${source_default.blue(msg)}`);
705
+ break;
706
+ case "DEBUG":
707
+ console.log(`[${chalkedDate}] [${source_default.greenBright(service)}] [${source_default.cyan(level)}] \xBB ${source_default.cyan(msg)}`);
708
+ break;
709
+ case "TRACE":
710
+ console.log(`[${chalkedDate}] [${source_default.greenBright(service)}] [${source_default.gray(level)}] \xBB ${source_default.gray(msg)}`);
711
+ break;
712
+ }
713
+ }
714
+ /**
715
+ * @public Logs a message to the console using the runtime's default console implementation with the **CRITICAL** Level
716
+ *
717
+ * @param service Service that emitted the log call
718
+ * @param msg Message to log
719
+ */
720
+ critical(service, msg) {
721
+ this.log(service, msg, "CRITICAL");
722
+ }
723
+ /**
724
+ * @public Logs a message to the console using the runtime's default console implementation with the **ERROR** Level
725
+ *
726
+ * @param service Service that emitted the log call
727
+ * @param msg Message to log
728
+ */
729
+ error(service, msg) {
730
+ this.log(service, msg, "ERROR");
731
+ }
732
+ /**
733
+ * @public Logs a message to the console using the runtime's default console implementation with the **WARNING** Level
734
+ *
735
+ * @param service Service that emitted the log call
736
+ * @param msg Message to log
737
+ */
738
+ warning(service, msg) {
739
+ this.log(service, msg, "WARNING");
740
+ }
741
+ /**
742
+ * @public Logs a message to the console using the runtime's default console implementation with the **INFO** Level
743
+ *
744
+ * @param service Service that emitted the log call
745
+ * @param msg Message to log
746
+ */
747
+ info(service, msg) {
748
+ this.log(service, msg, "INFO");
749
+ }
750
+ /**
751
+ * @public Logs a message to the console using the runtime's default console implementation with the **DEBUG** Level
752
+ *
753
+ * @param service Service that emitted the log call
754
+ * @param msg Message to log
755
+ */
756
+ debug(service, msg) {
757
+ this.log(service, msg, "DEBUG");
758
+ }
759
+ /**
760
+ * @public Logs a message to the console using the runtime's default console implementation with the **TRACE** Level
761
+ *
762
+ * @param service Service that emitted the log call
763
+ * @param msg Message to log
764
+ */
765
+ trace(service, msg) {
766
+ this.log(service, msg, "TRACE");
767
+ }
768
+ };
769
+
770
+ // src/client.ts
771
+ var Client = class {
772
+ static {
773
+ __name(this, "Client");
774
+ }
775
+ logger;
776
+ axios;
777
+ validation;
778
+ baseURL;
779
+ constructor(clientOptions) {
780
+ this.logger = new Logger(clientOptions?.logger);
781
+ this.validation = clientOptions?.validation ?? {};
782
+ this.baseURL = (clientOptions?.baseURL ?? "https://mowojang.matdoes.dev").toLowerCase();
783
+ this.axios = axiosInstance_default({ fallback: true, ...clientOptions }, this.logger);
784
+ }
785
+ shouldValidate(config) {
786
+ return this.validation?.enabled || config?.validation?.enabled || false;
787
+ }
788
+ getValidationMinLength(config) {
789
+ if (this.validation?.minimumUsernameLength === 1) return 1;
790
+ if (this.validation?.minimumUsernameLength === 2) return 2;
791
+ if (config?.validation?.minimumUsernameLength === 1) return 1;
792
+ if (config?.validation?.minimumUsernameLength === 2) return 2;
793
+ return void 0;
794
+ }
795
+ /**
796
+ * Returns an Array of Player Profiles consisting of their Usernames and UUIDs
797
+ *
798
+ * Players considered "INVALID" are excluded from the results
799
+ */
800
+ async getProfiles(players, config) {
801
+ try {
802
+ if (this.shouldValidate(config) && !validateArray(players, validatePlayer, this.getValidationMinLength(config)))
803
+ return { data: null, error: "INVALID_INPUT" };
804
+ players = players.map((player) => {
805
+ if (validateUUID(player)) return undashUUID(player);
806
+ return player.toLowerCase();
807
+ }).sort();
808
+ const usePost = config?.usePost ?? false;
809
+ if (usePost) {
810
+ const fetchResponse = await this.axios.post(this.baseURL, players, {
811
+ cache: config?.cache ?? { ttl: 15 * 60 * 1e3 }
812
+ });
813
+ if (!Array.isArray(fetchResponse?.data)) return { data: null, error: "UNKNOWN_ERROR" };
814
+ return {
815
+ data: fetchResponse.data.map((player) => {
816
+ return {
817
+ UUID: player.id,
818
+ username: player.name
819
+ };
820
+ }),
821
+ error: null
822
+ };
823
+ }
824
+ const profilePromises = [];
825
+ players.forEach((player) => {
826
+ profilePromises.push(this.getProfile(player, config));
827
+ });
828
+ const profiles = (await Promise.all(profilePromises)).filter((p) => p.data !== null).map((p) => p.data);
829
+ return {
830
+ // @ts-ignore
831
+ data: profiles,
832
+ error: null
833
+ };
834
+ } catch {
835
+ return { data: null, error: "UNKNOWN_ERROR" };
836
+ }
837
+ }
838
+ /**
839
+ * Returns a Player's Profile consisting of their Username and UUID
840
+ *
841
+ */
842
+ async getProfile(player, config) {
843
+ try {
844
+ if (this.shouldValidate(config) && !validatePlayer(player, this.getValidationMinLength(config)))
845
+ return { data: null, error: "INVALID_INPUT" };
846
+ const fetchResponse = await this.axios.get(`${this.baseURL}/${player}`, {
847
+ cache: config?.cache ?? { ttl: 15 * 60 * 1e3 }
848
+ });
849
+ return {
850
+ data: {
851
+ UUID: fetchResponse.data.id,
852
+ username: fetchResponse.data.name
853
+ },
854
+ error: null
855
+ };
856
+ } catch {
857
+ return { data: null, error: "INVALID_PLAYER" };
858
+ }
859
+ }
860
+ /**
861
+ * A Simple Wrapper to Retrieve Only the UUID of a Player's Profile
862
+ *
863
+ */
864
+ async getUUID(username, config) {
865
+ const profile = await this.getProfile(username, config);
866
+ if (profile.error) return null;
867
+ return profile.data.UUID;
868
+ }
869
+ /**
870
+ * A Simple Wrapper to Retrieve Only the Username of a Player's Profile
871
+ *
872
+ */
873
+ async getUsername(UUID, config) {
874
+ const profile = await this.getProfile(UUID, config);
875
+ if (profile.error) return null;
876
+ return profile.data.username;
877
+ }
878
+ /**
879
+ * Returns an Array of Player Sessions consisting of their Usernames, UUIDs, Skins and Capes
880
+ *
881
+ * Players considered "INVALID" are excluded from the results
882
+ */
883
+ async getSessions(players, config) {
884
+ try {
885
+ if (this.shouldValidate(config) && !validateArray(players, validatePlayer, this.getValidationMinLength(config)))
886
+ return { data: null, error: "INVALID_INPUT" };
887
+ players = players.map((player) => {
888
+ if (validateUUID(player)) return undashUUID(player);
889
+ return player.toLowerCase();
890
+ });
891
+ const sessionsPromises = [];
892
+ players.forEach((player) => {
893
+ sessionsPromises.push(this.getSession(player, config));
894
+ });
895
+ const sessions = (await Promise.all(sessionsPromises)).filter((session) => session.data !== null).map((session) => session.data);
896
+ return {
897
+ // @ts-ignore
898
+ data: sessions,
899
+ error: null
900
+ };
901
+ } catch {
902
+ return { data: null, error: "UNKNOWN_ERROR" };
903
+ }
904
+ }
905
+ /**
906
+ * Returns a Player's Sessions consisting of their Username, UUID, Skin and Cape
907
+ *
908
+ */
909
+ async getSession(player, config) {
910
+ if (this.shouldValidate(config) && !validatePlayer(player, this.getValidationMinLength(config)))
911
+ return { data: null, error: "INVALID_INPUT" };
912
+ const UUID = await this.getUUID(player);
913
+ if (!UUID) return { data: null, error: "INVALID_PLAYER" };
914
+ return await this.axios.get(`${this.baseURL}/session/minecraft/profile/${UUID}`, {
915
+ cache: config?.cache ?? { ttl: 15 * 60 * 1e3 }
916
+ }).then((fetchResponse) => {
917
+ let textures = fetchResponse.data.properties.find((property) => property.name === "textures").value;
918
+ let skin = null;
919
+ let cape = null;
920
+ if (textures) {
921
+ textures = JSON.parse(Buffer.from(textures, "base64").toString()).textures;
922
+ if (textures.SKIN) {
923
+ skin = {
924
+ url: textures.SKIN.url,
925
+ hash: textures.SKIN.url.split("/").at(-1),
926
+ metadata: {
927
+ slim: textures.SKIN?.metadata?.model === "slim"
928
+ }
929
+ };
930
+ }
931
+ if (textures.CAPE) {
932
+ cape = {
933
+ url: textures.CAPE.url,
934
+ hash: textures.CAPE.url.split("/").at(-1)
935
+ };
936
+ }
937
+ }
938
+ return {
939
+ data: {
940
+ UUID: fetchResponse.data.id,
941
+ username: fetchResponse.data.name,
942
+ skin,
943
+ cape,
944
+ actions: fetchResponse.data.profileActions
945
+ },
946
+ error: null
947
+ };
948
+ }).catch((fetchError) => {
949
+ if (isAxiosError(fetchError)) {
950
+ return { data: null, error: "INVALID_PLAYER" };
951
+ }
952
+ return { data: null, error: "UNKNOWN_ERROR" };
953
+ });
954
+ }
955
+ /**
956
+ * A Simple Wrapper to Retrieve Only the Skin from a Player's Session
957
+ *
958
+ */
959
+ async getSkin(player, config) {
960
+ const session = await this.getSession(player, config);
961
+ if (session.error) return null;
962
+ return session.data.skin;
963
+ }
964
+ /**
965
+ * A Simple Wrapper to Retrieve Only the Player's Skin from their Session Data Loaded into a Buffer
966
+ *
967
+ */
968
+ async getSkinBuffer(player, config) {
969
+ const session = await this.getSession(player, config);
970
+ if (session.error || !session.data.skin) return null;
971
+ const fetchResponse = await this.axios.get(session.data.skin.url, {
972
+ responseType: "arraybuffer",
973
+ cache: config?.cache ?? { ttl: 24 * 60 * 60 * 1e3 }
974
+ });
975
+ return Buffer.from(fetchResponse.data, "base64");
976
+ }
977
+ /**
978
+ * A Simple Wrapper to Retrieve Only the Cape Data from a Player's Session
979
+ *
980
+ */
981
+ async getCape(player, config) {
982
+ const session = await this.getSession(player, config);
983
+ if (session.error) return null;
984
+ return session.data.cape;
985
+ }
986
+ /**
987
+ * A Simple Wrapper to Retrieve Only the Player's Cape from their Session Data Loaded into a Buffer
988
+ *
989
+ */
990
+ async getCapeBuffer(player, config) {
991
+ const session = await this.getSession(player, config);
992
+ if (session.error || !session.data.cape) return null;
993
+ const fetchResponse = await this.axios.get(session.data.cape.url, {
994
+ responseType: "arraybuffer",
995
+ cache: config?.cache ?? { ttl: 30 * 24 * 60 * 60 * 1e3 }
996
+ });
997
+ return Buffer.from(fetchResponse.data, "base64");
998
+ }
999
+ };
1000
+
1001
+ // src/index.ts
1002
+ import { buildStorage, buildMemoryStorage } from "axios-cache-interceptor";
1003
+ var validate = {
1004
+ player: validatePlayer,
1005
+ UUID: validateUUID,
1006
+ username: validateUsername
1007
+ };
1008
+ var utils = {
1009
+ dashUUID,
1010
+ undashUUID
1011
+ };
1012
+ var cache = {
1013
+ buildStorage,
1014
+ buildMemoryStorage
1015
+ };
1016
+ export {
1017
+ Client,
1018
+ cache,
1019
+ utils,
1020
+ validate
1021
+ };