-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Client] Improve client functionality and dogfood @blizzard-api/wow
- Loading branch information
Showing
9 changed files
with
137 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@blizzard-api/client': patch | ||
--- | ||
|
||
Improve client functionality and dogfood @blizzard-api/wow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { Origins } from '@blizzard-api/core'; | ||
import type { AxiosResponse } from 'axios'; | ||
|
||
export interface AccessToken { | ||
access_token: string; | ||
token_type: 'bearer'; | ||
expires_in: number; | ||
sub?: string; | ||
} | ||
|
||
export interface AccessTokenRequestArguments { | ||
origin?: Origins; | ||
key?: string; | ||
secret?: string; | ||
} | ||
|
||
export interface ValidateAccessTokenArguments { | ||
origin?: Origins; | ||
token?: string; | ||
} | ||
|
||
export interface ValidateAccessTokenResponse { | ||
scope: Array<string>; | ||
account_authorities: Array<unknown>; | ||
exp: number; | ||
client_authorities: Array<unknown>; | ||
authorities: Array<string>; | ||
client_id: string; | ||
} | ||
|
||
export interface IBlizzardApiClient { | ||
getAccessToken: (options: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>; | ||
setAccessToken: (token: string) => void; | ||
refreshAccessToken: (options: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>; | ||
validateAccessToken: (options: ValidateAccessTokenArguments) => Promise<AxiosResponse<ValidateAccessTokenResponse>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export type { ClientOptions } from './client.js'; | ||
export { BlizzardApiClient } from './client.js'; | ||
export { BlizzardApiClient } from './client/index.js'; |
4 changes: 2 additions & 2 deletions
4
packages/client/tests/client.test.ts → packages/client/src/tests/client.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { wow } from '@blizzard-api/wow'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { environment } from '~/environment'; | ||
import { BlizzardApiClient } from '../../client'; | ||
|
||
describe('achievement', async () => { | ||
const client = new BlizzardApiClient({ | ||
key: environment.blizzardClientId, | ||
secret: environment.blizzardClientSecret, | ||
origin: 'eu', | ||
}); | ||
const access = await client.getAccessToken(); | ||
client.setAccessToken(access.data.access_token); | ||
|
||
it('should be able to fetch an achievement', async () => { | ||
const response = await client.sendRequest<{ id: number }>(wow.achievement.achievement(16_542)).catch((error) => { | ||
console.error('error', error); | ||
throw new Error('Failed to fetch achievement'); | ||
}); | ||
|
||
expect(response.data.id).toBe(16_542); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters