Skip to content

Commit

Permalink
[Client] Update types in client after updates in core, and expose the…
Browse files Browse the repository at this point in the history
… types
  • Loading branch information
Pewtro committed Mar 29, 2024
1 parent 190f5e7 commit 3d23667
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-turtles-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@blizzard-api/client': patch
---

Update types in client after updates in core, and expose the types
16 changes: 10 additions & 6 deletions packages/client/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { stringify } from 'node:querystring';
import { getEndpoint } from '@blizzard-api/core';
import type { Origins, Locales, ClientOptions, ResourceResponse, Resource } from '@blizzard-api/core';
import type { Origins, Locales, ResourceResponse, Resource } from '@blizzard-api/core';
import type { AxiosResponse } from 'axios';
import axios from 'axios';
import type {
AccessToken,
AccessTokenRequestArguments,
ClientOptions,
IBlizzardApiClient,
ValidateAccessTokenArguments,
ValidateAccessTokenResponse,
Expand Down Expand Up @@ -33,7 +34,10 @@ export class BlizzardApiClient implements IBlizzardApiClient {

public axios = axios.create();

public getRequestUrl<T = unknown>(resource: Resource<T>, options?: Partial<ClientOptions>) {
public getRequestUrl<T, Protected extends boolean = false>(
resource: Resource<T, Protected>,
options?: Partial<ClientOptions>,
) {
const config = { ...this.defaults, ...options };
const endpoint = getEndpoint(config.origin, config.locale);

Expand All @@ -42,8 +46,8 @@ export class BlizzardApiClient implements IBlizzardApiClient {
return `${endpoint.hostname}${backslashSeparator}${resource.path}`;
}

public getRequestConfig<T = unknown>(
resource: Resource<T>,
public getRequestConfig<T, Protected extends boolean = false>(
resource: Resource<T, Protected>,
options?: Partial<ClientOptions>,
headers?: Record<string, string>,
) {
Expand All @@ -67,8 +71,8 @@ export class BlizzardApiClient implements IBlizzardApiClient {
};
}

public sendRequest<T = void>(
resource: Resource<T>,
public sendRequest<T, Protected extends boolean = false>(
resource: Resource<T, Protected>,
options?: Partial<ClientOptions>,
headers?: Record<string, string>,
): ResourceResponse<AxiosResponse<T>> {
Expand Down
10 changes: 9 additions & 1 deletion packages/client/src/client/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Origins } from '@blizzard-api/core';
import type { Locales, Origins } from '@blizzard-api/core';
import type { AxiosResponse } from 'axios';

export interface AccessToken {
Expand Down Expand Up @@ -28,6 +28,14 @@ export interface ValidateAccessTokenResponse {
client_id: string;
}

export interface ClientOptions {
key: string;
secret: string;
origin: Origins;
locale?: Locales;
token?: string;
}

export interface IBlizzardApiClient {
getAccessToken: (options: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>;
setAccessToken: (token: string) => void;
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { BlizzardApiClient } from './client/index.js';
export * from './client/types';

0 comments on commit 3d23667

Please sign in to comment.