File tree Expand file tree Collapse file tree 3 files changed +49
-1
lines changed
Expand file tree Collapse file tree 3 files changed +49
-1
lines changed Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ import { ServerRegistryEntry } from "./types/server-registry/server-registry-ent
99import { Player } from "./types/player/player" ;
1010import { CachedPlayerName } from "./types/cache/cached-player-name" ;
1111import { StatisticsResponse } from "./types/response/statistics-response" ;
12+ import { Skin } from "./types/player/skin/skin" ;
13+ import { Page } from "./types/pagination/pagination" ;
1214
1315export 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
348366export default McUtilsAPI ;
Original file line number Diff line number Diff line change 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 [ ] > ;
You can’t perform that action at this time.
0 commit comments