Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

adds headers to wrapper response #35

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 75 additions & 59 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,28 @@ Get a player's monthly statistics.

Returns a Promise which resolves to the following object:

| Field | Type | Description |
| -------- | ------------------------------------------- | -------------------------------- |
| data | [Response](GAMES.md) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| Field | Type | Description |
| -------- | ------------------------------------------- | --------------------------------- |
| data | [Response](GAMES.md) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| headers | `Headers \| undefined` | Response headers from the request |

### Usage

```ts
import { getMonthlyStatsistics, Game } from "hive-bedrock-api";

// Get player's Treasure Wars stats from June 2023
const { data, error } = await getMonthlyStatsistics("player", Game.TreasureWars, {
year: 2023,
month: 6,
});
const { data, error } = await getMonthlyStatsistics(
"player",
Game.TreasureWars,
{
year: 2023,
month: 6,
}
);
```

## getMonthlyLeaderboard(game[, options])
Expand All @@ -50,12 +55,13 @@ Get the monthly leaderboard for a specific month.

Returns a Promise which resolves to the following object:

| Field | Type | Description |
| -------- | ------------------------------------------- | -------------------------------- |
| data | [Response](GAMES.md) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| Field | Type | Description |
| -------- | ------------------------------------------- | --------------------------------- |
| data | [Response](GAMES.md) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| headers | `Headers \| undefined` | Response headers from the request |

### Usage

Expand Down Expand Up @@ -87,6 +93,7 @@ Returns a Promise which resolves to the following object:
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| headers | `Headers \| undefined` | Response headers from the request |

### Usage

Expand All @@ -111,20 +118,23 @@ Get a player's season statistics.

Returns a Promise which resolves to the following object:

| Field | Type | Description |
| -------- | ------------------------------------------- | -------------------------------- |
| data | [Response](GAMES.md) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| Field | Type | Description |
| -------- | ------------------------------------------- | --------------------------------- |
| data | [Response](GAMES.md) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| headers | `Headers \| undefined` | Response headers from the request |

### Usage

```ts
import { getSeasonStatistics, Game } from "hive-bedrock-api";

// Get player's season stats
const { data, error } = await getSeasonStatistics("player", Game.BedWars, { season: 1 });
const { data, error } = await getSeasonStatistics("player", Game.BedWars, {
season: 1,
});
```

## getAllTimeLeaderboard(game[, options])
Expand All @@ -139,12 +149,13 @@ Get the all-time leaderboard for a game or games.

Returns a Promise which resolves to the following object:

| Field | Type | Description |
| -------- | ------------------------------------------- | -------------------------------- |
| data | [Response](GAMES.md) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| Field | Type | Description |
| -------- | ------------------------------------------- | --------------------------------- |
| data | [Response](GAMES.md) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| headers | `Headers \| undefined` | Response headers from the request |

### Usage

Expand All @@ -168,12 +179,13 @@ Get the season leaderboard for a game.

Returns a Promise which resolves to the following object:

| Field | Type | Description |
| -------- | ------------------------------------------- | -------------------------------- |
| data | [Response](GAMES.md) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| Field | Type | Description |
| -------- | ------------------------------------------- | --------------------------------- |
| data | [Response](GAMES.md) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| headers | `Headers \| undefined` | Response headers from the request |

### Usage

Expand All @@ -195,12 +207,13 @@ Get special data such as each game's all-time player count.

Returns a Promise which resolves to the following object:

| Field | Type | Description |
| -------- | ---------------------------------------------- | -------------------------------- |
| data | [Response](API.md#global-statistics) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| Field | Type | Description |
| -------- | ---------------------------------------------- | --------------------------------- |
| data | [Response](API.md#global-statistics) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| headers | `Headers \| undefined` | Response headers from the request |

### Usage

Expand All @@ -224,12 +237,13 @@ If the game has got only one map, returned data will be null and the error messa

Returns a Promise which resolves to the following object:

| Field | Type | Description |
| -------- | ------------------------------------------- | -------------------------------- |
| data | [Response](API.md#map-data) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| Field | Type | Description |
| -------- | ------------------------------------------- | --------------------------------- |
| data | [Response](API.md#map-data) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| headers | `Headers \| undefined` | Response headers from the request |

Allowed games (games with only one map don't work):

Expand Down Expand Up @@ -269,12 +283,13 @@ This includes level and prestige infomation.

Returns a Promise which resolves to the following object:

| Field | Type | Description |
| -------- | ------------------------------------------- | -------------------------------- |
| data | [Response](API.md#game-metadata) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| Field | Type | Description |
| -------- | ------------------------------------------- | --------------------------------- |
| data | [Response](API.md#game-metadata) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| headers | `Headers \| undefined` | Response headers from the request |

### Usage

Expand All @@ -297,12 +312,13 @@ Get a player's information, such as current/longest login streak, currently equi

Returns a Promise which resolves to the following object

| Field | Type | Description |
| -------- | ------------------------------------------- | -------------------------------- |
| data | [Response](API.md#playerinfo) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| Field | Type | Description |
| -------- | ------------------------------------------- | --------------------------------- |
| data | [Response](API.md#playerinfo) `\| null` | The response data |
| error | `{ code: number, message: string } \| null` | Error data |
| status | `number` | The http status returned |
| duration | `number \| undefined` | The duration of the http request |
| headers | `Headers \| undefined` | Response headers from the request |

### Usage

Expand Down
1 change: 1 addition & 0 deletions src/helpers/fetchEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default async function fetchEndpoint<T extends string>(

return {
status: request.status,
headers: request.headers,
data: response,
error: null,
duration,
Expand Down
9 changes: 5 additions & 4 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Game, Statistics, Timeframe } from "hive-bedrock-data";
interface APIResponse_Base {
duration?: number;
status: number;
headers?: Headers;
}
interface APIResponse_Error {
code: number;
Expand All @@ -23,7 +24,7 @@ export interface Options {
init: RequestInit;
}

export type OmittedSpecialStatistics<G extends Game, T extends Timeframe> = Omit<
Statistics<G, T>,
"first_played"
>;
export type OmittedSpecialStatistics<
G extends Game,
T extends Timeframe
> = Omit<Statistics<G, T>, "first_played">;