mcutils-js-api 2.0.31 → 2.0.33
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.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { ServerRegistryEntry } from "./types/server-registry/server-registry-ent
|
|
|
8
8
|
import { Player } from "./types/player/player";
|
|
9
9
|
import { CachedPlayerName } from "./types/cache/cached-player-name";
|
|
10
10
|
import { StatisticsResponse } from "./types/response/statistics-response";
|
|
11
|
+
import { Skin } from "./types/player/skin/skin";
|
|
12
|
+
import { Page } from "./types/pagination/pagination";
|
|
11
13
|
export declare class McUtilsAPI {
|
|
12
14
|
private readonly endpoint;
|
|
13
15
|
constructor(endpoint?: string);
|
|
@@ -184,5 +186,15 @@ export declare class McUtilsAPI {
|
|
|
184
186
|
statistics?: StatisticsResponse;
|
|
185
187
|
error?: ErrorResponse;
|
|
186
188
|
}>;
|
|
189
|
+
/**
|
|
190
|
+
* Fetch the list of available skins.
|
|
191
|
+
*
|
|
192
|
+
* @param page the page to fetch (default: 1)
|
|
193
|
+
* @returns the list of skins or the error (if one occurred)
|
|
194
|
+
*/
|
|
195
|
+
fetchSkins(page?: number): Promise<{
|
|
196
|
+
skins?: Page<Skin>;
|
|
197
|
+
error?: ErrorResponse;
|
|
198
|
+
}>;
|
|
187
199
|
}
|
|
188
200
|
export default McUtilsAPI;
|
package/dist/index.js
CHANGED
|
@@ -269,5 +269,20 @@ export class McUtilsAPI {
|
|
|
269
269
|
error: (await response.json()),
|
|
270
270
|
};
|
|
271
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Fetch the list of available skins.
|
|
274
|
+
*
|
|
275
|
+
* @param page the page to fetch (default: 1)
|
|
276
|
+
* @returns the list of skins or the error (if one occurred)
|
|
277
|
+
*/
|
|
278
|
+
async fetchSkins(page = 1) {
|
|
279
|
+
const response = await fetch(`${this.endpoint}/skins${this.buildParams({ page: String(page) })}`);
|
|
280
|
+
if (response.ok) {
|
|
281
|
+
return { skins: (await response.json()) };
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
error: (await response.json()),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
272
287
|
}
|
|
273
288
|
export default McUtilsAPI;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callback passed to a page fetcher: limit (items per page) and skip (offset).
|
|
3
|
+
*/
|
|
4
|
+
export type PageCallback = {
|
|
5
|
+
limit: number;
|
|
6
|
+
skip: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A single page of paginated results.
|
|
10
|
+
*/
|
|
11
|
+
export type Page<T> = {
|
|
12
|
+
items: T[];
|
|
13
|
+
totalItems: number;
|
|
14
|
+
itemsPerPage: number;
|
|
15
|
+
totalPages: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Pagination configuration (items per page and total count).
|
|
19
|
+
*/
|
|
20
|
+
export type PaginationConfig = {
|
|
21
|
+
itemsPerPage: number;
|
|
22
|
+
totalItems: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Fetcher used to load items for a page. Receives limit and skip via PageCallback.
|
|
26
|
+
*/
|
|
27
|
+
export type PageFetcher<T> = (callback: PageCallback) => T[] | Promise<T[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|