Skip to content

Commit 7e9ebec

Browse files
add skins endpoint
1 parent fd30036 commit 7e9ebec

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mcutils-js-api",
3-
"version": "2.0.32",
3+
"version": "2.0.33",
44
"module": "dist/index.js",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { ServerRegistryEntry } from "./types/server-registry/server-registry-ent
99
import { Player } from "./types/player/player";
1010
import { CachedPlayerName } from "./types/cache/cached-player-name";
1111
import { StatisticsResponse } from "./types/response/statistics-response";
12+
import { Skin } from "./types/player/skin/skin";
13+
import { Page } from "./types/pagination/pagination";
1214

1315
export class McUtilsAPI {
1416
private readonly endpoint: string;
@@ -343,6 +345,22 @@ export class McUtilsAPI {
343345
error: (await response.json()) as ErrorResponse,
344346
};
345347
}
348+
349+
/**
350+
* Fetch the list of available skins.
351+
*
352+
* @param page the page to fetch (default: 1)
353+
* @returns the list of skins or the error (if one occurred)
354+
*/
355+
async fetchSkins(page: number = 1): Promise<{ skins?: Page<Skin>; error?: ErrorResponse }> {
356+
const response = await fetch(`${this.endpoint}/skins${this.buildParams({ page: String(page) })}`);
357+
if (response.ok) {
358+
return { skins: (await response.json()) as Page<Skin> };
359+
}
360+
return {
361+
error: (await response.json()) as ErrorResponse,
362+
};
363+
}
346364
}
347365

348366
export default McUtilsAPI;

src/types/pagination/pagination.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
/**
10+
* A single page of paginated results.
11+
*/
12+
export type Page<T> = {
13+
items: T[];
14+
totalItems: number;
15+
itemsPerPage: number;
16+
totalPages: number;
17+
};
18+
19+
/**
20+
* Pagination configuration (items per page and total count).
21+
*/
22+
export type PaginationConfig = {
23+
itemsPerPage: number;
24+
totalItems: number;
25+
};
26+
27+
/**
28+
* Fetcher used to load items for a page. Receives limit and skip via PageCallback.
29+
*/
30+
export type PageFetcher<T> = (callback: PageCallback) => T[] | Promise<T[]>;

0 commit comments

Comments
 (0)